From a2173ef80a5bad5d54ac19c25670398e4afc7f58 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Sun, 7 Nov 2021 11:17:15 +0200 Subject: [PATCH] Switch PoW to a keccak heavyhash variant (#1841) * Add another hash domain for HeavyHash * Add a xoShiRo256PlusPlus implementation * Add a HeavyHash implementation * Replace our current PoW algorithm with oPoW * Change to pow hash to keccak256 * Fix genesis * Fix tests Co-authored-by: Elichai Turkel --- .../dagtraversalmanager/window_test.go | 180 +++++++++--------- .../difficultymanager_test.go | 2 +- .../processes/pruningmanager/pruning_test.go | 4 +- domain/consensus/utils/hashes/domains.go | 19 +- domain/consensus/utils/pow/heavyhash.go | 91 +++++++++ domain/consensus/utils/pow/heavyhash_test.go | 102 ++++++++++ domain/consensus/utils/pow/pow.go | 5 +- domain/consensus/utils/pow/xoshiro.go | 37 ++++ domain/consensus/utils/pow/xoshiro_test.go | 17 ++ domain/dagconfig/genesis.go | 36 ++-- util/difficulty/difficulty_test.go | 2 +- 11 files changed, 379 insertions(+), 116 deletions(-) create mode 100644 domain/consensus/utils/pow/heavyhash.go create mode 100644 domain/consensus/utils/pow/heavyhash_test.go create mode 100644 domain/consensus/utils/pow/xoshiro.go create mode 100644 domain/consensus/utils/pow/xoshiro_test.go diff --git a/domain/consensus/processes/dagtraversalmanager/window_test.go b/domain/consensus/processes/dagtraversalmanager/window_test.go index 076d8c5e2..7a751aaa6 100644 --- a/domain/consensus/processes/dagtraversalmanager/window_test.go +++ b/domain/consensus/processes/dagtraversalmanager/window_test.go @@ -40,12 +40,12 @@ func TestBlockWindow(t *testing.T) { { parents: []string{"C", "D"}, id: "E", - expectedWindow: []string{"D", "C", "B"}, + expectedWindow: []string{"C", "D", "B"}, }, { parents: []string{"C", "D"}, id: "F", - expectedWindow: []string{"D", "C", "B"}, + expectedWindow: []string{"C", "D", "B"}, }, { parents: []string{"A"}, @@ -60,37 +60,37 @@ func TestBlockWindow(t *testing.T) { { parents: []string{"H", "F"}, id: "I", - expectedWindow: []string{"F", "D", "C", "H", "B", "G"}, + expectedWindow: []string{"F", "H", "C", "D", "B", "G"}, }, { parents: []string{"I"}, id: "J", - expectedWindow: []string{"I", "F", "D", "C", "H", "B", "G"}, + expectedWindow: []string{"I", "F", "H", "C", "D", "B", "G"}, }, { parents: []string{"J"}, id: "K", - expectedWindow: []string{"J", "I", "F", "D", "C", "H", "B", "G"}, + expectedWindow: []string{"J", "I", "F", "H", "C", "D", "B", "G"}, }, { parents: []string{"K"}, id: "L", - expectedWindow: []string{"K", "J", "I", "F", "D", "C", "H", "B", "G"}, + expectedWindow: []string{"K", "J", "I", "F", "H", "C", "D", "B", "G"}, }, { parents: []string{"L"}, id: "M", - expectedWindow: []string{"L", "K", "J", "I", "F", "D", "C", "H", "B", "G"}, + expectedWindow: []string{"L", "K", "J", "I", "F", "H", "C", "D", "B", "G"}, }, { parents: []string{"M"}, id: "N", - expectedWindow: []string{"M", "L", "K", "J", "I", "F", "D", "C", "H", "B"}, + expectedWindow: []string{"M", "L", "K", "J", "I", "F", "H", "C", "D", "B"}, }, { parents: []string{"N"}, id: "O", - expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "D", "C", "H"}, + expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "H", "C", "D"}, }, }, dagconfig.TestnetParams.Name: { @@ -129,78 +129,6 @@ func TestBlockWindow(t *testing.T) { id: "H", expectedWindow: []string{"G"}, }, - { - parents: []string{"H", "F"}, - id: "I", - expectedWindow: []string{"F", "D", "H", "C", "G", "B"}, - }, - { - parents: []string{"I"}, - id: "J", - expectedWindow: []string{"I", "F", "D", "H", "C", "G", "B"}, - }, - { - parents: []string{"J"}, - id: "K", - expectedWindow: []string{"J", "I", "F", "D", "H", "C", "G", "B"}, - }, - { - parents: []string{"K"}, - id: "L", - expectedWindow: []string{"K", "J", "I", "F", "D", "H", "C", "G", "B"}, - }, - { - parents: []string{"L"}, - id: "M", - expectedWindow: []string{"L", "K", "J", "I", "F", "D", "H", "C", "G", "B"}, - }, - { - parents: []string{"M"}, - id: "N", - expectedWindow: []string{"M", "L", "K", "J", "I", "F", "D", "H", "C", "G"}, - }, - { - parents: []string{"N"}, - id: "O", - expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "D", "H", "C"}, - }, - }, - dagconfig.DevnetParams.Name: { - { - parents: []string{"A"}, - id: "B", - expectedWindow: []string{}, - }, - { - parents: []string{"B"}, - id: "C", - expectedWindow: []string{"B"}, - }, - { - parents: []string{"B"}, - id: "D", - expectedWindow: []string{"B"}, - }, - { - parents: []string{"D", "C"}, - id: "E", - expectedWindow: []string{"D", "C", "B"}, - }, - { - parents: []string{"D", "C"}, - id: "F", - expectedWindow: []string{"D", "C", "B"}, - }, - { - parents: []string{"A"}, - id: "G", - expectedWindow: []string{}, - }, - { - parents: []string{"G"}, - id: "H", - expectedWindow: []string{"G"}, - }, { parents: []string{"H", "F"}, id: "I", @@ -237,6 +165,78 @@ func TestBlockWindow(t *testing.T) { expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "D", "C", "H"}, }, }, + dagconfig.DevnetParams.Name: { + { + parents: []string{"A"}, + id: "B", + expectedWindow: []string{}, + }, + { + parents: []string{"B"}, + id: "C", + expectedWindow: []string{"B"}, + }, + { + parents: []string{"B"}, + id: "D", + expectedWindow: []string{"B"}, + }, + { + parents: []string{"C", "D"}, + id: "E", + expectedWindow: []string{"C", "D", "B"}, + }, + { + parents: []string{"C", "D"}, + id: "F", + expectedWindow: []string{"C", "D", "B"}, + }, + { + parents: []string{"A"}, + id: "G", + expectedWindow: []string{}, + }, + { + parents: []string{"G"}, + id: "H", + expectedWindow: []string{"G"}, + }, + { + parents: []string{"H", "F"}, + id: "I", + expectedWindow: []string{"F", "C", "H", "D", "G", "B"}, + }, + { + parents: []string{"I"}, + id: "J", + expectedWindow: []string{"I", "F", "C", "H", "D", "G", "B"}, + }, + { + parents: []string{"J"}, + id: "K", + expectedWindow: []string{"J", "I", "F", "C", "H", "D", "G", "B"}, + }, + { + parents: []string{"K"}, + id: "L", + expectedWindow: []string{"K", "J", "I", "F", "C", "H", "D", "G", "B"}, + }, + { + parents: []string{"L"}, + id: "M", + expectedWindow: []string{"L", "K", "J", "I", "F", "C", "H", "D", "G", "B"}, + }, + { + parents: []string{"M"}, + id: "N", + expectedWindow: []string{"M", "L", "K", "J", "I", "F", "C", "H", "D", "G"}, + }, + { + parents: []string{"N"}, + id: "O", + expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "C", "H", "D"}, + }, + }, dagconfig.SimnetParams.Name: { { parents: []string{"A"}, @@ -256,12 +256,12 @@ func TestBlockWindow(t *testing.T) { { parents: []string{"D", "C"}, id: "E", - expectedWindow: []string{"C", "D", "B"}, + expectedWindow: []string{"D", "C", "B"}, }, { parents: []string{"D", "C"}, id: "F", - expectedWindow: []string{"C", "D", "B"}, + expectedWindow: []string{"D", "C", "B"}, }, { parents: []string{"A"}, @@ -276,37 +276,37 @@ func TestBlockWindow(t *testing.T) { { parents: []string{"H", "F"}, id: "I", - expectedWindow: []string{"F", "C", "D", "H", "G", "B"}, + expectedWindow: []string{"F", "H", "D", "C", "G", "B"}, }, { parents: []string{"I"}, id: "J", - expectedWindow: []string{"I", "F", "C", "D", "H", "G", "B"}, + expectedWindow: []string{"I", "F", "H", "D", "C", "G", "B"}, }, { parents: []string{"J"}, id: "K", - expectedWindow: []string{"J", "I", "F", "C", "D", "H", "G", "B"}, + expectedWindow: []string{"J", "I", "F", "H", "D", "C", "G", "B"}, }, { parents: []string{"K"}, id: "L", - expectedWindow: []string{"K", "J", "I", "F", "C", "D", "H", "G", "B"}, + expectedWindow: []string{"K", "J", "I", "F", "H", "D", "C", "G", "B"}, }, { parents: []string{"L"}, id: "M", - expectedWindow: []string{"L", "K", "J", "I", "F", "C", "D", "H", "G", "B"}, + expectedWindow: []string{"L", "K", "J", "I", "F", "H", "D", "C", "G", "B"}, }, { parents: []string{"M"}, id: "N", - expectedWindow: []string{"M", "L", "K", "J", "I", "F", "C", "D", "H", "G"}, + expectedWindow: []string{"M", "L", "K", "J", "I", "F", "H", "D", "C", "G"}, }, { parents: []string{"N"}, id: "O", - expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "C", "D", "H"}, + expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "H", "D", "C"}, }, }, } diff --git a/domain/consensus/processes/difficultymanager/difficultymanager_test.go b/domain/consensus/processes/difficultymanager/difficultymanager_test.go index d4be63db3..a58b80381 100644 --- a/domain/consensus/processes/difficultymanager/difficultymanager_test.go +++ b/domain/consensus/processes/difficultymanager/difficultymanager_test.go @@ -132,7 +132,7 @@ func TestDifficulty(t *testing.T) { case dagconfig.TestnetParams.Name, dagconfig.DevnetParams.Name: expectedBits = uint32(0x1e7f83df) case dagconfig.MainnetParams.Name: - expectedBits = uint32(0x207f83df) + expectedBits = uint32(0x1e7f83df) } if tip.Header.Bits() != expectedBits { diff --git a/domain/consensus/processes/pruningmanager/pruning_test.go b/domain/consensus/processes/pruningmanager/pruning_test.go index 7a2f927e4..f7a8d6c9d 100644 --- a/domain/consensus/processes/pruningmanager/pruning_test.go +++ b/domain/consensus/processes/pruningmanager/pruning_test.go @@ -39,8 +39,8 @@ func TestPruning(t *testing.T) { "dag-for-test-pruning.json": { dagconfig.MainnetParams.Name: "503", dagconfig.TestnetParams.Name: "502", - dagconfig.DevnetParams.Name: "503", - dagconfig.SimnetParams.Name: "503", + dagconfig.DevnetParams.Name: "502", + dagconfig.SimnetParams.Name: "502", }, } diff --git a/domain/consensus/utils/hashes/domains.go b/domain/consensus/utils/hashes/domains.go index 67f48e507..43e6fe146 100644 --- a/domain/consensus/utils/hashes/domains.go +++ b/domain/consensus/utils/hashes/domains.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "github.com/pkg/errors" "golang.org/x/crypto/blake2b" + "golang.org/x/crypto/sha3" ) const ( @@ -13,6 +14,7 @@ const ( transcationSigningECDSADomain = "TransactionSigningHashECDSA" blockDomain = "BlockHash" proofOfWorkDomain = "ProofOfWorkHash" + heavyHashDomain = "HeavyHash" merkleBranchDomain = "MerkleBranchHash" ) @@ -66,11 +68,22 @@ func NewBlockHashWriter() HashWriter { // NewPoWHashWriter Returns a new HashWriter used for the PoW function func NewPoWHashWriter() HashWriter { - blake, err := blake2b.New256([]byte(proofOfWorkDomain)) + keccak256 := sha3.NewLegacyKeccak256() + _, err := keccak256.Write([]byte(proofOfWorkDomain)) if err != nil { - panic(errors.Wrapf(err, "this should never happen. %s is less than 64 bytes", proofOfWorkDomain)) + panic(errors.Wrap(err, "this should never happen")) } - return HashWriter{blake} + return HashWriter{keccak256} +} + +// NewHeavyHashWriter Returns a new HashWriter used for the HeavyHash function +func NewHeavyHashWriter() HashWriter { + keccak256 := sha3.NewLegacyKeccak256() + _, err := keccak256.Write([]byte(heavyHashDomain)) + if err != nil { + panic(errors.Wrap(err, "this should never happen")) + } + return HashWriter{keccak256} } // NewMerkleBranchHashWriter Returns a new HashWriter used for a merkle tree branch diff --git a/domain/consensus/utils/pow/heavyhash.go b/domain/consensus/utils/pow/heavyhash.go new file mode 100644 index 000000000..10ff095ba --- /dev/null +++ b/domain/consensus/utils/pow/heavyhash.go @@ -0,0 +1,91 @@ +package pow + +import ( + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" + "math" +) + +const eps float64 = 1e-9 + +type matrix [64][64]uint16 + +func generateMatrix(hash *externalapi.DomainHash) *matrix { + var mat matrix + generator := newxoShiRo256PlusPlus(hash) + for { + for i := range mat { + for j := 0; j < 64; j += 16 { + val := generator.Uint64() + for shift := 0; shift < 16; shift++ { + mat[i][j+shift] = uint16(val >> (4 * shift) & 0x0F) + } + } + } + if mat.computeRank() == 64 { + return &mat + } + } +} + +func (mat *matrix) computeRank() int { + var B [64][64]float64 + for i := range B { + for j := range B[0] { + B[i][j] = float64(mat[i][j]) + } + } + var rank int + var rowSelected [64]bool + for i := 0; i < 64; i++ { + var j int + for j := 0; j < 64; j++ { + if !rowSelected[j] && math.Abs(B[j][i]) > eps { + break + } + } + if j != 64 { + rank++ + rowSelected[j] = true + for p := i + 1; p < 64; p++ { + B[j][p] /= B[j][i] + } + for k := 0; k < 64; k++ { + if k != j && math.Abs(B[k][i]) > eps { + for p := i + 1; p < 64; p++ { + B[k][p] -= B[j][p] * B[k][i] + } + } + } + } + } + return rank +} + +func (mat *matrix) HeavyHash(hash *externalapi.DomainHash) *externalapi.DomainHash { + hashBytes := hash.ByteArray() + var vector [64]uint16 + var product [64]uint16 + for i := 0; i < 32; i++ { + vector[2*i] = uint16(hashBytes[i] >> 4) + vector[2*i+1] = uint16(hashBytes[i] & 0x0F) + } + // Matrix-vector multiplication, and convert to 4 bits. + for i := 0; i < 64; i++ { + var sum uint16 + for j := 0; j < 64; j++ { + sum += mat[i][j] * vector[j] + } + product[i] = sum >> 10 + } + + // Concatenate 4 LSBs back to 8 bit xor with sum1 + var res [32]byte + for i := range res { + res[i] = hashBytes[i] ^ (byte(product[2*i]<<4) | byte(product[2*i+1])) + } + // Hash again + writer := hashes.NewHeavyHashWriter() + writer.InfallibleWrite(res[:]) + return writer.Finalize() +} diff --git a/domain/consensus/utils/pow/heavyhash_test.go b/domain/consensus/utils/pow/heavyhash_test.go new file mode 100644 index 000000000..8b6739734 --- /dev/null +++ b/domain/consensus/utils/pow/heavyhash_test.go @@ -0,0 +1,102 @@ +package pow + +import ( + "bytes" + "encoding/hex" + "github.com/kaspanet/kaspad/domain/consensus/utils/hashes" + "testing" +) + +func BenchmarkMatrix_HeavyHash(b *testing.B) { + input := []byte("BenchmarkMatrix_HeavyHash") + writer := hashes.NewPoWHashWriter() + writer.InfallibleWrite(input) + hash := writer.Finalize() + matrix := generateMatrix(hash) + for i := 0; i < b.N; i++ { + hash = matrix.HeavyHash(hash) + } +} + +func TestMatrix_HeavyHash(t *testing.T) { + expected, err := hex.DecodeString("288fd7da3f7970c9bb2f8f0c802603a4750aab70afb39ba4174c1c3d57b7f6fe") + if err != nil { + t.Fatal(err) + } + input := []byte{0xC1, 0xEC, 0xFD, 0xFC} + writer := hashes.NewPoWHashWriter() + writer.InfallibleWrite(input) + hashed := testMatrix.HeavyHash(writer.Finalize()) + + if !bytes.Equal(expected, hashed.ByteSlice()) { + t.Fatalf("expected: %x == %s", expected, hashed) + } + +} + +var testMatrix = matrix{ + {13, 2, 14, 13, 2, 15, 14, 3, 10, 4, 1, 8, 4, 3, 8, 15, 15, 15, 15, 15, 2, 11, 15, 15, 15, 1, 7, 12, 12, 4, 2, 0, 6, 1, 14, 10, 12, 14, 15, 8, 10, 12, 0, 5, 13, 3, 14, 10, 10, 6, 12, 11, 11, 7, 6, 6, 10, 2, 2, 4, 11, 12, 0, 5}, + {4, 13, 0, 2, 1, 15, 13, 13, 11, 2, 5, 12, 15, 7, 0, 10, 7, 2, 6, 3, 12, 0, 12, 0, 2, 6, 7, 7, 7, 7, 10, 12, 11, 14, 12, 12, 4, 11, 10, 0, 10, 11, 2, 10, 1, 7, 7, 12, 15, 9, 5, 14, 9, 12, 3, 0, 12, 13, 4, 13, 8, 15, 11, 6}, + {14, 6, 15, 9, 8, 2, 2, 12, 2, 3, 4, 12, 13, 15, 4, 5, 13, 4, 3, 0, 14, 3, 5, 14, 3, 13, 4, 15, 9, 12, 7, 15, 5, 1, 13, 12, 9, 9, 8, 11, 14, 11, 4, 10, 12, 6, 12, 8, 6, 3, 9, 8, 1, 6, 0, 5, 8, 9, 12, 5, 14, 15, 2, 2}, + {9, 6, 7, 6, 0, 11, 5, 6, 2, 14, 12, 6, 4, 13, 8, 9, 2, 1, 9, 7, 4, 5, 10, 8, 11, 11, 11, 15, 7, 11, 1, 14, 3, 8, 14, 8, 2, 8, 13, 7, 8, 8, 15, 7, 1, 13, 7, 9, 1, 7, 15, 15, 0, 0, 12, 15, 13, 5, 13, 10, 1, 5, 6, 13}, + {4, 0, 12, 10, 6, 11, 14, 2, 2, 15, 4, 1, 2, 4, 2, 12, 13, 1, 9, 10, 8, 0, 2, 10, 13, 8, 9, 7, 5, 3, 8, 2, 6, 6, 1, 12, 3, 0, 1, 4, 2, 8, 3, 13, 6, 15, 0, 13, 14, 4, 15, 0, 7, 3, 7, 8, 5, 14, 14, 5, 5, 0, 1, 2}, + {12, 14, 6, 3, 3, 4, 6, 7, 1, 3, 2, 7, 15, 15, 15, 10, 9, 12, 0, 6, 3, 8, 5, 0, 13, 5, 0, 6, 0, 14, 2, 12, 10, 4, 11, 2, 10, 7, 7, 6, 8, 11, 4, 4, 11, 9, 3, 12, 10, 5, 2, 6, 5, 5, 10, 13, 12, 10, 1, 6, 14, 7, 12, 4}, + {7, 14, 6, 7, 7, 12, 4, 1, 8, 6, 8, 13, 13, 5, 12, 14, 10, 8, 6, 2, 12, 3, 8, 15, 5, 15, 15, 3, 14, 0, 8, 6, 9, 12, 9, 7, 3, 8, 4, 0, 7, 14, 3, 3, 13, 14, 3, 7, 3, 2, 2, 3, 3, 12, 6, 7, 4, 1, 14, 10, 6, 10, 2, 9}, + {14, 11, 15, 5, 7, 10, 1, 11, 4, 2, 6, 2, 9, 7, 4, 0, 9, 12, 11, 2, 3, 13, 1, 5, 4, 10, 5, 6, 6, 12, 8, 1, 1, 15, 4, 2, 12, 12, 0, 4, 14, 3, 11, 1, 7, 5, 9, 4, 3, 15, 7, 3, 15, 9, 8, 3, 8, 3, 3, 6, 7, 6, 9, 2}, + {10, 4, 6, 10, 5, 2, 15, 12, 0, 14, 14, 15, 14, 0, 12, 9, 1, 12, 4, 5, 5, 2, 10, 4, 2, 13, 11, 3, 1, 8, 10, 0, 7, 0, 12, 4, 11, 1, 14, 6, 14, 5, 5, 11, 11, 1, 3, 8, 0, 6, 11, 11, 8, 4, 7, 6, 14, 4, 9, 14, 9, 7, 13, 9}, + {12, 7, 9, 8, 2, 3, 3, 5, 14, 8, 0, 9, 7, 4, 2, 15, 15, 3, 11, 11, 8, 5, 7, 5, 0, 15, 10, 8, 0, 13, 1, 14, 8, 10, 1, 4, 13, 1, 13, 3, 11, 11, 2, 3, 10, 6, 8, 14, 15, 2, 10, 10, 12, 7, 7, 6, 6, 3, 13, 8, 1, 14, 2, 1}, + {2, 11, 6, 9, 13, 3, 12, 6, 0, 4, 6, 13, 8, 14, 6, 9, 10, 2, 10, 8, 4, 13, 6, 5, 0, 13, 15, 4, 2, 2, 1, 7, 5, 3, 3, 13, 7, 3, 5, 9, 15, 14, 14, 6, 0, 15, 11, 2, 4, 15, 6, 9, 8, 9, 15, 2, 6, 9, 15, 8, 4, 4, 11, 1}, + {10, 11, 8, 3, 11, 13, 10, 2, 2, 5, 2, 14, 15, 10, 2, 11, 0, 1, 8, 2, 14, 1, 10, 0, 3, 7, 5, 10, 7, 8, 15, 7, 2, 5, 13, 4, 10, 3, 6, 2, 3, 9, 6, 11, 7, 14, 1, 11, 9, 3, 3, 7, 6, 0, 9, 11, 4, 10, 4, 1, 9, 7, 4, 15}, + {13, 8, 15, 14, 11, 12, 5, 3, 9, 14, 1, 5, 14, 13, 14, 5, 13, 5, 4, 10, 9, 9, 0, 0, 6, 12, 5, 7, 2, 7, 2, 6, 6, 6, 1, 12, 9, 15, 7, 11, 11, 10, 11, 1, 10, 10, 0, 8, 1, 4, 5, 5, 8, 10, 10, 15, 6, 8, 13, 11, 11, 3, 15, 5}, + {8, 11, 5, 10, 1, 10, 9, 1, 12, 7, 6, 11, 1, 1, 4, 1, 2, 8, 4, 4, 7, 7, 8, 2, 7, 1, 14, 1, 8, 15, 15, 12, 10, 4, 15, 11, 3, 6, 10, 7, 4, 0, 10, 9, 11, 7, 1, 14, 4, 14, 3, 14, 10, 4, 13, 12, 5, 3, 12, 7, 10, 8, 0, 3}, + {9, 11, 6, 15, 14, 10, 0, 4, 7, 7, 6, 0, 7, 7, 12, 15, 5, 4, 12, 3, 7, 3, 0, 12, 2, 7, 11, 6, 7, 3, 2, 8, 5, 11, 9, 4, 3, 8, 11, 12, 3, 5, 14, 12, 4, 13, 12, 0, 3, 14, 4, 9, 1, 1, 9, 14, 10, 14, 8, 15, 6, 14, 10, 15}, + {10, 14, 10, 0, 10, 12, 15, 0, 3, 9, 11, 10, 3, 5, 1, 1, 9, 1, 7, 15, 7, 8, 10, 10, 12, 11, 5, 1, 10, 3, 6, 6, 13, 0, 13, 1, 4, 5, 9, 4, 9, 15, 8, 4, 13, 13, 4, 5, 5, 11, 1, 13, 15, 3, 10, 15, 7, 11, 10, 15, 8, 12, 10, 3}, + {8, 5, 11, 3, 8, 13, 15, 15, 3, 12, 1, 13, 1, 7, 1, 5, 6, 13, 7, 8, 5, 1, 12, 3, 10, 7, 12, 6, 14, 12, 15, 5, 3, 12, 2, 15, 11, 13, 1, 13, 8, 5, 8, 0, 13, 15, 7, 13, 6, 13, 10, 1, 11, 0, 8, 9, 5, 11, 2, 9, 9, 10, 4, 15}, + {0, 4, 12, 14, 3, 1, 7, 5, 11, 13, 5, 3, 11, 12, 6, 8, 10, 15, 11, 8, 7, 10, 0, 2, 5, 15, 6, 10, 4, 2, 3, 1, 13, 7, 6, 12, 14, 7, 6, 14, 12, 10, 6, 14, 12, 0, 12, 11, 6, 9, 3, 1, 12, 15, 15, 3, 5, 5, 10, 11, 7, 15, 13, 3}, + {12, 14, 2, 14, 13, 6, 15, 7, 8, 8, 14, 13, 9, 2, 2, 10, 3, 15, 6, 10, 11, 7, 13, 0, 12, 1, 5, 8, 8, 12, 1, 11, 1, 3, 2, 4, 10, 7, 7, 7, 3, 10, 7, 2, 2, 3, 0, 1, 13, 5, 8, 2, 14, 0, 11, 13, 9, 3, 13, 2, 14, 2, 15, 4}, + {0, 0, 13, 6, 9, 12, 15, 7, 8, 0, 7, 4, 12, 15, 3, 2, 7, 1, 14, 4, 9, 3, 13, 12, 11, 12, 9, 9, 3, 7, 10, 9, 1, 9, 10, 2, 10, 14, 11, 0, 14, 4, 15, 12, 12, 9, 9, 8, 14, 1, 9, 14, 0, 6, 1, 0, 13, 9, 7, 6, 13, 2, 3, 9}, + {8, 0, 10, 13, 0, 7, 9, 7, 5, 1, 0, 3, 7, 10, 3, 15, 1, 15, 3, 11, 2, 6, 3, 10, 0, 10, 10, 3, 4, 15, 8, 6, 11, 11, 7, 5, 8, 5, 7, 15, 1, 11, 7, 13, 13, 6, 13, 13, 4, 2, 3, 15, 9, 5, 10, 6, 6, 6, 3, 11, 15, 13, 1, 15}, + {1, 1, 2, 10, 2, 2, 9, 5, 9, 2, 0, 1, 14, 2, 11, 6, 11, 6, 1, 0, 13, 7, 14, 1, 15, 14, 13, 7, 12, 11, 8, 11, 2, 11, 6, 10, 2, 3, 0, 0, 15, 0, 4, 6, 4, 12, 5, 5, 7, 14, 10, 6, 0, 3, 13, 0, 8, 1, 13, 10, 5, 1, 7, 5}, + {0, 5, 2, 12, 10, 2, 5, 1, 14, 0, 1, 4, 15, 11, 8, 7, 11, 14, 15, 6, 4, 1, 6, 6, 7, 13, 12, 5, 13, 2, 1, 6, 2, 13, 5, 15, 0, 8, 8, 6, 5, 5, 2, 0, 3, 13, 14, 2, 10, 5, 7, 6, 14, 5, 1, 4, 11, 2, 11, 1, 8, 15, 2, 4}, + {9, 9, 4, 5, 2, 5, 3, 12, 14, 5, 1, 3, 3, 0, 0, 6, 7, 14, 0, 15, 14, 11, 3, 10, 1, 9, 4, 14, 7, 14, 1, 0, 15, 11, 5, 9, 4, 0, 0, 10, 4, 4, 0, 7, 8, 15, 12, 8, 10, 8, 1, 2, 1, 11, 12, 14, 14, 14, 8, 10, 1, 5, 13, 10}, + {5, 10, 4, 4, 11, 10, 0, 6, 0, 12, 10, 5, 9, 11, 8, 10, 11, 3, 11, 14, 12, 9, 4, 6, 11, 12, 8, 7, 6, 14, 0, 6, 12, 4, 5, 3, 9, 0, 11, 6, 1, 3, 2, 12, 8, 9, 7, 12, 14, 7, 12, 6, 11, 13, 0, 2, 1, 3, 1, 8, 12, 2, 15, 15}, + {10, 11, 2, 3, 11, 10, 1, 7, 1, 10, 10, 14, 5, 13, 10, 3, 11, 15, 9, 14, 11, 11, 3, 15, 11, 6, 15, 13, 13, 1, 1, 10, 5, 1, 5, 11, 10, 3, 9, 12, 12, 1, 5, 6, 3, 3, 1, 1, 12, 8, 3, 15, 6, 2, 8, 14, 3, 4, 10, 9, 7, 13, 2, 6}, + {12, 0, 1, 0, 4, 3, 3, 6, 8, 3, 1, 13, 6, 12, 1, 1, 1, 4, 12, 4, 4, 9, 9, 14, 15, 3, 6, 4, 11, 1, 12, 5, 6, 0, 10, 9, 1, 8, 14, 5, 2, 8, 4, 15, 12, 13, 7, 14, 12, 2, 6, 9, 4, 13, 0, 15, 10, 10, 6, 12, 7, 12, 9, 10}, + {0, 8, 5, 11, 12, 12, 11, 7, 2, 9, 2, 15, 1, 1, 0, 0, 6, 5, 10, 1, 11, 12, 8, 7, 1, 7, 10, 4, 2, 8, 2, 5, 1, 1, 2, 9, 2, 0, 3, 7, 5, 1, 5, 5, 3, 1, 4, 3, 14, 8, 11, 7, 8, 0, 2, 13, 3, 15, 1, 13, 14, 15, 11, 13}, + {8, 13, 5, 14, 2, 9, 9, 13, 15, 8, 2, 14, 4, 2, 6, 0, 1, 13, 10, 13, 6, 12, 15, 11, 6, 11, 9, 9, 2, 9, 6, 14, 2, 9, 12, 1, 13, 9, 5, 11, 10, 4, 4, 5, 8, 9, 13, 10, 9, 0, 5, 15, 4, 12, 7, 10, 6, 5, 5, 15, 8, 8, 11, 14}, + {6, 9, 6, 7, 1, 15, 0, 1, 4, 15, 5, 3, 10, 9, 15, 9, 14, 12, 7, 6, 3, 0, 12, 8, 12, 2, 11, 8, 11, 8, 1, 10, 10, 7, 7, 5, 3, 5, 1, 2, 13, 11, 2, 5, 2, 10, 10, 1, 14, 14, 8, 1, 11, 1, 2, 6, 15, 10, 8, 7, 10, 7, 0, 3}, + {12, 6, 11, 1, 1, 7, 8, 1, 5, 5, 8, 4, 6, 5, 6, 4, 2, 8, 4, 1, 0, 0, 14, 2, 10, 14, 14, 11, 2, 9, 14, 15, 12, 14, 9, 3, 7, 14, 4, 7, 12, 9, 3, 5, 1, 0, 12, 9, 10, 5, 11, 12, 10, 10, 6, 14, 6, 13, 13, 5, 5, 10, 13, 10}, + {12, 6, 13, 0, 8, 0, 10, 6, 15, 15, 7, 3, 0, 10, 13, 14, 10, 13, 5, 13, 15, 14, 3, 4, 10, 10, 9, 6, 6, 15, 2, 7, 0, 10, 6, 14, 2, 9, 11, 7, 5, 5, 13, 14, 11, 15, 9, 4, 2, 0, 15, 5, 4, 14, 14, 1, 3, 4, 5, 8, 1, 1, 10, 12}, + {2, 5, 0, 4, 11, 5, 5, 6, 10, 4, 6, 7, 10, 3, 0, 14, 14, 0, 12, 15, 11, 12, 13, 7, 6, 3, 9, 1, 9, 8, 8, 8, 4, 10, 3, 1, 7, 10, 3, 2, 12, 6, 15, 14, 0, 6, 8, 10, 1, 9, 12, 12, 15, 7, 1, 11, 15, 13, 0, 4, 10, 0, 12, 11}, + {8, 12, 14, 15, 14, 15, 10, 0, 2, 14, 3, 1, 2, 6, 0, 2, 1, 7, 9, 0, 15, 13, 5, 14, 6, 8, 15, 4, 15, 6, 10, 6, 15, 3, 12, 8, 5, 4, 10, 5, 3, 0, 4, 13, 10, 9, 8, 4, 6, 3, 9, 6, 12, 11, 9, 13, 8, 10, 9, 9, 8, 12, 1, 2}, + {11, 10, 15, 15, 5, 14, 15, 7, 5, 9, 14, 14, 7, 11, 6, 6, 3, 8, 2, 3, 4, 14, 11, 1, 12, 15, 11, 6, 0, 0, 13, 7, 14, 3, 12, 14, 0, 15, 6, 1, 11, 2, 11, 8, 3, 13, 4, 12, 10, 13, 7, 14, 9, 13, 3, 10, 2, 14, 13, 4, 12, 13, 14, 10}, + {1, 11, 2, 12, 1, 10, 7, 12, 3, 3, 14, 9, 1, 10, 0, 11, 8, 10, 12, 12, 4, 12, 2, 11, 5, 0, 3, 15, 8, 2, 14, 3, 10, 2, 1, 13, 6, 14, 0, 0, 8, 11, 6, 13, 15, 10, 12, 7, 7, 11, 14, 9, 2, 7, 6, 8, 14, 9, 14, 10, 11, 9, 9, 12}, + {5, 10, 14, 2, 1, 4, 11, 5, 10, 2, 13, 9, 6, 12, 11, 5, 13, 4, 5, 14, 8, 7, 15, 9, 8, 4, 5, 2, 9, 11, 5, 3, 12, 2, 6, 1, 7, 4, 11, 4, 15, 0, 5, 2, 13, 11, 11, 2, 15, 10, 0, 12, 5, 8, 10, 1, 4, 11, 3, 13, 11, 7, 9, 14}, + {9, 8, 10, 5, 0, 2, 5, 8, 7, 3, 3, 6, 11, 1, 13, 15, 4, 4, 11, 6, 2, 6, 13, 11, 2, 6, 9, 4, 5, 13, 12, 2, 8, 7, 7, 12, 14, 15, 5, 12, 7, 0, 15, 15, 0, 5, 15, 0, 3, 9, 10, 15, 9, 11, 10, 10, 5, 3, 9, 3, 12, 13, 0, 13}, + {1, 11, 15, 0, 10, 5, 3, 5, 6, 7, 1, 11, 4, 11, 4, 2, 5, 12, 2, 5, 5, 6, 1, 5, 14, 9, 1, 5, 14, 12, 6, 10, 0, 8, 5, 11, 11, 11, 12, 10, 8, 10, 10, 1, 14, 1, 0, 8, 4, 7, 0, 11, 3, 1, 11, 12, 11, 8, 14, 15, 9, 3, 1, 14}, + {14, 11, 12, 12, 4, 6, 8, 14, 15, 1, 11, 2, 13, 3, 6, 2, 7, 1, 8, 1, 4, 9, 11, 15, 8, 1, 10, 13, 4, 13, 2, 7, 7, 10, 5, 2, 12, 12, 12, 3, 10, 8, 2, 11, 0, 3, 8, 9, 4, 2, 15, 7, 15, 6, 4, 6, 12, 7, 14, 9, 9, 8, 14, 12}, + {15, 4, 8, 12, 11, 11, 9, 5, 0, 0, 7, 6, 10, 5, 8, 2, 5, 6, 14, 11, 13, 0, 13, 15, 5, 4, 9, 15, 13, 12, 14, 15, 10, 2, 3, 6, 10, 14, 1, 8, 6, 7, 10, 1, 14, 9, 12, 13, 7, 2, 12, 10, 6, 11, 15, 1, 15, 11, 13, 0, 6, 13, 7, 15}, + {3, 3, 12, 5, 14, 9, 14, 14, 8, 0, 9, 1, 2, 2, 14, 11, 7, 1, 3, 1, 14, 15, 12, 8, 14, 2, 4, 13, 10, 5, 10, 8, 1, 7, 6, 5, 4, 2, 11, 5, 4, 13, 14, 6, 13, 15, 6, 6, 7, 12, 11, 5, 13, 10, 9, 13, 9, 14, 5, 6, 7, 14, 11, 7}, + {14, 12, 11, 5, 0, 5, 10, 5, 7, 1, 7, 11, 1, 0, 13, 6, 5, 14, 3, 0, 5, 14, 6, 7, 8, 5, 8, 6, 6, 3, 6, 1, 8, 3, 10, 7, 15, 6, 11, 6, 6, 7, 13, 2, 2, 0, 0, 11, 1, 15, 2, 14, 5, 1, 4, 8, 0, 1, 8, 0, 1, 1, 2, 2}, + {10, 13, 13, 3, 15, 14, 9, 12, 15, 15, 8, 5, 8, 10, 5, 9, 6, 6, 7, 15, 1, 0, 14, 9, 1, 11, 6, 11, 13, 4, 6, 14, 9, 12, 13, 8, 14, 6, 14, 2, 3, 15, 4, 4, 14, 4, 9, 12, 8, 0, 9, 11, 13, 10, 8, 14, 3, 5, 7, 11, 6, 7, 15, 2}, + {9, 9, 11, 6, 11, 0, 5, 4, 8, 10, 8, 11, 2, 12, 8, 7, 11, 13, 6, 1, 13, 13, 11, 4, 5, 7, 7, 9, 6, 4, 12, 0, 11, 8, 6, 12, 11, 4, 15, 11, 12, 8, 11, 11, 1, 3, 6, 14, 9, 6, 7, 5, 0, 10, 3, 15, 13, 7, 0, 1, 13, 15, 1, 14}, + {10, 6, 8, 7, 3, 6, 9, 15, 1, 3, 10, 14, 9, 0, 0, 10, 0, 15, 2, 0, 0, 0, 6, 0, 13, 9, 9, 1, 8, 6, 13, 2, 1, 9, 14, 9, 1, 4, 8, 4, 2, 0, 8, 5, 0, 11, 12, 15, 13, 1, 14, 14, 15, 7, 8, 4, 4, 12, 1, 12, 8, 3, 9, 5}, + {12, 11, 1, 4, 10, 14, 8, 12, 2, 4, 15, 2, 9, 7, 7, 11, 15, 12, 10, 11, 7, 4, 13, 0, 8, 6, 8, 8, 10, 5, 5, 13, 3, 7, 9, 13, 13, 14, 6, 8, 1, 5, 7, 12, 4, 4, 6, 9, 13, 1, 6, 1, 6, 14, 5, 8, 2, 10, 4, 10, 1, 9, 6, 15}, + {4, 13, 4, 9, 6, 11, 1, 8, 7, 11, 11, 1, 3, 10, 12, 11, 1, 10, 6, 10, 0, 7, 3, 0, 0, 6, 3, 9, 2, 1, 4, 8, 2, 10, 2, 15, 9, 15, 14, 14, 15, 14, 3, 2, 7, 6, 6, 10, 8, 8, 4, 11, 1, 13, 6, 0, 2, 10, 0, 11, 15, 14, 6, 9}, + {15, 0, 12, 13, 0, 9, 10, 4, 11, 5, 10, 0, 8, 7, 3, 2, 12, 6, 3, 8, 5, 15, 14, 2, 13, 13, 6, 11, 5, 6, 9, 10, 14, 5, 14, 4, 9, 7, 5, 11, 13, 2, 7, 1, 14, 9, 0, 7, 8, 12, 11, 15, 2, 1, 5, 11, 3, 7, 5, 1, 6, 3, 8, 6}, + {0, 3, 8, 1, 4, 6, 3, 1, 3, 8, 2, 0, 15, 15, 14, 15, 13, 10, 11, 9, 2, 11, 5, 12, 3, 3, 0, 1, 5, 3, 11, 6, 10, 11, 8, 5, 7, 15, 4, 12, 8, 8, 12, 12, 12, 1, 9, 4, 11, 6, 10, 11, 1, 12, 8, 12, 5, 6, 1, 14, 2, 10, 3, 0}, + {10, 13, 6, 9, 11, 1, 4, 10, 0, 13, 8, 7, 4, 12, 15, 5, 14, 12, 6, 9, 0, 0, 10, 5, 13, 10, 15, 3, 0, 8, 7, 0, 9, 8, 10, 6, 11, 8, 10, 13, 11, 7, 5, 5, 9, 13, 1, 15, 0, 5, 15, 5, 4, 7, 9, 9, 15, 8, 2, 6, 3, 8, 5, 8}, + {14, 0, 6, 2, 4, 12, 2, 13, 6, 10, 5, 2, 2, 1, 6, 11, 1, 6, 9, 13, 0, 13, 9, 3, 12, 4, 3, 8, 7, 0, 9, 12, 0, 1, 7, 10, 10, 7, 3, 9, 13, 5, 15, 4, 13, 0, 8, 5, 4, 14, 11, 3, 3, 13, 15, 9, 9, 12, 9, 5, 2, 0, 1, 14}, + {4, 14, 13, 0, 14, 15, 11, 10, 11, 1, 3, 3, 9, 1, 12, 8, 6, 5, 15, 11, 1, 7, 5, 3, 8, 13, 0, 13, 11, 5, 8, 1, 8, 6, 13, 4, 13, 7, 12, 6, 5, 5, 7, 0, 12, 1, 1, 8, 1, 6, 4, 2, 8, 8, 15, 11, 11, 11, 4, 4, 4, 7, 13, 12}, + {14, 15, 10, 0, 4, 3, 1, 9, 13, 7, 9, 9, 15, 5, 0, 3, 9, 6, 4, 7, 13, 11, 3, 2, 7, 1, 6, 8, 13, 7, 10, 4, 3, 9, 5, 9, 2, 6, 10, 7, 9, 13, 2, 14, 2, 14, 7, 2, 14, 2, 8, 8, 0, 9, 0, 9, 12, 6, 7, 7, 6, 8, 12, 13}, + {5, 15, 8, 12, 11, 3, 13, 4, 5, 14, 10, 4, 15, 15, 1, 10, 9, 14, 6, 6, 4, 12, 4, 9, 12, 2, 15, 13, 2, 5, 12, 2, 3, 2, 15, 11, 12, 2, 6, 2, 11, 6, 7, 9, 12, 10, 5, 1, 1, 5, 9, 6, 14, 11, 3, 11, 6, 10, 11, 11, 0, 12, 15, 1}, + {12, 6, 8, 10, 2, 5, 7, 9, 8, 14, 15, 15, 13, 10, 15, 3, 10, 10, 6, 10, 14, 10, 7, 5, 3, 7, 6, 12, 11, 12, 8, 9, 12, 9, 15, 15, 15, 7, 8, 3, 15, 14, 1, 12, 0, 0, 4, 0, 9, 10, 8, 7, 14, 10, 8, 14, 6, 2, 8, 1, 11, 10, 0, 1}, + {12, 1, 2, 12, 7, 10, 4, 11, 5, 14, 10, 2, 2, 9, 4, 13, 3, 14, 3, 15, 5, 0, 14, 7, 7, 15, 6, 5, 2, 8, 15, 9, 6, 6, 13, 10, 9, 8, 6, 3, 14, 7, 12, 9, 7, 8, 13, 12, 14, 13, 6, 0, 5, 1, 9, 12, 14, 0, 11, 11, 6, 3, 11, 7}, + {15, 4, 8, 12, 8, 11, 4, 15, 1, 6, 2, 13, 1, 7, 7, 12, 0, 8, 14, 14, 10, 14, 0, 12, 0, 3, 3, 11, 7, 4, 2, 13, 0, 0, 11, 2, 5, 8, 12, 11, 6, 5, 6, 0, 0, 4, 0, 0, 1, 9, 9, 11, 3, 2, 13, 4, 13, 9, 15, 4, 7, 8, 3, 2}, + {3, 13, 8, 8, 12, 10, 5, 4, 7, 13, 10, 13, 14, 3, 2, 12, 11, 0, 9, 5, 6, 4, 14, 4, 6, 9, 2, 5, 10, 3, 9, 10, 5, 0, 12, 5, 15, 5, 15, 15, 2, 12, 3, 11, 0, 15, 9, 14, 1, 5, 6, 6, 14, 5, 8, 0, 5, 9, 3, 7, 7, 12, 15, 1}, + {1, 11, 7, 4, 13, 3, 0, 8, 11, 9, 15, 1, 4, 12, 2, 12, 10, 4, 14, 3, 9, 14, 14, 2, 3, 11, 12, 4, 5, 10, 6, 15, 2, 13, 13, 9, 9, 1, 11, 12, 12, 14, 1, 5, 15, 1, 7, 14, 12, 10, 11, 13, 13, 5, 2, 4, 7, 7, 9, 4, 14, 15, 13, 10}, + {14, 15, 9, 14, 9, 5, 13, 2, 0, 0, 14, 8, 6, 2, 0, 7, 11, 10, 2, 13, 2, 14, 9, 6, 4, 11, 5, 14, 6, 1, 6, 14, 6, 3, 9, 5, 2, 9, 3, 11, 1, 14, 5, 4, 12, 5, 3, 5, 11, 3, 11, 6, 13, 7, 13, 7, 4, 9, 4, 13, 8, 3, 5, 11}, + {13, 12, 12, 13, 8, 2, 4, 2, 10, 6, 3, 5, 7, 7, 6, 13, 8, 6, 15, 4, 12, 7, 15, 4, 3, 9, 8, 15, 0, 3, 12, 1, 9, 8, 13, 10, 15, 4, 14, 1, 6, 15, 0, 4, 8, 9, 3, 1, 3, 15, 5, 5, 1, 11, 11, 10, 11, 10, 8, 8, 5, 4, 13, 0}, + {8, 4, 15, 9, 14, 9, 5, 8, 8, 10, 5, 15, 9, 8, 12, 5, 11, 10, 2, 12, 13, 1, 0, 2, 6, 13, 11, 9, 12, 0, 5, 0, 11, 5, 14, 12, 3, 4, 2, 10, 3, 12, 5, 15, 4, 8, 14, 1, 0, 13, 9, 5, 2, 4, 13, 8, 2, 5, 8, 9, 15, 3, 5, 5}, + {0, 3, 3, 4, 6, 5, 5, 1, 3, 2, 14, 5, 10, 7, 15, 11, 7, 13, 15, 4, 0, 12, 9, 15, 12, 0, 3, 1, 14, 1, 12, 9, 13, 8, 9, 15, 12, 3, 5, 11, 3, 11, 4, 1, 9, 4, 13, 7, 4, 10, 6, 14, 13, 0, 9, 11, 15, 15, 3, 3, 13, 15, 10, 15}, +} diff --git a/domain/consensus/utils/pow/pow.go b/domain/consensus/utils/pow/pow.go index ca59c1aff..a65e79e44 100644 --- a/domain/consensus/utils/pow/pow.go +++ b/domain/consensus/utils/pow/pow.go @@ -36,6 +36,7 @@ func CalculateProofOfWorkValue(header externalapi.MutableBlockHeader) *big.Int { header.SetNonce(0) prePowHash := consensushashing.HeaderHash(header) + matrix := generateMatrix(prePowHash) header.SetTimeInMilliseconds(timestamp) header.SetNonce(nonce) @@ -52,7 +53,9 @@ func CalculateProofOfWorkValue(header externalapi.MutableBlockHeader) *big.Int { if err != nil { panic(errors.Wrap(err, "this should never happen. Hash digest should never return an error")) } - return toBig(writer.Finalize()) + powHash := writer.Finalize() + heavyHash := matrix.HeavyHash(powHash) + return toBig(heavyHash) } // ToBig converts a externalapi.DomainHash into a big.Int treated as a little endian string. diff --git a/domain/consensus/utils/pow/xoshiro.go b/domain/consensus/utils/pow/xoshiro.go new file mode 100644 index 000000000..7775d58a7 --- /dev/null +++ b/domain/consensus/utils/pow/xoshiro.go @@ -0,0 +1,37 @@ +package pow + +import ( + "encoding/binary" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" + "math/bits" +) + +type xoShiRo256PlusPlus struct { + s0 uint64 + s1 uint64 + s2 uint64 + s3 uint64 +} + +func newxoShiRo256PlusPlus(hash *externalapi.DomainHash) *xoShiRo256PlusPlus { + hashArray := hash.ByteArray() + return &xoShiRo256PlusPlus{ + s0: binary.LittleEndian.Uint64(hashArray[:8]), + s1: binary.LittleEndian.Uint64(hashArray[8:16]), + s2: binary.LittleEndian.Uint64(hashArray[16:24]), + s3: binary.LittleEndian.Uint64(hashArray[24:32]), + } +} + +func (x *xoShiRo256PlusPlus) Uint64() uint64 { + res := bits.RotateLeft64(x.s0+x.s3, 23) + x.s0 + t := x.s1 << 17 + x.s2 ^= x.s0 + x.s3 ^= x.s1 + x.s1 ^= x.s2 + x.s0 ^= x.s3 + + x.s2 ^= t + x.s3 = bits.RotateLeft64(x.s3, 45) + return res +} diff --git a/domain/consensus/utils/pow/xoshiro_test.go b/domain/consensus/utils/pow/xoshiro_test.go new file mode 100644 index 000000000..6f9815984 --- /dev/null +++ b/domain/consensus/utils/pow/xoshiro_test.go @@ -0,0 +1,17 @@ +package pow + +import "testing" + +// Test vectors are from here: https://github.com/rust-random/rngs/blob/17aa826cc38d3e8408c9489ac859fa9397acd479/rand_xoshiro/src/xoshiro256plusplus.rs#L121 +func TestXoShiRo256PlusPlus_Uint64(t *testing.T) { + state := xoShiRo256PlusPlus{1, 2, 3, 4} + expected := []uint64{41943041, 58720359, 3588806011781223, 3591011842654386, + 9228616714210784205, 9973669472204895162, 14011001112246962877, + 12406186145184390807, 15849039046786891736, 10450023813501588000} + for _, ex := range expected { + val := state.Uint64() + if val != ex { + t.Errorf("expected: %d, found: %d", ex, val) + } + } +} diff --git a/domain/dagconfig/genesis.go b/domain/dagconfig/genesis.go index 819c49293..c4a31097b 100644 --- a/domain/dagconfig/genesis.go +++ b/domain/dagconfig/genesis.go @@ -31,10 +31,10 @@ var genesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0, []*externa // genesisHash is the hash of the first block in the block DAG for the main // network (genesis block). var genesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{ - 0x75, 0xd8, 0x51, 0xcc, 0x91, 0xba, 0x55, 0x32, - 0xfd, 0xf9, 0x3e, 0xf2, 0xa5, 0x28, 0x92, 0x83, - 0x35, 0xe0, 0x61, 0xa2, 0xe4, 0x77, 0x76, 0x5e, - 0xd7, 0x10, 0x5d, 0x8e, 0x78, 0xc7, 0xb8, 0x0d, + 0x16, 0x57, 0xf4, 0x2c, 0x8e, 0x19, 0x81, 0xe7, + 0x7a, 0x02, 0x66, 0x42, 0x7c, 0xb4, 0x15, 0x59, + 0x88, 0x17, 0x50, 0xb9, 0x5b, 0xf9, 0x9d, 0xe1, + 0xfe, 0x89, 0x08, 0x44, 0xba, 0x0d, 0x00, 0xc4, }) // genesisMerkleRoot is the hash of the first transaction in the genesis block @@ -55,9 +55,9 @@ var genesisBlock = externalapi.DomainBlock{ genesisMerkleRoot, &externalapi.DomainHash{}, externalapi.NewDomainHashFromByteArray(muhash.EmptyMuHashHash.AsArray()), - 0x17c2df949fe, - 0x207fffff, - 0x0, + 0x17c5f0c90e6, + 0x1e7fffff, + 0x165c5, 0, 0, big.NewInt(0), @@ -86,10 +86,10 @@ var devnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0, // devGenesisHash is the hash of the first block in the block DAG for the development // network (genesis block). var devnetGenesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{ - 0xf1, 0xa4, 0x65, 0xfe, 0xd2, 0x08, 0x54, 0xc1, - 0x72, 0x60, 0xdc, 0x8b, 0x29, 0x67, 0x90, 0x1f, - 0xa9, 0x48, 0x47, 0x4e, 0x63, 0xa1, 0xfc, 0x09, - 0x6d, 0x10, 0x7b, 0x08, 0x23, 0x37, 0xfd, 0x59, + 0x3f, 0x4e, 0x3d, 0x83, 0x06, 0x9a, 0x19, 0x2b, + 0xe4, 0x32, 0xe9, 0x2b, 0x81, 0x6b, 0x27, 0xce, + 0xb0, 0x29, 0xea, 0x0a, 0x15, 0xb3, 0xba, 0x3f, + 0x73, 0x35, 0xfe, 0x9a, 0x78, 0x74, 0x60, 0x3c, }) // devnetGenesisMerkleRoot is the hash of the first transaction in the genesis block @@ -112,7 +112,7 @@ var devnetGenesisBlock = externalapi.DomainBlock{ externalapi.NewDomainHashFromByteArray(muhash.EmptyMuHashHash.AsArray()), 0x11e9db49828, 0x1e7fffff, - 0x268db, + 0x38244, 0, 0, big.NewInt(0), @@ -194,10 +194,10 @@ var testnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0, // testnetGenesisHash is the hash of the first block in the block DAG for the test // network (genesis block). var testnetGenesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{ - 0x47, 0x4f, 0xfd, 0xd1, 0xf8, 0x3d, 0x1d, 0x00, - 0xcb, 0x07, 0x17, 0x91, 0x56, 0x60, 0xd4, 0xa7, - 0x27, 0x5e, 0x43, 0xc2, 0x74, 0xe6, 0x76, 0x6e, - 0x34, 0xe4, 0x13, 0xbb, 0x24, 0x02, 0x30, 0x66, + 0xe0, 0xf5, 0xec, 0xd0, 0x3a, 0x46, 0xc5, 0xc9, + 0x55, 0xd7, 0xba, 0x3d, 0x56, 0xb8, 0x85, 0xe2, + 0xdb, 0x37, 0xe4, 0xd9, 0x0e, 0xf3, 0xab, 0xae, + 0x04, 0xac, 0x35, 0x6b, 0x7a, 0x30, 0x89, 0xa8, }) // testnetGenesisMerkleRoot is the hash of the first transaction in the genesis block @@ -218,9 +218,9 @@ var testnetGenesisBlock = externalapi.DomainBlock{ testnetGenesisMerkleRoot, &externalapi.DomainHash{}, externalapi.NewDomainHashFromByteArray(muhash.EmptyMuHashHash.AsArray()), - 0x17c2df94abb, + 0x17c5f0d12b2, 0x1e7fffff, - 0x35f16, + 0x52c45, 0, 0, big.NewInt(0), diff --git a/util/difficulty/difficulty_test.go b/util/difficulty/difficulty_test.go index 157e2820b..6843440dc 100644 --- a/util/difficulty/difficulty_test.go +++ b/util/difficulty/difficulty_test.go @@ -14,7 +14,7 @@ import ( func TestGetHashrateString(t *testing.T) { var results = map[string]string{ - dagconfig.MainnetParams.Name: "2 H/s", + dagconfig.MainnetParams.Name: "131.07 KH/s", dagconfig.TestnetParams.Name: "131.07 KH/s", dagconfig.DevnetParams.Name: "131.07 KH/s", dagconfig.SimnetParams.Name: "2.00 KH/s",