bridge: properly handle VAA submissions
This commit is contained in:
parent
206eca5ac5
commit
042ff4a14b
|
@ -100,6 +100,9 @@ pub enum Error {
|
||||||
/// Cannot wrap a solana native asset
|
/// Cannot wrap a solana native asset
|
||||||
#[error("CannotWrapNative")]
|
#[error("CannotWrapNative")]
|
||||||
CannotWrapNative,
|
CannotWrapNative,
|
||||||
|
/// VAA for this transfer has already been submitted
|
||||||
|
#[error("VAAAlreadySubmitted")]
|
||||||
|
VAAAlreadySubmitted,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Error> for ProgramError {
|
impl From<Error> for ProgramError {
|
||||||
|
|
|
@ -38,6 +38,7 @@ impl PrintProgramError for Error {
|
||||||
Error::SameChainTransfer => info!("Error: SameChainTransfer"),
|
Error::SameChainTransfer => info!("Error: SameChainTransfer"),
|
||||||
Error::VAATooLong => info!("Error: VAATooLong"),
|
Error::VAATooLong => info!("Error: VAATooLong"),
|
||||||
Error::CannotWrapNative => info!("Error: CannotWrapNative"),
|
Error::CannotWrapNative => info!("Error: CannotWrapNative"),
|
||||||
|
Error::VAAAlreadySubmitted => info!("Error: VAAAlreadySubmitted"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,12 @@ use crate::vaa::{VAABody, VAA};
|
||||||
pub const CHAIN_ID_SOLANA: u8 = 1;
|
pub const CHAIN_ID_SOLANA: u8 = 1;
|
||||||
/// maximum number of guardians
|
/// maximum number of guardians
|
||||||
pub const MAX_LEN_GUARDIAN_KEYS: usize = 20;
|
pub const MAX_LEN_GUARDIAN_KEYS: usize = 20;
|
||||||
|
/// maximum size of a posted VAA
|
||||||
|
pub const MAX_VAA_SIZE: usize = 1000;
|
||||||
/// size of a foreign address in bytes
|
/// size of a foreign address in bytes
|
||||||
const FOREIGN_ADDRESS_SIZE: usize = 32;
|
const FOREIGN_ADDRESS_SIZE: usize = 32;
|
||||||
|
|
||||||
/// length-prefixed serialized validator payment approval data
|
/// serialized VAA data
|
||||||
pub type VAAData = Vec<u8>;
|
pub type VAAData = Vec<u8>;
|
||||||
/// X and Y point of P for guardians
|
/// X and Y point of P for guardians
|
||||||
pub type GuardianKey = [u8; 64];
|
pub type GuardianKey = [u8; 64];
|
||||||
|
|
|
@ -654,9 +654,19 @@ impl Bridge {
|
||||||
if !proposal.matches_vaa(b) {
|
if !proposal.matches_vaa(b) {
|
||||||
return Err(Error::VAAProposalMismatch.into());
|
return Err(Error::VAAProposalMismatch.into());
|
||||||
}
|
}
|
||||||
|
if proposal.vaa_time != 0 {
|
||||||
|
return Err(Error::VAAAlreadySubmitted.into());
|
||||||
|
}
|
||||||
|
if vaa_data.len() > MAX_VAA_SIZE {
|
||||||
|
return Err(Error::VAATooLong.into());
|
||||||
|
}
|
||||||
|
|
||||||
// Set vaa
|
// Set vaa
|
||||||
proposal.vaa;
|
for i in 0..vaa_data.len() {
|
||||||
|
proposal.vaa[i] = vaa_data[i]
|
||||||
|
}
|
||||||
|
// Stop byte
|
||||||
|
proposal.vaa[vaa_data.len()] = 0xff;
|
||||||
proposal.vaa_time = vaa.timestamp;
|
proposal.vaa_time = vaa.timestamp;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -11,7 +11,7 @@ use solana_sdk::{account_info::AccountInfo, program_error::ProgramError, pubkey:
|
||||||
use zerocopy::AsBytes;
|
use zerocopy::AsBytes;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::instruction::{ForeignAddress, VAAData, MAX_LEN_GUARDIAN_KEYS};
|
use crate::instruction::{ForeignAddress, VAAData, MAX_LEN_GUARDIAN_KEYS, MAX_VAA_SIZE};
|
||||||
use crate::vaa::BodyTransfer;
|
use crate::vaa::BodyTransfer;
|
||||||
|
|
||||||
/// fee rate as a ratio
|
/// fee rate as a ratio
|
||||||
|
@ -65,7 +65,8 @@ pub struct TransferOutProposal {
|
||||||
/// nonce of the transfer
|
/// nonce of the transfer
|
||||||
pub nonce: u32,
|
pub nonce: u32,
|
||||||
/// vaa to unlock the tokens on the foreign chain
|
/// vaa to unlock the tokens on the foreign chain
|
||||||
pub vaa: [u8; 1000],
|
/// it is +1 byte long to make space for the termination byte
|
||||||
|
pub vaa: [u8; MAX_VAA_SIZE + 1],
|
||||||
/// time the vaa was submitted
|
/// time the vaa was submitted
|
||||||
pub vaa_time: u32,
|
pub vaa_time: u32,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue