-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce memory copy auction list #20
Conversation
WalkthroughThe modifications to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TermAuctionList
participant RepositoryTokens
User->>TermAuctionList: Submit Offer
TermAuctionList->>RepositoryTokens: Check if Token Seen
alt Token Not Seen
TermAuctionList->>RepositoryTokens: Mark Token as Seen
end
TermAuctionList->>TermAuctionList: Update Pending Offers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/TermAuctionList.sol (7 hunks)
Additional comments not posted (4)
src/TermAuctionList.sol (4)
25-25
: Addition ofsize
field inTermAuctionListData
struct.The addition of the
size
field directly tracks the number of offers, which simplifies operations like insertion and deletion by avoiding the need to iterate through the list to count elements. This is a positive change for performance, especially in a blockchain context where operations are cost-sensitive.
101-101
: Efficient use ofsize
inpendingOffers
.The function efficiently uses the
size
field to allocate memory for the array of offers, which optimizes gas usage and simplifies the code. This is a good practice in Solidity, especially in contract environments where every operation costs gas.
131-131
: Correct increment ofsize
ininsertPending
.The function properly increments the
size
field after inserting a new offer, ensuring that the count of offers remains accurate. This is crucial for maintaining the integrity of the list and for operations that depend on the size of the list.
194-194
: Correct decrement ofsize
inremoveCompleted
.The function properly decrements the
size
field when an offer is removed, which is essential for keeping the list's count accurate. This change ensures that the list's integrity is maintained throughout operations, which is critical in contract environments.
function _markRepoTokenAsSeen(address[] memory repoTokensSeen, address repoToken) private { | ||
uint256 i; | ||
while (repoTokensSeen[i] != address(0)) { | ||
i++; | ||
} | ||
repoTokensSeen[i] = repoToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Risk of data overwrite in _markRepoTokenAsSeen
.
The function does not check if there is an empty slot available in the array before assignment, which could lead to data overwrite or silent failures. Consider adding a check to ensure that there is at least one empty slot in the array before proceeding with the assignment.
+ require(i < repoTokensSeen.length, "No empty slot available");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
function _markRepoTokenAsSeen(address[] memory repoTokensSeen, address repoToken) private { | |
uint256 i; | |
while (repoTokensSeen[i] != address(0)) { | |
i++; | |
} | |
repoTokensSeen[i] = repoToken; | |
function _markRepoTokenAsSeen(address[] memory repoTokensSeen, address repoToken) private { | |
uint256 i; | |
while (repoTokensSeen[i] != address(0)) { | |
i++; | |
} | |
require(i < repoTokensSeen.length, "No empty slot available"); | |
repoTokensSeen[i] = repoToken; |
function _hasRepoTokenBeenSeen(address[] memory repoTokensSeen, address repoToken) private view returns(bool ) { | ||
uint256 i; | ||
bytes32 current = listData.head; | ||
while (current != NULL_NODE) { | ||
PendingOffer memory currentOffer = listData.offers[current]; | ||
PendingOfferMemory memory newOffer = offers[i]; | ||
|
||
newOffer.offerId = current; | ||
newOffer.repoToken = currentOffer.repoToken; | ||
newOffer.offerAmount = currentOffer.offerAmount; | ||
newOffer.termAuction = currentOffer.termAuction; | ||
newOffer.offerLocker = currentOffer.offerLocker; | ||
|
||
while (repoTokensSeen[i] != address(0)) { | ||
if (repoTokensSeen[i] == repoToken) { | ||
return true; | ||
} | ||
i++; | ||
current = _getNext(listData, current); | ||
} | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential risk of out-of-bounds error in _hasRepoTokenBeenSeen
.
The function iterates through an array without explicit boundary checks, which could lead to out-of-bounds errors if the array is full. Consider adding a boundary check or ensuring that the array size is always sufficient to include a sentinel value (like address(0)
).
+ require(i < repoTokensSeen.length, "Array index out of bounds");
Committable suggestion was skipped due to low confidence.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor