-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
122 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
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,34 +1,16 @@ | ||
use dep::std::hash::{pedersen_hash_with_separator, sha256}; | ||
use dep::protocol_types::constants::{ | ||
GENERATOR_INDEX__SIGNATURE_PAYLOAD, | ||
GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET, | ||
}; | ||
|
||
pub fn sha256_to_field<N>(bytes_to_hash: [u8; N]) -> Field { | ||
let sha256_hashed = sha256(bytes_to_hash); | ||
|
||
// Convert it to a field element | ||
let mut v = 1; | ||
let mut high = 0 as Field; | ||
let mut low = 0 as Field; | ||
|
||
for i in 0..16 { | ||
high = high + (sha256_hashed[15 - i] as Field) * v; | ||
low = low + (sha256_hashed[16 + 15 - i] as Field) * v; | ||
v = v * 256; | ||
use dep::protocol_types::{ | ||
constants::{ | ||
GENERATOR_INDEX__SIGNATURE_PAYLOAD, | ||
GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET, | ||
}, | ||
hash::{ | ||
sha256_to_field, | ||
pedersen_hash, | ||
} | ||
|
||
// Abuse that a % p + b % p = (a + b) % p and that low < p | ||
let hash_in_a_field = low + high * v; | ||
|
||
hash_in_a_field | ||
} | ||
}; | ||
|
||
pub fn compute_secret_hash(secret: Field) -> Field { | ||
// TODO(#1205) This is probably not the right index to use | ||
pedersen_hash([secret], GENERATOR_INDEX__L1_TO_L2_MESSAGE_SECRET) | ||
} | ||
|
||
pub fn pedersen_hash<N>(inputs: [Field; N], hash_index: u32) -> Field { | ||
pedersen_hash_with_separator(inputs, hash_index) | ||
} |
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