Skip to content

fix(optimizer): correct semantic classification of TRON instructions#118

Merged
CodeNinjaEvan merged 1 commit into
tronprotocol:release_0.8.28from
yanghang8612:fix/tron-instruction-semantics
Jun 24, 2026
Merged

fix(optimizer): correct semantic classification of TRON instructions#118
CodeNinjaEvan merged 1 commit into
tronprotocol:release_0.8.28from
yanghang8612:fix/tron-instruction-semantics

Conversation

@yanghang8612

@yanghang8612 yanghang8612 commented Jun 24, 2026

Copy link
Copy Markdown

Summary

libevmasm/SemanticInformation.cpp mis-classifies several TRON-specific instructions for the optimizer. The most serious is a Critical miscompilation on the via-IR pipeline.

Fixes

  • NATIVEFREEZEEXPIRETIME was treated as movable (Critical). It reads an address's stake expire-time — state that NATIVEFREEZE/NATIVEUNFREEZE mutate — but with sideEffects=false and no entry in the movable() / movableApartFromEffects() whitelists it fell through to "movable". The Yul CSE/LICM then reuses a cached freezeExpireTime value across an intervening freeze write, reading stale data. Added it to both whitelists (alongside TOKENBALANCE).
  • ISCONTRACT was missing from movableApartFromEffects() and isDeterministic(). It is the same family as EXTCODESIZE / TOKENBALANCE; added so it is optimized correctly and not over-conservatively.
  • NATIVEVOTE in readWriteOperations(): the memory-read length was the array element count rather than a byte length, which could let UnusedStoreEliminator drop the array writes. Changed to a conservative unknown-length read, and added a paramCount >= 4 guard before the size_t subtractions.
  • Removed the unreachable return true; after the movable() switch.

Verification

  • solc builds cleanly.
  • With --experimental-via-ir --optimize, NATIVEFREEZEEXPIRETIME (0xd7) is now emitted twice across a freeze write (previously CSE collapsed it to one). vote and ordinary contracts still compile on both the legacy and via-IR pipelines.

Targets release_0.8.28.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.

If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.

If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.

NATIVEFREEZEEXPIRETIME read state but was treated as movable, letting the
via-IR optimizer CSE its result across a freeze write and read stale data.
Add it and ISCONTRACT to the proper SemanticInformation whitelists; guard
NATIVEVOTE bounds and mark its memory reads as unknown-length.
@yanghang8612 yanghang8612 force-pushed the fix/tron-instruction-semantics branch from edb6c79 to 8a3c264 Compare June 24, 2026 03:18
@yanghang8612 yanghang8612 marked this pull request as ready for review June 24, 2026 03:24
@CodeNinjaEvan CodeNinjaEvan merged commit 22197df into tronprotocol:release_0.8.28 Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants