-
Notifications
You must be signed in to change notification settings - Fork 68
no-std implementation #167
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
base: main
Are you sure you want to change the base?
Changes from 16 commits
779a1e7
3e66ff7
0b79485
7492dde
8221123
ac1b571
cd52ded
0d05be0
54f8133
eeb1d5e
8849fcb
2c0d3dd
32883ab
04f9bcc
a6c3687
1f0e6e2
71710e9
df115f5
7875009
33f236a
8c50522
e5c0d21
2f46baf
248b5d1
63b847d
9177be3
6b971e2
918fda3
a850739
8be43ea
9862cab
e334085
6b7f33d
b6ced43
23cd342
bd19d7c
34bb57f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ use crate::altair as spec; | |
|
|
||
| use crate::crypto::{eth_fast_aggregate_verify, verify_signature}; | ||
| use crate::domains::DomainType; | ||
| use crate::prelude::*; | ||
| use crate::prelude::*; | ||
| use crate::primitives::{BlsPublicKey, ParticipationFlags, ValidatorIndex}; | ||
| use crate::signing::compute_signing_root; | ||
| use crate::state_transition::{ | ||
|
|
@@ -20,8 +22,6 @@ use spec::{ | |
| PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, SYNC_REWARD_WEIGHT, WEIGHT_DENOMINATOR, | ||
| }; | ||
| use ssz_rs::prelude::*; | ||
| use std::collections::{HashMap, HashSet}; | ||
| use std::iter::zip; | ||
|
|
||
| pub fn process_attestation< | ||
| const SLOTS_PER_HISTORICAL_ROOT: usize, | ||
|
|
@@ -202,8 +202,9 @@ pub fn process_deposit< | |
|
|
||
| let public_key = &deposit.data.public_key; | ||
| let amount = deposit.data.amount; | ||
| let cloned_validators = state.validators.clone(); | ||
|
||
| let validator_public_keys: HashSet<&BlsPublicKey> = | ||
| HashSet::from_iter(state.validators.iter().map(|v| &v.public_key)); | ||
| cloned_validators.iter().map(|v| &v.public_key).collect(); | ||
| if !validator_public_keys.contains(public_key) { | ||
| let mut deposit_message = DepositMessage { | ||
| public_key: public_key.clone(), | ||
|
|
@@ -315,9 +316,9 @@ pub fn process_sync_aggregate< | |
| let proposer_reward = | ||
| participant_reward * PROPOSER_WEIGHT / (WEIGHT_DENOMINATOR - PROPOSER_WEIGHT); | ||
|
|
||
| let cloned_validators = state.validators.clone(); | ||
|
||
| // Apply participant and proposer rewards | ||
| let all_public_keys = state | ||
| .validators | ||
| let all_public_keys = cloned_validators | ||
| .iter() | ||
| .enumerate() | ||
| .map(|(i, v)| (&v.public_key, i)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ pub use crate::altair::helpers::get_unslashed_participating_indices; | |
| pub use crate::altair::helpers::has_flag; | ||
| pub use crate::altair::helpers::slash_validator; | ||
| use crate::crypto::{fast_aggregate_verify, hash, verify_signature}; | ||
| use crate::prelude::*; | ||
| use crate::primitives::{ | ||
| Bytes32, CommitteeIndex, Domain, DomainType, Epoch, ForkDigest, Gwei, Root, Slot, | ||
| ValidatorIndex, Version, FAR_FUTURE_EPOCH, GENESIS_EPOCH, | ||
|
|
@@ -25,8 +26,7 @@ use spec::{ | |
| Validator, | ||
| }; | ||
| use ssz_rs::prelude::*; | ||
| use std::cmp; | ||
| use std::collections::HashSet; | ||
|
|
||
| pub fn compute_activation_exit_epoch(epoch: Epoch, context: &Context) -> Epoch { | ||
| epoch + 1 + context.max_seed_lookahead | ||
| } | ||
|
|
@@ -117,7 +117,12 @@ pub fn compute_proposer_index< | |
| loop { | ||
| let shuffled_index = compute_shuffled_index((i % total) as usize, total, seed, context)?; | ||
| let candidate_index = indices[shuffled_index]; | ||
| let i_bytes: [u8; 8] = (i / 32).to_le_bytes(); | ||
| #[cfg(not(feature = "serde"))] | ||
| let i_bytes: [u8; 4] = (i.saturating_div(32)).to_le_bytes(); | ||
|
|
||
| #[cfg(feature = "serde")] | ||
| let i_bytes: [u8; 8] = (i.saturating_div(32)).to_le_bytes(); | ||
|
|
||
|
||
| hash_input[32..].copy_from_slice(&i_bytes); | ||
| let random_byte = hash(hash_input).as_ref()[(i % 32)] as u64; | ||
| let effective_balance = state.validators[candidate_index].effective_balance; | ||
|
|
@@ -254,7 +259,7 @@ pub fn get_attesting_indices< | |
| }, | ||
| ))); | ||
| } | ||
| let mut indices = HashSet::with_capacity(bits.capacity()); | ||
| let mut indices = HashSet::new(); | ||
| for (i, validator_index) in committee.iter().enumerate() { | ||
| if bits[i] { | ||
| indices.insert(*validator_index); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.