s/field/word

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-07 13:37:17 +02:00
parent 9f8a8a782d
commit c0dd845b39
48 changed files with 291 additions and 282 deletions
+2 -2
View File
@@ -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 =
crate::byte_length::BYTE_LENGTH_ETH_ADDRESS * BIT_LENGTH_BYTE;
/// The field (usually `u256` or `i256`) bit-length.
pub const BIT_LENGTH_FIELD: usize = crate::byte_length::BYTE_LENGTH_FIELD * BIT_LENGTH_BYTE;
/// The VM word (usually `u256` or `i256`) bit-length.
pub const BIT_LENGTH_WORD: usize = crate::byte_length::BYTE_LENGTH_WORD * BIT_LENGTH_BYTE;
/// Bit length of the runtime value type.
pub const BIT_LENGTH_VALUE: usize = crate::byte_length::BYTE_LENGTH_VALUE * BIT_LENGTH_BYTE;
+2 -2
View File
@@ -15,8 +15,8 @@ pub const BYTE_LENGTH_X64: usize = 8;
/// The ETH address byte-length.
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
/// The field byte-length.
pub const BYTE_LENGTH_FIELD: usize = 32;
/// The word byte-length.
pub const BYTE_LENGTH_WORD: usize = 32;
/// Byte length of the runtime value type.
pub const BYTE_LENGTH_VALUE: usize = 16;
+4 -4
View File
@@ -1,7 +1,7 @@
{
"Fibonacci": 5971,
"ERC20": 53171,
"Baseline": 3912,
"Computation": 7380,
"Flipper": 4354,
"ERC20": 53186
"Flipper": 4353,
"Fibonacci": 5971,
"Computation": 7380
}
+4 -1
View File
@@ -88,6 +88,9 @@ fn link_host_functions(engine: &Engine) -> Linker<State> {
|caller: Caller<State>, out_ptr: u32, out_len_ptr: u32| -> Result<(), Trap> {
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();
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 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
.storage
+5 -2
View File
@@ -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,
);
+33 -33
View File
@@ -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),
)
+12 -14
View File
@@ -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))
}
+3 -14
View File
@@ -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",
);
+13 -13
View File
@@ -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",
);
+1 -1
View File
@@ -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 {
+12 -12
View File
@@ -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")
+3 -3
View File
@@ -9,10 +9,10 @@ pub static DEFAULT_EXECUTABLE_NAME: &str = "zksolc";
pub const OFFSET_SCRATCH_SPACE: usize = 0;
/// 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.
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.
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(
offset,
context.field_const(
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
),
context
.word_const((revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD) as u64),
"datacopy_contract_hash_offset",
)?;
@@ -33,8 +32,8 @@ where
{
revive_llvm_context::polkavm_evm_memory::store_byte(
context,
context.field_const(offset),
context.field_const(value),
context.word_const(offset),
context.word_const(value),
)?;
Ok(())
@@ -53,21 +52,21 @@ where
for (index, chunk) in source
.chars()
.collect::<Vec<char>>()
.chunks(revive_common::BYTE_LENGTH_FIELD * 2)
.chunks(revive_common::BYTE_LENGTH_WORD * 2)
.enumerate()
{
let mut value_string = chunk.iter().collect::<String>();
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(),
);
let datacopy_destination = context.builder().build_int_add(
destination,
context.field_const(offset as u64),
context.word_const(offset as u64),
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(
context,
datacopy_destination,
@@ -49,7 +49,7 @@ where
let condition = context.builder().build_int_compare(
inkwell::IntPredicate::NE,
condition.into_int_value(),
context.field_const(0),
context.word_const(0),
format!("conditional_{block_key}_condition_compared").as_str(),
)?;
@@ -299,7 +299,7 @@ impl Instruction {
..
} => {
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());
*value = mapping.get(key_extended.as_str()).cloned().ok_or_else(|| {
@@ -11,7 +11,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let result = context
.field_type()
.word_type()
.const_int_from_string(
value.to_ascii_uppercase().as_str(),
inkwell::types::StringRadix::Hexadecimal,
@@ -30,7 +30,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let result = context
.field_type()
.word_type()
.const_int_from_string(value.as_str(), inkwell::types::StringRadix::Decimal)
.expect("Always valid");
Ok(result.as_basic_value_enum())
+4 -4
View File
@@ -88,7 +88,7 @@ impl Assembly {
hash_data_mapping: &BTreeMap<String, String>,
) -> anyhow::Result<BTreeMap<String, String>> {
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());
let dependencies = match self.data.as_mut() {
@@ -100,7 +100,7 @@ impl Assembly {
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());
*data = match data {
@@ -136,7 +136,7 @@ impl Assembly {
hash_data_mapping: &BTreeMap<String, String>,
) -> anyhow::Result<BTreeMap<String, String>> {
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());
let dependencies = match self
@@ -150,7 +150,7 @@ impl Assembly {
None => return Ok(index_path_mapping),
};
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());
*data = match data {
@@ -162,8 +162,8 @@ where
.value
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
if value.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
Ok(Some(context.field_const(0).as_basic_value_enum()))
if value.len() > revive_common::BYTE_LENGTH_WORD * 2 {
Ok(Some(context.word_const(0).as_basic_value_enum()))
} else {
crate::evmla::assembly::instruction::stack::push(context, value).map(Some)
}
@@ -522,7 +522,7 @@ where
revive_llvm_context::polkavm_evm_comparison::compare(
context,
arguments[0].into_int_value(),
context.field_const(0),
context.word_const(0),
inkwell::IntPredicate::EQ,
)
.map(Some)
@@ -571,7 +571,7 @@ where
revive_llvm_context::polkavm_evm_bitwise::xor(
context,
arguments[0].into_int_value(),
context.field_type().const_all_ones(),
context.word_type().const_all_ones(),
)
.map(Some)
}
@@ -758,7 +758,7 @@ where
.solidity_mut()
.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)
}
InstructionName::ASSIGNIMMUTABLE => {
@@ -771,7 +771,7 @@ where
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();
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
.map(|_| None)
@@ -783,7 +783,7 @@ where
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
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 => {
let arguments = self.pop_arguments_llvm(context);
@@ -801,7 +801,7 @@ where
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
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::polkavm_evm_calldata::size(context).map(Some)
@@ -902,7 +902,7 @@ where
}
.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 => {
revive_llvm_context::polkavm_evm_return_data::size(context).map(Some)
}
@@ -1259,7 +1259,7 @@ where
)
.expect("Always exists");
let pointer = revive_llvm_context::PolkaVMPointer::new(
context.field_type(),
context.word_type(),
revive_llvm_context::PolkaVMAddressSpace::Stack,
context.evmla().stack
[self.stack.elements.len() - output_size + index]
@@ -1299,11 +1299,11 @@ where
let element_pointer = context.build_gep(
pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_const(revive_common::BIT_LENGTH_X32, index as u64),
],
context.field_type(),
context.word_type(),
format!("return_value_pointer_element_{}", index).as_str(),
);
context.build_store(element_pointer, argument)?;
@@ -766,7 +766,7 @@ impl Function {
let result = match (&operands[0], &operands[1]) {
(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 result = tag << offset;
if Self::is_tag_value_valid(blocks, &result) {
@@ -776,7 +776,7 @@ impl Function {
}
}
(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");
Element::Constant(constant << offset)
}
@@ -793,7 +793,7 @@ impl Function {
let result = match (&operands[0], &operands[1]) {
(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 result = tag >> offset;
if Self::is_tag_value_valid(blocks, &result) {
@@ -803,7 +803,7 @@ impl Function {
}
}
(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");
Element::Constant(constant >> offset)
}
@@ -1151,7 +1151,7 @@ where
let r#type = context.function_type(
vec![
context
.integer_type(revive_common::BIT_LENGTH_FIELD)
.integer_type(revive_common::BIT_LENGTH_WORD)
.as_basic_type_enum();
input_size
],
@@ -1200,7 +1200,7 @@ where
let mut stack_variables = Vec::with_capacity(self.stack_size);
for stack_index in 0..self.stack_size {
let pointer = context.build_alloca(
context.field_type(),
context.word_type(),
format!("stack_var_{stack_index:03}").as_str(),
);
let value = match self.r#type {
@@ -1215,7 +1215,7 @@ where
.get_nth_param((stack_index - 1) as u32)
.expect("Always valid")
}
_ => context.field_const(0).as_basic_value_enum(),
_ => context.word_const(0).as_basic_value_enum(),
};
context.build_store(pointer, value)?;
stack_variables.push(revive_llvm_context::PolkaVMArgument::new(
+2 -2
View File
@@ -33,7 +33,7 @@ impl Contract {
/// A shortcut constructor.
pub fn new(
path: String,
source_hash: [u8; revive_common::BYTE_LENGTH_FIELD],
source_hash: [u8; revive_common::BYTE_LENGTH_WORD],
source_version: SolcVersion,
ir: IR,
metadata_json: Option<serde_json::Value>,
@@ -98,7 +98,7 @@ impl Contract {
optimizer.settings().to_owned(),
);
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");
Some(sha3::Keccak256::digest(metadata_string.as_bytes()).into())
@@ -145,12 +145,12 @@ where
let field_pointer = context.build_gep(
tuple_pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_type(revive_common::BIT_LENGTH_X32)
.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(),
);
@@ -263,7 +263,7 @@ impl FunctionCall {
revive_llvm_context::polkavm_evm_comparison::compare(
context,
arguments[0].into_int_value(),
context.field_const(0),
context.word_const(0),
inkwell::IntPredicate::EQ,
)
.map(Some)
@@ -312,7 +312,7 @@ impl FunctionCall {
revive_llvm_context::polkavm_evm_bitwise::xor(
context,
arguments[0].into_int_value(),
context.field_type().const_all_ones(),
context.word_type().const_all_ones(),
)
.map(Some)
}
@@ -512,7 +512,7 @@ impl FunctionCall {
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();
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
.map(|_| None)
@@ -526,7 +526,7 @@ impl FunctionCall {
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
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::polkavm_evm_calldata::load(
@@ -543,7 +543,7 @@ impl FunctionCall {
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
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::polkavm_evm_calldata::size(context).map(Some)
@@ -877,8 +877,8 @@ impl FunctionCall {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
let offset = context.builder().build_int_add(
arguments[0].into_int_value(),
context.field_const(
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
context.word_const(
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD) as u64,
),
"datacopy_contract_hash_offset",
)?;
@@ -138,8 +138,7 @@ impl Literal {
let mut hex_string = if inner.is_hexadecimal {
string.clone()
} else {
let mut hex_string =
String::with_capacity(revive_common::BYTE_LENGTH_FIELD * 2);
let mut hex_string = String::with_capacity(revive_common::BYTE_LENGTH_WORD * 2);
let mut index = 0;
loop {
if index >= string.len() {
@@ -200,16 +199,16 @@ impl Literal {
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(
r#type.const_zero().as_basic_value_enum(),
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(
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
"0".repeat((revive_common::BYTE_LENGTH_WORD * 2) - hex_string.len())
.as_str(),
);
}
@@ -82,13 +82,13 @@ where
.into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.field_type(),
context.word_type(),
"for_condition_extended",
)?;
let condition = context.builder().build_int_compare(
inkwell::IntPredicate::NE,
condition,
context.field_const(0),
context.word_const(0),
"for_condition_compared",
)?;
context.build_conditional_branch(condition, body_block, join_block)?;
@@ -285,12 +285,12 @@ where
let pointer = context.build_gep(
pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type(),
context.word_type(),
format!("return_{index}_gep_pointer").as_str(),
);
context.build_store(pointer, r#type.const_zero())?;
@@ -61,13 +61,13 @@ where
.into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.field_type(),
context.word_type(),
"if_condition_extended",
)?;
let condition = context.builder().build_int_compare(
inkwell::IntPredicate::NE,
condition,
context.field_const(0),
context.word_const(0),
"if_condition_compared",
)?;
let main_block = context.append_basic_block("if_main");
@@ -185,7 +185,7 @@ where
let pointer = context.build_gep(
pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
+2 -2
View File
@@ -26,7 +26,7 @@ pub enum Type {
impl Default for Type {
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::Int(bitlength) => context.integer_type(bitlength),
Self::UInt(bitlength) => context.integer_type(bitlength),
Self::Custom(_) => context.field_type(),
Self::Custom(_) => context.word_type(),
}
}
}