Remove extra difficulty check for proofs (#289)

* Remove extra difficulty check for proofs

* remove need for underflow check

---------

Co-authored-by: Base Dev <gitlab.dollop533@passmail.net>
This commit is contained in:
Tyler Sturos 2024-09-03 14:40:50 -08:00 committed by GitHub
parent 025aa9baa4
commit ab065006b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 8 deletions

View File

@ -579,15 +579,22 @@ func (w *WesolowskiFrameProver) VerifyWeakRecursiveProof(
}
}
func (w *WesolowskiFrameProver) CalculateChallengeProofDifficulty(
increment uint32,
) uint32 {
if increment >= 700000 {
return 25000
}
return 200000 - (increment / 4)
}
func (w *WesolowskiFrameProver) CalculateChallengeProof(
challenge []byte,
core uint32,
increment uint32,
) ([]byte, error) {
difficulty := 200000 - (increment / 4)
if difficulty < 25000 || increment > 800000 {
difficulty = 25000
}
difficulty := w.CalculateChallengeProofDifficulty(increment)
instanceInput := binary.BigEndian.AppendUint32([]byte{}, core)
instanceInput = append(instanceInput, challenge...)
@ -606,10 +613,7 @@ func (w *WesolowskiFrameProver) VerifyChallengeProof(
core uint32,
proof []byte,
) bool {
difficulty := 200000 - (increment / 4)
if difficulty < 25000 || increment > 800000 {
difficulty = 25000
}
difficulty := w.CalculateChallengeProofDifficulty(increment)
if len(proof) != 516 {
return false

View File

@ -34,3 +34,24 @@ func TestChallengeProof(t *testing.T) {
assert.NoError(t, err)
assert.True(t, w.VerifyChallengeProof([]byte{0x01, 0x02, 0x03}, 1, 0, proofs))
}
func TestCalculateChallengeProofDifficulty(t *testing.T) {
l, _ := zap.NewProduction()
w := crypto.NewWesolowskiFrameProver(l)
// At 0 increments, the difficulty should be 200,000
difficulty0 := w.CalculateChallengeProofDifficulty(0)
assert.Equal(t, 200000, difficulty0)
// At 100,000 increments, the difficulty should be 175,000
difficulty100k := w.CalculateChallengeProofDifficulty(100000)
assert.Equal(t, 175000, difficulty100k)
// At 700,000 increments, the difficulty should be 25,000
difficulty700k := w.CalculateChallengeProofDifficulty(700000)
assert.Equal(t, 25000, difficulty700k)
// At 800,000 increments, the difficulty should stay at 25,000
difficulty800k := w.CalculateChallengeProofDifficulty(800000)
assert.Equal(t, 25000, difficulty800k)
}