[Evaluator]
Refactor:
-  SHA256 to take an array instead of variadic arguments
- To also account for Polynomial now being named Object
- To swicth LowLevelStdLib to use acir opcodes instead
-use super::{GadgetCaller, LowLevelStandardLibrary, HashLibrary};
-use crate::{
- circuit::gate::{GadgetCall, GadgetInput},
- Array, CallExpression, Environment, Evaluator, Gate, Polynomial
-};
+use super::GadgetCaller;
+use acir::circuit::gate::{GadgetCall, GadgetInput, Gate};
+use acir::OPCODE;
+use crate::object::{Array, Object};
+use crate::{CallExpression, Environment, Evaluator};
+
pub struct Sha256Gadget {}
impl GadgetCaller for Sha256Gadget {
- fn name() -> LowLevelStandardLibrary {
- LowLevelStandardLibrary::Hash(HashLibrary::SHA256)
+ fn name() -> OPCODE {
+ OPCODE::SHA256
}
fn call(
evaluator: &mut Evaluator,
env: &mut Environment,
call_expr: CallExpression,
- ) -> Polynomial {
+ ) -> Object {
let inputs = Sha256Gadget::prepare_inputs(evaluator, env, call_expr);
// Create two fresh variables that will link to the SHA256 output
@@ -38,7 +39,7 @@ impl GadgetCaller for Sha256Gadget {
contents: vec![low_128_poly, high_128_poly],
};
- Polynomial::Array(arr)
+ Object::Array(arr)
}
}
@@ -48,13 +49,26 @@ impl Sha256Gadget {
env: &mut Environment,
call_expr: CallExpression,
) -> Vec<GadgetInput> {
- let mut inputs: Vec<GadgetInput> = Vec::with_capacity(call_expr.arguments.len());
- for arg_expr in call_expr.arguments.into_iter() {
- let arg_poly = evaluator.expression_to_polynomial(env, arg_expr);
- let (witness, num_bits) = match arg_poly {
- Polynomial::Integer(integer) => (integer.witness, integer.num_bits),
- Polynomial::Linear(lin) => {
+ // For sha256, we expect a single input which should be an array
+
+ let mut objects : Vec<_>= call_expr.arguments.into_iter().map(|expr|evaluator.expression_to_object(env, expr)).collect();
+ let obj = {
+ assert_eq!(objects.len(), 1);
+ objects.pop().unwrap()
+ };
+
+ let arr = match obj{
+ Object::Array(arr) => arr,
+ _=> panic!("Sha256 should only take a single parameter, which is an array. This should have been caught by the compiler in the analysis phase")
+ };
+
+ let mut inputs: Vec<GadgetInput> = Vec::with_capacity(0);
+
+ for element in arr.contents.into_iter() {
+ let (witness, num_bits) = match element {
+ Object::Integer(integer) => (integer.witness, integer.num_bits),
+ Object::Linear(lin) => {
if !lin.is_unit() {
unimplemented!(
"SHA256 Logic for non unit witnesses is currently not implemented"
