OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

[Gas-1] Functions in `OrderBook` contract that are Never Called Within the Same Contract and are marked as `public` should be marked as `external` to Save Gas

Description:
In the current implementation of the OrderBook contract, several functions are declared with public visibility. However, these functions are never invoked from within the contract itself, they are only intended to be called externally by users or other contracts. In Solidity, functions marked as public can be accessed both externally and internally, while external functions can only be called from outside the contract. Marking such functions as external instead of public is a best practice when internal calls are not required.

Impact:
If left unaddressed, this inefficiency can accumulate, especially as the protocol scales and more users interact with these functions. It also sets a precedent for suboptimal gas usage, which can be avoided with a simple change in function visibility. Additionally, using the most restrictive and appropriate visibility modifiers improves code clarity and maintainability, making it easier for future developers and auditors to understand the intended usage of each function.

Recommended Mitigation:
Review all functions in the OrderBook contract that are currently marked as public and are not called internally. Change their visibility from public to external to optimize gas usage. This includes, but may not be limited to, functions such as createSellOrder, amendSellOrder, cancelSellOrder, buyOrder, getOrder, and getOrderDetailsString. Adopting this practice will help reduce gas costs for users and improve the overall efficiency of the contract.

function createSellOrder(
address _tokenToSell,
uint256 _amountToSell,
uint256 _priceInUSDC,
uint256 _deadlineDuration
- ) public returns (uint256) {
+ ) external returns (uint256) {
.
.
.
}
Updates

Lead Judging Commences

yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.