token-bridge
token-bridge copied to clipboard
Increase EXTRA_GAS_PERCENTAGE for erc20-to-native bridge mode
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 https://github.com/poanetwork/token-bridge/issues/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:
- The first validator sends the confirmation: https://blockscout.com/poa/dai/tx/0x7829faebb972d6de58434d9dac708369c89d3d08627a6abe9d18e26f5b561f4c/internal_transactions
- 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 invokeRewardByBlock.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 (https://github.com/poanetwork/poa-bridge-contracts/issues/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
)
- The first confirmation consumes 86242 of gas: https://blockscout.com/poa/dai/tx/0x60932b3ecfa327c618f238ff75f5e77dace4325d3a271ecf801386dbab4c3d71/internal_transactions
- The second confirmation consumes 71242 of gas: https://blockscout.com/poa/dai/tx/0x8f497ec2016d9c29ebc8e98b9ab2cdd039dab0d525f4aae34ade018ac874b2d3/internal_transactions
- 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