Skip to content

Latest commit

 

History

History
348 lines (183 loc) · 11.5 KB

TransactionPublishOption.md

File metadata and controls

348 lines (183 loc) · 11.5 KB

Module 0x1::TransactionPublishOption

TransactionPublishOption provide an option to limit:

Struct TransactionPublishOption

Defines and holds the publishing policies for the VM. There are three possible configurations:

  1. !script_allowed && !module_publishing_allowed No module publishing, only script function in module are allowed.
  2. script_allowed && !module_publishing_allowed No module publishing, custom scripts are allowed.
  3. script_allowed && module_publishing_allowed Both module publishing and custom scripts are allowed. We represent these as the following resource.
struct TransactionPublishOption has copy, drop, store
Fields
script_allowed: bool
module_publishing_allowed: bool

Constants

const EINVALID_ARGUMENT: u64 = 18;

The script hash already exists in the allowlist

The script hash has an invalid length

const EINVALID_SCRIPT_HASH: u64 = 1001;

const SCRIPT_HASH_LENGTH: u64 = 32;

Function initialize

Module initialization.

public fun initialize(account: &signer, script_allowed: bool, module_publishing_allowed: bool)
Implementation
public fun initialize(
    account: &signer,
    script_allowed: bool,
    module_publishing_allowed: bool,
) {
    Timestamp::assert_genesis();
    assert!(
        Signer::address_of(account) == CoreAddresses::GENESIS_ADDRESS(),
        Errors::requires_address(EPROLOGUE_ACCOUNT_DOES_NOT_EXIST),
    );
    let transaction_publish_option = Self::new_transaction_publish_option(script_allowed, module_publishing_allowed);
    Config::publish_new_config(
        account,
        transaction_publish_option,
    );
}
Specification

Function new_transaction_publish_option

Create a new option. Mainly used in DAO.

public fun new_transaction_publish_option(script_allowed: bool, module_publishing_allowed: bool): TransactionPublishOption::TransactionPublishOption
Implementation
public fun new_transaction_publish_option(
    script_allowed: bool,
    module_publishing_allowed: bool,
): TransactionPublishOption {
    TransactionPublishOption { script_allowed, module_publishing_allowed }
}
Specification
aborts_if false;

Function is_script_allowed

Check if sender can execute script with

public fun is_script_allowed(account: address): bool
Implementation
public fun is_script_allowed(account: address): bool {
    let publish_option = Config::get_by_address<TransactionPublishOption>(account);
    publish_option.script_allowed
}
Specification

Function is_module_allowed

Check if a sender can publish a module

public fun is_module_allowed(account: address): bool
Implementation
public fun is_module_allowed(account: address): bool {
    let publish_option = Config::get_by_address<TransactionPublishOption>(account);
    publish_option.module_publishing_allowed
}
Specification

schema AbortsIfTxnPublishOptionNotExistWithBool {
    is_script_or_package : bool;
    aborts_if is_script_or_package && !exists<Config::Config<TransactionPublishOption>>(CoreAddresses::GENESIS_ADDRESS());
}

Module Specification

pragma verify = false;
pragma aborts_if_is_strict = true;

fun spec_is_script_allowed(addr: address) : bool{
   let publish_option = Config::get_by_address<TransactionPublishOption>(addr);
   publish_option.script_allowed
}

fun spec_is_module_allowed(addr: address) : bool{
   let publish_option = Config::get_by_address<TransactionPublishOption>(addr);
   publish_option.module_publishing_allowed
}