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

Add gas price on initialization of Foreign erc-to-erc mode #91

Merged
merged 5 commits into from
Oct 17, 2018

Conversation

patitonar
Copy link
Contributor

Closes #86

test/erc_to_erc/foreign_bridge.test.js Show resolved Hide resolved
@@ -15,15 +15,18 @@ contract ForeignBridgeErcToErc is BasicBridge, BasicForeignBridge {
function initialize(
address _validatorContract,
address _erc20token,
uint256 _requiredBlockConfirmations
uint256 _requiredBlockConfirmations,
uint256 _gasPrice
) public returns(bool) {
require(!isInitialized(), "already initialized");
require(_validatorContract != address(0), "address cannot be empty");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's be consistent and return revert reason in all require in the initialize method.

My suggestion is to use values as numbers instead of strings since it should reduce the gas usage. You could do simple experiment in order to determine how gas consumption is reduced if a number will be used in require(_validatorContract != address(0), "address cannot be empty"); for example. You need to consider how the gas usage differs for both the contract deployment and the method invocation). If the difference is significant let's use numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran some tests to determine gas consumption, I deployed and call initialize method with the following variations on Kovan network:

  • No reason: require(_validatorContract != address(0));
  • Reason with number: require(_validatorContract != address(0), "1");
  • Reason with text: require(_validatorContract != address(0), "address cannot be empty");

Results:

Deploy:

  • No reason - Reason with number: + 22701
  • Reason with number - Reason with text: + 1344

Initialize method failed (called with address(0) for validatorContract parameter):

  • No reason - Reason with number: + 102
  • Reason with number - Reason with text: + 0

Initialize method success:

  • No reason - Reason with number: + 0
  • Reason with number - Reason with text: + 0

From the results, it seems that avoiding using reason on require saves a lot of gas on deployment and very little on calling the method. Changing a full text to a number have some impact on deployment I guess depending on the string length.

The other contracts doesn't use reason on require, except foreign erc20-to-native which was built based on this contract. Also it seems that reason string is not yet fully supported on toolings (web3/web3.js#1707) so I think that it could be a good idea to remove the reason string from these two contracts. What do you think @akolotov ?

Details from the tests:

require(_validatorContract != address(0), "address cannot be empty");

Deploy
https://kovan.etherscan.io/tx/0x42cb3448e31c2a873b77869759ddc92698cf9d89004e3d989a6952eb392f9d07
Gas Used By Transaction:2530163

Success initialization
https://kovan.etherscan.io/tx/0xe9d150b24edeb3007158d1997b77f19c690ab005c2e1e97deb0638e8799e581a
Gas Used By Transaction:152124

Failed initialization with zero_address on validators
https://kovan.etherscan.io/tx/0x1edcb0d738807b049df726c00ecb53b85b6d12292f9d2c83f252489e3e845f03
Gas Used By Transaction:26487


require(_validatorContract != address(0), "1");

Deploy
https://kovan.etherscan.io/tx/0x44690aa21eca360a28b85b6bacae44e8f11a603d28859f6115d70232df461295
Gas Used By Transaction:2528819

Success initialization
https://kovan.etherscan.io/tx/0x31b57c073d60820905a6b5db1e01a6cf28106f81a57862e23349d45df0fd2057
Gas Used By Transaction:152124

Failed initialization with zero_address on validators
https://kovan.etherscan.io/tx/0x74fbff2f43ba2d5dfe3b09e4c100265a15612d7bc6c20774b5c0a798d168f167
Gas Used By Transaction:26487


require(_validatorContract != address(0));

Deploy
https://kovan.etherscan.io/tx/0xbd67b40a0fba02aeac507535c8a33b61530733d56cde4233bc09b3b2532fba63
Gas Used By Transaction:2506118

Success initialization
https://kovan.etherscan.io/tx/0x539066f85a9a8d392f61bf15142d3322d49d669ad5bf336bc3fc1060babd846e
Gas Used By Transaction:152124

Failed initialization with zero_address on validators
https://kovan.etherscan.io/tx/0xc7f62f1abdaff1362a1baf282ecdc00fdd992ccb6b19b66580bd08522ec8d38e
Gas Used By Transaction:26385

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great! I vote for removing the revert reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

test/erc_to_erc/foreign_bridge.test.js Show resolved Hide resolved
@@ -15,15 +15,18 @@ contract ForeignBridgeErcToErc is BasicBridge, BasicForeignBridge {
function initialize(
address _validatorContract,
address _erc20token,
uint256 _requiredBlockConfirmations
uint256 _requiredBlockConfirmations,
uint256 _gasPrice
) public returns(bool) {
require(!isInitialized(), "already initialized");
require(_validatorContract != address(0), "address cannot be empty");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great! I vote for removing the revert reason.

@ghost ghost removed the in progress label Oct 8, 2018
@patitonar
Copy link
Contributor Author

@akolotov can we merge this PR?

@akolotov akolotov merged commit 9c20897 into erc20-to-native-#79 Oct 17, 2018
@ghost ghost removed the review label Oct 17, 2018
@fvictorio fvictorio deleted the gasPrice-foreign-erc-erc-#86 branch October 17, 2018 19:30
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.

3 participants