From a98701309d4ca557682e96963bd011aa3e0b7b13 Mon Sep 17 00:00:00 2001 From: schaeff Date: Sun, 25 Jul 2021 18:31:22 +0200 Subject: [PATCH] implement fold_program to avoid calling fold_module more than expected --- changelogs/unreleased/949-schaeff | 1 + zokrates_core/src/static_analysis/constant_inliner.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 changelogs/unreleased/949-schaeff 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_core/src/static_analysis/constant_inliner.rs b/zokrates_core/src/static_analysis/constant_inliner.rs index ad00d292..26920dcc 100644 --- a/zokrates_core/src/static_analysis/constant_inliner.rs +++ b/zokrates_core/src/static_analysis/constant_inliner.rs @@ -67,6 +67,17 @@ 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> { + for (id, _) in p.modules { + self.fold_module_id(id); + } + + 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) {