Skip to content

Commit

Permalink
feat(multisig_create): remove allow_external_execute
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed Jan 25, 2023
1 parent 76ece1f commit 7158f2c
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 52 deletions.
5 changes: 1 addition & 4 deletions programs/multisig/src/instructions/multisig_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub struct MultisigCreateArgs {
pub members: Vec<Member>,
/// Any key that is used to seed the multisig pda. Used solely as bytes for the seed, doesn't have any other meaning.
pub create_key: Pubkey,
/// Whether to allow non-member keys to execute txs.
pub allow_external_execute: Option<bool>,
/// Memo isn't used for anything, but is included in `CreatedEvent` that can later be parsed and indexed.
pub memo: Option<String>,
}
Expand Down Expand Up @@ -72,12 +70,11 @@ impl MultisigCreate<'_> {
multisig.authority_index = 1; // Default vault is the first authority.
multisig.transaction_index = 0;
multisig.stale_transaction_index = 0;
multisig.allow_external_execute = args.allow_external_execute.unwrap_or(false);
multisig.create_key = args.create_key;
multisig.bump = *ctx.bumps.get("multisig").unwrap();

emit!(MultisigCreated {
multisig: ctx.accounts.multisig.to_account_info().key.clone(),
multisig: ctx.accounts.multisig.to_account_info().key(),
memo: args.memo,
});

Expand Down
5 changes: 3 additions & 2 deletions programs/multisig/src/instructions/transaction_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct TransactionExecute<'info> {

#[account(
mut,
constraint = multisig.is_member(member.key()).is_some() || multisig.allow_external_execute @ MultisigError::NotAMember,
constraint = multisig.member_has_permission(member.key(), Permission::Execute) || multisig.allow_external_execute @ MultisigError::Unauthorized,
constraint = multisig.is_member(member.key()).is_some() @ MultisigError::NotAMember,
constraint = multisig.member_has_permission(member.key(), Permission::Execute) @ MultisigError::Unauthorized,
)]
pub member: Signer<'info>,
// `remaining_accounts` must include the following accounts in the exact order:
Expand Down Expand Up @@ -80,6 +80,7 @@ impl TransactionExecute<'_> {

// Execute the transaction instructions one-by-one.
for (ix, account_infos) in executable_message.to_instructions_and_accounts().iter() {
// FIXME: Prevent reentrancy.
invoke_signed(ix, account_infos, &[authority_seeds])?;
}

Expand Down
4 changes: 2 additions & 2 deletions programs/multisig/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct Multisig {
/// Last stale transaction index. All transactions up until this index are stale.
/// This index is updated when multisig config (members/threshold) changes.
pub stale_transaction_index: u64,
/// Whether to allow non-member keys to execute txs.
pub allow_external_execute: bool,
/// Reserved for future use.
pub _reserved: u8,
/// Key that is used to seed the multisig PDA.
/// Used solely as bytes for the seed, doesn't have any other meaning or function.
pub create_key: Pubkey,
Expand Down
6 changes: 3 additions & 3 deletions programs/multisig/src/utils/small_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use anchor_lang::prelude::*;
#[derive(Clone, Debug, Default)]
pub struct SmallVec<L, T>(Vec<T>, PhantomData<L>);

impl<L, T> Into<Vec<T>> for SmallVec<L, T> {
fn into(self) -> Vec<T> {
self.0
impl<L, T> From<SmallVec<L, T>> for Vec<T> {
fn from(val: SmallVec<L, T>) -> Self {
val.0
}
}

Expand Down
15 changes: 3 additions & 12 deletions sdk/multisig/idl/multisig.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@
"type": "u64"
},
{
"name": "allowExternalExecute",
"name": "reserved",
"docs": [
"Whether to allow non-member keys to execute txs."
"Reserved for future use."
],
"type": "bool"
"type": "u8"
},
{
"name": "createKey",
Expand Down Expand Up @@ -411,15 +411,6 @@
],
"type": "publicKey"
},
{
"name": "allowExternalExecute",
"docs": [
"Whether to allow non-member keys to execute txs."
],
"type": {
"option": "bool"
}
},
{
"name": "memo",
"docs": [
Expand Down
10 changes: 5 additions & 5 deletions sdk/multisig/src/generated/accounts/Multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type MultisigArgs = {
authorityIndex: number
transactionIndex: beet.bignum
staleTransactionIndex: beet.bignum
allowExternalExecute: boolean
reserved: number
createKey: web3.PublicKey
bump: number
}
Expand All @@ -43,7 +43,7 @@ export class Multisig implements MultisigArgs {
readonly authorityIndex: number,
readonly transactionIndex: beet.bignum,
readonly staleTransactionIndex: beet.bignum,
readonly allowExternalExecute: boolean,
readonly reserved: number,
readonly createKey: web3.PublicKey,
readonly bump: number
) {}
Expand All @@ -59,7 +59,7 @@ export class Multisig implements MultisigArgs {
args.authorityIndex,
args.transactionIndex,
args.staleTransactionIndex,
args.allowExternalExecute,
args.reserved,
args.createKey,
args.bump
)
Expand Down Expand Up @@ -196,7 +196,7 @@ export class Multisig implements MultisigArgs {
}
return x
})(),
allowExternalExecute: this.allowExternalExecute,
reserved: this.reserved,
createKey: this.createKey.toBase58(),
bump: this.bump,
}
Expand All @@ -221,7 +221,7 @@ export const multisigBeet = new beet.FixableBeetStruct<
['authorityIndex', beet.u8],
['transactionIndex', beet.u64],
['staleTransactionIndex', beet.u64],
['allowExternalExecute', beet.bool],
['reserved', beet.u8],
['createKey', beetSolana.publicKey],
['bump', beet.u8],
],
Expand Down
2 changes: 0 additions & 2 deletions sdk/multisig/src/generated/types/MultisigCreateArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type MultisigCreateArgs = {
threshold: number
members: Member[]
createKey: web3.PublicKey
allowExternalExecute: beet.COption<boolean>
memo: beet.COption<string>
}

Expand All @@ -29,7 +28,6 @@ export const multisigCreateArgsBeet =
['threshold', beet.u16],
['members', beet.array(memberBeet)],
['createKey', beetSolana.publicKey],
['allowExternalExecute', beet.coption(beet.bool)],
['memo', beet.coption(beet.utf8String)],
],
'MultisigCreateArgs'
Expand Down
2 changes: 2 additions & 0 deletions sdk/multisig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export * from "./pda.js";
export * as rpc from "./rpc.js";
/** Transactions for the multisig program. */
export * as transactions from "./transactions.js";
/** Instructions for the multisig program. */
export * as instructions from "./instructions.js";
/** Additional types */
export * as types from "./types.js";
/** Utils for the multisig program. */
Expand Down
36 changes: 36 additions & 0 deletions sdk/multisig/src/instructions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { createMultisigCreateInstruction, Member } from "./generated";

export function multisigCreate({
creator,
multisigPda,
configAuthority,
threshold,
members,
createKey,
memo,
}: {
creator: PublicKey;
multisigPda: PublicKey;
configAuthority: PublicKey;
threshold: number;
members: Member[];
createKey: PublicKey;
memo?: string;
}): TransactionInstruction {
return createMultisigCreateInstruction(
{
creator,
multisig: multisigPda,
},
{
args: {
configAuthority,
threshold,
members,
createKey,
memo: memo ?? null,
},
}
);
}
3 changes: 0 additions & 3 deletions sdk/multisig/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export async function multisigCreate({
threshold,
members,
createKey,
allowExternalExecute,
memo,
sendOptions,
}: {
Expand All @@ -31,7 +30,6 @@ export async function multisigCreate({
threshold: number;
members: Member[];
createKey: PublicKey;
allowExternalExecute?: boolean;
memo?: string;
sendOptions?: SendOptions;
}): Promise<TransactionSignature> {
Expand All @@ -45,7 +43,6 @@ export async function multisigCreate({
threshold,
members,
createKey,
allowExternalExecute,
memo,
});

Expand Down
28 changes: 10 additions & 18 deletions sdk/multisig/src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { getAuthorityPda, getTransactionPda } from "./pda";
import { transactionMessageBeet } from "./types";
import { isSignerIndex, isStaticWritableIndex } from "./utils";
import * as instructions from "./instructions.js";

/** Returns unsigned `VersionedTransaction` that needs to be signed by `creator` before sending it. */
export function multisigCreate({
Expand All @@ -29,7 +30,6 @@ export function multisigCreate({
threshold,
members,
createKey,
allowExternalExecute,
memo,
}: {
blockhash: string;
Expand All @@ -39,29 +39,21 @@ export function multisigCreate({
threshold: number;
members: Member[];
createKey: PublicKey;
allowExternalExecute?: boolean;
memo?: string;
}): VersionedTransaction {
const message = new TransactionMessage({
payerKey: creator,
recentBlockhash: blockhash,
instructions: [
createMultisigCreateInstruction(
{
creator,
multisig: multisigPda,
},
{
args: {
configAuthority,
threshold,
members,
createKey,
allowExternalExecute: allowExternalExecute ?? null,
memo: memo ?? null,
},
}
),
instructions.multisigCreate({
creator,
multisigPda,
configAuthority,
threshold,
members,
createKey,
memo,
}),
],
}).compileToV0Message();

Expand Down
1 change: 0 additions & 1 deletion tests/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ describe("multisig", () => {
assert.strictEqual(multisigAccount.authorityIndex, 1);
assert.strictEqual(multisigAccount.transactionIndex.toString(), "0");
assert.strictEqual(multisigAccount.staleTransactionIndex.toString(), "0");
assert.strictEqual(multisigAccount.allowExternalExecute, false);
assert.strictEqual(
multisigAccount.createKey.toBase58(),
autonomousMultisigCreateKey.toBase58()
Expand Down

0 comments on commit 7158f2c

Please sign in to comment.