diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs index 376b7894f26..b2123497750 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs @@ -529,7 +529,7 @@ impl DataFlowGraph { Value::Instruction { instruction, .. } => { let value_bit_size = self.type_of_value(value).bit_size(); if let Instruction::Cast(original_value, _) = self[instruction] { - let original_bit_size = self.type_of_value(original_value).bit_size(); + let original_bit_size = self.get_value_max_num_bits(original_value); // We might have cast e.g. `u1` to `u8` to be able to do arithmetic, // in which case we want to recover the original smaller bit size; // OTOH if we cast down, then we don't need the higher original size. diff --git a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs index 0eb15046065..f7a8bdd4b00 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs @@ -148,7 +148,15 @@ impl Context<'_, '_, '_> { || { // If we don't know `rhs`'s value then it could be anything up to the number // of bits in the type, e.g. u32 means shifting by up to 32 bits as otherwise we get overflow. - self.context.dfg.get_value_max_num_bits(rhs) + // get_value_max_num_bits might indicate that the underlying type actually has less + // bits than the RHS; e.g. because it was upcast from a u1 to a u32. + // The maximum value we can get would be `2^bits - 1`, but `u1` is the only interesting case, + // because even for u8 the max value is 255, larger than anything we get based on type. + if self.context.dfg.get_value_max_num_bits(rhs) == 1 { + 1 + } else { + self.context.dfg.type_of_value(rhs).bit_size() + } }, |rhs_constant| { // Happy case is that we know precisely by how many bits we're shifting by. @@ -467,15 +475,16 @@ mod tests { let ssa = Ssa::from_str(src).unwrap(); let ssa = ssa.remove_bit_shifts(); assert_ssa_snapshot!(ssa, @r" - acir(inline) fn main f0 { - b0(v0: u32): - v1 = cast v0 as Field - v3 = mul v1, Field 4 - v4 = truncate v3 to 32 bits, max_bit_size: 34 - v5 = cast v4 as u32 - return v5 - } - "); + acir(inline) fn main f0 { + b0(v0: u32): + v1 = cast v0 as Field + v3 = mul v1, Field 4 + v4 = truncate v3 to 32 bits, max_bit_size: 34 + v5 = cast v4 as u32 + return v5 + } + " + ); } #[test] @@ -548,6 +557,125 @@ mod tests { "#); } + #[test] + fn removes_shl_with_non_constant_rhs_casted_from_smaller_type() { + let src = " + acir(inline) fn main f0 { + b0(v0: u32, v1: u8): + v2 = cast v1 as u32 + v3 = shl v0, v2 + return v3 + } + "; + let ssa = Ssa::from_str(src).unwrap(); + let ssa = ssa.remove_bit_shifts(); + + // `max_bit_size` in `truncate` has to be 64, because even though `u8` is just 8 bits, + // the maximum value can be 255, which would clearly overflow, as anything over 32 would. + assert_ssa_snapshot!(ssa, @r#" + acir(inline) fn main f0 { + b0(v0: u32, v1: u8): + v2 = cast v1 as u32 + v3 = cast v1 as u32 + v5 = lt v3, u32 32 + constrain v5 == u1 1, "attempt to bit-shift with overflow" + v7 = cast v1 as Field + v9 = call to_le_bits(v7) -> [u1; 5] + v11 = array_get v9, index u32 4 -> u1 + v12 = not v11 + v13 = cast v11 as Field + v14 = cast v12 as Field + v16 = mul Field 2, v13 + v17 = add v14, v16 + v19 = array_get v9, index u32 3 -> u1 + v20 = not v19 + v21 = cast v19 as Field + v22 = cast v20 as Field + v23 = mul v17, v17 + v24 = mul v23, v22 + v25 = mul v23, Field 2 + v26 = mul v25, v21 + v27 = add v24, v26 + v29 = array_get v9, index u32 2 -> u1 + v30 = not v29 + v31 = cast v29 as Field + v32 = cast v30 as Field + v33 = mul v27, v27 + v34 = mul v33, v32 + v35 = mul v33, Field 2 + v36 = mul v35, v31 + v37 = add v34, v36 + v39 = array_get v9, index u32 1 -> u1 + v40 = not v39 + v41 = cast v39 as Field + v42 = cast v40 as Field + v43 = mul v37, v37 + v44 = mul v43, v42 + v45 = mul v43, Field 2 + v46 = mul v45, v41 + v47 = add v44, v46 + v49 = array_get v9, index u32 0 -> u1 + v50 = not v49 + v51 = cast v49 as Field + v52 = cast v50 as Field + v53 = mul v47, v47 + v54 = mul v53, v52 + v55 = mul v53, Field 2 + v56 = mul v55, v51 + v57 = add v54, v56 + v58 = cast v0 as Field + v59 = mul v58, v57 + v60 = truncate v59 to 32 bits, max_bit_size: 64 + v61 = cast v60 as u32 + return v61 + } + "#); + } + + #[test] + fn removes_shl_with_non_constant_rhs_casted_from_u1() { + let src = " + acir(inline) fn main f0 { + b0(v0: u64, v1: u1): + v2 = cast v1 as u8 + v3 = cast v2 as u32 + v4 = cast v3 as u64 + v5 = shl v0, v4 + return v5 + } + "; + let ssa = Ssa::from_str(src).unwrap(); + let ssa = ssa.remove_bit_shifts(); + + // What we are casting with can originally be only 1 bit, + // so in the truncate we expect to shift with less than + // if only considered the 64 bits based on the type. + assert_ssa_snapshot!(ssa, @r#" + acir(inline) fn main f0 { + b0(v0: u64, v1: u1): + v2 = cast v1 as u8 + v3 = cast v2 as u32 + v4 = cast v3 as u64 + v5 = cast v3 as u64 + v7 = lt v5, u64 64 + constrain v7 == u1 1, "attempt to bit-shift with overflow" + v9 = cast v3 as Field + v11 = call to_le_bits(v9) -> [u1; 1] + v13 = array_get v11, index u32 0 -> u1 + v14 = not v13 + v15 = cast v13 as Field + v16 = cast v14 as Field + v18 = mul Field 2, v15 + v19 = add v16, v18 + v20 = cast v0 as Field + v21 = mul v20, v19 + v22 = truncate v21 to 64 bits, max_bit_size: 65 + v23 = cast v22 as u64 + return v23 + } + "#); + } + #[test] fn does_not_generate_invalid_truncation_on_overflowing_bitshift() { // We want to ensure that the `max_bit_size` of the truncation does not exceed the field size. diff --git a/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/Nargo.toml b/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/Nargo.toml new file mode 100644 index 00000000000..5851dc3c3b4 --- /dev/null +++ b/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "shift_left_rhs_value_casted_from_smaller_type" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/Prover.toml b/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/Prover.toml new file mode 100644 index 00000000000..8982667e227 --- /dev/null +++ b/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/Prover.toml @@ -0,0 +1,2 @@ +b = 10 +return = 7435510297333629952 diff --git a/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/src/main.nr b/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/src/main.nr new file mode 100644 index 00000000000..4fb32532916 --- /dev/null +++ b/test_programs/execution_success/shift_left_rhs_value_casted_from_smaller_type/src/main.nr @@ -0,0 +1,3 @@ +fn main(b: u8) -> pub u64 { + (15877946327378367777 << (b as u64)) +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__expanded.snap new file mode 100644 index 00000000000..99b246eec42 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__expanded.snap @@ -0,0 +1,7 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +fn main(b: u8) -> pub u64 { + 15877946327378367777_u64 << (b as u64) +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..b58720d2b52 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap @@ -0,0 +1,91 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "b", + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 64 + }, + "visibility": "public" + }, + "error_types": { + "2561832918745063247": { + "error_kind": "string", + "string": "Field failed to decompose into specified 6 limbs" + }, + "5421095327929394772": { + "error_kind": "string", + "string": "attempt to bit-shift with overflow" + } + } + }, + "bytecode": [ + "func 0", + "current witness index : _25", + "private parameters indices : [_0]", + "public parameters indices : []", + "return value indices : [_1]", + "BLACKBOX::RANGE [(_0, 8)] []", + "BRILLIG CALL func 0: inputs: [EXPR [ (1, _0) 18446744073709551552 ], EXPR [ 18446744073709551616 ]], outputs: [_2, _3]", + "BLACKBOX::RANGE [(_3, 64)] []", + "EXPR [ (1, _0) (-18446744073709551616, _2) (-1, _3) 18446744073709551552 ]", + "EXPR [ (-1, _2) 0 ]", + "BRILLIG CALL func 1: inputs: [EXPR [ (1, _0) 0 ], EXPR [ 6 ], EXPR [ 2 ]], outputs: [[_4, _5, _6, _7, _8, _9]]", + "BLACKBOX::RANGE [(_4, 1)] []", + "BLACKBOX::RANGE [(_5, 1)] []", + "BLACKBOX::RANGE [(_6, 1)] []", + "BLACKBOX::RANGE [(_7, 1)] []", + "BLACKBOX::RANGE [(_8, 1)] []", + "BLACKBOX::RANGE [(_9, 1)] []", + "EXPR [ (1, _0) (-1, _4) (-2, _5) (-4, _6) (-8, _7) (-16, _8) (-32, _9) 0 ]", + "EXPR [ (1, _9, _9) (2, _9) (-1, _10) 1 ]", + "EXPR [ (-1, _8) (-1, _11) 1 ]", + "EXPR [ (2, _8, _10) (1, _10, _11) (-1, _12) 0 ]", + "EXPR [ (1, _12, _12) (-1, _13) 0 ]", + "EXPR [ (-1, _7) (-1, _14) 1 ]", + "EXPR [ (2, _7, _13) (1, _13, _14) (-1, _15) 0 ]", + "EXPR [ (1, _15, _15) (-1, _16) 0 ]", + "EXPR [ (-1, _6) (-1, _17) 1 ]", + "EXPR [ (2, _6, _16) (1, _16, _17) (-1, _18) 0 ]", + "EXPR [ (1, _18, _18) (-1, _19) 0 ]", + "EXPR [ (-1, _5) (-1, _20) 1 ]", + "EXPR [ (2, _5, _19) (1, _19, _20) (-1, _21) 0 ]", + "EXPR [ (1, _21, _21) (-1, _22) 0 ]", + "EXPR [ (-1, _4) (-1, _23) 1 ]", + "BRILLIG CALL func 0: inputs: [EXPR [ (31755892654756735554, _22, _4) (15877946327378367777, _22, _23) 0 ], EXPR [ 18446744073709551616 ]], outputs: [_24, _25]", + "BLACKBOX::RANGE [(_24, 64)] []", + "BLACKBOX::RANGE [(_25, 64)] []", + "EXPR [ (31755892654756735554, _4, _22) (15877946327378367777, _22, _23) (-18446744073709551616, _24) (-1, _25) 0 ]", + "EXPR [ (1, _1) (-1, _25) 0 ]", + "unconstrained func 0", + "[Const { destination: Direct(10), bit_size: Integer(U32), value: 2 }, Const { destination: Direct(11), bit_size: Integer(U32), value: 0 }, CalldataCopy { destination_address: Direct(0), size_address: Direct(10), offset_address: Direct(11) }, BinaryFieldOp { destination: Direct(2), op: IntegerDiv, lhs: Direct(0), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(1), op: Mul, lhs: Direct(2), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(1), op: Sub, lhs: Direct(0), rhs: Direct(1) }, Mov { destination: Direct(0), source: Direct(2) }, Stop { return_data: HeapVector { pointer: Direct(11), size: Direct(10) } }]", + "unconstrained func 1", + "[Const { destination: Direct(5), bit_size: Integer(U32), value: 0 }, Const { destination: Direct(6), bit_size: Integer(U32), value: 1 }, Const { destination: Direct(7), bit_size: Integer(U32), value: 3 }, CalldataCopy { destination_address: Direct(0), size_address: Direct(7), offset_address: Direct(5) }, Cast { destination: Direct(1), source: Direct(1), bit_size: Integer(U32) }, Const { destination: Direct(9), bit_size: Integer(U32), value: 10 }, BinaryIntOp { destination: Direct(7), op: Add, bit_size: U32, lhs: Direct(9), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(3), op: IntegerDiv, lhs: Direct(0), rhs: Direct(2) }, BinaryFieldOp { destination: Direct(4), op: Mul, lhs: Direct(3), rhs: Direct(2) }, BinaryFieldOp { destination: Direct(4), op: Sub, lhs: Direct(0), rhs: Direct(4) }, Store { destination_pointer: Direct(9), source: Direct(4) }, BinaryIntOp { destination: Direct(9), op: Add, bit_size: U32, lhs: Direct(9), rhs: Direct(6) }, Mov { destination: Direct(0), source: Direct(3) }, BinaryIntOp { destination: Direct(8), op: LessThan, bit_size: U32, lhs: Direct(9), rhs: Direct(7) }, JumpIf { condition: Direct(8), location: 7 }, Const { destination: Direct(9), bit_size: Integer(U32), value: 10 }, Stop { return_data: HeapVector { pointer: Direct(9), size: Direct(1) } }]" + ], + "debug_symbols": "[debug_symbols]", + "file_map": "[file_map]", + "names": [ + "main" + ], + "brillig_names": [ + "directive_integer_quotient", + "directive_to_radix" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_0.snap new file mode 100644 index 00000000000..b58720d2b52 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_0.snap @@ -0,0 +1,91 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "b", + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 64 + }, + "visibility": "public" + }, + "error_types": { + "2561832918745063247": { + "error_kind": "string", + "string": "Field failed to decompose into specified 6 limbs" + }, + "5421095327929394772": { + "error_kind": "string", + "string": "attempt to bit-shift with overflow" + } + } + }, + "bytecode": [ + "func 0", + "current witness index : _25", + "private parameters indices : [_0]", + "public parameters indices : []", + "return value indices : [_1]", + "BLACKBOX::RANGE [(_0, 8)] []", + "BRILLIG CALL func 0: inputs: [EXPR [ (1, _0) 18446744073709551552 ], EXPR [ 18446744073709551616 ]], outputs: [_2, _3]", + "BLACKBOX::RANGE [(_3, 64)] []", + "EXPR [ (1, _0) (-18446744073709551616, _2) (-1, _3) 18446744073709551552 ]", + "EXPR [ (-1, _2) 0 ]", + "BRILLIG CALL func 1: inputs: [EXPR [ (1, _0) 0 ], EXPR [ 6 ], EXPR [ 2 ]], outputs: [[_4, _5, _6, _7, _8, _9]]", + "BLACKBOX::RANGE [(_4, 1)] []", + "BLACKBOX::RANGE [(_5, 1)] []", + "BLACKBOX::RANGE [(_6, 1)] []", + "BLACKBOX::RANGE [(_7, 1)] []", + "BLACKBOX::RANGE [(_8, 1)] []", + "BLACKBOX::RANGE [(_9, 1)] []", + "EXPR [ (1, _0) (-1, _4) (-2, _5) (-4, _6) (-8, _7) (-16, _8) (-32, _9) 0 ]", + "EXPR [ (1, _9, _9) (2, _9) (-1, _10) 1 ]", + "EXPR [ (-1, _8) (-1, _11) 1 ]", + "EXPR [ (2, _8, _10) (1, _10, _11) (-1, _12) 0 ]", + "EXPR [ (1, _12, _12) (-1, _13) 0 ]", + "EXPR [ (-1, _7) (-1, _14) 1 ]", + "EXPR [ (2, _7, _13) (1, _13, _14) (-1, _15) 0 ]", + "EXPR [ (1, _15, _15) (-1, _16) 0 ]", + "EXPR [ (-1, _6) (-1, _17) 1 ]", + "EXPR [ (2, _6, _16) (1, _16, _17) (-1, _18) 0 ]", + "EXPR [ (1, _18, _18) (-1, _19) 0 ]", + "EXPR [ (-1, _5) (-1, _20) 1 ]", + "EXPR [ (2, _5, _19) (1, _19, _20) (-1, _21) 0 ]", + "EXPR [ (1, _21, _21) (-1, _22) 0 ]", + "EXPR [ (-1, _4) (-1, _23) 1 ]", + "BRILLIG CALL func 0: inputs: [EXPR [ (31755892654756735554, _22, _4) (15877946327378367777, _22, _23) 0 ], EXPR [ 18446744073709551616 ]], outputs: [_24, _25]", + "BLACKBOX::RANGE [(_24, 64)] []", + "BLACKBOX::RANGE [(_25, 64)] []", + "EXPR [ (31755892654756735554, _4, _22) (15877946327378367777, _22, _23) (-18446744073709551616, _24) (-1, _25) 0 ]", + "EXPR [ (1, _1) (-1, _25) 0 ]", + "unconstrained func 0", + "[Const { destination: Direct(10), bit_size: Integer(U32), value: 2 }, Const { destination: Direct(11), bit_size: Integer(U32), value: 0 }, CalldataCopy { destination_address: Direct(0), size_address: Direct(10), offset_address: Direct(11) }, BinaryFieldOp { destination: Direct(2), op: IntegerDiv, lhs: Direct(0), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(1), op: Mul, lhs: Direct(2), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(1), op: Sub, lhs: Direct(0), rhs: Direct(1) }, Mov { destination: Direct(0), source: Direct(2) }, Stop { return_data: HeapVector { pointer: Direct(11), size: Direct(10) } }]", + "unconstrained func 1", + "[Const { destination: Direct(5), bit_size: Integer(U32), value: 0 }, Const { destination: Direct(6), bit_size: Integer(U32), value: 1 }, Const { destination: Direct(7), bit_size: Integer(U32), value: 3 }, CalldataCopy { destination_address: Direct(0), size_address: Direct(7), offset_address: Direct(5) }, Cast { destination: Direct(1), source: Direct(1), bit_size: Integer(U32) }, Const { destination: Direct(9), bit_size: Integer(U32), value: 10 }, BinaryIntOp { destination: Direct(7), op: Add, bit_size: U32, lhs: Direct(9), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(3), op: IntegerDiv, lhs: Direct(0), rhs: Direct(2) }, BinaryFieldOp { destination: Direct(4), op: Mul, lhs: Direct(3), rhs: Direct(2) }, BinaryFieldOp { destination: Direct(4), op: Sub, lhs: Direct(0), rhs: Direct(4) }, Store { destination_pointer: Direct(9), source: Direct(4) }, BinaryIntOp { destination: Direct(9), op: Add, bit_size: U32, lhs: Direct(9), rhs: Direct(6) }, Mov { destination: Direct(0), source: Direct(3) }, BinaryIntOp { destination: Direct(8), op: LessThan, bit_size: U32, lhs: Direct(9), rhs: Direct(7) }, JumpIf { condition: Direct(8), location: 7 }, Const { destination: Direct(9), bit_size: Integer(U32), value: 10 }, Stop { return_data: HeapVector { pointer: Direct(9), size: Direct(1) } }]" + ], + "debug_symbols": "[debug_symbols]", + "file_map": "[file_map]", + "names": [ + "main" + ], + "brillig_names": [ + "directive_integer_quotient", + "directive_to_radix" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..b58720d2b52 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_false_inliner_9223372036854775807.snap @@ -0,0 +1,91 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "b", + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 64 + }, + "visibility": "public" + }, + "error_types": { + "2561832918745063247": { + "error_kind": "string", + "string": "Field failed to decompose into specified 6 limbs" + }, + "5421095327929394772": { + "error_kind": "string", + "string": "attempt to bit-shift with overflow" + } + } + }, + "bytecode": [ + "func 0", + "current witness index : _25", + "private parameters indices : [_0]", + "public parameters indices : []", + "return value indices : [_1]", + "BLACKBOX::RANGE [(_0, 8)] []", + "BRILLIG CALL func 0: inputs: [EXPR [ (1, _0) 18446744073709551552 ], EXPR [ 18446744073709551616 ]], outputs: [_2, _3]", + "BLACKBOX::RANGE [(_3, 64)] []", + "EXPR [ (1, _0) (-18446744073709551616, _2) (-1, _3) 18446744073709551552 ]", + "EXPR [ (-1, _2) 0 ]", + "BRILLIG CALL func 1: inputs: [EXPR [ (1, _0) 0 ], EXPR [ 6 ], EXPR [ 2 ]], outputs: [[_4, _5, _6, _7, _8, _9]]", + "BLACKBOX::RANGE [(_4, 1)] []", + "BLACKBOX::RANGE [(_5, 1)] []", + "BLACKBOX::RANGE [(_6, 1)] []", + "BLACKBOX::RANGE [(_7, 1)] []", + "BLACKBOX::RANGE [(_8, 1)] []", + "BLACKBOX::RANGE [(_9, 1)] []", + "EXPR [ (1, _0) (-1, _4) (-2, _5) (-4, _6) (-8, _7) (-16, _8) (-32, _9) 0 ]", + "EXPR [ (1, _9, _9) (2, _9) (-1, _10) 1 ]", + "EXPR [ (-1, _8) (-1, _11) 1 ]", + "EXPR [ (2, _8, _10) (1, _10, _11) (-1, _12) 0 ]", + "EXPR [ (1, _12, _12) (-1, _13) 0 ]", + "EXPR [ (-1, _7) (-1, _14) 1 ]", + "EXPR [ (2, _7, _13) (1, _13, _14) (-1, _15) 0 ]", + "EXPR [ (1, _15, _15) (-1, _16) 0 ]", + "EXPR [ (-1, _6) (-1, _17) 1 ]", + "EXPR [ (2, _6, _16) (1, _16, _17) (-1, _18) 0 ]", + "EXPR [ (1, _18, _18) (-1, _19) 0 ]", + "EXPR [ (-1, _5) (-1, _20) 1 ]", + "EXPR [ (2, _5, _19) (1, _19, _20) (-1, _21) 0 ]", + "EXPR [ (1, _21, _21) (-1, _22) 0 ]", + "EXPR [ (-1, _4) (-1, _23) 1 ]", + "BRILLIG CALL func 0: inputs: [EXPR [ (31755892654756735554, _22, _4) (15877946327378367777, _22, _23) 0 ], EXPR [ 18446744073709551616 ]], outputs: [_24, _25]", + "BLACKBOX::RANGE [(_24, 64)] []", + "BLACKBOX::RANGE [(_25, 64)] []", + "EXPR [ (31755892654756735554, _4, _22) (15877946327378367777, _22, _23) (-18446744073709551616, _24) (-1, _25) 0 ]", + "EXPR [ (1, _1) (-1, _25) 0 ]", + "unconstrained func 0", + "[Const { destination: Direct(10), bit_size: Integer(U32), value: 2 }, Const { destination: Direct(11), bit_size: Integer(U32), value: 0 }, CalldataCopy { destination_address: Direct(0), size_address: Direct(10), offset_address: Direct(11) }, BinaryFieldOp { destination: Direct(2), op: IntegerDiv, lhs: Direct(0), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(1), op: Mul, lhs: Direct(2), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(1), op: Sub, lhs: Direct(0), rhs: Direct(1) }, Mov { destination: Direct(0), source: Direct(2) }, Stop { return_data: HeapVector { pointer: Direct(11), size: Direct(10) } }]", + "unconstrained func 1", + "[Const { destination: Direct(5), bit_size: Integer(U32), value: 0 }, Const { destination: Direct(6), bit_size: Integer(U32), value: 1 }, Const { destination: Direct(7), bit_size: Integer(U32), value: 3 }, CalldataCopy { destination_address: Direct(0), size_address: Direct(7), offset_address: Direct(5) }, Cast { destination: Direct(1), source: Direct(1), bit_size: Integer(U32) }, Const { destination: Direct(9), bit_size: Integer(U32), value: 10 }, BinaryIntOp { destination: Direct(7), op: Add, bit_size: U32, lhs: Direct(9), rhs: Direct(1) }, BinaryFieldOp { destination: Direct(3), op: IntegerDiv, lhs: Direct(0), rhs: Direct(2) }, BinaryFieldOp { destination: Direct(4), op: Mul, lhs: Direct(3), rhs: Direct(2) }, BinaryFieldOp { destination: Direct(4), op: Sub, lhs: Direct(0), rhs: Direct(4) }, Store { destination_pointer: Direct(9), source: Direct(4) }, BinaryIntOp { destination: Direct(9), op: Add, bit_size: U32, lhs: Direct(9), rhs: Direct(6) }, Mov { destination: Direct(0), source: Direct(3) }, BinaryIntOp { destination: Direct(8), op: LessThan, bit_size: U32, lhs: Direct(9), rhs: Direct(7) }, JumpIf { condition: Direct(8), location: 7 }, Const { destination: Direct(9), bit_size: Integer(U32), value: 10 }, Stop { return_data: HeapVector { pointer: Direct(9), size: Direct(1) } }]" + ], + "debug_symbols": "[debug_symbols]", + "file_map": "[file_map]", + "names": [ + "main" + ], + "brillig_names": [ + "directive_integer_quotient", + "directive_to_radix" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..18e3953f1f8 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap @@ -0,0 +1,53 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "b", + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 64 + }, + "visibility": "public" + }, + "error_types": { + "15764276373176857197": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": [ + "func 0", + "current witness index : _1", + "private parameters indices : [_0]", + "public parameters indices : []", + "return value indices : [_1]", + "BRILLIG CALL func 0: inputs: [EXPR [ (1, _0) 0 ]], outputs: [_1]", + "unconstrained func 0", + "[Const { destination: Direct(2), bit_size: Integer(U32), value: 1 }, Const { destination: Direct(1), bit_size: Integer(U32), value: 32838 }, Const { destination: Direct(0), bit_size: Integer(U32), value: 3 }, Const { destination: Relative(2), bit_size: Integer(U32), value: 1 }, Const { destination: Relative(3), bit_size: Integer(U32), value: 0 }, CalldataCopy { destination_address: Direct(32836), size_address: Relative(2), offset_address: Relative(3) }, Cast { destination: Direct(32836), source: Direct(32836), bit_size: Integer(U8) }, Mov { destination: Relative(1), source: Direct(32836) }, Call { location: 14 }, Call { location: 15 }, Mov { destination: Direct(32837), source: Relative(1) }, Const { destination: Relative(2), bit_size: Integer(U32), value: 32837 }, Const { destination: Relative(3), bit_size: Integer(U32), value: 1 }, Stop { return_data: HeapVector { pointer: Relative(2), size: Relative(3) } }, Return, Call { location: 21 }, Cast { destination: Relative(2), source: Relative(1), bit_size: Integer(U64) }, Const { destination: Relative(1), bit_size: Integer(U64), value: 15877946327378367777 }, BinaryIntOp { destination: Relative(3), op: Shl, bit_size: U64, lhs: Relative(1), rhs: Relative(2) }, Mov { destination: Relative(1), source: Relative(3) }, Return, Const { destination: Direct(32772), bit_size: Integer(U32), value: 30720 }, BinaryIntOp { destination: Direct(32771), op: LessThan, bit_size: U32, lhs: Direct(0), rhs: Direct(32772) }, JumpIf { condition: Direct(32771), location: 26 }, IndirectConst { destination_pointer: Direct(1), bit_size: Integer(U64), value: 15764276373176857197 }, Trap { revert_data: HeapVector { pointer: Direct(1), size: Direct(2) } }, Return]" + ], + "debug_symbols": "[debug_symbols]", + "file_map": "[file_map]", + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_0.snap new file mode 100644 index 00000000000..18e3953f1f8 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_0.snap @@ -0,0 +1,53 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "b", + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 64 + }, + "visibility": "public" + }, + "error_types": { + "15764276373176857197": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": [ + "func 0", + "current witness index : _1", + "private parameters indices : [_0]", + "public parameters indices : []", + "return value indices : [_1]", + "BRILLIG CALL func 0: inputs: [EXPR [ (1, _0) 0 ]], outputs: [_1]", + "unconstrained func 0", + "[Const { destination: Direct(2), bit_size: Integer(U32), value: 1 }, Const { destination: Direct(1), bit_size: Integer(U32), value: 32838 }, Const { destination: Direct(0), bit_size: Integer(U32), value: 3 }, Const { destination: Relative(2), bit_size: Integer(U32), value: 1 }, Const { destination: Relative(3), bit_size: Integer(U32), value: 0 }, CalldataCopy { destination_address: Direct(32836), size_address: Relative(2), offset_address: Relative(3) }, Cast { destination: Direct(32836), source: Direct(32836), bit_size: Integer(U8) }, Mov { destination: Relative(1), source: Direct(32836) }, Call { location: 14 }, Call { location: 15 }, Mov { destination: Direct(32837), source: Relative(1) }, Const { destination: Relative(2), bit_size: Integer(U32), value: 32837 }, Const { destination: Relative(3), bit_size: Integer(U32), value: 1 }, Stop { return_data: HeapVector { pointer: Relative(2), size: Relative(3) } }, Return, Call { location: 21 }, Cast { destination: Relative(2), source: Relative(1), bit_size: Integer(U64) }, Const { destination: Relative(1), bit_size: Integer(U64), value: 15877946327378367777 }, BinaryIntOp { destination: Relative(3), op: Shl, bit_size: U64, lhs: Relative(1), rhs: Relative(2) }, Mov { destination: Relative(1), source: Relative(3) }, Return, Const { destination: Direct(32772), bit_size: Integer(U32), value: 30720 }, BinaryIntOp { destination: Direct(32771), op: LessThan, bit_size: U32, lhs: Direct(0), rhs: Direct(32772) }, JumpIf { condition: Direct(32771), location: 26 }, IndirectConst { destination_pointer: Direct(1), bit_size: Integer(U64), value: 15764276373176857197 }, Trap { revert_data: HeapVector { pointer: Direct(1), size: Direct(2) } }, Return]" + ], + "debug_symbols": "[debug_symbols]", + "file_map": "[file_map]", + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..18e3953f1f8 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__force_brillig_true_inliner_9223372036854775807.snap @@ -0,0 +1,53 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "b", + "type": { + "kind": "integer", + "sign": "unsigned", + "width": 8 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 64 + }, + "visibility": "public" + }, + "error_types": { + "15764276373176857197": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": [ + "func 0", + "current witness index : _1", + "private parameters indices : [_0]", + "public parameters indices : []", + "return value indices : [_1]", + "BRILLIG CALL func 0: inputs: [EXPR [ (1, _0) 0 ]], outputs: [_1]", + "unconstrained func 0", + "[Const { destination: Direct(2), bit_size: Integer(U32), value: 1 }, Const { destination: Direct(1), bit_size: Integer(U32), value: 32838 }, Const { destination: Direct(0), bit_size: Integer(U32), value: 3 }, Const { destination: Relative(2), bit_size: Integer(U32), value: 1 }, Const { destination: Relative(3), bit_size: Integer(U32), value: 0 }, CalldataCopy { destination_address: Direct(32836), size_address: Relative(2), offset_address: Relative(3) }, Cast { destination: Direct(32836), source: Direct(32836), bit_size: Integer(U8) }, Mov { destination: Relative(1), source: Direct(32836) }, Call { location: 14 }, Call { location: 15 }, Mov { destination: Direct(32837), source: Relative(1) }, Const { destination: Relative(2), bit_size: Integer(U32), value: 32837 }, Const { destination: Relative(3), bit_size: Integer(U32), value: 1 }, Stop { return_data: HeapVector { pointer: Relative(2), size: Relative(3) } }, Return, Call { location: 21 }, Cast { destination: Relative(2), source: Relative(1), bit_size: Integer(U64) }, Const { destination: Relative(1), bit_size: Integer(U64), value: 15877946327378367777 }, BinaryIntOp { destination: Relative(3), op: Shl, bit_size: U64, lhs: Relative(1), rhs: Relative(2) }, Mov { destination: Relative(1), source: Relative(3) }, Return, Const { destination: Direct(32772), bit_size: Integer(U32), value: 30720 }, BinaryIntOp { destination: Direct(32771), op: LessThan, bit_size: U32, lhs: Direct(0), rhs: Direct(32772) }, JumpIf { condition: Direct(32771), location: 26 }, IndirectConst { destination_pointer: Direct(1), bit_size: Integer(U64), value: 15764276373176857197 }, Trap { revert_data: HeapVector { pointer: Direct(1), size: Direct(2) } }, Return]" + ], + "debug_symbols": "[debug_symbols]", + "file_map": "[file_map]", + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__stdout.snap b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__stdout.snap new file mode 100644 index 00000000000..d845e7fbab0 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/shift_left_rhs_value_casted_from_smaller_type/execute__tests__stdout.snap @@ -0,0 +1,5 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: stdout +--- +[shift_left_rhs_value_casted_from_smaller_type] Circuit output: 7435510297333629952