Skip to content

Fix test_uint32_shr failing on debug builds.#98

Open
defuse wants to merge 1 commit intozcash:mainfrom
defuse:fix-uint32-test
Open

Fix test_uint32_shr failing on debug builds.#98
defuse wants to merge 1 commit intozcash:mainfrom
defuse:fix-uint32-test

Conversation

@defuse
Copy link
Copy Markdown
Collaborator

@defuse defuse commented Feb 19, 2019

This makes shr behave differently than Rust's >> in release mode but IMO how >> works in release mode is kinda dumb -- I could see myself assuming the argument to shr or the right argument to >> saturates instead of taking the value mod 32, and introducing security bugs that way -- so this seems safer.

@defuse defuse mentioned this pull request Feb 19, 2019
Comment thread src/circuit/uint32.rs
for _ in 0..50 {
for i in 32..60 {
let num = rng.gen();
let result = std::panic::catch_unwind(|| UInt32::constant(num).shr(i));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better approach is using #[should_panic] on the test itself.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't do that because I wanted the test to make sure it panics on a bunch of different values, whereas #[should_panic] would only ensure one of the values cause a panic.

stefandeml pushed a commit to stefandeml/sapling-crypto that referenced this pull request Jul 5, 2019
Copy link
Copy Markdown
Collaborator Author

@defuse defuse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! I thought I replied to the comment but it never got posted because my reply was part of this review which I never submitted!

Comment thread src/circuit/uint32.rs
for _ in 0..50 {
for i in 32..60 {
let num = rng.gen();
let result = std::panic::catch_unwind(|| UInt32::constant(num).shr(i));
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't do that because I wanted the test to make sure it panics on a bunch of different values, whereas #[should_panic] would only ensure one of the values cause a panic.

Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK with nonblocking comment.

Comment thread src/circuit/uint32.rs
fn test_uint32_shr_overflow() {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

for _ in 0..50 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really needed to do this 50 times? The behaviour is easily seen from the source to not be value-dependent.

@str4d
Copy link
Copy Markdown
Contributor

str4d commented Nov 14, 2019

This PR would need to be migrated over to the main rust crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants