From 18e45a9d93f0e9283a04f2113176a0301bf533c2 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Wed, 6 Nov 2024 11:41:41 +0900 Subject: [PATCH 1/2] introduce hook max gas --- proto/opinit/opchild/v1/types.proto | 2 + x/opchild/keeper/deposit.go | 15 ++- x/opchild/keeper/msg_server.go | 7 +- x/opchild/keeper/msg_server_test.go | 58 ++++++++++ x/opchild/types/params.go | 5 +- x/opchild/types/types.pb.go | 170 +++++++++++++++++----------- 6 files changed, 186 insertions(+), 71 deletions(-) diff --git a/proto/opinit/opchild/v1/types.proto b/proto/opinit/opchild/v1/types.proto index 94ba8cd7..103440c1 100644 --- a/proto/opinit/opchild/v1/types.proto +++ b/proto/opinit/opchild/v1/types.proto @@ -47,6 +47,8 @@ message Params { (amino.dont_omitempty) = true, (gogoproto.moretags) = "yaml:\"fee_whitelist\"" ]; + // Max gas for hook execution of `MsgFinalizeTokenDeposit` + uint64 hook_max_gas = 7 [(gogoproto.moretags) = "yaml:\"hook_max_gas\""]; } // Validator defines a validator, together with the total amount of the diff --git a/x/opchild/keeper/deposit.go b/x/opchild/keeper/deposit.go index b313005f..e4433ccd 100644 --- a/x/opchild/keeper/deposit.go +++ b/x/opchild/keeper/deposit.go @@ -4,11 +4,19 @@ import ( "context" "fmt" + storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/initia-labs/OPinit/x/opchild/types" ) -func (k Keeper) handleBridgeHook(ctx sdk.Context, data []byte) (success bool, reason string) { +func (k Keeper) handleBridgeHook(ctx sdk.Context, data []byte, hookMaxGas uint64) (success bool, reason string) { + originGasMeter := ctx.GasMeter() + gasForHook := originGasMeter.GasRemaining() + if gasForHook > hookMaxGas { + gasForHook = hookMaxGas + } + defer func() { if r := recover(); r != nil { reason = fmt.Sprintf("panic: %v", r) @@ -18,8 +26,13 @@ func (k Keeper) handleBridgeHook(ctx sdk.Context, data []byte) (success bool, re if len(reason) > maxReasonLength { reason = reason[:maxReasonLength] + "..." } + + originGasMeter.ConsumeGas(ctx.GasMeter().GasConsumedToLimit(), "bridge hook") }() + // use new gas meter with the hook max gas limit + ctx = ctx.WithGasMeter(storetypes.NewGasMeter(gasForHook)) + tx, err := k.txDecoder(data) if err != nil { reason = fmt.Sprintf("Failed to decode tx: %s", err) diff --git a/x/opchild/keeper/msg_server.go b/x/opchild/keeper/msg_server.go index 4d44d372..b220a5b8 100644 --- a/x/opchild/keeper/msg_server.go +++ b/x/opchild/keeper/msg_server.go @@ -436,10 +436,15 @@ func (ms MsgServer) FinalizeTokenDeposit(ctx context.Context, req *types.MsgFina sdk.NewAttribute(types.AttributeKeyFinalizeHeight, strconv.FormatUint(req.Height, 10)), ) + params, err := ms.GetParams(ctx) + if err != nil { + return nil, err + } + // if the deposit is successful and the data is not empty, execute the hook hookSuccess := true if depositSuccess && len(req.Data) > 0 { - hookSuccess, reason = ms.handleBridgeHook(sdkCtx, req.Data) + hookSuccess, reason = ms.handleBridgeHook(sdkCtx, req.Data, params.HookMaxGas) event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeySuccess, strconv.FormatBool(hookSuccess))) if !hookSuccess { event = event.AppendAttributes(sdk.NewAttribute(types.AttributeKeyReason, "hook failed; "+reason)) diff --git a/x/opchild/keeper/msg_server_test.go b/x/opchild/keeper/msg_server_test.go index 3d616e1c..81376762 100644 --- a/x/opchild/keeper/msg_server_test.go +++ b/x/opchild/keeper/msg_server_test.go @@ -9,6 +9,7 @@ import ( "time" "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" testutilsims "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" @@ -559,6 +560,63 @@ func Test_MsgServer_Deposit_HookFail(t *testing.T) { require.Equal(t, math.NewInt(0), afterBalance.Amount) } +func Test_MsgServer_Deposit_HookFail_WithOutOfGas(t *testing.T) { + ctx, input := createDefaultTestInput(t) + ms := keeper.NewMsgServerImpl(&input.OPChildKeeper) + + bz := sha3.Sum256([]byte("test_token")) + denom := "l2/" + hex.EncodeToString(bz[:]) + + require.Equal(t, math.ZeroInt(), input.BankKeeper.GetBalance(ctx, addrs[1], denom).Amount) + + // empty deposit to create account + priv, _, addr := keyPubAddr() + msg := types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addr.String(), sdk.NewCoin(denom, math.ZeroInt()), 1, 1, "test_token", nil) + _, err := ms.FinalizeTokenDeposit(ctx, msg) + require.NoError(t, err) + + // create hook data + acc := input.AccountKeeper.GetAccount(ctx, addr) + require.NotNil(t, acc) + privs, accNums, accSeqs := []cryptotypes.PrivKey{priv}, []uint64{acc.GetAccountNumber()}, []uint64{0} + signedTxBz, err := input.EncodingConfig.TxConfig.TxEncoder()(generateTestTx( + t, input, + []sdk.Msg{banktypes.NewMsgSend(addr, addrs[2], sdk.NewCoins(sdk.NewCoin(denom, math.NewInt(100))))}, + privs, accNums, accSeqs, sdk.UnwrapSDKContext(ctx).ChainID(), + )) + require.NoError(t, err) + + params, err := input.OPChildKeeper.GetParams(ctx) + require.NoError(t, err) + + params.HookMaxGas = 1 + input.OPChildKeeper.SetParams(ctx, params) + + // valid deposit + ctx = sdk.UnwrapSDKContext(ctx).WithEventManager(sdk.NewEventManager()).WithGasMeter(storetypes.NewGasMeter(2_000_000)) + msg = types.NewMsgFinalizeTokenDeposit(addrsStr[0], addrsStr[1], addr.String(), sdk.NewCoin(denom, math.NewInt(100)), 2, 1, "test_token", signedTxBz) + _, err = ms.FinalizeTokenDeposit(ctx, msg) + require.NoError(t, err) + + for _, event := range sdk.UnwrapSDKContext(ctx).EventManager().Events() { + if event.Type == types.EventTypeFinalizeTokenDeposit { + attrIdx := slices.Index(event.Attributes, sdk.NewAttribute(types.AttributeKeySuccess, "false").ToKVPair()) + require.Positive(t, attrIdx) + require.Equal(t, event.Attributes[attrIdx+1].Key, types.AttributeKeyReason) + require.Contains(t, event.Attributes[attrIdx+1].Value, "hook failed;") + require.Contains(t, event.Attributes[attrIdx+1].Value, "panic:") + } + } + + // check addrs[2] balance + afterBalance := input.BankKeeper.GetBalance(ctx, addrs[2], denom) + require.Equal(t, math.NewInt(0), afterBalance.Amount) + + // check receiver has no balance + afterBalance = input.BankKeeper.GetBalance(ctx, addr, denom) + require.Equal(t, math.NewInt(0), afterBalance.Amount) +} + func Test_MsgServer_UpdateOracle(t *testing.T) { ctx, input := createDefaultTestInput(t) opchildKeeper := input.OPChildKeeper diff --git a/x/opchild/types/params.go b/x/opchild/types/params.go index fbf3fd59..c8b2d85c 100644 --- a/x/opchild/types/params.go +++ b/x/opchild/types/params.go @@ -10,6 +10,7 @@ import ( var ( DefaultMinGasPrices = sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyNewDecWithPrec(15, 2))) // 0.15 + DefaultHookMaxGas = uint64(1_000_000) ) // DefaultParams returns default move parameters @@ -21,11 +22,12 @@ func DefaultParams() Params { DefaultHistoricalEntries, DefaultMinGasPrices, []string{}, + DefaultHookMaxGas, ) } // NewParams creates a new Params instance -func NewParams(admin string, bridgeExecutors []string, maxValidators, historicalEntries uint32, minGasPrice sdk.DecCoins, feeWhitelist []string) Params { +func NewParams(admin string, bridgeExecutors []string, maxValidators, historicalEntries uint32, minGasPrice sdk.DecCoins, feeWhitelist []string, hookMaxGas uint64) Params { return Params{ Admin: admin, BridgeExecutors: bridgeExecutors, @@ -33,6 +35,7 @@ func NewParams(admin string, bridgeExecutors []string, maxValidators, historical HistoricalEntries: historicalEntries, MinGasPrices: minGasPrice, FeeWhitelist: feeWhitelist, + HookMaxGas: hookMaxGas, } } diff --git a/x/opchild/types/types.pb.go b/x/opchild/types/types.pb.go index f5d8d0c7..7663ac9e 100644 --- a/x/opchild/types/types.pb.go +++ b/x/opchild/types/types.pb.go @@ -76,6 +76,8 @@ type Params struct { Admin string `protobuf:"bytes,5,opt,name=admin,proto3" json:"admin,omitempty" yaml:"admin"` // the list of addresses that are allowed to pay zero fee. FeeWhitelist []string `protobuf:"bytes,6,rep,name=fee_whitelist,json=feeWhitelist,proto3" json:"fee_whitelist,omitempty" yaml:"fee_whitelist"` + // Max gas for hook execution of `MsgFinalizeTokenDeposit` + HookMaxGas uint64 `protobuf:"varint,7,opt,name=hook_max_gas,json=hookMaxGas,proto3" json:"hook_max_gas,omitempty" yaml:"hook_max_gas"` } func (m *Params) Reset() { *m = Params{} } @@ -338,75 +340,77 @@ func init() { func init() { proto.RegisterFile("opinit/opchild/v1/types.proto", fileDescriptor_2cc6df244b706d68) } var fileDescriptor_2cc6df244b706d68 = []byte{ - // 1075 bytes of a gzipped FileDescriptorProto + // 1110 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xbf, 0x6f, 0xdb, 0xc6, - 0x17, 0x17, 0x6d, 0x39, 0x89, 0x4e, 0xb2, 0x2d, 0x1f, 0x1c, 0x7c, 0x65, 0x39, 0x21, 0x09, 0x2e, - 0x5f, 0xc1, 0xad, 0x48, 0xc8, 0xa9, 0x81, 0xd6, 0x53, 0x22, 0x59, 0x29, 0x84, 0x04, 0xb6, 0x40, - 0xd9, 0x0d, 0x9a, 0x85, 0xa0, 0xc8, 0x93, 0x74, 0x30, 0xc9, 0x23, 0x78, 0x94, 0x62, 0xfd, 0x07, - 0x81, 0x97, 0x76, 0xec, 0x62, 0xc0, 0x40, 0x97, 0x34, 0x53, 0x86, 0x6e, 0xfd, 0x07, 0x8c, 0x02, - 0x05, 0x82, 0x4e, 0x9d, 0x94, 0xd6, 0x1e, 0xd2, 0x59, 0x43, 0xe7, 0xe2, 0xee, 0xa8, 0x1f, 0x71, - 0x5d, 0xa4, 0x8b, 0x7d, 0xef, 0x7d, 0x3e, 0xef, 0xdd, 0xd3, 0xe7, 0xde, 0x7b, 0x04, 0xf7, 0x49, - 0x88, 0x03, 0x1c, 0x1b, 0x24, 0x74, 0x7a, 0xd8, 0x73,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, 0x5d, 0xc9, 0xa9, 0xe7, 0xe5, 0x39, 0x15, 0xd9, 0x43, 0x62, - 0xbb, 0xec, 0xd9, 0x6d, 0x6a, 0x1c, 0x34, 0xf9, 0x17, 0xec, 0x64, 0xfa, 0xd1, 0xe5, 0x82, 0xb6, - 0x6f, 0xf1, 0x41, 0x7d, 0xf0, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x78, 0x6c, 0x3d, 0xf1, 0x93, - 0x07, 0x00, 0x00, + 0x17, 0x17, 0x6d, 0x39, 0x8e, 0x4e, 0xb2, 0x2d, 0xdf, 0xd7, 0x41, 0x64, 0x39, 0x21, 0x09, 0x2e, + 0x5f, 0x21, 0xad, 0x49, 0x28, 0x69, 0x80, 0xc6, 0x53, 0x42, 0x45, 0x09, 0x8c, 0xa4, 0xb6, 0x40, + 0xc5, 0x0d, 0x9a, 0x85, 0x38, 0x91, 0x67, 0xe9, 0x60, 0x92, 0x47, 0xf0, 0x28, 0xc5, 0xfa, 0x0f, + 0x02, 0x2f, 0xed, 0xd8, 0x25, 0x40, 0x80, 0x2e, 0x69, 0xa6, 0x0c, 0xdd, 0xfa, 0x0f, 0x04, 0x9d, + 0x82, 0x4e, 0x9d, 0x94, 0xd6, 0x19, 0xd2, 0x59, 0x43, 0xe7, 0xe2, 0xee, 0xa8, 0x1f, 0x71, 0x5d, + 0xa4, 0x8b, 0x74, 0xef, 0x7d, 0x3e, 0xef, 0xdd, 0xdd, 0xe7, 0xde, 0x7b, 0x04, 0x57, 0x69, 0x4c, + 0x22, 0x92, 0x5a, 0x34, 0xf6, 0x7a, 0x24, 0xf0, 0xad, 0x41, 0xdd, 0x4a, 0x87, 0x31, 0x66, 0x66, + 0x9c, 0xd0, 0x94, 0xc2, 0x75, 0x09, 0x9b, 0x19, 0x6c, 0x0e, 0xea, 0xd5, 0x75, 0x14, 0x92, 0x88, + 0x5a, 0xe2, 0x57, 0xb2, 0xaa, 0xaa, 0x47, 0x59, 0x48, 0x99, 0xd5, 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xe6, 0x7e, 0x7b, 0xaf, 0xe6, 0x9e, 0x6c, 0xcf, 0xa9, + 0xc8, 0x1f, 0x92, 0xa0, 0xed, 0x00, 0x75, 0x98, 0xb5, 0xdf, 0x12, 0x1f, 0xbf, 0xe3, 0xe9, 0xf7, + 0x5a, 0x08, 0xda, 0xb9, 0x20, 0x1a, 0xf5, 0xc6, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4a, 0x69, + 0x76, 0x1a, 0xce, 0x07, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -461,6 +465,9 @@ func (this *Params) Equal(that interface{}) bool { return false } } + if this.HookMaxGas != that1.HookMaxGas { + return false + } return true } func (this *BridgeInfo) Equal(that interface{}) bool { @@ -575,6 +582,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.HookMaxGas != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.HookMaxGas)) + i-- + dAtA[i] = 0x38 + } if len(m.FeeWhitelist) > 0 { for iNdEx := len(m.FeeWhitelist) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.FeeWhitelist[iNdEx]) @@ -896,6 +908,9 @@ func (m *Params) Size() (n int) { n += 1 + l + sovTypes(uint64(l)) } } + if m.HookMaxGas != 0 { + n += 1 + sovTypes(uint64(m.HookMaxGas)) + } return n } @@ -1199,6 +1214,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.FeeWhitelist = append(m.FeeWhitelist, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HookMaxGas", wireType) + } + m.HookMaxGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HookMaxGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) From cbb75b7b8d48aa06e5c02337f089e558ac4166ae Mon Sep 17 00:00:00 2001 From: beer-1 Date: Wed, 6 Nov 2024 13:17:00 +0900 Subject: [PATCH 2/2] return bridge hook early if max gas is zero --- x/opchild/keeper/deposit.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/opchild/keeper/deposit.go b/x/opchild/keeper/deposit.go index e4433ccd..bb79e29d 100644 --- a/x/opchild/keeper/deposit.go +++ b/x/opchild/keeper/deposit.go @@ -11,6 +11,10 @@ import ( ) func (k Keeper) handleBridgeHook(ctx sdk.Context, data []byte, hookMaxGas uint64) (success bool, reason string) { + if hookMaxGas == 0 { + return false, "hook max gas is zero" + } + originGasMeter := ctx.GasMeter() gasForHook := originGasMeter.GasRemaining() if gasForHook > hookMaxGas {