Skip to content

Commit

Permalink
refactor: Rename snippet for verifying MMR membership
Browse files Browse the repository at this point in the history
Rename the snippet for verifying MMR membership where the leaf index is
provided through non-determinism. This is done in anticipation of adding
a snippet where the leaf index is provided on the stack.
  • Loading branch information
Sword-Smith committed Apr 30, 2024
1 parent 57c3ed7 commit 0b4e9c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name": "tasmlib_mmr_verify_from_secret_in",
"name": "tasmlib_mmr_verify_from_secret_in_secret_leaf_index",
"benchmark_result": {
"clock_cycle_count": 1104,
"hash_table_height": 390,
Expand All @@ -11,7 +11,7 @@
"case": "CommonCase"
},
{
"name": "tasmlib_mmr_verify_from_secret_in",
"name": "tasmlib_mmr_verify_from_secret_in_secret_leaf_index",
"benchmark_result": {
"clock_cycle_count": 1974,
"hash_table_height": 570,
Expand Down
4 changes: 2 additions & 2 deletions tasm-lib/src/exported_snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use crate::mmr::calculate_new_peaks_from_append::CalculateNewPeaksFromAppend;
use crate::mmr::calculate_new_peaks_from_leaf_mutation::MmrCalculateNewPeaksFromLeafMutationMtIndices;
use crate::mmr::leaf_index_to_mt_index_and_peak_index::MmrLeafIndexToMtIndexAndPeakIndex;
use crate::mmr::verify_from_memory::MmrVerifyFromMemory;
use crate::mmr::verify_from_secret_in::MmrVerifyLeafMembershipFromSecretIn;
use crate::mmr::verify_from_secret_in_secret_leaf_index::MmrVerifyFromSecretInSecretLeafIndex;
use crate::neptune::mutator_set::commit::Commit;
use crate::neptune::mutator_set::get_swbf_indices::GetSwbfIndices;
use crate::other_snippets::bfe_add::BfeAdd;
Expand Down Expand Up @@ -378,7 +378,7 @@ pub fn name_to_snippet(fn_name: &str) -> Box<dyn BasicSnippet> {
Box::new(MmrCalculateNewPeaksFromLeafMutationMtIndices)
}
"tasmlib_mmr_leaf_index_to_mt_index_and_peak_index" => Box::new(MmrLeafIndexToMtIndexAndPeakIndex),
"tasmlib_mmr_verify_from_secret_in" => Box::new(MmrVerifyLeafMembershipFromSecretIn),
"tasmlib_mmr_verify_from_secret_in_secret_leaf_index" => Box::new(MmrVerifyFromSecretInSecretLeafIndex),
"tasmlib_mmr_bag_peaks" => Box::new(BagPeaks),
"tasmlib_mmr_verify_from_memory" => Box::new(MmrVerifyFromMemory),

Expand Down
2 changes: 1 addition & 1 deletion tasm-lib/src/mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub mod calculate_new_peaks_from_append;
pub mod calculate_new_peaks_from_leaf_mutation;
pub mod leaf_index_to_mt_index_and_peak_index;
pub mod verify_from_memory;
pub mod verify_from_secret_in;
pub mod verify_from_secret_in_secret_leaf_index;

pub const MAX_MMR_HEIGHT: usize = 64;
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use super::leaf_index_to_mt_index_and_peak_index::MmrLeafIndexToMtIndexAndPeakIn
/// Verify that a digest is a leaf in the MMR accumulator. Takes both authentication path and
/// leaf index from secret-in. Crashes the VM if the authentication fails.
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash)]
pub struct MmrVerifyLeafMembershipFromSecretIn;
pub struct MmrVerifyFromSecretInSecretLeafIndex;

impl BasicSnippet for MmrVerifyLeafMembershipFromSecretIn {
impl BasicSnippet for MmrVerifyFromSecretInSecretLeafIndex {
fn inputs(&self) -> Vec<(DataType, String)> {
vec![(
DataType::Tuple(vec![
Expand All @@ -31,7 +31,7 @@ impl BasicSnippet for MmrVerifyLeafMembershipFromSecretIn {
}

fn entrypoint(&self) -> String {
"tasmlib_mmr_verify_from_secret_in".into()
"tasmlib_mmr_verify_from_secret_in_secret_leaf_index".into()
}

// Already on stack (can be secret of public input): _ *peaks leaf_count_hi leaf_count_lo [digest (leaf)]
Expand Down Expand Up @@ -117,7 +117,7 @@ mod benches {

#[test]
fn verify_from_secret_in_benchmark() {
ShadowedProcedure::new(MmrVerifyLeafMembershipFromSecretIn).bench();
ShadowedProcedure::new(MmrVerifyFromSecretInSecretLeafIndex).bench();
}
}

Expand Down Expand Up @@ -155,15 +155,15 @@ mod tests {
#[test]
fn prop() {
for _ in 0..10 {
ShadowedProcedure::new(MmrVerifyLeafMembershipFromSecretIn).test();
ShadowedProcedure::new(MmrVerifyFromSecretInSecretLeafIndex).test();
}
}

#[test]
fn mmra_ap_verify_test_one() {
let digest0 = VmHasher::hash(&BFieldElement::new(4545));
let (mmra, _mps) = mmra_with_mps::<Tip5>(1u64, vec![(0, digest0)]);
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_positive_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_positive_test(
&mmra,
digest0,
0u64,
Expand All @@ -180,15 +180,15 @@ mod tests {
let (mmr, _mps) = mmra_with_mps::<Tip5>(leaf_count, vec![(0u64, digest0), (1u64, digest1)]);

let leaf_index_0 = 0;
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_positive_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_positive_test(
&mmr,
digest0,
leaf_index_0,
vec![digest1],
);

let leaf_index_1 = 1;
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_positive_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_positive_test(
&mmr,
digest1,
leaf_index_1,
Expand All @@ -199,7 +199,7 @@ mod tests {
#[test]
fn mmra_ap_verify_test_pbt() {
let max_size = 19;
let snippet = MmrVerifyLeafMembershipFromSecretIn;
let snippet = MmrVerifyFromSecretInSecretLeafIndex;

for leaf_count in 0..max_size {
let digests: Vec<Digest> = random_elements(leaf_count);
Expand Down Expand Up @@ -275,15 +275,15 @@ mod tests {
let real_membership_proof_last = mmr.append(last_leaf);

// Positive tests
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_positive_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_positive_test(
&mmr,
second_to_last_leaf,
second_to_last_leaf_index,
real_membership_proof_second_to_last
.authentication_path
.clone(),
);
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_positive_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_positive_test(
&mmr,
last_leaf,
last_leaf_index,
Expand All @@ -292,13 +292,13 @@ mod tests {

// Negative tests
let bad_leaf: Digest = thread_rng().gen();
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_negative_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_negative_test(
&mmr,
bad_leaf,
second_to_last_leaf_index,
real_membership_proof_second_to_last.authentication_path,
);
MmrVerifyLeafMembershipFromSecretIn.prop_verify_from_secret_in_negative_test(
MmrVerifyFromSecretInSecretLeafIndex.prop_verify_from_secret_in_negative_test(
&mmr,
bad_leaf,
last_leaf_index,
Expand All @@ -307,7 +307,7 @@ mod tests {
}
}

impl Procedure for MmrVerifyLeafMembershipFromSecretIn {
impl Procedure for MmrVerifyFromSecretInSecretLeafIndex {
fn rust_shadow(
&self,
stack: &mut Vec<BFieldElement>,
Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {
}
}

impl MmrVerifyLeafMembershipFromSecretIn {
impl MmrVerifyFromSecretInSecretLeafIndex {
fn prepare_state(
&self,
mmr: &MmrAccumulator<Tip5>,
Expand Down Expand Up @@ -486,7 +486,7 @@ mod tests {
let init_state = self.prepare_state(mmr, claimed_leaf, leaf_index, auth_path.clone());
let expected_final_stack = self.init_stack_for_isolated_run();
test_rust_equivalence_given_complete_state(
&ShadowedProcedure::new(MmrVerifyLeafMembershipFromSecretIn),
&ShadowedProcedure::new(MmrVerifyFromSecretInSecretLeafIndex),
&init_state.stack,
&[],
&init_state.nondeterminism,
Expand Down

0 comments on commit 0b4e9c6

Please sign in to comment.