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

MPT: lo/hi + challengeAPI + preimage checks + performance improvements #1531

Merged
merged 162 commits into from
Aug 9, 2023

Conversation

Brechtpd
Copy link
Collaborator

@Brechtpd Brechtpd commented Jul 15, 2023

Description

This PR is currently against to intermediate PR #1530 that just merges in the main, so the diff is cleaner.

  • Updates the MPT branch for the latest main
  • lo/hi support
  • Challenge API integration
  • keccak endianness change
  • Added preimage checks for keys used in the tree paths
  • Performance improvements (expressions degree can and is reduced to 5)
  • Misc other small improvements

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?

Brechtpd and others added 30 commits April 9, 2023 01:47
# Conflicts:
#	Cargo.lock
#	gadgets/src/util.rs
#	zkevm-circuits/Cargo.toml
#	zkevm-circuits/src/bytecode_circuit/dev.rs
#	zkevm-circuits/src/evm_circuit.rs
#	zkevm-circuits/src/evm_circuit/step.rs
#	zkevm-circuits/src/evm_circuit/util.rs
#	zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs
#	zkevm-circuits/src/lib.rs
#	zkevm-circuits/src/table.rs
#	zkevm-circuits/src/tx_circuit.rs
#	zkevm-circuits/src/util.rs
#	zkevm-circuits/src/witness/mpt.rs
hero78119 and others added 16 commits July 4, 2023 08:12
…#1486)

### Description

Add overall summary for cell utilization

### Issue Link

N/A

### Type of change

- [x] New feature (non-breaking change which adds functionality)

### Contents

- sum of `available_cells`
- sum of `unused_cells`
- Utilization `#unused_cells`/`#available_cells`

### Example output
#### Storage_1
```
Main:
+-----------------------------------+------------------------------+-------------------------+
| "storage_1" total_available_cells | "storage_1" total_used_cells | "storage_1" Utilization (%) |
+-----------------------------------+------------------------------+-------------------------+
| 25480                             | 6482                         | 25.4                    |
+-----------------------------------+------------------------------+-------------------------+

Word-lo-hi
+-----------------------------------+------------------------------+-----------------------------+
| "storage_1" total_available_cells | "storage_1" total_used_cells | "storage_1" Utilization (%) |
+-----------------------------------+------------------------------+-----------------------------+
| 24080                             | 7078                         | 29.4                        |
+-----------------------------------+------------------------------+-----------------------------+
```

#### Storage_2
```
Main
+-----------------------------------+------------------------------+-------------------------+
| "storage_2" total_available_cells | "storage_2" total_used_cells | "storage_2" Utilization |
+-----------------------------------+------------------------------+-------------------------+
| 1456                              | 467                          | 32.1                    |
+-----------------------------------+------------------------------+-------------------------+

Word-lo-hi
+-----------------------------------+------------------------------+-----------------------------+
| "storage_2" total_available_cells | "storage_2" total_used_cells | "storage_2" Utilization (%) |
+-----------------------------------+------------------------------+-----------------------------+
| 1376                              | 14                           | 1.0                         |
+-----------------------------------+------------------------------+-----------------------------+
```

#### Byte_lookup
```
Main

+-------------------------------------+--------------------------------+---------------------------+
| "byte_lookup" total_available_cells | "byte_lookup" total_used_cells | "byte_lookup" Utilization |
+-------------------------------------+--------------------------------+---------------------------+
| 8736                                | 6786                           | 77.7                      |
+-------------------------------------+--------------------------------+---------------------------+

Word-lo-hi
+-------------------------------------+--------------------------------+-------------------------------+
| "byte_lookup" total_available_cells | "byte_lookup" total_used_cells | "byte_lookup" Utilization (%) |
+-------------------------------------+--------------------------------+-------------------------------+
| 8256                                | 6566                           | 79.5                          |
+-------------------------------------+--------------------------------+-------------------------------+
```
# Conflicts:
#	Cargo.lock
#	zkevm-circuits/src/state_circuit.rs
#	zkevm-circuits/src/table/keccak_table.rs
#	zkevm-circuits/src/table/mpt_table.rs
#	zkevm-circuits/src/witness/mpt.rs
### Description

