Users can DOS the token deposits for any future bridges
The InitiateTokenDeposit function did not verify that the provided bridge ID existed, allowing a user to deposit to a non-existent bridge and increment its L1 sequence. This could cause future deposits to that bridge to be rejected on L2 due to a sequence mismatch, potentially blocking deposits.
Users can create a bridge on L1 that points to L2 chains, which allows them to transfer funds between the 2 chains. When creating a bridge an incremental ID is generated for that bridge, and saved. To deposit coins to an L2, users have to call InitiateTokenDeposit on the L1.
This sequence gets attached to the L2 message, when FinalizeTokenDeposit gets called, and gets validated on the L2, to ensure that messages are in order.
finalizedL1Sequence, err := ms.GetNextL1Sequence(ctx)
if err != nil {
return nil, err
}
if req.Sequence < finalizedL1Sequence {
// No op instead of returning an error
return &types.MsgFinalizeTokenDepositResponse{Result: types.NOOP}, nil
} else if req.Sequence > finalizedL1Sequence {
return nil, types.ErrInvalidSequence
}
This is all good for now. However, the issue is that the InitiateTokenDeposit function doesn’t check if the provided input bridge ID is created before processing the message.
This allows a malicious user to initial a deposit on a non-existent bridge ID, which increments the l1Sequence to 2, the deposit sequence will be 1. This message won’t be processed and sent to the L2, because simply the bridge/L2 doesn’t exist.
Later, when a L2 and a bridge are created for that bridge ID (remember it’s incremental), any deposits initiated from the L1 will fail, because the sequence number will be > 1. On L2, finalizedL1Sequence will be 1, which forces the following validation to fail:
Thanks for your finding! I have looked your descriptions and seems the problem exists, but the effect is not that serious actually.
In your report,
any deposits initiated from the L1 will fail, because the sequence number will be > 1. On L2, finalizedL1Sequence will be 1, which forces the following validation to fail:
but, actually, all these deposits still can be relayed. L1 sequence is increased before create bridge, but still bridge bot can relay it in sequence order and on l2 the sequence will be increased in order without problem.
@beer-1 - the message would be relayed with the wrong L1 sequence. The following is a scenario on the host chain. This is where a malicious actor performs a deposit on a non-existent bridge, which increases the next L1 sequence of that bridge to 2, then when the bridge is created and a legitimate deposit is done, it will have an L2 sequence of 2.
func Test_InitiateTokenDeposit_NonExistBridge(t *testing.T) {
ctx, input := createDefaultTestInput(t)
ms := keeper.NewMsgServerImpl(input.OPHostKeeper)
config := types.BridgeConfig{
Proposer: addrsStr[0],
Challenger: addrsStr[1],
SubmissionInterval: time.Second * 10,
FinalizationPeriod: time.Second * 60,
SubmissionStartHeight: 1,
Metadata: []byte{1, 2, 3},
BatchInfo: types.BatchInfo{Submitter: addrsStr[0], ChainType: types.BatchInfo_INITIA},
}
createRes, err := ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config))
require.NoError(t, err)
require.Equal(t, uint64(1), createRes.BridgeId) // Bridge with ID 1 is created
// @audit => "Malicious" deposit to increase the L1 sequence
amount := sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))
input.Faucet.Fund(ctx, addrs[1], amount)
_, err = ms.InitiateTokenDeposit(
ctx,
types.NewMsgInitiateTokenDeposit(addrsStr[1], 2, "l2_addr", amount, []byte("messages")), // Deposit to non-exist bridge, ID 100
)
require.NoError(t, err)
require.True(t, input.BankKeeper.GetBalance(ctx, addrs[1], sdk.DefaultBondDenom).IsZero())
// Bridge with ID 2 that doesn't exist, holds some amount
require.Equal(t, amount, input.BankKeeper.GetBalance(ctx, types.BridgeAddress(2), sdk.DefaultBondDenom))
// @audit => Create the bridge with ID 2
createRes, err = ms.CreateBridge(ctx, types.NewMsgCreateBridge(addrsStr[0], config))
require.NoError(t, err)
require.Equal(t, uint64(2), createRes.BridgeId) // Bridge with ID 2 is created
// @audit => Legitimate deposit to the bridge
amount = sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))
input.Faucet.Fund(ctx, addrs[1], amount)
depositRes, err := ms.InitiateTokenDeposit(
ctx,
types.NewMsgInitiateTokenDeposit(addrsStr[1], 2, "l2_addr", amount, []byte("messages")),
)
require.NoError(t, err)
// @audit => The L1 sequence should be 2
require.Equal(t, uint64(2), depositRes.Sequence)
}
The executor won’t relay the malicious deposit (which makes sense, as the bridge didn’t even exist at that point). However, it will relay the legitimate deposit, but while passing the L1 sequence as 2 (which is emitted in the legitimate deposit on the host) here.
On the child side, the following will be run and reverted because of this, where finalizedL1Sequence = 1 and req.Sequence = 2:
We believe that this situation would be only temporary because the executor has disable_auto_set_l1_height and l1_start_height settings which can be set by the admin operating the executor (executor.go#L207C1-L209C11) to include early deposit messages if any:
File: executor.go
205: if ex.host.Node().GetSyncedHeight() == 0 {
206: // use l1 start height from the config if auto set is disabled
207: if ex.cfg.DisableAutoSetL1Height {
208: l1StartHeight = ex.cfg.L1StartHeight
209: } else {
Once this is done, nothing prevents early messages from being processed, then unblocking the bridge.
The above comment is invalid; we can see that the returned l1StartHeight from the attached function getNodeStartHeights will only be used when initializing the node. You can follow that variable drilling, and we’ll see that it is only being used here and is set as the synced height, this has nothing to do with the L1 sequence.
For clearer evidence, you can simply look at deposit which “catches” deposit messages from the host; which builds the finalize token deposit message. It is using the sequence emitted from the host events. In other words, the only source of truth of L2’s L1 sequence is the host’s sequence, which is messed up because of what’s mentioned in this report.
As a result, no this is not temporary, because setting the L1 start height for the executor has nothing to do with the L1 sequence.
This finding’s impact (bridge dos) is based on the fact that a “L1 sequence = 2” deposit cannot be processed before the “L1 sequence = 1” deposit.
My comment above shows how the “L1 sequence = 1” can be correctly processed despite being submitted before bridge creation; hence, mitigating the impact from a “permanent” loss to a “temporary” loss that can be mitigated by configuration.
The impact, while real, can be mitigated reasonably easily, so high risk is a stretch.
The original report as published on Code4rena, by 0xAlix2. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
Deposits to future bridges could be blocked because their sequence numbers would be higher than expected, though the text notes this may be temporary if the executor is configured to process early messages.
What the attacker needed
Ability to call InitiateTokenDeposit; a bridge ID that does not yet exist
The fix
The fix was to add a check that the bridge ID is less than the next bridge ID before processing the deposit.
How it was found
Create a bridge with ID 1.
Call InitiateTokenDeposit with a non-existent bridge ID (e.g., 100), which succeeds and increments that bridge's L1 sequence.
Later create a bridge with that ID (e.g., 2) and make a legitimate deposit, which gets sequence 2.
The executor relays the legitimate deposit with sequence 2, but on L2 the finalizedL1Sequence is 1, so the deposit is rejected.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A bridge lets you move funds between two blockchains. Each deposit gets a number (sequence) that must be processed in order. The bug let someone send a deposit to a bridge that didn't exist yet, which used up the first number. Later, real deposits started at number two, but the other chain expected number one, so it rejected them.
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.