# 我被黑了 **Published by:** [TinyHill](https://paragraph.com/@tinyhill/) **Published on:** 2021-11-06 **URL:** https://paragraph.com/@tinyhill/uC0xs0lcvdTKjlZAxpMC ## Content 今天我在heco上的套利合约被人黑了,损失大概是53000美金。 合约的漏洞大致是: 合约中有approve 给router的操作 router是输入传的 黑客传入自己的合约作为router,但是实际在他的router.swap的逻辑中不做任何操作,所以approve给他的金额没有消费掉 给我转小额,通过我的余额检查 从我的逻辑中退出后,因为approve给他的限额没有消费掉,现在可以从我的合约里直接转钱走了 其实,合约的检查可以更仔细,但是之前考虑到合约不对外且不开源,为了方便,没有加一下验证。这次是真的被迫涨记性了 通过这次的被盗,至少有一下几点心得: 合约不开源是可以反编译的,solidity反编译的可读性相对较高 套利合约,是容易被人盯上的 sender和tx.origin的检查不能少 逻辑结束的时候,除了余额检查,应该取消所有approve 哎 ## Publication Information - [TinyHill](https://paragraph.com/@tinyhill/): Publication homepage - [All Posts](https://paragraph.com/@tinyhill/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@tinyhill): Subscribe to updates - [Twitter](https://twitter.com/JosQiu): Follow on Twitter