-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
chains/solana/contracts/programs/ccip-router/src/instructions/v1/ocr3impl.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use anchor_lang::AnchorSerialize; | ||
|
||
use crate::{CommitInput, ExecutionReportSingleChain}; | ||
|
||
use super::ocr3base::{Ocr3Report, ReportContext}; | ||
|
||
pub struct Ocr3ReportForCommit<'a>(pub &'a CommitInput); | ||
|
||
impl Ocr3Report for Ocr3ReportForCommit<'_> { | ||
fn hash(&self, ctx: &ReportContext) -> [u8; 32] { | ||
use anchor_lang::solana_program::hash; | ||
let mut buffer: Vec<u8> = Vec::new(); | ||
self.0.serialize(&mut buffer).unwrap(); | ||
let report_len = self.len() as u16; // u16 > max tx size, u8 may have overflow | ||
hash::hashv(&[&report_len.to_le_bytes(), &buffer, &ctx.as_bytes()]).to_bytes() | ||
} | ||
|
||
fn len(&self) -> usize { | ||
4 + (32 + 28) * self.0.price_updates.token_price_updates.len() + // token_price_updates | ||
4 + (8 + 28) * self.0.price_updates.gas_price_updates.len() + // gas_price_updates | ||
self.0.merkle_root.len() | ||
// + 4 + 65 * self.rmn_signatures.len() | ||
} | ||
} | ||
|
||
pub struct Ocr3ReportForExecutionReportSingleChain<'a>(pub &'a ExecutionReportSingleChain); | ||
|
||
impl Ocr3Report for Ocr3ReportForExecutionReportSingleChain<'_> { | ||
fn hash(&self, _: &ReportContext) -> [u8; 32] { | ||
[0; 32] // not needed, this report is not hashed for signing | ||
} | ||
fn len(&self) -> usize { | ||
let offchain_token_data_len = self | ||
.0 | ||
.offchain_token_data | ||
.iter() | ||
.fold(0, |acc, e| acc + 4 + e.len()); | ||
|
||
8 // source chain selector | ||
+ self.0.message.len() // ccip message | ||
+ 4 + offchain_token_data_len// offchain_token_data | ||
+ 32 // root | ||
+ 4 + self.0.proofs.len() * 32 // count + proofs | ||
+ 4 + self.0.token_indexes.len() // token_indexes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters