From 24757865c6bbd9becb0256e97e8492d1f73987d9 Mon Sep 17 00:00:00 2001 From: colin <102356659+colinlyguo@users.noreply.github.com> Date: Wed, 26 Mar 2025 19:55:02 +0800 Subject: [PATCH] fix(api): eth_getProof crash (#1159) * fix(api): eth_getProof crash * return PoseidonCodeHash for zktrie * fix --- internal/ethapi/api.go | 33 ++++++++++++++++++++------------- params/version.go | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 83b04f4a61..78e7dbe09c 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 @@ -723,17 +721,26 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre return nil, proofErr } - 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, - }, state.Error() + result := &AccountResult{ + 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, + } + + if state.IsZktrie() { + if storageTrie != nil { + result.PoseidonCodeHash = state.GetPoseidonCodeHash(address) + } else { + result.PoseidonCodeHash = codehash.EmptyPoseidonCodeHash + } + } + + return result, state.Error() } // GetHeaderByNumber returns the requested canonical block header. diff --git a/params/version.go b/params/version.go index 4716919647..d986e37759 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 )