|
4 | 4 | "context"
|
5 | 5 | "math"
|
6 | 6 |
|
7 |
| - "github.com/ethereum/go-ethereum/common" |
8 | 7 | "github.com/jackc/pgx/v4"
|
9 | 8 | "github.com/jackc/pgx/v4/pgxpool"
|
10 | 9 | pubsub "github.com/libp2p/go-libp2p-pubsub"
|
@@ -186,6 +185,24 @@ func (h *DecryptionKeysHandler) MessagePrototypes() []p2pmsg.Message {
|
186 | 185 | return []p2pmsg.Message{&p2pmsg.DecryptionKeys{}}
|
187 | 186 | }
|
188 | 187 |
|
| 188 | +func validateSignerIndices(extra *p2pmsg.DecryptionKeys_Gnosis, n int) (pubsub.ValidationResult, error) { |
| 189 | + for i, signerIndex := range extra.Gnosis.SignerIndices { |
| 190 | + if i >= 1 { |
| 191 | + prevSignerIndex := extra.Gnosis.SignerIndices[i-1] |
| 192 | + if signerIndex == prevSignerIndex { |
| 193 | + return pubsub.ValidationReject, errors.New("duplicate signer index found") |
| 194 | + } |
| 195 | + if signerIndex < prevSignerIndex { |
| 196 | + return pubsub.ValidationReject, errors.New("signer indices not ordered") |
| 197 | + } |
| 198 | + } |
| 199 | + if signerIndex >= uint64(n) { |
| 200 | + return pubsub.ValidationReject, errors.New("signer index out of range") |
| 201 | + } |
| 202 | + } |
| 203 | + return pubsub.ValidationAccept, nil |
| 204 | +} |
| 205 | + |
189 | 206 | func (h *DecryptionKeysHandler) ValidateMessage(ctx context.Context, msg p2pmsg.Message) (pubsub.ValidationResult, error) {
|
190 | 207 | keys := msg.(*p2pmsg.DecryptionKeys)
|
191 | 208 | extra, ok := keys.Extra.(*p2pmsg.DecryptionKeys_Gnosis)
|
@@ -220,25 +237,14 @@ func (h *DecryptionKeysHandler) ValidateMessage(ctx context.Context, msg p2pmsg.
|
220 | 237 | if int32(len(extra.Gnosis.SignerIndices)) != keyperSet.Threshold {
|
221 | 238 | return pubsub.ValidationReject, errors.Errorf("expected %d signers, got %d", keyperSet.Threshold, len(extra.Gnosis.SignerIndices))
|
222 | 239 | }
|
223 |
| - signers := []common.Address{} |
224 |
| - for i, signerIndex := range extra.Gnosis.SignerIndices { |
225 |
| - if i >= 1 { |
226 |
| - prevSignerIndex := extra.Gnosis.SignerIndices[i-1] |
227 |
| - if signerIndex == prevSignerIndex { |
228 |
| - return pubsub.ValidationReject, errors.New("duplicate signer index found") |
229 |
| - } |
230 |
| - if signerIndex < prevSignerIndex { |
231 |
| - return pubsub.ValidationReject, errors.New("signer indices not ordered") |
232 |
| - } |
233 |
| - } |
234 |
| - if signerIndex >= uint64(len(keyperSet.Keypers)) { |
235 |
| - return pubsub.ValidationReject, errors.New("signer index out of range") |
236 |
| - } |
237 |
| - signer, err := shdb.DecodeAddress(keyperSet.Keypers[signerIndex]) |
238 |
| - if err != nil { |
239 |
| - return pubsub.ValidationReject, errors.Wrap(err, "failed to decode signer address") |
240 |
| - } |
241 |
| - signers = append(signers, signer) |
| 240 | + |
| 241 | + res, err := validateSignerIndices(extra, len(keyperSet.Keypers)) |
| 242 | + if res != pubsub.ValidationAccept { |
| 243 | + return res, err |
| 244 | + } |
| 245 | + signers, err := keyperSet.GetSubset(extra.Gnosis.SignerIndices) |
| 246 | + if err != nil { |
| 247 | + return pubsub.ValidationReject, err |
242 | 248 | }
|
243 | 249 |
|
244 | 250 | identityPreimages := []identitypreimage.IdentityPreimage{}
|
|
0 commit comments