Skip to content

Commit

Permalink
Include new batch swap output data in public circuit inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Apr 19, 2024
1 parent bb3e620 commit 30ebbc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 11 additions & 1 deletion crates/core/component/dex/src/batch_swap_output_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ impl ToConstraintField<Fq> for BatchSwapOutputData {
.to_field_elements()
.expect("Fq types are Bls12-377 field members"),
);
public_inputs.extend(
Fq::from(self.sct_position_prefix.epoch())
.to_field_elements()
.expect("Fq types are Bls12-377 field members"),
);
public_inputs.extend(
Fq::from(self.sct_position_prefix.block())
.to_field_elements()
.expect("Fq types are Bls12-377 field members"),
);
Some(public_inputs)
}
}
Expand Down Expand Up @@ -469,7 +479,7 @@ mod tests {
height: 0u64,
trading_pair,
epoch_starting_height: 0u64,
sct_position_prefix: Position::default(),
sct_position_prefix: 0u64.into(),
};

// Now suppose our user's contribution is:
Expand Down
15 changes: 10 additions & 5 deletions crates/core/component/dex/src/swap_claim/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ fn check_satisfaction(
anyhow::bail!("claim fee did not match public input");
}

let block: u64 = private.state_commitment_proof.position().block().into();
let note_commitment_block_height: u64 = public.output_data.epoch_starting_height + block;
if note_commitment_block_height != public.output_data.height {
anyhow::bail!("swap commitment height did not match public input");
}
anyhow::ensure!(
private.state_commitment_proof.position().block()
== public.output_data.sct_position_prefix.block(),
"scm block did not match batch swap"
);
anyhow::ensure!(
private.state_commitment_proof.position().epoch()
== public.output_data.sct_position_prefix.epoch(),
"scm epoch did not match batch swap"
);

if private.swap_plaintext.trading_pair != public.output_data.trading_pair {
anyhow::bail!("trading pair did not match public input");
Expand Down

0 comments on commit 30ebbc0

Please sign in to comment.