-
Notifications
You must be signed in to change notification settings - Fork 463
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
fixed a bug where strings with will get the wrong sha256 value #6030
Conversation
ca810ad
to
74ee05f
Compare
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.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
corelib/src/test/sha256_test.cairo
line 15 at r1 (raw file):
assert_eq!(a, 0x9834876d); let [a, _, _, _, _, _, _, _,] = compute_sha256_byte_array(@"aaaa"); assert_eq!(a, 0x61be55a8);
extend these tests as well.
Code quote:
let [a, _, _, _, _, _, _, _,] = compute_sha256_byte_array(@"a");
assert_eq!(a, 0xca978112);
let [a, _, _, _, _, _, _, _,] = compute_sha256_byte_array(@"aa");
assert_eq!(a, 0x961b6dd3);
let [a, _, _, _, _, _, _, _,] = compute_sha256_byte_array(@"aaa");
assert_eq!(a, 0x9834876d);
let [a, _, _, _, _, _, _, _,] = compute_sha256_byte_array(@"aaaa");
assert_eq!(a, 0x61be55a8);
corelib/src/test/sha256_test.cairo
line 408 at r1 (raw file):
3889463563, 3109547134, 3732685805
make all tests with hex numeric values.
Code quote:
3545823548,
3587795446,
676063049,
3347034665,
1546494401,
3889463563,
3109547134,
3732685805
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.
Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @TomerStarkware)
corelib/src/test/sha256_test.cairo
line 410 at r1 (raw file):
3732685805 ] );
also - consider adding a test helper function converting a u32 array to u256 to vastly shorten the tests.
fn to_u256(arr: [u32; 8]) -> u256 {
let mut value: u256 = 0;
for word in arr.span() {
value *= 0x100000000;
value += word.into();
}
value
}
69b7ac7
to
a549f01
Compare
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.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @orizi)
corelib/src/test/sha256_test.cairo
line 15 at r1 (raw file):
Previously, orizi wrote…
extend these tests as well.
Done.
corelib/src/test/sha256_test.cairo
line 408 at r1 (raw file):
Previously, orizi wrote…
make all tests with hex numeric values.
Done.
corelib/src/test/sha256_test.cairo
line 410 at r1 (raw file):
Previously, orizi wrote…
also - consider adding a test helper function converting a u32 array to u256 to vastly shorten the tests.
fn to_u256(arr: [u32; 8]) -> u256 { let mut value: u256 = 0; for word in arr.span() { value *= 0x100000000; value += word.into(); } value }
Done.
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.
Reviewed 1 of 2 files at r1, all commit messages.
Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @TomerStarkware)
corelib/src/test/sha256_test.cairo
line 12 at r3 (raw file):
value } #[test]
put after the test, have emptyline between the functions and doc.
also - consider just making it also call the sha itself:
Suggestion:
use core::starknet::SyscallResultTrait;
use core::sha256::compute_sha256_byte_array;
fn sha256_as_u256(input: ByteArray) -> u256 {
let hash_result = compute_sha256_byte_array(@input);
let mut value: u256 = 0;
for word in hash_result.span() {
value *= 0x100000000;
value = value + (*word).into();
};
value
}
#[test]
a549f01
to
4279c75
Compare
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.
Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @orizi)
corelib/src/test/sha256_test.cairo
line 12 at r3 (raw file):
Previously, orizi wrote…
put after the test, have emptyline between the functions and doc.
also - consider just making it also call the sha itself:
Done.
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.
Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @TomerStarkware)
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @TomerStarkware)
This change is![Reviewable](https://github.com/camo/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)