Skip to content

Commit

Permalink
AUDIT: Hardcode vault and restaking program ids (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol authored Jan 16, 2025
1 parent 7f29462 commit fbd3dd8
Show file tree
Hide file tree
Showing 85 changed files with 347 additions and 2,139 deletions.
20 changes: 0 additions & 20 deletions cli/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ pub async fn admin_create_config(
.default_ncn_fee_bps(default_ncn_fee_bps)
.tie_breaker_admin(keypair.pubkey())
.fee_wallet(fee_wallet)
.restaking_program(handler.restaking_program_id)
.instruction();

let program = client.get_account(&handler.tip_router_program_id).await?;
Expand Down Expand Up @@ -236,7 +235,6 @@ pub async fn admin_register_st_mint(
.ncn(ncn)
.st_mint(vault_account.supported_mint)
.ncn_fee_group(ncn_fee_group.group)
.restaking_program(handler.restaking_program_id)
.reward_multiplier_bps(reward_multiplier_bps);

if let Some(switchboard_feed) = switchboard_feed {
Expand Down Expand Up @@ -293,9 +291,7 @@ pub async fn register_vault(handler: &CliHandler, vault: &Pubkey) -> Result<()>
.ncn(ncn)
.ncn_vault_ticket(ncn_vault_ticket)
.restaking_config(restaking_config)
.restaking_program_id(handler.restaking_program_id)
.vault_ncn_ticket(vault_ncn_ticket)
.vault_program_id(handler.vault_program_id)
.vault_registry(vault_registry)
.instruction();

Expand Down Expand Up @@ -409,7 +405,6 @@ pub async fn create_weight_table(handler: &CliHandler, epoch: u64) -> Result<()>
.epoch_state(epoch_state)
.weight_table(weight_table)
.payer(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -493,7 +488,6 @@ pub async fn admin_set_weight_with_st_mint(
.weight_table(weight_table)
.epoch_state(epoch_state)
.weight_table_admin(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.st_mint(*st_mint)
.weight(weight)
.epoch(epoch)
Expand Down Expand Up @@ -590,7 +584,6 @@ pub async fn create_epoch_snapshot(handler: &CliHandler, epoch: u64) -> Result<(
.weight_table(weight_table)
.epoch_snapshot(epoch_snapshot)
.payer(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -651,7 +644,6 @@ pub async fn create_operator_snapshot(
.epoch_snapshot(epoch_snapshot)
.operator_snapshot(operator_snapshot)
.payer(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -684,7 +676,6 @@ pub async fn create_operator_snapshot(
.epoch_snapshot(epoch_snapshot)
.operator_snapshot(operator_snapshot)
.payer(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -766,8 +757,6 @@ pub async fn snapshot_vault_operator_delegation(
.weight_table(weight_table)
.epoch_snapshot(epoch_snapshot)
.operator_snapshot(operator_snapshot)
.vault_program(handler.vault_program_id)
.restaking_program(handler.restaking_program_id)
.epoch(epoch)
.instruction();

Expand Down Expand Up @@ -903,7 +892,6 @@ pub async fn admin_cast_vote(
.operator_snapshot(operator_snapshot)
.operator(operator)
.operator_admin(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.meta_merkle_root(meta_merkle_root)
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -949,7 +937,6 @@ pub async fn create_base_reward_router(handler: &CliHandler, epoch: u64) -> Resu
.base_reward_router(base_reward_router)
.base_reward_receiver(base_reward_receiver)
.payer(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -1045,7 +1032,6 @@ pub async fn create_ncn_reward_router(
.ncn_reward_router(ncn_reward_router)
.ncn_reward_receiver(ncn_reward_receiver)
.payer(keypair.pubkey())
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.ncn_fee_group(ncn_fee_group.group)
.epoch(epoch)
Expand Down Expand Up @@ -1098,7 +1084,6 @@ pub async fn route_base_rewards(handler: &CliHandler, epoch: u64) -> Result<()>
.ballot_box(ballot_box)
.base_reward_router(base_reward_router)
.base_reward_receiver(base_reward_receiver)
.restaking_program(handler.restaking_program_id)
.max_iterations(max_iterations)
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -1177,7 +1162,6 @@ pub async fn route_ncn_rewards(
.operator_snapshot(operator_snapshot)
.ncn_reward_router(ncn_reward_router)
.ncn_reward_receiver(ncn_reward_receiver)
.restaking_program(handler.restaking_program_id)
.ncn_fee_group(ncn_fee_group.group)
.max_iterations(max_iterations)
.epoch(epoch)
Expand Down Expand Up @@ -1259,7 +1243,6 @@ pub async fn distribute_base_ncn_rewards(
.base_reward_receiver(base_reward_receiver)
.ncn_reward_router(ncn_reward_router)
.ncn_reward_receiver(ncn_reward_receiver)
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.ncn_fee_group(ncn_fee_group.group)
.epoch(epoch)
Expand Down Expand Up @@ -1326,7 +1309,6 @@ pub async fn distribute_base_rewards(
.ncn(ncn)
.base_reward_router(base_reward_router)
.base_reward_receiver(base_reward_receiver)
.restaking_program(handler.restaking_program_id)
.system_program(system_program::id())
.epoch(epoch)
.base_fee_wallet(*base_fee_wallet)
Expand Down Expand Up @@ -1522,7 +1504,6 @@ pub async fn distribute_ncn_operator_rewards(
.stake_pool_program(stake_pool_accounts.stake_pool_program_id)
.token_program(handler.token_program_id)
.system_program(system_program::id())
.restaking_program(handler.restaking_program_id)
.ncn_fee_group(ncn_fee_group.group)
.epoch(epoch)
.instruction();
Expand Down Expand Up @@ -1570,7 +1551,6 @@ pub async fn admin_set_tie_breaker(
.tie_breaker_admin(keypair.pubkey())
.meta_merkle_root(meta_merkle_root)
.epoch(epoch)
.restaking_program(handler.restaking_program_id)
.instruction();

send_and_log_transaction(
Expand Down
25 changes: 4 additions & 21 deletions clients/js/jito_tip_router/instructions/adminRegisterStMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export type AdminRegisterStMintInstruction<
TAccountStMint extends string | IAccountMeta<string> = string,
TAccountVaultRegistry extends string | IAccountMeta<string> = string,
TAccountAdmin extends string | IAccountMeta<string> = string,
TAccountRestakingProgram extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
Expand All @@ -73,9 +72,6 @@ export type AdminRegisterStMintInstruction<
? WritableSignerAccount<TAccountAdmin> &
IAccountSignerMeta<TAccountAdmin>
: TAccountAdmin,
TAccountRestakingProgram extends string
? ReadonlyAccount<TAccountRestakingProgram>
: TAccountRestakingProgram,
...TRemainingAccounts,
]
>;
Expand Down Expand Up @@ -137,14 +133,12 @@ export type AdminRegisterStMintInput<
TAccountStMint extends string = string,
TAccountVaultRegistry extends string = string,
TAccountAdmin extends string = string,
TAccountRestakingProgram extends string = string,
> = {
config: Address<TAccountConfig>;
ncn: Address<TAccountNcn>;
stMint: Address<TAccountStMint>;
vaultRegistry: Address<TAccountVaultRegistry>;
admin: TransactionSigner<TAccountAdmin>;
restakingProgram: Address<TAccountRestakingProgram>;
ncnFeeGroup: AdminRegisterStMintInstructionDataArgs['ncnFeeGroup'];
rewardMultiplierBps: AdminRegisterStMintInstructionDataArgs['rewardMultiplierBps'];
switchboardFeed: AdminRegisterStMintInstructionDataArgs['switchboardFeed'];
Expand All @@ -157,16 +151,14 @@ export function getAdminRegisterStMintInstruction<
TAccountStMint extends string,
TAccountVaultRegistry extends string,
TAccountAdmin extends string,
TAccountRestakingProgram extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: AdminRegisterStMintInput<
TAccountConfig,
TAccountNcn,
TAccountStMint,
TAccountVaultRegistry,
TAccountAdmin,
TAccountRestakingProgram
TAccountAdmin
>,
config?: { programAddress?: TProgramAddress }
): AdminRegisterStMintInstruction<
Expand All @@ -175,8 +167,7 @@ export function getAdminRegisterStMintInstruction<
TAccountNcn,
TAccountStMint,
TAccountVaultRegistry,
TAccountAdmin,
TAccountRestakingProgram
TAccountAdmin
> {
// Program address.
const programAddress =
Expand All @@ -189,10 +180,6 @@ export function getAdminRegisterStMintInstruction<
stMint: { value: input.stMint ?? null, isWritable: false },
vaultRegistry: { value: input.vaultRegistry ?? null, isWritable: true },
admin: { value: input.admin ?? null, isWritable: true },
restakingProgram: {
value: input.restakingProgram ?? null,
isWritable: false,
},
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
Expand All @@ -210,7 +197,6 @@ export function getAdminRegisterStMintInstruction<
getAccountMeta(accounts.stMint),
getAccountMeta(accounts.vaultRegistry),
getAccountMeta(accounts.admin),
getAccountMeta(accounts.restakingProgram),
],
programAddress,
data: getAdminRegisterStMintInstructionDataEncoder().encode(
Expand All @@ -222,8 +208,7 @@ export function getAdminRegisterStMintInstruction<
TAccountNcn,
TAccountStMint,
TAccountVaultRegistry,
TAccountAdmin,
TAccountRestakingProgram
TAccountAdmin
>;

return instruction;
Expand All @@ -240,7 +225,6 @@ export type ParsedAdminRegisterStMintInstruction<
stMint: TAccountMetas[2];
vaultRegistry: TAccountMetas[3];
admin: TAccountMetas[4];
restakingProgram: TAccountMetas[5];
};
data: AdminRegisterStMintInstructionData;
};
Expand All @@ -253,7 +237,7 @@ export function parseAdminRegisterStMintInstruction<
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedAdminRegisterStMintInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 6) {
if (instruction.accounts.length < 5) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -271,7 +255,6 @@ export function parseAdminRegisterStMintInstruction<
stMint: getNextAccount(),
vaultRegistry: getNextAccount(),
admin: getNextAccount(),
restakingProgram: getNextAccount(),
},
data: getAdminRegisterStMintInstructionDataDecoder().decode(
instruction.data
Expand Down
29 changes: 4 additions & 25 deletions clients/js/jito_tip_router/instructions/adminSetConfigFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export type AdminSetConfigFeesInstruction<
TAccountConfig extends string | IAccountMeta<string> = string,
TAccountNcn extends string | IAccountMeta<string> = string,
TAccountNcnAdmin extends string | IAccountMeta<string> = string,
TAccountRestakingProgram extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
Expand All @@ -63,9 +62,6 @@ export type AdminSetConfigFeesInstruction<
? ReadonlySignerAccount<TAccountNcnAdmin> &
IAccountSignerMeta<TAccountNcnAdmin>
: TAccountNcnAdmin,
TAccountRestakingProgram extends string
? ReadonlyAccount<TAccountRestakingProgram>
: TAccountRestakingProgram,
...TRemainingAccounts,
]
>;
Expand Down Expand Up @@ -133,12 +129,10 @@ export type AdminSetConfigFeesInput<
TAccountConfig extends string = string,
TAccountNcn extends string = string,
TAccountNcnAdmin extends string = string,
TAccountRestakingProgram extends string = string,
> = {
config: Address<TAccountConfig>;
ncn: Address<TAccountNcn>;
ncnAdmin: TransactionSigner<TAccountNcnAdmin>;
restakingProgram: Address<TAccountRestakingProgram>;
newBlockEngineFeeBps: AdminSetConfigFeesInstructionDataArgs['newBlockEngineFeeBps'];
baseFeeGroup: AdminSetConfigFeesInstructionDataArgs['baseFeeGroup'];
newBaseFeeWallet: AdminSetConfigFeesInstructionDataArgs['newBaseFeeWallet'];
Expand All @@ -151,22 +145,15 @@ export function getAdminSetConfigFeesInstruction<
TAccountConfig extends string,
TAccountNcn extends string,
TAccountNcnAdmin extends string,
TAccountRestakingProgram extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: AdminSetConfigFeesInput<
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountRestakingProgram
>,
input: AdminSetConfigFeesInput<TAccountConfig, TAccountNcn, TAccountNcnAdmin>,
config?: { programAddress?: TProgramAddress }
): AdminSetConfigFeesInstruction<
TProgramAddress,
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountRestakingProgram
TAccountNcnAdmin
> {
// Program address.
const programAddress =
Expand All @@ -177,10 +164,6 @@ export function getAdminSetConfigFeesInstruction<
config: { value: input.config ?? null, isWritable: true },
ncn: { value: input.ncn ?? null, isWritable: false },
ncnAdmin: { value: input.ncnAdmin ?? null, isWritable: false },
restakingProgram: {
value: input.restakingProgram ?? null,
isWritable: false,
},
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
Expand All @@ -196,7 +179,6 @@ export function getAdminSetConfigFeesInstruction<
getAccountMeta(accounts.config),
getAccountMeta(accounts.ncn),
getAccountMeta(accounts.ncnAdmin),
getAccountMeta(accounts.restakingProgram),
],
programAddress,
data: getAdminSetConfigFeesInstructionDataEncoder().encode(
Expand All @@ -206,8 +188,7 @@ export function getAdminSetConfigFeesInstruction<
TProgramAddress,
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountRestakingProgram
TAccountNcnAdmin
>;

return instruction;
Expand All @@ -222,7 +203,6 @@ export type ParsedAdminSetConfigFeesInstruction<
config: TAccountMetas[0];
ncn: TAccountMetas[1];
ncnAdmin: TAccountMetas[2];
restakingProgram: TAccountMetas[3];
};
data: AdminSetConfigFeesInstructionData;
};
Expand All @@ -235,7 +215,7 @@ export function parseAdminSetConfigFeesInstruction<
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedAdminSetConfigFeesInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 4) {
if (instruction.accounts.length < 3) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -251,7 +231,6 @@ export function parseAdminSetConfigFeesInstruction<
config: getNextAccount(),
ncn: getNextAccount(),
ncnAdmin: getNextAccount(),
restakingProgram: getNextAccount(),
},
data: getAdminSetConfigFeesInstructionDataDecoder().decode(
instruction.data
Expand Down
Loading

0 comments on commit fbd3dd8

Please sign in to comment.