Skip to content
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

all: EIP-compliant verkle tree support #23630

Closed

Conversation

gballet
Copy link
Member

@gballet gballet commented Sep 23, 2021

This PR adds a --verkle switch that makes geth use verkle trees instead of the MPT. It implements the following:

  • It adds a new Trie type, namely VerkleTree;
  • It merges the account and storage tries, using the addressing scheme described in the draft EIP;
  • It decouples writing to the tree from database state updates;
  • It only uses the snapshot for its storage - to achieve this, it creates the snapshot at genesis time;
  • It computes a verkle proof for the block at the end of the block execution, and publishes it with the block in a new VerkleProof field;
  • It makes it possible to statelessly execute/verify a block just using the data provided in the proof, thus transforming geth into a verkle light client (final proof verification isn't currently performed, due to some required changes in go-verkle, that will be implemented shortly).

This PR doesn't include:

  • Syncing: right now, only full sync is supported and won't be supported until
  • A mechanism for switching from the current MPT to verkle trees, the network has to be started from scratch.

This is a rebase of #23563, with some extra fixes.

TODO:

  • in gasSLoad and other locations, the initial data isn't loaded from the database and an invalid default is used. There should be something to just mark the location as accessed, and then a later load from the db (maybe concurrent in VerkleProofGeneration)
  • integrate the IPA-based go-verkle when it's ready
  • verify the proof before executing everything, this is done by adding proof verification in DeserializeVerkleProof
  • remove the dependency of go-verkle on go-ethereum, this breaks the linter - still broken because of a circular dependency in consensys/gruby.
    • common
    • rlp
  • add tests for stateless contract execution
  • make sure tests pass when --verkle isn't set

@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch 3 times, most recently from 6562bff to 936e7f1 Compare September 23, 2021 19:40
@gballet gballet mentioned this pull request Sep 24, 2021
7 tasks
@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch from dd505fd to be9f9e9 Compare September 30, 2021 19:31
@paulmillr
Copy link

Does this improve performance in any way? How can we run some benchmarks?

cmd/utils/flags.go Outdated Show resolved Hide resolved
core/genesis.go Outdated Show resolved Hide resolved
@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch 4 times, most recently from 9dd8aec to 60b8f90 Compare November 9, 2021 08:18
@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch from 80f090f to afd2166 Compare November 12, 2021 16:05
} else {
b.statedb.SetWitness(accesses)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplification here: since the statedb now contains an AccessWitness, one can remove it from the signature of ApplyTransaction and directly merge it there.

@@ -202,6 +203,17 @@ func New(diskdb ethdb.KeyValueStore, triedb *trie.Database, cache int, root comm
}
if err != nil {
if rebuild {
if useVerkle {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if useVerkle is really necessary, since we have IsVerkle handy.

@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch from ef6b8b7 to fb221aa Compare November 20, 2021 08:40
trie/verkle.go Outdated Show resolved Hide resolved
trie/verkle.go Outdated Show resolved Hide resolved
gballet and others added 7 commits November 26, 2021 16:30
verkle: Implement Trie, NodeIterator and Database ifs

Fix crash in TestDump

Fix TestDump

Fix TrieCopy

remove unnecessary traces

fix: Error() returned errIteratorEnd in verkle node iterator

rewrite the iterator and change the signature of OpenStorageTrie

add the adapter to reuse the account trie for storage

don't try to deserialize a storage leaf into an account

Fix statedb unit tests (#14)

* debug code

* Fix more unit tests

* remove traces

* Go back to the full range

One tree to rule them all

remove updateRoot, there is no root to update

store code inside the account leaf

fix build

save current state for Sina

Update go-verkle to latest

Charge WITNESS_*_COST gas on storage loads

Add witness costs for SSTORE as well

Charge witness gas in the case of code execution

corresponding code deletion

add a --verkle flag to separate verkle experiments from regular geth operations

use the snapshot to get data

stateless execution from block witness

AccessWitness functions

Add block generation test + genesis snapshot generation

test stateless block execution (#18)

* test stateless block execution

* Force tree resolution before generating the proof

increased coverage in stateless test execution (#19)

* test stateless block execution

* Force tree resolution before generating the proof

* increase coverage in stateless test execution

ensure geth compiles

fix issues in tests with verkle trees deactivated

Ensure stateless data is available when executing statelessly (#20)

* Ensure stateless data is available when executing statelessly

* Actual execution of a statless block

* bugfixes in stateless block execution

* code cleanup

 - Reduce PR footprint by reverting NewEVM to its original signature
 - Move the access witness to the block context
 - prepare for a change in AW semantics
   Need to store the initial values.
 - Use the touch helper function, DRY

* revert the signature of MustCommit to its original form (#21)

fix leaf proofs in stateless execution (#22)

* Fixes in witness pre-state

* Add the recipient's nonce to the witness

* reduce PR footprint and investigate issue in root state calculation

* quick build fix

cleanup: Remove extra parameter in ToBlock

revert ToBlock to its older signature

fix import cycle in vm tests

fix linter issue

fix appveyor build

fix nil pointers in tests

Add indices, yis and Cis to the block's Verkle proof

upgrade geth dependency to drop geth's common dep

fix cmd/devp2p tests

fix rebase issues

quell an appveyor warning

fix address touching in SLOAD and SSTORE

fix access witness for code size

touch target account data before calling

make sure the proper locations get touched in (ext)codecopy

touch all code pages in execution

add pushdata to witness

remove useless code in genesis snapshot generation

testnet: fix some of the rebase/drift issues

Fix verkle proof generation in block

fix an issue occuring when chunking past the code size

fix: ensure the code copy doesn't extend past the code size
upgrade to latest go-verkle

update go-verkle to get more fixes

simplify code by removing all stateless references (#25)

fix verkle proof test by enforcing values alignment to 32 bytes

remove unneeded KZG tag

fix the stateless test

Move AccessWitness into StateDB (#27)

* move AccessWitness into StateDB

* set Accesses in TxContext constructor

* Ensures that a statedb is initialized with a witness

* copy AccessWitness in StateDB.Copy.  use copied state in miner worker.commit.

* remove redundant line

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

Fix contract creation issue
* enable verkle on cancun block: take 2

* fix typo.  make unreachable line panic message more clear
@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch from d0bcc59 to e1adb6f Compare March 25, 2022 10:26
@gballet gballet force-pushed the verkle-trie-proof-in-block-rebased branch from e1adb6f to dd6425e Compare March 25, 2022 10:29
@@ -357,6 +381,20 @@ func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big
return g.MustCommit(db)
}

func DefaultVerkleGenesisBlock() *Genesis {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: remove

@gballet
Copy link
Member Author

gballet commented Jul 6, 2022

Replaced by #25253, closing this one.

@gballet gballet closed this Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants