Skip to content

Commit

Permalink
refine output and log info
Browse files Browse the repository at this point in the history
  • Loading branch information
shuo-young committed Mar 19, 2024
1 parent 9d651a8 commit 36ef04a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 42 deletions.
38 changes: 6 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@
<p>
<img alt="Static Badge" src="https://img.shields.io/badge/rust-1.75.0-blue">
<img alt="Static Badge" src="https://img.shields.io/badge/ubuntu-20.04-yellow">
<img alt="Static Badge" src="https://img.shields.io/badge/docker-v0.1-purple">
<img alt="Static Badge" src="https://img.shields.io/badge/docker-v0.2-purple">
<a href="doc url" target="_blank">
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
</a>
<a href="LICSEN" target="_blank">
<img alt="License: Apache" src="https://img.shields.io/badge/License-Apache-yellow.svg" />
</a>
<img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/shuo-young/lydia/publish-docker-image.yml">
<!-- <img alt="GitHub forks" src="https://img.shields.io/github/forks/NFTDefects/nftdefects">
<!-- <img alt="GitHub forks" src="https://img.shields.io/github/stars/NFTDefects/nftdefects"> -->

<!-- <a href="https://twitter.com/shall_yangshuo" target="_blank">
<img alt="Twitter: shall\_yangshuo" src="https://img.shields.io/twitter/follow/shall_yangshuo.svg?style=social" />
</a> -->
</p>

<br />
Expand All @@ -27,16 +20,6 @@

<h3 align="center">Lydia</h3>

<p align="center">
<!-- <a href="https://github.com/shuo-young/BlockWatchdog"><strong>Explore the docs »</strong></a> -->
<!-- <br /> -->
<!-- <br /> -->
<!-- <a href="https://github.com/shuo-young/BlockWatchdog">View Demo</a>
· -->
<a href="https://github.com/shuo-young/lydia/issues">Report Bug</a>
·
<a href="https://github.com/shuo-young/lydia/issues">Request Feature</a>
</p>
</div>

<!-- TABLE OF CONTENTS -->
Expand All @@ -63,7 +46,6 @@
<!-- <li><a href="#code-structure">Code Structure</a></li> -->
<li><a href="#features">Features</a></li>
<!-- <li><a href="#publication">Publication</a></li> -->
<li><a href="#contact">Contact</a></li>
<li><a href="#license">License</a></li>

</ol>
Expand Down Expand Up @@ -103,7 +85,7 @@ cargo build --release
2. Or you can build or pull the docker image.

```sh
docker build -t lydia:v0.1 .
docker build -t lydia:local .
docker pull ghcr.io/shuo-young/lydia:latest
```

Expand All @@ -112,17 +94,17 @@ docker pull ghcr.io/shuo-young/lydia:latest
### Local

```sh
RUST_LOG=info cargo run -- ETH 0x10C509AA9ab291C76c45414e7CdBd375e1D5AcE8
RUST_LOG=info cargo run -- -b ETH -l 0x10C509AA9ab291C76c45414e7CdBd375e1D5AcE8
# or use build bin
./target/release/lydia -- ETH 0x10C509AA9ab291C76c45414e7CdBd375e1D5AcE8
./target/release/lydia -b ETH -l 0x10C509AA9ab291C76c45414e7CdBd375e1D5AcE8
```

### Docker

For the docker image, run with the following command.

```sh
docker run ghcr.io/shuo-young/lydia:latest ETH 0x10C509AA9ab291C76c45414e7CdBd375e1D5AcE8
docker run ghcr.io/shuo-young/lydia:latest -b ETH -l 0x10C509AA9ab291C76c45414e7CdBd375e1D5AcE8
```

## Features
Expand All @@ -133,15 +115,7 @@ docker run ghcr.io/shuo-young/lydia:latest ETH 0x10C509AA9ab291C76c45414e7CdBd37
- Report critical attack semantic, e.g., call in hook functions, selfdestruct, use randomnumer, creation (sole and multi) etc.
- Locating call sites that could perform reentrancy and possible reentrancy targets.

## Contact

👤 **Shuo Yang**

- Website: [shuo-young.github.io](https://shuo-young.github.io/)
- Twitter: [@shall_yangshuo](https://twitter.com/shall_yangshuo)
- Github: [@shuo-young](https://github.com/shuo-young)

## License

Copyright © 2024 [Shuo Yang](https://github.com/shuo-young).<br />
This project is [Apache](https://github.com/NFTDefects/nftdefects/blob/master/LICENSE) licensed.
This project is [Apache](https://github.com/shuo-young/lydia/blob/master/LICENSE) licensed.
7 changes: 4 additions & 3 deletions src/graph/call_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ impl<'a> CallGraph<'a> {
&self.visited_funcs
}

#[allow(unused_variables)]
pub async fn construct_cross_contract_call_graph(
&mut self,
source: Source,
) -> Result<(), Box<dyn std::error::Error>> {
let mut pending = vec![source];
println!("{:?}", pending);
// println!("{:?}", pending);
while let Some(temp) = pending.pop() {
let index = pending.len();
println!("pending length: {}", index);
println!("current temp contract: {}", temp.logic_addr);
// println!("pending length: {}", index);
// println!("current temp contract: {}", temp.logic_addr);
if temp.level > self.max_level {
self.max_level = temp.level;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async fn main() {
} else {
for func_sign in external_call_in_func_signature.clone().into_iter() {
// let mut contracts_mut = contracts.borrow_mut();
println!("{}", func_sign);
println!("call flow originated from function {}", func_sign);
let source = Source {
platform: platform.to_string(),
logic_addr: logic_address.to_string(),
Expand Down Expand Up @@ -316,6 +316,7 @@ async fn main() {
duration.subsec_nanos()
)
.into();
println!("{:?}", result);
let mut res: HashMap<String, Result> = HashMap::new();
res.insert(logic_address.to_string(), result);

Expand Down
12 changes: 6 additions & 6 deletions src/outputter/result_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

use crate::flow::flow_analysis::{ReachableSiteInfo, ReenterInfo};

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Result {
pub is_attack: bool,
pub warning: String,
Expand All @@ -28,31 +28,31 @@ pub struct Result {
pub reentrancy_path_info: HashMap<String, PathInfo>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct SemanticFeatures {
pub op_creation: OpCreation,
pub op_selfdestruct: bool,
pub op_env: bool,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct OpCreation {
pub op_multicreate: bool,
pub op_solecreate: bool,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct ExternalCall {
pub externalcall_inhook: bool,
pub externalcall_infallback: bool,
// pub hooks_focused: Vec<String>,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Overlap {
pub has_overlap: bool,
pub overlap_external_call: Vec<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct PathInfo {
pub victim_call: Vec<ReachableSiteInfo>,
pub attacker_reenter: Vec<ReenterInfo>,
Expand Down

0 comments on commit 36ef04a

Please sign in to comment.