Switch to uint32 difficulty

This commit is contained in:
Agost Biro 2024-06-05 23:39:50 +02:00
parent a1b78e0949
commit 373faec6f1
No known key found for this signature in database
4 changed files with 15 additions and 15 deletions

View File

@ -248,14 +248,14 @@ pub trait VDF: Send + Debug {
/// Solve and prove with the Wesolowski VDF using the given parameters. /// 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).
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(); 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. /// Verify with the Wesolowski VDF using the given parameters.
/// `alleged_solution` is the output of `wesolowski_solve`. /// `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(); let vdf = WesolowskiVDFParams(int_size_bits).new();
vdf.verify(challenge, difficulty, alleged_solution).is_ok() vdf.verify(challenge, difficulty.into(), alleged_solution).is_ok()
} }

View File

@ -1,4 +1,4 @@
namespace vdf { namespace vdf {
sequence<u8> wesolowski_solve(u16 int_size_bits, [ByRef] sequence<u8> challenge, u64 difficulty); 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, u64 difficulty, [ByRef] sequence<u8> alleged_solution); boolean wesolowski_verify(u16 int_size_bits, [ByRef] sequence<u8> challenge, u32 difficulty, [ByRef] sequence<u8> alleged_solution);
}; };

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 uint64) []uint8 { func WesolowskiSolve(challenge []uint8, difficulty uint32) []uint8 {
return generated.WesolowskiSolve(intSizeBits, challenge, difficulty) return 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 uint64, allegedSolution []uint8) bool { func WesolowskiVerify(challenge []uint8, difficulty uint32, allegedSolution []uint8) bool {
return generated.WesolowskiVerify(intSizeBits, challenge, difficulty, allegedSolution) return generated.WesolowskiVerify(intSizeBits, challenge, difficulty, allegedSolution)
} }

View File

@ -12,7 +12,7 @@ func getChallenge(seed string) [32]byte {
} }
func TestProveVerify(t *testing.T) { func TestProveVerify(t *testing.T) {
difficulty := uint64(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)
@ -22,12 +22,12 @@ func TestProveVerify(t *testing.T) {
} }
func TestProveRustVerifyNekro(t *testing.T) { func TestProveRustVerifyNekro(t *testing.T) {
difficulty := 100 difficulty := uint32(100)
challenge := getChallenge("TestProveRustVerifyNekro") challenge := getChallenge("TestProveRustVerifyNekro")
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
solution := vdf.WesolowskiSolve(challenge[:], uint64(difficulty)) solution := vdf.WesolowskiSolve(challenge[:], difficulty)
nekroVdf := nekrovdf.New(uint32(difficulty), challenge) nekroVdf := nekrovdf.New(difficulty, challenge)
isOk := nekroVdf.Verify([516]byte(solution)) isOk := nekroVdf.Verify([516]byte(solution))
if !isOk { if !isOk {
t.Fatalf("Verification failed") t.Fatalf("Verification failed")
@ -37,14 +37,14 @@ func TestProveRustVerifyNekro(t *testing.T) {
} }
func TestProveNekroVerifyRust(t *testing.T) { func TestProveNekroVerifyRust(t *testing.T) {
difficulty := 100 difficulty := uint32(100)
challenge := getChallenge("TestProveNekroVerifyRust") challenge := getChallenge("TestProveNekroVerifyRust")
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
nekroVdf := nekrovdf.New(uint32(difficulty), challenge) nekroVdf := nekrovdf.New(difficulty, challenge)
nekroVdf.Execute() nekroVdf.Execute()
proof := nekroVdf.GetOutput() proof := nekroVdf.GetOutput()
isOk := vdf.WesolowskiVerify(challenge[:], uint64(difficulty), proof[:]) isOk := vdf.WesolowskiVerify(challenge[:], difficulty, proof[:])
if !isOk { if !isOk {
t.Fatalf("Verification failed") t.Fatalf("Verification failed")
} }