Skip to content

Assert in logic gate fails for larger input #678

Closed
@moCello

Description

@moCello

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions