Implement extcodehash (#77)

This commit is contained in:
Ermal Kaleci
2024-10-21 10:13:50 +02:00
committed by GitHub
parent 82ae22c163
commit ee83d28a51
10 changed files with 582 additions and 477 deletions
@@ -49,11 +49,31 @@ where
/// Translates the `extcodehash` instruction.
pub fn hash<'ctx, D>(
_context: &mut Context<'ctx, D>,
_address: inkwell::values::IntValue<'ctx>,
context: &mut Context<'ctx, D>,
address: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where
D: Dependency + Clone,
{
todo!()
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer = context.build_alloca_at_entry(address_type, "address_pointer");
let address_truncated =
context
.builder()
.build_int_truncate(address, address_type, "address_truncated")?;
let address_swapped = context.build_byte_swap(address_truncated.into())?;
context.build_store(address_pointer, address_swapped)?;
let extcodehash_pointer =
context.build_alloca_at_entry(context.word_type(), "extcodehash_pointer");
context.build_runtime_call(
revive_runtime_api::polkavm_imports::CODE_HASH,
&[
address_pointer.to_int(context).into(),
extcodehash_pointer.to_int(context).into(),
],
);
context.build_byte_swap(context.build_load(extcodehash_pointer, "extcodehash_value")?)
}