Skip to content

Commit

Permalink
Invalidate transactions when owner set changes
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Mar 10, 2021
1 parent be70755 commit ae220ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions programs/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod multisig {
multisig.owners = owners;
multisig.threshold = threshold;
multisig.nonce = nonce;
multisig.owner_set_seqno = 0;
Ok(())
}

Expand Down Expand Up @@ -69,6 +70,7 @@ pub mod multisig {
tx.signers = signers;
tx.multisig = *ctx.accounts.multisig.to_account_info().key;
tx.did_execute = false;
tx.owner_set_seqno = ctx.accounts.multisig.owner_set_seqno;

Ok(())
}
Expand Down Expand Up @@ -98,6 +100,8 @@ pub mod multisig {
}

multisig.owners = owners;
multisig.owner_set_seqno += 1;

Ok(())
}

Expand Down Expand Up @@ -184,6 +188,7 @@ pub struct CreateTransaction<'info> {

#[derive(Accounts)]
pub struct Approve<'info> {
#[account("multisig.owner_set_seqno == transaction.owner_set_seqno")]
multisig: ProgramAccount<'info, Multisig>,
#[account(mut, belongs_to = multisig)]
transaction: ProgramAccount<'info, Transaction>,
Expand All @@ -205,6 +210,7 @@ pub struct Auth<'info> {

#[derive(Accounts)]
pub struct ExecuteTransaction<'info> {
#[account("multisig.owner_set_seqno == transaction.owner_set_seqno")]
multisig: ProgramAccount<'info, Multisig>,
#[account(seeds = [
multisig.to_account_info().key.as_ref(),
Expand All @@ -220,6 +226,7 @@ pub struct Multisig {
owners: Vec<Pubkey>,
threshold: u64,
nonce: u8,
owner_set_seqno: u32,
}

#[account]
Expand All @@ -236,6 +243,8 @@ pub struct Transaction {
signers: Vec<bool>,
// Boolean ensuring one time execution.
did_execute: bool,
// Owner set sequence number.
owner_set_seqno: u32,
}

impl From<&Transaction> for Instruction {
Expand Down
4 changes: 3 additions & 1 deletion tests/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ describe("multisig", () => {
});

let multisigAccount = await program.account.multisig(multisig.publicKey);

assert.equal(multisigAccount.nonce, nonce);
assert.ok(multisigAccount.threshold.eq(new anchor.BN(2)));
assert.deepEqual(multisigAccount.owners, owners);
assert.ok(multisigAccount.ownerSetSeqno === 0);

const pid = program.programId;
const accounts = [
Expand Down Expand Up @@ -88,6 +88,7 @@ describe("multisig", () => {
assert.deepEqual(txAccount.data, data);
assert.ok(txAccount.multisig.equals(multisig.publicKey));
assert.equal(txAccount.didExecute, false);
assert.ok(txAccount.ownerSetSeqno === 0);

// Other owner approves transactoin.
await program.rpc.approve({
Expand Down Expand Up @@ -129,5 +130,6 @@ describe("multisig", () => {
assert.equal(multisigAccount.nonce, nonce);
assert.ok(multisigAccount.threshold.eq(new anchor.BN(2)));
assert.deepEqual(multisigAccount.owners, newOwners);
assert.ok(multisigAccount.ownerSetSeqno === 1);
});
});

0 comments on commit ae220ce

Please sign in to comment.