Skip to content

Commit

Permalink
LoaderV2 integration (#139)
Browse files Browse the repository at this point in the history
* wip: apply loader v2, need to fix move to json error

* copy type conversion functions from runtime loader & handle json parsing error

* bump aptos core loader v2 version

* introduce InitiaModuleStorage using LRU module cache

* introduce InitiaCodeStorage to connect InitiaModuleStorage

* manage module cache as a single unit within the Initia VM

* manage script cache as a single unit within the Initia VM

* fmt and clippy

* compiled module & script interface change

* use custom move (#140)

* update rust version

* clone runtime_environment on every call

* introduce lock on cache (#141)

* use aptor-core move & flush type_cache every vm call

* not cloning environment with flushed ty_cache

* fix coderabbit audit

* feat: deps code upgrade policy check (#144)

* upgrade policy check to dependency modules

* fix broken tests

* pass policy check if dep is stdlib

* add code publish tests

* fmt and clippy

* feat: implement flashswap (#142)

* implement flashswap

* fix typo;

* fix missing pool_amounts conversion

* change the impl to use hot potato pattern

* fix typo and add borrow_amounts read function

* rename get_borrow_amounts

* movefmt

* lock the pool at flash swap and disallow provide liquidity and swap operations

* add testcases

* fmt and rebuild

* lock first before calling external functoins

* add flash swap event

* feat: support multisend cosmos interface (#143)

* introduce multisend

* remove unused from minitia_stdlib

* add comments for the error handlings

* change to call move function instead of reading table context data (#147)

* change to call move function instead of reading table context data

* lint

* change to do not receive module_ids

---------

Co-authored-by: beer-1 <[email protected]>
Co-authored-by: beer-1 <[email protected]>

* apply recent aptos update making struct index map to arc

* calculate cache size using real heap size

* fmt clippy

* add storage & code conversion test

* fix script access specifier

* add code scale test code to be used in e2e test & debug code to identify equal structs

* add panic handling when fetching size

* apply merged version

* Feat/refactor native code (#154)

* change upgrade policy u8 to enum

* code test cleanup & use loaderv2 as default

* code module type

* typo

* nit error message change

* cleanup module cache code

* nit error message

* delete type conversion funcs from sessionExt & use them from session directly

* use 1 as cache weight for all cache items

* minor lint fix

* feat: use constant cache weight for all modules & scripts (#156)

* use 1 as cache weight for all cache items

* small refactor

---------

Co-authored-by: beer-1 <[email protected]>
Co-authored-by: beer-1 <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent f7e687c commit 7255fbd
Show file tree
Hide file tree
Showing 174 changed files with 3,364 additions and 976 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[env]

RUST_BIGDECIMAL_FMT_EXPONENTIAL_UPPER_THRESHOLD="100"
RUST_BIGDECIMAL_FMT_EXPONENTIAL_LOWER_THRESHOLD="100"
RUST_BIGDECIMAL_FMT_EXPONENTIAL_LOWER_THRESHOLD="100"
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install latest rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77.1
toolchain: 1.80.1
override: true
components: rustfmt, clippy
- uses: actions/setup-go@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Install latest rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77.1
toolchain: 1.80.1
- name: Build Rust
run: make build-rust
- uses: actions/setup-go@v4
Expand Down
105 changes: 54 additions & 51 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ license = "BUSL-1.1"
license-file = "LICENSE"
homepage = "https://initia.xyz"
repository = "https://github.com/initia-labs/movevm"
rust-version = "1.77.1"
rust-version = "1.80.1"

[workspace.dependencies]
# Internal crate dependencies.
Expand All @@ -65,9 +65,11 @@ initia-move-resource-viewer = { path = "crates/resource-viewer" }

# External crate dependencies.
# Please do not add any test features here: they should be declared by the individual crate.
anyhow = "1.0.41"
bcs = "0.1.5"
ambassador = "0.4.1"
anyhow = "1.0.71"
bcs = { git = "https://github.com/aptos-labs/bcs.git", rev = "d31fab9d81748e2594be5cd5cdf845786a30562d" }
better_any = "0.1.1"
claims = "0.7"
clru = "^0.6.2"
cbindgen = "0.26.0"
clap = { version = "4.3.9", features = ["derive", "env", "suggestions"] }
Expand All @@ -76,7 +78,7 @@ dialoguer = "0.10.2"
ed25519-consensus = { version = "2.0.1", features = ["serde"] }
errno = "0.3.0"
hex = { version = "0.4.3", default-features = false }
itertools = "0.10.3"
itertools = "0.13"
libsecp256k1 = { version = "0.7.1" }
log = { version = "0.4.17", features = [
"max_level_debug",
Expand All @@ -95,16 +97,17 @@ serde-generate = { git = "https://github.com/aptos-labs/serde-reflection", rev =
serde-reflection = { git = "https://github.com/aptos-labs/serde-reflection", rev = "73b6bbf748334b71ff6d7d09d06a29e3062ca075" }
sha2 = "0.10.8"
sha3 = "0.10.6"
smallvec = "1.6.1"
smallvec = "1.8.0"
smallbitvec = "2.5.1"
tempfile = "3.2.0"
tempfile = "3.3.0"
serial_test = "1.0.0"
thiserror = "1.0.34"
thiserror = "1.0.37"
tsu = "1.0.1"
bytes = "1.4.0"
parking_lot = "0.12.1"
base64 = "0.21.7"
bigdecimal = ">=0.4.5"
primitive-types = { version = "0.10" }
bech32 = "0.11"
triomphe = "0.1.9"
ripemd = "0.1.1"
Expand All @@ -113,51 +116,51 @@ tiny-keccak = { version = "2.0.2", features = ["keccak", "sha3"] }
# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES

move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-bytecode-verifier = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-bytecode-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-core-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-docgen = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-model = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-package = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-prover-boogie-backend = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-prover-bytecode-pipeline = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-resource-viewer = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-stackless-bytecode = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-stdlib = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-vm-test-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-vm-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "85966af7ddcf971f3f04f4f409c3e67c9d9b11cb" }
move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-bytecode-verifier = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-bytecode-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-core-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-docgen = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-model = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-package = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-prover-boogie-backend = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-prover-bytecode-pipeline = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-resource-viewer = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-stackless-bytecode = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-stdlib = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-vm-test-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }
move-vm-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" }

# END MOVE DEPENDENCIES

# FOR LOCAL DEVELOPMENNT
# move-binary-format = { path = "../aptos-core/third_party/move/move-binary-format" }
# move-bytecode-verifier = { path = "../aptos-core/third_party/move/move-bytecode-verifier" }
# move-bytecode-utils = { path = "../aptos-core/third_party/move/tools/move-bytecode-utils" }
# move-cli = { path = "../aptos-core/third_party/move/tools/move-cli" }
# move-command-line-common = { path = "../aptos-core/third_party/move/move-command-line-common" }
# move-compiler = { path = "../aptos-core/third_party/move/move-compiler" }
# move-coverage ={ path = "../aptos-core/third_party/move/tools/move-coverage" }
# move-core-types = { path = "../aptos-core/third_party/move/move-core/types" }
# move-docgen = { path = "../aptos-core/third_party/move/move-prover/move-docgen" }
# move-model = { path = "../aptos-core/third_party/move/move-model" }
# move-package = { path = "../aptos-core/third_party/move/tools/move-package" }
# move-prover = { path = "../aptos-core/third_party/move/move-prover" }
# move-prover-boogie-backend = { path = "../aptos-core/third_party/move/move-prover/boogie-backend" }
# move-prover-bytecode-pipeline = { path = "../aptos-core/third_party/move/move-prover/bytecode-pipeline" }
# move-resource-viewer = { path = "../aptos-core/third_party/move/tools/move-resource-viewer" }
# move-stackless-bytecode = { path = "../aptos-core/third_party/move/move-model/bytecode" }
# move-stdlib = { path = "../aptos-core/third_party/move/move-stdlib" }
# move-symbol-pool = { path = "../aptos-core/third_party/move/move-symbol-pool" }
# move-unit-test = { path = "../aptos-core/third_party/move/tools/move-unit-test" }
# move-vm-runtime = { path = "../aptos-core/third_party/move/move-vm/runtime" }
# move-vm-test-utils = { path = "../aptos-core/third_party/move/move-vm/test-utils" }
# move-vm-types = { path = "../aptos-core/third_party/move/move-vm/types" }
# move-binary-format = { path = "../move/move-binary-format" }
# move-bytecode-verifier = { path = "../move/move-bytecode-verifier" }
# move-bytecode-utils = { path = "../move/tools/move-bytecode-utils" }
# move-cli = { path = "../move/tools/move-cli" }
# move-command-line-common = { path = "../move/move-command-line-common" }
# move-compiler = { path = "../move/move-compiler" }
# move-coverage ={ path = "../move/tools/move-coverage" }
# move-core-types = { path = "../move/move-core/types" }
# move-docgen = { path = "../move/move-prover/move-docgen" }
# move-model = { path = "../move/move-model" }
# move-package = { path = "../move/tools/move-package" }
# move-prover = { path = "../move/move-prover" }
# move-prover-boogie-backend = { path = "../move/move-prover/boogie-backend" }
# move-prover-bytecode-pipeline = { path = "../move/move-prover/bytecode-pipeline" }
# move-resource-viewer = { path = "../move/tools/move-resource-viewer" }
# move-stackless-bytecode = { path = "../move/move-model/bytecode" }
# move-stdlib = { path = "../move/move-stdlib" }
# move-symbol-pool = { path = "../move/move-symbol-pool" }
# move-unit-test = { path = "../move/tools/move-unit-test" }
# move-vm-runtime = { path = "../move/move-vm/runtime" }
# move-vm-test-utils = { path = "../move/move-vm/test-utils" }
# move-vm-types = { path = "../move/move-vm/types" }
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test-safety:
# Use package list mode to include all subdirectores. The -count=1 turns off caching.
GODEBUG=cgocheck=2 go test -race -v -count=1 -parallel=1 ./...

test-rust: test-compiler test-lib test-e2e test-movevm test-json
test-rust: test-compiler test-lib test-e2e test-movevm test-json test-storage

test-compiler:
cargo test -p initia-move-compiler
Expand All @@ -67,6 +67,9 @@ test-json:
test-lib:
cargo test -p initia-move-vm

test-storage:
cargo test -p initia-move-storage

test-e2e:
cargo test -p e2e-move-tests --features testing

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Initia MoveVM

The Initia MoveVM is forked from [wasmvm](https://github.com/CosmWasm/wasmvm) with some modifications to support ([Aptos](https://github.com/aptos-labs/aptos-core)) MoveVM.
This mechanism allows the users to compile, initialize, and execute Move Smart Contracts from Go applications, in particular from [x/move](https://github.com/initia-labs/initia/tree/main/x/move).

Expand All @@ -8,7 +9,7 @@ This repo contains both Rust and Go codes. The rust code is compiled into a dll/

## Supported Platform

Requires **Rust 1.77+ and Go 1.22+.**
Requires **Rust 1.80+ and Go 1.22+.**

The Rust implementation of the VM is compiled to a library called libmovevm. This is then linked to the Go code when the final binary is built. For that reason not all systems supported by Go are supported by this project.

Expand Down Expand Up @@ -44,4 +45,4 @@ There are two parts to this code - go and rust. The first step is to ensure that

If this is present, then `make test` will run the Go test suite and you can import this code freely. If it is not present you will have to build it for your system, and ideally add it to this repo with a PR (on your fork). We will set up a proper CI system for building these binaries, but we are not there yet.

To build the rust side, try make `build-rust` and wait for it to compile. This depends on `cargo` being installed with rustc version 1.77+. Generally, you can just use rustup to install all this with no problems.
To build the rust side, try make `build-rust` and wait for it to compile. This depends on `cargo` being installed with rustc version 1.80+. Generally, you can just use rustup to install all this with no problems.
2 changes: 1 addition & 1 deletion builders/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN set -eux \

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/rustup-init" \
&& chmod +x rustup-init \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.77.1 \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.80.1 \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME

Expand Down
2 changes: 1 addition & 1 deletion builders/Dockerfile.centos7
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ENV RUSTUP_HOME=/usr/local/rustup \

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" \
&& chmod +x rustup-init \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.77.1 \
&& ./rustup-init -y --no-modify-path --profile minimal --default-toolchain 1.80.1 \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
&& rustup --version \
Expand Down
2 changes: 1 addition & 1 deletion builders/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.77.1-bullseye
FROM rust:1.80.1-bullseye

# Install build dependencies
RUN apt-get update \
Expand Down
11 changes: 6 additions & 5 deletions crates/compiler/src/unit_test_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ impl InitiaUnitTestFactory {
let table_change_set = table_context
.into_change_set()
.map_err(|e| e.finish(Location::Undefined))?;
let write_set = WriteSet::new(changes.clone(), table_change_set).map_err(|e| {
PartialVMError::new(StatusCode::FAILED_TO_SERIALIZE_WRITE_SET_CHANGES)
.with_message(e.to_string())
.finish(Location::Undefined)
})?;
let write_set =
WriteSet::new_with_change_set(changes.clone(), table_change_set).map_err(|e| {
PartialVMError::new(StatusCode::FAILED_TO_SERIALIZE_WRITE_SET_CHANGES)
.with_message(e.to_string())
.finish(Location::Undefined)
})?;

gas_meter.charge_write_set_gas(&write_set)?;

Expand Down
1 change: 1 addition & 0 deletions crates/e2e-move-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ default = []
testing = [
"initia-move-gas/testing",
"initia-move-natives/testing",
"initia-move-storage/testing",
"move-vm-runtime/testing",
]
Loading

0 comments on commit 7255fbd

Please sign in to comment.