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

Enforce EOF version validation rules #4959

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
review changes
Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
  • Loading branch information
shemnon committed Jan 19, 2023
commit 27d975b8938cb7c5c64701af860437197fc91436
4 changes: 1 addition & 3 deletions evm/src/main/java/org/hyperledger/besu/evm/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,5 @@ public interface Code {
*
* @return The version of hte ode.
*/
default int getEofVersion() {
return 0;
}
int getEofVersion();
}
5 changes: 5 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/code/CodeV0.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public int getCodeSectionCount() {
return 1;
}

@Override
public int getEofVersion() {
return 0;
}

/**
* Calculate jump destination.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ private MessageFrame testMemoryFrame(
return messageFrame;
}

@org.junit.Test
public void eofV1CannotCreateLegacy() {
@Test
void eofV1CannotCreateLegacy() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size());
final MessageFrame messageFrame =
Expand All @@ -331,8 +331,8 @@ public void eofV1CannotCreateLegacy() {
assertThat(messageFrame.getStackItem(0)).isEqualTo(UInt256.ZERO);
}

@org.junit.Test
public void legacyCanCreateEOFv1() {
@Test
void legacyCanCreateEOFv1() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_EOF.size());
final MessageFrame messageFrame =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CreateOperationTest {
class CreateOperationTest {

private final WorldUpdater worldUpdater = mock(WorldUpdater.class);
private final WrappedEvmAccount account = mock(WrappedEvmAccount.class);
Expand Down Expand Up @@ -83,7 +83,7 @@ public class CreateOperationTest {
private static final int SHANGHAI_CREATE_GAS = 41240;

@Test
public void createFromMemoryMutationSafe() {
void createFromMemoryMutationSafe() {

// Given: Execute a CREATE operation with a contract that logs in the constructor
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
Expand Down Expand Up @@ -126,7 +126,7 @@ public void createFromMemoryMutationSafe() {
}

@Test
public void nonceTooLarge() {
void nonceTooLarge() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size());
final ArrayDeque<MessageFrame> messageFrameStack = new ArrayDeque<>();
Expand All @@ -145,7 +145,7 @@ public void nonceTooLarge() {
}

@Test
public void messageFrameStackTooDeep() {
void messageFrameStackTooDeep() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size());
final ArrayDeque<MessageFrame> messageFrameStack = new ArrayDeque<>();
Expand All @@ -164,7 +164,7 @@ public void messageFrameStackTooDeep() {
}

@Test
public void notEnoughValue() {
void notEnoughValue() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size());
final ArrayDeque<MessageFrame> messageFrameStack = new ArrayDeque<>();
Expand All @@ -186,7 +186,7 @@ public void notEnoughValue() {
}

@Test
public void shanghaiMaxInitCodeSizeCreate() {
void shanghaiMaxInitCodeSizeCreate() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.fromHexString("0xc000");
final ArrayDeque<MessageFrame> messageFrameStack = new ArrayDeque<>();
Expand Down Expand Up @@ -218,7 +218,7 @@ public void shanghaiMaxInitCodeSizeCreate() {
}

@Test
public void shanghaiMaxInitCodeSizePlus1Create() {
void shanghaiMaxInitCodeSizePlus1Create() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.fromHexString("0xc001");
final ArrayDeque<MessageFrame> messageFrameStack = new ArrayDeque<>();
Expand All @@ -242,7 +242,7 @@ public void shanghaiMaxInitCodeSizePlus1Create() {
}

@Test
public void eofV1CannotCreateLegacy() {
void eofV1CannotCreateLegacy() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size());
final MessageFrame messageFrame =
Expand All @@ -266,7 +266,7 @@ public void eofV1CannotCreateLegacy() {
}

@Test
public void legacyCanCreateEOFv1() {
void legacyCanCreateEOFv1() {
final UInt256 memoryOffset = UInt256.fromHexString("0xFF");
final UInt256 memoryLength = UInt256.valueOf(SIMPLE_EOF.size());
final MessageFrame messageFrame =
Expand Down