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

fix tracer previous step memory pointers #3740

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type StructLogRes struct {
Depth int `json:"depth"`
Error string `json:"error,omitempty"`
Stack *[]string `json:"stack,omitempty"`
ReturnData *string `json:"returnData,omitempty"`
Memory *[]string `json:"memory,omitempty"`
Storage *map[string]string `json:"storage,omitempty"`
RefundCounter uint64 `json:"refund,omitempty"`
Expand Down Expand Up @@ -123,6 +124,14 @@ func (l *JSONLogger) ParseTrace(result *runtime.ExecutionResult, receipt types.R
structLogRes.Storage = &storage
}

var returnData *string
if l.cfg.EnableReturnData && len(step.ReturnData) > 0 {
rd := hex.EncodeToHex(step.ReturnData)
returnData = &rd
}

structLogRes.ReturnData = returnData

structLogs = append(structLogs, structLogRes)
}

Expand Down
3 changes: 2 additions & 1 deletion state/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ func (s *State) buildTrace(evm *fakevm.FakeEVM, result *runtime.ExecutionResult,
}

// Populate the step memory for future steps
step.Memory = memory.Data()
step.Memory = make([]byte, len(memory.Data()))
copy(step.Memory[0:], memory.Data()[0:])

// set Contract
contract := fakevm.NewContract(
Expand Down
8 changes: 8 additions & 0 deletions test/contracts/auto/Sha.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

contract Sha {
function hash() public {
sha256("hello world");
}
}
224 changes: 224 additions & 0 deletions test/contracts/bin/Sha/Sha.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/contracts/bin/triggerErrors/triggerErrors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/e2e/debug_calltracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestDebugTraceTransactionCallTracer(t *testing.T) {
{name: "log0 all zeros", prepare: prepareLog0, createSignedTx: createLog0AllZeros},
{name: "log0 empty", prepare: prepareLog0, createSignedTx: createLog0Empty},
{name: "log0 short", prepare: prepareLog0, createSignedTx: createLog0Short},
{name: "sha256", prepare: prepareSha256, createSignedTx: createSha256},

// failed transactions
{name: "sc deployment reverted", createSignedTx: createScDeployRevertedSignedTx},
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/debug_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Memory"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/OpCallAux"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Revert2"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Sha"
"github.com/0xPolygonHermez/zkevm-node/test/operations"
"github.com/0xPolygonHermez/zkevm-node/test/testutils"
"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -953,3 +954,29 @@ func createLog0Short(t *testing.T, ctx context.Context, auth *bind.TransactOpts,

return tx, nil
}

func prepareSha256(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client) (map[string]interface{}, error) {
_, tx, sc, err := Sha.DeploySha(auth, client)
require.NoError(t, err)

err = operations.WaitTxToBeMined(ctx, client, tx, operations.DefaultTimeoutTxToBeMined)
require.NoError(t, err)

return map[string]interface{}{
"sc": sc,
}, nil
}

func createSha256(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client, customData map[string]interface{}) (*ethTypes.Transaction, error) {
scInterface := customData["sc"]
sc := scInterface.(*Sha.Sha)

opts := *auth
opts.NoSend = true
opts.GasLimit = fixedTxGasLimit

tx, err := sc.Hash(&opts)
require.NoError(t, err)

return tx, nil
}
Loading
Loading