From ddcdbfe9444fbc396317755b3ac7cf76a6db9448 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 4 Jul 2019 13:40:26 +0100 Subject: [PATCH] rust: allow empty code in evmc_execute() --- bindings/rust/evmc-declare/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bindings/rust/evmc-declare/src/lib.rs b/bindings/rust/evmc-declare/src/lib.rs index 928fc6a..ae40832 100644 --- a/bindings/rust/evmc-declare/src/lib.rs +++ b/bindings/rust/evmc-declare/src/lib.rs @@ -337,10 +337,10 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream { { use evmc_vm::EvmcVm; - assert!(!msg.is_null()); - assert!(!context.is_null()); assert!(!instance.is_null()); - assert!(!code.is_null()); + // TODO: context is optional in case of the "precompiles" capability + assert!(!context.is_null()); + assert!(!msg.is_null()); let execution_context = unsafe { ::evmc_vm::ExecutionContext::new( @@ -349,8 +349,14 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream { ) }; - let code_ref: &[u8] = unsafe { - ::std::slice::from_raw_parts(code, code_size) + let empty_code = [0u8;0]; + let code_ref: &[u8] = if code.is_null() { + assert_eq!(code_size, 0); + &empty_code + } else { + unsafe { + ::std::slice::from_raw_parts(code, code_size) + } }; let container = unsafe {