Merge pull request #238 from mjkeating/tree_hash_add_padding2

Updated TreeHash to spec - added padding
This commit is contained in:
Paul Hauner
2019-02-19 16:54:36 +11:00
committed by GitHub
33 changed files with 267 additions and 218 deletions
+7 -7
View File
@@ -60,12 +60,12 @@ impl Decodable for Attestation {
}
impl TreeHash for Attestation {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.aggregation_bitfield.hash_tree_root());
result.append(&mut self.data.hash_tree_root());
result.append(&mut self.custody_bitfield.hash_tree_root());
result.append(&mut self.aggregate_signature.hash_tree_root());
result.append(&mut self.aggregation_bitfield.hash_tree_root_internal());
result.append(&mut self.data.hash_tree_root_internal());
result.append(&mut self.custody_bitfield.hash_tree_root_internal());
result.append(&mut self.aggregate_signature.hash_tree_root_internal());
hash(&result)
}
}
@@ -99,11 +99,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Attestation::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+11 -11
View File
@@ -82,16 +82,16 @@ impl Decodable for AttestationData {
}
impl TreeHash for AttestationData {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.slot.hash_tree_root());
result.append(&mut self.shard.hash_tree_root());
result.append(&mut self.beacon_block_root.hash_tree_root());
result.append(&mut self.epoch_boundary_root.hash_tree_root());
result.append(&mut self.shard_block_root.hash_tree_root());
result.append(&mut self.latest_crosslink.hash_tree_root());
result.append(&mut self.justified_epoch.hash_tree_root());
result.append(&mut self.justified_block_root.hash_tree_root());
result.append(&mut self.slot.hash_tree_root_internal());
result.append(&mut self.shard.hash_tree_root_internal());
result.append(&mut self.beacon_block_root.hash_tree_root_internal());
result.append(&mut self.epoch_boundary_root.hash_tree_root_internal());
result.append(&mut self.shard_block_root.hash_tree_root_internal());
result.append(&mut self.latest_crosslink.hash_tree_root_internal());
result.append(&mut self.justified_epoch.hash_tree_root_internal());
result.append(&mut self.justified_block_root.hash_tree_root_internal());
hash(&result)
}
}
@@ -129,11 +129,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = AttestationData::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
@@ -29,11 +29,11 @@ impl Decodable for AttestationDataAndCustodyBit {
}
impl TreeHash for AttestationDataAndCustodyBit {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.data.hash_tree_root());
result.append(&mut self.data.hash_tree_root_internal());
// TODO: add bool ssz
// result.append(custody_bit.hash_tree_root());
// result.append(custody_bit.hash_tree_root_internal());
ssz::hash(&result)
}
}
@@ -68,11 +68,11 @@ mod test {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = AttestationDataAndCustodyBit::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+5 -5
View File
@@ -32,10 +32,10 @@ impl Decodable for AttesterSlashing {
}
impl TreeHash for AttesterSlashing {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.slashable_attestation_1.hash_tree_root());
result.append(&mut self.slashable_attestation_2.hash_tree_root());
result.append(&mut self.slashable_attestation_1.hash_tree_root_internal());
result.append(&mut self.slashable_attestation_2.hash_tree_root_internal());
hash(&result)
}
}
@@ -67,11 +67,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = AttesterSlashing::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+10 -10
View File
@@ -97,15 +97,15 @@ impl Decodable for BeaconBlock {
}
impl TreeHash for BeaconBlock {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.slot.hash_tree_root());
result.append(&mut self.parent_root.hash_tree_root());
result.append(&mut self.state_root.hash_tree_root());
result.append(&mut self.randao_reveal.hash_tree_root());
result.append(&mut self.eth1_data.hash_tree_root());
result.append(&mut self.signature.hash_tree_root());
result.append(&mut self.body.hash_tree_root());
result.append(&mut self.slot.hash_tree_root_internal());
result.append(&mut self.parent_root.hash_tree_root_internal());
result.append(&mut self.state_root.hash_tree_root_internal());
result.append(&mut self.randao_reveal.hash_tree_root_internal());
result.append(&mut self.eth1_data.hash_tree_root_internal());
result.append(&mut self.signature.hash_tree_root_internal());
result.append(&mut self.body.hash_tree_root_internal());
hash(&result)
}
}
@@ -142,11 +142,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = BeaconBlock::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+8 -8
View File
@@ -45,13 +45,13 @@ impl Decodable for BeaconBlockBody {
}
impl TreeHash for BeaconBlockBody {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.proposer_slashings.hash_tree_root());
result.append(&mut self.attester_slashings.hash_tree_root());
result.append(&mut self.attestations.hash_tree_root());
result.append(&mut self.deposits.hash_tree_root());
result.append(&mut self.exits.hash_tree_root());
result.append(&mut self.proposer_slashings.hash_tree_root_internal());
result.append(&mut self.attester_slashings.hash_tree_root_internal());
result.append(&mut self.attestations.hash_tree_root_internal());
result.append(&mut self.deposits.hash_tree_root_internal());
result.append(&mut self.exits.hash_tree_root_internal());
hash(&result)
}
}
@@ -86,11 +86,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = BeaconBlockBody::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+30 -26
View File
@@ -1059,33 +1059,37 @@ impl Decodable for BeaconState {
}
impl TreeHash for BeaconState {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.slot.hash_tree_root());
result.append(&mut self.genesis_time.hash_tree_root());
result.append(&mut self.fork.hash_tree_root());
result.append(&mut self.validator_registry.hash_tree_root());
result.append(&mut self.validator_balances.hash_tree_root());
result.append(&mut self.validator_registry_update_epoch.hash_tree_root());
result.append(&mut self.latest_randao_mixes.hash_tree_root());
result.append(&mut self.previous_epoch_start_shard.hash_tree_root());
result.append(&mut self.current_epoch_start_shard.hash_tree_root());
result.append(&mut self.previous_calculation_epoch.hash_tree_root());
result.append(&mut self.current_calculation_epoch.hash_tree_root());
result.append(&mut self.previous_epoch_seed.hash_tree_root());
result.append(&mut self.current_epoch_seed.hash_tree_root());
result.append(&mut self.previous_justified_epoch.hash_tree_root());
result.append(&mut self.justified_epoch.hash_tree_root());
result.append(&mut self.justification_bitfield.hash_tree_root());
result.append(&mut self.finalized_epoch.hash_tree_root());
result.append(&mut self.latest_crosslinks.hash_tree_root());
result.append(&mut self.latest_block_roots.hash_tree_root());
result.append(&mut self.latest_index_roots.hash_tree_root());
result.append(&mut self.latest_penalized_balances.hash_tree_root());
result.append(&mut self.latest_attestations.hash_tree_root());
result.append(&mut self.batched_block_roots.hash_tree_root());
result.append(&mut self.latest_eth1_data.hash_tree_root());
result.append(&mut self.eth1_data_votes.hash_tree_root());
result.append(&mut self.slot.hash_tree_root_internal());
result.append(&mut self.genesis_time.hash_tree_root_internal());
result.append(&mut self.fork.hash_tree_root_internal());
result.append(&mut self.validator_registry.hash_tree_root_internal());
result.append(&mut self.validator_balances.hash_tree_root_internal());
result.append(
&mut self
.validator_registry_update_epoch
.hash_tree_root_internal(),
);
result.append(&mut self.latest_randao_mixes.hash_tree_root_internal());
result.append(&mut self.previous_epoch_start_shard.hash_tree_root_internal());
result.append(&mut self.current_epoch_start_shard.hash_tree_root_internal());
result.append(&mut self.previous_calculation_epoch.hash_tree_root_internal());
result.append(&mut self.current_calculation_epoch.hash_tree_root_internal());
result.append(&mut self.previous_epoch_seed.hash_tree_root_internal());
result.append(&mut self.current_epoch_seed.hash_tree_root_internal());
result.append(&mut self.previous_justified_epoch.hash_tree_root_internal());
result.append(&mut self.justified_epoch.hash_tree_root_internal());
result.append(&mut self.justification_bitfield.hash_tree_root_internal());
result.append(&mut self.finalized_epoch.hash_tree_root_internal());
result.append(&mut self.latest_crosslinks.hash_tree_root_internal());
result.append(&mut self.latest_block_roots.hash_tree_root_internal());
result.append(&mut self.latest_index_roots.hash_tree_root_internal());
result.append(&mut self.latest_penalized_balances.hash_tree_root_internal());
result.append(&mut self.latest_attestations.hash_tree_root_internal());
result.append(&mut self.batched_block_roots.hash_tree_root_internal());
result.append(&mut self.latest_eth1_data.hash_tree_root_internal());
result.append(&mut self.eth1_data_votes.hash_tree_root_internal());
hash(&result)
}
}
+2 -2
View File
@@ -85,11 +85,11 @@ pub fn test_ssz_round_trip() {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = BeaconState::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+5 -5
View File
@@ -33,10 +33,10 @@ impl Decodable for CasperSlashing {
}
impl TreeHash for CasperSlashing {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.slashable_vote_data_1.hash_tree_root());
result.append(&mut self.slashable_vote_data_2.hash_tree_root());
result.append(&mut self.slashable_vote_data_1.hash_tree_root_internal());
result.append(&mut self.slashable_vote_data_2.hash_tree_root_internal());
hash(&result)
}
}
@@ -68,11 +68,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = CasperSlashing::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+5 -5
View File
@@ -43,10 +43,10 @@ impl Decodable for Crosslink {
}
impl TreeHash for Crosslink {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.epoch.hash_tree_root());
result.append(&mut self.shard_block_root.hash_tree_root());
result.append(&mut self.epoch.hash_tree_root_internal());
result.append(&mut self.shard_block_root.hash_tree_root_internal());
hash(&result)
}
}
@@ -78,11 +78,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Crosslink::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -37,11 +37,11 @@ impl Decodable for Deposit {
}
impl TreeHash for Deposit {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.branch.hash_tree_root());
result.append(&mut self.index.hash_tree_root());
result.append(&mut self.deposit_data.hash_tree_root());
result.append(&mut self.branch.hash_tree_root_internal());
result.append(&mut self.index.hash_tree_root_internal());
result.append(&mut self.deposit_data.hash_tree_root_internal());
hash(&result)
}
}
@@ -74,11 +74,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Deposit::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -37,11 +37,11 @@ impl Decodable for DepositData {
}
impl TreeHash for DepositData {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.amount.hash_tree_root());
result.append(&mut self.timestamp.hash_tree_root());
result.append(&mut self.deposit_input.hash_tree_root());
result.append(&mut self.amount.hash_tree_root_internal());
result.append(&mut self.timestamp.hash_tree_root_internal());
result.append(&mut self.deposit_input.hash_tree_root_internal());
hash(&result)
}
}
@@ -74,11 +74,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = DepositData::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -38,11 +38,11 @@ impl Decodable for DepositInput {
}
impl TreeHash for DepositInput {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.pubkey.hash_tree_root());
result.append(&mut self.withdrawal_credentials.hash_tree_root());
result.append(&mut self.proof_of_possession.hash_tree_root());
result.append(&mut self.pubkey.hash_tree_root_internal());
result.append(&mut self.withdrawal_credentials.hash_tree_root_internal());
result.append(&mut self.proof_of_possession.hash_tree_root_internal());
hash(&result)
}
}
@@ -75,11 +75,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = DepositInput::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+5 -5
View File
@@ -34,10 +34,10 @@ impl Decodable for Eth1Data {
}
impl TreeHash for Eth1Data {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.deposit_root.hash_tree_root());
result.append(&mut self.block_hash.hash_tree_root());
result.append(&mut self.deposit_root.hash_tree_root_internal());
result.append(&mut self.block_hash.hash_tree_root_internal());
hash(&result)
}
}
@@ -69,11 +69,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Eth1Data::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+5 -5
View File
@@ -34,10 +34,10 @@ impl Decodable for Eth1DataVote {
}
impl TreeHash for Eth1DataVote {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.eth1_data.hash_tree_root());
result.append(&mut self.vote_count.hash_tree_root());
result.append(&mut self.eth1_data.hash_tree_root_internal());
result.append(&mut self.vote_count.hash_tree_root_internal());
hash(&result)
}
}
@@ -69,11 +69,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Eth1DataVote::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -37,11 +37,11 @@ impl Decodable for Exit {
}
impl TreeHash for Exit {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.epoch.hash_tree_root());
result.append(&mut self.validator_index.hash_tree_root());
result.append(&mut self.signature.hash_tree_root());
result.append(&mut self.epoch.hash_tree_root_internal());
result.append(&mut self.validator_index.hash_tree_root_internal());
result.append(&mut self.signature.hash_tree_root_internal());
hash(&result)
}
}
@@ -74,11 +74,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Exit::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -36,11 +36,11 @@ impl Decodable for Fork {
}
impl TreeHash for Fork {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.previous_version.hash_tree_root());
result.append(&mut self.current_version.hash_tree_root());
result.append(&mut self.epoch.hash_tree_root());
result.append(&mut self.previous_version.hash_tree_root_internal());
result.append(&mut self.current_version.hash_tree_root_internal());
result.append(&mut self.epoch.hash_tree_root_internal());
hash(&result)
}
}
@@ -73,11 +73,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Fork::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+7 -7
View File
@@ -41,12 +41,12 @@ impl Decodable for PendingAttestation {
}
impl TreeHash for PendingAttestation {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.aggregation_bitfield.hash_tree_root());
result.append(&mut self.data.hash_tree_root());
result.append(&mut self.custody_bitfield.hash_tree_root());
result.append(&mut self.inclusion_slot.hash_tree_root());
result.append(&mut self.aggregation_bitfield.hash_tree_root_internal());
result.append(&mut self.data.hash_tree_root_internal());
result.append(&mut self.custody_bitfield.hash_tree_root_internal());
result.append(&mut self.inclusion_slot.hash_tree_root_internal());
hash(&result)
}
}
@@ -80,11 +80,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = PendingAttestation::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -37,11 +37,11 @@ impl Decodable for ProposalSignedData {
}
impl TreeHash for ProposalSignedData {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.slot.hash_tree_root());
result.append(&mut self.shard.hash_tree_root());
result.append(&mut self.block_root.hash_tree_root());
result.append(&mut self.slot.hash_tree_root_internal());
result.append(&mut self.shard.hash_tree_root_internal());
result.append(&mut self.block_root.hash_tree_root_internal());
hash(&result)
}
}
@@ -74,11 +74,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = ProposalSignedData::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+8 -8
View File
@@ -46,13 +46,13 @@ impl Decodable for ProposerSlashing {
}
impl TreeHash for ProposerSlashing {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.proposer_index.hash_tree_root());
result.append(&mut self.proposal_data_1.hash_tree_root());
result.append(&mut self.proposal_signature_1.hash_tree_root());
result.append(&mut self.proposal_data_2.hash_tree_root());
result.append(&mut self.proposal_signature_2.hash_tree_root());
result.append(&mut self.proposer_index.hash_tree_root_internal());
result.append(&mut self.proposal_data_1.hash_tree_root_internal());
result.append(&mut self.proposal_signature_1.hash_tree_root_internal());
result.append(&mut self.proposal_data_2.hash_tree_root_internal());
result.append(&mut self.proposal_signature_2.hash_tree_root_internal());
hash(&result)
}
}
@@ -87,11 +87,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = ProposerSlashing::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+6 -6
View File
@@ -36,11 +36,11 @@ impl Decodable for ShardReassignmentRecord {
}
impl TreeHash for ShardReassignmentRecord {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.validator_index.hash_tree_root());
result.append(&mut self.shard.hash_tree_root());
result.append(&mut self.slot.hash_tree_root());
result.append(&mut self.validator_index.hash_tree_root_internal());
result.append(&mut self.shard.hash_tree_root_internal());
result.append(&mut self.slot.hash_tree_root_internal());
hash(&result)
}
}
@@ -73,11 +73,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = ShardReassignmentRecord::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+7 -7
View File
@@ -40,12 +40,12 @@ impl Decodable for SlashableAttestation {
}
impl TreeHash for SlashableAttestation {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.validator_indices.hash_tree_root());
result.append(&mut self.data.hash_tree_root());
result.append(&mut self.custody_bitfield.hash_tree_root());
result.append(&mut self.aggregate_signature.hash_tree_root());
result.append(&mut self.validator_indices.hash_tree_root_internal());
result.append(&mut self.data.hash_tree_root_internal());
result.append(&mut self.custody_bitfield.hash_tree_root_internal());
result.append(&mut self.aggregate_signature.hash_tree_root_internal());
hash(&result)
}
}
@@ -79,11 +79,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = SlashableAttestation::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+7 -7
View File
@@ -64,12 +64,12 @@ impl Decodable for SlashableVoteData {
}
impl TreeHash for SlashableVoteData {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.custody_bit_0_indices.hash_tree_root());
result.append(&mut self.custody_bit_1_indices.hash_tree_root());
result.append(&mut self.data.hash_tree_root());
result.append(&mut self.aggregate_signature.hash_tree_root());
result.append(&mut self.custody_bit_0_indices.hash_tree_root_internal());
result.append(&mut self.custody_bit_1_indices.hash_tree_root_internal());
result.append(&mut self.data.hash_tree_root_internal());
result.append(&mut self.aggregate_signature.hash_tree_root_internal());
hash(&result)
}
}
@@ -177,11 +177,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = SlashableVoteData::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+4 -4
View File
@@ -224,9 +224,9 @@ macro_rules! impl_ssz {
}
impl TreeHash for $type {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.0.hash_tree_root());
result.append(&mut self.0.hash_tree_root_internal());
hash(&result)
}
}
@@ -560,11 +560,11 @@ macro_rules! ssz_tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = $type::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
+12 -10
View File
@@ -122,15 +122,17 @@ impl Decodable for Validator {
}
impl TreeHash for Validator {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.pubkey.hash_tree_root());
result.append(&mut self.withdrawal_credentials.hash_tree_root());
result.append(&mut self.activation_epoch.hash_tree_root());
result.append(&mut self.exit_epoch.hash_tree_root());
result.append(&mut self.withdrawal_epoch.hash_tree_root());
result.append(&mut self.penalized_epoch.hash_tree_root());
result.append(&mut u64::from(status_flag_to_byte(self.status_flags)).hash_tree_root());
result.append(&mut self.pubkey.hash_tree_root_internal());
result.append(&mut self.withdrawal_credentials.hash_tree_root_internal());
result.append(&mut self.activation_epoch.hash_tree_root_internal());
result.append(&mut self.exit_epoch.hash_tree_root_internal());
result.append(&mut self.withdrawal_epoch.hash_tree_root_internal());
result.append(&mut self.penalized_epoch.hash_tree_root_internal());
result.append(
&mut u64::from(status_flag_to_byte(self.status_flags)).hash_tree_root_internal(),
);
hash(&result)
}
}
@@ -190,11 +192,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = Validator::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests
@@ -59,13 +59,13 @@ impl Decodable for ValidatorRegistryDeltaBlock {
}
impl TreeHash for ValidatorRegistryDeltaBlock {
fn hash_tree_root(&self) -> Vec<u8> {
fn hash_tree_root_internal(&self) -> Vec<u8> {
let mut result: Vec<u8> = vec![];
result.append(&mut self.latest_registry_delta_root.hash_tree_root());
result.append(&mut self.validator_index.hash_tree_root());
result.append(&mut self.pubkey.hash_tree_root());
result.append(&mut self.slot.hash_tree_root());
result.append(&mut self.flag.hash_tree_root());
result.append(&mut self.latest_registry_delta_root.hash_tree_root_internal());
result.append(&mut self.validator_index.hash_tree_root_internal());
result.append(&mut self.pubkey.hash_tree_root_internal());
result.append(&mut self.slot.hash_tree_root_internal());
result.append(&mut self.flag.hash_tree_root_internal());
hash(&result)
}
}
@@ -100,11 +100,11 @@ mod tests {
}
#[test]
pub fn test_hash_tree_root() {
pub fn test_hash_tree_root_internal() {
let mut rng = XorShiftRng::from_seed([42; 16]);
let original = ValidatorRegistryDeltaBlock::random_for_test(&mut rng);
let result = original.hash_tree_root();
let result = original.hash_tree_root_internal();
assert_eq!(result.len(), 32);
// TODO: Add further tests