Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring and EVMLiSA as a Library #44

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
97be245
Refactoring
merendamattia Feb 26, 2025
6b5b641
Refactored the analysis of a set of contracts
merendamattia Feb 27, 2025
b7999ac
Refactoring: integrated json, basic blocks, statistics, benchmark
merendamattia Feb 27, 2025
6ebeeaf
Refactoring: results saved to file
merendamattia Feb 27, 2025
2cfbf01
Refactoring: created .dot file manager
merendamattia Feb 27, 2025
aa39f84
Added function selectors in cfg basic blocks and fixed colors
merendamattia Feb 28, 2025
e798fcf
Added legend to .dot file
merendamattia Feb 28, 2025
1dc7fff
Refactoring: removed old methods, updated readme
merendamattia Feb 28, 2025
e2e99b0
Added new example
merendamattia Feb 28, 2025
42cf22e
Merge from master branch
merendamattia Feb 28, 2025
3cf4203
Apply spotless
merendamattia Feb 28, 2025
e604ca3
Added output directory path option
merendamattia Feb 28, 2025
507a5dc
Refactored ground truth test
merendamattia Feb 28, 2025
7fcbefa
Added ground truth data for test
merendamattia Feb 28, 2025
1963b84
Minor changes
merendamattia Feb 28, 2025
34f9f4a
Added javadoc
merendamattia Feb 28, 2025
21b0c4a
Fixed bug in the computation of functions entry points
merendamattia Feb 28, 2025
aa43ece
Refactoring and added javadoc
merendamattia Mar 1, 2025
52c28d5
Added javadoc
merendamattia Mar 1, 2025
9c76803
Removed LiSA logs printing during analysis
merendamattia Mar 1, 2025
bf477f1
Fixed colors in the cfg dump
merendamattia Mar 1, 2025
53432ed
Removed debug prints in tests, renamed extension ABI to .abi
merendamattia Mar 2, 2025
c96e7c4
Updated readme
merendamattia Mar 2, 2025
6fe7436
Apply spotless
merendamattia Mar 2, 2025
ae76268
Removed comments
merendamattia Mar 2, 2025
6a38174
Added test mode in analysis
merendamattia Mar 3, 2025
ee16bb9
Optimized the creation of contracts in buildContractsFromFile(), intr…
merendamattia Mar 3, 2025
6261ad1
Fixed basic blocks generation, fixed bug in edges' color
merendamattia Mar 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
# Ignore output directories that contain generated results
evm-outputs/
test-ground-truth-stats/
evm-testcases/ground-truth/test-ground-truth-results/logs.txt
evm-testcases/ground-truth/test-ground-truth-results/statistics.csv
evm-testcases/ground-truth/test/*

# Ignore 50-ground-truth file
evm-testcases/ground-truth/50-ground-truth/**/*.html
evm-testcases/ground-truth/50-ground-truth/**/*.opcode
evm-testcases/ground-truth/50-ground-truth/**/*.json
evm-testcases/ground-truth/50-ground-truth/**/*.dot
evm-testcases/ground-truth/50-ground-truth/**/*.js


