From bfb007ed48afddfdc378253af72c33a8ecab1f24 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Thu, 27 Jul 2023 18:25:46 +0200 Subject: [PATCH] fix: eth get prover data issues (#24) --- jsonrpc/eth_endpoint.go | 15 ++++++++++++--- prover/prover.go | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/jsonrpc/eth_endpoint.go b/jsonrpc/eth_endpoint.go index 21a0afcab5..ab42881d8a 100644 --- a/jsonrpc/eth_endpoint.go +++ b/jsonrpc/eth_endpoint.go @@ -99,8 +99,9 @@ type Eth struct { var ( ErrInsufficientFunds = errors.New("insufficient funds for execution") //Empty code hash is 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 - EmptyCodeHash = hex.EncodeToHex([]byte{197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, - 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}) + EmptyCodeHashBytes = []byte{197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, + 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112} + EmptyCodeHash = hex.EncodeToHex(EmptyCodeHashBytes) ) // ChainId returns the chain id of the client @@ -786,7 +787,15 @@ func (e *Eth) GetProverData(block BlockNumberOrHash) (interface{}, error) { // Get the full account nonce, balance, state root and code hash of the state before this // block is executed acc, err := e.store.GetAccount(previousHeader.StateRoot, accountAddress) - if err != nil { + if errors.Is(err, ErrStateNotFound) { + // Account used for the first time, not yet in storage + acc = &Account{ + Nonce: 0, + Balance: big.NewInt(0), + Root: types.Hash{}, + CodeHash: EmptyCodeHashBytes, // Empty code hash + } + } else if err != nil { return nil, err } diff --git a/prover/prover.go b/prover/prover.go index ad42f5b53e..8b19d2844f 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -48,7 +48,9 @@ func ParseBlockAccounts(block *types.Block) ([]string, error) { var accounts = make([]string, 0) for _, tx := range block.Transactions { accounts = append(accounts, tx.From.String()) - accounts = append(accounts, (*tx.To).String()) + if tx.To != nil { + accounts = append(accounts, (*tx.To).String()) + } } return accounts, nil