Skip to content

Commit 089fd71

Browse files
GiovanniTorrisi-ChainSecurityStefan Effenberger
andauthored
Include empty mapping keys (#85)
* Delete DVF file regardless of test outcome * Debug issue and fix * Add tests for empty key in string and byte mapping * Update decode test data * Clean up * Fix decodign test * updated test case dvfs * updated e2e tests to use different ports in all cases --------- Co-authored-by: Stefan Effenberger <stefan.effenberger@chainsecurity.com>
1 parent b90c78f commit 089fd71

11 files changed

Lines changed: 66 additions & 10 deletions

lib/state/contract_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<'a> ContractState<'a> {
366366
)
367367
);
368368
// Look for mapping usages
369-
if length_in_bytes > U256::from(32_u64)
369+
if length_in_bytes >= U256::from(32_u64)
370370
&& length_in_bytes < U256::from(usize::MAX / 2)
371371
{
372372
let usize_str_length =

lib/web3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,7 @@ impl StorageSnapshot {
20472047
}
20482048
}
20492049

2050-
// Collect all storage slots that have not previously been queried
2050+
// Collect all storage slots that have not been queried previously
20512051
pub fn get_unused_nonzero_storage_slots(&self) -> Vec<UnusedStoragePart> {
20522052
let mut unused_storage_parts: Vec<UnusedStoragePart> = vec![];
20532053

tests/Contracts/src/BytesMapping.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ contract BytesMapping {
1212
x[bytes("Hello this is a test")] = 5;
1313
x[bytes("A veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryvery long string")] = 42;
1414
b = bytes("Just some normal bytes.");
15+
x[bytes("")] = 42;
1516
}
1617

1718
function f() external {

tests/Contracts/src/StringMapping.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ contract StringMapping {
1212
x["A veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryvery long string"] = 42;
1313
y["abc"] = "a short string";
1414
y["a"] = "A veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryvery long string.";
15+
x[""] = 42;
1516
emit SomeE("EventData", 1000);
1617
}
1718

tests/expected_dvfs/Deploy_0.dvf.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
"value_hint": "4a75737420736f6d65206e6f726d616c2062797465732e",
2222
"comparison_operator": "Equal"
2323
},
24+
{
25+
"slot": "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
26+
"offset": 0,
27+
"var_name": "x[0x]",
28+
"var_type": "t_uint256",
29+
"value": "0x000000000000000000000000000000000000000000000000000000000000002a",
30+
"value_hint": "42",
31+
"comparison_operator": "Equal"
32+
},
2433
{
2534
"slot": "0x4a8918e67ba0b26637797e1472ee3d675d66efda39253f7139f8eabc58b20ffb",
2635
"offset": 0,

tests/expected_dvfs/Deploy_0_b1.dvf.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"version": "0.9.1",
3-
"id": "0x4be820f0e3915aa5f0cc36ac62260161931c5873c01ed998e18c5f62fbcd2ed0",
3+
"id": "0x25996dc252a0472b41456da06f497121e6d712e89eb3d46b84765f3759640a5b",
44
"contract_name": "BytesMapping",
55
"address": "0x5fbdb2315678afecb367f032d93f642f64180aa3",
6-
"chain_id": 1337,
6+
"chain_id": 31337,
77
"deployment_block_num": 2,
88
"init_block_num": 2,
9-
"deployment_tx": "0x11819f70620f7d3a7a69eee5e9ad55cedec78c9fc5a83ab743fdec42a77ab504",
9+
"deployment_tx": "0xa2179eff8c7827da8b42a4b2a304d7449f49a8923818b21e553fdb7c8b3357cb",
1010
"codehash": "0x3867a08d0f6ad7f18a522cb18383fa3eb688bbde257d84652a614fda9167b190",
1111
"insecure": false,
1212
"immutables": [],
@@ -21,6 +21,15 @@
2121
"value_hint": "4a75737420736f6d65206e6f726d616c2062797465732e",
2222
"comparison_operator": "Equal"
2323
},
24+
{
25+
"slot": "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
26+
"offset": 0,
27+
"var_name": "x[0x]",
28+
"var_type": "t_uint256",
29+
"value": "0x000000000000000000000000000000000000000000000000000000000000002a",
30+
"value_hint": "42",
31+
"comparison_operator": "Equal"
32+
},
2433
{
2534
"slot": "0x4a8918e67ba0b26637797e1472ee3d675d66efda39253f7139f8eabc58b20ffb",
2635
"offset": 0,

tests/expected_dvfs/Deploy_0_updated.dvf.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
"value_hint": "4a75737420736f6d65206e6f726d616c2062797465732e",
2121
"comparison_operator": "Equal"
2222
},
23+
{
24+
"slot": "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
25+
"offset": 0,
26+
"var_name": "x[0x]",
27+
"var_type": "t_uint256",
28+
"value": "0x000000000000000000000000000000000000000000000000000000000000002a",
29+
"value_hint": "42",
30+
"comparison_operator": "Equal"
31+
},
2332
{
2433
"slot": "0x4a8918e67ba0b26637797e1472ee3d675d66efda39253f7139f8eabc58b20ffb",
2534
"offset": 0,

tests/expected_dvfs/Deploy_1.dvf.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
"immutables": [],
1313
"constructor_args": [],
1414
"critical_storage_variables": [
15+
{
16+
"slot": "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
17+
"offset": 0,
18+
"var_name": "x[]",
19+
"var_type": "t_uint256",
20+
"value": "0x000000000000000000000000000000000000000000000000000000000000002a",
21+
"value_hint": "42",
22+
"comparison_operator": "Equal"
23+
},
1524
{
1625
"slot": "0x2fccf76901d0aa8dbb54cf0f8d3d8db6b27e630b57020bc913d21efd33831cbc",
1726
"offset": 0,

tests/expected_dvfs/Deploy_1_b1.dvf.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
{
22
"version": "0.9.1",
3-
"id": "0xddec5fab35250ee9bb557688e3df2c8ddca9c277e454546e5358aa48a1dfd25c",
3+
"id": "0x62fabab8f05c6d0fd7dfe72a984b8a9260ca936be36a3a203e40d8143d4240f0",
44
"contract_name": "StringMapping",
55
"address": "0x5fbdb2315678afecb367f032d93f642f64180aa3",
6-
"chain_id": 1337,
6+
"chain_id": 31337,
77
"deployment_block_num": 2,
88
"init_block_num": 2,
9-
"deployment_tx": "0xbd44492ce35b11b438be83b11fef8e1f18f3dd1f847c791083f3659d2a66885c",
9+
"deployment_tx": "0x7a0aa5e701e0c9d0e249bf3ae61a1723583ab168eec26b652e6d7331ea3980fb",
1010
"codehash": "0x2feab59f98325c0ad112156daca7c79dc9e9e17c16be3e374874788370b91e02",
1111
"insecure": false,
1212
"immutables": [],
1313
"constructor_args": [],
1414
"critical_storage_variables": [
15+
{
16+
"slot": "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
17+
"offset": 0,
18+
"var_name": "x[]",
19+
"var_type": "t_uint256",
20+
"value": "0x000000000000000000000000000000000000000000000000000000000000002a",
21+
"value_hint": "42",
22+
"comparison_operator": "Equal"
23+
},
1524
{
1625
"slot": "0x2fccf76901d0aa8dbb54cf0f8d3d8db6b27e630b57020bc913d21efd33831cbc",
1726
"offset": 0,

tests/expected_dvfs/Deploy_1_updated.dvf.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
"immutables": [],
1212
"constructor_args": [],
1313
"critical_storage_variables": [
14+
{
15+
"slot": "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
16+
"offset": 0,
17+
"var_name": "x[]",
18+
"var_type": "t_uint256",
19+
"value": "0x000000000000000000000000000000000000000000000000000000000000002a",
20+
"value_hint": "42",
21+
"comparison_operator": "Equal"
22+
},
1423
{
1524
"slot": "0x2fccf76901d0aa8dbb54cf0f8d3d8db6b27e630b57020bc913d21efd33831cbc",
1625
"offset": 0,

0 commit comments

Comments
 (0)