From 373faec6f17b49a648573bdf450ba2b64cd551e7 Mon Sep 17 00:00:00 2001
From: Agost Biro <agostbiro@gmail.com>
Date: Wed, 5 Jun 2024 23:39:50 +0200
Subject: [PATCH] Switch to uint32 difficulty

---
 crates/vdf/src/lib.rs  |  8 ++++----
 crates/vdf/src/lib.udl |  4 ++--
 vdf/vdf.go             |  4 ++--
 vdf/vdf_test.go        | 14 +++++++-------
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/crates/vdf/src/lib.rs b/crates/vdf/src/lib.rs
index 0cd128c..4156829 100644
--- a/crates/vdf/src/lib.rs
+++ b/crates/vdf/src/lib.rs
@@ -248,14 +248,14 @@ pub trait VDF: Send + Debug {
 
 /// Solve and prove with the Wesolowski VDF using the given parameters.
 /// Outputs the concatenated solution and proof (in this order).
-pub fn wesolowski_solve(int_size_bits: u16, challenge: &[u8], difficulty: u64) -> Vec<u8> {
+pub fn wesolowski_solve(int_size_bits: u16, challenge: &[u8], difficulty: u32) -> Vec<u8> {
     let vdf = WesolowskiVDFParams(int_size_bits).new();
-    vdf.solve(challenge, difficulty).expect("invalid difficulty")
+    vdf.solve(challenge, difficulty.into()).expect("invalid difficulty")
 }
 
 /// Verify with the Wesolowski VDF using the given parameters.
 /// `alleged_solution` is the output of `wesolowski_solve`.
-pub fn wesolowski_verify(int_size_bits: u16, challenge: &[u8], difficulty: u64, alleged_solution: &[u8]) -> bool {
+pub fn wesolowski_verify(int_size_bits: u16, challenge: &[u8], difficulty: u32, alleged_solution: &[u8]) -> bool {
     let vdf = WesolowskiVDFParams(int_size_bits).new();
-    vdf.verify(challenge, difficulty, alleged_solution).is_ok()
+    vdf.verify(challenge, difficulty.into(), alleged_solution).is_ok()
 }
diff --git a/crates/vdf/src/lib.udl b/crates/vdf/src/lib.udl
index 4c48661..66c0d18 100644
--- a/crates/vdf/src/lib.udl
+++ b/crates/vdf/src/lib.udl
@@ -1,4 +1,4 @@
 namespace vdf {
-    sequence<u8> wesolowski_solve(u16 int_size_bits, [ByRef] sequence<u8> challenge, u64 difficulty);
-    boolean wesolowski_verify(u16 int_size_bits, [ByRef] sequence<u8> challenge, u64 difficulty, [ByRef] sequence<u8> alleged_solution);
+    sequence<u8> wesolowski_solve(u16 int_size_bits, [ByRef] sequence<u8> challenge, u32 difficulty);
+    boolean wesolowski_verify(u16 int_size_bits, [ByRef] sequence<u8> challenge, u32 difficulty, [ByRef] sequence<u8> alleged_solution);
 };
diff --git a/vdf/vdf.go b/vdf/vdf.go
index bef860f..37c0225 100644
--- a/vdf/vdf.go
+++ b/vdf/vdf.go
@@ -10,12 +10,12 @@ const intSizeBits = uint16(2048)
 
 // WesolowskiSolve Solve and prove with the Wesolowski VDF using the given parameters.
 // Outputs the concatenated solution and proof (in this order).
-func WesolowskiSolve(challenge []uint8, difficulty uint64) []uint8 {
+func WesolowskiSolve(challenge []uint8, difficulty uint32) []uint8 {
 	return generated.WesolowskiSolve(intSizeBits, challenge, difficulty)
 }
 
 // WesolowskiVerify Verify with the Wesolowski VDF using the given parameters.
 // `allegedSolution` is the output of `WesolowskiSolve`.
-func WesolowskiVerify(challenge []uint8, difficulty uint64, allegedSolution []uint8) bool {
+func WesolowskiVerify(challenge []uint8, difficulty uint32, allegedSolution []uint8) bool {
 	return generated.WesolowskiVerify(intSizeBits, challenge, difficulty, allegedSolution)
 }
diff --git a/vdf/vdf_test.go b/vdf/vdf_test.go
index 1e9d4b2..cd1d2b3 100644
--- a/vdf/vdf_test.go
+++ b/vdf/vdf_test.go
@@ -12,7 +12,7 @@ func getChallenge(seed string) [32]byte {
 }
 
 func TestProveVerify(t *testing.T) {
-	difficulty := uint64(10000)
+	difficulty := uint32(10000)
 	challenge := getChallenge("TestProveVerify")
 	solution := vdf.WesolowskiSolve(challenge[:], difficulty)
 	isOk := vdf.WesolowskiVerify(challenge[:], difficulty, solution)
@@ -22,12 +22,12 @@ func TestProveVerify(t *testing.T) {
 }
 
 func TestProveRustVerifyNekro(t *testing.T) {
-	difficulty := 100
+	difficulty := uint32(100)
 	challenge := getChallenge("TestProveRustVerifyNekro")
 
 	for i := 0; i < 100; i++ {
-		solution := vdf.WesolowskiSolve(challenge[:], uint64(difficulty))
-		nekroVdf := nekrovdf.New(uint32(difficulty), challenge)
+		solution := vdf.WesolowskiSolve(challenge[:], difficulty)
+		nekroVdf := nekrovdf.New(difficulty, challenge)
 		isOk := nekroVdf.Verify([516]byte(solution))
 		if !isOk {
 			t.Fatalf("Verification failed")
@@ -37,14 +37,14 @@ func TestProveRustVerifyNekro(t *testing.T) {
 }
 
 func TestProveNekroVerifyRust(t *testing.T) {
-	difficulty := 100
+	difficulty := uint32(100)
 	challenge := getChallenge("TestProveNekroVerifyRust")
 
 	for i := 0; i < 100; i++ {
-		nekroVdf := nekrovdf.New(uint32(difficulty), challenge)
+		nekroVdf := nekrovdf.New(difficulty, challenge)
 		nekroVdf.Execute()
 		proof := nekroVdf.GetOutput()
-		isOk := vdf.WesolowskiVerify(challenge[:], uint64(difficulty), proof[:])
+		isOk := vdf.WesolowskiVerify(challenge[:], difficulty, proof[:])
 		if !isOk {
 			t.Fatalf("Verification failed")
 		}