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 'full-witness-contract-interaction.json' test #1558

Open
wants to merge 1 commit into
base: feat/apply-zero-traces-to-a-smt-trie
Choose a base branch
from
Open
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
29 changes: 12 additions & 17 deletions smt/pkg/smt/smt_state_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"encoding/hex"
"errors"
"fmt"
"math/big"

"github.com/holiman/uint256"
"github.com/ledgerwatch/erigon-lib/common"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/types/accounts"
Expand Down Expand Up @@ -51,7 +49,7 @@ func (s *SMT) CreateContract(address common.Address) error {
}

// ApplyTraces applies a map of traces on the given SMT and returns new instance of SMT, without altering the original one.
func (s *SMT) ApplyTraces(traces map[libcommon.Address]*types.TxnTrace, rd trie.RetainDecider) (*SMT, error) {
func (s *SMT) ApplyTraces(traces map[common.Address]*types.TxnTrace, rd trie.RetainDecider) (*SMT, error) {
// result, err := s.Copy(context.Background(), rd)
// if err != nil {
// return nil, err
Expand All @@ -76,23 +74,18 @@ func (s *SMT) ApplyTraces(traces map[libcommon.Address]*types.TxnTrace, rd trie.
addrString := addr.Hex()

// Set account balance and nonce
balanceBig := big.NewInt(0)
if trace.Balance != nil {
balanceBig = trace.Balance.ToBig()
}

nonceBig := big.NewInt(0)
if trace.Nonce != nil {
nonceBig = trace.Nonce.ToBig()
}
balanceBig := trace.Balance.ToBig()

if _, err := result.SetAccountState(addrString, balanceBig, nonceBig); err != nil {
return nil, err
if _, err := result.SetAccountBalance(addrString, balanceBig); err != nil {
return nil, err
}
}

// Set account nonce
if trace.Nonce != nil {
if _, err := result.SetAccountNonce(addrString, trace.Nonce.ToBig()); err != nil {
nonceBig := trace.Nonce.ToBig()

if _, err := result.SetAccountNonce(addrString, nonceBig); err != nil {
return nil, err
}
}
Expand All @@ -112,8 +105,10 @@ func (s *SMT) ApplyTraces(traces map[libcommon.Address]*types.TxnTrace, rd trie.

// Set account bytecode
if trace.CodeUsage != nil {
if err := result.SetContractBytecode(addrString, hex.EncodeToString(trace.CodeUsage.Write)); err != nil {
return nil, err
if trace.CodeUsage.Write != nil {
if err := result.SetContractBytecode(addrString, hex.EncodeToString(trace.CodeUsage.Write)); err != nil {
return nil, err
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions smt/pkg/smt/smt_state_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func TestSMTApplyTraces(t *testing.T) {
// name: "SC deployment full witness",
// file: "./testdata/zerotraces/full-witness-contract-deployment.json",
// },
// {
// name: "SC interaction full witness",
// file: "./testdata/zerotraces/full-witness-contract-interaction.json",
// },
{
name: "SC interaction full witness",
file: "./testdata/zerotraces/full-witness-contract-interaction.json",
},
}

for _, c := range cases {
Expand Down