From ec5da1c381a95129cd10be66b757d21798079d91 Mon Sep 17 00:00:00 2001 From: Captain Date: Fri, 10 Jun 2022 09:05:45 +0000 Subject: [PATCH] Release96: POW bugfix in AstroBWTv3 --- astrobwt/astrobwtv3/LICENSE.txt | 2 +- astrobwt/astrobwtv3/pow.go | 22 ++++++++++++---------- astrobwt/astrobwtv3/pow_test.go | 24 ++++++++++++++++++++++-- config/version.go | 2 +- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/astrobwt/astrobwtv3/LICENSE.txt b/astrobwt/astrobwtv3/LICENSE.txt index 34bc4f25..1e0e59d0 100644 --- a/astrobwt/astrobwtv3/LICENSE.txt +++ b/astrobwt/astrobwtv3/LICENSE.txt @@ -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: diff --git a/astrobwt/astrobwtv3/pow.go b/astrobwt/astrobwtv3/pow.go index 016a838e..50f44d7e 100644 --- a/astrobwt/astrobwtv3/pow.go +++ b/astrobwt/astrobwtv3/pow.go @@ -1,6 +1,8 @@ package astrobwtv3 import "fmt" + +//import "os" import "math/bits" import "encoding/binary" import "crypto/rand" @@ -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 @@ -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 { @@ -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] { diff --git a/astrobwt/astrobwtv3/pow_test.go b/astrobwt/astrobwtv3/pow_test.go index 7179a677..02947baf 100644 --- a/astrobwt/astrobwtv3/pow_test.go +++ b/astrobwt/astrobwtv3/pow_test.go @@ -4,6 +4,7 @@ import "os" import "fmt" import "math/rand" import "testing" +import "encoding/hex" var cases [][]byte @@ -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"}, @@ -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) } diff --git a/config/version.go b/config/version.go index 056e3e7d..fcf9dd10 100644 --- a/config/version.go +++ b/config/version.go @@ -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")