Skip to content

refactor(vm): optimize opcode energy cost calculation with BigInteger#6613

Open
yanghang8612 wants to merge 1 commit intotronprotocol:developfrom
yanghang8612:optimize/energy-calculation
Open

refactor(vm): optimize opcode energy cost calculation with BigInteger#6613
yanghang8612 wants to merge 1 commit intotronprotocol:developfrom
yanghang8612:optimize/energy-calculation

Conversation

@yanghang8612
Copy link
Copy Markdown
Contributor

Summary

  • Use BigInteger instead of DataWord for memory size computation in energy cost calculation to improve precision
  • Add allowTvmOsaka proposal config in VMConfig for future activation control
  • Add unit tests for the optimized calculation

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kuny0707 kuny0707 requested review from CodeNinjaEvan and Federico2014 and removed request for CodeNinjaEvan April 6, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants