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

Waylon/eip4844 #536

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d516082
eip4844
0xJepsen Jun 27, 2023
6dd8a58
eip4844
0xJepsen Jun 27, 2023
9cb1af6
point_evaluation
0xJepsen Jun 28, 2023
2236da8
compiling
0xJepsen Jul 1, 2023
81bde72
Merge branch 'main' into waylon/EIP4844
0xJepsen Jul 1, 2023
cb98cc2
map
0xJepsen Jul 3, 2023
422ef45
fmt
0xJepsen Jul 3, 2023
6581bf8
Merge branch 'waylon/EIP4844' of github.com:/0xJepsen/revm into waylo…
0xJepsen Jul 3, 2023
0ad5c0c
compile
0xJepsen Jul 15, 2023
50ded79
rewrote `point_evaluation_run()`
Autoparallel Jul 15, 2023
cc71fc1
rewrote `point_evaluation_run()`
Autoparallel Jul 15, 2023
b0dbd78
Merge branch 'waylon/EIP4844' of github.com:/0xJepsen/revm into waylo…
0xJepsen Jul 16, 2023
a6b4b10
tests :white_check_mark:
Autoparallel Jul 16, 2023
4221435
helpers
0xJepsen Jul 17, 2023
f158c0c
Merge branch 'waylon/EIP4844' of github.com:/0xJepsen/revm into waylo…
0xJepsen Jul 17, 2023
f4802d9
cryptographic helpers
0xJepsen Jul 18, 2023
0e9a803
bytes to kzgProof
0xJepsen Jul 18, 2023
a916ebc
fix: add kzg check conditions
shuklaayush Jul 18, 2023
c2d6bf9
Merge pull request #2 from shuklaayush/feat/kzg-check
0xJepsen Jul 18, 2023
678cf97
c-kzg ffi bindings
0xJepsen Jul 18, 2023
e141a5d
Update
0xJepsen Jul 21, 2023
ae9fbc7
Gas
0xJepsen Jul 27, 2023
3b0d7d9
requested changes + gas
0xJepsen Aug 1, 2023
4703719
Merge branch 'main' into waylon/EIP4844
0xJepsen Aug 1, 2023
b2df738
fmt
0xJepsen Aug 1, 2023
e59dc86
Merge branch 'waylon/EIP4844' of github.com:/0xJepsen/revm into waylo…
0xJepsen Aug 1, 2023
66fadac
Update Cargo.lock
0xJepsen Aug 1, 2023
10ff3b2
Update opcode.rs
0xJepsen Aug 1, 2023
b81aea8
specID
0xJepsen Aug 1, 2023
4109d04
check spec ID
0xJepsen Aug 1, 2023
35c3106
Merge branch 'main' into waylon/EIP4844
0xJepsen Aug 8, 2023
f036892
Merge branch 'bluealloy:main' into waylon/EIP4844
0xJepsen Aug 8, 2023
8c4b6af
remove unused imports
0xJepsen Aug 8, 2023
5ce680d
Some requested changes
0xJepsen Aug 9, 2023
4d61567
remove rust-kzg
0xJepsen Aug 9, 2023
36568d1
Merge branch 'main' into waylon/EIP4844
0xJepsen Aug 17, 2023
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
122 changes: 122 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/interpreter/src/gas/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ pub const WARM_STORAGE_READ_COST: u64 = 100;
pub const INITCODE_WORD_COST: u64 = 2;

pub const CALL_STIPEND: u64 = 2300;

/// EIP-4844: HASH_OPCODE_GAS
pub const HASH_OPCODE_GAS: u64 = 3;
1 change: 1 addition & 0 deletions crates/interpreter/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ pub fn eval<H: Host, S: Spec>(opcode: u8, interp: &mut Interpreter, host: &mut H
opcode::STATICCALL => host::static_call::<S>(interp, host), //check
opcode::CHAINID => host_env::chainid::<S>(interp, host),
opcode::MCOPY => memory::mcopy::<S>(interp, host),
opcode::HASH_OPCODE_BYTE => memory::blob_hash::<S>(interp, host),
_ => return_not_found(interp, host),
}
}
33 changes: 25 additions & 8 deletions crates/interpreter/src/instructions/memory.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use core::cmp::max;
use core::ops::Index;

use revm_primitives::SpecId::CANCUN;
use crate::{gas, interpreter::Interpreter, primitives::U256, Host, InstructionResult};
use core::cmp::max;

use crate::{
gas,
interpreter::Interpreter,
primitives::{Spec, U256},
Host, InstructionResult,
};
use revm_primitives::{Spec, SpecId::CANCUN};