We remove the witness tx struct.

We can wait for the lo-hi refactor ready then for this PR.

### Issue Link

Part of privacy-scaling-explorations#1391

### Type of change

New feature (non-breaking change which adds functionality)

### Contents

- Remove zkevm-circuits/src/witness/tx.rs entirely
- Remove eth_block field from block
- Acquire txID ASAP so we don't need a Optional<tx_id>
…s#1515)

### Description

Fixed rws padding logic and padding error handling.

### Issue Link


privacy-scaling-explorations#1507

### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

### Contents

- more documentation on padding logic
- fix max_rws calculation
- de-duplicated startop in end_block.tx by skip second one.
- panic instead of confused error log in padding calculation function.
…xplorations#1514)

### Description

Combines LookupU8 and LookupU16 under Lookup(Table).

### Issue Link

privacy-scaling-explorations#1510

### 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
- [x] Refactor

<!--

### Contents

- [_item_]

### Rationale

[_design decisions and extended information_]

### How Has This Been Tested?

[_explanation_]

<hr>

## How to fill a PR description 

Please give a concise description of your PR.

The target readers could be future developers, reviewers, and auditors.
By reading your description, they should easily understand the changes
proposed in this pull request.

MUST: Reference the issue to resolve

### Single responsability

Is RECOMMENDED to create single responsibility commits, but not
mandatory.

Anyway, you MUST enumerate the changes in a unitary way, e.g.

```
This PR contains:
- Cleanup of xxxx, yyyy
- Changed xxxx to yyyy in order to bla bla
- Added xxxx function to ...
- Refactored ....
```

### Design choices

RECOMMENDED to:
- What types of design choices did you face?
- What decisions you have made?
- Any valuable information that could help reviewers to think critically
-->

---------

Co-authored-by: Ming <hero78119@gmail.com>
### Description

circuit for invalid creation code error in create, markdown spec
privacy-scaling-explorations/zkevm-specs#400
### Issue Link

issue privacy-scaling-explorations#1291 

### Type of change

- [x] New feature (non-breaking change which adds functionality)

### Rationale

Get first byte of code to store , check it is 0xef

This PR contains:
- buss mapping: at the return opcode in create, get the first byte .
- add circuit & test 
- add tx deploy trace test .

---------

Co-authored-by: Steven Gu <asongala@163.com>
privacy-scaling-explorations#1452)

### Description

Change ethers-rs related packages from 0.17.0 to 2.0.7

### Issue Link

privacy-scaling-explorations#1451

### Type of change

- [x] New feature (non-breaking change which adds functionality)

### Rationale

We need nothing more than simply upgrading the package.
…rivacy-scaling-explorations#1517)

### Description

Remove evm_word challenge and optimize from 3->2 phase in dev phase.

### Issue Link


privacy-scaling-explorations#1516

### Type of change

- [x] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
…1500)

### Description

Introduce the `debug_expression` method to the `EVMConstraintBuilder`
which allows specifying an expression inside an ExecutionGadget to be
evaluated and printed during assignment.

This can be very useful for debugging. With this we can print the value
of cells, but also of arbitrary expressions. For example, it allows
printing the evaluation of all the expressions used in a lookup
(previous to the RLC).

### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] 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

When calling `cb.debug_expression`, the expression is stored in the
`EVMConstraintBuilder` along with a string. Later on, at assignment,
whenever a step is assigned to an `ExecutionState` that had some debug
expressions specified, those expressions will be evaluated and printed.

#### Example usage

In the `PushGadget::configure` method I include the following line:
```rust
cb.debug_expression("push.code_hash", code_hash.expr());
```
Then I run the a test that assigns this state (with `--nocapture` to see
the stdout):
```
cargo test push_gadget_simple --release --all-features -- --nocapture
```
And I will get the following:
```
Debug expression "push.code_hash"=0x178027364c9ed08d00e38dbf197bbf65e45779c1d1b9dca1a229f7b7360892ce [offset=19, step=Op(PUSH1), expr=Advice { query_index: 591, column_index: 76, rotation: Rotation(0), phase: Phase(1) }]
```

