Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change some types from U256 to U64 #1539

Closed
wants to merge 5 commits into from
Closed

Conversation

KaoImin
Copy link
Contributor

@KaoImin KaoImin commented Nov 10, 2023

What this PR does / why we need it?

This PR:

  1. Change the block_number parameter type of axon_getMetadata and axon_getProposal from U256 to U64. Since then no need to check the u64 overflow.
  2. Change some as_u64 to low_u64 to improve performance

What is the impact of this PR?

No Breaking Change

PR relation:

  • Ref #
CI Settings

CI Usage

Tip: Check the CI you want to run below, and then comment /run-ci.

CI Switch

  • Web3 Compatible Tests
  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests

CI Description

CI Name Description
Web3 Compatible Test Test the Web3 compatibility of Axon
v3 Core Test Run the compatibility tests provided by Uniswap V3
OCT 1-5 | 6-10 | 11 | 12-15 | 16-19 Run the compatibility tests provided by OpenZeppelin

@KaoImin KaoImin marked this pull request as ready for review November 13, 2023 03:02
@KaoImin KaoImin requested a review from a team as a code owner November 13, 2023 03:02
@KaoImin KaoImin requested review from jjyr, Simon-Tl and driftluo and removed request for jjyr and Simon-Tl November 13, 2023 03:02
@Flouse
Copy link
Contributor

Flouse commented Nov 13, 2023

/run-ci

Copy link

CI tests run on commit:

CI test list:

  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests
  • Web3 Compatible Tests

Please check ci test results later.

@yangby-cryptape
Copy link
Collaborator

yangby-cryptape commented Nov 14, 2023

I think this PR is useless.

Since you don't allow those types to large than u64::MAX, why you define them as U256?
You should just define them as u64.

@KaoImin KaoImin marked this pull request as draft November 14, 2023 02:29
Copy link
Collaborator

@yangby-cryptape yangby-cryptape left a comment

Choose a reason for hiding this comment

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

Ref: #1553

@Flouse Flouse mentioned this pull request Nov 15, 2023
9 tasks
@KaoImin KaoImin force-pushed the fix-u256-cast-u64 branch 2 times, most recently from 3912e05 to b7784a4 Compare November 15, 2023 07:11
@KaoImin KaoImin changed the title fix: fix some convert U256 to u64 maybe overflow refactor: change some JSON RPC types from U256 to U64 Nov 15, 2023
@KaoImin KaoImin changed the title refactor: change some JSON RPC types from U256 to U64 refactor: change some types from U256 to U64 Nov 15, 2023
@KaoImin
Copy link
Contributor Author

KaoImin commented Nov 16, 2023

/run-ci

@KaoImin KaoImin marked this pull request as ready for review November 16, 2023 02:42
Copy link

CI tests run on commit:

CI test list:

  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests
  • Web3 Compatible Tests

Please check ci test results later.

@KaoImin KaoImin requested a review from Flouse November 16, 2023 02:42
Copy link
Collaborator

@yangby-cryptape yangby-cryptape left a comment

Choose a reason for hiding this comment

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

When I said

After value > u64::max_value().into(), as_u64() should be replaced with low_u64().

in previous comment.

There is a very important precondition: value > u64::max_value().into() should be checked.

Without that precondition, the low_u64() should NOT be used.
It may change the value silently.

@Flouse Flouse marked this pull request as draft November 20, 2023 04:06
@Flouse Flouse linked an issue Nov 23, 2023 that may be closed by this pull request
@KaoImin
Copy link
Contributor Author

KaoImin commented Nov 23, 2023

The task move to #1591

@KaoImin KaoImin closed this Nov 23, 2023
@KaoImin KaoImin deleted the fix-u256-cast-u64 branch November 27, 2023 11:58
Flouse added a commit that referenced this pull request Dec 4, 2023
* refactor: change many U256 type to U64
* change some safe as_u64 to low_u64 & cargo fmt
* refactor the gas price and limit check
* refactor prepay gas calculation
* revert max gas limit
* fix e2e test
* Update eth_getBalance.test.js
* remove useless code

This PR is substitute for #1539

Some mainly changes:
* Change the type of `nonce` from `U256` to `U64` according to the [EIP-2681](https://eips.ethereum.org/EIPS/eip-2681) limit the account nonce to be between `0` and `2^64-1`.
 * Change the type of `gas_limit` from `U256` to `U64`. According to the current gas cost of the most complex ethereum transaction is on the order of million, `U64` is enough.
* Change the type of `chain_id` from `U256` to `U64` according to  [metamask limit](https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553). The [`ChainId` opcode](https://eips.ethereum.org/EIPS/eip-1344) returns a 256-bit value, so it should not larger than `U256::MAX / 2 - 35`.This issue does not lead to consensus in Ethereum community, however,  I think limit the max chain ID to `4503599627370476` is enough currently. Many temporary L2/L3 need a unique chain ID is the demand of variable-lenght chain ID in foreseeable future. But we do not have the demand now. If the day comes, we can change the chain ID type to `U256` even without hardfork.
* Set the [`Default Max Price`](https://github.com/ethereum/go-ethereum/blob/be65b47/eth/gasprice/gasprice.go#L38) as `500` Gwei that is same as go-ethereum. Meanwhile, change the type of `gas_price` from `U256` to `U64`.

---------

Co-authored-by: sunchengzhu <[email protected]>
Co-authored-by: Flouse <[email protected]>
Flouse added a commit that referenced this pull request Dec 4, 2023
* refactor: change many U256 type to U64
* change some safe as_u64 to low_u64 & cargo fmt
* refactor the gas price and limit check
* refactor prepay gas calculation
* revert max gas limit
* fix e2e test
* Update eth_getBalance.test.js
* remove useless code

This PR is substitute for #1539

Some mainly changes:
* Change the type of `nonce` from `U256` to `U64` according to the [EIP-2681](https://eips.ethereum.org/EIPS/eip-2681) limit the account nonce to be between `0` and `2^64-1`.
 * Change the type of `gas_limit` from `U256` to `U64`. According to the current gas cost of the most complex ethereum transaction is on the order of million, `U64` is enough.
* Change the type of `chain_id` from `U256` to `U64` according to  [metamask limit](https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553). The [`ChainId` opcode](https://eips.ethereum.org/EIPS/eip-1344) returns a 256-bit value, so it should not larger than `U256::MAX / 2 - 35`.This issue does not lead to consensus in Ethereum community, however,  I think limit the max chain ID to `4503599627370476` is enough currently. Many temporary L2/L3 need a unique chain ID is the demand of variable-lenght chain ID in foreseeable future. But we do not have the demand now. If the day comes, we can change the chain ID type to `U256` even without hardfork.
* Set the [`Default Max Price`](https://github.com/ethereum/go-ethereum/blob/be65b47/eth/gasprice/gasprice.go#L38) as `500` Gwei that is same as go-ethereum. Meanwhile, change the type of `gas_price` from `U256` to `U64`.

---------

Co-authored-by: sunchengzhu <[email protected]>
Co-authored-by: Flouse <[email protected]>
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.

Duplicated calculation in eth_estimateGas.
3 participants