1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

Merge pull request #917 from Zokrates/field-size-in-bits

Add FIELD_SIZE_IN_BITS constant to EMBED
This commit is contained in:
Thibaut Schaeffer 2021-06-17 14:58:04 +02:00 committed by GitHub
commit 6eea32a0fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 2 deletions

View file

@ -0,0 +1 @@
Add `FIELD_SIZE_IN_BITS`, `FIELD_MIN` and `FIELD_MAX` constants to `field` stdlib module

View file

@ -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)),

View file

@ -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": []
}

View file

@ -0,0 +1,8 @@
from "EMBED" import FIELD_SIZE_IN_BITS
const field FIELD_MIN = 0
const field FIELD_MAX = -1
// A dummy `main` function, should NOT be used.
def main():
return

View file

@ -0,0 +1,17 @@
{
"entry_point": "./tests/tests/field.zok",
"max_constraint_count": 3,
"curves": ["Bn128"],
"tests": [
{
"input": {
"values": []
},
"output": {
"Ok": {
"values": ["0", "21888242871839275222246405745257275088548364400416034343698204186575808495616", "254"]
}
}
}
]
}

View file

@ -0,0 +1,4 @@
from "field" import FIELD_MIN, FIELD_MAX, FIELD_SIZE_IN_BITS
def main() -> (field, field, u32):
return FIELD_MIN, FIELD_MAX, FIELD_SIZE_IN_BITS