-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`.
- Loading branch information
Showing
12 changed files
with
130 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use u256::U256; | ||
use zkevm_opcode_defs::{BlobSha256Format, ContractCodeSha256Format, VersionedHashLen32}; | ||
|
||
use crate::{ | ||
addressing_modes::{Arguments, Destination, Register1, Register2, Source}, | ||
fat_pointer::FatPointer, | ||
instruction::InstructionResult, | ||
Instruction, VirtualMachine, World, | ||
}; | ||
|
||
use super::{common::instruction_boilerplate, HeapInterface}; | ||
|
||
fn decommit( | ||
vm: &mut VirtualMachine, | ||
instruction: *const Instruction, | ||
world: &mut dyn World, | ||
) -> InstructionResult { | ||
instruction_boilerplate(vm, instruction, world, |vm, args, world| { | ||
let code_hash = Register1::get(args, &mut vm.state); | ||
let extra_cost = Register2::get(args, &mut vm.state).low_u32(); | ||
|
||
let mut buffer = [0u8; 32]; | ||
code_hash.to_big_endian(&mut buffer); | ||
|
||
let preimage_len_in_bytes = | ||
zkevm_opcode_defs::system_params::NEW_KERNEL_FRAME_MEMORY_STIPEND; | ||
|
||
if vm.state.use_gas(extra_cost).is_err() | ||
|| (!ContractCodeSha256Format::is_valid(&buffer) | ||
&& !BlobSha256Format::is_valid(&buffer)) | ||
{ | ||
Register1::set(args, &mut vm.state, U256::zero()); | ||
return; | ||
} | ||
|
||
let program = vm.world_diff.decommit_opcode(world, code_hash); | ||
|
||
let heap = vm.state.heaps.allocate(); | ||
vm.state.current_frame.heaps_i_am_keeping_alive.push(heap); | ||
vm.state.heaps[heap].memset(program.as_ref()); | ||
|
||
let value = FatPointer { | ||
offset: 0, | ||
memory_page: heap, | ||
start: 0, | ||
length: preimage_len_in_bytes, | ||
}; | ||
let value = value.into_u256(); | ||
Register1::set_fat_ptr(args, &mut vm.state, value); | ||
}) | ||
} | ||
impl Instruction { | ||
pub fn from_decommit( | ||
abi: Register1, | ||
burn: Register2, | ||
out: Register1, | ||
arguments: Arguments, | ||
) -> Self { | ||
Self { | ||
arguments: arguments | ||
.write_source(&abi) | ||
.write_source(&burn) | ||
.write_destination(&out), | ||
handler: decommit, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters