Skip to content

Commit

Permalink
feat: squid changes (#27)
Browse files Browse the repository at this point in the history
* Made the squid changes

* some cleanup

* Making sure all txns are executed as part of await

* Trying to finalize Txns before the next one happens

* add coverage

* try moving different things into bin

* testing stuff

* more tests

* fixed tests

* Update .github/workflows/codecov.yaml

Co-authored-by: Milap Sheth <[email protected]>

* Update move/squid/sources/squid/swap_info.move

Co-authored-by: Milap Sheth <[email protected]>

* fix a small bug

* remove code coverage

* added squid deployment

* feat: audit address comments (#28)

* Addressed all relevant audit comments

* added some comments

* fixed tests

* Update move/axelar/sources/gateway.move

* Update move/axelar/sources/gateway.move

* rename

---------

Co-authored-by: Milap Sheth <[email protected]>

---------

Co-authored-by: Milap Sheth <[email protected]>
  • Loading branch information
Foivos and milapsheth authored May 26, 2024
1 parent c705d1d commit 9466557
Show file tree
Hide file tree
Showing 29 changed files with 526 additions and 356 deletions.
4 changes: 2 additions & 2 deletions move/abi/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "Abi"
version = "0.0.1"
published-at = "0xe716e153ada17d39bf0e2325658d5969d885c2c548cd55f2068f29831be1d42a"
published-at = "0xab66686154d5c503d7f796d130c6b3dd966cc1f0a5d8b3436c97b48fda6c1841"
edition = "2024.beta"

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

[addresses]
abi = "0xe716e153ada17d39bf0e2325658d5969d885c2c548cd55f2068f29831be1d42a"
abi = "0xab66686154d5c503d7f796d130c6b3dd966cc1f0a5d8b3436c97b48fda6c1841"
4 changes: 2 additions & 2 deletions move/axelar/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "Axelar"
version = "0.0.1"
published-at = "0x4c1b0c036766f48f5d067200fe2c2418f4455970470ec8931a3ab338a7249adc"
published-at = "0xc6097c5ea89ff12983f963ff0d6e9b6e6f97026d3f284555c1f3e810809a09bb"
edition = "2024.beta"

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

[addresses]
axelar = "0x4c1b0c036766f48f5d067200fe2c2418f4455970470ec8931a3ab338a7249adc"
axelar = "0xc6097c5ea89ff12983f963ff0d6e9b6e6f97026d3f284555c1f3e810809a09bb"
52 changes: 36 additions & 16 deletions move/axelar/sources/gateway.move
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ module axelar::gateway {
/// Trying to `take_approved_call` with a wrong payload.
const EPayloadHashMismatch: u64 = 5;

/// Trying to execute the same operatorhsip transfer command again.
const EAlreadyTransferedOperatorship: u64 = 6;

/// Trying to set initial validators again
const EAlreadyInitialized: u64 = 6;

// These are currently supported
const SELECTOR_APPROVE_CONTRACT_CALL: vector<u8> = b"approveContractCall";
const SELECTOR_TRANSFER_OPERATORSHIP: vector<u8> = b"transferOperatorship";
Expand All @@ -63,6 +69,7 @@ module axelar::gateway {
id: UID,
approvals: Table<address, Approval>,
validators: AxelarValidators,
operatorship_transfers: Table<address, bool>,
}

/// CallApproval struct which can consumed only by a `Channel` object.
Expand Down Expand Up @@ -97,11 +104,17 @@ module axelar::gateway {
id: object::new(ctx),
approvals: table::new(ctx),
validators: validators::new(),
operatorship_transfers: table::new(ctx),
};

transfer::share_object(gateway);
}

public fun set_initial_validators(self: &mut Gateway, payload: vector<u8>) {
assert!(self.validators.epoch() == 0, EAlreadyInitialized);
self.validators.transfer_operatorship(payload);
}

#[allow(implicit_const_copy)]
/// The main entrypoint for the external approval processing.
/// Parses data and attaches call approvals to the Axelar object to be
Expand Down Expand Up @@ -175,6 +188,9 @@ module axelar::gateway {
if (!allow_operatorship_transfer) {
continue
};

assert!(!self.operatorship_transfers.contains(cmd_id), EAlreadyTransferedOperatorship);
self.operatorship_transfers.add(cmd_id, true);
allow_operatorship_transfer = false;
borrow_mut_validators(self).transfer_operatorship(payload);
} else {
Expand Down Expand Up @@ -283,13 +299,17 @@ module axelar::gateway {
fun borrow_mut_validators(self: &mut Gateway): &mut AxelarValidators {
&mut self.validators
}

#[test_only]
public fun new(ctx: &mut TxContext): Gateway {
let mut validators = validators::new();
validators.init_for_testing();

Gateway {
id: object::new(ctx),
approvals: table::new(ctx),
validators: validators::new(),
validators,
operatorship_transfers: table::new(ctx),
}
}

Expand Down Expand Up @@ -344,28 +364,28 @@ module axelar::gateway {
];

let data = get_data(&chain_id, &command_ids, &commands, &params);
let proof = x"";
let proof = validators::proof_for_testing();
let mut input = vector[];

vector::append(&mut input, bcs::to_bytes(&data));
vector::append(&mut input, bcs::to_bytes(&proof));

assert!(gateway.approvals.contains(@0x1) == false, 0);
assert!(gateway.validators.epoch() == 0, 3);
assert!(gateway.validators.epoch() == 1, 3);

process_commands(&mut gateway, input);

assert!(gateway.approvals.contains(@0x1) == true, 2);
let approval_hash = get_approval_hash(
&@0x1,
&@0x1,
&source_chain,
&source_address,
&target_id,
&payload_hash,
);

assert!(approval_hash == gateway.approvals.borrow(@0x1).approval_hash, 3);
assert!(gateway.validators.epoch() == 1, 4);
assert!(gateway.validators.epoch() == 2, 4);

assert!(gateway.validators.test_contains_operators(
&new_operators_1,
Expand All @@ -381,7 +401,7 @@ module axelar::gateway {
&new_operators_1,
&new_weights_1,
new_threshold_1,
) == 1, 7);
) == 2, 7);


sui::test_utils::destroy(gateway);
Expand All @@ -399,9 +419,9 @@ module axelar::gateway {
let params = vector[];

let data = get_data(&chain_id, &command_ids, &commands, &params);
let proof = x"";
let proof = validators::proof_for_testing();
let mut input = vector[];

vector::append(&mut input, bcs::to_bytes(&data));
vector::append(&mut input, bcs::to_bytes(&proof));

Expand All @@ -422,9 +442,9 @@ module axelar::gateway {
let params = vector[];

let data = get_data(&chain_id, &command_ids, &commands, &params);
let proof = x"";
let proof = validators::proof_for_testing();
let mut input = vector[];

vector::append(&mut input, bcs::to_bytes(&data));
vector::append(&mut input, bcs::to_bytes(&proof));

Expand All @@ -445,9 +465,9 @@ module axelar::gateway {
let params = vector[x""];

let data = get_data(&chain_id, &command_ids, &commands, &params);
let proof = x"";
let proof = validators::proof_for_testing();
let mut input = vector[];

vector::append(&mut input, bcs::to_bytes(&data));
vector::append(&mut input, bcs::to_bytes(&proof));

Expand Down Expand Up @@ -483,9 +503,9 @@ module axelar::gateway {
];

let data = get_data(&chain_id, &command_ids, &commands, &params);
let proof = x"";
let proof = validators::proof_for_testing();
let mut input = vector[];

vector::append(&mut input, bcs::to_bytes(&data));
vector::append(&mut input, bcs::to_bytes(&proof));

Expand Down
32 changes: 26 additions & 6 deletions move/axelar/sources/validators.move
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ module axelar::validators {
proof: vector<u8>
): bool {
let epoch = epoch(validators);
// Allow the validators to validate any proof before the first set of operators is set (so that they can be rotated).
if (epoch == 0) {
return true
};

// Turn everything into bcs bytes and split data.
let mut proof = bcs::new(proof);
Expand All @@ -73,7 +69,7 @@ module axelar::validators {
assert!(operators_epoch != 0 && epoch - operators_epoch < OLD_KEY_RETENTION, EInvalidOperators);
let (mut i, mut weight, mut operator_index) = (0, 0, 0);
let total_signatures = vector::length(&signatures);
while (i < total_signatures) {
while (i < total_signatures && weight < threshold) {

let mut signature = *vector::borrow(&signatures, i);
normalize_signature(&mut signature);
Expand All @@ -86,12 +82,14 @@ module axelar::validators {
assert!(operator_index < operators_length, EMalformedSigners);

weight = weight + *vector::borrow(&weights, operator_index);
if (weight >= threshold) { return operators_epoch == epoch };

operator_index = operator_index + 1;

i = i + 1;
};

if (weight >= threshold) { return operators_epoch == epoch };

abort ELowSignaturesWeight
}

Expand All @@ -118,6 +116,7 @@ module axelar::validators {
// Remove old epoch for the operators if it exists
let epoch = validators.epoch() + 1;
let epoch_for_hash = validators.epoch_for_hash_mut();
// We are likely to change the architecture a bit to conform to our standars better in the future.
if (epoch_for_hash.contains(&new_operators_hash)) {
epoch_for_hash.remove(&new_operators_hash);
};
Expand Down Expand Up @@ -191,6 +190,27 @@ module axelar::validators {
/// Expected to be returned from ecrecover.
const SIGNER: vector<u8> = x"037286a4f1177bea06c8e15cf6ec3df0b7747a01ac2329ca2999dfd74eff599028";

#[test_only]
public fun proof_for_testing(): vector<u8> {
let mut proof: vector<u8> = vector[];
let mut i = 0;
while ( i < 19 ) {
vector::push_back(&mut proof, 0);
i = i + 1;
};
proof
}

#[test_only]
public fun init_for_testing(self: &mut AxelarValidators) {
let new_operators_hash = operators_hash(&vector[], &vector[], 0);
let epoch = 1;

self.epoch_for_hash.insert(new_operators_hash, epoch);

self.set_epoch(epoch);
}

#[test_only]
public fun get_transfer_params(new_operators: &vector<vector<u8>>, new_weights: &vector<u128>, new_threshold: &u128): vector<u8> {
let mut bcs = vector::empty<u8>();
Expand Down
4 changes: 2 additions & 2 deletions move/gas_service/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "Governance"
version = "0.0.1"
published-at = "0x578987b18d4d60ba54533ebf578cb724e4e892bebb9eb35b354e159953995b57"
published-at = "0x83187fc09392a9d547acd16caeca3bf8662452d75d1853d5a454074103161161"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }
Axelar = { local = "../axelar" }

[addresses]
gas_service = "0x578987b18d4d60ba54533ebf578cb724e4e892bebb9eb35b354e159953995b57"
gas_service = "0x83187fc09392a9d547acd16caeca3bf8662452d75d1853d5a454074103161161"
4 changes: 2 additions & 2 deletions move/governance/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "Governance"
version = "0.0.1"
published-at = "0x26de81e805d4608df54b89477e160c2b19e5c222adb0a0cc57e63647a7b3f5d1"
published-at = "0x927d8379a35d435db5b95daa6e624eea047f71832fadc0ed5d97640a711e601e"
edition = "2024.beta"

[dependencies]
Expand All @@ -10,4 +10,4 @@ Axelar = { local = "../axelar" }
Abi = { local = "../abi" }

[addresses]
governance = "0x26de81e805d4608df54b89477e160c2b19e5c222adb0a0cc57e63647a7b3f5d1"
governance = "0x927d8379a35d435db5b95daa6e624eea047f71832fadc0ed5d97640a711e601e"
16 changes: 8 additions & 8 deletions move/interchain_token/sources/interchain_token.move
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module interchain_token::tt {
module interchain_token::q {
use sui::coin::{Self};
use sui::url::{Url};

public struct TT has drop {}
public struct Q has drop {}

fun init(witness: TT, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency<TT>(
fun init(witness: Q, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency<Q>(
witness,
6,
b"TT",
b"Test Token",
9,
b"Q",
b"Quote",
b"",
option::none<Url>(),
ctx
);
transfer::public_transfer(treasury, tx_context::sender(ctx));
transfer::public_transfer(metadata, tx_context::sender(ctx));
}
}
}
4 changes: 2 additions & 2 deletions move/its/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ITS"
version = "0.0.1"
published-at = "0x4f54b4023596c4889208ec65243c1a2a93dad567458803d8f469abc861257b98"
published-at = "0x6897eff98e4db46b53131a73baf9e705647bd9c337df3f23d702616fbadf3093"
#published-at = "0x996939577aed09e0f9bc6690d85c6bbdb0228353cbe4dbb326b3c2d7f59cbff9"
edition = "2024.beta"

Expand All @@ -11,4 +11,4 @@ Axelar = { local = "../axelar" }
Governance = { local = "../governance" }

[addresses]
its = "0x4f54b4023596c4889208ec65243c1a2a93dad567458803d8f469abc861257b98"
its = "0x6897eff98e4db46b53131a73baf9e705647bd9c337df3f23d702616fbadf3093"
4 changes: 2 additions & 2 deletions move/squid/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "Squid"
version = "0.0.1"
published-at = "0x6b3d7de8dda55754c03490d91638c64ac28af14d4fd1c2aab3db6ec9b7b6a32b"
published-at = "0xf94eccf537d2dc1a8decfc77c0da01bb83d840c37f768f868d81092ca123456a"
edition = "2024.beta"

[dependencies]
Expand All @@ -11,4 +11,4 @@ Axelar = { local = "../axelar" }
ITS = { local = "../its" }

[addresses]
squid = "0x6b3d7de8dda55754c03490d91638c64ac28af14d4fd1c2aab3db6ec9b7b6a32b"
squid = "0xf94eccf537d2dc1a8decfc77c0da01bb83d840c37f768f868d81092ca123456a"
Loading

0 comments on commit 9466557

Please sign in to comment.