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

Update to Move2024 #4147

Open
wants to merge 1 commit into
base: sui-upgrade-testnet
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions sui/wormhole/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "E8C411A83F4F7EF268B73C732B9B6F49F7B204F0C9C2530765365C38B76EF646"
manifest_digest = "F24DE9952B3B73F37574346F868C342DE75B44914ED8C68274D2F1401E25806F"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

dependencies = [
Expand All @@ -11,17 +11,17 @@ dependencies = [

[[move.package]]
name = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "041c5f2bae2fe52079e44b70514333532d69f4e6", subdir = "crates/sui-framework/packages/move-stdlib" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
name = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "041c5f2bae2fe52079e44b70514333532d69f4e6", subdir = "crates/sui-framework/packages/sui-framework" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ name = "MoveStdlib" },
]

[move.toolchain-version]
compiler-version = "1.19.0"
edition = "legacy"
compiler-version = "1.34.0"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion sui/wormhole/Move.mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ published-at = "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb
[dependencies.Sui]
git = "https://github.com/MystenLabs/sui.git"
subdir = "crates/sui-framework/packages/sui-framework"
rev = "041c5f2bae2fe52079e44b70514333532d69f4e6"
rev = "framework/mainnet"

[addresses]
wormhole = "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a"
2 changes: 1 addition & 1 deletion sui/wormhole/Move.testnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ published-at = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a
[dependencies.Sui]
git = "https://github.com/MystenLabs/sui.git"
subdir = "crates/sui-framework/packages/sui-framework"
rev = "041c5f2bae2fe52079e44b70514333532d69f4e6"
rev = "framework/testnet"

[addresses]
wormhole = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94"
1 change: 0 additions & 1 deletion sui/wormhole/Move.toml

This file was deleted.

13 changes: 13 additions & 0 deletions sui/wormhole/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "Wormhole"
version = "0.2.0"
edition = "2024.beta"
published-at = "0xf47329f4344f3bf0f8e436e2f7b485466cff300f12a166563995d3888c296a94"

[dependencies.Sui]
git = "https://github.com/MystenLabs/sui.git"
subdir = "crates/sui-framework/packages/sui-framework"
rev = "framework/testnet"

[addresses]
wormhole = "0x123456"
49 changes: 23 additions & 26 deletions sui/wormhole/sources/datatypes/bytes20.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/// This module implements a custom type representing a fixed-size array of
/// length 20.
module wormhole::bytes20 {
use std::vector::{Self};

use wormhole::bytes::{Self};
use wormhole::cursor::{Cursor};
Expand All @@ -17,7 +16,7 @@ module wormhole::bytes20 {
const LEN: u64 = 20;

/// Container for `vector<u8>`, which has length == 20.
struct Bytes20 has copy, drop, store {
public struct Bytes20 has copy, drop, store {
data: vector<u8>
}

Expand All @@ -33,10 +32,10 @@ module wormhole::bytes20 {

/// Create new `Bytes20` of all zeros.
public fun default(): Bytes20 {
let data = vector::empty();
let i = 0;
let mut data = vector[];
let mut i = 0;
while (i < LEN) {
vector::push_back(&mut data, 0);
data.push_back(0);
i = i + 1;
};
new(data)
Expand All @@ -49,8 +48,8 @@ module wormhole::bytes20 {

/// Either trim or pad (depending on length of the input `vector<u8>`) to 20
/// bytes.
public fun from_bytes(buf: vector<u8>): Bytes20 {
let len = vector::length(&buf);
public fun from_bytes(mut buf: vector<u8>): Bytes20 {
let len = buf.length();
if (len > LEN) {
trim_nonzero_left(&mut buf);
new(buf)
Expand All @@ -72,9 +71,9 @@ module wormhole::bytes20 {

/// Validate that any of the bytes in underlying data is non-zero.
public fun is_nonzero(self: &Bytes20): bool {
let i = 0;
let mut i = 0;
while (i < LEN) {
if (*vector::borrow(&self.data, i) > 0) {
if (*self.data.borrow(i) > 0) {
return true
};
i = i + 1;
Expand All @@ -85,29 +84,28 @@ module wormhole::bytes20 {

/// Check that the input data is correct length.
fun is_valid(data: &vector<u8>): bool {
vector::length(data) == LEN
data.length() == LEN
}

/// For vector size less than 20, add zeros to the left.
fun pad_left(data: &vector<u8>, data_reversed: bool): vector<u8> {
let out = vector::empty();
let len = vector::length(data);
let i = len;
let mut out = vector[];
let len = data.length();
let mut i = len;
while (i < LEN) {
vector::push_back(&mut out, 0);
out.push_back(0);
i = i + 1;
};
if (data_reversed) {
let i = 0;
let mut i = 0;
while (i < len) {
vector::push_back(
&mut out,
*vector::borrow(data, len - i - 1)
out.push_back(
*data.borrow(len - i - 1)
);
i = i + 1;
};
} else {
vector::append(&mut out, *data);
out.append(*data);
};

out
Expand All @@ -116,26 +114,25 @@ module wormhole::bytes20 {
/// Trim bytes from the left if they are zero. If any of these bytes
/// are non-zero, abort.
fun trim_nonzero_left(data: &mut vector<u8>) {
vector::reverse(data);
let (i, n) = (0, vector::length(data) - LEN);
data.reverse();
let (mut i, n) = (0, data.length() - LEN);
while (i < n) {
assert!(vector::pop_back(data) == 0, E_CANNOT_TRIM_NONZERO);
assert!(data.pop_back() == 0, E_CANNOT_TRIM_NONZERO);
i = i + 1;
};
vector::reverse(data);
data.reverse();
}
}

#[test_only]
module wormhole::bytes20_tests {
use std::vector::{Self};

use wormhole::bytes20::{Self};

#[test]
public fun new() {
let data = x"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
assert!(vector::length(&data) == 20, 0);
assert!(data.length() == 20, 0);
let actual = bytes20::new(data);

assert!(bytes20::data(&actual) == data, 0);
Expand Down Expand Up @@ -170,7 +167,7 @@ module wormhole::bytes20_tests {
public fun cannot_new_non_20_byte_vector() {
let data =
x"deadbeefdeadbeefdeadbeefdeadbeefdeadbe";
assert!(vector::length(&data) != 20, 0);
assert!(data.length() != 20, 0);
bytes20::new(data);
}
}
Loading