Skip to content

gas: add unchecked for ConduitController#updateChannel #440

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

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions contracts/conduit/ConduitController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ contract ConduitController is ConduitControllerInterface {
} else if (!isOpen && channelPreviouslyOpen) {
// Set a previously open channel as closed via "swap & pop" method.
// Decrement located index to get the index of the closed channel.
uint256 removedChannelIndex = channelIndexPlusOne - 1;

uint256 removedChannelIndex;
// channelPreviouslyOpen already make sure channelIndexPlusOne > 0
unchecked {
removedChannelIndex = channelIndexPlusOne - 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks safe

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify: this is safe.
In this branch, channelPreviouslyOpen must be true, which means that channelIndexPlusOne != 0. Since it has type uint, it must be > 0 therefore safe.

}
// Use length of channels array to determine index of last channel.
uint256 finalChannelIndex = conduitProperties.channels.length - 1;

Expand Down