# HPAY 攻击事件分析 **Published by:** [ACai](https://paragraph.com/@acai/) **Published on:** 2022-11-09 **URL:** https://paragraph.com/@acai/hpay ## Content 背景分析文档目录:contract ├─autocompound │ AutocompundStaking.sol │ ├─base │ BaseStaking.sol │ MintableSupplyStaking.sol │ TaxedStaking.sol │ ├─lib │ StakingUtils.sol │ ├─presets │ MintableAutoCompundRelockBonus.sol │ └─timelock FixedTimeLockStaking.sol RelockBonusStaking.sol StaticFixedTimeLockStaking.sol 更多信息: https://wooded-meter-1d8.notion.site/0e85e02c5ed34df3855ea9f3ca40f53b?v=22e5e2c506ef4caeb40b4f78e23517ee&p=d4489312830a40819dbfc3ec1fb4246c&pm=s漏洞分析setTokenMintableAutoCompundRelockBonus.setToken 函数功能权限设置不当,任意用户可以修改结构体 configuration 中的 stakingToken 与 rewardsToken 参数。struct StakingConfiguration { uint256 rewardRate; uint256 startTime; uint256 minStake; uint256 maxStake; ERC20 stakingToken; ERC20 rewardsToken; } 攻击过程创建一个 fakeToken;调用 setToken 函数将 stakingToken 与 rewardsToken 设为攻击者创建的 fakeToken;setToken调用 stake 函数,向 MintableAutoCompundRelockBonus 合约转入 fakeToken。此时 _balances[msg.sender] 将会记录攻击者存入的 fakeToken 数量;stake调用 setToken 函数将 stakingToken 与 rewardsToken 设为 HPAY;调用 withdraw 函数,从 MintableAutoCompundRelockBonus 合约转出 HPAY 。此时合约根据先前步骤 3 中存入 fakeToken 所记录的 _balances[msg.sender] 进行提款操作,实际提出的是 HPAY。 ## Publication Information - [ACai](https://paragraph.com/@acai/): Publication homepage - [All Posts](https://paragraph.com/@acai/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@acai): Subscribe to updates