Skip to content

Commit

Permalink
fix: bundle proof calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
roynalnaruto committed Nov 7, 2024
1 parent 0e78819 commit 14deabc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions prover/src/proof/proof_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ impl BundleProofV2 {
/// [ public_input_bytes | accumulator_bytes | proof ]
pub fn calldata(&self) -> Vec<u8> {
std::iter::empty()
.chain(self.instances[ACCUMULATOR_BYTES..].iter())
.chain(self.instances[0..ACCUMULATOR_BYTES].iter())
.chain(self.instances.iter())
.chain(self.proof.iter())
.cloned()
.collect::<Vec<_>>()
Expand Down Expand Up @@ -347,25 +346,48 @@ impl Proof for BundleProofV2Metadata {
mod tests {
use tempdir::TempDir;

use crate::{read_json, BundleProofV2, EvmProof};
use crate::{deploy_and_call, read, read_json, BundleProofV2, EvmProof};

#[test]
fn serde_bundle_proof() -> anyhow::Result<()> {
fn bundle_proof_backwards_compat() -> anyhow::Result<()> {
// Read [`EvmProof`] from test data.
let evm_proof = read_json::<_, EvmProof>("test_data/evm-proof.json")?;

// Build bundle proofs.
let bundle_proof_v2 = BundleProofV2::new_from_raw(
&evm_proof.proof.proof,
&evm_proof.proof.instances,
&evm_proof.proof.vk,
)?;
let bundle_proof = crate::BundleProof::from(evm_proof.proof);

assert_eq!(bundle_proof.calldata(), bundle_proof_v2.calldata());

Ok(())
}

#[test]
fn verify_bundle_proof() -> anyhow::Result<()> {
// Create a tmp test directory.
let dir = TempDir::new("proof_v2")?;

// Read [`EvmProof`] from test data.
let evm_proof = read_json::<_, EvmProof>("test_data/evm-proof.json")?;
let verifier = read("test_data/evm-verifier.bin")?;

// Build bundle proof v2.
let bundle_proof = BundleProofV2::new_from_raw(
&evm_proof.proof.proof,
&evm_proof.proof.instances,
&evm_proof.proof.vk,
)?;

// Dump the bundle proof v2 into a tmp dir.
let dir = TempDir::new("proof_v2")?;
// Dump the bundle proof v2.
bundle_proof.dump(&dir, "suffix")?;
dir.close()?;

Ok(())
// Verify the bundle proof v2 with EVM verifier contract.
assert!(deploy_and_call(verifier, bundle_proof.calldata()).is_ok());

Ok(dir.close()?)
}
}
2 changes: 1 addition & 1 deletion prover/test_data/evm-proof.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"proof":{"proof":"BjJEevMsXHDtIPlxUeoCX2bSA8c6sqLX/XpKPQk1QJMfRyLL0SIzrU4UZl0kkMGv1Q5dU2v6I4aaBHZpHse0rQoEpct3/KDuf92bE18CidMcavWWPqswUV52unUKKCHoECN5on4o8DnBbQ6Bu0qRLBDEKo7Fe61/+IOcXJMrzhgEoTwgJfK5R/+u0bTlA+7MMfjvm3rhXy3PVUqcwcPMdw9mMUzPBr4JEFKkuGbM7P2uknzxjGtmby4lfS19mRsUC3QG3RFcKdoW5O2k2eHJmG2Pdq+2i0phMowSP/Wsm7YCqLoukIfpkO8M8InHTgPeNEFCJuumc3CUBEuq0jaMVQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIDE/Ph/AFv/U/tskFm3jTNlLczNnwacW99NKCUlt3IfhB4B7CRvE7yx4czXJwIfVyQuHYG3piUh96g2pKm7prWKjqGnKyLjtR+5jpS1/hrCl5JRBhhGI36yY1U9BDeMsYcZh6LddY9cSopo2WsQs85EKAC93m/jaKfgvkHbm1NCRUrP3TbKZrzy4ykqkCI08b4967gJf5KcU3O6+44jrSeLoIhKUb3LEC58xBb9+zU9dG6LvK3olr9g+NG1FAaLN0IgK35iGcfCdWygichS0m6BZ7IKWkKFt2Ejbkx0DT+mC5XlTgVNOYjfI0kV7s+Dze0xtRAFI0xrPsYaZeL7vtwHbr3cnq4YIjCRFqc5v9SCcrCtCEBa2vZOrm1ALotLYMaw8296Wxn9dkxiqPFQdELreApeRkjBDGtC8BB/pbGKywT4Bs+1hdymaWa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AAAAAAUn2flHFfjCUj8UAAAAAAAAAAAAAAAAAAAAAAAAAAAABuIYooZldvq5UVqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQnf90hS3Tv9G91vMloktkEfTw520n9B8XWr92uzMdjzvot29jacqJcAAAAAAAAAAAAAAAAAAAAAIY+4Be1mT6hzdgY13HkZNAAAAAAAAAAAAAAAAAAAAAAOYRdBTeI/h1ABow+afQfsAAAAAAAAAAAAAAAAAAAAAKusra6vAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAkBSU3y4mikWSpekX65K5IAAAAAAAAAAAAAAAAAAAAAFwhiTka2U7nZgae8vzYraAAAAAAAAAAAAAAAAAAAAAAz7n6jeqFPuxKFRp/OqlKdgAAAAAAAAAAAAAAAAAAAAAkccTpus5BBCOxH2Be8HGTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIJ1AAAAAAAAAAAAAAAAAAAAAAsG6UZ0iMzttF8QL7yOb5WAAAAAAAAAAAAAAAAAAAAAAf8LIRd7c5Qinatn5XK//xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE=","vk":"AAAAGgAAAARX2S0K1wF333B1waOsnG/vcASJmWG9YM6SNWCBy1ywDypuNyCQrqoPJvIVXOq6I7k0FOLtC23/wUlpV5XZJVYRvnTQT732GsQk9SbLYKO0HXDQX74zc4W6+04/WbBby2RE5Xpxs7SS+QefbTL8QYR7MnzElOK8gyZFf346gyd1DEa15Vck1FpZYwhhPwHa8a9F3fkVWmKrWs8XIHYU4hNSiyVw+UEuc4FYFVc7I6aoactklYnAfIPu3D9rzH4+i1+gXJJEqDXgfWfK+9szR4ysEnkuzgFrCcTvIG1U2mAJJg==","git_version":"33191d8"},"num_instance":[25]}
Binary file added prover/test_data/evm-verifier.bin
Binary file not shown.

0 comments on commit 14deabc

Please sign in to comment.