---------

Co-authored-by: Chih Cheng Liang <chihchengliang@gmail.com>
### Description

- Removed #[allow(dead_code)]  and `#![allow(unused_imports)]`.
- Removed most of the dead code. Kept a few with the "_" initial name.
- Reorganize dev modules and feature flags for "zkevm-circuits" crate. 
- ~~"test" flag is only used when test utils are shared within
"zkevm-circuits"~~ "test" flag is gone.
   - "test-util" flag is used when utils are shared with testool crate.
- "test-circuits" flag is reserved for test circuits that are shared
with integration tests.


### Issue Link


### Type of change

- [x] New feature (non-breaking change which adds functionality)


### Rationale

These are the reason I keep a method:

- The method is a sensible API and is tested. Although it is unused but
it makes sense to keep it. The `remainder` method of the Constant
Division Gadget is such an example.
- Variants in Enums. We use the `match` macro for them so it is
important we don't miss any variant. It makes sense to keep them even
when we don't use them.
- Work in progress and recent works. Cell manager and _error_depth are
examples.

I remove a method or a gadget for these reasons.

- If it has been there for a long time but never used.
- Default removing them to question us hard if the gadget really sparks
joy. batched_is_zero and binary number gadgets are such cases.

### How Has This Been Tested?

```
cargo build --all-features
cargo test // just for build, without running the full tests
```
…acy-scaling-explorations#1524)

### Description

- rm deprecated, unreachable_code
- doc some parts.

### Issue Link

part of  privacy-scaling-explorations#1494

### Type of change

- [ ] New feature (non-breaking change which adds functionality)
# Conflicts:
#	Cargo.lock
#	zkevm-circuits/src/state_circuit.rs
#	zkevm-circuits/src/table/mpt_table.rs
#	zkevm-circuits/src/witness/mpt.rs
@github-actions github-actions bot added crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements labels Jul 15, 2023
@Brechtpd Brechtpd mentioned this pull request Jul 15, 2023
4 tasks
Copy link
Collaborator

@miha-stopar miha-stopar left a comment

Choose a reason for hiding this comment

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

Wonderful!!

meta.lookup_any(lookup.description, |_meta| {
let table = self.get_dynamic_table_values(*lookup_name);
meta.lookup_any(lookup.description, |meta| {
// Fixed lookup is a direct lookup into the pre-difined fixed tables
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: pre-difined -> pre-defined

@adria0
Copy link
Member

adria0 commented Jul 28, 2023

@Brechtpd which witness generation repo I should use to test it?

I checked with https://github.com/privacy-scaling-explorations/mpt-witness-generator and https://github.com/CeciliaZ030/mpt-witness-generator but none of them works. Or maybe I'm doing something wrong.

@Brechtpd
Copy link
Collaborator Author

Oh it's the one linked above that's currently still a PR on the PSE repo: privacy-scaling-explorations/mpt-witness-generator#3.

@adria0
Copy link
Member

adria0 commented Jul 28, 2023

Oh it's the one linked above that's currently still a PR on the PSE repo: privacy-scaling-explorations/mpt-witness-generator#3.

Thanks @Brechtpd !

@adria0 adria0 self-requested a review August 8, 2023 14:18
@adria0 adria0 merged commit 3c5fbfd into privacy-scaling-explorations:mpt-main-sync Aug 9, 2023
7 checks passed
Brechtpd added a commit that referenced this pull request Aug 9, 2023
### Description

Just merges the MPT branch with the master, without fixing any issues
(and so breaks the code). The actual merge is done in
#1531,
the only purpose of this PR is to have a nicer diff for the other PR
without breaking the code in the current `mpt2` branch.

### 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)
- [X] 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?
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
crate-circuit-benchmarks Issues related to the circuit-benchmarks 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.