Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
82c004ef
Commit
82c004ef
authored
Jan 24, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `eof-crawler` CLI
parent
51fb98aa
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
3084 additions
and
0 deletions
+3084
-0
.gitignore
op-chain-ops/eof-crawler/.gitignore
+2
-0
Cargo.lock
op-chain-ops/eof-crawler/Cargo.lock
+2850
-0
Cargo.toml
op-chain-ops/eof-crawler/Cargo.toml
+18
-0
README.md
op-chain-ops/eof-crawler/README.md
+24
-0
ipc.rs
op-chain-ops/eof-crawler/src/ipc.rs
+93
-0
main.rs
op-chain-ops/eof-crawler/src/main.rs
+97
-0
No files found.
op-chain-ops/eof-crawler/.gitignore
0 → 100644
View file @
82c004ef
# Rust compilation artifacts
target/
op-chain-ops/eof-crawler/Cargo.lock
0 → 100644
View file @
82c004ef
This diff is collapsed.
Click to expand it.
op-chain-ops/eof-crawler/Cargo.toml
0 → 100644
View file @
82c004ef
[package]
name
=
"eof-crawler"
version
=
"0.1.0"
edition
=
"2021"
[dependencies]
clap
=
{
version
=
"4.1.3"
,
features
=
["derive"]
}
tokio
=
{
version
=
"1.24.2"
,
features
=
["macros"]
}
futures
=
"0.3.25"
rayon
=
"1.6.1"
eyre
=
"0.6.8"
ethers
=
{
version
=
"1.0.2"
,
features
=
["ipc"]
}
yansi
=
"0.5.1"
serde
=
{
version
=
"1.0.152"
,
features
=
["derive"]
}
serde_json
=
"1.0.91"
[[bin]]
name
=
"eof-crawler"
op-chain-ops/eof-crawler/README.md
0 → 100644
View file @
82c004ef
# `eof-crawler`
Simple CLI tool to scan all accounts in a geth snapshot file for contracts that begin with the EOF prefix and store them.
## Usage
```
sh
Usage: eof-crawler
--snapshot-file
<SNAPSHOT_FILE>
Options:
-s
,
--snapshot-file
<SNAPSHOT_FILE> The path to the geth snapshot file
-h
,
--help
Print
help
-V
,
--version
Print version
```
1.
To begin, create a geth snapshot:
```
sh
geth snapshot dump
--nostorage
>>
snapshot.txt
```
1.
Once the snapshot has been generated, feed it into the CLI:
```
sh
cargo r
--
-s
./snapshot.txt
```
1.
The CLI will output a file named
`eof_contracts.json`
containing all found EOF-prefixed contracts.
op-chain-ops/eof-crawler/src/ipc.rs
0 → 100644
View file @
82c004ef
use
clap
::
Parser
;
use
ethers
::
providers
::{
Ipc
,
Middleware
,
Provider
};
use
eyre
::
Result
;
use
futures
::
future
;
use
rayon
::
prelude
::
*
;
use
serde
::
Serialize
;
use
std
::
sync
::
Arc
;
use
yansi
::
Paint
;
#[derive(Parser)]
#[command(version,
about)]
struct
EofCrawler
{
/// The path to the IPC socket to connect to
#[clap(short,
long)]
ipc
:
String
,
/// The block to start crawling from
#[clap(short,
long)]
start
:
Option
<
u64
>
,
/// The block to end crawling at
#[clap(short,
long)]
end
:
Option
<
u64
>
,
}
#[derive(Serialize)]
struct
EOFContract
{
address
:
String
,
deployment_block
:
u64
,
deployer
:
String
,
bytecode
:
String
,
}
#[tokio::main]
#[allow(dead_code)]
async
fn
main
()
->
Result
<
()
>
{
// Parse CLI args
let
args
=
EofCrawler
::
parse
();
// Create a new provider with a connection to an IPC socket
let
provider
=
Arc
::
new
(
Provider
::
<
Ipc
>
::
connect_ipc
(
&
args
.ipc
)
.await
?
);
// Unless a starting block was specified, begin at genesis.
let
start
=
args
.start
.unwrap_or
(
0
);
// Get the latest block or use the end specified in the CLI args
let
end
=
match
args
.end
{
Some
(
block
)
=>
block
,
None
=>
provider
.get_block_number
()
.await
?
.as_u64
(),
};
// Perform a parallel search over blocks [0, block] for contracts
// that were deployed with the EOF prefix.
println!
(
"{}"
,
Paint
::
green
(
format!
(
"Starting search on block range [{start}, {end}]"
))
);
let
tasks
:
Vec
<
_
>
=
(
start
..=
end
)
.into_iter
()
.map
(|
block_no
|
{
// Clone the provider's reference counter to move into the task
let
provider
=
Arc
::
clone
(
&
provider
);
// Spawn a task to search for EOF contracts in the block
tokio
::
spawn
(
async
move
{
// Grab the block at the current block number, panic if we were unable
// to fetch it.
let
block
=
provider
.get_block_with_txs
(
block_no
)
.await
.unwrap
()
.unwrap
();
// Iterate through all transactions within the block in parallel to look
// for creation txs.
block
.transactions
.into_par_iter
()
.for_each
(|
tx
|
{
// `tx.to` is `None` if the transaction is a contract creation
// TODO: Check if contract creation failed.
if
tx
.to
.is_none
()
{
// TODO: Pull the runtime code from the creation code; store info
// about the contract.
}
});
})
})
.collect
();
// Wait on futures in parallel.
future
::
join_all
(
tasks
)
.await
;
Ok
(())
}
op-chain-ops/eof-crawler/src/main.rs
0 → 100644
View file @
82c004ef
use
clap
::
Parser
;
use
ethers
::
utils
::{
hex
,
keccak256
};
use
eyre
::
Result
;
use
serde
::{
Deserialize
,
Serialize
};
use
std
::{
fs
::
File
,
io
::{
BufRead
,
BufReader
},
};
use
yansi
::{
Color
,
Paint
};
#[derive(Parser)]
#[command(version,
about)]
struct
EofCrawler
{
/// The path to the geth snapshot file.
#[clap(short,
long)]
snapshot_file
:
String
,
}
#[derive(Serialize,
Deserialize,
Debug)]
struct
SnapshotAccount
{
/// The bytecode of the account
code
:
Option
<
String
>
,
/// The public key of the account
#[serde(rename(deserialize
=
"key"
))]
public_key
:
String
,
/// The address of the account
address
:
Option
<
String
>
,
}
fn
main
()
->
Result
<
()
>
{
let
args
=
EofCrawler
::
parse
();
let
mut
eof_contracts
:
Vec
<
SnapshotAccount
>
=
Vec
::
new
();
let
file
=
File
::
open
(
&
args
.snapshot_file
)
?
;
let
mut
reader
=
BufReader
::
new
(
file
);
println!
(
"{}"
,
Paint
::
wrapping
(
format!
(
"Starting EOF contract search in {}"
,
Paint
::
yellow
(
&
args
.snapshot_file
)
),)
.fg
(
Color
::
Cyan
)
);
let
mut
buf
=
String
::
new
();
// Ignore the first line of the snapshot, which contains the root of the snapshot.
if
let
Ok
(
mut
num_bytes
)
=
reader
.read_line
(
&
mut
buf
)
{
while
num_bytes
>
0
{
buf
.clear
();
num_bytes
=
reader
.read_line
(
&
mut
buf
)
?
;
if
buf
.is_empty
()
{
break
;
}
// Check if the account is a contract, and if it is, check if it has an EOF
// prefix.
let
mut
contract
:
SnapshotAccount
=
serde_json
::
from_str
(
&
buf
)
?
;
if
let
Some
(
code
)
=
contract
.code
.as_ref
()
{
if
&
code
[
2
..
4
]
.to_uppercase
()
==
"EF"
{
// Derive the address of the account from the public key.
// address = keccak256(public_key)[12:]
let
address
=
{
let
public_key
=
hex
::
decode
(
&
contract
.public_key
[
2
..
])
?
;
format!
(
"0x{}"
,
hex
::
encode
(
&
keccak256
(
&
public_key
)[
12
..
]))
};
contract
.address
=
Some
(
address
);
eof_contracts
.push
(
contract
);
}
}
}
}
println!
(
"{}"
,
Paint
::
wrapping
(
format!
(
"Found {} EOF contracts"
,
Paint
::
yellow
(
eof_contracts
.len
())
))
.fg
(
Color
::
Cyan
)
);
std
::
fs
::
write
(
"eof_contracts.json"
,
serde_json
::
to_string_pretty
(
&
eof_contracts
)
?
,
)
?
;
println!
(
"{}"
,
Paint
::
wrapping
(
format!
(
"Wrote EOF contracts to {}"
,
Paint
::
yellow
(
"eof_contracts.json"
)
))
.fg
(
Color
::
Green
)
);
Ok
(())
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment