Skip to content

Commit

Permalink
Release96: POW bugfix in AstroBWTv3
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDero committed Jun 10, 2022
1 parent 165497c commit ec5da1c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion astrobwt/astrobwtv3/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020 DERO Foundation. All rights reserved.
Copyright (c) 2022 DERO Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
22 changes: 12 additions & 10 deletions astrobwt/astrobwtv3/pow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package astrobwtv3

import "fmt"

//import "os"
import "math/bits"
import "encoding/binary"
import "crypto/rand"
Expand Down Expand Up @@ -36,14 +38,14 @@ func AstroBWTv3(input []byte) (outputhash [32]byte) {
scratch := Pool.Get().(*ScratchData)
defer Pool.Put(scratch)

/* defer func() {
if r := recover(); r != nil { // if something happens due to RAM issues in miner, we should continue, avoiding crashes if possible
var buf [16]byte
rand.Read(buf[:])
outputhash = sha256.Sum256(buf[:]) // return a random falsified hash which will fail the check
}
}()
*/
defer func() {
if r := recover(); r != nil { // if something happens due to RAM issues in miner, we should continue, avoiding crashes if possible
var buf [16]byte
rand.Read(buf[:])
outputhash = sha256.Sum256(buf[:]) // return a random falsified hash which will fail the check
}
}()

var step_3 [256]byte
var counter [16]byte

Expand Down Expand Up @@ -2423,11 +2425,12 @@ func AstroBWTv3(input []byte) (outputhash [32]byte) {

step_3[255] = step_3[255] ^ step_3[pos1] ^ step_3[pos2]

copy(scratch.data[(tries-1)*256:], step_3[:]) // copy all the tmp states

if tries > 260+16 || (step_3[255] >= 0xf0 && tries > 260) { // keep looping until condition is satisfied
break
}

copy(scratch.data[(tries-1)*256:], step_3[:]) // copy all the tmp states
}

if CALCULATE_DISTRIBUTION {
Expand All @@ -2444,7 +2447,6 @@ func AstroBWTv3(input []byte) (outputhash [32]byte) {
if LittleEndian {
scratch.hasher.Reset()
scratch.hasher.Write(scratch.sa_bytes[:data_len*4])

} else {
var s [MAX_LENGTH * 4]byte
for i, c := range scratch.sa[:data_len] {
Expand Down
24 changes: 22 additions & 2 deletions astrobwt/astrobwtv3/pow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "os"
import "fmt"
import "math/rand"
import "testing"
import "encoding/hex"

var cases [][]byte

Expand Down Expand Up @@ -36,8 +37,8 @@ var random_pow_tests = []PowTest{
{"715c3d8c61a967b7664b1413f8af5a2a9ba0005922cb0ba4fac8a2d502b92cd6", "abc"},
{"74cc16efc1aac4768eb8124e23865da4c51ae134e29fa4773d80099c8bd39ab8", "abcd"},
{"d080d0484272d4498bba33530c809a02a4785368560c5c3eac17b5dacd357c4b", "abcde"},
{"ecd6e38831e64304071517c2eaa2f8a90333643849b672e81ab72c41d1237e9c", "abcdef"},
{"18dae03cfaedbe50859e19f599ea39aa541058a8c536b5697032d484c3747d74", "abcdefg"},
{"813e89e0484cbd3fbb3ee059083af53ed761b770d9c245be142c676f669e4607", "abcdef"},
{"3972fe8fe2c9480e9d4eff383b160e2f05cc855dc47604af37bc61fdf20f21ee", "abcdefg"},
{"f96191b7e39568301449d75d42d05090e41e3f79a462819473a62b1fcc2d0997", "abcdefgh"},
{"8c76af6a57dfed744d5b7467fa822d9eb8536a851884aa7d8e3657028d511322", "abcdefghi"},
{"f838568c38f83034b2ff679d5abf65245bd2be1b27c197ab5fbac285061cf0a7", "abcdefghij"},
Expand All @@ -53,6 +54,25 @@ func TestAstroBWTv3(t *testing.T) {
}
}

func TestAstroBWTv3repeattest(t *testing.T) {
data, _ := hex.DecodeString("419ebb000000001bbdc9bf2200000000635d6e4e24829b4249fe0e67878ad4350000000043f53e5436cf610000086b00")

var random_data [48]byte

for i := 0; i < 1024; i++ {
rand.Read(random_data[:])

if i%2 == 0 {
hash := fmt.Sprintf("%x", AstroBWTv3(data[:]))
if hash != "c392762a462fd991ace791bfe858c338c10c23c555796b50f665b636cb8c8440" {
t.Fatalf("%d test failed hash %s", i, hash)
}
} else {
_ = AstroBWTv3(random_data[:])
}
}
}

func Benchmark_AstroBWTv3_2(b *testing.B) {
benchmark_AstroBWTv3(b, 2)
}
Expand Down
2 changes: 1 addition & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ import "github.com/blang/semver/v4"

// right now it has to be manually changed
// do we need to include git commitsha??
var Version = semver.MustParse("3.5.0-95.DEROHE.STARGATE+26022022")
var Version = semver.MustParse("3.5.1-96.DEROHE.STARGATE+26022022")

0 comments on commit ec5da1c

Please sign in to comment.