mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-19 05:11:03 +00:00
@@ -16,8 +16,8 @@ pub const BIT_LENGTH_X64: usize = crate::byte_length::BYTE_LENGTH_X64 * BIT_LENG
|
|||||||
pub const BIT_LENGTH_ETH_ADDRESS: usize =
|
pub const BIT_LENGTH_ETH_ADDRESS: usize =
|
||||||
crate::byte_length::BYTE_LENGTH_ETH_ADDRESS * BIT_LENGTH_BYTE;
|
crate::byte_length::BYTE_LENGTH_ETH_ADDRESS * BIT_LENGTH_BYTE;
|
||||||
|
|
||||||
/// The field (usually `u256` or `i256`) bit-length.
|
/// The VM word (usually `u256` or `i256`) bit-length.
|
||||||
pub const BIT_LENGTH_FIELD: usize = crate::byte_length::BYTE_LENGTH_FIELD * BIT_LENGTH_BYTE;
|
pub const BIT_LENGTH_WORD: usize = crate::byte_length::BYTE_LENGTH_WORD * BIT_LENGTH_BYTE;
|
||||||
|
|
||||||
/// Bit length of the runtime value type.
|
/// Bit length of the runtime value type.
|
||||||
pub const BIT_LENGTH_VALUE: usize = crate::byte_length::BYTE_LENGTH_VALUE * BIT_LENGTH_BYTE;
|
pub const BIT_LENGTH_VALUE: usize = crate::byte_length::BYTE_LENGTH_VALUE * BIT_LENGTH_BYTE;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ pub const BYTE_LENGTH_X64: usize = 8;
|
|||||||
/// The ETH address byte-length.
|
/// The ETH address byte-length.
|
||||||
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
|
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
|
||||||
|
|
||||||
/// The field byte-length.
|
/// The word byte-length.
|
||||||
pub const BYTE_LENGTH_FIELD: usize = 32;
|
pub const BYTE_LENGTH_WORD: usize = 32;
|
||||||
|
|
||||||
/// Byte length of the runtime value type.
|
/// Byte length of the runtime value type.
|
||||||
pub const BYTE_LENGTH_VALUE: usize = 16;
|
pub const BYTE_LENGTH_VALUE: usize = 16;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Fibonacci": 5971,
|
"ERC20": 53171,
|
||||||
"Baseline": 3912,
|
"Baseline": 3912,
|
||||||
"Computation": 7380,
|
"Flipper": 4353,
|
||||||
"Flipper": 4354,
|
"Fibonacci": 5971,
|
||||||
"ERC20": 53186
|
"Computation": 7380
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,9 @@ fn link_host_functions(engine: &Engine) -> Linker<State> {
|
|||||||
|caller: Caller<State>, out_ptr: u32, out_len_ptr: u32| -> Result<(), Trap> {
|
|caller: Caller<State>, out_ptr: u32, out_len_ptr: u32| -> Result<(), Trap> {
|
||||||
let (mut caller, state) = caller.split();
|
let (mut caller, state) = caller.split();
|
||||||
|
|
||||||
|
let out_len = caller.read_u32(out_len_ptr)?;
|
||||||
|
assert_eq!(out_len, 16, "spurious output buffer size: {out_len}");
|
||||||
|
|
||||||
let value = state.value.to_le_bytes();
|
let value = state.value.to_le_bytes();
|
||||||
|
|
||||||
caller.write_memory(out_ptr, &value)?;
|
caller.write_memory(out_ptr, &value)?;
|
||||||
@@ -152,7 +155,7 @@ fn link_host_functions(engine: &Engine) -> Linker<State> {
|
|||||||
|
|
||||||
let key = caller.read_memory_into_vec(key_ptr, key_len)?;
|
let key = caller.read_memory_into_vec(key_ptr, key_len)?;
|
||||||
let out_len = caller.read_u32(out_len_ptr)?;
|
let out_len = caller.read_u32(out_len_ptr)?;
|
||||||
assert!(out_len >= 32);
|
assert_eq!(out_len, 32, "spurious output buffer size: {out_len}");
|
||||||
|
|
||||||
let value = state
|
let value = state
|
||||||
.storage
|
.storage
|
||||||
|
|||||||
@@ -42,12 +42,15 @@ pub static GLOBAL_CONST_ARRAY_PREFIX: &str = "const_array_";
|
|||||||
/// The global verbatim getter identifier prefix.
|
/// The global verbatim getter identifier prefix.
|
||||||
pub static GLOBAL_VERBATIM_GETTER_PREFIX: &str = "get_global::";
|
pub static GLOBAL_VERBATIM_GETTER_PREFIX: &str = "get_global::";
|
||||||
|
|
||||||
|
/// The static word size.
|
||||||
|
pub static GLOBAL_WORD_SIZE: &str = "word_size";
|
||||||
|
|
||||||
/// The external call data offset in the auxiliary heap.
|
/// The external call data offset in the auxiliary heap.
|
||||||
pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0;
|
pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0;
|
||||||
|
|
||||||
/// The constructor return data offset in the auxiliary heap.
|
/// The constructor return data offset in the auxiliary heap.
|
||||||
pub const HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA: u64 =
|
pub const HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA: u64 =
|
||||||
8 * (revive_common::BYTE_LENGTH_FIELD as u64);
|
8 * (revive_common::BYTE_LENGTH_WORD as u64);
|
||||||
|
|
||||||
/// The number of the extra ABI data arguments.
|
/// The number of the extra ABI data arguments.
|
||||||
pub const EXTRA_ABI_DATA_SIZE: usize = 0;
|
pub const EXTRA_ABI_DATA_SIZE: usize = 0;
|
||||||
@@ -71,4 +74,4 @@ pub const SYSTEM_CALL_BIT: bool = true;
|
|||||||
/// - constructor arguments offset (32 bytes)
|
/// - constructor arguments offset (32 bytes)
|
||||||
/// - constructor arguments length (32 bytes)
|
/// - constructor arguments length (32 bytes)
|
||||||
pub const DEPLOYER_CALL_HEADER_SIZE: usize =
|
pub const DEPLOYER_CALL_HEADER_SIZE: usize =
|
||||||
revive_common::BYTE_LENGTH_X32 + (revive_common::BYTE_LENGTH_FIELD * 4);
|
revive_common::BYTE_LENGTH_X32 + (revive_common::BYTE_LENGTH_WORD * 4);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub struct Build {
|
|||||||
/// The PolkaVM text assembly.
|
/// The PolkaVM text assembly.
|
||||||
pub assembly_text: String,
|
pub assembly_text: String,
|
||||||
/// The metadata hash.
|
/// The metadata hash.
|
||||||
pub metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
pub metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||||
/// The PolkaVM binary bytecode.
|
/// The PolkaVM binary bytecode.
|
||||||
pub bytecode: Vec<u8>,
|
pub bytecode: Vec<u8>,
|
||||||
/// The PolkaVM bytecode hash.
|
/// The PolkaVM bytecode hash.
|
||||||
@@ -24,7 +24,7 @@ impl Build {
|
|||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
assembly_text: String,
|
assembly_text: String,
|
||||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||||
bytecode: Vec<u8>,
|
bytecode: Vec<u8>,
|
||||||
bytecode_hash: String,
|
bytecode_hash: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl<'ctx> Intrinsics<'ctx> {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
let void_type = llvm.void_type();
|
let void_type = llvm.void_type();
|
||||||
let bool_type = llvm.bool_type();
|
let bool_type = llvm.bool_type();
|
||||||
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32);
|
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32);
|
||||||
let _stack_field_pointer_type = llvm.ptr_type(AddressSpace::Stack.into());
|
let _stack_field_pointer_type = llvm.ptr_type(AddressSpace::Stack.into());
|
||||||
let heap_field_pointer_type = llvm.ptr_type(AddressSpace::Heap.into());
|
let heap_field_pointer_type = llvm.ptr_type(AddressSpace::Heap.into());
|
||||||
let generic_byte_pointer_type = llvm.ptr_type(AddressSpace::Generic.into());
|
let generic_byte_pointer_type = llvm.ptr_type(AddressSpace::Generic.into());
|
||||||
@@ -114,7 +114,7 @@ impl<'ctx> Intrinsics<'ctx> {
|
|||||||
llvm: &'ctx inkwell::context::Context,
|
llvm: &'ctx inkwell::context::Context,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> Vec<inkwell::types::BasicTypeEnum<'ctx>> {
|
) -> Vec<inkwell::types::BasicTypeEnum<'ctx>> {
|
||||||
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32);
|
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32);
|
||||||
|
|
||||||
match name {
|
match name {
|
||||||
name if name == Self::FUNCTION_MEMORY_COPY => vec![
|
name if name == Self::FUNCTION_MEMORY_COPY => vec![
|
||||||
|
|||||||
@@ -187,10 +187,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let div = Self::declare(
|
let div = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_DIV,
|
Self::FUNCTION_DIV,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -206,10 +206,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let r#mod = Self::declare(
|
let r#mod = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_MOD,
|
Self::FUNCTION_MOD,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -225,10 +225,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let sdiv = Self::declare(
|
let sdiv = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SDIV,
|
Self::FUNCTION_SDIV,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -244,10 +244,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let smod = Self::declare(
|
let smod = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SMOD,
|
Self::FUNCTION_SMOD,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -263,10 +263,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let shl = Self::declare(
|
let shl = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SHL,
|
Self::FUNCTION_SHL,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -282,10 +282,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let shr = Self::declare(
|
let shr = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SHR,
|
Self::FUNCTION_SHR,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -301,10 +301,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let sar = Self::declare(
|
let sar = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SAR,
|
Self::FUNCTION_SAR,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -320,10 +320,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let byte = Self::declare(
|
let byte = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_BYTE,
|
Self::FUNCTION_BYTE,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
2
|
2
|
||||||
@@ -358,13 +358,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let sha3 = Self::declare(
|
let sha3 = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SHA3,
|
Self::FUNCTION_SHA3,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.ptr_type(AddressSpace::Heap.into())
|
llvm.ptr_type(AddressSpace::Heap.into())
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BOOLEAN as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BOOLEAN as u32)
|
||||||
@@ -388,16 +388,16 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
let system_request = Self::declare(
|
let system_request = Self::declare(
|
||||||
module,
|
module,
|
||||||
Self::FUNCTION_SYSTEM_REQUEST,
|
Self::FUNCTION_SYSTEM_REQUEST,
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.fn_type(
|
.fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
llvm.ptr_type(AddressSpace::Stack.into())
|
llvm.ptr_type(AddressSpace::Stack.into())
|
||||||
@@ -412,7 +412,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
Function::set_default_attributes(llvm, system_request, optimizer);
|
Function::set_default_attributes(llvm, system_request, optimizer);
|
||||||
|
|
||||||
let external_call_arguments: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
|
let external_call_arguments: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
crate::polkavm::context::function::runtime::entry::Entry::MANDATORY_ARGUMENTS_COUNT
|
crate::polkavm::context::function::runtime::entry::Entry::MANDATORY_ARGUMENTS_COUNT
|
||||||
@@ -420,7 +420,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
];
|
];
|
||||||
let mut mimic_call_arguments = external_call_arguments.clone();
|
let mut mimic_call_arguments = external_call_arguments.clone();
|
||||||
mimic_call_arguments.push(
|
mimic_call_arguments.push(
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
@@ -429,13 +429,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
llvm.ptr_type(AddressSpace::Generic.into())
|
llvm.ptr_type(AddressSpace::Generic.into())
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
];
|
];
|
||||||
external_call_arguments_by_ref.extend::<Vec<inkwell::types::BasicMetadataTypeEnum>>(vec![
|
external_call_arguments_by_ref.extend::<Vec<inkwell::types::BasicMetadataTypeEnum>>(vec![
|
||||||
llvm.custom_width_int_type(
|
llvm.custom_width_int_type(
|
||||||
revive_common::BIT_LENGTH_FIELD as u32
|
revive_common::BIT_LENGTH_WORD as u32
|
||||||
)
|
)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
@@ -443,7 +443,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
]);
|
]);
|
||||||
let mut mimic_call_arguments_by_ref = external_call_arguments_by_ref.clone();
|
let mut mimic_call_arguments_by_ref = external_call_arguments_by_ref.clone();
|
||||||
mimic_call_arguments_by_ref.push(
|
mimic_call_arguments_by_ref.push(
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
@@ -522,7 +522,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
Self::FUNCTION_RETURN,
|
Self::FUNCTION_RETURN,
|
||||||
llvm.void_type().fn_type(
|
llvm.void_type().fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
3
|
3
|
||||||
@@ -538,7 +538,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
|||||||
Self::FUNCTION_REVERT,
|
Self::FUNCTION_REVERT,
|
||||||
llvm.void_type().fn_type(
|
llvm.void_type().fn_type(
|
||||||
vec![
|
vec![
|
||||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
.as_basic_type_enum()
|
.as_basic_type_enum()
|
||||||
.into();
|
.into();
|
||||||
3
|
3
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl<'ctx> Return<'ctx> {
|
|||||||
|
|
||||||
/// Returns the return data size in bytes, based on the default stack alignment.
|
/// Returns the return data size in bytes, based on the default stack alignment.
|
||||||
pub fn return_data_size(&self) -> usize {
|
pub fn return_data_size(&self) -> usize {
|
||||||
revive_common::BYTE_LENGTH_FIELD
|
revive_common::BYTE_LENGTH_WORD
|
||||||
* match self {
|
* match self {
|
||||||
Self::None => 0,
|
Self::None => 0,
|
||||||
Self::Primitive { .. } => 1,
|
Self::Primitive { .. } => 1,
|
||||||
|
|||||||
@@ -81,12 +81,12 @@ where
|
|||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let function_type = context.function_type(
|
let function_type = context.function_type(
|
||||||
vec![
|
vec![
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
false,
|
false,
|
||||||
@@ -144,7 +144,7 @@ where
|
|||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
|
|
||||||
let status_code_result_pointer = context.build_alloca(
|
let status_code_result_pointer = context.build_alloca(
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
"contract_call_result_status_code_pointer",
|
"contract_call_result_status_code_pointer",
|
||||||
);
|
);
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -62,19 +62,19 @@ where
|
|||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
context.set_code_type(CodeType::Deploy);
|
context.set_code_type(CodeType::Deploy);
|
||||||
if let Some(vyper) = context.vyper_data.as_ref() {
|
if let Some(vyper) = context.vyper_data.as_ref() {
|
||||||
for index in 0..vyper.immutables_size() / revive_common::BYTE_LENGTH_FIELD {
|
for index in 0..vyper.immutables_size() / revive_common::BYTE_LENGTH_WORD {
|
||||||
let offset = (crate::polkavm::r#const::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
let offset = (crate::polkavm::r#const::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||||
as usize)
|
as usize)
|
||||||
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_FIELD;
|
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_WORD;
|
||||||
let value = index * revive_common::BYTE_LENGTH_FIELD;
|
let value = index * revive_common::BYTE_LENGTH_WORD;
|
||||||
let pointer = Pointer::new_with_offset(
|
let pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::HeapAuxiliary,
|
AddressSpace::HeapAuxiliary,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
context.field_const(offset as u64),
|
context.word_const(offset as u64),
|
||||||
"immutable_index_initializer",
|
"immutable_index_initializer",
|
||||||
);
|
);
|
||||||
context.build_store(pointer, context.field_const(value as u64))?;
|
context.build_store(pointer, context.word_const(value as u64))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ where
|
|||||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
let function_type = context.function_type(
|
let function_type = context.function_type(
|
||||||
vec![
|
vec![
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
1,
|
1,
|
||||||
false,
|
false,
|
||||||
@@ -124,7 +124,7 @@ where
|
|||||||
let signature_pointer = Pointer::new_with_offset(
|
let signature_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
self.address_space,
|
self.address_space,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
input_offset,
|
input_offset,
|
||||||
"deployer_call_signature_pointer",
|
"deployer_call_signature_pointer",
|
||||||
);
|
);
|
||||||
@@ -132,13 +132,13 @@ where
|
|||||||
|
|
||||||
let salt_offset = context.builder().build_int_add(
|
let salt_offset = context.builder().build_int_add(
|
||||||
input_offset,
|
input_offset,
|
||||||
context.field_const(revive_common::BYTE_LENGTH_X32 as u64),
|
context.word_const(revive_common::BYTE_LENGTH_X32 as u64),
|
||||||
"deployer_call_salt_offset",
|
"deployer_call_salt_offset",
|
||||||
)?;
|
)?;
|
||||||
let salt_pointer = Pointer::new_with_offset(
|
let salt_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
self.address_space,
|
self.address_space,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
salt_offset,
|
salt_offset,
|
||||||
"deployer_call_salt_pointer",
|
"deployer_call_salt_pointer",
|
||||||
);
|
);
|
||||||
@@ -146,47 +146,47 @@ where
|
|||||||
|
|
||||||
let arguments_offset_offset = context.builder().build_int_add(
|
let arguments_offset_offset = context.builder().build_int_add(
|
||||||
salt_offset,
|
salt_offset,
|
||||||
context.field_const((revive_common::BYTE_LENGTH_FIELD * 2) as u64),
|
context.word_const((revive_common::BYTE_LENGTH_WORD * 2) as u64),
|
||||||
"deployer_call_arguments_offset_offset",
|
"deployer_call_arguments_offset_offset",
|
||||||
)?;
|
)?;
|
||||||
let arguments_offset_pointer = Pointer::new_with_offset(
|
let arguments_offset_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
self.address_space,
|
self.address_space,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
arguments_offset_offset,
|
arguments_offset_offset,
|
||||||
"deployer_call_arguments_offset_pointer",
|
"deployer_call_arguments_offset_pointer",
|
||||||
);
|
);
|
||||||
context.build_store(
|
context.build_store(
|
||||||
arguments_offset_pointer,
|
arguments_offset_pointer,
|
||||||
context.field_const(
|
context.word_const(
|
||||||
(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE
|
(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE
|
||||||
- (revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD))
|
- (revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD))
|
||||||
as u64,
|
as u64,
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let arguments_length_offset = context.builder().build_int_add(
|
let arguments_length_offset = context.builder().build_int_add(
|
||||||
arguments_offset_offset,
|
arguments_offset_offset,
|
||||||
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
|
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
||||||
"deployer_call_arguments_length_offset",
|
"deployer_call_arguments_length_offset",
|
||||||
)?;
|
)?;
|
||||||
let arguments_length_pointer = Pointer::new_with_offset(
|
let arguments_length_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
self.address_space,
|
self.address_space,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
arguments_length_offset,
|
arguments_length_offset,
|
||||||
"deployer_call_arguments_length_pointer",
|
"deployer_call_arguments_length_pointer",
|
||||||
);
|
);
|
||||||
let arguments_length_value = context.builder().build_int_sub(
|
let arguments_length_value = context.builder().build_int_sub(
|
||||||
input_length,
|
input_length,
|
||||||
context.field_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64),
|
context.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64),
|
||||||
"deployer_call_arguments_length",
|
"deployer_call_arguments_length",
|
||||||
)?;
|
)?;
|
||||||
context.build_store(arguments_length_pointer, arguments_length_value)?;
|
context.build_store(arguments_length_pointer, arguments_length_value)?;
|
||||||
|
|
||||||
let result_pointer =
|
let result_pointer =
|
||||||
context.build_alloca(context.field_type(), "deployer_call_result_pointer");
|
context.build_alloca(context.word_type(), "deployer_call_result_pointer");
|
||||||
context.build_store(result_pointer, context.field_const(0))?;
|
context.build_store(result_pointer, context.word_const(0))?;
|
||||||
let deployer_call_result_type = context.structure_type(&[
|
let deployer_call_result_type = context.structure_type(&[
|
||||||
context
|
context
|
||||||
.llvm()
|
.llvm()
|
||||||
@@ -203,7 +203,7 @@ where
|
|||||||
let is_value_zero = context.builder().build_int_compare(
|
let is_value_zero = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
value,
|
value,
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
"deployer_call_is_value_zero",
|
"deployer_call_is_value_zero",
|
||||||
)?;
|
)?;
|
||||||
context.build_conditional_branch(is_value_zero, value_zero_block, value_non_zero_block)?;
|
context.build_conditional_branch(is_value_zero, value_zero_block, value_non_zero_block)?;
|
||||||
@@ -252,7 +252,7 @@ where
|
|||||||
let result_abi_data_pointer = context.build_gep(
|
let result_abi_data_pointer = context.build_gep(
|
||||||
deployer_call_result_pointer,
|
deployer_call_result_pointer,
|
||||||
&[
|
&[
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
context
|
context
|
||||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||||
.const_zero(),
|
.const_zero(),
|
||||||
@@ -269,7 +269,7 @@ where
|
|||||||
let result_status_code_pointer = context.build_gep(
|
let result_status_code_pointer = context.build_gep(
|
||||||
deployer_call_result_pointer,
|
deployer_call_result_pointer,
|
||||||
&[
|
&[
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
context
|
context
|
||||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||||
.const_int(1, false),
|
.const_int(1, false),
|
||||||
@@ -288,7 +288,7 @@ where
|
|||||||
|
|
||||||
context.set_basic_block(success_block);
|
context.set_basic_block(success_block);
|
||||||
let result_abi_data_pointer = Pointer::new(
|
let result_abi_data_pointer = Pointer::new(
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
AddressSpace::Generic,
|
AddressSpace::Generic,
|
||||||
result_abi_data.into_pointer_value(),
|
result_abi_data.into_pointer_value(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -55,26 +55,26 @@ impl Entry {
|
|||||||
|
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
AddressSpace::Stack,
|
AddressSpace::Stack,
|
||||||
context.field_undef(),
|
context.word_undef(),
|
||||||
);
|
);
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
AddressSpace::Stack,
|
AddressSpace::Stack,
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
);
|
);
|
||||||
|
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_CALL_FLAGS,
|
crate::polkavm::GLOBAL_CALL_FLAGS,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
AddressSpace::Stack,
|
AddressSpace::Stack,
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
);
|
);
|
||||||
|
|
||||||
let extra_abi_data_type = context.array_type(
|
let extra_abi_data_type = context.array_type(
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
crate::polkavm::EXTRA_ABI_DATA_SIZE,
|
crate::polkavm::EXTRA_ABI_DATA_SIZE,
|
||||||
);
|
);
|
||||||
context.set_global(
|
context.set_global(
|
||||||
@@ -84,6 +84,13 @@ impl Entry {
|
|||||||
extra_abi_data_type.const_zero(),
|
extra_abi_data_type.const_zero(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
context.set_global(
|
||||||
|
crate::polkavm::GLOBAL_WORD_SIZE,
|
||||||
|
context.xlen_type(),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
context.integer_const(crate::polkavm::XLEN, revive_common::BYTE_LENGTH_WORD as u64),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,12 +132,12 @@ impl Entry {
|
|||||||
.into_int_value();
|
.into_int_value();
|
||||||
let calldata_size_casted = context.builder().build_int_z_extend(
|
let calldata_size_casted = context.builder().build_int_z_extend(
|
||||||
calldata_size,
|
calldata_size,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
"zext_input_len",
|
"zext_input_len",
|
||||||
)?;
|
)?;
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
AddressSpace::Stack,
|
AddressSpace::Stack,
|
||||||
calldata_size_casted,
|
calldata_size_casted,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ where
|
|||||||
pub fn build(
|
pub fn build(
|
||||||
mut self,
|
mut self,
|
||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let module_clone = self.module.clone();
|
let module_clone = self.module.clone();
|
||||||
|
|
||||||
@@ -437,12 +437,12 @@ where
|
|||||||
0 => FunctionReturn::none(),
|
0 => FunctionReturn::none(),
|
||||||
1 => {
|
1 => {
|
||||||
self.set_basic_block(entry_block);
|
self.set_basic_block(entry_block);
|
||||||
let pointer = self.build_alloca(self.field_type(), "return_pointer");
|
let pointer = self.build_alloca(self.word_type(), "return_pointer");
|
||||||
FunctionReturn::primitive(pointer)
|
FunctionReturn::primitive(pointer)
|
||||||
}
|
}
|
||||||
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
|
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
|
||||||
let first_argument = value.get_first_param().expect("Always exists");
|
let first_argument = value.get_first_param().expect("Always exists");
|
||||||
let r#type = self.structure_type(vec![self.field_type(); size].as_slice());
|
let r#type = self.structure_type(vec![self.word_type(); size].as_slice());
|
||||||
let pointer = first_argument.into_pointer_value();
|
let pointer = first_argument.into_pointer_value();
|
||||||
FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size)
|
FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size)
|
||||||
}
|
}
|
||||||
@@ -450,7 +450,7 @@ where
|
|||||||
self.set_basic_block(entry_block);
|
self.set_basic_block(entry_block);
|
||||||
let pointer = self.build_alloca(
|
let pointer = self.build_alloca(
|
||||||
self.structure_type(
|
self.structure_type(
|
||||||
vec![self.field_type().as_basic_type_enum(); size].as_slice(),
|
vec![self.word_type().as_basic_type_enum(); size].as_slice(),
|
||||||
),
|
),
|
||||||
"return_pointer",
|
"return_pointer",
|
||||||
);
|
);
|
||||||
@@ -561,7 +561,7 @@ where
|
|||||||
.ok_or_else(|| anyhow::anyhow!("The dependency manager is unset"))
|
.ok_or_else(|| anyhow::anyhow!("The dependency manager is unset"))
|
||||||
.and_then(|manager| {
|
.and_then(|manager| {
|
||||||
let address = manager.resolve_library(path)?;
|
let address = manager.resolve_library(path)?;
|
||||||
let address = self.field_const_str_hex(address.as_str());
|
let address = self.word_const_str_hex(address.as_str());
|
||||||
Ok(address)
|
Ok(address)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -647,7 +647,7 @@ where
|
|||||||
AddressSpace::Storage => {
|
AddressSpace::Storage => {
|
||||||
let storage_key_value = self.builder().build_ptr_to_int(
|
let storage_key_value = self.builder().build_ptr_to_int(
|
||||||
pointer.value,
|
pointer.value,
|
||||||
self.field_type(),
|
self.word_type(),
|
||||||
"storage_ptr_to_int",
|
"storage_ptr_to_int",
|
||||||
)?;
|
)?;
|
||||||
let storage_key_pointer =
|
let storage_key_pointer =
|
||||||
@@ -658,7 +658,7 @@ where
|
|||||||
"storage_key_pointer_casted",
|
"storage_key_pointer_casted",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let storage_value_pointer = self.build_alloca(self.field_type(), "storage_value");
|
let storage_value_pointer = self.build_alloca(self.word_type(), "storage_value");
|
||||||
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
||||||
storage_value_pointer.value,
|
storage_value_pointer.value,
|
||||||
self.xlen_type(),
|
self.xlen_type(),
|
||||||
@@ -679,7 +679,7 @@ where
|
|||||||
storage_value_length_pointer.value,
|
storage_value_length_pointer.value,
|
||||||
self.integer_const(
|
self.integer_const(
|
||||||
crate::polkavm::XLEN,
|
crate::polkavm::XLEN,
|
||||||
revive_common::BIT_LENGTH_FIELD as u64,
|
revive_common::BYTE_LENGTH_WORD as u64,
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -745,7 +745,7 @@ where
|
|||||||
|
|
||||||
let value = value.as_basic_value_enum();
|
let value = value.as_basic_value_enum();
|
||||||
let value = match value.get_type().into_int_type().get_bit_width() as usize {
|
let value = match value.get_type().into_int_type().get_bit_width() as usize {
|
||||||
revive_common::BIT_LENGTH_FIELD => self.build_byte_swap(value),
|
revive_common::BIT_LENGTH_WORD => self.build_byte_swap(value),
|
||||||
revive_common::BIT_LENGTH_BYTE => value,
|
revive_common::BIT_LENGTH_BYTE => value,
|
||||||
_ => unreachable!("Only word and byte sized values can be stored on EVM heap"),
|
_ => unreachable!("Only word and byte sized values can be stored on EVM heap"),
|
||||||
};
|
};
|
||||||
@@ -759,7 +759,7 @@ where
|
|||||||
AddressSpace::Storage => {
|
AddressSpace::Storage => {
|
||||||
let storage_key_value = self.builder().build_ptr_to_int(
|
let storage_key_value = self.builder().build_ptr_to_int(
|
||||||
pointer.value,
|
pointer.value,
|
||||||
self.field_type(),
|
self.word_type(),
|
||||||
"storage_ptr_to_int",
|
"storage_ptr_to_int",
|
||||||
)?;
|
)?;
|
||||||
let storage_key_pointer =
|
let storage_key_pointer =
|
||||||
@@ -1052,18 +1052,18 @@ where
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let pointer_casted = self.builder.build_ptr_to_int(
|
let pointer_casted = self.builder.build_ptr_to_int(
|
||||||
source.value,
|
source.value,
|
||||||
self.field_type(),
|
self.word_type(),
|
||||||
format!("{name}_pointer_casted").as_str(),
|
format!("{name}_pointer_casted").as_str(),
|
||||||
)?;
|
)?;
|
||||||
let return_data_size_shifted = self.builder.build_right_shift(
|
let return_data_size_shifted = self.builder.build_right_shift(
|
||||||
pointer_casted,
|
pointer_casted,
|
||||||
self.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
|
self.word_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
|
||||||
false,
|
false,
|
||||||
format!("{name}_return_data_size_shifted").as_str(),
|
format!("{name}_return_data_size_shifted").as_str(),
|
||||||
)?;
|
)?;
|
||||||
let return_data_size_truncated = self.builder.build_and(
|
let return_data_size_truncated = self.builder.build_and(
|
||||||
return_data_size_shifted,
|
return_data_size_shifted,
|
||||||
self.field_const(u32::MAX as u64),
|
self.word_const(u32::MAX as u64),
|
||||||
format!("{name}_return_data_size_truncated").as_str(),
|
format!("{name}_return_data_size_truncated").as_str(),
|
||||||
)?;
|
)?;
|
||||||
let is_return_data_size_lesser = self.builder.build_int_compare(
|
let is_return_data_size_lesser = self.builder.build_int_compare(
|
||||||
@@ -1162,7 +1162,7 @@ where
|
|||||||
)?;
|
)?;
|
||||||
let extended = self.builder().build_int_z_extend_or_bit_cast(
|
let extended = self.builder().build_int_z_extend_or_bit_cast(
|
||||||
truncated,
|
truncated,
|
||||||
self.field_type(),
|
self.word_type(),
|
||||||
"offset_extended",
|
"offset_extended",
|
||||||
)?;
|
)?;
|
||||||
let is_overflow = self.builder().build_int_compare(
|
let is_overflow = self.builder().build_int_compare(
|
||||||
@@ -1337,26 +1337,26 @@ where
|
|||||||
self.integer_type(bit_length).const_int(value, false)
|
self.integer_type(bit_length).const_int(value, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a 256-bit field type constant.
|
/// Returns a word type constant.
|
||||||
pub fn field_const(&self, value: u64) -> inkwell::values::IntValue<'ctx> {
|
pub fn word_const(&self, value: u64) -> inkwell::values::IntValue<'ctx> {
|
||||||
self.field_type().const_int(value, false)
|
self.word_type().const_int(value, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a 256-bit field type undefined value.
|
/// Returns a word type undefined value.
|
||||||
pub fn field_undef(&self) -> inkwell::values::IntValue<'ctx> {
|
pub fn word_undef(&self) -> inkwell::values::IntValue<'ctx> {
|
||||||
self.field_type().get_undef()
|
self.word_type().get_undef()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a field type constant from a decimal string.
|
/// Returns a word type constant from a decimal string.
|
||||||
pub fn field_const_str_dec(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
pub fn word_const_str_dec(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||||
self.field_type()
|
self.word_type()
|
||||||
.const_int_from_string(value, inkwell::types::StringRadix::Decimal)
|
.const_int_from_string(value, inkwell::types::StringRadix::Decimal)
|
||||||
.unwrap_or_else(|| panic!("Invalid string constant `{value}`"))
|
.unwrap_or_else(|| panic!("Invalid string constant `{value}`"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a field type constant from a hexadecimal string.
|
/// Returns a word type constant from a hexadecimal string.
|
||||||
pub fn field_const_str_hex(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
pub fn word_const_str_hex(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||||
self.field_type()
|
self.word_type()
|
||||||
.const_int_from_string(
|
.const_int_from_string(
|
||||||
value.strip_prefix("0x").unwrap_or(value),
|
value.strip_prefix("0x").unwrap_or(value),
|
||||||
inkwell::types::StringRadix::Hexadecimal,
|
inkwell::types::StringRadix::Hexadecimal,
|
||||||
@@ -1396,10 +1396,10 @@ where
|
|||||||
.custom_width_int_type(revive_common::BIT_LENGTH_VALUE as u32)
|
.custom_width_int_type(revive_common::BIT_LENGTH_VALUE as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the default field type.
|
/// Returns the default word type.
|
||||||
pub fn field_type(&self) -> inkwell::types::IntType<'ctx> {
|
pub fn word_type(&self) -> inkwell::types::IntType<'ctx> {
|
||||||
self.llvm
|
self.llvm
|
||||||
.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
|
.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the array type with the specified length.
|
/// Returns the array type with the specified length.
|
||||||
@@ -1441,14 +1441,14 @@ where
|
|||||||
.llvm
|
.llvm
|
||||||
.void_type()
|
.void_type()
|
||||||
.fn_type(argument_types.as_slice(), false),
|
.fn_type(argument_types.as_slice(), false),
|
||||||
1 => self.field_type().fn_type(argument_types.as_slice(), false),
|
1 => self.word_type().fn_type(argument_types.as_slice(), false),
|
||||||
_size if is_near_call_abi && self.is_system_mode() => {
|
_size if is_near_call_abi && self.is_system_mode() => {
|
||||||
let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
|
let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
|
||||||
argument_types.insert(0, return_type.as_basic_type_enum().into());
|
argument_types.insert(0, return_type.as_basic_type_enum().into());
|
||||||
return_type.fn_type(argument_types.as_slice(), false)
|
return_type.fn_type(argument_types.as_slice(), false)
|
||||||
}
|
}
|
||||||
size => self
|
size => self
|
||||||
.structure_type(vec![self.field_type().as_basic_type_enum(); size].as_slice())
|
.structure_type(vec![self.word_type().as_basic_type_enum(); size].as_slice())
|
||||||
.fn_type(argument_types.as_slice(), false),
|
.fn_type(argument_types.as_slice(), false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1508,14 +1508,14 @@ where
|
|||||||
inkwell::attributes::AttributeLoc::Param(index as u32),
|
inkwell::attributes::AttributeLoc::Param(index as u32),
|
||||||
self.llvm.create_enum_attribute(
|
self.llvm.create_enum_attribute(
|
||||||
Attribute::Dereferenceable as u32,
|
Attribute::Dereferenceable as u32,
|
||||||
(revive_common::BIT_LENGTH_FIELD * 2) as u64,
|
(revive_common::BIT_LENGTH_WORD * 2) as u64,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
call_site_value.add_attribute(
|
call_site_value.add_attribute(
|
||||||
inkwell::attributes::AttributeLoc::Return,
|
inkwell::attributes::AttributeLoc::Return,
|
||||||
self.llvm.create_enum_attribute(
|
self.llvm.create_enum_attribute(
|
||||||
Attribute::Dereferenceable as u32,
|
Attribute::Dereferenceable as u32,
|
||||||
(revive_common::BIT_LENGTH_FIELD * 2) as u64,
|
(revive_common::BIT_LENGTH_WORD * 2) as u64,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ impl<'ctx> Pointer<'ctx> {
|
|||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
r#type: context.field_type().as_basic_type_enum(),
|
r#type: context.word_type().as_basic_type_enum(),
|
||||||
address_space: AddressSpace::Stack,
|
address_space: AddressSpace::Stack,
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,17 @@ impl<'ctx> Pointer<'ctx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Cast this pointer to a register sized integer value.
|
||||||
|
pub fn to_int<D>(&self, context: &Context<'ctx, D>) -> inkwell::values::IntValue<'ctx>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
context
|
||||||
|
.builder()
|
||||||
|
.build_ptr_to_int(self.value, context.xlen_type(), "ptr_to_xlen")
|
||||||
|
.expect("we should be positioned")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn address_space_cast<D>(
|
pub fn address_space_cast<D>(
|
||||||
self,
|
self,
|
||||||
context: &Context<'ctx, D>,
|
context: &Context<'ctx, D>,
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ impl SolidityData {
|
|||||||
|
|
||||||
/// Returns the current number of immutables values in the contract.
|
/// Returns the current number of immutables values in the contract.
|
||||||
pub fn immutables_size(&self) -> usize {
|
pub fn immutables_size(&self) -> usize {
|
||||||
self.immutables.len() * revive_common::BYTE_LENGTH_FIELD
|
self.immutables.len() * revive_common::BYTE_LENGTH_WORD
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocates memory for an immutable value in the auxiliary heap.
|
/// Allocates memory for an immutable value in the auxiliary heap.
|
||||||
/// If the identifier is already known, just returns its offset.
|
/// If the identifier is already known, just returns its offset.
|
||||||
pub fn allocate_immutable(&mut self, identifier: &str) -> usize {
|
pub fn allocate_immutable(&mut self, identifier: &str) -> usize {
|
||||||
let number_of_elements = self.immutables.len();
|
let number_of_elements = self.immutables.len();
|
||||||
let new_offset = number_of_elements * revive_common::BYTE_LENGTH_FIELD;
|
let new_offset = number_of_elements * revive_common::BYTE_LENGTH_WORD;
|
||||||
*self
|
*self
|
||||||
.immutables
|
.immutables
|
||||||
.entry(identifier.to_owned())
|
.entry(identifier.to_owned())
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ pub fn check_attribute_null_pointer_is_invalid() {
|
|||||||
.add_function(
|
.add_function(
|
||||||
"test",
|
"test",
|
||||||
context
|
context
|
||||||
.field_type()
|
.word_type()
|
||||||
.fn_type(&[context.field_type().into()], false),
|
.fn_type(&[context.word_type().into()], false),
|
||||||
1,
|
1,
|
||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)
|
)
|
||||||
@@ -50,8 +50,8 @@ pub fn check_attribute_optimize_for_size_mode_3() {
|
|||||||
.add_function(
|
.add_function(
|
||||||
"test",
|
"test",
|
||||||
context
|
context
|
||||||
.field_type()
|
.word_type()
|
||||||
.fn_type(&[context.field_type().into()], false),
|
.fn_type(&[context.word_type().into()], false),
|
||||||
1,
|
1,
|
||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)
|
)
|
||||||
@@ -73,8 +73,8 @@ pub fn check_attribute_optimize_for_size_mode_z() {
|
|||||||
.add_function(
|
.add_function(
|
||||||
"test",
|
"test",
|
||||||
context
|
context
|
||||||
.field_type()
|
.word_type()
|
||||||
.fn_type(&[context.field_type().into()], false),
|
.fn_type(&[context.word_type().into()], false),
|
||||||
1,
|
1,
|
||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)
|
)
|
||||||
@@ -96,8 +96,8 @@ pub fn check_attribute_min_size_mode_3() {
|
|||||||
.add_function(
|
.add_function(
|
||||||
"test",
|
"test",
|
||||||
context
|
context
|
||||||
.field_type()
|
.word_type()
|
||||||
.fn_type(&[context.field_type().into()], false),
|
.fn_type(&[context.word_type().into()], false),
|
||||||
1,
|
1,
|
||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)
|
)
|
||||||
@@ -119,8 +119,8 @@ pub fn check_attribute_min_size_mode_z() {
|
|||||||
.add_function(
|
.add_function(
|
||||||
"test",
|
"test",
|
||||||
context
|
context
|
||||||
.field_type()
|
.word_type()
|
||||||
.fn_type(&[context.field_type().into()], false),
|
.fn_type(&[context.word_type().into()], false),
|
||||||
1,
|
1,
|
||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -63,17 +63,17 @@ where
|
|||||||
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
||||||
let join_block = context.append_basic_block("shift_left_join");
|
let join_block = context.append_basic_block("shift_left_join");
|
||||||
|
|
||||||
let result_pointer = context.build_alloca(context.field_type(), "shift_left_result_pointer");
|
let result_pointer = context.build_alloca(context.word_type(), "shift_left_result_pointer");
|
||||||
let condition_is_overflow = context.builder().build_int_compare(
|
let condition_is_overflow = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::UGT,
|
inkwell::IntPredicate::UGT,
|
||||||
shift,
|
shift,
|
||||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||||
"shift_left_is_overflow",
|
"shift_left_is_overflow",
|
||||||
)?;
|
)?;
|
||||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||||
|
|
||||||
context.set_basic_block(overflow_block);
|
context.set_basic_block(overflow_block);
|
||||||
context.build_store(result_pointer, context.field_const(0))?;
|
context.build_store(result_pointer, context.word_const(0))?;
|
||||||
context.build_unconditional_branch(join_block);
|
context.build_unconditional_branch(join_block);
|
||||||
|
|
||||||
context.set_basic_block(non_overflow_block);
|
context.set_basic_block(non_overflow_block);
|
||||||
@@ -101,17 +101,17 @@ where
|
|||||||
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
||||||
let join_block = context.append_basic_block("shift_right_join");
|
let join_block = context.append_basic_block("shift_right_join");
|
||||||
|
|
||||||
let result_pointer = context.build_alloca(context.field_type(), "shift_right_result_pointer");
|
let result_pointer = context.build_alloca(context.word_type(), "shift_right_result_pointer");
|
||||||
let condition_is_overflow = context.builder().build_int_compare(
|
let condition_is_overflow = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::UGT,
|
inkwell::IntPredicate::UGT,
|
||||||
shift,
|
shift,
|
||||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||||
"shift_right_is_overflow",
|
"shift_right_is_overflow",
|
||||||
)?;
|
)?;
|
||||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||||
|
|
||||||
context.set_basic_block(overflow_block);
|
context.set_basic_block(overflow_block);
|
||||||
context.build_store(result_pointer, context.field_const(0))?;
|
context.build_store(result_pointer, context.word_const(0))?;
|
||||||
context.build_unconditional_branch(join_block);
|
context.build_unconditional_branch(join_block);
|
||||||
|
|
||||||
context.set_basic_block(non_overflow_block);
|
context.set_basic_block(non_overflow_block);
|
||||||
@@ -145,14 +145,12 @@ where
|
|||||||
let non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
|
let non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
|
||||||
let join_block = context.append_basic_block("shift_right_arithmetic_join");
|
let join_block = context.append_basic_block("shift_right_arithmetic_join");
|
||||||
|
|
||||||
let result_pointer = context.build_alloca(
|
let result_pointer =
|
||||||
context.field_type(),
|
context.build_alloca(context.word_type(), "shift_right_arithmetic_result_pointer");
|
||||||
"shift_right_arithmetic_result_pointer",
|
|
||||||
);
|
|
||||||
let condition_is_overflow = context.builder().build_int_compare(
|
let condition_is_overflow = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::UGT,
|
inkwell::IntPredicate::UGT,
|
||||||
shift,
|
shift,
|
||||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||||
"shift_right_arithmetic_is_overflow",
|
"shift_right_arithmetic_is_overflow",
|
||||||
)?;
|
)?;
|
||||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||||
@@ -160,7 +158,7 @@ where
|
|||||||
context.set_basic_block(overflow_block);
|
context.set_basic_block(overflow_block);
|
||||||
let sign_bit = context.builder().build_right_shift(
|
let sign_bit = context.builder().build_right_shift(
|
||||||
value,
|
value,
|
||||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||||
false,
|
false,
|
||||||
"shift_right_arithmetic_sign_bit",
|
"shift_right_arithmetic_sign_bit",
|
||||||
)?;
|
)?;
|
||||||
@@ -176,11 +174,11 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.set_basic_block(overflow_positive_block);
|
context.set_basic_block(overflow_positive_block);
|
||||||
context.build_store(result_pointer, context.field_const(0))?;
|
context.build_store(result_pointer, context.word_const(0))?;
|
||||||
context.build_unconditional_branch(join_block);
|
context.build_unconditional_branch(join_block);
|
||||||
|
|
||||||
context.set_basic_block(overflow_negative_block);
|
context.set_basic_block(overflow_negative_block);
|
||||||
context.build_store(result_pointer, context.field_type().const_all_ones())?;
|
context.build_store(result_pointer, context.word_type().const_all_ones())?;
|
||||||
context.build_unconditional_branch(join_block);
|
context.build_unconditional_branch(join_block);
|
||||||
|
|
||||||
context.set_basic_block(non_overflow_block);
|
context.set_basic_block(non_overflow_block);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ where
|
|||||||
let offset = context.build_gep(
|
let offset = context.build_gep(
|
||||||
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
||||||
&[offset],
|
&[offset],
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
"calldata_pointer_with_offset",
|
"calldata_pointer_with_offset",
|
||||||
);
|
);
|
||||||
context
|
context
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ where
|
|||||||
)?;
|
)?;
|
||||||
let result = context.builder().build_int_z_extend_or_bit_cast(
|
let result = context.builder().build_int_z_extend_or_bit_cast(
|
||||||
result,
|
result,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
"comparison_result_extended",
|
"comparison_result_extended",
|
||||||
)?;
|
)?;
|
||||||
Ok(result.as_basic_value_enum())
|
Ok(result.as_basic_value_enum())
|
||||||
|
|||||||
@@ -129,6 +129,6 @@ where
|
|||||||
)?;
|
)?;
|
||||||
Ok(context
|
Ok(context
|
||||||
.builder()
|
.builder()
|
||||||
.build_int_z_extend(heap_size, context.field_type(), "heap_size_extended")?
|
.build_int_z_extend(heap_size, context.word_type(), "heap_size_extended")?
|
||||||
.as_basic_value_enum())
|
.as_basic_value_enum())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ where
|
|||||||
{
|
{
|
||||||
let signature_hash_string =
|
let signature_hash_string =
|
||||||
crate::polkavm::utils::keccak256(crate::polkavm::DEPLOYER_SIGNATURE_CREATE.as_bytes());
|
crate::polkavm::utils::keccak256(crate::polkavm::DEPLOYER_SIGNATURE_CREATE.as_bytes());
|
||||||
let signature_hash = context.field_const_str_hex(signature_hash_string.as_str());
|
let signature_hash = context.word_const_str_hex(signature_hash_string.as_str());
|
||||||
|
|
||||||
let salt = context.field_const(0);
|
let salt = context.word_const(0);
|
||||||
|
|
||||||
let function = Runtime::deployer_call(context);
|
let function = Runtime::deployer_call(context);
|
||||||
let result = context
|
let result = context
|
||||||
@@ -58,9 +58,9 @@ where
|
|||||||
{
|
{
|
||||||
let signature_hash_string =
|
let signature_hash_string =
|
||||||
crate::polkavm::utils::keccak256(crate::polkavm::DEPLOYER_SIGNATURE_CREATE2.as_bytes());
|
crate::polkavm::utils::keccak256(crate::polkavm::DEPLOYER_SIGNATURE_CREATE2.as_bytes());
|
||||||
let signature_hash = context.field_const_str_hex(signature_hash_string.as_str());
|
let signature_hash = context.word_const_str_hex(signature_hash_string.as_str());
|
||||||
|
|
||||||
let salt = salt.unwrap_or_else(|| context.field_const(0));
|
let salt = salt.unwrap_or_else(|| context.word_const(0));
|
||||||
|
|
||||||
let function = Runtime::deployer_call(context);
|
let function = Runtime::deployer_call(context);
|
||||||
let result = context
|
let result = context
|
||||||
@@ -107,7 +107,7 @@ where
|
|||||||
})?;
|
})?;
|
||||||
if contract_path.as_str() == parent {
|
if contract_path.as_str() == parent {
|
||||||
return Ok(Argument::new_with_constant(
|
return Ok(Argument::new_with_constant(
|
||||||
context.field_const(0).as_basic_value_enum(),
|
context.word_const(0).as_basic_value_enum(),
|
||||||
num::BigUint::zero(),
|
num::BigUint::zero(),
|
||||||
));
|
));
|
||||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||||
@@ -116,7 +116,7 @@ where
|
|||||||
|
|
||||||
let hash_string = context.compile_dependency(identifier.as_str())?;
|
let hash_string = context.compile_dependency(identifier.as_str())?;
|
||||||
let hash_value = context
|
let hash_value = context
|
||||||
.field_const_str_hex(hash_string.as_str())
|
.word_const_str_hex(hash_string.as_str())
|
||||||
.as_basic_value_enum();
|
.as_basic_value_enum();
|
||||||
Ok(Argument::new_with_original(hash_value, hash_string))
|
Ok(Argument::new_with_original(hash_value, hash_string))
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ where
|
|||||||
})?;
|
})?;
|
||||||
if contract_path.as_str() == parent {
|
if contract_path.as_str() == parent {
|
||||||
return Ok(Argument::new_with_constant(
|
return Ok(Argument::new_with_constant(
|
||||||
context.field_const(0).as_basic_value_enum(),
|
context.word_const(0).as_basic_value_enum(),
|
||||||
num::BigUint::zero(),
|
num::BigUint::zero(),
|
||||||
));
|
));
|
||||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||||
@@ -164,7 +164,7 @@ where
|
|||||||
|
|
||||||
let size_bigint = num::BigUint::from(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE);
|
let size_bigint = num::BigUint::from(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE);
|
||||||
let size_value = context
|
let size_value = context
|
||||||
.field_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
|
.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
|
||||||
.as_basic_value_enum();
|
.as_basic_value_enum();
|
||||||
Ok(Argument::new_with_constant(size_value, size_bigint))
|
Ok(Argument::new_with_constant(size_value, size_bigint))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,25 +16,14 @@ where
|
|||||||
let offset_casted = context.safe_truncate_int_to_xlen(offset)?;
|
let offset_casted = context.safe_truncate_int_to_xlen(offset)?;
|
||||||
let length_casted = context.safe_truncate_int_to_xlen(length)?;
|
let length_casted = context.safe_truncate_int_to_xlen(length)?;
|
||||||
let input_pointer = context.build_heap_gep(offset_casted, length_casted)?;
|
let input_pointer = context.build_heap_gep(offset_casted, length_casted)?;
|
||||||
let input_pointer_casted = context.builder().build_ptr_to_int(
|
let output_pointer = context.build_alloca(context.word_type(), "output_pointer");
|
||||||
input_pointer.value,
|
|
||||||
context.xlen_type(),
|
|
||||||
"input_pointer_casted",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let output_pointer = context.build_alloca(context.field_type(), "output_pointer");
|
|
||||||
let output_pointer_casted = context.builder().build_ptr_to_int(
|
|
||||||
output_pointer.value,
|
|
||||||
context.xlen_type(),
|
|
||||||
"output_pointer_casted",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
context.build_runtime_call(
|
context.build_runtime_call(
|
||||||
runtime_api::HASH_KECCAK_256,
|
runtime_api::HASH_KECCAK_256,
|
||||||
&[
|
&[
|
||||||
input_pointer_casted.into(),
|
input_pointer.to_int(context).into(),
|
||||||
length_casted.into(),
|
length_casted.into(),
|
||||||
output_pointer_casted.into(),
|
output_pointer.to_int(context).into(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ where
|
|||||||
let value = context.build_load(output_pointer, "transferred_value")?;
|
let value = context.build_load(output_pointer, "transferred_value")?;
|
||||||
let value_extended = context.builder().build_int_z_extend(
|
let value_extended = context.builder().build_int_z_extend(
|
||||||
value.into_int_value(),
|
value.into_int_value(),
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
"transferred_value_extended",
|
"transferred_value_extended",
|
||||||
)?;
|
)?;
|
||||||
Ok(value_extended.as_basic_value_enum())
|
Ok(value_extended.as_basic_value_enum())
|
||||||
|
|||||||
@@ -23,21 +23,21 @@ where
|
|||||||
Some(CodeType::Deploy) => {
|
Some(CodeType::Deploy) => {
|
||||||
let index_double = context.builder().build_int_mul(
|
let index_double = context.builder().build_int_mul(
|
||||||
index,
|
index,
|
||||||
context.field_const(2),
|
context.word_const(2),
|
||||||
"immutable_load_index_double",
|
"immutable_load_index_double",
|
||||||
)?;
|
)?;
|
||||||
let offset_absolute = context.builder().build_int_add(
|
let offset_absolute = context.builder().build_int_add(
|
||||||
index_double,
|
index_double,
|
||||||
context.field_const(
|
context.word_const(
|
||||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||||
+ (3 * revive_common::BYTE_LENGTH_FIELD) as u64,
|
+ (3 * revive_common::BYTE_LENGTH_WORD) as u64,
|
||||||
),
|
),
|
||||||
"immutable_offset_absolute",
|
"immutable_offset_absolute",
|
||||||
)?;
|
)?;
|
||||||
let immutable_pointer = Pointer::new_with_offset(
|
let immutable_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::HeapAuxiliary,
|
AddressSpace::HeapAuxiliary,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
offset_absolute,
|
offset_absolute,
|
||||||
"immutable_pointer",
|
"immutable_pointer",
|
||||||
);
|
);
|
||||||
@@ -68,21 +68,21 @@ where
|
|||||||
Some(CodeType::Deploy) => {
|
Some(CodeType::Deploy) => {
|
||||||
let index_double = context.builder().build_int_mul(
|
let index_double = context.builder().build_int_mul(
|
||||||
index,
|
index,
|
||||||
context.field_const(2),
|
context.word_const(2),
|
||||||
"immutable_load_index_double",
|
"immutable_load_index_double",
|
||||||
)?;
|
)?;
|
||||||
let index_offset_absolute = context.builder().build_int_add(
|
let index_offset_absolute = context.builder().build_int_add(
|
||||||
index_double,
|
index_double,
|
||||||
context.field_const(
|
context.word_const(
|
||||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||||
+ (2 * revive_common::BYTE_LENGTH_FIELD) as u64,
|
+ (2 * revive_common::BYTE_LENGTH_WORD) as u64,
|
||||||
),
|
),
|
||||||
"index_offset_absolute",
|
"index_offset_absolute",
|
||||||
)?;
|
)?;
|
||||||
let index_offset_pointer = Pointer::new_with_offset(
|
let index_offset_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::HeapAuxiliary,
|
AddressSpace::HeapAuxiliary,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
index_offset_absolute,
|
index_offset_absolute,
|
||||||
"immutable_index_pointer",
|
"immutable_index_pointer",
|
||||||
);
|
);
|
||||||
@@ -90,13 +90,13 @@ where
|
|||||||
|
|
||||||
let value_offset_absolute = context.builder().build_int_add(
|
let value_offset_absolute = context.builder().build_int_add(
|
||||||
index_offset_absolute,
|
index_offset_absolute,
|
||||||
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
|
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
||||||
"value_offset_absolute",
|
"value_offset_absolute",
|
||||||
)?;
|
)?;
|
||||||
let value_offset_pointer = Pointer::new_with_offset(
|
let value_offset_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::HeapAuxiliary,
|
AddressSpace::HeapAuxiliary,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
value_offset_absolute,
|
value_offset_absolute,
|
||||||
"immutable_value_pointer",
|
"immutable_value_pointer",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ where
|
|||||||
let pointer = Pointer::new_with_offset(
|
let pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::Heap,
|
AddressSpace::Heap,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
offset,
|
offset,
|
||||||
"memory_load_pointer",
|
"memory_load_pointer",
|
||||||
);
|
);
|
||||||
@@ -37,7 +37,7 @@ where
|
|||||||
let pointer = Pointer::new_with_offset(
|
let pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::Heap,
|
AddressSpace::Heap,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
offset,
|
offset,
|
||||||
"memory_store_pointer",
|
"memory_store_pointer",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,22 +24,22 @@ where
|
|||||||
let immutables_offset_pointer = Pointer::new_with_offset(
|
let immutables_offset_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::HeapAuxiliary,
|
AddressSpace::HeapAuxiliary,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
context.field_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
context.word_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||||
"immutables_offset_pointer",
|
"immutables_offset_pointer",
|
||||||
);
|
);
|
||||||
context.build_store(
|
context.build_store(
|
||||||
immutables_offset_pointer,
|
immutables_offset_pointer,
|
||||||
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
|
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let immutables_number_pointer = Pointer::new_with_offset(
|
let immutables_number_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::HeapAuxiliary,
|
AddressSpace::HeapAuxiliary,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
context.field_const(
|
context.word_const(
|
||||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||||
+ (revive_common::BYTE_LENGTH_FIELD as u64),
|
+ (revive_common::BYTE_LENGTH_WORD as u64),
|
||||||
),
|
),
|
||||||
"immutables_number_pointer",
|
"immutables_number_pointer",
|
||||||
);
|
);
|
||||||
@@ -47,22 +47,22 @@ where
|
|||||||
context.build_store(
|
context.build_store(
|
||||||
immutables_number_pointer,
|
immutables_number_pointer,
|
||||||
context
|
context
|
||||||
.field_const((immutable_values_size / revive_common::BYTE_LENGTH_FIELD) as u64),
|
.word_const((immutable_values_size / revive_common::BYTE_LENGTH_WORD) as u64),
|
||||||
)?;
|
)?;
|
||||||
let immutables_size = context.builder().build_int_mul(
|
let immutables_size = context.builder().build_int_mul(
|
||||||
context.field_const(immutable_values_size as u64),
|
context.word_const(immutable_values_size as u64),
|
||||||
context.field_const(2),
|
context.word_const(2),
|
||||||
"immutables_size",
|
"immutables_size",
|
||||||
)?;
|
)?;
|
||||||
let return_data_length = context.builder().build_int_add(
|
let return_data_length = context.builder().build_int_add(
|
||||||
immutables_size,
|
immutables_size,
|
||||||
context.field_const((revive_common::BYTE_LENGTH_FIELD * 2) as u64),
|
context.word_const((revive_common::BYTE_LENGTH_WORD * 2) as u64),
|
||||||
"return_data_length",
|
"return_data_length",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.build_exit(
|
context.build_exit(
|
||||||
context.integer_const(crate::polkavm::XLEN, 0),
|
context.integer_const(crate::polkavm::XLEN, 0),
|
||||||
context.field_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
context.word_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||||
return_data_length,
|
return_data_length,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
@@ -115,8 +115,8 @@ where
|
|||||||
{
|
{
|
||||||
crate::polkavm::evm::memory::store(
|
crate::polkavm::evm::memory::store(
|
||||||
context,
|
context,
|
||||||
context.field_type().const_all_ones(),
|
context.word_type().const_all_ones(),
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
)?;
|
)?;
|
||||||
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ where
|
|||||||
{
|
{
|
||||||
match context.get_global_value(crate::polkavm::GLOBAL_RETURN_DATA_SIZE) {
|
match context.get_global_value(crate::polkavm::GLOBAL_RETURN_DATA_SIZE) {
|
||||||
Ok(global) => Ok(global),
|
Ok(global) => Ok(global),
|
||||||
Err(_error) => Ok(context.field_const(0).as_basic_value_enum()),
|
Err(_error) => Ok(context.word_const(0).as_basic_value_enum()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ where
|
|||||||
context.build_conditional_branch(is_copy_out_of_bounds, error_block, join_block)?;
|
context.build_conditional_branch(is_copy_out_of_bounds, error_block, join_block)?;
|
||||||
|
|
||||||
context.set_basic_block(error_block);
|
context.set_basic_block(error_block);
|
||||||
crate::polkavm::evm::r#return::revert(context, context.field_const(0), context.field_const(0))?;
|
crate::polkavm::evm::r#return::revert(context, context.word_const(0), context.word_const(0))?;
|
||||||
|
|
||||||
context.set_basic_block(join_block);
|
context.set_basic_block(join_block);
|
||||||
let destination = Pointer::new_with_offset(
|
let destination = Pointer::new_with_offset(
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ where
|
|||||||
let position_pointer = Pointer::new_with_offset(
|
let position_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::Storage,
|
AddressSpace::Storage,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
position,
|
position,
|
||||||
"storage_load_position_pointer",
|
"storage_load_position_pointer",
|
||||||
);
|
);
|
||||||
@@ -35,7 +35,7 @@ where
|
|||||||
let position_pointer = Pointer::new_with_offset(
|
let position_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::Storage,
|
AddressSpace::Storage,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
position,
|
position,
|
||||||
"storage_store_position_pointer",
|
"storage_store_position_pointer",
|
||||||
);
|
);
|
||||||
@@ -54,7 +54,7 @@ where
|
|||||||
let position_pointer = Pointer::new_with_offset(
|
let position_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::TransientStorage,
|
AddressSpace::TransientStorage,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
position,
|
position,
|
||||||
"transient_storage_load_position_pointer",
|
"transient_storage_load_position_pointer",
|
||||||
);
|
);
|
||||||
@@ -73,7 +73,7 @@ where
|
|||||||
let position_pointer = Pointer::new_with_offset(
|
let position_pointer = Pointer::new_with_offset(
|
||||||
context,
|
context,
|
||||||
AddressSpace::TransientStorage,
|
AddressSpace::TransientStorage,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
position,
|
position,
|
||||||
"transient_storage_store_position_pointer",
|
"transient_storage_store_position_pointer",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub fn initialize_target() {
|
|||||||
pub fn build_assembly_text(
|
pub fn build_assembly_text(
|
||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
assembly_text: &str,
|
assembly_text: &str,
|
||||||
_metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
_metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||||
debug_config: Option<&DebugConfig>,
|
debug_config: Option<&DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
if let Some(debug_config) = debug_config {
|
if let Some(debug_config) = debug_config {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ where
|
|||||||
let in_bounds_block = context.append_basic_block(format!("{name}_is_bounds_block").as_str());
|
let in_bounds_block = context.append_basic_block(format!("{name}_is_bounds_block").as_str());
|
||||||
let join_block = context.append_basic_block(format!("{name}_join_block").as_str());
|
let join_block = context.append_basic_block(format!("{name}_join_block").as_str());
|
||||||
|
|
||||||
let pointer = context.build_alloca(context.field_type(), format!("{name}_pointer").as_str());
|
let pointer = context.build_alloca(context.word_type(), format!("{name}_pointer").as_str());
|
||||||
context.build_store(pointer, max_value)?;
|
context.build_store(pointer, max_value)?;
|
||||||
|
|
||||||
let is_in_bounds = context.builder().build_int_compare(
|
let is_in_bounds = context.builder().build_int_compare(
|
||||||
@@ -103,13 +103,13 @@ where
|
|||||||
let input_offset = crate::polkavm::utils::clamp(
|
let input_offset = crate::polkavm::utils::clamp(
|
||||||
context,
|
context,
|
||||||
input_offset,
|
input_offset,
|
||||||
context.field_const(u32::MAX as u64),
|
context.word_const(u32::MAX as u64),
|
||||||
"abi_data_input_offset",
|
"abi_data_input_offset",
|
||||||
)?;
|
)?;
|
||||||
let input_length = crate::polkavm::utils::clamp(
|
let input_length = crate::polkavm::utils::clamp(
|
||||||
context,
|
context,
|
||||||
input_length,
|
input_length,
|
||||||
context.field_const(u32::MAX as u64),
|
context.word_const(u32::MAX as u64),
|
||||||
"abi_data_input_length",
|
"abi_data_input_length",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -120,23 +120,23 @@ where
|
|||||||
let gas = crate::polkavm::utils::clamp(
|
let gas = crate::polkavm::utils::clamp(
|
||||||
context,
|
context,
|
||||||
gas,
|
gas,
|
||||||
context.field_const(u32::MAX as u64),
|
context.word_const(u32::MAX as u64),
|
||||||
"abi_data_gas",
|
"abi_data_gas",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let input_offset_shifted = context.builder().build_left_shift(
|
let input_offset_shifted = context.builder().build_left_shift(
|
||||||
input_offset,
|
input_offset,
|
||||||
context.field_const((revive_common::BIT_LENGTH_X32 * 2) as u64),
|
context.word_const((revive_common::BIT_LENGTH_X32 * 2) as u64),
|
||||||
"abi_data_input_offset_shifted",
|
"abi_data_input_offset_shifted",
|
||||||
)?;
|
)?;
|
||||||
let input_length_shifted = context.builder().build_left_shift(
|
let input_length_shifted = context.builder().build_left_shift(
|
||||||
input_length,
|
input_length,
|
||||||
context.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
|
context.word_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
|
||||||
"abi_data_input_length_shifted",
|
"abi_data_input_length_shifted",
|
||||||
)?;
|
)?;
|
||||||
let gas_shifted = context.builder().build_left_shift(
|
let gas_shifted = context.builder().build_left_shift(
|
||||||
gas,
|
gas,
|
||||||
context.field_const((revive_common::BIT_LENGTH_X32 * 6) as u64),
|
context.word_const((revive_common::BIT_LENGTH_X32 * 6) as u64),
|
||||||
"abi_data_gas_shifted",
|
"abi_data_gas_shifted",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -150,8 +150,8 @@ where
|
|||||||
.build_int_add(abi_data, gas_shifted, "abi_data_add_gas")?;
|
.build_int_add(abi_data, gas_shifted, "abi_data_add_gas")?;
|
||||||
if let AddressSpace::HeapAuxiliary = address_space {
|
if let AddressSpace::HeapAuxiliary = address_space {
|
||||||
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
|
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
|
||||||
context.field_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
context.word_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
||||||
context.field_const((revive_common::BIT_LENGTH_X32 * 7) as u64),
|
context.word_const((revive_common::BIT_LENGTH_X32 * 7) as u64),
|
||||||
"abi_data_auxiliary_heap_marker_shifted",
|
"abi_data_auxiliary_heap_marker_shifted",
|
||||||
)?;
|
)?;
|
||||||
abi_data = context.builder().build_int_add(
|
abi_data = context.builder().build_int_add(
|
||||||
@@ -162,8 +162,8 @@ where
|
|||||||
}
|
}
|
||||||
if is_system_call {
|
if is_system_call {
|
||||||
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
|
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
|
||||||
context.field_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
context.word_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
||||||
context.field_const(
|
context.word_const(
|
||||||
((revive_common::BIT_LENGTH_X32 * 7) + (revive_common::BIT_LENGTH_BYTE * 3)) as u64,
|
((revive_common::BIT_LENGTH_X32 * 7) + (revive_common::BIT_LENGTH_BYTE * 3)) as u64,
|
||||||
),
|
),
|
||||||
"abi_data_system_call_marker_shifted",
|
"abi_data_system_call_marker_shifted",
|
||||||
@@ -188,7 +188,7 @@ where
|
|||||||
{
|
{
|
||||||
let mut padded_data = initial_data;
|
let mut padded_data = initial_data;
|
||||||
padded_data.extend(vec![
|
padded_data.extend(vec![
|
||||||
context.field_undef();
|
context.word_undef();
|
||||||
crate::polkavm::EXTRA_ABI_DATA_SIZE - padded_data.len()
|
crate::polkavm::EXTRA_ABI_DATA_SIZE - padded_data.len()
|
||||||
]);
|
]);
|
||||||
padded_data.try_into().expect("Always valid")
|
padded_data.try_into().expect("Always valid")
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ pub static DEFAULT_EXECUTABLE_NAME: &str = "zksolc";
|
|||||||
pub const OFFSET_SCRATCH_SPACE: usize = 0;
|
pub const OFFSET_SCRATCH_SPACE: usize = 0;
|
||||||
|
|
||||||
/// The memory pointer offset.
|
/// The memory pointer offset.
|
||||||
pub const OFFSET_MEMORY_POINTER: usize = 2 * revive_common::BYTE_LENGTH_FIELD;
|
pub const OFFSET_MEMORY_POINTER: usize = 2 * revive_common::BYTE_LENGTH_WORD;
|
||||||
|
|
||||||
/// The empty slot offset.
|
/// The empty slot offset.
|
||||||
pub const OFFSET_EMPTY_SLOT: usize = 3 * revive_common::BYTE_LENGTH_FIELD;
|
pub const OFFSET_EMPTY_SLOT: usize = 3 * revive_common::BYTE_LENGTH_WORD;
|
||||||
|
|
||||||
/// The non-reserved memory offset.
|
/// The non-reserved memory offset.
|
||||||
pub const OFFSET_NON_RESERVED: usize = 4 * revive_common::BYTE_LENGTH_FIELD;
|
pub const OFFSET_NON_RESERVED: usize = 4 * revive_common::BYTE_LENGTH_WORD;
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ where
|
|||||||
{
|
{
|
||||||
let offset = context.builder().build_int_add(
|
let offset = context.builder().build_int_add(
|
||||||
offset,
|
offset,
|
||||||
context.field_const(
|
context
|
||||||
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
|
.word_const((revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD) as u64),
|
||||||
),
|
|
||||||
"datacopy_contract_hash_offset",
|
"datacopy_contract_hash_offset",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -33,8 +32,8 @@ where
|
|||||||
{
|
{
|
||||||
revive_llvm_context::polkavm_evm_memory::store_byte(
|
revive_llvm_context::polkavm_evm_memory::store_byte(
|
||||||
context,
|
context,
|
||||||
context.field_const(offset),
|
context.word_const(offset),
|
||||||
context.field_const(value),
|
context.word_const(value),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -53,21 +52,21 @@ where
|
|||||||
for (index, chunk) in source
|
for (index, chunk) in source
|
||||||
.chars()
|
.chars()
|
||||||
.collect::<Vec<char>>()
|
.collect::<Vec<char>>()
|
||||||
.chunks(revive_common::BYTE_LENGTH_FIELD * 2)
|
.chunks(revive_common::BYTE_LENGTH_WORD * 2)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
{
|
{
|
||||||
let mut value_string = chunk.iter().collect::<String>();
|
let mut value_string = chunk.iter().collect::<String>();
|
||||||
value_string.push_str(
|
value_string.push_str(
|
||||||
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - chunk.len())
|
"0".repeat((revive_common::BYTE_LENGTH_WORD * 2) - chunk.len())
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let datacopy_destination = context.builder().build_int_add(
|
let datacopy_destination = context.builder().build_int_add(
|
||||||
destination,
|
destination,
|
||||||
context.field_const(offset as u64),
|
context.word_const(offset as u64),
|
||||||
format!("datacopy_destination_index_{index}").as_str(),
|
format!("datacopy_destination_index_{index}").as_str(),
|
||||||
)?;
|
)?;
|
||||||
let datacopy_value = context.field_const_str_hex(value_string.as_str());
|
let datacopy_value = context.word_const_str_hex(value_string.as_str());
|
||||||
revive_llvm_context::polkavm_evm_memory::store(
|
revive_llvm_context::polkavm_evm_memory::store(
|
||||||
context,
|
context,
|
||||||
datacopy_destination,
|
datacopy_destination,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ where
|
|||||||
let condition = context.builder().build_int_compare(
|
let condition = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::NE,
|
inkwell::IntPredicate::NE,
|
||||||
condition.into_int_value(),
|
condition.into_int_value(),
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
format!("conditional_{block_key}_condition_compared").as_str(),
|
format!("conditional_{block_key}_condition_compared").as_str(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ impl Instruction {
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut key_extended =
|
let mut key_extended =
|
||||||
"0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - value.len());
|
"0".repeat(revive_common::BYTE_LENGTH_WORD * 2 - value.len());
|
||||||
key_extended.push_str(value.as_str());
|
key_extended.push_str(value.as_str());
|
||||||
|
|
||||||
*value = mapping.get(key_extended.as_str()).cloned().ok_or_else(|| {
|
*value = mapping.get(key_extended.as_str()).cloned().ok_or_else(|| {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ where
|
|||||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||||
{
|
{
|
||||||
let result = context
|
let result = context
|
||||||
.field_type()
|
.word_type()
|
||||||
.const_int_from_string(
|
.const_int_from_string(
|
||||||
value.to_ascii_uppercase().as_str(),
|
value.to_ascii_uppercase().as_str(),
|
||||||
inkwell::types::StringRadix::Hexadecimal,
|
inkwell::types::StringRadix::Hexadecimal,
|
||||||
@@ -30,7 +30,7 @@ where
|
|||||||
D: revive_llvm_context::PolkaVMDependency + Clone,
|
D: revive_llvm_context::PolkaVMDependency + Clone,
|
||||||
{
|
{
|
||||||
let result = context
|
let result = context
|
||||||
.field_type()
|
.word_type()
|
||||||
.const_int_from_string(value.as_str(), inkwell::types::StringRadix::Decimal)
|
.const_int_from_string(value.as_str(), inkwell::types::StringRadix::Decimal)
|
||||||
.expect("Always valid");
|
.expect("Always valid");
|
||||||
Ok(result.as_basic_value_enum())
|
Ok(result.as_basic_value_enum())
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ impl Assembly {
|
|||||||
hash_data_mapping: &BTreeMap<String, String>,
|
hash_data_mapping: &BTreeMap<String, String>,
|
||||||
) -> anyhow::Result<BTreeMap<String, String>> {
|
) -> anyhow::Result<BTreeMap<String, String>> {
|
||||||
let mut index_path_mapping = BTreeMap::new();
|
let mut index_path_mapping = BTreeMap::new();
|
||||||
let index = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2);
|
let index = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2);
|
||||||
index_path_mapping.insert(index, full_path.to_owned());
|
index_path_mapping.insert(index, full_path.to_owned());
|
||||||
|
|
||||||
let dependencies = match self.data.as_mut() {
|
let dependencies = match self.data.as_mut() {
|
||||||
@@ -100,7 +100,7 @@ impl Assembly {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - index.len());
|
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2 - index.len());
|
||||||
index_extended.push_str(index.as_str());
|
index_extended.push_str(index.as_str());
|
||||||
|
|
||||||
*data = match data {
|
*data = match data {
|
||||||
@@ -136,7 +136,7 @@ impl Assembly {
|
|||||||
hash_data_mapping: &BTreeMap<String, String>,
|
hash_data_mapping: &BTreeMap<String, String>,
|
||||||
) -> anyhow::Result<BTreeMap<String, String>> {
|
) -> anyhow::Result<BTreeMap<String, String>> {
|
||||||
let mut index_path_mapping = BTreeMap::new();
|
let mut index_path_mapping = BTreeMap::new();
|
||||||
let index = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2);
|
let index = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2);
|
||||||
index_path_mapping.insert(index, full_path.to_owned());
|
index_path_mapping.insert(index, full_path.to_owned());
|
||||||
|
|
||||||
let dependencies = match self
|
let dependencies = match self
|
||||||
@@ -150,7 +150,7 @@ impl Assembly {
|
|||||||
None => return Ok(index_path_mapping),
|
None => return Ok(index_path_mapping),
|
||||||
};
|
};
|
||||||
for (index, data) in dependencies.iter_mut() {
|
for (index, data) in dependencies.iter_mut() {
|
||||||
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - index.len());
|
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2 - index.len());
|
||||||
index_extended.push_str(index.as_str());
|
index_extended.push_str(index.as_str());
|
||||||
|
|
||||||
*data = match data {
|
*data = match data {
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ where
|
|||||||
.value
|
.value
|
||||||
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
|
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
|
||||||
|
|
||||||
if value.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
|
if value.len() > revive_common::BYTE_LENGTH_WORD * 2 {
|
||||||
Ok(Some(context.field_const(0).as_basic_value_enum()))
|
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
||||||
} else {
|
} else {
|
||||||
crate::evmla::assembly::instruction::stack::push(context, value).map(Some)
|
crate::evmla::assembly::instruction::stack::push(context, value).map(Some)
|
||||||
}
|
}
|
||||||
@@ -522,7 +522,7 @@ where
|
|||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
)
|
)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
@@ -571,7 +571,7 @@ where
|
|||||||
revive_llvm_context::polkavm_evm_bitwise::xor(
|
revive_llvm_context::polkavm_evm_bitwise::xor(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
context.field_type().const_all_ones(),
|
context.word_type().const_all_ones(),
|
||||||
)
|
)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
@@ -758,7 +758,7 @@ where
|
|||||||
.solidity_mut()
|
.solidity_mut()
|
||||||
.get_or_allocate_immutable(key.as_str());
|
.get_or_allocate_immutable(key.as_str());
|
||||||
|
|
||||||
let index = context.field_const(offset as u64);
|
let index = context.word_const(offset as u64);
|
||||||
revive_llvm_context::polkavm_evm_immutable::load(context, index).map(Some)
|
revive_llvm_context::polkavm_evm_immutable::load(context, index).map(Some)
|
||||||
}
|
}
|
||||||
InstructionName::ASSIGNIMMUTABLE => {
|
InstructionName::ASSIGNIMMUTABLE => {
|
||||||
@@ -771,7 +771,7 @@ where
|
|||||||
|
|
||||||
let offset = context.solidity_mut().allocate_immutable(key.as_str());
|
let offset = context.solidity_mut().allocate_immutable(key.as_str());
|
||||||
|
|
||||||
let index = context.field_const(offset as u64);
|
let index = context.word_const(offset as u64);
|
||||||
let value = arguments.pop().expect("Always exists").into_int_value();
|
let value = arguments.pop().expect("Always exists").into_int_value();
|
||||||
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
@@ -783,7 +783,7 @@ where
|
|||||||
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
||||||
{
|
{
|
||||||
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
||||||
Ok(Some(context.field_const(0).as_basic_value_enum()))
|
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
||||||
let arguments = self.pop_arguments_llvm(context);
|
let arguments = self.pop_arguments_llvm(context);
|
||||||
@@ -801,7 +801,7 @@ where
|
|||||||
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
||||||
{
|
{
|
||||||
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
||||||
Ok(Some(context.field_const(0).as_basic_value_enum()))
|
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
||||||
revive_llvm_context::polkavm_evm_calldata::size(context).map(Some)
|
revive_llvm_context::polkavm_evm_calldata::size(context).map(Some)
|
||||||
@@ -902,7 +902,7 @@ where
|
|||||||
}
|
}
|
||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
}
|
}
|
||||||
InstructionName::PUSHSIZE => Ok(Some(context.field_const(0).as_basic_value_enum())),
|
InstructionName::PUSHSIZE => Ok(Some(context.word_const(0).as_basic_value_enum())),
|
||||||
InstructionName::RETURNDATASIZE => {
|
InstructionName::RETURNDATASIZE => {
|
||||||
revive_llvm_context::polkavm_evm_return_data::size(context).map(Some)
|
revive_llvm_context::polkavm_evm_return_data::size(context).map(Some)
|
||||||
}
|
}
|
||||||
@@ -1259,7 +1259,7 @@ where
|
|||||||
)
|
)
|
||||||
.expect("Always exists");
|
.expect("Always exists");
|
||||||
let pointer = revive_llvm_context::PolkaVMPointer::new(
|
let pointer = revive_llvm_context::PolkaVMPointer::new(
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
revive_llvm_context::PolkaVMAddressSpace::Stack,
|
revive_llvm_context::PolkaVMAddressSpace::Stack,
|
||||||
context.evmla().stack
|
context.evmla().stack
|
||||||
[self.stack.elements.len() - output_size + index]
|
[self.stack.elements.len() - output_size + index]
|
||||||
@@ -1299,11 +1299,11 @@ where
|
|||||||
let element_pointer = context.build_gep(
|
let element_pointer = context.build_gep(
|
||||||
pointer,
|
pointer,
|
||||||
&[
|
&[
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
context
|
context
|
||||||
.integer_const(revive_common::BIT_LENGTH_X32, index as u64),
|
.integer_const(revive_common::BIT_LENGTH_X32, index as u64),
|
||||||
],
|
],
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
format!("return_value_pointer_element_{}", index).as_str(),
|
format!("return_value_pointer_element_{}", index).as_str(),
|
||||||
);
|
);
|
||||||
context.build_store(element_pointer, argument)?;
|
context.build_store(element_pointer, argument)?;
|
||||||
|
|||||||
@@ -766,7 +766,7 @@ impl Function {
|
|||||||
|
|
||||||
let result = match (&operands[0], &operands[1]) {
|
let result = match (&operands[0], &operands[1]) {
|
||||||
(Element::Tag(tag), Element::Constant(offset)) => {
|
(Element::Tag(tag), Element::Constant(offset)) => {
|
||||||
let offset = offset % revive_common::BIT_LENGTH_FIELD;
|
let offset = offset % revive_common::BIT_LENGTH_WORD;
|
||||||
let offset = offset.to_u64().expect("Always valid");
|
let offset = offset.to_u64().expect("Always valid");
|
||||||
let result = tag << offset;
|
let result = tag << offset;
|
||||||
if Self::is_tag_value_valid(blocks, &result) {
|
if Self::is_tag_value_valid(blocks, &result) {
|
||||||
@@ -776,7 +776,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Element::Constant(constant), Element::Constant(offset)) => {
|
(Element::Constant(constant), Element::Constant(offset)) => {
|
||||||
let offset = offset % revive_common::BIT_LENGTH_FIELD;
|
let offset = offset % revive_common::BIT_LENGTH_WORD;
|
||||||
let offset = offset.to_u64().expect("Always valid");
|
let offset = offset.to_u64().expect("Always valid");
|
||||||
Element::Constant(constant << offset)
|
Element::Constant(constant << offset)
|
||||||
}
|
}
|
||||||
@@ -793,7 +793,7 @@ impl Function {
|
|||||||
|
|
||||||
let result = match (&operands[0], &operands[1]) {
|
let result = match (&operands[0], &operands[1]) {
|
||||||
(Element::Tag(tag), Element::Constant(offset)) => {
|
(Element::Tag(tag), Element::Constant(offset)) => {
|
||||||
let offset = offset % revive_common::BIT_LENGTH_FIELD;
|
let offset = offset % revive_common::BIT_LENGTH_WORD;
|
||||||
let offset = offset.to_u64().expect("Always valid");
|
let offset = offset.to_u64().expect("Always valid");
|
||||||
let result = tag >> offset;
|
let result = tag >> offset;
|
||||||
if Self::is_tag_value_valid(blocks, &result) {
|
if Self::is_tag_value_valid(blocks, &result) {
|
||||||
@@ -803,7 +803,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Element::Constant(constant), Element::Constant(offset)) => {
|
(Element::Constant(constant), Element::Constant(offset)) => {
|
||||||
let offset = offset % revive_common::BIT_LENGTH_FIELD;
|
let offset = offset % revive_common::BIT_LENGTH_WORD;
|
||||||
let offset = offset.to_u64().expect("Always valid");
|
let offset = offset.to_u64().expect("Always valid");
|
||||||
Element::Constant(constant >> offset)
|
Element::Constant(constant >> offset)
|
||||||
}
|
}
|
||||||
@@ -1151,7 +1151,7 @@ where
|
|||||||
let r#type = context.function_type(
|
let r#type = context.function_type(
|
||||||
vec![
|
vec![
|
||||||
context
|
context
|
||||||
.integer_type(revive_common::BIT_LENGTH_FIELD)
|
.integer_type(revive_common::BIT_LENGTH_WORD)
|
||||||
.as_basic_type_enum();
|
.as_basic_type_enum();
|
||||||
input_size
|
input_size
|
||||||
],
|
],
|
||||||
@@ -1200,7 +1200,7 @@ where
|
|||||||
let mut stack_variables = Vec::with_capacity(self.stack_size);
|
let mut stack_variables = Vec::with_capacity(self.stack_size);
|
||||||
for stack_index in 0..self.stack_size {
|
for stack_index in 0..self.stack_size {
|
||||||
let pointer = context.build_alloca(
|
let pointer = context.build_alloca(
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
format!("stack_var_{stack_index:03}").as_str(),
|
format!("stack_var_{stack_index:03}").as_str(),
|
||||||
);
|
);
|
||||||
let value = match self.r#type {
|
let value = match self.r#type {
|
||||||
@@ -1215,7 +1215,7 @@ where
|
|||||||
.get_nth_param((stack_index - 1) as u32)
|
.get_nth_param((stack_index - 1) as u32)
|
||||||
.expect("Always valid")
|
.expect("Always valid")
|
||||||
}
|
}
|
||||||
_ => context.field_const(0).as_basic_value_enum(),
|
_ => context.word_const(0).as_basic_value_enum(),
|
||||||
};
|
};
|
||||||
context.build_store(pointer, value)?;
|
context.build_store(pointer, value)?;
|
||||||
stack_variables.push(revive_llvm_context::PolkaVMArgument::new(
|
stack_variables.push(revive_llvm_context::PolkaVMArgument::new(
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ impl Contract {
|
|||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
path: String,
|
path: String,
|
||||||
source_hash: [u8; revive_common::BYTE_LENGTH_FIELD],
|
source_hash: [u8; revive_common::BYTE_LENGTH_WORD],
|
||||||
source_version: SolcVersion,
|
source_version: SolcVersion,
|
||||||
ir: IR,
|
ir: IR,
|
||||||
metadata_json: Option<serde_json::Value>,
|
metadata_json: Option<serde_json::Value>,
|
||||||
@@ -98,7 +98,7 @@ impl Contract {
|
|||||||
optimizer.settings().to_owned(),
|
optimizer.settings().to_owned(),
|
||||||
);
|
);
|
||||||
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
||||||
let metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]> = if include_metadata_hash
|
let metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]> = if include_metadata_hash
|
||||||
{
|
{
|
||||||
let metadata_string = serde_json::to_string(&metadata).expect("Always valid");
|
let metadata_string = serde_json::to_string(&metadata).expect("Always valid");
|
||||||
Some(sha3::Keccak256::digest(metadata_string.as_bytes()).into())
|
Some(sha3::Keccak256::digest(metadata_string.as_bytes()).into())
|
||||||
|
|||||||
@@ -145,12 +145,12 @@ where
|
|||||||
let field_pointer = context.build_gep(
|
let field_pointer = context.build_gep(
|
||||||
tuple_pointer,
|
tuple_pointer,
|
||||||
&[
|
&[
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
context
|
context
|
||||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||||
.const_int(index as u64, false),
|
.const_int(index as u64, false),
|
||||||
],
|
],
|
||||||
context.field_type().as_basic_type_enum(),
|
context.word_type().as_basic_type_enum(),
|
||||||
format!("assignment_binding_{index}_gep_pointer").as_str(),
|
format!("assignment_binding_{index}_gep_pointer").as_str(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ impl FunctionCall {
|
|||||||
revive_llvm_context::polkavm_evm_comparison::compare(
|
revive_llvm_context::polkavm_evm_comparison::compare(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
)
|
)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
@@ -312,7 +312,7 @@ impl FunctionCall {
|
|||||||
revive_llvm_context::polkavm_evm_bitwise::xor(
|
revive_llvm_context::polkavm_evm_bitwise::xor(
|
||||||
context,
|
context,
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
context.field_type().const_all_ones(),
|
context.word_type().const_all_ones(),
|
||||||
)
|
)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
}
|
}
|
||||||
@@ -512,7 +512,7 @@ impl FunctionCall {
|
|||||||
|
|
||||||
let offset = context.solidity_mut().allocate_immutable(key.as_str());
|
let offset = context.solidity_mut().allocate_immutable(key.as_str());
|
||||||
|
|
||||||
let index = context.field_const(offset as u64);
|
let index = context.word_const(offset as u64);
|
||||||
let value = arguments[2].value.into_int_value();
|
let value = arguments[2].value.into_int_value();
|
||||||
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
|
||||||
.map(|_| None)
|
.map(|_| None)
|
||||||
@@ -526,7 +526,7 @@ impl FunctionCall {
|
|||||||
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
||||||
{
|
{
|
||||||
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
||||||
Ok(Some(context.field_const(0).as_basic_value_enum()))
|
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
||||||
revive_llvm_context::polkavm_evm_calldata::load(
|
revive_llvm_context::polkavm_evm_calldata::load(
|
||||||
@@ -543,7 +543,7 @@ impl FunctionCall {
|
|||||||
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
|
||||||
{
|
{
|
||||||
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
revive_llvm_context::PolkaVMCodeType::Deploy => {
|
||||||
Ok(Some(context.field_const(0).as_basic_value_enum()))
|
Ok(Some(context.word_const(0).as_basic_value_enum()))
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
revive_llvm_context::PolkaVMCodeType::Runtime => {
|
||||||
revive_llvm_context::polkavm_evm_calldata::size(context).map(Some)
|
revive_llvm_context::polkavm_evm_calldata::size(context).map(Some)
|
||||||
@@ -877,8 +877,8 @@ impl FunctionCall {
|
|||||||
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
|
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
|
||||||
let offset = context.builder().build_int_add(
|
let offset = context.builder().build_int_add(
|
||||||
arguments[0].into_int_value(),
|
arguments[0].into_int_value(),
|
||||||
context.field_const(
|
context.word_const(
|
||||||
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
|
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD) as u64,
|
||||||
),
|
),
|
||||||
"datacopy_contract_hash_offset",
|
"datacopy_contract_hash_offset",
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
@@ -138,8 +138,7 @@ impl Literal {
|
|||||||
let mut hex_string = if inner.is_hexadecimal {
|
let mut hex_string = if inner.is_hexadecimal {
|
||||||
string.clone()
|
string.clone()
|
||||||
} else {
|
} else {
|
||||||
let mut hex_string =
|
let mut hex_string = String::with_capacity(revive_common::BYTE_LENGTH_WORD * 2);
|
||||||
String::with_capacity(revive_common::BYTE_LENGTH_FIELD * 2);
|
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
loop {
|
loop {
|
||||||
if index >= string.len() {
|
if index >= string.len() {
|
||||||
@@ -200,16 +199,16 @@ impl Literal {
|
|||||||
hex_string
|
hex_string
|
||||||
};
|
};
|
||||||
|
|
||||||
if hex_string.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
|
if hex_string.len() > revive_common::BYTE_LENGTH_WORD * 2 {
|
||||||
return Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
|
return Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
|
||||||
r#type.const_zero().as_basic_value_enum(),
|
r#type.const_zero().as_basic_value_enum(),
|
||||||
string,
|
string,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if hex_string.len() < revive_common::BYTE_LENGTH_FIELD * 2 {
|
if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 {
|
||||||
hex_string.push_str(
|
hex_string.push_str(
|
||||||
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
|
"0".repeat((revive_common::BYTE_LENGTH_WORD * 2) - hex_string.len())
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,13 +82,13 @@ where
|
|||||||
.into_int_value();
|
.into_int_value();
|
||||||
let condition = context.builder().build_int_z_extend_or_bit_cast(
|
let condition = context.builder().build_int_z_extend_or_bit_cast(
|
||||||
condition,
|
condition,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
"for_condition_extended",
|
"for_condition_extended",
|
||||||
)?;
|
)?;
|
||||||
let condition = context.builder().build_int_compare(
|
let condition = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::NE,
|
inkwell::IntPredicate::NE,
|
||||||
condition,
|
condition,
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
"for_condition_compared",
|
"for_condition_compared",
|
||||||
)?;
|
)?;
|
||||||
context.build_conditional_branch(condition, body_block, join_block)?;
|
context.build_conditional_branch(condition, body_block, join_block)?;
|
||||||
|
|||||||
@@ -285,12 +285,12 @@ where
|
|||||||
let pointer = context.build_gep(
|
let pointer = context.build_gep(
|
||||||
pointer,
|
pointer,
|
||||||
&[
|
&[
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
context
|
context
|
||||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||||
.const_int(index as u64, false),
|
.const_int(index as u64, false),
|
||||||
],
|
],
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
format!("return_{index}_gep_pointer").as_str(),
|
format!("return_{index}_gep_pointer").as_str(),
|
||||||
);
|
);
|
||||||
context.build_store(pointer, r#type.const_zero())?;
|
context.build_store(pointer, r#type.const_zero())?;
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ where
|
|||||||
.into_int_value();
|
.into_int_value();
|
||||||
let condition = context.builder().build_int_z_extend_or_bit_cast(
|
let condition = context.builder().build_int_z_extend_or_bit_cast(
|
||||||
condition,
|
condition,
|
||||||
context.field_type(),
|
context.word_type(),
|
||||||
"if_condition_extended",
|
"if_condition_extended",
|
||||||
)?;
|
)?;
|
||||||
let condition = context.builder().build_int_compare(
|
let condition = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::NE,
|
inkwell::IntPredicate::NE,
|
||||||
condition,
|
condition,
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
"if_condition_compared",
|
"if_condition_compared",
|
||||||
)?;
|
)?;
|
||||||
let main_block = context.append_basic_block("if_main");
|
let main_block = context.append_basic_block("if_main");
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ where
|
|||||||
let pointer = context.build_gep(
|
let pointer = context.build_gep(
|
||||||
pointer,
|
pointer,
|
||||||
&[
|
&[
|
||||||
context.field_const(0),
|
context.word_const(0),
|
||||||
context
|
context
|
||||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||||
.const_int(index as u64, false),
|
.const_int(index as u64, false),
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub enum Type {
|
|||||||
|
|
||||||
impl Default for Type {
|
impl Default for Type {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::UInt(revive_common::BIT_LENGTH_FIELD)
|
Self::UInt(revive_common::BIT_LENGTH_WORD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ impl Type {
|
|||||||
Self::Bool => context.integer_type(revive_common::BIT_LENGTH_BOOLEAN),
|
Self::Bool => context.integer_type(revive_common::BIT_LENGTH_BOOLEAN),
|
||||||
Self::Int(bitlength) => context.integer_type(bitlength),
|
Self::Int(bitlength) => context.integer_type(bitlength),
|
||||||
Self::UInt(bitlength) => context.integer_type(bitlength),
|
Self::UInt(bitlength) => context.integer_type(bitlength),
|
||||||
Self::Custom(_) => context.field_type(),
|
Self::Custom(_) => context.word_type(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user