Skip to content

Commit

Permalink
Merge branch 'murisi/test-vectors-with-randomness2' (#3296)
Browse files Browse the repository at this point in the history
* origin/murisi/test-vectors-with-randomness2:
  Added a changelog entry.
  Start including MASP randomness in the test vectors.
  • Loading branch information
brentstone committed May 30, 2024
2 parents be889bb + 1a0f24d commit 76d6bb8
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Include the used MASP randomness parameters in the test vectors.
([\#3296](https://github.com/anoma/namada/pull/3296))
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 @@ -125,8 +125,8 @@ libc = "0.2.97"
libloading = "0.7.2"
linkme = "0.3.24"
# branch = "main"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "3aacc707c5948e7423589ac617305448bead9842" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "3aacc707c5948e7423589ac617305448bead9842", default-features = false, features = ["local-prover"] }
masp_primitives = { git = "https://github.com/anoma/masp", rev = "4ede1c42d76d6348af8224bc8bfac4404321fe82" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "4ede1c42d76d6348af8224bc8bfac4404321fe82", default-features = false, features = ["local-prover"] }
num256 = "0.3.5"
num_cpus = "1.13.0"
num-derive = "0.4"
Expand Down
8 changes: 6 additions & 2 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ pub mod testing {
use borsh_ext::BorshSerializeExt;
use governance::ProposalType;
use ibc::primitives::proto::Any;
use masp_primitives::transaction::components::sapling::builder::StoredBuildParams;
use masp_primitives::transaction::TransparentAddress;
use namada_account::{InitAccount, UpdateAccount};
use namada_core::address::testing::{
Expand Down Expand Up @@ -870,6 +871,7 @@ pub mod testing {
VoteProposal(VoteProposalData),
Withdraw(Withdraw),
Transfer(Transfer),
MaspTransfer(Transfer, (StoredBuildParams, String)),
Bond(Bond),
Redelegation(Redelegation),
UpdateStewardCommission(UpdateStewardCommission),
Expand Down Expand Up @@ -1067,7 +1069,7 @@ pub mod testing {
mut header in arb_header(),
wrapper in arb_wrapper_tx(),
code_hash in arb_hash(),
(masp_tx_type, (shielded_transfer, asset_types)) in prop_oneof![
(masp_tx_type, (shielded_transfer, asset_types, build_params)) in prop_oneof![
(Just(MaspTxType::Shielded), arb_shielded_transfer(0..MAX_ASSETS)),
(Just(MaspTxType::Shielding), arb_shielding_transfer(encode_address(&transfer.source), 1)),
(Just(MaspTxType::Deshielding), arb_deshielding_transfer(encode_address(&transfer.target), 1)),
Expand Down Expand Up @@ -1116,7 +1118,9 @@ pub mod testing {
// Link the Builder to the Transaction by hash code
target: masp_tx_hash,
});
(tx, TxData::Transfer(transfer))
let build_param_bytes =
data_encoding::HEXLOWER.encode(&build_params.serialize_to_vec());
(tx, TxData::MaspTransfer(transfer, (build_params, build_param_bytes)))
}
}

Expand Down
22 changes: 13 additions & 9 deletions crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,7 @@ pub mod testing {
use masp_primitives::sapling::prover::TxProver;
use masp_primitives::sapling::redjubjub::Signature;
use masp_primitives::sapling::{ProofGenerationKey, Rseed};
use masp_primitives::transaction::components::sapling::builder::StoredBuildParams;
use masp_primitives::transaction::components::GROTH_PROOF_SIZE;
use masp_proofs::bellman::groth16::Proof;
use proptest::prelude::*;
Expand Down Expand Up @@ -2938,19 +2939,20 @@ pub mod testing {
prover_rng in arb_rng().prop_map(TestCsprng),
mut rng in arb_rng().prop_map(TestCsprng),
bparams_rng in arb_rng().prop_map(TestCsprng),
) -> (ShieldedTransfer, HashMap<AssetData, u64>) {
) -> (ShieldedTransfer, HashMap<AssetData, u64>, StoredBuildParams) {
let mut rng_build_params = RngBuildParams::new(bparams_rng);
let (masp_tx, metadata) = builder.clone().build(
&MockTxProver(Mutex::new(prover_rng)),
&FeeRule::non_standard(U64Sum::zero()),
&mut rng,
&mut RngBuildParams::new(bparams_rng),
&mut rng_build_params,
).unwrap();
(ShieldedTransfer {
builder: builder.map_builder(WalletMap),
metadata,
masp_tx,
epoch,
}, asset_types)
}, asset_types, rng_build_params.to_stored().unwrap())
}
}

Expand All @@ -2968,19 +2970,20 @@ pub mod testing {
prover_rng in arb_rng().prop_map(TestCsprng),
mut rng in arb_rng().prop_map(TestCsprng),
bparams_rng in arb_rng().prop_map(TestCsprng),
) -> (ShieldedTransfer, HashMap<AssetData, u64>) {
) -> (ShieldedTransfer, HashMap<AssetData, u64>, StoredBuildParams) {
let mut rng_build_params = RngBuildParams::new(bparams_rng);
let (masp_tx, metadata) = builder.clone().build(
&MockTxProver(Mutex::new(prover_rng)),
&FeeRule::non_standard(U64Sum::zero()),
&mut rng,
&mut RngBuildParams::new(bparams_rng),
&mut rng_build_params,
).unwrap();
(ShieldedTransfer {
builder: builder.map_builder(WalletMap),
metadata,
masp_tx,
epoch,
}, asset_types)
}, asset_types, rng_build_params.to_stored().unwrap())
}
}

Expand All @@ -2998,19 +3001,20 @@ pub mod testing {
prover_rng in arb_rng().prop_map(TestCsprng),
mut rng in arb_rng().prop_map(TestCsprng),
bparams_rng in arb_rng().prop_map(TestCsprng),
) -> (ShieldedTransfer, HashMap<AssetData, u64>) {
) -> (ShieldedTransfer, HashMap<AssetData, u64>, StoredBuildParams) {
let mut rng_build_params = RngBuildParams::new(bparams_rng);
let (masp_tx, metadata) = builder.clone().build(
&MockTxProver(Mutex::new(prover_rng)),
&FeeRule::non_standard(U64Sum::zero()),
&mut rng,
&mut RngBuildParams::new(bparams_rng),
&mut rng_build_params,
).unwrap();
(ShieldedTransfer {
builder: builder.map_builder(WalletMap),
metadata,
masp_tx,
epoch,
}, asset_types)
}, asset_types, rng_build_params.to_stored().unwrap())
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ path = "make-db-migration.rs"
namada-eth-bridge = ["namada_sdk/namada-eth-bridge"]

[dev-dependencies]
masp_primitives = { workspace = true, features = ["transparent-inputs"] }
masp_proofs = { workspace = true, default-features = false, features = ["local-prover", "download-params"] }
namada_apps_lib = {path = "../crates/apps_lib", features = ["migrations"]}
namada_macros = {path = "../crates/macros"}
Expand Down
2 changes: 2 additions & 0 deletions examples/tx_schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::error::Error;

use masp_primitives::transaction::components::sapling::builder::StoredBuildParams;
use namada_sdk::borsh::BorshSchema;
use namada_sdk::tx::Tx;

Expand All @@ -12,6 +13,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
let mut definitions = BTreeMap::new();
Tx::add_definitions_recursively(&mut definitions);
StoredBuildParams::add_definitions_recursively(&mut definitions);
std::fs::write(&args[1], format!("{:#?}", definitions))
.expect("unable to save schema");
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions wasm/Cargo.lock

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

6 changes: 3 additions & 3 deletions wasm_for_tests/Cargo.lock

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

0 comments on commit 76d6bb8

Please sign in to comment.