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

Anonymity mining claims pallet update #303

Merged
merged 43 commits into from
Mar 21, 2023
Merged

Anonymity mining claims pallet update #303

merged 43 commits into from
Mar 21, 2023

Conversation

semaraugusto
Copy link
Contributor

Summary of changes
Changes introduced in this pull request:
Updates anonimity-mining-claims pallet.

  • Can now initialize/update Unspent and Spent tree roots and verify against the proof roots during claiming.
  • Adding claims-verifier pallet for the zero-knowledge verification using our fixtures.
  • Adding handle_proof_verification implementation

Reference issue to close (if applicable)

Closes #299

@drewstone drewstone requested a review from 1xstj March 11, 2023 03:17
Copy link
Contributor

@drewstone drewstone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One big thing is to convert this pallet back to without an instancing. Let me know your thoughts, if you think we should have multiple versions of these pallets then that's certainly a worthwhile discussion.

circom_from_raw(wasm_buffer)
}

pub fn generate_proof<const N: usize>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you break proving out into a separate file and put a feature flag on the mod? Best to keep code that can't go in the runtime separate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire folder circom-proving is already meant to not be used in the runtime. It is only meant for testing. Technically speaking, we can get rid of the verify_proof function in this file, since it is identical to that in primitives/verifying/circom.rs.

Ok((proof, full_assignment))
}

/// Verifies a given RLN proof
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs / comments need more closer review please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also worth attributing where we got the code from in a citation on the top (add a license header and cite relevant entities w/ links)

/// The map of trees to the maximum number of anchor edges they can have
#[pallet::storage]
#[pallet::getter(fn max_edges)]
pub type MaxEdges<T: Config<I>, I: 'static = ()> = StorageValue<_, u32, ValueQuery>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently doesn't match the comment. Is this meant to be a map? Also since it's rewards pallet we should probably map ResourceID -> u32 to indicate the size of the bridge that a resource ID in question has.

pub type LinkableTreeHasEdge<T: Config<I>, I: 'static = ()> =
StorageMap<_, Blake2_128Concat, (T::TreeId, T::ChainId), bool, ValueQuery>;
#[pallet::getter(fn registered_resource_ids)]
pub type RegisteredResourceIds<T: Config<I>, I: 'static = ()> =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory the anonymity claims could be built on a chain with a SignatureBridge which does register resource IDs. We could and maybe should support a post-registration hook on that pallet which we can use to hook in here so we don't have to double register things all the time.


/// The next spent tree root index
#[pallet::storage]
#[pallet::getter(fn next_spent_root_index)]
pub(super) type NextSpentRootIndex<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::RootIndex, ValueQuery>;
StorageMap<_, Blake2_128Concat, ResourceId, T::RootIndex, ValueQuery>;

// Map of treeId -> root index -> root value for unspent roots
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update comments to account for ResourceId update.

// Add nullifier on VAnchor
for nullifier in &proof_data.input_nullifiers {
T::VAnchor::add_nullifier_hash(Self::ap_vanchor_tree_id(), *nullifier)?;
/// Ensure valid unspent roots
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need better function docs, will help speed up review process to understand the expectation of each function.

TokenWrapper: pallet_token_wrapper::{Pallet, Call, Storage, Event<T>},
KeyStorage: pallet_key_storage::{Pallet, Call, Storage, Event<T>, Config<T>},
AnonymityMiningClaims: pallet_anonymity_mining_claims::{Pallet, Call, Storage, Event<T>, Config<T>}
AnonymityMiningClaims: pallet_anonymity_mining_claims::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't make this pallet instance-able. That allows us to have multiple versions of the same pallet in the runtime, which does seem a bit overkill. The way to do this is to remove all <I> and instance trait extensions. Things like:

  • <T, I> -> <T>
  • <T, I = ()> -> <T>
  • <T: Config<I>, I: 'static = ()> -> <T: Config>

Do book time with me if you want to pair and I can help you learn to do this quickly.

Copy link
Contributor

@akileshtangella akileshtangella Mar 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a non-instanceable pallet take in an instanceable pallet in its Config trait? Because we take in a VAnchor type that represents the APVAnchor and pallet_vanchor is instanceable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume so, maybe @1xstj can chime in too.


#[pallet::storage]
#[pallet::getter(fn parameters)]
/// Details of the module's parameters for different vanchor configurations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments need updating

@akileshtangella akileshtangella changed the title Anonimity mining claims pallet update Anonymity mining claims pallet update Mar 11, 2023
@drewstone
Copy link
Contributor

drewstone commented Mar 11, 2023 via email

@akileshtangella
Copy link
Contributor

@drewstone I'm in favor of merging this. There was a bit trouble getting the benchmarks done, but at least the claims pallet verifier is working. I want @semaraugusto to move onto some other tasks. WDYT?

@akileshtangella akileshtangella marked this pull request as ready for review March 21, 2023 14:59
@drewstone
Copy link
Contributor

drewstone commented Mar 21, 2023

Sounds fine to me. Please make tasks to track benchmarking separately so we can add to future sprints. @saiakilesh.

@drewstone drewstone merged commit f06bc17 into main Mar 21, 2023
@drewstone drewstone deleted the semar/claims-pallet branch March 21, 2023 20:34
@akileshtangella
Copy link
Contributor

Sounds fine to me. Please make tasks to track benchmarking separately so we can add to future sprints. @saiakilesh.

Will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TASK] Anonymity Mining Claims Pallet
3 participants