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

feat(levm): add ethereum foundation tests #957

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
856b57a
Add tests folder to gitignore file
maximopalopoli Oct 23, 2024
8b78bd0
Add eftests file
maximopalopoli Oct 23, 2024
480ca0e
cargo fmt
maximopalopoli Oct 23, 2024
a82dabf
Update types structure
maximopalopoli Oct 24, 2024
ab4714c
Refactor: extract parse behavior
maximopalopoli Oct 24, 2024
c1a3da7
Filter not json files when collecting contents
maximopalopoli Oct 24, 2024
850ab7f
Update imports
maximopalopoli Oct 24, 2024
a030de4
cargo fmt changes
maximopalopoli Oct 24, 2024
d02647c
Clippy fixes
maximopalopoli Oct 24, 2024
251ed37
Modify Vm's account to use it in tests
maximopalopoli Oct 24, 2024
399252c
Refactor types: change flags and add fields
maximopalopoli Oct 24, 2024
f9f9d22
Add Initialize of VM struct
maximopalopoli Oct 24, 2024
cff5f6d
Add execution and verify suggestions
maximopalopoli Oct 24, 2024
3993b49
Add imports
maximopalopoli Oct 24, 2024
da4929a
Add a comment of expected behavior in accrued_substate
maximopalopoli Oct 25, 2024
c8d34f5
Rename intern Account to don't overwrite VM's one
maximopalopoli Oct 25, 2024
ae47b08
Add verify idea, prints and fmt
maximopalopoli Oct 25, 2024
402db1f
Refactor: move init of environment to other func
maximopalopoli Oct 25, 2024
4f8b321
Merge branch 'main' into levm/feat/add-ef-tests
maximopalopoli Oct 29, 2024
9c295da
Adapt current implementation to main changes
maximopalopoli Oct 29, 2024
6bbc0b7
change some vm input parameters
maximopalopoli Oct 29, 2024
fa002c4
Use common folder utils to improve bytes parsing
maximopalopoli Oct 29, 2024
4f22db3
Fix bug of reading an empty contract code
maximopalopoli Oct 29, 2024
40bc6b0
clippy+fmt changes
maximopalopoli Oct 29, 2024
c2deabd
Comment execution (currently with creation tests)
maximopalopoli Oct 29, 2024
4e461b4
Change address translation in opcodes
maximopalopoli Oct 30, 2024
aed305f
Handle TxDestination enum in vm exec
maximopalopoli Oct 30, 2024
a6027c9
add readme description for test (temporary) and modify path of tests
JereSalo Nov 4, 2024
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
1 change: 1 addition & 0 deletions crates/vm/levm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ serde_json = { version = "1.0.117" }
walkdir = "2.5.0"
ethereum_rust-rlp.workspace = true
keccak-hash = "0.10.0"
ethereum_rust-core.workspace = true

[dev-dependencies]
hex = "0.4.3"
Expand Down
5 changes: 5 additions & 0 deletions crates/vm/levm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Features:
[CallFrame](./docs/callframe.md)

### Testing

#### Unit Testing
To run the project's tests, do `make test`.

#### EF Tests
To run the EF Tests first download them from [here](https://github.com/ethereum/tests/tree/develop/GeneralStateTests). Then, inside the `tests` folder, create another folder named `ef_testcases` and include all the downloaded folders inside it.

Run `make help` to see available commands
1 change: 1 addition & 0 deletions crates/vm/levm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum VMError {
NonceOverflow,
}

#[derive(Debug, Clone)]
pub enum OpcodeSuccess {
Continue,
Result(ResultReason),
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/levm/src/opcode_handlers/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
constants::{call_opcode, SUCCESS_FOR_RETURN},
errors::ResultReason,
errors::ResultReason, vm::word_to_address,
};

use super::*;
Expand All @@ -15,7 +15,7 @@ impl VM {
current_call_frame: &mut CallFrame,
) -> Result<OpcodeSuccess, VMError> {
let gas = current_call_frame.stack.pop()?;
let code_address = Address::from_low_u64_be(current_call_frame.stack.pop()?.low_u64());
let code_address = word_to_address(current_call_frame.stack.pop()?);
let value = current_call_frame.stack.pop()?;
let args_offset = current_call_frame
.stack
Expand Down Expand Up @@ -95,7 +95,7 @@ impl VM {
current_call_frame: &mut CallFrame,
) -> Result<OpcodeSuccess, VMError> {
let gas = current_call_frame.stack.pop()?;
let code_address = Address::from_low_u64_be(current_call_frame.stack.pop()?.low_u64());
let code_address = word_to_address(current_call_frame.stack.pop()?);
let value = current_call_frame.stack.pop()?;
let args_offset = current_call_frame.stack.pop()?.try_into().unwrap();
let args_size = current_call_frame.stack.pop()?.try_into().unwrap();
Expand Down Expand Up @@ -158,7 +158,7 @@ impl VM {
current_call_frame: &mut CallFrame,
) -> Result<OpcodeSuccess, VMError> {
let gas = current_call_frame.stack.pop()?;
let code_address = Address::from_low_u64_be(current_call_frame.stack.pop()?.low_u64());
let code_address = word_to_address(current_call_frame.stack.pop()?);
let args_offset = current_call_frame.stack.pop()?.try_into().unwrap();
let args_size = current_call_frame.stack.pop()?.try_into().unwrap();
let ret_offset = current_call_frame.stack.pop()?.try_into().unwrap();
Expand Down Expand Up @@ -192,7 +192,7 @@ impl VM {
current_call_frame: &mut CallFrame,
) -> Result<OpcodeSuccess, VMError> {
let gas = current_call_frame.stack.pop()?;
let code_address = Address::from_low_u64_be(current_call_frame.stack.pop()?.low_u64());
let code_address = word_to_address(current_call_frame.stack.pop()?);
let args_offset = current_call_frame.stack.pop()?.try_into().unwrap();
let args_size = current_call_frame.stack.pop()?.try_into().unwrap();
let ret_offset = current_call_frame.stack.pop()?.try_into().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use ethereum_rust_rlp;
use ethereum_rust_rlp::encode::RLPEncode;
use ethereum_types::H160;
use keccak_hash::keccak;
use serde::{Deserialize, Serialize};
use sha3::{Digest, Keccak256};
use std::{
collections::{HashMap, HashSet},
str::FromStr,
};

#[derive(Clone, Default, Debug, PartialEq, Eq)]
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Account {
pub address: Address,
pub balance: U256,
Expand All @@ -24,7 +25,7 @@ pub struct Account {
pub nonce: u64,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct StorageSlot {
pub original_value: U256,
pub current_value: U256,
Expand Down Expand Up @@ -154,7 +155,7 @@ impl Db {
#[derive(Debug, Clone, Default)]
// TODO: https://github.com/lambdaclass/ethereum_rust/issues/604
pub struct Substate {
pub warm_addresses: HashSet<Address>,
pub warm_addresses: HashSet<Address>, // Should be a hashmap <Address, AccountInfo>
}

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -366,11 +367,10 @@ impl VM {
if contract_code.len() > MAX_CODE_SIZE {
return Err(VMError::ContractOutputTooBig);
}
// Supposing contract code has contents
if contract_code[0] == INVALID_CONTRACT_PREFIX {

if !contract_code.is_empty() && contract_code[0] == INVALID_CONTRACT_PREFIX {
return Err(VMError::InvalidInitialByte);
}

// If the initialization code completes successfully, a final contract-creation cost is paid,
// the code-deposit cost, c, proportional to the size of the created contract’s code
let creation_cost = 200 * contract_code.len();
Expand Down
Loading