Skip to content

Commit 8e0e5ab

Browse files
authored
chore: remove unnecessary trait bounds (#7635)
1 parent a9de769 commit 8e0e5ab

File tree

8 files changed

+62
-77
lines changed

8 files changed

+62
-77
lines changed

acvm-repo/acir/src/circuit/opcodes.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,8 @@ pub enum Opcode<F: AcirField> {
134134
impl<F: AcirField> std::fmt::Display for Opcode<F> {
135135
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136136
match self {
137-
Opcode::AssertZero(expr) => {
138-
write!(f, "EXPR [ ")?;
139-
for i in &expr.mul_terms {
140-
write!(f, "({}, _{}, _{}) ", i.0, i.1.witness_index(), i.2.witness_index())?;
141-
}
142-
for i in &expr.linear_combinations {
143-
write!(f, "({}, _{}) ", i.0, i.1.witness_index())?;
144-
}
145-
write!(f, "{}", expr.q_c)?;
146-
147-
write!(f, " ]")
148-
}
149-
150-
Opcode::BlackBoxFuncCall(g) => write!(f, "{g}"),
137+
Opcode::AssertZero(expr) => expr.fmt(f),
138+
Opcode::BlackBoxFuncCall(g) => g.fmt(f),
151139
Opcode::MemoryOp { block_id, op, predicate } => {
152140
write!(f, "MEM ")?;
153141
if let Some(pred) = predicate {

acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs

+39-37
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<F: std::fmt::Display> std::fmt::Display for FunctionInput<F> {
8282
}
8383

8484
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
85-
pub enum BlackBoxFuncCall<F: AcirField> {
85+
pub enum BlackBoxFuncCall<F> {
8686
AES128Encrypt {
8787
inputs: Vec<FunctionInput<F>>,
8888
iv: Box<[FunctionInput<F>; 16]>,
@@ -216,7 +216,7 @@ pub enum BlackBoxFuncCall<F: AcirField> {
216216
},
217217
}
218218

219-
impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
219+
impl<F> BlackBoxFuncCall<F> {
220220
pub fn get_black_box_func(&self) -> BlackBoxFunc {
221221
match self {
222222
BlackBoxFuncCall::AES128Encrypt { .. } => BlackBoxFunc::AES128Encrypt,
@@ -246,6 +246,41 @@ impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
246246
self.get_black_box_func().name()
247247
}
248248

249+
pub fn get_outputs_vec(&self) -> Vec<Witness> {
250+
match self {
251+
BlackBoxFuncCall::Blake2s { outputs, .. }
252+
| BlackBoxFuncCall::Blake3 { outputs, .. } => outputs.to_vec(),
253+
254+
BlackBoxFuncCall::Keccakf1600 { outputs, .. } => outputs.to_vec(),
255+
256+
BlackBoxFuncCall::Sha256Compression { outputs, .. } => outputs.to_vec(),
257+
258+
BlackBoxFuncCall::AES128Encrypt { outputs, .. }
259+
| BlackBoxFuncCall::Poseidon2Permutation { outputs, .. } => outputs.to_vec(),
260+
261+
BlackBoxFuncCall::AND { output, .. }
262+
| BlackBoxFuncCall::XOR { output, .. }
263+
| BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
264+
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
265+
BlackBoxFuncCall::MultiScalarMul { outputs, .. }
266+
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => {
267+
vec![outputs.0, outputs.1, outputs.2]
268+
}
269+
BlackBoxFuncCall::RANGE { .. }
270+
| BlackBoxFuncCall::RecursiveAggregation { .. }
271+
| BlackBoxFuncCall::BigIntFromLeBytes { .. }
272+
| BlackBoxFuncCall::BigIntAdd { .. }
273+
| BlackBoxFuncCall::BigIntSub { .. }
274+
| BlackBoxFuncCall::BigIntMul { .. }
275+
| BlackBoxFuncCall::BigIntDiv { .. } => {
276+
vec![]
277+
}
278+
BlackBoxFuncCall::BigIntToLeBytes { outputs, .. } => outputs.to_vec(),
279+
}
280+
}
281+
}
282+
283+
impl<F: Copy> BlackBoxFuncCall<F> {
249284
pub fn get_inputs_vec(&self) -> Vec<FunctionInput<F>> {
250285
match self {
251286
BlackBoxFuncCall::AES128Encrypt { inputs, .. }
@@ -333,39 +368,6 @@ impl<F: Copy + AcirField> BlackBoxFuncCall<F> {
333368
}
334369
}
335370

336-
pub fn get_outputs_vec(&self) -> Vec<Witness> {
337-
match self {
338-
BlackBoxFuncCall::Blake2s { outputs, .. }
339-
| BlackBoxFuncCall::Blake3 { outputs, .. } => outputs.to_vec(),
340-
341-
BlackBoxFuncCall::Keccakf1600 { outputs, .. } => outputs.to_vec(),
342-
343-
BlackBoxFuncCall::Sha256Compression { outputs, .. } => outputs.to_vec(),
344-
345-
BlackBoxFuncCall::AES128Encrypt { outputs, .. }
346-
| BlackBoxFuncCall::Poseidon2Permutation { outputs, .. } => outputs.to_vec(),
347-
348-
BlackBoxFuncCall::AND { output, .. }
349-
| BlackBoxFuncCall::XOR { output, .. }
350-
| BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
351-
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
352-
BlackBoxFuncCall::MultiScalarMul { outputs, .. }
353-
| BlackBoxFuncCall::EmbeddedCurveAdd { outputs, .. } => {
354-
vec![outputs.0, outputs.1, outputs.2]
355-
}
356-
BlackBoxFuncCall::RANGE { .. }
357-
| BlackBoxFuncCall::RecursiveAggregation { .. }
358-
| BlackBoxFuncCall::BigIntFromLeBytes { .. }
359-
| BlackBoxFuncCall::BigIntAdd { .. }
360-
| BlackBoxFuncCall::BigIntSub { .. }
361-
| BlackBoxFuncCall::BigIntMul { .. }
362-
| BlackBoxFuncCall::BigIntDiv { .. } => {
363-
vec![]
364-
}
365-
BlackBoxFuncCall::BigIntToLeBytes { outputs, .. } => outputs.to_vec(),
366-
}
367-
}
368-
369371
pub fn get_input_witnesses(&self) -> BTreeSet<Witness> {
370372
let mut result = BTreeSet::new();
371373
for input in self.get_inputs_vec() {
@@ -429,7 +431,7 @@ fn get_outputs_string(outputs: &[Witness]) -> String {
429431
}
430432
}
431433

432-
impl<F: std::fmt::Display + Copy + AcirField> std::fmt::Display for BlackBoxFuncCall<F> {
434+
impl<F: std::fmt::Display + Copy> std::fmt::Display for BlackBoxFuncCall<F> {
433435
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
434436
let uppercase_name = self.name().to_uppercase();
435437
write!(f, "BLACKBOX::{uppercase_name} ")?;
@@ -454,7 +456,7 @@ impl<F: std::fmt::Display + Copy + AcirField> std::fmt::Display for BlackBoxFunc
454456
}
455457
}
456458

457-
impl<F: std::fmt::Display + Copy + AcirField> std::fmt::Debug for BlackBoxFuncCall<F> {
459+
impl<F: std::fmt::Display + Copy> std::fmt::Debug for BlackBoxFuncCall<F> {
458460
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
459461
std::fmt::Display::fmt(self, f)
460462
}

acvm-repo/acir/src/native_types/expression/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ impl<F: AcirField> Default for Expression<F> {
3333
}
3434
}
3535

36-
impl<F: AcirField> std::fmt::Display for Expression<F> {
36+
impl<F: std::fmt::Display> std::fmt::Display for Expression<F> {
3737
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
38-
if let Some(witness) = self.to_witness() {
39-
write!(f, "x{}", witness.witness_index())
40-
} else {
41-
write!(f, "%{:?}%", crate::circuit::opcodes::Opcode::AssertZero(self.clone()))
38+
write!(f, "EXPR [ ")?;
39+
for i in &self.mul_terms {
40+
write!(f, "({}, _{}, _{}) ", i.0, i.1.witness_index(), i.2.witness_index())?;
4241
}
42+
for i in &self.linear_combinations {
43+
write!(f, "({}, _{}) ", i.0, i.1.witness_index())?;
44+
}
45+
write!(f, "{}", self.q_c)?;
46+
47+
write!(f, " ]")
4348
}
4449
}
4550

acvm-repo/acir/src/native_types/witness_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ impl<F> From<BTreeMap<Witness, F>> for WitnessMap<F> {
8484
}
8585
}
8686

87-
impl<F: Serialize + AcirField> WitnessMap<F> {
87+
impl<F: Serialize> WitnessMap<F> {
8888
pub(crate) fn bincode_serialize(&self) -> Result<Vec<u8>, WitnessMapError> {
8989
bincode::serialize(self).map_err(|e| SerializationError::Deserialize(e.to_string()).into())
9090
}
9191
}
9292

93-
impl<F: AcirField + for<'a> Deserialize<'a>> WitnessMap<F> {
93+
impl<F: for<'a> Deserialize<'a>> WitnessMap<F> {
9494
pub(crate) fn bincode_deserialize(buf: &[u8]) -> Result<Self, WitnessMapError> {
9595
bincode::deserialize(buf).map_err(|e| SerializationError::Deserialize(e.to_string()).into())
9696
}
@@ -120,7 +120,7 @@ impl<F: Serialize + AcirField> TryFrom<WitnessMap<F>> for Vec<u8> {
120120
}
121121
}
122122

123-
impl<F: AcirField + for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessMap<F> {
123+
impl<F: for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessMap<F> {
124124
type Error = WitnessMapError;
125125

126126
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {

acvm-repo/acir/src/native_types/witness_stack.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ impl<F> From<WitnessMap<F>> for WitnessStack<F> {
7070
}
7171
}
7272

73-
impl<F: Serialize + AcirField> WitnessStack<F> {
73+
impl<F: Serialize> WitnessStack<F> {
7474
pub(crate) fn bincode_serialize(&self) -> Result<Vec<u8>, WitnessStackError> {
7575
bincode::serialize(self).map_err(|e| WitnessStackError(e.into()))
7676
}
7777
}
7878

79-
impl<F: AcirField + for<'a> Deserialize<'a>> WitnessStack<F> {
79+
impl<F: for<'a> Deserialize<'a>> WitnessStack<F> {
8080
pub(crate) fn bincode_deserialize(buf: &[u8]) -> Result<Self, WitnessStackError> {
8181
bincode::deserialize(buf).map_err(|e| WitnessStackError(e.into()))
8282
}
@@ -114,7 +114,7 @@ impl<F: Serialize + AcirField> TryFrom<WitnessStack<F>> for Vec<u8> {
114114
}
115115
}
116116

117-
impl<F: AcirField + for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessStack<F> {
117+
impl<F: for<'a> Deserialize<'a>> TryFrom<&[u8]> for WitnessStack<F> {
118118
type Error = WitnessStackError;
119119

120120
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {

acvm-repo/acir/src/proto/convert/acir.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ use noir_protobuf::{ProtoCodec, decode_oneof_map};
1616

1717
use super::ProtoSchema;
1818

19-
impl<F> ProtoCodec<circuit::Circuit<F>, Circuit> for ProtoSchema<F>
20-
where
21-
F: AcirField,
22-
{
19+
impl<F: AcirField> ProtoCodec<circuit::Circuit<F>, Circuit> for ProtoSchema<F> {
2320
fn encode(value: &circuit::Circuit<F>) -> Circuit {
2421
Circuit {
2522
current_witness_index: value.current_witness_index,

acvm-repo/acir/src/proto/convert/brillig.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ use crate::proto::brillig::{
1313

1414
use super::ProtoSchema;
1515

16-
impl<F> ProtoCodec<circuit::brillig::BrilligBytecode<F>, BrilligBytecode> for ProtoSchema<F>
17-
where
18-
F: AcirField,
16+
impl<F: AcirField> ProtoCodec<circuit::brillig::BrilligBytecode<F>, BrilligBytecode>
17+
for ProtoSchema<F>
1918
{
2019
fn encode(value: &circuit::brillig::BrilligBytecode<F>) -> BrilligBytecode {
2120
BrilligBytecode { bytecode: Self::encode_vec(&value.bytecode) }
@@ -28,10 +27,7 @@ where
2827
}
2928
}
3029

31-
impl<F> ProtoCodec<brillig::Opcode<F>, BrilligOpcode> for ProtoSchema<F>
32-
where
33-
F: AcirField,
34-
{
30+
impl<F: AcirField> ProtoCodec<brillig::Opcode<F>, BrilligOpcode> for ProtoSchema<F> {
3531
fn encode(value: &brillig::Opcode<F>) -> BrilligOpcode {
3632
use brillig_opcode::*;
3733

acvm-repo/acir/src/proto/convert/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ pub(crate) struct ProtoSchema<F> {
1616
field: PhantomData<F>,
1717
}
1818

19-
impl<F> ProtoCodec<circuit::Program<F>, Program> for ProtoSchema<F>
20-
where
21-
F: AcirField,
22-
{
19+
impl<F: AcirField> ProtoCodec<circuit::Program<F>, Program> for ProtoSchema<F> {
2320
fn encode(value: &circuit::Program<F>) -> Program {
2421
Program {
2522
functions: Self::encode_vec(&value.functions),

0 commit comments

Comments
 (0)