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

Assert in logic gate fails for larger input #678

Closed
moCello opened this issue Apr 25, 2022 · 0 comments
Closed

Assert in logic gate fails for larger input #678

moCello opened this issue Apr 25, 2022 · 0 comments
Labels
fix:bug Something isn't working

Comments

@moCello
Copy link
Member

moCello commented Apr 25, 2022

Describe the bug
An internal assert in the logic gates XOR and AND is failing for larger input (i.e. a BlsScarar crated from 4 large u64). The output seems to be correct.

To Reproduce
In constraint_system::logic::tests::test_logic_xor_and_constraint we only test rather small BlsScalars. Adding a test for larger values causes a panic in 'src/constraint_system/logic.rs:286:9' in the function 'logic_gate'

#[test]
fn logic_xor() {
    let res = gadget_tester(
        |composer| {
            let a = BlsScalar::from_raw([
                0xffefffff00000001,
                0x53bda402fffe5bfe,
                0x3319d80809a1d805,
                0x73eda758299d7d48,
            ]);
            let b = BlsScalar::from_raw([
                0xffeffa89f2eebc13,
                0x19420effaad6cb43,
                0x0000138739efccab,
                0x2979bc292cccde11,
            ]);
            let witness_a = composer.append_witness(a);
            let witness_b = composer.append_witness(b);
            let bits = 32 * 8;
            let xor_res =
                composer.component_xor(witness_a, witness_b, bits);
            // Check that the XOR result is indeed what we are expecting.
            composer.assert_equal_constant(xor_res, a ^ b, None);
        },
        500,
    );
    assert!(res.is_ok());
}

Expected behaviour
The function 'logic_gate' shouldn't panic with arbitrary input

Logs/Screenshot
This is the error message:

---- constraint_system::logic::tests::logic_xor stdout ----
thread 'constraint_system::logic::tests::logic_xor' panicked at 'assertion failed: `(left == right)`
  left: `000000000000000002480300fab78458f54fbcecef4f8c996f05c5ac00000000`,
 right: `000000000000f0ffffffffffffffffffffffffffffffdfffffffffff04000000`', src/constraint_system/logic.rs:286:9

Platform
all

Additional context
n/a

@moCello moCello added the fix:bug Something isn't working label Apr 25, 2022
@moCello moCello changed the title Logic gates are not working properly Assert in logic gate fails for larger input Apr 28, 2022
@moCello moCello linked a pull request May 2, 2022 that will close this issue
@moCello moCello closed this as completed in 65972e4 May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant