From 500498f8bc9f32e4160173ceb11ab27e830c4b3d Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 24 Jan 2025 11:07:55 +0100 Subject: [PATCH] Replace assert by revert (#216) * Replace assert with revert --- contracts/Marketplace.sol | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4c5cc93..1f70bb9 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -376,8 +376,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { uint256 collateralAmount = slot.currentCollateral; _marketplaceTotals.sent += (payoutAmount + collateralAmount); slot.state = SlotState.Paid; - assert(_token.transfer(rewardRecipient, payoutAmount)); - assert(_token.transfer(collateralRecipient, collateralAmount)); + if (!_token.transfer(rewardRecipient, payoutAmount)) { + revert Marketplace_TransferFailed(); + } + + if (!_token.transfer(collateralRecipient, collateralAmount)) { + revert Marketplace_TransferFailed(); + } } /** @@ -406,8 +411,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { uint256 collateralAmount = slot.currentCollateral; _marketplaceTotals.sent += (payoutAmount + collateralAmount); slot.state = SlotState.Paid; - assert(_token.transfer(rewardRecipient, payoutAmount)); - assert(_token.transfer(collateralRecipient, collateralAmount)); + if (!_token.transfer(rewardRecipient, payoutAmount)) { + revert Marketplace_TransferFailed(); + } + + if (!_token.transfer(collateralRecipient, collateralAmount)) { + revert Marketplace_TransferFailed(); + } } /** @@ -473,7 +483,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { uint256 amount = context.fundsToReturnToClient; _marketplaceTotals.sent += amount; - assert(_token.transfer(withdrawRecipient, amount)); + + if (!_token.transfer(withdrawRecipient, amount)) { + revert Marketplace_TransferFailed(); + } // We zero out the funds tracking in order to prevent double-spends context.fundsToReturnToClient = 0;