Skip to content

Commit

Permalink
Refactors masp_commitment_anchor_key to be generic
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Dec 28, 2023
1 parent 90aa75b commit 978c24a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
3 changes: 1 addition & 2 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand Down Expand Up @@ -570,7 +569,7 @@ where
.into_storage_result()?;
let anchor_key =
namada::core::types::token::masp_commitment_anchor_key(
&bls12_381::Scalar::from(updated_tree.root()),
updated_tree.root(),
);
self.wl_storage.write(&anchor_key, ())?;
}
Expand Down
4 changes: 1 addition & 3 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ where
.write(&note_commitment_tree_key, empty_commitment_tree)
.unwrap();
let commitment_tree_anchor_key =
namada::core::types::token::masp_commitment_anchor_key(
&bls12_381::Scalar::from(anchor),
);
namada::core::types::token::masp_commitment_anchor_key(anchor);
self.wl_storage
.write(&commitment_tree_anchor_key, ())
.unwrap();
Expand Down
3 changes: 1 addition & 2 deletions benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::rc::Rc;
use std::str::FromStr;

use criterion::{criterion_group, criterion_main, Criterion};
use masp_primitives::bls12_381;
use masp_primitives::sapling::Node;
use namada::core::ledger::governance::storage::proposal::ProposalType;
use namada::core::ledger::governance::storage::vote::{
Expand Down Expand Up @@ -515,7 +514,7 @@ fn setup_storage_for_masp_verification(
.unwrap()
.unwrap();
let anchor_key = namada::core::types::token::masp_commitment_anchor_key(
&bls12_381::Scalar::from(updated_tree.root()),
updated_tree.root(),
);
shielded_ctx
.shell
Expand Down
4 changes: 2 additions & 2 deletions core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,11 +1216,11 @@ pub fn masp_commitment_tree_key() -> Key {
}

/// Get a key for a masp commitment tree anchor
pub fn masp_commitment_anchor_key(anchor: &Scalar) -> Key {
pub fn masp_commitment_anchor_key(anchor: impl Into<Scalar>) -> Key {
Key::from(MASP.to_db_key())
.push(&MASP_NOTE_COMMITMENT_ANCHOR_PREFIX.to_owned())
.expect("Cannot obtain a storage key")
.push(&Hash(anchor.to_bytes()))
.push(&Hash(anchor.into().to_bytes()))
.expect("Cannot obtain a storage key")
}

Expand Down
2 changes: 1 addition & 1 deletion shared/src/ledger/native_vp/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ where
for description in shielded_spends {
let anchor_key =
namada_core::types::token::masp_commitment_anchor_key(
&description.anchor,
description.anchor,
);

// Check if the provided anchor was published before
Expand Down

0 comments on commit 978c24a

Please sign in to comment.