Skip to content

Latest commit

 

History

History
71 lines (48 loc) · 3.23 KB

tip-474.md

File metadata and controls

71 lines (48 loc) · 3.23 KB
tip: 474
title: Optimize the return value of chainid opcode
author: yanghang8612 <yanghang8612@163.com>
discussions to: https://github.com/tronprotocol/TIPs/issues/474
status: Final
type: Standards Track
category: VM
created: 2022-11-04

Abstract

This TIP aims to optimize the return value of the chainid opcode.

Motivation

The chainId of the TRON mainnet can be queried through the jsonrpc interface, as follows

curl --location --request POST 'https://api.trongrid.io/jsonrpc' \
--header 'Content-Type: application/json' \
--data-raw '{"jsonrpc":"2.0", "method": "eth_chainId", "params": [], "id": 1}'

{"jsonrpc":"2.0","id":1,"result":"0x2b6653dc"}

After the Istanbul proposal takes effect, the chainid opcode becomes valid and it pushes the genesis block id of the current chain onto the stack (defined in tip-174).

In different networks, the return values of the chainid opcode are as follows:

  • mainnet: 0x00000000000000001ebf88508a03865c71d452e25f4d51194196a1d22b6653dc
  • nile: 0x0000000000000000d698d4192c56cb6be724a558448e2684802de4d6cd8690dc
  • shasta: 0x0000000000000000de1aa88295e1fcf982742f773e0419c5a9c134c994a9059e

The return value of the chainid opcode does not match the chainId value queried by the jsonrpc interface. When dApp developers use tools such as metamask to access the TRON network and send transactions, this difference will cause some transactions to fail, such as permit type transactions.

Meanwhile, the return value of the chainid opcode is very large. For the javascript language that commonly used in web3 application development, the maximum integer value is Number.MAX_SAFE_INTEGER(defined in link), and it is clear that the above return values exceed that Number.MAX_SAFE_INTEGER.

  • Number.MAX_SAFE_INTEGER: 2**53 - 1 = 9007199254740991

Therefore, it is necessary to optimize the return value of the chainid opcode in the TRON network.

Specification

After the getAllowOptimizedReturnValueOfChainId(71th) proposal takes effect, the chainid opcode pushes the same value as the jsonrpc interface onto the stack.

The new return value of the chainid opcode for all networks are as follows:

  • mainnet:
    • In Hex: 0x2b6653dc
    • In Decimal: 728126428
  • nile:
    • In Hex: 0xcd8690dc
    • In Decimal: 3448148188
  • shasta:
    • In Hex: 0x94a9059e
    • In Decimal: 2494104990

Rationale

The new values above do not conflict with any chainId of the existing EVM networks.

Backwards Compatibility

Firstly, the new return values proposed in this tip are consistent with some of the TRON community's protocol standards, such as tip-1193 and tip-712.

Secondly, after analyzing the bytecode of the smart contracts on the mainnet and extensive community discussions, we concluded that the proposal has no significant forward compatibility issues. See issue for related analysis and discussion.

Security Considerations

There is no known security consideration.