mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 09:01:32 +01:00
finish eddsa
This commit is contained in:
@@ -15,18 +15,7 @@ func _right_rotate(n [64]frontend.Variable, bits int) [64]frontend.Variable {
|
||||
return result
|
||||
}
|
||||
|
||||
func Sha512Bytes(api frontend.API, in []frontend.Variable) ([512]frontend.Variable) {
|
||||
bits := []frontend.Variable{}
|
||||
for _, v := range in {
|
||||
b := api.ToBinary(v, 8)
|
||||
for i := 0; i < 8; i++ {
|
||||
bits = append(bits, b[7-i])
|
||||
}
|
||||
}
|
||||
return Sha512Bits(api, bits)
|
||||
}
|
||||
|
||||
func Sha512Bits(api frontend.API, in []frontend.Variable) ([512]frontend.Variable) {
|
||||
func Sha512(api frontend.API, in []frontend.Variable) ([512]frontend.Variable) {
|
||||
_not := func(x [64]frontend.Variable) [64]frontend.Variable {
|
||||
return not(api, x)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ type Sha512Circuit struct {
|
||||
}
|
||||
|
||||
func (circuit *Sha512Circuit) Define(api frontend.API) error {
|
||||
res := Sha512Bits(api, circuit.in)
|
||||
res := Sha512(api, circuit.in)
|
||||
if len(res) != 512 { panic("bad length") }
|
||||
for i := 0; i < 512; i++ {
|
||||
api.AssertIsEqual(res[i], circuit.out[i])
|
||||
@@ -28,8 +28,7 @@ var testCurve = ecc.BN254
|
||||
func TestSha512(t *testing.T) {
|
||||
assert := test.NewAssert(t)
|
||||
|
||||
testCase := func(input, output string) {
|
||||
in := toBytes(input)
|
||||
testCase := func(in []byte, output string) {
|
||||
out, err := hex.DecodeString(output)
|
||||
if err != nil { panic(err) }
|
||||
if len(out) != 512 / 8 { panic("bad output length") }
|
||||
@@ -46,8 +45,9 @@ func TestSha512(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
testCase("", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
|
||||
testCase("Succinct Labs", "503ace098aa03f6feec1b5df0a38aee923f744a775508bc81f2b94ad139be297c2e8cd8c44af527b5d3f017a7fc929892c896604047e52e3f518924f52bff0dc")
|
||||
testCase([]byte(""), "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
|
||||
testCase([]byte("Succinct Labs"), "503ace098aa03f6feec1b5df0a38aee923f744a775508bc81f2b94ad139be297c2e8cd8c44af527b5d3f017a7fc929892c896604047e52e3f518924f52bff0dc")
|
||||
testCase(decode("35c323757c20640a294345c89c0bfcebe3d554fdb0c7b7a0bdb72222c531b1ecf7ec1c43f4de9d49556de87b86b26a98942cb078486fdb44de38b80864c3973153756363696e6374204c616273"), "4388243c4452274402673de881b2f942ff5730fd2c7d8ddb94c3e3d789fb3754380cba8faa40554d9506a0730a681e88ab348a04bc5c41d18926f140b59aed39")
|
||||
}
|
||||
|
||||
func toBits(arr []byte) []frontend.Variable {
|
||||
@@ -64,6 +64,10 @@ func toBits(arr []byte) []frontend.Variable {
|
||||
return result
|
||||
}
|
||||
|
||||
func toBytes(s string) []byte {
|
||||
return []byte(s)
|
||||
func decode(s string) []byte {
|
||||
result, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user