wormchain: tokenbridge: Don't change registered decimals

Don't allow an AssetMeta payload to change the decimals of a registered
asset as this would cause issues with any unredeemed token transfers.
This commit is contained in:
Chirantan Ekbote 2022-08-25 17:46:01 +09:00 committed by Chirantan Ekbote
parent d1b6512954
commit 124307140d
2 changed files with 16 additions and 2 deletions

View File

@ -196,16 +196,29 @@ func (k msgServer) ExecuteVAA(goCtx context.Context, msg *types.MsgExecuteVAA) (
} }
identifier := types.GetWrappedCoinIdentifier(tokenChain, tokenAddress) identifier := types.GetWrappedCoinIdentifier(tokenChain, tokenAddress)
baseDenom := "b" + identifier
rollBackProtection, found := k.GetCoinMetaRollbackProtection(ctx, identifier) rollBackProtection, found := k.GetCoinMetaRollbackProtection(ctx, identifier)
if found && rollBackProtection.LastUpdateSequence >= v.Sequence { if found && rollBackProtection.LastUpdateSequence >= v.Sequence {
return nil, types.ErrAssetMetaRollback return nil, types.ErrAssetMetaRollback
} }
if meta, found := k.bankKeeper.GetDenomMetaData(ctx, baseDenom); found {
if meta.Display != identifier {
return nil, fmt.Errorf("mis-matched display denom; %s != %s", meta.Display, identifier)
}
for _, d := range meta.DenomUnits {
if d.Denom == identifier && d.Exponent != uint32(decimals) {
return nil, types.ErrChangeDecimals
}
}
}
k.bankKeeper.SetDenomMetaData(ctx, btypes.Metadata{ k.bankKeeper.SetDenomMetaData(ctx, btypes.Metadata{
Description: fmt.Sprintf("Wormhole wrapped asset from chain %d with address %x", tokenChain, tokenAddress), Description: fmt.Sprintf("Wormhole wrapped asset from chain %d with address %x", tokenChain, tokenAddress),
DenomUnits: []*btypes.DenomUnit{ DenomUnits: []*btypes.DenomUnit{
{ {
Denom: "b" + identifier, Denom: baseDenom,
Exponent: 0, Exponent: 0,
}, },
{ {
@ -213,7 +226,7 @@ func (k msgServer) ExecuteVAA(goCtx context.Context, msg *types.MsgExecuteVAA) (
Exponent: uint32(decimals), Exponent: uint32(decimals),
}, },
}, },
Base: "b" + identifier, Base: baseDenom,
Display: identifier, Display: identifier,
Name: name, Name: name,
Symbol: symbol, Symbol: symbol,

View File

@ -36,5 +36,6 @@ var (
ErrAssetMetaRollback = sdkerrors.Register(ModuleName, 1134, "asset meta must have a higher sequence than the last update") ErrAssetMetaRollback = sdkerrors.Register(ModuleName, 1134, "asset meta must have a higher sequence than the last update")
ErrNegativeFee = sdkerrors.Register(ModuleName, 1135, "fee cannot be negative") ErrNegativeFee = sdkerrors.Register(ModuleName, 1135, "fee cannot be negative")
ErrRegisterWormholeChain = sdkerrors.Register(ModuleName, 1136, "cannot register an emitter for wormhole-chain on wormhole-chain") ErrRegisterWormholeChain = sdkerrors.Register(ModuleName, 1136, "cannot register an emitter for wormhole-chain on wormhole-chain")
ErrChangeDecimals = sdkerrors.Register(ModuleName, 1137, "cannot change decimals of registered asset metadata")
ErrUnregisteredChain = sdkerrors.Register(ModuleName, 1138, "chain is not registered") ErrUnregisteredChain = sdkerrors.Register(ModuleName, 1138, "chain is not registered")
) )