Skip to content

Commit 8e84670

Browse files
authored
Merge pull request OffchainLabs#3233 from OffchainLabs/relyt-live-tracing
Gas Dimension Trace Tests
2 parents 517a697 + 7d78cc8 commit 8e84670

File tree

121 files changed

+12041
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+12041
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules
1010
.DS_Store
1111
.idea
1212
.vscode
13+
.cursor
1314
cmd/node/data
1415
cmd/node/node
1516
solgen/go/

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@
4141
[submodule "contracts-legacy"]
4242
path = contracts-legacy
4343
url = https://github.com/OffchainLabs/nitro-contracts.git
44+
[submodule "contracts-local/lib/openzeppelin-contracts"]
45+
path = contracts-local/lib/openzeppelin-contracts
46+
url = https://github.com/OpenZeppelin/openzeppelin-contracts
47+
[submodule "contracts-local/src/precompiles"]
48+
path = contracts-local/src/precompiles
49+
url = https://github.com/OffchainLabs/nitro-precompile-interfaces.git

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ test-go-redis: test-go-deps
243243
gotestsum --format short-verbose --no-color=false -- -p 1 -run TestRedis ./system_tests/... ./arbnode/... -- --test_redis=redis://localhost:6379/0
244244
@printf $(done)
245245

246+
.PHONY: test-go-gas-dimensions
247+
test-go-gas-dimensions: test-go-deps
248+
gotestsum --format short-verbose --no-color=false -- -timeout 120m ./system_tests/... -run "TestDim(Log|TxOp)" -tags gasdimensionstest
249+
@printf $(done)
250+
246251
.PHONY: test-gen-proofs
247252
test-gen-proofs: \
248253
$(arbitrator_test_wasms) \
@@ -291,6 +296,7 @@ clean:
291296
rm -rf brotli/buildfiles
292297
@rm -rf contracts/build contracts/cache solgen/go/
293298
@rm -rf contracts-legacy/build contracts-legacy/cache
299+
@rm -rf contracts-local/out contracts-local/forge-cache
294300
@rm -f .make/*
295301

296302
.PHONY: docker
@@ -595,18 +601,20 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(prover_bin)
595601
go run solgen/gen.go
596602
@touch $@
597603

598-
.make/solidity: $(DEP_PREDICATE) safe-smart-account/contracts/*/*.sol safe-smart-account/contracts/*.sol contracts/src/*/*.sol contracts-legacy/src/*/*.sol .make/yarndeps $(ORDER_ONLY_PREDICATE) .make
604+
.make/solidity: $(DEP_PREDICATE) safe-smart-account/contracts/*/*.sol safe-smart-account/contracts/*.sol contracts/src/*/*.sol contracts-legacy/src/*/*.sol contracts-local/src/*/*.sol contracts-local/gas-dimensions/src/*.sol .make/yarndeps $(ORDER_ONLY_PREDICATE) .make
599605
yarn --cwd safe-smart-account build
600606
yarn --cwd contracts build
601607
yarn --cwd contracts build:forge:yul
602608
yarn --cwd contracts-legacy build
603609
yarn --cwd contracts-legacy build:forge:yul
610+
make -C contracts-local build
604611
@touch $@
605612

606613
.make/yarndeps: $(DEP_PREDICATE) */package.json */yarn.lock $(ORDER_ONLY_PREDICATE) .make
607614
yarn --cwd safe-smart-account install
608615
yarn --cwd contracts install
609616
yarn --cwd contracts-legacy install
617+
make -C contracts-local install
610618
@touch $@
611619

612620
.make/cbrotli-lib: $(DEP_PREDICATE) $(ORDER_ONLY_PREDICATE) .make

contracts-local/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build/
2+
cache/
3+
node_modules/
4+
forge-cache/
5+
out/
6+
.env
7+
.DS_Store
8+
lcov.info
9+
broadcast/

contracts-local/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.PHONY: build build-forge build-forge-sol build-forge-gas-dimensions build-forge-gas-dimensions-yul
2+
3+
install:
4+
forge install
5+
6+
build: build-forge
7+
8+
build-forge: build-forge-sol build-forge-gas-dimensions build-forge-gas-dimensions-yul
9+
10+
build-forge-sol:
11+
FOUNDRY_PROFILE=default forge build --skip *.yul --skip src/mocks/HostioTest.sol --skip src/mocks/ArbOS11To32UpgradeTest.sol && \
12+
FOUNDRY_PROFILE=solc824 forge build src/mocks/HostioTest.sol src/mocks/ArbOS11To32UpgradeTest.sol
13+
14+
build-forge-gas-dimensions:
15+
FOUNDRY_PROFILE=gas-dimensions forge build
16+
17+
build-forge-gas-dimensions-yul:
18+
FOUNDRY_PROFILE=gas-dimensions-yul forge build --skip *.sol

contracts-local/foundry.toml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[profile.default]
2+
src = 'src'
3+
out = 'out/src'
4+
libs = ['node_modules', 'lib']
5+
test = 'test'
6+
cache_path = 'forge-cache/sol'
7+
via_ir = false
8+
remappings = ['ds-test/=lib/forge-std/lib/ds-test/src/',
9+
'forge-std/=lib/forge-std/src/',
10+
'openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/']
11+
fs_permissions = [{ access = "read", path = "./"}]
12+
solc = '0.8.17'
13+
optimizer = true
14+
optimizer_runs = 2000
15+
evm_version = 'paris'
16+
17+
[profile.solc824]
18+
src = 'src'
19+
out = 'out/src'
20+
libs = ['node_modules', 'lib']
21+
test = 'test'
22+
cache_path = 'forge-cache/sol'
23+
via_ir = false
24+
remappings = ['ds-test/=lib/forge-std/lib/ds-test/src/',
25+
'forge-std/=lib/forge-std/src/',
26+
'openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/']
27+
fs_permissions = [{ access = "read", path = "./"}]
28+
solc = '0.8.24'
29+
optimizer = true
30+
optimizer_runs = 100
31+
evm_version = 'cancun'
32+
33+
[profile.gas-dimensions]
34+
src = 'gas-dimensions/src'
35+
test = 'gas-dimensions/test'
36+
script = 'gas-dimeinsions/script'
37+
out = 'out/gas-dimensions'
38+
libs = ['lib']
39+
cache_path = 'forge-cache/gas-dimensions'
40+
optimizer = false
41+
yul_optimizer = false
42+
via_ir = false
43+
evm_version = 'cancun'
44+
remappings = ['ds-test/=lib/forge-std/lib/ds-test/src/',
45+
'forge-std/=lib/forge-std/src/']
46+
fs_permissions = [{ access = "read", path = "./"}]
47+
include_paths = ['gas-dimensions/src/', 'gas-dimensions/scripts']
48+
auto_detect_remappings = false
49+
solc = '0.8.30'
50+
51+
[profile.gas-dimensions-yul]
52+
src = 'gas-dimensions/yul'
53+
out = 'out/gas-dimensions-yul'
54+
libs = []
55+
cache_path = 'forge-cache/gas-dimensions-yul'
56+
remappings = []
57+
auto_detect_remappings = false
58+
59+
[fmt]
60+
line_length = 100
61+
tab_width = 4
62+
bracket_spacing = false
63+
int_types = "long"
64+
multiline_func_header = "params_first"
65+
quote_style = "double"
66+
number_underscore = "preserve"
67+
hex_underscore = "remove"
68+
single_line_statement_blocks = "preserve"
69+
override_spacing = false
70+
wrap_comments = false
71+
ignore = []
72+
contract_new_lines = false
73+
sort_imports = false
74+
75+
[fuzz]
76+
runs = 1000
77+
78+
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Gas Dimension Test Contracts
2+
3+
This folder contains smart contracts that force various types of opcodes to run in different configurations. This is used to test gas accounting across multiple gas dimensions, e.g. computation, state read/write, storage growth, etc.
4+
5+
# Scripts for Debugging
6+
7+
The scripts for running the contracts are intended to be used with forge script, e.g.
8+
9+
```bash
10+
forge script gas-dimensions/scripts/Sstore.s.sol -vvvvv --private-key "nitro.dev.node.private.key.here" --slow --broadcast --rpc-url http://127.0.0.1:8547 --priority-gas-price "1000000000" --with-gas-price "2000000000" -g "10000" --chain-id "412346"
11+
```
12+
13+
These scripts can be helpful when manually debugging the code in `gas-dimensions/src/` against a local dev node.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025, Offchain Labs, Inc.
2+
// For license information, see:
3+
// https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md
4+
// SPDX-License-Identifier: BUSL-1.1
5+
6+
pragma solidity ^0.8.13;
7+
8+
import {Script, VmSafe, console} from "forge-std/Script.sol";
9+
import {Balance} from "../src//Balance.sol";
10+
11+
contract BalanceScript is Script {
12+
function setUp() public {}
13+
14+
function run() public {
15+
vm.startBroadcast(address(0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E));
16+
payable(address(0xdeadbeef)).transfer(1000000000000000000);
17+
Balance balance = new Balance();
18+
balance.callBalanceCold();
19+
balance.callBalanceWarm();
20+
vm.stopBroadcast();
21+
}
22+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2025, Offchain Labs, Inc.
2+
// For license information, see:
3+
// https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md
4+
// SPDX-License-Identifier: BUSL-1.1
5+
6+
pragma solidity ^0.8.13;
7+
8+
import {Script, VmSafe, console} from "forge-std/Script.sol";
9+
import {Caller, Callee} from "../src/Call.sol";
10+
11+
contract CallTestScript is Script {
12+
function setUp() public {}
13+
14+
function run() public {
15+
vm.startBroadcast(address(0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E));
16+
17+
Callee callee1 = new Callee();
18+
Callee callee2 = new Callee();
19+
Callee callee3 = new Callee();
20+
Callee callee4 = new Callee();
21+
Caller caller = new Caller();
22+
payable(caller).transfer(1 ether);
23+
24+
// five axes:
25+
// warm / cold
26+
// target has code / target has no code
27+
// target funded / not funded
28+
// sending money with the call / no transfer
29+
// memory expansion / memory unchanged
30+
31+
// 1. warm + target has code + target not funded + zero value + memory unchanged
32+
caller.warmNoTransferMemUnchanged(address(callee1));
33+
// 2. warm + target has code + target not funded + positive value + memory unchanged
34+
caller.warmPayableMemUnchanged(address(callee2));
35+
// 3. warm + target has no code + zero value
36+
caller.warmNoTransferMemExpansion(address(0xbeef));
37+
// 4. warm + target has no code + positive value
38+
caller.warmPayableMemExpansion(address(0xbeef));
39+
// 5. cold + target has code + zero value
40+
caller.coldNoTransferMemUnchanged(address(callee3));
41+
// 6. cold + target has code + positive value
42+
caller.coldPayableMemUnchanged(address(callee4));
43+
// 7. cold + target has no code + zero value
44+
caller.coldNoTransferMemExpansion(address(0xbeef));
45+
// 8. cold + target has no code + positive value
46+
caller.coldPayableMemExpansion(address(0xbeef));
47+
48+
vm.stopBroadcast();
49+
}
50+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2025, Offchain Labs, Inc.
2+
// For license information, see:
3+
// https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md
4+
// SPDX-License-Identifier: BUSL-1.1
5+
6+
pragma solidity ^0.8.13;
7+
8+
import {Script, VmSafe, console} from "forge-std/Script.sol";
9+
import {Counter} from "../src/Counter.sol";
10+
import {Cloner} from "../src/Cloner.sol";
11+
12+
contract CounterScript is Script {
13+
function setUp() public {}
14+
15+
function run() public {
16+
vm.startBroadcast(address(0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E));
17+
Counter counterImpl = new Counter();
18+
console.log("counterImpl", address(counterImpl));
19+
Cloner cloner = new Cloner(address(counterImpl));
20+
console.log("cloner", address(cloner));
21+
22+
address counter1Addr = cloner.createCounter();
23+
address counter2Addr = cloner.create2Counter(bytes32(uint256(1)));
24+
25+
console.log("counter1 addr", counter1Addr);
26+
console.log("counter2 addr", counter2Addr);
27+
28+
Counter counter1 = Counter(counter1Addr);
29+
counter1.setNumber(1);
30+
console.log("counter1 set number", counter1.number(), " on ", counter1Addr);
31+
counter1.increment();
32+
console.log("counter1 incremented", counter1.number(), " on ", counter1Addr);
33+
vm.stopBroadcast();
34+
}
35+
}

0 commit comments

Comments
 (0)