Skip to content

Commit

Permalink
Reorder stack elements to from 0...n-1 to 0,n-1,1,2,...,n-2 in hashin…
Browse files Browse the repository at this point in the history
…g to match order in proving
  • Loading branch information
anodar committed Jan 24, 2024
1 parent cc39670 commit e925b7c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,17 @@ impl Machine {
let heights: Vec<_> = self.guards.iter().map($field).collect();

// Map each &[Value] slice to its hash using `hash_stack` and collect these hashes into a vector
let slice_hashes: Vec<_> = $stacks.iter()
// Reorder stacks for hashing to follow same order as in proof:
// [0, n-1, 1, 2, ..., n - 2].
let ordered_stacks: Vec<_> = match $stacks.len() {
0 => Vec::new(),
1 => vec![*$stacks.first().unwrap()],
_ => std::iter::once(*$stacks.first().unwrap())
.chain(std::iter::once(*$stacks.last().unwrap()))
.chain($stacks.iter().skip(1).take($stacks.len() - 2).cloned())
.collect()
};
let slice_hashes: Vec<_> = ordered_stacks.iter()
.map(|slice| hash_stack(slice.iter().map(|v| v.hash()), concat!($prefix, " stack:")))
.collect();
hash_stack_with_heights(slice_hashes, &heights, concat!($prefix, " stack:"))
Expand Down

0 comments on commit e925b7c

Please sign in to comment.