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

fix: builders #159

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ release-build-linux:
rm -rf target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) \
-v $(shell pwd):/code/ \
$(BUILDERS_PREFIX)-centos7
$(BUILDERS_PREFIX)-debian
cp artifacts/libmovevm.x86_64.so api
cp artifacts/libmovevm.aarch64.so api
cp artifacts/libcompiler.x86_64.so api
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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.

Linux (tested on CentOS7 and Alpine) and macOS are supported.
Linux (tested on Ubuntu, Debian, and Alpine) and macOS are supported.

### Builds of libmovevm

Expand Down
91 changes: 0 additions & 91 deletions builders/Dockerfile.centos7

This file was deleted.

66 changes: 66 additions & 0 deletions builders/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Use a debian version that is old enough to lead to a low
# glibc requirement of builds.
# Debian 11 "Bullseye" has long-term support until August 31st, 2026
FROM --platform=linux/amd64 debian:11-slim

RUN apt update -y \
&& apt install -y gcc make gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu wget perl

# GET FROM https://github.com/rust-lang/docker-rust-nightly
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH

RUN wget --no-verbose "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.80.1 \
&& rm rustup-init \
&& chmod -R a+w $RUSTUP_HOME $CARGO_HOME \
&& rustup --version \
&& cargo --version \
&& rustc --version \
&& chmod -R 777 /usr/local/cargo \
&& rustup target add aarch64-unknown-linux-gnu

## COPY BUILD SCRIPTS

WORKDIR /code

COPY guest/*.sh /opt/
RUN chmod +x /opt/*.sh

RUN mkdir /.cargo
RUN chmod +rx /.cargo
COPY guest/cargo-config /.cargo/config

#############
## OPENSSL ##
#############

RUN wget "https://www.openssl.org/source/openssl-1.1.1k.tar.gz"

# Install openssl for x86_64. This is required by Move
RUN tar -zxvf ./openssl-1.1.1k.tar.gz \
&& cd openssl-1.1.1k \
&& INSTALL_DIR="/opt/x86_64-openssl" \
&& ./Configure linux-x86_64 --prefix="$INSTALL_DIR" threads no-shared \
&& make -j$(nproc) \
&& make install_sw \
&& cd .. \
&& rm -rf ./openssl-1.1.1k

# Install openssl for cross-compilation. This is required by Move
RUN tar -zxvf ./openssl-1.1.1k.tar.gz \
&& cd openssl-1.1.1k \
&& INSTALL_DIR="/opt/aarch64-openssl" \
&& ./Configure linux-aarch64 --cross-compile-prefix=aarch64-linux-gnu- --prefix="$INSTALL_DIR" threads no-shared \
&& make -j$(nproc) \
&& make install_sw \
&& cd .. \
&& rm -rf ./openssl-1.1.1k

RUN rm ./openssl-1.1.1k.tar.gz

WORKDIR /code

CMD ["/opt/build_linux.sh"]
10 changes: 5 additions & 5 deletions builders/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BUILDERS_PREFIX := initia/go-ext-builder:0001

.PHONY: docker-image-centos7
docker-image-centos7:
docker build --pull . -t $(BUILDERS_PREFIX)-centos7 -f ./Dockerfile.centos7
.PHONY: docker-image-debian
docker-image-debian:
docker build --pull . -t $(BUILDERS_PREFIX)-debian -f ./Dockerfile.debian

.PHONY: docker-image-cross
docker-image-cross:
Expand All @@ -13,10 +13,10 @@ docker-image-alpine:
docker build --pull . -t $(BUILDERS_PREFIX)-alpine -f ./Dockerfile.alpine

.PHONY: docker-images
docker-images: docker-image-centos7 docker-image-cross docker-image-alpine
docker-images: docker-image-debian docker-image-cross docker-image-alpine

.PHONY: docker-publish
docker-publish: docker-images
docker push $(BUILDERS_PREFIX)-cross
docker push $(BUILDERS_PREFIX)-centos7
docker push $(BUILDERS_PREFIX)-debian
docker push $(BUILDERS_PREFIX)-alpine
1 change: 1 addition & 0 deletions crates/e2e-move-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sha3 = { workspace = true }
bytes = { workspace = true }
bigdecimal = { workspace = true }
bech32 = { workspace = true }
base64 = { workspace = true }

initia-move-types = { workspace = true }
initia-move-vm = { workspace = true }
Expand Down
24 changes: 14 additions & 10 deletions crates/e2e-move-tests/src/tests/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use move_core_types::account_address::AccountAddress;
use move_core_types::language_storage::TypeTag;
use move_core_types::vm_status::VMStatus;

use base64::{self, Engine};
use bech32::{Bech32, Hrp};
use sha3::{Digest, Sha3_256};

Expand Down Expand Up @@ -397,7 +398,7 @@ fn test_cosmos_pay_fee() {
let timeout_fee_denom = str::from_utf8(FEE_B_SYMBOL).unwrap();
let sender_cosmos_addr =
bech32::encode::<Bech32>(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap();
let expected_data = format!("{{\"@type\":\"/ibc.applications.fee.v1.MsgPayPacketFee\",\"fee\":{{\"ack_fee\":[{{\"amount\":\"{ack_fee_amount}\",\"denom\":\"{ack_fee_denom}\"}}],\"recv_fee\":[{{\"amount\":\"{recv_fee_amount}\",\"denom\":\"{recv_fee_denom}\"}}],\"timeout_fee\":[{{\"amount\":\"{timeout_fee_amount}\",\"denom\":\"{timeout_fee_denom}\"}}]}},\"relayers\":[],\"signer\":\"{sender_cosmos_addr}\",\"source_channel\":\"{source_channel}\",\"source_port\":\"{source_port}\"}}");
let expected_data = format!("{{\"@type\":\"/ibc.applications.fee.v1.MsgPayPacketFee\",\"fee\":{{\"ack_fee\":[{{\"amount\":\"{ack_fee_amount}\",\"denom\":\"{ack_fee_denom}\"}}],\"recv_fee\":[{{\"amount\":\"{recv_fee_amount}\",\"denom\":\"{recv_fee_denom}\"}}],\"timeout_fee\":[{{\"amount\":\"{timeout_fee_amount}\",\"denom\":\"{timeout_fee_denom}\"}}]}},\"relayers\":[],\"signer\":\"{sender_cosmos_addr}\",\"source_channel_id\":\"{source_channel}\",\"source_port_id\":\"{source_port}\"}}");

let test_pay_fee = (
sender,
Expand Down Expand Up @@ -442,12 +443,13 @@ fn test_cosmos_move_execute() {
let arg1 = vec![1, 2, 3];
let arg2 = vec![4, 5, 6];

let arg1_hex = hex::encode(arg1.clone());
let arg2_hex = hex::encode(arg2.clone());
let base64 = base64::engine::general_purpose::STANDARD;
let arg1_base64 = base64.encode(arg1.clone());
let arg2_base64 = base64.encode(arg2.clone());
let module_addr_hex = module_address.to_hex_literal();
let sender_cosmos_addr =
bech32::encode::<Bech32>(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap();
let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecute\",\"args\":[\"{arg1_hex}\",\"{arg2_hex}\"],\"function_name\":\"{function_name}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}");
let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecute\",\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"],\"function_name\":\"{function_name}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}");

let test_move_execute = (
sender,
Expand Down Expand Up @@ -532,12 +534,13 @@ fn test_cosmos_move_script() {
let arg1 = vec![1, 2, 3];
let arg2 = vec![4, 5, 6];

let code_bytes_hex = hex::encode(code_bytes.clone());
let arg1_hex = hex::encode(arg1.clone());
let arg2_hex = hex::encode(arg2.clone());
let base64 = base64::engine::general_purpose::STANDARD;
let code_bytes_base64 = base64.encode(code_bytes.clone());
let arg1_base64 = base64.encode(arg1.clone());
let arg2_base64 = base64.encode(arg2.clone());
let sender_cosmos_addr =
bech32::encode::<Bech32>(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap();
let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScript\",\"args\":[\"{arg1_hex}\",\"{arg2_hex}\"],\"code_bytes\":\"{code_bytes_hex}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}");
let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScript\",\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"],\"code_bytes\":\"{code_bytes_base64}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}");

let test_move_script = (
sender,
Expand Down Expand Up @@ -575,10 +578,11 @@ fn test_cosmos_move_script_with_json() {
let arg1 = b"\"hello\"".to_vec();
let arg2 = b"\"world\"".to_vec();

let code_bytes_hex = hex::encode(code_bytes.clone());
let base64 = base64::engine::general_purpose::STANDARD;
let code_bytes_base64 = base64.encode(code_bytes.clone());
let sender_cosmos_addr =
bech32::encode::<Bech32>(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap();
let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScriptJSON\",\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"],\"code_bytes\":\"{code_bytes_hex}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}");
let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScriptJSON\",\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"],\"code_bytes\":\"{code_bytes_base64}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}");

let test_move_script = (
sender,
Expand Down
Binary file modified precompile/binaries/minlib/cosmos.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/cosmos.mv
Binary file not shown.
21 changes: 13 additions & 8 deletions precompile/modules/initia_stdlib/sources/cosmos.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module initia_std::cosmos {
use std::error;
use std::coin::metadata_to_denom;
use std::collection::collection_to_class_id;
use std::base64;

use initia_std::json;

Expand Down Expand Up @@ -78,7 +79,7 @@ module initia_std::cosmos {
module_name: String,
function_name: String,
type_args: vector<String>,
args: vector<vector<u8>>
args: vector<String> // base64 encoded
}

public entry fun move_execute(
Expand All @@ -89,6 +90,7 @@ module initia_std::cosmos {
type_args: vector<String>,
args: vector<vector<u8>>
) {
let args = vector::map(args, |arg| base64::to_string(arg));
stargate(
sender,
json::marshal(
Expand Down Expand Up @@ -142,9 +144,9 @@ module initia_std::cosmos {
struct ScriptRequest has copy, drop {
_type_: String,
sender: String,
code_bytes: vector<u8>,
code_bytes: String, // base64 encoded
type_args: vector<String>,
args: vector<vector<u8>>
args: vector<String> // base64 encoded
}

public entry fun move_script(
Expand All @@ -153,6 +155,8 @@ module initia_std::cosmos {
type_args: vector<String>,
args: vector<vector<u8>>
) {
let args = vector::map(args, |arg| base64::to_string(arg));
let code_bytes = base64::to_string(code_bytes);
stargate(
sender,
json::marshal(
Expand All @@ -170,7 +174,7 @@ module initia_std::cosmos {
struct ScriptJSONRequest has copy, drop {
_type_: String,
sender: String,
code_bytes: vector<u8>,
code_bytes: String,
type_args: vector<String>,
args: vector<String>
}
Expand All @@ -181,6 +185,7 @@ module initia_std::cosmos {
type_args: vector<String>,
args: vector<String>
) {
let code_bytes = base64::to_string(code_bytes);
stargate(
sender,
json::marshal(
Expand Down Expand Up @@ -356,8 +361,8 @@ module initia_std::cosmos {
struct PayFeeRequest has copy, drop {
_type_: String,
_signer_: String,
source_port: String,
source_channel: String,
source_port_id: String,
source_channel_id: String,
fee: Fee,
relayers: vector<String>
}
Expand All @@ -381,8 +386,8 @@ module initia_std::cosmos {
&PayFeeRequest {
_type_: string::utf8(b"/ibc.applications.fee.v1.MsgPayPacketFee"),
_signer_: address::to_sdk(signer::address_of(sender)),
source_port,
source_channel,
source_port_id: source_port,
source_channel_id: source_channel,
fee: Fee {
recv_fee: vector[
CosmosCoin {
Expand Down
Loading
Loading