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

feat: Create a verify_decoded_mpt_node for a circuit #284

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
89b6731
add a preliminary set of logic for verifying decoded lits.
hidenori-shinohara Nov 8, 2023
28aefe0
Add logic for MPTVariable and one simple test that passes
hidenori-shinohara Nov 8, 2023
5ccba6d
Start using MPTVariable in DecodeHint, tests do not pass yet.
hidenori-shinohara Nov 8, 2023
e782c52
Split the circuit into `decode_mpt_node` and `verify_decoded_mpt_node…
hidenori-shinohara Nov 8, 2023
69f6cd7
Remove LIST_LEN since it's getting quite confusing
hidenori-shinohara Nov 8, 2023
0dab5d8
Add a simple test for verify_decoded_mpt_node
hidenori-shinohara Nov 8, 2023
3ae1bb2
Implement MPTVariable::elements<F> and add a test
hidenori-shinohara Nov 8, 2023
cd35c37
Add a new definition for `MPTVariable` using the `CircuitVariable` tr…
hidenori-shinohara Nov 9, 2023
7917919
Remove the MPTVariable definition, as we already have one with the Ci…
hidenori-shinohara Nov 9, 2023
c957691
Remove the remaining references to the old MPTVariable that I just de…
hidenori-shinohara Nov 9, 2023
07e0026
Fix `test_verify_decoded_mpt_node` so now it fails as expected. (I ha…
hidenori-shinohara Nov 9, 2023
24da8c9
Finish writing the logic for `verify_decoded_mpt_node`. The test fail…
hidenori-shinohara Nov 9, 2023
70bbe79
Add `watch` to visually compare the expected value and the actual out…
hidenori-shinohara Nov 9, 2023
64d8dd6
clean up the logging statements
hidenori-shinohara Nov 9, 2023
feeb37f
Continue to work on verify_decode_mpt_node. Fix some obvious bugs and…
hidenori-shinohara Nov 9, 2023
8a56258
Highlight some important comments about temporary changes since we ca…
hidenori-shinohara Nov 9, 2023
8ad1ce1
Update stuff in both the non-circuit verification logic/tests and the…
hidenori-shinohara Nov 9, 2023
7027696
Readability commit. Add more comments and update some variable names.…
hidenori-shinohara Nov 9, 2023
d12cec3
Fix an obvious bug. Tests still fail.
hidenori-shinohara Nov 9, 2023
2ac02c0
I am aware of a few more issues, but if challenger = 1, the tests pas…
hidenori-shinohara Nov 9, 2023
c993ab1
Start working on a different abstraction `calculate_polynomial_emulat…
hidenori-shinohara Nov 9, 2023
d701674
My first pass of calculate_polynomial_emulating_rlp_encoding, tests s…
hidenori-shinohara Nov 9, 2023
f32dd03
Tests pass when challenger = 1. Tests fail when challenger != 1. Indi…
hidenori-shinohara Nov 9, 2023
c8e6146
Fix a signficant bug on powers. Not all tests pass yet.
hidenori-shinohara Nov 9, 2023
d771521
All tests pass. This fixes a bug and removes debugging statements. Te…
hidenori-shinohara Nov 9, 2023
fdc26dd
Add a "negative" test that is expected to fail.
hidenori-shinohara Nov 9, 2023
1e1d9ee
Readability
hidenori-shinohara Nov 9, 2023
6953b4d
factor out the prefix-shift logic
hidenori-shinohara Nov 10, 2023
08e1e2c
I found a bug, and this commit adds a test case
hidenori-shinohara Nov 10, 2023
86114bc
This now works with case 1 (<= 55 bytes) and case 2 (<= 255 bytes). c…
hidenori-shinohara Nov 10, 2023
0d2414c
Fix bugs, now all tests seem to pass
hidenori-shinohara Nov 10, 2023
fd23111
Clean up the unused imports
hidenori-shinohara Nov 10, 2023
8702eaa
clean up comments
hidenori-shinohara Nov 10, 2023
ee4b81b
add a simple test for single bytes
hidenori-shinohara Nov 10, 2023
4a9d4ef
Add div_rem to U32Variable
hidenori-shinohara Nov 10, 2023
71c62f5
Clean up the div_mod operation with the newly implemented function fr…
hidenori-shinohara Nov 10, 2023
039b945
Add `calculate_polynomial_emulating_rlp_encoding_cubic` but I don't u…
hidenori-shinohara Nov 10, 2023
d33f5d8
Tests pass with CubicElement
hidenori-shinohara Nov 10, 2023
c2c57cd
Adds random_seeds to CircuitBuilder
hidenori-shinohara Nov 10, 2023
afc1984
seeds seem to be working!
hidenori-shinohara Nov 10, 2023
b6aba48
Remove the seed code as we already have the challenger that takes the…
hidenori-shinohara Nov 10, 2023
8a28f32
Make sure that we observe all the inputs for the decode verification
hidenori-shinohara Nov 11, 2023
1187979
Remove the loop which is now unnecessary since we have a cubic extens…
hidenori-shinohara Nov 11, 2023
1f4b28d
Remove unused imports
hidenori-shinohara Nov 11, 2023
e3d6f3e
minor cleanups
hidenori-shinohara Nov 11, 2023
5481057
Minor typos
hidenori-shinohara Nov 11, 2023
fdec6dd
Clean up a TODO
hidenori-shinohara Nov 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plonky2x/core/src/frontend/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
self.beaconchain_api_client = Some(client);
}

