Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bsamuels453 committed Nov 30, 2024
1 parent c9cac8c commit e014459
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions chain/fork/remote_state_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *RemoteStateProvider) ImportStateObject(addr common.Address, snapId int)
}

bal, nonce, code, err := s.cache.GetStateObject(addr)
if err != nil {
if err == nil {
s.recordImportedStateObject(addr, snapId)
return bal, nonce, code, nil
} else {
Expand All @@ -60,7 +60,7 @@ func (s *RemoteStateProvider) ImportStorageAt(addr common.Address, slot common.H
}
}
data, err := s.cache.GetStorageAt(addr, slot)
if err != nil {
if err == nil {
s.recordImportedStateSlot(addr, slot, snapId)
return data, nil
} else {
Expand Down
8 changes: 4 additions & 4 deletions chain/test_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestChainBlockNumberJumping(t *testing.T) {
// verifies have no registered contract deployments.
func TestChainDynamicDeployments(t *testing.T) {
// Copy our testdata over to our testing directory
contractPath := testutils.CopyToTesDirectory(t, "testdata/contracts/deployment_with_inner.sol")
contractPath := testutils.CopyToTestDirectory(t, "testdata/contracts/deployment_with_inner.sol")

// Execute our tests in the given test path
testutils.ExecuteInDirectory(t, contractPath, func() {
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestChainDynamicDeployments(t *testing.T) {
// have no registered contract deployments.
func TestChainDeploymentWithArgs(t *testing.T) {
// Copy our testdata over to our testing directory
contractPath := testutils.CopyToTesDirectory(t, "testdata/contracts/deployment_with_args.sol")
contractPath := testutils.CopyToTestDirectory(t, "testdata/contracts/deployment_with_args.sol")

// Execute our tests in the given test path
testutils.ExecuteInDirectory(t, contractPath, func() {
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestChainDeploymentWithArgs(t *testing.T) {
// that the ending state is the same.
func TestChainCloning(t *testing.T) {
// Copy our testdata over to our testing directory
contractPath := testutils.CopyToTesDirectory(t, "testdata/contracts/deployment_single.sol")
contractPath := testutils.CopyToTestDirectory(t, "testdata/contracts/deployment_single.sol")

// Execute our tests in the given test path
testutils.ExecuteInDirectory(t, contractPath, func() {
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestChainCloning(t *testing.T) {
// semantics to be the same whenever run with the same messages being sent for all the same blocks.
func TestChainCallSequenceReplayMatchSimple(t *testing.T) {
// Copy our testdata over to our testing directory
contractPath := testutils.CopyToTesDirectory(t, "testdata/contracts/deployment_single.sol")
contractPath := testutils.CopyToTestDirectory(t, "testdata/contracts/deployment_single.sol")

// Execute our tests in the given test path
testutils.ExecuteInDirectory(t, contractPath, func() {
Expand Down
5 changes: 3 additions & 2 deletions chain/types/medusa_statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ var _ MedusaStateDB = (*state.ForkStateDb)(nil)

type MedusaStateDB interface {
vm.StateDB

// add the extra methods that Medusa uses.
// geth's built-in statedb interface is not complete.
// We need to add the extra methods that Medusa uses.
IntermediateRoot(bool) common.Hash
Finalise(bool)
Logs() []*types.Log
GetLogs(common.Hash, uint64, common.Hash) []*types.Log
TxIndex() int
SetBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason)
Expand Down
6 changes: 3 additions & 3 deletions fuzzing/executiontracer/execution_tracer.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package executiontracer

import (
"github.com/crytic/medusa/chain/types"
"math/big"

"github.com/crytic/medusa/chain"
"github.com/crytic/medusa/fuzzing/contracts"
"github.com/crytic/medusa/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
coretypes "github.com/ethereum/go-ethereum/core/types"

Expand All @@ -20,7 +20,7 @@ import (
// CallWithExecutionTrace obtains an execution trace for a given call, on the provided chain, using the state
// provided. If a nil state is provided, the current chain state will be used.
// Returns the ExecutionTrace for the call or an error if one occurs.
func CallWithExecutionTrace(testChain *chain.TestChain, contractDefinitions contracts.Contracts, msg *core.Message, state *state.StateDB) (*core.ExecutionResult, *ExecutionTrace, error) {
func CallWithExecutionTrace(testChain *chain.TestChain, contractDefinitions contracts.Contracts, msg *core.Message, state types.MedusaStateDB) (*core.ExecutionResult, *ExecutionTrace, error) {
// Create an execution tracer
executionTracer := NewExecutionTracer(contractDefinitions, testChain.CheatCodeContracts())
defer executionTracer.Close()
Expand Down Expand Up @@ -302,7 +302,7 @@ func (t *ExecutionTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope t
// TODO: Move this to OnLog
if op == byte(vm.LOG0) || op == byte(vm.LOG1) || op == byte(vm.LOG2) || op == byte(vm.LOG3) || op == byte(vm.LOG4) {
t.onNextCaptureState = append(t.onNextCaptureState, func() {
logs := t.evmContext.StateDB.(*state.StateDB).Logs()
logs := t.evmContext.StateDB.(types.MedusaStateDB).Logs()
if len(logs) > 0 {
t.currentCallFrame.Operations = append(t.currentCallFrame.Operations, logs[len(logs)-1])
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/crytic/medusa-geth v0.0.0-20241130173605-b90d9e750c68
replace github.com/ethereum/go-ethereum => github.com/crytic/medusa-geth v0.0.0-20241130192903-8ab947767bf4
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXk
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/crytic/medusa-geth v0.0.0-20240919134035-0fd368c28419 h1:MJXzWPObZtF0EMRqX64JkzJDj+GMLPxg3XK5xb12FFU=
github.com/crytic/medusa-geth v0.0.0-20240919134035-0fd368c28419/go.mod h1:ajGCVsk6ctffGwe9TSDQqj4HIUUQ1WdUit5tWFNl8Tw=
github.com/crytic/medusa-geth v0.0.0-20241130173605-b90d9e750c68 h1:omfbSnk8EEIr/B+Sv1iHqTK5sZPw4JfNojbAgFMR9g4=
github.com/crytic/medusa-geth v0.0.0-20241130173605-b90d9e750c68/go.mod h1:ajGCVsk6ctffGwe9TSDQqj4HIUUQ1WdUit5tWFNl8Tw=
github.com/crytic/medusa-geth v0.0.0-20241130192903-8ab947767bf4 h1:hUCM94+Pa65FkkRynJUktVinTHvAdxxcIeuLEkC1/bc=
github.com/crytic/medusa-geth v0.0.0-20241130192903-8ab947767bf4/go.mod h1:ajGCVsk6ctffGwe9TSDQqj4HIUUQ1WdUit5tWFNl8Tw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit e014459

Please sign in to comment.