iden3 / go-iden3-crypto

Go implementation of some cryptographic primitives (that fit inside the SNARK field) and compatible with circomlib
Apache License 2.0
117 stars 38 forks source link

poseidon.Sum(nil) panics #64

Open olegrok opened 2 months ago

olegrok commented 2 months ago

Code is following

package common

import (
    "testing"
    "github.com/iden3/go-iden3-crypto/poseidon"
)

func TestHashNil(t *testing.T) {
    t.Parallel()

    poseidon.Sum(nil)
}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x5681f7]

goroutine 8 [running]:
testing.tRunner.func1.2({0x5d5880, 0x918290})
    /snap/go/10630/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
    /snap/go/10630/src/testing/testing.go:1634 +0x377
panic({0x5d5880?, 0x918290?})
    /snap/go/10630/src/runtime/panic.go:770 +0x132
math/big.(*Int).Bytes(0x0)
    /snap/go/10630/src/math/big/int.go:527 +0x17
github.com/iden3/go-iden3-crypto/poseidon.(*hasher).Sum(0xb?, {0x0, 0x0, 0x0})
    /vendor/github.com/iden3/go-iden3-crypto/poseidon/poseidon_wrapper.go:44 +0x73
github.com/iden3/go-iden3-crypto/poseidon.Sum({0x0, 0x0, 0x0})
    /vendor/github.com/iden3/go-iden3-crypto/poseidon/poseidon_wrapper.go:19 +0xa3
github.com/NilFoundation/nil/common.TestHashNil(0xc000151040)
    /common/hash_test.go:34 +0x25
testing.tRunner(0xc000151040, 0x7971a8)
    /snap/go/10630/src/testing/testing.go:1689 +0xfb
created by testing.(*T).Run in goroutine 1
    /snap/go/10630/src/testing/testing.go:1742 +0x390