diff --git a/app/app.go b/app/app.go index c278293e5..2c4253835 100644 --- a/app/app.go +++ b/app/app.go @@ -37,6 +37,7 @@ import ( v1_5 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.5" v1_6 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.6" v1_7 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.7" + v1_8 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.8" icaauthtypes "github.com/scrtlabs/SecretNetwork/x/mauth/types" "github.com/cosmos/cosmos-sdk/version" @@ -118,7 +119,7 @@ var ( distrtypes.ModuleName: true, } - Upgrades = []upgrades.Upgrade{v1_3.Upgrade, v1_4.Upgrade, v1_5.Upgrade, v1_6.Upgrade, v1_7.Upgrade} + Upgrades = []upgrades.Upgrade{v1_3.Upgrade, v1_4.Upgrade, v1_5.Upgrade, v1_6.Upgrade, v1_7.Upgrade, v1_8.Upgrade} ) // Verify app interface at compile time diff --git a/app/upgrades/v1.8/upgrade.go b/app/upgrades/v1.8/upgrade.go new file mode 100644 index 000000000..ac422182b --- /dev/null +++ b/app/upgrades/v1.8/upgrade.go @@ -0,0 +1,35 @@ +package v1_8 + +import ( + "fmt" + + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/scrtlabs/SecretNetwork/app/keepers" + "github.com/scrtlabs/SecretNetwork/app/upgrades" +) + +const upgradeName = "v1.8" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: upgradeName, + CreateUpgradeHandler: createUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} + +func createUpgradeHandler(mm *module.Manager, keepers *keepers.SecretAppKeepers, configurator module.Configurator, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info(` _ _ _____ _____ _____ _____ ______ `) + ctx.Logger().Info(`| | | | __ \ / ____| __ \ /\ | __ \| ____|`) + ctx.Logger().Info(`| | | | |__) | | __| |__) | / \ | | | | |__ `) + ctx.Logger().Info(`| | | | ___/| | |_ | _ / / /\ \ | | | | __| `) + ctx.Logger().Info(`| |__| | | | |__| | | \ \ / ____ \| |__| | |____ `) + ctx.Logger().Info(` \____/|_| \_____|_| \_\/_/ \_\_____/|______|`) + + ctx.Logger().Info(fmt.Sprintf("Running module migrations for %s...", upgradeName)) + return mm.RunMigrations(ctx, configurator, vm) + } +} diff --git a/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs b/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs index ae7a412c8..882ed9c16 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/contract_operations.rs @@ -155,12 +155,12 @@ pub fn init( debug!("New random: {:?}", versioned_env.get_random()); } + update_msg_counter(block_height); //let start = Instant::now(); let result = engine.init(&versioned_env, validated_msg); // let duration = start.elapsed(); // trace!("Time elapsed in engine.init: {:?}", duration); - update_msg_counter(block_height); *used_gas = engine.gas_used(); let output = result?; @@ -322,10 +322,10 @@ pub fn handle( versioned_env.set_contract_hash(&contract_hash); + update_msg_counter(block_height); let result = engine.handle(&versioned_env, validated_msg, &parsed_handle_type); *used_gas = engine.gas_used(); - update_msg_counter(block_height); let mut output = result?; diff --git a/cosmwasm/enclaves/shared/contract-engine/src/random.rs b/cosmwasm/enclaves/shared/contract-engine/src/random.rs index f9fc3ba90..cc1a3667c 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/random.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/random.rs @@ -52,8 +52,12 @@ pub fn derive_random(seed: &Binary, contract_key: &ContractKey, height: u64) -> pub fn update_msg_counter(height: u64) { let mut counter = MSG_COUNTER.lock().unwrap(); - counter.height = height; - counter.counter += 1; + if counter.height != height { + counter.height = height; + counter.counter = 0; + } else { + counter.counter += 1; + } trace!("counter incremented to: {:?}", counter); } diff --git a/docs/proposals/v1.8.md b/docs/proposals/v1.8.md new file mode 100644 index 000000000..44c2d9271 --- /dev/null +++ b/docs/proposals/v1.8.md @@ -0,0 +1,13 @@ +This proposal proposes that the chain elect to do an **EMERGENCY** software upgrade to the v1.8 software version of the Secret Network codebase on block **7,760,000**, which is estimated to occur on **Saturday, March 4, 2023 at ~3pm UTC**. Block times have high variance, so please monitor the chain for more precise time estimates. + +## Emergency Upgrade Reason + +After the upgrade to v1.7 on March 1, many node runners experienced node crashes with an apphash error either when starting from state sync or after restarting their node's process. Upon conducting a root cause analysis, SCRT Labs discovered a bug in our v1.7 code. + +The bug was caused by the introduction of a new encryption scheme in v1.7. Specifically, a unique salt was added to the encryption of each storage write, which includes a counter of contract calls within each block. This counter only exists in the enclave's memory, and the bug caused it to never reset when a new block began. As a result, restarting a node or starting from state sync caused the counter to become out of sync with all the nodes that had not been restarted after the v1.7 upgrade. Consequently, this resulted in a different encryption output which is part of consensus. + +While this bug still exists, existing nodes cannot restart their process and new nodes cannot join the network. + +## Upgrade Instructions + +See [docs.scrt.network](https://docs.scrt.network/secret-network-documentation/infrastructure/upgrade-instructions/v1.8) for upgrade instructions.