界: Code Quality

程式碼品質不佳,會導致無法預料的行為。從使用者的角度來看,這通常表現為可用性不佳。對於攻擊者而言,這提供了以意想不到的方式向系統施加壓力的機會。

Solidity Misconfiguration: Floating Pragma

Abstract
合約使用浮動 pragma 且 Solidity 編譯器未鎖定至特定版本。
Explanation
開發人員可以指定在建立智慧合約時所使用的相容 Solidity 編譯器版本範圍。但不建議這樣做,因為合約通常僅在一個可用的版本中進行開發和測試。這會給使用已知安全弱點的過時版本編譯器進行編譯留下可乘之機。

範例 1:以下這行程式碼設定了 pragma,這樣智慧合約就不會在 0.4.5 之前的版本中編譯,也無法在 0.5.0 及更高版本的編譯器中發揮效用。


pragma solidity ^0.4.5;
References
[1] Enterprise Ethereum Alliance Source code, pragma, and compilers
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 5
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 3
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - Common Weakness Enumeration CWE ID 664
[7] Standards Mapping - Smart Contract Weakness Classification SWC-103
desc.structural.solidity.swc103