From 9ea3484798e12aff9722cbf91f45daaed604e6be Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 4 Oct 2024 16:28:02 +0000 Subject: [PATCH] bugfix: fix inconsistent order of static entries between padding and effective slice --- .../plugins/table/frame_table_builder.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/zkwasm/src/runtime/monitor/plugins/table/frame_table_builder.rs b/crates/zkwasm/src/runtime/monitor/plugins/table/frame_table_builder.rs index 33f32a54c..9661463be 100644 --- a/crates/zkwasm/src/runtime/monitor/plugins/table/frame_table_builder.rs +++ b/crates/zkwasm/src/runtime/monitor/plugins/table/frame_table_builder.rs @@ -102,18 +102,28 @@ impl FrameTableBuilder { // Prepare for the next slice. This will remove all the entries that are returned fn flush(&mut self) -> specs::jtable::FrameTable { let frame_table = { + /* self.current_returned.iter().rev(), why rev()? + * + * Support an image has start function, then initial_frame_entries should have two entries: + * * zkmain -> 0 + * * start -> zkmain + * If we pad a slice, the inherited frame entries of the trivial slice should have two entries with ordering, + * but if first non-trivial slice terminating, 'current_returned' with 'inherited = true' will have + * two entires with reverse ordering, since frame it's a stack(pop from current_unreturned then push into current_returned). + * This crashes commitment checking between trivial slice's post image table and first non-trivial slice's pre image table. + */ let inherited = self - .current_returned + .current_unreturned .iter() - .chain(self.current_unreturned.iter()) + .chain(self.current_returned.iter().rev()) .filter(|entry| entry.inherited) .map(Into::into) .collect::>(); let called = self - .current_returned + .current_unreturned .iter() - .chain(self.current_unreturned.iter()) + .chain(self.current_returned.iter()) .filter(|entry| !entry.inherited) .map(Into::into) .collect::>();