diff --git a/changelogs/unreleased/947-schaeff b/changelogs/unreleased/947-schaeff new file mode 100644 index 00000000..07e3af35 --- /dev/null +++ b/changelogs/unreleased/947-schaeff @@ -0,0 +1 @@ +Fix abi encoder bug for struct values where the members are encoded in the wrong order \ No newline at end of file diff --git a/changelogs/unreleased/949-schaeff b/changelogs/unreleased/949-schaeff new file mode 100644 index 00000000..146b5923 --- /dev/null +++ b/changelogs/unreleased/949-schaeff @@ -0,0 +1 @@ +Fix state corruption in the constant inliner \ No newline at end of file diff --git a/zokrates_abi/src/lib.rs b/zokrates_abi/src/lib.rs index 81e3fdfe..205af548 100644 --- a/zokrates_abi/src/lib.rs +++ b/zokrates_abi/src/lib.rs @@ -14,14 +14,11 @@ impl> Encode for Inputs { } } -use std::collections::BTreeMap; use std::fmt; use zokrates_core::typed_absy::types::{ConcreteType, UBitwidth}; use zokrates_field::Field; -type Map = BTreeMap; - #[derive(Debug, PartialEq)] pub enum Error { Json(String), @@ -48,7 +45,7 @@ pub enum Value { Field(T), Boolean(bool), Array(Vec>), - Struct(Map>), + Struct(Vec<(String, Value)>), } #[derive(PartialEq, Debug)] @@ -328,7 +325,6 @@ pub fn parse_strict(s: &str, types: Vec) -> Result(): + u32 junk = test() + K + return + +// dummy main +def main(): + return \ No newline at end of file diff --git a/zokrates_cli/examples/imports/inliner_state_aux.zok b/zokrates_cli/examples/imports/inliner_state_aux.zok new file mode 100644 index 00000000..f828089d --- /dev/null +++ b/zokrates_cli/examples/imports/inliner_state_aux.zok @@ -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] \ No newline at end of file diff --git a/zokrates_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index e0d6da98..0e2ace9c 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -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) {