From 13cdb5eaf7451dfcd5ed409b60eb2a89b90477d9 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 5 Oct 2023 11:10:25 +0200 Subject: [PATCH] trie: implement trie-write filter-function --- trie/stackproof.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/trie/stackproof.go b/trie/stackproof.go index c5b4eace9e..118c1dc387 100644 --- a/trie/stackproof.go +++ b/trie/stackproof.go @@ -394,3 +394,29 @@ func VerifyRangeProofWithStack(rootHash common.Hash, firstKey []byte, keys [][]b // hasRightElement is true if the hashes we inserted are non-0 return len(hps) > 0, nil } + +// wrarpWriteFunction returns a NodeWriteFunc which filters away writes that are +// on the boundary: parents of first/last. +func wrapWriteFunction(origin, first, last []byte, w NodeWriteFunc) NodeWriteFunc { + if w == nil { + return nil + } + var originBorder = keybytesToHex(origin) + var leftBorder = keybytesToHex(first) + var rightBorder = keybytesToHex(last) + return func(origin common.Hash, path []byte, hash common.Hash, blob []byte) { + if bytes.HasPrefix(originBorder, path) { + //fmt.Printf("path %x tainted left (parent to %x)\n", path, leftBorder) + return + } + if bytes.HasPrefix(leftBorder, path) { + //fmt.Printf("path %x tainted left (parent to %x)\n", path, leftBorder) + return + } + if bytes.HasPrefix(rightBorder, path) { + //fmt.Printf("path %x tainted right (parent to %x)\n", path, rightBorder) + return + } + w(origin, path, hash, blob) + } +}