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

Extend Native-ERC20 limits functionality on contracts v1.1 #109

Merged
merged 6 commits into from
Dec 11, 2018

Conversation

patitonar
Copy link
Contributor

Copy link
Collaborator

@akolotov akolotov left a comment

Choose a reason for hiding this comment

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

The comments added to the Foreign bridge contract are also applicable to the Home bridge contract as well.

@ghost ghost added the in progress label Nov 26, 2018
@ghost ghost removed the in progress label Nov 26, 2018
Copy link
Collaborator

@akolotov akolotov left a comment

Choose a reason for hiding this comment

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

Please do the following:

  1. Port changes you made to the gists you prepared
  2. Deploy the bridge contracts (and run Rust bridge) to Sokol<->Kovan. The version of contracts must be the same as it is deployed now in ETH and POA.
  3. Make few transaction through the bridge in both directions. Make sure that the bridge balance is not zero after that.
  4. Upgrade contracts on both sides. The version of contracts must be taken from the gists.
  5. Set the validators limits.
  6. Make sure that the state of the bridge is the same: the same balance, the previous state of user limits (daily limit).
  7. Reset the revisited blocks and restart the bridge. Make sure that transactions which were transferred successfully at the step 3, are not transferred one more time (double spend).
  8. Make few transfers in both directions.

@patitonar
Copy link
Contributor Author

@akolotov Followed the steps you mentioned. Everything worked as expected. Here are some notes from my actions:

  1. Updated gist with last changes:
    Gist for deployed HomeBridge: https://gist.github.com/patitonar/df585134034f5b6fbe01928fc6e00e36
    Gist for deployed ForeignBridge: https://gist.github.com/patitonar/0ff940d070ef5c4d3dbd70e44eeae361

  2. Deployed bridge contracts using deploy script and run rust bridge on Sokol - Kovan.

  • v1.0 poa-bridge-contracts
  • v0.3.0 poa-bridge
    [   Home  ] HomeBridge: 0xDf1DA79e7908702bBa07860Ff4961EE5bFE69aAE at block 5809810
    [ Foreign ] ForeignBridge: 0x3518297716D5FB68e625Abcb4C491B03D36711ed at block 9499616
    [ Foreign ] POA20: 0x0D820bb285038a724efE599671CD40e134C192F0
  1. Used Bridge UI v1.0.0 to send transactions. After some tx the state was:
    Home
    Remaining Daily POA Quota: 29,999,998.9 POA
    Locked POA in Bridge Contract: 1.00 POA

    Foreign
    Remaining Daily POA20 Quota: 14,999,999.9 POA20
    POA20 Tokens Amount: 1.00 POA20
  1. Compiled contracts from gist files
        npm install solc@0.4.24 
        solcjs --version  // 0.4.24+commit.e67f0147.Emscripten.clang
        ../node_modules/solc/solcjs gist_home.sol --bin 
        ../node_modules/solc/solcjs gist_foreign.sol --bin
        ../node_modules/solc/solcjs gist_home.sol --abi 
        ../node_modules/solc/solcjs gist_foreign.sol --abi

Used eth-cli tool for the following steps.

  • Deploy new bridge contract on Home
eth deploy <PK> gist_home_sol_HomeBridge.bin --sokol 
// output: 0xee2Cf1d8d6236AF0Fd100D196Ffbc49F8fe4D1d4
  • Loaded Home contracts
eth load-contract HomeBridge.abi  0xDf1DA79e7908702bBa07860Ff4961EE5bFE69aAE EternalStorageProxy.json  0xDf1DA79e7908702bBa07860Ff4961EE5bFE69aAE --sokol

then

web3.eth.accounts.wallet.add(<0xPK>) // to unlock account
EternalStorageProxy.methods.version().call() // '1'
EternalStorageProxy.methods.upgradeTo('2', '0xee2Cf1d8d6236AF0Fd100D196Ffbc49F8fe4D1d4').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
EternalStorageProxy.methods.version().call() // '2'
  • Deployed new bridge contract on Foreign
eth deploy <PK> gist_foreign_sol_ForeignBridge.bin --kovan
  // output: 0x2A9782f7fF77101C59Fa3c7AadCd61E87C933Bc8
  • Loaded Foreign contracts
eth load-contract ForeignBridge.abi 0x3518297716D5FB68e625Abcb4C491B03D36711ed EternalStorageProxy.json  0x3518297716D5FB68e625Abcb4C491B03D36711ed --kovan

then

