-
Notifications
You must be signed in to change notification settings - Fork 2
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
Ensured that the Supra protocol configuration settings are stored in the Move state. #84
Changes from all commits
05c67bf
24c1596
c3b2495
617e383
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/// Maintains protocol configuation settings specific to Supra. The config is stored in a | ||
/// may be updated by root. | ||
module supra_framework::supra_config { | ||
use std::error; | ||
use std::vector; | ||
use supra_framework::chain_status; | ||
use supra_framework::config_buffer; | ||
use supra_framework::reconfiguration; | ||
use supra_framework::system_addresses; | ||
|
||
friend supra_framework::genesis; | ||
friend supra_framework::reconfiguration_with_dkg; | ||
|
||
struct SupraConfig has drop, key, store { | ||
config: vector<u8>, | ||
} | ||
|
||
/// The provided on chain config bytes are empty or invalid | ||
const EINVALID_CONFIG: u64 = 1; | ||
|
||
/// Publishes the SupraConfig config. | ||
public(friend) fun initialize(supra_framework: &signer, config: vector<u8>) { | ||
system_addresses::assert_supra_framework(supra_framework); | ||
assert!(vector::length(&config) > 0, error::invalid_argument(EINVALID_CONFIG)); | ||
move_to(supra_framework, SupraConfig { config }); | ||
} | ||
|
||
/// This can be called by on-chain governance to update on-chain configs for the next epoch. | ||
/// Example usage: | ||
/// ``` | ||
/// supra_framework::supra_config::set_for_next_epoch(&framework_signer, some_config_bytes); | ||
/// supra_framework::supra_governance::reconfigure(&framework_signer); | ||
/// ``` | ||
public fun set_for_next_epoch(account: &signer, config: vector<u8>) { | ||
system_addresses::assert_supra_framework(account); | ||
assert!(vector::length(&config) > 0, error::invalid_argument(EINVALID_CONFIG)); | ||
std::config_buffer::upsert<SupraConfig>(SupraConfig {config}); | ||
} | ||
|
||
/// Only used in reconfigurations to apply the pending `SupraConfig`, if there is any. | ||
public(friend) fun on_new_epoch(framework: &signer) acquires SupraConfig { | ||
system_addresses::assert_supra_framework(framework); | ||
if (config_buffer::does_exist<SupraConfig>()) { | ||
let new_config = config_buffer::extract<SupraConfig>(); | ||
if (exists<SupraConfig>(@supra_framework)) { | ||
*borrow_global_mut<SupraConfig>(@supra_framework) = new_config; | ||
} else { | ||
move_to(framework, new_config); | ||
}; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
spec supra_framework::supra_config { | ||
/// <high-level-req> | ||
/// No.: 1 | ||
/// Requirement: During genesis, the Supra framework account should be assigned the supra config resource. | ||
/// Criticality: Medium | ||
/// Implementation: The supra_config::initialize function calls the assert_supra_framework function to ensure | ||
/// that the signer is the supra_framework and then assigns the SupraConfig resource to it. | ||
/// Enforcement: Formally verified via [high-level-req-1](initialize). | ||
/// | ||
/// No.: 2 | ||
/// Requirement: Only aptos framework account is allowed to update the supra protocol configuration. | ||
/// Criticality: Medium | ||
/// Implementation: The supra_config::set function ensures that the signer is supra_framework. | ||
/// Enforcement: Formally verified via [high-level-req-2](set). | ||
/// | ||
/// No.: 3 | ||
/// Requirement: Only a valid configuration can be used during initialization and update. | ||
/// Criticality: Medium | ||
/// Implementation: Both the initialize and set functions validate the config by ensuring its length to be greater | ||
/// than 0. | ||
/// Enforcement: Formally verified via [high-level-req-3.1](initialize) and [high-level-req-3.2](set). | ||
/// </high-level-req> | ||
/// | ||
spec module { | ||
use supra_framework::chain_status; | ||
pragma verify = true; | ||
pragma aborts_if_is_strict; | ||
invariant [suspendable] chain_status::is_operating() ==> exists<SupraConfig>(@supra_framework); | ||
} | ||
|
||
/// Ensure caller is admin. | ||
/// Aborts if StateStorageUsage already exists. | ||
spec initialize(supra_framework: &signer, config: vector<u8>) { | ||
use std::signer; | ||
let addr = signer::address_of(supra_framework); | ||
/// [high-level-req-1] | ||
aborts_if !system_addresses::is_supra_framework_address(addr); | ||
aborts_if exists<SupraConfig>(@supra_framework); | ||
/// [high-level-req-3.1] | ||
aborts_if !(len(config) > 0); | ||
ensures global<SupraConfig>(addr) == SupraConfig { config }; | ||
} | ||
|
||
spec set_for_next_epoch(account: &signer, config: vector<u8>) { | ||
include config_buffer::SetForNextEpochAbortsIf; | ||
} | ||
|
||
spec on_new_epoch(framework: &signer) { | ||
requires @supra_framework == std::signer::address_of(framework); | ||
include config_buffer::OnNewEpochRequirement<SupraConfig>; | ||
aborts_if 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. Curious: What does this check do? 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. Not sure tbh. I just copied the spec for consensus_config and changed it in the same way that I changed the contract itself. @axiongsupra will double check to make sure everything's alright. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
ROOT="$(pwd)" | ||
cargo build --release | ||
cd ./aptos-move/framework/supra-framework && "$ROOT"/target/release/aptos move test || exit 1 | ||
cd .. | ||
cargo test --release -p aptos-framework -- --skip prover || exit 2 | ||
RUST_MIN_STACK=104857600 cargo nextest run -p e2e-move-tests || exit 3 |
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.
Should this be Supra framework?
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.
Yes. I didn't update the docs very carefully. We'll have to update that in future PR.