bridge: use constant for max guardians
This commit is contained in:
parent
51ed6323b4
commit
6a548e5695
|
@ -20,7 +20,8 @@ use crate::vaa::{VAABody, VAA};
|
|||
|
||||
/// chain id of this chain
|
||||
pub const CHAIN_ID_SOLANA: u8 = 1;
|
||||
|
||||
/// maximum number of guardians
|
||||
pub const MAX_LEN_GUARDIAN_KEYS: usize = 20;
|
||||
/// size of a foreign address in bytes
|
||||
const FOREIGN_ADDRESS_SIZE: usize = 32;
|
||||
|
||||
|
@ -37,7 +38,7 @@ pub struct InitializePayload {
|
|||
/// number of initial guardians
|
||||
pub len_guardians: u8,
|
||||
/// guardians that are allowed to sign mints
|
||||
pub initial_guardian: [[u8; 20]; 20],
|
||||
pub initial_guardian: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
|
||||
/// config for the bridge
|
||||
pub config: BridgeConfig,
|
||||
}
|
||||
|
@ -225,10 +226,10 @@ pub fn initialize(
|
|||
initial_guardian: Vec<[u8; 20]>,
|
||||
config: &BridgeConfig,
|
||||
) -> Result<Instruction, ProgramError> {
|
||||
if initial_guardian.len() > 20 {
|
||||
if initial_guardian.len() > MAX_LEN_GUARDIAN_KEYS {
|
||||
return Err(ProgramError::InvalidArgument);
|
||||
}
|
||||
let mut initial_g = [[0u8; 20]; 20];
|
||||
let mut initial_g = [[0u8; 20]; MAX_LEN_GUARDIAN_KEYS];
|
||||
for (i, key) in initial_guardian.iter().enumerate() {
|
||||
initial_g[i] = *key;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use spl_token::state::Mint;
|
|||
|
||||
use crate::error::Error;
|
||||
use crate::instruction::BridgeInstruction::*;
|
||||
use crate::instruction::MAX_LEN_GUARDIAN_KEYS;
|
||||
use crate::instruction::{BridgeInstruction, TransferOutPayload, VAAData, CHAIN_ID_SOLANA};
|
||||
use crate::state::*;
|
||||
use crate::vaa::{BodyTransfer, BodyUpdateGuardianSet, VAABody, VAA};
|
||||
|
@ -71,7 +72,7 @@ impl Bridge {
|
|||
program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
len_guardians: u8,
|
||||
initial_guardian_key: [[u8; 20]; 20],
|
||||
initial_guardian_key: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
|
||||
config: BridgeConfig,
|
||||
) -> ProgramResult {
|
||||
let account_info_iter = &mut accounts.iter();
|
||||
|
@ -117,7 +118,7 @@ impl Bridge {
|
|||
return Err(Error::AlreadyExists.into());
|
||||
}
|
||||
|
||||
if len_guardians > 20 {
|
||||
if len_guardians > MAX_LEN_GUARDIAN_KEYS as u8 {
|
||||
return Err(ProgramError::InvalidInstructionData);
|
||||
}
|
||||
|
||||
|
@ -130,7 +131,7 @@ impl Bridge {
|
|||
guardian_info.is_initialized = true;
|
||||
guardian_info.index = 0;
|
||||
guardian_info.creation_time = clock.unix_timestamp.as_();
|
||||
guardian_info.keys = initial_guardian_key;
|
||||
guardian_info.keys = initial_guardian_key.into();
|
||||
guardian_info.len_keys = len_guardians;
|
||||
|
||||
Ok(())
|
||||
|
@ -545,14 +546,14 @@ impl Bridge {
|
|||
return Err(Error::AlreadyExists.into());
|
||||
}
|
||||
|
||||
if b.new_keys.len() > 20 {
|
||||
if b.new_keys.len() > MAX_LEN_GUARDIAN_KEYS {
|
||||
return Err(Error::InvalidVAAFormat.into());
|
||||
}
|
||||
|
||||
// Set values on the new guardian set
|
||||
guardian_set_new.is_initialized = true;
|
||||
guardian_set_new.index = b.new_index;
|
||||
let mut new_guardians = [[0u8; 20]; 20];
|
||||
let mut new_guardians = [[0u8; 20]; MAX_LEN_GUARDIAN_KEYS];
|
||||
for (i, guardian) in b.new_keys.iter().enumerate() {
|
||||
new_guardians[i] = *guardian
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use solana_sdk::{account_info::AccountInfo, program_error::ProgramError, pubkey:
|
|||
use zerocopy::AsBytes;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::instruction::{ForeignAddress, VAAData};
|
||||
use crate::instruction::{ForeignAddress, VAAData, MAX_LEN_GUARDIAN_KEYS};
|
||||
use crate::vaa::BodyTransfer;
|
||||
|
||||
/// fee rate as a ratio
|
||||
|
@ -34,7 +34,7 @@ pub struct GuardianSet {
|
|||
/// number of keys stored
|
||||
pub len_keys: u8,
|
||||
/// public key of the threshold schnorr set
|
||||
pub keys: [[u8; 20]; 20],
|
||||
pub keys: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
|
||||
/// creation time
|
||||
pub creation_time: u32,
|
||||
/// expiration time when VAAs issued by this set are no longer valid
|
||||
|
|
Loading…
Reference in New Issue