2024-06-05 20:45:50 +00:00
|
|
|
package vdf_test
|
|
|
|
|
|
|
|
import (
|
2024-06-05 21:19:15 +00:00
|
|
|
"golang.org/x/crypto/sha3"
|
|
|
|
nekrovdf "source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/vdf"
|
2024-06-05 21:56:34 +00:00
|
|
|
"source.quilibrium.com/quilibrium/monorepo/vdf"
|
2024-06-05 20:45:50 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-06-05 21:19:15 +00:00
|
|
|
func getChallenge(seed string) [32]byte {
|
|
|
|
return sha3.Sum256([]byte(seed))
|
|
|
|
}
|
2024-06-05 20:45:50 +00:00
|
|
|
|
|
|
|
func TestProveVerify(t *testing.T) {
|
2024-06-05 21:39:50 +00:00
|
|
|
difficulty := uint32(10000)
|
2024-06-05 21:19:15 +00:00
|
|
|
challenge := getChallenge("TestProveVerify")
|
2024-06-05 21:33:32 +00:00
|
|
|
solution := vdf.WesolowskiSolve(challenge[:], difficulty)
|
|
|
|
isOk := vdf.WesolowskiVerify(challenge[:], difficulty, solution)
|
2024-06-05 20:45:50 +00:00
|
|
|
if !isOk {
|
2024-06-05 21:19:15 +00:00
|
|
|
t.Fatalf("Verification failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProveRustVerifyNekro(t *testing.T) {
|
2024-06-05 21:39:50 +00:00
|
|
|
difficulty := uint32(100)
|
2024-06-05 21:19:15 +00:00
|
|
|
challenge := getChallenge("TestProveRustVerifyNekro")
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
2024-06-05 21:39:50 +00:00
|
|
|
solution := vdf.WesolowskiSolve(challenge[:], difficulty)
|
|
|
|
nekroVdf := nekrovdf.New(difficulty, challenge)
|
2024-06-05 21:19:15 +00:00
|
|
|
isOk := nekroVdf.Verify([516]byte(solution))
|
|
|
|
if !isOk {
|
|
|
|
t.Fatalf("Verification failed")
|
|
|
|
}
|
|
|
|
challenge = sha3.Sum256(solution)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProveNekroVerifyRust(t *testing.T) {
|
2024-06-05 21:39:50 +00:00
|
|
|
difficulty := uint32(100)
|
2024-06-05 21:19:15 +00:00
|
|
|
challenge := getChallenge("TestProveNekroVerifyRust")
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
2024-06-05 21:39:50 +00:00
|
|
|
nekroVdf := nekrovdf.New(difficulty, challenge)
|
2024-06-05 21:19:15 +00:00
|
|
|
nekroVdf.Execute()
|
|
|
|
proof := nekroVdf.GetOutput()
|
2024-06-05 21:39:50 +00:00
|
|
|
isOk := vdf.WesolowskiVerify(challenge[:], difficulty, proof[:])
|
2024-06-05 21:19:15 +00:00
|
|
|
if !isOk {
|
|
|
|
t.Fatalf("Verification failed")
|
|
|
|
}
|
|
|
|
challenge = sha3.Sum256(proof[:])
|
2024-06-05 20:45:50 +00:00
|
|
|
}
|
|
|
|
}
|