77 "github.com/crytic/medusa/fuzzing/contracts"
88 "github.com/crytic/medusa/fuzzing/executiontracer"
99 "github.com/crytic/medusa/utils"
10- "github.com/ethereum/go-ethereum/common"
11- "github.com/ethereum/go-ethereum/eth/tracers"
1210)
1311
1412// ExecuteCallSequenceFetchElementFunc describes a function that is called to obtain the next call sequence element to
@@ -28,7 +26,7 @@ type ExecuteCallSequenceExecutionCheckFunc func(currentExecutedSequence CallSequ
2826// A "post element executed check" function is provided to check whether execution should stop after each element is
2927// executed.
3028// Returns the call sequence which was executed and an error if one occurs.
31- func ExecuteCallSequenceIteratively (chain * chain.TestChain , fetchElementFunc ExecuteCallSequenceFetchElementFunc , executionCheckFunc ExecuteCallSequenceExecutionCheckFunc , getTracerFn func ( txIndex int , txHash common. Hash ) * tracers. Tracer ) (CallSequence , error ) {
29+ func ExecuteCallSequenceIteratively (chain * chain.TestChain , fetchElementFunc ExecuteCallSequenceFetchElementFunc , executionCheckFunc ExecuteCallSequenceExecutionCheckFunc , additionalTracers ... * chain. TestChainTracer ) (CallSequence , error ) {
3230 // If there is no fetch element function provided, throw an error
3331 if fetchElementFunc == nil {
3432 return nil , fmt .Errorf ("could not execute call sequence on chain as the 'fetch element function' provided was nil" )
@@ -90,7 +88,7 @@ func ExecuteCallSequenceIteratively(chain *chain.TestChain, fetchElementFunc Exe
9088 }
9189
9290 // Try to add our transaction to this block.
93- err = chain .PendingBlockAddTx (callSequenceElement .Call .ToCoreMessage (), getTracerFn )
91+ err = chain .PendingBlockAddTx (callSequenceElement .Call .ToCoreMessage (), additionalTracers ... )
9492
9593 if err != nil {
9694 // If we encountered a block gas limit error, this tx is too expensive to fit in this block.
@@ -168,17 +166,14 @@ func ExecuteCallSequence(chain *chain.TestChain, callSequence CallSequence) (Cal
168166 return nil , nil
169167 }
170168
171- return ExecuteCallSequenceIteratively (chain , fetchElementFunc , nil , nil )
169+ return ExecuteCallSequenceIteratively (chain , fetchElementFunc , nil )
172170}
173171
174172// ExecuteCallSequenceWithTracer attaches an executiontracer.ExecutionTracer to ExecuteCallSequenceIteratively and attaches execution traces to the call sequence elements.
175173func ExecuteCallSequenceWithExecutionTracer (testChain * chain.TestChain , contractDefinitions contracts.Contracts , callSequence CallSequence , verboseTracing bool ) (CallSequence , error ) {
176174 // Create a new execution tracer
177175 executionTracer := executiontracer .NewExecutionTracer (contractDefinitions , testChain .CheatCodeContracts ())
178176 defer executionTracer .Close ()
179- getTracerFunc := func (txIndex int , txHash common.Hash ) * tracers.Tracer {
180- return executionTracer .NativeTracer ().Tracer
181- }
182177
183178 // Execute our sequence with a simple fetch operation provided to obtain each element.
184179 fetchElementFunc := func (currentIndex int ) (* CallSequenceElement , error ) {
@@ -188,8 +183,8 @@ func ExecuteCallSequenceWithExecutionTracer(testChain *chain.TestChain, contract
188183 return nil , nil
189184 }
190185
191- // Execute the call sequence
192- executedCallSeq , err := ExecuteCallSequenceIteratively (testChain , fetchElementFunc , nil , getTracerFunc )
186+ // Execute the call sequence and attach the execution tracer
187+ executedCallSeq , err := ExecuteCallSequenceIteratively (testChain , fetchElementFunc , nil , executionTracer . NativeTracer () )
193188
194189 // By default, we only trace the last element in the call sequence.
195190 traceFrom := len (callSequence ) - 1
0 commit comments