From 56cef579943e7178c637e590c63c31912cfb4185 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Fri, 26 May 2023 11:46:11 +0100 Subject: [PATCH] add empty keccak var opcode --- src/barretenberg_structures.rs | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/barretenberg_structures.rs b/src/barretenberg_structures.rs index 64f575a2..9564a0ff 100644 --- a/src/barretenberg_structures.rs +++ b/src/barretenberg_structures.rs @@ -311,6 +311,36 @@ impl Keccak256Constraint { } } +#[derive(Clone, Hash, Debug, Serialize, Deserialize)] +pub(crate) struct Keccak256VarConstraint { + pub(crate) inputs: Vec<(i32, i32)>, + pub(crate) result: [i32; 32], + pub(crate) var_message_size: i32, +} + +impl Keccak256VarConstraint { + fn to_bytes(&self) -> Vec { + let mut buffer = Vec::new(); + + let inputs_len = self.inputs.len() as u32; + buffer.extend_from_slice(&inputs_len.to_be_bytes()); + for constraint in self.inputs.iter() { + buffer.extend_from_slice(&constraint.0.to_be_bytes()); + buffer.extend_from_slice(&constraint.1.to_be_bytes()); + } + + let result_len = self.result.len() as u32; + buffer.extend_from_slice(&result_len.to_be_bytes()); + for constraint in self.result.iter() { + buffer.extend_from_slice(&constraint.to_be_bytes()); + } + + buffer.extend_from_slice(&self.var_message_size.to_be_bytes()); + + buffer + } +} + #[derive(Clone, Hash, Debug, Serialize, Deserialize)] pub(crate) struct PedersenConstraint { pub(crate) inputs: Vec, @@ -408,6 +438,7 @@ pub(crate) struct ConstraintSystem { blake2s_constraints: Vec, block_constraints: Vec, keccak_constraints: Vec, + keccak_var_constraints: Vec, pedersen_constraints: Vec, hash_to_field_constraints: Vec, fixed_base_scalar_mul_constraints: Vec, @@ -584,6 +615,13 @@ impl ConstraintSystem { buffer.extend(&constraint.to_bytes()); } + // Serialize each Keccak Var constraint + let keccak_var_len = self.keccak_var_constraints.len() as u32; + buffer.extend_from_slice(&keccak_var_len.to_be_bytes()); + for constraint in self.keccak_var_constraints.iter() { + buffer.extend(&constraint.to_bytes()); + } + // Serialize each Pedersen constraint let pedersen_len = self.pedersen_constraints.len() as u32; buffer.extend_from_slice(&pedersen_len.to_be_bytes()); @@ -707,6 +745,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { let mut blake2s_constraints: Vec = Vec::new(); let mut block_constraints: Vec = Vec::new(); let mut keccak_constraints: Vec = Vec::new(); + let keccak_var_constraints: Vec = Vec::new(); let mut pedersen_constraints: Vec = Vec::new(); let mut schnorr_constraints: Vec = Vec::new(); let mut ecdsa_secp256k1_constraints: Vec = Vec::new(); @@ -1055,6 +1094,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { hash_to_field_constraints, constraints, fixed_base_scalar_mul_constraints, + keccak_var_constraints, }) } }