Skip to content

Commit

Permalink
Group the parameters for the different descriptors.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi authored and batconjurer committed May 14, 2024
1 parent f39e965 commit 5525d73
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 86 deletions.
2 changes: 1 addition & 1 deletion masp_primitives/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ impl<T: BorshSchema> BorshSchema for Note<T> {
}

fn declaration() -> Declaration {
"Note".into()
format!("Note<{}>", T::declaration())
}
}

Expand Down
11 changes: 3 additions & 8 deletions masp_primitives/src/sapling/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub trait TxProver {
/// while accumulating its value commitment randomness inside the context for later
/// use.
///
#[allow(clippy::too_many_arguments)]
fn output_proof(
&self,
ctx: &mut Self::SaplingProvingContext,
Expand Down Expand Up @@ -117,10 +118,7 @@ pub mod mock {
_merkle_path: MerklePath<Node>,
rcv: jubjub::Fr,
) -> Result<([u8; GROTH_PROOF_SIZE], jubjub::ExtendedPoint, PublicKey), ()> {
let cv = asset_type
.value_commitment(value, rcv)
.commitment()
.into();
let cv = asset_type.value_commitment(value, rcv).commitment().into();

let rk =
PublicKey(proof_generation_key.ak.into()).randomize(ar, SPENDING_KEY_GENERATOR);
Expand All @@ -138,10 +136,7 @@ pub mod mock {
value: u64,
rcv: jubjub::Fr,
) -> ([u8; GROTH_PROOF_SIZE], jubjub::ExtendedPoint) {
let cv = asset_type
.value_commitment(value, rcv)
.commitment()
.into();
let cv = asset_type.value_commitment(value, rcv).commitment().into();

([0u8; GROTH_PROOF_SIZE], cv)
}
Expand Down
36 changes: 20 additions & 16 deletions masp_primitives/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<P: consensus::Parameters> Builder<P> {
prover: &impl TxProver,
fee_rule: &FR,
rng: &mut (impl CryptoRng + RngCore),
mrng: &mut impl BuildParams,
bparams: &mut impl BuildParams,
) -> Result<(Transaction, SaplingMetadata), Error<FR::Error>> {
let fee = fee_rule
.fee_required(
Expand All @@ -306,15 +306,15 @@ impl<P: consensus::Parameters> Builder<P> {
self.sapling_builder.outputs().len(),
)
.map_err(Error::Fee)?;
self.build_internal(prover, fee, rng, mrng)
self.build_internal(prover, fee, rng, bparams)
}

fn build_internal<FE>(
self,
prover: &impl TxProver,
fee: U64Sum,
rng: &mut (impl CryptoRng + RngCore),
mrng: &mut impl BuildParams,
bparams: &mut impl BuildParams,
) -> Result<(Transaction, SaplingMetadata), Error<FE>> {
let consensus_branch_id = BranchId::for_height(&self.params, self.target_height);

Expand All @@ -341,7 +341,7 @@ impl<P: consensus::Parameters> Builder<P> {
prover,
&mut ctx,
rng,
mrng,
bparams,
self.target_height,
self.progress_notifier.as_ref(),
)
Expand Down Expand Up @@ -375,7 +375,13 @@ impl<P: consensus::Parameters> Builder<P> {
let (sapling_bundle, tx_metadata) = match unauthed_tx
.sapling_bundle
.map(|b| {
b.apply_signatures(prover, &mut ctx, rng, mrng, shielded_sig_commitment.as_ref())
b.apply_signatures(
prover,
&mut ctx,
rng,
bparams,
shielded_sig_commitment.as_ref(),
)
})
.transpose()
.map_err(Error::SaplingBuild)?
Expand All @@ -399,9 +405,7 @@ impl<P: consensus::Parameters> Builder<P> {
}
}

pub trait MapBuilder<P1, K1, N1, P2, K2, N2>:
sapling::builder::MapBuilder<P1, K1, P2, K2>
{
pub trait MapBuilder<P1, K1, N1, P2, K2, N2>: sapling::builder::MapBuilder<P1, K1, P2, K2> {
fn map_notifier(&self, s: N1) -> N2;
}

Expand Down Expand Up @@ -450,9 +454,9 @@ mod testing {
pub fn mock_build(
self,
rng: &mut (impl CryptoRng + RngCore),
mrng: &mut impl BuildParams,
bparams: &mut impl BuildParams,
) -> Result<(Transaction, SaplingMetadata), Error<Infallible>> {
self.build(&MockTxProver, &fixed::FeeRule::standard(), rng, mrng)
self.build(&MockTxProver, &fixed::FeeRule::standard(), rng, bparams)
}
}
}
Expand Down Expand Up @@ -549,7 +553,7 @@ mod tests {
// Expect a binding signature error, because our inputs aren't valid, but this shows
// that a binding signature was attempted
assert_eq!(
builder.mock_build(&mut OsRng, &mut build_s::RngRandomness::new(OsRng)),
builder.mock_build(&mut OsRng, &mut build_s::RngBuildParams::new(OsRng)),
Err(Error::SaplingBuild(build_s::Error::BindingSig))
);
}
Expand All @@ -570,7 +574,7 @@ mod tests {
{
let builder = Builder::new(TEST_NETWORK, tx_height);
assert_eq!(
builder.mock_build(&mut OsRng, &mut build_s::RngRandomness::new(OsRng)),
builder.mock_build(&mut OsRng, &mut build_s::RngBuildParams::new(OsRng)),
Err(Error::InsufficientFunds(I128Sum::from_sum(
DEFAULT_FEE.clone()
)))
Expand All @@ -589,7 +593,7 @@ mod tests {
.add_sapling_output(ovk, to, zec(), 50000, MemoBytes::empty())
.unwrap();
assert_eq!(
builder.mock_build(&mut OsRng, &mut build_s::RngRandomness::new(OsRng)),
builder.mock_build(&mut OsRng, &mut build_s::RngBuildParams::new(OsRng)),
Err(Error::InsufficientFunds(
I128Sum::from_pair(zec(), 50000).unwrap()
+ &I128Sum::from_sum(DEFAULT_FEE.clone())
Expand All @@ -605,7 +609,7 @@ mod tests {
.add_transparent_output(&transparent_address, zec(), 50000)
.unwrap();
assert_eq!(
builder.mock_build(&mut OsRng, &mut build_s::RngRandomness::new(OsRng)),
builder.mock_build(&mut OsRng, &mut build_s::RngBuildParams::new(OsRng)),
Err(Error::InsufficientFunds(
I128Sum::from_pair(zec(), 50000).unwrap()
+ &I128Sum::from_sum(DEFAULT_FEE.clone())
Expand Down Expand Up @@ -639,7 +643,7 @@ mod tests {
.add_transparent_output(&transparent_address, zec(), 20000)
.unwrap();
assert_eq!(
builder.mock_build(&mut OsRng, &mut build_s::RngRandomness::new(OsRng)),
builder.mock_build(&mut OsRng, &mut build_s::RngBuildParams::new(OsRng)),
Err(Error::InsufficientFunds(
ValueSum::from_pair(zec(), 1).unwrap()
))
Expand Down Expand Up @@ -674,7 +678,7 @@ mod tests {
.add_transparent_output(&transparent_address, zec(), 20000)
.unwrap();
assert_eq!(
builder.mock_build(&mut OsRng, &mut build_s::RngRandomness::new(OsRng)),
builder.mock_build(&mut OsRng, &mut build_s::RngBuildParams::new(OsRng)),
Err(Error::SaplingBuild(build_s::Error::BindingSig))
)
}
Expand Down
Loading

0 comments on commit 5525d73

Please sign in to comment.