From 237925ab898388549b5b617d9a696cd1c10ed7a9 Mon Sep 17 00:00:00 2001 From: Milap Sheth Date: Thu, 11 Jul 2024 18:45:06 -0400 Subject: [PATCH] refactor(axelar-gateway)!: rename pubkey to pub_key (#69) Co-authored-by: Kiryl Yermakou --- move/abi/Move.lock | 2 +- move/axelar_gateway/Move.lock | 4 +- move/axelar_gateway/Move.toml | 4 +- move/axelar_gateway/sources/auth.move | 4 +- move/axelar_gateway/sources/types/proof.move | 2 +- .../sources/types/weighted_signer.move | 38 +++++++++---------- move/gas_service/Move.lock | 4 +- move/governance/Move.lock | 4 +- move/interchain_token/Move.lock | 2 +- move/its/Move.lock | 4 +- move/operators/Move.lock | 2 +- move/squid/Move.lock | 4 +- move/test/Move.lock | 2 +- scripts/bcs.js | 2 +- src/bcs.ts | 2 +- test/axelar-gateway.js | 34 +++++++++-------- 16 files changed, 58 insertions(+), 56 deletions(-) diff --git a/move/abi/Move.lock b/move/abi/Move.lock index 9ac7913a..36601d64 100644 --- a/move/abi/Move.lock +++ b/move/abi/Move.lock @@ -21,6 +21,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/axelar_gateway/Move.lock b/move/axelar_gateway/Move.lock index 370d6384..94088f11 100644 --- a/move/axelar_gateway/Move.lock +++ b/move/axelar_gateway/Move.lock @@ -2,7 +2,7 @@ [move] version = 2 -manifest_digest = "1EB54C26C3FA638760DAA54E631C0B13A09FFC472C1CAA730C9A7879E463B455" +manifest_digest = "10303CE6C59BAA2CE814E3D11BACC8CB24BE0F8D66753B02190E291CA40F0D39" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ { name = "Sui" }, @@ -21,6 +21,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/axelar_gateway/Move.toml b/move/axelar_gateway/Move.toml index c18a9029..437df0e2 100644 --- a/move/axelar_gateway/Move.toml +++ b/move/axelar_gateway/Move.toml @@ -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" diff --git a/move/axelar_gateway/sources/auth.move b/move/axelar_gateway/sources/auth.move index b3b5c65a..a3e0f07f 100644 --- a/move/axelar_gateway/sources/auth.move +++ b/move/axelar_gateway/sources/auth.move @@ -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; }; diff --git a/move/axelar_gateway/sources/types/proof.move b/move/axelar_gateway/sources/types/proof.move index d541a4c2..255e795b 100644 --- a/move/axelar_gateway/sources/types/proof.move +++ b/move/axelar_gateway/sources/types/proof.move @@ -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): vector { + public(package) fun recover_pub_key(self: &Signature, message: &vector): vector { ecdsa::secp256k1_ecrecover(&self.bytes, message, 0) } diff --git a/move/axelar_gateway/sources/types/weighted_signer.move b/move/axelar_gateway/sources/types/weighted_signer.move index b4fd6cc3..6c1dbd62 100644 --- a/move/axelar_gateway/sources/types/weighted_signer.move +++ b/move/axelar_gateway/sources/types/weighted_signer.move @@ -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, + pub_key: vector, weight: u128, } - public fun pubkey(self: &WeightedSigner): vector { - self.pubkey + public fun pub_key(self: &WeightedSigner): vector { + self.pub_key } public fun weight(self: &WeightedSigner): u128 { @@ -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, weight: u128): WeightedSigner { - assert!(pubkey.length() == PUBKEY_LENGTH, EInvalidPubkeyLength); + public(package) fun new(pub_key: vector, 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 }; @@ -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; } } diff --git a/move/gas_service/Move.lock b/move/gas_service/Move.lock index 5cc24c5f..916edd92 100644 --- a/move/gas_service/Move.lock +++ b/move/gas_service/Move.lock @@ -2,7 +2,7 @@ [move] version = 2 -manifest_digest = "A020C8D244BDE64D6F5F3107506F682AEA99E933953DE1FB01352999724E43EB" +manifest_digest = "087A028093BEA5B33AB826F8CFE6D5B029A93CC7ACFE21C55F92BE7AA4500D07" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ { name = "Sui" }, @@ -21,6 +21,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/governance/Move.lock b/move/governance/Move.lock index a4cb0602..72ef3426 100644 --- a/move/governance/Move.lock +++ b/move/governance/Move.lock @@ -2,7 +2,7 @@ [move] version = 2 -manifest_digest = "9DC4C192CAEBB80F2FBB1DC3CCEC7F9714E98AF18EBC9396F08BDB826A59E4F3" +manifest_digest = "DDE122A0D708826C620F1612EA66CF667DC100950E4572CE1B5D769914214352" deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" dependencies = [ { name = "Abi" }, @@ -39,6 +39,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/interchain_token/Move.lock b/move/interchain_token/Move.lock index 8b658462..e724791e 100644 --- a/move/interchain_token/Move.lock +++ b/move/interchain_token/Move.lock @@ -21,6 +21,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/its/Move.lock b/move/its/Move.lock index c52c3519..47590cbe 100644 --- a/move/its/Move.lock +++ b/move/its/Move.lock @@ -2,7 +2,7 @@ [move] version = 2 -manifest_digest = "C47498B72EFC749BF4D0D66D86BC3702ADBFBD16CF406FA05127DAD55FBE28C4" +manifest_digest = "1147666C677721F15D3F7BBBFAEBB42A77A1E40BADAC55CF5299A610C616C456" deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" dependencies = [ { name = "AxelarGateway" }, @@ -49,6 +49,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/operators/Move.lock b/move/operators/Move.lock index 18983bb6..be0fe288 100644 --- a/move/operators/Move.lock +++ b/move/operators/Move.lock @@ -21,6 +21,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/squid/Move.lock b/move/squid/Move.lock index f6bf9855..f12af4c3 100644 --- a/move/squid/Move.lock +++ b/move/squid/Move.lock @@ -2,7 +2,7 @@ [move] version = 2 -manifest_digest = "384A3D94552582FBDD012034F0BE9AC30A837A35416FCCFBA340F7C3597FB0D3" +manifest_digest = "F04564A9B03EECFDBF7CA6366332C84FE6CD5664BA92120778113C63A95FFC65" deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C" dependencies = [ { name = "AxelarGateway" }, @@ -69,6 +69,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/move/test/Move.lock b/move/test/Move.lock index ed1e8c31..07851ec1 100644 --- a/move/test/Move.lock +++ b/move/test/Move.lock @@ -30,6 +30,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.26.1" +compiler-version = "1.25.1" edition = "2024.beta" flavor = "sui" diff --git a/scripts/bcs.js b/scripts/bcs.js index a3148e5a..e2abc062 100644 --- a/scripts/bcs.js +++ b/scripts/bcs.js @@ -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, }); diff --git a/src/bcs.ts b/src/bcs.ts index 16f1d206..fc1f3def 100644 --- a/src/bcs.ts +++ b/src/bcs.ts @@ -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, }); diff --git a/test/axelar-gateway.js b/test/axelar-gateway.js index ac3048df..8d682530 100644 --- a/test/axelar-gateway.js +++ b/test/axelar-gateway.js @@ -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'); @@ -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]), @@ -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({ @@ -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(); @@ -149,7 +151,7 @@ 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]), @@ -157,14 +159,14 @@ describe('Axelar Gateway', () => { 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();