Skip to content

Commit

Permalink
Renumber EOF and Transient storage (hyperledger#5550)
Browse files Browse the repository at this point in the history
As per a recent EIP update the opcode numbers for Transient Storage
have been updated.  EOF opcodes were also updated.
Update the code and test cases for the new numbers.

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
  • Loading branch information
shemnon authored Jun 12, 2023
1 parent cb12a2c commit 9913a5a
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
public class CodeValidationSubCommandTest {

static final String CODE_STOP_ONLY = "0xef0001 010004 020001-0001 030000 00 00000000 00";
static final String CODE_RETF_ONLY = "0xef0001 010004 020001-0001 030000 00 00000000 b1";
static final String CODE_BAD_MAGIC = "0xefffff 010004 020001-0001 030000 00 00000000 b1";
static final String CODE_RETF_ONLY = "0xef0001 010004 020001-0001 030000 00 00000000 e4";
static final String CODE_BAD_MAGIC = "0xefffff 010004 020001-0001 030000 00 00000000 e4";
static final String CODE_INTERIOR_COMMENTS =
"0xef0001 010008 020002-000c-0002 030000 00 \n"
+ "# 7 inputs 1 output,\n"
+ "00000007-07010007 \n"
+ "59-59-59-59-59-59-59-b00001-50-b1\n"
+ "# No immediate data\n"
+ "f1-b1";
"""
0xef0001 010008 020002-000c-0002 030000 00
# 7 inputs 1 output,
00000007-07010007
59-59-59-59-59-59-59-e30001-50-e4
# No immediate data
f1-e4""";
static final String CODE_MULTIPLE =
CODE_STOP_ONLY + "\n" + CODE_BAD_MAGIC + "\n" + CODE_RETF_ONLY + "\n";

Expand Down Expand Up @@ -67,7 +68,12 @@ public void testMultipleViaInput() {
new CodeValidateSubCommand(bais, new PrintStream(baos));
codeValidateSubCommand.run();
assertThat(baos.toString(UTF_8))
.contains("OK 00\n" + "err: layout - EOF header byte 1 incorrect\n" + "OK b1\n");
.contains(
"""
OK 00
err: layout - EOF header byte 1 incorrect
OK e4
""");
}

@Test
Expand Down Expand Up @@ -104,7 +110,12 @@ public void testMultipleViaCli() {
cmd.parseArgs(CODE_STOP_ONLY, CODE_BAD_MAGIC, CODE_RETF_ONLY);
codeValidateSubCommand.run();
assertThat(baos.toString(UTF_8))
.contains("OK 00\n" + "err: layout - EOF header byte 1 incorrect\n" + "OK b1\n");
.contains(
"""
OK 00
err: layout - EOF header byte 1 incorrect
OK e4
""");
}

@Test
Expand All @@ -116,7 +127,7 @@ public void testCliEclipsesInput() {
final CommandLine cmd = new CommandLine(codeValidateSubCommand);
cmd.parseArgs(CODE_RETF_ONLY);
codeValidateSubCommand.run();
assertThat(baos.toString(UTF_8)).contains("OK b1\n");
assertThat(baos.toString(UTF_8)).contains("OK e4\n");
}

@Test
Expand All @@ -128,7 +139,7 @@ public void testInteriorCommentsSkipped() {
final CommandLine cmd = new CommandLine(codeValidateSubCommand);
cmd.parseArgs(CODE_INTERIOR_COMMENTS);
codeValidateSubCommand.run();
assertThat(baos.toString(UTF_8)).contains("OK 59595959595959b0000150b1,f1b1\n");
assertThat(baos.toString(UTF_8)).contains("OK 59595959595959e3000150e4,f1e4\n");
}

@Test
Expand All @@ -140,6 +151,11 @@ public void testBlankLinesAndCommentsSkipped() {
new CodeValidateSubCommand(bais, new PrintStream(baos));
codeValidateSubCommand.run();
assertThat(baos.toString(UTF_8))
.isEqualTo("OK 00\n" + "err: layout - EOF header byte 1 incorrect\n" + "OK b1\n");
.isEqualTo(
"""
OK 00
err: layout - EOF header byte 1 incorrect
OK e4
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ private CodeV1Validation() {
VALID, // 0x59 - MSIZE
VALID, // 0x5a - GAS
VALID, // 0x5b - NOOOP (née JUMPDEST)
VALID_AND_TERMINAL, // 0X5c - RJUMP
VALID, // 0X5d - RJUMPI
VALID, // 0X5e - RJUMPV
VALID, // 0X5c - TLOAD
VALID, // 0X5d - TSTORE
VALID, // 0X5e - MCOPY
VALID, // 0X5f - PUSH0
VALID, // 0x60 - PUSH1
VALID, // 0x61 - PUSH2
Expand Down Expand Up @@ -219,9 +219,9 @@ private CodeV1Validation() {
INVALID, // 0xad
INVALID, // 0xae
INVALID, // 0xaf
VALID, // 0xb0 - CALLF
VALID_AND_TERMINAL, // 0xb1 - RETF
INVALID, // 0xb2 - JUMPF
INVALID, // 0xb0
INVALID, // 0xb1
INVALID, // 0xb2
INVALID, // 0xb3
INVALID, // 0xb4
INVALID, // 0xb5
Expand Down Expand Up @@ -267,11 +267,11 @@ private CodeV1Validation() {
INVALID, // 0xdd
INVALID, // 0xde
INVALID, // 0xef
INVALID, // 0xe0
INVALID, // 0xe1
INVALID, // 0xe2
INVALID, // 0xe3
INVALID, // 0xe4
VALID_AND_TERMINAL, // 0xe0 - RJUMP
VALID, // 0xe1 - RJUMPI
VALID, // 0xe2 - RJUMPV
VALID, // 0xe3 - CALLF
VALID_AND_TERMINAL, // 0xe4 - RETF
INVALID, // 0xe5
INVALID, // 0xe6
INVALID, // 0xe7
Expand Down Expand Up @@ -398,9 +398,9 @@ private CodeV1Validation() {
{0, 1, 1}, // 0x59 - MSIZE
{0, 1, 1}, // 0x5a - GAS
{0, 0, 1}, // 0x5b - NOOP (née JUMPDEST)
{0, 0, -3}, // 0x5c - RJUMP
{1, 0, 3}, // 0x5d - RJUMPI
{1, 0, 2}, // 0x5e - RJUMPV
{1, 1, 1}, // 0x5c - TLOAD
{2, 0, 1}, // 0x5d - TSTORE
{4, 0, 1}, // 0x5e - MCOPY
{0, 1, 1}, // 0x5f - PUSH0
{0, 1, 2}, // 0x60 - PUSH1
{0, 1, 3}, // 0x61 - PUSH2
Expand Down Expand Up @@ -482,9 +482,9 @@ private CodeV1Validation() {
{0, 0, 0}, // 0xad
{0, 0, 0}, // 0xae
{0, 0, 0}, // 0xaf
{0, 0, 3}, // 0xb0 - CALLF
{0, 0, -1}, // 0xb1 - RETF
{0, 0, 0}, // 0xb2 - JUMPF
{0, 0, 0}, // 0xb0
{0, 0, 0}, // 0xb1
{0, 0, 0}, // 0xb2
{0, 0, 0}, // 0xb3
{0, 0, 0}, // 0xb4
{0, 0, 0}, // 0xb5
Expand Down Expand Up @@ -530,12 +530,12 @@ private CodeV1Validation() {
{0, 0, 0}, // 0xdd
{0, 0, 0}, // 0xde
{0, 0, 0}, // 0xef
{0, 0, 0}, // 0xe0
{0, 0, 0}, // 0xe1
{0, 0, 0}, // 0xe2
{0, 0, 0}, // 0xe3
{0, 0, 0}, // 0xe4
{0, 0, 0}, // 0xe5
{0, 0, -3}, // 0xe0 - RJUMP
{1, 0, 3}, // 0xe1 - RJUMPI
{1, 0, 2}, // 0xe2 - RJUMPV
{0, 0, 3}, // 0xe3 - CALLF
{0, 0, -1}, // 0xe4 - RETF
{0, 0, 0}, // 0xe5 - JUMPF
{0, 0, 0}, // 0xe6
{0, 0, 0}, // 0xe7
{0, 0, 0}, // 0xe8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class CallFOperation extends AbstractOperation {

/** The constant OPCODE. */
public static final int OPCODE = 0xb0;
public static final int OPCODE = 0xe3;
/** The Call F success. */
static final OperationResult callfSuccess = new OperationResult(5, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class JumpFOperation extends AbstractOperation {

/** The constant OPCODE. */
public static final int OPCODE = 0xb2;
public static final int OPCODE = 0xe5;
/** The Jump F success operation result. */
static final OperationResult jumpfSuccess = new OperationResult(3, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class RelativeJumpIfOperation extends RelativeJumpOperation {

/** The constant OPCODE. */
public static final int OPCODE = 0x5d;
public static final int OPCODE = 0xe1;

/**
* Instantiates a new Relative jump If operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class RelativeJumpOperation extends AbstractFixedCostOperation {

/** The constant OPCODE. */
public static final int OPCODE = 0x5c;
public static final int OPCODE = 0xe0;

/**
* Instantiates a new Relative jump operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class RelativeJumpVectorOperation extends AbstractFixedCostOperation {

/** The constant OPCODE. */
public static final int OPCODE = 0x5e;
public static final int OPCODE = 0xe2;

/**
* Instantiates a new Relative jump vector operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class RetFOperation extends AbstractOperation {

/** The Opcode. */
public static final int OPCODE = 0xb1;
public static final int OPCODE = 0xe4;
/** The Ret F success. */
static final OperationResult retfSuccess = new OperationResult(4, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TLoadOperation extends AbstractOperation {
* @param gasCalculator gas calculator for costing
*/
public TLoadOperation(final GasCalculator gasCalculator) {
super(0xb3, "TLOAD", 1, 1, gasCalculator);
super(0x5C, "TLOAD", 1, 1, gasCalculator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TStoreOperation extends AbstractOperation {
* @param gasCalculator gas calculator for costing
*/
public TStoreOperation(final GasCalculator gasCalculator) {
super(0xb4, "TSTORE", 2, 0, gasCalculator);
super(0x5D, "TSTORE", 2, 0, gasCalculator);
}

@Override
Expand Down
Loading

0 comments on commit 9913a5a

Please sign in to comment.