Skip to content

Commit

Permalink
Proof Zero Preimage (#778)
Browse files Browse the repository at this point in the history
* complete move fixtures

* add tower link to genesis preimage, make preimage a fixed 1024 size

* add wizard to add a tower link

* patching e2e tests and tools tests

* more sane fixtures managment for e2e tests

* patch merge

* patch fixtures helpers locations

* remove duplicate fixtures helper

* makefile recipe to backup 0L folder

* bring back info prints

* delay difficulty for stage was off.

* patch globals for vdf difficulty

* rename block_0.json throughout

* skip add_tower when in test mode for onboarding

* patch build
  • Loading branch information
0o-de-lally authored Oct 22, 2021
1 parent 8d27568 commit 68ef326
Show file tree
Hide file tree
Showing 76 changed files with 598 additions and 559 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 49 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,42 @@ mv-bin:
reset:
onboard val --skip-mining --upstream-peer http://167.172.248.37/ --source-path ~/libra

reset-safety:
jq -r '.["${ACC}-oper/safety_data"].value = { "epoch": 0, "last_voted_round": 0, "preferred_round": 0, "last_vote": null }' ${DATA_PATH}/key_store.json > ${DATA_PATH}/temp_key_store && mv ${DATA_PATH}/temp_key_store ${DATA_PATH}/key_store.json


backup:
cd ~ && rsync -av --exclude db/ --exclude logs/ ~/.0L ~/0L_backup_$(shell date +"%m-%d-%y")
cd ~ && rsync -av --exclude db/ --exclude logs/ ~/.0L ~/0L_backup_$(shell date +"%m-%d-%y-%T")

confirm:
@read -p "Continue (y/n)?" CONT; \
if [ "$$CONT" = "y" ]; then \
echo "deleting...."; \
else \
exit 1; \
fi \

danger-delete-all:
@echo THIS WILL WIPE ALL YOUR FILES in ${HOME}/.0L
@echo it will also make a backup at ${HOME}/backup_0L/
@echo the files github_token.txt, autopay_batch.json, set_layout, ./vdf_proofs/ and ./blocks/ will be returned to ${HOME}/.0L/
make confirm
make backup
rm -rf ${HOME}/.0L | true
mkdir ${HOME}/.0L/
make danger-restore

danger-restore:
cp ${HOME}/backup_0L/github_token.txt ${HOME}/.0L/ | true
cp ${HOME}/backup_0L/autopay_batch.json ${HOME}/.0L/ | true
rsync -rtv ${HOME}/backup_0L/blocks/ ${HOME}/.0L/blocks | true
rsync -rtv ${HOME}/backup_0L/vdf_proofs/ ${HOME}/.0L/vdf_proofs | true
rsync -rtv ${HOME}/backup_0L/set_layout.toml ${HOME}/.0L/ | true





clear-prod-db:
@echo WIPING DB
make confirm
rm -rf ${DATA_PATH}/db | true

reset-safety:
Expand Down Expand Up @@ -185,22 +212,14 @@ gen-make-pull:
--shared-backend ${GENESIS_REMOTE} \
--pull-request-user ${GITHUB_USER}

genesis-miner:
cargo run -p tower -- zero


gen-onboard:
cargo run -p onboard ${CARGO_ARGS} -- val --genesis-ceremony
cargo run -p onboard ${CARGO_ARGS} -- val --genesis-ceremony

ceremony: gen-fork-repo gen-onboard
gen-reset:
cargo run -p onboard ${CARGO_ARGS} -- val --genesis-ceremony --skip-mining

# cargo run -p tower ${CARGO_ARGS} -- zero

register:
# export ACC=$(shell toml get ${DATA_PATH}/0L.toml profile.account)
# @echo Initializing from ${DATA_PATH}/0L.toml with account:
# @echo ${ACC}
# make init
gen-register:

@echo the OPER initializes local accounts and submit pubkeys to github
ACC=${ACC}-oper make oper-key
Expand All @@ -214,10 +233,8 @@ register:
@echo OPER send signed transaction with configurations for *OWNER* account
ACC=${ACC}-oper OWNER=${ACC} IP=${IP} make reg

ifeq (${TEST}, y)
@echo Making pull request to genesis coordination repo
make gen-make-pull
endif

init-test:
echo ${MNEM} | head -c -1 | cargo run -p diem-genesis-tool -- init --path=${DATA_PATH} --namespace=${ACC}
Expand All @@ -227,15 +244,15 @@ init:
# OWNER does this
# Submits proofs to shared storage
add-proofs:
cargo run -p diem-genesis-tool ${CARGO_ARGS} -- mining \
--path-to-genesis-pow ${DATA_PATH}/blocks/block_0.json \
cargo run -p diem-genesis-tool ${CARGO_ARGS} -- mining \
--path-to-genesis-pow ${DATA_PATH}/vdf_proofs/proof_0.json \
--path-to-account-json ${DATA_PATH}/account.json \
--shared-backend ${REMOTE}

# OPER does this
# Submits operator key to github, and creates local OPERATOR_ACCOUNT
oper-key:
cargo run -p diem-genesis-tool ${CARGO_ARGS} -- operator-key \
cargo run -p diem-genesis-tool ${CARGO_ARGS} -- operator-key \
--validator-backend ${LOCAL} \
--shared-backend ${REMOTE}

Expand Down Expand Up @@ -291,7 +308,7 @@ genesis:
#### NODE MANAGEMENT ####
start:
# run in foreground. Only for testing, use a daemon for net.
cargo run -p diem-node -- --config ${DATA_PATH}/validator.node.yaml
NODE_ENV=error cargo run -p diem-node -- --config ${DATA_PATH}/validator.node.yaml

# Start a fullnode instead of a validator node
start-full:
Expand Down Expand Up @@ -327,8 +344,8 @@ ifeq (${TEST}, y)
@if test -d ${DATA_PATH}; then \
cd ${DATA_PATH} && rm -rf libradb *.yaml *.blob *.json db *.toml; \
fi
@if test -d ${DATA_PATH}/blocks; then \
rm -f ${DATA_PATH}/blocks/*.json; \
@if test -d ${DATA_PATH}/vdf_proofs; then \
rm -f ${DATA_PATH}/vdf_proofs/*.json; \
fi
endif

Expand Down Expand Up @@ -359,11 +376,11 @@ ifdef TEST
@if test ! -d ${DATA_PATH}; then \
echo Creating Directories \
mkdir ${DATA_PATH}; \
mkdir -p ${DATA_PATH}/blocks/; \
mkdir -p ${DATA_PATH}/vdf_proofs/; \
fi

@if test -f ${DATA_PATH}/blocks/block_0.json; then \
rm ${DATA_PATH}/blocks/block_0.json; \
@if test -f ${DATA_PATH}/vdf_proofs/proof_0.json; then \
rm ${DATA_PATH}/vdf_proofs/proof_0.json; \
fi

@if test -f ${DATA_PATH}/0L.toml; then \
Expand All @@ -373,7 +390,7 @@ ifdef TEST
# skip miner configuration with fixtures
cp ./ol/fixtures/configs/${NS}.toml ${DATA_PATH}/0L.toml
# skip mining proof zero with fixtures
cp ./ol/fixtures/blocks/${NODE_ENV}/${NS}/block_0.json ${DATA_PATH}/blocks/block_0.json
cp ./ol/fixtures/vdf_proofs/${NODE_ENV}/${NS}/proof_0.json ${DATA_PATH}/vdf_proofs/proof_0.json
# place a mock autopay.json in root
cp ./ol/fixtures/autopay/${NS}.autopay_batch.json ${DATA_PATH}/autopay_batch.json
# place a mock account.json in root, used as template for onboarding
Expand Down Expand Up @@ -486,14 +503,14 @@ clean-tags:
git tag -d ${TAG}

nuke-testnet:
@echo WIPING EVERYTHING but keeping: github_token.txt, autopay_batch.json, set_layout.toml, /blocks/block_0.json
@echo WIPING EVERYTHING but keeping: github_token.txt, autopay_batch.json, set_layout.toml, /vdf_proofs/proof_0.json

@if test -d ${DATA_PATH}; then \
cd ${DATA_PATH} && cp github_token.txt autopay_batch.json set_layout.toml blocks/block_0.json ~/; \
cd ${DATA_PATH} && cp github_token.txt autopay_batch.json set_layout.toml vdf_proofs/proof_0.json ~/; \
cd ${DATA_PATH} && rm -rf *; \
cd ~ && cp github_token.txt autopay_batch.json set_layout.toml ${DATA_PATH}; \
cd ${DATA_PATH} && mkdir blocks;\
cd ~ && cp block_0.json ${DATA_PATH}/blocks/; \
cd ${DATA_PATH} && mkdir vdf_proofs;\
cd ~ && cp proof_0.json ${DATA_PATH}/vdf_proofs/; \
fi


Expand Down
9 changes: 4 additions & 5 deletions config/global-constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ pub const VDF_SECURITY_PARAM: u16 = 512;
/// Filename for 0L configs
pub const CONFIG_FILE: &str = "0L.toml";


// TODO: make this lazy static.
/// Switch settings between production and testing
pub fn delay_difficulty() -> u64 {
let node_env = match env::var("NODE_ENV") {
Ok(val) => val,
_ => "prod".to_string() // default to "prod" if not set
};
// must explicitly set env to prod to use production difficulty.
if node_env == "prod" {
return 120_000_000
// test settings need to be set explicitly
if node_env == "test" {
return 100 // difficulty for test suites and on local for debugging purposes.
}
return 100 // difficulty for test suites and on local for debugging purposes.
return 120_000_000
}
12 changes: 6 additions & 6 deletions config/management/genesis/src/ol_node_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ pub fn write_node_config_files(
disk_storage.path = output_dir.clone().join("key_store.json");
disk_storage.namespace = Some(namespace.to_owned());

// Write the genesis waypoint without a namespaced storage.
let mut safety_rules_storage = OnDiskStorageConfig::default();
safety_rules_storage.set_data_dir(output_dir.clone());
safety_rules_storage.path = output_dir.clone().join("safety_rules.json");
safety_rules_storage.namespace = Some(namespace.to_owned());
// // Write the genesis waypoint without a namespaced storage.
// let mut safety_rules_storage = OnDiskStorageConfig::default();
// safety_rules_storage.set_data_dir(output_dir.clone());
// safety_rules_storage.path = output_dir.clone().join("safety_rules.json");
// safety_rules_storage.namespace = Some(namespace.to_owned());

// Get node configs template
let mut config = if *fullnode_only {
Expand Down Expand Up @@ -181,7 +181,7 @@ pub fn write_node_config_files(
c.execution.genesis_file_location = genesis_path.clone();

c.consensus.safety_rules.service = SafetyRulesService::Thread;
c.consensus.safety_rules.backend = SecureBackend::OnDiskStorage(safety_rules_storage);
c.consensus.safety_rules.backend = SecureBackend::OnDiskStorage(disk_storage.clone());

c
};
Expand Down
8 changes: 4 additions & 4 deletions language/diem-framework/modules/0L/Globals.move
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,25 @@ module Globals {

if (StagingNet::is_staging_net()) {
return GlobalConstants {
epoch_length: 60 * 20, // 20 mins, enough for a hard miner proof.
epoch_length: 60 * 40, // 20 mins, enough for a hard miner proof.
max_validators_per_set: 100,
subsidy_ceiling_gas: 8640000 * coin_scale,
vdf_difficulty: 5000000,
vdf_difficulty: 120000000,
epoch_mining_thres_lower: 1,
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof.
epoch_slow_wallet_unlock: 10000000,
}
} else {
return GlobalConstants {
epoch_length: 60 * 60 * 24, // approx 24 hours at 1.4 blocks/sec
epoch_length: 60 * 60 * 24, // approx 24 hours at 1.4 vdf_proofs/sec
max_validators_per_set: 100, // max expected for BFT limits.
// See DiemVMConfig for gas constants:
// Target max gas units per transaction 100000000
// target max block time: 2 secs
// target transaction per sec max gas: 20
// uses "scaled representation", since there are no decimals.
subsidy_ceiling_gas: 8640000 * coin_scale, // subsidy amount assumes 24 hour epoch lengths. Also needs to be adjusted for coin_scale the onchain representation of human readable value.
vdf_difficulty: 5000000, // FYI approx 10 mins per proof on 2020 macbook pro 2.5 ghz quadcore
vdf_difficulty: 120000000, // FYI approx 30 mins per proof on 2020 macbook pro 2.5 ghz quadcore
epoch_mining_thres_lower: 7, // NOTE: bootstrapping, allowance for operator error.
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof.
epoch_slow_wallet_unlock: 1000 * coin_scale, // approx 10 years for largest accounts in genesis.
Expand Down
3 changes: 1 addition & 2 deletions language/diem-framework/modules/0L/TestFixtures.move
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module TestFixtures{
x"0051dfa4c3341c18197b72f5e5eecc693eb56d408206c206d90f5ec7a75f833b2affb0ea7280d4513ab8351f39362d362203ff3e41882309e7900f470f0a27eeeb7b"
}

//FROM: diem/fixtures/block_0.json.stage.alice
public fun alice_0_easy_chal(): vector<u8> {
assert(Testnet::is_testnet(), 130102014010);
x"87515d94a244235a1433d7117bc0cb154c613c2f4b1e67ca8d98a542ee3f59f5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006578706572696d656e74616c6400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074657374"
Expand All @@ -42,7 +41,7 @@ module TestFixtures{
x"00639237baac2348608e1e6dbcee015a2a628780d97f865f17c6e9f99d325ecb120052b0be3b0578af20cf0c4304ab14cbe7635a4247ed4ff3fcbd488bc66eb88cb7"
}

//FROM: diem/fixtures/block_1.json.stage.alice
//FROM: ol/fixtures/proof_1.json.stage.alice

public fun alice_1_easy_chal(): vector<u8> {
assert(Testnet::is_testnet(), 130102014010);
Expand Down
75 changes: 1 addition & 74 deletions language/diem-framework/modules/doc/DiemAccount.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ before and after every transaction.
- [Function `preburn`](#0x1_DiemAccount_preburn)
- [Function `extract_withdraw_capability`](#0x1_DiemAccount_extract_withdraw_capability)
- [Function `restore_withdraw_capability`](#0x1_DiemAccount_restore_withdraw_capability)
- [Function `vm_make_payment`](#0x1_DiemAccount_vm_make_payment)
- [Function `process_community_wallets`](#0x1_DiemAccount_process_community_wallets)
- [Function `vm_make_payment_no_limit`](#0x1_DiemAccount_vm_make_payment_no_limit)
- [Function `vm_burn_from_balance`](#0x1_DiemAccount_vm_burn_from_balance)
Expand Down Expand Up @@ -2694,79 +2693,6 @@ Return the withdraw capability to the account it originally came from



</details>

<a name="0x1_DiemAccount_vm_make_payment"></a>

## Function `vm_make_payment`



<pre><code><b>public</b> <b>fun</b> <a href="DiemAccount.md#0x1_DiemAccount_vm_make_payment">vm_make_payment</a>&lt;Token: store&gt;(payer: address, payee: address, amount: u64, metadata: vector&lt;u8&gt;, metadata_signature: vector&lt;u8&gt;, vm: &signer)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="DiemAccount.md#0x1_DiemAccount_vm_make_payment">vm_make_payment</a>&lt;Token: store&gt;(
payer : address,
payee: address,
amount: u64,
metadata: vector&lt;u8&gt;,
metadata_signature: vector&lt;u8&gt;,
vm: &signer
) <b>acquires</b> <a href="DiemAccount.md#0x1_DiemAccount">DiemAccount</a> , <a href="DiemAccount.md#0x1_DiemAccount_Balance">Balance</a>, <a href="DiemAccount.md#0x1_DiemAccount_AccountOperationsCapability">AccountOperationsCapability</a>, <a href="DiemAccount.md#0x1_DiemAccount_AutopayEscrow">AutopayEscrow</a>, <a href="DiemAccount.md#0x1_DiemAccount_CumulativeDeposits">CumulativeDeposits</a>, <a href="DiemAccount.md#0x1_DiemAccount_SlowWallet">SlowWallet</a> { //////// 0L ////////
<b>if</b> (<a href="../../../../../../move-stdlib/docs/Signer.md#0x1_Signer_address_of">Signer::address_of</a>(vm) != <a href="CoreAddresses.md#0x1_CoreAddresses_DIEM_ROOT_ADDRESS">CoreAddresses::DIEM_ROOT_ADDRESS</a>()) <b>return</b>;
<b>if</b> (amount == 0) <b>return</b>;

// Check payee can receive funds in this currency.
<b>if</b> (!<b>exists</b>&lt;<a href="DiemAccount.md#0x1_DiemAccount_Balance">Balance</a>&lt;Token&gt;&gt;(payee)) <b>return</b>;
// <b>assert</b>(<b>exists</b>&lt;<a href="DiemAccount.md#0x1_DiemAccount_Balance">Balance</a>&lt;Token&gt;&gt;(payee), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_not_published">Errors::not_published</a>(<a href="DiemAccount.md#0x1_DiemAccount_EROLE_CANT_STORE_BALANCE">EROLE_CANT_STORE_BALANCE</a>));

// Check there is a payer
<b>if</b> (!<a href="DiemAccount.md#0x1_DiemAccount_exists_at">exists_at</a>(payer)) <b>return</b>;
// <b>assert</b>(<a href="DiemAccount.md#0x1_DiemAccount_exists_at">exists_at</a>(payer), <a href="../../../../../../move-stdlib/docs/Errors.md#0x1_Errors_not_published">Errors::not_published</a>(<a href="DiemAccount.md#0x1_DiemAccount_EACCOUNT">EACCOUNT</a>));

// Check the payer is in possession of withdraw token.
<b>if</b> (<a href="DiemAccount.md#0x1_DiemAccount_delegated_withdraw_capability">delegated_withdraw_capability</a>(payer)) <b>return</b>;

<b>let</b> (max_withdraw, withdrawal_allowed) = <a href="AccountLimits.md#0x1_AccountLimits_max_withdrawal">AccountLimits::max_withdrawal</a>&lt;Token&gt;(payer);
<b>if</b> (!withdrawal_allowed) <b>return</b>;

// VM can extract the withdraw token.
<b>let</b> account = borrow_global_mut&lt;<a href="DiemAccount.md#0x1_DiemAccount">DiemAccount</a>&gt;(payer);
<b>let</b> cap = <a href="../../../../../../move-stdlib/docs/Option.md#0x1_Option_extract">Option::extract</a>(&<b>mut</b> account.withdraw_capability);

<b>let</b> transfer_now =
<b>if</b> (max_withdraw &gt;= amount) {
amount
} <b>else</b> {
max_withdraw
};
<b>let</b> transfer_later = amount - transfer_now;
<b>if</b> (transfer_now &gt; 0) {
<a href="DiemAccount.md#0x1_DiemAccount_pay_from">pay_from</a>&lt;Token&gt;(
&cap,
payee,
transfer_now,
metadata,
metadata_signature
);
};

<b>if</b> (transfer_later &gt; 0) {
<a href="DiemAccount.md#0x1_DiemAccount_new_escrow">new_escrow</a>&lt;Token&gt;(vm, payer, payee, transfer_later);
};

<a href="DiemAccount.md#0x1_DiemAccount_restore_withdraw_capability">restore_withdraw_capability</a>(cap);
}
</code></pre>



</details>

<a name="0x1_DiemAccount_process_community_wallets"></a>
Expand Down Expand Up @@ -3583,6 +3509,7 @@ Creating an account at address 0x0 will abort as it is a reserved address for th
}
);

<a href="Receipts.md#0x1_Receipts_init">Receipts::init</a>(&new_account);
//////// 0L ////////
// NOTE: <b>if</b> all accounts are <b>to</b> be slow set this
// <a href="DiemAccount.md#0x1_DiemAccount_set_slow">set_slow</a>(&new_account);
Expand Down
2 changes: 1 addition & 1 deletion language/diem-framework/modules/doc/Globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Get the constants for the current network

<b>if</b> (<a href="Testnet.md#0x1_StagingNet_is_staging_net">StagingNet::is_staging_net</a>()) {
<b>return</b> <a href="Globals.md#0x1_Globals_GlobalConstants">GlobalConstants</a> {
epoch_length: 60 * 20, // 20 mins, enough for a hard miner proof.
epoch_length: 60 * 40, // 20 mins, enough for a hard miner proof.
max_validators_per_set: 100,
subsidy_ceiling_gas: 8640000 * coin_scale,
vdf_difficulty: 5000000,
Expand Down
Loading

0 comments on commit 68ef326

Please sign in to comment.