web3.eth.accounts.wallet.add(<0xPK>) // to unlock account
EternalStorageProxy.methods.version().call() // '1'
EternalStorageProxy.methods.upgradeTo('2', '0x2A9782f7fF77101C59Fa3c7AadCd61E87C933Bc8').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
EternalStorageProxy.methods.version().call() // '2'
  • Loaded contracts on Home and then:
    HomeBridge.methods.setForeignDailyLimit('5000000000000000000').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
    HomeBridge.methods.setForeignMaxPerTx('1000000000000000000').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
  • Loaded contracts on Foreign and then:
    ForeignBridge.methods.setHomeDailyLimit('5000000000000000000').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
    ForeignBridge.methods.setHomeMaxPerTx('1000000000000000000').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
  1. The state of the bridge was the same.
    Home
    Remaining Daily POA Quota: 29,999,998.9 POA
    Locked POA in Bridge Contract: 1.00 POA

    Foreign
    Remaining Daily POA20 Quota: 14,999,999.9 POA20
    POA20 Tokens Amount: 1.00 POA20
  1. Reset revised blocks by bridge. No double spend happened.
  2. Used Bridge UI again, sent a few transfers. Worked as expected.

@akolotov
Copy link
Collaborator

Ok. Great! I will take a look at the gists one more time and will initiate the procedure of the contracts upgrade.

@akolotov
Copy link
Collaborator

akolotov commented Dec 2, 2018

@patitonar I tried to describe the upgrade procedure and found that it is quite complicated and could lead to a situation when transactions will not be accepted for short period of time since we don't want to stop validators during upgrade.

That's why my suggestion is to introduce an additional method in the contracts that are in your gist. This method will be responsible for migration from one version of contract to another. In the case of HomeBridge contract it will be as following:

function upgradeFrom2To3() public {
    requires(!boolStorage[keccak256("isUpgradedFrom2To3")]);
    uintStorage[keccak256("foreignDailyLimit")] = 1500000 eth;
    emit ForeignDailyLimit(1500000 eth);
    uintStorage[keccak256("foreignMaxPerTx")] = 1500000 eth;
    boolStorage[keccak256("isUpgradedFrom2To3")] = true;
}

For the ForeignBridge contract it will be:

function upgradeFrom1To2() public {
    requires(!boolStorage[keccak256("isUpgradedFrom1To2")]);
    uintStorage[keccak256("homeDailyLimit")] = 3000000 eth;
    emit HomeDailyLimit(3000000 eth);
    uintStorage[keccak256("homeMaxPerTx")] = 1500000 eth;
    boolStorage[keccak256("isUpgradedFrom1To2")] = true;
}

It will allow us upgrade and initialize everything in one transaction by calling upgradeToAndCall of EternalStorageProxy contract.

Please modify gists correspondingly and perform tests for upgrade similar to you did here: #109 (comment)

@patitonar
Copy link
Contributor Author

@akolotov I made some corrections on the methods you suggested (replaced requires with require and eth with ether) and updated the gist to include them:
Gist for HomeBridge
Gist for ForeignBridge

Then I followed the same steps as before, except at the moment of the upgrade of the contracts:

  • On Home:
  1. Deployed new version
eth deploy <PK> HomeBridge.bin --sokol // 0x56e5BE6733ebf726cAC18e473fcb73B83e1eD4AB
  1. Upgrade contract version
HomeBridge.methods.upgradeFrom2To3().encodeABI() // '0xf91b853b'
EternalStorageProxy.methods.upgradeToAndCall('2', '0x56e5BE6733ebf726cAC18e473fcb73B83e1eD4AB', '0xf91b853b').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})
  • On Foreign:
  1. Deployed new version
eth deploy <PK> ForeignBridge.bin --kovan // 0xdb18D3964a1A5dAA1Cad6cb0bfe3F9e35931c2Ea
  1. Upgrade contract version
ForeignBridge.methods.upgradeFrom1To2().encodeABI() // '0xe1bb8044'
EternalStorageProxy.methods.upgradeToAndCall('2', '0xdb18D3964a1A5dAA1Cad6cb0bfe3F9e35931c2Ea', '0xe1bb8044').send({from: '0x3752F0a521b2E383693f658D6FC377953024C207', gas: 4000000})

The state of the bridge was the same after the upgrade, no double spend was produced by Rust Bridge and transactions performed using bridge-ui worked as expected.

@akolotov akolotov merged commit 9623988 into develop-1.1 Dec 11, 2018
@ghost ghost removed the review label Dec 11, 2018
@akolotov
Copy link
Collaborator

The upgraded version of contracts was applied to the ETH mainnet and POA Core:

@akolotov akolotov deleted the extend-limits-functionality-1.1-rc0 branch January 8, 2019 11:16
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.

2 participants