github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/trie/zkproof/types.go (about)

     1  package zkproof
     2  
     3  import (
     4  	"github.com/scroll-tech/go-ethereum/common/hexutil"
     5  )
     6  
     7  type MPTWitnessType int
     8  
     9  const (
    10  	MPTWitnessNothing MPTWitnessType = iota
    11  	MPTWitnessNatural
    12  	MPTWitnessRWTbl
    13  )
    14  
    15  // SMTPathNode represent a node in the SMT Path, all hash is saved by the present of
    16  // zktype.Hash
    17  type SMTPathNode struct {
    18  	Value   hexutil.Bytes `json:"value"`
    19  	Sibling hexutil.Bytes `json:"sibling"`
    20  }
    21  
    22  // SMTPath is the whole path of SMT
    23  type SMTPath struct {
    24  	KeyPathPart *hexutil.Big  `json:"pathPart"` //the path part in key
    25  	Root        hexutil.Bytes `json:"root"`
    26  	Path        []SMTPathNode `json:"path,omitempty"` //path start from top
    27  	Leaf        *SMTPathNode  `json:"leaf,omitempty"` //would be omitted for empty leaf, the sibling indicate key
    28  }
    29  
    30  // StateAccount is the represent of StateAccount in L2 circuit
    31  // Notice in L2 we have different hash scheme against StateAccount.MarshalByte
    32  type StateAccount struct {
    33  	Nonce            int           `json:"nonce"`
    34  	Balance          *hexutil.Big  `json:"balance"` //just the common hex expression of integer (big-endian)
    35  	KeccakCodeHash   hexutil.Bytes `json:"keccakCodeHash,omitempty"`
    36  	PoseidonCodeHash hexutil.Bytes `json:"poseidonCodeHash,omitempty"`
    37  	CodeSize         uint64        `json:"codeSize,omitempty"`
    38  }
    39  
    40  // StateStorage is the represent of a stored key-value pair for specified account
    41  type StateStorage struct {
    42  	Key   hexutil.Bytes `json:"key"` //notice this is the preimage of storage key
    43  	Value hexutil.Bytes `json:"value"`
    44  }
    45  
    46  // StorageTrace record the updating on state trie and (if changed) account trie
    47  // represent by the [before, after] updating of SMTPath amont tries and Account
    48  type StorageTrace struct {
    49  	// which log the trace is responded for, -1 indicate not caused
    50  	// by opcode (like gasRefund, coinbase, setNonce, etc)
    51  	Address         hexutil.Bytes    `json:"address"`
    52  	AccountKey      hexutil.Bytes    `json:"accountKey"`
    53  	AccountPath     [2]*SMTPath      `json:"accountPath"`
    54  	AccountUpdate   [2]*StateAccount `json:"accountUpdate"`
    55  	StateKey        hexutil.Bytes    `json:"stateKey,omitempty"`
    56  	CommonStateRoot hexutil.Bytes    `json:"commonStateRoot,omitempty"` //CommonStateRoot is used if there is no update on state storage
    57  	StatePath       [2]*SMTPath      `json:"statePath,omitempty"`
    58  	StateUpdate     [2]*StateStorage `json:"stateUpdate,omitempty"`
    59  }