Add support for protobuf TxGenerator and SIGN_MODE_DIRECT (#6385)
* Add TxWrapper, encoder, decoder and DirectModeHandler * fix pkg name * Update API and leave test TODO's * Update TxWrapper API * tests for tx wrapper (#6410) * WIP: added test for direct mode handler * updated code * Add msg * Update TxWrapper API * Fix pubkey declaration * Add pubkey for tests * Fix SetFee * Remove logs * Avoid global var declaration for tests * Add test for GetPubKeys * Fix direct signing tests * Add more test cases for GetSignBytes * Revert SetFee API * Remove logs * Refactor tests Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> * Refactoring * Refactoring * Integrate SignatureV2 API * Fix wrapper tests * Fix tests * Linting and API tweaks * Update API * WIP on updating API * Fix tests * Update to new SigVerifiableTx * Rename * Update docs to reflect ADR 020 * proto-gen * proto docs * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * Add tests * Refactor and improving test coverage * WIP on test coverage * WIP on test coverage * proto-gen * Fix CompactBitArray.Size() bug * Rename * Remove Builder interface * Address review comments * Update x/auth/tx/sigs.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/auth/tx/encoder.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update x/auth/tx/encoder.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Address review feedback * Fix build issues * Resolve conflicts * Fix ValidateBasic test coverage * Add test for malicious multisig Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
anilCSE
sahith-narahari
Federico Kunze
atheeshp
Alexander Bezobchuk
parent
feb69770ef
commit
2f44fbf2ab
@@ -26,8 +26,8 @@ func NewCompactBitArray(bits int) *CompactBitArray {
|
||||
}
|
||||
}
|
||||
|
||||
// Size returns the number of bits in the bitarray
|
||||
func (bA *CompactBitArray) Size() int {
|
||||
// Count returns the number of bits in the bitarray
|
||||
func (bA *CompactBitArray) Count() int {
|
||||
if bA == nil {
|
||||
return 0
|
||||
} else if bA.ExtraBitsStored == uint32(0) {
|
||||
@@ -38,12 +38,12 @@ func (bA *CompactBitArray) Size() int {
|
||||
}
|
||||
|
||||
// GetIndex returns the bit at index i within the bit array.
|
||||
// The behavior is undefined if i >= bA.Size()
|
||||
// The behavior is undefined if i >= bA.Count()
|
||||
func (bA *CompactBitArray) GetIndex(i int) bool {
|
||||
if bA == nil {
|
||||
return false
|
||||
}
|
||||
if i >= bA.Size() {
|
||||
if i >= bA.Count() {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ func (bA *CompactBitArray) GetIndex(i int) bool {
|
||||
}
|
||||
|
||||
// SetIndex sets the bit at index i within the bit array.
|
||||
// The behavior is undefined if i >= bA.Size()
|
||||
// The behavior is undefined if i >= bA.Count()
|
||||
func (bA *CompactBitArray) SetIndex(i int, v bool) bool {
|
||||
if bA == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if i >= bA.Size() {
|
||||
if i >= bA.Count() {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (bA *CompactBitArray) StringIndented(indent string) string {
|
||||
}
|
||||
lines := []string{}
|
||||
bits := ""
|
||||
size := bA.Size()
|
||||
size := bA.Count()
|
||||
for i := 0; i < size; i++ {
|
||||
if bA.GetIndex(i) {
|
||||
bits += "x"
|
||||
@@ -152,7 +152,7 @@ func (bA *CompactBitArray) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
bits := `"`
|
||||
size := bA.Size()
|
||||
size := bA.Count()
|
||||
for i := 0; i < size; i++ {
|
||||
if bA.GetIndex(i) {
|
||||
bits += `x`
|
||||
@@ -204,7 +204,7 @@ func (bA *CompactBitArray) UnmarshalJSON(bz []byte) error {
|
||||
// CompactMarshal is a space efficient encoding for CompactBitArray.
|
||||
// It is not amino compatible.
|
||||
func (bA *CompactBitArray) CompactMarshal() []byte {
|
||||
size := bA.Size()
|
||||
size := bA.Count()
|
||||
if size <= 0 {
|
||||
return []byte("null")
|
||||
}
|
||||
|
||||
+49
-34
@@ -299,7 +299,7 @@ func (m *CompactBitArray) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_CompactBitArray.Merge(m, src)
|
||||
}
|
||||
func (m *CompactBitArray) XXX_Size() int {
|
||||
return xxx_messageInfo_CompactBitArray.Size(m)
|
||||
return m.Size()
|
||||
}
|
||||
func (m *CompactBitArray) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_CompactBitArray.DiscardUnknown(m)
|
||||
@@ -331,39 +331,38 @@ func init() {
|
||||
func init() { proto.RegisterFile("cosmos/crypto/crypto.proto", fileDescriptor_5fa415c569c5d31a) }
|
||||
|
||||
var fileDescriptor_5fa415c569c5d31a = []byte{
|
||||
// 500 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xc1, 0x6e, 0xd3, 0x30,
|
||||
0x18, 0xc7, 0xe3, 0x76, 0x65, 0xab, 0xbb, 0xad, 0x60, 0x55, 0x22, 0xab, 0x44, 0x52, 0xe5, 0x80,
|
||||
0x0a, 0x12, 0xa9, 0x5a, 0xd4, 0x21, 0x7a, 0x5b, 0xc6, 0x61, 0x52, 0x85, 0x54, 0x65, 0x1c, 0x10,
|
||||
0x12, 0xaa, 0x92, 0xd4, 0xa4, 0x51, 0x93, 0x38, 0xb2, 0x1d, 0x09, 0x3f, 0x01, 0x57, 0x8e, 0x1c,
|
||||
0xb7, 0x3b, 0x0f, 0xc2, 0xb1, 0x47, 0x4e, 0x15, 0x4a, 0xdf, 0x60, 0x4f, 0x80, 0x6a, 0x27, 0xdb,
|
||||
0x00, 0x71, 0x72, 0xbe, 0xff, 0xef, 0x73, 0xfc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9b, 0x9a, 0x73, 0xfe, 0xa3, 0x30, 0xc0, 0xba, 0x30, 0xc0, 0xaf, 0xc2, 0x00, 0x5f,
|
||||
0xb7, 0x86, 0xb6, 0xde, 0x1a, 0xda, 0xcf, 0xad, 0xa1, 0x7d, 0x78, 0x16, 0x46, 0x7c, 0x99, 0xfb,
|
||||
0x76, 0x40, 0x92, 0x41, 0xf5, 0xa0, 0xe5, 0xf2, 0x82, 0x2d, 0x56, 0xd5, 0xdb, 0xe6, 0x22, 0xc3,
|
||||
0xcc, 0x7f, 0x20, 0x2f, 0xeb, 0xe5, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1c, 0xa2, 0x1f, 0xee,
|
||||
0xf9, 0x02, 0x00, 0x00,
|
||||
// 495 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x4f, 0x6f, 0xd3, 0x30,
|
||||
0x18, 0xc6, 0xe3, 0xfe, 0x61, 0xd4, 0xdd, 0x56, 0xb0, 0x2a, 0x91, 0x55, 0x22, 0xa9, 0x72, 0x40,
|
||||
0x05, 0x89, 0x54, 0x2d, 0xea, 0x10, 0xbd, 0x2d, 0xe3, 0x30, 0xa9, 0x42, 0xaa, 0x32, 0x0e, 0xc0,
|
||||
0xa5, 0x4a, 0x52, 0x93, 0x46, 0x4d, 0xe2, 0xc8, 0x76, 0x24, 0xfc, 0x09, 0xb8, 0x72, 0xe4, 0x08,
|
||||
0x77, 0x3e, 0x08, 0xc7, 0x1e, 0x39, 0x55, 0x28, 0xfd, 0x06, 0xfb, 0x04, 0xa8, 0x76, 0xb2, 0x0d,
|
||||
0xd0, 0x4e, 0xce, 0xfb, 0xfc, 0x5e, 0xc7, 0xcf, 0xf3, 0xda, 0xb0, 0x17, 0x10, 0x96, 0x10, 0x36,
|
||||
0x0c, 0xa8, 0xc8, 0x38, 0x29, 0x17, 0x3b, 0xa3, 0x84, 0x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, 0x4f, 0xc3, 0x88, 0xaf, 0x72, 0xdf, 0x0e, 0x48, 0x32, 0xac,
|
||||
0x1e, 0xb3, 0x5c, 0x9e, 0xb3, 0xe5, 0xba, 0x7a, 0xd7, 0x5c, 0x64, 0x98, 0xf9, 0xf7, 0xe4, 0x45,
|
||||
0xbd, 0xf8, 0x13, 0x00, 0x00, 0xff, 0xff, 0x73, 0x8c, 0x25, 0x71, 0xf5, 0x02, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *PublicKey) Marshal() (dAtA []byte, err error) {
|
||||
@@ -748,6 +747,22 @@ func (m *MultiSignature) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *CompactBitArray) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.ExtraBitsStored != 0 {
|
||||
n += 1 + sovCrypto(uint64(m.ExtraBitsStored))
|
||||
}
|
||||
l = len(m.Elems)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovCrypto(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovCrypto(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (pk PubKeyMultisigThreshold) VerifyBytes(msg []byte, marshalledSig []byte)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
size := sig.BitArray.Size()
|
||||
size := sig.BitArray.Count()
|
||||
// ensure bit array is the correct size
|
||||
if len(pk.PubKeys) != size {
|
||||
return false
|
||||
@@ -78,7 +78,7 @@ func (pk PubKeyMultisigThreshold) VerifyBytes(msg []byte, marshalledSig []byte)
|
||||
func (pk PubKeyMultisigThreshold) VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *signing.MultiSignatureData) error {
|
||||
bitarray := sig.BitArray
|
||||
sigs := sig.Signatures
|
||||
size := bitarray.Size()
|
||||
size := bitarray.Count()
|
||||
// ensure bit array is the correct size
|
||||
if len(pk.PubKeys) != size {
|
||||
return fmt.Errorf("bit array size is incorrect %d", len(pk.PubKeys))
|
||||
|
||||
Reference in New Issue
Block a user