Skip to content

Commit 43467e5

Browse files
authored
Merge pull request #440 from mingwatch/mingwatch-gas-optimization-1
gas: add unchecked for ConduitController#updateChannel
2 parents 256c420 + 85eabe7 commit 43467e5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

contracts/conduit/ConduitController.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ contract ConduitController is ConduitControllerInterface {
157157
} else if (!isOpen && channelPreviouslyOpen) {
158158
// Set a previously open channel as closed via "swap & pop" method.
159159
// Decrement located index to get the index of the closed channel.
160-
uint256 removedChannelIndex = channelIndexPlusOne - 1;
161-
160+
uint256 removedChannelIndex;
161+
// channelPreviouslyOpen already ensures channelIndexPlusOne > 0
162+
unchecked {
163+
removedChannelIndex = channelIndexPlusOne - 1;
164+
}
162165
// Use length of channels array to determine index of last channel.
163166
uint256 finalChannelIndex = conduitProperties.channels.length - 1;
164167

0 commit comments

Comments
 (0)