-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Spec] Add the initial specs for ed25519
and multi_ed25519
#5677
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 |
---|---|---|
@@ -1,11 +1,53 @@ | ||
spec aptos_std::ed25519 { | ||
spec public_key_validate_internal { | ||
// TODO: temporary mockup. | ||
|
||
// ----------------------- | ||
// Function specifications | ||
// ----------------------- | ||
|
||
spec new_unvalidated_public_key_from_bytes(bytes: vector<u8>): UnvalidatedPublicKey { | ||
let length = len(bytes); | ||
aborts_if length != PUBLIC_KEY_NUM_BYTES; | ||
ensures result == UnvalidatedPublicKey { bytes }; | ||
} | ||
|
||
spec new_validated_public_key_from_bytes(bytes: vector<u8>): Option<ValidatedPublicKey> { | ||
aborts_if false; | ||
let cond = spec_public_key_validate_internal(bytes); | ||
ensures cond ==> result == option::spec_some(ValidatedPublicKey{bytes}); | ||
ensures !cond ==> result == option::spec_none<ValidatedPublicKey>(); | ||
} | ||
|
||
spec new_signature_from_bytes(bytes: vector<u8>): Signature { | ||
aborts_if len(bytes)!= SIGNATURE_NUM_BYTES; | ||
ensures result == Signature { bytes }; | ||
} | ||
|
||
|
||
// ---------------- | ||
// Native functions | ||
// ---------------- | ||
|
||
spec fun spec_public_key_validate_internal(bytes: vector<u8>): bool; | ||
|
||
spec fun spec_signature_verify_strict_internal( | ||
signature: vector<u8>, | ||
public_key: vector<u8>, | ||
message: vector<u8> | ||
): bool; | ||
|
||
spec public_key_validate_internal(bytes: vector<u8>): bool { | ||
pragma opaque; | ||
aborts_if false; | ||
ensures result == spec_public_key_validate_internal(bytes); | ||
} | ||
|
||
spec signature_verify_strict_internal { | ||
// TODO: temporary mockup. | ||
spec signature_verify_strict_internal( | ||
signature: vector<u8>, | ||
public_key: vector<u8>, | ||
message: vector<u8>) | ||
: bool { | ||
pragma opaque; | ||
aborts_if false; | ||
ensures result == spec_signature_verify_strict_internal(signature, public_key, message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,11 +1,56 @@ | ||||
spec aptos_std::multi_ed25519 { | ||||
spec public_key_validate_internal { | ||||
// TODO: temporary mockup. | ||||
|
||||
// ----------------------- | ||||
// Function specifications | ||||
// ----------------------- | ||||
|
||||
spec new_unvalidated_public_key_from_bytes(bytes: vector<u8>): UnvalidatedPublicKey { | ||||
let length = len(bytes); | ||||
aborts_if length / INDIVIDUAL_PUBLIC_KEY_NUM_BYTES > MAX_NUMBER_OF_PUBLIC_KEYS; | ||||
aborts_if length % INDIVIDUAL_PUBLIC_KEY_NUM_BYTES != THRESHOLD_SIZE_BYTES; | ||||
ensures result == UnvalidatedPublicKey { bytes }; | ||||
} | ||||
|
||||
spec new_validated_public_key_from_bytes(bytes: vector<u8>): Option<ValidatedPublicKey> { | ||||
aborts_if len(bytes) % INDIVIDUAL_PUBLIC_KEY_NUM_BYTES == THRESHOLD_SIZE_BYTES | ||||
&& len(bytes) / INDIVIDUAL_PUBLIC_KEY_NUM_BYTES > MAX_NUMBER_OF_PUBLIC_KEYS; | ||||
let cond = len(bytes) % INDIVIDUAL_PUBLIC_KEY_NUM_BYTES == THRESHOLD_SIZE_BYTES | ||||
&& spec_public_key_validate_internal(bytes); | ||||
ensures cond ==> result == option::spec_some(ValidatedPublicKey{bytes}); | ||||
ensures !cond ==> result == option::spec_none<ValidatedPublicKey>(); | ||||
} | ||||
|
||||
spec new_signature_from_bytes(bytes: vector<u8>): Signature { | ||||
aborts_if len(bytes) % INDIVIDUAL_SIGNATURE_NUM_BYTES != BITMAP_NUM_OF_BYTES; | ||||
ensures result == Signature { bytes }; | ||||
} | ||||
|
||||
|
||||
// ---------------- | ||||
// Native functions | ||||
// ---------------- | ||||
|
||||
spec fun spec_public_key_validate_internal(bytes: vector<u8>): bool; | ||||
|
||||
spec fun spec_signature_verify_strict_internal( | ||||
multisignature: vector<u8>, | ||||
public_key: vector<u8>, | ||||
message: vector<u8> | ||||
): bool; | ||||
|
||||
spec public_key_validate_internal(bytes: vector<u8>): bool { | ||||
pragma opaque; | ||||
aborts_if len(bytes) / INDIVIDUAL_PUBLIC_KEY_NUM_BYTES > MAX_NUMBER_OF_PUBLIC_KEYS; | ||||
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. Hey @junkil-park, I see this says that the native aborts upon this condition, but the native never aborts.
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. I think my initial reply in the discussion above made it seem like the native aborts upon this condition, but it merely returns false. 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. Thank you letting me know! I put up the fix here: https://github.com/aptos-labs/aptos-core/pull/5832/files#diff-ed6845718b5d03098f058edfc43ace50fc05ff3d18bf729521701a36b0c19bc3R45 |
||||
ensures result == spec_public_key_validate_internal(bytes); | ||||
} | ||||
|
||||
spec signature_verify_strict_internal { | ||||
// TODO: temporary mockup. | ||||
spec signature_verify_strict_internal( | ||||
multisignature: vector<u8>, | ||||
public_key: vector<u8>, | ||||
message: vector<u8> | ||||
): bool { | ||||
pragma opaque; | ||||
aborts_if false; | ||||
ensures result == spec_signature_verify_strict_internal(multisignature, public_key, message); | ||||
} | ||||
} |
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.
How come you don't do the
length / INDIVIDUAL_PUBLIC_KEY_NUM_BYTES > MAX_NUMBER_OF_PUBLIC_KEYS
check here too?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.
@alinush ,
cond
is here to model the condition in this line: https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-stdlib/sources/cryptography/multi_ed25519.move#L123Does the Move function
new_validated_public_key_from_bytes
actually need the additional check you're mentioning?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 see: That check is done in the
public_key_validate_internal
native, whichnew_validated_public_key_from_bytes
calls. I guess that's why I didn't replicate it.A bit confusing now reading my own code 🤦 ...
Would you mind adding a comment at line 123 (which you linked to) that says:
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.
Thanks! Added the comment.
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.
Hey @junkil-park, I was taking another look, and now I noticed that you added the
length / INDIVIDUAL_PUBLIC_KEY_NUM_BYTES > MAX_NUMBER_OF_PUBLIC_KEYS
check here too.But, as per my new comment below, this abort will never happen because the native called by
new_validated_public_key_from_bytes
would only returns false, not abort.