如何阅读智能合约?How to read smart contracts?
在区块浏览器(如 PolygonScan)打开一个合约,重点看几栏:Open a contract on a block explorer (such as PolygonScan) and focus on a few sections:
- 是否开源验证(Verified):能看到源码才谈得上核实;没验证的合约是黑盒。Whether it's open-source verified (Verified): only when you can see the source code can you talk about verification; an unverified contract is a black box.
- Read(读):不花 gas 的查询函数,如 owner()、totalSupply()、paused()。Read: query functions that cost no gas, such as owner(), totalSupply(), paused().
- Write(写):会改状态的函数,如 mint()、pause()、upgradeTo()。Write: functions that change state, such as mint(), pause(), upgradeTo().
几个高风险信号要会认:Learn to recognize a few high-risk signals:
- mint() 且管理员能随意调用 = 可增发。mint() that an admin can call at will = it can mint more supply.
- pause() / blacklist() = 能暂停交易或拉黑地址。pause() / blacklist() = it can pause trading or blacklist addresses.
- upgradeTo() / 代理合约(Proxy) = 逻辑可被更换,真正跑的代码在「实现合约」里。upgradeTo() / a proxy contract (Proxy) = the logic can be swapped out; the code that actually runs lives in the "implementation contract".
- owner 未放弃 / 有各种 ROLE = 权限集中在某些地址。owner not renounced / various ROLEs present = power is concentrated in certain addresses.
关键原则:不要只看函数名字下结论。名字叫 emergencyWithdraw(紧急提取)不代表保护用户,要看它到底是用户提现还是管理员提走合约资产。看到 renounceOwnership(放弃所有权)也别急着放心,可能还有 ProxyAdmin、DEFAULT_ADMIN_ROLE、多签等其他管理入口。Key principle: don't draw conclusions from a function's name alone. A function called emergencyWithdraw doesn't mean it protects users — check whether it's users withdrawing their own funds or an admin taking the contract's assets. Seeing renounceOwnership isn't a reason to relax either — there may still be other admin entry points like ProxyAdmin, DEFAULT_ADMIN_ROLE, or a multisig.
本站的合约验证中心已经把起源两条链上的合约整理好:是否开源、是否代理、可否升级、Owner、多签等一览,每个都能点到浏览器独立核实。先用它建立感觉,再自己去浏览器抠细节。This site's Contract Verify has already organized the contracts on ORIGIN's two chains: whether open source, whether a proxy, whether upgradeable, the owner, the multisig and more — all in one view, each clickable through to the explorer for independent verification. Use it to build a feel first, then dig into the details on the explorer yourself.
📝 本节测验📝 Quiz
1. 阅读合约的第一步应确认?1. The first step when reading a contract is to confirm?
2. 下列哪个是「可增发」的信号?2. Which of the following is a signal of "can mint more supply"?
3. 看到 renounceOwnership(放弃所有权)就一定安全吗?3. Does seeing renounceOwnership always mean it's safe?
4. 代理合约(Proxy)意味着?4. A proxy contract (Proxy) means?
5. 判断一个 Write 函数的风险,正确做法是?5. To judge the risk of a Write function, the correct approach is?
❓ 常见问题❓ FAQ
不会编程能读懂合约吗?Can you understand a contract without knowing how to code?
能。阅读合约主要是在区块浏览器上看合约是否开源、区分读/写函数、找出关键权限(能否增发/暂停/升级、owner 是谁),不需要自己写代码。Yes. Reading a contract is mainly about checking on a block explorer whether it's open source, telling read functions from write functions, and finding the key permissions (can it mint / pause / upgrade, who is the owner) — you don't need to write any code yourself.
看到 mint() 函数就说明有问题吗?Does seeing a mint() function mean there's a problem?
不一定。要看谁能调用、有没有上限和多签。函数存在不等于危险,关键是权限是否集中、是否可被单个地址无限调用。Not necessarily. Look at who can call it and whether there's a cap and a multisig. A function existing doesn't equal danger — what matters is whether the power is concentrated and whether a single address can call it without limit.