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

refactor(axelar-gateway)!: rename pubkey to pub_key #69

Merged
merged 4 commits into from
Jul 11, 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 move/abi/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
4 changes: 2 additions & 2 deletions move/axelar_gateway/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "1EB54C26C3FA638760DAA54E631C0B13A09FFC472C1CAA730C9A7879E463B455"
manifest_digest = "10303CE6C59BAA2CE814E3D11BACC8CB24BE0F8D66753B02190E291CA40F0D39"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
4 changes: 2 additions & 2 deletions move/axelar_gateway/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "AxelarGateway"
version = "0.1.0"
published-at = "0xe44f3fb828db14a0dd991de2aed9c987ee49faf7c31bf819b986a058a38e9935"
published-at = "0x0"
edition = "2024.beta"

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

[addresses]
axelar_gateway = "0xcd391ade5ab55a218f8988df8f3aa38ec019651c217244f7f689616c87d8c289"
axelar_gateway = "0x0"
clock = "0x6"
4 changes: 2 additions & 2 deletions move/axelar_gateway/sources/auth.move
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ module axelar_gateway::auth {
let mut i = 0;

while (i < signatures_length) {
let pubkey = signatures[i].recover_pubkey(&message);
let pub_key = signatures[i].recover_pub_key(&message);

while (signer_index < signers_length && signers.signers()[signer_index].pubkey() != pubkey) {
while (signer_index < signers_length && signers.signers()[signer_index].pub_key() != pub_key) {
signer_index = signer_index + 1;
};

Expand Down
2 changes: 1 addition & 1 deletion move/axelar_gateway/sources/types/proof.move
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module axelar_gateway::proof {
}

/// Recover the public key from an EVM recoverable signature, using keccak256 as the hash function
public(package) fun recover_pubkey(self: &Signature, message: &vector<u8>): vector<u8> {
public(package) fun recover_pub_key(self: &Signature, message: &vector<u8>): vector<u8> {
ecdsa::secp256k1_ecrecover(&self.bytes, message, 0)
}

Expand Down
38 changes: 19 additions & 19 deletions move/axelar_gateway/sources/types/weighted_signer.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ module axelar_gateway::weighted_signer {
// ---------

/// Length of a public key
const PUBKEY_LENGTH: u64 = 33;
const PUB_KEY_LENGTH: u64 = 33;

// -----
// Types
// -----

public struct WeightedSigner has copy, drop, store {
pubkey: vector<u8>,
pub_key: vector<u8>,
weight: u128,
}

public fun pubkey(self: &WeightedSigner): vector<u8> {
self.pubkey
public fun pub_key(self: &WeightedSigner): vector<u8> {
self.pub_key
}

public fun weight(self: &WeightedSigner): u128 {
Expand All @@ -29,44 +29,44 @@ module axelar_gateway::weighted_signer {
// Errors
// ------

const EInvalidPubkeyLength: u64 = 0;
const EInvalidPubKeyLength: u64 = 0;

// -----------------
// Package Functions
// -----------------

public(package) fun new(pubkey: vector<u8>, weight: u128): WeightedSigner {
assert!(pubkey.length() == PUBKEY_LENGTH, EInvalidPubkeyLength);
public(package) fun new(pub_key: vector<u8>, weight: u128): WeightedSigner {
assert!(pub_key.length() == PUB_KEY_LENGTH, EInvalidPubKeyLength);

WeightedSigner { pubkey, weight }
WeightedSigner { pub_key, weight }
}

/// Empty weighted signer
public(package) fun default(): WeightedSigner {
let mut pubkey = @0x0.to_bytes();
pubkey.push_back(0);
let mut pub_key = @0x0.to_bytes();
pub_key.push_back(0);

WeightedSigner {
pubkey,
pub_key,
weight: 0,
}
}

public(package) fun peel(bcs: &mut BCS): WeightedSigner {
let pubkey = bcs.peel_vec_u8();
let pub_key = bcs.peel_vec_u8();
let weight = bcs.peel_u128();

new(pubkey, weight)
new(pub_key, weight)
}

/// Check if self.signer is less than other.signer as bytes
public(package) fun lt(self: &WeightedSigner, other: &WeightedSigner): bool {
let mut i = 0;

while (i < PUBKEY_LENGTH) {
if (self.pubkey[i] < other.pubkey[i]) {
while (i < PUB_KEY_LENGTH) {
if (self.pub_key[i] < other.pub_key[i]) {
return true
} else if (self.pubkey[i] > other.pubkey[i]) {
} else if (self.pub_key[i] > other.pub_key[i]) {
return false
};

Expand All @@ -85,11 +85,11 @@ module axelar_gateway::weighted_signer {
let signer = default();

assert!(signer.weight == 0, 0);
assert!(signer.pubkey.length() == PUBKEY_LENGTH, 1);
assert!(signer.pub_key.length() == PUB_KEY_LENGTH, 1);

let mut i = 0;
while (i < PUBKEY_LENGTH) {
assert!(signer.pubkey[i] == 0, 2);
while (i < PUB_KEY_LENGTH) {
assert!(signer.pub_key[i] == 0, 2);
i = i + 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions move/gas_service/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "A020C8D244BDE64D6F5F3107506F682AEA99E933953DE1FB01352999724E43EB"
manifest_digest = "087A028093BEA5B33AB826F8CFE6D5B029A93CC7ACFE21C55F92BE7AA4500D07"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
4 changes: 2 additions & 2 deletions move/governance/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "9DC4C192CAEBB80F2FBB1DC3CCEC7F9714E98AF18EBC9396F08BDB826A59E4F3"
manifest_digest = "DDE122A0D708826C620F1612EA66CF667DC100950E4572CE1B5D769914214352"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ name = "Abi" },
Expand Down Expand Up @@ -39,6 +39,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion move/interchain_token/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
4 changes: 2 additions & 2 deletions move/its/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "C47498B72EFC749BF4D0D66D86BC3702ADBFBD16CF406FA05127DAD55FBE28C4"
manifest_digest = "1147666C677721F15D3F7BBBFAEBB42A77A1E40BADAC55CF5299A610C616C456"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ name = "AxelarGateway" },
Expand Down Expand Up @@ -49,6 +49,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion move/operators/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
4 changes: 2 additions & 2 deletions move/squid/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "384A3D94552582FBDD012034F0BE9AC30A837A35416FCCFBA340F7C3597FB0D3"
manifest_digest = "F04564A9B03EECFDBF7CA6366332C84FE6CD5664BA92120778113C63A95FFC65"
deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C"
dependencies = [
{ name = "AxelarGateway" },
Expand Down Expand Up @@ -69,6 +69,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion move/test/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.26.1"
compiler-version = "1.25.1"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion scripts/bcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getAxelarStructs() {
});

const WeightedSigner = bcs.struct('WeightedSigner', {
pubkey: bcs.vector(bcs.U8),
pub_key: bcs.vector(bcs.U8),
weight: bcs.U128,
});

Expand Down
2 changes: 1 addition & 1 deletion src/bcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function getAxelarStructs() {
});

const WeightedSigner = bcs.struct('WeightedSigner', {
pubkey: bcs.vector(bcs.U8),
pub_key: bcs.vector(bcs.U8),
weight: bcs.U128,
});

Expand Down
34 changes: 18 additions & 16 deletions test/axelar-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui.js/faucet
const { publishPackage, getRandomBytes32, expectRevert, expectEvent } = require('./utils');
const { TxBuilder } = require('../dist/tx-builder');
const {
bcsStructs: { axelarStructs },
bcsStructs: {
gateway: { WeightedSigners, MessageToSign, Proof },
},
} = require('../dist/bcs');
const { arrayify, hexlify, keccak256 } = require('ethers/lib/utils');
const secp256k1 = require('secp256k1');
Expand All @@ -26,22 +28,22 @@ describe('Axelar Gateway', () => {

function calculateNextSigners() {
operatorKeys = [getRandomBytes32(), getRandomBytes32(), getRandomBytes32()];
const pubkeys = operatorKeys.map((key) => Secp256k1Keypair.fromSecretKey(arrayify(key)).getPublicKey().toRawBytes());
const pubKeys = operatorKeys.map((key) => Secp256k1Keypair.fromSecretKey(arrayify(key)).getPublicKey().toRawBytes());
const keys = operatorKeys.map((key, index) => {
return { privkey: key, pubkey: pubkeys[index] };
return { privKey: key, pubKey: pubKeys[index] };
});
keys.sort((key1, key2) => {
for (let i = 0; i < 33; i++) {
if (key1.pubkey[i] < key2.pubkey[i]) return -1;
if (key1.pubkey[i] > key2.pubkey[i]) return 1;
if (key1.pubKey[i] < key2.pubKey[i]) return -1;
if (key1.pubKey[i] > key2.pubKey[i]) return 1;
}

return 0;
});
operatorKeys = keys.map((key) => key.privkey);
operatorKeys = keys.map((key) => key.privKey);
signers = {
signers: keys.map((key) => {
return { pubkey: key.pubkey, weight: 1 };
return { pub_key: key.pubKey, weight: 1 };
}),
threshold: 2,
nonce: hexlify([++nonce]),
Expand Down Expand Up @@ -93,7 +95,7 @@ describe('Axelar Gateway', () => {

calculateNextSigners();

const encodedSigners = axelarStructs.WeightedSigners.serialize(signers).toBytes();
const encodedSigners = WeightedSigners.serialize(signers).toBytes();
const builder = new TxBuilder(client);

const separator = await builder.moveCall({
Expand All @@ -118,18 +120,18 @@ describe('Axelar Gateway', () => {
const proofKeys = operatorKeys;
calculateNextSigners();

const encodedSigners = axelarStructs.WeightedSigners.serialize(signers).toBytes();
const encodedSigners = WeightedSigners.serialize(signers).toBytes();

const hashed = hashMessage(encodedSigners);

const message = axelarStructs.MessageToSign.serialize({
const message = MessageToSign.serialize({
domain_separator: domainSeparator,
signers_hash: keccak256(axelarStructs.WeightedSigners.serialize(proofSigners).toBytes()),
signers_hash: keccak256(WeightedSigners.serialize(proofSigners).toBytes()),
data_hash: hashed,
}).toBytes();

const signatures = sign(proofKeys, message);
const encodedProof = axelarStructs.Proof.serialize({
const encodedProof = Proof.serialize({
signers: proofSigners,
signatures,
}).toBytes();
Expand All @@ -149,22 +151,22 @@ describe('Axelar Gateway', () => {
const proofSigners = signers;
const proofKeys = operatorKeys;

const encodedSigners = axelarStructs.WeightedSigners.serialize({
const encodedSigners = WeightedSigners.serialize({
signers: [],
threshold: 2,
nonce: hexlify([nonce + 1]),
}).toBytes();

const hashed = hashMessage(encodedSigners);

const message = axelarStructs.MessageToSign.serialize({
const message = MessageToSign.serialize({
domain_separator: domainSeparator,
signers_hash: keccak256(axelarStructs.WeightedSigners.serialize(proofSigners).toBytes()),
signers_hash: keccak256(WeightedSigners.serialize(proofSigners).toBytes()),
data_hash: hashed,
}).toBytes();

const signatures = sign(proofKeys, message);
const encodedProof = axelarStructs.Proof.serialize({
const encodedProof = Proof.serialize({
signers: proofSigners,
signatures,
}).toBytes();
Expand Down
Loading