rustle
v2.0

沙沙作響是Rust近智能合約的自動靜態分析器。它可以幫助將幾十個不同的漏洞定位在近乎智能合約中。根據Defillama的說法,在附近的前10名DAPP中,有8個由Blocksec審核。憑藉豐富的審計經驗和對近協議的深刻理解,我們構建了此工具並與社區分享。
在Linux中使用以下命令安裝所需的工具包。命令在Ubuntu 20.04 LTS中進行了測試。
# install Rust Toolchain
curl --proto ' =https ' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# install LLVM 15
sudo bash -c " $( wget -O - https://apt.llvm.org/llvm.sh ) " 15
# install Python toolchain
sudo apt install python3 python3-pip # requires python >= 3.8
pip3 install -r utils/requirements.txt # you need to clone this repo first
# add WASM target
rustup target add wasm32-unknown-unknown
# install other components
sudo apt install figlet
cargo install rustfilt
# [optional] useful tools for developing
LLVM_VERSION=
sudo apt install clangd- $LLVM_VERSION clang-format- $LLVM_VERSION clang-tidy- $LLVM_VERSION 以下命令適用於使用MACOS的用戶,僅在Apple Silicon Mac上進行測試,因此請謹慎使用它們。
# install Rust Toolchain
curl --proto ' =https ' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# install LLVM 15
brew install llvm@15
# install Python packages
pip3 install -r utils/requirements.txt # you need to clone this repo first
# using macOS default python3
# add WASM target
rustup target add wasm32-unknown-unknown
# install other components
brew install figlet coreutils gsed
cargo install rustfilt我們提供了Docker解決方案。
# build the image
docker build --build-arg UID= ` id -u ` --build-arg GID= ` id -g ` -t rustle .
# run a container from the image
docker run --name rustle -it -v ` pwd ` :/rustle -w /rustle rustle bash
# exec the container
docker start rustle
docker exec -it -w /rustle rustle bash./rustle [-t | --tg_dir < tg_dir > ] [-d | --detector < detector_list > ] [-o | --output < output_dir > ] [-h | --help] < src_dir >src_dir :通往合同源的路徑。tg_dir :通往合同目標的路徑。默認值與src_dir相同。detector :檢測器列表。它可用於傳遞由,默認為all 。all組啟用所有檢測器。high , medium , low和info組,以使探測器組具有不同的嚴重性(請參閱探測器)nep-ft , nep-storage和nep-nft組,以實現為指定NEP實施的檢測器(請參閱NEP檢測器組)output :將生成審核報告的路徑。默認為./audit-result 。注意:如果貨物構建的目標位代碼( .bc二進制)不在$src_dir中,則使用-t|--tg_dir設置目標目錄,否則將其設置為$src_dir 。
下面的命令顯示了分析線性的示例。
# clone LiNEAR
git clone https://github.com/linear-protocol/LiNEAR.git ~ /near-repo/LiNEAR
# run Rustle
./rustle -t ~ /near-repo/LiNEAR ~ /near-repo/LiNEAR/contracts/linear
# [optional] run Rustle on specified detectors or severity groups and save audit reports in `~/linear-report`
./rustle -t ~ /near-repo/LiNEAR ~ /near-repo/LiNEAR/contracts/linear -d high,medium,complex-loop -o ~ /linear-reportCSV-Format報告將在“ ./audit-result”目錄中生成。
所有漏洞都可以找到。
| 檢測器ID | 描述 | 嚴重程度 |
|---|---|---|
unhandled-promise | 查找未處理的Promises | 高的 |
non-private-callback | 缺少宏#[private]回調功能 | 高的 |
reentrancy | 查找容易受到重新進入攻擊的功能 | 高的 |
unsafe-math | 缺乏算術操作的溢出檢查 | 高的 |
self-transfer | 缺少sender != receiver | 高的 |
incorrect-json-type | 參數或返回值中使用的錯誤類型 | 高的 |
unsaved-changes | 收集的更改未保存 | 高的 |
nft-approval-check | 在沒有approval id的情況下查找nft_transfer | 高的 |
nft-owner-check | 在沒有所有者檢查的情況下找到批准或撤銷功能 | 高的 |
div-before-mul | 由於操作訂單不正確而導致的精確損失 | 中等的 |
round | 無需指定天花板或地板而捨入 | 中等的 |
lock-callback | 回調功能的恐慌可能會鎖定合同 | 中等的 |
yocto-attach | 在特權功能中沒有assert_one_yocto | 中等的 |
dup-collection-id | 重複的ID在集合中使用 | 中等的 |
unregistered-receiver | 對未註冊的轉移接收器沒有恐慌 | 中等的 |
nep${id}-interface | 查找所有未完成的NEP接口 | 中等的 |
prepaid-gas | 缺少在ft_transfer_call中檢查預付費氣的檢查 | 低的 |
non-callback-private | 宏#[private]在非呼叫功能中使用 | 低的 |
unused-ret | 功能結果未使用或檢查 | 低的 |
upgrade-func | 合同中沒有升級功能 | 低的 |
tautology | 有條件分支的重言術 | 低的 |
storage-gas | 缺少餘額檢查存儲擴展 | 低的 |
unclaimed-storage-fee | 存儲之前缺少餘額檢查 | 低的 |
inconsistency | 使用相似但略有不同的符號 | 資訊 |
timestamp | 查找timestamp的所有用途 | 資訊 |
complex-loop | 找到具有復雜邏輯的所有循環,可能導致DOS | 資訊 |
ext-call | 查找所有交叉合同調用 | 資訊 |
promise-result | 找到承諾結果的所有用途 | 資訊 |
transfer | 查找所有轉移動作 | 資訊 |
public-interface | 找到所有公共接口 | 資訊 |
除了嚴重性水平,沙沙作用還通過相應的NEP提供了一些檢測器組。目前,沙沙作響支持以下組。
| NEP | 檢測器組ID | 檢測器ID |
|---|---|---|
| NEP-141 | nep-ft | nep141-interface , self-transfer , unregistered-receiver |
| NEP-145 | nep-storage | nep145-interface , unclaimed-storage-fee |
| NEP-171,NEP-178 | nep-nft | nep171-interface , nft-approval-check , nft-owner-check |
audit目標的依賴性及其名稱中的檢測器列表和嚴重性組中的目標./rustle腳本。audit.py中的其他檢測器代碼)。沙沙作響可以在開發過程中用於迭代掃描近乎智能的合同。這可以節省大量的手動努力並減輕一部分潛在問題。但是,複雜邏輯或與語義相關的脆弱性仍然是沙沙作響的限制。找到復雜的語義問題需要Blocksec的專家進行詳盡而徹底的審查。與我們聯繫以獲取審計服務。
該項目屬於AGPLV3許可證。有關完整許可文本,請參見許可證文件。