-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into kirugan/blockifier-0.…
…13.2
- Loading branch information
Showing
4 changed files
with
10 additions
and
16 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
package crypto | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/NethermindEth/juno/core/felt" | ||
"golang.org/x/crypto/sha3" | ||
) | ||
|
||
// StarknetKeccak implements [Starknet keccak] | ||
// | ||
// [Starknet keccak]: https://docs.starknet.io/architecture-and-concepts/cryptography/hash-functions/#starknet_keccak | ||
func StarknetKeccak(b []byte) (*felt.Felt, error) { | ||
func StarknetKeccak(b []byte) *felt.Felt { | ||
h := sha3.NewLegacyKeccak256() | ||
_, err := h.Write(b) | ||
if err != nil { | ||
return nil, err | ||
// actual implementation (sha3.state{} type) doesn't return error in Write method | ||
// we keep this panic as an assertion in case they will modify the implementation | ||
panic(fmt.Errorf("failed to write to LegacyKeccak256 hash: %w", err)) | ||
} | ||
d := h.Sum(nil) | ||
// Remove the first 6 bits from the first byte | ||
d[0] &= 3 | ||
return new(felt.Felt).SetBytes(d), nil | ||
return new(felt.Felt).SetBytes(d) | ||
} |
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