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

Add Deneb (EIP-4844) types and presets #170

Merged
merged 20 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ce7ae59
Add types & presets for EIP-4844 (Deneb)
jimmygchen Jan 16, 2023
cf0dc53
Add SignedBeaconBlockAndBlobsSidecar
jimmygchen Jan 16, 2023
f1979b7
Merge branch 'main' into deneb-types-and-presets
jimmygchen Jan 16, 2023
9753758
Merge branch 'capella-types-and-presets' into deneb-types-and-presets
jimmygchen Jan 16, 2023
999c76c
Merge branch 'main' into deneb-types-and-presets
jimmygchen Jan 17, 2023
29a2d9d
Remove unnecessary kzg struct and error types
jimmygchen Jan 19, 2023
2ec0027
Merge branch 'main' into deneb-types-and-presets
jimmygchen Jan 19, 2023
a7bdc61
Make KZG constants public
jimmygchen Jan 19, 2023
9d757a5
Merge branch 'deneb-types-and-presets' of github.com:jimmygchen/ether…
jimmygchen Jan 19, 2023
cca4e6f
Merge branch 'capella-types-and-presets' into deneb-types-and-presets
jimmygchen Jan 25, 2023
d2e3969
Merge branch 'main' into deneb-types-and-presets
jimmygchen Feb 2, 2023
d8f1307
Add missing serde annotation
jimmygchen Feb 2, 2023
f4cbc30
Merge branch 'main' into deneb-types-and-presets
jimmygchen Feb 16, 2023
22b9915
Replace all EIP4844 references with Deneb
jimmygchen Feb 16, 2023
4c82111
Free the blobs and add BlindedBlobSidecar
jimmygchen Feb 16, 2023
d421d28
Merge branch 'main' into deneb-types-and-presets
jimmygchen Mar 30, 2023
ff52824
Merge branch 'main' into deneb-types-and-presets
jimmygchen Apr 3, 2023
184c841
Merge branch 'main' into deneb-types-and-presets
jimmygchen Jul 12, 2023
6fa4035
Update Deneb types to latest spec
jimmygchen Jul 12, 2023
4d40289
Add Deneb `BeaconState`s to presets.
jimmygchen Jul 12, 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
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI suite

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Read toolchain file
id: rust-toolchain
run: |
RUST_TOOLCHAIN=$(grep 'channel' rust-toolchain.toml | awk '{split($0,a," = "); print a[2]}' | tr -d '"')
echo "RUST_TOOLCHAIN=$RUST_TOOLCHAIN" >> $GITHUB_OUTPUT
shell: bash

- name: Install toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.rust-toolchain.outputs.RUST_TOOLCHAIN }}

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Build
run: cargo build --all-targets --all-features --verbose

- name: Run tests
run: cargo test --verbose

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true

- name: Check format
run: cargo +nightly fmt --all --check

- name: Check clippy
run: cargo +nightly clippy --all-targets --all-features --verbose -- -D warnings
30 changes: 0 additions & 30 deletions .github/workflows/rust.yml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fn main() {
let sig = sk.sign(msg);

let valid = verify_signature(&pk, msg, &sig).is_ok();
println!("Signature is valid: {:?}", valid);
println!("Signature is valid: {valid:?}");
}
4 changes: 2 additions & 2 deletions examples/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() {
.push(SignedVoluntaryExit::default());

let block_json = serde_json::to_string(&block).unwrap();
println!("{}", block_json);
println!("{block_json}");
let _: SignedBeaconBlock = serde_json::from_str(&block_json).unwrap();

let mut state = BeaconState::default();
Expand All @@ -37,7 +37,7 @@ fn main() {
.push(PendingAttestation::default());

let state_json = serde_json::to_string(&state).unwrap();
println!("{}", state_json);
println!("{state_json}");
let _: BeaconState = serde_json::from_str(&state_json).unwrap();

let sync_committee = SyncCommittee::default();
Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ test:
# partition much heavier "integration tests" to a separate command
cargo test
fmt:
cargo fmt
cargo +nightly fmt --all
lint: fmt
cargo clippy --all-features
cargo +nightly clippy --all-targets --all-features
build:
cargo build --all-features
cargo build --all-targets --all-features
run-ci: lint build test
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.66"
2 changes: 1 addition & 1 deletion src/altair/state_transition/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub fn process_voluntary_exit<
validator.activation_eligibility_epoch + context.shard_committee_period;
if current_epoch < minimum_time_active {
return Err(invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::ValidatoIsNotActiveForLongEnough {
InvalidVoluntaryExit::ValidatorIsNotActiveForLongEnough {
current_epoch,
minimum_time_active,
},
Expand Down
2 changes: 1 addition & 1 deletion src/bellatrix/state_transition/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ pub fn process_voluntary_exit<
validator.activation_eligibility_epoch + context.shard_committee_period;
if current_epoch < minimum_time_active {
return Err(invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::ValidatoIsNotActiveForLongEnough {
InvalidVoluntaryExit::ValidatorIsNotActiveForLongEnough {
current_epoch,
minimum_time_active,
},
Expand Down
5 changes: 2 additions & 3 deletions src/bin/gen_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ impl VisitMut for GenericsEditor {
}) {
let generics = &mut node.generics;
for bound in BELLATRIX_BEACON_STATE_BOUNDS {
let param: GenericParam =
syn::parse_str(&format!("const {}: usize", bound)).unwrap();
let param: GenericParam = syn::parse_str(&format!("const {bound}: usize")).unwrap();
generics.params.push(param);
}
}
Expand Down Expand Up @@ -436,7 +435,7 @@ struct Spec {
}

fn load_modules(spec: Specs, modules: &[Modules]) -> HashMap<Modules, Module> {
let module_dir = PathBuf::from(format!("src/{}", spec));
let module_dir = PathBuf::from(format!("src/{spec}"));
let mut loaded_modules = HashMap::new();
for &m in modules {
let module = Module::new(m, spec);
Expand Down
33 changes: 14 additions & 19 deletions src/bin/gen_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn generate_module_decl_src<'a>(modules: impl Iterator<Item = &'a String>) -> St
} else {
module
};
writeln!(src, "mod {};", module).unwrap();
writeln!(src, "mod {module};").unwrap();
}
src
}
Expand Down Expand Up @@ -118,8 +118,7 @@ fn generate_suite_src(

writeln!(
src,
"use crate::spec_test_runners::{}::{};",
runner, test_case_type
"use crate::spec_test_runners::{runner}::{test_case_type};",
)
.unwrap();

Expand Down Expand Up @@ -152,7 +151,7 @@ fn generate_suite_src(
generics += ", usize"
}
}
test_case_type = format!("{}::<{}>", test_case_type, generics);
test_case_type = format!("{test_case_type}::<{generics}>");
if data.execution_handler.len() == 1 && data.execution_handler.contains_key(&Spec::All)
{
execution_handler += &data.execution_handler[&Spec::All];
Expand All @@ -179,16 +178,15 @@ fn generate_suite_src(
}

if needs_spec_import {
writeln!(src, "use ethereum_consensus::{}::{} as spec;", fork, config).unwrap();
writeln!(src, "use ethereum_consensus::{fork}::{config} as spec;").unwrap();
writeln!(src, "use ssz_rs::prelude::*;").unwrap();
}

// special case imports here...
if matches!(runner, "transition") {
writeln!(
src,
"use ethereum_consensus::state_transition::{}::{{Executor, BeaconState}};",
config
"use ethereum_consensus::state_transition::{config}::{{Executor, BeaconState}};",
)
.unwrap();
let pre_fork = match spec {
Expand All @@ -198,24 +196,22 @@ fn generate_suite_src(
};
writeln!(
src,
"use ethereum_consensus::{}::{} as pre_spec;",
pre_fork, config
"use ethereum_consensus::{pre_fork}::{config} as pre_spec;",
)
.unwrap();
writeln!(
src,
"use ethereum_consensus::bellatrix::{}::NoOpExecutionEngine;",
config
"use ethereum_consensus::bellatrix::{config}::NoOpExecutionEngine;",
)
.unwrap();
}
if matches!(runner, "fork") {
match spec {
Spec::Altair => {
writeln!(src, "use ethereum_consensus::phase0::{} as phase0;", config).unwrap();
writeln!(src, "use ethereum_consensus::phase0::{config} as phase0;").unwrap();
}
Spec::Bellatrix => {
writeln!(src, "use ethereum_consensus::altair::{} as altair;", config).unwrap();
writeln!(src, "use ethereum_consensus::altair::{config} as altair;").unwrap();
}
_ => todo!("support other forks"),
}
Expand All @@ -227,13 +223,12 @@ fn generate_suite_src(
let test_src = format!(
r#"
#[test]
fn test_{}() {{
let {} test_case = {}::from("{}");
{}
test_case.{};
fn test_{test_case}() {{
let {mut_decl} test_case = {test_case_type}::from("{source_path}");
{preamble}
test_case.{execution_handler};
}}
"#,
test_case, mut_decl, test_case_type, source_path, preamble, execution_handler,
"#
);
src += &test_src;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn write_bytes_to_lower_hex<T: AsRef<[u8]>>(
write!(f, "0x")?;
}
for i in data.as_ref() {
write!(f, "{:02x}", i)?;
write!(f, "{i:02x}")?;
}
Ok(())
}
1 change: 1 addition & 0 deletions src/capella/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use blinded_beacon_block::*;
pub use bls_to_execution_change::*;
pub use execution::*;
pub use presets::Preset;
pub use withdrawal::*;

pub use crate::altair::{
SyncAggregate, SyncAggregatorSelectionData, SyncCommittee, PARTICIPATION_FLAG_WEIGHTS,
Expand Down
8 changes: 4 additions & 4 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ impl fmt::LowerHex for PublicKey {

impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "PublicKey({:#x})", self)
write!(f, "PublicKey({self:#x})")
}
}

impl fmt::Display for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#x}", self)
write!(f, "{self:#x}")
}
}

Expand Down Expand Up @@ -345,13 +345,13 @@ impl fmt::LowerHex for Signature {

impl fmt::Debug for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Signature({:#x})", self)
write!(f, "Signature({self:#x})")
}
}

impl fmt::Display for Signature {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#x}", self)
write!(f, "{self:#x}")
}
}

Expand Down
Loading