Skip to content

Commit

Permalink
feat: update apply_deposit and add_validator_to_registry to altai…
Browse files Browse the repository at this point in the history
…r changes (ReamLabs#103)

* fix: correctly implement apply_deposit and add_validator_to_registry

* chore: make linter happy

* test: integrate ef-tests

* fix: apply reviews from jihoon and kolby

* chore: make linter happy
  • Loading branch information
syjn99 authored Feb 15, 2025
1 parent 5d51028 commit d151b93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions crates/common/consensus/src/deneb/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,15 @@ impl BeaconState {
self.balances
.push(amount)
.map_err(|err| anyhow!("Couldn't push to balances {:?}", err))?;
self.previous_epoch_participation
.push(0)
.map_err(|err| anyhow!("Couldn't push to previous_epoch_participation {:?}", err))?;
self.current_epoch_participation
.push(0)
.map_err(|err| anyhow!("Couldn't push to current_epoch_participation {:?}", err))?;
self.inactivity_scores
.push(0)
.map_err(|err| anyhow!("Couldn't push to inactivity_scores {:?}", err))?;
Ok(())
}

Expand All @@ -823,8 +832,10 @@ impl BeaconState {
let signing_root = compute_signing_root(deposit_message, domain);
let sig = blst::min_pk::Signature::from_bytes(&signature.signature)
.map_err(|err| anyhow!("Failed to convert signiture type {err:?}"))?;
let public_key = PublicKey::from_bytes(&pubkey.inner)
.map_err(|err| anyhow!("Failed to convert pubkey type {err:?}"))?;
let public_key = match PublicKey::from_bytes(&pubkey.inner) {
Ok(pk) => pk,
Err(_) => return Ok(()), // Skip deposits with invalid public keys
};
let verification_result =
sig.fast_aggregate_verify(true, signing_root.as_ref(), DST, &[&public_key]);
if verification_result == blst::BLST_ERROR::BLST_SUCCESS {
Expand Down
3 changes: 2 additions & 1 deletion testing/ef-tests/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "ef-tests")]

use ef_tests::test_consensus_type;
use ef_tests::{test_consensus_type, test_operation, utils};
use ream_consensus::{
attestation::Attestation,
attestation_data::AttestationData,
Expand Down Expand Up @@ -64,3 +64,4 @@ test_consensus_type!(VoluntaryExit);
test_consensus_type!(Withdrawal);

// Testing operations for block processing
test_operation!(deposit, Deposit, "deposit", process_deposit);

0 comments on commit d151b93

Please sign in to comment.