Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(levm): ginitcodeword specification, fix gas #1402

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,13 @@ impl VM {
let created_contract = Account::new(value, calldata.clone(), 1, HashMap::new());
cache::insert_account(&mut cache, new_contract_address, created_contract);

let bytecode: Bytes = calldata.clone();

let initial_call_frame = CallFrame::new(
env.origin,
new_contract_address,
new_contract_address,
bytecode,
Bytes::new(), // Bytecode is assigned after passing validations.
value,
Bytes::new(), // Contract creation does not have calldata
calldata, // Calldata is removed after passing validations.
false,
env.gas_limit,
U256::zero(),
Expand Down Expand Up @@ -378,12 +376,7 @@ impl VM {
.checked_add(CREATE_BASE_COST)
.ok_or(OutOfGasError::ConsumedGasOverflow)?;

let number_of_words: u64 = initial_call_frame
.calldata
.chunks(WORD_SIZE)
.len()
.try_into()
.map_err(|_| InternalError::ConversionError)?;
let number_of_words = initial_call_frame.calldata.len().div_ceil(WORD_SIZE);

intrinsic_gas = intrinsic_gas
.checked_add(
Expand Down Expand Up @@ -493,7 +486,7 @@ impl VM {
// (4) INITCODE_SIZE_EXCEEDED
if self.is_create() {
// INITCODE_SIZE_EXCEEDED
if initial_call_frame.bytecode.len() > INIT_CODE_MAX_SIZE {
if initial_call_frame.calldata.len() > INIT_CODE_MAX_SIZE {
return Err(VMError::TxValidation(
TxValidationError::InitcodeSizeExceeded,
));
Expand Down Expand Up @@ -589,6 +582,12 @@ impl VM {
let cache_before_execution = self.cache.clone();
self.validate_transaction(&mut initial_call_frame)?;

if self.is_create() {
// Assign bytecode to context and empty calldata
initial_call_frame.bytecode = initial_call_frame.calldata.clone();
initial_call_frame.calldata = Bytes::new();
}

// Maybe can be done in validate_transaction
let sender = initial_call_frame.msg_sender;
let receiver_address = initial_call_frame.to;
Expand Down
2 changes: 2 additions & 0 deletions crates/vm/levm/tests/edge_case_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Here add #![allow(clippy::<lint_name>)] if necessary, we don't want to lint the test code.

use std::str::FromStr;

use bytes::Bytes;
Expand Down
Loading