Commit 0e6ad3bb authored by han0110's avatar han0110

fix: get absense proof and brute-forcely enumerate all possible short node preimage pairs

parent c2f67a9c
......@@ -355,7 +355,8 @@ func (s *stateObject) updateTrie(db Database) Trie {
var v []byte
oracle.PrefetchStorage(db.BlockNumber, s.address, key)
//oracle.PrefetchStorage(big.NewInt(db.BlockNumber.Int64()+1), s.address, key)
// Get absense proof of current key in case the deletion make the extension node to short node.
oracle.PrefetchStorage(big.NewInt(db.BlockNumber.Int64()+1), s.address, key)
if (value == common.Hash{}) {
//fmt.Println("delete", s.address, key)
s.setError(tr.TryDelete(key[:]))
......
......@@ -22,3 +22,8 @@ func Preimage(hash common.Hash) []byte {
}
return val
}
// TODO: Maybe we will want to have a seperate preimages for next block's preimages?
func Preimages() map[common.Hash][]byte {
return preimages
}
package trie
import (
"bytes"
"fmt"
"io"
"math/big"
......@@ -8,7 +9,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/rlp"
)
// rawNode is a simple binary blob used to differentiate between collapsed trie
......@@ -61,3 +64,37 @@ func (db *Database) insert(hash common.Hash, size int, node node) {
// can put things in the oracle here if we care
//fmt.Println("insert", hash, size)
}
// TODO: Create pairs only when seeing pos
func genPossibleShortNodePreimage(pos int) {
preimages := oracle.Preimages()
newPreimages := make(map[common.Hash][]byte)
for _, val := range preimages {
node, err := decodeNode(nil, val)
if err != nil {
continue
}
if node, ok := node.(*shortNode); ok {
for i := 1; i < len(node.Key); i += 1 {
n := shortNode{
Key: hexToCompact(node.Key[len(node.Key)-i:]),
Val: node.Val,
}
buf := new(bytes.Buffer)
if err := rlp.Encode(buf, n); err != nil {
panic("encode error: " + err.Error())
}
preimage := buf.Bytes()
if len(preimage) < 32 {
continue
}
newPreimages[crypto.Keccak256Hash(preimage)] = preimage
}
}
}
for hash, val := range newPreimages {
preimages[hash] = val
}
}
......@@ -443,6 +443,8 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
// might not be loaded yet, resolve it just for this
// check.
// TODO: Try to cache short nodes already generated
genPossibleShortNodePreimage(pos)
// remove this optimisticly? if it's not a shortNode, it doesn't do anything
cnode, err := t.resolve(n.Children[pos], prefix)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment