-
Notifications
You must be signed in to change notification settings - Fork 99
Introduce precompiles to manage ERC20 connector #51
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
Merged
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
193418e
Add connector precompiles: WIP.
sept-en c4b85a9
Update required precompiles for ERC20-Connector
mfornet 88faeec
fix style and refactor
joshuajbouw f54d3ab
Address comments
mfornet 17fb6a6
Add map to register tokens in the evm (#52)
mfornet 9143800
rustfmt
mfornet 1b97f2c
rename gas related costs
mfornet ebcda33
Implement ft_on_transfer and register_relayer
mfornet 6d7da99
Add custom erc20 contract to the EVM. (#53)
mfornet f7b71c5
Adapt ERC20 connector to the new interface
mfornet 6680a51
Fix deploy_erc20 and add tests
mfornet fd3a1da
Process Input/Output in ft_on_transfer
mfornet 21d2a0f
Fix ft_on_transfer
mfornet 55fa12a
Tests and fix ft_on_transfer
mfornet ee7d789
Implement exit to near
mfornet 3328bb8
Implement exit to Ethereum
mfornet c848791
Fix input
mfornet 75a5af2
Merge branch 'erc20-precompiles' into develop
mfornet 1b44941
Added standard cargo clippy action
mrLSD b216463
Use newer version of evm
mfornet a977480
Add state to precompiles
mfornet eb4690f
Next reformatting to run tests without contract features
mfornet 072c84f
cargo test is working
mfornet 183521f
Remove warnings
mfornet 77c42f7
Merge remote-tracking branch 'origin/erc20-precompiles' into erc20-pr…
mfornet 638e59a
Schedule promise call
mfornet af82972
Use flags for precompiles + abi.encodePacked
mfornet ee48453
Use is_static for precompiles
mfornet 083dbe0
Fail on static function + schedule promise
mfornet 439fe10
Apply promises and add bijection map
mfornet 562c9e1
Address comments from Michael
mfornet a2f2eef
Fix tests
mfornet 61a2a04
Add tests for stakc
mfornet 58c928a
Build testing contract
mfornet 8f3dbc3
Fix docker tests
mfornet 82831a1
Fix mint tests
mfornet 2c18046
Test exit functions
mfornet 4548125
Merge branch 'develop' into erc20-precompiles
mfornet fde10b0
Address comments
mfornet 7766216
Fix solidity linter
mfornet b0d5836
Fix clippy
mfornet d51fd7c
Fix tests
mfornet 7b0e89c
Fix CI (1)
mfornet 3d0ff4e
Update state_migration_test
mfornet 7cc2741
Check without cache
mfornet 138bc2f
Use lazy-static directly
birchmd 9db448d
Revert "Check without cache"
birchmd d50a04a
Update get_evicted and gas_limit
mfornet e5a7459
Merge branch 'develop' into erc20-precompiles
mfornet 8fca125
Use EVM dependency from sputnik
mfornet b03e1c2
Ignore lint for test solidity contract
mfornet d2106cb
nit
mfornet 386fcde
Add doc string for register_len
mfornet d323edd
Update promise error
mfornet f643c8e
Update interface to communicate with token-connector
mfornet 9a58ab1
Fix precompile for eth-connector
mfornet fdcaf44
Merge branch 'develop' into erc20-precompiles
mfornet 3b10f8c
Refactor after merge
mfornet f5a3530
Use Json for NEP141 interface
mfornet 221a3fd
Merge remote-tracking branch 'origin/develop' into erc20-precompiles
mfornet c95e3af
Use clippy suggestion
mfornet abc8641
Fix failing tests
mfornet 3f46802
Use upstream sputnik vm
mfornet 9cfb2fe
Use pre-computed selector
mfornet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| node_modules | ||
|
|
||
| # solium fails to run linter in Tester.sol | ||
| # see issue for more details: https://github.com/duaraghav8/Ethlint/issues/293 | ||
| contracts/test/Tester.sol | ||
|
|
||
| # solium fails to run linter in Tester.sol | ||
| # see issue for more details: https://github.com/duaraghav8/Ethlint/issues/294 | ||
| contracts/test/StateTest.sol |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,4 @@ | |
| "security/no-block-members": ["off"], | ||
| "security/no-inline-assembly": ["warning"] | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // SPDX-License-Identifier: CC0 1.0 Universal | ||
| pragma solidity ^0.8.0; | ||
|
|
||
|
|
||
| contract AdminControlled { | ||
| address public admin; | ||
| uint public paused; | ||
|
|
||
| constructor(address _admin, uint flags) { | ||
| admin = _admin; | ||
|
|
||
| // Add the possibility to set pause flags on the initialization | ||
| paused = flags; | ||
| } | ||
|
|
||
| modifier onlyAdmin { | ||
| require(msg.sender == admin); | ||
| _; | ||
| } | ||
|
|
||
| modifier pausable(uint flag) { | ||
| require((paused & flag) == 0 || msg.sender == admin); | ||
| _; | ||
| } | ||
|
|
||
| function adminPause(uint flags) public onlyAdmin { | ||
| paused = flags; | ||
| } | ||
|
|
||
| function adminSstore(uint key, uint value) public onlyAdmin { | ||
| assembly { | ||
| sstore(key, value) | ||
| } | ||
| } | ||
|
|
||
| function adminSendEth(address payable destination, uint amount) public onlyAdmin { | ||
| destination.transfer(amount); | ||
| } | ||
|
|
||
| function adminReceiveEth() public payable onlyAdmin {} | ||
|
|
||
| function adminDelegatecall(address target, bytes memory data) public payable onlyAdmin returns (bytes memory) { | ||
| (bool success, bytes memory rdata) = target.delegatecall(data); | ||
| require(success); | ||
| return rdata; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // SPDX-License-Identifier: CC0 1.0 Universal | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "@openzeppelin/contracts/utils/Context.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
| import "./AdminControlled.sol"; | ||
| import "./IExit.sol"; | ||
|
|
||
|
|
||
| /** | ||
| * @title SimpleToken | ||
| * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator. | ||
| * Note they can later distribute these tokens as they wish using `transfer` and other | ||
| * `ERC20` functions. | ||
| */ | ||
| contract EvmErc20 is Context, ERC20, AdminControlled, IExit { | ||
| uint8 private _decimals; | ||
|
|
||
| constructor (string memory name, string memory symbol, uint8 decimal, address admin) ERC20(name, symbol) AdminControlled(admin, 0) { | ||
| _decimals = decimal; | ||
| } | ||
|
|
||
| function decimals() public view override returns (uint8) { | ||
| return _decimals; | ||
| } | ||
|
|
||
| function mint(address account, uint256 amount) public onlyAdmin { | ||
| _mint(account, amount); | ||
| } | ||
|
|
||
| function withdrawToNear(bytes memory recipient, uint256 amount) external override { | ||
| _burn(msg.sender, amount); | ||
|
|
||
| bytes32 amount_b = bytes32(amount); | ||
| bytes memory input = abi.encodePacked("\x01", amount_b, recipient); | ||
| uint input_size = 1 + 32 + recipient.length; | ||
|
|
||
| assembly { | ||
| let res := staticcall(gas(), 0xe9217bc70b7ed1f598ddd3199e80b093fa71124f, add(input, 32), input_size, 0, 32) | ||
| } | ||
| } | ||
|
|
||
| function withdrawToEthereum(address recipient, uint256 amount) external override { | ||
| _burn(msg.sender, amount); | ||
|
|
||
| bytes32 amount_b = bytes32(amount); | ||
| bytes20 recipient_b = bytes20(recipient); | ||
| bytes memory input = abi.encodePacked("\x01", amount_b, recipient_b); | ||
| uint input_size = 1 + 32 + 20; | ||
|
|
||
| assembly { | ||
| let res := staticcall(gas(), 0xb0bd02f6a392af548bdf1cfaee5dfa0eefcc8eab, add(input, 32), input_size, 0, 32) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-License-Identifier: CC0 1.0 Universal | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| interface IExit { | ||
| function withdrawToNear(bytes memory recipient, uint256 amount) external; | ||
|
|
||
| function withdrawToEthereum(address recipient, uint256 amount) external; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // SPDX-License-Identifier: CC0 1.0 Universal | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "../IExit.sol"; | ||
|
|
||
| contract Tester { | ||
| IExit public erc20Token; | ||
|
|
||
| constructor (IExit _erc20Token) { | ||
| erc20Token = _erc20Token; | ||
| } | ||
|
|
||
| function helloWorld(string memory name) public pure returns(string memory) { | ||
| return string(abi.encodePacked("Hello ", name, "!")); | ||
| } | ||
|
|
||
| // Use flag to indicate if should withdraw to NEAR (true) or to Ethereum (false) | ||
| function withdraw(bool toNear) external { | ||
| if (toNear) { | ||
| erc20Token.withdrawToNear("target.aurora", 1); | ||
| } else { | ||
| erc20Token.withdrawToEthereum(0xE0f5206BBD039e7b0592d8918820024e2a7437b9, 1); | ||
| } | ||
| } | ||
|
|
||
| function withdrawAndFail(bool toNear) external { | ||
| this.withdraw(toNear); | ||
| require(false); | ||
| } | ||
|
|
||
| function tryWithdrawAndAvoidFail(bool toNear) external { | ||
| try this.withdrawAndFail(toNear) { | ||
| require(false); | ||
| } catch { | ||
| } | ||
| } | ||
|
|
||
| function tryWithdrawAndAvoidFailAndSucceed(bool toNear) external { | ||
| this.tryWithdrawAndAvoidFail(toNear); | ||
| this.withdraw(toNear); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const artifact = require(process.argv[2]); | ||
| if (!fs.existsSync('res')) { | ||
| fs.mkdirSync('res'); | ||
| } | ||
| fs.writeFileSync(path.join('res', 'EvmErc20.hex'), artifact.bytecode); | ||
| fs.writeFileSync(path.join('res', 'EvmErc20.bin'), Buffer.from(artifact.bytecode.substring(2), 'hex')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.