Skip to content

Commit 7270603

Browse files
committed
Add ContractAddress to stored receipt fields for arb txs
1 parent 01cc043 commit 7270603

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

core/state_processor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/ethereum/go-ethereum/core/state"
2727
"github.com/ethereum/go-ethereum/core/types"
2828
"github.com/ethereum/go-ethereum/core/vm"
29-
"github.com/ethereum/go-ethereum/crypto"
3029
"github.com/ethereum/go-ethereum/params"
3130
)
3231

@@ -131,8 +130,8 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, author *com
131130
receipt.GasUsed = result.UsedGas
132131

133132
// If the transaction created a contract, store the creation address in the receipt.
134-
if msg.To() == nil {
135-
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
133+
if result.TopLevelDeployed != nil {
134+
receipt.ContractAddress = *result.TopLevelDeployed
136135
}
137136

138137
// Set the receipt logs and create the bloom filter.

core/state_transition.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ type ExecutionResult struct {
9191
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
9292

9393
// Arbitrum: a tx may yield others that need to run afterward (see retryables)
94-
ScheduledTxes types.Transactions
94+
ScheduledTxes types.Transactions
95+
TopLevelDeployed *common.Address
9596
}
9697

9798
// Unwrap returns the internal evm error which allows us for further
@@ -360,12 +361,14 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
360361
if rules.IsBerlin {
361362
st.state.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
362363
}
364+
var deployedContract *common.Address
363365
var (
364366
ret []byte
365367
vmerr error // vm errors do not effect consensus and are therefore not assigned to err
366368
)
367369
if contractCreation {
368-
ret, _, st.gas, vmerr = st.evm.Create(sender, st.data, st.gas, st.value)
370+
deployedContract = &common.Address{}
371+
ret, *deployedContract, st.gas, vmerr = st.evm.Create(sender, st.data, st.gas, st.value)
369372
} else {
370373
// Increment the nonce for the next transaction
371374
st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
@@ -410,10 +413,11 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
410413
}
411414

412415
return &ExecutionResult{
413-
UsedGas: st.gasUsed(),
414-
Err: vmerr,
415-
ReturnData: ret,
416-
ScheduledTxes: st.evm.ProcessingHook.ScheduledTxes(),
416+
UsedGas: st.gasUsed(),
417+
Err: vmerr,
418+
ReturnData: ret,
419+
ScheduledTxes: st.evm.ProcessingHook.ScheduledTxes(),
420+
TopLevelDeployed: deployedContract,
417421
}, nil
418422
}
419423

core/types/receipt.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type storedReceiptRLP struct {
102102
CumulativeGasUsed uint64
103103
L1GasUsed uint64
104104
Logs []*LogForStorage
105+
ContractAddress *common.Address `rlp:"optional"` // set on new versions if an Arbitrum tx type
105106
}
106107

107108
type arbLegacyStoredReceiptRLP struct {
@@ -313,6 +314,9 @@ func (r *ReceiptForStorage) EncodeRLP(_w io.Writer) error {
313314
}
314315
}
315316
w.ListEnd(logList)
317+
if r.Type >= ArbitrumDepositTxType && r.Type != ArbitrumLegacyTxType && r.ContractAddress != (common.Address{}) {
318+
w.WriteBytes(r.ContractAddress[:])
319+
}
316320
w.ListEnd(outerList)
317321
return w.Flush()
318322
}
@@ -379,6 +383,9 @@ func decodeStoredReceiptRLP(r *ReceiptForStorage, blob []byte) error {
379383
r.Logs[i] = (*Log)(log)
380384
}
381385
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
386+
if stored.ContractAddress != nil {
387+
r.ContractAddress = *stored.ContractAddress
388+
}
382389

383390
return nil
384391
}
@@ -464,7 +471,7 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, nu
464471

465472
if rs[i].Type != ArbitrumLegacyTxType {
466473
// The contract address can be derived from the transaction itself
467-
if txs[i].To() == nil {
474+
if txs[i].To() == nil && rs[i].ContractAddress == (common.Address{}) {
468475
// Deriving the signer is expensive, only do if it's actually needed
469476
from, _ := Sender(signer, txs[i])
470477
rs[i].ContractAddress = crypto.CreateAddress(from, txs[i].Nonce())

0 commit comments

Comments
 (0)