Fix rent calculation and hardening (#163)

* use proper account for min balance calculation

* check bridge key in sig verify

* check bridge key in VAA processor
This commit is contained in:
Hendrik Hofstadt 2021-01-25 15:11:38 +01:00 committed by GitHub
parent 171afb28d2
commit a5380b8ab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -210,6 +210,12 @@ impl Bridge {
return Err(Error::InvalidSysvar.into());
}
// Verify bridge key because it is used as subsidizer
let expected_bridge_key = Self::derive_bridge_id(program_id)?;
if *bridge_info.key != expected_bridge_key {
return Err(ProgramError::InvalidAccountData);
}
let guardian_data = guardian_set_info.try_borrow_data()?;
let guardian_set: &GuardianSet = Self::unpack_immutable(&guardian_data)?;
@ -691,6 +697,12 @@ impl Bridge {
let mut guardian_data = guardian_set_info.try_borrow_mut_data()?;
let guardian_set: &mut GuardianSet = Bridge::unpack(&mut guardian_data)?;
// Verify bridge key because it is used as subsidizer and for key derivation
let expected_bridge_key = Self::derive_bridge_id(program_id)?;
if *bridge_info.key != expected_bridge_key {
return Err(ProgramError::InvalidAccountData);
}
// Check that the guardian set is valid
let expected_guardian_set =
Bridge::derive_guardian_set_id(program_id, bridge_info.key, vaa.guardian_set_index)?;
@ -1269,7 +1281,7 @@ impl Bridge {
/// The amount of sol that needs to be held in the BridgeConfig account in order to make it
/// exempt of rent payments.
const MIN_BRIDGE_BALANCE: u64 = (((solana_program::rent::ACCOUNT_STORAGE_OVERHEAD + size_of::<BridgeConfig>() as u64) *
const MIN_BRIDGE_BALANCE: u64 = (((solana_program::rent::ACCOUNT_STORAGE_OVERHEAD + size_of::<Bridge>() as u64) *
solana_program::rent::DEFAULT_LAMPORTS_PER_BYTE_YEAR) as f64
* solana_program::rent::DEFAULT_EXEMPTION_THRESHOLD) as u64;