Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertion mode: fail and save reproducer if custom error is returned #460

Open
bsamuels453 opened this issue Aug 27, 2024 · 1 comment
Open

Comments

@bsamuels453
Copy link

Right now we allow the user to configure what kinds of reverts will make Medusa identify a counterexample.

We should have support for custom errors as well, especially for when debugging reversion statistics.

@0xalpharush
Copy link
Contributor

We need to update the assertion test config to allow users to supply error selectors and check for them in the assertion test case provider here

// Try to unpack a custom Solidity error from the return values.
matchedCustomError, unpackedCustomErrorArgs := abiutils.GetSolidityCustomRevertError(callFrame.CodeContractAbi, callFrame.ReturnError, callFrame.ReturnData)

methodId := contracts.GetContractMethodID(lastCall.Contract, lastCallMethod)
// Check if we encountered an enabled panic code.
// Try to unpack our error and return data for a panic code and verify that that panic code should be treated as a failing case.
// Solidity >0.8.0 introduced asserts failing as reverts but with special return data. But we indicate we also
// want to be backwards compatible with older Solidity which simply hit an invalid opcode and did not actually
// have a panic code.
lastExecutionResult := lastCall.ChainReference.MessageResults().ExecutionResult
panicCode := abiutils.GetSolidityPanicCode(lastExecutionResult.Err, lastExecutionResult.ReturnData, true)
failure := false
if panicCode != nil {
failure = encounteredAssertionFailure(panicCode.Uint64(), t.fuzzer.config.Fuzzing.Testing.AssertionTesting.PanicCodeConfig)

Until it is implemented, one can write a try-catch on the error selector and assert false

@0xalpharush 0xalpharush changed the title Have Medusa explode on custom errors assertion mode: fail and save reproducer if custom error is returned Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants