Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masp miscellaneous fixes #2282

Merged
merged 28 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d8b5114
Updates masp tx to reveal nullifiers
grarco Nov 30, 2023
9f855dc
Masp VP checks uniqueness of nullifiers
grarco Nov 30, 2023
5cc290c
Removes wrong comment
grarco Nov 30, 2023
9ed6d52
Changelog #2240
grarco Nov 30, 2023
f1156c1
Fixes masp vp nullifier validation
grarco Dec 1, 2023
144536f
Reduce code duplication to reveal masp nullifiers
grarco Dec 1, 2023
39e00c5
Refactors `handle_masp_tx`
grarco Dec 4, 2023
4fb5142
Updates masp tx with note commitment tree and anchor
grarco Dec 1, 2023
cf1ad17
Updates masp vp to validate note commitment tree and anchor
grarco Dec 2, 2023
61a46de
Refactors masp nullifiers check in a separate function
grarco Dec 2, 2023
2183aaa
Updates commitment tree anchor only once per block
grarco Dec 2, 2023
f7da77b
Updates the merkle tree anchor only if the tree changed
grarco Dec 3, 2023
694b949
Fixes commitment tree validation in masp vp. Adds a workaround to upd…
grarco Dec 6, 2023
8841aac
Fixes masp vp benchmark
grarco Dec 6, 2023
c09875f
Updates comment
grarco Dec 6, 2023
6276330
Changelog #2244
grarco Dec 6, 2023
fdf7693
`update_allowed_conversions` to publish the updated convert anchor
grarco Dec 6, 2023
3ef207a
Masp VP verifies the anchors of convert descriptions
grarco Dec 6, 2023
01caceb
Improves masp vp keys verification
grarco Dec 7, 2023
751b0df
Removes redundant masp dependency from bench crate
grarco Dec 7, 2023
463bfc8
Fixes conversion anchor handling
grarco Dec 7, 2023
ba7c132
Fixes masp key validation
grarco Dec 7, 2023
1971cf8
Changelog #2248
grarco Dec 7, 2023
7108d5c
Stricter checks on sapling bundle components
grarco Dec 11, 2023
2218b64
Removes useless MASP key from `vp_user`
grarco Dec 13, 2023
f33ebe7
Removes useless fee unshielding epoch
grarco Dec 13, 2023
bb8cd86
Minor refactor to masp fee unshield tests
grarco Dec 13, 2023
4f5a419
Changelog #2282
grarco Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/2282-masp-misc-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Removed useless epoch for fee unshielding.
([\#2282](https://github.com/anoma/namada/pull/2282))
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/2240-nullifier-uniqueness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Prevents double-spending in masp by adding a nullifier set.
([\#2240](https://github.com/anoma/namada/pull/2240))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updates masp tx to store the notes and the native vp to validate them and the
anchors. ([\#2244](https://github.com/anoma/namada/pull/2244))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updates the masp vp to validate the convert description's anchor.
([\#2248](https://github.com/anoma/namada/pull/2248))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2282-masp-misc-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Removed useless epoch for fee unshielding and refactored tests.
([\#2282](https://github.com/anoma/namada/pull/2282))
1 change: 1 addition & 0 deletions Cargo.lock

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

50 changes: 19 additions & 31 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub async fn submit_reveal_aux<'a>(
"Submitting a tx to reveal the public key for address \
{address}..."
);
let (mut tx, signing_data, _epoch) =
let (mut tx, signing_data) =
tx::build_reveal_pk(context, &args, &public_key).await?;

signing::generate_test_vector(context, &tx).await?;
Expand All @@ -244,7 +244,7 @@ pub async fn submit_bridge_pool_tx<'a, N: Namada<'a>>(
args: args::EthereumBridgePool,
) -> Result<(), error::Error> {
let tx_args = args.tx.clone();
let (mut tx, signing_data, _epoch) = args.clone().build(namada).await?;
let (mut tx, signing_data) = args.clone().build(namada).await?;

signing::generate_test_vector(namada, &tx).await?;

Expand Down Expand Up @@ -272,7 +272,7 @@ where
{
submit_reveal_aux(namada, args.tx.clone(), &args.owner).await?;

let (mut tx, signing_data, _epoch) = args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;

signing::generate_test_vector(namada, &tx).await?;

Expand All @@ -296,7 +296,7 @@ pub async fn submit_update_account<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _epoch) = args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;

signing::generate_test_vector(namada, &tx).await?;

Expand All @@ -320,8 +320,7 @@ pub async fn submit_init_account<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _epoch) =
tx::build_init_account(namada, &args).await?;
let (mut tx, signing_data) = tx::build_init_account(namada, &args).await?;

signing::generate_test_vector(namada, &tx).await?;

Expand Down Expand Up @@ -919,7 +918,7 @@ where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
submit_reveal_aux(namada, args.tx.clone(), &args.source).await?;
let (mut tx, signing_data, _epoch) = args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -945,8 +944,7 @@ where
let current_epoch = rpc::query_and_print_epoch(namada).await;
let governance_parameters =
rpc::query_governance_parameters(namada.client()).await;
let (mut tx_builder, signing_data, _fee_unshield_epoch) = if args.is_offline
{
let (mut tx_builder, signing_data) = if args.is_offline {
let proposal = OfflineProposal::try_from(args.proposal_data.as_ref())
.map_err(|e| {
error::TxError::FailedGovernaneProposalDeserialize(
Expand Down Expand Up @@ -1071,8 +1069,7 @@ pub async fn submit_vote_proposal<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx_builder, signing_data, _fee_unshield_epoch) = if args.is_offline
{
let (mut tx_builder, signing_data) = if args.is_offline {
let default_signer = Some(args.voter.clone());
let signing_data = aux_signing_data(
namada,
Expand Down Expand Up @@ -1247,8 +1244,7 @@ where
let default_address = args.source.clone().unwrap_or(args.validator.clone());
submit_reveal_aux(namada, args.tx.clone(), &default_address).await?;

let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -1271,7 +1267,7 @@ pub async fn submit_unbond<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch, latest_withdrawal_pre) =
let (mut tx, signing_data, latest_withdrawal_pre) =
args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

Expand All @@ -1297,8 +1293,7 @@ pub async fn submit_withdraw<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -1321,8 +1316,7 @@ pub async fn submit_claim_rewards<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand Down Expand Up @@ -1368,8 +1362,7 @@ pub async fn submit_validator_commission_change<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -1392,8 +1385,7 @@ pub async fn submit_validator_metadata_change<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand Down Expand Up @@ -1438,8 +1430,7 @@ pub async fn submit_unjail_validator<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -1462,8 +1453,7 @@ pub async fn submit_deactivate_validator<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -1486,8 +1476,7 @@ pub async fn submit_reactivate_validator<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;
signing::generate_test_vector(namada, &tx).await?;

if args.tx.dump_tx {
Expand All @@ -1510,8 +1499,7 @@ pub async fn submit_update_steward_commission<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _fee_unshield_epoch) =
args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;

signing::generate_test_vector(namada, &tx).await?;

Expand All @@ -1535,7 +1523,7 @@ pub async fn submit_resign_steward<'a, N: Namada<'a>>(
where
<N::Client as namada::ledger::queries::Client>::Error: std::fmt::Display,
{
let (mut tx, signing_data, _epoch) = args.build(namada).await?;
let (mut tx, signing_data) = args.build(namada).await?;

signing::generate_test_vector(namada, &tx).await?;

Expand Down
30 changes: 29 additions & 1 deletion apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
//! Implementation of the `FinalizeBlock` ABCI++ method for the Shell

use data_encoding::HEXUPPER;
use masp_primitives::merkle_tree::CommitmentTree;
use masp_primitives::sapling::Node;
use masp_proofs::bls12_381;
use namada::core::ledger::inflation;
use namada::core::ledger::masp_conversions::update_allowed_conversions;
use namada::core::ledger::pgf::ADDRESS as pgf_address;
use namada::core::types::storage::KeySeg;
use namada::ledger::events::EventType;
use namada::ledger::gas::{GasMetering, TxGasMeter};
use namada::ledger::parameters::storage as params_storage;
use namada::ledger::pos::{namada_proof_of_stake, staking_token_address};
use namada::ledger::protocol;
use namada::ledger::storage::wl_storage::WriteLogAndStorage;
use namada::ledger::storage::write_log::StorageModification;
use namada::ledger::storage::EPOCH_SWITCH_BLOCKS_DELAY;
use namada::ledger::storage_api::token::credit_tokens;
use namada::ledger::storage_api::{pgf, StorageRead, StorageWrite};
use namada::ledger::storage_api::{pgf, ResultExt, StorageRead, StorageWrite};
use namada::proof_of_stake::{
find_validator_by_raw_hash, read_last_block_proposer_address,
read_pos_params, read_total_stake, write_last_block_proposer_address,
};
use namada::types::address::MASP;
use namada::types::dec::Dec;
use namada::types::key::tm_raw_hash_to_string;
use namada::types::storage::{BlockHash, BlockResults, Epoch, Header};
use namada::types::token::{
MASP_NOTE_COMMITMENT_ANCHOR_PREFIX, MASP_NOTE_COMMITMENT_TREE_KEY,
};
use namada::types::transaction::protocol::{
ethereum_tx_data_variants, ProtocolTxType,
};
Expand Down Expand Up @@ -557,6 +566,25 @@ where
tracing::info!("{}", stats);
tracing::info!("{}", stats.format_tx_executed());

// Update the MASP commitment tree anchor if the tree was updated
let tree_key = Key::from(MASP.to_db_key())
.push(&MASP_NOTE_COMMITMENT_TREE_KEY.to_owned())
.expect("Cannot obtain a storage key");
if let Some(StorageModification::Write { value }) =
self.wl_storage.write_log.read(&tree_key).0
{
let updated_tree = CommitmentTree::<Node>::try_from_slice(value)
.into_storage_result()?;
let anchor_key = Key::from(MASP.to_db_key())
.push(&MASP_NOTE_COMMITMENT_ANCHOR_PREFIX.to_owned())
.expect("Cannot obtain a storage key")
.push(&namada::core::types::hash::Hash(
bls12_381::Scalar::from(updated_tree.root()).to_bytes(),
))
.expect("Cannot obtain a storage key");
self.wl_storage.write(&anchor_key, ())?;
}

if update_for_tendermint {
self.update_epoch(&mut response);
// send the latest oracle configs. These may have changed due to
Expand Down
43 changes: 43 additions & 0 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
use std::collections::HashMap;
use std::hash::Hash;

use masp_primitives::merkle_tree::CommitmentTree;
use masp_primitives::sapling::Node;
use masp_proofs::bls12_381;
use namada::ledger::parameters::Parameters;
use namada::ledger::storage::traits::StorageHasher;
use namada::ledger::storage::{DBIter, DB};
use namada::ledger::storage_api::token::{credit_tokens, write_denom};
use namada::ledger::storage_api::StorageWrite;
use namada::ledger::{ibc, pos};
use namada::proof_of_stake::BecomeValidator;
use namada::types::address::MASP;
use namada::types::hash::Hash as CodeHash;
use namada::types::key::*;
use namada::types::storage::KeySeg;
use namada::types::time::{DateTimeUtc, TimeZone, Utc};
use namada::types::token::{
MASP_CONVERT_ANCHOR_KEY, MASP_NOTE_COMMITMENT_ANCHOR_PREFIX,
MASP_NOTE_COMMITMENT_TREE_KEY,
};
use namada::vm::validate_untrusted_wasm;
use namada_sdk::eth_bridge::EthBridgeStatus;
use namada_sdk::proof_of_stake::types::ValidatorMetaData;
Expand Down Expand Up @@ -172,6 +180,41 @@ where

ibc::init_genesis_storage(&mut self.wl_storage);

// Init masp commitment tree and anchor
let empty_commitment_tree: CommitmentTree<Node> =
CommitmentTree::empty();
let anchor = empty_commitment_tree.root();
let note_commitment_tree_key = Key::from(MASP.to_db_key())
.push(&MASP_NOTE_COMMITMENT_TREE_KEY.to_owned())
.expect("Cannot obtain a storage key");
self.wl_storage
.write(&note_commitment_tree_key, empty_commitment_tree)
.unwrap();
let commitment_tree_anchor_key = Key::from(MASP.to_db_key())
.push(&MASP_NOTE_COMMITMENT_ANCHOR_PREFIX.to_owned())
.expect("Cannot obtain a storage key")
.push(&namada::core::types::hash::Hash(
bls12_381::Scalar::from(anchor).to_bytes(),
))
.expect("Cannot obtain a storage key");
self.wl_storage
.write(&commitment_tree_anchor_key, ())
.unwrap();

// Init masp convert anchor
let convert_anchor_key = Key::from(MASP.to_db_key())
.push(&MASP_CONVERT_ANCHOR_KEY.to_owned())
.expect("Cannot obtain a storage key");
self.wl_storage.write(
&convert_anchor_key,
namada::core::types::hash::Hash(
bls12_381::Scalar::from(
self.wl_storage.storage.conversion_state.tree.root(),
)
.to_bytes(),
),
)?;

// Set the initial validator set
response.validators = self
.get_abci_validator_updates(true, |pk, power| {
Expand Down
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ path = "host_env.rs"
[dev-dependencies]
namada = { path = "../shared", features = ["testing"] }
namada_apps = { path = "../apps", features = ["benches"] }
masp_primitives.workspace = true
borsh.workspace = true
borsh-ext.workspace = true
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down
Loading
Loading