Skip to content

Commit

Permalink
Minor simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Oct 25, 2024
1 parent cca223a commit 9da3136
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions eth/tracers/native/zero.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,22 @@ func (t *zeroTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcom
}
}

receiverTxTrace := t.tx.Traces[to]
senderTxTrace := t.tx.Traces[from]

// The recipient balance includes the value transferred.
toBal := new(big.Int).Sub(t.tx.Traces[to].Balance.ToBig(), value.ToBig())
t.tx.Traces[to].Balance = uint256.MustFromBig(toBal)
toBal := new(big.Int).Sub(receiverTxTrace.Balance.ToBig(), value.ToBig())
receiverTxTrace.Balance = uint256.MustFromBig(toBal)

// The sender balance is after reducing: value and gasLimit.
// We need to re-add them to get the pre-tx balance.
fromBal := new(big.Int).Set(t.tx.Traces[from].Balance.ToBig())
fromBal := new(big.Int).Set(senderTxTrace.Balance.ToBig())
gasPrice := env.TxContext.GasPrice
consumedGas := new(big.Int).Mul(gasPrice.ToBig(), new(big.Int).SetUint64(t.gasLimit))
fromBal.Add(fromBal, new(big.Int).Add(value.ToBig(), consumedGas))
t.tx.Traces[from].Balance = uint256.MustFromBig(fromBal)
if t.tx.Traces[from].Nonce.Cmp(uint256.NewInt(0)) > 0 {
t.tx.Traces[from].Nonce.Sub(t.tx.Traces[from].Nonce, uint256.NewInt(1))
senderTxTrace.Balance = uint256.MustFromBig(fromBal)
if senderTxTrace.Nonce.Cmp(uint256.NewInt(0)) > 0 {
senderTxTrace.Nonce.Sub(senderTxTrace.Nonce, uint256.NewInt(1))
}
}

Expand Down Expand Up @@ -325,10 +328,7 @@ func (t *zeroTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
// GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`).
func (t *zeroTracer) GetResult() (json.RawMessage, error) {
var res []byte
var err error
res, err = json.Marshal(t.tx)

res, err := json.Marshal(t.tx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9da3136

Please sign in to comment.