pub fn mload(interpreter: &mut Interpreter, _host: &mut dyn Host) {
gas!(interpreter, gas::VERYLOW);
Expand Down Expand Up @@ -68,3 +64,24 @@ pub fn mcopy<SPEC: Spec>(interpreter: &mut Interpreter, _host: &mut dyn Host) {
// copy memory in place
interpreter.memory.copy(dest, src, len);
}

/// see https://eips.ethereum.org/EIPS/eip-4844
pub fn blob_hash<SPEC: Spec>(interpreter: &mut Interpreter, host: &mut dyn Host) {
check!(interpreter, SPEC::enabled(CANCUN));
// We add an instruction BLOBHASH (with opcode HASH_OPCODE_BYTE) which reads index from the top of the stack as big-endian uint256,
// and replaces it on the stack with tx.blob_versioned_hashes[index] if index < len(tx.blob_versioned_hashes),
// and otherwise with a zeroed bytes32 value. The opcode has a gas cost of HASH_OPCODE_GAS.
gas!(interpreter, gas::HASH_OPCODE_GAS);
pop_top!(interpreter, index);
let index = as_usize_saturated!(index);
if index < host.env().tx.blob_versioned_hashes.len() {
// Replace the top of the stack with the versioned hash here
push!(
interpreter,
*host.env().tx.blob_versioned_hashes.index(index)
);
} else {
// else write out a zerod out 32 bytes
push!(interpreter, U256::ZERO);
}
}
5 changes: 3 additions & 2 deletions crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub const INVALID: u8 = 0xfe;
pub const ADDRESS: u8 = 0x30;
pub const BALANCE: u8 = 0x31;
pub const BASEFEE: u8 = 0x48;
pub const HASH_OPCODE_BYTE: u8 = 0x49;
pub const ORIGIN: u8 = 0x32;
pub const CALLER: u8 = 0x33;
pub const CALLVALUE: u8 = 0x34;
Expand Down Expand Up @@ -262,7 +263,7 @@ pub const OPCODE_JUMPMAP: [Option<&'static str>; 256] = [
/* 0x46 */ Some("CHAINID"),
/* 0x47 */ Some("SELFBALANCE"),
/* 0x48 */ Some("BASEFEE"),
/* 0x49 */ None,
/* 0x49 */ Some("HASH_OPCODE_BYTE"),
/* 0x4a */ None,
/* 0x4b */ None,
/* 0x4c */ None,
Expand Down Expand Up @@ -642,7 +643,7 @@ macro_rules! gas_opcodee {
} else {
0
}),
/* 0x49 */ OpInfo::none(),
/* 0x49 */ OpInfo::gas(3),
/* 0x4a */ OpInfo::none(),
/* 0x4b */ OpInfo::none(),
/* 0x4c */ OpInfo::none(),
Expand Down
4 changes: 4 additions & 0 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ secp256k1 = { version = "0.27.0", default-features = false, features = [
], optional = true }
sha2 = { version = "0.10.5", default-features = false }

# For the audited ckzg ffi bindings from the EF
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", package = "c-kzg" }


[dev-dependencies]
hex = "0.4"

Expand Down
21 changes: 20 additions & 1 deletion crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod bn128;
mod hash;
mod identity;
mod modexp;
mod point_evaluation;
mod secp256k1;

use once_cell::sync::OnceCell;
Expand Down Expand Up @@ -92,7 +93,8 @@ pub enum SpecId {
BYZANTIUM = 1,
ISTANBUL = 2,
BERLIN = 3,
LATEST = 4,
CANCUN = 4,
LATEST = 5,
}

impl SpecId {
Expand Down Expand Up @@ -191,6 +193,22 @@ impl Precompiles {
})
}

pub fn cancun() -> &'static Self {
static INSTANCE: OnceCell<Precompiles> = OnceCell::new();
INSTANCE.get_or_init(|| {
let mut precompiles = Self::berlin().clone();
precompiles.fun.extend(
vec![
// EIP-4848: Point evaluation precompile.
point_evaluation::POINT_EVALUATION_PRECOMPILE,
]
.into_iter()
.map(From::from),
);
precompiles
})
}

pub fn latest() -> &'static Self {
Self::berlin()
}
Expand All @@ -201,6 +219,7 @@ impl Precompiles {
SpecId::BYZANTIUM => Self::byzantium(),
SpecId::ISTANBUL => Self::istanbul(),
SpecId::BERLIN => Self::berlin(),
SpecId::CANCUN => Self::cancun(),
SpecId::LATEST => Self::latest(),
}
}
Expand Down
Loading
Loading