vechain / go-ecvrf

Elliptic Curve Verifiable Radom Function(ECVRF) library written in Go
MIT License
8 stars 11 forks source link

panic: math/big: buffer too small to fit value when using ecvrf.Secp256k1Sha256Tai.Prove #4

Closed yy57 closed 1 year ago

yy57 commented 1 year ago

Thanks for your contributions of the implementation of ecvrf.

When I'm using ecvrf.Secp256k1Sha256Tai.Prove in my code, a panic comes:

`panic: math/big: buffer too small to fit value

goroutine 1 [running]: math/big.nat.bytes(...) /usr/local/go1.18/src/math/big/nat.go:1166 math/big.(Int).FillBytes(0xc00007c8e0, {0xc000022961, 0x20, 0x20}) /usr/local/go1.18/src/math/big/int.go:466 +0xf8 crypto/elliptic.MarshalCompressed({0x63dbf8?, 0x6e7558?}, 0xc0000b3d30?, 0x47fcbb?) /usr/local/go1.18/src/crypto/elliptic/elliptic.go:382 +0xb6 github.com/vechain/go-ecvrf.(core).Marshal(...) /home/flybear/go/pkg/mod/github.com/vechain/go-ecvrf@v0.0.0-20220525125849-96fa0442e765/core.go:46 github.com/vechain/go-ecvrf.(core).HashToCurveTryAndIncrement(0xc0000b3e28, 0xc0000b3e18, {0xc0000242e0, 0x20, 0x20}) /home/flybear/go/pkg/mod/github.com/vechain/go-ecvrf@v0.0.0-20220525125849-96fa0442e765/core.go:94 +0xca github.com/vechain/go-ecvrf.(vrf).Prove(0x63d640?, 0xc0000a0720, {0xc0000242e0, 0x20, 0x20}) /home/flybear/go/pkg/mod/github.com/vechain/go-ecvrf@v0.0.0-20220525125849-96fa0442e765/vrf.go:92 +0xd5 main.main() /home/flybear/Code/new/main.go:73 +0x137 exit status 2`

I am confused whether there is any wrong operations in my code.

ecdsa private key

-----BEGIN PRIVATE KEY----- MIGkAgEBBDCwC9t6gX86b+U3LhLQb87W+B6HSSq7+oXXcd2Arya0s0Fxf6kS/zbv R3al96T8QxigBwYFK4EEACKhZANiAAQMv937zAcd6ZnrU//ZivqFMuoScQ4+vKP8 7P/6MLPXpzh53fHDdyHim815OHU7adCN/lT8ARZO2TXEoxYezZojqPsUdCS6LSVe eIEfJ7qdf+E2oLiLubzKamwpxj0b2WI= -----END PRIVATE KEY-----

data(string form) for prove

\xd7\x03\xb2\xfb\x04\xda\x1c\x03\xab\xa0dI\x96\x98\xc5Uru \xb5V\xdasWͽ\xa4\xf5k\xa5\xbdN`

yy57 commented 1 year ago

Thanks for your contributions of the implementation of ecvrf.

When I'm using ecvrf.Secp256k1Sha256Tai.Prove in my code, a panic comes:

`panic: math/big: buffer too small to fit value

goroutine 1 [running]: math/big.nat.bytes(...) /usr/local/go1.18/src/math/big/nat.go:1166 math/big.(Int).FillBytes(0xc00007c8e0, {0xc000022961, 0x20, 0x20}) /usr/local/go1.18/src/math/big/int.go:466 +0xf8 crypto/elliptic.MarshalCompressed({0x63dbf8?, 0x6e7558?}, 0xc0000b3d30?, 0x47fcbb?) /usr/local/go1.18/src/crypto/elliptic/elliptic.go:382 +0xb6 github.com/vechain/go-ecvrf.(core).Marshal(...) /home/flybear/go/pkg/mod/github.com/vechain/go-ecvrf@v0.0.0-20220525125849-96fa0442e765/core.go:46 github.com/vechain/go-ecvrf.(core).HashToCurveTryAndIncrement(0xc0000b3e28, 0xc0000b3e18, {0xc0000242e0, 0x20, 0x20}) /home/flybear/go/pkg/mod/github.com/vechain/go-ecvrf@v0.0.0-20220525125849-96fa0442e765/core.go:94 +0xca github.com/vechain/go-ecvrf.(vrf).Prove(0x63d640?, 0xc0000a0720, {0xc0000242e0, 0x20, 0x20}) /home/flybear/go/pkg/mod/github.com/vechain/go-ecvrf@v0.0.0-20220525125849-96fa0442e765/vrf.go:92 +0xd5 main.main() /home/flybear/Code/new/main.go:73 +0x137 exit status 2`

I am confused whether there is any wrong operations in my code.

ecdsa private key

-----BEGIN PRIVATE KEY----- MIGkAgEBBDCwC9t6gX86b+U3LhLQb87W+B6HSSq7+oXXcd2Arya0s0Fxf6kS/zbv R3al96T8QxigBwYFK4EEACKhZANiAAQMv937zAcd6ZnrU//ZivqFMuoScQ4+vKP8 7P/6MLPXpzh53fHDdyHim815OHU7adCN/lT8ARZO2TXEoxYezZojqPsUdCS6LSVe eIEfJ7qdf+E2oLiLubzKamwpxj0b2WI= -----END PRIVATE KEY-----

data(string form) for prove

\xd7\x03\xb2\xfb\x04\xda\x1c\x03\xab\xa0dI\x96\x98\xc5Uru \xb5V\xdasWͽ\xa4\xf5k\xa5\xbdN`

data(string form) for prove \xd7\x03\xb2\xfb\x04\xda\x1c\x03`\xab\xa0dI\x96\x98\xc5Uru\xb5V\xdasWͽ\xa4\xf5k\xa5\xbdN

qianbin commented 1 year ago

Could you provide the code?

yy57 commented 1 year ago

Could you provide the code?

sorry, my mistake.

when I generate ecdsa key, I use parameter elliptic.P384()

sk, _ := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)

but in vrf prove, it work in 256 ecvrf.Secp256k1Sha256Tai.Prove

The issue might arise from this.