Timeswap contest - jayjonah8's results

Like Uniswap, but for lending & borrowing.

General Information

Platform: Code4rena

Start Date: 04/01/2022

Pot Size: $75,000 USDC

Total HM: 17

Participants: 33

Period: 7 days

Judge: 0xean

Total Solo HM: 14

Id: 74

League: ETH

Timeswap

Findings Distribution

Researcher Performance

Rank: 1/33

Findings: 7

Award: $24,145.68

🌟 Selected for report: 7

🚀 Solo Findings: 4

Findings Information

🌟 Selected for report: jayjonah8

Labels

bug
3 (High Risk)
resolved
sponsor confirmed

Awards

5679.4846 USDC - $5,679.48

External Links

Handle

jayjonah8

Vulnerability details

Impact

In TimeswapPair.sol, the mint() function has a callback in the middle of the function while there are still updates to state that take place after the callback. The lock modifier guards against reentrancy but not against cross function reentrancy. Since the protocol implements Uniswap like functionality, this can be extremely dangerous especially with regard to composability/interacting with other protocols and contracts. The callback before important state changes (updates to reserve asset, collateral, and totalDebtCreated) also violates the Checks Effects Interactions best practices further widening the attack surface.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L177

https://fravoll.github.io/solidity-patterns/checks_effects_interactions.html

cross function reentrancy https://medium.com/coinmonks/protect-your-solidity-smart-contracts-from-reentrancy-attacks-9972c3af7c21

Tools Used

Manual code review

The callback Callback.mint(asset, collateral, xIncrease, dueOut.collateral, data) should be placed at the end of the mint() function after all state updates have taken place.

Findings Information

🌟 Selected for report: jayjonah8

Labels

bug
3 (High Risk)
resolved
sponsor confirmed

Awards

5679.4846 USDC - $5,679.48

External Links

Handle

jayjonah8

Vulnerability details

Impact

In TimeswapPair.sol, the lend() function has a callback to the msg.sender in the middle of the function while there are still updates to state that take place after the callback. The lock modifier guards against reentrancy but not against cross function reentrancy. Since the protocol implements Uniswap like functionality, this can be extremely dangerous especially with regard to composability/interacting with other protocols and contracts. The callback before important state changes (updates to totalClaims bonds, insurance and reserves assets) also violates the Checks Effects Interactions best practices further widening the attack surface.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L246

https://fravoll.github.io/solidity-patterns/checks_effects_interactions.html

cross function reentrancy https://medium.com/coinmonks/protect-your-solidity-smart-contracts-from-reentrancy-attacks-9972c3af7c21

Tools Used

Manual code review

The callback Callback.lend(asset, xIncrease, data); should be placed at the end of the lend() function after all state updates have taken place.

Findings Information

🌟 Selected for report: jayjonah8

Labels

bug
3 (High Risk)
resolved
sponsor confirmed

Awards

5679.4846 USDC - $5,679.48

External Links

Handle

jayjonah8

Vulnerability details

Impact

In TimeswapPair.sol, the borrow() function has a callback to the msg.sender in the middle of the function while there are still updates to state that take place after the callback. The lock modifier guards against reentrancy but not against cross function reentrancy. Since the protocol implements Uniswap like functionality, this can be extremely dangerous especially with regard to composability/interacting with other protocols and contracts. The callback before important state changes (updates to collateral, totalDebtCreated and reserves assets) also violates the Checks Effects Interactions best practices further widening the attack surface.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L322

https://fravoll.github.io/solidity-patterns/checks_effects_interactions.html

cross function reentrancy https://medium.com/coinmonks/protect-your-solidity-smart-contracts-from-reentrancy-attacks-9972c3af7c21

Tools Used

Manual code review

The callback Callback.borrow(collateral, dueOut.collateral, data); should be placed at the end of the borrow() function after all state updates have taken place.

Findings Information

🌟 Selected for report: jayjonah8

Labels

bug
3 (High Risk)
resolved
sponsor confirmed

Awards

5679.4846 USDC - $5,679.48

External Links

Handle

jayjonah8

Vulnerability details

Impact

In TimeswapPair.sol, the pay() function has a callback to the msg.sender in the middle of the function while there are still updates to state that take place after the callback. The lock modifier guards against reentrancy but not against cross function reentrancy. Since the protocol implements Uniswap like functionality, this can be extremely dangerous especially with regard to composability/interacting with other protocols and contracts. The callback before important state changes (updates to reserves collateral and reserves assets) also violates the Checks Effects Interactions best practices further widening the attack surface.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L369

https://fravoll.github.io/solidity-patterns/checks_effects_interactions.html

cross function reentrancy https://medium.com/coinmonks/protect-your-solidity-smart-contracts-from-reentrancy-attacks-9972c3af7c21

Tools Used

Manual code review

The callback "if (assetIn > 0) Callback.pay(asset, assetIn, data);" should be placed at the end of the pay() function after all state updates have taken place.

Findings Information

🌟 Selected for report: jayjonah8

Also found by: Fitraldys

Labels

bug
2 (Med Risk)
sponsor confirmed

Awards

766.7304 USDC - $766.73

External Links

Handle

jayjonah8

Vulnerability details

Impact

In CollateralizedDebt.sol, the mint() function calls _safeMint() which has a callback to the "to" address argument. Functions with callbacks should have reentrancy guards in place for protection against possible malicious actors both from inside and outside the protocol.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Convenience/contracts/CollateralizedDebt.sol#L76

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol#L263

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol#L395

Tools Used

Manual code review

Add a reentrancy guard modifier on the mint() function in CollateralizedDebt.sol

Findings Information

🌟 Selected for report: jayjonah8

Labels

bug
1 (Low Risk)
resolved
sponsor confirmed

Awards

567.9485 USDC - $567.95

External Links

Handle

jayjonah8

Vulnerability details

Impact

In TimeswapConvenience.sol the constructor takes in 2 addresses for _factory and _weth and sets them in storage without checking that they are unique which can introduce possible costly errors during deployment.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Convenience/contracts/TimeswapConvenience.sol#L62

Tools Used

Manuel code review

Add to TimeswapConvenience.sol constructor: require(_factory != _weth, "Duplicate address")

Findings Information

🌟 Selected for report: jayjonah8

Labels

bug
G (Gas Optimization)
resolved
sponsor confirmed

Awards

93.0809 USDC - $93.08

External Links

Handle

jayjonah8

Vulnerability details

Impact

In TimeswapPair.sol the pay() function calls safeTransfer() and does so using the SafeTransfer.sol library when it can simply add the open zeppelin SafeERC20.sol import directly inside TimeswapPair.sol itself eliminating the unnecessary code in the protocols own SafeTransfer library.

Proof of Concept

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L374

https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/libraries/SafeTransfer.sol#L7

Tools Used

Manual code review

Use the open zeppelin SafeERC20 import directly inside the TimeswapPair.sol file instead of calling your own library. The extra safeTransfer library can then be deleted.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter