Merge branch 'develop' of github.com:Zokrates/ZoKrates into generic-structs
This commit is contained in:
commit
5f75c495a0
6 changed files with 31 additions and 7 deletions
1
changelogs/unreleased/947-schaeff
Normal file
1
changelogs/unreleased/947-schaeff
Normal file
|
@ -0,0 +1 @@
|
|||
Fix abi encoder bug for struct values where the members are encoded in the wrong order
|
1
changelogs/unreleased/949-schaeff
Normal file
1
changelogs/unreleased/949-schaeff
Normal file
|
@ -0,0 +1 @@
|
|||
Fix state corruption in the constant inliner
|
|
@ -14,14 +14,11 @@ impl<T: From<usize>> Encode<T> for Inputs<T> {
|
|||
}
|
||||
}
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use zokrates_core::typed_absy::types::{ConcreteType, UBitwidth};
|
||||
|
||||
use zokrates_field::Field;
|
||||
|
||||
type Map<K, V> = BTreeMap<K, V>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
Json(String),
|
||||
|
@ -48,7 +45,7 @@ pub enum Value<T> {
|
|||
Field(T),
|
||||
Boolean(bool),
|
||||
Array(Vec<Value<T>>),
|
||||
Struct(Map<String, Value<T>>),
|
||||
Struct(Vec<(String, Value<T>)>),
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
|
@ -328,7 +325,6 @@ pub fn parse_strict<T: Field>(s: &str, types: Vec<ConcreteType>) -> Result<Value
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::iter::FromIterator;
|
||||
use zokrates_core::typed_absy::types::{
|
||||
ConcreteStructMember, ConcreteStructType, ConcreteType,
|
||||
};
|
||||
|
@ -512,10 +508,10 @@ mod tests {
|
|||
Value::U64(5u64),
|
||||
Value::Boolean(true),
|
||||
Value::Array(vec![Value::Field(1.into()), Value::Field(2.into())]),
|
||||
Value::Struct(BTreeMap::from_iter(vec![
|
||||
Value::Struct(vec![
|
||||
("a".to_string(), Value::Field(1.into())),
|
||||
("b".to_string(), Value::Field(2.into())),
|
||||
])),
|
||||
]),
|
||||
]);
|
||||
|
||||
let serde_value = values.into_serde_json();
|
||||
|
|
12
zokrates_cli/examples/imports/inliner_state.zok
Normal file
12
zokrates_cli/examples/imports/inliner_state.zok
Normal file
|
@ -0,0 +1,12 @@
|
|||
from "./inliner_state_aux" import main as test
|
||||
|
||||
// we check that the constant inliner does not get corrupted
|
||||
// notice that the constant generic has the same name as the constant `K`
|
||||
// defined in the `test1.zok` module
|
||||
def tmp<K>():
|
||||
u32 junk = test() + K
|
||||
return
|
||||
|
||||
// dummy main
|
||||
def main():
|
||||
return
|
5
zokrates_cli/examples/imports/inliner_state_aux.zok
Normal file
5
zokrates_cli/examples/imports/inliner_state_aux.zok
Normal file
|
@ -0,0 +1,5 @@
|
|||
// the issue only shows if `K` is an array, renaming this constant to something else works
|
||||
const u32[1] K = [1]
|
||||
|
||||
def main() -> u32:
|
||||
return K[0]
|
|
@ -67,6 +67,15 @@ impl<'ast, 'a, T: Field> ConstantInliner<'ast, T> {
|
|||
}
|
||||
|
||||
impl<'ast, T: Field> Folder<'ast, T> for ConstantInliner<'ast, T> {
|
||||
fn fold_program(&mut self, p: TypedProgram<'ast, T>) -> TypedProgram<'ast, T> {
|
||||
self.fold_module_id(p.main.clone());
|
||||
|
||||
TypedProgram {
|
||||
modules: std::mem::take(&mut self.modules),
|
||||
..p
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_module_id(&mut self, id: OwnedTypedModuleId) -> OwnedTypedModuleId {
|
||||
// anytime we encounter a module id, visit the corresponding module if it hasn't been done yet
|
||||
if !self.treated(&id) {
|
||||
|
|
Loading…
Reference in a new issue