forked from kaspanet/kaspad
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fishhash plus implementation with hard fork procedure #47
Merged
lemois-1337
merged 1 commit into
karlsen-network:2024_testnet_1_fishhashplus
from
okilisan:2024_testnet_1_fishhashplus
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pow | ||
|
||
import ( | ||
"github.com/karlsen-network/karlsend/domain/consensus/model/externalapi" | ||
|
||
//"crypto/sha3" | ||
"encoding/binary" | ||
) | ||
|
||
func fishhashPlusKernel(ctx *fishhashContext, seed hash512) hash256 { | ||
indexLimit := uint32(ctx.FullDatasetNumItems) | ||
mix := mergeHashes(seed, seed) | ||
|
||
//log.Debugf("lookup matrix : ") | ||
for i := uint32(0); i < numDatasetAccesses; i++ { | ||
|
||
mixGroup := [8]uint32{} | ||
for c := uint32(0); c < 8; c++ { | ||
mixGroup[c] = binary.LittleEndian.Uint32(mix[(4*4*c+0):]) ^ binary.LittleEndian.Uint32(mix[(4*4*c+4):]) ^ binary.LittleEndian.Uint32(mix[(4*4*c+8):]) ^ binary.LittleEndian.Uint32(mix[(4*4*c+12):]) | ||
} | ||
|
||
p0 := (mixGroup[0] ^ mixGroup[3] ^ mixGroup[6]) % indexLimit | ||
p1 := (mixGroup[1] ^ mixGroup[4] ^ mixGroup[7]) % indexLimit | ||
p2 := (mixGroup[2] ^ mixGroup[5] ^ i) % indexLimit | ||
|
||
fetch0 := lookup(ctx, p0) | ||
fetch1 := lookup(ctx, p1) | ||
fetch2 := lookup(ctx, p2) | ||
|
||
for j := 0; j < 32; j++ { | ||
binary.LittleEndian.PutUint32( | ||
fetch1[4*j:], | ||
fnv1(binary.LittleEndian.Uint32(mix[4*j:4*j+4]), binary.LittleEndian.Uint32(fetch1[4*j:4*j+4]))) | ||
binary.LittleEndian.PutUint32( | ||
fetch2[4*j:], | ||
binary.LittleEndian.Uint32(mix[4*j:4*j+4])^binary.LittleEndian.Uint32(fetch2[4*j:4*j+4])) | ||
} | ||
|
||
//fmt.Printf("The NEW fetch1 is : %x \n", fetch1) | ||
//fmt.Printf("The NEW fetch2 is : %x \n", fetch2) | ||
|
||
for j := 0; j < 16; j++ { | ||
binary.LittleEndian.PutUint64( | ||
mix[8*j:], | ||
binary.LittleEndian.Uint64(fetch0[8*j:8*j+8])*binary.LittleEndian.Uint64(fetch1[8*j:8*j+8])+binary.LittleEndian.Uint64(fetch2[8*j:8*j+8])) | ||
} | ||
//log.Debugf("\n") | ||
} | ||
|
||
mixHash := hash256{} | ||
for i := 0; i < (len(mix) / 4); i += 4 { | ||
j := 4 * i | ||
h1 := fnv1(binary.LittleEndian.Uint32(mix[j:]), binary.LittleEndian.Uint32(mix[j+4:])) | ||
h2 := fnv1(h1, binary.LittleEndian.Uint32(mix[j+8:])) | ||
h3 := fnv1(h2, binary.LittleEndian.Uint32(mix[j+12:])) | ||
binary.LittleEndian.PutUint32(mixHash[i:], h3) | ||
} | ||
|
||
return mixHash | ||
} | ||
|
||
func fishHashPlus(ctx *fishhashContext, hashin *externalapi.DomainHash) *externalapi.DomainHash { | ||
|
||
seed := hash512{} | ||
copy(seed[:], hashin.ByteSlice()) | ||
|
||
output := fishhashPlusKernel(ctx, seed) | ||
outputArray := [32]byte{} | ||
copy(outputArray[:], output[:]) | ||
return externalapi.NewDomainHashFromByteArray(&outputArray) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this is commented? Explicit error in case an old node would send a wrong version block after hardfork is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been replaced by a conditional check on BlockVersionAfterHF BlockVersionBeforeHF to reject block with bad version after or before HF