Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ unused_must_use = "warn"
mismatched_lifetime_syntaxes = "allow"

[workspace.lints.clippy]
cast_lossless = "warn"
semicolon_if_nothing_returned = "warn"
result_large_err = "allow"
uninlined_format_args = "warn"
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acir_field/src/field_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ impl<F: PrimeField> AcirField for FieldElement<F> {
let as_bigint = self.0.into_bigint();
let limbs = as_bigint.as_ref();

let mut result = limbs[0] as u128;
let mut result = u128::from(limbs[0]);
if limbs.len() > 1 {
let high_limb = limbs[1] as u128;
let high_limb = u128::from(limbs[1]);
result += high_limb << 64;
}

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/blackbox/aes128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) fn solve_aes128_encryption_opcode<F: AcirField>(

// Write witness assignments
for (output_witness, value) in outputs.iter().zip(ciphertext.into_iter()) {
insert_value(output_witness, F::from(value as u128), initial_witness)?;
insert_value(output_witness, F::from(u128::from(value)), initial_witness)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/blackbox/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl AcvmBigIntSolver {
bytes.push(0);
}
bytes.iter().zip(outputs.iter()).for_each(|(byte, output)| {
initial_witness.insert(*output, F::from(*byte as u128));
initial_witness.insert(*output, F::from(u128::from(*byte)));
});
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/blackbox/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) fn solve_sha_256_permutation_opcode<F: AcirField>(
sha256_compression(&mut state, &message);

for (output_witness, value) in outputs.iter().zip(state.into_iter()) {
insert_value(output_witness, F::from(value as u128), initial_witness)?;
insert_value(output_witness, F::from(u128::from(value)), initial_witness)?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) fn solve<F: AcirField>(
}
let output_state = keccakf1600(state)?;
for (output_witness, value) in outputs.iter().zip(output_state.into_iter()) {
insert_value(output_witness, F::from(value as u128), initial_witness)?;
insert_value(output_witness, F::from(u128::from(value)), initial_witness)?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/acvm/src/pwg/memory_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<F: AcirField> MemoryOpSolver<F> {
if index >= self.block_len {
return Err(OpcodeResolutionError::IndexOutOfBounds {
opcode_location: ErrorLocation::Unresolved,
index: F::from(index as u128),
index: F::from(u128::from(index)),
array_size: self.block_len,
});
}
Expand All @@ -62,7 +62,7 @@ impl<F: AcirField> MemoryOpSolver<F> {
fn read_memory_index(&self, index: MemoryIndex) -> Result<F, OpcodeResolutionError<F>> {
self.block_value.get(&index).copied().ok_or(OpcodeResolutionError::IndexOutOfBounds {
opcode_location: ErrorLocation::Unresolved,
index: F::from(index as u128),
index: F::from(u128::from(index)),
array_size: self.block_len,
})
}
Expand Down
12 changes: 6 additions & 6 deletions acvm-repo/acvm/tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ prop_compose! {
(inputs in proptest::collection::vec(any::<(u8, bool)>(), modulus.len()), modulus in Just(modulus))
-> (Vec<ConstantOrWitness>, Vec<u8>) {
let inputs = inputs.into_iter().zip(modulus.iter()).map(|((input, use_constant), modulus_byte)| {
(FieldElement::from(input.clamp(0, *modulus_byte) as u128), use_constant)
(FieldElement::from(u128::from(input.clamp(0, *modulus_byte))), use_constant)
}).collect();
(inputs, modulus)
}
Expand All @@ -913,7 +913,7 @@ prop_compose! {
-> (Vec<ConstantOrWitness>, Vec<ConstantOrWitness>, Vec<u8>) {
let (inputs, modulus) = inputs_modulus;
let second_inputs = second_inputs.into_iter().zip(modulus.iter()).map(|((input, use_constant), modulus_byte)| {
(FieldElement::from(input.clamp(0, *modulus_byte) as u128), use_constant)
(FieldElement::from(u128::from(input.clamp(0, *modulus_byte))), use_constant)
}).collect();
(inputs, second_inputs, modulus)
}
Expand All @@ -925,7 +925,7 @@ prop_compose! {
-> (Vec<ConstantOrWitness>, Vec<ConstantOrWitness>, Vec<ConstantOrWitness>, Vec<u8>) {
let (inputs, second_inputs, modulus) = inputs_pair_modulus;
let third_inputs = third_inputs.into_iter().zip(modulus.iter()).map(|((input, use_constant), modulus_byte)| {
(FieldElement::from(input.clamp(0, *modulus_byte) as u128), use_constant)
(FieldElement::from(u128::from(input.clamp(0, *modulus_byte))), use_constant)
}).collect();
(inputs, second_inputs, third_inputs, modulus)
}
Expand Down Expand Up @@ -1718,7 +1718,7 @@ proptest! {
let mut extra_bytes: Vec<_> = extra_bytes
.into_iter()
.take(extra_bytes_len as usize)
.map(|(x, use_constant)| (FieldElement::from(x as u128), use_constant))
.map(|(x, use_constant)| (FieldElement::from(u128::from(x)), use_constant))
.collect();
input.append(&mut extra_bytes);
let expected_results: Vec<_> = drop_use_constant(&input);
Expand All @@ -1733,7 +1733,7 @@ proptest! {
let mut extra_bytes: Vec<_> = extra_bytes
.into_iter()
.take(extra_bytes_len as usize)
.map(|(x, use_constant)| (FieldElement::from(x as u128), use_constant))
.map(|(x, use_constant)| (FieldElement::from(u128::from(x)), use_constant))
.collect();
input.append(&mut extra_bytes);
let expected_results: Vec<_> = drop_use_constant(&input);
Expand All @@ -1748,7 +1748,7 @@ proptest! {
fn bigint_from_to_le_bytes_bigger_than_u8((input, modulus) in bigint_with_modulus(), patch_location: usize, larger_value: u16, use_constant: bool) {
let mut input = input;
let patch_location = patch_location % input.len();
let larger_value = FieldElement::from(std::cmp::max((u8::MAX as u16) + 1, larger_value) as u128);
let larger_value = FieldElement::from(u128::from(std::cmp::max(u16::from(u8::MAX) + 1, larger_value)));
input[patch_location] = (larger_value, use_constant);
let expected_results: Vec<_> = drop_use_constant(&input);
let pedantic_solving = true;
Expand Down
4 changes: 2 additions & 2 deletions acvm-repo/bn254_blackbox_solver/src/embedded_curve_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn multi_scalar_mul(
Ok((
FieldElement::from_repr(out_x),
FieldElement::from_repr(out_y),
FieldElement::from(output_point.is_zero() as u128),
FieldElement::from(u128::from(output_point.is_zero())),
))
} else {
Ok((FieldElement::from(0_u128), FieldElement::from(0_u128), FieldElement::from(1_u128)))
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn embedded_curve_add(
Ok((
FieldElement::from_repr(res_x),
FieldElement::from_repr(res_y),
FieldElement::from(res.is_zero() as u128),
FieldElement::from(u128::from(res.is_zero())),
))
} else if res.is_zero() {
Ok((FieldElement::from(0_u128), FieldElement::from(0_u128), FieldElement::from(1_u128)))
Expand Down
8 changes: 4 additions & 4 deletions acvm-repo/brillig_vm/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub(crate) fn evaluate_binary_int_op<F: AcirField>(
} else {
Err(BrilligArithmeticError::BitshiftOverflow {
bit_size: 8,
shift_size: rhs as u128,
shift_size: u128::from(rhs),
})
}
}
Expand All @@ -189,7 +189,7 @@ pub(crate) fn evaluate_binary_int_op<F: AcirField>(
} else {
Err(BrilligArithmeticError::BitshiftOverflow {
bit_size: 16,
shift_size: rhs as u128,
shift_size: u128::from(rhs),
})
}
}
Expand All @@ -199,7 +199,7 @@ pub(crate) fn evaluate_binary_int_op<F: AcirField>(
} else {
Err(BrilligArithmeticError::BitshiftOverflow {
bit_size: 32,
shift_size: rhs as u128,
shift_size: u128::from(rhs),
})
}
}
Expand All @@ -209,7 +209,7 @@ pub(crate) fn evaluate_binary_int_op<F: AcirField>(
} else {
Err(BrilligArithmeticError::BitshiftOverflow {
bit_size: 64,
shift_size: rhs as u128,
shift_size: u128::from(rhs),
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions acvm-repo/brillig_vm/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,28 @@ pub(crate) fn cast<F: AcirField>(
(U8(value), BitSize::Integer(IntegerBitSize::U32)) => U32(value.into()),
(U8(value), BitSize::Integer(IntegerBitSize::U64)) => U64(value.into()),
(U8(value), BitSize::Integer(IntegerBitSize::U128)) => U128(value.into()),
(U8(value), BitSize::Field) => Field((value as u128).into()),
(U8(value), BitSize::Field) => Field(u128::from(value).into()),

(U16(value), BitSize::Integer(IntegerBitSize::U1)) => U1(value & 0x01 == 1),
(U16(value), BitSize::Integer(IntegerBitSize::U8)) => U8(value as u8),
(U16(value), BitSize::Integer(IntegerBitSize::U32)) => U32(value.into()),
(U16(value), BitSize::Integer(IntegerBitSize::U64)) => U64(value.into()),
(U16(value), BitSize::Integer(IntegerBitSize::U128)) => U128(value.into()),
(U16(value), BitSize::Field) => Field((value as u128).into()),
(U16(value), BitSize::Field) => Field(u128::from(value).into()),

(U32(value), BitSize::Integer(IntegerBitSize::U1)) => U1(value & 0x01 == 1),
(U32(value), BitSize::Integer(IntegerBitSize::U8)) => U8(value as u8),
(U32(value), BitSize::Integer(IntegerBitSize::U16)) => U16(value as u16),
(U32(value), BitSize::Integer(IntegerBitSize::U64)) => U64(value.into()),
(U32(value), BitSize::Integer(IntegerBitSize::U128)) => U128(value.into()),
(U32(value), BitSize::Field) => Field((value as u128).into()),
(U32(value), BitSize::Field) => Field(u128::from(value).into()),

(U64(value), BitSize::Integer(IntegerBitSize::U1)) => U1(value & 0x01 == 1),
(U64(value), BitSize::Integer(IntegerBitSize::U8)) => U8(value as u8),
(U64(value), BitSize::Integer(IntegerBitSize::U16)) => U16(value as u16),
(U64(value), BitSize::Integer(IntegerBitSize::U32)) => U32(value as u32),
(U64(value), BitSize::Integer(IntegerBitSize::U128)) => U128(value.into()),
(U64(value), BitSize::Field) => Field((value as u128).into()),
(U64(value), BitSize::Field) => Field(u128::from(value).into()),

(U128(value), BitSize::Integer(IntegerBitSize::U1)) => U1(value & 0x01 == 1),
(U128(value), BitSize::Integer(IntegerBitSize::U8)) => U8(value as u8),
Expand Down
18 changes: 9 additions & 9 deletions acvm-repo/brillig_vm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl<F: AcirField> MemoryValue<F> {
match self {
MemoryValue::Field(value) => *value,
MemoryValue::U1(value) => F::from(*value),
MemoryValue::U8(value) => F::from(*value as u128),
MemoryValue::U16(value) => F::from(*value as u128),
MemoryValue::U32(value) => F::from(*value as u128),
MemoryValue::U64(value) => F::from(*value as u128),
MemoryValue::U8(value) => F::from(u128::from(*value)),
MemoryValue::U16(value) => F::from(u128::from(*value)),
MemoryValue::U32(value) => F::from(u128::from(*value)),
MemoryValue::U64(value) => F::from(u128::from(*value)),
MemoryValue::U128(value) => F::from(*value),
}
}
Expand All @@ -115,11 +115,11 @@ impl<F: AcirField> MemoryValue<F> {
pub fn to_u128(&self) -> Result<u128, MemoryTypeError> {
match self {
MemoryValue::Field(..) => Err(MemoryTypeError::NotAnInteger),
MemoryValue::U1(value) => Ok(*value as u8 as u128),
MemoryValue::U8(value) => Ok(*value as u128),
MemoryValue::U16(value) => Ok(*value as u128),
MemoryValue::U32(value) => Ok(*value as u128),
MemoryValue::U64(value) => Ok(*value as u128),
MemoryValue::U1(value) => Ok(u128::from(*value)),
MemoryValue::U8(value) => Ok(u128::from(*value)),
MemoryValue::U16(value) => Ok(u128::from(*value)),
MemoryValue::U32(value) => Ok(u128::from(*value)),
MemoryValue::U64(value) => Ok(u128::from(*value)),
MemoryValue::U128(value) => Ok(*value),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn report_all<'files>(
diagnostics.append(&mut errors);

let error_count =
diagnostics.iter().map(|error| error.report(files, deny_warnings) as u32).sum();
diagnostics.iter().map(|error| u32::from(error.report(files, deny_warnings))).sum();

ReportedErrors { error_count }
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/acir/acir_context/big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub(super) struct BigIntId {

impl BigIntId {
pub(super) fn bigint_id<F: From<u128>>(&self) -> F {
F::from(self.bigint_id as u128)
F::from(u128::from(self.bigint_id))
}

pub(super) fn modulus_id<F: From<u128>>(&self) -> F {
F::from(self.modulus_id as u128)
F::from(u128::from(self.modulus_id))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<F: AcirField, B: BlackBoxFunctionSolver<F>> AcirContext<F, B> {
output_count = 0;

let modulus_id = self.big_int_ctx.get_or_insert_modulus(big_modulus);
let result_id = self.big_int_ctx.new_big_int(F::from(modulus_id as u128));
let result_id = self.big_int_ctx.new_big_int(F::from(u128::from(modulus_id)));
(modulus, vec![result_id.bigint_id::<F>(), result_id.modulus_id::<F>()])
}
BlackBoxFunc::AES128Encrypt => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,12 @@ impl<F: AcirField> GeneratedAcir<F> {
let limbs_nb = Expression {
mul_terms: Vec::new(),
linear_combinations: Vec::new(),
q_c: F::from(limb_count as u128),
q_c: F::from(u128::from(limb_count)),
};
let radix_expr = Expression {
mul_terms: Vec::new(),
linear_combinations: Vec::new(),
q_c: F::from(radix as u128),
q_c: F::from(u128::from(radix)),
};
let inputs = vec![
BrilligInputs::Single(expr.clone()),
Expand Down
12 changes: 6 additions & 6 deletions compiler/noirc_evaluator/src/acir/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,10 +1134,10 @@ fn test_u32(lhs in 0u32.., rhs in 0u32..) {

//unchecked operations assume no under/over-flow
let mut unchecked_operators = vec![];
if (lhs + rhs).to_u128() <= u32::MAX as u128 {
if (lhs + rhs).to_u128() <= u128::from(u32::MAX) {
unchecked_operators.push("unchecked_add");
}
if (lhs * rhs).to_u128() <= u32::MAX as u128 {
if (lhs * rhs).to_u128() <= u128::from(u32::MAX) {
unchecked_operators.push("unchecked_mul");
}
if lhs >= rhs {
Expand Down Expand Up @@ -1176,17 +1176,17 @@ fn test_constraint_u64(lhs in 0u64.., rhs in 0u64..) {

#[test]
fn test_constraint_u16(lhs in 0u16.., rhs in 0u16..) {
let lhs = FieldElement::from(lhs as u128);
let rhs = FieldElement::from(rhs as u128);
let lhs = FieldElement::from(u128::from(lhs));
let rhs = FieldElement::from(u128::from(rhs));
let operators = ["constrain ==", "constrain !="];
test_operators(&operators, "u16", &[lhs,rhs]);
test_operators(&operators, "i16", &[lhs,rhs]);
}

#[test]
fn test_constraint_u8(lhs in 0u8.., rhs in 0u8..) {
let lhs = FieldElement::from(lhs as u128);
let rhs = FieldElement::from(rhs as u128);
let lhs = FieldElement::from(u128::from(lhs));
let rhs = FieldElement::from(u128::from(rhs));
let operators = ["constrain ==", "constrain !="];
test_operators(&operators, "u8", &[lhs,rhs]);
test_operators(&operators, "i8", &[lhs,rhs]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<
ctx.indirect_const_instruction(
current_revert_data_pointer,
64,
(error_selector.as_u64() as u128).into(),
u128::from(error_selector.as_u64()).into(),
);

ctx.codegen_usize_op_in_place(current_revert_data_pointer, BrilligBinaryOp::Add, 1);
Expand Down Expand Up @@ -286,7 +286,7 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<
self.indirect_const_instruction(
ReservedRegisters::free_memory_pointer(),
64,
(error_selector.as_u64() as u128).into(),
u128::from(error_selector.as_u64()).into(),
);
self.trap_instruction(HeapVector {
pointer: ReservedRegisters::free_memory_pointer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<

// The modulus is guaranteed to fit, since we are truncating down to a bit size that is strictly less than the value_to_truncate.bit_size
let modulus_var = self.make_constant_instruction(
F::from(2_usize).pow(&F::from(bit_size as u128)),
F::from(2_usize).pow(&F::from(u128::from(bit_size))),
value_to_truncate.bit_size,
);

Expand Down
Loading
Loading