Skip to content

Commit

Permalink
simplify proof submission
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Aug 27, 2024
1 parent 6faca9d commit 51224cb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ node sui/gateway.js rotate --signers wallet --proof wallet --currentNonce test -

Use the same nonce for `--currentNonce` as the `--nonce` when deploying the gateway.

To submit a proof constructed on Amplifier, run the following with the multisig session id,
```bash
node sui/gateway.js submitProof [multisig session id]
```

### Multisig

To create a Multisig, follow the documentation [here](https://docs.sui.io/guides/developer/cryptography/multisig).
Expand Down
59 changes: 38 additions & 21 deletions sui/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async function approve(keypair, client, config, chain, contractConfig, args, opt
tx.moveCall({
target: `${packageId}::gateway::approve_messages`,
arguments: [
tx.object(contractConfig.objects.gateway),
tx.object(contractConfig.objects.Gateway),
tx.pure(bcs.vector(bcs.u8()).serialize(encodedMessages).toBytes()),
tx.pure(bcs.vector(bcs.u8()).serialize(encodedProof).toBytes()),
],
Expand All @@ -213,32 +213,49 @@ async function approve(keypair, client, config, chain, contractConfig, args, opt
printInfo('Approved messages', receipt.digest);
}

async function rotateSigners(keypair, client, config, chain, contractConfig, args, options) {
async function submitProof(keypair, client, config, chain, contractConfig, args, options) {
const packageId = contractConfig.address;
const [multisigSessionId] = args;
const [ multisigSessionId ] = args;
const { payload, status } = await getMultisigProof(config, chain.axelarId, multisigSessionId);

if (!payload.verifier_set) {
throw new Error('No signers to rotate');
}

if (!status.completed) {
throw new Error('Multisig session not completed');
}

const executeData = executeDataStruct.parse(arrayify('0x' + status.completed.execute_data));

if (!payload.verifier_set) {
throw new Error('No signers to rotate');
}

const tx = new Transaction();

tx.moveCall({
target: `${packageId}::gateway::rotate_signers`,
arguments: [
tx.object(contractConfig.objects.Gateway),
tx.object(suiClockAddress),
tx.pure(bcs.vector(bcs.u8()).serialize(new Uint8Array(executeData.payload)).toBytes()),
tx.pure(bcs.vector(bcs.u8()).serialize(new Uint8Array(executeData.proof)).toBytes()),
],
});
if (payload.verifier_set) {
printInfo('Submitting rotate_signers');

tx.moveCall({
target: `${packageId}::gateway::rotate_signers`,
arguments: [
tx.object(contractConfig.objects.Gateway),
tx.object(suiClockAddress),
tx.pure(bcs.vector(bcs.u8()).serialize(new Uint8Array(executeData.payload)).toBytes()),
tx.pure(bcs.vector(bcs.u8()).serialize(new Uint8Array(executeData.proof)).toBytes()),
],
});
} else if (payload.messages) {
printInfo('Submitting approve_messages');

tx.moveCall({
target: `${packageId}::gateway::approve_messages`,
arguments: [
tx.object(contractConfig.objects.Gateway),
tx.pure(bcs.vector(bcs.u8()).serialize(new Uint8Array(executeData.payload)).toBytes()),
tx.pure(bcs.vector(bcs.u8()).serialize(new Uint8Array(executeData.proof)).toBytes()),
],
});
} else {
throw new Error(`Unknown payload type: ${payload}`);
}

const receipt = await broadcast(client, keypair, tx);

Expand Down Expand Up @@ -271,9 +288,9 @@ async function rotate(keypair, client, config, chain, contractConfig, args, opti
],
});

await broadcast(client, keypair, tx);
const receipt = await broadcast(client, keypair, tx);

printInfo('Signers rotated succesfully');
printInfo('Signers rotated', receipt.digest);
}

async function mainProcessor(processor, args, options) {
Expand Down Expand Up @@ -324,10 +341,10 @@ if (require.main === module) {
});

program
.command('rotateSigners <multisigSessionId>')
.description('Rotate signers at the gateway contract from amplifier proof')
.command('submitProof <multisigSessionId>')
.description('Submit proof for the provided amplifier multisig session id')
.action((multisigSessionId, options) => {
mainProcessor(rotateSigners, [multisigSessionId], options);
mainProcessor(submitProof, [multisigSessionId], options);
});

program
Expand Down

0 comments on commit 51224cb

Please sign in to comment.