Skip to content

Commit

Permalink
feat: solidity std json input to tensor data
Browse files Browse the repository at this point in the history
  • Loading branch information
He1pa committed Jan 30, 2024
1 parent cb07903 commit 9b4946d
Show file tree
Hide file tree
Showing 25 changed files with 1,877 additions and 92 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ target/
/tmp/
# Created by default with `src/ci/docker/run.sh`
/obj/
**/Cargo.lock

## Temporary files
*~
Expand Down Expand Up @@ -65,3 +66,11 @@ benches/*.xls
coverage.xml
lcov_cobertura.py
TEST-*.xml

## node
node_modules
package-lock.json

#test data
tensor/src/test_data
ai_intent/example/output/*

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ai_intent/example/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

script_dir=$(cd "$(dirname "$0")" && pwd)

input_dir="$script_dir/input"
root=$(cd "$script_dir/../.." && pwd)

# cd "$root" & npm install

ir_cli sol2tensor "$input_dir"
64 changes: 62 additions & 2 deletions ir_cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ir_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ inkwell = { git = "https://github.com/TheDan64/inkwell", rev = "4f18389938292f6d
] }
smart_ir_macro = { path = "../smart_ir_macro", version = "0.3.0" }
smart_ir = { path = "../smart_ir" }
yul_to_ir = { path = "../yul_to_ir" }
tensor = { path = "../tensor" }
compiler_base_span = "0.0.1"
chrono = "0.4.26"
log = "0.4.14"
Expand Down
63 changes: 63 additions & 0 deletions ir_cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
use std::sync::Arc;
use tensor;
use wasmi::*;
use yul_to_ir;

fn main() {
let matches = clap_app!(ir_cli =>
Expand All @@ -36,6 +38,12 @@ fn main() {
(@arg INPUT: +required +multiple "Sets the input textual ir file to build")
(@arg VERBOSE: -v --verbose "Print test information verbosely")
)
(@subcommand yul2ir =>
(@arg INPUT: +required +takes_value "Sets the input textual ir file to build")
)
(@subcommand sol2tensor =>
(@arg INPUT: +required +takes_value "Sets the input textual ir file to build")
)
).get_matches();

if let Some(matches) = matches.subcommand_matches("run") {
Expand Down Expand Up @@ -171,6 +179,61 @@ fn main() {
}
}
}
} else if let Some(matches) = matches.subcommand_matches("yul2ir") {
if let Some(input) = matches.value_of("INPUT") {
let path = std::path::Path::new(&input);
if path.is_file() {
let mut new_file_path = String::from(input);
new_file_path.truncate(new_file_path.len() - "yul".len());
new_file_path.push_str("ir");
let src = match std::fs::read_to_string(&path) {
Ok(src) => src,
Err(_) => {
println!(
"{}",
format!(
"Failed to load source file, can't find {}",
path.to_str().unwrap()
)
);
panic!();
}
};
yul_to_ir::yul2ir(&src, Some(&new_file_path));
} else if path.is_dir() {
let entries = fs::read_dir(input).expect("");
for entry in entries {
if let Ok(entry) = entry {
let file_path = entry.path();
if let Some(extension) = file_path.extension() {
if extension == "yul" {
let mut new_file_path = file_path.to_str().unwrap().to_string();
new_file_path.truncate(new_file_path.len() - "yul".len());
new_file_path.push_str("ir");
let src = match std::fs::read_to_string(&file_path) {
Ok(src) => src,
Err(_) => {
println!(
"{}",
format!(
"Failed to load source file, can't find {}",
file_path.to_str().unwrap()
)
);
panic!();
}
};
yul_to_ir::yul2ir(&src, Some(&new_file_path));
}
}
}
}
}
}
} else if let Some(matches) = matches.subcommand_matches("sol2tensor") {
if let Some(input) = matches.value_of("INPUT") {
tensor::sol2tensor::sol_to_tensor(input, true);
}
} else {
println!("{}", matches.usage());
}
Expand Down
104 changes: 104 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"name": "DAppCons",
"version": "1.0.0",
"description": "DApp Consistency detector",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wuzhy1ng/DAppCons.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/wuzhy1ng/DAppCons/issues"
},
"homepage": "https://github.com/wuzhy1ng/DAppCons#readme",
"dependencies": {
"solc-typed-ast": "^17.0.0",
"solcv0.4.1": "npm:[email protected]",
"solcv0.4.10": "npm:[email protected]",
"solcv0.4.11": "npm:[email protected]",
"solcv0.4.13": "npm:[email protected]",
"solcv0.4.14": "npm:[email protected]",
"solcv0.4.15": "npm:[email protected]",
"solcv0.4.16": "npm:[email protected]",
"solcv0.4.17": "npm:[email protected]",
"solcv0.4.18": "npm:[email protected]",
"solcv0.4.19": "npm:[email protected]",
"solcv0.4.2": "npm:[email protected]",
"solcv0.4.20": "npm:[email protected]",
"solcv0.4.21": "npm:[email protected]",
"solcv0.4.22": "npm:[email protected]",
"solcv0.4.23": "npm:[email protected]",
"solcv0.4.24": "npm:[email protected]",
"solcv0.4.25": "npm:[email protected]",
"solcv0.4.26": "npm:[email protected]",
"solcv0.4.5": "npm:[email protected]",
"solcv0.4.6": "npm:[email protected]",
"solcv0.4.7": "npm:[email protected]",
"solcv0.4.8": "npm:[email protected]",
"solcv0.4.9": "npm:[email protected]",
"solcv0.5.0": "npm:[email protected]",
"solcv0.5.1": "npm:[email protected]",
"solcv0.5.10": "npm:[email protected]",
"solcv0.5.11": "npm:[email protected]",
"solcv0.5.12": "npm:[email protected]",
"solcv0.5.13": "npm:[email protected]",
"solcv0.5.14": "npm:[email protected]",
"solcv0.5.15": "npm:[email protected]",
"solcv0.5.16": "npm:[email protected]",
"solcv0.5.17": "npm:[email protected]",
"solcv0.5.2": "npm:[email protected]",
"solcv0.5.3": "npm:[email protected]",
"solcv0.5.4": "npm:[email protected]",
"solcv0.5.5": "npm:[email protected]",
"solcv0.5.6": "npm:[email protected]",
"solcv0.5.7": "npm:[email protected]",
"solcv0.5.8": "npm:[email protected]",
"solcv0.5.9": "npm:[email protected]",
"solcv0.6.0": "npm:[email protected]",
"solcv0.6.1": "npm:[email protected]",
"solcv0.6.10": "npm:[email protected]",
"solcv0.6.11": "npm:[email protected]",
"solcv0.6.12": "npm:[email protected]",
"solcv0.6.2": "npm:[email protected]",
"solcv0.6.3": "npm:[email protected]",
"solcv0.6.4": "npm:[email protected]",
"solcv0.6.5": "npm:[email protected]",
"solcv0.6.6": "npm:[email protected]",
"solcv0.6.7": "npm:[email protected]",
"solcv0.6.8": "npm:[email protected]",
"solcv0.6.9": "npm:[email protected]",
"solcv0.7.0": "npm:[email protected]",
"solcv0.7.1": "npm:[email protected]",
"solcv0.7.2": "npm:[email protected]",
"solcv0.7.3": "npm:[email protected]",
"solcv0.7.4": "npm:[email protected]",
"solcv0.7.5": "npm:[email protected]",
"solcv0.7.6": "npm:[email protected]",
"solcv0.8.0": "npm:[email protected]",
"solcv0.8.1": "npm:[email protected]",
"solcv0.8.10": "npm:[email protected]",
"solcv0.8.11": "npm:[email protected]",
"solcv0.8.12": "npm:[email protected]",
"solcv0.8.13": "npm:[email protected]",
"solcv0.8.14": "npm:[email protected]",
"solcv0.8.15": "npm:[email protected]",
"solcv0.8.16": "npm:[email protected]",
"solcv0.8.17": "npm:[email protected]",
"solcv0.8.18": "npm:[email protected]",
"solcv0.8.19": "npm:[email protected]",
"solcv0.8.20": "npm:[email protected]",
"solcv0.8.2": "npm:[email protected]",
"solcv0.8.3": "npm:[email protected]",
"solcv0.8.4": "npm:[email protected]",
"solcv0.8.5": "npm:[email protected]",
"solcv0.8.6": "npm:[email protected]",
"solcv0.8.7": "npm:[email protected]",
"solcv0.8.8": "npm:[email protected]",
"solcv0.8.9": "npm:[email protected]"
}
}
13 changes: 13 additions & 0 deletions tensor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "tensor"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
smart_ir = { path = "../smart_ir" }
yul_to_ir = { path = "../yul_to_ir" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
regex = "1.10.2"
1 change: 1 addition & 0 deletions tensor/data.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tensor/data_inconsistent.json

Large diffs are not rendered by default.

Loading

0 comments on commit 9b4946d

Please sign in to comment.