Skip to content

feat(vm,consensus): harden resource calculations(TIP-833)#6721

Open
halibobo1205 wants to merge 3 commits intotronprotocol:developfrom
halibobo1205:feature/tip-833-harden-resource-calculation
Open

feat(vm,consensus): harden resource calculations(TIP-833)#6721
halibobo1205 wants to merge 3 commits intotronprotocol:developfrom
halibobo1205:feature/tip-833-harden-resource-calculation

Conversation

@halibobo1205
Copy link
Copy Markdown
Collaborator

Summary

Implements TIP-833 to harden resource calculations across native and VM paths:

  • Algorithm: BigInteger-based intermediate products in ResourceProcessor (increase/increaseV2/unDelegateIncreaseV2/getNewWindowSize/getUsage) and RepositoryImpl (increase/getUsage); longValueExact() performs an explicit range check before writing back to long, replacing silent overflow wrap with a deterministic ArithmeticException that reverts the transaction.
  • Resource limits: calculateGlobalEnergyLimit{,V2} and calculateGlobalNetLimit{,V2} (and the VM-side calculateGlobalEnergyLimit) drop (long)((double) weight * limit / totalWeight) for two BigInteger helpers — calculateGlobalLimitV1 (preserves "floor frozeBalance/TRX_PRECISION first") and calculateGlobalLimitV2 (single integer truncation, fractional weight preserved so frozeBalance < TRX_PRECISION still yields a proportional non-zero result).
  • Adaptive limit: EnergyProcessor.updateAdaptiveTotalEnergyLimit and RepositoryImpl.usageToBalance (the (long)((double) usage * weight/limit * TRX_PRECISION) reverse-calculation) move to BigInteger under the same gate.
  • Governance: New proposal ALLOW_HARDEN_RESOURCE_CALCULATION (code 97), requires fork VERSION_4_8_2, one-time activation; behaviour pre-activation is byte-identical to current mainnet.

Reference

TIP-833: Harden ResourceProcessor Resource Window Calculations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:consensus topic:vm VM, smart contract

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant