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

Inserted extension node #1548

Closed
wants to merge 304 commits into from
Closed

Inserted extension node #1548

wants to merge 304 commits into from

Conversation

miha-stopar
Copy link
Collaborator

Description

Support for modified extension nodes.

This happens when an extension node is replaced by another (shorter or longer) extension node. For example, we have an extension node at n1 n2 n3 n4 n5 n6 with branch with two leaves at positions n and m. If we add a leaf at n1 n2 n3 n4 n7 where n5 != n7, a new extension node is inserted at n1 n2 n3 n4 with a new branch with an extension node at position n5 (with only one nibble n6) and a leaf at position n7. In this case, the S proof contains the extension node at n1 n2 n3 n4 n5 n6 and no underlying branch and leaf (the modification happens at n1 n2 n3 n4 n7 and only an extension node is find there), thus we need to add a placeholder branch and a placeholder leaf.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

miha-stopar and others added 18 commits October 27, 2022 16:23
Some refactoring which I believe decreases code duplication and
increases code readability.

Some TODOs:
- [x] The code required to get the previous rlc/mult data or the
inclusion in the parent check is quite complicated because of the
different node types. Instead it may be better to use a fixed location
to store this data in so a node can simply use this data directly
instead of having to figure out on its own where to find the data. This
is cleaner because this way each node can decide on its own how these
should be handled.
- [x] Currently RLP decoding is done using a couple of selectors that
are inputs from the prover. Then there are some checks if these are
correct, though these are not complete. I think it's easier to think
about this if we would just use a lookup to directly verify if these
selectors are set correctly so we don't have to worry about edge cases
are cases that are hard to constrain using custom gates.
- [x] There are currently many cases in the main state maching because
each row type is it's own state. However there is not really any reuse
between custom gates between these rows, except for branches. It'll
likely be quite a bit simple to just have a single state for account,
storage and extension and just use multiple rows in those states
- [x] May be a good idea to split up branches and extension nodes. (semi
done)
- [ ] There's a couple of circuit tools that were added in this PR to
make writing the MPT circuit more manageable. A lot of these tools can
still be greatly improved.
- [ ] Number of lookups has been reduced a lot, but there are still many
optimization possibilities (have not looked into reducing the expression
degree for example).
- [x] The circuit uses a fixed layout which uses around 100 columns (of
which a lot need to be byte constrained so needs a lot of lookups as
well). This makes the circuit quite a bit more dense than probably
required, a more flexible way to manager the required data so the
width/height can be choses would be very useful I think.
### Description

This PR simply merges the current `main` into the MPT branch `mpt2`.
This is the first step to get some further MPT changes merged into the
MPT branch without making the PRs too big.

```
This PR contains:
- Merge `main` into `mpt2` with the necessary changes to the MPT circuit
```

### Issue Link

[_link issue here_]

### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Contents

- [_item_]

### Rationale

[_design decisions and extended information_]

### How Has This Been Tested?

Intermediate step, so limited testing

---------

