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

bug: One of the arguments does not satisfy the requirements of the libfunc. #4744

Closed
bajpai244 opened this issue Jan 5, 2024 · 6 comments · Fixed by #4777
Closed

bug: One of the arguments does not satisfy the requirements of the libfunc. #4744

bajpai244 opened this issue Jan 5, 2024 · 6 comments · Fixed by #4777
Labels
bug Something isn't working

Comments

@bajpai244
Copy link

Bug Report

Cairo version: 2.3.0-rc0

Current behavior:

fn g(ref v: Felt252Vec<u64>, a: usize, b: usize, c: usize, d: usize, x: u64, y: u64) {
    let mut v_a = v[a];
    let mut v_b = v[b];
    let mut v_c = v[c];
    let mut v_d = v[d];

    v_a = u64_wrapping_add(u64_wrapping_add(v_a, v_b), x);
    v_a = u64_wrapping_add(u64_wrapping_add(v_a, v_b), y);
} 

The above code fails with the following error:

testing bugreport ...
Error: Failed setting up runner.

Caused by:
    #42: One of the arguments does not satisfy the requirements of the libfunc.
error: process did not exit successfully: exit status: 1

Expected behavior:

The above code should compile and work.

Other information:

I have seen a similar issue which has been closed at #3863, not sure if my bug is arriving because of the same reason.

@bajpai244 bajpai244 added the bug Something isn't working label Jan 5, 2024
@enitrat
Copy link
Contributor

enitrat commented Jan 5, 2024

I suggested a temporary workaround as you suggested to me last time @orizi, which is

#[inline(never)]
fn no_op() {}


fn g(ref v: Felt252Vec<u64>, a: usize, b: usize, c: usize, d: usize, x: u64, y: u64) {
    let mut v_a = v[a];
    let mut v_b = v[b];
    let mut v_c = v[c];
    let mut v_d = v[d];

    let tmp = u64_wrapping_add(v_a, v_b);
    no_op();
    v_a = u64_wrapping_add(tmp, x);
    no_op();
    v_d = rotate_right(v_d ^ v_a, 32);
    v_c = u64_wrapping_add(v_c, v_d);
    no_op();
    v_b = rotate_right(v_b ^ v_c, 24);

which allowed us to compile

@orizi
Copy link
Collaborator

orizi commented Jan 9, 2024

please check with 2.4.0 - cant try reproduce by myself as i got no self contained code for reproduction.

@enitrat
Copy link
Contributor

enitrat commented Jan 9, 2024

@bajpai244 this was 2.4 right? not 2.3.0-rc0

@orizi
Copy link
Collaborator

orizi commented Jan 9, 2024

managed to run in main and on 2.4.0 and it seemed to fully work.
feel free to reopen if doesn't actually work.

@orizi orizi closed this as completed Jan 9, 2024
@enitrat
Copy link
Contributor

enitrat commented Jan 9, 2024

Just re-checked, we're running a recent nightly build and the error still occurs.

❯ scarb test -p evm
     Running cairo-test evm
   Compiling test(evm_unittest) evm v0.1.0 (/Users/msaug/kkrt-labs/kakarot-ssj/crates/evm/Scarb.toml)
    Finished release target(s) in 10 seconds
testing evm ...
Error: Failed setting up runner.

Caused by:
    #725711: One of the arguments does not satisfy the requirements of the libfunc.

❯ scarb --version
scarb 2.4.0+nightly-2023-12-23 (9447d26cc 2023-12-23)
cairo: 2.4.0 (362c5f748)
sierra: 1.4.0
❯ scarb --version
scarb 2.4.0+nightly-2023-12-23 (9447d26cc 2023-12-23)
cairo: 2.4.0 (362c5f748)
sierra: 1.4.0

Full code: https://github.com/kkrt-labs/kakarot-ssj/blob/8bc2e966880e129c393f97723108f515cd88acf8/crates/utils/src/crypto/blake2_compress.cairo#L147-L175

removing the no_op and running this doesn't work

fn g(ref v: Felt252Vec<u64>, a: usize, b: usize, c: usize, d: usize, x: u64, y: u64) {
    let mut v_a = v[a];
    let mut v_b = v[b];
    let mut v_c = v[c];
    let mut v_d = v[d];

    let tmp = u64_wrapping_add(v_a, v_b);
    v_a = u64_wrapping_add(tmp, x);
    v_d = rotate_right(v_d ^ v_a, 32);
    v_c = u64_wrapping_add(v_c, v_d);
    v_b = rotate_right(v_b ^ v_c, 24);

    let tmp = u64_wrapping_add(v_a, v_b);
    v_a = u64_wrapping_add(tmp, y);
    v_d = rotate_right(v_d ^ v_a, 16);
    v_c = u64_wrapping_add(v_c, v_d);
    v_b = rotate_right(v_b ^ v_c, 63);

    v.set(a, v_a);
    v.set(b, v_b);
    v.set(c, v_c);
    v.set(d, v_d);
}

@orizi
Copy link
Collaborator

orizi commented Jan 9, 2024

managed to more or less minimally recreate now - thanks!

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
None yet
Development

Successfully merging a pull request may close this issue.

3 participants