From b67674a1c0eecf9e29a2613beb49a9b8e2b38acb Mon Sep 17 00:00:00 2001 From: James Wenzel Date: Thu, 29 Feb 2024 13:08:00 -0700 Subject: [PATCH 1/8] add tstorish test script --- foundry.toml | 22 +++++++++++++--------- script/TstorishDeploy.s.sol | 17 +++++++++++++++++ tstorish.sh | 23 +++++++++++++++++++++++ tstorish/Tstorish.t.sol | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 script/TstorishDeploy.s.sol create mode 100644 tstorish.sh create mode 100644 tstorish/Tstorish.t.sol diff --git a/foundry.toml b/foundry.toml index eadf4fa..1dfb3ce 100644 --- a/foundry.toml +++ b/foundry.toml @@ -19,7 +19,7 @@ remappings = [ 'seaport-types/=src/types/', 'seaport-core/src/=src/core/', 'seaport-core/=src/core/', - 'seaport/=src/main/' + 'seaport/=src/main/', ] optimizer_runs = 4_294_967_295 fs_permissions = [ @@ -28,7 +28,7 @@ fs_permissions = [ { access = "write", path = "./call-metrics.txt" }, { access = "write", path = "./mutation-metrics.txt" }, { access = "write", path = "./assume-metrics.txt" }, - { access = "write", path = "./fuzz_debug.json" } + { access = "write", path = "./fuzz_debug.json" }, ] [profile.validator] @@ -47,7 +47,8 @@ out = 'reference-out' script = 'reference' # specify something so it doesn't try to compile the files in test/foundry test = 'test/foundry' -cache_path='reference-cache' +cache_path = 'reference-cache' +evm_version = 'cancun' [profile.optimized] src = 'src' @@ -57,14 +58,14 @@ out = 'optimized-out' script = 'script' bytecode_hash = 'none' # no need to compile tests with via-ir since they load optimized bytecode directly by default -test ='src/main' +test = 'src/main' evm_version = 'cancun' -cache_path='optimized-cache' -extra_output_files=['irOptimized'] +cache_path = 'optimized-cache' +extra_output_files = ['irOptimized'] [profile.test] src = 'test/foundry' -cache_path='test-cache' +cache_path = 'test-cache' [profile.test.fuzz] runs = 1_000 @@ -81,11 +82,14 @@ optimizer = false test = 'test/foundry/new' [profile.offerers] -src='offerers' -test='offerers' +src = 'offerers' +test = 'offerers' out = 'offerers-out' script = 'offerers' +[profile.tstorish] +test = 'tstorish' + [fmt] line_length = 80 tab_width = 4 diff --git a/script/TstorishDeploy.s.sol b/script/TstorishDeploy.s.sol new file mode 100644 index 0000000..06f6d65 --- /dev/null +++ b/script/TstorishDeploy.s.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import { Script, console2 } from "forge-std/Script.sol"; +import { ConduitController } from + "seaport-core/src/conduit/ConduitController.sol"; +import { Consideration } from "seaport-core/src/lib/Consideration.sol"; + +contract TstorishDeploy is Script { + function run() public { + vm.broadcast(); + ConduitController controller = new ConduitController(); + vm.label(address(controller), "controller"); + vm.broadcast(); + Consideration seaport = new Consideration(address(controller)); + } +} diff --git a/tstorish.sh b/tstorish.sh new file mode 100644 index 0000000..ceaf28b --- /dev/null +++ b/tstorish.sh @@ -0,0 +1,23 @@ +# remove old dump +rm -f seaport.dump +# spin up anvil and prepare to dump state +anvil --hardfork shanghai --dump-state $cwd/seaport.dump & +# save pid to kill later +pid=$! +# execute foundry script to deploy seaport +FOUNDRY_PROFILE=optimized forge script TstorishDeploy --fork-url http://localhost:8545 --slow --skip-simulation --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +# exit anvil +kill $pid +sleep 0.5 +# spin up anvil and load dumped state +anvil --hardfork cancun --load-state $cwd/seaport.dump & +# save pid to kill later +pid=$! +# execute Tstorish test +FOUNDRY_PROFILE=tstorish forge test --fork-url http://localhost:8545 +# get exit code of previous +exit_code=$? +# kill anvil +kill $pid +# exit with exit code of previous +exit $exit_code diff --git a/tstorish/Tstorish.t.sol b/tstorish/Tstorish.t.sol new file mode 100644 index 0000000..f0a4d49 --- /dev/null +++ b/tstorish/Tstorish.t.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.17; + +import { Test } from "forge-std/Test.sol"; +import { + Consideration, + ConsiderationInterface +} from "seaport-core/src/lib/Consideration.sol"; +import { ReentrancyGuard } from "seaport-core/src/lib/ReentrancyGuard.sol"; + +contract TstorishTest is Test { + ReentrancyGuard seaport; + + function setUp() public { + seaport = ReentrancyGuard( + payable( + // second contract deployed by first anvil pk + 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 + ) + ); + } + + function testActivate() public { + // first call updates storage + vm.record(); + seaport.__activateTstore(); + (bytes32[] memory reads, bytes32[] memory writes) = + vm.accesses(address(seaport)); + assertEq(writes.length, 1); + // second call reverts + vm.expectRevert(ReentrancyGuard.TStoreAlreadyActivated.selector); + seaport.__activateTstore(); + } +} From ca5723d151ea35198d43faf4c2c83f01d706552c Mon Sep 17 00:00:00 2001 From: James Wenzel Date: Thu, 29 Feb 2024 15:45:24 -0700 Subject: [PATCH 2/8] update tstorish, fix error --- tstorish.sh | 18 ++++++++++++------ tstorish/Tstorish.t.sol | 10 +++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tstorish.sh b/tstorish.sh index ceaf28b..a675ff7 100644 --- a/tstorish.sh +++ b/tstorish.sh @@ -1,20 +1,26 @@ # remove old dump rm -f seaport.dump # spin up anvil and prepare to dump state -anvil --hardfork shanghai --dump-state $cwd/seaport.dump & +anvil --hardfork shanghai --dump-state ./seaport.dump & # save pid to kill later pid=$! # execute foundry script to deploy seaport -FOUNDRY_PROFILE=optimized forge script TstorishDeploy --fork-url http://localhost:8545 --slow --skip-simulation --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +FOUNDRY_PROFILE=optimized forge script TstorishDeploy --rpc-url http://localhost:8545 --slow --skip-simulation --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +# get code of 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +seaport=$(curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "latest"],"id":1}' -H "Content-Type: application/json" http://localhost:8545) # exit anvil +echo $seaport kill $pid -sleep 0.5 -# spin up anvil and load dumped state -anvil --hardfork cancun --load-state $cwd/seaport.dump & +anvil --hardfork shanghai & +# call setCode on the 0xe7f address with the $seaport var +curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", '"$seaport"'],"id":1}' -H "Content-Type: application/json" http://localhost:8545 +# call setCode on the 0xcafac3dd18ac6c6e92c921884f9e4176737c052c address with 0x3d5c +curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xcafac3dd18ac6c6e92c921884f9e4176737c052c", "0x3d5c"],"id":1}' -H "Content-Type: application/json" http://localhost:8545 # save pid to kill later pid=$! +# mine a block # execute Tstorish test -FOUNDRY_PROFILE=tstorish forge test --fork-url http://localhost:8545 +FOUNDRY_PROFILE=tstorish forge test -vvvv --fork-url http://localhost:8545 # get exit code of previous exit_code=$? # kill anvil diff --git a/tstorish/Tstorish.t.sol b/tstorish/Tstorish.t.sol index f0a4d49..df06090 100644 --- a/tstorish/Tstorish.t.sol +++ b/tstorish/Tstorish.t.sol @@ -2,11 +2,11 @@ pragma solidity ^0.8.17; import { Test } from "forge-std/Test.sol"; + import { - Consideration, - ConsiderationInterface -} from "seaport-core/src/lib/Consideration.sol"; -import { ReentrancyGuard } from "seaport-core/src/lib/ReentrancyGuard.sol"; + ReentrancyGuard, + ReentrancyErrors +} from "seaport-core/src/lib/ReentrancyGuard.sol"; contract TstorishTest is Test { ReentrancyGuard seaport; @@ -28,7 +28,7 @@ contract TstorishTest is Test { vm.accesses(address(seaport)); assertEq(writes.length, 1); // second call reverts - vm.expectRevert(ReentrancyGuard.TStoreAlreadyActivated.selector); + vm.expectRevert(ReentrancyErrors.TStoreAlreadyActivated.selector); seaport.__activateTstore(); } } From a93e42082739b5bb00508efcf394ee1bacfe800e Mon Sep 17 00:00:00 2001 From: James Wenzel Date: Thu, 29 Feb 2024 15:49:45 -0700 Subject: [PATCH 3/8] fix --- foundry.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/foundry.toml b/foundry.toml index 1dfb3ce..5382014 100644 --- a/foundry.toml +++ b/foundry.toml @@ -48,7 +48,6 @@ script = 'reference' # specify something so it doesn't try to compile the files in test/foundry test = 'test/foundry' cache_path = 'reference-cache' -evm_version = 'cancun' [profile.optimized] src = 'src' @@ -87,9 +86,6 @@ test = 'offerers' out = 'offerers-out' script = 'offerers' -[profile.tstorish] -test = 'tstorish' - [fmt] line_length = 80 tab_width = 4 From 1ae21fdf108692cfbfc7dd2a512699023353d2d2 Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Thu, 29 Feb 2024 18:27:11 -0500 Subject: [PATCH 4/8] give anvil a chance to warm up the second time around --- tstorish.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tstorish.sh b/tstorish.sh index a675ff7..8ce751f 100644 --- a/tstorish.sh +++ b/tstorish.sh @@ -12,12 +12,14 @@ seaport=$(curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params": echo $seaport kill $pid anvil --hardfork shanghai & +# save pid to kill later +pid=$! +# wait for anvil to warm up +sleep 5 # call setCode on the 0xe7f address with the $seaport var curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", '"$seaport"'],"id":1}' -H "Content-Type: application/json" http://localhost:8545 # call setCode on the 0xcafac3dd18ac6c6e92c921884f9e4176737c052c address with 0x3d5c curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xcafac3dd18ac6c6e92c921884f9e4176737c052c", "0x3d5c"],"id":1}' -H "Content-Type: application/json" http://localhost:8545 -# save pid to kill later -pid=$! # mine a block # execute Tstorish test FOUNDRY_PROFILE=tstorish forge test -vvvv --fork-url http://localhost:8545 From d45e0022aadd21870e003cde382458594ed450dc Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Thu, 29 Feb 2024 18:40:40 -0500 Subject: [PATCH 5/8] see if this works --- tstorish.sh | 2 -- tstorish/Tstorish.t.sol | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tstorish.sh b/tstorish.sh index 8ce751f..e35dac1 100644 --- a/tstorish.sh +++ b/tstorish.sh @@ -18,8 +18,6 @@ pid=$! sleep 5 # call setCode on the 0xe7f address with the $seaport var curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", '"$seaport"'],"id":1}' -H "Content-Type: application/json" http://localhost:8545 -# call setCode on the 0xcafac3dd18ac6c6e92c921884f9e4176737c052c address with 0x3d5c -curl -X POST --data '{"jsonrpc":"2.0","method":"anvil_setCode","params":["0xcafac3dd18ac6c6e92c921884f9e4176737c052c", "0x3d5c"],"id":1}' -H "Content-Type: application/json" http://localhost:8545 # mine a block # execute Tstorish test FOUNDRY_PROFILE=tstorish forge test -vvvv --fork-url http://localhost:8545 diff --git a/tstorish/Tstorish.t.sol b/tstorish/Tstorish.t.sol index df06090..6eb80f8 100644 --- a/tstorish/Tstorish.t.sol +++ b/tstorish/Tstorish.t.sol @@ -21,6 +21,11 @@ contract TstorishTest is Test { } function testActivate() public { + vm.etch( + 0xcafac3dd18ac6c6e92c921884f9e4176737c052c, + hex"3d5c" + ); + // first call updates storage vm.record(); seaport.__activateTstore(); From 79a3af7a97625eb8595c5ec81dc1e73825545a25 Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Thu, 29 Feb 2024 18:43:00 -0500 Subject: [PATCH 6/8] include tstorish profile --- foundry.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/foundry.toml b/foundry.toml index 5382014..d88e2ca 100644 --- a/foundry.toml +++ b/foundry.toml @@ -86,6 +86,9 @@ test = 'offerers' out = 'offerers-out' script = 'offerers' +[profile.tstorish] +test = 'tstorish' + [fmt] line_length = 80 tab_width = 4 From c6dae78d7cd5b7f50faa94ccfb0760ab2ef27c6e Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Thu, 29 Feb 2024 18:45:59 -0500 Subject: [PATCH 7/8] checksum --- tstorish/Tstorish.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tstorish/Tstorish.t.sol b/tstorish/Tstorish.t.sol index 6eb80f8..ab8220e 100644 --- a/tstorish/Tstorish.t.sol +++ b/tstorish/Tstorish.t.sol @@ -22,7 +22,7 @@ contract TstorishTest is Test { function testActivate() public { vm.etch( - 0xcafac3dd18ac6c6e92c921884f9e4176737c052c, + 0xCafac3dD18aC6c6e92c921884f9E4176737C052c, hex"3d5c" ); From 240e0707adfe667908d450bedac35ad08afee0aa Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Thu, 29 Feb 2024 18:52:32 -0500 Subject: [PATCH 8/8] use jq to parse --- tstorish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tstorish.sh b/tstorish.sh index e35dac1..e0a7ce4 100644 --- a/tstorish.sh +++ b/tstorish.sh @@ -7,7 +7,7 @@ pid=$! # execute foundry script to deploy seaport FOUNDRY_PROFILE=optimized forge script TstorishDeploy --rpc-url http://localhost:8545 --slow --skip-simulation --broadcast --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # get code of 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 -seaport=$(curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "latest"],"id":1}' -H "Content-Type: application/json" http://localhost:8545) +seaport=$(curl -sX POST --data '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", "latest"],"id":1}' -H "Content-Type: application/json" http://localhost:8545 | jq '.result') # exit anvil echo $seaport kill $pid