Skip to content

Commit 65945d0

Browse files
committed
all: convert to geas-ffi
1 parent 9b5d485 commit 65945d0

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
cache/
22
out/
3-
test/*.t.sol

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[profile.default]
2+
evm_version = 'prague'
23
src = 'src'
34
out = 'out'
5+
ffi = true
46
libs = ['lib']

test/BeaconRoot.t.sol.in renamed to test/BeaconRoot.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
pragma solidity ^0.8.13;
33

44
import "forge-std/Test.sol";
5+
import "geas-ffi/Geas.sol";
56
import "../src/Contract.sol";
67

7-
address constant addr = 0x000000000000000000000000000000000000000b;
8+
address constant addr = 0x0000000000000000000000000000000000000bBB;
89
address constant sysaddr = 0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE;
910
uint256 constant buflen = 8191;
1011
bytes32 constant root = hex"88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6";
@@ -25,7 +26,7 @@ contract ContractTest is Test {
2526
address unit;
2627

2728
function setUp() public {
28-
vm.etch(addr, hex"@bytecode@");
29+
vm.etch(addr, Geas.compile("src/beacon_root/main.eas"));
2930
unit = addr;
3031
}
3132

test/Consolidation.t.sol.in renamed to test/Consolidation.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4+
import "geas-ffi/Geas.sol";
45
import "./Test.sol";
56

67
uint256 constant target_per_block = 1;
@@ -10,8 +11,8 @@ uint256 constant inhibitor = uint256(bytes32(0xfffffffffffffffffffffffffffffffff
1011
contract ConsolidationTest is Test {
1112

1213
function setUp() public {
13-
vm.etch(addr, hex"@bytecode@");
14-
vm.etch(fakeExpo, hex"@bytecode_expo@");
14+
vm.etch(addr, Geas.compile("src/consolidations/main.eas"));
15+
vm.etch(fakeExpo, Geas.compile("src/common/fake_expo_test.eas"));
1516
}
1617

1718
// testInvalidRequest checks that common invalid requests are rejected.

test/ExecutionHash.t.sol.in renamed to test/ExecutionHash.t.sol

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.13;
33

44
import "forge-std/Test.sol";
5+
import "geas-ffi/Geas.sol";
56
import "../src/Contract.sol";
67

78
address constant addr = 0x000000000000000000000000000000000000aaaa;
@@ -18,40 +19,37 @@ function hash_idx() view returns (bytes32) {
1819
}
1920

2021
contract ContractTest is Test {
21-
address unit;
22-
2322
function setUp() public {
24-
vm.etch(addr, hex"@bytecode@");
25-
unit = addr;
23+
vm.etch(addr, Geas.compile("src/execution_hash/main.eas"));
2624
}
2725

2826
// testRead verifies the contract returns the expected execution hash.
2927
function testExecRead() public {
3028
// Store hash at expected indexes.
31-
vm.store(unit, hash_idx(), hash);
29+
vm.store(addr, hash_idx(), hash);
3230

3331
// Read hash associated with current timestamp.
34-
(bool ret, bytes memory data) = unit.call(bytes.concat(lastBlockNumber()));
32+
(bool ret, bytes memory data) = addr.call(bytes.concat(lastBlockNumber()));
3533
assertTrue(ret);
3634
assertEq(data, bytes.concat(hash));
3735
}
3836

3937
function testReadBadCalldataSize() public {
4038
// Store hash at expected indexes.
41-
vm.store(unit, hash_idx(), hash);
39+
vm.store(addr, hash_idx(), hash);
4240

4341
// Call with 0 byte arguement.
44-
(bool ret, bytes memory data) = unit.call(hex"");
42+
(bool ret, bytes memory data) = addr.call(hex"");
4543
assertFalse(ret);
4644
assertEq(data, hex"");
4745

4846
// Call with 31 byte arguement.
49-
(ret, data) = unit.call(hex"00000000000000000000000000000000000000000000000000000000001337");
47+
(ret, data) = addr.call(hex"00000000000000000000000000000000000000000000000000000000001337");
5048
assertFalse(ret);
5149
assertEq(data, hex"");
5250

5351
// Call with 33 byte arguement.
54-
(ret, data) = unit.call(hex"000000000000000000000000000000000000000000000000000000000000001337");
52+
(ret, data) = addr.call(hex"000000000000000000000000000000000000000000000000000000000000001337");
5553
assertFalse(ret);
5654
assertEq(data, hex"");
5755
}
@@ -62,25 +60,25 @@ contract ContractTest is Test {
6260
uint256 number = block.number-1;
6361

6462
// Store hash at expected indexes.
65-
vm.store(unit, hash_idx(), hash);
63+
vm.store(addr, hash_idx(), hash);
6664

6765
// Request current block.
68-
(bool ret, bytes memory data) = unit.call(bytes.concat(bytes32(block.number)));
66+
(bool ret, bytes memory data) = addr.call(bytes.concat(bytes32(block.number)));
6967
assertFalse(ret);
7068
assertEq(data, hex"");
7169

7270
// Wrap around buflen once forward.
73-
(ret, data) = unit.call(bytes.concat(bytes32(number+buflen)));
71+
(ret, data) = addr.call(bytes.concat(bytes32(number+buflen)));
7472
assertFalse(ret);
7573
assertEq(data, hex"");
7674

7775
// Wrap around buflen once backward.
78-
(ret, data) = unit.call(bytes.concat(bytes32(number-buflen)));
76+
(ret, data) = addr.call(bytes.concat(bytes32(number-buflen)));
7977
assertFalse(ret);
8078
assertEq(data, hex"");
8179

8280
// Block number zero should fail.
83-
(ret, data) = unit.call(bytes.concat(bytes32(0)));
81+
(ret, data) = addr.call(bytes.concat(bytes32(0)));
8482
assertFalse(ret);
8583
assertEq(data, hex"");
8684
}
@@ -89,12 +87,12 @@ contract ContractTest is Test {
8987
function testUpdate() public {
9088
// Simulate pre-block call to set hash.
9189
vm.prank(sysaddr);
92-
(bool ret, bytes memory data) = unit.call(bytes.concat(hash));
90+
(bool ret, bytes memory data) = addr.call(bytes.concat(hash));
9391
assertTrue(ret);
9492
assertEq(data, hex"");
9593

9694
// Verify hash.
97-
bytes32 got = vm.load(unit, hash_idx());
95+
bytes32 got = vm.load(addr, hash_idx());
9896
assertEq(got, hash);
9997
}
10098

@@ -110,13 +108,13 @@ contract ContractTest is Test {
110108

111109
// Simulate pre-block call to set hash.
112110
vm.prank(sysaddr);
113-
(bool ret, bytes memory data) = unit.call(bytes.concat(pbbr));
111+
(bool ret, bytes memory data) = addr.call(bytes.concat(pbbr));
114112
assertTrue(ret);
115113
assertEq(data, hex"");
116114

117115
// Call contract as normal account to get exeuction hash associated
118116
// with current timestamp.
119-
(ret, data) = unit.call(bytes.concat(lastBlockNumber()));
117+
(ret, data) = addr.call(bytes.concat(lastBlockNumber()));
120118
assertTrue(ret);
121119
assertEq(data, bytes.concat(pbbr));
122120

@@ -136,7 +134,7 @@ contract ContractTest is Test {
136134
for (uint256 i = 0; i < buflen; i += 1) {
137135
bytes32 pbbr = bytes32(i*1337);
138136
vm.prank(sysaddr);
139-
(bool ret, bytes memory data) = unit.call(bytes.concat(pbbr));
137+
(bool ret, bytes memory data) = addr.call(bytes.concat(pbbr));
140138
assertTrue(ret);
141139
assertEq(data, hex"");
142140
if (i+1 < buflen) {
@@ -152,7 +150,7 @@ contract ContractTest is Test {
152150
// Attempt to read all values in same block context.
153151
for (uint256 i = 0; i < buflen; i += 1) {
154152
bytes32 num = bytes32(uint256(base+i));
155-
(bool ret, bytes memory got) = unit.call(bytes.concat(num));
153+
(bool ret, bytes memory got) = addr.call(bytes.concat(num));
156154
assertTrue(ret);
157155
assertEq(got, bytes.concat(bytes32(i*1337)));
158156
}

test/FakeExpo.t.sol.in renamed to test/FakeExpo.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4+
import "geas-ffi/Geas.sol";
45
import "./Test.sol";
56

67
contract FakeExpoTest is Test {
78
function setUp() public {
8-
vm.etch(fakeExpo, hex"@bytecode@");
9+
vm.etch(fakeExpo, Geas.compile("src/common/fake_expo_test.eas"));
910
}
1011

1112
// testFakeExpo calls the fake exponentiation logic with specific values.

test/Withdrawal.t.sol.in renamed to test/Withdrawal.t.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4+
import "geas-ffi/Geas.sol";
45
import "./Test.sol";
56

67
uint256 constant target_per_block = 2;
78
uint256 constant max_per_block = 16;
89
uint256 constant inhibitor = uint256(bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff));
910

1011
contract WithdrawalsTest is Test {
11-
address unit;
12-
1312
function setUp() public {
14-
vm.etch(addr, hex"@bytecode@");
15-
vm.etch(fakeExpo, hex"@bytecode_expo@");
16-
unit = addr;
13+
vm.etch(addr, Geas.compile("src/withdrawals/main.eas"));
14+
vm.etch(fakeExpo, Geas.compile("src/common/fake_expo_test.eas"));
1715
}
1816

1917
// testInvalidWithdrawal checks that common invalid withdrawal requests are rejected.

0 commit comments

Comments
 (0)