Add nekryptology compatibility tests

This commit is contained in:
Agost Biro 2024-06-05 23:19:15 +02:00
parent 81dd7550af
commit fe3419b898
No known key found for this signature in database
3 changed files with 56 additions and 5 deletions

View File

@ -1,3 +1,12 @@
module "source.quilibrium.com/quilibrium/cermonyclient/vdf" module source.quilibrium.com/quilibrium/cermonyclient/vdf
go 1.20 go 1.20
// A necessary hack until source.quilibrium.com is open to all
replace source.quilibrium.com/quilibrium/monorepo/nekryptology => ../nekryptology
require (
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/sys v0.21.0 // indirect
source.quilibrium.com/quilibrium/monorepo/nekryptology v0.0.0-00010101000000-000000000000 // indirect
)

4
vdf/go.sum Normal file
View File

@ -0,0 +1,4 @@
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

View File

@ -1,17 +1,55 @@
package vdf_test package vdf_test
import ( import (
"golang.org/x/crypto/sha3"
"source.quilibrium.com/quilibrium/cermonyclient/vdf" "source.quilibrium.com/quilibrium/cermonyclient/vdf"
nekrovdf "source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/vdf"
"testing" "testing"
) )
const intSizeBits = uint16(2048) const intSizeBits = uint16(2048)
const difficulty = uint64(10000)
func getChallenge(seed string) [32]byte {
return sha3.Sum256([]byte(seed))
}
func TestProveVerify(t *testing.T) { func TestProveVerify(t *testing.T) {
solution := vdf.WesolowskiSolve(intSizeBits, []byte{0x01, 0x02, 0x03}, difficulty) difficulty := uint64(10000)
isOk := vdf.WesolowskiVerify(intSizeBits, []byte{0x01, 0x02, 0x03}, difficulty, solution) challenge := getChallenge("TestProveVerify")
solution := vdf.WesolowskiSolve(intSizeBits, challenge[:], difficulty)
isOk := vdf.WesolowskiVerify(intSizeBits, challenge[:], difficulty, solution)
if !isOk { if !isOk {
t.Errorf("WesolowskiVerify failed") t.Fatalf("Verification failed")
}
}
func TestProveRustVerifyNekro(t *testing.T) {
difficulty := 100
challenge := getChallenge("TestProveRustVerifyNekro")
for i := 0; i < 100; i++ {
solution := vdf.WesolowskiSolve(intSizeBits, challenge[:], uint64(difficulty))
nekroVdf := nekrovdf.New(uint32(difficulty), challenge)
isOk := nekroVdf.Verify([516]byte(solution))
if !isOk {
t.Fatalf("Verification failed")
}
challenge = sha3.Sum256(solution)
}
}
func TestProveNekroVerifyRust(t *testing.T) {
difficulty := 100
challenge := getChallenge("TestProveNekroVerifyRust")
for i := 0; i < 100; i++ {
nekroVdf := nekrovdf.New(uint32(difficulty), challenge)
nekroVdf.Execute()
proof := nekroVdf.GetOutput()
isOk := vdf.WesolowskiVerify(intSizeBits, challenge[:], uint64(difficulty), proof[:])
if !isOk {
t.Fatalf("Verification failed")
}
challenge = sha3.Sum256(proof[:])
} }
} }