Skip to content

Commit

Permalink
Enable V5 transaction test vectors in the groth16 tests (#2383)
Browse files Browse the repository at this point in the history
This also simplifies the code.
  • Loading branch information
teor2345 authored Jun 24, 2021
1 parent 1b6688f commit 5bce941
Showing 1 changed file with 39 additions and 60 deletions.
99 changes: 39 additions & 60 deletions zebra-consensus/src/primitives/groth16/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,29 @@ where
let mut async_checks = FuturesUnordered::new();

for tx in transactions {
match &*tx {
Transaction::V1 { .. }
| Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V5 { .. } => (),
Transaction::V4 {
sapling_shielded_data,
..
} => {
if let Some(sapling_shielded_data) = sapling_shielded_data {
for spend in sapling_shielded_data.spends_per_anchor() {
tracing::trace!(?spend);

let spend_rsp = spend_verifier
.ready_and()
.await?
.call(groth16::ItemWrapper::from(&spend).into());

async_checks.push(spend_rsp);
}

for output in sapling_shielded_data.outputs() {
tracing::trace!(?output);

let output_rsp = output_verifier
.ready_and()
.await?
.call(groth16::ItemWrapper::from(output).into());

async_checks.push(output_rsp);
}
}
}
let spends = tx.sapling_spends_per_anchor();
let outputs = tx.sapling_outputs();

for spend in spends {
tracing::trace!(?spend);

let spend_rsp = spend_verifier
.ready_and()
.await?
.call(groth16::ItemWrapper::from(&spend).into());

async_checks.push(spend_rsp);
}

for output in outputs {
tracing::trace!(?output);

let output_rsp = output_verifier
.ready_and()
.await?
.call(groth16::ItemWrapper::from(output).into());

async_checks.push(output_rsp);
}

while let Some(result) = async_checks.next().await {
Expand Down Expand Up @@ -108,33 +98,22 @@ where
let mut async_checks = FuturesUnordered::new();

for tx in transactions {
match &*tx {
Transaction::V1 { .. }
| Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V5 { .. } => (),
Transaction::V4 {
sapling_shielded_data,
..
} => {
if let Some(sapling_shielded_data) = sapling_shielded_data {
for output in sapling_shielded_data.outputs() {
// This changes the primary inputs to the proof
// verification, causing it to fail for this proof.
let mut modified_output = output.clone();
modified_output.cm_u = jubjub::Fq::zero();

tracing::trace!(?modified_output);

let output_rsp = output_verifier
.ready_and()
.await?
.call(groth16::ItemWrapper::from(&modified_output).into());

async_checks.push(output_rsp);
}
}
}
let outputs = tx.sapling_outputs();

for output in outputs {
// This changes the primary inputs to the proof
// verification, causing it to fail for this proof.
let mut modified_output = output.clone();
modified_output.cm_u = jubjub::Fq::zero();

tracing::trace!(?modified_output);

let output_rsp = output_verifier
.ready_and()
.await?
.call(groth16::ItemWrapper::from(&modified_output).into());

async_checks.push(output_rsp);
}

while let Some(result) = async_checks.next().await {
Expand Down

0 comments on commit 5bce941

Please sign in to comment.