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

Full Prover Abstraction for public API #14

Closed
wants to merge 13 commits into from
97 changes: 61 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ plonky2 = "0.1.4"
ethers = { version ="2.0.11", default-features = false, features = ["rustls"]}

# supporting latest plonky2
plonky2_crypto = { git = "https://github.com/nikkolasg/plonky2-crypto" }
plonky2_crypto = { git = "https://github.com/nikkolasg/plonky2-crypto" , branch = "feat/serialization" }
rand = "0.8.5"
serde = "1.0.193"
# TODO: see if we can revert to upstream repo: originally used
# to fetch proof with "node" instead of already encoded struct
eth_trie = { git = "https://github.com/nikkolasg/eth-trie.rs" }
rlp = "0.5.2"
sha3 = "0.10.8"
bincode = "1.3.3"

[dev-dependencies]
anyhow = "1.0.75"
csv = "1.3.0"
hex = "0.4.3"
itertools = "0.12.0"
rlp = "0.5.2"
Expand All @@ -33,3 +35,6 @@ tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }

[features]
ci = []

[patch.crates-io]
plonky2 = { git = "https://github.com/nikkolasg/plonky2" }
4 changes: 3 additions & 1 deletion src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
types::{Block, BlockId, Bytes, Transaction, TransactionReceipt, U64},
};
use rlp::{Encodable, Rlp, RlpStream};
#[cfg(feature = "ci")]
use std::env;
use std::sync::Arc;

use crate::utils::keccak256;
/// A wrapper around a transaction and its receipt. The receipt is used to filter
/// bad transactions, so we only compute over valid transactions.
pub(crate) struct TxAndReceipt(Transaction, TransactionReceipt);

Check warning on line 17 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Test Suite

struct `TxAndReceipt` is never constructed

Check warning on line 17 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Check

struct `TxAndReceipt` is never constructed

impl TxAndReceipt {
pub fn tx(&self) -> &Transaction {

Check warning on line 20 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Test Suite

methods `tx`, `receipt`, `tx_rlp`, and `receipt_rlp` are never used

Check warning on line 20 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Check

methods `tx`, `receipt`, `tx_rlp`, and `receipt_rlp` are never used
&self.0
}
pub fn receipt(&self) -> &TransactionReceipt {
Expand Down Expand Up @@ -60,7 +62,7 @@

/// Structure containing the block header and its transactions / receipts. Amongst other things,
/// it is used to create a proof of inclusion for any transaction inside this block.
pub struct BlockData {

Check warning on line 65 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Test Suite

struct `BlockData` is never constructed

Check warning on line 65 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Check

struct `BlockData` is never constructed
pub block: ethers::types::Block<Transaction>,
pub txs: Vec<TxAndReceipt>,
// TODO: add generics later - this may be re-used amongst different workers
Expand All @@ -71,7 +73,7 @@
impl BlockData {
pub async fn fetch<T: Into<BlockId> + Send + Sync>(blockid: T) -> Result<Self> {
#[cfg(feature = "ci")]
let url = env::var("CI_RPC_URL").expect("RPC_URL env var not set");
let url = env::var("CI_RPC_URL").expect("CI_RPC_URL env var not set");
#[cfg(not(feature = "ci"))]
let url = "https://eth.llamarpc.com";
//let provider = Provider::<Http>::try_from
Expand Down Expand Up @@ -215,10 +217,10 @@
let mut key_len = 0;
for node in path {
match node {
Node::Branch(b) => key_len += 1,

Check warning on line 220 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `b`

Check warning on line 220 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `b`
Node::Extension(e) => key_len += e.read().unwrap().prefix.len(),
Node::Leaf(l) => key_len += l.key.len(),
Node::Hash(h) => panic!("what is a hash node!?"),

Check warning on line 223 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `h`

Check warning on line 223 in src/eth.rs

View workflow job for this annotation

GitHub Actions / Check

unused variable: `h`
Node::Empty => panic!("should not be an empty node in the path"),
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ pub(crate) fn hash_array<F: RichField + Extendable<D>, const D: usize>(
// reason why ^: this is annoying to do in circuit.
let num_bytes = ceil_div_usize(padded_len_bits, 8);
let diff = num_bytes - length;
// we need to make sure that there is enough data len to fit the padding inside
assert!(
length + diff <= total_len,
"not enough data to fit padding: (data) {}+{} (padding) > {}",
length,
diff,
total_len
);

let diff_target = b.add_virtual_target();
pw.set_target(diff_target, F::from_canonical_usize(diff));
Expand Down Expand Up @@ -133,7 +141,8 @@ pub(crate) fn hash_array<F: RichField + Extendable<D>, const D: usize>(
input: BigUintTarget {
limbs: node_u32_target,
},
input_bits: padded_len_bits,
//input_bits: padded_len_bits,
input_bits: 0,
blocks,
};

Expand Down
Loading
Loading