hermez-node/common/ethrollup.go
common/ethrollup.goRaw
1package common
2
3import (
4 "math/big"
5
6 ethCommon "github.com/ethereum/go-ethereum/common"
7 "github.com/ethereum/go-ethereum/crypto"
8)
9
10// RollupVars contain the Rollup smart contract variables
11// type RollupVars struct {
12// EthBlockNum uint64
13// ForgeL1Timeout *big.Int
14// FeeL1UserTx *big.Int
15// FeeAddToken *big.Int
16// TokensHEZ eth.Address
17// Governance eth.Address
18// }
19
20// AuctionVars contain the Auction smart contract variables
21// type AuctionVars struct {
22// EthBlockNum uint64
23// SlotDeadline uint
24// CloseAuctionSlots uint
25// OpenAuctionSlots uint
26// Governance eth.Address
27// MinBidSlots MinBidSlots
28// Outbidding int
29// DonationAddress eth.Address
30// GovernanceAddress eth.Address
31// AllocationRatio AllocationRatio
32// }
33
34// WithdrawDelayerVars contains the Withdrawal Delayer smart contract variables
35// type WithdrawDelayerVars struct {
36// HermezRollupAddress eth.Address
37// HermezGovernanceDAOAddress eth.Address
38// WhiteHackGroupAddress eth.Address
39// WithdrawalDelay uint
40// EmergencyModeStartingTime time.Time
41// EmergencyModeEnabled bool
42// }
43
44// MinBidSlots TODO
45// type MinBidSlots [6]uint
46//
47// // AllocationRatio TODO
48// type AllocationRatio struct {
49// Donation uint
50// Burn uint
51// Forger uint
52// }
53
54const (
55 // RollupConstMaxFeeIdxCoordinator is the maximum number of tokens the
56 // coordinator can use to collect fees (determines the number of tokens
57 // that the coordinator can collect fees from). This value is
58 // determined by the circuit.
59 RollupConstMaxFeeIdxCoordinator = 64
60 // RollupConstReservedIDx First 256 indexes reserved, first user index will be the 256
61 RollupConstReservedIDx = 255
62 // RollupConstExitIDx IDX 1 is reserved for exits
63 RollupConstExitIDx = 1
64 // RollupConstLimitLoadAmount Max load amount allowed (loadAmount: L1 --> L2)
65 RollupConstLimitLoadAmount = (1 << 128)
66 // RollupConstLimitL2TransferAmount Max amount allowed (amount L2 --> L2)
67 RollupConstLimitL2TransferAmount = (1 << 192)
68 // RollupConstLimitTokens Max number of tokens allowed to be registered inside the rollup
69 RollupConstLimitTokens = (1 << 32)
70 // RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature
71 RollupConstL1CoordinatorTotalBytes = 101
72 // RollupConstL1UserTotalBytes [20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx +
73 // [2 bytes] loadAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx
74 RollupConstL1UserTotalBytes = 72
75 // RollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch
76 RollupConstMaxL1UserTx = 128
77 // RollupConstMaxL1Tx Maximum L1 transactions allowed to be queued in a batch
78 RollupConstMaxL1Tx = 256
79 // RollupConstInputSHAConstantBytes [6 bytes] lastIdx + [6 bytes] newLastIdx + [32 bytes] stateRoot + [32 bytes] newStRoot + [32 bytes] newExitRoot +
80 // [_MAX_L1_TX * _L1_USER_TOTALBYTES bytes] l1TxsData + totalL2TxsDataLength + feeIdxCoordinatorLength + [2 bytes] chainID =
81 // 18542 bytes + totalL2TxsDataLength + feeIdxCoordinatorLength
82 RollupConstInputSHAConstantBytes = 18542
83 // RollupConstNumBuckets Number of buckets
84 RollupConstNumBuckets = 5
85 // RollupConstMaxWithdrawalDelay max withdrawal delay in seconds
86 RollupConstMaxWithdrawalDelay = 2 * 7 * 24 * 60 * 60
87 // RollupConstExchangeMultiplier exchange multiplier
88 RollupConstExchangeMultiplier = 1e14
89 // LenVerifiers number of Rollup Smart Contract Verifiers
90 LenVerifiers = 1
91)
92
93var (
94 // RollupConstEthAddressInternalOnly This ethereum address is used internally for rollup accounts that don't have ethereum address, only Babyjubjub
95 // This non-ethereum accounts can be created by the coordinator and allow users to have a rollup
96 // account without needing an ethereum address
97 RollupConstEthAddressInternalOnly = ethCommon.HexToAddress("0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF")
98 // RollupConstRfield Modulus zkSNARK
99 RollupConstRfield, _ = new(big.Int).SetString(
100 "21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
101
102 // RollupConstERC1820 ERC1820Registry address
103 RollupConstERC1820 = ethCommon.HexToAddress("0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24")
104
105 // ERC777 tokens signatures
106
107 // RollupConstRecipientInterfaceHash ERC777 recipient interface hash
108 RollupConstRecipientInterfaceHash = crypto.Keccak256([]byte("ERC777TokensRecipient"))
109 // RollupConstPerformL1UserTxSignature the signature of the function that can be called thru an ERC777 `send`
110 RollupConstPerformL1UserTxSignature = crypto.Keccak256([]byte("addL1Transaction(uint256,uint48,uint16,uint16,uint32,uint48)"))
111 // RollupConstAddTokenSignature the signature of the function that can be called thru an ERC777 `send`
112 RollupConstAddTokenSignature = crypto.Keccak256([]byte("addToken(address)"))
113 // RollupConstSendSignature ERC777 Signature
114 RollupConstSendSignature = crypto.Keccak256([]byte("send(address,uint256,bytes)"))
115 // RollupConstERC777Granularity ERC777 Signature
116 RollupConstERC777Granularity = crypto.Keccak256([]byte("granularity()"))
117 // RollupConstWithdrawalDelayerDeposit This constant are used to deposit tokens from ERC77 tokens into withdrawal delayer
118 RollupConstWithdrawalDelayerDeposit = crypto.Keccak256([]byte("deposit(address,address,uint192)"))
119
120 // ERC20 signature
121
122 // RollupConstTransferSignature This constant is used in the _safeTransfer internal method in order to safe GAS.
123 RollupConstTransferSignature = crypto.Keccak256([]byte("transfer(address,uint256)"))
124 // RollupConstTransferFromSignature This constant is used in the _safeTransfer internal method in order to safe GAS.
125 RollupConstTransferFromSignature = crypto.Keccak256([]byte("transferFrom(address,address,uint256)"))
126 // RollupConstApproveSignature This constant is used in the _safeTransfer internal method in order to safe GAS.
127 RollupConstApproveSignature = crypto.Keccak256([]byte("approve(address,uint256)"))
128 // RollupConstERC20Signature ERC20 decimals signature
129 RollupConstERC20Signature = crypto.Keccak256([]byte("decimals()"))
130)
131
132// RollupVerifierStruct is the information about verifiers of the Rollup Smart Contract
133type RollupVerifierStruct struct {
134 MaxTx int64 `json:"maxTx"`
135 NLevels int64 `json:"nlevels"`
136}
137
138// RollupConstants are the constants of the Rollup Smart Contract
139type RollupConstants struct {
140 AbsoluteMaxL1L2BatchTimeout int64 `json:"absoluteMaxL1L2BatchTimeout"`
141 TokenHEZ ethCommon.Address `json:"tokenHEZ"`
142 Verifiers []RollupVerifierStruct `json:"verifiers"`
143 HermezAuctionContract ethCommon.Address `json:"hermezAuctionContract"`
144 HermezGovernanceDAOAddress ethCommon.Address `json:"hermezGovernanceDAOAddress"`
145 SafetyAddress ethCommon.Address `json:"safetyAddress"`
146 WithdrawDelayerContract ethCommon.Address `json:"withdrawDelayerContract"`
147}
148
149// Bucket are the variables of each Bucket of Rollup Smart Contract
150type Bucket struct {
151 CeilUSD uint64 `json:"ceilUSD"`
152 BlockStamp uint64 `json:"blockStamp"`
153 Withdrawals uint64 `json:"withdrawals"`
154 BlockWithdrawalRate uint64 `json:"blockWithdrawalRate"`
155 MaxWithdrawals uint64 `json:"maxWithdrawals"`
156}
157
158// RollupVariables are the variables of the Rollup Smart Contract
159type RollupVariables struct {
160 FeeAddToken *big.Int `json:"feeAddToken" meddler:"fee_addtoken"`
161 ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1l2_timeout"`
162 WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay"`
163 Buckets [RollupConstNumBuckets]Bucket `json:"buckets" meddler:"buckets,json"`
164}