環(huán)境:
macbook pro
Truffle v5.0.35 (core: 5.0.35)
Node v12.10.0
Solidity - 0.4.24 (solc-js)
一、概述
??Mythx為以太坊智能合約的安全檢測工具,SWC Registry可以看到具體的test cases
二、Mythx插件安裝&運行
在裝插件前請把node環(huán)境和truffle裝起來
利用npm進行安裝:
npm install truffle-security
安裝完,利用truffle創(chuàng)建一個項目,寫一個檢查的只能合約,運行就ok了
truffle run verify
看到以下運行打印的信息,如果沒有MythX賬號只是trial模式,分析項目有限,所以如果要跑全權限的話就要注冊mythx的賬號了
bigcherry_contract git:(master) ? truffle run verify
You are currently running MythX in Trial mode. This mode reports only a partial analysis of your smart contracts, limited to three vulnerabilities. To get a complete analysis, sign up for a free MythX account at https://mythx.io.
三、注冊Mythx賬號
安裝MetaMask
Mythx注冊需要關聯(lián)metamask賬號注冊Mythx
這個按照注冊提示走就好郵件驗證
這步一定要做-
修改密碼
最好修改咯
image.png

image.png

image.png
四、設置環(huán)境變量
把以下代碼加到/etc/profile末尾,然后執(zhí)行source /etc/profile
export MYTHX_ETH_ADDRESS=0x1234567891235678900000000000000000000000
export MYTHX_PASSWORD='Put your password in here!'
然后再運行truffle run verify就看到檢測的項目多了。
五、配置選項
當運行如下命令的時候就會看到選項,可以在運行的時候去配置,也可以寫一個truffle-security.json文件把配置寫在里面
truffle run verify --help
truffle-security.json文件內容:
{
"style": "table",
"limit":1
}
六、問題查找
(py374) ? bigcherry_contract git:(master) ? truffle run verify contracts/new-supernode.sol:BCHC_Token
Welcome to MythX! You are currently running in Free mode.
BCHC_Token |**********************************************************************************| 100% || Elapsed: 9.1s ? completed
/Users/JC/Documents/project/grg_blockchain/contract/bigcherry_contract/contracts/new-supernode.sol
║ Line │ Column │ Type │ Message │ Rule ID ║
╟──────────┼──────────┼──────────┼────────────────────────────────────────────────────────┼──────────────────────╢
║ -1 │ 0 │ warning │ Upgrade to MythX Pro to unlock the ability to test │ N/A ║
║ │ │ │ for even more vulnerabilities, perform deeper │ ║
║ │ │ │ security analysis, and more. │ ║
║ │ │ │ https://mythx.io/plans │ ║
║ 1 │ 0 │ warning │ A floating pragma is set. │ SWC-103 ║
║ 17 │ 27 │ warning │ The state variable visibility is not set. │ SWC-108 ║
║ 48 │ 28 │ warning │ The state variable visibility is not set. │ SWC-108 ║
這里有幾個warning如果想知道某個warning的含義就拿RuleID去https://swcregistry.io/docs/SWC-103找相應的答案,還有正確的寫法。
