Fix alt_bn128_pairing syscall length check
- Idea
- Draft
- Review
- Accept
- Implement
- Active
Decision brief
Why this proposal matters
The alt_bn128_pairing syscall takes a byte slice as input, interprets the bytes as an array of pairs of g1 and g2 points on bn128 elliptic curve, and applies a pairing operation. If the byte slice input has an improper length, the function should terminate early. Specifically, if the byte slice length is not a multiple of 192 (the sum of the lengths of g1 and g2 points), the function should terminate early with an error. However, the current code does not perform this check correctly. This document proposes to fix this length check by checking for the correct length.
Proposal at a glance
What changes
- The alt_bn128_pairing syscall takes a byte slice as input, interprets the bytes as an array of pairs of g1 and g2 points on bn128 elliptic curve, and applies a pairing operation. If the byte slice input has an improper length, the function should terminate early.…
Stakeholder map
Who is affected
Builders & client teams Medium impact
This fix will prevent accidental misuse of the alt_bn128_pairing syscall function and make programs easier to debug.
Action requirement unknownValidators & operators Impact unknown
No proposal-specific evidence was found for this group.
Action requirement unknownUsers & stakers Impact unknown
No proposal-specific evidence was found for this group.
Action requirement unknownGovernance & ecosystem Impact unknown
No proposal-specific evidence was found for this group.
Action requirement unknownExact source revision
Full proposal document
0616093b2952Summary
The alt_bn128_pairing syscall takes a byte slice as input,
interprets the bytes as an array of pairs of g1 and g2 points on bn128 elliptic
curve, and applies a pairing operation. If the byte slice input has an improper
length, the function should terminate early. Specifically, if the byte slice
length is not a multiple of 192 (the sum of the lengths of g1 and g2 points),
the function should terminate early with an error.
However, the current code does not perform this check correctly.
This document proposes to fix this length check by checking for the correct length.
Motivation
The alt_bn128_pairing function still works with the incorrect length check
because it only processes multiples of 192 bytes and discards the rest.
However, there could be successful inputs that are not multiples of 192.
This could make the application logic harder to debug.
Alternatives Considered
Leave as is.
New Terminology
N/A
Detailed Design
Currently, the code checks than checked_rem of the input length and
ALT_BN128_PAIRING_ELEMENT_LEN (which is 192) is not None.
However, checked_rem returns None when the rhs is 0,
which never happens in this context.
pub fn alt_bn128_pairing(input: &[u8]) -> Result<Vec<u8>, AltBn128Error> {
if input
.len()
.checked_rem(consts::ALT_BN128_PAIRING_ELEMENT_LEN)
.is_none()
{
return Err(AltBn128Error::InvalidInputData);
}
// logic omitted...
}
The correct logic should check that the remainder is 0.
pub fn alt_bn128_pairing(input: &[u8]) -> Result<Vec<u8>, AltBn128Error> {
if input.len() % ALT_BN128_PAIRING_ELEMENT_LEN != 0 {
return Err(AltBn128Error::InvalidInputData);
}
// logic omitted...
}
Impact
This fix will prevent accidental misuse of the alt_bn128_pairing
syscall function and make programs easier to debug.
Security Considerations
This does update the behavior of the syscall function and therefore should be properly feature-gated.
Drawbacks (Optional)
None
Evidence graph
Related proposals and rollout
One or more sources are unavailable.
Upstream review record
Upstream discussion & review
One or more sources are unavailable.
Provenance
Evidence & technical details
Rollout or chain data, source revisions, freshness and integrity. 3
Provenance
Evidence & technical details
Rollout or chain data, source revisions, freshness and integrity.SIMD
Deployment Status
bnYzodLwmybj7e1HAe98yZrdJTd7we69eMMLgCXqKZmExact source revision
Sources & integrity
- Proposal document pinned_commit_blob
0616093b2952ed6de52c4a27d66aadd11d48d4f9 - simd-document document · stale · Sep 10, 2026
0616093b2952ed6de52c4a27d66aadd11d48d4f9
One or more sources are unavailable.
One or more sources are unavailable.
simd.watch community discussion · SIMD-0334
Powered by Giscus · Sign in with GitHub to comment
Community comments load when this section approaches the viewport.