View functions like totalSupply() and balanceOf(address) should read from storage and return the value to the caller with minimal overhead. In this codebase, _allowance demonstrates an efficient pattern: it loads a value into a local variable (remaining := sload(…)) and lets Solidity handle the return implicitly, avoiding extra memory writes.
totalSupply_ and _balanceOf manually build return data using mstore and return inside inline assembly, which adds extra memory operations and a raw return, increasing gas costs compared to the implicit return pattern used in _allowance. The discrepancy leads to avoidable gas consumption, especially when these functions are called frequently by off-chain indexers and on-chain contracts.
Likelihood: High
High usage of view functions: Calls to totalSupply() and balanceOf() occur constantly (wallets, explorers, price oracles, strategy contracts). Each call pays the overhead introduced by manual mstore + return.
Pattern repeated across code: Both functions employ the same manual return pattern, so the additional cost compounds across the most frequently used endpoints.
Impact: Medium
Increased gas for on-chain callers: On-chain systems that read balances/supply (e.g., vaults performing checks during state transitions) pay more gas than necessary.
Higher operational cost in aggregate: Even if off-chain eth_call gas is not charged to users, many rollups and metered environments account for execution resources; the inefficiency can affect system throughput and costs over time.
A minimal illustration using the two patterns side by side:
Adopt the _allowance pattern: load into a local return variable and rely on Solidity’s implicit return, removing manual mstore/return.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.