refactor(vm): optimize opcode energy cost calculation with BigInteger#6613
Conversation
Use BigInteger for memory size computation to improve precision and add unit tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| // witness array zero, amount array non-zero | ||
| Program program = mockProgram(0, 0, 64, 1, 0); | ||
| long cost = EnergyCost.getVoteWitnessCost3(program); | ||
| // witnessMemNeeded = 0 (size is zero) |
There was a problem hiding this comment.
The unit tests in VoteWitnessCost3Test are well-structured — especially appreciate the overflow boundary coverage in testLargeArrayLengthOverflow and testLargeOffsetOverflow, and the consistency check against cost2 in testConsistentWithCost2ForSmallValues. One minor note: the comment in testZeroLengthOneArray states witnessMemNeeded = 0, but cost3 computes size = 0 * 32 + 32 = 32, which is non-zero — worth clarifying if this is an intentional behavior change from cost2.
There was a problem hiding this comment.
Good catch! The comment was indeed inaccurate — in cost3, even when arrayLength is 0, the size is computed as 0 * 32 + 32 = 32 (accounting for the dynamic array length prefix), so witnessMemNeeded is 32, not 0. This is an intentional behavior difference from cost2, where a zero-length DataWord after mul stays zero and memNeeded returns 0. Fixed the comment in the latest push. Thanks for the review!
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
BigIntegerinstead ofDataWordfor memory size computation in energy cost calculation to improve precisionallowTvmOsakaproposal config inVMConfigfor future activation control