diff --git a/zokrates_core/src/imports.rs b/zokrates_core/src/imports.rs index f43c388a..39a5c8cc 100644 --- a/zokrates_core/src/imports.rs +++ b/zokrates_core/src/imports.rs @@ -14,6 +14,7 @@ use std::fmt; use std::io; use std::path::{Path, PathBuf}; +use crate::absy::types::UnresolvedType; use typed_arena::Arena; use zokrates_common::Resolver; use zokrates_field::{Bn128Field, Field}; @@ -156,6 +157,17 @@ impl Importer { id: symbol.get_alias(), symbol: Symbol::Flat(FlatEmbed::U8FromBits), }, + "FIELD_SIZE_IN_BITS" => SymbolDeclaration { + id: symbol.get_alias(), + symbol: Symbol::Here(SymbolDefinition::Constant( + ConstantDefinition { + ty: UnresolvedType::Uint(32).into(), + expression: Expression::U32Constant(T::get_required_bits() as u32) + .into(), + } + .start_end(pos.0, pos.1), + )), + }, s => { return Err(CompileErrorInner::ImportError( Error::new(format!("Embed {} not found", s)).with_pos(Some(pos)), diff --git a/zokrates_core_test/tests/tests/cached_condition.json b/zokrates_core_test/tests/tests/cached_condition.json index 5601f26f..5b4edff3 100644 --- a/zokrates_core_test/tests/tests/cached_condition.json +++ b/zokrates_core_test/tests/tests/cached_condition.json @@ -1,4 +1,5 @@ { - "entry_point": "./tests/tests/cached_condition.zok", - "max_constraint_count": 2015 + "entry_point": "./tests/tests/cached_condition.zok", + "max_constraint_count": 2015, + "tests": [] } \ No newline at end of file diff --git a/zokrates_core_test/tests/tests/constants/field_size_in_bits.zok b/zokrates_core_test/tests/tests/constants/field_size_in_bits.zok new file mode 100644 index 00000000..f9ca4061 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field_size_in_bits.zok @@ -0,0 +1,4 @@ +from "EMBED" import FIELD_SIZE_IN_BITS + +def main() -> u32: + return FIELD_SIZE_IN_BITS diff --git a/zokrates_core_test/tests/tests/constants/field_size_in_bits_bls12_377.json b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bls12_377.json new file mode 100644 index 00000000..4ab95053 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bls12_377.json @@ -0,0 +1,17 @@ +{ + "entry_point": "./tests/tests/constants/field_size_in_bits.zok", + "max_constraint_count": 1, + "curves": ["Bls12_377"], + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["253"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/field_size_in_bits_bls12_381.json b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bls12_381.json new file mode 100644 index 00000000..8b806f9b --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bls12_381.json @@ -0,0 +1,17 @@ +{ + "entry_point": "./tests/tests/constants/field_size_in_bits.zok", + "max_constraint_count": 1, + "curves": ["Bls12_381"], + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["255"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/field_size_in_bits_bn128.json b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bn128.json new file mode 100644 index 00000000..56a34c9d --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bn128.json @@ -0,0 +1,17 @@ +{ + "entry_point": "./tests/tests/constants/field_size_in_bits.zok", + "max_constraint_count": 1, + "curves": ["Bn128"], + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["254"] + } + } + } + ] +} diff --git a/zokrates_core_test/tests/tests/constants/field_size_in_bits_bw6_761.json b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bw6_761.json new file mode 100644 index 00000000..39ea9270 --- /dev/null +++ b/zokrates_core_test/tests/tests/constants/field_size_in_bits_bw6_761.json @@ -0,0 +1,17 @@ +{ + "entry_point": "./tests/tests/constants/field_size_in_bits.zok", + "max_constraint_count": 1, + "curves": ["Bw6_761"], + "tests": [ + { + "input": { + "values": [] + }, + "output": { + "Ok": { + "values": ["377"] + } + } + } + ] +}