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:
parent
d1b6512954
commit
124307140d
|
@ -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,
|
||||||
|
|
|
@ -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")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue