Skip to content

Commit 2475786

Browse files
authored
fix(api): eth_getProof crash (#1159)
* fix(api): eth_getProof crash * return PoseidonCodeHash for zktrie * fix
1 parent 2ff8403 commit 2475786

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

internal/ethapi/api.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,6 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre
692692
storageHash = types.EmptyRootHash
693693
}
694694
keccakCodeHash := state.GetKeccakCodeHash(address)
695-
poseidonCodeHash := state.GetPoseidonCodeHash(address)
696695
storageProof := make([]StorageResult, len(storageKeys))
697696

698697
// 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
701700
} else {
702701
// no storageTrie means the account does not exist, so the codeHash is the hash of an empty bytearray.
703702
keccakCodeHash = codehash.EmptyKeccakCodeHash
704-
poseidonCodeHash = codehash.EmptyPoseidonCodeHash
705703
}
706704

707705
// create the proof for the storageKeys
@@ -723,17 +721,26 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre
723721
return nil, proofErr
724722
}
725723

726-
return &AccountResult{
727-
Address: address,
728-
AccountProof: toHexSlice(accountProof),
729-
Balance: (*hexutil.Big)(state.GetBalance(address)),
730-
KeccakCodeHash: keccakCodeHash,
731-
PoseidonCodeHash: poseidonCodeHash,
732-
CodeSize: hexutil.Uint64(state.GetCodeSize(address)),
733-
Nonce: hexutil.Uint64(state.GetNonce(address)),
734-
StorageHash: storageHash,
735-
StorageProof: storageProof,
736-
}, state.Error()
724+
result := &AccountResult{
725+
Address: address,
726+
AccountProof: toHexSlice(accountProof),
727+
Balance: (*hexutil.Big)(state.GetBalance(address)),
728+
KeccakCodeHash: keccakCodeHash,
729+
CodeSize: hexutil.Uint64(state.GetCodeSize(address)),
730+
Nonce: hexutil.Uint64(state.GetNonce(address)),
731+
StorageHash: storageHash,
732+
StorageProof: storageProof,
733+
}
734+
735+
if state.IsZktrie() {
736+
if storageTrie != nil {
737+
result.PoseidonCodeHash = state.GetPoseidonCodeHash(address)
738+
} else {
739+
result.PoseidonCodeHash = codehash.EmptyPoseidonCodeHash
740+
}
741+
}
742+
743+
return result, state.Error()
737744
}
738745

739746
// GetHeaderByNumber returns the requested canonical block header.

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 32 // Patch version component of the current release
27+
VersionPatch = 33 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)