mirror of
https://github.com/logos-messaging/go-zerokit-rln.git
synced 2026-01-02 13:13:11 +00:00
Ensure no out of bound
This commit is contained in:
parent
a5ebd1023f
commit
4e7f9e1f30
13
rln/rln.go
13
rln/rln.go
@ -406,6 +406,11 @@ func (r *RLN) GetMerkleProof(index MembershipIndex) (MerkleProof, error) {
|
|||||||
return MerkleProof{}, err
|
return MerkleProof{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if we can read the first byte
|
||||||
|
if len(proofBytes) < 8 {
|
||||||
|
return MerkleProof{}, errors.New(fmt.Sprintf("wrong output size: %d", len(proofBytes)))
|
||||||
|
}
|
||||||
|
|
||||||
var result MerkleProof
|
var result MerkleProof
|
||||||
var numElements big.Int
|
var numElements big.Int
|
||||||
var numIndexes big.Int
|
var numIndexes big.Int
|
||||||
@ -416,6 +421,14 @@ func (r *RLN) GetMerkleProof(index MembershipIndex) (MerkleProof, error) {
|
|||||||
numElements.SetBytes(revert(proofBytes[offset : offset+8]))
|
numElements.SetBytes(revert(proofBytes[offset : offset+8]))
|
||||||
offset += 8
|
offset += 8
|
||||||
|
|
||||||
|
// With numElements we can determine the expected length of the proof.
|
||||||
|
expectedLen := 8 + int(32*numElements.Uint64()) + 8 + int(numElements.Uint64())
|
||||||
|
if len(proofBytes) != expectedLen {
|
||||||
|
return MerkleProof{}, errors.New(fmt.Sprintf("wrong output size expected: %d, current: %d",
|
||||||
|
expectedLen,
|
||||||
|
len(proofBytes)))
|
||||||
|
}
|
||||||
|
|
||||||
result.PathElements = make([]MerkleNode, numElements.Uint64())
|
result.PathElements = make([]MerkleNode, numElements.Uint64())
|
||||||
|
|
||||||
for i := uint64(0); i < numElements.Uint64(); i++ {
|
for i := uint64(0); i < numElements.Uint64(); i++ {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user