Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable EOF CALL opcodes in legacy #7544

Merged
merged 8 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public long gasAvailableForChildCall(final MessageFrame frame) {

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
Code callingCode = frame.getCode();
if (callingCode.getEofVersion() == 0) {
return InvalidOperation.INVALID_RESULT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add some tests showing that an INVALID_RESULT is returned for legacy with EXTCALL, EXTDELEGATECALL and EXTSTATICCALL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ethereum/execution-spec-tests/pull/768/files

Tests all legacy-invalid opcodes, not just EXT*CREATE.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we can pull in the latest execution-spec tests when they get published 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f19e242 also should address @jframe's concern

}

final Bytes toBytes = frame.getStackItem(STACK_TO).trimLeadingZeros();
final Wei value = value(frame);
final boolean zeroValue = value.isZero();
Expand Down Expand Up @@ -141,7 +146,7 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
frame.clearReturnData();

// delegate calls to prior EOF versions are prohibited
if (isDelegate() && frame.getCode().getEofVersion() != code.getEofVersion()) {
if (isDelegate() && callingCode.getEofVersion() != code.getEofVersion()) {
return softFailure(frame, cost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
/** The Call operation. */
public class ExtCallOperation extends AbstractExtCallOperation {

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

static final int STACK_VALUE = 3;

/**
Expand All @@ -32,7 +35,7 @@ public class ExtCallOperation extends AbstractExtCallOperation {
* @param gasCalculator the gas calculator
*/
public ExtCallOperation(final GasCalculator gasCalculator) {
super(0xF8, "EXTCALL", 4, 1, gasCalculator);
super(OPCODE, "EXTCALL", 4, 1, gasCalculator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
/** The Delegate call operation. */
public class ExtDelegateCallOperation extends AbstractExtCallOperation {

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

/**
* Instantiates a new Delegate call operation.
*
* @param gasCalculator the gas calculator
*/
public ExtDelegateCallOperation(final GasCalculator gasCalculator) {
super(0xF9, "EXTDELEGATECALL", 3, 1, gasCalculator);
super(OPCODE, "EXTDELEGATECALL", 3, 1, gasCalculator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
/** The Static call operation. */
public class ExtStaticCallOperation extends AbstractExtCallOperation {

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

/**
* Instantiates a new Static call operation.
*
* @param gasCalculator the gas calculator
*/
public ExtStaticCallOperation(final GasCalculator gasCalculator) {
super(0xFB, "EXTSTATICCALL", 3, 1, gasCalculator);
super(OPCODE, "EXTSTATICCALL", 3, 1, gasCalculator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class ExtCallOperationTest {
private final WorldUpdater worldUpdater = mock(WorldUpdater.class);
private final MutableAccount account = mock(MutableAccount.class);
private static final EVM EOF_EVM = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT);
public static final Code LEGACY_CODE =
EOF_EVM.getCodeUncached(Bytes.of(ExtCallOperation.OPCODE, 1));
public static final Code SIMPLE_EOF =
EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000000"));
public static final Code INVALID_EOF =
Expand Down Expand Up @@ -118,6 +120,7 @@ void gasTest(
final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(parentGas)
.code(SIMPLE_EOF)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
Expand Down Expand Up @@ -208,6 +211,7 @@ void callWithValueTest(
final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(parentGas)
.code(SIMPLE_EOF)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(valueSent)
.pushStackItem(Bytes.EMPTY)
Expand Down Expand Up @@ -243,6 +247,7 @@ void overflowTest() {
final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(400000)
.code(SIMPLE_EOF)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
Expand Down Expand Up @@ -273,4 +278,33 @@ void overflowTest() {
assertThat(parentFrame.getStackItem(0))
.isEqualTo(AbstractExtCallOperation.EOF1_EXCEPTION_STACK_ITEM);
}

@Test
void legacyTest() {
final ExtCallOperation operation = new ExtCallOperation(new PragueEOFGasCalculator());

final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(400000)
.code(LEGACY_CODE)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
.pushStackItem(CONTRACT_ADDRESS)
.worldUpdater(worldUpdater)
.build();
messageFrame.warmUpAddress(CONTRACT_ADDRESS);
when(account.getBalance()).thenReturn(Wei.ZERO);
when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash());
when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes());
when(worldUpdater.get(any())).thenReturn(account);
when(worldUpdater.getAccount(any())).thenReturn(account);
when(worldUpdater.updater()).thenReturn(worldUpdater);

var result = operation.execute(messageFrame, EOF_EVM);

assertThat(result.getGasCost()).isZero();
assertThat(result.getHaltReason()).isEqualTo(ExceptionalHaltReason.INVALID_OPERATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class ExtDelegateCallOperationTest {
private final MutableAccount account = mock(MutableAccount.class);
// private final MutableAccount targetAccount = mock(MutableAccount.class);
private static final EVM EOF_EVM = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT);
public static final Code LEGACY_CODE =
EOF_EVM.getCodeUncached(Bytes.of(ExtDelegateCallOperation.OPCODE, 1));
public static final Code SIMPLE_EOF =
EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000000"));
public static final Code SIMPLE_LEGACY = EOF_EVM.getCodeUncached(Bytes.fromHexString("0x00"));
Expand Down Expand Up @@ -229,6 +231,7 @@ void overflowTest() {
final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(400000)
.code(SIMPLE_EOF)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
Expand Down Expand Up @@ -258,4 +261,34 @@ void overflowTest() {
assertThat(parentFrame.getStackItem(0))
.isEqualTo(AbstractExtCallOperation.EOF1_EXCEPTION_STACK_ITEM);
}

@Test
void legacyTest() {
final ExtDelegateCallOperation operation =
new ExtDelegateCallOperation(new PragueEOFGasCalculator());

final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(400000)
.code(LEGACY_CODE)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
.pushStackItem(CONTRACT_ADDRESS)
.worldUpdater(worldUpdater)
.build();
messageFrame.warmUpAddress(CONTRACT_ADDRESS);
when(account.getBalance()).thenReturn(Wei.ZERO);
when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash());
when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes());
when(worldUpdater.get(any())).thenReturn(account);
when(worldUpdater.getAccount(any())).thenReturn(account);
when(worldUpdater.updater()).thenReturn(worldUpdater);

var result = operation.execute(messageFrame, EOF_EVM);

assertThat(result.getGasCost()).isZero();
assertThat(result.getHaltReason()).isEqualTo(ExceptionalHaltReason.INVALID_OPERATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class ExtStaticCallOperationTest {
private final WorldUpdater worldUpdater = mock(WorldUpdater.class);
private final MutableAccount account = mock(MutableAccount.class);
private static final EVM EOF_EVM = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT);
public static final Code LEGACY_CODE =
EOF_EVM.getCodeUncached(Bytes.of(ExtStaticCallOperation.OPCODE, 1));
public static final Code SIMPLE_EOF =
EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000000"));
public static final Code INVALID_EOF =
Expand Down Expand Up @@ -119,6 +121,7 @@ void gasTest(
final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(parentGas)
.code(SIMPLE_EOF)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
Expand Down Expand Up @@ -154,6 +157,7 @@ void overflowTest() {
final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(400000)
.code(SIMPLE_EOF)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
Expand Down Expand Up @@ -183,4 +187,34 @@ void overflowTest() {
assertThat(parentFrame.getStackItem(0))
.isEqualTo(AbstractExtCallOperation.EOF1_EXCEPTION_STACK_ITEM);
}

@Test
void legacyTest() {
final ExtStaticCallOperation operation =
new ExtStaticCallOperation(new PragueEOFGasCalculator());

final var messageFrame =
new TestMessageFrameBuilder()
.initialGas(400000)
.code(LEGACY_CODE)
.pushStackItem(CONTRACT_ADDRESS) // canary for non-returning
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
.pushStackItem(Bytes.EMPTY)
.pushStackItem(CONTRACT_ADDRESS)
.worldUpdater(worldUpdater)
.build();
messageFrame.warmUpAddress(CONTRACT_ADDRESS);
when(account.getBalance()).thenReturn(Wei.ZERO);
when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash());
when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes());
when(worldUpdater.get(any())).thenReturn(account);
when(worldUpdater.getAccount(any())).thenReturn(account);
when(worldUpdater.updater()).thenReturn(worldUpdater);

var result = operation.execute(messageFrame, EOF_EVM);

assertThat(result.getGasCost()).isZero();
assertThat(result.getHaltReason()).isEqualTo(ExceptionalHaltReason.INVALID_OPERATION);
}
}
Loading