Skip to content

Commit

Permalink
fix(dr): convert gas limits to u128 to prevent overflow
Browse files Browse the repository at this point in the history
Also satisfy clippy.
  • Loading branch information
Thomasvdam committed Jan 21, 2025
1 parent 5e23963 commit 2269a44
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 51 deletions.
4 changes: 2 additions & 2 deletions contract/src/msgs/data_requests/execute/post_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ impl ExecuteHandler for execute::post_request::Execute {
// Take the funds from the user
let token = TOKEN.load(deps.storage)?;
let funds = cw_utils::must_pay(&info, &token)?;
let required =
Uint128::from(self.posted_dr.exec_gas_limit + self.posted_dr.tally_gas_limit) * self.posted_dr.gas_price;
let required = (Uint128::from(self.posted_dr.exec_gas_limit) + Uint128::from(self.posted_dr.tally_gas_limit))
* self.posted_dr.gas_price;
if funds < required {
return Err(ContractError::InsufficientFunds(
required,
Expand Down
3 changes: 2 additions & 1 deletion contract/src/msgs/data_requests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl TestInfo {
seda_payload: Vec<u8>,
payback_address: Vec<u8>,
env_height: u64,
funds: Option<u128>,
) -> Result<String, ContractError> {
let msg = execute::post_request::Execute {
posted_dr,
Expand All @@ -111,7 +112,7 @@ impl TestInfo {
self.set_block_height(env_height);

// someone posts a data request
let res: PostRequestResponsePayload = self.execute_with_funds(sender, &msg, 20)?;
let res: PostRequestResponsePayload = self.execute_with_funds(sender, &msg, funds.unwrap_or(20))?;
assert_eq!(
env_height, res.height,
"chain height does not match data request height"
Expand Down
Loading

0 comments on commit 2269a44

Please sign in to comment.