diff --git a/crates/core/component/dex/src/batch_swap_output_data.rs b/crates/core/component/dex/src/batch_swap_output_data.rs index f810136b38..2f384656a2 100644 --- a/crates/core/component/dex/src/batch_swap_output_data.rs +++ b/crates/core/component/dex/src/batch_swap_output_data.rs @@ -6,12 +6,12 @@ use ark_r1cs_std::{ select::CondSelectGadget, }; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; -use decaf377::{r1cs::FqVar, Fq}; +use decaf377::Fq; use penumbra_proto::{penumbra::core::component::dex::v1 as pb, DomainType}; -use penumbra_tct::Position; +use penumbra_tct::{r1cs::PositionVar, Position}; use serde::{Deserialize, Serialize}; -use penumbra_num::fixpoint::{bit_constrain, U128x128, U128x128Var}; +use penumbra_num::fixpoint::{U128x128, U128x128Var}; use penumbra_num::{Amount, AmountVar}; use crate::TradingPairVar; @@ -130,19 +130,9 @@ impl ToConstraintField for BatchSwapOutputData { .expect("trading_pair is a Bls12-377 field member"), ); public_inputs.extend( - Fq::from(self.epoch_starting_height) + self.sct_position_prefix .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"), + .expect("Position types are Bls12-377 field members"), ); Some(public_inputs) } @@ -156,8 +146,7 @@ pub struct BatchSwapOutputDataVar { pub unfilled_1: U128x128Var, pub unfilled_2: U128x128Var, pub trading_pair: TradingPairVar, - pub epoch: FqVar, - pub block: FqVar, + pub sct_position_prefix: PositionVar, } impl AllocVar for BatchSwapOutputDataVar { @@ -181,28 +170,13 @@ impl AllocVar for BatchSwapOutputDataVar { let unfilled_1 = U128x128Var::new_variable(cs.clone(), || Ok(unfilled_1_fixpoint), mode)?; let unfilled_2_fixpoint: U128x128 = output_data.unfilled_2.into(); let unfilled_2 = U128x128Var::new_variable(cs.clone(), || Ok(unfilled_2_fixpoint), mode)?; - let epoch = FqVar::new_variable( - cs.clone(), - || Ok(Fq::from(output_data.sct_position_prefix.epoch())), - mode, - )?; - let block = FqVar::new_variable( - cs.clone(), - || Ok(Fq::from(output_data.sct_position_prefix.block())), - mode, - )?; - // Check that epoch and block are 16 bits - let _ = bit_constrain(epoch.clone(), 16); - let _ = bit_constrain(block.clone(), 16); let trading_pair = TradingPairVar::new_variable_unchecked( cs.clone(), || Ok(output_data.trading_pair), mode, )?; - let epoch_starting_height = - FqVar::new_variable(cs, || Ok(Fq::from(output_data.epoch_starting_height)), mode)?; - // Check the epoch starting height is 64 bits - let _ = bit_constrain(epoch_starting_height.clone(), 64); + let sct_position_prefix = + PositionVar::new_variable(cs.clone(), || Ok(output_data.sct_position_prefix), mode)?; Ok(Self { delta_1, @@ -212,8 +186,7 @@ impl AllocVar for BatchSwapOutputDataVar { unfilled_1, unfilled_2, trading_pair, - epoch, - block, + sct_position_prefix, }) } } @@ -454,10 +427,10 @@ mod tests { lambda_2: Amount::from(1u32), unfilled_1: Amount::from(1u32), unfilled_2: Amount::from(1u32), - height: 1, + height: 0, trading_pair, - epoch_starting_height: 1, - sct_position_prefix: Position::default(), + epoch_starting_height: 0, + sct_position_prefix: 0u64.into(), }, } } diff --git a/crates/core/component/dex/src/swap_claim/proof.rs b/crates/core/component/dex/src/swap_claim/proof.rs index e90a863277..7484e1d307 100644 --- a/crates/core/component/dex/src/swap_claim/proof.rs +++ b/crates/core/component/dex/src/swap_claim/proof.rs @@ -261,10 +261,12 @@ impl ConstraintSynthesizer for SwapClaimCircuit { // Validate the swap commitment's height matches the output data's height (i.e. the clearing price height). output_data_var - .block + .sct_position_prefix + .block()? .enforce_equal(&position_var.block()?)?; output_data_var - .epoch + .sct_position_prefix + .epoch()? .enforce_equal(&position_var.epoch()?)?; // Validate that the output data's trading pair matches the note commitment's trading pair.