#39271 [SC-Insight] Check `numericAnswer` before external call to check answer is valid or not
Submitted on Jan 26th 2025 at 19:17:39 UTC by @iehnnkta for Audit Comp | Butter
Report ID: #39271
Report Type: Smart Contract
Report severity: Insight
Target: https://github.com/immunefi-team/audit-comp-butter-cfm-v1
Impacts:
Unbounded gas consumption
Description
Vulnerability Detail
In the function FlatCFM::resolve
, updates the payouts array, which further ne reported into the conditional token contract.
Here as numericAnswer
is already typecasted answer
which is in bytes32. So instead of checking answer
is invalid or not, it is highly recommended to check numericAnswer
is zero or not. Because if numericAnswer
is zero, function oracleAdapter::isInvalid
function returns false, and then numericAnswer
returns true. Which is waste of heavy amount of gas, the function making external call.
Proof of Concept
Proof of Concept
Now as you can see, same function I have recreated in the remix, to check the gas consumption of each case, i.e., numericAnswer
is being cheked first and last. In attached images also,
we can see that when
numericAnswer
checked first before checkinganswer
is invalid outcome or nor results in --653 gas
.Similarly when
numericAnswer
checked afteranswer
is invalid or not resluts in --6526 gas
Was this helpful?