Skip to content

Commit

Permalink
Merge branch 'main' into levm/fix/memory-alignment-extcodecopy
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli committed Nov 25, 2024
2 parents acd3d21 + 450476a commit a669e94
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/loc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,27 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Generate the loc report
id: loc-report
run: make loc
echo "content=$(cat loc_report.md)" >> $GITHUB_OUTPUT

- name: Post results in summary
run: |
echo "# `ethrex` lines of code report:\n\n" >> $GITHUB_STEP_SUMMARY
$(cat loc_report.md) >> $GITHUB_STEP_SUMMARY
- name: Post results to slack
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
blocks:
- type: "header"
text:
type: "plain_text"
text: ethrex lines of code report
- type: "section"
text:
type: "mrkdwn"
text: ${{steps.loc-report.outputs.content}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ tests_v3.0.0.tar.gz
.env

levm_ef_tests_report.txt

loc_report.md
4 changes: 2 additions & 2 deletions cmd/ef_tests/levm/runner/revm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use ethrex_core::{types::TxKind, Address};
use ethrex_levm::errors::{TransactionReport, TxResult};
use ethrex_storage::{error::StoreError, AccountUpdate};
use ethrex_vm::{db::StoreWrapper, spec_id, EvmState, RevmAddress, RevmU256};
use ethrex_vm::{db::StoreWrapper, EvmState, RevmAddress, RevmU256, SpecId};
use revm::{
db::State,
inspectors::TracerEip3155 as RevmTracerEip3155,
Expand Down Expand Up @@ -135,7 +135,7 @@ pub fn prepare_revm_for_tx<'state>(
.with_block_env(block_env)
.with_tx_env(tx_env)
.modify_cfg_env(|cfg| cfg.chain_id = chain_spec.chain_id)
.with_spec_id(spec_id(&chain_spec, test.env.current_timestamp.as_u64()))
.with_spec_id(SpecId::CANCUN)
.with_external_context(
RevmTracerEip3155::new(Box::new(std::io::stderr())).without_summary(),
);
Expand Down
25 changes: 15 additions & 10 deletions cmd/loc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use colored::Colorize;
use std::path::PathBuf;
use tokei::{Config, LanguageType, Languages};

Expand All @@ -23,14 +22,20 @@ fn main() {
languages.get_statistics(&[ethrex_l2], &[], &config);
let ethrex_l2_loc = &languages.get(&LanguageType::Rust).unwrap();

println!("{}", "ethrex loc summary".bold());
println!("{}", "====================".bold());
println!(
"{}: {:?}",
"ethrex L1".bold(),
ethrex_loc.code - ethrex_l2_loc.code - levm_loc.code
let report = format!(
r#"```
ethrex loc summary
====================
ethrex L1: {}
ethrex L2: {}
levm: {}
ethrex (total): {}
```"#,
ethrex_loc.code - ethrex_l2_loc.code - levm_loc.code,
ethrex_l2_loc.code,
levm_loc.code,
ethrex_loc.code,
);
println!("{}: {:?}", "ethrex L2".bold(), ethrex_l2_loc.code);
println!("{}: {:?}", "levm".bold(), levm_loc.code);
println!("{}: {:?}", "ethrex (total)".bold(), ethrex_loc.code);

std::fs::write("loc_report.md", report).unwrap();
}
30 changes: 17 additions & 13 deletions crates/vm/levm/src/opcode_handlers/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ impl VM {

self.increase_consumed_gas(current_call_frame, gas_cost)?;

if size == 0 {
return Ok(OpcodeSuccess::Continue);
}

if !is_cached {
self.cache_from_db(&address);
};
Expand Down Expand Up @@ -397,19 +401,19 @@ impl VM {
}

let sub_return_data_len = current_call_frame.sub_return_data.len();
let data = if returndata_offset < sub_return_data_len {
current_call_frame.sub_return_data.slice(
returndata_offset
..(returndata_offset
.checked_add(size)
.ok_or(VMError::Internal(
InternalError::ArithmeticOperationOverflow,
))?)
.min(sub_return_data_len),
)
} else {
vec![0u8; size].into()
};

if returndata_offset >= sub_return_data_len {
return Err(VMError::VeryLargeNumber); // Maybe can create a new error instead of using this one
}
let data = current_call_frame.sub_return_data.slice(
returndata_offset
..(returndata_offset
.checked_add(size)
.ok_or(VMError::Internal(
InternalError::ArithmeticOperationOverflow,
))?)
.min(sub_return_data_len),
);

current_call_frame.memory.store_bytes(dest_offset, &data)?;

Expand Down
4 changes: 0 additions & 4 deletions crates/vm/levm/src/opcode_handlers/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
call_frame::CallFrame,
constants::SUCCESS_FOR_RETURN,
errors::{InternalError, OpcodeSuccess, ResultReason, VMError},
gas_cost,
vm::{word_to_address, VM},
Expand Down Expand Up @@ -184,9 +183,6 @@ impl VM {

let return_data = current_call_frame.memory.load_range(offset, size)?.into();
current_call_frame.returndata = return_data;
current_call_frame
.stack
.push(U256::from(SUCCESS_FOR_RETURN))?;

Ok(OpcodeSuccess::Result(ResultReason::Return))
}
Expand Down

0 comments on commit a669e94

Please sign in to comment.