Skip to content

Commit

Permalink
Implement generational storage (#87)
Browse files Browse the repository at this point in the history
* Base precompile code between connectors (#73)

* Base precompile code between connectors

* Handle errors and validate input

* Use proper result

* Document `aurora encode-address` usage.

* Cache cargo artifacts between CI runs. (#92)

* Address comments from audit. (#86)

* Validate register length in `read_input_arr20()`
* Only read register length in `Engine::get_code_size`
* Add `read_input_borsh()`
* Ensure `method.args.len() == args_decoded.len()`
* Ensure register size is 8 in `read_u64`
* Use constant to specify the register ID used in `read_input()`

* Reduce size of `cargo cache` in CI. (#95)

* Define a `Wei` newtype for balances. (#96)

* Fix evm-bully builds after recent refactoring. (#100)

* Refactor `Engine::get_state` to return a `Result`. (#99)

* Ensure that `Cargo.lock` in the repo is valid. (#101)

* Remove unneeded nightly feature. (#102)

* Implement BC generational storage.

* fix address input

* remove note

* put key on the end of the storage key

* remove pub from methods

* Dispatch precompiles on the full address. (#107)

* Support state migration on upgrade. (#103)

* Implement the ETH connector. (#59)

* Move when to call `set_generation`

* Fix arg

Co-authored-by: Marcelo Fornet <mfornet94@gmail.com>
Co-authored-by: Arto Bendiken <arto@aurora.dev>
Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Evgeny Ukhanov <mrlsd@ya.ru>
  • Loading branch information
6 people committed Jun 4, 2021
1 parent aaf1ed9 commit d67b59e
Show file tree
Hide file tree
Showing 45 changed files with 5,452 additions and 358 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ jobs:
steps:
- name: Clone the repository
uses: actions/checkout@v2
- name: Cache Cargo artifacts
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install the toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-03-25
override: true
- run: make release
- run: ls -lH release.wasm
- run: make test-build
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
args: --locked --verbose
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Rust artifacts
/*.wasm
/target/
etc/state-migration-test/target/

node_modules/
artifacts/
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ wee_alloc = { version = "0.4.5", default-features = false }
lunarity-lexer = { git = "https://github.com/ilblackdragon/lunarity", rev = "5201d9a76f7e491082b7f74af7e64049271e387f", default-features = false }
ethabi = { git = "https://github.com/darwinia-network/ethabi", branch = "xavier-no-std", default-features = false }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
byte-slice-cast = { version = "1.0", default-features = false }
rjson = { version = "0.3.1", default-features = false }

[dev-dependencies]
Expand All @@ -76,5 +77,9 @@ git2 = "0.13"
default = ["sha2", "std"]
std = ["borsh/std", "evm/std", "primitive-types/std", "rlp/std", "sha3/std", "ethabi/std", "lunarity-lexer/std", "bn/std"]
testnet = []
contract = []
engine = []
contract = ["engine"]
evm_bully = []
log = []
exit-precompiles = ["contract"]
integration-test = ["log"]
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CARGO = cargo
NEAR = near
FEATURES = contract
FEATURES = contract,log

ifeq ($(evm-bully),yes)
FEATURES := $(FEATURES),evm_bully
Expand All @@ -15,6 +15,7 @@ release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm

target/wasm32-unknown-unknown/release/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs)
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

debug: debug.wasm

Expand All @@ -24,8 +25,10 @@ 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

etc/eth-contracts/artifacts/contracts/StateTest.sol/SelfDestructFactory.json: etc/eth-contracts/contracts/StateTest.sol
cd etc/eth-contracts && yarn && yarn compile
test-build:
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

.PHONY: all release debug

Expand All @@ -38,10 +41,10 @@ check-format:
$(CARGO) fmt -- --check

check-clippy:
$(CARGO) +nightly clippy --no-default-features --features=$(FEATURES) -- -D warnings
$(CARGO) clippy --no-default-features --features=$(FEATURES) -- -D warnings

# test depends on release since `tests/test_upgrade.rs` includes `release.wasm`
test: release etc/eth-contracts/artifacts/contracts/StateTest.sol/SelfDestructFactory.json
test: test-build
$(CARGO) test

format:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ aurora deploy-code 0x600060005560648060106000396000f360e060020a6000350480638ada0

### Examining EVM contract state

```console
$ aurora encode-address test.near
0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B
```

```sh
aurora get-nonce 0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B
aurora get-balance 0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B
Expand All @@ -127,6 +132,11 @@ aurora get-storage-at 0xFc481F4037887e10708552c0D7563Ec6858640d6 0

### Calling an EVM contract read-only

```console
$ aurora encode-address test.near
0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B
```

```sh
aurora view --sender 0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B 0xFc481F4037887e10708552c0D7563Ec6858640d6 0x8ada066e # getCounter()
aurora view --sender 0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B 0xFc481F4037887e10708552c0D7563Ec6858640d6 0xd09de08a # increment()
Expand Down
42 changes: 42 additions & 0 deletions doc/eth-connector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ETH connector

## Build
1. For production set in the Makefile
```
FEATURES = contract
```
1.1. For **development and testing** set in the Makefile
```
FEATURES = contract,integration-test
```
2. Build release: `$ make release`
3. Run tests: `$ cargo test`
4. Deploying process is common for Aurora itself. Please reference [README.md](../README.md)

## Initialize eth-conenctor
With `near-cli` run:
```
$ near call <NEAR_ACC> new_eth_connector '{"prover_account": "<PROVER_NEAR_ACCOUNT>", "eth_custodian_address": "<ETH_ADDRESS>"}' --account-id <NEAR_ACC>
```

## ETH connector specific methods
* new_eth_connector (call once)
* deposit (mutable)
* withdraw (mutable, payable)
* finish_deposit_near (private, mutable)
* ft_total_supply (view)
* ft_total_supply_near (view)
* ft_total_supply_eth (view)
* ft_balance_of (view)
* ft_balance_of_eth (view)
* ft_transfer (mutable, payable)
* ft_resolve_transfer (private, mutable)
* ft_transfer_call (mutable, payable)
* ft_on_transfer (private, mutable)
* storage_deposit (mutable)
* storage_withdraw (mutable, payable)
* storage_balance_of (view)

## Ethereum specific flow
Follow by [this instruction](https://github.com/aurora-is-near/eth-connector/blob/master/README.md).

0 comments on commit d67b59e

Please sign in to comment.