Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 42 additions & 0 deletions c-api/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,48 @@ typedef struct vm_exec_vm_hook_c_func_pointers {
int32_t key_handle,
int32_t message_handle,
int32_t sig_handle);
void (*activate_unsafe_mode_func_ptr)(void *context);
void (*deactivate_unsafe_mode_func_ptr)(void *context);
int32_t (*managed_get_num_errors_func_ptr)(void *context);
void (*managed_get_error_with_index_func_ptr)(void *context, int32_t index, int32_t error_handle);
void (*managed_get_last_error_func_ptr)(void *context, int32_t error_handle);
int32_t (*managed_verify_groth16_func_ptr)(void *context,
int32_t curve_id,
int32_t proof_handle,
int32_t vk_handle,
int32_t pub_witness_handle);
int32_t (*managed_verify_plonk_func_ptr)(void *context,
int32_t curve_id,
int32_t proof_handle,
int32_t vk_handle,
int32_t pub_witness_handle);
int32_t (*managed_add_ec_func_ptr)(void *context,
int32_t curve_id,
int32_t group_id,
int32_t point1_handle,
int32_t point2_handle,
int32_t result_handle);
int32_t (*managed_mul_ec_func_ptr)(void *context,
int32_t curve_id,
int32_t group_id,
int32_t point_handle,
int32_t scalar_handle,
int32_t result_handle);
int32_t (*managed_multi_exp_ec_func_ptr)(void *context,
int32_t curve_id,
int32_t group_id,
int32_t points_handle,
int32_t scalars_handle,
int32_t result_handle);
int32_t (*managed_map_to_curve_ec_func_ptr)(void *context,
int32_t curve_id,
int32_t group_id,
int32_t element_handle,
int32_t result_handle);
int32_t (*managed_pairing_checks_ec_func_ptr)(void *context,
int32_t curve_id,
int32_t points_g1_handle,
int32_t points_g2_handle);
} vm_exec_vm_hook_c_func_pointers;

typedef struct vm_exec_compilation_options_t {
Expand Down
12 changes: 12 additions & 0 deletions c-api/src/capi_vm_hook_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@ pub struct vm_exec_vm_hook_c_func_pointers {
pub managed_verify_secp256r1_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32,
pub managed_verify_blssignature_share_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32,
pub managed_verify_blsaggregated_signature_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32,
pub activate_unsafe_mode_func_ptr: extern "C" fn(context: *mut c_void),
pub deactivate_unsafe_mode_func_ptr: extern "C" fn(context: *mut c_void),
pub managed_get_num_errors_func_ptr: extern "C" fn(context: *mut c_void) -> i32,
pub managed_get_error_with_index_func_ptr: extern "C" fn(context: *mut c_void, index: i32, error_handle: i32),
pub managed_get_last_error_func_ptr: extern "C" fn(context: *mut c_void, error_handle: i32),
pub managed_verify_groth16_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> i32,
pub managed_verify_plonk_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> i32,
pub managed_add_ec_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, group_id: i32, point1_handle: i32, point2_handle: i32, result_handle: i32) -> i32,
pub managed_mul_ec_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, group_id: i32, point_handle: i32, scalar_handle: i32, result_handle: i32) -> i32,
pub managed_multi_exp_ec_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, group_id: i32, points_handle: i32, scalars_handle: i32, result_handle: i32) -> i32,
pub managed_map_to_curve_ec_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, group_id: i32, element_handle: i32, result_handle: i32) -> i32,
pub managed_pairing_checks_ec_func_ptr: extern "C" fn(context: *mut c_void, curve_id: i32, points_g1_handle: i32, points_g2_handle: i32) -> i32,
}

impl std::fmt::Debug for vm_exec_vm_hook_c_func_pointers {
Expand Down
48 changes: 48 additions & 0 deletions c-api/src/capi_vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,4 +1146,52 @@ impl multiversx_chain_vm_executor::VMHooksLegacy for CapiVMHooks {
fn managed_verify_blsaggregated_signature(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_verify_blsaggregated_signature_func_ptr)(self.vm_hooks_ptr, key_handle, message_handle, sig_handle)
}

fn activate_unsafe_mode(&self) {
(self.c_func_pointers_ptr.activate_unsafe_mode_func_ptr)(self.vm_hooks_ptr)
}

fn deactivate_unsafe_mode(&self) {
(self.c_func_pointers_ptr.deactivate_unsafe_mode_func_ptr)(self.vm_hooks_ptr)
}

fn managed_get_num_errors(&self) -> i32 {
(self.c_func_pointers_ptr.managed_get_num_errors_func_ptr)(self.vm_hooks_ptr)
}

fn managed_get_error_with_index(&self, index: i32, error_handle: i32) {
(self.c_func_pointers_ptr.managed_get_error_with_index_func_ptr)(self.vm_hooks_ptr, index, error_handle)
}

fn managed_get_last_error(&self, error_handle: i32) {
(self.c_func_pointers_ptr.managed_get_last_error_func_ptr)(self.vm_hooks_ptr, error_handle)
}

fn managed_verify_groth16(&self, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_verify_groth16_func_ptr)(self.vm_hooks_ptr, curve_id, proof_handle, vk_handle, pub_witness_handle)
}

fn managed_verify_plonk(&self, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_verify_plonk_func_ptr)(self.vm_hooks_ptr, curve_id, proof_handle, vk_handle, pub_witness_handle)
}

fn managed_add_ec(&self, curve_id: i32, group_id: i32, point1_handle: i32, point2_handle: i32, result_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_add_ec_func_ptr)(self.vm_hooks_ptr, curve_id, group_id, point1_handle, point2_handle, result_handle)
}

fn managed_mul_ec(&self, curve_id: i32, group_id: i32, point_handle: i32, scalar_handle: i32, result_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_mul_ec_func_ptr)(self.vm_hooks_ptr, curve_id, group_id, point_handle, scalar_handle, result_handle)
}

fn managed_multi_exp_ec(&self, curve_id: i32, group_id: i32, points_handle: i32, scalars_handle: i32, result_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_multi_exp_ec_func_ptr)(self.vm_hooks_ptr, curve_id, group_id, points_handle, scalars_handle, result_handle)
}

fn managed_map_to_curve_ec(&self, curve_id: i32, group_id: i32, element_handle: i32, result_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_map_to_curve_ec_func_ptr)(self.vm_hooks_ptr, curve_id, group_id, element_handle, result_handle)
}

fn managed_pairing_checks_ec(&self, curve_id: i32, points_g1_handle: i32, points_g2_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_pairing_checks_ec_func_ptr)(self.vm_hooks_ptr, curve_id, points_g1_handle, points_g2_handle)
}
}
72 changes: 72 additions & 0 deletions vm-executor-experimental/src/we_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,66 @@ fn wasmer_import_managed_verify_blsaggregated_signature(env: FunctionEnvMut<VMHo
with_vm_hooks(env, |vh| vh.managed_verify_blsaggregated_signature(key_handle, message_handle, sig_handle))
}

#[rustfmt::skip]
fn wasmer_import_activate_unsafe_mode(env: FunctionEnvMut<VMHooksWrapper>) -> Result<(), VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.activate_unsafe_mode())
}

#[rustfmt::skip]
fn wasmer_import_deactivate_unsafe_mode(env: FunctionEnvMut<VMHooksWrapper>) -> Result<(), VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.deactivate_unsafe_mode())
}

#[rustfmt::skip]
fn wasmer_import_managed_get_num_errors(env: FunctionEnvMut<VMHooksWrapper>) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_get_num_errors())
}

#[rustfmt::skip]
fn wasmer_import_managed_get_error_with_index(env: FunctionEnvMut<VMHooksWrapper>, index: i32, error_handle: i32) -> Result<(), VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_get_error_with_index(index, error_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_get_last_error(env: FunctionEnvMut<VMHooksWrapper>, error_handle: i32) -> Result<(), VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_get_last_error(error_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_verify_groth16(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_verify_groth16(curve_id, proof_handle, vk_handle, pub_witness_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_verify_plonk(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_verify_plonk(curve_id, proof_handle, vk_handle, pub_witness_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_add_ec(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, group_id: i32, point1_handle: i32, point2_handle: i32, result_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_add_ec(curve_id, group_id, point1_handle, point2_handle, result_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_mul_ec(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, group_id: i32, point_handle: i32, scalar_handle: i32, result_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_mul_ec(curve_id, group_id, point_handle, scalar_handle, result_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_multi_exp_ec(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, group_id: i32, points_handle: i32, scalars_handle: i32, result_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_multi_exp_ec(curve_id, group_id, points_handle, scalars_handle, result_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_map_to_curve_ec(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, group_id: i32, element_handle: i32, result_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_map_to_curve_ec(curve_id, group_id, element_handle, result_handle))
}

#[rustfmt::skip]
fn wasmer_import_managed_pairing_checks_ec(env: FunctionEnvMut<VMHooksWrapper>, curve_id: i32, points_g1_handle: i32, points_g2_handle: i32) -> Result<i32, VMHooksEarlyExit> {
with_vm_hooks(env, |vh| vh.managed_pairing_checks_ec(curve_id, points_g1_handle, points_g2_handle))
}

pub fn generate_import_object(store: &mut Store, vh_wrapper: VMHooksWrapper) -> Imports {
let function_env = FunctionEnv::new(store, vh_wrapper);

Expand Down Expand Up @@ -1678,6 +1738,18 @@ pub fn generate_import_object(store: &mut Store, vh_wrapper: VMHooksWrapper) ->
"managedVerifySecp256r1" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_verify_secp256r1),
"managedVerifyBLSSignatureShare" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_verify_blssignature_share),
"managedVerifyBLSAggregatedSignature" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_verify_blsaggregated_signature),
"activateUnsafeMode" => Function::new_typed_with_env(store, &function_env, wasmer_import_activate_unsafe_mode),
"deactivateUnsafeMode" => Function::new_typed_with_env(store, &function_env, wasmer_import_deactivate_unsafe_mode),
"managedGetNumErrors" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_get_num_errors),
"managedGetErrorWithIndex" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_get_error_with_index),
"managedGetLastError" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_get_last_error),
"managedVerifyGroth16" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_verify_groth16),
"managedVerifyPlonk" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_verify_plonk),
"managedAddEC" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_add_ec),
"managedMulEC" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_mul_ec),
"managedMultiExpEC" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_multi_exp_ec),
"managedMapToCurveEC" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_map_to_curve_ec),
"managedPairingChecksEC" => Function::new_typed_with_env(store, &function_env, wasmer_import_managed_pairing_checks_ec),

}
}
Expand Down
72 changes: 72 additions & 0 deletions vm-executor-wasmer/src/wasmer_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,66 @@ fn wasmer_import_managed_verify_blsaggregated_signature(env: &VMHooksWrapper, ke
env.vm_hooks.managed_verify_blsaggregated_signature(key_handle, message_handle, sig_handle)
}

