Closed code423n4 closed 2 years ago
Duplicate: Maker can grief fillOrder by revoking approval, cancelling the original order or using custom baseAssets/assets via mempool frontrunning and cause a revert: https://github.com/code-423n4/2022-06-putty-findings/issues/414
part of warden's QA: #173
Lines of code
https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L268-L380
Vulnerability details
Impact
Function
fillOrder
suppose to fills an offchain order and settles it onchain.maker
signs the orders and give spending allowances toPuttyV2
contract and thentaker
sends that signed order to this function. butmaker
can interrupttaker
transaction and make it revert.maker
can watch miners transaction pools and whenever sees his order is going to be filled in a transaction, he can front-run that transaction and removePuttyV2
allowance of spending his tokens, thentaker
transaction would fail in blockchain. there are other ways formaker
to perform this attack like reverting onisValidSignatureNow()
whenorder.maker
is a contract andPuttyV2
makes an external call to see that signature is valid,maker
can revert on that external call based on some logics and causetaker
griefing. The real problem is that orders are signed on off-chain orderbook andtaker
who send them to on-chain contract is in risk of getting rejected transactions andmaker
can cause this very easily.Proof of Concept
This is
fillOrder()
codes:As you can see code tries to transfer some
ERC20
orERC721
tokens fromorder.maker
to contract address andmaker
can remove spending allowance forPuttyV2
address by front-running and cause thefillOrder()
transaction to fail. also in the beginning of function, code usesSignatureChecker.isValidSignatureNow(order.maker, orderHash, signature)
andmaker
can revert the transaction in this call too because whenorder.maker
is a contract, thenisValidSignatureNow()
makes a external call toorder.maker
. The steps of this exploit are:maker
signs an order and put in off-chain order book. (very appealing order)PuttyV2
allowance permission to spend tokens in the orders.fillOrder()
PuttyV2
. (or logics ofisValidSignatureNow()
reverts based ontx.origin
)Tools Used
VIM
Recommended Mitigation Steps
There should be some mechanism in the onchain code that made sure that order signers lose some tokens if their order signature was valid but the spending allowance wasn't correct.
maker
s should stake some gas collateral.