Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: disallow same sender tx appear in the same tx after contract #566

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#558](https://github.com/crypto-org-chain/ethermint/pull/558) New tracer in predecessors to trace balance correctly when `debug_traceTransaction`.
* (rpc) [#559](https://github.com/crypto-org-chain/ethermint/pull/559) Use basefee of transaction height instead of minus one height when `debug_traceTransaction`.
* (rpc) [#562](https://github.com/crypto-org-chain/ethermint/pull/562) Fix nil pointer panic with legacy transaction format.
* (ante) [#566](https://github.com/crypto-org-chain/ethermint/pull/566) Disallow same sender tx appear after contract creation in the same batch tx.

### Improvements

Expand Down
35 changes: 35 additions & 0 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,38 @@ func CheckAndSetEthSenderNonce(

return nil
}

// DetectContractCreationBatchTx returns error if same same transaction appear after contract creation tx in the same
yihuang marked this conversation as resolved.
Show resolved Hide resolved
// batch
func DetectContractCreationBatchTx(ctx sdk.Context, tx sdk.Tx) error {
if !ctx.IsCheckTx() {
// only check in mempool logic
return nil
}

if len(tx.GetMsgs()) <= 1 {
return nil
}

senders := make(map[string]struct{})
for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

sender := string(msgEthTx.GetSender().Bytes())
if _, ok := senders[sender]; ok {
return errorsmod.Wrapf(
errortypes.ErrInvalidRequest,
"same sender included after contract creation in the batch transaction",
)
}

if msgEthTx.AsTransaction().To() == nil {
mmsqe marked this conversation as resolved.
Show resolved Hide resolved
senders[sender] = struct{}{}
}
}

return nil
}
5 changes: 5 additions & 0 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
return ctx, err
}

// reject contract creation tx in batch tx
if err := DetectContractCreationBatchTx(ctx, tx); err != nil {
return ctx, err
}

extraDecorators := options.ExtraDecorators
if options.PendingTxListener != nil {
extraDecorators = append(extraDecorators, newTxListenerDecorator(options.PendingTxListener))
Expand Down