-
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
feec33f
commit c68c4e6
Showing
4 changed files
with
262 additions
and
8 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); | ||
} | ||
} |
52 changes: 48 additions & 4 deletions
52
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,55 @@ | ||
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 false; | ||
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 false; | ||
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); | ||
} | ||
} |