dss
dss copied to clipboard
Optimize rpow(x,n,base)
-
Optimize rpow(x,n,base) for the case x != 0 && n == 0 (291 gas vs 383 gas)
switch x case 0 {switch n case 0 {z := b} default {z := 0}} default { ... }
=>
switch n case 0 { z := b } default { switch x case 0 { z := 0 } default { ... } }
-
Simplify overflow check for squaring in rpow(x,n,base) (2355 gas vs 2388 gas for x = 2, n = 255)
let xx := mul(x, x) if iszero(eq(div(xx, x), x)) { revert(0,0) }
=>
let xx := mul(x, x) if shr(128, x) { revert(0,0) }
@kmbarry1 can you get these optimisations to pass the spec? 😛
I will give it a try today!
Also, just to give "official" comment on this: looks good, but there are two things I want to check prior to merging:
- gas for
x != 0 && n != 0
is not worsened (I don't think it is, looks like it should be at least the same, maybe better, but want to check explicitly) - must successfully formally verify this
@kmbarry1 do we have any update on this regarding FV?
Am getting through the backlog of changes that are definitely going in before analyzing this.