#[rustfmt::skip]
fn wasmer_import_activate_unsafe_mode(env: &VMHooksWrapper) {
env.vm_hooks.activate_unsafe_mode()
}

#[rustfmt::skip]
fn wasmer_import_deactivate_unsafe_mode(env: &VMHooksWrapper) {
env.vm_hooks.deactivate_unsafe_mode()
}

#[rustfmt::skip]
fn wasmer_import_managed_get_num_errors(env: &VMHooksWrapper) -> i32 {
env.vm_hooks.managed_get_num_errors()
}

#[rustfmt::skip]
fn wasmer_import_managed_get_error_with_index(env: &VMHooksWrapper, index: i32, error_handle: i32) {
env.vm_hooks.managed_get_error_with_index(index, error_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_get_last_error(env: &VMHooksWrapper, error_handle: i32) {
env.vm_hooks.managed_get_last_error(error_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_verify_groth16(env: &VMHooksWrapper, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> i32 {
env.vm_hooks.managed_verify_groth16(curve_id, proof_handle, vk_handle, pub_witness_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_verify_plonk(env: &VMHooksWrapper, curve_id: i32, proof_handle: i32, vk_handle: i32, pub_witness_handle: i32) -> i32 {
env.vm_hooks.managed_verify_plonk(curve_id, proof_handle, vk_handle, pub_witness_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_add_ec(env: &VMHooksWrapper, curve_id: i32, group_id: i32, point1_handle: i32, point2_handle: i32, result_handle: i32) -> i32 {
env.vm_hooks.managed_add_ec(curve_id, group_id, point1_handle, point2_handle, result_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_mul_ec(env: &VMHooksWrapper, curve_id: i32, group_id: i32, point_handle: i32, scalar_handle: i32, result_handle: i32) -> i32 {
env.vm_hooks.managed_mul_ec(curve_id, group_id, point_handle, scalar_handle, result_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_multi_exp_ec(env: &VMHooksWrapper, curve_id: i32, group_id: i32, points_handle: i32, scalars_handle: i32, result_handle: i32) -> i32 {
env.vm_hooks.managed_multi_exp_ec(curve_id, group_id, points_handle, scalars_handle, result_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_map_to_curve_ec(env: &VMHooksWrapper, curve_id: i32, group_id: i32, element_handle: i32, result_handle: i32) -> i32 {
env.vm_hooks.managed_map_to_curve_ec(curve_id, group_id, element_handle, result_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_pairing_checks_ec(env: &VMHooksWrapper, curve_id: i32, points_g1_handle: i32, points_g2_handle: i32) -> i32 {
env.vm_hooks.managed_pairing_checks_ec(curve_id, points_g1_handle, points_g2_handle)
}

pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObject {
imports! {
"env" => {
Expand Down Expand Up @@ -1675,6 +1735,18 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje
"managedVerifySecp256r1" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_secp256r1),
"managedVerifyBLSSignatureShare" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_blssignature_share),
"managedVerifyBLSAggregatedSignature" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_blsaggregated_signature),
"activateUnsafeMode" => Function::new_native_with_env(store, env.clone(), wasmer_import_activate_unsafe_mode),
"deactivateUnsafeMode" => Function::new_native_with_env(store, env.clone(), wasmer_import_deactivate_unsafe_mode),
"managedGetNumErrors" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_num_errors),
"managedGetErrorWithIndex" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_error_with_index),
"managedGetLastError" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_last_error),
"managedVerifyGroth16" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_groth16),
"managedVerifyPlonk" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_plonk),
"managedAddEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_add_ec),
"managedMulEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_mul_ec),
"managedMultiExpEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_multi_exp_ec),
"managedMapToCurveEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_map_to_curve_ec),
"managedPairingChecksEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_pairing_checks_ec),

}
}
Expand Down
Loading
Loading