You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #159: Fix array_fold "powers of 2" bug and turn on serde by default
f64ba1f array_fold: a few minor cleanups (Andrew Poelstra)
75b93b0 array_fold: add regression test for power-of-2 size tree array folding (Andrew Poelstra)
21f6ff8 array_fold: handle powers of two correctly (Andrew Poelstra)
be22f90 turn on 'serde' feature by default (Andrew Poelstra)
17e4937 simc: add explicit error when trying to use a .wit file without serde (Andrew Poelstra)
Pull request description:
The serde thing is unrelated but it was super simple so I threw it in here. Can split it out if someone complains.
The main part of this PR is the 4-line patch
```diff
--- a/src/compile/builtins.rs
+++ b/src/compile/builtins.rs
@@ -21,6 +21,6 @@
f_powers_of_two: &Vec<ProgNode>,
) -> Result<ProgNode, simplicity::types::Error> {
- if n == 1 {
- return Ok(f_powers_of_two[0].clone());
+ if n.is_power_of_two() {
+ return Ok(f_powers_of_two[n.ilog2() as usize].clone());
}
// For n > 1 the next largest power is always >= 0
```
Essentially, in `array_fold` we start by computing the folds for a bunch of power-of-2 array sizes, then use these as building blocks to do non-powers-of-2 in a sort of unbalanced tree algorithm. However, if our array size was exactly a power of 2 (or, I suspect, a multiple of any power of 2 except 1..), we would attempt to fold a power-of-2 tree with a 0-sized tree, which led to an assertion failure. In these cases we shouldn't be folding at all; we should be looking at our precomputed fold.
I put this simple patch in one commit, and the following commit refactors the logic a bit to make this clearer.
Fixes#144Fixes#153
ACKs for top commit:
canndrew:
ACK f64ba1f
Tree-SHA512: 6f37e26d2b3be2631d19d3d93b6e4912260669c4185ed40b17081e9a1d576564cca48397f21ffa76faa77cd40d8c4cad65a5af285e46322c8c3a47d3825db9a7
0 commit comments