diff --git a/changelogs/unreleased/772-dark64 b/changelogs/unreleased/772-dark64 new file mode 100644 index 00000000..31cb80ac --- /dev/null +++ b/changelogs/unreleased/772-dark64 @@ -0,0 +1 @@ +Introduce u64 type, add keccak{256,384,512} and sha3{256,384,512} hash functions to stdlib \ No newline at end of file diff --git a/zokrates_abi/src/lib.rs b/zokrates_abi/src/lib.rs index 0cbc02c1..e2e4a8a0 100644 --- a/zokrates_abi/src/lib.rs +++ b/zokrates_abi/src/lib.rs @@ -45,6 +45,7 @@ enum Value { U8(u8), U16(u16), U32(u32), + U64(u64), Field(T), Boolean(bool), Array(Vec>), @@ -56,6 +57,7 @@ enum CheckedValue { U8(u8), U16(u16), U32(u32), + U64(u64), Field(T), Boolean(bool), Array(Vec>), @@ -72,6 +74,7 @@ impl fmt::Display for Value { Value::U8(v) => write!(f, "{:#04x}", v), Value::U16(v) => write!(f, "{:#06x}", v), Value::U32(v) => write!(f, "{:#010x}", v), + Value::U64(v) => write!(f, "{:#018x}", v), Value::Boolean(v) => write!(f, "{}", v), Value::Array(v) => write!( f, @@ -100,6 +103,7 @@ impl Value { (Value::U8(f), ConcreteType::Uint(UBitwidth::B8)) => Ok(CheckedValue::U8(f)), (Value::U16(f), ConcreteType::Uint(UBitwidth::B16)) => Ok(CheckedValue::U16(f)), (Value::U32(f), ConcreteType::Uint(UBitwidth::B32)) => Ok(CheckedValue::U32(f)), + (Value::U64(f), ConcreteType::Uint(UBitwidth::B64)) => Ok(CheckedValue::U64(f)), (Value::Boolean(b), ConcreteType::Boolean) => Ok(CheckedValue::Boolean(b)), (Value::Array(a), ConcreteType::Array(array_type)) => { let size = array_type.size; @@ -162,6 +166,7 @@ impl> Encode for CheckedValue { CheckedValue::U8(t) => vec![T::from(t as usize)], CheckedValue::U16(t) => vec![T::from(t as usize)], CheckedValue::U32(t) => vec![T::from(t as usize)], + CheckedValue::U64(t) => vec![T::from(t as usize)], CheckedValue::Boolean(b) => vec![if b { 1.into() } else { 0.into() }], CheckedValue::Array(a) => a.into_iter().flat_map(|v| v.encode()).collect(), CheckedValue::Struct(s) => s.into_iter().flat_map(|(_, v)| v.encode()).collect(), @@ -205,6 +210,9 @@ impl Decode for CheckedValue { ConcreteType::Uint(UBitwidth::B32) => { CheckedValue::U32(raw.pop().unwrap().to_dec_string().parse().unwrap()) } + ConcreteType::Uint(UBitwidth::B64) => { + CheckedValue::U64(raw.pop().unwrap().to_dec_string().parse().unwrap()) + } ConcreteType::Boolean => { let v = raw.pop().unwrap(); CheckedValue::Boolean(if v == 0.into() { @@ -276,6 +284,9 @@ impl TryFrom for Value { 10 => u32::from_str_radix(&s[2..], 16) .map(Value::U32) .map_err(|_| format!("Expected u32 value, found {}", s)), + 18 => u64::from_str_radix(&s[2..], 16) + .map(Value::U64) + .map_err(|_| format!("Expected u64 value, found {}", s)), _ => Err(format!("Cannot parse {} to any type", s)), }) } @@ -306,6 +317,7 @@ impl CheckedValue { CheckedValue::U8(u) => serde_json::Value::String(format!("{:#04x}", u)), CheckedValue::U16(u) => serde_json::Value::String(format!("{:#06x}", u)), CheckedValue::U32(u) => serde_json::Value::String(format!("{:#010x}", u)), + CheckedValue::U64(u) => serde_json::Value::String(format!("{:#018x}", u)), CheckedValue::Boolean(b) => serde_json::Value::Bool(b), CheckedValue::Array(a) => { serde_json::Value::Array(a.into_iter().map(|e| e.into_serde_json()).collect()) diff --git a/zokrates_book/src/language/types.md b/zokrates_book/src/language/types.md index 78d12125..573d5b77 100644 --- a/zokrates_book/src/language/types.md +++ b/zokrates_book/src/language/types.md @@ -22,7 +22,7 @@ Note that for field elements, the division operation multiplies the numerator wi Booleans are available in ZoKrates. When a boolean is used as a parameter of the main function, the program is constrained to only accept `0` or `1` for that parameter. A boolean can be asserted to be true using an `assert(bool)` statement. -### `u8/u16/u32` +### `u8/u16/u32/u64` Unsigned integers represent positive numbers of the interval `[0, 2 ** bitwidth[`, where `bitwidth` is specified in the type's name, e.g., 32 bits in the case of u32. Their arithmetics are defined modulo `2 ** bitwidth`. @@ -34,9 +34,9 @@ The division operation calculates the standard floor division for integers. The ### Numeric inference -In the case of decimal literals like `42`, the compiler tries to find the appropriate type (`field`, `u8`, `u16` or `u32`) depending on the context. If it cannot converge to a single option, an error is returned. This means that there is no default type for decimal literals. +In the case of decimal literals like `42`, the compiler tries to find the appropriate type (`field`, `u8`, `u16`, `u32` or `u64`) depending on the context. If it cannot converge to a single option, an error is returned. This means that there is no default type for decimal literals. -All operations between literals have the semantics of the infered type. +All operations between literals have the semantics of the inferred type. ```zokrates {{#include ../../../zokrates_cli/examples/book/numeric_inference.zok}} diff --git a/zokrates_core/src/absy/from_ast.rs b/zokrates_core/src/absy/from_ast.rs index 1fa7b779..ccf3a55b 100644 --- a/zokrates_core/src/absy/from_ast.rs +++ b/zokrates_core/src/absy/from_ast.rs @@ -583,6 +583,9 @@ impl<'ast> From> for absy::ExpressionNode<' pest::DecimalSuffix::Field(_) => absy::Expression::FieldConstant( BigUint::parse_bytes(&expression.value.span.as_str().as_bytes(), 10).unwrap(), ), + pest::DecimalSuffix::U64(_) => { + absy::Expression::U64Constant(expression.value.span.as_str().parse().unwrap()) + } pest::DecimalSuffix::U32(_) => { absy::Expression::U32Constant(expression.value.span.as_str().parse().unwrap()) } @@ -607,6 +610,9 @@ impl<'ast> From> for absy::ExpressionNode<'ast> use crate::absy::NodeValue; match expression.value { + pest::HexNumberExpression::U64(e) => { + absy::Expression::U64Constant(u64::from_str_radix(&e.span.as_str(), 16).unwrap()) + } pest::HexNumberExpression::U32(e) => { absy::Expression::U32Constant(u32::from_str_radix(&e.span.as_str(), 16).unwrap()) } @@ -683,6 +689,7 @@ impl<'ast> From> for absy::UnresolvedTypeNode<'ast> { pest::BasicType::U8(t) => UnresolvedType::Uint(8).span(t.span), pest::BasicType::U16(t) => UnresolvedType::Uint(16).span(t.span), pest::BasicType::U32(t) => UnresolvedType::Uint(32).span(t.span), + pest::BasicType::U64(t) => UnresolvedType::Uint(64).span(t.span), }, pest::Type::Array(t) => { let inner_type = match t.ty { @@ -692,6 +699,7 @@ impl<'ast> From> for absy::UnresolvedTypeNode<'ast> { pest::BasicType::U8(t) => UnresolvedType::Uint(8).span(t.span), pest::BasicType::U16(t) => UnresolvedType::Uint(16).span(t.span), pest::BasicType::U32(t) => UnresolvedType::Uint(32).span(t.span), + pest::BasicType::U64(t) => UnresolvedType::Uint(64).span(t.span), }, pest::BasicOrStructType::Struct(t) => { UnresolvedType::User(t.span.as_str().to_string()).span(t.span) diff --git a/zokrates_core/src/absy/mod.rs b/zokrates_core/src/absy/mod.rs index e6921d95..0eccc134 100644 --- a/zokrates_core/src/absy/mod.rs +++ b/zokrates_core/src/absy/mod.rs @@ -495,6 +495,7 @@ pub enum Expression<'ast> { U8Constant(u8), U16Constant(u16), U32Constant(u32), + U64Constant(u64), Identifier(Identifier<'ast>), Add(Box>, Box>), Sub(Box>, Box>), @@ -543,6 +544,7 @@ impl<'ast> fmt::Display for Expression<'ast> { Expression::U8Constant(ref i) => write!(f, "{}", i), Expression::U16Constant(ref i) => write!(f, "{}", i), Expression::U32Constant(ref i) => write!(f, "{}", i), + Expression::U64Constant(ref i) => write!(f, "{}", i), Expression::IntConstant(ref i) => write!(f, "{}", i), Expression::Identifier(ref var) => write!(f, "{}", var), Expression::Add(ref lhs, ref rhs) => write!(f, "({} + {})", lhs, rhs), @@ -628,6 +630,7 @@ impl<'ast> fmt::Debug for Expression<'ast> { Expression::U8Constant(ref i) => write!(f, "U8({:x})", i), Expression::U16Constant(ref i) => write!(f, "U16({:x})", i), Expression::U32Constant(ref i) => write!(f, "U32({:x})", i), + Expression::U64Constant(ref i) => write!(f, "U64({:x})", i), Expression::FieldConstant(ref i) => write!(f, "Field({:?})", i), Expression::IntConstant(ref i) => write!(f, "Int({:?})", i), Expression::Identifier(ref var) => write!(f, "Ide({})", var), diff --git a/zokrates_core/src/embed.rs b/zokrates_core/src/embed.rs index 3decfdf0..e1b0326d 100644 --- a/zokrates_core/src/embed.rs +++ b/zokrates_core/src/embed.rs @@ -29,9 +29,11 @@ pub enum FlatEmbed { U8ToBits, U16ToBits, U32ToBits, + U64ToBits, U8FromBits, U16FromBits, U32FromBits, + U64FromBits, } impl FlatEmbed { @@ -65,6 +67,12 @@ impl FlatEmbed { DeclarationType::Boolean, 32usize, ))]), + FlatEmbed::U64ToBits => DeclarationSignature::new() + .inputs(vec![DeclarationType::uint(64)]) + .outputs(vec![DeclarationType::array(( + DeclarationType::Boolean, + 64usize, + ))]), FlatEmbed::U8FromBits => DeclarationSignature::new() .outputs(vec![DeclarationType::uint(8)]) .inputs(vec![DeclarationType::array(( @@ -83,6 +91,12 @@ impl FlatEmbed { DeclarationType::Boolean, 32usize, ))]), + FlatEmbed::U64FromBits => DeclarationSignature::new() + .outputs(vec![DeclarationType::uint(64)]) + .inputs(vec![DeclarationType::array(( + DeclarationType::Boolean, + 64usize, + ))]), #[cfg(feature = "bellman")] FlatEmbed::Sha256Round => DeclarationSignature::new() .inputs(vec![ @@ -120,9 +134,11 @@ impl FlatEmbed { FlatEmbed::U8ToBits => "_U8_TO_BITS", FlatEmbed::U16ToBits => "_U16_TO_BITS", FlatEmbed::U32ToBits => "_U32_TO_BITS", + FlatEmbed::U64ToBits => "_U64_TO_BITS", FlatEmbed::U8FromBits => "_U8_FROM_BITS", FlatEmbed::U16FromBits => "_U16_FROM_BITS", FlatEmbed::U32FromBits => "_U32_FROM_BITS", + FlatEmbed::U64FromBits => "_U64_FROM_BITS", } } diff --git a/zokrates_core/src/flatten/mod.rs b/zokrates_core/src/flatten/mod.rs index fbec3419..61c287aa 100644 --- a/zokrates_core/src/flatten/mod.rs +++ b/zokrates_core/src/flatten/mod.rs @@ -857,6 +857,11 @@ impl<'ast, T: Field> Flattener<'ast, T> { param_expressions: Vec>, ) -> Vec> { match embed { + crate::embed::FlatEmbed::U64ToBits => self.flatten_u_to_bits( + statements_flattened, + param_expressions[0].clone(), + 64.into(), + ), crate::embed::FlatEmbed::U32ToBits => self.flatten_u_to_bits( statements_flattened, param_expressions[0].clone(), @@ -870,6 +875,9 @@ impl<'ast, T: Field> Flattener<'ast, T> { crate::embed::FlatEmbed::U8ToBits => { self.flatten_u_to_bits(statements_flattened, param_expressions[0].clone(), 8.into()) } + crate::embed::FlatEmbed::U64FromBits => { + vec![self.flatten_bits_to_u(statements_flattened, param_expressions, 64.into())] + } crate::embed::FlatEmbed::U32FromBits => { vec![self.flatten_bits_to_u(statements_flattened, param_expressions, 32.into())] } @@ -1125,7 +1133,7 @@ impl<'ast, T: Field> Flattener<'ast, T> { let _ = self.get_bits( FlatUExpression::with_field(FlatExpression::Add( box FlatExpression::Sub(box r.into(), box d.clone()), - box FlatExpression::Number(T::from(2usize.pow(target_bitwidth.to_usize() as u32))), + box FlatExpression::Number(T::from(2_u128.pow(target_bitwidth.to_usize() as u32))), )), target_bitwidth.to_usize(), target_bitwidth, @@ -2077,7 +2085,8 @@ impl<'ast, T: Field> Flattener<'ast, T> { .collect(); match embed { - FlatEmbed::U32FromBits + FlatEmbed::U64FromBits + | FlatEmbed::U32FromBits | FlatEmbed::U16FromBits | FlatEmbed::U8FromBits => { let bits = exprs diff --git a/zokrates_core/src/imports.rs b/zokrates_core/src/imports.rs index 55aed8ce..0794645c 100644 --- a/zokrates_core/src/imports.rs +++ b/zokrates_core/src/imports.rs @@ -179,6 +179,17 @@ impl Importer { .start_end(pos.0, pos.1), ); } + "EMBED/u64_to_bits" => { + let alias = alias.unwrap_or("u64_to_bits"); + + symbols.push( + SymbolDeclaration { + id: &alias, + symbol: Symbol::Flat(FlatEmbed::U64ToBits), + } + .start_end(pos.0, pos.1), + ); + } "EMBED/u32_to_bits" => { let alias = alias.unwrap_or("u32_to_bits"); @@ -212,6 +223,17 @@ impl Importer { .start_end(pos.0, pos.1), ); } + "EMBED/u64_from_bits" => { + let alias = alias.unwrap_or("u64_from_bits"); + + symbols.push( + SymbolDeclaration { + id: &alias, + symbol: Symbol::Flat(FlatEmbed::U64FromBits), + } + .start_end(pos.0, pos.1), + ); + } "EMBED/u32_from_bits" => { let alias = alias.unwrap_or("u32_from_bits"); diff --git a/zokrates_core/src/semantics.rs b/zokrates_core/src/semantics.rs index 08855172..3bd4f160 100644 --- a/zokrates_core/src/semantics.rs +++ b/zokrates_core/src/semantics.rs @@ -1840,6 +1840,7 @@ impl<'ast, T: Field> Checker<'ast, T> { Expression::U8Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(8).into()), Expression::U16Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(16).into()), Expression::U32Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(32).into()), + Expression::U64Constant(n) => Ok(UExpressionInner::Value(n.into()).annotate(64).into()), Expression::FunctionCall(fun_id, generics, arguments) => { // check the generic arguments, if any let generics_checked: Option>>> = generics diff --git a/zokrates_core/src/static_analysis/propagation.rs b/zokrates_core/src/static_analysis/propagation.rs index 92970cff..fb32bdd7 100644 --- a/zokrates_core/src/static_analysis/propagation.rs +++ b/zokrates_core/src/static_analysis/propagation.rs @@ -438,6 +438,11 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { true => { let r: Option> = match embed { FlatEmbed::U32ToField => None, // todo + FlatEmbed::U64FromBits => Some(process_u_from_bits( + assignees.clone(), + arguments.clone(), + UBitwidth::B64, + )), FlatEmbed::U32FromBits => Some(process_u_from_bits( assignees.clone(), arguments.clone(), @@ -453,6 +458,11 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Propagator<'ast, 'a, T> { arguments.clone(), UBitwidth::B8, )), + FlatEmbed::U64ToBits => Some(process_u_to_bits( + assignees.clone(), + arguments.clone(), + UBitwidth::B64, + )), FlatEmbed::U32ToBits => Some(process_u_to_bits( assignees.clone(), arguments.clone(), diff --git a/zokrates_core/src/static_analysis/uint_optimizer.rs b/zokrates_core/src/static_analysis/uint_optimizer.rs index aad636ac..10296a20 100644 --- a/zokrates_core/src/static_analysis/uint_optimizer.rs +++ b/zokrates_core/src/static_analysis/uint_optimizer.rs @@ -117,7 +117,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { let range = e.bitwidth.to_usize(); - let range_max: T = (2_usize.pow(range as u32) - 1).into(); + let range_max: T = (2_u128.pow(range as u32) - 1).into(); assert!(range < max_bitwidth / 2); @@ -319,7 +319,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { let e = self.fold_uint_expression(e); let by = self.fold_uint_expression(by); - let by_max: usize = by + let by_max: u128 = by .metadata .clone() .unwrap() @@ -327,7 +327,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { .to_dec_string() .parse() .unwrap(); - let e_max: usize = e + let e_max: u128 = e .metadata .clone() .unwrap() @@ -336,7 +336,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { .parse() .unwrap(); - let max = T::from((e_max << by_max) & (2_usize.pow(range as u32) - 1)); + let max = T::from((e_max << by_max) & (2_u128.pow(range as u32) - 1)); UExpression::left_shift(force_reduce(e), force_reduce(by)).with_max(max) } @@ -351,7 +351,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { _ => 0, }; - let e_max: usize = e + let e_max: u128 = e .metadata .clone() .unwrap() @@ -360,7 +360,7 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { .parse() .unwrap(); - let max = (e_max & (2_usize.pow(range as u32) - 1)) >> by_u; + let max = (e_max & (2_u128.pow(range as u32) - 1)) >> by_u; let max = T::from(max); @@ -423,6 +423,21 @@ impl<'ast, T: Field> Folder<'ast, T> for UintOptimizer<'ast, T> { )], ZirStatement::MultipleDefinition(lhs, rhs) => match rhs { ZirExpressionList::EmbedCall(embed, generics, arguments) => match embed { + FlatEmbed::U64FromBits => { + assert_eq!(lhs.len(), 1); + self.register( + lhs[0].clone(), + UMetadata { + max: T::from(2).pow(64) - T::from(1), + should_reduce: ShouldReduce::False, + }, + ); + + vec![ZirStatement::MultipleDefinition( + lhs, + ZirExpressionList::EmbedCall(embed, generics, arguments), + )] + } FlatEmbed::U32FromBits => { assert_eq!(lhs.len(), 1); self.register( diff --git a/zokrates_core/src/typed_absy/types.rs b/zokrates_core/src/typed_absy/types.rs index 12ada63a..6622bddd 100644 --- a/zokrates_core/src/typed_absy/types.rs +++ b/zokrates_core/src/typed_absy/types.rs @@ -387,6 +387,8 @@ pub enum UBitwidth { B16 = 16, #[serde(rename = "32")] B32 = 32, + #[serde(rename = "64")] + B64 = 64, } impl UBitwidth { @@ -401,6 +403,7 @@ impl From for UBitwidth { 8 => UBitwidth::B8, 16 => UBitwidth::B16, 32 => UBitwidth::B32, + 64 => UBitwidth::B64, _ => unreachable!(), } } @@ -512,6 +515,7 @@ impl<'de, S: Deserialize<'de>> Deserialize<'de> for GType { "u8" => strict_type(mapping, GType::Uint(UBitwidth::B8)), "u16" => strict_type(mapping, GType::Uint(UBitwidth::B16)), "u32" => strict_type(mapping, GType::Uint(UBitwidth::B32)), + "u64" => strict_type(mapping, GType::Uint(UBitwidth::B64)), t => Err(D::Error::custom(format!("invalid type `{}`", t))), } } diff --git a/zokrates_core/src/zir/types.rs b/zokrates_core/src/zir/types.rs index 48626022..de0142d3 100644 --- a/zokrates_core/src/zir/types.rs +++ b/zokrates_core/src/zir/types.rs @@ -18,6 +18,8 @@ pub enum UBitwidth { B16 = 16, #[serde(rename = "32")] B32 = 32, + #[serde(rename = "64")] + B64 = 64, } impl UBitwidth { @@ -26,6 +28,7 @@ impl UBitwidth { UBitwidth::B8 => 8, UBitwidth::B16 => 16, UBitwidth::B32 => 32, + UBitwidth::B64 => 64, } } } @@ -36,6 +39,7 @@ impl From for UBitwidth { 8 => UBitwidth::B8, 16 => UBitwidth::B16, 32 => UBitwidth::B32, + 64 => UBitwidth::B64, _ => unreachable!(), } } diff --git a/zokrates_core_test/tests/tests/uint/add.json b/zokrates_core_test/tests/tests/uint/add.json deleted file mode 100644 index e42dc1d6..00000000 --- a/zokrates_core_test/tests/tests/uint/add.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/add.zok", - "max_constraint_count": 29, - "tests": [ - { - "input": { - "values": ["0xff", "0x01"] - }, - "output": { - "Ok": { - "values": ["0x00"] - } - } - }, - { - "input": { - "values": ["0x00", "0x01"] - }, - "output": { - "Ok": { - "values": ["0x01"] - } - } - }, - { - "input": { - "values": ["0xff", "0xff"] - }, - "output": { - "Ok": { - "values": ["0xfe"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/and.json b/zokrates_core_test/tests/tests/uint/and.json deleted file mode 100644 index 19217cd1..00000000 --- a/zokrates_core_test/tests/tests/uint/and.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/and.zok", - "max_constraint_count": 27, - "tests": [ - { - "input": { - "values": ["0xff", "0xff"] - }, - "output": { - "Ok": { - "values": ["0xff"] - } - } - }, - { - "input": { - "values": ["0xff", "0x00"] - }, - "output": { - "Ok": { - "values": ["0x00"] - } - } - }, - { - "input": { - "values": ["0x23", "0x34"] - }, - "output": { - "Ok": { - "values": ["0x20"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/div.json b/zokrates_core_test/tests/tests/uint/div.json deleted file mode 100644 index 91f0ce15..00000000 --- a/zokrates_core_test/tests/tests/uint/div.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/div.zok", - "max_constraint_count": 43, - "tests": [ - { - "input": { - "values": ["255", "1"] - }, - "output": { - "Ok": { - "values": ["255"] - } - } - }, - { - "input": { - "values": ["42", "10"] - }, - "output": { - "Ok": { - "values": ["4"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/div.zok b/zokrates_core_test/tests/tests/uint/div.zok deleted file mode 100644 index 730ce4b2..00000000 --- a/zokrates_core_test/tests/tests/uint/div.zok +++ /dev/null @@ -1,6 +0,0 @@ -def main(u8 x, u8 y) -> u8: - assert(0x02 / 0x02 == 0x01) - assert(0x04 / 0x02 == 0x02) - assert(0x05 / 0x02 == 0x02) - assert(0xff / 0x03 == 0x55) - return x / y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/div_rem.json b/zokrates_core_test/tests/tests/uint/div_rem.json deleted file mode 100644 index c01879bb..00000000 --- a/zokrates_core_test/tests/tests/uint/div_rem.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/div_rem.zok", - "max_constraint_count": 43, - "tests": [ - { - "input": { - "values": ["255", "1"] - }, - "output": { - "Ok": { - "values": ["255", "0"] - } - } - }, - { - "input": { - "values": ["42", "10"] - }, - "output": { - "Ok": { - "values": ["4", "2"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/div_rem.zok b/zokrates_core_test/tests/tests/uint/div_rem.zok deleted file mode 100644 index 73f5f16f..00000000 --- a/zokrates_core_test/tests/tests/uint/div_rem.zok +++ /dev/null @@ -1,2 +0,0 @@ -def main(u8 n, u8 d) -> (u8, u8): - return n / d, n % d \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/from_to_bits.json b/zokrates_core_test/tests/tests/uint/from_to_bits.json index e086d206..13b55420 100644 --- a/zokrates_core_test/tests/tests/uint/from_to_bits.json +++ b/zokrates_core_test/tests/tests/uint/from_to_bits.json @@ -1,34 +1,34 @@ { "entry_point": "./tests/tests/uint/from_to_bits.zok", - "max_constraint_count": 34, + "max_constraint_count": 128, "tests": [ { "input": { - "values": ["0x00000000", "0x0000", "0x00"] + "values": ["0x0000000000000000", "0x00000000", "0x0000", "0x00"] }, "output": { "Ok": { - "values": ["0x00000000", "0x0000", "0x00"] + "values": ["0x0000000000000000", "0x00000000", "0x0000", "0x00"] } } }, { "input": { - "values": ["0xffffffff", "0xffff", "0xff"] + "values": ["0xffffffffffffffff", "0xffffffff", "0xffff", "0xff"] }, "output": { "Ok": { - "values": ["0xffffffff", "0xffff", "0xff"] + "values": ["0xffffffffffffffff", "0xffffffff", "0xffff", "0xff"] } } }, { "input": { - "values": ["0x12345678", "0x1234", "0x12"] + "values": ["0x1234567812345678", "0x12345678", "0x1234", "0x12"] }, "output": { "Ok": { - "values": ["0x12345678", "0x1234", "0x12"] + "values": ["0x1234567812345678", "0x12345678", "0x1234", "0x12"] } } } diff --git a/zokrates_core_test/tests/tests/uint/from_to_bits.zok b/zokrates_core_test/tests/tests/uint/from_to_bits.zok index 6bb7b804..b3b52ccc 100644 --- a/zokrates_core_test/tests/tests/uint/from_to_bits.zok +++ b/zokrates_core_test/tests/tests/uint/from_to_bits.zok @@ -1,3 +1,5 @@ +import "EMBED/u64_to_bits" as to_bits_64 +import "EMBED/u64_from_bits" as from_bits_64 import "EMBED/u32_to_bits" as to_bits_32 import "EMBED/u32_from_bits" as from_bits_32 import "EMBED/u16_to_bits" as to_bits_16 @@ -5,8 +7,9 @@ import "EMBED/u16_from_bits" as from_bits_16 import "EMBED/u8_to_bits" as to_bits_8 import "EMBED/u8_from_bits" as from_bits_8 -def main(u32 e, u16 f, u8 g) -> (u32, u16, u8): +def main(u64 d, u32 e, u16 f, u8 g) -> (u64, u32, u16, u8): + bool[64] d_bits = to_bits_64(d) bool[32] e_bits = to_bits_32(e) bool[16] f_bits = to_bits_16(f) bool[8] g_bits = to_bits_8(g) - return from_bits_32(e_bits), from_bits_16(f_bits), from_bits_8(g_bits) \ No newline at end of file + return from_bits_64(d_bits), from_bits_32(e_bits), from_bits_16(f_bits), from_bits_8(g_bits) \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/mul.json b/zokrates_core_test/tests/tests/uint/mul.json deleted file mode 100644 index 628b71ae..00000000 --- a/zokrates_core_test/tests/tests/uint/mul.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/mul.zok", - "max_constraint_count": 37, - "tests": [ - { - "input": { - "values": ["2", "2"] - }, - "output": { - "Ok": { - "values": ["4"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/or.json b/zokrates_core_test/tests/tests/uint/or.json deleted file mode 100644 index 28273855..00000000 --- a/zokrates_core_test/tests/tests/uint/or.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/or.zok", - "max_constraint_count": 27, - "tests": [ - { - "input": { - "values": ["0xff", "0xff"] - }, - "output": { - "Ok": { - "values": ["0xff"] - } - } - }, - { - "input": { - "values": ["0xff", "0x00"] - }, - "output": { - "Ok": { - "values": ["0xff"] - } - } - }, - { - "input": { - "values": ["0x23", "0x34"] - }, - "output": { - "Ok": { - "values": ["0x37"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/rem.json b/zokrates_core_test/tests/tests/uint/rem.json deleted file mode 100644 index a8a9e7ac..00000000 --- a/zokrates_core_test/tests/tests/uint/rem.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/rem.zok", - "max_constraint_count": 43, - "tests": [ - { - "input": { - "values": ["255", "1"] - }, - "output": { - "Ok": { - "values": ["0"] - } - } - }, - { - "input": { - "values": ["42", "10"] - }, - "output": { - "Ok": { - "values": ["2"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/rem.zok b/zokrates_core_test/tests/tests/uint/rem.zok deleted file mode 100644 index c72401dc..00000000 --- a/zokrates_core_test/tests/tests/uint/rem.zok +++ /dev/null @@ -1,7 +0,0 @@ -def main(u8 x, u8 y) -> u8: - assert(0x02 % 0x02 == 0x00) - assert(0x04 % 0x02 == 0x00) - assert(0x05 % 0x02 == 0x01) - assert(0xff % 0x03 == 0x00) - assert(0xff % 0x01 == 0x00) - return x % y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/shift.json b/zokrates_core_test/tests/tests/uint/shift.json deleted file mode 100644 index 654da115..00000000 --- a/zokrates_core_test/tests/tests/uint/shift.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/shift.zok", - "max_constraint_count": 34, - "tests": [ - { - "input": { - "values": ["0x12345678"] - }, - "output": { - "Ok": { - "values": ["0x01234567"] - } - } - }, - { - "input": { - "values": ["0x01234567"] - }, - "output": { - "Ok": { - "values": ["0x00123456"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/add.json b/zokrates_core_test/tests/tests/uint/u16/add.json new file mode 100644 index 00000000..9cf286be --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/add.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/add.zok", + "max_constraint_count": 53, + "tests": [ + { + "input": { + "values": ["0xffff", "0x0001"] + }, + "output": { + "Ok": { + "values": ["0x0000"] + } + } + }, + { + "input": { + "values": ["0x1000", "0x1000"] + }, + "output": { + "Ok": { + "values": ["0x2000"] + } + } + }, + { + "input": { + "values": ["0xffff", "0xffff"] + }, + "output": { + "Ok": { + "values": ["0xfffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/add.zok b/zokrates_core_test/tests/tests/uint/u16/add.zok new file mode 100644 index 00000000..9cc1c17c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/add.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> u16: + return a + b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/and.json b/zokrates_core_test/tests/tests/uint/u16/and.json new file mode 100644 index 00000000..c2029124 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/and.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/and.zok", + "max_constraint_count": 51, + "tests": [ + { + "input": { + "values": ["0xffff", "0xffff"] + }, + "output": { + "Ok": { + "values": ["0xffff"] + } + } + }, + { + "input": { + "values": ["0xffff", "0x0000"] + }, + "output": { + "Ok": { + "values": ["0x0000"] + } + } + }, + { + "input": { + "values": ["0x1234", "0x5678"] + }, + "output": { + "Ok": { + "values": ["0x1230"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/and.zok b/zokrates_core_test/tests/tests/uint/u16/and.zok new file mode 100644 index 00000000..a038b1eb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/and.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> u16: + return a & b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/div.json b/zokrates_core_test/tests/tests/uint/u16/div.json new file mode 100644 index 00000000..9c22237f --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/div.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/div.zok", + "max_constraint_count": 88, + "tests": [ + { + "input": { + "values": ["0x1000", "0x1000"] + }, + "output": { + "Ok": { + "values": ["0x0001"] + } + } + }, + { + "input": { + "values": ["0x1000", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0x0800"] + } + } + }, + { + "input": { + "values": ["0x1001", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0x0800"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/div.zok b/zokrates_core_test/tests/tests/uint/u16/div.zok new file mode 100644 index 00000000..a047e4cb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/div.zok @@ -0,0 +1,2 @@ +def main(u16 x, u16 y) -> u16: + return x / y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/eq.json b/zokrates_core_test/tests/tests/uint/u16/eq.json new file mode 100644 index 00000000..19e68395 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/eq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/eq.zok", + "max_constraint_count": 37, + "tests": [ + { + "input": { + "values": ["0x0002", "0x0002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0002", "0x0004"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/eq.zok b/zokrates_core_test/tests/tests/uint/u16/eq.zok new file mode 100644 index 00000000..da6bde28 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/eq.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> bool: + return a == b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/gt.json b/zokrates_core_test/tests/tests/uint/u16/gt.json new file mode 100644 index 00000000..f9845b43 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/gt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/gt.zok", + "max_constraint_count": 697, + "tests": [ + { + "input": { + "values": ["0x0004", "0x0002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0002", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/gt.zok b/zokrates_core_test/tests/tests/uint/u16/gt.zok new file mode 100644 index 00000000..41453552 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/gt.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> bool: + return a > b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/gte.json b/zokrates_core_test/tests/tests/uint/u16/gte.json new file mode 100644 index 00000000..5512846a --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/gte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/gte.zok", + "max_constraint_count": 699, + "tests": [ + { + "input": { + "values": ["0x0004", "0x0002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0002", "0x0002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0001", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/gte.zok b/zokrates_core_test/tests/tests/uint/u16/gte.zok new file mode 100644 index 00000000..4111057a --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/gte.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> bool: + return a >= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/lshift.json b/zokrates_core_test/tests/tests/uint/u16/lshift.json new file mode 100644 index 00000000..466e1b0a --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/lshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/lshift.zok", + "max_constraint_count": 18, + "tests": [ + { + "input": { + "values": ["0x0002"] + }, + "output": { + "Ok": { + "values": ["0x0004"] + } + } + }, + { + "input": { + "values": ["0xffff"] + }, + "output": { + "Ok": { + "values": ["0xfffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/lshift.zok b/zokrates_core_test/tests/tests/uint/u16/lshift.zok new file mode 100644 index 00000000..18a30a8f --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/lshift.zok @@ -0,0 +1,2 @@ +def main(u16 x) -> u16: + return x << 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/lt.json b/zokrates_core_test/tests/tests/uint/u16/lt.json new file mode 100644 index 00000000..f21f396a --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/lt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/lt.zok", + "max_constraint_count": 697, + "tests": [ + { + "input": { + "values": ["0x0002", "0x0004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0002", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/lt.zok b/zokrates_core_test/tests/tests/uint/u16/lt.zok new file mode 100644 index 00000000..9a6b2b49 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/lt.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> bool: + return a < b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/lte.json b/zokrates_core_test/tests/tests/uint/u16/lte.json new file mode 100644 index 00000000..a7b170c3 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/lte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/lte.zok", + "max_constraint_count": 699, + "tests": [ + { + "input": { + "values": ["0x0002", "0x0004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0002", "0x0002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0003", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/lte.zok b/zokrates_core_test/tests/tests/uint/u16/lte.zok new file mode 100644 index 00000000..f60160af --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/lte.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> bool: + return a <= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/mul.json b/zokrates_core_test/tests/tests/uint/u16/mul.json new file mode 100644 index 00000000..4b8ca537 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/mul.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/mul.zok", + "max_constraint_count": 69, + "tests": [ + { + "input": { + "values": ["0x0002", "0x0008"] + }, + "output": { + "Ok": { + "values": ["0x0010"] + } + } + }, + { + "input": { + "values": ["0xffff", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0xfffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/mul.zok b/zokrates_core_test/tests/tests/uint/u16/mul.zok new file mode 100644 index 00000000..da465553 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/mul.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> u16: + return a * b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/neq.json b/zokrates_core_test/tests/tests/uint/u16/neq.json new file mode 100644 index 00000000..4a37373d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/neq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/neq.zok", + "max_constraint_count": 37, + "tests": [ + { + "input": { + "values": ["0x0002", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["0x0002", "0x0004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/neq.zok b/zokrates_core_test/tests/tests/uint/u16/neq.zok new file mode 100644 index 00000000..906da545 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/neq.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> bool: + return a != b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/not.json b/zokrates_core_test/tests/tests/uint/u16/not.json new file mode 100644 index 00000000..d544a576 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/not.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/not.zok", + "max_constraint_count": 18, + "tests": [ + { + "input": { + "values": ["0x0001"] + }, + "output": { + "Ok": { + "values": ["0xfffe"] + } + } + }, + { + "input": { + "values": ["0xffff"] + }, + "output": { + "Ok": { + "values": ["0x0000"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/not.zok b/zokrates_core_test/tests/tests/uint/u16/not.zok new file mode 100644 index 00000000..0b03209c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/not.zok @@ -0,0 +1,2 @@ +def main(u16 a) -> u16: + return !a \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/or.json b/zokrates_core_test/tests/tests/uint/u16/or.json new file mode 100644 index 00000000..dafb687b --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/or.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/or.zok", + "max_constraint_count": 51, + "tests": [ + { + "input": { + "values": ["0xffff", "0xffff"] + }, + "output": { + "Ok": { + "values": ["0xffff"] + } + } + }, + { + "input": { + "values": ["0xffff", "0x0000"] + }, + "output": { + "Ok": { + "values": ["0xffff"] + } + } + }, + { + "input": { + "values": ["0x1234", "0x5678"] + }, + "output": { + "Ok": { + "values": ["0x567c"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/or.zok b/zokrates_core_test/tests/tests/uint/u16/or.zok new file mode 100644 index 00000000..e3ccc9a6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/or.zok @@ -0,0 +1,2 @@ +def main(u16 x, u16 y) -> u16: + return x | y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/rem.json b/zokrates_core_test/tests/tests/uint/u16/rem.json new file mode 100644 index 00000000..77cd9164 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/rem.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/rem.zok", + "max_constraint_count": 88, + "tests": [ + { + "input": { + "values": ["0x0002", "0x0004"] + }, + "output": { + "Ok": { + "values": ["0x0002"] + } + } + }, + { + "input": { + "values": ["0xffff", "0x0001"] + }, + "output": { + "Ok": { + "values": ["0x0000"] + } + } + }, + { + "input": { + "values": ["0x1001", "0x0002"] + }, + "output": { + "Ok": { + "values": ["0x0001"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/rem.zok b/zokrates_core_test/tests/tests/uint/u16/rem.zok new file mode 100644 index 00000000..4d53d732 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/rem.zok @@ -0,0 +1,2 @@ +def main(u16 x, u16 y) -> u16: + return x % y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/rshift.json b/zokrates_core_test/tests/tests/uint/u16/rshift.json new file mode 100644 index 00000000..d8129016 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/rshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/rshift.zok", + "max_constraint_count": 18, + "tests": [ + { + "input": { + "values": ["0x1000"] + }, + "output": { + "Ok": { + "values": ["0x0800"] + } + } + }, + { + "input": { + "values": ["0xffff"] + }, + "output": { + "Ok": { + "values": ["0x7fff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/rshift.zok b/zokrates_core_test/tests/tests/uint/u16/rshift.zok new file mode 100644 index 00000000..3d95cd3c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/rshift.zok @@ -0,0 +1,2 @@ +def main(u16 x) -> u16: + return x >> 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/sub.json b/zokrates_core_test/tests/tests/uint/u16/sub.json new file mode 100644 index 00000000..39e6bd1b --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/sub.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u16/sub.zok", + "max_constraint_count": 53, + "tests": [ + { + "input": { + "values": ["0xffff", "0x0001"] + }, + "output": { + "Ok": { + "values": ["0xfffe"] + } + } + }, + { + "input": { + "values": ["0x0000", "0x0001"] + }, + "output": { + "Ok": { + "values": ["0xffff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/sub.zok b/zokrates_core_test/tests/tests/uint/u16/sub.zok new file mode 100644 index 00000000..d6e31c7d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/sub.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> u16: + return a - b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/xor.json b/zokrates_core_test/tests/tests/uint/u16/xor.json new file mode 100644 index 00000000..cb9c95ee --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/xor.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u16/xor.zok", + "max_constraint_count": 51, + "tests": [ + { + "input": { + "values": ["0xffff", "0xffff"] + }, + "output": { + "Ok": { + "values": ["0x0000"] + } + } + }, + { + "input": { + "values": ["0xffff", "0x0000"] + }, + "output": { + "Ok": { + "values": ["0xffff"] + } + } + }, + { + "input": { + "values": ["0x1234", "0x5678"] + }, + "output": { + "Ok": { + "values": ["0x444c"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u16/xor.zok b/zokrates_core_test/tests/tests/uint/u16/xor.zok new file mode 100644 index 00000000..620364d8 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u16/xor.zok @@ -0,0 +1,2 @@ +def main(u16 a, u16 b) -> u16: + return a ^ b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/add.json b/zokrates_core_test/tests/tests/uint/u32/add.json new file mode 100644 index 00000000..91c876af --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/add.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/add.zok", + "max_constraint_count": 101, + "tests": [ + { + "input": { + "values": ["0xffffffff", "0x00000001"] + }, + "output": { + "Ok": { + "values": ["0x00000000"] + } + } + }, + { + "input": { + "values": ["0x10000000", "0x10000000"] + }, + "output": { + "Ok": { + "values": ["0x20000000"] + } + } + }, + { + "input": { + "values": ["0xffffffff", "0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0xfffffffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/add.zok b/zokrates_core_test/tests/tests/uint/u32/add.zok new file mode 100644 index 00000000..f3846ffb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/add.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> u32: + return a + b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/and.json b/zokrates_core_test/tests/tests/uint/u32/and.json new file mode 100644 index 00000000..ccac4718 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/and.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/and.zok", + "max_constraint_count": 99, + "tests": [ + { + "input": { + "values": ["0xffffffff", "0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0xffffffff"] + } + } + }, + { + "input": { + "values": ["0xffffffff", "0x00000000"] + }, + "output": { + "Ok": { + "values": ["0x00000000"] + } + } + }, + { + "input": { + "values": ["0x12345678", "0x87654321"] + }, + "output": { + "Ok": { + "values": ["0x02244220"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/and.zok b/zokrates_core_test/tests/tests/uint/u32/and.zok new file mode 100644 index 00000000..5b9287cb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/and.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> u32: + return a & b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/div.json b/zokrates_core_test/tests/tests/uint/u32/div.json new file mode 100644 index 00000000..ef1574c5 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/div.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/div.zok", + "max_constraint_count": 168, + "tests": [ + { + "input": { + "values": ["0x10000000", "0x10000000"] + }, + "output": { + "Ok": { + "values": ["0x00000001"] + } + } + }, + { + "input": { + "values": ["0x10000000", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0x08000000"] + } + } + }, + { + "input": { + "values": ["0x10000001", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0x08000000"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/div.zok b/zokrates_core_test/tests/tests/uint/u32/div.zok new file mode 100644 index 00000000..1f768959 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/div.zok @@ -0,0 +1,2 @@ +def main(u32 x, u32 y) -> u32: + return x / y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/eq.json b/zokrates_core_test/tests/tests/uint/u32/eq.json new file mode 100644 index 00000000..e5040792 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/eq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/eq.zok", + "max_constraint_count": 69, + "tests": [ + { + "input": { + "values": ["0x00000002", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000002", "0x00000004"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/eq.zok b/zokrates_core_test/tests/tests/uint/u32/eq.zok new file mode 100644 index 00000000..b2087fdf --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/eq.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> bool: + return a == b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/gt.json b/zokrates_core_test/tests/tests/uint/u32/gt.json new file mode 100644 index 00000000..71b7e1d6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/gt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/gt.zok", + "max_constraint_count": 729, + "tests": [ + { + "input": { + "values": ["0x00000004", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000002", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/gt.zok b/zokrates_core_test/tests/tests/uint/u32/gt.zok new file mode 100644 index 00000000..acb0df0c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/gt.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> bool: + return a > b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/gte.json b/zokrates_core_test/tests/tests/uint/u32/gte.json new file mode 100644 index 00000000..feb45f8b --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/gte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/gte.zok", + "max_constraint_count": 731, + "tests": [ + { + "input": { + "values": ["0x00000004", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000002", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000001", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/gte.zok b/zokrates_core_test/tests/tests/uint/u32/gte.zok new file mode 100644 index 00000000..e08264a9 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/gte.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> bool: + return a >= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/lshift.json b/zokrates_core_test/tests/tests/uint/u32/lshift.json new file mode 100644 index 00000000..9fddb95e --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/lshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/lshift.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0x00000002"] + }, + "output": { + "Ok": { + "values": ["0x00000004"] + } + } + }, + { + "input": { + "values": ["0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0xfffffffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/lshift.zok b/zokrates_core_test/tests/tests/uint/u32/lshift.zok new file mode 100644 index 00000000..f417823b --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/lshift.zok @@ -0,0 +1,2 @@ +def main(u32 x) -> u32: + return x << 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/lt.json b/zokrates_core_test/tests/tests/uint/u32/lt.json new file mode 100644 index 00000000..5a80d005 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/lt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/lt.zok", + "max_constraint_count": 729, + "tests": [ + { + "input": { + "values": ["0x00000002", "0x00000004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000002", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/lt.zok b/zokrates_core_test/tests/tests/uint/u32/lt.zok new file mode 100644 index 00000000..05cc5d53 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/lt.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> bool: + return a < b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/lte.json b/zokrates_core_test/tests/tests/uint/u32/lte.json new file mode 100644 index 00000000..32532942 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/lte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/lte.zok", + "max_constraint_count": 731, + "tests": [ + { + "input": { + "values": ["0x00000002", "0x00000004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000002", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x00000003", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/lte.zok b/zokrates_core_test/tests/tests/uint/u32/lte.zok new file mode 100644 index 00000000..0975ee9d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/lte.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> bool: + return a <= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/mul.json b/zokrates_core_test/tests/tests/uint/u32/mul.json new file mode 100644 index 00000000..8504aafb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/mul.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/mul.zok", + "max_constraint_count": 133, + "tests": [ + { + "input": { + "values": ["0x00000002", "0x00000008"] + }, + "output": { + "Ok": { + "values": ["0x00000010"] + } + } + }, + { + "input": { + "values": ["0xffffffff", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0xfffffffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/mul.zok b/zokrates_core_test/tests/tests/uint/u32/mul.zok new file mode 100644 index 00000000..bfeb9156 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/mul.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> u32: + return a * b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/neq.json b/zokrates_core_test/tests/tests/uint/u32/neq.json new file mode 100644 index 00000000..c64f2d39 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/neq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/neq.zok", + "max_constraint_count": 69, + "tests": [ + { + "input": { + "values": ["0x00000002", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["0x00000002", "0x00000004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/neq.zok b/zokrates_core_test/tests/tests/uint/u32/neq.zok new file mode 100644 index 00000000..db6f1b1d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/neq.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> bool: + return a != b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/not.json b/zokrates_core_test/tests/tests/uint/u32/not.json new file mode 100644 index 00000000..a17fe27d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/not.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/not.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0x00000001"] + }, + "output": { + "Ok": { + "values": ["0xfffffffe"] + } + } + }, + { + "input": { + "values": ["0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0x00000000"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/shift.zok b/zokrates_core_test/tests/tests/uint/u32/not.zok similarity index 51% rename from zokrates_core_test/tests/tests/uint/shift.zok rename to zokrates_core_test/tests/tests/uint/u32/not.zok index f962c5f2..8a3545af 100644 --- a/zokrates_core_test/tests/tests/uint/shift.zok +++ b/zokrates_core_test/tests/tests/uint/u32/not.zok @@ -1,2 +1,2 @@ def main(u32 a) -> u32: - return a >> 0x00000004 \ No newline at end of file + return !a \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/or.json b/zokrates_core_test/tests/tests/uint/u32/or.json new file mode 100644 index 00000000..3b095d54 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/or.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/or.zok", + "max_constraint_count": 99, + "tests": [ + { + "input": { + "values": ["0xffffffff", "0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0xffffffff"] + } + } + }, + { + "input": { + "values": ["0xffffffff", "0x00000000"] + }, + "output": { + "Ok": { + "values": ["0xffffffff"] + } + } + }, + { + "input": { + "values": ["0x12345678", "0x87654321"] + }, + "output": { + "Ok": { + "values": ["0x97755779"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/or.zok b/zokrates_core_test/tests/tests/uint/u32/or.zok new file mode 100644 index 00000000..fb9d9a5b --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/or.zok @@ -0,0 +1,2 @@ +def main(u32 x, u32 y) -> u32: + return x | y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/rem.json b/zokrates_core_test/tests/tests/uint/u32/rem.json new file mode 100644 index 00000000..faeda5db --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/rem.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/rem.zok", + "max_constraint_count": 168, + "tests": [ + { + "input": { + "values": ["0x00000002", "0x00000004"] + }, + "output": { + "Ok": { + "values": ["0x00000002"] + } + } + }, + { + "input": { + "values": ["0xffffffff", "0x00000001"] + }, + "output": { + "Ok": { + "values": ["0x00000000"] + } + } + }, + { + "input": { + "values": ["0x10000001", "0x00000002"] + }, + "output": { + "Ok": { + "values": ["0x00000001"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/rem.zok b/zokrates_core_test/tests/tests/uint/u32/rem.zok new file mode 100644 index 00000000..d5a1f22f --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/rem.zok @@ -0,0 +1,2 @@ +def main(u32 x, u32 y) -> u32: + return x % y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/rshift.json b/zokrates_core_test/tests/tests/uint/u32/rshift.json new file mode 100644 index 00000000..1b852b57 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/rshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/rshift.zok", + "max_constraint_count": 34, + "tests": [ + { + "input": { + "values": ["0x10000000"] + }, + "output": { + "Ok": { + "values": ["0x08000000"] + } + } + }, + { + "input": { + "values": ["0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0x7fffffff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/rshift.zok b/zokrates_core_test/tests/tests/uint/u32/rshift.zok new file mode 100644 index 00000000..c70ee2c6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/rshift.zok @@ -0,0 +1,2 @@ +def main(u32 x) -> u32: + return x >> 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/sub.json b/zokrates_core_test/tests/tests/uint/u32/sub.json new file mode 100644 index 00000000..2d607519 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/sub.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u32/sub.zok", + "max_constraint_count": 101, + "tests": [ + { + "input": { + "values": ["0xffffffff", "0x00000001"] + }, + "output": { + "Ok": { + "values": ["0xfffffffe"] + } + } + }, + { + "input": { + "values": ["0x00000000", "0x00000001"] + }, + "output": { + "Ok": { + "values": ["0xffffffff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/sub.zok b/zokrates_core_test/tests/tests/uint/u32/sub.zok new file mode 100644 index 00000000..5700177c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/sub.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> u32: + return a - b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/xor.json b/zokrates_core_test/tests/tests/uint/u32/xor.json new file mode 100644 index 00000000..e37db969 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/xor.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u32/xor.zok", + "max_constraint_count": 99, + "tests": [ + { + "input": { + "values": ["0xffffffff", "0xffffffff"] + }, + "output": { + "Ok": { + "values": ["0x00000000"] + } + } + }, + { + "input": { + "values": ["0xffffffff", "0x00000000"] + }, + "output": { + "Ok": { + "values": ["0xffffffff"] + } + } + }, + { + "input": { + "values": ["0x12345678", "0x87654321"] + }, + "output": { + "Ok": { + "values": ["0x95511559"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u32/xor.zok b/zokrates_core_test/tests/tests/uint/u32/xor.zok new file mode 100644 index 00000000..59cf98d5 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u32/xor.zok @@ -0,0 +1,2 @@ +def main(u32 a, u32 b) -> u32: + return a ^ b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/add.json b/zokrates_core_test/tests/tests/uint/u64/add.json new file mode 100644 index 00000000..0663fc03 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/add.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/add.zok", + "max_constraint_count": 197, + "tests": [ + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000001"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000000"] + } + } + }, + { + "input": { + "values": ["0x1000000000000000", "0x1000000000000000"] + }, + "output": { + "Ok": { + "values": ["0x2000000000000000"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff", "0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0xfffffffffffffffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/add.zok b/zokrates_core_test/tests/tests/uint/u64/add.zok new file mode 100644 index 00000000..66077da7 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/add.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> u64: + return a + b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/and.json b/zokrates_core_test/tests/tests/uint/u64/and.json new file mode 100644 index 00000000..93ada893 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/and.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/and.zok", + "max_constraint_count": 195, + "tests": [ + { + "input": { + "values": ["0xffffffffffffffff", "0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0xffffffffffffffff"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000000"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000000"] + } + } + }, + { + "input": { + "values": ["0x1234567812345678", "0x8765432187654321"] + }, + "output": { + "Ok": { + "values": ["0x224422002244220"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/and.zok b/zokrates_core_test/tests/tests/uint/u64/and.zok new file mode 100644 index 00000000..4e693107 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/and.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> u64: + return a & b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/div.json b/zokrates_core_test/tests/tests/uint/u64/div.json new file mode 100644 index 00000000..a3b92ed6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/div.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/div.zok", + "max_constraint_count": 328, + "tests": [ + { + "input": { + "values": ["0x1000000000000000", "0x1000000000000000"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000001"] + } + } + }, + { + "input": { + "values": ["0x1000000000000000", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0x0800000000000000"] + } + } + }, + { + "input": { + "values": ["0x1000000000000001", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0x0800000000000000"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/div.zok b/zokrates_core_test/tests/tests/uint/u64/div.zok new file mode 100644 index 00000000..2b637ddb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/div.zok @@ -0,0 +1,2 @@ +def main(u64 x, u64 y) -> u64: + return x / y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/eq.json b/zokrates_core_test/tests/tests/uint/u64/eq.json new file mode 100644 index 00000000..01480b02 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/eq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/eq.zok", + "max_constraint_count": 133, + "tests": [ + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000004"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/eq.zok b/zokrates_core_test/tests/tests/uint/u64/eq.zok new file mode 100644 index 00000000..ed6c5bba --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/eq.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> bool: + return a == b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/gt.json b/zokrates_core_test/tests/tests/uint/u64/gt.json new file mode 100644 index 00000000..7224a66d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/gt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/gt.zok", + "max_constraint_count": 793, + "tests": [ + { + "input": { + "values": ["0x0000000000000004", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/gt.zok b/zokrates_core_test/tests/tests/uint/u64/gt.zok new file mode 100644 index 00000000..3af2e9eb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/gt.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> bool: + return a > b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/gte.json b/zokrates_core_test/tests/tests/uint/u64/gte.json new file mode 100644 index 00000000..7ab764a9 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/gte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/gte.zok", + "max_constraint_count": 795, + "tests": [ + { + "input": { + "values": ["0x0000000000000004", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000001", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/gte.zok b/zokrates_core_test/tests/tests/uint/u64/gte.zok new file mode 100644 index 00000000..fb6f0b5d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/gte.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> bool: + return a >= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/lshift.json b/zokrates_core_test/tests/tests/uint/u64/lshift.json new file mode 100644 index 00000000..70ac4e60 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/lshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/lshift.zok", + "max_constraint_count": 66, + "tests": [ + { + "input": { + "values": ["0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000004"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0xfffffffffffffffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/lshift.zok b/zokrates_core_test/tests/tests/uint/u64/lshift.zok new file mode 100644 index 00000000..55798fe5 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/lshift.zok @@ -0,0 +1,2 @@ +def main(u64 x) -> u64: + return x << 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/lt.json b/zokrates_core_test/tests/tests/uint/u64/lt.json new file mode 100644 index 00000000..4c74006a --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/lt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/lt.zok", + "max_constraint_count": 793, + "tests": [ + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/lt.zok b/zokrates_core_test/tests/tests/uint/u64/lt.zok new file mode 100644 index 00000000..32769392 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/lt.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> bool: + return a < b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/lte.json b/zokrates_core_test/tests/tests/uint/u64/lte.json new file mode 100644 index 00000000..6c35f5d5 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/lte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/lte.zok", + "max_constraint_count": 795, + "tests": [ + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x0000000000000003", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/lte.zok b/zokrates_core_test/tests/tests/uint/u64/lte.zok new file mode 100644 index 00000000..3d335192 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/lte.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> bool: + return a <= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/mul.json b/zokrates_core_test/tests/tests/uint/u64/mul.json new file mode 100644 index 00000000..3afc1f46 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/mul.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/mul.zok", + "max_constraint_count": 261, + "tests": [ + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000008"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000010"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0xfffffffffffffffe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/mul.zok b/zokrates_core_test/tests/tests/uint/u64/mul.zok new file mode 100644 index 00000000..99ad92d6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/mul.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> u64: + return a * b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/neq.json b/zokrates_core_test/tests/tests/uint/u64/neq.json new file mode 100644 index 00000000..72e448b7 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/neq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/neq.zok", + "max_constraint_count": 133, + "tests": [ + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000004"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/neq.zok b/zokrates_core_test/tests/tests/uint/u64/neq.zok new file mode 100644 index 00000000..e2db5d37 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/neq.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> bool: + return a != b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/not.json b/zokrates_core_test/tests/tests/uint/u64/not.json new file mode 100644 index 00000000..244feef6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/not.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/not.zok", + "max_constraint_count": 66, + "tests": [ + { + "input": { + "values": ["0x0000000000000001"] + }, + "output": { + "Ok": { + "values": ["0xfffffffffffffffe"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000000"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/not.zok b/zokrates_core_test/tests/tests/uint/u64/not.zok new file mode 100644 index 00000000..fbbc0009 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/not.zok @@ -0,0 +1,2 @@ +def main(u64 a) -> u64: + return !a \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/or.json b/zokrates_core_test/tests/tests/uint/u64/or.json new file mode 100644 index 00000000..2492f950 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/or.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/or.zok", + "max_constraint_count": 195, + "tests": [ + { + "input": { + "values": ["0xffffffffffffffff", "0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0xffffffffffffffff"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000000"] + }, + "output": { + "Ok": { + "values": ["0xffffffffffffffff"] + } + } + }, + { + "input": { + "values": ["0x1234567812345678", "0x8765432187654321"] + }, + "output": { + "Ok": { + "values": ["0x9775577997755779"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/or.zok b/zokrates_core_test/tests/tests/uint/u64/or.zok new file mode 100644 index 00000000..f74669ad --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/or.zok @@ -0,0 +1,2 @@ +def main(u64 x, u64 y) -> u64: + return x | y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/rem.json b/zokrates_core_test/tests/tests/uint/u64/rem.json new file mode 100644 index 00000000..8e390e33 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/rem.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/rem.zok", + "max_constraint_count": 328, + "tests": [ + { + "input": { + "values": ["0x0000000000000002", "0x0000000000000004"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000002"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000001"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000000"] + } + } + }, + { + "input": { + "values": ["0x1000000000000001", "0x0000000000000002"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000001"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/rem.zok b/zokrates_core_test/tests/tests/uint/u64/rem.zok new file mode 100644 index 00000000..7d40d228 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/rem.zok @@ -0,0 +1,2 @@ +def main(u64 x, u64 y) -> u64: + return x % y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/rshift.json b/zokrates_core_test/tests/tests/uint/u64/rshift.json new file mode 100644 index 00000000..e279b3a7 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/rshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/rshift.zok", + "max_constraint_count": 66, + "tests": [ + { + "input": { + "values": ["0x1000000000000000"] + }, + "output": { + "Ok": { + "values": ["0x0800000000000000"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0x7fffffffffffffff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/rshift.zok b/zokrates_core_test/tests/tests/uint/u64/rshift.zok new file mode 100644 index 00000000..e2d36c47 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/rshift.zok @@ -0,0 +1,2 @@ +def main(u64 x) -> u64: + return x >> 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/sub.json b/zokrates_core_test/tests/tests/uint/u64/sub.json new file mode 100644 index 00000000..93b4c3b8 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/sub.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u64/sub.zok", + "max_constraint_count": 197, + "tests": [ + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000001"] + }, + "output": { + "Ok": { + "values": ["0xfffffffffffffffe"] + } + } + }, + { + "input": { + "values": ["0x0000000000000000", "0x0000000000000001"] + }, + "output": { + "Ok": { + "values": ["0xffffffffffffffff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/sub.zok b/zokrates_core_test/tests/tests/uint/u64/sub.zok new file mode 100644 index 00000000..deda0fb5 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/sub.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> u64: + return a - b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/xor.json b/zokrates_core_test/tests/tests/uint/u64/xor.json new file mode 100644 index 00000000..8fff5bf2 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/xor.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u64/xor.zok", + "max_constraint_count": 195, + "tests": [ + { + "input": { + "values": ["0xffffffffffffffff", "0xffffffffffffffff"] + }, + "output": { + "Ok": { + "values": ["0x0000000000000000"] + } + } + }, + { + "input": { + "values": ["0xffffffffffffffff", "0x0000000000000000"] + }, + "output": { + "Ok": { + "values": ["0xffffffffffffffff"] + } + } + }, + { + "input": { + "values": ["0x1234567812345678", "0x8765432187654321"] + }, + "output": { + "Ok": { + "values": ["0x9551155995511559"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u64/xor.zok b/zokrates_core_test/tests/tests/uint/u64/xor.zok new file mode 100644 index 00000000..9f96c6d9 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u64/xor.zok @@ -0,0 +1,2 @@ +def main(u64 a, u64 b) -> u64: + return a ^ b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/add.json b/zokrates_core_test/tests/tests/uint/u8/add.json new file mode 100644 index 00000000..4a51cd8c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/add.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/add.zok", + "max_constraint_count": 29, + "tests": [ + { + "input": { + "values": ["0xff", "0x01"] + }, + "output": { + "Ok": { + "values": ["0x00"] + } + } + }, + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["0x04"] + } + } + }, + { + "input": { + "values": ["0xff", "0xff"] + }, + "output": { + "Ok": { + "values": ["0xfe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/add.zok b/zokrates_core_test/tests/tests/uint/u8/add.zok similarity index 63% rename from zokrates_core_test/tests/tests/uint/add.zok rename to zokrates_core_test/tests/tests/uint/u8/add.zok index 925f2208..2fc36f43 100644 --- a/zokrates_core_test/tests/tests/uint/add.zok +++ b/zokrates_core_test/tests/tests/uint/u8/add.zok @@ -1,2 +1,2 @@ def main(u8 a, u8 b) -> u8: - return a + b \ No newline at end of file + return a + b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/and.json b/zokrates_core_test/tests/tests/uint/u8/and.json new file mode 100644 index 00000000..c2944f1c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/and.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/and.zok", + "max_constraint_count": 27, + "tests": [ + { + "input": { + "values": ["0xff", "0xff"] + }, + "output": { + "Ok": { + "values": ["0xff"] + } + } + }, + { + "input": { + "values": ["0xff", "0x00"] + }, + "output": { + "Ok": { + "values": ["0x00"] + } + } + }, + { + "input": { + "values": ["0x23", "0x34"] + }, + "output": { + "Ok": { + "values": ["0x20"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/and.zok b/zokrates_core_test/tests/tests/uint/u8/and.zok similarity index 63% rename from zokrates_core_test/tests/tests/uint/and.zok rename to zokrates_core_test/tests/tests/uint/u8/and.zok index f53e0ee4..8c66852d 100644 --- a/zokrates_core_test/tests/tests/uint/and.zok +++ b/zokrates_core_test/tests/tests/uint/u8/and.zok @@ -1,2 +1,2 @@ def main(u8 a, u8 b) -> u8: - return a & b \ No newline at end of file + return a & b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/div.json b/zokrates_core_test/tests/tests/uint/u8/div.json new file mode 100644 index 00000000..b5cda8d1 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/div.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/div.zok", + "max_constraint_count": 48, + "tests": [ + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["0x01"] + } + } + }, + { + "input": { + "values": ["0x04", "0x02"] + }, + "output": { + "Ok": { + "values": ["0x02"] + } + } + }, + { + "input": { + "values": ["0x2a", "0x0a"] + }, + "output": { + "Ok": { + "values": ["0x04"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/div.zok b/zokrates_core_test/tests/tests/uint/u8/div.zok new file mode 100644 index 00000000..2c8c2ce1 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/div.zok @@ -0,0 +1,2 @@ +def main(u8 x, u8 y) -> u8: + return x / y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/eq.json b/zokrates_core_test/tests/tests/uint/u8/eq.json new file mode 100644 index 00000000..46bf0752 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/eq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/eq.zok", + "max_constraint_count": 21, + "tests": [ + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x02", "0x04"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/eq.zok b/zokrates_core_test/tests/tests/uint/u8/eq.zok new file mode 100644 index 00000000..fe36c5e6 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/eq.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> bool: + return a == b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/gt.json b/zokrates_core_test/tests/tests/uint/u8/gt.json new file mode 100644 index 00000000..e1432041 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/gt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/gt.zok", + "max_constraint_count": 681, + "tests": [ + { + "input": { + "values": ["0x04", "0x02"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/gt.zok b/zokrates_core_test/tests/tests/uint/u8/gt.zok new file mode 100644 index 00000000..689b1548 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/gt.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> bool: + return a > b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/gte.json b/zokrates_core_test/tests/tests/uint/u8/gte.json new file mode 100644 index 00000000..1b3d35b8 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/gte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/gte.zok", + "max_constraint_count": 681, + "tests": [ + { + "input": { + "values": ["0x04", "0x02"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x01", "0x02"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/gte.zok b/zokrates_core_test/tests/tests/uint/u8/gte.zok new file mode 100644 index 00000000..88cb58bb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/gte.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> bool: + return a >= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/lshift.json b/zokrates_core_test/tests/tests/uint/u8/lshift.json new file mode 100644 index 00000000..ca664ad9 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/lshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/lshift.zok", + "max_constraint_count": 10, + "tests": [ + { + "input": { + "values": ["0x02"] + }, + "output": { + "Ok": { + "values": ["0x04"] + } + } + }, + { + "input": { + "values": ["0xff"] + }, + "output": { + "Ok": { + "values": ["0xfe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/lshift.zok b/zokrates_core_test/tests/tests/uint/u8/lshift.zok new file mode 100644 index 00000000..0744d507 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/lshift.zok @@ -0,0 +1,2 @@ +def main(u8 x) -> u8: + return x << 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/lt.json b/zokrates_core_test/tests/tests/uint/u8/lt.json new file mode 100644 index 00000000..c290cd94 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/lt.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/lt.zok", + "max_constraint_count": 681, + "tests": [ + { + "input": { + "values": ["0x02", "0x04"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/lt.zok b/zokrates_core_test/tests/tests/uint/u8/lt.zok new file mode 100644 index 00000000..258c943f --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/lt.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> bool: + return a < b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/lte.json b/zokrates_core_test/tests/tests/uint/u8/lte.json new file mode 100644 index 00000000..f2bd803f --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/lte.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/lte.zok", + "max_constraint_count": 683, + "tests": [ + { + "input": { + "values": ["0x02", "0x04"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + }, + { + "input": { + "values": ["0x03", "0x02"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/lte.zok b/zokrates_core_test/tests/tests/uint/u8/lte.zok new file mode 100644 index 00000000..47de1f47 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/lte.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> bool: + return a <= b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/mul.json b/zokrates_core_test/tests/tests/uint/u8/mul.json new file mode 100644 index 00000000..72878d75 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/mul.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/mul.zok", + "max_constraint_count": 37, + "tests": [ + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["0x04"] + } + } + }, + { + "input": { + "values": ["0xff", "0x02"] + }, + "output": { + "Ok": { + "values": ["0xfe"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/mul.zok b/zokrates_core_test/tests/tests/uint/u8/mul.zok similarity index 63% rename from zokrates_core_test/tests/tests/uint/mul.zok rename to zokrates_core_test/tests/tests/uint/u8/mul.zok index 195ff2b4..6336cced 100644 --- a/zokrates_core_test/tests/tests/uint/mul.zok +++ b/zokrates_core_test/tests/tests/uint/u8/mul.zok @@ -1,2 +1,2 @@ def main(u8 a, u8 b) -> u8: - return a * b \ No newline at end of file + return a * b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/neq.json b/zokrates_core_test/tests/tests/uint/u8/neq.json new file mode 100644 index 00000000..fae87c75 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/neq.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/neq.zok", + "max_constraint_count": 21, + "tests": [ + { + "input": { + "values": ["0x02", "0x02"] + }, + "output": { + "Ok": { + "values": ["0"] + } + } + }, + { + "input": { + "values": ["0x02", "0x04"] + }, + "output": { + "Ok": { + "values": ["1"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/neq.zok b/zokrates_core_test/tests/tests/uint/u8/neq.zok new file mode 100644 index 00000000..50dbe3be --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/neq.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> bool: + return a != b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/not.json b/zokrates_core_test/tests/tests/uint/u8/not.json new file mode 100644 index 00000000..40e9153d --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/not.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/not.zok", + "max_constraint_count": 10, + "tests": [ + { + "input": { + "values": ["0x01"] + }, + "output": { + "Ok": { + "values": ["0xfe"] + } + } + }, + { + "input": { + "values": ["0xff"] + }, + "output": { + "Ok": { + "values": ["0x00"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/not.zok b/zokrates_core_test/tests/tests/uint/u8/not.zok new file mode 100644 index 00000000..422b309c --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/not.zok @@ -0,0 +1,2 @@ +def main(u8 a) -> u8: + return !a \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/or.json b/zokrates_core_test/tests/tests/uint/u8/or.json new file mode 100644 index 00000000..5e756cf1 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/or.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/or.zok", + "max_constraint_count": 27, + "tests": [ + { + "input": { + "values": ["0xff", "0xff"] + }, + "output": { + "Ok": { + "values": ["0xff"] + } + } + }, + { + "input": { + "values": ["0xff", "0x00"] + }, + "output": { + "Ok": { + "values": ["0xff"] + } + } + }, + { + "input": { + "values": ["0x23", "0x34"] + }, + "output": { + "Ok": { + "values": ["0x37"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/or.zok b/zokrates_core_test/tests/tests/uint/u8/or.zok similarity index 63% rename from zokrates_core_test/tests/tests/uint/or.zok rename to zokrates_core_test/tests/tests/uint/u8/or.zok index fbd290b0..31594593 100644 --- a/zokrates_core_test/tests/tests/uint/or.zok +++ b/zokrates_core_test/tests/tests/uint/u8/or.zok @@ -1,2 +1,2 @@ def main(u8 x, u8 y) -> u8: - return x | y \ No newline at end of file + return x | y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/rem.json b/zokrates_core_test/tests/tests/uint/u8/rem.json new file mode 100644 index 00000000..e89ce3eb --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/rem.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/rem.zok", + "max_constraint_count": 48, + "tests": [ + { + "input": { + "values": ["0x02", "0x04"] + }, + "output": { + "Ok": { + "values": ["0x02"] + } + } + }, + { + "input": { + "values": ["0xff", "0x01"] + }, + "output": { + "Ok": { + "values": ["0x00"] + } + } + }, + { + "input": { + "values": ["0x2a", "0x0a"] + }, + "output": { + "Ok": { + "values": ["0x02"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/rem.zok b/zokrates_core_test/tests/tests/uint/u8/rem.zok new file mode 100644 index 00000000..e9f6a7b3 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/rem.zok @@ -0,0 +1,2 @@ +def main(u8 x, u8 y) -> u8: + return x % y \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/rshift.json b/zokrates_core_test/tests/tests/uint/u8/rshift.json new file mode 100644 index 00000000..1155edbc --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/rshift.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/rshift.zok", + "max_constraint_count": 10, + "tests": [ + { + "input": { + "values": ["0x02"] + }, + "output": { + "Ok": { + "values": ["0x01"] + } + } + }, + { + "input": { + "values": ["0xff"] + }, + "output": { + "Ok": { + "values": ["0x7f"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/rshift.zok b/zokrates_core_test/tests/tests/uint/u8/rshift.zok new file mode 100644 index 00000000..c9200960 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/rshift.zok @@ -0,0 +1,2 @@ +def main(u8 x) -> u8: + return x >> 1 \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/sub.json b/zokrates_core_test/tests/tests/uint/u8/sub.json new file mode 100644 index 00000000..084bce99 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/sub.json @@ -0,0 +1,26 @@ +{ + "entry_point": "./tests/tests/uint/u8/sub.zok", + "max_constraint_count": 29, + "tests": [ + { + "input": { + "values": ["0xff", "0x01"] + }, + "output": { + "Ok": { + "values": ["0xfe"] + } + } + }, + { + "input": { + "values": ["0x00", "0x01"] + }, + "output": { + "Ok": { + "values": ["0xff"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/sub.zok b/zokrates_core_test/tests/tests/uint/u8/sub.zok new file mode 100644 index 00000000..7e101a83 --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/sub.zok @@ -0,0 +1,2 @@ +def main(u8 a, u8 b) -> u8: + return a - b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/u8/xor.json b/zokrates_core_test/tests/tests/uint/u8/xor.json new file mode 100644 index 00000000..5a814ebe --- /dev/null +++ b/zokrates_core_test/tests/tests/uint/u8/xor.json @@ -0,0 +1,36 @@ +{ + "entry_point": "./tests/tests/uint/u8/xor.zok", + "max_constraint_count": 27, + "tests": [ + { + "input": { + "values": ["0xff", "0xff"] + }, + "output": { + "Ok": { + "values": ["0x00"] + } + } + }, + { + "input": { + "values": ["0xff", "0x00"] + }, + "output": { + "Ok": { + "values": ["0xff"] + } + } + }, + { + "input": { + "values": ["0x23", "0x34"] + }, + "output": { + "Ok": { + "values": ["0x17"] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/xor.zok b/zokrates_core_test/tests/tests/uint/u8/xor.zok similarity index 63% rename from zokrates_core_test/tests/tests/uint/xor.zok rename to zokrates_core_test/tests/tests/uint/u8/xor.zok index e2b4ac52..445667a0 100644 --- a/zokrates_core_test/tests/tests/uint/xor.zok +++ b/zokrates_core_test/tests/tests/uint/u8/xor.zok @@ -1,2 +1,2 @@ def main(u8 a, u8 b) -> u8: - return a ^ b \ No newline at end of file + return a ^ b \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/uint/xor.json b/zokrates_core_test/tests/tests/uint/xor.json deleted file mode 100644 index b9b98ae0..00000000 --- a/zokrates_core_test/tests/tests/uint/xor.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "entry_point": "./tests/tests/uint/xor.zok", - "max_constraint_count": 27, - "tests": [ - { - "input": { - "values": ["0xff", "0xff"] - }, - "output": { - "Ok": { - "values": ["0x00"] - } - } - }, - { - "input": { - "values": ["0xff", "0x00"] - }, - "output": { - "Ok": { - "values": ["0xff"] - } - } - }, - { - "input": { - "values": ["0x23", "0x34"] - }, - "output": { - "Ok": { - "values": ["0x17"] - } - } - } - ] -} \ No newline at end of file diff --git a/zokrates_parser/src/ace_mode/index.js b/zokrates_parser/src/ace_mode/index.js index a535a1fe..7855ab53 100644 --- a/zokrates_parser/src/ace_mode/index.js +++ b/zokrates_parser/src/ace_mode/index.js @@ -37,7 +37,7 @@ ace.define("ace/mode/zokrates_highlight_rules",["require","exports","module","ac var ZoKratesHighlightRules = function () { var keywords = ( - "assert|as|bool|byte|def|do|else|endfor|export|false|field|for|if|then|fi|import|from|in|private|public|return|struct|true|u8|u16|u32" + "assert|as|bool|byte|def|do|else|endfor|export|false|field|for|if|then|fi|import|from|in|private|public|return|struct|true|u8|u16|u32|u64" ); var keywordMapper = this.createKeywordMapper({ diff --git a/zokrates_parser/src/zokrates.pest b/zokrates_parser/src/zokrates.pest index 94daad5e..50c12fba 100644 --- a/zokrates_parser/src/zokrates.pest +++ b/zokrates_parser/src/zokrates.pest @@ -20,9 +20,10 @@ parameter = {vis? ~ ty ~ identifier} ty_field = {"field"} ty_bool = {"bool"} ty_u8 = {"u8"} -ty_u32 = {"u32"} ty_u16 = {"u16"} -ty_basic = { ty_field | ty_bool | ty_u8 | ty_u16 | ty_u32 } +ty_u32 = {"u32"} +ty_u64 = {"u64"} +ty_basic = { ty_field | ty_bool | ty_u8 | ty_u16 | ty_u32 | ty_u64 } ty_basic_or_struct = { ty_basic | ty_struct } ty_array = { ty_basic_or_struct ~ ("[" ~ expression ~ "]")+ } ty = { ty_array | ty_basic | ty_struct } @@ -107,19 +108,21 @@ literal = { hex_literal | decimal_literal | boolean_literal } decimal_literal = ${ decimal_number ~ decimal_suffix? } decimal_number = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } -decimal_suffix = { decimal_suffix_u8 | decimal_suffix_u16 | decimal_suffix_u32 | decimal_suffix_field } +decimal_suffix = { decimal_suffix_u8 | decimal_suffix_u16 | decimal_suffix_u32 | decimal_suffix_u64 | decimal_suffix_field } decimal_suffix_u8 = { "u8" } decimal_suffix_u16 = { "u16" } decimal_suffix_u32 = { "u32" } +decimal_suffix_u64 = { "u64" } decimal_suffix_field = { "f" } boolean_literal = { "true" | "false" } hex_literal = !{ "0x" ~ hex_number } -hex_number = { hex_number_u32 | hex_number_u16 | hex_number_u8 } +hex_number = { hex_number_u64 | hex_number_u32 | hex_number_u16 | hex_number_u8 } hex_number_u8 = { ASCII_HEX_DIGIT{2} } hex_number_u16 = { ASCII_HEX_DIGIT{4} } hex_number_u32 = { ASCII_HEX_DIGIT{8} } +hex_number_u64 = { ASCII_HEX_DIGIT{16} } // Operators @@ -155,5 +158,5 @@ COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) } // the ordering of reserved keywords matters: if "as" is before "assert", then "assert" gets parsed as (as)(sert) and incorrectly // accepted keyword = @{"assert"|"as"|"bool"|"byte"|"def"|"do"|"else"|"endfor"|"export"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"| - "in"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32" + "in"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32"|"u64" } diff --git a/zokrates_pest_ast/src/lib.rs b/zokrates_pest_ast/src/lib.rs index 79735845..3f1ea138 100644 --- a/zokrates_pest_ast/src/lib.rs +++ b/zokrates_pest_ast/src/lib.rs @@ -215,6 +215,7 @@ mod ast { U8(U8Type<'ast>), U16(U16Type<'ast>), U32(U32Type<'ast>), + U64(U64Type<'ast>), } #[derive(Debug, FromPest, PartialEq, Clone)] @@ -268,6 +269,13 @@ mod ast { pub span: Span<'ast>, } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::ty_u64))] + pub struct U64Type<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::ty_struct))] pub struct StructType<'ast> { @@ -796,6 +804,7 @@ mod ast { U8(U8Suffix<'ast>), U16(U16Suffix<'ast>), U32(U32Suffix<'ast>), + U64(U64Suffix<'ast>), Field(FieldSuffix<'ast>), } @@ -820,6 +829,13 @@ mod ast { pub span: Span<'ast>, } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::decimal_suffix_u64))] + pub struct U64Suffix<'ast> { + #[pest_ast(outer())] + pub span: Span<'ast>, + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::decimal_suffix_field))] pub struct FieldSuffix<'ast> { @@ -866,6 +882,7 @@ mod ast { U8(U8NumberExpression<'ast>), U16(U16NumberExpression<'ast>), U32(U32NumberExpression<'ast>), + U64(U64NumberExpression<'ast>), } #[derive(Debug, FromPest, PartialEq, Clone)] @@ -895,6 +912,15 @@ mod ast { pub span: Span<'ast>, } + #[derive(Debug, FromPest, PartialEq, Clone)] + #[pest_ast(rule(Rule::hex_number_u64))] + pub struct U64NumberExpression<'ast> { + #[pest_ast(outer(with(span_into_str)))] + pub value: String, + #[pest_ast(outer())] + pub span: Span<'ast>, + } + #[derive(Debug, FromPest, PartialEq, Clone)] #[pest_ast(rule(Rule::identifier))] pub struct IdentifierExpression<'ast> { diff --git a/zokrates_stdlib/stdlib/hashes/keccak/256bit.zok b/zokrates_stdlib/stdlib/hashes/keccak/256bit.zok new file mode 100644 index 00000000..59d800fe --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/keccak/256bit.zok @@ -0,0 +1,4 @@ +import "hashes/keccak/keccak" as keccak + +def main(u64[N] input) -> u64[4]: + return keccak::(input, 0x0000000000000001)[..4] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/keccak/384bit.zok b/zokrates_stdlib/stdlib/hashes/keccak/384bit.zok new file mode 100644 index 00000000..f261ebcc --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/keccak/384bit.zok @@ -0,0 +1,4 @@ +import "hashes/keccak/keccak" as keccak + +def main(u64[N] input) -> u64[6]: + return keccak::(input, 0x0000000000000001)[..6] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/keccak/512bit.zok b/zokrates_stdlib/stdlib/hashes/keccak/512bit.zok new file mode 100644 index 00000000..8345df52 --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/keccak/512bit.zok @@ -0,0 +1,4 @@ +import "hashes/keccak/keccak" as keccak + +def main(u64[N] input) -> u64[8]: + return keccak::(input, 0x0000000000000001)[..8] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/keccak/keccak.zok b/zokrates_stdlib/stdlib/hashes/keccak/keccak.zok new file mode 100644 index 00000000..791ef30b --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/keccak/keccak.zok @@ -0,0 +1,95 @@ +// based on keccak-f[1600] permutation + +def rho() -> u32[24]: + return [ + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 + ] + +def pi() -> u32[24]: + return [ + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 + ] + +def rc() -> u64[24]: + return [ + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 + ] + +// left rotation +def rotl64(u64 x, u32 n) -> u64: + return ((x << n) | (x >> (64 - n))) + +// compression function +def keccakf(u64[25] st) -> u64[25]: + u32[24] rotc = rho() + u32[24] piln = pi() + u64[24] rndc = rc() + + u64[5] bc = [0; 5] + u64 t = 0 + + for u32 r in 0..24 do + // theta + for u32 i in 0..5 do + bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20] + endfor + + for u32 i in 0..5 do + t = bc[(i + 4) % 5] ^ rotl64(bc[(i + 1) % 5], 1) + for u32 j in 0..5 do + st[(j * 5) + i] = st[(j * 5) + i] ^ t + endfor + endfor + + t = st[1] + + // rho pi + for u32 i in 0..24 do + bc[0] = st[piln[i]] + st[piln[i]] = rotl64(t, rotc[i]) + t = bc[0] + endfor + + // chi + for u32 i in 0..5 do + for u32 j in 0..5 do + bc[j] = st[(i * 5) + j] + endfor + for u32 j in 0..5 do + u32 p = (i * 5) + j + st[p] = st[p] ^ (!bc[(j + 1) % 5] & bc[(j + 2) % 5]) + endfor + endfor + + // iota + st[0] = st[0] ^ rndc[r] + endfor + return st + +def main(u64[N] input, u64 pad) -> u64[25]: + u64[25] q = [0; 25] + u32 rate = (200 - (W / 4)) / 8 + u32 pt = 0 + + // update + for u32 i in 0..N do + q[pt] = q[pt] ^ input[i] + pt = (pt + 1) % rate + q = if pt == 0 then keccakf(q) else q fi + endfor + + // finalize + q[pt] = q[pt] ^ pad + q[rate - 1] = q[rate - 1] ^ 0x8000000000000000 + + q = keccakf(q) + return q \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/sha3/256bit.zok b/zokrates_stdlib/stdlib/hashes/sha3/256bit.zok new file mode 100644 index 00000000..99d213fa --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/sha3/256bit.zok @@ -0,0 +1,4 @@ +import "hashes/keccak/keccak" as keccak + +def main(u64[N] input) -> (u64[4]): + return keccak::(input, 0x0000000000000006)[..4] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/sha3/384bit.zok b/zokrates_stdlib/stdlib/hashes/sha3/384bit.zok new file mode 100644 index 00000000..1b6dfeff --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/sha3/384bit.zok @@ -0,0 +1,4 @@ +import "hashes/keccak/keccak" as keccak + +def main(u64[N] input) -> (u64[6]): + return keccak::(input, 0x0000000000000006)[..6] \ No newline at end of file diff --git a/zokrates_stdlib/stdlib/hashes/sha3/512bit.zok b/zokrates_stdlib/stdlib/hashes/sha3/512bit.zok new file mode 100644 index 00000000..6c37836e --- /dev/null +++ b/zokrates_stdlib/stdlib/hashes/sha3/512bit.zok @@ -0,0 +1,4 @@ +import "hashes/keccak/keccak" as keccak + +def main(u64[N] input) -> (u64[8]): + return keccak::(input, 0x0000000000000006)[..8] \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/keccak/256bit.json b/zokrates_stdlib/tests/tests/hashes/keccak/256bit.json new file mode 100644 index 00000000..fc1db71e --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/keccak/256bit.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/keccak/256bit.zok", + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": [] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/keccak/256bit.zok b/zokrates_stdlib/tests/tests/hashes/keccak/256bit.zok new file mode 100644 index 00000000..36eb3635 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/keccak/256bit.zok @@ -0,0 +1,6 @@ +import "hashes/keccak/256bit" as keccak256 + +def main(): + u64[4] h = keccak256::<20>([42; 20]) + assert(h == [0x09330DD35B609CA9, 0xDACFC1598C95602C, 0xACD911013FB018F3, 0x17233D68F05E0826]) + return \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/keccak/384bit.json b/zokrates_stdlib/tests/tests/hashes/keccak/384bit.json new file mode 100644 index 00000000..b90c14f3 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/keccak/384bit.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/keccak/384bit.zok", + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": [] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/keccak/384bit.zok b/zokrates_stdlib/tests/tests/hashes/keccak/384bit.zok new file mode 100644 index 00000000..019bf558 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/keccak/384bit.zok @@ -0,0 +1,6 @@ +import "hashes/keccak/384bit" as keccak384 + +def main(): + u64[6] h = keccak384::<20>([42; 20]) + assert(h == [0x2E9DCE590F0A1908, 0x0C4234AB952C5598, 0xFB2DF066B44780C2, 0x717039E101D4A8DA, 0xBAD1EFE140C4B2C4, 0xFAE08DAC3438416E]) + return \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/keccak/512bit.json b/zokrates_stdlib/tests/tests/hashes/keccak/512bit.json new file mode 100644 index 00000000..6ee6daa5 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/keccak/512bit.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/keccak/512bit.zok", + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": [] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/keccak/512bit.zok b/zokrates_stdlib/tests/tests/hashes/keccak/512bit.zok new file mode 100644 index 00000000..4e7d3e91 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/keccak/512bit.zok @@ -0,0 +1,9 @@ +import "hashes/keccak/512bit" as keccak512 + +def main(): + u64[8] h = keccak512::<20>([42; 20]) + assert(h == [ + 0x2716192386255918, 0x68DFF390376BBF13, 0xBD695ADA4CD230E3, 0xF3B00388676A04D3, + 0x484F3F1BB9F36A09, 0x9D0119067282F940, 0xDF27DE0F48072A66, 0xF5957972134160EB + ]) + return \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/sha3/256bit.json b/zokrates_stdlib/tests/tests/hashes/sha3/256bit.json new file mode 100644 index 00000000..86108146 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/sha3/256bit.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/sha3/256bit.zok", + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": [] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/sha3/256bit.zok b/zokrates_stdlib/tests/tests/hashes/sha3/256bit.zok new file mode 100644 index 00000000..e5988be9 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/sha3/256bit.zok @@ -0,0 +1,6 @@ +import "hashes/sha3/256bit" as sha3_256 + +def main(): + u64[4] h = sha3_256::<20>([42; 20]) + assert(h == [0x84350A3A90DED183, 0x70518606C7DC401A, 0x2D44F39C0FCEAC92, 0x3E9533A716130C5A]) + return \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/sha3/384bit.json b/zokrates_stdlib/tests/tests/hashes/sha3/384bit.json new file mode 100644 index 00000000..2d03a2a5 --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/sha3/384bit.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/sha3/384bit.zok", + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": [] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/sha3/384bit.zok b/zokrates_stdlib/tests/tests/hashes/sha3/384bit.zok new file mode 100644 index 00000000..cfc24b4d --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/sha3/384bit.zok @@ -0,0 +1,6 @@ +import "hashes/sha3/384bit" as sha3_384 + +def main(): + u64[6] h = sha3_384::<20>([42; 20]) + assert(h == [0x75A036FA8B615B37, 0x6C73086BB56F092C, 0x536E658916EC18AE, 0xB2F2EEE620CDF698, 0xB7E904DE62A70A31, 0x84FDAA0665836ADD]) + return \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/sha3/512bit.json b/zokrates_stdlib/tests/tests/hashes/sha3/512bit.json new file mode 100644 index 00000000..a5dba0ca --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/sha3/512bit.json @@ -0,0 +1,15 @@ +{ + "entry_point": "./tests/tests/hashes/sha3/512bit.zok", + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": [] + } + } + } + ] +} \ No newline at end of file diff --git a/zokrates_stdlib/tests/tests/hashes/sha3/512bit.zok b/zokrates_stdlib/tests/tests/hashes/sha3/512bit.zok new file mode 100644 index 00000000..b5846a3e --- /dev/null +++ b/zokrates_stdlib/tests/tests/hashes/sha3/512bit.zok @@ -0,0 +1,9 @@ +import "hashes/sha3/512bit" as sha3_512 + +def main(): + u64[8] h = sha3_512::<20>([42; 20]) + assert(h == [ + 0x22DFD92B47C60DAC, 0xDA47C8C247A84FA2, 0x7C5809F122D6950A, 0x8034D41097680656, + 0xD6D06F820B046994, 0xF62743594A554B88, 0x4966E0821CB4D667, 0x974D4391624C5619 + ]) + return \ No newline at end of file diff --git a/zokrates_test/src/lib.rs b/zokrates_test/src/lib.rs index ebcd9556..7c48ebf4 100644 --- a/zokrates_test/src/lib.rs +++ b/zokrates_test/src/lib.rs @@ -2,9 +2,13 @@ extern crate serde_derive; use std::fs::File; +use std::io::{BufReader, Read}; use std::path::{Path, PathBuf}; + +use zokrates_core::compile::{compile, CompileConfig}; use zokrates_core::ir; use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field}; +use zokrates_fs_resolver::FileSystemResolver; #[derive(Serialize, Deserialize, Clone)] enum Curve { @@ -46,15 +50,8 @@ struct Output { type Val = String; fn parse_val(s: String) -> T { - let s = if s.starts_with("0x") { - u32::from_str_radix(s.trim_start_matches("0x"), 16) - .unwrap() - .to_string() - } else { - s - }; - - T::try_from_dec_str(&s).unwrap() + let radix = if s.starts_with("0x") { 16 } else { 10 }; + T::try_from_str(s.trim_start_matches("0x"), radix).unwrap() } impl From> for ComparableResult { @@ -85,10 +82,6 @@ fn compare(result: ir::ExecutionResult, expected: TestResult) -> Re Ok(()) } -use std::io::{BufReader, Read}; -use zokrates_core::compile::{compile, CompileConfig}; -use zokrates_fs_resolver::FileSystemResolver; - pub fn test_inner(test_path: &str) { let t: Tests = serde_json::from_reader(BufReader::new(File::open(Path::new(test_path)).unwrap())).unwrap();