Hash
const Hash: {
"BLAKE2B": {
"hash": Bytes;
};
"Keccak256": {
"hash": Bytes;
};
"Keccak384": {
"hash": Bytes;
};
"Keccak512": {
"hash": Bytes;
};
"Poseidon": {
"Sponge": typeof Sponge;
"Unsafe": {
"hashToGroup": Group;
};
"hash": Field;
"hashPacked": Field;
"hashToGroup": Group;
"hashWithPrefix": Field;
"initialState": [Field, Field, Field];
"update": [Field, Field, Field];
};
"SHA2_256": {
"hash": Gadgets.SHA256.hash;
};
"SHA3_256": {
"hash": Bytes;
};
"SHA3_384": {
"hash": Bytes;
};
"SHA3_512": {
"hash": Bytes;
};
"hash": Poseidon.hash;
};
A collection of hash functions which can be used in provable code.
Type declaration
BLAKE2B
BLAKE2B: {
"hash": Bytes;
};
BLAKE2B.hash()
Parameters
• bytes: Bytes
Returns
Bytes
Keccak256
Keccak256: {
"hash": Bytes;
};
The pre-NIST Keccak hash function with an output length of 256 bits.
Keccak256.hash()
Hashes the given bytes using Keccak-256.
This is an alias for Keccak.preNist(256, bytes).\
See Keccak.preNist for details and usage examples.
Parameters
• bytes: Bytes
Returns
Bytes
Keccak384
Keccak384: {
"hash": Bytes;
};
The pre-NIST Keccak hash function with an output length of 384 bits.
Keccak384.hash()
Hashes the given bytes using Keccak-384.
This is an alias for Keccak.preNist(384, bytes).\
See Keccak.preNist for details and usage examples.
Parameters
• bytes: Bytes
Returns
Bytes
Keccak512
Keccak512: {
"hash": Bytes;
};
The pre-NIST Keccak hash function with an output length of 512 bits.
Keccak512.hash()
Hashes the given bytes using Keccak-512.
This is an alias for Keccak.preNist(512, bytes).\
See Keccak.preNist for details and usage examples.
Parameters
• bytes: Bytes
Returns
Bytes
Poseidon
Poseidon: {
"Sponge": typeof Sponge;
"Unsafe": {
"hashToGroup": Group;
};
"hash": Field;
"hashPacked": Field;
"hashToGroup": Group;
"hashWithPrefix": Field;
"initialState": [Field, Field, Field];
"update": [Field, Field, Field];
};
Poseidon.Sponge
Sponge: typeof Sponge;
Poseidon.Unsafe
Unsafe: {
"hashToGroup": Group;
};
Poseidon.Unsafe.hashToGroup()
Low-level version of Poseidon.hashToGroup().
Warning: This function is marked unsafe because its output is not deterministic. It returns the square root of a value without constraining which of the two possible square roots is chosen. This allows the prover to choose between two different hashes, which can be a vulnerability if consuming code treats the output as unique.
Parameters
• input: Field[]
Returns
Poseidon.hash()
Parameters
• input: Field[]
Returns
Poseidon.hashPacked()
Hashes a provable type efficiently.
let skHash = Poseidon.hashPacked(PrivateKey, secretKey);
Note: Instead of just doing Poseidon.hash(value.toFields()), this
uses the toInput() method on the provable type to pack the input into as few
field elements as possible. This saves constraints because packing has a much
lower per-field element cost than hashing.
Type parameters
• T
Parameters
• type: WithProvable\<Hashable\<T>>
• value: T
Returns
Poseidon.hashToGroup()
Hashes a list of field elements to a point on the Pallas curve.
The output point is deterministic and its discrete log is not efficiently computable.
Parameters
• input: Field[]
Returns
Poseidon.hashWithPrefix()
Parameters
• prefix: string
• input: Field[]
Returns
Poseidon.initialState()
Returns
Poseidon.update()
Parameters
• state: [Field, Field, Field]
• input: Field[]
Returns
SHA2_256
SHA2_256: {
"hash": Gadgets.SHA256.hash;
};
The SHA2 hash function with an output length of 256 bits.
SHA2_256.hash()
hash: (data: FlexibleBytes) => Bytes = Gadgets.SHA256.hash;
Hashes the given bytes using SHA2-256.
This is an alias for Gadgets.SHA256.hash(bytes).\
See Gadgets.SHA256.hash for details and usage examples.
Parameters
• data: FlexibleBytes
Returns
Bytes
SHA3_256
SHA3_256: {
"hash": Bytes;
};
The SHA3 hash function with an output length of 256 bits.
SHA3_256.hash()
Hashes the given bytes using SHA3-256.
This is an alias for Keccak.nistSha3(256, bytes).\
See Keccak.nistSha3 for details and usage examples.
Parameters
• bytes: Bytes
Returns
Bytes
SHA3_384
SHA3_384: {
"hash": Bytes;
};
The SHA3 hash function with an output length of 384 bits.
SHA3_384.hash()
Hashes the given bytes using SHA3-384.
This is an alias for Keccak.nistSha3(384, bytes).\
See Keccak.nistSha3 for details and usage examples.
Parameters
• bytes: Bytes
Returns
Bytes
SHA3_512
SHA3_512: {
"hash": Bytes;
};
The SHA3 hash function with an output length of 512 bits.
SHA3_512.hash()
Hashes the given bytes using SHA3-512.
This is an alias for Keccak.nistSha3(512, bytes).\
See Keccak.nistSha3 for details and usage examples.
Parameters
• bytes: Bytes
Returns
Bytes
hash()
hash: (input: Field[]) => Field = Poseidon.hash;
Hashes the given field elements using Poseidon. Alias for Poseidon.hash().
let hash = Hash.hash([a, b, c]);
Important: This is by far the most efficient hash function o1js has available in provable code. Use it by default, if no compatibility concerns require you to use a different hash function.
The Poseidon implementation operates over the native Pallas base field and uses parameters generated specifically for the Mina blockchain.
We use a rate of 2, which means that 2 field elements are hashed per permutation.
A permutation causes 11 rows in the constraint system.
You can find the full set of Poseidon parameters here.
Parameters
• input: Field[]