Use arrays in Weso interfaces

This commit is contained in:
Agost Biro 2024-06-06 00:05:02 +02:00
parent 3368c40d13
commit 2a53399b4a
No known key found for this signature in database
2 changed files with 10 additions and 10 deletions

View File

@ -10,12 +10,12 @@ const intSizeBits = uint16(2048)
// WesolowskiSolve Solve and prove with the Wesolowski VDF using the given parameters. // WesolowskiSolve Solve and prove with the Wesolowski VDF using the given parameters.
// Outputs the concatenated solution and proof (in this order). // Outputs the concatenated solution and proof (in this order).
func WesolowskiSolve(challenge []uint8, difficulty uint32) []uint8 { func WesolowskiSolve(challenge [32]byte, difficulty uint32) [516]byte {
return generated.WesolowskiSolve(intSizeBits, challenge, difficulty) return [516]byte(generated.WesolowskiSolve(intSizeBits, challenge[:], difficulty))
} }
// WesolowskiVerify Verify with the Wesolowski VDF using the given parameters. // WesolowskiVerify Verify with the Wesolowski VDF using the given parameters.
// `allegedSolution` is the output of `WesolowskiSolve`. // `allegedSolution` is the output of `WesolowskiSolve`.
func WesolowskiVerify(challenge []uint8, difficulty uint32, allegedSolution []uint8) bool { func WesolowskiVerify(challenge [32]byte, difficulty uint32, allegedSolution [516]byte) bool {
return generated.WesolowskiVerify(intSizeBits, challenge, difficulty, allegedSolution) return generated.WesolowskiVerify(intSizeBits, challenge[:], difficulty, allegedSolution[:])
} }

View File

@ -14,8 +14,8 @@ func getChallenge(seed string) [32]byte {
func TestProveVerify(t *testing.T) { func TestProveVerify(t *testing.T) {
difficulty := uint32(10000) difficulty := uint32(10000)
challenge := getChallenge("TestProveVerify") challenge := getChallenge("TestProveVerify")
solution := vdf.WesolowskiSolve(challenge[:], difficulty) solution := vdf.WesolowskiSolve(challenge, difficulty)
isOk := vdf.WesolowskiVerify(challenge[:], difficulty, solution) isOk := vdf.WesolowskiVerify(challenge, difficulty, solution)
if !isOk { if !isOk {
t.Fatalf("Verification failed") t.Fatalf("Verification failed")
} }
@ -26,13 +26,13 @@ func TestProveRustVerifyNekro(t *testing.T) {
challenge := getChallenge("TestProveRustVerifyNekro") challenge := getChallenge("TestProveRustVerifyNekro")
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
solution := vdf.WesolowskiSolve(challenge[:], difficulty) solution := vdf.WesolowskiSolve(challenge, difficulty)
nekroVdf := nekrovdf.New(difficulty, challenge) nekroVdf := nekrovdf.New(difficulty, challenge)
isOk := nekroVdf.Verify([516]byte(solution)) isOk := nekroVdf.Verify(solution)
if !isOk { if !isOk {
t.Fatalf("Verification failed") t.Fatalf("Verification failed")
} }
challenge = sha3.Sum256(solution) challenge = sha3.Sum256(solution[:])
} }
} }
@ -44,7 +44,7 @@ func TestProveNekroVerifyRust(t *testing.T) {
nekroVdf := nekrovdf.New(difficulty, challenge) nekroVdf := nekrovdf.New(difficulty, challenge)
nekroVdf.Execute() nekroVdf.Execute()
proof := nekroVdf.GetOutput() proof := nekroVdf.GetOutput()
isOk := vdf.WesolowskiVerify(challenge[:], difficulty, proof[:]) isOk := vdf.WesolowskiVerify(challenge, difficulty, proof)
if !isOk { if !isOk {
t.Fatalf("Verification failed") t.Fatalf("Verification failed")
} }