11// SPDX-License-Identifier: MIT
22
3- /// @authors: [@unknownunknown1, @fnanni-0, @shalzz]
3+ /// @authors: [@unknownunknown1, @fnanni-0, @shalzz, @jaybuidl ]
44/// @reviewers: []
55/// @auditors: []
66/// @bounties: []
@@ -29,7 +29,7 @@ contract Escrow is IArbitrableV2 {
2929 WaitingSender,
3030 WaitingReceiver,
3131 DisputeCreated,
32- Resolved
32+ TransactionResolved
3333 }
3434
3535 enum Resolution {
@@ -105,7 +105,7 @@ contract Escrow is IArbitrableV2 {
105105 // ************************************* //
106106
107107 modifier onlyByGovernor () {
108- require ( address ( this ) == msg .sender , " Only the governor allowed. " );
108+ if (governor != msg .sender ) revert GovernorOnly ( );
109109 _;
110110 }
111111
@@ -194,9 +194,9 @@ contract Escrow is IArbitrableV2 {
194194 /// @param _amount Amount to pay in wei.
195195 function pay (uint256 _transactionID , uint256 _amount ) external {
196196 Transaction storage transaction = transactions[_transactionID];
197- require (transaction.sender == msg .sender , " The caller must be the sender. " );
198- require (transaction.status == Status.NoDispute, " The transaction must not be disputed. " );
199- require (_amount <= transaction.amount, " Maximum amount available for payment exceeded. " );
197+ if (transaction.sender != msg .sender ) revert SenderOnly ( );
198+ if (transaction.status != Status.NoDispute) revert TransactionDisputed ( );
199+ if (_amount > transaction.amount) revert MaximumPaymentAmountExceeded ( );
200200
201201 transaction.receiver.send (_amount); // It is the user responsibility to accept ETH.
202202 transaction.amount -= _amount;
@@ -209,9 +209,9 @@ contract Escrow is IArbitrableV2 {
209209 /// @param _amountReimbursed Amount to reimburse in wei.
210210 function reimburse (uint256 _transactionID , uint256 _amountReimbursed ) external {
211211 Transaction storage transaction = transactions[_transactionID];
212- require (transaction.receiver == msg .sender , " The caller must be the receiver. " );
213- require (transaction.status == Status.NoDispute, " The transaction must not be disputed. " );
214- require (_amountReimbursed <= transaction.amount, " Maximum reimbursement available exceeded. " );
212+ if (transaction.receiver != msg .sender ) revert ReceiverOnly ( );
213+ if (transaction.status != Status.NoDispute) revert TransactionDisputed ( );
214+ if (_amountReimbursed > transaction.amount) revert MaximumPaymentAmountExceeded ( );
215215
216216 transaction.sender.send (_amountReimbursed); // It is the user responsibility to accept ETH.
217217 transaction.amount -= _amountReimbursed;
@@ -223,13 +223,12 @@ contract Escrow is IArbitrableV2 {
223223 /// @param _transactionID The index of the transaction.
224224 function executeTransaction (uint256 _transactionID ) external {
225225 Transaction storage transaction = transactions[_transactionID];
226- require (block .timestamp >= transaction.deadline, " Deadline not passed. " );
227- require (transaction.status == Status.NoDispute, " The transaction must not be disputed. " );
226+ if (block .timestamp < transaction.deadline) revert DeadlineNotPassed ( );
227+ if (transaction.status != Status.NoDispute) revert TransactionDisputed ( );
228228
229229 transaction.receiver.send (transaction.amount); // It is the user responsibility to accept ETH.
230230 transaction.amount = 0 ;
231-
232- transaction.status = Status.Resolved;
231+ transaction.status = Status.TransactionResolved;
233232
234233 emit TransactionResolved (_transactionID, Resolution.TransactionExecuted);
235234 }
@@ -241,20 +240,17 @@ contract Escrow is IArbitrableV2 {
241240 /// @param _transactionID The index of the transaction.
242241 function payArbitrationFeeBySender (uint256 _transactionID ) external payable {
243242 Transaction storage transaction = transactions[_transactionID];
244- require (
245- transaction.status < Status.DisputeCreated,
246- "Dispute has already been created or because the transaction has been executed. "
247- );
248- require (msg .sender == transaction.sender, "The caller must be the sender. " );
243+ if (transaction.status >= Status.DisputeCreated) revert DisputeAlreadyCreatedOrTransactionAlreadyExecuted ();
244+ if (msg .sender != transaction.sender) revert SenderOnly ();
249245
250246 transaction.senderFee += msg .value ;
251247 uint256 arbitrationCost = arbitrator.arbitrationCost (arbitratorExtraData);
252- require (transaction.senderFee >= arbitrationCost, " The sender fee must cover arbitration costs. " );
248+ if (transaction.senderFee < arbitrationCost) revert SenderFeeNotCoverArbitrationCosts ( );
253249
254250 transaction.lastInteraction = block .timestamp ;
255251
256- // The receiver still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
257252 if (transaction.receiverFee < arbitrationCost) {
253+ // The receiver still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
258254 transaction.status = Status.WaitingReceiver;
259255 emit HasToPayFee (_transactionID, Party.Receiver);
260256 } else {
@@ -268,20 +264,17 @@ contract Escrow is IArbitrableV2 {
268264 /// @param _transactionID The index of the transaction.
269265 function payArbitrationFeeByReceiver (uint256 _transactionID ) external payable {
270266 Transaction storage transaction = transactions[_transactionID];
271- require (
272- transaction.status < Status.DisputeCreated,
273- "Dispute has already been created or because the transaction has been executed. "
274- );
275- require (msg .sender == transaction.receiver, "The caller must be the receiver. " );
267+ if (transaction.status >= Status.DisputeCreated) revert DisputeAlreadyCreatedOrTransactionAlreadyExecuted ();
268+ if (msg .sender != transaction.receiver) revert ReceiverOnly ();
276269
277270 transaction.receiverFee += msg .value ;
278271 uint256 arbitrationCost = arbitrator.arbitrationCost (arbitratorExtraData);
279- require (transaction.receiverFee >= arbitrationCost, " The receiver fee must cover arbitration costs. " );
272+ if (transaction.receiverFee < arbitrationCost) revert ReceiverFeeNotCoverArbitrationCosts ( );
280273
281274 transaction.lastInteraction = block .timestamp ;
282- // The sender still has to pay. This can also happen if he has paid,
283- // but arbitrationCost has increased.
275+
284276 if (transaction.senderFee < arbitrationCost) {
277+ // The sender still has to pay. This can also happen if he has paid, but arbitrationCost has increased.
285278 transaction.status = Status.WaitingSender;
286279 emit HasToPayFee (_transactionID, Party.Sender);
287280 } else {
@@ -294,8 +287,8 @@ contract Escrow is IArbitrableV2 {
294287 /// @param _transactionID The index of the transaction.
295288 function timeOutBySender (uint256 _transactionID ) external {
296289 Transaction storage transaction = transactions[_transactionID];
297- require (transaction.status == Status.WaitingReceiver, " The transaction is not waiting on the receiver. " );
298- require (block .timestamp - transaction.lastInteraction >= feeTimeout, " Timeout time has not passed yet. " );
290+ if (transaction.status != Status.WaitingReceiver) revert NotWaitingForReceiverFees ( );
291+ if (block .timestamp - transaction.lastInteraction < feeTimeout) revert TimeoutNotPassed ( );
299292
300293 if (transaction.receiverFee != 0 ) {
301294 transaction.receiver.send (transaction.receiverFee); // It is the user responsibility to accept ETH.
@@ -309,8 +302,8 @@ contract Escrow is IArbitrableV2 {
309302 /// @param _transactionID The index of the transaction.
310303 function timeOutByReceiver (uint256 _transactionID ) external {
311304 Transaction storage transaction = transactions[_transactionID];
312- require (transaction.status == Status.WaitingSender, " The transaction is not waiting on the sender. " );
313- require (block .timestamp - transaction.lastInteraction >= feeTimeout, " Timeout time has not passed yet. " );
305+ if (transaction.status != Status.WaitingSender) revert NotWaitingForSenderFees ( );
306+ if (block .timestamp - transaction.lastInteraction < feeTimeout) revert TimeoutNotPassed ( );
314307
315308 if (transaction.senderFee != 0 ) {
316309 transaction.sender.send (transaction.senderFee); // It is the user responsibility to accept ETH.
@@ -327,12 +320,12 @@ contract Escrow is IArbitrableV2 {
327320 /// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved
328321 /// for "Refuse to arbitrate".
329322 function rule (uint256 _disputeID , uint256 _ruling ) external override {
330- require (msg .sender == address (arbitrator), "The caller must be the arbitrator. " );
331- require (_ruling <= AMOUNT_OF_CHOICES, "Invalid ruling. " );
323+ if (msg .sender != address (arbitrator)) revert ArbitratorOnly ();
324+ if (_ruling > AMOUNT_OF_CHOICES) revert InvalidRuling ();
325+
332326 uint256 transactionID = disputeIDtoTransactionID[_disputeID];
333327 Transaction storage transaction = transactions[transactionID];
334-
335- require (transaction.status == Status.DisputeCreated, "The dispute has already been resolved. " );
328+ if (transaction.status != Status.DisputeCreated) revert DisputeAlreadyResolved ();
336329
337330 emit Ruling (arbitrator, _disputeID, _ruling);
338331 executeRuling (transactionID, _ruling);
@@ -390,7 +383,7 @@ contract Escrow is IArbitrableV2 {
390383 transaction.amount = 0 ;
391384 transaction.senderFee = 0 ;
392385 transaction.receiverFee = 0 ;
393- transaction.status = Status.Resolved ;
386+ transaction.status = Status.TransactionResolved ;
394387
395388 emit TransactionResolved (_transactionID, Resolution.RulingEnforced);
396389 }
@@ -404,4 +397,24 @@ contract Escrow is IArbitrableV2 {
404397 function getCountTransactions () external view returns (uint256 ) {
405398 return transactions.length ;
406399 }
400+
401+ // ************************************* //
402+ // * Errors * //
403+ // ************************************* //
404+
405+ error GovernorOnly ();
406+ error SenderOnly ();
407+ error ReceiverOnly ();
408+ error ArbitratorOnly ();
409+ error TransactionDisputed ();
410+ error MaximumPaymentAmountExceeded ();
411+ error DisputeAlreadyCreatedOrTransactionAlreadyExecuted ();
412+ error DeadlineNotPassed ();
413+ error SenderFeeNotCoverArbitrationCosts ();
414+ error ReceiverFeeNotCoverArbitrationCosts ();
415+ error NotWaitingForReceiverFees ();
416+ error NotWaitingForSenderFees ();
417+ error TimeoutNotPassed ();
418+ error InvalidRuling ();
419+ error DisputeAlreadyResolved ();
407420}
0 commit comments