Signed-off-by: smtmfft <smtm@taiko.xzy>
Signed-off-by: smtmfft <smtm@taiko.xyz>
Co-authored-by: pinkiebell <40266861+pinkiebell@users.noreply.github.com>
Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
Co-authored-by: z2trillion <z2trillion@users.noreply.github.com>
Co-authored-by: Eduard S <eduardsanou@posteo.net>
Co-authored-by: adria0.eth <5526331+adria0@users.noreply.github.com>
Co-authored-by: Han <tinghan0110@gmail.com>
Co-authored-by: smtmfft <99081233+smtmfft@users.noreply.github.com>
Co-authored-by: smtmfft <smtm@taiko.xzy>
Co-authored-by: Chih Cheng Liang <chihchengliang@gmail.com>
Co-authored-by: DreamWuGit <wwuwwei@126.com>
Co-authored-by: Rohit Narurkar <rohit.narurkar@protonmail.com>
Co-authored-by: Zhang Zhuo <mycinbrin@gmail.com>
Co-authored-by: Ming <hero78119@gmail.com>
Co-authored-by: Wu Sung Ming <wusm@sea.com>
Co-authored-by: xiaodino <qinyi@taikocha.in>
Co-authored-by: Mason Liang <mason@0x.org>
Co-authored-by: Steven <asongala@163.com>
Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com>
Co-authored-by: Paul <108982045+ChengYueJia@users.noreply.github.com>
Co-authored-by: AronisAt79 <45406504+AronisAt79@users.noreply.github.com>
Co-authored-by: Mason Liang <mason@scroll.io>
Co-authored-by: JohnWick2ETH <104916412+JohnWick2ETH@users.noreply.github.com>
Co-authored-by: kunxian xia <xiakunxian130@gmail.com>
Co-authored-by: Leo Lara <leolara@users.noreply.github.com>
Co-authored-by: zengzengzenghuy <85567868+zengzengzenghuy@users.noreply.github.com>
Co-authored-by: john xu <john@taiko.xyz>
Co-authored-by: Miha Stopar <miha.stopar@xlab.si>
Co-authored-by: aguzmant103 <67167307+aguzmant103@users.noreply.github.com>
Co-authored-by: Richord <rzhang139@gmail.com>
Co-authored-by: Kimi Wu <leonhartwu@gmail.com>
Co-authored-by: Mickey <hedgefund996@gmail.com>
Co-authored-by: Luozhu <70309026+LuozhuZhang@users.noreply.github.com>
Co-authored-by: DoHoon Kim <59155248+DoHoonKim8@users.noreply.github.com>
Co-authored-by: jeong0982 <jeong0982@kaist.ac.kr>
Co-authored-by: Andy Arditi <andyrdt@gmail.com>
Co-authored-by: David Nevado <davidnevadoc@users.noreply.github.com>
Co-authored-by: omahs <73983677+omahs@users.noreply.github.com>
Co-authored-by: Richord <rrzhang@usc.edu>
Co-authored-by: ntampakas <nick@gmx.co.uk>
Co-authored-by: ashWhiteHat <phantomofrotten@gmail.com>
Co-authored-by: naure <naure@users.noreply.github.com>
Co-authored-by: Aurélien Nicolas <info@nau.re>
Co-authored-by: testuser-at-490752553772 <m_aronis@hotmail.com>
Co-authored-by: xiaodino <ruby@taiko.xyz>
Co-authored-by: Thomas Pan <43927782+thomaspanf@users.noreply.github.com>
Co-authored-by: Akase Cho <lightsing@users.noreply.github.com>
Co-authored-by: Vu <vu.voth@gmail.com>
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
Co-authored-by: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com>
Co-authored-by: adria0 <adria0@nowhere>
# Conflicts:
#	Cargo.lock
#	circuit-benchmarks/Cargo.toml
#	eth-types/src/geth_types.rs
#	gadgets/src/util.rs
#	keccak256/Cargo.toml
#	keccak256/src/arith_helpers.rs
#	keccak256/src/keccak_arith.rs
#	keccak256/src/lib.rs
#	keccak256/src/plain.rs
#	testool/src/compiler.rs
#	zkevm-circuits/Cargo.toml
#	zkevm-circuits/src/evm_circuit.rs
#	zkevm-circuits/src/pi_circuit.rs
#	zkevm-circuits/src/state_circuit.rs
#	zkevm-circuits/src/state_circuit/constraint_builder.rs
#	zkevm-circuits/src/table.rs
#	zkevm-circuits/src/table/keccak_table.rs
#	zkevm-circuits/src/table/mpt_table.rs
#	zkevm-circuits/src/tx_circuit/dev.rs
#	zkevm-circuits/src/tx_circuit/sign_verify.rs
#	zkevm-circuits/src/util.rs
#	zkevm-circuits/src/witness/mpt.rs
### Description

- Added some missing MPT constraints
- Integrated some EVM tools like degree reduction and lookups using
dedicated columns

### Issue Link

[_link issue here_]

### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Contents

- [_item_]

### Rationale

[_design decisions and extended information_]

### How Has This Been Tested?

[_explanation_]

---------

Co-authored-by: Cecilia Zhang <zhangyixin319@gmail.com>
Co-authored-by: CeciliaZ030 <45245961+CeciliaZ030@users.noreply.github.com>
### Description

New descriptors are used which have `Vec<Node>` structure and thus the
conversion in `witness_row.rs` from `[][]byte` to `Vec<Node>` was
removed. Note that `keccak_data` is now part of the `Node` struct - each
node holds the byte streams that need to be hashed.

Additionally, an MPT benchmark was added (some structs needed to be made
public).

### Type of change

- [x] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] This change requires a documentation update

### Contents

- All tests updated.
- `prepare_witness` function removed from `witness_row.rs`.
- MPT test updated to not use `prepare_witness`.
- Benchmark added.
@github-actions github-actions bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label Aug 1, 2023
@miha-stopar miha-stopar marked this pull request as draft August 1, 2023 14:58
Base automatically changed from mpt2 to main August 10, 2023 11:27
@github-actions github-actions bot added T-bench Type: benchmark improvements crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-gadgets Issues related to the gadgets workspace member labels Aug 10, 2023
@miha-stopar
Copy link
Collaborator Author

Closed in favour of #1563. I am starting the modified extension node almost from scratch, so it was the easiest just to open a new branch (using the main which has now MPT merged).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-gadgets Issues related to the gadgets workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants