Commit 91349655 authored by clabby's avatar clabby

Semgrep + README

parent 0d86b084
...@@ -4,6 +4,8 @@ Simple CLI tool to scan all accounts in a geth LevelDB for contracts that begin ...@@ -4,6 +4,8 @@ Simple CLI tool to scan all accounts in a geth LevelDB for contracts that begin
## Usage ## Usage
1. Pass the directory of the Geth DB into the tool
```sh ```sh
go run eof_crawler.go <db_path> go run eof_crawler.go <db_path>
``` ```
2. Once the indexing has completed, an array of all EOF-prefixed contracts will be written to `eof_contracts.json`.
...@@ -3,7 +3,6 @@ package main ...@@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil"
"log" "log"
"os" "os"
"time" "time"
...@@ -69,7 +68,10 @@ func main() { ...@@ -69,7 +68,10 @@ func main() {
for it.Next() { for it.Next() {
// Decode the state account // Decode the state account
var data types.StateAccount var data types.StateAccount
rlp.DecodeBytes(it.Value, &data) err := rlp.DecodeBytes(it.Value, &data)
if err != nil {
log.Fatalf("Failed to decode state account: %v", err)
}
// Check to see if the account has any code associated with it before performing // Check to see if the account has any code associated with it before performing
// more reads from the trie & db. // more reads from the trie & db.
...@@ -100,7 +102,6 @@ func main() { ...@@ -100,7 +102,6 @@ func main() {
code, err := stateDB.ContractCode(crypto.Keccak256Hash(addrBytes), common.BytesToHash(data.CodeHash)) code, err := stateDB.ContractCode(crypto.Keccak256Hash(addrBytes), common.BytesToHash(data.CodeHash))
if err != nil { if err != nil {
log.Fatalf("Could not load code for account %x: %v", addr, err) log.Fatalf("Could not load code for account %x: %v", addr, err)
continue
} }
// Check if the contract's runtime bytecode starts with the EOF prefix. // Check if the contract's runtime bytecode starts with the EOF prefix.
...@@ -125,7 +126,10 @@ func main() { ...@@ -125,7 +126,10 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("Cannot marshal EOF contracts: %v", err) log.Fatalf("Cannot marshal EOF contracts: %v", err)
} }
err = ioutil.WriteFile("eof_contracts.json", file, 0644) err = os.WriteFile("eof_contracts.json", file, 0644)
if err != nil {
log.Fatalf("Failed to write EOF contracts array to file: %v", err)
}
log.Printf("Wrote list of EOF contracts to `eof_contracts.json`") log.Printf("Wrote list of EOF contracts to `eof_contracts.json`")
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment