Skip to content

Commit e4c43d6

Browse files
danceratopzleolara
andauthored
fix(tests) fix ported quadratic complexity tests (#2784)
* fix(tests): correct stQuadraticComplexityTest post-state expectations Three of these tests embed the runtime caller address directly in their target contract's bytecode. The expected post hashed in a literal hex string of the bytecode that hardcoded the pre-dynamic EOA address (e.g. \`0xd9b97c712eb…\`), so once \`pre.fund_eoa()\` started picking addresses dynamically the deployed code no longer matched the expected hex. Hoist the bytecode into a \`target_code\` variable used both at deploy time and as the expected \`code\`, so the address baked in via \`Op.CALL(address=addr, …)\` is whatever \`addr\` resolves to at fill time: - \`test_call50000\` - \`test_callcode50000\` - \`test_call20_kbytes_contract50_2\` \`test_quadratic_complexity_solidity_call_data_copy\` had a different drift: its post asserted empty storage on \`contract_0\`, but the success path (\`g=1\`, 250M gas) commits \`SSTORE(0, 50000)\` before entering the loop. Make the expected storage \`g\`-conditional so \`g=0\` (OOG) keeps an empty \`storage\` and \`g=1\` records slot 0. * chore(tests): remove unrequired `# noqa: F841` * chore(ported_static): mark stQuadraticComplexityTest fixes as @manually-enhanced The four post-state corrections cherry-picked from PR #2784 should not be overwritten the next time `tests/ported_static/` is regenerated by `scripts/filler_to_python`. Add the `@manually-enhanced` marker to each docstring so the regenerator skips them. --------- Co-authored-by: Leo Lara <leo@leolara.me>
1 parent 8a052aa commit e4c43d6

4 files changed

Lines changed: 44 additions & 28 deletions

File tree

tests/ported_static/stQuadraticComplexityTest/test_call20_kbytes_contract50_2.py

Lines changed: 11 additions & 7 deletions
Large diffs are not rendered by default.

tests/ported_static/stQuadraticComplexityTest/test_call50000.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
Ported from:
55
state_tests/stQuadraticComplexityTest/Call50000Filler.json
6+
7+
@manually-enhanced: Do not overwrite. Post-state expectations corrected
8+
manually (see PR #2784).
69
"""
710

811
import pytest
@@ -70,11 +73,11 @@ def test_call50000(
7073
gas_limit=860000000,
7174
)
7275

73-
addr = pre.fund_eoa(amount=7000) # noqa: F841
76+
addr = pre.fund_eoa(amount=7000)
7477
# Source: lll
7578
# { (def 'i 0x80) (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALL 1600 <eoa:0xaaaf5374fce5edbc8e2a8697c15331677e6ebf0b> 1 0 50000 0 0) ) [[ 1 ]] @i} # noqa: E501
76-
target = pre.deploy_contract( # noqa: F841
77-
code=Op.JUMPDEST
79+
target_code = (
80+
Op.JUMPDEST
7881
+ Op.JUMPI(
7982
pc=0x3F, condition=Op.ISZERO(Op.LT(Op.MLOAD(offset=0x80), 0xC350))
8083
)
@@ -94,7 +97,10 @@ def test_call50000(
9497
+ Op.JUMP(pc=0x0)
9598
+ Op.JUMPDEST
9699
+ Op.SSTORE(key=0x1, value=Op.MLOAD(offset=0x80))
97-
+ Op.STOP,
100+
+ Op.STOP
101+
)
102+
target = pre.deploy_contract(
103+
code=target_code,
98104
balance=0xFFFFFFFFFFFFF,
99105
nonce=0,
100106
)
@@ -108,9 +114,7 @@ def test_call50000(
108114
addr: Account(storage={}, code=b"", nonce=0),
109115
target: Account(
110116
storage={},
111-
code=bytes.fromhex(
112-
"5b61c3506080511015603f576000600061c3506000600173d9b97c712ebce43f3c19179bbef44b550f9e8bc0610640f16000556001608051016080526000565b60805160015500" # noqa: E501
113-
),
117+
code=bytes(target_code),
114118
nonce=0,
115119
),
116120
},
@@ -123,9 +127,7 @@ def test_call50000(
123127
addr: Account(storage={}, code=b"", nonce=0),
124128
target: Account(
125129
storage={},
126-
code=bytes.fromhex(
127-
"5b61c3506080511015603f576000600061c3506000600173d9b97c712ebce43f3c19179bbef44b550f9e8bc0610640f16000556001608051016080526000565b60805160015500" # noqa: E501
128-
),
130+
code=bytes(target_code),
129131
nonce=0,
130132
),
131133
},

tests/ported_static/stQuadraticComplexityTest/test_callcode50000.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
Ported from:
55
state_tests/stQuadraticComplexityTest/Callcode50000Filler.json
6+
7+
@manually-enhanced: Do not overwrite. Post-state expectations corrected
8+
manually (see PR #2784).
69
"""
710

811
import pytest
@@ -70,11 +73,11 @@ def test_callcode50000(
7073
gas_limit=8600000000,
7174
)
7275

73-
addr = pre.fund_eoa(amount=7000) # noqa: F841
76+
addr = pre.fund_eoa(amount=7000)
7477
# Source: lll
7578
# { (def 'i 0x80) (for {} (< @i 50000) [i](+ @i 1) [[ 0 ]] (CALLCODE 1600 <eoa:0xaaaf5374fce5edbc8e2a8697c15331677e6ebf0b> 1 0 50000 0 0) ) [[ 1 ]] @i} # noqa: E501
76-
target = pre.deploy_contract( # noqa: F841
77-
code=Op.JUMPDEST
79+
target_code = (
80+
Op.JUMPDEST
7881
+ Op.JUMPI(
7982
pc=0x3F, condition=Op.ISZERO(Op.LT(Op.MLOAD(offset=0x80), 0xC350))
8083
)
@@ -94,7 +97,10 @@ def test_callcode50000(
9497
+ Op.JUMP(pc=0x0)
9598
+ Op.JUMPDEST
9699
+ Op.SSTORE(key=0x1, value=Op.MLOAD(offset=0x80))
97-
+ Op.STOP,
100+
+ Op.STOP
101+
)
102+
target = pre.deploy_contract(
103+
code=target_code,
98104
balance=0xFFFFFFFFFFFFF,
99105
nonce=0,
100106
)
@@ -108,9 +114,7 @@ def test_callcode50000(
108114
addr: Account(storage={}, code=b"", nonce=0),
109115
target: Account(
110116
storage={},
111-
code=bytes.fromhex(
112-
"5b61c3506080511015603f576000600061c3506000600173d9b97c712ebce43f3c19179bbef44b550f9e8bc0610640f26000556001608051016080526000565b60805160015500" # noqa: E501
113-
),
117+
code=bytes(target_code),
114118
nonce=0,
115119
),
116120
},
@@ -123,9 +127,7 @@ def test_callcode50000(
123127
addr: Account(storage={}, code=b"", nonce=0),
124128
target: Account(
125129
storage={},
126-
code=bytes.fromhex(
127-
"5b61c3506080511015603f576000600061c3506000600173d9b97c712ebce43f3c19179bbef44b550f9e8bc0610640f26000556001608051016080526000565b60805160015500" # noqa: E501
128-
),
130+
code=bytes(target_code),
129131
nonce=0,
130132
),
131133
},

tests/ported_static/stQuadraticComplexityTest/test_quadratic_complexity_solidity_call_data_copy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
Ported from:
55
state_tests/stQuadraticComplexityTest/QuadraticComplexitySolidity_CallDataCopyFiller.json
6+
7+
@manually-enhanced: Do not overwrite. Post-state expectations corrected
8+
manually (see PR #2784).
69
"""
710

811
import pytest
@@ -152,9 +155,14 @@ def test_quadratic_complexity_solidity_call_data_copy(
152155
value=tx_value[v],
153156
)
154157

158+
# With `g=1` the tx completes the inner CALL loop and the
159+
# leading `SSTORE(0, 50000)` (the loop-counter snapshot taken
160+
# before entering the loop body) commits. With `g=0` the tx
161+
# OOGs and rolls everything back, leaving storage empty.
162+
contract_0_storage = {0: 0xC350} if g == 1 else {}
155163
post = {
156164
contract_0: Account(
157-
storage={},
165+
storage=contract_0_storage,
158166
code=bytes.fromhex(
159167
"60003560e060020a9004806361a4770614601557005b601e6004356024565b60006000f35b60008160008190555073b94f5374fce5edbc8e2a8697c15331677e6ebf0b90505b600082131560bf5780600160a060020a03166000600060007f6a7573740000000000000000000000000000000000000000000000000000000081526004017f63616c6c000000000000000000000000000000000000000000000000000000008152602001600060008560155a03f150506001820391506045565b505056" # noqa: E501
160168
),

0 commit comments

Comments
 (0)