| 研究生: |
徐浤瑋 Hsu, Hung-Wei |
|---|---|
| 論文名稱: |
增強 GPTScan 之智慧合約弱點檢測能力 Enhancing GPTScan for Smart Contract Vulnerability Detection |
| 指導教授: |
陳恭
莊豐源 |
| 學位類別: |
碩士
Master |
| 系所名稱: |
商學院 - 資訊管理學系 Department of Management Information System |
| 論文出版年: | 2026 |
| 畢業學年度: | 114 |
| 語文別: | 中文 |
| 論文頁數: | 77 |
| 中文關鍵詞: | 智慧合約 、預言機 、弱點偵測 、大型語言模型 、靜態分析 |
| 外文關鍵詞: | Smart Contract, Oracle, Vulnerability Detection, Large Language Model, Static Analysis |
| 相關次數: | 點閱:15 下載:0 |
| 分享至: |
| 查詢本校圖書館目錄 查詢臺灣博碩士論文知識加值系統 勘誤回報 |
智慧合約一旦部署即難以直接修改(即便採可升級代理架構,亦僅能整體替換實作邏輯而無法就地修補),其程式碼弱點可能造成不可逆之資產損失。其中預言機(Oracle)操控已成為損失金額最高之弱點類別之一,並於 OWASP Smart Contract Top 10(2025)列為第二名。現有偵測工具中,純靜態分析難以涵蓋業務邏輯層弱點,純大型語言模型(LLM)方法則有高誤報率與結果不穩定之問題;GPTScan 結合靜態分析與 LLM 之混合式框架雖具優勢,惟其原有十種弱點類型尚未涵蓋預言機特定弱點。
本研究以 GPTScan 為基礎框架,新增四條針對預言機弱點之偵測規則:缺乏預言機價格新鮮度檢查、缺乏去中心化預言機價格來源、預言機即時價格操縱與預言機 TWAP 觀察窗口不足,將其可偵測弱點類型由十種擴充至十四種。本研究建構涵蓋合成合約(102 個函式)與真實世界合約(23 個已知攻擊協議共 117 個函式)之測試集,合計 219 個函式層級標註,並以 5 輪重複實驗量化推理模型之隨機性。
實驗結果顯示,四條規則成功整合至 GPTScan,並於真實合約達到平均 F1 85.03%,且於全部四條規則均優於函式層級純 LLM 基線,平均高出 8.71 個百分點,其中需靜態資料流確認之兩條規則增益最為顯著。四條規則之偵測效能對 LLM 模型選擇亦具一定程度之穩健性:更換為 gemini-2.5-flash 後真實合約平均 F1 大致持平(86.00%),跨模型多數決進一步提升至 87.74%,此增益與模型異質性帶來能力互補之解釋一致。整體而言,本研究驗證了混合式偵測框架於預言機弱點偵測之有效性,並歸納四類弱點各自適用之驗證策略,此一對應關係亦為後續研究提供方向性之初步證據。
Smart contracts are difficult to modify once deployed (even upgradeable-proxy patterns can only replace the entire implementation logic rather than patch it in place), so code-level vulnerabilities can cause irreversible losses. Price oracle manipulation is among the highest-loss categories and ranks second (SC02) in the OWASP Smart Contract Top 10 (2025). Pure static analyzers struggle to cover business-logic vulnerabilities, while pure large language model (LLM) approaches suffer from high false-positive rates and unstable results. GPTScan, a hybrid framework combining static analysis with LLMs, mitigates both, but its original ten vulnerability types do not cover oracle-specific weaknesses.
This study extends GPTScan with four oracle vulnerability detection rules—Stale Oracle Validation Missing, Lack of Decentralized Oracle Sources, Spot Price Oracle Manipulation, and Insufficient TWAP Window or Single Observation—expanding its coverage from ten to fourteen types. We build a test set of 219 function-level annotations (102 synthetic and 117 real-world functions across 23 attacked protocols) and quantify reasoning-model randomness through 5-round repeated experiments.
The results show that the four rules integrate successfully, reaching an average real-world F1 of 85.03% and outperforming a function-level pure-LLM baseline by 8.71 percentage points across all four rules, with the largest gains on the two rules that require static data-flow confirmation. The rules also show a degree of robustness to LLM choice: replacing the backend with gemini-2.5-flash keeps a comparable F1 (86.00%), and a cross-model majority-voting ensemble further raises it to 87.74%, consistent with the gain arising from model heterogeneity rather than repeated sampling. Overall, the hybrid framework is effective for oracle vulnerability detection, and we characterize which verification strategy matches each vulnerability class, together with preliminary directional evidence.
致謝 i
摘要 ii
Abstract iii
目次 iv
表次 vi
圖次 vii
第一章 緒論 1
1.1 研究背景與動機 1
1.2 研究問題 2
1.3 研究目的與貢獻 3
1.4 論文架構 3
第二章 文獻探討 5
2.1 區塊鏈、智慧合約與去中心化金融 5
2.2 智慧合約弱點分類 6
2.3 靜態分析工具 7
2.4 機器學習方法於智慧合約弱點偵測 7
2.5 大型語言模型於程式碼分析之應用 8
2.6 GPTScan:結合 LLM 與靜態分析 8
2.7 預言機安全問題 12
2.8 相關研究比較 14
第三章 研究方法 17
3.1 研究設計概覽 17
3.2 規則設計框架 18
3.3 Rule 1:缺乏預言機價格新鮮度檢查 20
3.4 Rule 2:缺乏去中心化預言機價格來源 24
3.5 Rule 3:預言機即時價格操縱 28
3.6 Rule 4:預言機 TWAP 觀察窗口不足 32
3.7 測試案例設計 36
3.8 純 LLM 基線實驗協定 38
3.9 跨模型泛化與多數決實驗協定 40
3.10 評估方法 41
第四章 實驗結果與討論 42
4.1 實驗環境 42
4.2 GPTScan 擴充版偵測結果 42
4.3 純 LLM 基線對照 44
4.4 RQ3:跨模型泛化與穩健性分析 48
4.5 討論 53
第五章 結論與未來展望 58
5.1 研究總結 58
5.2 研究問題回應 58
5.3 研究限制 61
5.4 未來展望 63
參考文獻 66
附錄 70
Adams, A., Wan, X., & Zinsmeister, N. (2022). Uniswap v3 TWAP oracles in proof of stake [Uniswap Labs Blog]. https://blog.uniswap.org/uniswap-v3-oracles (cit. pp. 13, 32).
Atzei, N., Bartoletti, M., & Cimoli, T. (2017). A survey of attacks on Ethereum smart contracts. Proceedings of the 6th International Conference on Principles of Security and Trust (POST 2017). https://doi.org/10.1007/978-3-662-54455-6_8 (cit. p. 6).
Binance Research. (2023). Oracle-less: Challenging the status quo. https://public.bnbstatic.com/static/files/research/oracle-less-challenging-the-status-quo.pdf (cit. p. 2).
Buterin, V. (2014). A next-generation smart contract and decentralized application platform [Ethereum Whitepaper]. https://ethereum.org/content/whitepaper/whitepaper-pdf/Ethereum_Whitepaper_-_Buterin_2014.pdf (cit. p. 5).
CertiK. (2025). Oracle wars: The rise of price manipulation attacks. https://www.certik.com/resources/blog/oracle-wars-the-rise-of-price-manipulation-attacks (cit. p. 12).
Chainalysis. (2026). 2025 crypto theft reaches $3.4 billion. https://www.chainalysis.com/blog/crypto-hacking-stolen-funds-2026/ (cit. p. 1).
Chaliasos, S., Charalambous, M. A., Zhou, L., Galanopoulou, R., Gervais, A., Mitropoulos, D., & Livshits, B. (2024). Smart contract and DeFi security tools: Do they meet the needs of practitioners? Proceedings of the IEEE/ACM 46th International Conference on Software Engineering. https://doi.org/10.1145/3597503.3623302 (cit. p. 7).
Chen, C., Su, J., Chen, J., Wang, Y., Bi, T., Yu, J., Wang, Y., Lin, X., Chen, T., & Zheng, Z. (2025). When ChatGPT meets smart contract vulnerability detection: How far are we? ACM Transactions on Software Engineering and Methodology, 34(4), Article 100. https://doi.org/10.1145/3702973 (cit. pp. 1, 8, 16, 56).
David, I., Zhou, L., Qin, K., Song, D., Cavallaro, L., & Gervais, A. (2023). Do you still need a manual smart contract audit? [arXiv:2306.12338]. https://doi.org/10.48550/arXiv.2306.12338 (cit. pp. 16, 39).
DefiLlama. (2025). DeFi total value locked (TVL) [Retrieved March 2026]. https://defillama.com/ (cit. p. 1).
Deng, X., Beillahi, S. M., Minwalla, C., Du, H., Veneris, A., & Long, F. (2024). Safeguarding DeFi smart contracts against oracle deviations. Proceedings of the IEEE/ACM 46th International Conference on Software Engineering. https://doi.org/10.1145/3597503.3639225 (cit. p. 16).
Ellis, S., Juels, A., & Nazarov, S. (2017). ChainLink: A decentralized oracle network [Whitepaper]. https://research.chain.link/whitepaper-v1.pdf (cit. p. 5).
Feist, J., Grieco, G., & Groce, A. (2019). Slither: A static analysis framework for smart contracts. IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB). https://doi.org/10.1109/WETSEB.2019.00008 (cit. p. 7).
Ivanov, N., Li, C., Yan, Q., Sun, Z., Cao, Z., & Luo, X. (2023). Security threat mitigation for smart contracts: A comprehensive survey. ACM Computing Surveys, 55(14s), Article 326. https://doi.org/10.1145/3593293 (cit. pp. 5, 7).
Kojima, T., Gu, S. S., Reid, M., Matsuo, Y., & Iwasawa, Y. (2022). Large language models are zero-shot reasoners. Advances in Neural Information Processing Systems, 35, 22199–22213 (cit. p. 10).
Luu, L., Chu, D.-H., Olickel, H., Saxena, P., & Hobor, A. (2016). Making smart contracts smarter. Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security, 254–269. https://doi.org/10.1145/2976749.2978309 (cit. p. 6).
Mackinga, T., Nadahalli, T., & Wattenhofer, R. (2022). TWAP oracle attacks: Easier done than said? 2022 IEEE International Conference on Blockchain and Cryptocurrency (ICBC). https://eprint.iacr.org/2022/445 (cit. pp. 13, 32, 65).
OpenAI. (2023). GPT-4 technical report. https://doi.org/10.48550/arXiv.2303.08774 (cit. p. 8).
OpenAI. (2025). GPT-5 system card. https://cdn.openai.com/gpt-5-system-card.pdf (cit. p. 11).
OWASP Foundation. (2025a). Smart contract top 10. https://owasp.org/www-project-smart-contract-top-10/ (cit. pp. 2, 3).
OWASP Foundation. (2025b). Smart contract weakness enumeration (SCWE), stable version v1.0. https://scs.owasp.org/SCWE/ (cit. p. 7).
Perez, D., & Livshits, B. (2021). Smart contract vulnerabilities: Vulnerable does not imply exploited. Proceedings of the 30th USENIX Security Symposium, 1325–1341. https://www.usenix.org/conference/usenixsecurity21/presentation/perez (cit. p. 7).
Qian, P., Liu, Z., He, Q., Zimmermann, R., & Wang, X. (2020). Towards automated reentrancy detection for smart contracts based on sequential models. IEEE Access, 8, 19685–19695. https://doi.org/10.1109/ACCESS.2020.2969429 (cit. p. 7).
Sun, Y., Wu, D., Xue, Y., Liu, H., Wang, H., Xu, Z., Xie, X., & Liu, Y. (2024). GPTScan: Detecting logic vulnerabilities in smart contracts by combining GPT with program analysis. Proceedings of the IEEE/ACM 46th International Conference on Software Engineering. https://doi.org/10.1145/3597503.3639117 (cit. pp. 1, 8, 9, 18, 56, 57).
Szabo, N. (1996). Smart contracts: Building blocks for digital markets. Extropy, (16) (cit. p. 5).
Tann, W. J.-W., Han, X. J., Gupta, S. S., & Ong, Y.-S. (2018). Towards safer smart contracts: A sequence learning approach to detecting security threats [arXiv:1811.06632]. https://doi.org/10.48550/arXiv.1811.06632 (cit. p. 7).
Three Sigma. (2025). 2024 most exploited DeFi vulnerabilities. https://threesigma.xyz/blog/exploit/2024-defi-exploits-top-vulnerabilities (cit. p. 12).
Wang, W., Song, J., Xu, G., Li, Y., Wang, H., & Su, C. (2021). ContractWard: Automated vulnerability detection models for Ethereum smart contracts. IEEE Transactions on Network Science and Engineering, 8(2), 1133–1144. https://doi.org/10.1109/TNSE.2020.2968505 (cit. pp. 1, 7, 14).
Wang, X., Wei, J., Schuurmans, D., Le, Q. V., Chi, E. H., Narang, S., Chowdhery, A., & Zhou, D. (2023). Self-consistency improves chain of thought reasoning in language models. Proceedings of the 11th International Conference on Learning Representations (ICLR 2023). https://openreview.net/forum?id=1PL1NIMMrw (cit. pp. 8, 40, 51).
Zhang, Z., Zhang, B., Xu, W., & Lin, Z. (2023). Demystifying exploitable bugs in smart contracts. Proceedings of the IEEE/ACM 45th International Conference on Software Engineering, 615–627. https://doi.org/10.1109/ICSE48619.2023.00061 (cit. p. 7).
Zhuang, Y., Liu, Z., Qian, P., Liu, Q., Wang, X., & He, Q. (2020). Smart contract vulnerability detection using graph neural network. Proceedings of the 29th International Joint Conference on Artificial Intelligence (IJCAI 2020), 3283–3290. https://doi.org/10.24963/ijcai.2020/454 (cit. p. 7).
全文公開日期 2031/07/26