Skip to content
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

Blow up in constraints on sha256_var (NOT solved by 0.34.0) (EASY WORKAROUND) #6144

Open
jp4g opened this issue Sep 24, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@jp4g
Copy link

jp4g commented Sep 24, 2024

Aim

I want to conditionally assign the preimage of a sha256_var hash

Expected Behavior

Constraints do not blow up

Bug

Constraints blow up the same way they did when trying to assign variable length (not constant in var param) sha256_var input in 0.33.0

To Reproduce

// I want to pack items into a sha256 hash
// Assuming 0-padded past `item_x_length`
let item_1: [u8; 64] = ...;
let item_1_length: u32 = 17;
let item_2: [u8; 128] = ...;
let item_2_length: u32 = 100;

// I try directly assigning indexes
let mut preimage = [0; 192];
let mut index = 0;
for i in 0..64 {
    if i < item_1_length {
         preimage[index] = item_1[i];
         index += 1;
    }
}
for i in 0..128 {
    if i < item_2_length {
         preimage[index] = item_2[i];
         index += 1;
    }
}
// blows up constraints
let hash = std::hash::sha256_var(preimage, item_1_length + item_2_length);

Workaround

Yes

Workaround Description

// I want to pack items into a sha256 hash
// Assuming 0-padded past `item_x_length`
let item_1: [u8; 64] = ...;
let item_1_length: u32 = 17;
let item_2: [u8; 128] = ...;
let item_2_length: u32 = 100;

// I try directly assigning indexes
let mut preimage = [0; 192];

for i in 0..64 {
    preimage[i] = item_1[i];
}
for i in 0..128 {
    preimage[i + 64] = item_2[i]
}
// expected constraints
let hash = std::hash::sha256_var(preimage, item_1_length + item_2_length);

Additional Context

I know that the working way is actually more efficient anyways but it is forseeable that someone would try to do this pattern. Maybe they figure out they can just assign the way in the workaround, but it is probably in best interest to not totally break unoptimized code patterns

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

No response

NoirJS Version

0.34.0

Proving Backend Tooling & Version

0.55.0

Would you like to submit a PR for this Issue?

None

Support Needs

none

@jp4g jp4g added the bug Something isn't working label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant