- -
คุณมีชุดสัญญาอัจฉริยะและต้องการค้นหาสัญญาทั้งหมดที่มีวิธี public
ชื่อ withdrawEth
แต่คำศัพท์ grep ให้ผลบวกลวงจำนวนมากใช่ไหม Solgrep ช่วยได้ที่นี่! -
- npm install -g solgrep
Solgrep ค้นหาสัญญาอัจฉริยะในไดเร็กทอรีเป้าหมายซ้ำๆ แยกวิเคราะห์หน่วยต้นทางเพื่อทำความเข้าใจความหมายภาษา และทำให้ข้อมูลนี้พร้อมใช้งานสำหรับฟังก์ชันตัวกรองที่ใช้จาวาสคริปต์ที่มีประสิทธิภาพ ด้วยวิธีนี้ คุณสามารถ:
AST_EXACT
และ AST_FUZZY
) วิธีที่พบบ่อยที่สุดในการใช้เครื่องมือนี้คือการรันด้วยตัวเลือก --find=<js-filter-statement>
โดยที่ js-filter-statement
เป็น javascript one-liner ที่บอกกลไกว่าคุณสนใจอะไร คุณจะระบุคำสั่งที่ส่งคืน 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')"
Lexial ตรงกับซอร์สโค้ดของฟังก์ชันหรือไม่
⇒ 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 ASTfunction.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/