From 6c3723ff95aefb550e5ca38449594437f7aeed6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 29 Feb 2024 16:27:39 +0100 Subject: [PATCH] Drop support for Java bindings There are some EVM features not implemented for Java (e.g. transient storage). The bindings probably never worked and there is no interest in using or maintaining these. --- CMakeLists.txt | 6 - bindings/java/.gitignore | 23 - bindings/java/CMakeLists.txt | 35 -- bindings/java/Makefile | 54 -- bindings/java/build.gradle | 42 -- bindings/java/c/evmc-vm.c | 147 ----- bindings/java/c/host.c | 505 ------------------ bindings/java/c/host.h | 31 -- bindings/java/java/build.gradle | 7 - .../ethereum/evmc/EvmcLoaderException.java | 15 - .../main/java/org/ethereum/evmc/EvmcVm.java | 193 ------- .../src/main/java/org/ethereum/evmc/Host.java | 96 ---- .../java/org/ethereum/evmc/HostContext.java | 175 ------ .../test/java/org/ethereum/evmc/EvmcTest.java | 266 --------- .../org/ethereum/evmc/TestHostContext.java | 76 --- .../java/org/ethereum/evmc/TestMessage.java | 81 --- bindings/java/settings.gradle | 2 - bindings/java/wrapper.gradle | 4 - circle.yml | 23 - 19 files changed, 1781 deletions(-) delete mode 100644 bindings/java/.gitignore delete mode 100644 bindings/java/CMakeLists.txt delete mode 100644 bindings/java/Makefile delete mode 100644 bindings/java/build.gradle delete mode 100644 bindings/java/c/evmc-vm.c delete mode 100644 bindings/java/c/host.c delete mode 100644 bindings/java/c/host.h delete mode 100644 bindings/java/java/build.gradle delete mode 100644 bindings/java/java/src/main/java/org/ethereum/evmc/EvmcLoaderException.java delete mode 100644 bindings/java/java/src/main/java/org/ethereum/evmc/EvmcVm.java delete mode 100644 bindings/java/java/src/main/java/org/ethereum/evmc/Host.java delete mode 100644 bindings/java/java/src/main/java/org/ethereum/evmc/HostContext.java delete mode 100644 bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java delete mode 100644 bindings/java/java/src/test/java/org/ethereum/evmc/TestHostContext.java delete mode 100644 bindings/java/java/src/test/java/org/ethereum/evmc/TestMessage.java delete mode 100644 bindings/java/settings.gradle delete mode 100644 bindings/java/wrapper.gradle diff --git a/CMakeLists.txt b/CMakeLists.txt index a1b0fdd62..c15e1416c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,6 @@ include(CablePackage) include(CMakeDependentOption) include(CMakePackageConfigHelpers) -option(EVMC_JAVA "Enable building Java Native Interface (JNI) bindings" OFF) - option(EVMC_INSTALL "Enable EVMC installation (e.g. make install)" ON) option(EVMC_TESTING "Build everything (libraries, tools, examples, internal tests)" OFF) @@ -78,10 +76,6 @@ set(EVMC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) add_subdirectory(lib) -if(EVMC_JAVA) - add_subdirectory(bindings/java) -endif() - if(EVMC_TOOLS) add_subdirectory(tools) endif() diff --git a/bindings/java/.gitignore b/bindings/java/.gitignore deleted file mode 100644 index 926d4822c..000000000 --- a/bindings/java/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -.idea/ -.vscode -java/build/* -java/out/* -c/build/* -*.o -*.dylib -.DS_Store -.gradle -build -.classpath -.project -.settings/ -java/.classpath -java/.project -java/.settings/ -java/bin/ -java/hs_err_pid* -gradle/ -gradlew -gradlew.bat -c/evmc-vm.h -*.class diff --git a/bindings/java/CMakeLists.txt b/bindings/java/CMakeLists.txt deleted file mode 100644 index d592e37cc..000000000 --- a/bindings/java/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# EVMC: Ethereum Client-VM Connector API. -# Copyright 2020 The EVMC Authors. -# Licensed under the Apache License, Version 2.0. - -include(UseJava) - -find_package(Java REQUIRED COMPONENTS Development) -find_package(JNI REQUIRED) - -add_jar(evmc-jar - OUTPUT_NAME evmc-java - VERSION ${PROJECT_VERSION} - SOURCES - java/src/main/java/org/ethereum/evmc/EvmcLoaderException.java - java/src/main/java/org/ethereum/evmc/EvmcVm.java - java/src/main/java/org/ethereum/evmc/Host.java - java/src/main/java/org/ethereum/evmc/HostContext.java - GENERATE_NATIVE_HEADERS evmc-java-native-headers) - -add_library(evmc-java SHARED) -target_sources(evmc-java PRIVATE - c/evmc-vm.c - c/host.c - c/host.h) -target_include_directories(evmc-java PRIVATE ${JNI_INCLUDE_DIRS}) -target_link_libraries(evmc-java PRIVATE evmc-java-native-headers evmc::evmc evmc::loader ${JNI_LIBRARIES}) - -if(EVMC_INSTALL) - install(TARGETS evmc-java EXPORT evmcTargets - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - - install_jar(evmc-jar DESTINATION ${CMAKE_INSTALL_DATADIR}/java) -endif() \ No newline at end of file diff --git a/bindings/java/Makefile b/bindings/java/Makefile deleted file mode 100644 index 6e7dcca8f..000000000 --- a/bindings/java/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -# EVMC: Ethereum Client-VM Connector API. -# Copyright 2019 The EVMC Authors. -# Licensed under the Apache License, Version 2.0. - -JAVA_HOME:=$(shell java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | sed 's/\s*java.home = //' | sed 's/\/jre//') -EXTENSION:="so" -ifeq ($(OS),Windows_NT) - EXTENSION:=dll -else - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - EXTENSION:=so - endif - ifeq ($(UNAME_S),Darwin) - EXTENSION:=dylib - endif -endif - -SOURCE_DIR = $(realpath $(CURDIR)/../..) -OUT_DIR = $(CURDIR)/c/build -BUILD_DIR = $(OUT_DIR)/_cmake_build - -lint: gradlew - ./gradlew --no-daemon clean spotlessCheck - -build: gradlew java/src/test/resources/libexample-vm.$(EXTENSION) java/src/main/resources/libevmc-java.$(EXTENSION) - mkdir -p ./java/build - ./gradlew --no-daemon clean spotlessApply build - -test: build - ./gradlew --no-daemon test - -gradlew: - gradle --no-daemon setup - -$(OUT_DIR)/lib/libexample-vm.$(EXTENSION): $(OUT_DIR)/lib/libevmc-java.$(EXTENSION) - -$(OUT_DIR)/lib/libevmc-java.$(EXTENSION): - mkdir -p $(BUILD_DIR) - (cd $(BUILD_DIR) && cmake $(SOURCE_DIR) -DCMAKE_INSTALL_PREFIX=$(OUT_DIR) -DEVMC_JAVA=ON -DJAVA_HOME=$(JAVA_HOME) -DEVMC_EXAMPLES=ON) - cmake --build $(OUT_DIR)/_cmake_build --target install - -java/src/main/resources/libevmc-java.$(EXTENSION): $(OUT_DIR)/lib/libevmc-java.$(EXTENSION) - mkdir -p java/src/main/resources - cp $(OUT_DIR)/lib/libevmc-java.$(EXTENSION) java/src/main/resources/libevmc-java.$(EXTENSION) - -java/src/test/resources/libexample-vm.$(EXTENSION): $(OUT_DIR)/lib/libexample-vm.$(EXTENSION) - mkdir -p java/src/test/resources - cp $(OUT_DIR)/lib/libexample-vm.$(EXTENSION) java/src/test/resources/libexample-vm.$(EXTENSION) - -clean: - rm -rf $(OUT_DIR) - rm -rf build - rm -rf ./java/build/ diff --git a/bindings/java/build.gradle b/bindings/java/build.gradle deleted file mode 100644 index a4b1218ee..000000000 --- a/bindings/java/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. - -plugins { - id 'com.diffplug.spotless' version '6.9.1' -} -apply from: "${rootDir}/wrapper.gradle" -allprojects { - apply plugin: 'java-library' - repositories { - google() - mavenCentral() - } - sourceCompatibility = '11' - apply plugin: 'com.diffplug.spotless' - spotless { - java { - // This path needs to be relative to each project - target fileTree('.') { - include '**/*.java' - exclude '**/.gradle/**' - } - importOrder 'org.ethereum', 'java', '' - trimTrailingWhitespace() - endWithNewline() - googleJavaFormat('1.7') - } - } -} - -subprojects { - tasks.withType(Test) { - testLogging.showStandardStreams = true - // If GRADLE_MAX_TEST_FORKS is not set, use half the available processors - maxParallelForks = (System.getenv('GRADLE_MAX_TEST_FORKS') ?: (Runtime.runtime.availableProcessors().intdiv(2) ?: 1)).toInteger() - useJUnitPlatform() - reports { - junitXml.required = true - } - } -} diff --git a/bindings/java/c/evmc-vm.c b/bindings/java/c/evmc-vm.c deleted file mode 100644 index 1d5915d5a..000000000 --- a/bindings/java/c/evmc-vm.c +++ /dev/null @@ -1,147 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. - -#include "host.h" -#include "org_ethereum_evmc_EvmcVm.h" -#include -#include - -#include -#include -#include - -JNIEXPORT jobject JNICALL Java_org_ethereum_evmc_EvmcVm_load_1and_1create(JNIEnv* jenv, - jclass jcls, - jstring jfilename) -{ - (void)jcls; - struct evmc_vm* evm = NULL; - jint rs = evmc_java_set_jvm(jenv); - (void)rs; - assert(rs == JNI_OK); - // load the EVM - const char* filename = (*jenv)->GetStringUTFChars(jenv, jfilename, NULL); - assert(filename != NULL); - enum evmc_loader_error_code loader_error = EVMC_LOADER_UNSPECIFIED_ERROR; - evm = evmc_load_and_create(filename, &loader_error); - (*jenv)->ReleaseStringUTFChars(jenv, jfilename, filename); - if (loader_error != EVMC_LOADER_SUCCESS) - { - const char* error_msg = evmc_last_error_msg(); - jclass exception_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/EvmcLoaderException"); - assert(exception_class != NULL); - (*jenv)->ThrowNew(jenv, exception_class, error_msg ? error_msg : "Loading EVMC VM failed"); - } - jobject jresult = (*jenv)->NewDirectByteBuffer(jenv, (void*)evm, sizeof(struct evmc_vm)); - assert(jresult != NULL); - return jresult; -} - -JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_abi_1version(JNIEnv* jenv, jclass jcls) -{ - (void)jenv; - (void)jcls; - return EVMC_ABI_VERSION; -} - -JNIEXPORT jstring JNICALL Java_org_ethereum_evmc_EvmcVm_name(JNIEnv* jenv, - jclass jcls, - jobject jevm) -{ - (void)jcls; - struct evmc_vm* evm = (struct evmc_vm*)(*jenv)->GetDirectBufferAddress(jenv, jevm); - assert(evm != NULL); - const char* evm_name = evmc_vm_name(evm); - return (*jenv)->NewStringUTF(jenv, evm_name); -} - -JNIEXPORT jstring JNICALL Java_org_ethereum_evmc_EvmcVm_version(JNIEnv* jenv, - jclass jcls, - jobject jevm) -{ - (void)jcls; - struct evmc_vm* evm = (struct evmc_vm*)(*jenv)->GetDirectBufferAddress(jenv, jevm); - assert(evm != NULL); - const char* evm_version = evmc_vm_version(evm); - return (*jenv)->NewStringUTF(jenv, evm_version); -} - -JNIEXPORT void JNICALL Java_org_ethereum_evmc_EvmcVm_destroy(JNIEnv* jenv, - jclass jcls, - jobject jevm) -{ - (void)jcls; - struct evmc_vm* evm = (struct evmc_vm*)(*jenv)->GetDirectBufferAddress(jenv, jevm); - assert(evm != NULL); - evmc_destroy(evm); -} - -static jobject AllocateDirect(JNIEnv* jenv, size_t capacity) -{ - const char java_class_name[] = "java/nio/ByteBuffer"; - const char java_method_name[] = "allocateDirect"; - const char java_method_signature[] = "(I)Ljava/nio/ByteBuffer;"; - - jclass jcls = (*jenv)->FindClass(jenv, java_class_name); - assert(jcls != NULL); - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, jcls, java_method_name, java_method_signature); - assert(method != NULL); - return (*jenv)->CallStaticObjectMethod(jenv, jcls, method, capacity); -} - -JNIEXPORT jobject JNICALL Java_org_ethereum_evmc_EvmcVm_execute(JNIEnv* jenv, - jclass jcls, - jobject jevm, - jobject jcontext, - jint jrev, - jobject jmsg, - jobject jcode) -{ - (void)jcls; - struct evmc_message* msg = (struct evmc_message*)(*jenv)->GetDirectBufferAddress(jenv, jmsg); - assert(msg != NULL); - size_t code_size; - const uint8_t* code = GetDirectBuffer(jenv, jcode, &code_size); - struct evmc_vm* evm = (struct evmc_vm*)(*jenv)->GetDirectBufferAddress(jenv, jevm); - assert(evm != NULL); - const struct evmc_host_interface* host = evmc_java_get_host_interface(); - jobject jresult = AllocateDirect(jenv, sizeof(struct evmc_result)); - assert(jresult != NULL); - struct evmc_result* result = - (struct evmc_result*)(*jenv)->GetDirectBufferAddress(jenv, jresult); - assert(result != NULL); - *result = evmc_execute(evm, host, (struct evmc_host_context*)jcontext, (enum evmc_revision)jrev, - msg, code, code_size); - return jresult; -} - -JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_get_1capabilities(JNIEnv* jenv, - jclass jcls, - jobject jevm) -{ - (void)jcls; - struct evmc_vm* evm = (struct evmc_vm*)(*jenv)->GetDirectBufferAddress(jenv, jevm); - assert(evm != NULL); - return (jint)evm->get_capabilities(evm); -} - -JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_set_1option(JNIEnv* jenv, - jclass jcls, - jobject jevm, - jstring jname, - jstring jval) -{ - (void)jcls; - struct evmc_vm* evm = (struct evmc_vm*)(*jenv)->GetDirectBufferAddress(jenv, jevm); - assert(evm != NULL); - const char* name = (*jenv)->GetStringUTFChars(jenv, jname, 0); - const char* value = (*jenv)->GetStringUTFChars(jenv, jval, 0); - assert(name != NULL); - assert(value != NULL); - enum evmc_set_option_result option_result = evmc_set_option(evm, name, value); - (*jenv)->ReleaseStringUTFChars(jenv, jname, name); - (*jenv)->ReleaseStringUTFChars(jenv, jval, value); - return (jint)option_result; -} diff --git a/bindings/java/c/host.c b/bindings/java/c/host.c deleted file mode 100644 index 71a847989..000000000 --- a/bindings/java/c/host.c +++ /dev/null @@ -1,505 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. - -#include -#include -#include - -#include "host.h" - -static JavaVM* jvm; - -int evmc_java_set_jvm(JNIEnv* jenv) -{ - return (*jenv)->GetJavaVM(jenv, &jvm); -} - -static JNIEnv* attach() -{ - JNIEnv* jenv; - jint rs = (*jvm)->AttachCurrentThread(jvm, (void**)&jenv, NULL); - (void)rs; - assert(rs == JNI_OK); - assert(jenv != NULL); - return jenv; -} - -// Why isn't this helper part of JNI? -static jbyteArray CopyDataToJava(JNIEnv* jenv, const void* ptr, size_t size) -{ - jbyteArray ret = (*jenv)->NewByteArray(jenv, (jsize)size); - assert(ret != NULL); - (*jenv)->SetByteArrayRegion(jenv, ret, 0, (jsize)size, (jbyte*)ptr); - return ret; -} - -static void CopyFromByteBuffer(JNIEnv* jenv, jobject src, void* dst, size_t size) -{ - size_t src_size; - const void* ptr = GetDirectBuffer(jenv, src, &src_size); - if (src_size != size) - { - jclass exception_class = (*jenv)->FindClass(jenv, "java/lang/IllegalArgumentException"); - assert(exception_class != NULL); - (*jenv)->ThrowNew(jenv, exception_class, "Unexpected ByteBuffer length."); - } - memcpy(dst, ptr, size); -} - -static bool account_exists_fn(struct evmc_host_context* context, const evmc_address* address) -{ - const char java_method_name[] = "account_exists"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B)Z"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - - // call java method - jboolean jresult = - (*jenv)->CallStaticBooleanMethod(jenv, host_class, method, (jobject)context, jaddress); - return jresult != JNI_FALSE; -} - -static evmc_bytes32 get_storage_fn(struct evmc_host_context* context, - const evmc_address* address, - const evmc_bytes32* key) -{ - const char java_method_name[] = "get_storage"; - const char java_method_signature[] = - "(Lorg/ethereum/evmc/HostContext;[B[B)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - jbyteArray jkey = CopyDataToJava(jenv, key, sizeof(struct evmc_bytes32)); - - // call java method - jobject jresult = - (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context, jaddress, jkey); - assert(jresult != NULL); - - evmc_bytes32 result; - CopyFromByteBuffer(jenv, jresult, &result, sizeof(evmc_bytes32)); - return result; -} - -static enum evmc_storage_status set_storage_fn(struct evmc_host_context* context, - const evmc_address* address, - const evmc_bytes32* key, - const evmc_bytes32* value) -{ - const char java_method_name[] = "set_storage"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B[B[B)I"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - jbyteArray jkey = CopyDataToJava(jenv, key, sizeof(struct evmc_bytes32)); - jbyteArray jval = CopyDataToJava(jenv, value, sizeof(struct evmc_bytes32)); - - // call java method - jint jresult = (*jenv)->CallStaticIntMethod(jenv, host_class, method, (jobject)context, - jaddress, jkey, jval); - return (enum evmc_storage_status)jresult; -} - -static evmc_uint256be get_balance_fn(struct evmc_host_context* context, const evmc_address* address) -{ - const char java_method_name[] = "get_balance"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - - // call java method - jobject jresult = - (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context, jaddress); - assert(jresult != NULL); - - evmc_uint256be result; - CopyFromByteBuffer(jenv, jresult, &result, sizeof(evmc_uint256be)); - - (*jenv)->ReleaseByteArrayElements(jenv, jaddress, (jbyte*)address, 0); - - return result; -} - -static size_t get_code_size_fn(struct evmc_host_context* context, const evmc_address* address) -{ - const char java_method_name[] = "get_code_size"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B)I"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - - // call java method - jint jresult = - (*jenv)->CallStaticIntMethod(jenv, host_class, method, (jobject)context, jaddress); - return (size_t)jresult; -} - -static evmc_bytes32 get_code_hash_fn(struct evmc_host_context* context, const evmc_address* address) -{ - const char java_method_name[] = "get_code_hash"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - - // call java method - jobject jresult = - (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context, jaddress); - assert(jresult != NULL); - - evmc_bytes32 result; - CopyFromByteBuffer(jenv, jresult, &result, sizeof(evmc_bytes32)); - - (*jenv)->ReleaseByteArrayElements(jenv, jaddress, (jbyte*)address, 0); - - return result; -} - -static inline size_t min(size_t a, size_t b) -{ - return (a > b) ? b : a; -} - -static size_t copy_code_fn(struct evmc_host_context* context, - const evmc_address* address, - size_t code_offset, - uint8_t* buffer_data, - size_t buffer_size) -{ - const char java_method_name[] = "copy_code"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - - // call java method - jobject jresult = - (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context, jaddress); - assert(jresult != NULL); - - // copy jresult back to buffer_data - size_t code_size; - uint8_t* code = GetDirectBuffer(jenv, jresult, &code_size); - - size_t length = 0; - if (code_offset < code_size) - { - length = min(buffer_size, code_size - code_offset); - if (length > 0) - memcpy(buffer_data, code + code_offset, length); - } - - (*jenv)->ReleaseByteArrayElements(jenv, jaddress, (jbyte*)address, 0); - - return length; -} - -static bool selfdestruct_fn(struct evmc_host_context* context, - const evmc_address* address, - const evmc_address* beneficiary) -{ - const char java_method_name[] = "selfdestruct"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B[B)Z"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - jbyteArray jbeneficiary = CopyDataToJava(jenv, beneficiary, sizeof(struct evmc_address)); - - // call java method - jboolean jresult = (*jenv)->CallStaticBooleanMethod(jenv, host_class, method, (jobject)context, - jaddress, jbeneficiary); - return jresult != JNI_FALSE; -} - -static struct evmc_result call_fn(struct evmc_host_context* context, const struct evmc_message* msg) -{ - const char java_method_name[] = "call"; - const char java_method_signature[] = - "(Lorg/ethereum/evmc/HostContext;Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jobject jmsg = (*jenv)->NewDirectByteBuffer(jenv, (void*)msg, sizeof(struct evmc_message)); - assert(jmsg != NULL); - - // call java method - jobject jresult = - (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context, jmsg); - assert(jresult != NULL); - - struct evmc_result result; - CopyFromByteBuffer(jenv, jresult, &result, sizeof(struct evmc_result)); - return result; -} - -static struct evmc_tx_context get_tx_context_fn(struct evmc_host_context* context) -{ - const char java_method_name[] = "get_tx_context"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // call java method - jobject jresult = (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context); - assert(jresult != NULL); - - struct evmc_tx_context result; - CopyFromByteBuffer(jenv, jresult, &result, sizeof(struct evmc_tx_context)); - return result; -} - -static evmc_bytes32 get_block_hash_fn(struct evmc_host_context* context, int64_t number) -{ - char java_method_name[] = "get_block_hash"; - char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;J)Ljava/nio/ByteBuffer;"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // call java method - jobject jresult = - (*jenv)->CallStaticObjectMethod(jenv, host_class, method, (jobject)context, (jlong)number); - assert(jresult != NULL); - - evmc_bytes32 result; - CopyFromByteBuffer(jenv, jresult, &result, sizeof(evmc_bytes32)); - return result; -} - -static void emit_log_fn(struct evmc_host_context* context, - const evmc_address* address, - const uint8_t* data, - size_t data_size, - const evmc_bytes32 topics[], - size_t topics_count) -{ - const char java_method_name[] = "emit_log"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B[BI[[BI)V"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - jbyteArray jdata = CopyDataToJava(jenv, data, data_size); - - jclass byte_type = (*jenv)->FindClass(jenv, "[B"); - jobjectArray jtopics = (*jenv)->NewObjectArray(jenv, (jsize)topics_count, byte_type, NULL); - assert(jtopics != NULL); - for (size_t i = 0; i < topics_count; i++) - { - jbyteArray jtopic = CopyDataToJava(jenv, topics[i].bytes, sizeof(struct evmc_bytes32)); - (*jenv)->SetObjectArrayElement(jenv, jtopics, (jsize)i, jtopic); - (*jenv)->DeleteLocalRef(jenv, jtopic); - } - - // call java method - (*jenv)->CallStaticIntMethod(jenv, host_class, method, (jobject)context, jaddress, jdata, - data_size, jtopics, topics_count); -} - -static enum evmc_access_status access_account_fn(struct evmc_host_context* context, - const evmc_address* address) -{ - const char java_method_name[] = "access_account"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B)I"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - - // call java method - jint jresult = - (*jenv)->CallStaticIntMethod(jenv, host_class, method, (jobject)context, jaddress); - assert(jresult == EVMC_ACCESS_COLD || jresult == EVMC_ACCESS_WARM); - return (enum evmc_access_status)jresult; -} - -static enum evmc_access_status access_storage_fn(struct evmc_host_context* context, - const evmc_address* address, - const evmc_bytes32* key) -{ - const char java_method_name[] = "access_storage"; - const char java_method_signature[] = "(Lorg/ethereum/evmc/HostContext;[B[B)I"; - - assert(context != NULL); - JNIEnv* jenv = attach(); - - // get java class - jclass host_class = (*jenv)->FindClass(jenv, "org/ethereum/evmc/Host"); - assert(host_class != NULL); - - // get java method - jmethodID method = - (*jenv)->GetStaticMethodID(jenv, host_class, java_method_name, java_method_signature); - assert(method != NULL); - - // set java method params - jbyteArray jaddress = CopyDataToJava(jenv, address, sizeof(struct evmc_address)); - jbyteArray jkey = CopyDataToJava(jenv, key, sizeof(struct evmc_bytes32)); - - // call java method - jint jresult = - (*jenv)->CallStaticIntMethod(jenv, host_class, method, (jobject)context, jaddress, jkey); - assert(jresult == EVMC_ACCESS_COLD || jresult == EVMC_ACCESS_WARM); - return (enum evmc_access_status)jresult; -} - -const struct evmc_host_interface* evmc_java_get_host_interface() -{ - static const struct evmc_host_interface host = { - account_exists_fn, get_storage_fn, set_storage_fn, get_balance_fn, get_code_size_fn, - get_code_hash_fn, copy_code_fn, selfdestruct_fn, call_fn, get_tx_context_fn, - get_block_hash_fn, emit_log_fn, access_account_fn, access_storage_fn, - }; - return &host; -} diff --git a/bindings/java/c/host.h b/bindings/java/c/host.h deleted file mode 100644 index 9812b23da..000000000 --- a/bindings/java/c/host.h +++ /dev/null @@ -1,31 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -#include "evmc/evmc.h" -#include -#include - -#ifndef _Included_org_ethereum_evmc_Host -#define _Included_org_ethereum_evmc_Host -#ifdef __cplusplus -extern "C" { -#endif - -int evmc_java_set_jvm(JNIEnv*); -const struct evmc_host_interface* evmc_java_get_host_interface(); - -static inline void* GetDirectBuffer(JNIEnv* jenv, jobject buf, size_t* size) -{ - void* ret = (uint8_t*)(*jenv)->GetDirectBufferAddress(jenv, buf); - assert(ret != NULL); - jlong buf_size = (*jenv)->GetDirectBufferCapacity(jenv, buf); - assert(buf_size != -1); - if (size) - *size = (size_t)buf_size; - return ret; -} - -#ifdef __cplusplus -} -#endif -#endif diff --git a/bindings/java/java/build.gradle b/bindings/java/java/build.gradle deleted file mode 100644 index 89fc23477..000000000 --- a/bindings/java/java/build.gradle +++ /dev/null @@ -1,7 +0,0 @@ -dependencies { - testImplementation 'org.apache.commons:commons-lang3:3.0' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.2' - - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2' -} diff --git a/bindings/java/java/src/main/java/org/ethereum/evmc/EvmcLoaderException.java b/bindings/java/java/src/main/java/org/ethereum/evmc/EvmcLoaderException.java deleted file mode 100644 index 1861e8a9f..000000000 --- a/bindings/java/java/src/main/java/org/ethereum/evmc/EvmcLoaderException.java +++ /dev/null @@ -1,15 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -/** Exception thrown when the EVMC binding or VM fails to load. */ -public class EvmcLoaderException extends Exception { - public EvmcLoaderException(String message) { - super(message); - } - - public EvmcLoaderException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/bindings/java/java/src/main/java/org/ethereum/evmc/EvmcVm.java b/bindings/java/java/src/main/java/org/ethereum/evmc/EvmcVm.java deleted file mode 100644 index c5de454b7..000000000 --- a/bindings/java/java/src/main/java/org/ethereum/evmc/EvmcVm.java +++ /dev/null @@ -1,193 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; - -/** - * The Java interface to the evm instance. - * - *

Defines the Java methods capable of accessing the evm implementation. - */ -public final class EvmcVm implements AutoCloseable { - private static final Throwable evmcLoadingError; - private ByteBuffer nativeVm; - - // Load the dynamic library containing the JNI bindings to EVMC. - static { - Throwable error = null; - - // First try loading from global path. - try { - System.loadLibrary("libevmc-java"); - } catch (UnsatisfiedLinkError globalLoadingError) { - String extension = null; - String os = System.getProperty("os.name").toLowerCase(); - if (os.contains("win")) { - extension = "dll"; - } else if (os.contains("nix") || os.contains("nux") || os.contains("aix")) { - extension = "so"; - } else if (os.contains("mac") || os.contains("darwin")) { - extension = "dylib"; - } else { - // Give up, because we are unsure what system we are running on. - error = globalLoadingError; - } - - // Try loading the binding from the package. - if (extension != null) { - try { - Path evmcLib = Files.createTempFile("libevmc-java", extension); - Files.copy( - EvmcVm.class.getResourceAsStream("/libevmc-java." + extension), - evmcLib, - StandardCopyOption.REPLACE_EXISTING); - evmcLib.toFile().deleteOnExit(); - // We are somewhat certain about the file, try loading it. - try { - System.load(evmcLib.toAbsolutePath().toString()); - } catch (UnsatisfiedLinkError packageLoadingError) { - error = packageLoadingError; - } - } catch (IOException packageCreationError) { - error = packageCreationError; - } - } - } - evmcLoadingError = error; - } - - /** - * Returns true if the native library was loaded successfully and EVMC capabilities are available. - * - * @return true if the library is available - */ - public static boolean isAvailable() { - return evmcLoadingError == null; - } - - /** - * This method loads the specified evm shared library and loads/initializes the jni bindings. - * - * @param filename /path/filename of the evm shared object - * @throws org.ethereum.evmc.EvmcLoaderException - */ - public static EvmcVm create(String filename) throws EvmcLoaderException { - if (!isAvailable()) { - throw new EvmcLoaderException("EVMC JNI binding library failed to load", evmcLoadingError); - } - return new EvmcVm(filename); - } - - private EvmcVm(String filename) throws EvmcLoaderException { - nativeVm = load_and_create(filename); - } - - /** - * This method loads the specified EVM implementation and returns its pointer. - * - * @param filename Path to the dynamic object representing the EVM implementation - * @return Internal object pointer. - * @throws org.ethereum.evmc.EvmcLoaderException - */ - private static native ByteBuffer load_and_create(String filename) throws EvmcLoaderException; - - /** - * EVMC ABI version implemented by the VM instance. - * - *

Can be used to detect ABI incompatibilities. The EVMC ABI version represented by this file - * is in ::EVMC_ABI_VERSION. - */ - public static native int abi_version(); - - /** - * The name of the EVMC VM implementation. - * - *

It MUST be a NULL-terminated not empty string. The content MUST be UTF-8 encoded (this - * implies ASCII encoding is also allowed). - */ - private static native String name(ByteBuffer nativeVm); - - /** Function is a wrapper around native name(). */ - public String name() { - return name(nativeVm); - } - - /** - * The version of the EVMC VM implementation, e.g. "1.2.3b4". - * - *

It MUST be a NULL-terminated not empty string. The content MUST be UTF-8 encoded (this - * implies ASCII encoding is also allowed). - */ - private static native String version(ByteBuffer nativeVm); - - /** Function is a wrapper around native version(). */ - public String version() { - return version(nativeVm); - } - - /** - * Function to destroy the VM instance. - * - *

This is a mandatory method and MUST NOT be set to NULL. - */ - private static native void destroy(ByteBuffer nativeVm); - - /** - * Function to execute a code by the VM instance. - * - *

This is a mandatory method and MUST NOT be set to NULL. - */ - private static native ByteBuffer execute( - ByteBuffer nativeVm, HostContext context, int rev, ByteBuffer msg, ByteBuffer code); - - /** - * Function is a wrapper around native execute. - * - *

This allows the context to managed in one method - */ - public synchronized ByteBuffer execute( - HostContext context, int rev, ByteBuffer msg, ByteBuffer code) { - return execute(nativeVm, context, rev, msg, code); - } - - /** - * A method returning capabilities supported by the VM instance. - * - *

The value returned MAY change when different options are set via the set_option() method. - * - *

A Client SHOULD only rely on the value returned if it has queried it after it has called the - * set_option(). - * - *

This is a mandatory method and MUST NOT be set to NULL. - */ - private static native int get_capabilities(ByteBuffer nativeVm); - - /** Function is a wrapper around native get_capabilities(). */ - public int get_capabilities() { - return get_capabilities(nativeVm); - } - - /** - * Function that modifies VM's options. - * - *

If the VM does not support this feature the pointer can be NULL. - */ - private static native int set_option(ByteBuffer nativeVm, String name, String value); - - /** Function is a wrapper around native set_option(). */ - public int set_option(String name, String value) { - return set_option(nativeVm, name, value); - } - - /** This method cleans up resources. */ - @Override - public void close() { - destroy(nativeVm); - } -} diff --git a/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java b/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java deleted file mode 100644 index 83bf57b75..000000000 --- a/bindings/java/java/src/main/java/org/ethereum/evmc/Host.java +++ /dev/null @@ -1,96 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -import java.nio.ByteBuffer; - -/** - * The Host interface. - * - *

The set of all callback functions expected by VM instances. - */ -final class Host { - private static ByteBuffer ensureDirectBuffer(ByteBuffer input) { - // Reallocate if needed. - if (!input.isDirect()) { - return ByteBuffer.allocateDirect(input.remaining()).put(input); - } - return input; - } - - /** Check account existence callback function. */ - static boolean account_exists(HostContext context, byte[] address) { - return context.accountExists(address); - } - - /** Get storage callback function. */ - static ByteBuffer get_storage(HostContext context, byte[] address, byte[] key) { - return ensureDirectBuffer(context.getStorage(address, key)); - } - - /** Set storage callback function. */ - static int set_storage(HostContext context, byte[] address, byte[] key, byte[] value) { - return context.setStorage(address, key, value); - } - /** Get balance callback function. */ - static ByteBuffer get_balance(HostContext context, byte[] address) { - return ensureDirectBuffer(context.getBalance(address)); - } - - /** Get code size callback function. */ - static int get_code_size(HostContext context, byte[] address) { - return context.getCodeSize(address); - } - - /** Get code hash callback function. */ - static ByteBuffer get_code_hash(HostContext context, byte[] address) { - return ensureDirectBuffer(context.getCodeHash(address)); - } - - /** Copy code callback function. */ - static ByteBuffer copy_code(HostContext context, byte[] address) { - return ensureDirectBuffer(context.getCode(address)); - } - - /** Selfdestruct callback function. */ - static boolean selfdestruct(HostContext context, byte[] address, byte[] beneficiary) { - return context.selfdestruct(address, beneficiary); - } - - /** Call callback function. */ - static ByteBuffer call(HostContext context, ByteBuffer msg) { - return ensureDirectBuffer(context.call(msg)); - } - - /** Get transaction context callback function. */ - static ByteBuffer get_tx_context(HostContext context) { - return ensureDirectBuffer(context.getTxContext()); - } - - /** Get block hash callback function. */ - static ByteBuffer get_block_hash(HostContext context, long number) { - return ensureDirectBuffer(context.getBlockHash(number)); - } - - /** Emit log callback function. */ - static void emit_log( - HostContext context, - byte[] address, - byte[] data, - int data_size, - byte[][] topics, - int topic_count) { - context.emitLog(address, data, data_size, topics, topic_count); - } - - /** Access account callback function. */ - static int access_account(HostContext context, byte[] address) { - return context.accessAccount(address); - } - - /** Access storage callback function. */ - static int access_storage(HostContext context, byte[] address, byte[] key) { - return context.accessStorage(address, key); - } -} diff --git a/bindings/java/java/src/main/java/org/ethereum/evmc/HostContext.java b/bindings/java/java/src/main/java/org/ethereum/evmc/HostContext.java deleted file mode 100644 index 7a8b874a7..000000000 --- a/bindings/java/java/src/main/java/org/ethereum/evmc/HostContext.java +++ /dev/null @@ -1,175 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -import java.nio.ByteBuffer; - -/** - * This interface represents the callback functions must be implemented in order to interface with - * the EVM. - */ -public interface HostContext { - /** - * Check account existence function. - * - *

This function is used by the VM to check if there exists an account at given address. - * - * @param address The address of the account the query is about. - * @return true if exists, false otherwise. - */ - boolean accountExists(byte[] address); - - /** - * Access account function. - * - *

This function is used by the VM to add the given address to accessed_addresses substate (see - * EIP-2929). - * - * @param address The address of the account. - * @return 0 if cold access, 1 if warm access. - * @todo Change return type to enum. - */ - int accessAccount(byte[] address); - - /** - * Access storage function. - * - *

This function is used by the VM to add the given account storage entry to - * accessed_storage_keys substate (see EIP-2929). - * - * @param address The address of the account. - * @param key The index of the account's storage entry. - * @return 0 if cold access, 1 if warm access. - * @todo Change return type to enum. - */ - int accessStorage(byte[] address, byte[] key); - - /** - * Get storage function. - * - *

This function is used by a VM to query the given account storage entry. - * - * @param address The address of the account. - * @param key The index of the account's storage entry. - * @return The storage value at the given storage key or null bytes if the account does not exist. - */ - ByteBuffer getStorage(byte[] address, byte[] key); - - /** - * Set storage function. - * - *

This function is used by a VM to update the given account storage entry. The VM MUST make - * sure that the account exists. This requirement is only a formality because VM implementations - * only modify storage of the account of the current execution context (i.e. referenced by - * evmc_message::recipient). - * - * @param address The address of the account. - * @param key The index of the storage entry. - * @param value The value to be stored. - * @return The effect on the storage item. - */ - int setStorage(byte[] address, byte[] key, byte[] value); - - /** - * Get balance function. - * - *

This function is used by a VM to query the balance of the given account. - * - * @param address The address of the account. - * @return The balance of the given account or 0 if the account does not exist. - */ - ByteBuffer getBalance(byte[] address); - - /** - * Get code size function. - * - *

This function is used by a VM to get the size of the code stored in the account at the given - * address. - * - * @param address The address of the account. - * @return The size of the code in the account or 0 if the account does not exist. - */ - int getCodeSize(byte[] address); - - /** - * Get code hash function. - * - *

This function is used by a VM to get the keccak256 hash of the code stored in the account at - * the given address. For existing accounts not having a code, this function returns keccak256 - * hash of empty data. - * - * @param address The address of the account. - * @return The hash of the code in the account or null bytes if the account does not exist. - */ - ByteBuffer getCodeHash(byte[] address); - - /** - * Copy code function. - * - *

This function is used by an EVM to request a copy of the code of the given account to the - * memory buffer provided by the EVM. The Client MUST copy the requested code, starting with the - * given offset, to the provided memory buffer up to the size of the buffer or the size of the - * code, whichever is smaller. - * - * @param address The address of the account. - * @return A copy of the requested code. - */ - ByteBuffer getCode(byte[] address); - - /** - * Selfdestruct function. - * - *

This function is used by an EVM to SELFDESTRUCT given contract. The execution of the - * contract will not be stopped, that is up to the EVM. - * - * @param address The address of the contract to be selfdestructed. - * @param beneficiary The address where the remaining ETH is going to be transferred. - * @return The information if the given address has not been registered as selfdestructed yet. - * True if registered for the first time, false otherwise. - */ - boolean selfdestruct(byte[] address, byte[] beneficiary); - - /** - * This function supports EVM calls. - * - * @param msg The call parameters. - * @return The result of the call. - */ - ByteBuffer call(ByteBuffer msg); - - /** - * Get transaction context function. - * - *

This function is used by an EVM to retrieve the transaction and block context. - * - * @return The transaction context. - */ - ByteBuffer getTxContext(); - - /** - * Get block hash function. - * - *

This function is used by a VM to query the hash of the header of the given block. If the - * information about the requested block is not available, then this is signalled by returning - * null bytes. - * - * @param number The block number. - * @return The block hash or null bytes if the information about the block is not available. - */ - ByteBuffer getBlockHash(long number); - - /** - * Log function. - * - *

This function is used by an EVM to inform about a LOG that happened during an EVM bytecode - * execution. - * - * @param address The address of the contract that generated the log. - * @param data The unindexed data attached to the log. - * @param dataSize The length of the data. - * @param topics The the array of topics attached to the log. - * @param topicCount The number of the topics. Valid values are between 0 and 4 inclusively. - */ - void emitLog(byte[] address, byte[] data, int dataSize, byte[][] topics, int topicCount); -} diff --git a/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java b/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java deleted file mode 100644 index 26687d182..000000000 --- a/bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java +++ /dev/null @@ -1,266 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -import java.net.URL; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -final class EvmcTest { - private static final String exampleVmPath; - - static { - String extension = null; - String os = System.getProperty("os.name", "generic").toLowerCase(); - if (os.contains("mac") || os.contains("darwin")) { - extension = "dylib"; - } else if (os.contains("win")) { - extension = "dll"; - } else { - extension = "so"; - } - - URL exampleVM = EvmcTest.class.getClassLoader().getResource("libexample-vm." + extension); - exampleVmPath = exampleVM.getFile(); - } - - @Test - void testInitCloseDestroy() throws Exception { - Assertions.assertDoesNotThrow( - () -> { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) {} - }); - } - - @Test - void testAbiVersion() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - int abiVersion = vm.abi_version(); - assert (abiVersion > 0); - } - } - - @Test - void testName() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - String name = vm.name(); - assert (name.length() > 0); - assert (name.equals("example_vm")); - } - } - - @Test - void testVersion() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - String version = vm.version(); - assert (version.length() >= 5); - } - } - - @Test - void testExecute_returnAddress() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - HostContext context = new TestHostContext(); - int BYZANTIUM = 4; - int EVMC_CALL = 0; - int kind = EVMC_CALL; - char[] sender = "39bf71de1b7d7be3b51\0".toCharArray(); - char[] recipient = "53cf77204eEef952e25\0".toCharArray(); - char[] value = "1\0".toCharArray(); - char[] inputData = "hello w\0".toCharArray(); - long gas = 200000; - int depth = 0; - ByteBuffer msg = - new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer(); - - byte[] code = {0x30, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3}; // return_address - ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); - - ByteBuffer result = - vm.execute(context, BYZANTIUM, msg, bbcode).order(ByteOrder.nativeOrder()); - int statusCode = result.getInt(); - result.getInt(); // padding - long gasLeft = result.getLong(); - assert (statusCode == 0); - assert (gasLeft == 199994); - } - } - - /** Tests callbacks: get_storage_fn & set_storage_fn */ - @Test - void testExecute_counter() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - HostContext context = new TestHostContext(); - int BYZANTIUM = 4; - int EVMC_CALL = 0; - int kind = EVMC_CALL; - char[] sender = "39bf71de1b7d7be3b51\0".toCharArray(); - char[] recipient = "53cf77204eEef952e25\0".toCharArray(); - char[] value = "1\0".toCharArray(); - char[] inputData = "hello w\0".toCharArray(); - long gas = 200000; - int depth = 0; - ByteBuffer msg = - new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer(); - - byte[] code = {0x60, 0x01, 0x60, 0x00, 0x54, 0x01, 0x60, 0x00, 0x55}; // counter - ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); - - ByteBuffer result = - vm.execute(context, BYZANTIUM, msg, bbcode).order(ByteOrder.nativeOrder()); - int statusCode = result.getInt(); - result.getInt(); // padding - long gasLeft = result.getLong(); - assert (statusCode == 0); - assert (gasLeft == 199994); - } - } - - /** Tests callbacks: get_tx_context_fn */ - @Test - void testExecute_returnBlockNumber() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - HostContext context = new TestHostContext(); - int BYZANTIUM = 4; - int EVMC_CALL = 0; - int kind = EVMC_CALL; - char[] sender = "39bf71de1b7d7be3b51\0".toCharArray(); - char[] recipient = "53cf77204eEef952e25\0".toCharArray(); - char[] value = "1\0".toCharArray(); - char[] inputData = "hello w\0".toCharArray(); - long gas = 200000; - int depth = 0; - ByteBuffer msg = - new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer(); - - byte[] code = {0x43, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3}; // return_block_number( - ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); - - ByteBuffer result = - vm.execute(context, BYZANTIUM, msg, bbcode).order(ByteOrder.nativeOrder()); - int statusCode = result.getInt(); - result.getInt(); // padding - long gasLeft = result.getLong(); - assert (statusCode == 0); - assert (gasLeft == 199994); - } - } - - /** Tests callbacks: get_tx_context_fn & set_storage_fn */ - @Test - void testExecute_saveReturnBlockNumber() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - HostContext context = new TestHostContext(); - int BYZANTIUM = 4; - int EVMC_CALL = 0; - int kind = EVMC_CALL; - char[] sender = "39bf71de1b7d7be3b51\0".toCharArray(); - char[] recipient = "53cf77204eEef952e25\0".toCharArray(); - char[] value = "1\0".toCharArray(); - char[] inputData = "hello w\0".toCharArray(); - long gas = 200000; - int depth = 0; - ByteBuffer msg = - new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer(); - - byte[] code = { - 0x43, 0x60, 0x00, 0x55, 0x43, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3 - }; // save_return_block_number - ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); - - ByteBuffer result = - vm.execute(context, BYZANTIUM, msg, bbcode).order(ByteOrder.nativeOrder()); - int statusCode = result.getInt(); - result.getInt(); // padding - long gasLeft = result.getLong(); - assert (statusCode == 0); - assert (gasLeft == 199991); - } - } - - /** Tests callbacks: call_fn */ - @Test - void testExecute_makeCall() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - HostContext context = new TestHostContext(); - int BYZANTIUM = 4; - int EVMC_CALL = 0; - int kind = EVMC_CALL; - char[] sender = "39bf71de1b7d7be3b51\0".toCharArray(); - char[] recipient = "53cf77204eEef952e25\0".toCharArray(); - char[] value = "1\0".toCharArray(); - char[] inputData = "hello w\0".toCharArray(); - long gas = 200000; - int depth = 0; - ByteBuffer msg = - new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer(); - byte[] code = { - 0x60, - 0x00, - (byte) 0x80, - (byte) 0x80, - (byte) 0x80, - (byte) 0x80, - (byte) 0x80, - (byte) 0x80, - (byte) 0xf1 - }; // make_a_call( - ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); - - ByteBuffer result = - vm.execute(context, BYZANTIUM, msg, bbcode).order(ByteOrder.nativeOrder()); - int statusCode = result.getInt(); - result.getInt(); // padding - long gasLeft = result.getLong(); - assert (statusCode == 0); - assert (gasLeft == 199992); - } - } - - @Test - void testExecute_EVMC_CREATE() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - HostContext context = new TestHostContext(); - int BYZANTIUM = 4; - int EVMC_CREATE = 3; - int kind = EVMC_CREATE; - char[] sender = "39bf71de1b7d7be3b51\\0".toCharArray(); - char[] recipient = "53cf77204eEef952e25\0".toCharArray(); - char[] value = "1\0".toCharArray(); - char[] inputData = "hello w\0".toCharArray(); - long gas = 200000; - int depth = 0; - ByteBuffer msg = - new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer(); - byte[] code = {0x00}; - ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code); - - ByteBuffer result = - vm.execute(context, BYZANTIUM, msg, bbcode).order(ByteOrder.nativeOrder()); - int statusCode = result.getInt(); - result.getInt(); // padding - long gasLeft = result.getLong(); - assert (statusCode == 0); - assert (gasLeft == 199999); - } - } - - @Test - void testGetCapabilities() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - int capabilities = vm.get_capabilities(); - assert (capabilities > 0); - } - } - - @Test - void testSetOption() throws Exception { - try (EvmcVm vm = EvmcVm.create(exampleVmPath)) { - int result = vm.set_option("verbose", "1"); - assert (result == 0); - } - } -} diff --git a/bindings/java/java/src/test/java/org/ethereum/evmc/TestHostContext.java b/bindings/java/java/src/test/java/org/ethereum/evmc/TestHostContext.java deleted file mode 100644 index 016aa2659..000000000 --- a/bindings/java/java/src/test/java/org/ethereum/evmc/TestHostContext.java +++ /dev/null @@ -1,76 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -import java.nio.ByteBuffer; - -class TestHostContext implements HostContext { - @Override - public boolean accountExists(byte[] address) { - return true; - } - - @Override - public int accessAccount(byte[] address) { - return 0; - } - - @Override - public int accessStorage(byte[] address, byte[] key) { - return 0; - } - - @Override - public ByteBuffer getStorage(byte[] address, byte[] key) { - return ByteBuffer.allocateDirect(32).put(new byte[32]); - } - - @Override - public int setStorage(byte[] address, byte[] key, byte[] value) { - return 0; - } - - @Override - public ByteBuffer getBalance(byte[] address) { - return ByteBuffer.allocateDirect(32).put(new byte[32]); - } - - @Override - public int getCodeSize(byte[] address) { - return address.length; - } - - @Override - public ByteBuffer getCodeHash(byte[] address) { - return ByteBuffer.allocateDirect(32).put(new byte[32]); - } - - @Override - public ByteBuffer getCode(byte[] address) { - return ByteBuffer.allocateDirect(64).put(new byte[64]); - } - - @Override - public boolean selfdestruct(byte[] address, byte[] beneficiary) { - return false; - } - - @Override - public ByteBuffer call(ByteBuffer msg) { - return ByteBuffer.allocateDirect(72).put(new byte[72]); - } - - @Override - public ByteBuffer getTxContext() { - return ByteBuffer.allocateDirect(240).put(new byte[240]); - } - - @Override - public ByteBuffer getBlockHash(long number) { - return ByteBuffer.allocateDirect(32).put(new byte[32]); - } - - @Override - public void emitLog(byte[] address, byte[] data, int dataSize, byte[][] topics, int topicCount) {} -} diff --git a/bindings/java/java/src/test/java/org/ethereum/evmc/TestMessage.java b/bindings/java/java/src/test/java/org/ethereum/evmc/TestMessage.java deleted file mode 100644 index 6a652f332..000000000 --- a/bindings/java/java/src/test/java/org/ethereum/evmc/TestMessage.java +++ /dev/null @@ -1,81 +0,0 @@ -// EVMC: Ethereum Client-VM Connector API. -// Copyright 2019-2020 The EVMC Authors. -// Licensed under the Apache License, Version 2.0. -package org.ethereum.evmc; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.CharBuffer; -import java.nio.charset.StandardCharsets; - -public class TestMessage { - int kind; - int flags; - int depth; - long gas; - char[] recipient; - char[] sender; - char[] inputData; - long inputSize; - char[] value; - byte[] createSalt; - byte[] codeAddress; - - public TestMessage( - int kind, - char[] sender, - char[] recipient, - char[] value, - char[] inputData, - long gas, - int depth) { - this.kind = kind; - this.flags = 0; - this.depth = depth; - this.gas = gas; - this.recipient = recipient; - this.sender = sender; - this.inputData = inputData; - this.inputSize = (long) inputData.length; - this.value = value; - this.createSalt = new byte[32]; - this.codeAddress = new byte[20]; - } - - public TestMessage(ByteBuffer msg) { - this.kind = msg.getInt(); - this.flags = msg.getInt(); - this.depth = msg.getInt(); - msg.getInt(); // padding - this.gas = msg.getLong(); - ByteBuffer tmpbuf = msg.get(new byte[20]); - this.recipient = StandardCharsets.ISO_8859_1.decode(tmpbuf).array(); - tmpbuf = msg.get(new byte[20]); - this.sender = StandardCharsets.ISO_8859_1.decode(tmpbuf).array(); - tmpbuf = msg.get(new byte[8]); - this.inputData = StandardCharsets.ISO_8859_1.decode(tmpbuf).array(); - this.inputSize = msg.getLong(); - tmpbuf = msg.get(new byte[32]); - this.value = StandardCharsets.ISO_8859_1.decode(tmpbuf).array(); - this.createSalt = msg.get(new byte[32]).array(); - this.codeAddress = msg.get(new byte[20]).array(); - } - - public ByteBuffer toByteBuffer() { - - return ByteBuffer.allocateDirect(172) - .order(ByteOrder.nativeOrder()) - .putInt(kind) // 4 - .putInt(flags) // 4 - .putInt(depth) // 4 - .put(new byte[4]) // 4 (padding) - .putLong(gas) // 8 - .put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(recipient))) // 20 - .put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(sender))) // 20 - .put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(inputData))) // 8 - .putLong(inputSize) // 8 - .put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(value))) // 32 - .put(createSalt) // 32 - .put(codeAddress); // 20 - } -} diff --git a/bindings/java/settings.gradle b/bindings/java/settings.gradle deleted file mode 100644 index 395ce3e0a..000000000 --- a/bindings/java/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'evmc' -include 'java' diff --git a/bindings/java/wrapper.gradle b/bindings/java/wrapper.gradle deleted file mode 100644 index 707d1dbf9..000000000 --- a/bindings/java/wrapper.gradle +++ /dev/null @@ -1,4 +0,0 @@ -task setup(type: Wrapper) { - description = "Download the gradle wrapper and requisite files. Overwrites existing wrapper files." - gradleVersion = "7.5.1" -} diff --git a/circle.yml b/circle.yml index be3ffb953..b493ee2ba 100644 --- a/circle.yml +++ b/circle.yml @@ -404,28 +404,6 @@ jobs: choco install -y mingw --version 11.2 - go_test - bindings-java: - docker: - - image: cimg/openjdk:18.0 - environment: - CMAKE_OPTIONS: -DEVMC_JAVA=ON - steps: - - checkout - - build - - test - - run: - name: "Java Lint (spotlessCheck)" - working_directory: bindings/java - command: make lint - - run: - name: "Java Build" - working_directory: bindings/java - command: make clean build - - run: - name: "Java Test" - working_directory: bindings/java - command: make test - bindings-rust: docker: - image: rust:1 @@ -517,7 +495,6 @@ workflows: tags: only: /.*/ - bindings-go-windows - - bindings-java - bindings-rust: requires: - build-gcc-min