Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Conversation

@rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Aug 5, 2019

Follow the spec: Use the concatenation of VRF outputs within the epoch as opposed to the XOR.

@rphmeier rphmeier added the A0-please_review Pull request needs code review. label Aug 5, 2019
Copy link
Contributor

@Demi-Marie Demi-Marie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit

let segment_idx: u32 = <SegmentIndex>::mutate(|s| rstd::mem::replace(s, 0));

// overestimate to the segment being full.
let rho_size = segment_idx.saturating_add(1) as usize * UNDER_CONSTRUCTION_SEGMENT_LENGTH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let rho_size = segment_idx.saturating_add(1) as usize * UNDER_CONSTRUCTION_SEGMENT_LENGTH;
let rho_size = (segment_idx.saturating_add(1) as usize).saturating_mul(UNDER_CONSTRUCTION_SEGMENT_LENGTH);

@Demi-Marie Demi-Marie mentioned this pull request Aug 5, 2019
@Demi-Marie Demi-Marie merged commit 4408fa7 into master Aug 6, 2019
@Demi-Marie Demi-Marie deleted the rh-fix-babe-randomness branch August 6, 2019 00:50
epoch_index: u64,
rho: [u8; VRF_OUTPUT_LENGTH],
rho: impl Iterator<Item=[u8; VRF_OUTPUT_LENGTH]>,
rho_size_hint: Option<usize>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought usize is not allowed due to different size between wasm and native build?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not allowed to be shared between WASM and native, but otherwise you can use it. The size of a vector can not be greater than usize::max anyway.

Copy link
Contributor Author

@rphmeier rphmeier Aug 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's right -- this isn't exposed anywhere and it's only used to do memory allocation (in which case it is the right unit). the hint is also purely for optimization - it being too large or small shouldn't change the effect of the code

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, can wasm's usize differ when running on different platforms? If so, we might advise only to run on 64 bit platforms, so no bad parachain code can leak usize::MAX somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasm is currently always only 32bit. Rho can only store 2^32 elments at max.

s.extend_from_slice(&vrf_output[..]);
}

runtime_io::blake2_256(&s)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious: We do not hash incrementally in situations like this because repeatedly crossing the wasm boundary costs more than an allocation?

@burdges
Copy link

burdges commented Aug 11, 2019

I like this much more than xor.

In future, if it improves anything like avoiding fetches from storage, then we can always change the spec to include some randomness_accumulator : [u8; 32] in the block header, so each block does

randomness_accumulator = blake2s(randomness_accumulator ++ our_vrf_output)

@rphmeier
Copy link
Contributor Author

@burdges yeah, i thought of doing that as well. it is more hashes in the end, but that might be a good alternative.

@burdges
Copy link

burdges commented Aug 11, 2019

It's one extra hash and the block header being 32 bytes larger vs an extra fetch from storage. It's minor anyways. :)

@Demi-Marie Demi-Marie mentioned this pull request Sep 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_review Pull request needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants