forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 284
fix(zktrie): fix deletion proofs and collect them in commiting phase #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a8f2741
new deletion proof
noel2004 a413434
complete tracer and test
noel2004 3ca688c
extend proof for parallel tracing
noel2004 f7bb624
integrating into blocktrace
noel2004 c1c2c00
lint
noel2004 e649e1b
deduplication of deletion proofs
noel2004 8973c8e
fix an issue on marking deletion
noel2004 5438b11
Merge branch 'develop' into fix/deletion_proof_2
0xmountaintop cd5b554
fixs since last review
noel2004 97906b2
Merge remote-tracking branch 'origin/develop' into fix/deletion_proof_2
noel2004 ce40624
Merge remote-tracking branch 'origin/develop' into fix/deletion_proof_2
noel2004 b2e7caa
Merge remote-tracking branch 'origin/develop' into fix/deletion_proof_2
ba4d3ee
Merge branch 'develop' into fix/deletion_proof_2
0xmountaintop 78b66e6
Update version.go
0xmountaintop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package state | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| zkt "github.com/scroll-tech/zktrie/types" | ||
|
|
||
| zktrie "github.com/scroll-tech/go-ethereum/trie" | ||
|
|
||
| "github.com/scroll-tech/go-ethereum/common" | ||
| "github.com/scroll-tech/go-ethereum/crypto" | ||
| "github.com/scroll-tech/go-ethereum/ethdb" | ||
| ) | ||
|
|
||
| type TrieProve interface { | ||
| Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) error | ||
| } | ||
|
|
||
| type ZktrieProofTracer struct { | ||
| *zktrie.ProofTracer | ||
| } | ||
|
|
||
| // MarkDeletion overwrite the underlayer method with secure key | ||
| func (t ZktrieProofTracer) MarkDeletion(key common.Hash) { | ||
| key_s, _ := zkt.ToSecureKeyBytes(key.Bytes()) | ||
| t.ProofTracer.MarkDeletion(key_s.Bytes()) | ||
| } | ||
|
|
||
| // Merge overwrite underlayer method with proper argument | ||
| func (t ZktrieProofTracer) Merge(another ZktrieProofTracer) { | ||
| t.ProofTracer.Merge(another.ProofTracer) | ||
| } | ||
|
|
||
| func (t ZktrieProofTracer) Available() bool { | ||
| return t.ProofTracer != nil | ||
| } | ||
|
|
||
| // NewProofTracer is not in Db interface and used explictily for reading proof in storage trie (not updated by the dirty value) | ||
| func (s *StateDB) NewProofTracer(trieS Trie) ZktrieProofTracer { | ||
| if s.IsZktrie() { | ||
| zkTrie := trieS.(*zktrie.ZkTrie) | ||
| if zkTrie == nil { | ||
| panic("unexpected trie type for zktrie") | ||
| } | ||
| return ZktrieProofTracer{zkTrie.NewProofTracer()} | ||
| } | ||
| return ZktrieProofTracer{} | ||
| } | ||
|
|
||
| // GetStorageTrieForProof is not in Db interface and used explictily for reading proof in storage trie (not updated by the dirty value) | ||
| func (s *StateDB) GetStorageTrieForProof(addr common.Address) (Trie, error) { | ||
|
|
||
| // try the trie in stateObject first, else we would create one | ||
| stateObject := s.getStateObject(addr) | ||
| if stateObject == nil { | ||
| // still return a empty trie | ||
| addrHash := crypto.Keccak256Hash(addr[:]) | ||
| dummy_trie, _ := s.db.OpenStorageTrie(addrHash, common.Hash{}) | ||
| return dummy_trie, nil | ||
| } | ||
|
|
||
| trie := stateObject.trie | ||
| var err error | ||
| if trie == nil { | ||
| // use a new, temporary trie | ||
| trie, err = s.db.OpenStorageTrie(stateObject.addrHash, stateObject.data.Root) | ||
noel2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return nil, fmt.Errorf("can't create storage trie on root %s: %v ", stateObject.data.Root, err) | ||
| } | ||
| } | ||
|
|
||
| return trie, nil | ||
| } | ||
|
|
||
| // GetSecureTrieProof handle any interface with Prove (should be a Trie in most case) and | ||
| // deliver the proof in bytes | ||
| func (s *StateDB) GetSecureTrieProof(trieProve TrieProve, key common.Hash) ([][]byte, error) { | ||
|
|
||
| var proof proofList | ||
| var err error | ||
| if s.IsZktrie() { | ||
| key_s, _ := zkt.ToSecureKeyBytes(key.Bytes()) | ||
| err = trieProve.Prove(key_s.Bytes(), 0, &proof) | ||
| } else { | ||
| err = trieProve.Prove(crypto.Keccak256(key.Bytes()), 0, &proof) | ||
| } | ||
| return proof, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.