Skip to content

Commit aaa6912

Browse files
committed
solana: Add more err handling and documentation
1 parent 592063c commit aaa6912

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

solana/programs/ntt-quoter/src/processor/request_relay.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const GWEI: u64 = u64::pow(10, 9);
9292
// might be more efficient to use f64 or ruint crate
9393
// SECURITY: Integer division is OK here. The calling code is responsible for understanding that
9494
// this function returns the quotient of the operation and that the remainder will be lost.
95+
// The divisor is explicitly checked in this function.
9596
#[allow(clippy::integer_division)]
9697
fn mul_div(scalar: u64, numerator: u64, denominator: u64) -> StdResult<u64, NttQuoterError> {
9798
if denominator == 0 {

solana/programs/ntt-quoter/src/processor/update_prices.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ pub struct UpdateSolPrice<'info> {
1616
)]
1717
pub authority: Signer<'info>,
1818

19-
#[account(mut)]
2019
pub instance: Account<'info, Instance>,
2120
}
2221

2322
pub fn update_sol_price(ctx: Context<UpdateSolPrice>, args: UpdateSolPriceArgs) -> Result<()> {
23+
// `sol_price` is used as a divisor in arithmetic operations so it is invalid for its value to
24+
// be zero.
25+
if args.sol_price == 0 {
26+
return Err(NttQuoterError::PriceCannotBeZero.into());
27+
}
2428
ctx.accounts.instance.sol_price = args.sol_price;
2529
Ok(())
2630
}

0 commit comments

Comments
 (0)