You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated the syscall function API to take in PodG1 and PodG2 types directly. I think this results in a much cleaner interface (more consistent with the bls12-381 implementation) and simpler implementation since we don't need to worry about byte slicing and length checks.
One disadvantage is that length checks like this has to be taken care of by the caller, which will be in solana-syscalls. We will have to be careful to preserve the original behavior. For example:
For G1 big-endian addition and multiplication, if input length is smaller than 128, there must be padding.
I also thought a bit about implementing Pod and Zeroable. I think (please correctly if I am wrong) if we didn't implement Pod, then we need to do something like:
let p_bytes: [u8; 64] = input[0..64].try_into().unwrap();
let q_bytes: [u8; 64] = input[64..128].try_into().unwrap();
let p = PodG1(p_bytes);
let q = PodG1(q_bytes);
But if we do implement Pod, then we can do:
let points: &[PodG1] = bytemuck::cast_slice(input);
let p = &points[0];
let q = &points[1];
In syscall, instead of the above, we do use translate_type for the conversion, but this is an unsafe function and it inherently assumes the Rust struct we are casting into has a perfectly predictable, contiguous byte layout with zero padding, which Pod and Zeroable guarantees. bytemuck is a pretty light dependency, so I don't think it hurts to have it.
But if you have strong feelings to remove Pod or Zeroable, then let me know @LStan. If we do remove it, then we probably want to do the same for bls12-381 as well.
One disadvantage is that length checks like this has to be taken care of by the caller, which will be in solana-syscalls. We will have to be careful to preserve the original behavior. For example:
* For G1 big-endian addition and multiplication, if input length is smaller than 128, there must be padding.
I have some doubts about this. I remember you planned to change input length check for BE from <= to ==. This will be a new variant in the Version enum. However, the logic for it will need to be implemented in solana-syscalls crate. Doesn't this kind of break encapsulation?
In syscall, instead of the above, we do use translate_type for the conversion, but this is an unsafe function and it inherently assumes the Rust struct we are casting into has a perfectly predictable, contiguous byte layout with zero padding, which Pod and Zeroable guarantees. bytemuck is a pretty light dependency, so I don't think it hurts to have it.
Why does the code for bls12-381 use translate_type instead of cast_slice? If translate_type is unsafe, why isn't it marked as unsafe?
The reason will be displayed to describe this comment to others. Learn more.
i think it may be more efficient to build two vectors here; so later on you don't need to iterate it twice to build iters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Updated the syscall function API to take in
PodG1andPodG2types directly. I think this results in a much cleaner interface (more consistent with the bls12-381 implementation) and simpler implementation since we don't need to worry about byte slicing and length checks.One disadvantage is that length checks like this has to be taken care of by the caller, which will be in solana-syscalls. We will have to be careful to preserve the original behavior. For example:
I also thought a bit about implementing
PodandZeroable. I think (please correctly if I am wrong) if we didn't implementPod, then we need to do something like:But if we do implement
Pod, then we can do:In syscall, instead of the above, we do use
translate_typefor the conversion, but this is an unsafe function and it inherently assumes the Rust struct we are casting into has a perfectly predictable, contiguous byte layout with zero padding, whichPodandZeroableguarantees.bytemuckis a pretty light dependency, so I don't think it hurts to have it.But if you have strong feelings to remove
PodorZeroable, then let me know @LStan. If we do remove it, then we probably want to do the same for bls12-381 as well.