diff --git a/crates/integration/codesize.json b/crates/integration/codesize.json index ed08958..8148d7d 100644 --- a/crates/integration/codesize.json +++ b/crates/integration/codesize.json @@ -1,10 +1,10 @@ { - "Baseline": 983, - "Computation": 4207, - "DivisionArithmetics": 40509, - "ERC20": 47068, - "Events": 1791, - "FibonacciIterative": 3044, - "Flipper": 3405, - "SHA1": 33583 + "Baseline": 981, + "Computation": 4145, + "DivisionArithmetics": 40606, + "ERC20": 47335, + "Events": 1773, + "FibonacciIterative": 3027, + "Flipper": 3385, + "SHA1": 33545 } \ No newline at end of file diff --git a/crates/llvm-context/src/polkavm/const/mod.rs b/crates/llvm-context/src/polkavm/const/mod.rs index 36013b6..91e8177 100644 --- a/crates/llvm-context/src/polkavm/const/mod.rs +++ b/crates/llvm-context/src/polkavm/const/mod.rs @@ -1,14 +1,8 @@ //! The LLVM context constants. -/// Runtime API methods. -pub mod runtime_api; - /// The LLVM framework version. pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4); -/// The PolkaVM version. -pub const ZKEVM_VERSION: semver::Version = semver::Version::new(1, 3, 2); - /// The register width sized type pub static XLEN: usize = revive_common::BIT_LENGTH_X32; @@ -24,31 +18,6 @@ pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize"; /// The call flags global variable name. pub static GLOBAL_CALL_FLAGS: &str = "call_flags"; -/// The constant array global variable name prefix. -pub static GLOBAL_CONST_ARRAY_PREFIX: &str = "const_array_"; - -/// The global verbatim getter identifier prefix. -pub static GLOBAL_VERBATIM_GETTER_PREFIX: &str = "get_global::"; - -/// The external call data offset in the auxiliary heap. -pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0; - -/// The constructor return data offset in the auxiliary heap. -pub const HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA: u64 = - 8 * (revive_common::BYTE_LENGTH_WORD as u64); - -/// The `create` method deployer signature. -pub static DEPLOYER_SIGNATURE_CREATE: &str = "create(bytes32,bytes32,bytes)"; - -/// The `create2` method deployer signature. -pub static DEPLOYER_SIGNATURE_CREATE2: &str = "create2(bytes32,bytes32,bytes)"; - -/// The absence of system call bit. -pub const NO_SYSTEM_CALL_BIT: bool = false; - -/// The system call bit. -pub const SYSTEM_CALL_BIT: bool = true; - /// The deployer call header size that consists of: /// - bytecode hash (32 bytes) pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD; diff --git a/crates/llvm-context/src/polkavm/const/runtime_api.rs b/crates/llvm-context/src/polkavm/const/runtime_api.rs deleted file mode 100644 index 9de82e7..0000000 --- a/crates/llvm-context/src/polkavm/const/runtime_api.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! Runtime API import and export symbols. - -pub mod exports { - /// The contract deploy export. - pub static CALL: &str = "call"; - - /// The contract call export. - pub static DEPLOY: &str = "deploy"; - - /// All exported symbols. - /// Useful for configuring common attributes and linkage. - pub static EXPORTS: [&str; 2] = [CALL, DEPLOY]; -} - -pub mod imports { - pub static SBRK: &str = "__sbrk_internal"; - - pub static MEMORY_SIZE: &str = "__msize"; - - pub static ADDRESS: &str = "address"; - - pub static BALANCE: &str = "balance"; - - pub static BALANCE_OF: &str = "balance_of"; - - pub static BLOCK_NUMBER: &str = "block_number"; - - pub static CHAIN_ID: &str = "chain_id"; - - pub static CALL: &str = "call"; - - pub static CALLER: &str = "caller"; - - pub static CODE_SIZE: &str = "code_size"; - - pub static DEPOSIT_EVENT: &str = "deposit_event"; - - pub static GET_IMMUTABLE_DATA: &str = "get_immutable_data"; - - pub static GET_STORAGE: &str = "get_storage"; - - pub static HASH_KECCAK_256: &str = "hash_keccak_256"; - - pub static INPUT: &str = "input"; - - pub static INSTANTIATE: &str = "instantiate"; - - pub static NOW: &str = "now"; - - pub static RETURN: &str = "seal_return"; - - pub static RETURNDATACOPY: &str = "return_data_copy"; - - pub static RETURNDATASIZE: &str = "return_data_size"; - - pub static SET_STORAGE: &str = "set_storage"; - - pub static SET_IMMUTABLE_DATA: &str = "set_immutable_data"; - - pub static VALUE_TRANSFERRED: &str = "value_transferred"; - - /// All imported runtime API symbols. - /// Useful for configuring common attributes and linkage. - pub static IMPORTS: [&str; 23] = [ - SBRK, - MEMORY_SIZE, - ADDRESS, - BALANCE, - BALANCE_OF, - BLOCK_NUMBER, - CALL, - CALLER, - CHAIN_ID, - CODE_SIZE, - DEPOSIT_EVENT, - GET_IMMUTABLE_DATA, - GET_STORAGE, - HASH_KECCAK_256, - INPUT, - INSTANTIATE, - NOW, - RETURN, - RETURNDATACOPY, - RETURNDATASIZE, - SET_IMMUTABLE_DATA, - SET_STORAGE, - VALUE_TRANSFERRED, - ]; -} diff --git a/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs b/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs index ea7d348..e43cb06 100644 --- a/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs +++ b/crates/llvm-context/src/polkavm/context/function/runtime/entry.rs @@ -5,7 +5,6 @@ use inkwell::types::BasicType; use crate::polkavm::context::address_space::AddressSpace; use crate::polkavm::context::function::runtime; use crate::polkavm::context::Context; -use crate::polkavm::r#const::*; use crate::polkavm::Dependency; use crate::polkavm::WriteLLVM; @@ -19,9 +18,6 @@ impl Entry { /// The call flags argument index. pub const ARGUMENT_INDEX_CALL_FLAGS: usize = 0; - /// The number of mandatory arguments. - pub const MANDATORY_ARGUMENTS_COUNT: usize = 2; - /// Reserve 1kb for calldata. pub const MAX_CALLDATA_SIZE: usize = 1024; @@ -112,7 +108,7 @@ impl Entry { context.integer_const(crate::polkavm::XLEN, Self::MAX_CALLDATA_SIZE as u64), )?; context.build_runtime_call( - runtime_api::imports::INPUT, + revive_runtime_api::polkavm_imports::INPUT, &[input_pointer_casted.into(), length_pointer_casted.into()], ); diff --git a/crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs b/crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs index b229857..e9e1665 100644 --- a/crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs +++ b/crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs @@ -4,8 +4,8 @@ use crate::polkavm::context::address_space::AddressSpace; use crate::polkavm::context::function::runtime; use crate::polkavm::context::pointer::Pointer; use crate::polkavm::context::Context; +use crate::polkavm::Dependency; use crate::polkavm::WriteLLVM; -use crate::polkavm::{runtime_api, Dependency}; /// A function for requesting the immutable data from the runtime. /// This is a special function that is only used by the front-end generated code. @@ -70,7 +70,7 @@ where .value .as_pointer_value(); context.build_runtime_call( - runtime_api::imports::GET_IMMUTABLE_DATA, + revive_runtime_api::polkavm_imports::GET_IMMUTABLE_DATA, &[ context .builder() diff --git a/crates/llvm-context/src/polkavm/context/mod.rs b/crates/llvm-context/src/polkavm/context/mod.rs index 8f54bcc..212aca0 100644 --- a/crates/llvm-context/src/polkavm/context/mod.rs +++ b/crates/llvm-context/src/polkavm/context/mod.rs @@ -26,7 +26,6 @@ use inkwell::values::BasicValue; use crate::optimizer::settings::Settings as OptimizerSettings; use crate::optimizer::Optimizer; -use crate::polkavm::r#const::*; use crate::polkavm::DebugConfig; use crate::polkavm::Dependency; use crate::target_machine::target::Target; @@ -136,7 +135,7 @@ where ) .expect("the PolkaVM imports module should be linkable"); - for import in runtime_api::imports::IMPORTS { + for import in revive_runtime_api::polkavm_imports::IMPORTS { module .get_function(import) .expect("should be declared") @@ -696,7 +695,7 @@ where let transient = pointer.address_space == AddressSpace::TransientStorage; self.build_runtime_call( - runtime_api::imports::GET_STORAGE, + revive_runtime_api::polkavm_imports::GET_STORAGE, &[ self.xlen_type().const_int(transient as u64, false).into(), storage_key_pointer_casted.into(), @@ -795,7 +794,7 @@ where let transient = pointer.address_space == AddressSpace::TransientStorage; self.build_runtime_call( - runtime_api::imports::SET_STORAGE, + revive_runtime_api::polkavm_imports::SET_STORAGE, &[ self.xlen_type().const_int(transient as u64, false).into(), storage_key_pointer_casted.into(), @@ -1030,7 +1029,7 @@ where )?; self.build_runtime_call( - runtime_api::imports::RETURN, + revive_runtime_api::polkavm_imports::RETURN, &[flags.into(), offset_pointer.into(), length_pointer.into()], ); self.build_unreachable(); @@ -1100,7 +1099,7 @@ where Ok(self .builder() .build_call( - self.runtime_api_method(runtime_api::imports::SBRK), + self.runtime_api_method(revive_runtime_api::polkavm_imports::SBRK), &[offset.into(), size.into()], "call_sbrk", )? @@ -1115,7 +1114,7 @@ where Ok(self .builder() .build_call( - self.runtime_api_method(runtime_api::imports::MEMORY_SIZE), + self.runtime_api_method(revive_runtime_api::polkavm_imports::MEMORY_SIZE), &[], "call_msize", )? diff --git a/crates/llvm-context/src/polkavm/evm/call.rs b/crates/llvm-context/src/polkavm/evm/call.rs index 2247250..1cf67d2 100644 --- a/crates/llvm-context/src/polkavm/evm/call.rs +++ b/crates/llvm-context/src/polkavm/evm/call.rs @@ -5,7 +5,6 @@ use inkwell::values::BasicValue; use crate::polkavm::context::argument::Argument; use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; const STATIC_CALL_FLAG: u32 = 0b0001_0000; const REENTRANT_CALL_FLAG: u32 = 0b0000_1000; @@ -77,7 +76,7 @@ where arguments, )?; - let name = runtime_api::imports::CALL; + let name = revive_runtime_api::polkavm_imports::CALL; let argument_pointer = context.builder().build_ptr_to_int( argument_pointer.value, context.xlen_type(), diff --git a/crates/llvm-context/src/polkavm/evm/context.rs b/crates/llvm-context/src/polkavm/evm/context.rs index 741e20e..cf4adeb 100644 --- a/crates/llvm-context/src/polkavm/evm/context.rs +++ b/crates/llvm-context/src/polkavm/evm/context.rs @@ -4,7 +4,6 @@ use inkwell::values::BasicValue; use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates the `gas_limit` instruction. pub fn gas_limit<'ctx, D>( @@ -43,7 +42,7 @@ pub fn chain_id<'ctx, D>( where D: Dependency + Clone, { - context.build_runtime_call_to_getter(runtime_api::imports::CHAIN_ID) + context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::CHAIN_ID) } /// Translates the `block_number` instruction. @@ -53,7 +52,7 @@ pub fn block_number<'ctx, D>( where D: Dependency + Clone, { - context.build_runtime_call_to_getter(runtime_api::imports::BLOCK_NUMBER) + context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::BLOCK_NUMBER) } /// Translates the `block_timestamp` instruction. @@ -63,7 +62,7 @@ pub fn block_timestamp<'ctx, D>( where D: Dependency + Clone, { - context.build_runtime_call_to_getter(runtime_api::imports::NOW) + context.build_runtime_call_to_getter(revive_runtime_api::polkavm_imports::NOW) } /// Translates the `block_hash` instruction. @@ -119,7 +118,7 @@ where "address_output", ); context.build_runtime_call( - runtime_api::imports::ADDRESS, + revive_runtime_api::polkavm_imports::ADDRESS, &[pointer.to_int(context).into()], ); context.build_load_address(pointer) @@ -137,7 +136,7 @@ where "address_output", ); context.build_runtime_call( - runtime_api::imports::CALLER, + revive_runtime_api::polkavm_imports::CALLER, &[pointer.to_int(context).into()], ); context.build_load_address(pointer) diff --git a/crates/llvm-context/src/polkavm/evm/create.rs b/crates/llvm-context/src/polkavm/evm/create.rs index 7a4620c..1aee521 100644 --- a/crates/llvm-context/src/polkavm/evm/create.rs +++ b/crates/llvm-context/src/polkavm/evm/create.rs @@ -7,7 +7,6 @@ use crate::polkavm::context::argument::Argument; use crate::polkavm::context::code_type::CodeType; use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates the contract `create` and `create2` instruction. /// @@ -82,7 +81,7 @@ where "instantiate_argument_pointer", )?; context.build_runtime_call( - runtime_api::imports::INSTANTIATE, + revive_runtime_api::polkavm_imports::INSTANTIATE, &[argument_pointer.into()], ); diff --git a/crates/llvm-context/src/polkavm/evm/crypto.rs b/crates/llvm-context/src/polkavm/evm/crypto.rs index 3e83ea6..c3a11e7 100644 --- a/crates/llvm-context/src/polkavm/evm/crypto.rs +++ b/crates/llvm-context/src/polkavm/evm/crypto.rs @@ -2,7 +2,6 @@ use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates the `sha3` instruction. pub fn sha3<'ctx, D>( @@ -19,7 +18,7 @@ where let output_pointer = context.build_alloca(context.word_type(), "output_pointer"); context.build_runtime_call( - runtime_api::imports::HASH_KECCAK_256, + revive_runtime_api::polkavm_imports::HASH_KECCAK_256, &[ input_pointer.to_int(context).into(), length_casted.into(), diff --git a/crates/llvm-context/src/polkavm/evm/ether_gas.rs b/crates/llvm-context/src/polkavm/evm/ether_gas.rs index a1fbe75..e59b9ba 100644 --- a/crates/llvm-context/src/polkavm/evm/ether_gas.rs +++ b/crates/llvm-context/src/polkavm/evm/ether_gas.rs @@ -4,7 +4,6 @@ use inkwell::values::BasicValue; use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates the `gas` instruction. pub fn gas<'ctx, D>( @@ -26,7 +25,7 @@ where let output_pointer = context.build_alloca(context.value_type(), "value_transferred"); context.build_store(output_pointer, context.word_const(0))?; context.build_runtime_call( - runtime_api::imports::VALUE_TRANSFERRED, + revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED, &[output_pointer.to_int(context).into()], ); context.build_load(output_pointer, "value_transferred") @@ -50,7 +49,7 @@ where )?; context.build_runtime_call( - runtime_api::imports::BALANCE_OF, + revive_runtime_api::polkavm_imports::BALANCE_OF, &[address_pointer.to_int(context).into(), balance.into()], ); @@ -71,7 +70,10 @@ where "balance", )?; - context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]); + context.build_runtime_call( + revive_runtime_api::polkavm_imports::BALANCE, + &[balance.into()], + ); context.build_load(balance_pointer, "balance") } diff --git a/crates/llvm-context/src/polkavm/evm/event.rs b/crates/llvm-context/src/polkavm/evm/event.rs index ecf4935..2c10c90 100644 --- a/crates/llvm-context/src/polkavm/evm/event.rs +++ b/crates/llvm-context/src/polkavm/evm/event.rs @@ -4,7 +4,6 @@ use inkwell::values::BasicValue; use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates a log or event call. /// @@ -77,7 +76,10 @@ where ] }; - let _ = context.build_runtime_call(runtime_api::imports::DEPOSIT_EVENT, &arguments); + let _ = context.build_runtime_call( + revive_runtime_api::polkavm_imports::DEPOSIT_EVENT, + &arguments, + ); Ok(()) } diff --git a/crates/llvm-context/src/polkavm/evm/ext_code.rs b/crates/llvm-context/src/polkavm/evm/ext_code.rs index b34bdd8..2cca655 100644 --- a/crates/llvm-context/src/polkavm/evm/ext_code.rs +++ b/crates/llvm-context/src/polkavm/evm/ext_code.rs @@ -4,7 +4,6 @@ use inkwell::values::BasicValue; use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates the `extcodesize` instruction if `address` is `Some`. /// Otherwise, translates the `codesize` instruction. @@ -31,10 +30,15 @@ where )?; let value = context .build_runtime_call( - runtime_api::imports::CODE_SIZE, + revive_runtime_api::polkavm_imports::CODE_SIZE, &[address_pointer_casted.into()], ) - .unwrap_or_else(|| panic!("{} should return a value", runtime_api::imports::CODE_SIZE)) + .unwrap_or_else(|| { + panic!( + "{} should return a value", + revive_runtime_api::polkavm_imports::CODE_SIZE + ) + }) .into_int_value(); Ok(context diff --git a/crates/llvm-context/src/polkavm/evm/return.rs b/crates/llvm-context/src/polkavm/evm/return.rs index a65e265..f152ae9 100644 --- a/crates/llvm-context/src/polkavm/evm/return.rs +++ b/crates/llvm-context/src/polkavm/evm/return.rs @@ -4,7 +4,7 @@ use crate::polkavm::context::address_space::AddressSpace; use crate::polkavm::context::code_type::CodeType; use crate::polkavm::context::pointer::Pointer; use crate::polkavm::context::Context; -use crate::polkavm::{runtime_api, Dependency}; +use crate::polkavm::Dependency; /// Translates the `return` instruction. pub fn r#return<'ctx, D>( @@ -51,7 +51,7 @@ where .value .as_pointer_value(); context.build_runtime_call( - runtime_api::imports::SET_IMMUTABLE_DATA, + revive_runtime_api::polkavm_imports::SET_IMMUTABLE_DATA, &[ context .builder() diff --git a/crates/llvm-context/src/polkavm/evm/return_data.rs b/crates/llvm-context/src/polkavm/evm/return_data.rs index 3812bd2..bd29f50 100644 --- a/crates/llvm-context/src/polkavm/evm/return_data.rs +++ b/crates/llvm-context/src/polkavm/evm/return_data.rs @@ -2,7 +2,6 @@ use crate::polkavm::context::Context; use crate::polkavm::Dependency; -use crate::polkavm_const::runtime_api; /// Translates the return data size. pub fn size<'ctx, D>( @@ -18,7 +17,7 @@ where "return_data_copy_output_pointer", )?; context.build_runtime_call( - runtime_api::imports::RETURNDATASIZE, + revive_runtime_api::polkavm_imports::RETURNDATASIZE, &[output_pointer_parameter.into()], ); context.build_load(output_pointer, "return_data_size_load") @@ -59,7 +58,7 @@ where )?; context.build_runtime_call( - runtime_api::imports::RETURNDATACOPY, + revive_runtime_api::polkavm_imports::RETURNDATACOPY, &[ output_pointer.into(), output_length_pointer_int.into(), diff --git a/crates/runtime-api/src/polkavm_exports.rs b/crates/runtime-api/src/polkavm_exports.rs index 70b7e54..dddf160 100644 --- a/crates/runtime-api/src/polkavm_exports.rs +++ b/crates/runtime-api/src/polkavm_exports.rs @@ -2,6 +2,16 @@ use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, sup include!(concat!(env!("OUT_DIR"), "/polkavm_exports.rs")); +/// The contract deploy export. +pub static CALL: &str = "call"; + +/// The contract call export. +pub static DEPLOY: &str = "deploy"; + +/// All exported symbols. +/// Useful for configuring common attributes and linkage. +pub static EXPORTS: [&str; 2] = [CALL, DEPLOY]; + /// Creates a LLVM module from the [BITCODE]. /// The module exports `call` and `deploy` functions (which are named thereafter). /// Returns `Error` if the bitcode fails to parse, which should never happen. @@ -23,7 +33,7 @@ mod tests { let context = inkwell::context::Context::create(); let module = polkavm_exports::module(&context, "polkavm_exports").unwrap(); - assert!(module.get_function("call").is_some()); - assert!(module.get_function("deploy").is_some()); + assert!(module.get_function(polkavm_exports::CALL).is_some()); + assert!(module.get_function(polkavm_exports::DEPLOY).is_some()); } } diff --git a/crates/runtime-api/src/polkavm_imports.c b/crates/runtime-api/src/polkavm_imports.c index 9e6f05d..5d50f49 100644 --- a/crates/runtime-api/src/polkavm_imports.c +++ b/crates/runtime-api/src/polkavm_imports.c @@ -64,86 +64,44 @@ void * memmove(void *dst, const void *src, size_t n) { // Imports +POLKAVM_IMPORT(void, address, uint32_t) + +POLKAVM_IMPORT(void, balance, uint32_t) + +POLKAVM_IMPORT(void, balance_of, uint32_t, uint32_t) + +POLKAVM_IMPORT(void, block_number, uint32_t) + +POLKAVM_IMPORT(uint32_t, call, uint32_t) + +POLKAVM_IMPORT(void, caller, uint32_t) + +POLKAVM_IMPORT(void, chain_id, uint32_t) + +POLKAVM_IMPORT(uint32_t, code_size, uint32_t) + +POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t) + +POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t); + +POLKAVM_IMPORT(uint32_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) + +POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t) + POLKAVM_IMPORT(void, input, uint32_t, uint32_t) +POLKAVM_IMPORT(uint32_t, instantiate, uint32_t) + +POLKAVM_IMPORT(void, now, uint32_t) + POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t) +POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) + POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t) POLKAVM_IMPORT(void, return_data_size, uint32_t) POLKAVM_IMPORT(void, set_immutable_data, uint32_t, uint32_t); -POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t); - POLKAVM_IMPORT(void, value_transferred, uint32_t) - -POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, clear_storage, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, contains_storage, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, take_storage, uint32_t, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, call, uint32_t) - -POLKAVM_IMPORT(uint32_t, delegate_call, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, instantiate, uint32_t) - -POLKAVM_IMPORT(void, terminate, uint32_t) - -POLKAVM_IMPORT(void, caller, uint32_t) - -POLKAVM_IMPORT(uint32_t, is_contract, uint32_t) - -POLKAVM_IMPORT(uint32_t, code_hash, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, code_size, uint32_t) - -POLKAVM_IMPORT(void, own_code_hash, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, caller_is_origin) - -POLKAVM_IMPORT(uint32_t, caller_is_root) - -POLKAVM_IMPORT(void, address, uint32_t) - -POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, gas_left, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, balance, uint32_t) - -POLKAVM_IMPORT(void, balance_of, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, chain_id, uint32_t) - -POLKAVM_IMPORT(void, now, uint32_t) - -POLKAVM_IMPORT(void, minimum_balance, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, block_number, uint32_t) - -POLKAVM_IMPORT(void, hash_sha2_256, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, hash_blake2_256, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(void, hash_blake2_128, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, call_chain_extension, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, debug_message, uint32_t, uint32_t) - -POLKAVM_IMPORT(uint32_t, set_code_hash, uint32_t) - -POLKAVM_IMPORT(uint64_t, instantiation_nonce,) - -POLKAVM_IMPORT(uint32_t, transfer, uint32_t, uint32_t, uint32_t, uint32_t) diff --git a/crates/runtime-api/src/polkavm_imports.rs b/crates/runtime-api/src/polkavm_imports.rs index fc90f3f..373f69c 100644 --- a/crates/runtime-api/src/polkavm_imports.rs +++ b/crates/runtime-api/src/polkavm_imports.rs @@ -10,6 +10,80 @@ use inkwell::{context::Context, memory_buffer::MemoryBuffer, module::Module, sup include!(concat!(env!("OUT_DIR"), "/polkavm_imports.rs")); +pub static SBRK: &str = "__sbrk_internal"; + +pub static MEMORY_SIZE: &str = "__msize"; + +pub static ADDRESS: &str = "address"; + +pub static BALANCE: &str = "balance"; + +pub static BALANCE_OF: &str = "balance_of"; + +pub static BLOCK_NUMBER: &str = "block_number"; + +pub static CALL: &str = "call"; + +pub static CALLER: &str = "caller"; + +pub static CHAIN_ID: &str = "chain_id"; + +pub static CODE_SIZE: &str = "code_size"; + +pub static DEPOSIT_EVENT: &str = "deposit_event"; + +pub static GET_IMMUTABLE_DATA: &str = "get_immutable_data"; + +pub static GET_STORAGE: &str = "get_storage"; + +pub static HASH_KECCAK_256: &str = "hash_keccak_256"; + +pub static INPUT: &str = "input"; + +pub static INSTANTIATE: &str = "instantiate"; + +pub static NOW: &str = "now"; + +pub static RETURN: &str = "seal_return"; + +pub static SET_STORAGE: &str = "set_storage"; + +pub static RETURNDATACOPY: &str = "return_data_copy"; + +pub static RETURNDATASIZE: &str = "return_data_size"; + +pub static SET_IMMUTABLE_DATA: &str = "set_immutable_data"; + +pub static VALUE_TRANSFERRED: &str = "value_transferred"; + +/// All imported runtime API symbols. +/// Useful for configuring common attributes and linkage. +pub static IMPORTS: [&str; 23] = [ + SBRK, + MEMORY_SIZE, + ADDRESS, + BALANCE, + BALANCE_OF, + BLOCK_NUMBER, + CALL, + CALLER, + CHAIN_ID, + CODE_SIZE, + DEPOSIT_EVENT, + GET_IMMUTABLE_DATA, + GET_STORAGE, + HASH_KECCAK_256, + INPUT, + INSTANTIATE, + NOW, + RETURN, + RETURNDATACOPY, + RETURNDATASIZE, + SET_IMMUTABLE_DATA, + SET_STORAGE, + VALUE_TRANSFERRED, +]; + /// Creates a LLVM module from the [BITCODE]. /// The module imports `pallet-revive` runtime API functions. /// Returns `Error` if the bitcode fails to parse, which should never happen.