Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Drifted account leaf partially fixed; logging msgs removed
Browse files Browse the repository at this point in the history
  • Loading branch information
miha-stopar committed Sep 22, 2023
1 parent d58d770 commit 6100beb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
1 change: 0 additions & 1 deletion mpt-witness-generator/oracle/preimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var preimages = make(map[common.Hash][]byte)
func Preimage(hash common.Hash) ([]byte, error) {
val, ok := preimages[hash]
if !ok {
fmt.Println("can't find preimage", hash)
return nil, errors.New("can't find preimage")
}
comphash := crypto.Keccak256Hash(val)
Expand Down
6 changes: 3 additions & 3 deletions mpt-witness-generator/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (s *StateDB) SetStateObjectIfExists(addr common.Address) {
ap := oracle.PrefetchAccount(s.Db.BlockNumber, addr, nil)
if len(ap) > 0 {
ret, _ := hex.DecodeString(ap[len(ap)-1][2:])
s.setStateObjectFromEncoding(addr, ret)
s.SetStateObjectFromEncoding(addr, ret)
}
}
}
Expand Down Expand Up @@ -594,7 +594,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {

// Added for MPT generator. This loads account into stateObjects - if an account is not
// in stateObjects, a new account is created in GetOrNewStateObject.
func (s *StateDB) setStateObjectFromEncoding(addr common.Address, enc []byte) error {
func (s *StateDB) SetStateObjectFromEncoding(addr common.Address, enc []byte) error {
if len(enc) == 0 {
return errors.New("encoding of account is of length 0")
}
Expand All @@ -605,7 +605,7 @@ func (s *StateDB) setStateObjectFromEncoding(addr common.Address, enc []byte) er
if err := rlp.DecodeBytes(accData, data); err != nil {
// If it's not account RLP, nothing is set (in stateObjects) - this is to prevent
// the need of checking whether enc is account RLP or something else (like branch RLP).
fmt.Println("failed to decode account")
// fmt.Println("failed to decode account")
return nil
}

Expand Down
1 change: 0 additions & 1 deletion mpt-witness-generator/trie/stacktrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ func (st *StackTrie) hash(doUpdate bool) {
if st.db != nil {
// TODO! Is it safe to Put the slice here?
// Do all db implementations copy the value provided?
fmt.Println("into db:", st.val)
st.db.Put(st.val, h.tmp)
}
}
Expand Down
4 changes: 0 additions & 4 deletions mpt-witness-generator/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ func (t *Trie) insert(n Node, prefix, key []byte, value Node) (bool, Node, error
}
// Otherwise, replace it with a short node leading up to the branch.
// (this is extension node)
if matchlen > 2 {
fmt.Println(matchlen)
fmt.Println("====")
}
return true, &ShortNode{key[:matchlen], branch, t.newFlag()}, nil

case *FullNode:
Expand Down
8 changes: 6 additions & 2 deletions mpt-witness-generator/witness/prepare_witness.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package witness

import (
"encoding/hex"
"fmt"
"math/big"

Expand Down Expand Up @@ -200,7 +201,7 @@ func obtainTwoProofsAndConvertToWitness(trieModifications []TrieModification, st
addrh := crypto.Keccak256(addr.Bytes())
accountAddr := trie.KeybytesToHex(addrh)

oracle.PrefetchAccount(statedb.Db.BlockNumber, tMod.Address, nil)
ap := oracle.PrefetchAccount(statedb.Db.BlockNumber, tMod.Address, nil)
oracle.PrefetchStorage(statedb.Db.BlockNumber, addr, tMod.Key, nil)

if specialTest == 1 {
Expand All @@ -211,7 +212,10 @@ func obtainTwoProofsAndConvertToWitness(trieModifications []TrieModification, st
check(err)

if !statedb.Exist(addr) {
statedb.CreateObject(addr)
if len(ap) > 0 {
ret, _ := hex.DecodeString(ap[len(ap)-1][2:])
statedb.SetStateObjectFromEncoding(addr, ret)
}
}

storageProof, neighbourNode1, extNibbles1, isLastLeaf1, isNeighbourNodeHashed1, err := statedb.GetStorageProof(addr, tMod.Key)
Expand Down

0 comments on commit 6100beb

Please sign in to comment.