Open nlordell opened 9 months ago
What is the best way to benchmark the difference?
Not sure about the project's benchmarking conventions, but perhaps you can run the tests with the --gas-report
flag. More on it here: https://book.getfoundry.sh/forge/gas-reports
Could you ensure linting and rebase with previous PR to ensure CI's OK?
For the rest OK for me.
@rdubois-crypto - should be rebased to latest master
.
When investigating the
mulmuladd
issue, I noticed that at the start of the function, we have a loop to skipindex
for leading 0s in bothu
andv
.Currently, it was computing the a value
0bXY
(whereX
bit being set indicates thatv{index}
is set, andY
bit indicates thatu{index}
is set) and storing it to a temporary variable (T4
) for checking if the leading bit was 0 or not. This PR changes the logic to store it directly to thezz
variable instead of having it be recomputed after the loop finishes.At first, this was implemented by changing the condition of the loop to "is either
v{index}
oru{index}
set?" but computingzz
directly should be slightly better on average (if we assume even bit distribution, there is only a 25% chance this will save gas).Also,
eq(X, 0) -> iszero(X)
for slightly smaller code and less gas used.What is the best way to benchmark the difference?