mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 03:41:02 +00:00
@@ -671,15 +671,13 @@ where
|
||||
"offset_ptrtoint",
|
||||
)?;
|
||||
let pointer_value = unsafe {
|
||||
self.builder
|
||||
.build_gep(
|
||||
self.byte_type(),
|
||||
heap_pointer.value.as_pointer_value(),
|
||||
&[offset],
|
||||
"heap_offset_via_gep",
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
self.builder.build_gep(
|
||||
self.byte_type(),
|
||||
heap_pointer.value.as_pointer_value(),
|
||||
&[offset],
|
||||
"heap_offset_via_gep",
|
||||
)
|
||||
}?;
|
||||
let value = self
|
||||
.builder()
|
||||
.build_load(pointer.r#type, pointer_value, name)?;
|
||||
@@ -806,6 +804,7 @@ where
|
||||
)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let value = self.build_byte_swap(value.as_basic_value_enum());
|
||||
|
||||
let instruction = self.builder.build_store(pointer_value, value).unwrap();
|
||||
|
||||
@@ -78,6 +78,7 @@ impl<'ctx> Pointer<'ctx> {
|
||||
"Stack pointers cannot be addressed"
|
||||
);
|
||||
|
||||
let offset = context.safe_truncate_int_to_i32(offset).unwrap();
|
||||
let value = context
|
||||
.builder
|
||||
.build_int_to_ptr(
|
||||
|
||||
@@ -59,29 +59,36 @@ pub fn copy<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
// TODO: Untested
|
||||
let destination = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.byte_type(),
|
||||
destination_offset,
|
||||
"calldata_copy_destination_pointer",
|
||||
);
|
||||
let heap_pointer = context
|
||||
.get_global(crate::eravm::GLOBAL_HEAP_MEMORY_POINTER)?
|
||||
.value
|
||||
.as_pointer_value();
|
||||
let destination = unsafe {
|
||||
context.builder().build_gep(
|
||||
context.byte_type(),
|
||||
heap_pointer,
|
||||
&[destination_offset],
|
||||
"calldata_pointer_with_offset",
|
||||
)
|
||||
}?;
|
||||
|
||||
let calldata_pointer = context
|
||||
.get_global(crate::eravm::GLOBAL_CALLDATA_POINTER)?
|
||||
.value
|
||||
.as_pointer_value();
|
||||
let source = context.build_gep(
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
||||
&[source_offset],
|
||||
context.field_type().as_basic_type_enum(),
|
||||
"calldata_pointer_with_offset",
|
||||
);
|
||||
let source = unsafe {
|
||||
context.builder().build_gep(
|
||||
context.byte_type(),
|
||||
calldata_pointer,
|
||||
&[source_offset],
|
||||
"calldata_pointer_with_offset",
|
||||
)
|
||||
}?;
|
||||
|
||||
context.build_memcpy(
|
||||
context.intrinsics().memory_copy_from_generic,
|
||||
destination,
|
||||
source,
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, destination),
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, source),
|
||||
size,
|
||||
"calldata_copy_memcpy_from_child",
|
||||
)
|
||||
|
||||
@@ -9,12 +9,52 @@ use crate::eravm::Dependency;
|
||||
/// Translates the `sha3` instruction.
|
||||
///
|
||||
pub fn sha3<'ctx, D>(
|
||||
_context: &mut Context<'ctx, D>,
|
||||
_offset: inkwell::values::IntValue<'ctx>,
|
||||
_length: inkwell::values::IntValue<'ctx>,
|
||||
context: &mut Context<'ctx, D>,
|
||||
offset: inkwell::values::IntValue<'ctx>,
|
||||
length: inkwell::values::IntValue<'ctx>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
todo!()
|
||||
let offset_casted = context.safe_truncate_int_to_i32(offset)?;
|
||||
let heap_pointer = context.get_global(crate::eravm::GLOBAL_HEAP_MEMORY_POINTER)?;
|
||||
let input_pointer = unsafe {
|
||||
context.builder().build_gep(
|
||||
context.byte_type(),
|
||||
heap_pointer.value.as_pointer_value(),
|
||||
&[offset_casted],
|
||||
"heap_offset_via_gep",
|
||||
)
|
||||
}?;
|
||||
let input_pointer_casted = context.builder().build_ptr_to_int(
|
||||
input_pointer,
|
||||
context.integer_type(32),
|
||||
"input_pointer_casted",
|
||||
)?;
|
||||
|
||||
let length_casted = context.safe_truncate_int_to_i32(length)?;
|
||||
|
||||
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.integer_type(32),
|
||||
"output_pointer_casted",
|
||||
)?;
|
||||
|
||||
let function = context
|
||||
.module()
|
||||
.get_function("hash_keccak_256")
|
||||
.expect("is declared");
|
||||
|
||||
context.builder().build_call(
|
||||
function,
|
||||
&[
|
||||
input_pointer_casted.into(),
|
||||
length_casted.into(),
|
||||
output_pointer_casted.into(),
|
||||
],
|
||||
"call_seal_hash_keccak_256",
|
||||
)?;
|
||||
|
||||
Ok(context.build_byte_swap(context.build_load(output_pointer, "sha3_output")?))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user