Skip to content

Commit

Permalink
Merge pull request #5 from ethereum-optimism/height-check
Browse files Browse the repository at this point in the history
core: deposit txs block height check in block body validation
  • Loading branch information
protolambda committed Sep 6, 2022
1 parent 357290d commit a0b7861
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
return fmt.Errorf("uncle root hash mismatch: have %x, want %x", hash, header.UncleHash)
}
// deposits included their positional information for tx-hashing purposes.
// height := block.NumberU64()
height := block.NumberU64()
for i, tx := range block.Transactions() {
if tx.Type() == types.DepositTxType {
// TODO: Deposit Tx includes the height of the L1 block, not the L2 block
// if tx.BlockHeight() != height {
// return fmt.Errorf("deposit included in block with wrong block height: %d, expected %d", tx.BlockHeight(), height)
// }
if tx.BlockHeight() != height {
return fmt.Errorf("deposit included in block with wrong block height: %d, expected %d", tx.BlockHeight(), height)
}
if tx.TransactionIndex() != uint64(i) {
return fmt.Errorf("deposit included in block at wrong index: %d, expected %d", tx.TransactionIndex(), i)
}
Expand Down
6 changes: 6 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,26 @@ func (tx *Transaction) To() *common.Address {
return copyAddressPtr(tx.inner.to())
}

// BlockHeight returns the L2 block height encoded in the deposit tx.
// This returns 0 if this is not a deposit tx.
func (tx *Transaction) BlockHeight() uint64 {
if dep, ok := tx.inner.(*DepositTx); ok {
return dep.BlockHeight
}
return 0
}

// TransactionIndex returns the tx index encoded in the deposit tx.
// This returns 0 if this is not a deposit tx.
func (tx *Transaction) TransactionIndex() uint64 {
if dep, ok := tx.inner.(*DepositTx); ok {
return dep.TransactionIndex
}
return 0
}

// Mint returns the ETH to mint in the deposit tx.
// This returns nil if there is nothing to mint, or if this is not a deposit tx.
func (tx *Transaction) Mint() *big.Int {
if dep, ok := tx.inner.(*DepositTx); ok {
return dep.Mint
Expand Down

0 comments on commit a0b7861

Please sign in to comment.