mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-24 23:55:18 +00:00
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:
parent
025aa9baa4
commit
ab065006b4
@ -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(
|
func (w *WesolowskiFrameProver) CalculateChallengeProof(
|
||||||
challenge []byte,
|
challenge []byte,
|
||||||
core uint32,
|
core uint32,
|
||||||
increment uint32,
|
increment uint32,
|
||||||
) ([]byte, error) {
|
) ([]byte, error) {
|
||||||
difficulty := 200000 - (increment / 4)
|
difficulty := w.CalculateChallengeProofDifficulty(increment)
|
||||||
if difficulty < 25000 || increment > 800000 {
|
|
||||||
difficulty = 25000
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceInput := binary.BigEndian.AppendUint32([]byte{}, core)
|
instanceInput := binary.BigEndian.AppendUint32([]byte{}, core)
|
||||||
instanceInput = append(instanceInput, challenge...)
|
instanceInput = append(instanceInput, challenge...)
|
||||||
@ -606,10 +613,7 @@ func (w *WesolowskiFrameProver) VerifyChallengeProof(
|
|||||||
core uint32,
|
core uint32,
|
||||||
proof []byte,
|
proof []byte,
|
||||||
) bool {
|
) bool {
|
||||||
difficulty := 200000 - (increment / 4)
|
difficulty := w.CalculateChallengeProofDifficulty(increment)
|
||||||
if difficulty < 25000 || increment > 800000 {
|
|
||||||
difficulty = 25000
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(proof) != 516 {
|
if len(proof) != 516 {
|
||||||
return false
|
return false
|
||||||
|
@ -34,3 +34,24 @@ func TestChallengeProof(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, w.VerifyChallengeProof([]byte{0x01, 0x02, 0x03}, 1, 0, proofs))
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user