[? 】
一連のスマート コントラクトがあり、 withdrawEth
という名前のpublic
メソッドを持つすべてのコントラクトを検索したいと考えていますが、字句 grep では多くの誤検知が発生しますか?ここでソルグレップが役立ちます。 ?
? npm install -g solgrep
Solgrep は、ターゲット ディレクトリ内のスマート コントラクトを再帰的に検索し、ソース ユニットを解析して言語のセマンティクスを理解し、この情報を強力な JavaScript ベースのフィルター関数で利用できるようにします。これにより、次のことが可能になります。
AST_EXACT
とAST_FUZZY
一致)おそらく、このツールを使用する最も一般的な方法は、 --find=<js-filter-statement>
オプションを使用してツールを実行することです。js js-filter-statement
関心のある内容をエンジンに伝える JavaScript のワンライナーです。 boolean
を返すステートメント (「検索モード」) を指定するか、抽出する情報を返すステートメント (「抽出モード」) を指定します。
--find=<js-filter-statement>
への信頼できる入力のみを許可するようにしてください。
--find
、 --rule
使用する場合は、引数の正しい順序を確認してください。 「使用法」を参照してください。
デフォルトのルールを実行して統計を表示しますか?
⇒ solgrep < folder >
特定または複数の組み込みルールを実行しますか (利用可能なルールをリストするにはsolgrep -l
)?
⇒ solgrep < folder > -- rule = IsInitializable -- rule = Stats
withdrawEth
という名前の関数を持つコントラクトを持つすべてのソースユニットを検索したいとしますか?
⇒ solgrep < folder > -- find = "function.name=='withdrawEth'"
同じことをしますが、大文字と小文字は区別されませんか?
⇒ solgrep < folder > -- find = "function.name.toLowerCase()=='withdraweth'"
selfdestruct
呼び出すすべての関数を検索しますか?
⇒ solgrep < folder > -- find = "function.callsTo('selfdestruct')"
すべてのコントラクトからすべての関数名を抽出しますか?
⇒ solgrep < folder > -- find = "function.name"
すべてのexternal
関数のリストを取得しますか?
⇒ solgrep < folder > -- find = "function.visibility.includes('external')"
ERC777
契約を見つけますか?
⇒ solgrep < folder > -- find = "contract.name=='ERC777'"
すべての契約名を抽出しますか?
⇒ solgrep < folder > -- find = "contract.name"
すべてのインターフェース名を抽出しますか?
⇒ solgrep < folder > -- find = "contract.name && contract.kind=='interface'"
AST
内の何かと一致しますか?
⇒ solgrep < folder > -- find = "Object.keys(function.modifiers).includes('nonReentrant')"
関数のソースコードと字句一致しますか?
⇒ solgrep < folder > -- find = "function.getSource().includes('hi')"
重複した契約を見つけますか? (AST の正確な一致とあいまいな一致)
⇒ solgrep < folder > -- rule DupeFinder
すべての結果をファイルに書き込むには、オプション--output=<output.json>
を使用します。
--find
の組み込みキーワードsourceUnit
オブジェクトは、エンジンが現在処理しているソース ファイルと一致します。contract
オブジェクトは、エンジンが現在処理しているコントラクトと一致します。function
オブジェクトは、エンジンが現在処理している関数と一致します。 次の方法が使用できます。
<sourceUnit|contract|function>.getSource()
- ユニットのソース コードへのアクセスを提供します<sourceUnit|contract|function>.ast
- Solidity-parser AST への直接アクセスを提供します。function.callsTo('withdrawEth')
- すべてのコントラクト内の、 withdrawEth
という名前のメソッドを呼び出すすべての関数を検索します。特殊なコントラクト関数は次のように参照できます。
function.name == '__fallback__'
function.name == '__receiveEther__'
function.name == '__constructor__'
Stats
- 処理されたファイル、コントラクト、一意の名前などの数に関する統計を収集します。GenericGrep
- --find
機能の背後にあるエンジンです共有は思いやりです- ルールを提出してください!
⇒ solgrep -- help
Usage: solgrep < folder | ... > [ options ]
Options:
- r , -- rule Enable rules [ array ] [ default : [ ] ]
- l , -- list - rules List available rules [ boolean ] [ default : false ]
- f , -- find Find / Extract information using custom pattern
[ array ] [ default : [ ] ]
- o , -- output Write "results" as JSON to output file path . [ string ]
- h , -- help Show help [ boolean ]
- v , -- version Show version number [ boolean ]
--find
、 --rule
) を使用する場合は、必ず次の形式を使用してください。
⇒ solgrep <folder|...> [options]
または
⇒ solgrep [options] -- <folder|...>
そうしないと、追加のオプションが追加の--find
オプションとして解釈される可能性があります。
const solgrep = require ( 'solgrep' ) ;
let sg = new SolGrep ( '::memory::' , rules , callbacks ) ;
sg . analyzeDir ( "/path/to/smart/contracts" ) . then ( ( ) => {
console . log ( " ──────────────────────────── Results" )
console . log ( sg . results )
console . log ( " ────────────────────────────" )
sgrep . close ( ) ;
} )
すべてのsourceUnits
およびcontracts
からすべての関数名を抽出する方法を示す例を次に示します。
⇒ solgrep . . / d0 -- find = 'function.name'
? SolGrep v0 .0 .3 ready !
Enabled Modules :
✔️ GenericGrep _function . name
[ ████████████████████████████████████████ ] 100 % | ? ETA : 0 s | 5 / 5 | ? 389 | 0 | . . / d0
────────────────────────────
{
'../d0/D0788Af7a613b81F437a51b96594A6387c7329b1_PendleLiquidityMiningBaseV2Multi.sol' : [
{
rule : 'GenericGrep' ,
tag : 'match-function: PendleLiquidityMiningBaseV2Multi.__constructor__' ,
info : '__constructor__' ,
loc : [ Object ]
} ,
{
rule : 'GenericGrep' ,
tag : 'match-function: PendleLiquidityMiningBaseV2Multi.setUpEmergencyMode' ,
info : 'setUpEmergencyMode' ,
loc : [ Object ]
} ,
...
設定オプションを指定しない場合は、デフォルトの組み込み grep ルールが使用され、 stats
モジュールを使用して数値が計算されます。
⇒ solgrep . . / d6
? SolGrep v0 .0 .1 starting . . .
? . . / d6
████████████████████████████████████████ 100 % | ETA : 0 s | 5 / 5
──────────────────────────── Results
{
'../d6/d60a598998ed27a7C54315F2675908B628E434B1_LiquidityPool.sol' : [
{
rule : 'IsInitializable' ,
tag : 'INITIALIZEABLE' ,
info : 'initialize - public initialize function; likely proxy'
} ,
{
rule : 'IsInitializable' ,
tag : 'INITIALIZEABLE' ,
info : 'initialize - public initialize function; likely proxy'
}
] ,
'../d6/d64E77C7C6A1dcC7e302F8fe31A22745e223c39c_MyStrategy.sol' : [
{
rule : 'IsInitializable' ,
tag : 'INITIALIZEABLE' ,
info : 'initialize - public initialize function; likely proxy'
}
] ,
undefined : [ { rule : 'Stats' , tag : 'STATS' , info : [ Object ] } ]
}
────────────────────────────
{
sourceUnits : 4 ,
contracts : {
total : 13 ,
names : {
ERC20 : 1 ,
StrategySushiEthMimLp : 1 ,
LiquidityPool : 1 ,
Getter : 1 ,
Governance : 1 ,
LibraryEvents : 1 ,
Perpetual : 1 ,
Storage : 1 ,
ArbiBoneman : 1 ,
ERC721 : 1 ,
MyStrategy : 1 ,
PausableUpgradeable : 1 ,
SettAccessControl : 1
}
} ,
interfaces : {
total : 39 ,
names : {
IERC20 : 1 ,
IJar : 1 ,
IStakingRewards : 1 ,
IStakingRewardsFactory : 1 ,
IMasterchef : 1 ,
UniswapRouterV2 : 1 ,
IUniswapV2Pair : 1 ,
IUniswapV2Factory : 1 ,
IRewarder : 1 ,
IMiniChefV2 : 1 ,
ILiquidityPool : 1 ,
IOracle : 1 ,
IAccessControl : 1 ,
IGovernor : 1 ,
IPoolCreatorFull : 1 ,
ISymbolService : 1 ,
IPoolCreator : 1 ,
ITracer : 1 ,
IVersionControl : 1 ,
IVariables : 1 ,
IKeeperWhitelist : 1 ,
IProxyAdmin : 1 ,
IDecimals : 1 ,
ILiquidityPoolGetter : 1 ,
ILiquidityPoolGovernance : 1 ,
IPerpetual : 1 ,
IERC721Enumerable : 1 ,
IERC721 : 1 ,
IERC721Receiver : 1 ,
IERC721Metadata : 1 ,
IERC165 : 1 ,
ICurveGauge : 1 ,
ICurveStableSwapREN : 1 ,
IUniswapRouterV2 : 1 ,
IStrategy : 1 ,
IController : 2 ,
IERC20Upgradeable : 2
}
} ,
libraries : {
total : 31 ,
names : {
SafeMath : 1 ,
SafeERC20 : 1 ,
BoringERC20 : 1 ,
EnumerableSetUpgradeable : 1 ,
SafeCastUpgradeable : 1 ,
AMMModule : 1 ,
LiquidityPoolModule : 1 ,
PerpetualModule : 1 ,
SignedSafeMathUpgradeable : 1 ,
Constant : 1 ,
Math : 1 ,
SafeMathExt : 1 ,
Utils : 1 ,
MarginAccountModule : 1 ,
EnumerableSet : 1 ,
OrderData : 1 ,
CollateralModule : 1 ,
TradeModule : 1 ,
OrderModule : 1 ,
Signature : 1 ,
ECDSAUpgradeable : 1 ,
Strings : 1 ,
MathUpgradeable : 1 ,
Address : 2 ,
SafeMathUpgradeable : 2 ,
AddressUpgradeable : 2 ,
SafeERC20Upgradeable : 2
}
} ,
abstract : {
total : 13 ,
names : {
StrategyBase : 1 ,
StrategySushiFarmBase : 1 ,
ReentrancyGuardUpgradeable : 1 ,
ERC721Enumerable : 1 ,
Ownable : 1 ,
ERC165 : 1 ,
BaseStrategy : 1 ,
Context : 2 ,
ContextUpgradeable : 2 ,
Initializable : 2
}
}
}
TOTAL FILES : 5
ERRORS: 1
────────────────────────────
cheers ?
@ tintinweb
ConsenSys Diligence @ https : //consensys.net/diligence/
https : //github.com/tintinweb/solgrep/