-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
170 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[package] | ||
name = "Abi" | ||
version = "0.1.0" | ||
published-at = "0x0" | ||
published-at = "0x845c6fa54ccb69bde81098dabac0e1fb11dd9ae217a034992203ce99801a3b67" | ||
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] | ||
abi = "0x0" | ||
abi = "0x845c6fa54ccb69bde81098dabac0e1fb11dd9ae217a034992203ce99801a3b67" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[package] | ||
name = "AxelarGateway" | ||
version = "0.1.0" | ||
published-at = "0x1611b7e3e958f74e4ef9f4727333a98d095a9f71baf4c814d310d986db1f5662" | ||
published-at = "0x7bc9ff900d613dba5c53b5f84869a229ebb791be61b6f30cfec6d4f6130492c7" | ||
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 = "0x1611b7e3e958f74e4ef9f4727333a98d095a9f71baf4c814d310d986db1f5662" | ||
axelar_gateway = "0x7bc9ff900d613dba5c53b5f84869a229ebb791be61b6f30cfec6d4f6130492c7" | ||
clock = "0x6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[package] | ||
name = "GasService" | ||
version = "0.1.0" | ||
published-at = "0xe356c310916a4f0c76a2c50b1101f66a328eee2626f709b1138e5ca2a537d438" | ||
published-at = "0x9249adc3fac09edb21a0848af2ccf4901ffb3689124bc91d67bc613903ca643c" | ||
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] | ||
gas_service = "0xe356c310916a4f0c76a2c50b1101f66a328eee2626f709b1138e5ca2a537d438" | ||
gas_service = "0x9249adc3fac09edb21a0848af2ccf4901ffb3689124bc91d67bc613903ca643c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[package] | ||
name = "Test" | ||
version = "0.1.0" | ||
published-at = "0x9110bc3d96f77d7ddd6ef058627fb9369c6bfbedfb169228e9d20959a5f893cd" | ||
published-at = "0x64cb77be32074cff87043543664dafb4eb766f980d08694cffca8c8136321872" | ||
edition = "2024.beta" | ||
|
||
[dependencies] | ||
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" } | ||
AxelarGateway = { local = "../axelar_gateway" } | ||
|
||
[addresses] | ||
test = "0x9110bc3d96f77d7ddd6ef058627fb9369c6bfbedfb169228e9d20959a5f893cd" | ||
test = "0x64cb77be32074cff87043543664dafb4eb766f980d08694cffca8c8136321872" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client'); | ||
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519'); | ||
const { Secp256k1Keypair } = require('@mysten/sui.js/keypairs/secp256k1'); | ||
const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui.js/faucet'); | ||
const { publishPackage, getRandomBytes32 } = require('./utils'); | ||
const { TxBuilder } = require('../dist/tx-builder'); | ||
const { bcsStructs: { axelarStructs } } = require('../dist/bcs'); | ||
const { arrayify, hexlify, keccak256 } = require('ethers/lib/utils'); | ||
const secp256k1 = require('secp256k1'); | ||
|
||
const COMMAND_TYPE_ROTATE_SIGNERS = 1; | ||
|
||
describe.only('test', () => { | ||
let client; | ||
const operator = Ed25519Keypair.fromSecretKey(arrayify(getRandomBytes32())); | ||
const deployer = Ed25519Keypair.fromSecretKey(arrayify(getRandomBytes32())); | ||
const keypair = Ed25519Keypair.fromSecretKey(arrayify(getRandomBytes32())); | ||
const domainSeparator = getRandomBytes32(); | ||
let operatorKeys; | ||
let signers; | ||
let nonce = 0; | ||
let packageId; | ||
|
||
|
||
function calculateNextSigners() { | ||
operatorKeys = [getRandomBytes32(), getRandomBytes32(), getRandomBytes32()]; | ||
pubkeys = operatorKeys.map(key => Secp256k1Keypair.fromSecretKey(arrayify(key)).getPublicKey().toRawBytes()); | ||
const keys = operatorKeys.map((key,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; | ||
} | ||
return 0; | ||
}); | ||
operatorKeys = keys.map(key => key.privkey); | ||
signers = { | ||
signers: keys.map((key) => { | ||
return { pubkey: key.pubkey, weight: 1 }; | ||
}), | ||
threshold: 2, | ||
nonce: hexlify([++nonce]), | ||
}; | ||
} | ||
|
||
function hashMessage(data) { | ||
const toHash = new Uint8Array(data.length + 1); | ||
toHash[0] = COMMAND_TYPE_ROTATE_SIGNERS; | ||
toHash.set(data, 1); | ||
|
||
return keccak256(toHash); | ||
} | ||
|
||
function sign(privKeys, messageToSign) { | ||
const signatures = []; | ||
for(const privKey of privKeys) { | ||
const { signature, recid } = secp256k1.ecdsaSign(arrayify(keccak256(messageToSign)), arrayify(privKey)); | ||
signatures.push(new Uint8Array([...signature, recid])); | ||
} | ||
return signatures; | ||
} | ||
|
||
async function sleep(ms = 1000) { | ||
await new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
const minimumRotationDelay = 1000; | ||
before(async () => { | ||
client = new SuiClient({ url: getFullnodeUrl('localnet') }); | ||
|
||
await Promise.all([operator, deployer, keypair].map( | ||
(keypair) => requestSuiFromFaucetV0({ | ||
host: getFaucetHost('localnet'), | ||
recipient: keypair.toSuiAddress(), | ||
}) | ||
)) | ||
|
||
let result = await publishPackage(client, deployer, 'axelar_gateway'); | ||
packageId = result.packageId; | ||
const creatorCap = result.publishTxn.objectChanges.find((change) => change.objectType === `${packageId}::gateway::CreatorCap`).objectId; | ||
|
||
calculateNextSigners(); | ||
|
||
const encodedSigners = axelarStructs.WeightedSigners.serialize(signers).toBytes(); | ||
const builder = new TxBuilder(client); | ||
|
||
const separator = await builder.moveCall({ | ||
target: `${packageId}::bytes32::new`, | ||
arguments: [domainSeparator], | ||
}); | ||
|
||
await builder.moveCall({ | ||
target: `${packageId}::gateway::setup`, | ||
arguments: [ | ||
creatorCap, | ||
operator.toSuiAddress(), | ||
separator, | ||
minimumRotationDelay, | ||
encodedSigners, | ||
'0x6', | ||
] | ||
}); | ||
|
||
result = await builder.signAndExecute(deployer); | ||
|
||
gateway = result.objectChanges.find((change) => change.objectType === `${packageId}::gateway::Gateway`).objectId; | ||
}); | ||
it('Should Rotate Signers', async () => { | ||
await sleep(2000); | ||
const proofSigners = signers; | ||
const proofKeys = operatorKeys; | ||
calculateNextSigners(); | ||
|
||
const encodedSigners = axelarStructs.WeightedSigners | ||
.serialize(signers) | ||
.toBytes(); | ||
|
||
const hashed = hashMessage(encodedSigners); | ||
|
||
const message = axelarStructs.MessageToSign | ||
.serialize({ | ||
domain_separator: domainSeparator, | ||
signers_hash: keccak256(axelarStructs.WeightedSigners.serialize(proofSigners).toBytes()), | ||
data_hash: hashed, | ||
}) | ||
.toBytes(); | ||
|
||
const signatures = sign(proofKeys, message); | ||
const encodedProof = axelarStructs.Proof | ||
.serialize({ | ||
signers: proofSigners, | ||
signatures, | ||
}) | ||
.toBytes(); | ||
|
||
const builder = new TxBuilder(client); | ||
|
||
await builder.moveCall({ | ||
target: `${packageId}::gateway::rotate_signers`, | ||
arguments: [ | ||
gateway, | ||
'0x6', | ||
encodedSigners, | ||
encodedProof, | ||
], | ||
}); | ||
|
||
await builder.signAndExecute(keypair); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters