-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only discover mappings under storage nodes (#78)
Our mapping discovery used to happen at every single potential mapping structure in the tree, but this meant that we would sometimes discover manual structures that look the same as being access to mapping storage slots even when they were not. We are now more restrictive.
- Loading branch information
1 parent
7cd825f
commit 5606c95
Showing
8 changed files
with
167 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
contract BatchEnsLookups { | ||
function resolveAddresses() public pure { | ||
keccak256( | ||
abi.encodePacked( | ||
sha3HexAddress() | ||
) | ||
); | ||
} | ||
|
||
function sha3HexAddress() private pure returns (bytes32 ret) { | ||
assembly { | ||
ret := keccak256(0, 40) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
contract MerkleTree { | ||
function purchaseMerkleAmount() external { | ||
bytes32[] memory proof = new bytes32[](1); | ||
bytes32 computedHash = bytes32(0); | ||
for (uint256 i = 0; i < proof.length; i++) { | ||
computedHash = _efficientHash(proof[i], computedHash); | ||
} | ||
} | ||
|
||
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
mstore(0x00, a) | ||
mstore(0x20, b) | ||
value := keccak256(0x00, 0x40) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//! This module tests the library's analysis capabilities on the local | ||
//! `BatchEnsLookups` contract`. | ||
#![cfg(test)] | ||
|
||
use storage_layout_analyzer::watchdog::LazyWatchdog; | ||
|
||
mod common; | ||
|
||
/// Tests the analyser on the bytecode of the BatchEnsLookups contract | ||
/// found [locally](../asset/BatchEnsLookups.sol). | ||
#[test] | ||
fn correctly_generates_a_layout() -> anyhow::Result<()> { | ||
// Create the analyzer | ||
let bytecode = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063b709959614602d575b600080fd5b60336035565b005b6028600020604051602001604b91815260200190565b60408051601f198184030190525256fea2646970667358221220645e42249fb219b90bda62dd9e9539000ea399d67aa68ba2a3521720a942364964736f6c634300080f0033"; | ||
let analyzer = common::new_analyzer_from_bytecode(bytecode, LazyWatchdog.in_rc())?; | ||
|
||
// Get the final storage layout for the input contract | ||
let layout = analyzer.analyze()?; | ||
|
||
// We should see no slots as this contract never uses storage opcodes. | ||
assert!(layout.slots().is_empty()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//! This module tests the library's analysis capabilities on the local | ||
//! `MerkleTree` contract`. | ||
#![cfg(test)] | ||
|
||
use storage_layout_analyzer::watchdog::LazyWatchdog; | ||
|
||
mod common; | ||
|
||
/// Tests the analyser on the bytecode of the MerkleTree contract | ||
/// found [locally](../asset/MerkleTree.sol). | ||
#[test] | ||
fn correctly_generates_a_layout() -> anyhow::Result<()> { | ||
// Create the analyzer | ||
let bytecode = "0x6080604052348015600f57600080fd5b506004361060285760003560e01c806388572a5c14602d575b600080fd5b60336035565b005b604080516001808252818301909252600091602080830190803683370190505090506000805b8251811015609d57608c838281518110607457607460a2565b60200260200101518360009182526020526040902090565b91508060968160b8565b915050605b565b505050565b634e487b7160e01b600052603260045260246000fd5b60006001820160d757634e487b7160e01b600052601160045260246000fd5b506001019056fea26469706673582212204208c6f43bc343f0a115564be7291cf69f0cd24036b2d9d1701db9b25bf6cb0264736f6c634300080f0033"; | ||
let analyzer = common::new_analyzer_from_bytecode(bytecode, LazyWatchdog.in_rc())?; | ||
|
||
// Get the final storage layout for the input contract | ||
let layout = analyzer.analyze()?; | ||
|
||
// We should see no slots as this contract never uses storage opcodes. | ||
assert!(layout.slots().is_empty()); | ||
|
||
Ok(()) | ||
} |