Skip to content
Merged
Show file tree
Hide file tree
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 Apr 27, 2021
c4b85a9
Update required precompiles for ERC20-Connector
mfornet May 4, 2021
88faeec
fix style and refactor
joshuajbouw May 4, 2021
f54d3ab
Address comments
mfornet May 4, 2021
17fb6a6
Add map to register tokens in the evm (#52)
mfornet May 4, 2021
9143800
rustfmt
mfornet May 4, 2021
1b97f2c
rename gas related costs
mfornet May 4, 2021
ebcda33
Implement ft_on_transfer and register_relayer
mfornet May 5, 2021
6d7da99
Add custom erc20 contract to the EVM. (#53)
mfornet May 6, 2021
f7b71c5
Adapt ERC20 connector to the new interface
mfornet May 6, 2021
6680a51
Fix deploy_erc20 and add tests
mfornet May 7, 2021
fd3a1da
Process Input/Output in ft_on_transfer
mfornet May 8, 2021
21d2a0f
Fix ft_on_transfer
mfornet May 8, 2021
55fa12a
Tests and fix ft_on_transfer
mfornet May 8, 2021
ee7d789
Implement exit to near
mfornet May 10, 2021
3328bb8
Implement exit to Ethereum
mfornet May 10, 2021
c848791
Fix input
mfornet May 11, 2021
75a5af2
Merge branch 'erc20-precompiles' into develop
mfornet May 13, 2021
1b44941
Added standard cargo clippy action
mrLSD May 20, 2021
b216463
Use newer version of evm
mfornet May 21, 2021
a977480
Add state to precompiles
mfornet May 21, 2021
eb4690f
Next reformatting to run tests without contract features
mfornet May 21, 2021
072c84f
cargo test is working
mfornet May 21, 2021
183521f
Remove warnings
mfornet May 21, 2021
77c42f7
Merge remote-tracking branch 'origin/erc20-precompiles' into erc20-pr…
mfornet May 21, 2021
638e59a
Schedule promise call
mfornet May 21, 2021
af82972
Use flags for precompiles + abi.encodePacked
mfornet May 29, 2021
ee48453
Use is_static for precompiles
mfornet May 29, 2021
083dbe0
Fail on static function + schedule promise
mfornet May 29, 2021
439fe10
Apply promises and add bijection map
mfornet May 29, 2021
562c9e1
Address comments from Michael
mfornet May 31, 2021
a2f2eef
Fix tests
mfornet May 31, 2021
61a2a04
Add tests for stakc
mfornet May 31, 2021
58c928a
Build testing contract
mfornet May 31, 2021
8f3dbc3
Fix docker tests
mfornet May 31, 2021
82831a1
Fix mint tests
mfornet Jun 3, 2021
2c18046
Test exit functions
mfornet Jun 3, 2021
4548125
Merge branch 'develop' into erc20-precompiles
mfornet Jun 8, 2021
fde10b0
Address comments
mfornet Jun 8, 2021
7766216
Fix solidity linter
mfornet Jun 8, 2021
b0d5836
Fix clippy
mfornet Jun 8, 2021
d51fd7c
Fix tests
mfornet Jun 8, 2021
7b0e89c
Fix CI (1)
mfornet Jun 9, 2021
3d0ff4e
Update state_migration_test
mfornet Jun 9, 2021
7cc2741
Check without cache
mfornet Jun 9, 2021
138bc2f
Use lazy-static directly
birchmd Jun 9, 2021
9db448d
Revert "Check without cache"
birchmd Jun 9, 2021
d50a04a
Update get_evicted and gas_limit
mfornet Jun 9, 2021
e5a7459
Merge branch 'develop' into erc20-precompiles
mfornet Jun 10, 2021
8fca125
Use EVM dependency from sputnik
mfornet Jun 10, 2021
b03e1c2
Ignore lint for test solidity contract
mfornet Jun 10, 2021
d2106cb
nit
mfornet Jun 10, 2021
386fcde
Add doc string for register_len
mfornet Jun 10, 2021
d323edd
Update promise error
mfornet Jun 10, 2021
f643c8e
Update interface to communicate with token-connector
mfornet Jun 16, 2021
9a58ab1
Fix precompile for eth-connector
mfornet Jun 16, 2021
fdcaf44
Merge branch 'develop' into erc20-precompiles
mfornet Jun 16, 2021
3b10f8c
Refactor after merge
mfornet Jun 16, 2021
f5a3530
Use Json for NEP141 interface
mfornet Jun 17, 2021
221a3fd
Merge remote-tracking branch 'origin/develop' into erc20-precompiles
mfornet Jun 17, 2021
c95e3af
Use clippy suggestion
mfornet Jun 17, 2021
abc8641
Fix failing tests
mfornet Jun 17, 2021
3f46802
Use upstream sputnik vm
mfornet Jun 17, 2021
9cfb2fe
Use pre-computed selector
mfornet Jun 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,23 @@ jobs:
toolchain: nightly-2021-03-25
override: true
components: clippy
- name: Run cargo clippy
- run: make etc/eth-contracts/res/EvmErc20.bin
- name: Run Contract cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --no-default-features --features=contract -- -D warnings
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy

contracts:
name: eth-contracts
runs-on: ubuntu-latest
steps:
- name: Clone the repository
uses: actions/checkout@v2
- name: Run yarn lint
working-directory: etc/eth-contracts
run: yarn && yarn lint
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@
# Rust artifacts
/*.wasm
/target/
etc/state-migration-test/target/

# Solidity artifacts
artifacts/
cache/
node_modules/
res/

# Other
etc/state-migration-test/target/

node_modules/*
artifacts/
cache
cache
18 changes: 10 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ rpath = false
blake2 = { git = "https://github.com/near/near-blake2.git", version = "0.9.1", default-features = false }
borsh = { version = "0.8.2", default-features = false }
bn = { package = "aurora-bn", git = "https://github.com/aurora-is-near/aurora-bn.git", default-features = false }
evm = { version = "0.27.0", default-features = false }
evm-core = { version = "0.27.1", default-features = false }
evm = { version = "0.28.0", default-features = false }
evm-core = { version = "0.28.0", default-features = false }
libsecp256k1 = { version = "0.3.5", default-features = false }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
primitive-types = { version = "0.9.0", default-features = false, features = ["rlp"] }
Expand Down Expand Up @@ -72,6 +72,8 @@ libsecp256k1 = "0.3.5"
rand = "0.7.3"
criterion = "0.3.4"
git2 = "0.13"
lazy-static-include = "3.1.1"
base64 = "0.13.0"

[features]
default = ["sha2", "std"]
Expand Down
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CARGO = cargo
NEAR = near
FEATURES = contract,log
Comment thread
mfornet marked this conversation as resolved.
FEATURES = contract,log,exit-precompiles

ifeq ($(evm-bully),yes)
FEATURES := $(FEATURES),evm_bully
Expand All @@ -13,11 +13,14 @@ release: release.wasm
release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm
ln -sf $< $@

target/wasm32-unknown-unknown/release/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs)
target/wasm32-unknown-unknown/release/aurora_engine.wasm: Cargo.toml Cargo.lock $(shell find src -name "*.rs") etc/eth-contracts/res/EvmErc20.bin
RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=$(FEATURES) -Z avoid-dev-deps
ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm
ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm

etc/eth-contracts/artifacts/contracts/StateTest.sol/StateTest.json: $(shell find etc/eth-contracts/contracts -name "*.sol") etc/eth-contracts/package.json
etc/eth-contracts/res/EvmErc20.bin: $(shell find etc/eth-contracts/contracts -name "*.sol") etc/eth-contracts/package.json
cd etc/eth-contracts && yarn && yarn build

etc/eth-contracts/artifacts/contracts/test/StateTest.sol/StateTest.json: $(shell find etc/eth-contracts/contracts -name "*.sol") etc/eth-contracts/package.json
cd etc/eth-contracts && yarn && yarn build

debug: debug.wasm
Expand All @@ -28,12 +31,12 @@ debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm
target/wasm32-unknown-unknown/debug/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs)
$(CARGO) build --target wasm32-unknown-unknown --no-default-features --features=$(FEATURES) -Z avoid-dev-deps

test-build: etc/eth-contracts/artifacts/contracts/StateTest.sol/StateTest.json
RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=contract,integration-test -Z avoid-dev-deps
ln -sf target/wasm32-unknown-unknown/release/aurora_engine.wasm release.wasm
ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm
test-build: etc/eth-contracts/artifacts/contracts/test/StateTest.sol/StateTest.json etc/eth-contracts/res/EvmErc20.bin
RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=contract,integration-test,exit-precompiles -Z avoid-dev-deps
ln -sf target/wasm32-unknown-unknown/release/aurora_engine.wasm release.wasm
ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm

.PHONY: all release debug
.PHONY: all release debug eth-contracts

deploy: release.wasm
$(NEAR) deploy --account-id=$(or $(NEAR_EVM_ACCOUNT),aurora.test.near) --wasm-file=$<
Expand Down
8 changes: 8 additions & 0 deletions etc/eth-contracts/.soliumignore
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
2 changes: 1 addition & 1 deletion etc/eth-contracts/.soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"security/no-block-members": ["off"],
"security/no-inline-assembly": ["warning"]
}
}
}
47 changes: 47 additions & 0 deletions etc/eth-contracts/contracts/AdminControlled.sol
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;
}
}
55 changes: 55 additions & 0 deletions etc/eth-contracts/contracts/EvmErc20.sol
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)
}
}
}
8 changes: 8 additions & 0 deletions etc/eth-contracts/contracts/IExit.sol
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;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// SPDX-License-Identifier: CC0 1.0 Universal
pragma solidity ^0.8.0;


contract SelfDestruct {
uint256 public counter;

constructor() public {
}
constructor() { }

function increase() public {
counter += 1;
Expand All @@ -15,9 +16,9 @@ contract SelfDestruct {
}
}


contract SelfDestructFactory {
constructor() public {
}
constructor() { }

function deploy() public returns(address) {
address addr = address(new SelfDestruct{salt: bytes32(uint256(0x1234))}());
Expand Down
42 changes: 42 additions & 0 deletions etc/eth-contracts/contracts/test/Tester.sol
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);
}
}
8 changes: 8 additions & 0 deletions etc/eth-contracts/main.js
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'));
5 changes: 3 additions & 2 deletions etc/eth-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"solium": "^1.2.5"
},
"scripts": {
"build": "hardhat compile",
"compile": "hardhat compile",
"build": "yarn compile && node main.js ./artifacts/contracts/EvmErc20.sol/EvmErc20.json",
"test": "hardhat test",
"coverage": "hardhat coverage",
"lint:js": "eslint .",
Expand All @@ -33,4 +34,4 @@
"lint": "yarn lint:js && yarn lint:sol",
"lint:fix": "yarn lint:js:fix && yarn lint:sol:fix"
}
}
}
Loading