Skip to content

Commit

Permalink
fix: account proof generation and preimage storage (#1090)
Browse files Browse the repository at this point in the history
* fix: don't pad addresses to be 32 bytes

* fix: proper preimage storage
  • Loading branch information
omerfirmak authored Nov 21, 2024
1 parent 4f473ce commit c8b5dad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
7 changes: 1 addition & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,8 @@ func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash {

// GetProof returns the Merkle proof for a given account.
func (s *StateDB) GetProof(addr common.Address) ([][]byte, error) {
return s.GetProofByHash(common.BytesToHash(addr.Bytes()))
}

// GetProofByHash returns the Merkle proof for a given account.
func (s *StateDB) GetProofByHash(addrHash common.Hash) ([][]byte, error) {
var proof zkproof.ProofList
err := s.trie.Prove(addrHash[:] /*, 0*/, &proof)
err := s.trie.Prove(addr.Bytes(), &proof)
return proof, err
}

Expand Down
5 changes: 3 additions & 2 deletions trie/zk_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (mt *ZkTrie) TryUpdate(key []byte, vFlag uint32, vPreimage []Byte32) error
mt.lock.Lock()
defer mt.lock.Unlock()

mt.secKeyCache[string(nodeKey.Bytes())] = key
mt.secKeyCache[string(nodeKey.Bytes())] = append([]byte{}, key...)

newRootKey, _, err := mt.addLeaf(newLeafNode, mt.rootKey, 0, path)
// sanity check
Expand Down Expand Up @@ -293,8 +293,9 @@ func (mt *ZkTrie) commit(nodeHash *Hash, path []byte, nodeSet *trienode.NodeSet,

if node.Type == NodeTypeLeaf_New {
if mt.preimages != nil {
nodeKeyBytes := node.NodeKey.Bytes()
mt.preimages.insertPreimage(map[common.Hash][]byte{
common.BytesToHash(nodeHash.Bytes()): node.NodeKey.Bytes(),
common.BytesToHash(nodeKeyBytes): mt.secKeyCache[string(nodeKeyBytes)],
})
}
if collectLeaf {
Expand Down

0 comments on commit c8b5dad

Please sign in to comment.