mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-16 06:11:08 +00:00
Allow arbitrary call data size (#135)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
//! Translates the calldata instructions.
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use inkwell::types::BasicType;
|
||||
|
||||
/// Translates the calldata load.
|
||||
pub fn load<'ctx, D>(
|
||||
@@ -14,19 +11,15 @@ pub fn load<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let calldata_pointer = context
|
||||
.get_global(crate::polkavm::GLOBAL_CALLDATA_POINTER)?
|
||||
.value
|
||||
.as_pointer_value();
|
||||
let offset = context.build_gep(
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
||||
&[offset],
|
||||
context.word_type().as_basic_type_enum(),
|
||||
"calldata_pointer_with_offset",
|
||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "call_data_output");
|
||||
let offset = context.safe_truncate_int_to_xlen(offset)?;
|
||||
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::CALL_DATA_LOAD,
|
||||
&[output_pointer.to_int(context).into(), offset.into()],
|
||||
);
|
||||
context
|
||||
.build_load(offset, "calldata_value")
|
||||
.and_then(|value| context.build_byte_swap(value))
|
||||
|
||||
context.build_load(output_pointer, "call_data_load_value")
|
||||
}
|
||||
|
||||
/// Translates the calldata size.
|
||||
@@ -37,8 +30,14 @@ where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let value = context.get_global_value(crate::polkavm::GLOBAL_CALLDATA_SIZE)?;
|
||||
|
||||
Ok(value)
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(
|
||||
value.into_int_value(),
|
||||
context.word_type(),
|
||||
"call_data_size_value",
|
||||
)?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Translates the calldata copy.
|
||||
@@ -51,20 +50,19 @@ pub fn copy<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let offset = context.safe_truncate_int_to_xlen(destination_offset)?;
|
||||
let source_offset = context.safe_truncate_int_to_xlen(source_offset)?;
|
||||
let size = context.safe_truncate_int_to_xlen(size)?;
|
||||
let destination = context.build_heap_gep(offset, size)?;
|
||||
let destination_offset = context.safe_truncate_int_to_xlen(destination_offset)?;
|
||||
let output_pointer = context.build_heap_gep(destination_offset, size)?;
|
||||
|
||||
let calldata_pointer = context
|
||||
.get_global(crate::polkavm::GLOBAL_CALLDATA_POINTER)?
|
||||
.value
|
||||
.as_pointer_value();
|
||||
let source = context.build_gep(
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
||||
&[context.safe_truncate_int_to_xlen(source_offset)?],
|
||||
context.byte_type(),
|
||||
"calldata_pointer_with_offset",
|
||||
context.build_runtime_call(
|
||||
revive_runtime_api::polkavm_imports::CALL_DATA_COPY,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
size.into(),
|
||||
source_offset.into(),
|
||||
],
|
||||
);
|
||||
|
||||
context.build_memcpy(destination, source, size, "calldata_copy_memcpy_from_child")
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user