Skip to content

Commit

Permalink
Fix migration code for hardcoded admins
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Sep 26, 2023
1 parent 98ff997 commit fa056ad
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions x/compute/internal/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,29 @@ func v1GetContractKey(ctx sdk.Context, k Keeper, contractAddress sdk.AccAddress)
// CurrentContractKeyProof []byte
// }
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
iter := prefix.NewStore(ctx.KVStore(m.keeper.storeKey), types.ContractKeyPrefix).Iterator(nil, nil)
store := prefix.NewStore(ctx.KVStore(m.keeper.storeKey), types.ContractKeyPrefix)
iter := store.Iterator(nil, nil)
defer iter.Close()

for ; iter.Valid(); iter.Next() {
var contractAddress sdk.AccAddress = iter.Key()

var contractInfo types.ContractInfo
m.keeper.cdc.MustUnmarshal(iter.Value(), &contractInfo)

if ctx.ChainID() == "secret-4" {
if hardcodedContractAdmins[contractAddress.String()] != "" {
contractInfo.Admin = hardcodedContractAdmins[contractAddress.String()]
// When the contract has a hardcoded admin via gov, adminProof is ignored inside the enclave.
// Otherwise and if valid, adminProof is a 32 bytes array (output of sha256).
// For future proofing and avoiding passing null pointers to the enclave, we'll set it to a 32 bytes array of 0.
contractInfo.AdminProof = make([]byte, 32)
}
historyEntry := contractInfo.InitialHistory(nil)
m.keeper.addToContractCodeSecondaryIndex(ctx, contractAddress, historyEntry)
m.keeper.appendToContractHistory(ctx, contractAddress, historyEntry)

if hardcodedContractAdmins[contractAddress.String()] != "" {
contractInfo.Admin = hardcodedContractAdmins[contractAddress.String()]
// When the contract has a hardcoded admin via gov, adminProof is ignored inside the enclave.
// Otherwise and if valid, adminProof is a 32 bytes array (output of sha256).
// For future proofing and avoiding passing null pointers to the enclave, we'll set it to a 32 bytes array of 0.
contractInfo.AdminProof = make([]byte, 32)

newContractInfoBz := m.keeper.cdc.MustMarshal(&contractInfo)
store.Set(iter.Key(), newContractInfoBz)
}

// get v1 contract key
Expand Down

0 comments on commit fa056ad

Please sign in to comment.