# Ignore benchmark file
scripts/python/benchmark-checkers/**/bytecode/**
scripts/python/benchmark-checkers/**/abi/**
Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,17 @@ java -jar build/libs/evm-lisa-all.jar [options]
```
Options:
-a,--address <arg> Address of an Ethereum smart contract.
-b,--benchmark <arg> Filepath of the benchmark.
--basic-blocks Generate CFG with basic blocks.
--abi-path <arg> Filepath of the abi file.
-b,--bytecode <arg> Bytecode to be analyzed (e.g., 0x6080...).
--benchmark <arg> Filepath of the benchmark.
--bytecode-path <arg> Filepath of the bytecode file.
-c,--cores <arg> Number of cores used in benchmark.
--checker-reentrancy Enable re-entrancy checker.
--checker-all Enable all security checkers.
--checker-reentrancy Enable reentrancy checker.
--checker-timestampdependency Enable timestamp-dependency checker.
--checker-txorigin Enable tx-origin checker.
--dot Export a dot-notation file.
--download-bytecode Download the bytecode.
--dump-report Dump analysis report.
--dump-stats Dump statistics.
-f,--filepath-bytecode <arg> Filepath of the bytecode file.
--html Export a graphic HTML report.
--link-unsound-jumps-to-all-jumpdest Link all the unsound jumps to all jumpdest.
-o,--output <arg> Output directory path.
--serialize-inputs Serialize inputs.
--output-directory-path <arg> Filepath of the output directory.
--stack-set-size <arg> Dimension of stack-set (default: 8).
--stack-size <arg> Dimension of stack (default: 32).
--use-live-storage Use the live storage in SLOAD.
Expand Down Expand Up @@ -147,6 +143,24 @@ valid jump destination as the top element;

---

## EVMLiSA as a library
EVMLiSA can be used as a Java library to analyze Ethereum smart contracts.
```java
// Single case (address)
EVMLiSA.analyzeContract(new SmartContract("0x123456..."));

// Single case (bytecode as a path)
EVMLiSA.analyzeContract(new SmartContract(Path.of("bytecode", "code.bytecode")));

// Single case (bytecode as a string)
EVMLiSA.analyzeContract(new SmartContract().setBytecode("0x6080..."));

// Multiple contracts
EVMLiSA.analyzeSetOfContracts(Path.of("list-of-contracts.txt"));
```

---

## Contributors
<a href="https://github.com/lisa-analyzer/evm-lisa/graphs/contributors">
<img src="https://contrib.rocks/image?repo=lisa-analyzer/evm-lisa" />
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies {
implementation 'io.github.cdimascio:dotenv-java:3.0.0'

implementation 'org.json:json:20210307'

implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
[
{
"inputs": [{
"name": "aEdZTTu",
"internalType": "uint256",
"type": "uint256"
}],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"indexed": true,
"name": "owner",
"internalType": "address",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"internalType": "address",
"type": "address"
},
{
"indexed": false,
"name": "value",
"internalType": "uint256",
"type": "uint256"
}
],
"name": "Approval",
"anonymous": false,
"type": "event"
},
{
"inputs": [
{
"indexed": true,
"name": "previousOwner",
"internalType": "address",
"type": "address"
},
{
"indexed": true,
"name": "newOwner",
"internalType": "address",
"type": "address"
}
],
"name": "OwnershipTransferred",
"anonymous": false,
"type": "event"
},
{
"inputs": [
{
"indexed": true,
"name": "from",
"internalType": "address",
"type": "address"
},
{
"indexed": true,
"name": "to",
"internalType": "address",
"type": "address"
},
{
"indexed": false,
"name": "value",
"internalType": "uint256",
"type": "uint256"
}
],
"name": "Transfer",
"anonymous": false,
"type": "event"
},
{
"outputs": [{
"name": "",
"internalType": "uint256",
"type": "uint256"
}],
"inputs": [
{
"name": "owner",
"internalType": "address",
"type": "address"
},
{
"name": "sender",
"internalType": "address",
"type": "address"
}
],
"name": "allowance",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "bool",
"type": "bool"
}],
"inputs": [
{
"name": "sender",
"internalType": "address",
"type": "address"
},
{
"name": "amount",
"internalType": "uint256",
"type": "uint256"
}
],
"name": "approve",
"stateMutability": "nonpayable",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "uint256",
"type": "uint256"
}],
"inputs": [{
"name": "account",
"internalType": "address",
"type": "address"
}],
"name": "balanceOf",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "uint8",
"type": "uint8"
}],
"inputs": [],
"name": "decimals",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "string",
"type": "string"
}],
"inputs": [],
"name": "name",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "address",
"type": "address"
}],
"inputs": [],
"name": "owner",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [],
"inputs": [],
"name": "renounceOwnership",
"stateMutability": "nonpayable",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "string",
"type": "string"
}],
"inputs": [],
"name": "symbol",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "uint256",
"type": "uint256"
}],
"inputs": [],
"name": "totalSupply",
"stateMutability": "view",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "bool",
"type": "bool"
}],
"inputs": [
{
"name": "to",
"internalType": "address",
"type": "address"
},
{
"name": "amount",
"internalType": "uint256",
"type": "uint256"
}
],
"name": "transfer",
"stateMutability": "nonpayable",
"type": "function"
},
{
"outputs": [{
"name": "",
"internalType": "bool",
"type": "bool"
}],
"inputs": [
{
"name": "from",
"internalType": "address",
"type": "address"
},
{
"name": "to",
"internalType": "address",
"type": "address"
},
{
"name": "amount",
"internalType": "uint256",
"type": "uint256"
}
],
"name": "transferFrom",
"stateMutability": "nonpayable",
"type": "function"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x608060405234801561000f575f80fd5b50600436106100a6575f3560e01c806370a082311161006e57806370a082311461011f578063715018a6146101475780638da5cb5b1461015157806395d89b411461016b578063a9059cbb14610173578063dd62ed3e14610186575f80fd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f80fd5b6100b26101be565b6040516100bf91906107d8565b60405180910390f35b6100db6100d636600461083e565b61024e565b60405190151581526020016100bf565b6001545b6040519081526020016100bf565b6100db61010b366004610866565b610267565b604051601281526020016100bf565b6100ef61012d36600461089f565b6001600160a01b03165f9081526005602052604090205490565b61014f61030b565b005b5f546040516001600160a01b0390911681526020016100bf565b6100b26103ac565b6100db61018136600461083e565b6103bb565b6100ef6101943660046108b8565b6001600160a01b039182165f90815260046020908152604080832093909416825291909152205490565b6060600280546101cd906108e9565b80601f01602080910402602001604051908101604052809291908181526020018280546101f9906108e9565b80156102445780601f1061021b57610100808354040283529160200191610244565b820191905f5260205f20905b81548152906001019060200180831161022757829003601f168201915b5050505050905090565b5f3361025b8185856103c8565b60019150505b92915050565b6001600160a01b0383165f9081526004602090815260408083203380855292528220545f1981146102f457838110156102e75760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064015b60405180910390fd5b6102f486838684036103c8565b6102ff8686866104eb565b50600195945050505050565b5f546001600160a01b031633146103645760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016102de565b5f80546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a35f80546001600160a01b0319169055565b6060600380546101cd906108e9565b5f3361025b8185856104eb565b6001600160a01b03831661042a5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016102de565b6001600160a01b03821661048b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016102de565b6001600160a01b038381165f8181526004602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b0383161580159061050b57506001600160a01b03821615155b6105575760405162461bcd60e51b815260206004820181905260248201527f45524332303a207472616e7366657220746865207a65726f206164647265737360448201526064016102de565b6006546001600160a01b038481165f90815260056020526040812054909261058392169081908761066e565b9050818110156105d55760405162461bcd60e51b815260206004820152601a60248201527f45524332303a20616d6f756e74206f7665722062616c616e636500000000000060448201526064016102de565b6105df818361069d565b6001600160a01b038086165f90815260056020526040808220939093559085168152205461060d90836106f9565b6001600160a01b038085165f8181526005602052604090819020939093559151908616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906106609086815260200190565b60405180910390a350505050565b5f600183111561068a5761068384848461075e565b9050610695565b61068385848461075e565b949350505050565b5f828211156106ee5760405162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f77000060448201526064016102de565b5f6106958385610935565b5f806107058385610948565b9050838110156107575760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f77000000000060448201526064016102de565b9392505050565b604051635f94f14f60e01b81525f60048201819052602482018490526001600160a01b038381166044840152909190851690635f94f14f90606401602060405180830381865afa1580156107b4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610695919061095b565b5f6020808352835180828501525f5b81811015610803578581018301518582016040015282016107e7565b505f604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610839575f80fd5b919050565b5f806040838503121561084f575f80fd5b61085883610823565b946020939093013593505050565b5f805f60608486031215610878575f80fd5b61088184610823565b925061088f60208501610823565b9150604084013590509250925092565b5f602082840312156108af575f80fd5b61075782610823565b5f80604083850312156108c9575f80fd5b6108d283610823565b91506108e060208401610823565b90509250929050565b600181811c908216806108fd57607f821691505b60208210810361091b57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561026157610261610921565b8082018082111561026157610261610921565b5f6020828403121561096b575f80fd5b505191905056fea2646970667358221220477643666a3101d5ea8b1e62f534961c17ff8130cc77d213c8eaeeef1c5de9d364736f6c63430008140033
Loading
Loading