Full Report
Dynamic is a money market aggregator built that helps to enhance the DeFi lending experience. DYNA is the token of the ecosystem. When staking this token, a user can earn interest on it. The amount of interest is directly correlated to the length of time the token has been staked. If the more funds are added, then the portion should be changed. For instance, if I stake 5 DYNA then wait a month, I should get that interest. However, if I add funds to the contract after this point, the rewards of the new tokens should start from that point on. The code was not updating the information related to time. As a result, an attacker could stake a little amount of funds to rake up some time. Then, stake a HUGE amount of funds to make the contract believe we had staked these funds for a while. With this, we could extract wayyyy more value from the contract than we should be able to. In the real world, the attacker has a flash loan to make the amount of tokens much larger. Interesting hack when the time is not properly updated.
Analysis Summary
# Incident Report: Dynamic Protocol Reward Scaling Exploitation
## Executive Summary
The Dynamic protocol, a DeFi money market aggregator, suffered a smart contract exploitation due to a logic error in its staking reward calculation. By manipulating the "time-staked" variable, an attacker used extreme capital (via flash loans) to claim disproportionate rewards. The incident resulted in significant financial loss as the contract failed to reset the staking period when new funds were added.
## Incident Details
- **Discovery Date:** Not explicitly disclosed (Post-mortem analysis)
- **Incident Date:** Not explicitly disclosed
- **Affected Organization:** Dynamic Protocol
- **Sector:** Decentralized Finance (DeFi) / Cryptocurrency
- **Geography:** Global / Blockchain
## Timeline of Events
### Initial Access
- **Date/Time:** Immediate execution via smart contract interaction.
- **Vector:** Exploitation of logic flaw in `DYNA` staking contract.
- **Details:** The attacker initially staked a nominal amount of DYNA tokens to begin the "aging" process of their staking position.
### Lateral Movement
- **Not Applicable:** As this was an on-chain smart contract exploit, lateral movement across a private network did not occur. However, the attacker scaled their position vertically by utilizing a **Flash Loan** to acquire a massive volume of DYNA tokens.
### Data Exfiltration/Impact
- **Date/Time:** Following the aging period.
- **Details:** After the initial small stake had "aged," the attacker injected the flash-loaned capital into the same position. Because the contract failed to update the `time_staked` metadata for the new deposit, the contract treated the massive flash-loaned amount as if it had been staked for the entire duration. The attacker then withdrew the funds along with an inflated interest payout.
### Detection & Response
- **Discovery:** Discovered after an anomalous drain of rewards from the DYNA ecosystem.
- **Response Actions:** Analysis of the transaction logs revealed the failure of the smart contract to perform a "checkpoint" or reset of the reward multiplier upon additional deposits.
## Attack Methodology
- **Initial Access:** Direct interaction with the DYNA staking smart contract.
- **Persistence:** Not required; the attack was executed within a single or limited series of blocks.
- **Privilege Escalation:** Logic manipulation—tricking the contract into assigning high-tier reward seniority to new capital.
- **Defense Evasion:** Use of flash loans to bypass capital requirements.
- **Impact:** Forced depletion of the protocol's reward pool.
## Impact Assessment
- **Financial:** Significant loss of DYNA tokens from the reward treasury (Amount proportional to available liquidity at the time).
- **Data Breach:** None (Standard blockchain transparency).
- **Operational:** Disruption of the DYNA staking ecosystem; potential pause of the staking contract.
- **Reputational:** Loss of investor confidence in the protocol's smart contract security and auditing process.
## Indicators of Compromise
- **Behavioral indicators:**
- Transactions involving massive flash loans followed by immediate staking and un-staking.
- Disproportionately high reward claims relative to the actual time capital was at risk.
## Response Actions
- **Containment:** Likely pausing of the staking contract or the reward distribution mechanism.
- **Eradication:** Identification of the specific lines of code failing to update the `last_interaction_time` or `weighted_average_age` of the stake.
- **Recovery:** Development and deployment of a patched contract that enforces "reward scaling" or resets the time-multiplier upon additional deposits.
## Lessons Learned
- **Logic Flaw:** Reward multipliers based on time must be recalculated or reset whenever the principal balance changes ("Check-pointing").
- **Flash Loan Vulnerability:** Any protocol that scales rewards based on the balance of tokens must assume that an attacker can gain access to nearly infinite balance for a short period.
- **Validation:** Mathematical models for DeFi must be stress-tested against "time-travel" bugs where seniority is misapplied.
## Recommendations
- **Implement Checkpoints:** Ensure that `updateReward` modifiers or similar functions are called before any change to a user’s staked balance.
- **Weighted Average Staking:** Use a "Weighted Average Age" calculation so that adding 1,000 tokens to a 1-token stake significantly dilutes the average "age" of the position.
- **Third-Party Audits:** Subject smart contracts to rigorous logic audits specifically focused on reward distribution and flash loan resistance.