mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-13 21:11:03 +00:00
@@ -42,12 +42,15 @@ pub static GLOBAL_CONST_ARRAY_PREFIX: &str = "const_array_";
|
||||
/// The global verbatim getter identifier prefix.
|
||||
pub static GLOBAL_VERBATIM_GETTER_PREFIX: &str = "get_global::";
|
||||
|
||||
/// The static word size.
|
||||
pub static GLOBAL_WORD_SIZE: &str = "word_size";
|
||||
|
||||
/// The external call data offset in the auxiliary heap.
|
||||
pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0;
|
||||
|
||||
/// The constructor return data offset in the auxiliary heap.
|
||||
pub const HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA: u64 =
|
||||
8 * (revive_common::BYTE_LENGTH_FIELD as u64);
|
||||
8 * (revive_common::BYTE_LENGTH_WORD as u64);
|
||||
|
||||
/// The number of the extra ABI data arguments.
|
||||
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 length (32 bytes)
|
||||
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.
|
||||
pub assembly_text: String,
|
||||
/// 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.
|
||||
pub bytecode: Vec<u8>,
|
||||
/// The PolkaVM bytecode hash.
|
||||
@@ -24,7 +24,7 @@ impl Build {
|
||||
/// A shortcut constructor.
|
||||
pub fn new(
|
||||
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_hash: String,
|
||||
) -> Self {
|
||||
|
||||
@@ -39,7 +39,7 @@ impl<'ctx> Intrinsics<'ctx> {
|
||||
) -> Self {
|
||||
let void_type = llvm.void_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 heap_field_pointer_type = llvm.ptr_type(AddressSpace::Heap.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,
|
||||
name: &str,
|
||||
) -> 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 {
|
||||
name if name == Self::FUNCTION_MEMORY_COPY => vec![
|
||||
|
||||
@@ -187,10 +187,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let div = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -206,10 +206,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let r#mod = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -225,10 +225,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let sdiv = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -244,10 +244,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let smod = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -263,10 +263,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let shl = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -282,10 +282,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let shr = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -301,10 +301,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let sar = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -320,10 +320,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let byte = Self::declare(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.into();
|
||||
2
|
||||
@@ -358,13 +358,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
let sha3 = Self::declare(
|
||||
module,
|
||||
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(
|
||||
vec![
|
||||
llvm.ptr_type(AddressSpace::Heap.into())
|
||||
.as_basic_type_enum()
|
||||
.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()
|
||||
.into(),
|
||||
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(
|
||||
module,
|
||||
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(
|
||||
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()
|
||||
.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()
|
||||
.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()
|
||||
.into(),
|
||||
llvm.ptr_type(AddressSpace::Stack.into())
|
||||
@@ -412,7 +412,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Function::set_default_attributes(llvm, system_request, optimizer);
|
||||
|
||||
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()
|
||||
.into();
|
||||
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();
|
||||
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()
|
||||
.into(),
|
||||
);
|
||||
@@ -429,13 +429,13 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
llvm.ptr_type(AddressSpace::Generic.into())
|
||||
.as_basic_type_enum()
|
||||
.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()
|
||||
.into(),
|
||||
];
|
||||
external_call_arguments_by_ref.extend::<Vec<inkwell::types::BasicMetadataTypeEnum>>(vec![
|
||||
llvm.custom_width_int_type(
|
||||
revive_common::BIT_LENGTH_FIELD as u32
|
||||
revive_common::BIT_LENGTH_WORD as u32
|
||||
)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
@@ -443,7 +443,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
]);
|
||||
let mut mimic_call_arguments_by_ref = external_call_arguments_by_ref.clone();
|
||||
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()
|
||||
.into(),
|
||||
);
|
||||
@@ -522,7 +522,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Self::FUNCTION_RETURN,
|
||||
llvm.void_type().fn_type(
|
||||
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()
|
||||
.into();
|
||||
3
|
||||
@@ -538,7 +538,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Self::FUNCTION_REVERT,
|
||||
llvm.void_type().fn_type(
|
||||
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()
|
||||
.into();
|
||||
3
|
||||
|
||||
@@ -49,7 +49,7 @@ impl<'ctx> Return<'ctx> {
|
||||
|
||||
/// Returns the return data size in bytes, based on the default stack alignment.
|
||||
pub fn return_data_size(&self) -> usize {
|
||||
revive_common::BYTE_LENGTH_FIELD
|
||||
revive_common::BYTE_LENGTH_WORD
|
||||
* match self {
|
||||
Self::None => 0,
|
||||
Self::Primitive { .. } => 1,
|
||||
|
||||
@@ -81,12 +81,12 @@ where
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let function_type = context.function_type(
|
||||
vec![
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
],
|
||||
1,
|
||||
false,
|
||||
@@ -144,7 +144,7 @@ where
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
let status_code_result_pointer = context.build_alloca(
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"contract_call_result_status_code_pointer",
|
||||
);
|
||||
/*
|
||||
|
||||
@@ -62,19 +62,19 @@ where
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
context.set_code_type(CodeType::Deploy);
|
||||
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
|
||||
as usize)
|
||||
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_FIELD;
|
||||
let value = index * revive_common::BYTE_LENGTH_FIELD;
|
||||
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_WORD;
|
||||
let value = index * revive_common::BYTE_LENGTH_WORD;
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.field_const(offset as u64),
|
||||
context.word_type(),
|
||||
context.word_const(offset as u64),
|
||||
"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<()> {
|
||||
let function_type = context.function_type(
|
||||
vec![
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
],
|
||||
1,
|
||||
false,
|
||||
@@ -124,7 +124,7 @@ where
|
||||
let signature_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
input_offset,
|
||||
"deployer_call_signature_pointer",
|
||||
);
|
||||
@@ -132,13 +132,13 @@ where
|
||||
|
||||
let salt_offset = context.builder().build_int_add(
|
||||
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",
|
||||
)?;
|
||||
let salt_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
salt_offset,
|
||||
"deployer_call_salt_pointer",
|
||||
);
|
||||
@@ -146,47 +146,47 @@ where
|
||||
|
||||
let arguments_offset_offset = context.builder().build_int_add(
|
||||
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",
|
||||
)?;
|
||||
let arguments_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
arguments_offset_offset,
|
||||
"deployer_call_arguments_offset_pointer",
|
||||
);
|
||||
context.build_store(
|
||||
arguments_offset_pointer,
|
||||
context.field_const(
|
||||
context.word_const(
|
||||
(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,
|
||||
),
|
||||
)?;
|
||||
|
||||
let arguments_length_offset = context.builder().build_int_add(
|
||||
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",
|
||||
)?;
|
||||
let arguments_length_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
self.address_space,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
arguments_length_offset,
|
||||
"deployer_call_arguments_length_pointer",
|
||||
);
|
||||
let arguments_length_value = context.builder().build_int_sub(
|
||||
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",
|
||||
)?;
|
||||
context.build_store(arguments_length_pointer, arguments_length_value)?;
|
||||
|
||||
let result_pointer =
|
||||
context.build_alloca(context.field_type(), "deployer_call_result_pointer");
|
||||
context.build_store(result_pointer, context.field_const(0))?;
|
||||
context.build_alloca(context.word_type(), "deployer_call_result_pointer");
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
let deployer_call_result_type = context.structure_type(&[
|
||||
context
|
||||
.llvm()
|
||||
@@ -203,7 +203,7 @@ where
|
||||
let is_value_zero = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::EQ,
|
||||
value,
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
"deployer_call_is_value_zero",
|
||||
)?;
|
||||
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(
|
||||
deployer_call_result_pointer,
|
||||
&[
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
context
|
||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||
.const_zero(),
|
||||
@@ -269,7 +269,7 @@ where
|
||||
let result_status_code_pointer = context.build_gep(
|
||||
deployer_call_result_pointer,
|
||||
&[
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
context
|
||||
.integer_type(revive_common::BIT_LENGTH_X32)
|
||||
.const_int(1, false),
|
||||
@@ -288,7 +288,7 @@ where
|
||||
|
||||
context.set_basic_block(success_block);
|
||||
let result_abi_data_pointer = Pointer::new(
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Generic,
|
||||
result_abi_data.into_pointer_value(),
|
||||
);
|
||||
|
||||
@@ -55,26 +55,26 @@ impl Entry {
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
context.field_undef(),
|
||||
context.word_undef(),
|
||||
);
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
);
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALL_FLAGS,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
context.field_const(0),
|
||||
context.word_const(0),
|
||||
);
|
||||
|
||||
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,
|
||||
);
|
||||
context.set_global(
|
||||
@@ -84,6 +84,13 @@ impl Entry {
|
||||
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(())
|
||||
}
|
||||
|
||||
@@ -125,12 +132,12 @@ impl Entry {
|
||||
.into_int_value();
|
||||
let calldata_size_casted = context.builder().build_int_z_extend(
|
||||
calldata_size,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"zext_input_len",
|
||||
)?;
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_CALLDATA_SIZE,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
AddressSpace::Stack,
|
||||
calldata_size_casted,
|
||||
);
|
||||
|
||||
@@ -230,7 +230,7 @@ where
|
||||
pub fn build(
|
||||
mut self,
|
||||
contract_path: &str,
|
||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
|
||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||
) -> anyhow::Result<Build> {
|
||||
let module_clone = self.module.clone();
|
||||
|
||||
@@ -437,12 +437,12 @@ where
|
||||
0 => FunctionReturn::none(),
|
||||
1 => {
|
||||
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)
|
||||
}
|
||||
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
|
||||
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();
|
||||
FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size)
|
||||
}
|
||||
@@ -450,7 +450,7 @@ where
|
||||
self.set_basic_block(entry_block);
|
||||
let pointer = self.build_alloca(
|
||||
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",
|
||||
);
|
||||
@@ -561,7 +561,7 @@ where
|
||||
.ok_or_else(|| anyhow::anyhow!("The dependency manager is unset"))
|
||||
.and_then(|manager| {
|
||||
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)
|
||||
})
|
||||
}
|
||||
@@ -647,7 +647,7 @@ where
|
||||
AddressSpace::Storage => {
|
||||
let storage_key_value = self.builder().build_ptr_to_int(
|
||||
pointer.value,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
"storage_ptr_to_int",
|
||||
)?;
|
||||
let storage_key_pointer =
|
||||
@@ -658,7 +658,7 @@ where
|
||||
"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(
|
||||
storage_value_pointer.value,
|
||||
self.xlen_type(),
|
||||
@@ -679,7 +679,7 @@ where
|
||||
storage_value_length_pointer.value,
|
||||
self.integer_const(
|
||||
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 = 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,
|
||||
_ => unreachable!("Only word and byte sized values can be stored on EVM heap"),
|
||||
};
|
||||
@@ -759,7 +759,7 @@ where
|
||||
AddressSpace::Storage => {
|
||||
let storage_key_value = self.builder().build_ptr_to_int(
|
||||
pointer.value,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
"storage_ptr_to_int",
|
||||
)?;
|
||||
let storage_key_pointer =
|
||||
@@ -1052,18 +1052,18 @@ where
|
||||
) -> anyhow::Result<()> {
|
||||
let pointer_casted = self.builder.build_ptr_to_int(
|
||||
source.value,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
format!("{name}_pointer_casted").as_str(),
|
||||
)?;
|
||||
let return_data_size_shifted = self.builder.build_right_shift(
|
||||
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,
|
||||
format!("{name}_return_data_size_shifted").as_str(),
|
||||
)?;
|
||||
let return_data_size_truncated = self.builder.build_and(
|
||||
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(),
|
||||
)?;
|
||||
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(
|
||||
truncated,
|
||||
self.field_type(),
|
||||
self.word_type(),
|
||||
"offset_extended",
|
||||
)?;
|
||||
let is_overflow = self.builder().build_int_compare(
|
||||
@@ -1337,26 +1337,26 @@ where
|
||||
self.integer_type(bit_length).const_int(value, false)
|
||||
}
|
||||
|
||||
/// Returns a 256-bit field type constant.
|
||||
pub fn field_const(&self, value: u64) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type().const_int(value, false)
|
||||
/// Returns a word type constant.
|
||||
pub fn word_const(&self, value: u64) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type().const_int(value, false)
|
||||
}
|
||||
|
||||
/// Returns a 256-bit field type undefined value.
|
||||
pub fn field_undef(&self) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type().get_undef()
|
||||
/// Returns a word type undefined value.
|
||||
pub fn word_undef(&self) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type().get_undef()
|
||||
}
|
||||
|
||||
/// Returns a field type constant from a decimal string.
|
||||
pub fn field_const_str_dec(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type()
|
||||
/// Returns a word type constant from a decimal string.
|
||||
pub fn word_const_str_dec(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type()
|
||||
.const_int_from_string(value, inkwell::types::StringRadix::Decimal)
|
||||
.unwrap_or_else(|| panic!("Invalid string constant `{value}`"))
|
||||
}
|
||||
|
||||
/// Returns a field type constant from a hexadecimal string.
|
||||
pub fn field_const_str_hex(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.field_type()
|
||||
/// Returns a word type constant from a hexadecimal string.
|
||||
pub fn word_const_str_hex(&self, value: &str) -> inkwell::values::IntValue<'ctx> {
|
||||
self.word_type()
|
||||
.const_int_from_string(
|
||||
value.strip_prefix("0x").unwrap_or(value),
|
||||
inkwell::types::StringRadix::Hexadecimal,
|
||||
@@ -1396,10 +1396,10 @@ where
|
||||
.custom_width_int_type(revive_common::BIT_LENGTH_VALUE as u32)
|
||||
}
|
||||
|
||||
/// Returns the default field type.
|
||||
pub fn field_type(&self) -> inkwell::types::IntType<'ctx> {
|
||||
/// Returns the default word type.
|
||||
pub fn word_type(&self) -> inkwell::types::IntType<'ctx> {
|
||||
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.
|
||||
@@ -1441,14 +1441,14 @@ where
|
||||
.llvm
|
||||
.void_type()
|
||||
.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() => {
|
||||
let return_type = self.llvm().ptr_type(AddressSpace::Stack.into());
|
||||
argument_types.insert(0, return_type.as_basic_type_enum().into());
|
||||
return_type.fn_type(argument_types.as_slice(), false)
|
||||
}
|
||||
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),
|
||||
}
|
||||
}
|
||||
@@ -1508,14 +1508,14 @@ where
|
||||
inkwell::attributes::AttributeLoc::Param(index as u32),
|
||||
self.llvm.create_enum_attribute(
|
||||
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(
|
||||
inkwell::attributes::AttributeLoc::Return,
|
||||
self.llvm.create_enum_attribute(
|
||||
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,
|
||||
{
|
||||
Self {
|
||||
r#type: context.field_type().as_basic_type_enum(),
|
||||
r#type: context.word_type().as_basic_type_enum(),
|
||||
address_space: AddressSpace::Stack,
|
||||
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>(
|
||||
self,
|
||||
context: &Context<'ctx, D>,
|
||||
|
||||
@@ -19,14 +19,14 @@ impl SolidityData {
|
||||
|
||||
/// Returns the current number of immutables values in the contract.
|
||||
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.
|
||||
/// If the identifier is already known, just returns its offset.
|
||||
pub fn allocate_immutable(&mut self, identifier: &str) -> usize {
|
||||
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
|
||||
.immutables
|
||||
.entry(identifier.to_owned())
|
||||
|
||||
@@ -27,8 +27,8 @@ pub fn check_attribute_null_pointer_is_invalid() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -50,8 +50,8 @@ pub fn check_attribute_optimize_for_size_mode_3() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -73,8 +73,8 @@ pub fn check_attribute_optimize_for_size_mode_z() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -96,8 +96,8 @@ pub fn check_attribute_min_size_mode_3() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
@@ -119,8 +119,8 @@ pub fn check_attribute_min_size_mode_z() {
|
||||
.add_function(
|
||||
"test",
|
||||
context
|
||||
.field_type()
|
||||
.fn_type(&[context.field_type().into()], false),
|
||||
.word_type()
|
||||
.fn_type(&[context.word_type().into()], false),
|
||||
1,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
)
|
||||
|
||||
@@ -63,17 +63,17 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
||||
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(
|
||||
inkwell::IntPredicate::UGT,
|
||||
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",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_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.set_basic_block(non_overflow_block);
|
||||
@@ -101,17 +101,17 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
||||
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(
|
||||
inkwell::IntPredicate::UGT,
|
||||
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",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_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.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 join_block = context.append_basic_block("shift_right_arithmetic_join");
|
||||
|
||||
let result_pointer = context.build_alloca(
|
||||
context.field_type(),
|
||||
"shift_right_arithmetic_result_pointer",
|
||||
);
|
||||
let result_pointer =
|
||||
context.build_alloca(context.word_type(), "shift_right_arithmetic_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
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",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
@@ -160,7 +158,7 @@ where
|
||||
context.set_basic_block(overflow_block);
|
||||
let sign_bit = context.builder().build_right_shift(
|
||||
value,
|
||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
false,
|
||||
"shift_right_arithmetic_sign_bit",
|
||||
)?;
|
||||
@@ -176,11 +174,11 @@ where
|
||||
)?;
|
||||
|
||||
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.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.set_basic_block(non_overflow_block);
|
||||
|
||||
@@ -21,7 +21,7 @@ where
|
||||
let offset = context.build_gep(
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
||||
&[offset],
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
"calldata_pointer_with_offset",
|
||||
);
|
||||
context
|
||||
|
||||
@@ -24,7 +24,7 @@ where
|
||||
)?;
|
||||
let result = context.builder().build_int_z_extend_or_bit_cast(
|
||||
result,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"comparison_result_extended",
|
||||
)?;
|
||||
Ok(result.as_basic_value_enum())
|
||||
|
||||
@@ -129,6 +129,6 @@ where
|
||||
)?;
|
||||
Ok(context
|
||||
.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())
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ where
|
||||
{
|
||||
let signature_hash_string =
|
||||
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 result = context
|
||||
@@ -58,9 +58,9 @@ where
|
||||
{
|
||||
let signature_hash_string =
|
||||
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 result = context
|
||||
@@ -107,7 +107,7 @@ where
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
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(),
|
||||
));
|
||||
} 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_value = context
|
||||
.field_const_str_hex(hash_string.as_str())
|
||||
.word_const_str_hex(hash_string.as_str())
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::new_with_original(hash_value, hash_string))
|
||||
}
|
||||
@@ -155,7 +155,7 @@ where
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
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(),
|
||||
));
|
||||
} 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_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();
|
||||
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 length_casted = context.safe_truncate_int_to_xlen(length)?;
|
||||
let input_pointer = context.build_heap_gep(offset_casted, length_casted)?;
|
||||
let input_pointer_casted = context.builder().build_ptr_to_int(
|
||||
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",
|
||||
)?;
|
||||
let output_pointer = context.build_alloca(context.word_type(), "output_pointer");
|
||||
|
||||
context.build_runtime_call(
|
||||
runtime_api::HASH_KECCAK_256,
|
||||
&[
|
||||
input_pointer_casted.into(),
|
||||
input_pointer.to_int(context).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_extended = context.builder().build_int_z_extend(
|
||||
value.into_int_value(),
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"transferred_value_extended",
|
||||
)?;
|
||||
Ok(value_extended.as_basic_value_enum())
|
||||
|
||||
@@ -23,21 +23,21 @@ where
|
||||
Some(CodeType::Deploy) => {
|
||||
let index_double = context.builder().build_int_mul(
|
||||
index,
|
||||
context.field_const(2),
|
||||
context.word_const(2),
|
||||
"immutable_load_index_double",
|
||||
)?;
|
||||
let offset_absolute = context.builder().build_int_add(
|
||||
index_double,
|
||||
context.field_const(
|
||||
context.word_const(
|
||||
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",
|
||||
)?;
|
||||
let immutable_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
offset_absolute,
|
||||
"immutable_pointer",
|
||||
);
|
||||
@@ -68,21 +68,21 @@ where
|
||||
Some(CodeType::Deploy) => {
|
||||
let index_double = context.builder().build_int_mul(
|
||||
index,
|
||||
context.field_const(2),
|
||||
context.word_const(2),
|
||||
"immutable_load_index_double",
|
||||
)?;
|
||||
let index_offset_absolute = context.builder().build_int_add(
|
||||
index_double,
|
||||
context.field_const(
|
||||
context.word_const(
|
||||
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",
|
||||
)?;
|
||||
let index_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
index_offset_absolute,
|
||||
"immutable_index_pointer",
|
||||
);
|
||||
@@ -90,13 +90,13 @@ where
|
||||
|
||||
let value_offset_absolute = context.builder().build_int_add(
|
||||
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",
|
||||
)?;
|
||||
let value_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
value_offset_absolute,
|
||||
"immutable_value_pointer",
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ where
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
offset,
|
||||
"memory_load_pointer",
|
||||
);
|
||||
@@ -37,7 +37,7 @@ where
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
offset,
|
||||
"memory_store_pointer",
|
||||
);
|
||||
|
||||
@@ -24,22 +24,22 @@ where
|
||||
let immutables_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.field_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||
context.word_type(),
|
||||
context.word_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||
"immutables_offset_pointer",
|
||||
);
|
||||
context.build_store(
|
||||
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(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.field_const(
|
||||
context.word_type(),
|
||||
context.word_const(
|
||||
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",
|
||||
);
|
||||
@@ -47,22 +47,22 @@ where
|
||||
context.build_store(
|
||||
immutables_number_pointer,
|
||||
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(
|
||||
context.field_const(immutable_values_size as u64),
|
||||
context.field_const(2),
|
||||
context.word_const(immutable_values_size as u64),
|
||||
context.word_const(2),
|
||||
"immutables_size",
|
||||
)?;
|
||||
let return_data_length = context.builder().build_int_add(
|
||||
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",
|
||||
)?;
|
||||
|
||||
context.build_exit(
|
||||
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,
|
||||
)?;
|
||||
}
|
||||
@@ -115,8 +115,8 @@ where
|
||||
{
|
||||
crate::polkavm::evm::memory::store(
|
||||
context,
|
||||
context.field_type().const_all_ones(),
|
||||
context.field_const(0),
|
||||
context.word_type().const_all_ones(),
|
||||
context.word_const(0),
|
||||
)?;
|
||||
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
||||
Ok(())
|
||||
|
||||
@@ -17,7 +17,7 @@ where
|
||||
{
|
||||
match context.get_global_value(crate::polkavm::GLOBAL_RETURN_DATA_SIZE) {
|
||||
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.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);
|
||||
let destination = Pointer::new_with_offset(
|
||||
|
||||
@@ -16,7 +16,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Storage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"storage_load_position_pointer",
|
||||
);
|
||||
@@ -35,7 +35,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Storage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"storage_store_position_pointer",
|
||||
);
|
||||
@@ -54,7 +54,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::TransientStorage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"transient_storage_load_position_pointer",
|
||||
);
|
||||
@@ -73,7 +73,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::TransientStorage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"transient_storage_store_position_pointer",
|
||||
);
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn initialize_target() {
|
||||
pub fn build_assembly_text(
|
||||
contract_path: &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>,
|
||||
) -> anyhow::Result<Build> {
|
||||
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 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)?;
|
||||
|
||||
let is_in_bounds = context.builder().build_int_compare(
|
||||
@@ -103,13 +103,13 @@ where
|
||||
let input_offset = crate::polkavm::utils::clamp(
|
||||
context,
|
||||
input_offset,
|
||||
context.field_const(u32::MAX as u64),
|
||||
context.word_const(u32::MAX as u64),
|
||||
"abi_data_input_offset",
|
||||
)?;
|
||||
let input_length = crate::polkavm::utils::clamp(
|
||||
context,
|
||||
input_length,
|
||||
context.field_const(u32::MAX as u64),
|
||||
context.word_const(u32::MAX as u64),
|
||||
"abi_data_input_length",
|
||||
)?;
|
||||
|
||||
@@ -120,23 +120,23 @@ where
|
||||
let gas = crate::polkavm::utils::clamp(
|
||||
context,
|
||||
gas,
|
||||
context.field_const(u32::MAX as u64),
|
||||
context.word_const(u32::MAX as u64),
|
||||
"abi_data_gas",
|
||||
)?;
|
||||
|
||||
let input_offset_shifted = context.builder().build_left_shift(
|
||||
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",
|
||||
)?;
|
||||
let input_length_shifted = context.builder().build_left_shift(
|
||||
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",
|
||||
)?;
|
||||
let gas_shifted = context.builder().build_left_shift(
|
||||
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",
|
||||
)?;
|
||||
|
||||
@@ -150,8 +150,8 @@ where
|
||||
.build_int_add(abi_data, gas_shifted, "abi_data_add_gas")?;
|
||||
if let AddressSpace::HeapAuxiliary = address_space {
|
||||
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
|
||||
context.field_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
||||
context.field_const((revive_common::BIT_LENGTH_X32 * 7) as u64),
|
||||
context.word_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
||||
context.word_const((revive_common::BIT_LENGTH_X32 * 7) as u64),
|
||||
"abi_data_auxiliary_heap_marker_shifted",
|
||||
)?;
|
||||
abi_data = context.builder().build_int_add(
|
||||
@@ -162,8 +162,8 @@ where
|
||||
}
|
||||
if is_system_call {
|
||||
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
|
||||
context.field_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
||||
context.field_const(
|
||||
context.word_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
|
||||
context.word_const(
|
||||
((revive_common::BIT_LENGTH_X32 * 7) + (revive_common::BIT_LENGTH_BYTE * 3)) as u64,
|
||||
),
|
||||
"abi_data_system_call_marker_shifted",
|
||||
@@ -188,7 +188,7 @@ where
|
||||
{
|
||||
let mut padded_data = initial_data;
|
||||
padded_data.extend(vec![
|
||||
context.field_undef();
|
||||
context.word_undef();
|
||||
crate::polkavm::EXTRA_ABI_DATA_SIZE - padded_data.len()
|
||||
]);
|
||||
padded_data.try_into().expect("Always valid")
|
||||
|
||||
Reference in New Issue
Block a user