How are neuron IDs of SNS neurons derived? I somehow have in mind that they are based on the principal of the creating user and a memo but I can’t find any info about this.
Ok, I’ve found this derivation method in the rosetta code base.
fn neuron_subaccount_hash(principal: &PrincipalId, nonce: u64) -> [u8; 32] {
let mut state = ic_crypto_sha2::Sha256::new();
state.write(&[0x0c]);
state.write(b"neuron-stake");
state.write(principal.as_slice());
state.write(&nonce.to_be_bytes());
state.finish()
}
That works with example neurons of which I know the nonce and principal.
How are nonces of normal SNS neurons, which are created via the NNS dApp, defined? I know that developer neurons specify the memo in the sns_init.yaml file which is then taken for the neuron id generation but how are the nonce for other neurons defined? For the ones I could test, it doesn’t seem to go incrementally from 0 upwards. Is it random?
The nonce is the memo that was added to the ledger transaction for the token transfer to create the neuron (i.e. staking transfer).
For example, here is an example of a staking transfer to create a MOD neuron 78547ca1d46a9665261fc58302dbed5336ea7e7be8bd64ccff97e148ddacc32b. The nonce would be 1.
Thanks for the reply!
So if a user creates multiple neurons via the NNS dApp, the memo/nonce would continuously increment with each new one created?
I’ll double-check here and get back to you. A user could in theory create a neuron using quill
using a completely different memo.
Yes, when creating an SNS neuron on the NNS dapp, the memo will always incremented by 1.
Here is also the code for SNS neuron creation on the NNS dapp.
Hopefully, this gives better insight!