mirror of https://github.com/certusone/oyster.git
fix: use prefixes for PDAs to avoid collision attacks
This commit is contained in:
parent
c33bf0e11e
commit
66271c0c1d
|
@ -8,6 +8,7 @@ import {
|
|||
} from '@solana/web3.js';
|
||||
import { contexts, utils, models, ParsedAccount } from '@oyster/common';
|
||||
import {
|
||||
AUTHORITY_SEED_PROPOSAL,
|
||||
CustomSingleSignerTimelockTransactionLayout,
|
||||
TimelockSet,
|
||||
TimelockState,
|
||||
|
@ -50,7 +51,7 @@ export const addCustomSingleSignerTransaction = async (
|
|||
});
|
||||
|
||||
const [authority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
|
|
@ -12,7 +12,11 @@ import {
|
|||
actions,
|
||||
} from '@oyster/common';
|
||||
|
||||
import { TimelockSet, TimelockState } from '../models/timelock';
|
||||
import {
|
||||
AUTHORITY_SEED_PROPOSAL,
|
||||
TimelockSet,
|
||||
TimelockState,
|
||||
} from '../models/timelock';
|
||||
import { AccountLayout } from '@solana/spl-token';
|
||||
import { addSignerInstruction } from '../models/addSigner';
|
||||
const { createTokenAccount } = actions;
|
||||
|
@ -47,7 +51,7 @@ export const addSigner = async (
|
|||
);
|
||||
|
||||
const [mintAuthority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import { contexts, utils, actions, ParsedAccount } from '@oyster/common';
|
|||
import { AccountLayout, MintLayout } from '@solana/spl-token';
|
||||
import { initTimelockSetInstruction } from '../models/initTimelockSet';
|
||||
import {
|
||||
AUTHORITY_SEED_PROPOSAL,
|
||||
TimelockConfig,
|
||||
TimelockSetLayout,
|
||||
TimelockStateLayout,
|
||||
|
@ -205,7 +206,7 @@ async function getAssociatedAccountsAndInstructions(
|
|||
const PROGRAM_IDS = utils.programIds();
|
||||
|
||||
const [authority] = await PublicKey.findProgramAddress(
|
||||
[newProposalKey.publicKey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), newProposalKey.publicKey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
|
|
@ -12,7 +12,13 @@ import {
|
|||
actions,
|
||||
} from '@oyster/common';
|
||||
|
||||
import { TimelockConfig, TimelockSet, TimelockState } from '../models/timelock';
|
||||
import {
|
||||
AUTHORITY_SEED_PROPOSAL,
|
||||
AUTHORITY_SEED_PROPOSAL_VOTE,
|
||||
TimelockConfig,
|
||||
TimelockSet,
|
||||
TimelockState,
|
||||
} from '../models/timelock';
|
||||
|
||||
import { AccountLayout } from '@solana/spl-token';
|
||||
|
||||
|
@ -66,6 +72,7 @@ export const depositSourceTokensAndVote = async (
|
|||
|
||||
const [governanceVotingRecord] = await PublicKey.findProgramAddress(
|
||||
[
|
||||
Buffer.from(AUTHORITY_SEED_PROPOSAL_VOTE),
|
||||
PROGRAM_IDS.timelock.programId.toBuffer(),
|
||||
proposal.pubkey.toBuffer(),
|
||||
existingVoteAccount.toBuffer(),
|
||||
|
@ -107,7 +114,7 @@ export const depositSourceTokensAndVote = async (
|
|||
}
|
||||
|
||||
const [mintAuthority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import { contexts, utils, actions } from '@oyster/common';
|
|||
|
||||
import { AccountLayout, MintLayout, Token } from '@solana/spl-token';
|
||||
import {
|
||||
AUTHORITY_SEED_GOVERNANCE,
|
||||
ConsensusAlgorithm,
|
||||
ExecutionType,
|
||||
TimelockConfig,
|
||||
|
@ -118,6 +119,7 @@ export const registerProgramGovernance = async (
|
|||
|
||||
const [timelockConfigKey] = await PublicKey.findProgramAddress(
|
||||
[
|
||||
Buffer.from(AUTHORITY_SEED_GOVERNANCE),
|
||||
PROGRAM_IDS.timelock.programId.toBuffer(),
|
||||
uninitializedTimelockConfig.governanceMint.toBuffer(),
|
||||
council_mint_seed,
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
} from '@solana/web3.js';
|
||||
import { contexts, utils, models, ParsedAccount } from '@oyster/common';
|
||||
|
||||
import { TimelockSet } from '../models/timelock';
|
||||
import { AUTHORITY_SEED_PROPOSAL, TimelockSet } from '../models/timelock';
|
||||
import { removeSignerInstruction } from '../models/removeSigner';
|
||||
const { sendTransaction } = contexts.Connection;
|
||||
const { notify } = utils;
|
||||
|
@ -25,7 +25,7 @@ export const removeSigner = async (
|
|||
let instructions: TransactionInstruction[] = [];
|
||||
|
||||
const [mintAuthority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@ import {
|
|||
} from '@solana/web3.js';
|
||||
import { contexts, utils, models, ParsedAccount } from '@oyster/common';
|
||||
|
||||
import { TimelockSet, TimelockState } from '../models/timelock';
|
||||
import {
|
||||
AUTHORITY_SEED_PROPOSAL,
|
||||
TimelockSet,
|
||||
TimelockState,
|
||||
} from '../models/timelock';
|
||||
import { signInstruction } from '../models/sign';
|
||||
|
||||
const { sendTransaction } = contexts.Connection;
|
||||
|
@ -26,7 +30,7 @@ export const sign = async (
|
|||
let instructions: TransactionInstruction[] = [];
|
||||
|
||||
const [mintAuthority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import {
|
|||
} from '@oyster/common';
|
||||
|
||||
import {
|
||||
AUTHORITY_SEED_PROPOSAL,
|
||||
AUTHORITY_SEED_PROPOSAL_VOTE,
|
||||
TimelockSet,
|
||||
TimelockState,
|
||||
TimelockStateStatus,
|
||||
|
@ -79,7 +81,7 @@ export const withdrawVotingTokens = async (
|
|||
}
|
||||
|
||||
const [mintAuthority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
|
||||
|
@ -117,6 +119,7 @@ export const withdrawVotingTokens = async (
|
|||
|
||||
const [governanceVotingRecord] = await PublicKey.findProgramAddress(
|
||||
[
|
||||
Buffer.from(AUTHORITY_SEED_PROPOSAL_VOTE),
|
||||
PROGRAM_IDS.timelock.programId.toBuffer(),
|
||||
proposal.pubkey.toBuffer(),
|
||||
existingVoteAccount.toBuffer(),
|
||||
|
|
|
@ -11,6 +11,15 @@ export const INSTRUCTION_LIMIT = 450;
|
|||
export const TRANSACTION_SLOTS = 5;
|
||||
export const TEMP_FILE_TXN_SIZE = 1000;
|
||||
|
||||
/// Seed for proposal authority
|
||||
export const AUTHORITY_SEED_PROPOSAL = 'proposal';
|
||||
|
||||
/// Seed for governance authority
|
||||
export const AUTHORITY_SEED_GOVERNANCE = 'governance';
|
||||
|
||||
/// Seed for governance authority
|
||||
export const AUTHORITY_SEED_PROPOSAL_VOTE = 'proposal-vote';
|
||||
|
||||
export enum TimelockInstruction {
|
||||
InitTimelockSet = 1,
|
||||
AddSigner = 2,
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
PublicKey,
|
||||
Message,
|
||||
} from '@solana/web3.js';
|
||||
import { TimelockSet } from '../models/timelock';
|
||||
import { AUTHORITY_SEED_PROPOSAL, TimelockSet } from '../models/timelock';
|
||||
export async function serializeInstruction({
|
||||
connection,
|
||||
instr,
|
||||
|
@ -23,7 +23,7 @@ export async function serializeInstruction({
|
|||
await connection.getRecentBlockhash('max')
|
||||
).blockhash;
|
||||
const [authority] = await PublicKey.findProgramAddress(
|
||||
[proposal.pubkey.toBuffer()],
|
||||
[Buffer.from(AUTHORITY_SEED_PROPOSAL), proposal.pubkey.toBuffer()],
|
||||
PROGRAM_IDS.timelock.programId,
|
||||
);
|
||||
instructionTransaction.setSigners(authority);
|
||||
|
|
Loading…
Reference in New Issue