-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manipulation of the Y State Results in Interest Rate Manipulation #187
Comments
Warden rhynorater requested that we add the following information to this submission: I've crafted an easy reproduce script which I've attached below. Please follow the below instructions to set up:
This script will download the timeswap code base, download the exploit files I've configured from my server, install the required npm packages, then run the exploit script to provide the demo. If all goes according to plan, something like this should be the output:
This demonstrates the following scenario:
For the math to continue to function properly within this contract, there has to be an invariant condition that the constant I'd recommend that there be a modifier function that checks whether the Invariant holds at the end of each state changing function call. If it does not, then the contract should pause or the txn should revert. test.js:
attacker.sol:
lp.sol:
|
Handle
Rhynorater
Vulnerability details
Impact
Due to lack of constraints on user input in the
TimeswapPair.sol#mint
function, an attacker can arbitrarily modify the interest rate while only paying a minimal amount of Asset Token and Collateral Token.Disclosure: This is my first time attempting Ethereum hacking, so I might have made some mistakes here since the math is quite complex, but I'm going to give it a go.
Proof of Concept
The attack scenario is this: A malicious actor is able to hyper-inflate the interest rate on a pool by triggering a malicious mint function. The malicious actor does this to attack the LP and other members of the pool.
Consider the following HardHat script:
First, the LP deploys their pool and contributes their desired amount of tokens with the below contract:
Here are the initialization values:
With this configuration, I've calculated the interest rate to borrow on this pool using the functions defined here: https://timeswap.gitbook.io/timeswap/deep-dive/borrowing
to be:
Around 1% to 15%.
Then, the attacker comes along (see line containing
let atakcontrak
and after). The attacker deploys the following contract:Which contains the following settings for a mint:
According to my logs in hardhat:
The attacker is only required to pay 3 wei of Asset Token and 6 wei of Collateral token. However, after the attacker's malicious mint is up, the interest rate becomes:
Between 40 and 646 percent.
xyz values before and after:
This result in destruction of the pool.
The text was updated successfully, but these errors were encountered: