echidna icon indicating copy to clipboard operation
echidna copied to clipboard

Decode solidity panics e.g. aritmetic overflow

Open 0xalpharush opened this issue 2 years ago • 1 comments

Some solidity panics could be decoded and provided a human-readable error message . For example, mError revert 0x4e487b710000000000000000000000000000000000000000000000000000000000000011 becomes mError revert reason: aritmetic overflow

Idk haskell but this code seems relevant: https://github.com/crytic/echidna/blob/79af6a63e65ae491ddad0a3eae05d28685f53042/lib/Echidna/Exec.hs#L35-L43

Reference list of panics: https://soliditydeveloper.com/solidity-0.8

0xalpharush avatar May 14 '22 17:05 0xalpharush

could you post the whole error message? I'm sort of unfamiliar with the codebase so having some trouble finding the source of it @0xalpharush

AndyBarnard avatar Jul 18 '22 17:07 AndyBarnard

@ggrieco-tob I think all that needs to happen is to add a string to this Panic which indicates what the error code maps back to e.g. arithmetic overflow https://github.com/crytic/echidna/blob/8a265c2e3ed2badc1354fd639641438275dfe144/lib/Echidna/Events.hs#L77

0xalpharush avatar Jan 03 '23 14:01 0xalpharush

@0xalpharush could you include a minimal example of how to reproduce?

arcz avatar Jan 03 '23 15:01 arcz

test.sol


pragma solidity ^0.8.0;
contract Test {

	function test(uint a) external {
		uint x = type(uint).max + a;
	}
}
contract Tester {
	Test target;
	constructor() {
		target = new Test();
	}
	function x() external {
		try target.test(1) {
		} catch {
			assert(false);
		}
	}
}

echidna-test test.sol --contract Tester --test-mode assertion

Analyzing contract: /Users/alpharush/echidna/test.sol:Tester
x(): failed!💥  
  Call sequence:
    x()

Event sequence: Panic(1), merror Revert 0x4e487b710000000000000000000000000000000000000000000000000000000000000011 from: Test
AssertionFailed(..):  fuzzing (29284/50000)

0xalpharush avatar Jan 03 '23 15:01 0xalpharush

we recently updated hevm and now this error is printed slightly better (from the current master):

x(): failed!💥
  Call sequence:
    x()

Event sequence: Panic(1), merror Revert Panic(17)
AssertionFailed(..):  passed! 🎉

Unique instructions: 340
Unique codehashes: 2
Corpus size: 2
Seed: 5902941968390972108

arcz avatar Jan 04 '23 17:01 arcz

It would still be nice to decode 17 as arithmetic overflow instead of having to google around for what Panic(17) is

0xalpharush avatar Feb 14 '23 16:02 0xalpharush