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

Implement BEP-212 : Reduction of Refunds #1392

Closed
wants to merge 3 commits into from

Conversation

Mister-EA
Copy link
Contributor

Description

This PR implements BEP-212 . This is done by enabling EIP-3529 for BSC on the next hard fork block.

Concretely this BEP:

  • Removes gas refund for SELFDESTRUCT.
  • Caps the refund for SSTORE to 1/5th of the gas used in the transaction.
  • Lowers the SstoreClearsScheduleRefund from 15,000 to 4,800 .

Rationale

Currently the code implementing EIP-3592 is present in the repository, but is not enabled.

Moreover, no tests were added in the pull request implementing it in go-ethereum : ethereum/go-ethereum#22733 . Those tests were added in the ethereum git submodules which BSC does not use. For this reason new tests for EIP-3529 are added in this PR.

Since EIP-3529 is built upon EIP-2929, this PR also enables EIP-2929. For this a new VM instructionset is defined with both EIPs enabled.

Changes

Notable changes:

  • params/config.go : config changes to include hard fork block.
  • vm/jump_table.go : defining a new instructionset with EIP3529 and EIP2929 enabled.
  • core/blockchain_eip3529_test.go : tests for the gas refunds when EIP3529 is enabled or disabled.

@brilliant-lx
Copy link
Collaborator

Would it better to enable BEP-212 later, like the hard fork after Bonel, maybe the Lynn, so community would have more time to get prepared.

MatusKysel
MatusKysel previously approved these changes Mar 29, 2023
initialStorage[common.HexToHash("02")] = common.HexToHash("02")

// Expected gas is intrinsic + 2*pushGas + cold load (due to legacy tx) + SstoreReset (a->b such that a,b!=0) - sstoreClearGasRefund
expectedGasUsage := params.TxGas + 2*vm.GasFastestStep + params.ColdSloadCostEIP2929 + (params.SstoreResetGasEIP2200 - params.ColdSloadCostEIP2929) - params.SstoreClearsScheduleRefundEIP3529
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain this a bit more?

Copy link
Contributor Author

@Mister-EA Mister-EA Mar 30, 2023

Choose a reason for hiding this comment

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

Essentially what happens is that running the bytecode you have gas costs for:

  • intrinsic transaction gas
  • the two PUSH operations
  • Modifying a storage variable

and you have get a refund for:

  • Setting a storage variable to 0 from some other value (the refund is params.SstoreClearsScheduleRefundEIP3529)

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.

4 participants