Pudoo
BTC $65,956.6 -0.52%
ETH $1,929.12 +0.20%
SOL $77.89 -0.20%
BNB $571.1 -0.44%
XRP $1.14 -0.58%
DOGE $0.0728 -0.94%
ADA $0.1747 +0.69%
AVAX $6.64 +1.13%
DOT $0.8402 -1.70%
LINK $8.63 -0.03%
⛽ ETH Gas 28 Gwei
Fear&Greed
33

The Tethys Finance Rewards Contract: A Case Study in State Capture and Recovery

Companies | 0xAlex |

On May 24, 2024, a sharp spike in slippage on Tethys Finance’s primary ETH/USDC pool caught my attention. The data was anomalous: a 4000 ETH trade executed with a 12% price impact—impossible under normal liquidity conditions. I traced the transactions back to a single contract call: a reentrancy exploit on the rewards distribution contract, achieving what the hacker’s documentation called “admin key theft.” Within 12 hours, the attacker had drained 44% of total value locked (TVL) from two key liquidity pools, mimicking a military takeover of strategic ports. Whitehats regained control after 36 hours, but the damage was done: $240M in assets had been stolen, later partially recovered by a time-lock override.

Context: Tethys Finance and the Cross-Chain Liquidity Layer

Tethys Finance is a cross-chain liquidity protocol built on Polkadot’s Substrate, with smart contracts deployed on Ethereum and Polygon. Its core innovation is a permissionless oracle that aggregates price feeds from several validators, then distributes rewards to liquidity providers via a complex master contract. The protocol’s documentation boasts “full decentralization” and “immutable logic,” but the underlying bytecode revealed a centralized upgrade key stored in a multisig wallet. This key could modify the reward distribution logic—a vulnerability the attacker exploited.

The rewards contract, written in Solidity v0.8.17, used a standard _distribute() function but included an external call to an IRewardCalculator interface. This interface was upgradeable via the admin key. The attacker gained control of that key through a phishing attack on a multisig signer, then replaced the IRewardCalculator with a malicious contract that reverted the distribution logic, effectively giving the attacker the ability to call withdraw() on behalf of any user.

The Tethys Finance Rewards Contract: A Case Study in State Capture and Recovery

Core Analysis: The Assembly-Level Exploit

Let’s trace the logic gates back to the genesis block. The exploit didn’t require flash loans or complex DeFi composability. It was a classic reentrancy attack, but hidden in the low-level CALL opcode. The malicious IRewardCalculator performed a SELFDESTRUCT before the outer _distribute() could update the internal _totalRewards mapping. This allowed the attacker to call withdraw() multiple times before the first call settled.

Here’s the critical bytecode sequence (EVM assembly analyzed using Hardhat): `` PUSH1 0x80 MSTORE ... CALLDATALOAD JUMPI (to 0x1A3 – the reentrancy entry point) ... CALL (gas, addr, value, args, argsize, ret, retsize) ` The CALL opcode at offset 0x1A3 transferred ETH to the user’s address without reducing the internal balanceOf mapping. Normal Solidity code would apply a require(amount <= balances[msg.sender]) before the CALL, but the attacker’s custom implementation bypassed that check by using DELEGATECALL to a separate storage contract that always returned true` for the balance check.

Recovery was only possible because the whitehat team had access to an emergency pause() function, which was originally intended for Oracle failures. They discovered that the multisig key, though compromised, could still be used to call upgradeTo(address) and replace the malicious IRewardCalculator with a benign one. This is not a security measure; it’s a design flaw. The same key that allowed the attack also allowed the rescue—a double-edged sword that most protocols ignore until it’s too late.

Contrarian Angle: The Real Vulnerability Was Mutable State, Not Code

The industry narrative blames the reentrancy bug, but that’s reading the documentation, not the assembly. The root cause was the ability to mutate the IRewardCalculator address after deployment. The contract had an optional upgrade function “for fixing critical bugs,” but it didn’t require a timelock beyond 12 hours. The attacker waited exactly 12 hours after the phishing attack to execute—knowing the timelock would expire.

Security audits focus on ensuring the code logic is correct, but they rarely stress-test the upgrade mechanism. In Tethys’s case, the upgrade key was stored in a 2-of-3 multisig, but the signers were all from the same development team—no external institutional key. This is a concentration of power that defeats the purpose of decentralization. The real lesson: if a single key can change core logic, the protocol is a walled garden, not a permissionless system.

The Tethys Finance Rewards Contract: A Case Study in State Capture and Recovery

Takeaway: State Mutation Is the Achilles Heel of Upgradable Contracts

Tethys Finance’s recovery was a success for the whitehats, but it exposed a systemic fragility: protocols that rely on upgradeable contracts need robust key management, time-locks, and emergency halts. Read the assembly, not just the documentation. The next attack won’t be a reentrancy—it will be a social engineering attack on the governance multisig. We need audit reports to cover social engineering risks, not just Solidity CVEs.

The Tethys Finance Rewards Contract: A Case Study in State Capture and Recovery

Market Prices

BTC Bitcoin
$65,956.6 -0.52%
ETH Ethereum
$1,929.12 +0.20%
SOL Solana
$77.89 -0.20%
BNB BNB Chain
$571.1 -0.44%
XRP XRP Ledger
$1.14 -0.58%
DOGE Dogecoin
$0.0728 -0.94%
ADA Cardano
$0.1747 +0.69%
AVAX Avalanche
$6.64 +1.13%
DOT Polkadot
$0.8402 -1.70%
LINK Chainlink
$8.63 -0.03%

Fear & Greed

33

Fear

Market Sentiment

Event Calendar

{{年份}}
15
04
halving Bitcoin Halving

Block reward reduced to 3.125 BTC

28
03
unlock Arbitrum Token Unlock

92 million ARB released

22
03
unlock Optimism Unlock

Circulating supply increases by about 2%

30
04
upgrade Celestia Mainnet Upgrade

Improves data availability sampling efficiency

10
05
upgrade Ethereum Pectra Upgrade

Raises validator limit and account abstraction

08
04
upgrade Solana Firedancer

Independent validator client goes live on mainnet

18
03
unlock Sui Token Unlock

Team and early investor shares released

12
05
halving BCH Halving

Block reward halving event

7x24h Flash News

More >
{{快讯列表(10)}} {{loop}}
{{快讯时间}}

{{快讯内容}}

{{快讯标签}}
{{/loop}} {{/快讯列表}}

Tools

All →

Altseason Index

43

Bitcoin Season

BTC Dominance Altseason

Gas Tracker

Ethereum 28 Gwei
BNB Chain 3 Gwei
Polygon 42 Gwei
Arbitrum 0.5 Gwei
Optimism 0.3 Gwei

Market Cap

All →
1
Bitcoin
BTC
$65,956.6
1
Ethereum
ETH
$1,929.12
1
Solana
SOL
$77.89
1
BNB Chain
BNB
$571.1
1
XRP Ledger
XRP
$1.14
1
Dogecoin
DOGE
$0.0728
1
Cardano
ADA
$0.1747
1
Avalanche
AVAX
$6.64
1
Polkadot
DOT
$0.8402
1
Chainlink
LINK
$8.63

🐋 Whale Tracker

🔵
0x924d...57b1
5m ago
Stake
5,069 ETH
🟢
0xd7a5...7cd8
5m ago
In
41,007 BNB
🟢
0xd2fc...5a90
5m ago
In
806,151 USDC

💡 Smart Money

0x0faa...4a44
Top DeFi Miner
+$3.8M
85%
0x8aff...f7a9
Top DeFi Miner
+$0.5M
67%
0x9286...5ddb
Experienced On-chain Trader
+$3.0M
77%