-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make MultiKeyAuthenicator work #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,16 +163,14 @@ def serialize(self, serializer: Serializer): | |
|
||
class MultiSignature(asymmetric_crypto.Signature): | ||
signatures: List[Tuple[int, Signature]] | ||
BITMAP_NUM_OF_BYTES: int = 4 | ||
MAX_SIGNATURES: int = 16 | ||
|
||
def __init__(self, signatures: List[Tuple[int, asymmetric_crypto.Signature]]): | ||
# Sort first to ensure no issues in order | ||
# signatures.sort(key=lambda x: x[0]) | ||
self.signatures = [] | ||
for index, signature in signatures: | ||
assert ( | ||
index < self.BITMAP_NUM_OF_BYTES * 8 | ||
), "bitmap value exceeds maximum value" | ||
assert index < self.MAX_SIGNATURES, "bitmap value exceeds maximum value" | ||
if isinstance(signature, Signature): | ||
self.signatures.append((index, signature)) | ||
else: | ||
|
@@ -189,9 +187,9 @@ def __str__(self) -> str: | |
@staticmethod | ||
def deserialize(deserializer: Deserializer) -> MultiSignature: | ||
signatures = deserializer.sequence(Signature.deserialize) | ||
deserializer.uleb128() | ||
bitmap = deserializer.u32() | ||
num_bits = MultiSignature.BITMAP_NUM_OF_BYTES * 8 | ||
bitmap_raw = deserializer.to_bytes() | ||
bitmap = int.from_bytes(bitmap_raw, "little") | ||
num_bits = len(bitmap_raw) * 8 | ||
sig_index = 0 | ||
indexed_signatures = [] | ||
|
||
|
@@ -201,7 +199,7 @@ def deserialize(deserializer: Deserializer) -> MultiSignature: | |
indexed_signatures.append((i, signatures[sig_index])) | ||
sig_index += 1 | ||
|
||
return MultiSignature(signatures) | ||
return MultiSignature(indexed_signatures) | ||
|
||
def serialize(self, serializer: Serializer): | ||
actual_sigs = [] | ||
|
@@ -212,8 +210,8 @@ def serialize(self, serializer: Serializer): | |
actual_sigs.append(signature) | ||
|
||
serializer.sequence(actual_sigs, Serializer.struct) | ||
serializer.uleb128(self.BITMAP_NUM_OF_BYTES) | ||
serializer.u32(bitmap) | ||
count = 1 if bitmap < 256 else 2 | ||
serializer.to_bytes(bitmap.to_bytes(count, "little")) | ||
Comment on lines
+213
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The signature limit accepted on the other side only goes up to 255? https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs#L794-L798 Is there a reason it's doing custom byte sequence serialization? I noticed this is really not simple to do in the Python SDK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how the bitvec works... |
||
|
||
|
||
def index_to_bitmap_value(i: int) -> int: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find this 16 signature limit? Is this just for the SDK?
As far as I can tell, the limit is 255
https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs#L794-L798
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs#L811
distinct keys is 16... I think we kinda messed up here, but I think we can make this bigger without any impact since we use the bitvec.