fix: GenNewKeyRing should return out of bound error if s and ring size equal in value (#412)

This commit is contained in:
Banana-J 2024-01-29 11:27:48 +11:00 committed by GitHub
parent 743fc8500b
commit cac03bd960
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,9 +8,10 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"github.com/XinFinOrg/XDPoSChain/common"
"math/big" "math/big"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
) )
@ -28,18 +29,18 @@ const (
pubkeyHybrid byte = 0x6 // y_bit + x coord + y coord pubkeyHybrid byte = 0x6 // y_bit + x coord + y coord
) )
//The proof contains pretty much stuffs // The proof contains pretty much stuffs
//The proof contains pretty much stuffs // The proof contains pretty much stuffs
//Ring size rs: 1 byte => proof[0] // Ring size rs: 1 byte => proof[0]
//num input: number of real inputs: 1 byte => proof[1] // num input: number of real inputs: 1 byte => proof[1]
//List of inputs/UTXO index typed uint64 => total size = rs * numInput * 8 = proof[0]*proof[1]*8 // List of inputs/UTXO index typed uint64 => total size = rs * numInput * 8 = proof[0]*proof[1]*8
//List of key images: total size = numInput * 33 = proof[1] * 33 // List of key images: total size = numInput * 33 = proof[1] * 33
//number of output n: 1 byte // number of output n: 1 byte
//List of output => n * 130 bytes // List of output => n * 130 bytes
//transaction fee: uint256 => 32 byte // transaction fee: uint256 => 32 byte
//ringCT proof size ctSize: uint16 => 2 byte // ringCT proof size ctSize: uint16 => 2 byte
//ringCT proof: ctSize bytes // ringCT proof: ctSize bytes
//bulletproofs: bp // bulletproofs: bp
type PrivateSendVerifier struct { type PrivateSendVerifier struct {
proof []byte proof []byte
//ringCT RingCT //ringCT RingCT
@ -273,7 +274,7 @@ func GenNewKeyRing(size int, privkey *ecdsa.PrivateKey, s int) ([]*ecdsa.PublicK
ring := make([]*ecdsa.PublicKey, size) ring := make([]*ecdsa.PublicKey, size)
pubkey := privkey.Public().(*ecdsa.PublicKey) pubkey := privkey.Public().(*ecdsa.PublicKey)
if s > len(ring) { if s >= len(ring) {
return nil, errors.New("index s out of bounds") return nil, errors.New("index s out of bounds")
} }
@ -545,7 +546,7 @@ func Link(sig_a *RingSignature, sig_b *RingSignature) bool {
return false return false
} }
//function returns(mutiple rings, private keys, message, error) // function returns(mutiple rings, private keys, message, error)
func GenerateMultiRingParams(numRing int, ringSize int, s int) (rings []Ring, privkeys []*ecdsa.PrivateKey, m [32]byte, err error) { func GenerateMultiRingParams(numRing int, ringSize int, s int) (rings []Ring, privkeys []*ecdsa.PrivateKey, m [32]byte, err error) {
for i := 0; i < numRing; i++ { for i := 0; i < numRing; i++ {
privkey, err := crypto.GenerateKey() privkey, err := crypto.GenerateKey()