Nullifier
Class: Nullifier
Nullifiers are used as a public commitment to a specific anonymous account, to forbid actions like double spending, or allow a consistent identity between anonymous actions.
RFC: https://github.com/o1-labs/o1js/issues/756
Paper: https://eprint.iacr.org/2022/1255.pdf
Hierarchy
- { - private: { c: Field; g_r: Group; h_m_pk_r: Group; } ;- public: { nullifier: Group; s: Scalar; } ;- publicKey:- Group= Group }- ↳ - Nullifier
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new Nullifier(value)
Parameters
| Name | Type | Default value | 
|---|---|---|
| value | Object | undefined | 
| value.private | { c: Field; g_r: Group; h_m_pk_r: Group; } | undefined | 
| value.public | { nullifier: Group; s: Scalar; } | undefined | 
| value.publicKey | Group | Group | 
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).constructor
Defined in
Properties
private
• private: Object
Type declaration
| Name | Type | 
|---|---|
| c | Field | 
| g_r | Group | 
| h_m_pk_r | Group | 
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).private
Defined in
public
• public: Object
Type declaration
| Name | Type | 
|---|---|
| nullifier | Group | 
| s | Scalar | 
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).public
Defined in
publicKey
• publicKey: Group = Group
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).publicKey
Defined in
_isStruct
▪ Static _isStruct: true
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, })._isStruct
Defined in
check
▪ Static check: (value: { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }) => void
Type declaration
▸ (value): void
Add assertions to the proof to check if value is a valid member of type T.
This function does not return anything, rather creates any number of assertions on the proof to prove value is a valid member of the type T.
For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.
Parameters
| Name | Type | Default value | Description | 
|---|---|---|---|
| value | Object | undefined | the element of type Tto put assertions on. | 
| value.private | { c: Field; g_r: Group; h_m_pk_r: Group; } | undefined | - | 
| value.public | { nullifier: Group; s: Scalar; } | undefined | - | 
| value.publicKey | Group | Group | - | 
Returns
void
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).check
Defined in
fromFields
▪ Static fromFields: (fields: Field[]) => { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }
Type declaration
▸ (fields): Object
A function that returns an element of type T from the given provable data.
Important: For any element of type T, this function is the reverse operation of calling toFields method on an element of type T.
Parameters
| Name | Type | Description | 
|---|---|---|
| fields | Field[] | an array of Field elements describing the provable data of the new Telement. | 
Returns
Object
An element of type T generated from the given provable data.
| Name | Type | 
|---|---|
| private | { c: Field; g_r: Group; h_m_pk_r: Group; } | 
| public | { nullifier: Group; s: Scalar; } | 
| publicKey | Group | 
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).fromFields
Defined in
toAuxiliary
▪ Static toAuxiliary: (value?: { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }) => any[]
Type declaration
▸ (value?): any[]
A function that takes value (optional), an element of type T, as argument and returns an array of any type that make up the "auxiliary" (non-provable) data of value.
As any element of the interface ProvablePure<T> includes no "auxiliary" data by definition, this function always returns a default value.
Parameters
| Name | Type | Default value | Description | 
|---|---|---|---|
| value? | Object | undefined | the element of type Tto generate the auxiliary data array from, optional. If not provided, a default value for auxiliary data is returned. | 
| value.private | { c: Field; g_r: Group; h_m_pk_r: Group; } | undefined | - | 
| value.public | { nullifier: Group; s: Scalar; } | undefined | - | 
| value.publicKey | Group | Group | - | 
Returns
any[]
An empty array, as any element of the interface ProvablePure<T> includes no "auxiliary" data by definition.
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).toAuxiliary
Defined in
toFields
▪ Static toFields: (value: { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }) => Field[]
Type declaration
▸ (value): Field[]
A function that takes value, an element of type T, as argument and returns an array of Field elements that make up the provable data of value.
Parameters
| Name | Type | Default value | Description | 
|---|---|---|---|
| value | Object | undefined | the element of type Tto generate the Field array from. | 
| value.private | { c: Field; g_r: Group; h_m_pk_r: Group; } | undefined | - | 
| value.public | { nullifier: Group; s: Scalar; } | undefined | - | 
| value.publicKey | Group | Group | - | 
Returns
Field[]
A Field array describing how this T element is made up of Field elements.
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).toFields
Defined in
toInput
▪ Static toInput: (x: { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }) => { fields?: Field[] ; packed?: [Field, number][]  }
Type declaration
▸ (x): Object
Parameters
| Name | Type | Default value | 
|---|---|---|
| x | Object | undefined | 
| x.private | { c: Field; g_r: Group; h_m_pk_r: Group; } | undefined | 
| x.public | { nullifier: Group; s: Scalar; } | undefined | 
| x.publicKey | Group | Group | 
Returns
Object
| Name | Type | 
|---|---|
| fields? | Field[] | 
| packed? | [ Field,number][] | 
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).toInput
Defined in
toJSON
▪ Static toJSON: (x: { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }) => { private: { c: string; g_r: { x: string; y: string; }; h_m_pk_r: { x: string; y: string; }; } ; public: { nullifier: { x: string; y: string; }; s: string; } ; publicKey: { x: string ; y: string  } = Group }
Type declaration
▸ (x): Object
Parameters
| Name | Type | Default value | 
|---|---|---|
| x | Object | undefined | 
| x.private | { c: Field; g_r: Group; h_m_pk_r: Group; } | undefined | 
| x.public | { nullifier: Group; s: Scalar; } | undefined | 
| x.publicKey | Group | Group | 
Returns
Object
| Name | Type | 
|---|---|
| private | { c: string; g_r: { x: string; y: string; }; h_m_pk_r: { x: string; y: string; }; } | 
| public | { nullifier: { x: string; y: string; }; s: string; } | 
| publicKey | { x:string;y:string} | 
| publicKey.x | string | 
| publicKey.y | string | 
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).toJSON
Defined in
Methods
assertUnused
▸ assertUnused(witness, root): void
Checks if the Nullifier has been used before.
Example
// asserts that the nullifier has not been used before, throws an error otherwise
nullifier.assertUnused();
Parameters
| Name | Type | 
|---|---|
| witness | MerkleMapWitness | 
| root | Field | 
Returns
void
Defined in
getPublicKey
▸ getPublicKey(): PublicKey
Returns the PublicKey that is associated with this Nullifier.
Example
let pk = nullifier.getPublicKey();
Returns
Defined in
isUnused
▸ isUnused(witness, root): Bool
Returns the state of the Nullifier.
Example
// returns a Bool based on whether or not the nullifier has been used before
let isUnused = nullifier.isUnused();
Parameters
| Name | Type | 
|---|---|
| witness | MerkleMapWitness | 
| root | Field | 
Returns
Defined in
key
▸ key(): Field
The key of the nullifier, which belongs to a unique message and a public key. Used as an index in Merkle trees.
Example
// returns the key of the nullifier which can be used as index in a Merkle tree/map
let key = nullifier.key();
Returns
Defined in
setUsed
▸ setUsed(witness): Field
Sets the Nullifier, returns the new Merkle root.
Example
// calculates the new root of the Merkle tree in which the nullifier is set to used
let newRoot = nullifier.setUsed(witness);
Parameters
| Name | Type | 
|---|---|
| witness | MerkleMapWitness | 
Returns
Defined in
verify
▸ verify(message): void
Verifies that the Nullifier belongs to a specific message. Throws an error if the Nullifier is incorrect.
Example
let nullifierMessage = [voteId, ...otherData];
// throws an error if the nullifier is invalid or doesn't belong to this specific message
nullifier.verify(nullifierMessage);
Parameters
| Name | Type | 
|---|---|
| message | Field[] | 
Returns
void
Defined in
createTestNullifier
▸ Static createTestNullifier(message, sk): Nullifier
Note: This is not the recommended way to create a Nullifier in production. Please use mina-signer to create Nullifiers. Also, this function cannot be run within provable code to avoid unintended creations of Nullifiers - a Nullifier should never be created inside proveable code (e.g. a smart contract) directly, but rather created inside the users wallet (or other secure enclaves, so the private key never leaves that enclave).
PLUME: An ECDSA Nullifier Scheme for Unique Pseudonymity within Zero Knowledge Proofs https://eprint.iacr.org/2022/1255.pdf chapter 3 page 14
Parameters
| Name | Type | 
|---|---|
| message | Field[] | 
| sk | PrivateKey | 
Returns
Nullifier
Defined in
fromJSON
▸ Static fromJSON(json): Nullifier
Parameters
| Name | Type | 
|---|---|
| json | Nullifier | 
Returns
Overrides
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).fromJSON
Defined in
sizeInFields
▸ Static sizeInFields(): number
Return the size of the T type in terms of Field type, as Field is the primitive type.
Warning: This function returns a number, so you cannot use it to prove something on chain. You can use it during debugging or to understand the memory complexity of some type.
Returns
number
A number representing the size of the T type in terms of Field type.
Inherited from
Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).sizeInFields