From 260bee88572309370095c48424b9a71acea16afc Mon Sep 17 00:00:00 2001 From: unknownunknown1 Date: Wed, 17 Jun 2020 18:31:51 +1000 Subject: [PATCH 1/3] refactor(LinguoToken.sol): follow check-effect-interaction pattern --- .../standard/arbitration/LinguoToken.sol | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/contracts/standard/arbitration/LinguoToken.sol b/contracts/standard/arbitration/LinguoToken.sol index 0defc2cc..ba8c28ec 100644 --- a/contracts/standard/arbitration/LinguoToken.sol +++ b/contracts/standard/arbitration/LinguoToken.sol @@ -260,15 +260,15 @@ contract LinguoToken is Arbitrable { task.parties[uint(Party.Translator)] = msg.sender; task.status = Status.Assigned; - uint remainder = task.maxPrice.subCap(price); - require(task.token.transfer(task.requester, remainder), "Could not transfer tokens to the requester."); // Update requester's deposit since we reimbursed him the difference between maximal and actual price. task.requesterDeposit = price; task.sumDeposit += translatorDeposit; - remainder = msg.value - translatorDeposit; + uint remainder = msg.value - translatorDeposit; msg.sender.send(remainder); + remainder = task.maxPrice.subCap(price); + require(task.token.transfer(task.requester, remainder), "Could not transfer tokens to the requester."); emit TaskAssigned(_taskID, msg.sender, price, now); } @@ -300,8 +300,8 @@ contract LinguoToken is Arbitrable { task.requesterDeposit = 0; task.sumDeposit = 0; // Requester gets his deposit back and also the deposit of the translator, if there was one. Note that sumDeposit can't contain challenger's deposit until the task is in DisputeCreated status. - require(task.token.transfer(task.requester, requesterDeposit), "The token transfer was unsuccessful."); task.requester.send(sumDeposit); + require(task.token.transfer(task.requester, requesterDeposit), "The token transfer was unsuccessful."); emit TaskResolved(_taskID, "requester-reimbursed", now); } @@ -320,9 +320,9 @@ contract LinguoToken is Arbitrable { uint sumDeposit = task.sumDeposit; task.requesterDeposit = 0; task.sumDeposit = 0; - require(task.token.transfer(translator, requesterDeposit), "The token transfer was unsuccessful."); translator.send(sumDeposit); - + require(task.token.transfer(translator, requesterDeposit), "The token transfer was unsuccessful."); + emit TaskResolved(_taskID, "translation-accepted", now); } @@ -519,17 +519,19 @@ contract LinguoToken is Arbitrable { task.sumDeposit = 0; if(_ruling == uint(Party.None)){ - require(task.token.transfer(task.requester, task.requesterDeposit), "Could not transfer tokens to requester."); // The value of sumDeposit is split among parties in this case. If the sum is uneven the value of 1 wei can be burnt. sumDeposit = sumDeposit / 2; task.parties[uint(Party.Translator)].send(sumDeposit); task.parties[uint(Party.Challenger)].send(sumDeposit); + // When using a token of the advanced standard (ERC777 etc) the requester can revert this function and prevent fee reimbursement. + // This is not an issue however, because "0" ruling is an edge case. + require(task.token.transfer(task.requester, requesterDeposit), "Could not transfer tokens to requester."); } else if (_ruling == uint(Party.Translator)) { - require(task.token.transfer(task.parties[uint(Party.Translator)], requesterDeposit), "Could not transfer tokens to translator."); task.parties[uint(Party.Translator)].send(sumDeposit); + require(task.token.transfer(task.parties[uint(Party.Translator)], requesterDeposit), "Could not transfer tokens to translator."); } else { - require(task.token.transfer(task.requester, requesterDeposit), "Could not transfer tokens to requester."); task.parties[uint(Party.Challenger)].send(sumDeposit); + require(task.token.transfer(task.requester, requesterDeposit), "Could not transfer tokens to requester."); } emit TaskResolved(taskID, "dispute-settled", now); From d00cddf57c294e1c808b4ec9d9b33077d8d7f6a9 Mon Sep 17 00:00:00 2001 From: unknownunknown1 Date: Wed, 17 Jun 2020 22:52:30 +1000 Subject: [PATCH 2/3] docs(LinguoToken): comment update --- contracts/standard/arbitration/LinguoToken.sol | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contracts/standard/arbitration/LinguoToken.sol b/contracts/standard/arbitration/LinguoToken.sol index ba8c28ec..156311af 100644 --- a/contracts/standard/arbitration/LinguoToken.sol +++ b/contracts/standard/arbitration/LinguoToken.sol @@ -20,6 +20,7 @@ import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; * This version of the contract made for ERC-20 tokens support. * NOTE: This contract trusts that the Arbitrator is honest and will not reenter or modify its costs during a call. * The arbitrator must support appeal period. + * Also note that this contract trusts that the token transfers will not be blocked by the recepient. */ contract LinguoToken is Arbitrable { @@ -523,8 +524,6 @@ contract LinguoToken is Arbitrable { sumDeposit = sumDeposit / 2; task.parties[uint(Party.Translator)].send(sumDeposit); task.parties[uint(Party.Challenger)].send(sumDeposit); - // When using a token of the advanced standard (ERC777 etc) the requester can revert this function and prevent fee reimbursement. - // This is not an issue however, because "0" ruling is an edge case. require(task.token.transfer(task.requester, requesterDeposit), "Could not transfer tokens to requester."); } else if (_ruling == uint(Party.Translator)) { task.parties[uint(Party.Translator)].send(sumDeposit); From f5047d1f019d151bab3afb7f5780d491e336e76f Mon Sep 17 00:00:00 2001 From: unknownunknown1 Date: Wed, 17 Jun 2020 22:54:50 +1000 Subject: [PATCH 3/3] docs(LinguoToken): comment rephrase --- contracts/standard/arbitration/LinguoToken.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/standard/arbitration/LinguoToken.sol b/contracts/standard/arbitration/LinguoToken.sol index 156311af..3ec06100 100644 --- a/contracts/standard/arbitration/LinguoToken.sol +++ b/contracts/standard/arbitration/LinguoToken.sol @@ -20,7 +20,7 @@ import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; * This version of the contract made for ERC-20 tokens support. * NOTE: This contract trusts that the Arbitrator is honest and will not reenter or modify its costs during a call. * The arbitrator must support appeal period. - * Also note that this contract trusts that the token transfers will not be blocked by the recepient. + * Also note that this contract trusts that the tokens will not allow the recipients to block the transfers. */ contract LinguoToken is Arbitrable {