Skip to content

Commit

Permalink
add ethersolve provider to flow benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Feb 20, 2025
1 parent d33883f commit 23d7874
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ dist/

target/
.aider*
.gradle
2 changes: 1 addition & 1 deletion benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROVIDERS_SELECTORS ?= simple whatsabi evm-hound-rs sevm evmole-rs evmole-js evm
PROVIDERS_ARGUMENTS ?= simple evmole-rs evmole-js evmole-py
PROVIDERS_MUTABILITY ?= simple whatsabi sevm evmole-rs evmole-js evmole-py
PROVIDERS_STORAGE ?= evmole-rs smlxl
PROVIDERS_FLOW ?= evmole-rs evm-cfg sevm evm-cfg-builder heimdall-rs
PROVIDERS_FLOW ?= evmole-rs evm-cfg ethersolve sevm evm-cfg-builder heimdall-rs

DATASETS ?= largest1k random50k vyper
DATASETS_STORAGE ?= storage3k
Expand Down
2 changes: 1 addition & 1 deletion benchmark/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def show_arguments_or_mutability(providers: list[str], all_results: list, show_e
},
'flow': {
'datasets': ['largest1k', 'random50k', 'vyper'],
'providers': ['evmole-rs', 'evm-cfg', 'sevm', 'evm-cfg-builder', 'heimdall-rs']
'providers': ['evmole-rs', 'evm-cfg', 'ethersolve', 'sevm', 'evm-cfg-builder', 'heimdall-rs']
}
}

Expand Down
7 changes: 7 additions & 0 deletions benchmark/providers/ethersolve/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker.io/gradle:jdk23

WORKDIR /app
COPY ./build.gradle /app/
COPY ./src/main/java/HelloEtherSolve.java /app/src/main/java/
RUN gradle build
ENTRYPOINT ["java", "-jar", "/app/build/libs/app.jar"]
45 changes: 45 additions & 0 deletions benchmark/providers/ethersolve/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
id 'java'
id 'application'
}

repositories {
mavenCentral()
}

def etherSolveJar = layout.buildDirectory.file('libs/EtherSolve.jar')

tasks.register('downloadEtherSolve') {
outputs.file etherSolveJar
doLast {
def f = etherSolveJar.get().asFile
f.parentFile.mkdirs()
new URL('https://github.com/SeUniVr/EtherSolve/raw/main/artifact/EtherSolve.jar')
.withInputStream { inputStream ->
f.withOutputStream { it << inputStream }
}
}
}

dependencies {
implementation files(etherSolveJar)
implementation 'com.google.code.gson:gson:2.10.1'
}

tasks.named('compileJava') {
dependsOn 'downloadEtherSolve'
}

application {
mainClass = 'HelloEtherSolve'
}

jar {
manifest {
attributes 'Main-Class': application.mainClass
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
85 changes: 85 additions & 0 deletions benchmark/providers/ethersolve/src/main/java/HelloEtherSolve.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import parseTree.Contract;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;

public class HelloEtherSolve {
private static final long PROCESS_TIMEOUT_SECONDS = 10;
private final Gson gson = new Gson();

private List<Long[]> processContract(String bytecode) {
try {
return new Contract("Sample", bytecode, true)
.getRuntimeCfg()
.getSuccessorsMap()
.entrySet()
.stream()
.flatMap(entry -> entry.getValue().stream()
.map(successor -> new Long[]{entry.getKey(), successor}))
.collect(Collectors.toList());
} catch (Exception e) {
e.printStackTrace();
return List.of();
}
}

private List<Long[]> executeWithTimeout(String bytecode) {
ExecutorService executor = Executors.newSingleThreadExecutor();
try {
Future<List<Long[]>> future = executor.submit(() -> processContract(bytecode));
return future.get(PROCESS_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (TimeoutException e) {
return List.of();
} catch (Exception e) {
e.printStackTrace();
return List.of();
} finally {
executor.shutdownNow();
}
}

private void processFile(Path file, Map<String, Object[]> results) throws Exception {
if (!Files.isRegularFile(file)) return;

String content = Files.readString(file);
JsonObject json = gson.fromJson(content, JsonObject.class);
String bytecode = json.get("code").getAsString().substring(2);

long startTime = System.nanoTime();
List<Long[]> processResults = executeWithTimeout(bytecode);
long timeMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);

results.put(file.getFileName().toString(), new Object[]{timeMs, processResults});
}

public void execute(String[] args) throws Exception {
if (args.length < 3 || !"flow".equals(args[0])) {
System.out.println("Usage: self flow INPUT_DIR OUTPUT_FILE");
System.exit(1);
}

Map<String, Object[]> results = new HashMap<>();
Path inputDir = Paths.get(args[1]);
Path outputFile = Paths.get(args[2]);

try (DirectoryStream<Path> stream = Files.newDirectoryStream(inputDir)) {
for (Path file : stream) {
processFile(file, results);
}
}

Files.writeString(outputFile, gson.toJson(results));
}

public static void main(String[] args) {
try {
new HelloEtherSolve().execute(args);
} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit 23d7874

Please sign in to comment.