From e80917d7d1727f07963fffa037994e61d64d7043 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Wed, 26 Mar 2025 18:58:50 +0800 Subject: [PATCH 1/3] fix(api): eth_getProof crash --- internal/ethapi/api.go | 19 ++++++++----------- params/version.go | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 83b04f4a619..53ce57b48ee 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -692,7 +692,6 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre storageHash = types.EmptyRootHash } keccakCodeHash := state.GetKeccakCodeHash(address) - poseidonCodeHash := state.GetPoseidonCodeHash(address) storageProof := make([]StorageResult, len(storageKeys)) // if we have a storageTrie, (which means the account exists), we can update the storagehash @@ -701,7 +700,6 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre } else { // no storageTrie means the account does not exist, so the codeHash is the hash of an empty bytearray. keccakCodeHash = codehash.EmptyKeccakCodeHash - poseidonCodeHash = codehash.EmptyPoseidonCodeHash } // create the proof for the storageKeys @@ -724,15 +722,14 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre } return &AccountResult{ - Address: address, - AccountProof: toHexSlice(accountProof), - Balance: (*hexutil.Big)(state.GetBalance(address)), - KeccakCodeHash: keccakCodeHash, - PoseidonCodeHash: poseidonCodeHash, - CodeSize: hexutil.Uint64(state.GetCodeSize(address)), - Nonce: hexutil.Uint64(state.GetNonce(address)), - StorageHash: storageHash, - StorageProof: storageProof, + Address: address, + AccountProof: toHexSlice(accountProof), + Balance: (*hexutil.Big)(state.GetBalance(address)), + KeccakCodeHash: keccakCodeHash, + CodeSize: hexutil.Uint64(state.GetCodeSize(address)), + Nonce: hexutil.Uint64(state.GetNonce(address)), + StorageHash: storageHash, + StorageProof: storageProof, }, state.Error() } diff --git a/params/version.go b/params/version.go index 47169196477..d986e377596 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 8 // Minor version component of the current release - VersionPatch = 32 // Patch version component of the current release + VersionPatch = 33 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) From 57c00ba570f222ccbe527a7c384624af0a6bb83f Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Wed, 26 Mar 2025 19:30:42 +0800 Subject: [PATCH 2/3] return PoseidonCodeHash for zktrie --- internal/ethapi/api.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 53ce57b48ee..132ef2ffc81 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -679,7 +679,7 @@ type StorageResult struct { // GetProof returns the Merkle-proof for a given account and optionally some storage keys. func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) { - state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) + state, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) if state == nil || err != nil { return nil, err } @@ -721,7 +721,7 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre return nil, proofErr } - return &AccountResult{ + result := &AccountResult{ Address: address, AccountProof: toHexSlice(accountProof), Balance: (*hexutil.Big)(state.GetBalance(address)), @@ -730,7 +730,17 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre Nonce: hexutil.Uint64(state.GetNonce(address)), StorageHash: storageHash, StorageProof: storageProof, - }, state.Error() + } + + if !s.b.ChainConfig().IsEuclid(header.Time) { + if storageTrie != nil { + result.PoseidonCodeHash = state.GetPoseidonCodeHash(address) + } else { + result.PoseidonCodeHash = codehash.EmptyPoseidonCodeHash + } + } + + return result, state.Error() } // GetHeaderByNumber returns the requested canonical block header. From 6c2f241b9ac86c35c19827712aaa0d459460eb00 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Wed, 26 Mar 2025 19:31:36 +0800 Subject: [PATCH 3/3] fix --- internal/ethapi/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 132ef2ffc81..78e7dbe09c8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -679,7 +679,7 @@ type StorageResult struct { // GetProof returns the Merkle-proof for a given account and optionally some storage keys. func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Address, storageKeys []string, blockNrOrHash rpc.BlockNumberOrHash) (*AccountResult, error) { - state, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) + state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) if state == nil || err != nil { return nil, err } @@ -732,7 +732,7 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre StorageProof: storageProof, } - if !s.b.ChainConfig().IsEuclid(header.Time) { + if state.IsZktrie() { if storageTrie != nil { result.PoseidonCodeHash = state.GetPoseidonCodeHash(address) } else {