Skip to content

Commit

Permalink
feat: support EXTCODECOPY
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed May 23, 2024
1 parent 2e67331 commit 77af3ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 46 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# The `zkvyper` changelog

### [Unreleased]
## [Unreleased]

### [1.4.1] - 2024-04-24
### Added

- The support for `EXTCODECOPY` instruction

## [1.4.1] - 2024-04-24

### Added

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 48 additions & 42 deletions src/project/contract/vyper/expression/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,50 +1303,56 @@ impl Instruction {
if Some(crate::r#const::EXTCODESIZE_BLUEPRINT_ARGUMENT_NAME)
!= arguments[0].original.as_deref()
{
anyhow::bail!(
"The `EXTCODECOPY` instruction is only supported for the `create_from_blueprint built-in."
);
}

let hash_value = era_compiler_llvm_context::eravm_evm_ext_code::hash(
context,
arguments[0].value.into_int_value(),
)?;

let hash_heap_offset = context.builder().build_int_add(
arguments[1].value.into_int_value(),
context.field_const(
(era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)
as u64,
),
"extcodecopy_hash_offset",
)?;
let hash_heap_pointer = era_compiler_llvm_context::Pointer::new_with_offset(
context,
era_compiler_llvm_context::EraVMAddressSpace::Heap,
context.field_type(),
hash_heap_offset,
"extcodecopy_hash_destination",
)?;
context.build_store(hash_heap_pointer, hash_value)?;
era_compiler_llvm_context::eravm_evm_ext_code::copy(
context,
arguments[0].value.into_int_value(),
arguments[1].value.into_int_value(),
arguments[2].value.into_int_value(),
arguments[3].value.into_int_value(),
)
.map(|_| None)
} else {
let hash_value = era_compiler_llvm_context::eravm_evm_ext_code::hash(
context,
arguments[0].value.into_int_value(),
)?;

let hash_aux_heap_offset = context.field_const(
era_compiler_llvm_context::eravm_const::HEAP_AUX_OFFSET_EXTERNAL_CALL
+ (era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)
as u64,
);
let hash_aux_heap_pointer = era_compiler_llvm_context::Pointer::new_with_offset(
context,
era_compiler_llvm_context::EraVMAddressSpace::HeapAuxiliary,
context.field_type(),
hash_aux_heap_offset,
"extcodecopy_hash_destination",
)?;
context.build_store(hash_aux_heap_pointer, hash_value)?;
let hash_heap_offset = context.builder().build_int_add(
arguments[1].value.into_int_value(),
context.field_const(
(era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)
as u64,
),
"extcodecopy_hash_offset",
)?;
let hash_heap_pointer = era_compiler_llvm_context::Pointer::new_with_offset(
context,
era_compiler_llvm_context::EraVMAddressSpace::Heap,
context.field_type(),
hash_heap_offset,
"extcodecopy_hash_destination",
)?;
context.build_store(hash_heap_pointer, hash_value)?;

Ok(None)
let hash_aux_heap_offset = context.field_const(
era_compiler_llvm_context::eravm_const::HEAP_AUX_OFFSET_EXTERNAL_CALL
+ (era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)
as u64,
);
let hash_aux_heap_pointer =
era_compiler_llvm_context::Pointer::new_with_offset(
context,
era_compiler_llvm_context::EraVMAddressSpace::HeapAuxiliary,
context.field_type(),
hash_aux_heap_offset,
"extcodecopy_hash_destination",
)?;
context.build_store(hash_aux_heap_pointer, hash_value)?;

Ok(None)
}
}

Self::RETURN(inner) => inner.into_llvm_value(context).map(|_| None),
Expand Down
1 change: 0 additions & 1 deletion src/tests/unsupported_opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! It is not possible to reproduce:
//! - PC
//! - CALLCODE
//! - EXTCODECOPY without using Vyper built-in functions forbidden on the AST level
//!

#![cfg(test)]
Expand Down

0 comments on commit 77af3ef

Please sign in to comment.