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: add dummy circuit to final extraction for indexing Data with no provable extraction #415

Open
wants to merge 153 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
cd191cd
feat: allow for either aggregation-only or tabular-only queries
delehef Sep 10, 2024
719a0c0
Add Merkle-path verification gadget
nicholas-mainardi Sep 11, 2024
3794779
merge MPT extraction
nikkolasg Sep 12, 2024
3793aa1
is_multiplier
nikkolasg Sep 12, 2024
ebdd33a
multiplier for rows
nikkolasg Sep 12, 2024
071a2f0
and api
nikkolasg Sep 12, 2024
ac3443e
Add revelation circuit unproven offset
nicholas-mainardi Sep 12, 2024
3b735cd
refactoring of cell logic
nikkolasg Sep 13, 2024
2b3c289
wip
nikkolasg Sep 13, 2024
d3ae335
row leaf passing
nikkolasg Sep 13, 2024
ff8039c
Add APIs for simple select
nicholas-mainardi Sep 13, 2024
5079597
Update general query APIs
nicholas-mainardi Sep 13, 2024
36673ef
partial fixed
nikkolasg Sep 13, 2024
6713f66
full node fixed
nikkolasg Sep 13, 2024
90f8d1c
row tree test passing
nikkolasg Sep 13, 2024
3fe4b55
Fix build integration test
nicholas-mainardi Sep 13, 2024
8dcdc05
testing merge circuit
nikkolasg Sep 13, 2024
0ea3f41
API for merge
nikkolasg Sep 13, 2024
2d7de6f
adding one more circuit set size
nikkolasg Sep 13, 2024
f8a79d1
Fix build groth-16 crate
nicholas-mainardi Sep 13, 2024
e9c3bcb
wip
nikkolasg Sep 15, 2024
dbb8e7a
Refactor query test cases code
nicholas-mainardi Sep 16, 2024
799a60f
Merge with main
nicholas-mainardi Sep 16, 2024
b26ea94
fix: ORDER BY is not supported
delehef Sep 16, 2024
a36fd13
Merge pull request #355 from Lagrange-Labs/feat/drop-scalar-check
nikkolasg Sep 16, 2024
dfaa7d7
WiP: keep both queries types in a single test
nicholas-mainardi Sep 16, 2024
8fc299f
Merge branch 'main' into feat/tabular-queries
nicholas-mainardi Sep 16, 2024
76a4bdd
wip
nikkolasg Sep 17, 2024
4f7aec5
compiling
nikkolasg Sep 17, 2024
c0bb9a6
Merge branch 'feat/tabular-queries' into feat/unproven-limit-offset-q…
nicholas-mainardi Sep 18, 2024
28a3383
Working intergation test for simple select queries
nicholas-mainardi Sep 18, 2024
c3c199d
fmt
nicholas-mainardi Sep 18, 2024
170ad44
Run also commented test cases
nicholas-mainardi Sep 18, 2024
676dfec
Bind matching row keys and results in a single query
nicholas-mainardi Sep 18, 2024
34d88ec
Remove dead code
nicholas-mainardi Sep 18, 2024
689b929
Add distinct to circuit and Parsil
nicholas-mainardi Sep 19, 2024
56e0dde
Support DISTINCT and SELECT * queries in integration test
nicholas-mainardi Sep 19, 2024
17cd47f
Comment out test cases
nicholas-mainardi Sep 19, 2024
84fe37a
passing test
nikkolasg Sep 19, 2024
cd59ea3
More complex test case with wildcards
nicholas-mainardi Sep 19, 2024
d8bc019
integrated test refactor #1
nikkolasg Sep 19, 2024
1fb227d
refactoring #2 compiling
nikkolasg Sep 20, 2024
735b415
correct size of circuit set
nikkolasg Sep 20, 2024
cebaf1c
full refactoring #3
nikkolasg Sep 20, 2024
a1274ae
multiplier columns
nikkolasg Sep 20, 2024
aee4872
test case for merge
nikkolasg Sep 20, 2024
2ea4e0d
add metadata from contract
nikkolasg Sep 20, 2024
99022b6
merge updates
nikkolasg Sep 21, 2024
1024dbe
default sec cell
nikkolasg Sep 21, 2024
abd9989
debug storage root
nikkolasg Sep 21, 2024
c7bea49
fixing block
nikkolasg Sep 21, 2024
12e083f
ordered cells
nikkolasg Sep 21, 2024
f6a5647
more debug
nikkolasg Sep 21, 2024
4368993
debug
nikkolasg Sep 21, 2024
1d4c10e
fixing vdb row digest
nikkolasg Sep 21, 2024
e0ad8d5
correct update depending on type
nikkolasg Sep 21, 2024
8407145
fixing update of mapping
nikkolasg Sep 21, 2024
6352db1
final test
nikkolasg Sep 21, 2024
84cd5cb
handle deletion for single
nikkolasg Sep 21, 2024
619c950
multiple rows
nikkolasg Sep 22, 2024
ab88009
Update verifiable-db/src/cells_tree/api.rs
nikkolasg Sep 23, 2024
c580c01
Update verifiable-db/src/cells_tree/api.rs
nikkolasg Sep 23, 2024
2c51871
reviews first pass
nikkolasg Sep 23, 2024
8184bd3
correct conditional scalar mul
nikkolasg Sep 23, 2024
8b30e6a
better API
nikkolasg Sep 23, 2024
3b83417
more debug
nikkolasg Sep 23, 2024
e5635d0
more debug
nikkolasg Sep 23, 2024
1d05c47
Optimize SQL queries to get Merkle-path
nicholas-mainardi Sep 23, 2024
f877735
testing split digest
nikkolasg Sep 23, 2024
90e4d42
with correct name
nikkolasg Sep 23, 2024
5e057ed
more tests
nikkolasg Sep 23, 2024
9020e54
fixes
nikkolasg Sep 23, 2024
c90e821
query adaptable
nikkolasg Sep 23, 2024
edad5fa
putting back ignoring query
nikkolasg Sep 23, 2024
71c2ce7
Merge branch 'main' into feat/merge_table
nikkolasg Sep 23, 2024
8ce5ca1
Fix non-existence proven node selection
nicholas-mainardi Sep 25, 2024
185ff79
Comment to clarify non-existence node selection logic
nicholas-mainardi Sep 25, 2024
994a115
Check query upper bounds in Parsil + add LIMIT to query if missing
nicholas-mainardi Sep 26, 2024
5fd774f
Refactor revelation APIs to avoid calling ids_for_placeholder_hash
nicholas-mainardi Sep 26, 2024
c89fc0f
Add comment for cells tree hash construction
nicholas-mainardi Sep 27, 2024
0f706cf
Fix: ensure we always use the appropriate merge flag in rows tre circ…
nicholas-mainardi Oct 1, 2024
5a656bd
Merkle path with predecessor/successor gadget
nicholas-mainardi Oct 4, 2024
0cd9487
Merge branch 'main' into feat/merge_table
nikkolasg Oct 10, 2024
61dc87a
Universal query gadgets + refactor universal query circuit
nicholas-mainardi Oct 10, 2024
40ecb96
fmt
nicholas-mainardi Oct 10, 2024
f772131
Add universal_query_gadget file
nicholas-mainardi Oct 10, 2024
5916860
Merge branch 'feat/merge_table' into feat/tabular-queries
nicholas-mainardi Oct 15, 2024
9002398
Merge branch 'feat/tabular-queries' into feat/unproven-limit-offset-q…
nicholas-mainardi Oct 15, 2024
c87856f
Add LIMIT by default only in simple SELECT queries
nicholas-mainardi Oct 15, 2024
c7bd811
Avoid running wildcard queries on merged tables
nicholas-mainardi Oct 15, 2024
a5a6962
Fix parsil test
nicholas-mainardi Oct 15, 2024
94dca85
fix: MemoryStorage::all_keys_at should not return dead keys
delehef Oct 17, 2024
e58faee
feat: add random_key_at
delehef Oct 17, 2024
3644f27
Row processing + consecutive rows gadgets
nicholas-mainardi Oct 18, 2024
bfe76a9
Add untracked files
nicholas-mainardi Oct 21, 2024
63f1b05
More unit tests for are_consecutive_rows gadget
nicholas-mainardi Oct 21, 2024
cb2355f
WiP: aggregate chunks gadget
nicholas-mainardi Oct 22, 2024
9970724
WiP: aggregate chunks unit test
nicholas-mainardi Oct 23, 2024
a01cc95
Unit test for aggregate_chunks gadget
nicholas-mainardi Oct 24, 2024
600a6e9
Address comments
nicholas-mainardi Oct 25, 2024
85cdb54
Merge branch 'feat/merge_table' into feat/tabular-queries
nicholas-mainardi Oct 29, 2024
791ba8a
Merge branch 'feat/tabular-queries' into feat/unproven-limit-offset-q…
nicholas-mainardi Oct 29, 2024
e17ff40
Merge branch 'feat/unproven-limit-offset-queries' into feat/merkle-pa…
nicholas-mainardi Oct 29, 2024
5e2df85
Simple Select Queries with Unchecked Offset (#365)
nicholas-mainardi Oct 29, 2024
55e0421
Merge branch 'feat/tabular-queries' into feat/merkle-path-with-succes…
nicholas-mainardi Oct 29, 2024
1b7a41c
Fix build
nicholas-mainardi Oct 30, 2024
5483d50
chore: clippy
delehef Oct 31, 2024
845d900
Row chunk batching circuit
nicholas-mainardi Nov 4, 2024
60d3f34
[parsil] correctly handle LIMIT/OFFSET
delehef Nov 5, 2024
35d9623
[mp2] use more explicit names
delehef Nov 5, 2024
5bb0490
fix: imports
delehef Nov 5, 2024
e6d5701
Chunk aggregation circuit
nicholas-mainardi Nov 6, 2024
2e32687
Merge branch 'main' into feat/tabular-queries
nicholas-mainardi Nov 6, 2024
3644f30
Fix integration test + fmt
nicholas-mainardi Nov 6, 2024
6a27c73
use u32's for offset & limit
delehef Nov 6, 2024
ec32679
Fix test failing from time to time
nicholas-mainardi Nov 6, 2024
b5c5c4f
Non-existence circuit
nicholas-mainardi Nov 7, 2024
a65bf3b
merged with main
nikkolasg Nov 7, 2024
d23c0b7
add reset-db to devenv
delehef Nov 7, 2024
cd3da2d
Api for batching circuits
nicholas-mainardi Nov 8, 2024
d008cf8
Update result check + re-enable test with nonexisting secondary index
nicholas-mainardi Nov 8, 2024
62bb4d0
Test api for batching circuits
nicholas-mainardi Nov 11, 2024
d245bed
Revelation batching circuit
nicholas-mainardi Nov 12, 2024
cd47667
Include batching circuits in verifiable-db APIs
nicholas-mainardi Nov 12, 2024
c8f4bff
Merge branch 'feat/tabular-queries' into feat/merkle-path-with-succes…
nicholas-mainardi Nov 13, 2024
a3493fd
Merge branch 'feat/merkle-path-with-successor-gadget' into feat/batch…
nicholas-mainardi Nov 13, 2024
5787dc7
Address coments
nicholas-mainardi Nov 13, 2024
59bf6a2
Merge branch 'feat/batching_circuit_gadgets' into feat/batching_circuits
nicholas-mainardi Nov 13, 2024
6bf57e9
Woring integration test for batching queries
nicholas-mainardi Nov 16, 2024
d2dbeb2
Refactor TreeFetcher trait methods + fix build in all crates
nicholas-mainardi Nov 24, 2024
36c7bf0
Add UpdateTree for batching planner
nicholas-mainardi Nov 29, 2024
9ef67c0
Escape docs of batching planner to avoid interpreting them as doc-tests
nicholas-mainardi Nov 29, 2024
71513df
Merge branch 'main' into feat/merkle-path-with-successor-gadget
nicholas-mainardi Nov 30, 2024
e110090
Add dummy circuit to final extraction.
silathdiir Nov 27, 2024
3bf074c
fmt
nicholas-mainardi Dec 2, 2024
4728ed6
Merge branch 'feat/merkle-path-with-successor-gadget' into feat/batch…
nicholas-mainardi Dec 2, 2024
b257145
Address comments
nicholas-mainardi Dec 2, 2024
dce1d6a
Add renamed file
nicholas-mainardi Dec 2, 2024
67b92a4
Merge branch 'feat/batching_circuit_gadgets' into feat/batching_circuits
nicholas-mainardi Dec 3, 2024
9f25e3f
fmt
nicholas-mainardi Dec 3, 2024
27ef2df
Address comments
nicholas-mainardi Dec 3, 2024
9560978
Merge branch 'feat/batching_circuits' into feat/batching_integration_…
nicholas-mainardi Dec 4, 2024
8c1455d
Fix doc test
nicholas-mainardi Dec 4, 2024
0b9c80f
Replace query params with batching circuits + use batching public inp…
nicholas-mainardi Dec 6, 2024
593c937
Restructure verifiable-db query + fix dependent crates
nicholas-mainardi Dec 6, 2024
349f9d2
clippy + fmt
nicholas-mainardi Dec 6, 2024
2e7db73
Test distinct in revelation circuit tabular queries
nicholas-mainardi Dec 6, 2024
cf681c3
Working rust toolchain
nicholas-mainardi Dec 6, 2024
0666bb9
Address review comments
nicholas-mainardi Dec 11, 2024
5767a7a
Remove merge_flag from circuit + revert changes on integration test
nicholas-mainardi Dec 12, 2024
4208bb8
Merge branch 'fix/remove_old_query_circuits' into indexing-with-no-pr…
nicholas-mainardi Dec 12, 2024
73cc259
Update APIs
nicholas-mainardi Dec 12, 2024
26b090a
Integration test for off-chain data
nicholas-mainardi Dec 13, 2024
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
810 changes: 538 additions & 272 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions groth16-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ itertools.workspace = true
rand.workspace = true
serial_test.workspace = true
sha2.workspace = true
mp2_test = { path = "../mp2-test" }

recursion_framework = { path = "../recursion-framework" }
verifiable-db = { path = "../verifiable-db" }
7 changes: 6 additions & 1 deletion groth16-framework/tests/common/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
use super::{NUM_PREPROCESSING_IO, NUM_QUERY_IO};
use groth16_framework::{compile_and_generate_assets, utils::clone_circuit_data};
use mp2_common::{C, D, F};
use mp2_test::circuit::TestDummyCircuit;
use recursion_framework::framework_testing::TestingRecursiveCircuits;
use verifiable_db::{
api::WrapCircuitParams,
query::pi_len,
revelation::api::Parameters as RevelationParameters,
test_utils::{
INDEX_TREE_MAX_DEPTH, MAX_NUM_COLUMNS, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS,
Expand Down Expand Up @@ -40,6 +42,8 @@ impl TestContext {

// Generate a fake query circuit set.
let query_circuits = TestingRecursiveCircuits::<F, C, D, NUM_QUERY_IO>::default();
let dummy_universal_circuit =
TestDummyCircuit::<{ pi_len::<MAX_NUM_ITEMS_PER_OUTPUT>() }>::build();

// Create the revelation parameters.
let revelation_params = RevelationParameters::<
Expand All @@ -52,7 +56,8 @@ impl TestContext {
MAX_NUM_ITEMS_PER_OUTPUT,
MAX_NUM_PLACEHOLDERS,
>::build(
query_circuits.get_recursive_circuit_set(),
query_circuits.get_recursive_circuit_set(), // unused, so we provide a dummy one
dummy_universal_circuit.circuit_data().verifier_data(),
preprocessing_circuits.get_recursive_circuit_set(),
preprocessing_circuits
.verifier_data_for_input_proofs::<1>()
Expand Down
2 changes: 1 addition & 1 deletion mp2-common/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod test {
// holder: 0x188b264aa1456b869c3a92eeed32117ebb835f47
// NFT id https://opensea.io/assets/ethereum/0xbd3531da5cf5857e7cfaa92426877b022e612cf8/1116
let mapping_value =
Address::from_str("0x188B264AA1456B869C3a92eeeD32117EbB835f47").unwrap();
Address::from_str("0x29469395eAf6f95920E59F858042f0e28D98a20B").unwrap();
let nft_id: u32 = 1116;
let mapping_key = left_pad32(&nft_id.to_be_bytes());
let url = get_mainnet_url();
Expand Down
2 changes: 2 additions & 0 deletions mp2-common/src/group_hashing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ impl ToTargets for QuinticExtensionTarget {
}

impl FromTargets for CurveTarget {
const NUM_TARGETS: usize = CURVE_TARGET_LEN;

fn from_targets(t: &[Target]) -> Self {
assert!(t.len() >= CURVE_TARGET_LEN);
let x = QuinticExtensionTarget(t[0..EXTENSION_DEGREE].try_into().unwrap());
Expand Down
2 changes: 2 additions & 0 deletions mp2-common/src/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub type OutputHash = Array<U32Target, PACKED_HASH_LEN>;
pub type OutputByteHash = Array<Target, HASH_LEN>;

impl FromTargets for OutputHash {
const NUM_TARGETS: usize = PACKED_HASH_LEN;

fn from_targets(t: &[Target]) -> Self {
OutputHash::from_array(array::from_fn(|i| U32Target(t[i])))
}
Expand Down
9 changes: 4 additions & 5 deletions mp2-common/src/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,9 @@ impl<F: SerializableRichField<D>, const D: usize> CircuitBuilderU256<F, D>
left: &UInt256Target,
right: &UInt256Target,
) -> BoolTarget {
// left <= right iff left - right requires a borrow or left - right == 0
let (res, borrow) = self.sub_u256(left, right);
let less_than = BoolTarget::new_unsafe(borrow.0);
let is_eq = self.is_zero(&res);
self.or(less_than, is_eq)
// left <= right iff ! right < left
let is_greater = self.is_less_than_u256(right, left);
self.not(is_greater)
}

fn is_zero(&mut self, target: &UInt256Target) -> BoolTarget {
Expand Down Expand Up @@ -827,6 +825,7 @@ impl ToTargets for UInt256Target {
}

impl FromTargets for UInt256Target {
const NUM_TARGETS: usize = NUM_LIMBS;
// Expects big endian limbs as the standard format for IO
fn from_targets(t: &[Target]) -> Self {
Self::new_from_be_target_limbs(&t[..NUM_LIMBS]).unwrap()
Expand Down
60 changes: 45 additions & 15 deletions mp2-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{anyhow, Result};
use itertools::Itertools;
use plonky2::field::extension::Extendable;
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::hash::hash_types::{HashOut, HashOutTarget, RichField};
use plonky2::hash::hash_types::{HashOut, HashOutTarget, RichField, NUM_HASH_OUT_ELTS};
use plonky2::iop::target::{BoolTarget, Target};
use plonky2::iop::witness::{PartialWitness, WitnessWrite};
use plonky2::plonk::circuit_builder::CircuitBuilder;
Expand All @@ -19,26 +19,25 @@ use sha3::Keccak256;

use crate::array::Targetable;
use crate::poseidon::{HashableField, H};
use crate::serialization::circuit_data_serialization::SerializableRichField;
use crate::{group_hashing::EXTENSION_DEGREE, types::HashOutput, ProofTuple};
use crate::{D, F};

const TWO_POWER_8: usize = 256;
const TWO_POWER_16: usize = 65536;
const TWO_POWER_24: usize = 16777216;

#[allow(dead_code)]
trait ConnectSlice {
fn connect_slice(&mut self, a: &[Target], b: &[Target]);
// check that the closure $f actually panics, printing $msg as error message if the function
// did not panic; this macro is employed in tests in place of #[should_panic] to ensure that a
// panic occurred in the expected function rather than in other parts of the test
#[macro_export]
macro_rules! check_panic {
($f: expr, $msg: expr) => {{
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe($f));
assert!(result.is_err(), $msg);
}};
}

impl ConnectSlice for CircuitBuilder<F, D> {
fn connect_slice(&mut self, a: &[Target], b: &[Target]) {
assert_eq!(a.len(), b.len());
for (ai, bi) in a.iter().zip(b) {
self.connect(*ai, *bi);
}
}
}
pub use check_panic;

pub fn verify_proof_tuple<
F: RichField + Extendable<D>,
Expand Down Expand Up @@ -326,17 +325,20 @@ pub fn pack_and_compute_poseidon_target<F: HashableField + Extendable<D>, const
b.hash_n_to_hash_no_pad::<H>(packed)
}

pub trait SelectHashBuilder {
pub trait HashBuilder {
/// Select `first_hash` or `second_hash` as output depending on the Boolean `cond`
fn select_hash(
&mut self,
cond: BoolTarget,
first_hash: &HashOutTarget,
second_hash: &HashOutTarget,
) -> HashOutTarget;

/// Determine whether `first_hash == second_hash`
fn hash_eq(&mut self, first_hash: &HashOutTarget, second_hash: &HashOutTarget) -> BoolTarget;
}

impl<F: RichField + Extendable<D>, const D: usize> SelectHashBuilder for CircuitBuilder<F, D> {
impl<F: RichField + Extendable<D>, const D: usize> HashBuilder for CircuitBuilder<F, D> {
fn select_hash(
&mut self,
cond: BoolTarget,
Expand All @@ -352,6 +354,28 @@ impl<F: RichField + Extendable<D>, const D: usize> SelectHashBuilder for Circuit
.collect_vec(),
)
}

fn hash_eq(&mut self, first_hash: &HashOutTarget, second_hash: &HashOutTarget) -> BoolTarget {
let _true = self._true();
first_hash
.elements
.iter()
.zip(second_hash.elements.iter())
.fold(_true, |acc, (first, second)| {
let is_eq = self.is_equal(*first, *second);
self.and(acc, is_eq)
})
}
}

pub trait SelectTarget {
/// Return `first` if `cond` is true, `second` otherwise
fn select<F: SerializableRichField<D>, const D: usize>(
b: &mut CircuitBuilder<F, D>,
cond: &BoolTarget,
first: &Self,
second: &Self,
) -> Self;
}

pub trait ToFields<F: RichField> {
Expand Down Expand Up @@ -414,10 +438,16 @@ impl<F: RichField> Fieldable<F> for u64 {
}

pub trait FromTargets {
/// Number of targets necessary to instantiate `Self`
const NUM_TARGETS: usize;

/// Number of targets in `t` must be at least `Self::NUM_TARGETS`
fn from_targets(t: &[Target]) -> Self;
}

impl FromTargets for HashOutTarget {
const NUM_TARGETS: usize = NUM_HASH_OUT_ELTS;

fn from_targets(t: &[Target]) -> Self {
HashOutTarget {
elements: create_array(|i| t[i]),
Expand Down
42 changes: 41 additions & 1 deletion mp2-v1/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Main APIs and related structures

use std::iter::once;
use std::{collections::BTreeSet, iter::once};

use crate::{
block_extraction,
contract_extraction::{self, compute_metadata_digest as contract_metadata_digest},
final_extraction,
indexing::ColumnID,
length_extraction::{
self, compute_metadata_digest as length_metadata_digest, LengthCircuitInput,
},
Expand All @@ -20,11 +21,14 @@ use anyhow::Result;
use itertools::Itertools;
use mp2_common::{
digest::Digest,
group_hashing::map_to_curve_point,
poseidon::H,
types::HashOutput,
utils::{Fieldable, ToFields},
F,
};
use plonky2::{
field::types::Field,
iop::target::Target,
plonk::config::{GenericHashOut, Hasher},
};
Expand Down Expand Up @@ -141,6 +145,9 @@ pub fn generate_proof(params: &PublicParameters, input: CircuitInput) -> Result<
length_circuit_set,
)
}
final_extraction::CircuitInput::NoProvable(input) => {
params.final_extraction.generate_no_provable_proof(input)
}
}
}
CircuitInput::CellsTree(input) => verifiable_db::api::generate_proof(
Expand Down Expand Up @@ -243,3 +250,36 @@ pub fn metadata_hash(
// compute final hash
combine_digest_and_block(contract_digest + value_digest)
}

// compute metadata digest for a table including no provable extraction data:
// it corresponds to the digest of the column identifiers
pub(crate) fn no_provable_metadata_digest<I: IntoIterator<Item = ColumnID>>(
column_ids: I,
) -> Digest {
map_to_curve_point(
&column_ids
.into_iter()
.collect::<BTreeSet<_>>() // collect into a BTreeSet to ensure they are hashed
// in a deterministic order
.into_iter()
.map(F::from_canonical_u64)
.collect_vec(),
)
}

/// Compute the metadata hash for a table including no provable extraction data.
/// The input is the set of the column identifiers of the table
pub fn no_provable_metadata_hash<I: IntoIterator<Item = ColumnID>>(column_ids: I) -> MetadataHash {
let metadata_digest = no_provable_metadata_digest(column_ids);
// Add the prefix to the metadata digest to ensure the metadata digest
// will keep track of whether we use this dummy circuit or not.
// It's similar logic as the dummy circuit of final extraction.
let prefix = final_extraction::DUMMY_METADATA_DIGEST_PREFIX.to_fields();
let inputs = prefix
.into_iter()
.chain(metadata_digest.to_fields())
.collect_vec();
let digest = map_to_curve_point(&inputs);

combine_digest_and_block(digest)
}
Loading