Skip to content

Commit

Permalink
fix(trace): use string for big.Int (ethereum#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop authored Apr 1, 2022
1 parent 2329d32 commit 33fcd2b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ func (bc *BlockChain) writeBlockResult(state *state.StateDB, block *types.Block,
coinbase := types.AccountProofWrapper{
Address: block.Coinbase(),
Nonce: state.GetNonce(block.Coinbase()),
Balance: state.GetBalance(block.Coinbase()),
Balance: state.GetBalance(block.Coinbase()).String(),
CodeHash: state.GetCodeHash(block.Coinbase()),
}
// Get coinbase address's account proof.
Expand Down
4 changes: 1 addition & 3 deletions core/types/l2trace.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package types

import (
"math/big"

"github.com/scroll-tech/go-ethereum/common"
)

Expand Down Expand Up @@ -59,7 +57,7 @@ type ExtraData struct {
type AccountProofWrapper struct {
Address common.Address `json:"address"`
Nonce uint64 `json:"nonce"`
Balance *big.Int `json:"balance"`
Balance string `json:"balance"` // balance big.Int string
CodeHash common.Hash `json:"codeHash,omitempty"`
Proof []string `json:"proof,omitempty"`
Storage *StorageProofWrapper `json:"storage,omitempty"` // StorageProofWrapper can be empty if irrelated to storage operation
Expand Down
36 changes: 18 additions & 18 deletions core/types/l2trace_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

type BlockTrace struct {
Number *big.Int `json:"number"`
Number string `json:"number"` // big.Int string
Hash common.Hash `json:"hash"`
GasLimit uint64 `json:"gasLimit"`
Difficulty *big.Int `json:"difficulty"`
BaseFee *big.Int `json:"baseFee"`
Difficulty string `json:"difficulty"` // big.Int string
BaseFee string `json:"baseFee"` // big.Int string
Coinbase *AccountProofWrapper `json:"coinbase"`
Time uint64 `json:"time"`
Transactions []*TransactionTrace `json:"transactions"`
Expand All @@ -23,16 +23,16 @@ type TransactionTrace struct {
Type uint8 `json:"type"`
Nonce uint64 `json:"nonce"`
Gas uint64 `json:"gas"`
GasPrice *big.Int `json:"gasPrice"`
GasPrice string `json:"gasPrice"` // big.Int string
From common.Address `json:"from"`
To *common.Address `json:"to"`
ChainId *big.Int `json:"chainId"`
Value *big.Int `json:"value"`
ChainId string `json:"chainId"` // big.Int string
Value string `json:"value"` // big.Int string
Data string `json:"data"`
IsCreate bool `json:"isCreate"`
V *big.Int `json:"v"`
R *big.Int `json:"r"`
S *big.Int `json:"s"`
V string `json:"v"` // big.Int string
R string `json:"r"` // big.Int string
S string `json:"s"` // big.Int string
}

// NewTraceBlock supports necessary fields for roller.
Expand All @@ -42,11 +42,11 @@ func NewTraceBlock(config *params.ChainConfig, block *Block, coinbase *AccountPr
txs[i] = newTraceTransaction(tx, block.NumberU64(), config)
}
return &BlockTrace{
Number: block.Number(),
Number: block.Number().String(),
Hash: block.Hash(),
GasLimit: block.GasLimit(),
Difficulty: block.Difficulty(),
BaseFee: block.BaseFee(),
Difficulty: block.Difficulty().String(),
BaseFee: block.BaseFee().String(),
Coinbase: coinbase,
Time: block.Time(),
Transactions: txs,
Expand All @@ -62,17 +62,17 @@ func newTraceTransaction(tx *Transaction, blockNumber uint64, config *params.Cha
result := &TransactionTrace{
Type: tx.Type(),
Nonce: tx.Nonce(),
ChainId: tx.ChainId(),
ChainId: tx.ChainId().String(),
From: from,
Gas: tx.Gas(),
GasPrice: tx.GasPrice(),
GasPrice: tx.GasPrice().String(),
To: tx.To(),
Value: tx.Value(),
Value: tx.Value().String(),
Data: hexutil.Encode(tx.Data()),
IsCreate: tx.To() == nil,
V: v,
R: r,
S: s,
V: v.String(),
R: r.String(),
S: s.String(),
}
return result
}
4 changes: 2 additions & 2 deletions core/vm/logger_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func getWrappedProofForAddr(l *StructLogger, address common.Address) (*types.Acc
return &types.AccountProofWrapper{
Address: address,
Nonce: l.env.StateDB.GetNonce(address),
Balance: l.env.StateDB.GetBalance(address),
Balance: l.env.StateDB.GetBalance(address).String(),
CodeHash: l.env.StateDB.GetCodeHash(address),
Proof: encodeProof(proof),
}, nil
Expand All @@ -150,7 +150,7 @@ func getWrappedProofForStorage(l *StructLogger, address common.Address, key comm
return &types.AccountProofWrapper{
Address: address,
Nonce: l.env.StateDB.GetNonce(address),
Balance: l.env.StateDB.GetBalance(address),
Balance: l.env.StateDB.GetBalance(address).String(),
CodeHash: l.env.StateDB.GetCodeHash(address),
Proof: encodeProof(proof),
Storage: &types.StorageProofWrapper{
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
sender := &types.AccountProofWrapper{
Address: from,
Nonce: w.current.state.GetNonce(from),
Balance: w.current.state.GetBalance(from),
Balance: w.current.state.GetBalance(from).String(),
CodeHash: w.current.state.GetCodeHash(from),
}

Expand Down

0 comments on commit 33fcd2b

Please sign in to comment.