Skip to content

Commit e13b75e

Browse files
committed
Merge remote-tracking branch 'origin/generic-extraction-tree-creation' into generic-extraction-row-id-update
2 parents 93e04dc + a139673 commit e13b75e

File tree

96 files changed

+981
-1003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+981
-1003
lines changed

Cargo.lock

+263-208
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+38-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ members = [
1414
resolver = "2"
1515

1616
[workspace.dependencies]
17-
alloy = { version = "0.4", default-features = false, features = [
17+
alloy = { version = "0.6", default-features = false, features = [
1818
"consensus",
1919
"contract",
2020
"getrandom",
@@ -33,17 +33,30 @@ alloy = { version = "0.4", default-features = false, features = [
3333
] }
3434
anyhow = "1.0"
3535
base64 = "0.22"
36+
bb8 = "0.8.5"
37+
bb8-postgres = "0.8.1"
3638
bincode = "1.3"
39+
camelpaste = "0.1"
40+
clap = { version = "4.5", features = ["derive"] }
41+
colored = "2.1"
3742
csv = "1.3"
43+
delegate = "0.13"
44+
derive_more = { version = "1.0", features = ["constructor"] }
45+
dialoguer = { version = "0.11", features = ["fuzzy-select"] }
3846
env_logger = "0.11"
47+
envconfig = "0.11"
3948
# TODO: see if we can revert to upstream repo: originally used
4049
# to fetch proof with "node" instead of already encoded struct
50+
ethereum-types = "0.14.1"
4151
eth_trie = { git = "https://github.com/nikkolasg/eth-trie.rs" }
52+
futures = "0.3"
4253
glob = "0.3"
4354
gobuild = "0.1.0-alpha.1"
44-
hashbrown = "0.14"
55+
hashbrown = "0.15"
4556
hex = "0.4"
46-
itertools = "0.12"
57+
itertools = "0.13"
58+
jammdb = "0.11.0"
59+
lazy_static = "1.5.0"
4760
log = "0.4"
4861
num = "0.4"
4962
paste = "1.0"
@@ -55,16 +68,36 @@ plonky2_ecgfp5 = { git = "https://github.com/Lagrange-Labs/plonky2-ecgfp5" }
5568
plonky2_monolith = "0.1.0"
5669
plonky2x = { git = "https://github.com/Lagrange-Labs/succinctx", branch = "fix-build" }
5770
poseidon2_plonky2 = { git = "https://github.com/Lagrange-Labs/plonky2", branch = "upstream" }
71+
postgres-types = { version = "0.2.6", features = ["with-serde_json-1"] }
5872
rand = "0.8"
73+
rand_chacha = "0.3.1"
5974
revm = { version = "3.5", default-features = false }
6075
rlp = "0.5"
61-
rstest = "0.18"
76+
rstest = "0.23"
6277
serde = { version = "1.0", features = ["derive"] }
6378
serde_json = "1.0"
6479
serial_test = "3.0"
6580
sha2 = "0.10"
81+
sha256 = { version = "1.5.0", default-features = false }
6682
sha3 = "0.10"
67-
tokio = { version = "1.34", features = ["macros", "rt-multi-thread", "fs"] }
83+
simple_logger = { version = "5.0.0", default-features = false, features = [
84+
"colors",
85+
] }
86+
sqlparser = "0.49"
87+
stderrlog = { version = "0.6.0", default-features = false }
88+
tabled = { version = "0.16", features = ["ansi"] }
89+
test-log = "0.2.16"
90+
testfile = "0.1.5"
91+
thiserror = "2.0"
92+
tokio = { version = "1.34", features = [
93+
"sync",
94+
"macros",
95+
"macros",
96+
"rt-multi-thread",
97+
"fs",
98+
] }
99+
tokio-postgres = { version = "0.7", features = ["with-chrono-0_4"] }
100+
tracing = "0.1.40"
68101

69102
# just for test
70103
ethers = { git = "https://github.com/Lagrange-Labs/ethers-rs", default-features = false, features = [

custom-hooks/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Hook Installation
2+
3+
To install hooks in this file, from the root directory navigate to `./.git/hooks`. Then replace the corresponding file with the one in this folder. If you haven't installed any hooks before it will be called `<file-name>.sample` instead of just `<file-name>`. You may also
4+
have to make the files inside `./.git/hooks` executable by running `chmod +x ./.git/hooks/*` from the project root.

custom-hooks/pre-commit

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
if cargo fmt --all -- --check
6+
then
7+
echo "cargo fmt OK"
8+
else
9+
echo "There are some code style issues."
10+
echo "Run cargo fmt first."
11+
exit 1
12+
fi
13+
14+
if cargo clippy --all-targets -- -D warnings
15+
then
16+
echo "cargo clippy OK"
17+
else
18+
echo "There are some clippy issues."
19+
exit 1
20+
fi
21+
22+
exit 0

gnark-utils/lib/lib.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,16 @@ func SaveVerifierSolidity(assetDir string, vk groth16.VerifyingKey) error {
308308
}
309309
content := buf.String()
310310

311-
contractFile, err := os.Create(assetDir + "/verifier.sol")
311+
contractFile, err := os.Create(assetDir + "/Verifier.sol")
312312
if err != nil {
313-
return errors.Wrap(err, "create verifier.sol file")
313+
return errors.Wrap(err, "create Verifier.sol file")
314314
}
315315
defer contractFile.Close()
316316

317317
w := bufio.NewWriter(contractFile)
318318
// write the new content to the writer
319319
if _, err = w.Write([]byte(content)); err != nil {
320-
return errors.Wrap(err, "write to verifier.sol")
320+
return errors.Wrap(err, "write to Verifier.sol")
321321
}
322322

323323
return nil

gnark-utils/src/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use anyhow::Result;
55
use std::ffi::CString;
66

77
/// Compile the circuit data and generate the asset files of `r1cs.bin`,
8-
/// `pk.bin`, `vk.bin` and `verifier.sol`.
8+
/// `pk.bin`, `vk.bin` and `Verifier.sol`.
99
pub fn compile_and_generate_assets(
1010
common_circuit_data: &str,
1111
verifier_only_circuit_data: &str,

gnark-utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod go {
1515
extern "C" {
1616
/// Compile and generate the asset files from the circuit data to the
1717
/// specified dir. The generated files are `r1cs.bin`, `pk.bin`,
18-
/// `vk.bin` and `verifier.sol`.
18+
/// `vk.bin` and `Verifier.sol`.
1919
pub fn CompileAndGenerateAssets(
2020
common_circuit_data: *const c_char,
2121
verifier_only_circuit_data: *const c_char,

groth16-framework/src/compiler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::{
2222
type WrapCircuit = WrappedCircuit<DefaultParameters, Groth16WrapperParameters, D>;
2323

2424
/// Compile the circuit data and generate the asset files of `r1cs.bin`,
25-
/// `pk.bin`, `vk.bin` and `verifier.sol`.
25+
/// `pk.bin`, `vk.bin` and `Verifier.sol`.
2626
/// This function returns the full file path of the Solidity verifier contract.
2727
pub fn compile_and_generate_assets(
2828
circuit_data: CircuitData<F, C, D>,

groth16-framework/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! 1. Generate the asset files.
77
//!
88
//! The asset files are `circuit.bin`, `r1cs.bin`, `pk.bin`, `vk.bin` and
9-
//! `verifier.sol`. User could call the `compile_and_generate_assets`
9+
//! `Verifier.sol`. User could call the `compile_and_generate_assets`
1010
//! function to generate these files as below.
1111
//!
1212
//! ``
@@ -76,7 +76,7 @@ pub mod utils;
7676
mod verifier;
7777

7878
// The function is used to generate the asset files of `circuit.bin`,
79-
// `r1cs.bin`, `pk.bin`, `vk.bin` and `verifier.sol`. It's only necessary to be
79+
// `r1cs.bin`, `pk.bin`, `vk.bin` and `Verifier.sol`. It's only necessary to be
8080
// called for re-generating these asset files when the circuit code changes.
8181
pub use compiler::compile_and_generate_assets;
8282

groth16-framework/src/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn groth16_verify(asset_dir: &str, proof: &Groth16Proof) {
6666
/// Test the Solidity verification.
6767
fn evm_verify(asset_dir: &str, proof: &Groth16Proof) {
6868
let solidity_file_path = Path::new(asset_dir)
69-
.join("verifier.sol")
69+
.join("Verifier.sol")
7070
.to_string_lossy()
7171
.to_string();
7272

groth16-framework/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::{
1919
pub const CIRCUIT_DATA_FILENAME: &str = "circuit.bin";
2020

2121
/// The filename of the exported Solidity verifier contract.
22-
pub const SOLIDITY_VERIFIER_FILENAME: &str = "verifier.sol";
22+
pub const SOLIDITY_VERIFIER_FILENAME: &str = "Verifier.sol";
2323

2424
/// Convert a string with `0x` prefix to an U256.
2525
pub fn hex_to_u256(s: &str) -> Result<U256> {

groth16-framework/test_data/Groth16VerifierExtensions.sol groth16-framework/test_data/Groth16VerifierExtension.sol

+31-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {Verifier} from "./verifier.sol";
5+
import {Verifier} from "./Verifier.sol";
66

77
// The query input struct passed into the processQuery function
88
struct QueryInput {
@@ -40,7 +40,7 @@ enum QueryErrorCode {
4040
ComputationOverflow
4141
}
4242

43-
contract Query is Verifier {
43+
contract Groth16VerifierExtension is Verifier {
4444
// Top 3 bits mask.
4545
uint256 constant TOP_THREE_BIT_MASK = ~(uint256(7) << 253);
4646

@@ -94,7 +94,12 @@ contract Query is Verifier {
9494
// Then ensure this hash value equals to the last Groth16 input (groth16_inputs[2]).
9595
// 3. Parse the items from public inputs, and check as expected for query.
9696
// 4. Parse and return the query output from public inputs.
97-
function processQuery(bytes32[] calldata data, QueryInput memory query) public view returns (QueryOutput memory) {
97+
function processQuery(bytes32[] calldata data, QueryInput memory query)
98+
public
99+
view
100+
virtual
101+
returns (QueryOutput memory)
102+
{
98103
// 1. Groth16 verification
99104
uint256[3] memory groth16Inputs = verifyGroth16Proof(data);
100105

@@ -109,7 +114,7 @@ contract Query is Verifier {
109114
}
110115

111116
// Parse the Groth16 proofs and inputs, do verification, and returns the Groth16 inputs.
112-
function verifyGroth16Proof(bytes32[] calldata data) internal view returns (uint256[3] memory) {
117+
function verifyGroth16Proof(bytes32[] calldata data) internal view virtual returns (uint256[3] memory) {
113118
uint256[8] memory proofs;
114119
uint256[3] memory inputs;
115120

@@ -130,7 +135,7 @@ contract Query is Verifier {
130135
}
131136

132137
// Compute sha256 on the public inputs, and ensure it equals to the last Groth16 input.
133-
function verifyPublicInputs(bytes32[] calldata data, uint256[3] memory groth16Inputs) internal pure {
138+
function verifyPublicInputs(bytes32[] calldata data, uint256[3] memory groth16Inputs) internal pure virtual {
134139
// Parse the public inputs from calldata.
135140
bytes memory pi = parsePublicInputs(data);
136141

@@ -166,13 +171,18 @@ contract Query is Verifier {
166171
}
167172

168173
// Verify the public inputs with the expected query.
169-
function verifyQuery(bytes32[] calldata data, QueryInput memory query) internal pure returns (QueryErrorCode) {
174+
function verifyQuery(bytes32[] calldata data, QueryInput memory query)
175+
internal
176+
view
177+
virtual
178+
returns (QueryErrorCode)
179+
{
170180
// Retrieve the last Uint256 of public inputs.
171181
bytes32 rem = data[PI_REM_OFFSET];
172182

173183
// Check the block hash and computational hash.
174184
bytes32 blockHash = convertToBlockHash(data[PI_OFFSET + BLOCK_HASH_POS]);
175-
require(blockHash == query.blockHash, "Block hash must equal as expected.");
185+
verifyBlockHash(blockHash, query.blockHash);
176186
bytes32 computationalHash = data[PI_OFFSET + COMPUTATIONAL_HASH_POS];
177187
require(computationalHash == query.computationalHash, "Computational hash must equal as expected.");
178188

@@ -215,8 +225,21 @@ contract Query is Verifier {
215225
return QueryErrorCode.ComputationOverflow;
216226
}
217227

228+
/// @notice verifies two blockhashed are equal
229+
/// @param blockHash the blockhash computed from the proof
230+
/// @param expectedBlockHash the expected blockhash, retrieved from the query
231+
/// @dev this function is virtual to allow for different implementations in different environments
232+
function verifyBlockHash(bytes32 blockHash, bytes32 expectedBlockHash) internal view virtual {
233+
require(blockHash == expectedBlockHash, "Block hash must equal as expected.");
234+
}
235+
218236
// Parse the query output from the public inputs.
219-
function parseOutput(bytes32[] calldata data, QueryErrorCode error) internal pure returns (QueryOutput memory) {
237+
function parseOutput(bytes32[] calldata data, QueryErrorCode error)
238+
internal
239+
pure
240+
virtual
241+
returns (QueryOutput memory)
242+
{
220243
bytes32 rem = data[PI_REM_OFFSET];
221244

222245
// Retrieve total number of the matched rows.

groth16-framework/tests/common/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ pub(crate) use context::TestContext;
1111
pub(crate) use io::{TestQueryInput, TestQueryOutput};
1212

1313
pub(crate) const NUM_PREPROCESSING_IO: usize = verifiable_db::ivc::NUM_IO;
14-
pub(crate) const NUM_QUERY_IO: usize = verifiable_db::query::PI_LEN::<MAX_NUM_ITEMS_PER_OUTPUT>;
14+
pub(crate) const NUM_QUERY_IO: usize = verifiable_db::query::pi_len::<MAX_NUM_ITEMS_PER_OUTPUT>();

groth16-framework/tests/common/query.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ use mp2_common::{
1212
};
1313
use plonky2::field::types::PrimeField64;
1414
use verifiable_db::{
15-
query::api::CircuitInput as QueryInput,
1615
revelation::{api::CircuitInput, PublicInputs as RevelationPI},
1716
test_utils::{
18-
TestRevelationData, MAX_NUM_COLUMNS, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS,
19-
MAX_NUM_PLACEHOLDERS, MAX_NUM_PREDICATE_OPS, MAX_NUM_RESULT_OPS,
17+
TestRevelationData, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS, MAX_NUM_PLACEHOLDERS,
2018
},
2119
};
2220

groth16-framework/tests/query.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Test the Groth16 proving process for the query circuits.
2-
2+
#![allow(incomplete_features)]
33
#![feature(generic_const_exprs)]
44

55
mod common;
@@ -35,8 +35,8 @@ fn test_local_groth16_proof() {
3535

3636
// Verify the query in the Solidity function.
3737
// The editing Solidity code is saved in `test_data/TestGroth16Verifier.sol`.
38-
// TODO: In practice, the separate `Groth16VerifierExtensions.sol` and
39-
// `verifier.sol` should be used, but the `revm` (Rust EVM) cannot support
38+
// TODO: In practice, the separate `Groth16VerifierExtension.sol` and
39+
// `Verifier.sol` should be used, but the `revm` (Rust EVM) cannot support
4040
// compilated contract deployment (as inheritance) for now.
4141
verify_query_in_solidity(ASSET_DIR);
4242
}
@@ -64,8 +64,8 @@ fn test_groth16_proving_for_query() {
6464

6565
// Verify the query in the Solidity function.
6666
// The editing Solidity code is saved in `test_data/TestGroth16Verifier.sol`.
67-
// TODO: In practice, the separate `Groth16VerifierExtensions.sol` and
68-
// `verifier.sol` should be used, but the `revm` (Rust EVM) cannot support
67+
// TODO: In practice, the separate `Groth16VerifierExtension.sol` and
68+
// `Verifier.sol` should be used, but the `revm` (Rust EVM) cannot support
6969
// compilated contract deployment (as inheritance) for now.
7070
verify_query_in_solidity(ASSET_DIR);
7171
}

inspect/Cargo.toml

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ edition = "2021"
55

66
[dependencies]
77
anyhow.workspace = true
8+
clap.workspace = true
9+
colored.workspace = true
10+
dialoguer.workspace = true
811
hex.workspace = true
912
itertools.workspace = true
1013
serde.workspace = true
11-
12-
clap = { version = "4.5.17", features = ["derive"] }
13-
colored = "2.1.0"
14-
dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
15-
tabled = { version = "0.16.0", features = ["ansi"] }
16-
tokio = { version = "1.34", features = ["sync", "macros"], default-features = false }
14+
tabled.workspace = true
15+
tokio.workspace = true
1716

1817
ryhope = { path = "../ryhope" }
1918
mp2_v1 = { path = "../mp2-v1" }

mp2-common/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
anyhow.workspace = true
87
alloy.workspace = true
8+
anyhow.workspace = true
99
bincode.workspace = true
10-
derive_more = "0.99.18"
10+
derive_more.workspace = true
1111
eth_trie.workspace = true
12+
ethereum-types.workspace = true
1213
hashbrown.workspace = true
1314
hex.workspace = true
1415
itertools.workspace = true
@@ -23,16 +24,15 @@ rand.workspace = true
2324
rlp.workspace = true
2425
serde.workspace = true
2526
sha3.workspace = true
26-
ethereum-types = "0.14.1"
2727

2828
[dev-dependencies]
29+
ethers.workspace = true
2930
hex.workspace = true
3031
rand.workspace = true
32+
rstest.workspace = true
3133
tokio.workspace = true
32-
ethers.workspace = true
3334

3435
mp2_test = { path = "../mp2-test" }
35-
rstest.workspace = true
3636

3737
[features]
3838
ci = ["mp2_test/ci"]

mp2-common/src/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use plonky2_crypto::u32::arithmetic_u32::U32Target;
1616
use serde::{Deserialize, Serialize};
1717
use std::{array::from_fn as create_array, fmt::Debug, ops::Index};
1818

19-
use crate::utils::{less_than, less_than_or_equal_to};
19+
use crate::utils::less_than;
2020

2121
/// Utility trait to convert any value into its field representation equivalence
2222
pub trait ToField<F: RichField> {

0 commit comments

Comments
 (0)