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

feat(crypto): Add extra types and conversions #517

Merged
merged 1 commit into from
Oct 4, 2024
Merged

Conversation

AndrewWestberg
Copy link
Collaborator

Adding some ergonomic improvements to make Amaru code less ugly.

Comment on lines +316 to +343
pub enum VrfDerivation {
Leader,
Nonce,
}

pub fn derive_tagged_vrf_output(
block_vrf_output_bytes: &[u8],
derivation: VrfDerivation,
) -> Vec<u8> {
let mut tagged_vrf: Vec<u8> = match derivation {
VrfDerivation::Leader => vec![0x4C_u8], /* "L" */
VrfDerivation::Nonce => vec![0x4E_u8], /* "N" */
};

tagged_vrf.extend(block_vrf_output_bytes);
Hasher::<256>::hash(&tagged_vrf).to_vec()
}

impl HeaderBody {
pub fn leader_vrf_output(&self) -> Vec<u8> {
derive_tagged_vrf_output(&self.vrf_result.0, VrfDerivation::Leader)
}

pub fn nonce_vrf_output(&self) -> Vec<u8> {
derive_tagged_vrf_output(&self.vrf_result.0, VrfDerivation::Nonce)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we should put this logic in primitives. Why are we moving it from traverse to here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved it here because we said we didn't want to use pallas-traverse in Amaru. I believe it belongs in primitives because a leader_vrf and nonce_vrf exist in Alonzo and earlier headers. In babbage and beyond, these values are calculated instead of included in the header itself. I would consider these values as part of the header even though they're not explicitly in the header.

Copy link
Member

Choose a reason for hiding this comment

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

I approved and merged the PR to move along, but I think that adding business logic to a specific era in the primitives crate is a slippery slope. I admit that this particular case is pretty constrained and harmless, but I just want to state that the original scope of the primitives crate is to hold data structures matching the CDDL and their corresponding encoding / decoding logic.

@KtorZ advocates for leaving pallas-traverse outside of the shared kernel, I'm still on the fence. What I don't like is slowly merging business logic into primitives just to accommodate for this decision.

Pallas implementors need an api layer that is era-agnostic and more ergonomic than CDDL structures. If Amaru doesn't want to use pallas-traverse, then I believe this api layer should be Amaru-specific and live within it's own repo.

pallas-codec/src/utils.rs Outdated Show resolved Hide resolved
@scarmuega scarmuega merged commit 0ca7c34 into main Oct 4, 2024
7 checks passed
@scarmuega scarmuega deleted the amw/improvements branch October 4, 2024 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants