addCredit / increaseCredit cannot be called by lender first when token is ETH
The mutual consent mechanism for addCredit and increaseCredit does not revert on the first call, so when the lender sends ETH with that first call the ETH is lost. The borrower cannot complete the second call without sending ETH, so the lender cannot add credit first.
Lambda Follow with berndartmueller, Trust and 3 others
Originally disclosed on Code4rena
Submitted by Lambda, also found by berndartmueller, Trust, minhquanym, adriro, and HE1M
Impact
The functions addCredit and increaseCredit both ahve a mutualConsent or mutualConsentById modifier. Furthermore, these functions are payable and the lender needs to send the corresponding ETH with each call. However, if we look at the mutual consent modifier works, we can have a problem:
modifier mutualConsent(address _signerOne, address _signerTwo) {
if(_mutualConsent(_signerOne, _signerTwo)) {
// Run whatever code needed 2/2 consent
_;
}
}
function _mutualConsent(address _signerOne, address _signerTwo) internal returns(bool) {
if(msg.sender != _signerOne && msg.sender != _signerTwo) { revert Unauthorized(); }
address nonCaller = _getNonCaller(_signerOne, _signerTwo);
// The consent hash is defined by the hash of the transaction call data and sender of msg,
// which uniquely identifies the function, arguments, and sender.
bytes32 expectedHash = keccak256(abi.encodePacked(msg.data, nonCaller));
if (!mutualConsents[expectedHash]) {
bytes32 newHash = keccak256(abi.encodePacked(msg.data, msg.sender));
mutualConsents[newHash] = true;
emit MutualConsentRegistered(newHash);
return false;
}
delete mutualConsents[expectedHash];
return true;
}
The problem is: On the first call, when the other party has not given consent to the call yet, the modifier does not revert. It sets the consent of the calling party instead.
This is very problematic in combination with sending ETH for two reasons:
- When the lender performs the calls first and sends ETH along with the call, the call will not revert. It will instead set the consent for him, but the sent ETH is lost.
- Even when the lender thinks about this and does not provide any ETH on the first call, the borrower has to perform the second call. Of course, he will not provide the ETH with this call, but this will cause the transaction to revert. There is now no way for the borrower to also grant consent, but still let the lender perform the call.
Proof Of Concept
Lender Alice calls LineOfCredit.addCredit first to add a credit with 1 ETH. She sends 1 ETH with the call. However, because borrower Bob has not performed this call yet, the function body is not executed, but the 1 ETH is still sent. Afterwards, Bob wants to give his consent, so he performs the same call. However, this call reverts, because Bob does not send any ETH with it.
Recommended Mitigation Steps
Consider implementing an external function to grant consent to avoid this scenario. Also consider reverting when ETH is sent along, but the other party has not given their consent yet.
dmvt (judge) increased severity to High
kibagateaux (Debt DAO) confirmed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The mutual consent modifier records consent and returns false on the first call instead of reverting, so any ETH sent with that call is trapped in the contract.
Impact
The lender loses any ETH sent on the first call, and the lender cannot be the first to grant consent when the token is ETH.
What the attacker needed
Token is ETH; lender calls first; lender sends ETH with first call
The fix
The contract should provide a separate function to grant consent and should revert if ETH is sent before the other party has consented.
How it was found
- Lender Alice calls addCredit first with 1 ETH.
- The call does not execute the function body but records Alice's consent, and the 1 ETH is lost.
- Borrower Bob calls addCredit to give consent but sends no ETH.
- Bob's call reverts because the function is payable and requires ETH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract lets two parties agree before changing a credit line. The first party to call only records their agreement, but if they also send money (ETH) with that call, the money stays in the contract and is lost. The second party then cannot finish the agreement without also sending money, which they do not want to do.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.