Skip to content

Commit

Permalink
WIP: test masp dep
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed May 15, 2024
1 parent 1e4967f commit dea5d4b
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 111 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ libc = "0.2.97"
libloading = "0.7.2"
linkme = "0.3.24"
# branch = "murisi/namada-integration"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "d1e0876b304968edfa36707ffe4fb8fbbee131d2" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "d1e0876b304968edfa36707ffe4fb8fbbee131d2", default-features = false, features = ["local-prover"] }
masp_primitives = { git = "https://github.com/anoma/masp", rev = "4ff41d1b51659adeca3b8c501586c89032479871" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "4ff41d1b51659adeca3b8c501586c89032479871", default-features = false, features = ["local-prover"] }
num256 = "0.3.5"
num_cpus = "1.13.0"
num-derive = "0.3.3"
Expand Down
124 changes: 71 additions & 53 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ fn governance(c: &mut Criterion) {

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(governance
.validate_tx(
&signed_tx,
governance.ctx.keys_changed,
governance.ctx.verifiers,
)
.is_ok())
assert!(
governance
.validate_tx(
&signed_tx,
governance.ctx.keys_changed,
governance.ctx.verifiers,
)
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -444,13 +446,14 @@ fn ibc(c: &mut Criterion) {

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(ibc
.validate_tx(
assert!(
ibc.validate_tx(
&signed_tx,
ibc.ctx.keys_changed,
ibc.ctx.verifiers,
)
.is_ok())
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -508,13 +511,15 @@ fn vp_multitoken(c: &mut Criterion) {

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(multitoken
.validate_tx(
signed_tx,
multitoken.ctx.keys_changed,
multitoken.ctx.verifiers,
)
.is_ok())
assert!(
multitoken
.validate_tx(
signed_tx,
multitoken.ctx.keys_changed,
multitoken.ctx.verifiers,
)
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -617,13 +622,14 @@ fn masp(c: &mut Criterion) {
};

b.iter(|| {
assert!(masp
.validate_tx(
assert!(
masp.validate_tx(
&signed_tx,
masp.ctx.keys_changed,
masp.ctx.verifiers,
)
.is_ok());
.is_ok()
);
})
});
}
Expand Down Expand Up @@ -903,7 +909,7 @@ fn customize_masp_tx_data(
TransactionData<masp_primitives::transaction::Authorized>,
Transaction,
)> {
let (_, tx) = setup_storage_for_masp_verification("unshielding");
let (_, _, tx) = setup_storage_for_masp_verification("unshielding");
let transaction = tx
.sections
.into_iter()
Expand Down Expand Up @@ -1072,8 +1078,11 @@ fn masp_batch_validate(c: &mut Criterion) {
ctx
},
|ctx| {
assert!(ctx
.validate(spend_vk, convert_vk, output_vk, OsRng))
assert!(
ctx.validate(
spend_vk, convert_vk, output_vk, OsRng
)
)
},
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -1155,13 +1164,14 @@ fn pgf(c: &mut Criterion) {

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(pgf
.validate_tx(
assert!(
pgf.validate_tx(
&signed_tx,
pgf.ctx.keys_changed,
pgf.ctx.verifiers,
)
.is_ok())
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -1230,13 +1240,14 @@ fn eth_bridge_nut(c: &mut Criterion) {

c.bench_function("vp_eth_bridge_nut", |b| {
b.iter(|| {
assert!(nut
.validate_tx(
assert!(
nut.validate_tx(
&signed_tx,
nut.ctx.keys_changed,
nut.ctx.verifiers,
)
.is_ok())
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -1301,13 +1312,15 @@ fn eth_bridge(c: &mut Criterion) {

c.bench_function("vp_eth_bridge", |b| {
b.iter(|| {
assert!(eth_bridge
.validate_tx(
&signed_tx,
eth_bridge.ctx.keys_changed,
eth_bridge.ctx.verifiers,
)
.is_ok())
assert!(
eth_bridge
.validate_tx(
&signed_tx,
eth_bridge.ctx.keys_changed,
eth_bridge.ctx.verifiers,
)
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -1397,13 +1410,15 @@ fn eth_bridge_pool(c: &mut Criterion) {

c.bench_function("vp_eth_bridge_pool", |b| {
b.iter(|| {
assert!(bridge_pool
.validate_tx(
&signed_tx,
bridge_pool.ctx.keys_changed,
bridge_pool.ctx.verifiers,
)
.is_ok())
assert!(
bridge_pool
.validate_tx(
&signed_tx,
bridge_pool.ctx.keys_changed,
bridge_pool.ctx.verifiers,
)
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -1463,13 +1478,15 @@ fn parameters(c: &mut Criterion) {

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(parameters
.validate_tx(
&signed_tx,
parameters.ctx.keys_changed,
parameters.ctx.verifiers,
)
.is_ok())
assert!(
parameters
.validate_tx(
&signed_tx,
parameters.ctx.keys_changed,
parameters.ctx.verifiers,
)
.is_ok()
)
})
});
}
Expand Down Expand Up @@ -1532,13 +1549,14 @@ fn pos(c: &mut Criterion) {

group.bench_function(bench_name, |b| {
b.iter(|| {
assert!(pos
.validate_tx(
assert!(
pos.validate_tx(
&signed_tx,
pos.ctx.keys_changed,
pos.ctx.verifiers,
)
.is_ok())
.is_ok()
)
})
});
}
Expand Down
47 changes: 11 additions & 36 deletions crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,11 +1282,9 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
let required = value / threshold;
// Forget about the trace amount left over because we cannot
// realize its value
let trace = I128Sum::from_pair(asset_type, value % threshold)
.expect("the trace should be a valid i128");
let trace = I128Sum::from_pair(asset_type, value % threshold);
let normed_trace =
I128Sum::from_pair(normed_asset_type, value % threshold)
.expect("the trace should be a valid i128");
I128Sum::from_pair(normed_asset_type, value % threshold);
// Record how much more of the given conversion has been used
*usage += required;
// Apply the conversions to input and move the trace amount to output
Expand Down Expand Up @@ -1466,13 +1464,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {

// The amount contributed by this note before conversion
let pre_contr =
I128Sum::from_pair(note.asset_type, note.value as i128)
.map_err(|()| {
Error::Other(
"received note has invalid value or asset type"
.to_string(),
)
})?;
I128Sum::from_pair(note.asset_type, note.value as i128);
let (contr, normed_contr, proposed_convs) = self
.compute_exchanged_amount(
context.client(),
Expand Down Expand Up @@ -1553,12 +1545,10 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
res += ValueSum::from_pair(
pre_asset_type.token,
decoded_change,
)
.expect("expected this to fit");
);
}
None => {
undecoded += ValueSum::from_pair(*asset_type, *val)
.expect("expected this to fit");
undecoded += ValueSum::from_pair(*asset_type, *val);
}
_ => {}
}
Expand Down Expand Up @@ -1588,11 +1578,9 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
res += MaspAmount::from_pair(
(decoded.epoch, decoded.token),
decoded_change,
)
.expect("unable to construct decoded amount");
);
} else {
undecoded += ValueSum::from_pair(*asset_type, *val)
.expect("expected this to fit");
undecoded += ValueSum::from_pair(*asset_type, *val);
}
}
(res, undecoded)
Expand All @@ -1611,8 +1599,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
if let Some(decoded) =
self.decode_asset_type(client, *asset_type).await
{
res += ValueSum::from_pair((*asset_type, decoded), *val)
.expect("unable to construct decoded amount");
res += ValueSum::from_pair((*asset_type, decoded), *val);
}
}
res
Expand Down Expand Up @@ -1825,9 +1812,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {

// Anotate the asset type in the value balance with its decoding in
// order to facilitate cross-epoch computations
let value_balance = builder.value_balance().map_err(|e| {
Error::Other(format!("unable to complete value balance: {}", e))
})?;
let value_balance = builder.value_balance();
let value_balance = context
.shielded_mut()
.await
Expand Down Expand Up @@ -1917,8 +1902,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
// Convert the shortfall into a I128Sum
let mut shortfall = I128Sum::zero();
for (asset_type, val) in asset_types.iter().zip(rem_amount) {
shortfall += I128Sum::from_pair(*asset_type, val.into())
.expect("unable to construct value sum");
shortfall += I128Sum::from_pair(*asset_type, val.into());
}
// Return an insufficient ffunds error
return Result::Err(TransferErr::from(
Expand All @@ -1930,16 +1914,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
if let Some(sk) = spending_key {
// Represents the amount of inputs we are short by
let mut additional = I128Sum::zero();
for (asset_type, amt) in builder
.value_balance()
.map_err(|e| {
Error::Other(format!(
"unable to complete value balance: {}",
e
))
})?
.components()
{
for (asset_type, amt) in builder.value_balance().components() {
match amt.cmp(&0) {
Ordering::Greater => {
// Send the change in this asset type back to the sender
Expand Down
Loading

0 comments on commit dea5d4b

Please sign in to comment.