/// Adds all the constraints nedded before building the circuit and registering hints.
/// Adds all the constraints needed before building the circuit and registering hints.
fn pre_build(&mut self) {
let blake2b_accelerator = self.blake2b_accelerator.clone();
if let Some(accelerator) = blake2b_accelerator {
Expand Down
22 changes: 10 additions & 12 deletions plonky2x/core/src/frontend/eth/mpt/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
value: Bytes32Variable,
) {
const ELEMENT_LEN: usize = 32; // Maximum size of list element
const LIST_LEN: usize = 17; // Maximum length of the list for each proof element

let tree_radix = self.constant::<Variable>(L::Field::from_canonical_u8(16u8));
let branch_node_length = self.constant::<Variable>(L::Field::from_canonical_u8(17u8));
Expand Down Expand Up @@ -135,17 +134,16 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
self.assert_is_equal(checked_equality, t);
}

let (decoded_list, decoded_element_lens, len_decoded_list) = self
.decode_element_as_list::<ENCODING_LEN, LIST_LEN, ELEMENT_LEN>(
current_node,
len_nodes[i],
finished,
);
let mpt_node = self.decode_mpt_node::<ENCODING_LEN, ELEMENT_LEN>(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is cleaner lol

current_node,
len_nodes[i],
finished,
);

let is_branch = self.is_equal(len_decoded_list, branch_node_length);
let is_leaf = self.is_equal(len_decoded_list, leaf_or_extension_node_length);
let is_branch = self.is_equal(mpt_node.len, branch_node_length);
let is_leaf = self.is_equal(mpt_node.len, leaf_or_extension_node_length);
let key_terminated = self.is_equal(current_key_idx, const_64);
let path = decoded_list[0].as_slice().to_vec().to_nibbles(self);
let path = mpt_node.data[0].as_slice().to_vec().to_nibbles(self);
let prefix = path[0];
let prefix_leaf_even = self.is_equal(prefix, prefix_leaf_even);
let prefix_leaf_odd = self.is_equal(prefix, prefix_leaf_odd);
Expand Down Expand Up @@ -173,7 +171,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
let updated_current_node_id_idx = self.add(c, case_3_value); // TODO: make this more concise

let updated_current_node_id =
self.select_array(decoded_list.as_slice(), updated_current_node_id_idx);
self.select_array(mpt_node.data.as_slice(), updated_current_node_id_idx);
// If finished == 1, then we should not update the current_node_id
current_node_id = self.select_array(
&[updated_current_node_id, current_node_id],
Expand All @@ -185,7 +183,7 @@ impl<L: PlonkParameters<D>, const D: usize> CircuitBuilder<L, D> {
let d = self.or(prefix_extension_even, prefix_extension_odd);
do_path_remainder_check = self.and(do_path_remainder_check, d);

let e = self.mul(decoded_element_lens[0], two);
let e = self.mul(mpt_node.lens[0], two);
let f = self.mul(offset, do_path_remainder_check.variable);
let mut check_length = self.sub(e, f);
check_length = self.mul(check_length, do_path_remainder_check.variable);
Expand Down
Loading
Loading