Skip to content

Commit

Permalink
Update Tests for new block gas limits
Browse files Browse the repository at this point in the history
  • Loading branch information
DavePearce committed Jul 15, 2024
1 parent 8cb9db5 commit 54778a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
submodules: recursive
- uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: adopt
cache: 'gradle'
- uses: dafny-lang/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dafnyevm/DafnyEvm.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public DafnyEvm fork(EvmFork.Fork fork) {
* @param gasPrice
* @return
*/
public DafnyEvm blockInfo(BlockInfo info) {
public DafnyEvm blockInfo(BlockInfo info) {
this.blockInfo = info;
return this;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public DafnyEvm.State<?> execute(Transaction tx) {
BigInteger maxFeePerGas;
// Check block limit
if(tx.gasLimit().compareTo(blockInfo.gasLimit) > 0) {
return new State.Invalid(tracer,Transaction.Outcome.GAS_LIMIT_REACHED);
return new State.Invalid(tracer,Transaction.Outcome.GAS_LIMIT_REACHED);
}
// Account for access list
if (tx.accessList() != null && fork.IsActive(EIP2930)) {
Expand Down
29 changes: 17 additions & 12 deletions src/test/java/dafnyevm/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public class Tests {
/**
* Default gas limit to use for contract calls.
*/
public static final BigInteger DEFAULT_GAS = new BigInteger("10000000000");
public static final BigInteger DEFAULT_GAS = new BigInteger("1000000");
/**
* Default block gas limit to use for contract calls.
*/
public static final BigInteger DEFAULT_BLOCK_GAS = new BigInteger("30000000");
/**
* Default call data to use for a call (unless otherwise specified).
*/
Expand Down Expand Up @@ -1146,46 +1150,46 @@ public void test_returndatacopy_03() {

@Test
public void test_coinbase_01() {
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().coinBase(0xcccc));
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(DEFAULT_BLOCK_GAS).coinBase(0xcccc));
byte[] output = callWithReturn(21017, tx,
new int[] { COINBASE, PUSH1, 0x00, MSTORE, PUSH1, 0x20, PUSH1, 0x00, RETURN });
assertArrayEquals(UINT256(0xcccc), output);
}

@Test
public void test_timestamp_01() {
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().timeStamp(0xcccc));
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(DEFAULT_BLOCK_GAS).timeStamp(0xcccc));
byte[] output = callWithReturn(21017, tx,
new int[] { TIMESTAMP, PUSH1, 0x00, MSTORE, PUSH1, 0x20, PUSH1, 0x00, RETURN });
assertArrayEquals(UINT256(0xcccc), output);
}

@Test
public void test_number_01() {
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().number(0xcccc));
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(DEFAULT_BLOCK_GAS).number(0xcccc));
byte[] output = callWithReturn(21017, tx, new int[] { NUMBER, PUSH1, 0x00, MSTORE, PUSH1, 0x20, PUSH1, 0x00, RETURN });
assertArrayEquals(UINT256(0xcccc), output);
}

@Test
public void test_difficulty_01() {
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().difficulty(0xcccc));
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(DEFAULT_BLOCK_GAS).difficulty(0xcccc));
byte[] output = callWithReturn(21017, tx,
new int[] { DIFFICULTY, PUSH1, 0x00, MSTORE, PUSH1, 0x20, PUSH1, 0x00, RETURN });
assertArrayEquals(UINT256(0xcccc), output);
}

@Test
public void test_gaslimit_01() {
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(0xcccc));
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(0xcccccc));
byte[] output = callWithReturn(21017, tx,
new int[] { GASLIMIT, PUSH1, 0x00, MSTORE, PUSH1, 0x20, PUSH1, 0x00, RETURN });
assertArrayEquals(UINT256(0xcccc), output);
assertArrayEquals(UINT256(0xcccccc), output);
}

@Test
public void test_chainid_01() {
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().chainID(0xcccc));
DafnyEvm tx = defaultDafnyEvm().blockInfo(new BlockInfo().gasLimit(DEFAULT_BLOCK_GAS).chainID(0xcccc));
byte[] output = callWithReturn(21017, tx,
new int[] { CHAINID, PUSH1, 0x00, MSTORE, PUSH1, 0x20, PUSH1, 0x00, RETURN });
assertArrayEquals(UINT256(0xcccc), output);
Expand Down Expand Up @@ -2380,7 +2384,7 @@ public void test_recursive_call_01() {
@Test
public void test_recursive_call_02() {
// Recursive contract call (with lots of gas)
LegacyTransaction tx = (LegacyTransaction) defaultTxCall().setGasLimit(0xfffffffffL);
LegacyTransaction tx = (LegacyTransaction) defaultTxCall(); //.setGasLimit(0xfffffffffL);
// Recursive contract call
byte[] output = callWithReturn(23684, tx,new int[] {
// Branch to STOP if calldata == 0xF.
Expand All @@ -2397,9 +2401,9 @@ public void test_recursive_call_02() {
@Test
public void test_recursive_call_03() {
// Recursive contract call (with lots of gas)
LegacyTransaction tx = (LegacyTransaction) defaultTxCall().setGasLimit(0xffffffffffL);
LegacyTransaction tx = (LegacyTransaction) defaultTxCall().setGasLimit(0xfffffL);
//
byte[] output = callWithReturn(201077, tx,new int[] {
byte[] output = callWithReturn(1048575, tx,new int[] {
// Branch to STOP if calldata == 0x3ff.
PUSH1, 0x00, CALLDATALOAD, DUP1, PUSH2, 0x3, 0xff, EQ, PUSH1, 0x20, JUMPI,
// Add one to value for next call
Expand Down Expand Up @@ -2739,7 +2743,8 @@ private void invalidCall(Transaction.Outcome err, int[] words) {
}

private DafnyEvm defaultDafnyEvm() {
return new DafnyEvm().create(DEFAULT_SENDER, DEFAULT_BALANCE);
DafnyEvm.BlockInfo block = new BlockInfo().gasLimit(DEFAULT_BLOCK_GAS);
return new DafnyEvm().blockInfo(block).create(DEFAULT_SENDER, DEFAULT_BALANCE);
}

private LegacyTransaction defaultTxCall() {
Expand Down

0 comments on commit 54778a8

Please sign in to comment.