-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Spec] add boogie native for aggregator_v2 (#14881)
* add native for aggregator_v2 * handle comments * refactor aptos-natives.bpl
- Loading branch information
1 parent
6353f46
commit ee1791a
Showing
10 changed files
with
1,392 additions
and
59 deletions.
There are no files selected for viewing
837 changes: 828 additions & 9 deletions
837
aptos-move/framework/aptos-framework/doc/aggregator_v2.md
Large diffs are not rendered by default.
Oops, something went wrong.
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
100 changes: 68 additions & 32 deletions
100
aptos-move/framework/aptos-framework/sources/aggregator_v2/aggregator_v2.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,73 +1,109 @@ | ||
spec aptos_framework::aggregator_v2 { | ||
spec create_aggregator { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
|
||
spec Aggregator { | ||
pragma intrinsic; | ||
} | ||
|
||
spec create_unbounded_aggregator { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
spec max_value<IntElement: copy + drop>(aggregator: &Aggregator<IntElement>): IntElement { | ||
pragma intrinsic; | ||
} | ||
|
||
spec try_add { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
spec create_aggregator<IntElement: copy + drop>(max_value: IntElement): Aggregator<IntElement> { | ||
pragma intrinsic; | ||
} | ||
|
||
spec try_sub { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
spec create_unbounded_aggregator<IntElement: copy + drop>(): Aggregator<IntElement> { | ||
pragma intrinsic; | ||
} | ||
|
||
spec is_at_least_impl { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
spec try_add<IntElement>(aggregator: &mut Aggregator<IntElement>, value: IntElement): bool { | ||
pragma intrinsic; | ||
} | ||
|
||
spec read { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
spec add<IntElement>(aggregator: &mut Aggregator<IntElement>, value: IntElement) { | ||
pragma intrinsic; | ||
} | ||
|
||
spec try_sub<IntElement>(aggregator: &mut Aggregator<IntElement>, value: IntElement): bool { | ||
pragma intrinsic; | ||
} | ||
|
||
spec sub<IntElement>(aggregator: &mut Aggregator<IntElement>, value: IntElement) { | ||
pragma intrinsic; | ||
} | ||
|
||
spec is_at_least_impl<IntElement>(aggregator: &Aggregator<IntElement>, min_amount: IntElement): bool { | ||
pragma intrinsic; | ||
} | ||
|
||
spec read<IntElement>(aggregator: &Aggregator<IntElement>): IntElement { | ||
pragma intrinsic; | ||
} | ||
|
||
spec snapshot { | ||
// TODO: temporary mockup. | ||
spec snapshot<IntElement>(aggregator: &Aggregator<IntElement>): AggregatorSnapshot<IntElement> { | ||
pragma opaque; | ||
include AbortsIfIntElement<IntElement>; | ||
ensures [abstract] result.value == spec_get_value(aggregator); | ||
} | ||
|
||
spec create_snapshot { | ||
// TODO: temporary mockup. | ||
spec create_snapshot<IntElement: copy + drop>(value: IntElement): AggregatorSnapshot<IntElement> { | ||
pragma opaque; | ||
include AbortsIfIntElement<IntElement>; | ||
ensures [abstract] result.value == value; | ||
} | ||
|
||
spec read_snapshot { | ||
// TODO: temporary mockup. | ||
spec read_snapshot<IntElement>(snapshot: &AggregatorSnapshot<IntElement>): IntElement { | ||
pragma opaque; | ||
include AbortsIfIntElement<IntElement>; | ||
ensures [abstract] result == snapshot.value; | ||
} | ||
|
||
spec read_derived_string { | ||
// TODO: temporary mockup. | ||
spec read_derived_string(snapshot: &DerivedStringSnapshot): String { | ||
pragma opaque; | ||
aborts_if [abstract] false; | ||
ensures [abstract] result == snapshot.value; | ||
} | ||
|
||
spec create_derived_string { | ||
// TODO: temporary mockup. | ||
spec create_derived_string(value: String): DerivedStringSnapshot { | ||
pragma opaque; | ||
aborts_if [abstract] len(value.bytes) > 1024; | ||
ensures [abstract] result.value == value; | ||
} | ||
|
||
spec derive_string_concat { | ||
// TODO: temporary mockup. | ||
spec derive_string_concat<IntElement>(before: String, snapshot: &AggregatorSnapshot<IntElement>, after: String): DerivedStringSnapshot { | ||
pragma opaque; | ||
include AbortsIfIntElement<IntElement>; | ||
ensures [abstract] result.value.bytes == concat(before.bytes, concat(spec_get_string_value(snapshot).bytes, after.bytes)); | ||
aborts_if [abstract] len(before.bytes) + len(after.bytes) > 1024; | ||
} | ||
|
||
spec schema AbortsIfIntElement<IntElement> { | ||
use aptos_std::type_info; | ||
aborts_if [abstract] type_info::type_name<IntElement>().bytes != b"u64" && type_info::type_name<IntElement>().bytes != b"u128"; | ||
} | ||
|
||
// deprecated | ||
spec copy_snapshot { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
aborts_if [abstract] true; | ||
} | ||
|
||
// deprecated | ||
spec string_concat { | ||
// TODO: temporary mockup. | ||
pragma opaque; | ||
aborts_if [abstract] true; | ||
} | ||
|
||
// Get aggregator.value | ||
spec native fun spec_get_value<IntElement>(aggregator: Aggregator<IntElement>): IntElement; | ||
// Get aggregator.max_value | ||
spec native fun spec_get_max_value<IntElement>(aggregator: Aggregator<IntElement>): IntElement; | ||
// Uninterpreted spec function that translates the value inside aggregator into corresponding string representation | ||
spec fun spec_get_string_value<IntElement>(aggregator: AggregatorSnapshot<IntElement>): String; | ||
spec fun spec_read_snapshot<IntElement>(snapshot: AggregatorSnapshot<IntElement>): IntElement { | ||
snapshot.value | ||
} | ||
spec fun spec_read_derived_string(snapshot: DerivedStringSnapshot): String { | ||
snapshot.value | ||
} | ||
} |
Oops, something went wrong.