1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00

Merge branch 'develop' of github.com:Zokrates/ZoKrates into generic-structs

This commit is contained in:
schaeff 2021-07-26 17:03:48 +02:00
commit 5f75c495a0
6 changed files with 31 additions and 7 deletions

View file

@ -0,0 +1 @@
Fix abi encoder bug for struct values where the members are encoded in the wrong order

View file

@ -0,0 +1 @@
Fix state corruption in the constant inliner

View file

@ -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();

View 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

View 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]

View file

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