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

Increase EXTRA_GAS_PERCENTAGE for erc20-to-native bridge mode #126

Open
akolotov opened this issue Dec 25, 2018 · 0 comments
Open

Increase EXTRA_GAS_PERCENTAGE for erc20-to-native bridge mode #126

akolotov opened this issue Dec 25, 2018 · 0 comments

Comments

@akolotov
Copy link
Collaborator

The current version of the code deployed as the xDai bridge estimates gas usage before sending every transaction in order to sets gas limit in the transaction. Actual gas limit equals the estimated gas multiplied by 2 (implemented as part of #111). The multiplier was identified empirically during the test of erc20-to-native version of the bridge contracts.

During the testing the simplified version of the BlockReward contract was used:

https://github.com/poanetwork/poa-bridge-contracts/blob/339bd4ab0411b83f093af33d1d6a00a39af79654/contracts/test/BlockReward.sol#L21-L27

This implementation consumes less gas than the actual RewardByBlock contract:

https://github.com/poanetwork/poa-network-consensus-contracts/blob/b0fc8789850ef44f0eb0c277748415d3d194e94a/contracts/RewardByBlock.sol#L45-L58

Due to this confirmations sent by the validators to the bridge contracts to mint new xDai coins failed when the number of required signatures was increased:

  1. The first validator sends the confirmation: https://blockscout.com/poa/dai/tx/0x7829faebb972d6de58434d9dac708369c89d3d08627a6abe9d18e26f5b561f4c/internal_transactions
  2. The second validator sends the confirmation (the required signatures are 2): https://blockscout.com/poa/dai/tx/0xf0432ea4f9f496330627e181215f70aaabed1c0e79ec9ef2ca7cde345fda11af/internal_transactions. It fails due to gas limit when tries to invoke RewardByBlock.addExtraReceiver.

The solution is to increase EXTRA_GAS_PERCENTAGE in src/utils/constants.js. In order to identify the correct value that can be used for EXTRA_GAS_PERCENTAGE, it is necessary to perfom tests with an adequate BlockReward сontract (omni/tokenbridge-contracts#121) for 3 or 5 validators (2 of 3 or 3 of 5 signatures must be required).

Here are examples of transactions with confirmations for the xDai bridge run with a workaround applied (EXTRA_GAS_PERCENTAGE was set to 4)

  1. The first confirmation consumes 86242 of gas: https://blockscout.com/poa/dai/tx/0x60932b3ecfa327c618f238ff75f5e77dace4325d3a271ecf801386dbab4c3d71/internal_transactions
  2. The second confirmation consumes 71242 of gas: https://blockscout.com/poa/dai/tx/0x8f497ec2016d9c29ebc8e98b9ab2cdd039dab0d525f4aae34ade018ac874b2d3/internal_transactions
  3. The third confirmation is accounted and there are enough signatures to mint new coins. It consumes 176521 of gas: https://blockscout.com/poa/dai/tx/0xb2a220b5624122f69eb65168a6780ed09572ac772e461f6ec2214055f43175ec/internal_transactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant