Skip to content

Commit 183d105

Browse files
authored
Support the custom boogie file (aptos-labs#3206)
- Added `aptos-natives.bpl` - `Aptos CLI` includes it in invoking Prover - Separated the spec from the code - Prover should finish without error for the Aptos Framework
1 parent 175aeb3 commit 183d105

24 files changed

+147
-55
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
!**/*.mrb
1717
!config/src/config/test_data
1818
!aptos-move/framework/
19+
!crates/aptos/src/move_tool/*.bpl
1920
!api/doc/
2021
!ecosystem/indexer/migrations/**/*.sql
2122
!terraform/helm/aptos-node/

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
spec aptos_framework::aggregator {
2+
spec add { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
6+
spec sub { // TODO: temporary mockup.
7+
pragma opaque;
8+
}
9+
10+
spec read { // TODO: temporary mockup.
11+
pragma opaque;
12+
}
13+
14+
spec destroy { // TODO: temporary mockup.
15+
pragma opaque;
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spec aptos_framework::aggregator_factory {
2+
spec new_aggregator { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spec aptos_framework::state_storage {
2+
spec get_state_storage_usage_only_at_epoch_beginning { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
}

aptos-move/framework/aptos-framework/sources/timestamp.spec.move

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
spec aptos_framework::timestamp {
22
spec set_time_has_started {
3+
use std::signer;
34
/// This function can't be verified on its own and has to be verified in the context of Genesis execution.
45
///
56
/// After time has started, all invariants guarded by `Timestamp::is_operating` will become activated
67
/// and need to hold.
78
pragma delegate_invariants_to_caller;
9+
aborts_if exists<CurrentTimeMicroseconds>(signer::address_of(account));
810
include AbortsIfNotGenesis;
911
include system_addresses::AbortsIfNotAptosFramework{account};
1012
ensures is_operating();
@@ -52,11 +54,6 @@ spec aptos_framework::timestamp {
5254
spec_now_microseconds() / MICRO_CONVERSION_FACTOR
5355
}
5456

55-
spec assert_genesis {
56-
pragma opaque = true;
57-
include AbortsIfNotGenesis;
58-
}
59-
6057
/// Helper schema to specify that a function aborts if not in genesis.
6158
spec schema AbortsIfNotGenesis {
6259
aborts_if !is_genesis() with error::INVALID_STATE;

aptos-move/framework/aptos-stdlib/Move.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version = "1.0.0"
66
std = "0x1"
77
aptos_std = "0x1"
88
aptos_framework = "0x1"
9-
Extensions = "0x1" # TODO: Needed for Prover to instantiate `{{Ext}}` in prelude.
9+
Extensions = "0x1" # For Prover to instantiate `{{Ext}}` in prelude.
1010

1111
[dependencies]
1212
MoveStdlib = { local = "../move-stdlib" }

aptos-move/framework/aptos-stdlib/sources/capability.move

-10
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,4 @@ module std::capability {
190190
vector::push_back(v, x)
191191
}
192192
}
193-
194-
/// Helper specification function to check whether a capability exists at address.
195-
spec fun spec_has_cap<Feature>(addr: address): bool {
196-
exists<CapState<Feature>>(addr)
197-
}
198-
199-
/// Helper specification function to obtain the delegates of a capability.
200-
spec fun spec_delegates<Feature>(addr: address): vector<address> {
201-
global<CapState<Feature>>(addr).delegates
202-
}
203193
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spec std::capability {
2+
/// Helper specification function to check whether a capability exists at address.
3+
spec fun spec_has_cap<Feature>(addr: address): bool {
4+
exists<CapState<Feature>>(addr)
5+
}
6+
7+
/// Helper specification function to obtain the delegates of a capability.
8+
spec fun spec_delegates<Feature>(addr: address): vector<address> {
9+
global<CapState<Feature>>(addr).delegates
10+
}
11+
}

aptos-move/framework/aptos-stdlib/sources/cryptography/bls12381.move

-3
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ module aptos_std::bls12381 {
302302
public_key: vector<u8>,
303303
proof_of_possesion: vector<u8>
304304
): bool;
305-
spec verify_proof_of_possession { // TODO: temporary mockup.
306-
pragma opaque;
307-
}
308305

309306
/// CRYPTOGRAPHY WARNING: Assumes the public key has a valid proof-of-possesion (PoP). This prevents rogue-key
310307
/// attacks later on during signature aggregation.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
spec aptos_std::bls12381 {
2+
spec aggregate_pubkeys_internal { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
6+
spec aggregate_signatures_internal { // TODO: temporary mockup.
7+
pragma opaque;
8+
}
9+
10+
spec validate_pubkey_internal { // TODO: temporary mockup.
11+
pragma opaque;
12+
}
13+
14+
spec signature_subgroup_check_internal { // TODO: temporary mockup.
15+
pragma opaque;
16+
}
17+
18+
spec verify_aggregate_signature_internal { // TODO: temporary mockup.
19+
pragma opaque;
20+
}
21+
22+
spec verify_multisignature_internal { // TODO: temporary mockup.
23+
pragma opaque;
24+
}
25+
26+
spec verify_normal_signature_internal { // TODO: temporary mockup.
27+
pragma opaque;
28+
}
29+
30+
spec verify_proof_of_possession_internal { // TODO: temporary mockup.
31+
pragma opaque;
32+
}
33+
34+
spec verify_signature_share_internal { // TODO: temporary mockup.
35+
pragma opaque;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spec aptos_std::ed25519 {
2+
spec public_key_validate_internal { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
6+
spec signature_verify_strict_internal { // TODO: temporary mockup.
7+
pragma opaque;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spec aptos_std::secp256k1 {
2+
spec ecdsa_recover_internal { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
}

aptos-move/framework/aptos-stdlib/sources/event.move

-23
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,11 @@ module aptos_std::event {
4141
public fun guid<T: drop + store>(handle_ref: &EventHandle<T>): &GUID {
4242
&handle_ref.guid
4343
}
44-
spec guid {
45-
pragma intrinsic = false;
46-
}
4744

4845
/// Return the current counter associated with this EventHandle
4946
public fun counter<T: drop + store>(handle_ref: &EventHandle<T>): u64 {
5047
handle_ref.counter
5148
}
52-
spec counter {
53-
pragma intrinsic = false;
54-
}
5549

5650
/// Log `msg` as the `count`th event associated with the event stream identified by `guid`
5751
native fun write_to_event_store<T: drop + store>(guid: vector<u8>, count: u64, msg: T);
@@ -68,21 +62,4 @@ module aptos_std::event {
6862
let EventHandle<T> { counter: _, guid } = new_event_handle<T>(s);
6963
guid
7064
}
71-
72-
// ****************** SPECIFICATIONS *******************
73-
spec module {} // switch documentation context to module
74-
75-
spec module {
76-
/// Functions of the event module are mocked out using the intrinsic
77-
/// pragma. They are implemented in the prover's prelude.
78-
pragma intrinsic = true;
79-
80-
/// Determines equality between the guids of two event handles. Since fields of intrinsic
81-
/// structs cannot be accessed, this function is provided.
82-
fun spec_guid_eq<T>(h1: EventHandle<T>, h2: EventHandle<T>): bool {
83-
// The implementation currently can just use native equality since the mocked prover
84-
// representation does not have the `counter` field.
85-
h1 == h2
86-
}
87-
}
8865
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spec aptos_std::event {
2+
// ****************** SPECIFICATIONS *******************
3+
spec module {} // switch documentation context to module
4+
5+
spec module {
6+
/// Functions of the event module are mocked out using the intrinsic
7+
/// pragma. They are implemented in the prover's prelude.
8+
pragma intrinsic = true;
9+
10+
/// Determines equality between the guids of two event handles. Since fields of intrinsic
11+
/// structs cannot be accessed, this function is provided.
12+
fun spec_guid_eq<T>(h1: EventHandle<T>, h2: EventHandle<T>): bool {
13+
// The implementation currently can just use native equality since the mocked prover
14+
// representation does not have the `counter` field.
15+
h1 == h2
16+
}
17+
}
18+
}

aptos-move/framework/aptos-stdlib/sources/hash.move

-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,4 @@ module aptos_std::aptos_hash {
99

1010
sip_hash(bytes)
1111
}
12-
13-
spec sip_hash_from_value {
14-
// TODO: temporary mockup.
15-
pragma opaque;
16-
}
1712
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
spec aptos_std::aptos_hash {
2+
spec sip_hash_from_value {
3+
// TODO: temporary mockup.
4+
pragma opaque;
5+
}
6+
7+
spec sip_hash {
8+
// TODO: temporary mockup.
9+
pragma opaque;
10+
}
11+
}

aptos-move/framework/aptos-stdlib/sources/type_info.move

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ module aptos_std::type_info {
2222
public native fun type_of<T>(): TypeInfo;
2323
public native fun type_name<T>(): string::String;
2424

25-
spec type_of { // TODO: temporary mockup.
26-
pragma opaque;
27-
}
28-
2925
#[test]
3026
fun test() {
3127
let type_info = type_of<TypeInfo>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spec aptos_std::type_info {
2+
spec type_of { // TODO: temporary mockup.
3+
pragma opaque;
4+
}
5+
6+
spec type_name { // TODO: temporary mockup.
7+
pragma opaque;
8+
}
9+
}

aptos-move/framework/move-stdlib/Move.toml

-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ version = "1.5.0"
44

55
[addresses]
66
std = "0x1"
7-
8-
[dev-addresses]
9-
std = "0x1"

aptos-move/move-deps/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ move-ir-compiler = { git = "https://github.com/move-language/move", rev = "41395
3535
move-model = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }
3636
move-package = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }
3737
move-prover = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }
38+
move-prover-boogie-backend = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }
3839
move-prover-test-utils = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }
3940
move-resource-viewer = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }
4041
move-stackless-bytecode-interpreter = { git = "https://github.com/move-language/move", rev = "413955ea9246356b18af006584eb73283e9508da" }

aptos-move/move-deps/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub use move_ir_compiler;
1515
pub use move_model;
1616
pub use move_package;
1717
pub use move_prover;
18+
pub use move_prover_boogie_backend;
1819
pub use move_prover_test_utils;
1920
pub use move_resource_viewer;
2021
pub use move_stackless_bytecode_interpreter;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Copyright (c) Aptos
2+
// SPDX-License-Identifier: Apache-2.0

crates/aptos/src/move_tool/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use move_deps::{
4848
language_storage::{ModuleId, TypeTag},
4949
},
5050
move_package::{source_package::layout::SourcePackageLayout, BuildConfig},
51-
move_prover,
51+
move_prover, move_prover_boogie_backend,
5252
move_unit_test::UnitTestingConfig,
5353
};
5454
use std::fmt::{Display, Formatter};
@@ -322,6 +322,16 @@ impl CliCommand<&'static str> for ProvePackage {
322322
install_dir: self.move_options.output_dir.clone(),
323323
..Default::default()
324324
};
325+
326+
const APTOS_NATIVE_TEMPLATE: &[u8] = include_bytes!("aptos-natives.bpl");
327+
328+
let mut options = move_prover::cli::Options::default();
329+
options.backend.custom_natives =
330+
Some(move_prover_boogie_backend::options::CustomNativeOptions {
331+
template_bytes: APTOS_NATIVE_TEMPLATE.to_vec(),
332+
module_instance_names: vec![],
333+
});
334+
325335
let result = task::spawn_blocking(move || {
326336
move_cli::base::prove::run_move_prover(
327337
config,

0 commit comments

Comments
 (0)