Skip to content

Align contracts/contract.md with java-tron TVM source, solidity source and mainnet state#329

Open
abn2357 wants to merge 12 commits into
tronprotocol:masterfrom
abn2357:fix_smart_contract
Open

Align contracts/contract.md with java-tron TVM source, solidity source and mainnet state#329
abn2357 wants to merge 12 commits into
tronprotocol:masterfrom
abn2357:fix_smart_contract

Conversation

@abn2357
Copy link
Copy Markdown
Contributor

@abn2357 abn2357 commented May 18, 2026

Summary

Iteratively audited docs/contracts/contract.md against the current
java-tron TVM source, the tronprotocol/solidity fork, and on-chain
state. Fixes both factual drift and formatting. Content-aligned with
the English counterpart
tronprotocol/documentation-en#602.

Notable corrections:

  • SmartContract proto fields: tightened origin_energy_limit,
    code_hash, trx_hash (CREATE2-only), and version semantics
  • origin_energy_limit legacy default: noted that for old contracts
    deployed without this parameter, the stored value is 0 but the
    runtime substitutes a 10,000,000 energy default
    (CREATOR_DEFAULT_ENERGY_LIMIT) via
    ContractCapsule.getOriginEnergyLimit()
  • CREATE address derivation: clarified sha3omit12(rootTransactionId || nonce)
    layout, the 8-byte big-endian nonce, the per-root-transaction (not
    per-account) nonce semantics, and pointed to
    TransactionUtil.generateContractAddress(byte[], long)
  • Built-in functions: replaced the stale "TVM built-in function is not
    supported temporarily" note with concrete per-feature status, gated
    by their actual ALLOW_TVM_* chain parameters and referencing the
    committee proposals that activated them on mainnet:
    #29,
    #15,
    #18,
    #44,
    #72,
    #84,
    #89,
    #103
  • Transfer to non-existent address: explained the pre/post SOLIDITY_059
    behavior change (auto-account-creation after committee
    proposal #29)
  • blockhash: noted that block.blockhash(uint) was deprecated in
    upstream Solidity 0.4.22 and removed in 0.5.0; in TRON's Solidity
    fork the deprecation is inherited from tv_0.4.24 and the removal
    from tv_0.5.4 onwards
  • block.basefee: clarified it returns getEnergyFee (committee-set,
    not per-block EIP-1559), available since the London upgrade
  • now: noted removal in Solidity 0.7.0
  • wallet-cli address example: the original 31-byte hex string was one
    zero-byte short of the 32-byte ABI slot; padded to a proper 32-byte
    ABI-encoded value and rewrote the surrounding sentence to describe
    its structure (11 leading zero bytes + 21-byte TRON address) instead
    of the inaccurate "21-byte address" claim
  • Inner-call energy-limit API: call.value(x) sets msg.value (TRX
    amount), not the energy/gas limit. Corrected the message-call section
    to use call.gas(x) (chained syntax, removed in Solidity 0.7.0) or
    {gas: x, value: ...} (0.6.2+ options syntax), and normalized "gas"
    to "energy" where the text refers to TVM resource consumption rather
    than the Solidity API name
  • constant function modifier: dropped from the listed function
    modifiers because the TRON Solidity fork's Parser.cpp only accepts
    Token::Constant for state-variable declarations, not for function
    headers — function foo() constant { ... } is a parser error in the
    current compiler. Added a note that legacy contracts may still carry
    the deprecated modifier in their source/ABI; since view/pure/constant
    are compile-time annotations and never enter bytecode, already-deployed
    contracts keep working — only recompiling such sources fails

Formatting:

  • Backticked code identifiers consistently (proto fields, opcodes,
    chain parameters, Solidity globals/keywords, function and class
    names); left product/concept names (TRON, Ethereum, Solidity, TVM,
    TRX/sun, Stake 2.0, etc.) as plain text
  • Tightened ordered-list indentation under the built-in function
    section so nested bullets render reliably across renderers
  • Wrapped 'Energy' in backticks where introduced as the resource unit
  • Normalized the inline-note prefix to 注意:

Test plan

  • Cross-checked every claim against current java-tron TVM source
    (PrecompiledContracts.java, Op.java, OperationRegistry.java,
    Program.java, TransactionUtil.java, ProposalUtil.java,
    ContractCapsule.java, Constant.java)
  • Verified chain parameter activation on mainnet via
    wallet/getchainparameters
  • Verified historical committee proposal contents (which proposal
    activated which ALLOW_TVM_* key) via wallet/getproposalbyid
  • Verified upstream Solidity 0.4.22 / 0.5.0 / 0.7.0 changelog
    claims against the tronprotocol/solidity fork tags (tv_0.4.24,
    tv_0.5.4, tv_0.7.0)
  • Verified callcode is still an AddressType member and
    constant is rejected by parseFunctionHeader() against the
    tronprotocol/solidity fork (Types.cpp, Parser.cpp)
  • Visual review of the rendered page on the docs site (lists,
    backticks, code fences, tronscan links)

abn2357 added 12 commits May 18, 2026 15:16
- Rewrite the built-in function section: move it out of the shell code
  fence and list each feature by its ALLOW_TVM_* chain parameter and
  the committee proposal that activated it on mainnet (tronprotocol#15, tronprotocol#18, tronprotocol#29,
  tronprotocol#44, tronprotocol#72, tronprotocol#84, tronprotocol#89, tronprotocol#103)
- Fix the transfer-to-non-existent-address note: after the SOLIDITY_059
  upgrade (proposal tronprotocol#29), the TVM auto-creates the target account on
  transfer, matching system-contract behavior
- Add block.basefee bullet: returns getEnergyFee, available since the
  London upgrade (proposal tronprotocol#72)
- Add the missing Energy subsection
…-version notes

- Add missing 'version = 11' field to the SmartContract proto definition
- Add descriptions for code_hash, trx_hash (CREATE2-only) and version
- Rewrite the CREATE-address paragraph: spell out the
  sha3omit12(rootTransactionId || nonce) layout, the 8-byte nonce, the
  0x41 prefix, and the per-root-transaction nonce semantics (it
  increments on every internal action, not only CREATE); point to
  TransactionUtil.generateContractAddress(byte[], long)
- block.blockhash: note that 'block.blockhash(uint)' was deprecated in
  upstream Solidity 0.4.22 and removed in 0.5.0, inherited by TRON's
  Solidity fork from tv_0.4.24
- now: note removal in upstream Solidity 0.7.0, inherited by TRON's
  Solidity fork from tv_0.7.0
- Promote bullet-style subsection headers to '####' so they render as
  proper sub-headings instead of list items (constant function,
  message calls, delegatecall, CREATE, built-in function, address
  conversion/check/assignment)
- Wrap the SmartContract proto definition in a fenced code block
  ('solidity') instead of a 4-space indented block, matching the
  style used by the rest of the doc
- Backtick code identifiers consistently throughout: proto fields,
  Solidity globals/keywords ('view', 'pure', 'constant',
  'delegatecall', 'msg.sender', 'msg.value', etc), opcodes,
  exception names, currency-unit suffixes ('trx', 'sun', 'ether',
  'finney'), and the bullet labels under the Block Related list
… guidance

The original 'see II-4-7,II-4-8' pointer referred to a chapter
numbering scheme that no longer exists in the doc. Replace it with the
same concrete instruction used in the en-doc: convert the base58
address to its 20-byte hex form via wallet-cli or a TRON SDK before
assigning to a Solidity 'address'.
- Capitalize the product name 'Solidity' wherever it appeared as
  lowercase 'solidity' in prose (heading, address-section paragraphs)
- Add half-width spaces between CJK and Latin/digit characters per
  Chinese tech-writing convention ('20 字节', '21 字节', '返回 1')
- Fix '20 位地址' → '20 字节地址' (it's bytes, not bits)
- Backtick the Solidity 'address' type identifier in prose
- Rewrite the awkward L146 sentence about address-type conversion
- Reindent the three Solidity snippets in the address section to
  standard 4-space body indentation (the originals had column-0 function
  declarations with 8-space body indent that looked copy-pasted from
  a deeper context)
- Drop the extra blank line between the Block Related list and the
  Energy heading
The original hex string was 31 bytes (62 hex chars) — one zero-byte
short of the 32-byte ABI slot. Pad to a full 32-byte ABI-encoded value
and rewrite the surrounding sentence to describe its structure
(11 leading zero bytes + 21-byte TRON address) instead of the
inaccurate '21-byte address' claim.
The TRON Solidity fork's liblangutil/Token.h only registers the
currency-unit keywords 'wei', 'gwei', 'ether', 'sun' and 'trx' — the
'finney' and 'szabo' keywords were removed in upstream Solidity 0.7.0
and the TRON fork inherited the removal. Mentioning 'finney' is now a
compile error, so drop that sentence.
call.value(x) sets msg.value (TRX amount transferred), not the
energy/gas limit. Setting an energy limit on an inner call uses
call.gas(x) in the pre-0.6.2 chained syntax or {gas: x} in the 0.6.2+
options syntax — Solidity removed call.gas/call.value chaining in
0.7.0. Also normalize 'gas' to 'energy' for the TRON resource model
since the wording is talking about TVM consumption, not the API name.
The TRON Solidity fork's parser (Parser.cpp) only accepts Token::Constant
inside parseVariableDeclaration() for state-variable declarations
(alongside Immutable); parseFunctionHeader() does not recognize it.
Writing 'function foo() constant { ... }' is a parser error in the
current fork. Drop 'constant' from the listed function modifiers.

Add a note that legacy contracts may still carry the deprecated
'constant' modifier in their source / ABI — since view/pure/constant
are compile-time annotations only and never enter bytecode, already-
deployed contracts keep working; only recompiling such sources with
the current compiler fails.
The previous wording said TRON's Solidity fork inherits 'both' the
0.4.22 deprecation and the 0.5.0 removal of block.blockhash starting
from tv_0.4.24. That tag (Solidity 0.4.24) is post-deprecation but
pre-removal — it cannot have inherited the removal. Split the
inheritance: deprecation from tv_0.4.24, removal from tv_0.5.4 (the
earliest tv_0.5.x tag in the fork).
Where the Solidity upstream version and the TRON fork tv-tag have the
same numeric form (e.g., upstream 0.7.0 / tv_0.7.0), drop the
parenthetical 'TRON fork tv_X.Y.Z' restatement and write the version
once. Keep the dual notation only where the two diverge (blockhash:
upstream 0.4.22 vs fork tv_0.4.24, upstream 0.5.0 vs fork tv_0.5.4).
Also tighten the chained/options syntax labels to cite the precise
upstream version boundaries (removed in 0.7.0; introduced 0.6.2)
instead of the imprecise 'pre-0.6.2' shorthand.
Normalize the inline-note prefix to **Note**: / **注意**: across the
document. Also unify the lone 注: (shorthand) introduced in an earlier
commit to 注意: for label consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant