Merge pull request #917 from Zokrates/field-size-in-bits
Add FIELD_SIZE_IN_BITS constant to EMBED
This commit is contained in:
commit
6eea32a0fe
6 changed files with 45 additions and 2 deletions
1
changelogs/unreleased/917-dark64
Normal file
1
changelogs/unreleased/917-dark64
Normal file
|
@ -0,0 +1 @@
|
|||
Add `FIELD_SIZE_IN_BITS`, `FIELD_MIN` and `FIELD_MAX` constants to `field` stdlib module
|
|
@ -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)),
|
||||
|
|
|
@ -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": []
|
||||
}
|
8
zokrates_stdlib/stdlib/field.zok
Normal file
8
zokrates_stdlib/stdlib/field.zok
Normal 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
|
17
zokrates_stdlib/tests/tests/field.json
Normal file
17
zokrates_stdlib/tests/tests/field.json
Normal 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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
4
zokrates_stdlib/tests/tests/field.zok
Normal file
4
zokrates_stdlib/tests/tests/field.zok
Normal 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
|
Loading…
Reference in a new issue