Skip to main content

Hash Functions

Overview

The SDK provides various cryptographic hash functions that match Aleo's native hash implementations. These include BHP (Bowe-Hopwood-Pedersen), Pedersen, and Poseidon hash functions.

BHP Hash Functions

BHP (Bowe-Hopwood-Pedersen) hash functions are available with different input sizes:

  • BHP256 - 256-bit input hasher
  • BHP512 - 512-bit input hasher
  • BHP768 - 768-bit input hasher
  • BHP1024 - 1024-bit input hasher

BHP Methods

constructor

Create a BHP hasher with the default domain separator

new BHP256()BHP256
new BHP512()BHP512
new BHP768()BHP768
new BHP1024()BHP1024

setup

Create a BHP hasher with a custom domain separator

setup(domain_separator)BHP
ParamTypeDescription
domain_separatorstringCustom domain separator
returnBHPBHP hasher instance

hash

Returns the BHP hash of the input bits

hash(input)Field
ParamTypeDescription
inputArrayBoolean array representing the input bits
returnFieldThe hash result

hashToGroup

Returns a BHP hash as a group element

hashToGroup(input)Group
ParamTypeDescription
inputArrayBoolean array representing the input bits
returnGroupThe hash result as a group element

commit

Returns a BHP commitment with the given randomizer

commit(input, randomizer)Field
ParamTypeDescription
inputArrayBoolean array representing the input bits
randomizerScalarThe randomizer for the commitment
returnFieldThe commitment result

commitToGroup

Returns a BHP commitment as a group element

commitToGroup(input, randomizer)Group
ParamTypeDescription
inputArrayBoolean array representing the input bits
randomizerScalarThe randomizer for the commitment
returnGroupThe commitment result as a group element

Pedersen Hash Functions

Pedersen hash functions are available for small inputs:

  • Pedersen64 - up to 64-bit input
  • Pedersen128 - up to 128-bit input

Pedersen Methods

constructor

Create a Pedersen hasher with the default domain separator

new Pedersen64()Pedersen64
new Pedersen128()Pedersen128

setup

Create a Pedersen hasher with a custom domain separator

setup(domain_separator)Pedersen
ParamTypeDescription
domain_separatorstringCustom domain separator
returnPedersenPedersen hasher instance

hash

Returns the Pedersen hash of the input bits

hash(input)Field
ParamTypeDescription
inputArrayBoolean array representing the input bits
returnFieldThe hash result

commit

Returns a Pedersen commitment with the given randomizer

commit(input, randomizer)Field
ParamTypeDescription
inputArrayBoolean array representing the input bits
randomizerScalarThe randomizer for the commitment
returnFieldThe commitment result

commitToGroup

Returns a Pedersen commitment as a group element

commitToGroup(input, randomizer)Group
ParamTypeDescription
inputArrayBoolean array representing the input bits
randomizerScalarThe randomizer for the commitment
returnGroupThe commitment result as a group element

Poseidon Hash Functions

Poseidon hash functions operate on field elements with different input rates:

  • Poseidon2 - input rate of 2
  • Poseidon4 - input rate of 4
  • Poseidon8 - input rate of 8

Poseidon Methods

constructor

Create a Poseidon hasher with the default domain separator

new Poseidon2()Poseidon2
new Poseidon4()Poseidon4
new Poseidon8()Poseidon8

setup

Create a Poseidon hasher with a custom domain separator

setup(domain_separator)Poseidon
ParamTypeDescription
domain_separatorstringCustom domain separator
returnPoseidonPoseidon hasher instance

hash

Returns the Poseidon hash of the input field elements

hash(input)Field
ParamTypeDescription
inputArrayArray of Field elements
returnFieldThe hash result

hashMany

Returns the extended Poseidon hash with multiple outputs

hashMany(input, num_outputs)Array
ParamTypeDescription
inputArrayArray of Field elements
num_outputsnumberNumber of output field elements
returnArrayArray of Field elements

hashToScalar

Returns the Poseidon hash on the scalar field

hashToScalar(input)Scalar
ParamTypeDescription
inputArrayArray of Field elements
returnScalarThe hash result as a scalar

hashToGroup

Returns the Poseidon hash on the affine curve

hashToGroup(input)Group
ParamTypeDescription
inputArrayArray of Field elements
returnGroupThe hash result as a group element