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

Add zero tracer #137

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions cmd/rpcdaemon/commands/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
txns = append(txns, borTx)
}

cumulativeGas := uint64(0)

for idx, txn := range txns {
stream.WriteObjectStart()
stream.WriteObjectField("result")
Expand All @@ -141,9 +143,12 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
}

txCtx := evmtypes.TxContext{
TxHash: txn.Hash(),
Origin: msg.From(),
GasPrice: msg.GasPrice(),
TxHash: txn.Hash(),
Origin: msg.From(),
GasPrice: msg.GasPrice(),
Txn: txn,
CumulativeGasUsed: &cumulativeGas,
BlockNum: block.NumberU64(),
}

if borTx != nil && idx == len(txns)-1 {
Expand Down
56 changes: 56 additions & 0 deletions core/types/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Trace types for sending proof information to a zk prover as defined in https://github.com/0xPolygonZero/proof-protocol-decoder.
package types

import (
"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
)

type HexBytes []byte

func (b HexBytes) MarshalText() ([]byte, error) {
return hexutility.Bytes(b[:]).MarshalText()
}

type ContractCodeUsage struct {
Read *libcommon.Hash `json:"read,omitempty"`
Write HexBytes `json:"write,omitempty"`
}

type TxnTrace struct {
Balance *uint256.Int `json:"balance,omitempty"`
Nonce *uint256.Int `json:"nonce,omitempty"`
StorageRead []libcommon.Hash `json:"storage_read,omitempty"`
StorageWritten map[libcommon.Hash]*uint256.Int `json:"storage_written,omitempty"`
CodeUsage *ContractCodeUsage `json:"code_usage,omitempty"`
SelfDestructed *bool `json:"self_destructed,omitempty"`
StorageReadMap map[libcommon.Hash]struct{} `json:"-"`
}

type TxnMeta struct {
ByteCode HexBytes `json:"byte_code,omitempty"`
NewTxnTrieNode HexBytes `json:"new_txn_trie_node_byte,omitempty"`
NewReceiptTrieNode HexBytes `json:"new_receipt_trie_node_byte,omitempty"`
GasUsed uint64 `json:"gas_used,omitempty"`
}

type TxnInfo struct {
Traces map[libcommon.Address]*TxnTrace `json:"traces,omitempty"`
Meta TxnMeta `json:"meta,omitempty"`
}

type BlockUsedCodeHashes []libcommon.Hash

type CombinedPreImages struct {
Compact HexBytes `json:"compact,omitempty"`
}

type TriePreImage struct {
Combined CombinedPreImages `json:"combined,omitempty"`
}

type BlockTrace struct {
TriePreImage TriePreImage `json:"trie_pre_images,omitempty"`
TxnInfo []TxnInfo `json:"txn_info,omitempty"`
}
12 changes: 8 additions & 4 deletions core/vm/evmtypes/evmtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ type BlockContext struct {
// All fields can change between transactions.
type TxContext struct {
// Message information
TxHash libcommon.Hash
Origin libcommon.Address // Provides information for ORIGIN
GasPrice *uint256.Int // Provides information for GASPRICE
DataHashes []libcommon.Hash // Provides versioned data hashes for DATAHASH
TxHash libcommon.Hash
Origin libcommon.Address // Provides information for ORIGIN
GasPrice *uint256.Int // Provides information for GASPRICE
DataHashes []libcommon.Hash // Provides versioned data hashes for DATAHASH
Txn types.Transaction
CumulativeGasUsed *uint64
BlockNum uint64
}

type (
Expand Down Expand Up @@ -101,4 +104,5 @@ type IntraBlockState interface {
Snapshot() int

AddLog(*types.Log)
GetLogs(hash libcommon.Hash) []*types.Log
}
Loading
Loading