Skip to main content

Nullifier

o1js / Modules / 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

NameTypeDefault value
valueObjectundefined
value.private{ c: Field; g_r: Group; h_m_pk_r: Group; }undefined
value.public{ nullifier: Group; s: Scalar; }undefined
value.publicKeyGroupGroup

Inherited from

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).constructor

Defined in

lib/circuit-value.ts:382

Properties

private

private: Object

Type declaration

NameType
cField
g_rGroup
h_m_pk_rGroup

Inherited from

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).private

Defined in

lib/nullifier.ts:26


public

public: Object

Type declaration

NameType
nullifierGroup
sScalar

Inherited from

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).public

Defined in

lib/nullifier.ts:22


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

lib/nullifier.ts:21


_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

lib/circuit-value.ts:382


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
NameTypeDefault valueDescription
valueObjectundefinedthe element of type T to put assertions on.
value.private{ c: Field; g_r: Group; h_m_pk_r: Group; }undefined-
value.public{ nullifier: Group; s: Scalar; }undefined-
value.publicKeyGroupGroup-
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

snarky.d.ts:157


empty

Static empty: () => { private: { c: Field; g_r: Group; h_m_pk_r: Group; } ; public: { nullifier: Group; s: Scalar; } ; publicKey: Group = Group }

Type declaration

▸ (): Object

Returns

Object

NameType
private{ c: Field; g_r: Group; h_m_pk_r: Group; }
public{ nullifier: Group; s: Scalar; }
publicKeyGroup

Inherited from

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).empty

Defined in

lib/circuit-value.ts:391


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
NameTypeDescription
fieldsField[]an array of Field elements describing the provable data of the new T element.
Returns

Object

An element of type T generated from the given provable data.

NameType
private{ c: Field; g_r: Group; h_m_pk_r: Group; }
public{ nullifier: Group; s: Scalar; }
publicKeyGroup

Inherited from

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).fromFields

Defined in

snarky.d.ts:138


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
NameTypeDefault valueDescription
value?Objectundefinedthe element of type T to 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.publicKeyGroupGroup-
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

snarky.d.ts:127


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
NameTypeDefault valueDescription
valueObjectundefinedthe element of type T to 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.publicKeyGroupGroup-
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

snarky.d.ts:117


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
NameTypeDefault value
xObjectundefined
x.private{ c: Field; g_r: Group; h_m_pk_r: Group; }undefined
x.public{ nullifier: Group; s: Scalar; }undefined
x.publicKeyGroupGroup
Returns

Object

NameType
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

lib/circuit-value.ts:385


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
NameTypeDefault value
xObjectundefined
x.private{ c: Field; g_r: Group; h_m_pk_r: Group; }undefined
x.public{ nullifier: Group; s: Scalar; }undefined
x.publicKeyGroupGroup
Returns

Object

NameType
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.xstring
publicKey.ystring

Inherited from

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).toJSON

Defined in

lib/circuit-value.ts:389

Methods

assertUnused

assertUnused(witness, root): void

Checks if the Nullifier has been used before.

Parameters

NameType
witnessMerkleMapWitness
rootField

Returns

void

Example

// asserts that the nullifier has not been used before, throws an error otherwise
nullifier.assertUnused();

Defined in

lib/nullifier.ts:141


getPublicKey

getPublicKey(): PublicKey

Returns the PublicKey that is associated with this Nullifier.

Returns

PublicKey

Example

let pk = nullifier.getPublicKey();

Defined in

lib/nullifier.ts:170


isUnused

isUnused(witness, root): Bool

Returns the state of the Nullifier.

Parameters

NameType
witnessMerkleMapWitness
rootField

Returns

Bool

Example

// returns a Bool based on whether or not the nullifier has been used before
let isUnused = nullifier.isUnused();

Defined in

lib/nullifier.ts:121


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.

Returns

Field

Example

// returns the key of the nullifier which can be used as index in a Merkle tree/map
let key = nullifier.key();

Defined in

lib/nullifier.ts:108


setUsed

setUsed(witness): Field

Sets the Nullifier, returns the new Merkle root.

Parameters

NameType
witnessMerkleMapWitness

Returns

Field

Example

// calculates the new root of the Merkle tree in which the nullifier is set to used
let newRoot = nullifier.setUsed(witness);

Defined in

lib/nullifier.ts:156


verify

verify(message): void

Verifies that the Nullifier belongs to a specific message. Throws an error if the Nullifier is incorrect.

Parameters

NameType
messageField[]

Returns

void

Example

let nullifierMessage = [voteId, ...otherData];
// throws an error if the nullifier is invalid or doesn't belong to this specific message
nullifier.verify(nullifierMessage);

Defined in

lib/nullifier.ts:47


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

NameType
messageField[]
skPrivateKey

Returns

Nullifier

Defined in

lib/nullifier.ts:183


fromJSON

Static fromJSON(json): Nullifier

Parameters

NameType
jsonNullifier

Returns

Nullifier

Overrides

Struct({ publicKey: Group, public: { nullifier: Group, s: Scalar, }, private: { c: Field, g_r: Group, h_m_pk_r: Group, }, }).fromJSON

Defined in

lib/nullifier.ts:32


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

Defined in

snarky.d.ts:147