-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
evm: Echidna stateful fuzzing for NttManager (#393)
* Initial fuzzing harness * forge install: solidity-bytes-utils v0.8.2 * More fuzz test coverage * More fuzz tests * Fix ordering of checks * Fuzz transfer qol entrypoint * Refactor transfer fuzzing with fewer assumptions * More fuzzing progress for arbitrary instructions * More fuzzing * Fuzz cancelling * Get fuzz suite working again * Fix recent changes and add to CI * Fix action
- Loading branch information
Showing
8 changed files
with
961 additions
and
2 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
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,14 @@ | ||
testMode: "assertion" | ||
|
||
deployContracts: [ | ||
["0x1f1", "TransceiverStructs"], | ||
] | ||
|
||
cryticArgs: ["--compile-libraries=(TransceiverStructs,0x1f1)"] | ||
|
||
# Default is 0x6000, but we need to increase this as not compiled via ir | ||
codeSize: 0x8000 | ||
|
||
stopOnFail: false | ||
|
||
testLimit: 100000 |
Large diffs are not rendered by default.
Oops, something went wrong.
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,70 @@ | ||
pragma solidity >=0.8.8 <0.9.0; | ||
|
||
import "./IHevm.sol"; | ||
|
||
abstract contract FuzzingHelpers { | ||
address constant HEVM_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D; | ||
IHevm hevm = IHevm(HEVM_ADDRESS); | ||
|
||
|
||
event LogAddress(address); | ||
event LogUint256(uint256); | ||
event LogString(string); | ||
event AssertFail(string); | ||
|
||
// We need this to receive refunds for quotes | ||
receive() external payable {} | ||
|
||
function clampBetween(uint256 value, uint256 low, uint256 high) internal returns (uint256){ | ||
if (value < low || value > high) { | ||
uint ans = low + (value % (high - low + 1)); | ||
return ans; | ||
} | ||
return value; | ||
} | ||
|
||
function extractErrorSelector( | ||
bytes memory revertData | ||
) internal returns (uint256) { | ||
if (revertData.length < 4) { | ||
emit LogString("Return data too short."); | ||
return 0; | ||
} | ||
|
||
uint256 errorSelector = uint256( | ||
(uint256(uint8(revertData[0])) << 24) | | ||
(uint256(uint8(revertData[1])) << 16) | | ||
(uint256(uint8(revertData[2])) << 8) | | ||
uint256(uint8(revertData[3])) | ||
); | ||
|
||
return errorSelector; | ||
} | ||
|
||
function extractErrorString(bytes memory revertData) internal returns (bytes32) { | ||
if (revertData.length < 68) revert(); | ||
assembly { | ||
revertData := add(revertData, 0x04) | ||
} | ||
return keccak256(abi.encodePacked(abi.decode(revertData, (string)))); | ||
} | ||
|
||
function selectorToUint(bytes4 selector) internal returns (uint256) { | ||
return uint256(uint32(selector)); | ||
} | ||
|
||
function assertWithMsg(bool b, string memory reason) internal { | ||
if (!b) { | ||
emit AssertFail(reason); | ||
assert(false); | ||
} | ||
} | ||
|
||
function minUint8(uint8 a, uint8 b) internal returns (uint8) { | ||
return a < b ? a : b; | ||
} | ||
|
||
function minUint256(uint256 a, uint256 b) internal returns (uint256) { | ||
return a < b ? a : b; | ||
} | ||
} |
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,7 @@ | ||
pragma solidity >=0.8.8 <0.9.0; | ||
|
||
interface IHevm { | ||
function prank(address) external; | ||
|
||
function warp(uint256 newTimestamp) external; | ||
} |
Submodule solidity-bytes-utils
added at
e0115c