-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Spec] Add the initial specs for
ed25519
and multi_ed25519
- modeled the native functions with uninterpreted functions - added functional specifications
- Loading branch information
1 parent
3973311
commit 594878f
Showing
6 changed files
with
267 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 46 additions & 4 deletions
50
aptos-move/framework/aptos-stdlib/sources/cryptography/ed25519.spec.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 49 additions & 4 deletions
53
aptos-move/framework/aptos-stdlib/sources/cryptography/multi_ed25519.spec.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters