-
Notifications
You must be signed in to change notification settings - Fork 660
/
vectors_etrog.go
122 lines (109 loc) · 4.6 KB
/
vectors_etrog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package vectors
import (
"math/big"
"github.com/0xPolygonHermez/zkevm-node/merkletree"
"github.com/0xPolygonHermez/zkevm-node/state"
)
// StateTransitionTestCaseEtrog holds the metadata needed to run a state transition test
type StateTransitionTestCaseEtrog struct {
Description string `json:"Description"`
Genesis []GenesisEntityEtrog `json:"genesis"`
ExpectedOldStateRoot string `json:"expectedOldRoot"`
ExpectedNewStateRoot string `json:"expectedNewRoot"`
ExpectedNewLeafs map[string]LeafEtrog `json:"expectedNewLeafs"`
Receipts []TestReceipt `json:"receipts"`
GlobalExitRoot string `json:"globalExitRoot"`
Txs []TxEtrog `json:"txs"`
OldAccInputHash string `json:"oldAccInputHash"`
L1InfoRoot string `json:"l1InfoRoot"`
TimestampLimit string `json:"timestampLimit"`
L1InfoTree L1Infotree `json:"l1InfoTree"`
BatchL2Data string `json:"batchL2Data"`
BatchHashData string `json:"batchHashData"`
ForkID uint64 `json:"forkID"`
SequencerAddress string `json:"sequencerAddress"`
}
// L1InfoTree represents the state of the L1InfoTree
type L1Infotree struct {
SkipVerifyL1InfoRoot bool `json:"skipVerifyL1InfoRoot"`
}
// LeafEtrog represents the state of a leaf in the merkle tree
type LeafEtrog struct {
Balance argBigInt `json:"balance"`
Nonce string `json:"nonce"`
Storage map[string]string `json:"storage"`
IsSmartContract bool `json:"isSmartContract"`
Bytecode string `json:"bytecode"`
HashBytecode string `json:"hashBytecode"`
BytecodeLength int `json:"bytecodeLength"`
}
// GenesisEntityEtrog represents the state of an account or smart contract when the network
// starts
type GenesisEntityEtrog struct {
Address string `json:"address"`
PvtKey *string `json:"pvtKey"`
Balance argBigInt `json:"balance"`
Nonce string `json:"nonce"`
Storage map[string]string `json:"storage"`
IsSmartContract bool `json:"isSmartContract"`
Bytecode *string `json:"bytecode"`
}
// TxEtrog represents a transactions that will be applied during the test
type TxEtrog struct {
Type uint `json:"type"`
ID uint `json:"id"`
From string `json:"from"`
To string `json:"to"`
Nonce uint64 `json:"nonce"`
Value *big.Float `json:"value"`
GasLimit uint64 `json:"gasLimit"`
GasPrice *big.Float `json:"gasPrice"`
ChainID uint64 `json:"chainId"`
RawTx string `json:"rawTx"`
CustomRawTx string `json:"customRawTx"`
Overwrite Overwrite `json:"overwrite"`
EncodeInvalidData bool `json:"encodeInvalidData"`
Reason string `json:"reason"`
IndexL1InfoTree uint32 `json:"indexL1InfoTree"`
}
func GenerateGenesisActionsEtrog(genesis []GenesisEntityEtrog) []*state.GenesisAction {
var genesisActions []*state.GenesisAction
for _, genesisEntity := range genesis {
if genesisEntity.Balance.String() != "0" {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeBalance),
Value: genesisEntity.Balance.String(),
}
genesisActions = append(genesisActions, action)
}
if genesisEntity.Nonce != "" && genesisEntity.Nonce != "0" {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeNonce),
Value: genesisEntity.Nonce,
}
genesisActions = append(genesisActions, action)
}
if genesisEntity.IsSmartContract && genesisEntity.Bytecode != nil && *genesisEntity.Bytecode != "0x" {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeCode),
Bytecode: *genesisEntity.Bytecode,
}
genesisActions = append(genesisActions, action)
}
if genesisEntity.IsSmartContract && len(genesisEntity.Storage) > 0 {
for storageKey, storageValue := range genesisEntity.Storage {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeStorage),
StoragePosition: storageKey,
Value: storageValue,
}
genesisActions = append(genesisActions, action)
}
}
}
return genesisActions
}