mirror of
https://github.com/pseXperiments/icicle.git
synced 2026-01-09 07:27:56 -05:00
# Updates: ## Hashing - Added SpongeHasher class - Can be used to accept any hash function as an argument - Absorb and squeeze are now separated - Memory management is now mostly done by SpongeHasher class, each hash function only describes permutation kernels ## Tree builder - Tree builder is now hash-agnostic. - Tree builder now supports 2D input (matrices) - Tree builder can now use two different hash functions for layer 0 and compression layers ## Poseidon1 - Interface changed to classes - Now allows for any alpha - Now allows passing constants not in a single vector - Now allows for any domain tag - Constants are now released upon going out of scope - Rust wrappers changed to Poseidon struct ## Poseidon2 - Interface changed to classes - Constants are now released upon going out of scope - Rust wrappers changed to Poseidon2 struct ## Keccak - Added Keccak class which inherits SpongeHasher - Now doesn't use gpu registers for storing states To do: - [x] Update poseidon1 golang bindings - [x] Update poseidon1 examples - [x] Fix poseidon2 cuda test - [x] Fix poseidon2 merkle tree builder test - [x] Update keccak class with new design - [x] Update keccak test - [x] Check keccak correctness - [x] Update tree builder rust wrappers - [x] Leave doc comments Future work: - [ ] Add keccak merkle tree builder externs - [ ] Add keccak rust tree builder wrappers - [ ] Write docs - [ ] Add example - [ ] Fix device output for tree builder --------- Co-authored-by: Jeremy Felder <jeremy.felder1@gmail.com> Co-authored-by: nonam3e <71525212+nonam3e@users.noreply.github.com>
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package tests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
core "github.com/ingonyama-zk/icicle/v2/wrappers/golang/core"
|
|
cr "github.com/ingonyama-zk/icicle/v2/wrappers/golang/cuda_runtime"
|
|
grumpkin "github.com/ingonyama-zk/icicle/v2/wrappers/golang/curves/grumpkin"
|
|
poseidon "github.com/ingonyama-zk/icicle/v2/wrappers/golang/curves/grumpkin/poseidon"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestPoseidon(t *testing.T) {
|
|
|
|
arity := 2
|
|
numberOfStates := 1
|
|
|
|
ctx, _ := cr.GetDefaultDeviceContext()
|
|
p, err := poseidon.Load(uint32(arity), &ctx)
|
|
assert.Equal(t, core.IcicleSuccess, err.IcicleErrorCode)
|
|
|
|
cfg := p.GetDefaultSpongeConfig()
|
|
|
|
scalars := grumpkin.GenerateScalars(numberOfStates * arity)
|
|
scalars[0] = scalars[0].Zero()
|
|
scalars[1] = scalars[0].Zero()
|
|
|
|
scalarsCopy := core.HostSliceFromElements(scalars[:numberOfStates*arity])
|
|
|
|
var deviceInput core.DeviceSlice
|
|
scalarsCopy.CopyToDevice(&deviceInput, true)
|
|
var deviceOutput core.DeviceSlice
|
|
deviceOutput.Malloc(numberOfStates*scalarsCopy.SizeOfElement(), scalarsCopy.SizeOfElement())
|
|
|
|
err = p.HashMany(deviceInput, deviceOutput, uint32(numberOfStates), 1, 1, &cfg) //run Hash function
|
|
assert.Equal(t, core.IcicleSuccess, err.IcicleErrorCode)
|
|
|
|
output := make(core.HostSlice[grumpkin.ScalarField], numberOfStates)
|
|
output.CopyFromDevice(&deviceOutput)
|
|
}
|