From ec7dc5db2124f13a0a3dc3c38a694d0744350063 Mon Sep 17 00:00:00 2001 From: zajck Date: Mon, 8 Jan 2024 15:54:02 +0100 Subject: [PATCH] Add unchecked blocks --- .../facets/SequentialCommitHandlerFacet.sol | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/contracts/protocol/facets/SequentialCommitHandlerFacet.sol b/contracts/protocol/facets/SequentialCommitHandlerFacet.sol index c1b502389..c1460d015 100644 --- a/contracts/protocol/facets/SequentialCommitHandlerFacet.sol +++ b/contracts/protocol/facets/SequentialCommitHandlerFacet.sol @@ -139,9 +139,12 @@ contract SequentialCommitHandlerFacet is IBosonSequentialCommitHandler, PriceDis revert FeeAmountTooHigh(); } - // Get price paid by current buyer - uint256 len = exchangeCosts.length; - uint256 currentPrice = len == 0 ? offer.price : exchangeCosts[len - 1].price; + uint256 currentPrice; + unchecked { + // Get price paid by current buyer + uint256 len = exchangeCosts.length; + currentPrice = len == 0 ? offer.price : exchangeCosts[len - 1].price; + } // Calculate the minimal amount to be kept in the escrow escrowAmount = @@ -156,7 +159,10 @@ contract SequentialCommitHandlerFacet is IBosonSequentialCommitHandler, PriceDis } // Make sure enough get escrowed - payout = exchangeCost.price - escrowAmount; + // Escrow amount is guaranteed to be less than or equal to price + unchecked { + payout = exchangeCost.price - escrowAmount; + } if (_priceDiscovery.side == Side.Ask) { if (escrowAmount > 0) {