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

Execution traces for call sequences failing tests #105

Merged
merged 31 commits into from
Mar 22, 2023

Conversation

Xenomega
Copy link
Member

@Xenomega Xenomega commented Mar 13, 2023

This PR adds execution traces to call sequences which fail tests. All shrunken sequences will now be replayed to capture execution traces for discern what caused failures within a single transaction.

It currently supports:

  • Contract creation
  • Calls
  • Proxy calls
  • Cheat code contract calls
  • Input and output arguments
  • Asserts
  • Revert reasons
  • Self destruction
  • Events emitted
  • Custom solidity errors

Other TODOs:

  • Add a --trace-all flag and associated config option to indicate the fuzzer should attach execution traces to all finalized shrunken sequences.
  • Add to tests to target remaining untested trace operations (self destruction)

A later PR should add support for on-chain console.log(), which should be incorporated in the trace. An issue should be opened to track that prior to merging this PR.

anishnaik and others added 11 commits March 7, 2023 19:14
* Added helpers to extract Solidity errors/panics (now used by assertion test provider and execution tracer)
* Added fuzzer tests to verify execution trace output contains revert reasons and assertion failures
* Updated README with required solidity version for unit tests
# Conflicts:
#	fuzzing/calls/call_sequence.go
#	fuzzing/fuzzer_worker.go
@Xenomega Xenomega requested a review from anishnaik March 13, 2023 09:14
README.md Show resolved Hide resolved
…-execute a given call sequence without any custom checks

* Updated FuzzerWorker to re-execute the finalized shrunken sequence before performing the "finalized shrunken sequence" callback, so all providers can assume state is post-execution.
* Updated assertion test provider to attach an execution trace for the last call in a failing sequence
* Updated property test provider to attach execution traces for the last call in a failing sequence, and for its property test
* Updated the fuzzer worker so if a "trace all" flag is provided, it will attach execution traces to all finalized shrunken call sequence elements prior to returning the results to any test provider
* Updated TestChain to provide a method to get the post-execution state root hash for a given block number
@Xenomega
Copy link
Member Author

Xenomega commented Mar 15, 2023

The last commit I pushed makes the following changes:

  • FuzzerWorker will re-execute the finalized shrunken sequence before calling back to test providers (there was previously a deviation where the worker's chain state would be post-execution of call sequences for the initial test call back, and the shrink verifier, but not the final callback). This will let test providers consistently assume the state is post-execution of the call sequence.
  • [If "trace all" is enabled] FuzzerWorker attach traces to all elements of a finalized shrunken sequence, before returning it back to the test provider
  • AssertionTestCaseProvider attaches a trace to the last call always
  • PropertyTestCaseProvider attaches a trace to the last call, and the property test call, always

The "trace all" option is still currently a hardcoded bool and needs to be added to the config, along with a CLI flag to allow override enabling of it (even if config doesn't have it set).

- Removed the hardcoding of traceAll in fuzzerWorker.
- Added TraceAll config option
- Added trace-all flag to CLI that can override config option if necessary
@anishnaik
Copy link
Collaborator

The following has changed in the last 3 commits:

  1. We have added the traceAll config variable as well as the --trace-all CLI flag that can override the traceAll config variable. traceAll works as described by @Xenomega in his previous comment
  2. For call frames where no code is executed, we updated the visual formatting of it to make it look a bit cleaner
  3. Fix a small bug with error handling in call_sequence.go.

@Xenomega
Copy link
Member Author

Xenomega commented Mar 18, 2023

The last commit added support for cheat code contracts in execution traces. I might do some further cleanup later today, otherwise it should be good to go.

Note: CI failed on the last commit because markdown lint was flagging URLs in this repo as dead links, though it should have passed. I'm going to re-run it in a few hours and assume it was some glitch (as they are valid links). Otherwise I'll look into if a new release treats private repos differently.

EDIT: CI is failing due to tcort/markdown-link-check#246 , a new release broke the config file support...

EDIT (2): Applied a temporary fix for CI to master and merged it into this branch.

@Xenomega Xenomega mentioned this pull request Mar 20, 2023
11 tasks
coreTypes "github.com/ethereum/go-ethereum/core/types"
)

// UnpackEventAndValues takes a given contract ABI, and VM return values, and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incomplete comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 56caf88

@@ -76,47 +78,61 @@ func (t *PropertyTestCaseProvider) isPropertyTest(method abi.Method) bool {

// checkPropertyTestFailed executes a given property test method to see if it returns a failed status. This is used to
// facilitate testing of property test methods after every call the Fuzzer makes when testing call sequences.
func (t *PropertyTestCaseProvider) checkPropertyTestFailed(worker *FuzzerWorker, propertyTestMethod *contracts.DeployedContractMethod) (bool, error) {
// The property test is executed over the state indicating by the provided state root hash.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what we mean by "provided state root hash" here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was old from temporary code changes, removed in 56caf88

Copy link
Collaborator

@anishnaik anishnaik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bada bing bada boom

@Xenomega Xenomega merged commit 3da5b3c into master Mar 22, 2023
@Xenomega Xenomega deleted the dev/execution-tracing branch March 22, 2023 14:21
damilolaedwards pushed a commit that referenced this pull request Nov 16, 2023
* Introduction of execution trace attaching and displaying for failed test call sequences
* Added helpers to extract Solidity errors/panics (now used by assertion test provider and execution tracer)
* Added fuzzer tests to verify execution trace output
* Updated README with required solidity version for unit tests
* Provided a wrapper for ExecuteCallSequenceIteratively, to simply re-execute a given call sequence without any custom checks
* Updated FuzzerWorker to re-execute the finalized shrunken sequence before performing the "finalized shrunken sequence" callback, so all providers can assume state is post-execution.
* Updated assertion test provider to attach an execution trace for the last call in a failing sequence
* Updated property test provider to attach execution traces for the last call in a failing sequence, and for its property test
* Updated the fuzzer worker so if a "trace all" flag is provided, it will attach execution traces to all finalized shrunken call sequence elements prior to returning the results to any test provider
* Updated TestChain to provide a method to get the post-execution state root hash for a given block number
* Cleaned up ABI error and event helpers by splitting them off to a compilation-related "abiutils" package.

---------

Co-authored-by: anishnaik <anish.r.naik@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants