poseidon

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Poseidon hash function, written in the layered circuit.

Index

Constants

View Source
const GATE_4TH_POWER_COST = 20
View Source
const GATE_5TH_POWER_TYPE = 12345

Suppose we have a x^4 gate, which has id 12345 in the prover

View Source
const GATE_MUL_COST = 20
View Source
const GATE_MUL_TYPE = 12346

Variables

This section is empty.

Functions

func Mul

func Mul(field *big.Int, inputs []*big.Int, outputs []*big.Int) error

func PoseidonCircuit

func PoseidonCircuit(
	api frontend.API,
	engine m31.Field,
	param *PoseidonParams,
	input []frontend.Variable,
	useRandomness bool) frontend.Variable

Main function of proving poseidon in circuit.

To obtain a more efficient layered circuit representation, we also feed the internal state of the hash to this function.

func PoseidonM31

func PoseidonM31(param *PoseidonParams, input []constraint.Element) constraint.Element

func Power5

func Power5(field *big.Int, inputs []*big.Int, outputs []*big.Int) error

Types

type PoseidonInternalState

type PoseidonInternalState struct {
	AfterHalfFullRound    [16]constraint.Element
	AfterHalfPartialRound [16]constraint.Element
	AfterPartialRound     [16]constraint.Element
}

func PoseidonM31WithInternalStates

func PoseidonM31WithInternalStates(param *PoseidonParams, input []constraint.Element, withState bool) (PoseidonInternalState, constraint.Element)

Poseidon hash function over M31 field. For convenience, function also outputs an internal state when the hash function is half complete.

type PoseidonInternalStateVar

type PoseidonInternalStateVar struct {
	AfterHalfFullRound    [16]frontend.Variable
	AfterHalfPartialRound [16]frontend.Variable
	AfterPartialRound     [16]frontend.Variable
}

type PoseidonParams

type PoseidonParams struct {
	// number of full rounds
	NumFullRounds int
	// number of half full rounds
	NumHalfFullRounds int
	// number of partial rounds
	NumPartRounds int
	// number of half full rounds
	NumHalfPartialRounds int
	// number of states
	NumStates int
	// mds matrix
	MdsMatrix [][]uint32
	// external round constants
	ExternalRoundConstant [][]uint32
	// internal round constants
	InternalRoundConstant []uint32
}

func NewPoseidonParams

func NewPoseidonParams() *PoseidonParams

TODOs: the parameters are not secure. use a better way to generate the constants

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL