Skip to content

Commit bedc809

Browse files
tx: use original Keccak256 hash function
1 parent fe2d176 commit bedc809

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.keystore*/
22
.blockstore*/
33
bcn
4+
coverage.cov

chain/tx.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ type Hash [32]byte
1414

1515
func NewHash(val any) Hash {
1616
jval, _ := json.Marshal(val)
17-
hash := make([]byte, 64)
18-
sha3.ShakeSum256(hash, jval)
19-
return Hash(hash[:32])
17+
state := sha3.NewLegacyKeccak256()
18+
_, _ = state.Write(jval)
19+
hash := state.Sum(nil)
20+
return Hash(hash)
2021
}
2122

2223
func (h Hash) String() string {

doc/transaction.org

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ type Hash [32]byte
127127

128128
func NewHash(val any) Hash {
129129
jval, _ := json.Marshal(val)
130-
hash := make([]byte, 64)
131-
sha3.ShakeSum256(hash, jval)
132-
return Hash(hash[:32])
130+
state := sha3.NewLegacyKeccak256()
131+
_, _ = state.Write(jval)
132+
hash := state.Sum(nil)
133+
return Hash(hash)
133134
}
134135

135136
func (h Hash) String() string {

0 commit comments

Comments
 (0)