github.com/klaytn/klaytn@v1.12.1/params/protocol_params.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2015 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from params/protocol_params.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package params 22 23 import ( 24 "fmt" 25 "math/big" 26 "time" 27 ) 28 29 var TargetGasLimit = GenesisGasLimit // The artificial target 30 31 const ( 32 // Fee schedule parameters 33 34 CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. // G_callvalue 35 CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. // G_newaccount 36 TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. // G_transaction 37 TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. // G_transaction + G_create 38 TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. // G_txdatazero 39 QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. 40 SstoreSetGas uint64 = 20000 // Once per SLOAD operation. // G_sset 41 LogDataGas uint64 = 8 // Per byte in a LOG* operation's data. // G_logdata 42 CallStipend uint64 = 2300 // Free gas given at beginning of call. // G_callstipend 43 Sha3Gas uint64 = 30 // Once per SHA3 operation. // G_sha3 44 Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data. // G_sha3word 45 InitCodeWordGas uint64 = 2 // Once per word of the init code when creating a contract. // G_InitCodeWord 46 SstoreResetGas uint64 = 5000 // Once per SSTORE operation if the zeroness changes from zero. // G_sreset 47 SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change. // G_sreset 48 SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero. // R_sclear 49 50 // gasSStoreEIP2200 51 SstoreSentryGasEIP2200 uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed 52 SstoreSetGasEIP2200 uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero 53 SstoreResetGasEIP2200 uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else 54 SstoreClearsScheduleRefundEIP2200 uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot 55 56 ColdAccountAccessCostEIP2929 = uint64(2600) // COLD_ACCOUNT_ACCESS_COST 57 ColdSloadCostEIP2929 = uint64(2100) // COLD_SLOAD_COST 58 WarmStorageReadCostEIP2929 = uint64(100) // WARM_STORAGE_READ_COST 59 60 // In EIP-2200: SstoreResetGas was 5000. 61 // In EIP-2929: SstoreResetGas was changed to '5000 - COLD_SLOAD_COST'. 62 // In EIP-3529: SSTORE_CLEARS_SCHEDULE is defined as SSTORE_RESET_GAS + ACCESS_LIST_STORAGE_KEY_COST 63 // Which becomes: 5000 - 2100 + 1900 = 4800 64 SstoreClearsScheduleRefundEIP3529 uint64 = SstoreResetGasEIP2200 - ColdSloadCostEIP2929 + TxAccessListStorageKeyGas 65 66 JumpdestGas uint64 = 1 // Once per JUMPDEST operation. 67 CreateDataGas uint64 = 200 // Paid per byte for a CREATE operation to succeed in placing code into state. // G_codedeposit 68 ExpGas uint64 = 10 // Once per EXP instruction 69 LogGas uint64 = 375 // Per LOG* operation. // G_log 70 CopyGas uint64 = 3 // Partial payment for COPY operations, multiplied by words copied, rounded up. // G_copy 71 CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction. // G_create 72 Create2Gas uint64 = 32000 // Once per CREATE2 operation 73 SelfdestructRefundGas uint64 = 24000 // Refunded following a selfdestruct operation. // R_selfdestruct 74 MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL. // G_memory 75 LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas. // G_logtopic 76 TxDataNonZeroGas uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. // G_txdatanonzero 77 78 CallGas uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine) 79 ExtcodeSizeGas uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine) 80 SelfdestructGas uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine) 81 82 // Istanbul version of BalanceGas, SloadGas, ExtcodeHash is added. 83 BalanceGasEIP150 uint64 = 400 // Cost of BALANCE before EIP 1884 84 BalanceGasEIP1884 uint64 = 700 // Cost of BALANCE after EIP 1884 (part of Istanbul) 85 SloadGasEIP150 uint64 = 200 // Cost of SLOAD before EIP 1884 86 SloadGasEIP1884 uint64 = 800 // Cost of SLOAD after EIP 1884 (part of Istanbul) 87 SloadGasEIP2200 uint64 = 800 // Cost of SLOAD after EIP 2200 (part of Istanbul) 88 ExtcodeHashGasConstantinople uint64 = 400 // Cost of EXTCODEHASH before EIP 1884 89 ExtcodeHashGasEIP1884 uint64 = 700 // Cost of EXTCODEHASH after EIP 1884 (part in Istanbul) 90 91 // EXP has a dynamic portion depending on the size of the exponent 92 // was set to 10 in Frontier, was raised to 50 during Eip158 (Spurious Dragon) 93 ExpByte uint64 = 50 94 95 // Extcodecopy has a dynamic AND a static cost. This represents only the 96 // static portion of the gas. It was changed during EIP 150 (Tangerine) 97 ExtcodeCopyBase uint64 = 700 98 99 // CreateBySelfdestructGas is used when the refunded account is one that does 100 // not exist. This logic is similar to call. 101 // Introduced in Tangerine Whistle (Eip 150) 102 CreateBySelfdestructGas uint64 = 25000 103 104 // Fee for Service Chain 105 // TODO-Klaytn-ServiceChain The following parameters should be fixed. 106 // TODO-Klaytn-Governance The following parameters should be able to be modified by governance. 107 TxChainDataAnchoringGas uint64 = 21000 // Per transaction anchoring chain data. NOTE: Not payable on data of calls between transactions. // G_transactionchaindataanchoring 108 ChainDataAnchoringGas uint64 = 100 // Per byte of anchoring chain data NOTE: Not payable on data of calls between transactions. // G_chaindataanchoring 109 110 // Precompiled contract gas prices 111 112 EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price 113 Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation 114 Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation 115 Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation 116 Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation 117 IdentityBaseGas uint64 = 15 // Base price for a data copy operation 118 IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation 119 120 Bn256AddGasByzantium uint64 = 500 // Gas needed for an elliptic curve addition 121 Bn256AddGasIstanbul uint64 = 150 // Istanbul version of gas needed for an elliptic curve addition 122 Bn256ScalarMulGasByzantium uint64 = 40000 // Gas needed for an elliptic curve scalar multiplication 123 Bn256ScalarMulGasIstanbul uint64 = 6000 // Istanbul version of gas needed for an elliptic curve scalar multiplication 124 Bn256PairingBaseGasByzantium uint64 = 100000 // Base price for an elliptic curve pairing check 125 Bn256PairingBaseGasIstanbul uint64 = 45000 // Istanbul version of base price for an elliptic curve pairing check 126 Bn256PairingPerPointGasByzantium uint64 = 80000 // Per-point price for an elliptic curve pairing check 127 Bn256PairingPerPointGasIstanbul uint64 = 34000 // Istanbul version of per-point price for an elliptic curve pairing check 128 BlobTxPointEvaluationPrecompileGas uint64 = 50000 // Gas price for the point evaluation precompile. 129 VMLogBaseGas uint64 = 100 // Base price for a VMLOG operation 130 VMLogPerByteGas uint64 = 20 // Per-byte price for a VMLOG operation 131 FeePayerGas uint64 = 300 // Gas needed for calculating the fee payer of the transaction in a smart contract. 132 ValidateSenderGas uint64 = 5000 // Gas needed for validating the signature of a message. 133 134 // The Refund Quotient is the cap on how much of the used gas can be refunded. Before EIP-3529, 135 // up to half the consumed gas could be refunded. Redefined as 1/5th in EIP-3529 136 RefundQuotient uint64 = 2 137 RefundQuotientEIP3529 uint64 = 5 138 139 GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. 140 MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. 141 GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. 142 143 MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. 144 145 EpochDuration uint64 = 30000 // Duration between proof-of-work epochs. 146 CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack. 147 StackLimit uint64 = 1024 // Maximum size of VM stack allowed. 148 149 // eip-3860: limit and meter initcode (Shanghai) 150 MaxCodeSize = 24576 // Maximum bytecode to permit for a contract 151 MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions 152 153 // istanbul BFT 154 BFTMaximumExtraDataSize uint64 = 65 // Maximum size extra data may be after Genesis. 155 156 // AccountKey 157 // TODO-Klaytn: Need to fix below values. 158 TxAccountCreationGasDefault uint64 = 0 159 TxValidationGasDefault uint64 = 0 160 TxAccountCreationGasPerKey uint64 = 20000 // WARNING: With integer overflow in mind before changing this value. 161 TxValidationGasPerKey uint64 = 15000 // WARNING: With integer overflow in mind before changing this value. 162 163 // Fee for new tx types 164 // TODO-Klaytn: Need to fix values 165 TxGasAccountCreation uint64 = 21000 166 TxGasAccountUpdate uint64 = 21000 167 TxGasFeeDelegated uint64 = 10000 168 TxGasFeeDelegatedWithRatio uint64 = 15000 169 TxGasCancel uint64 = 21000 170 171 // Network Id 172 UnusedNetworkId uint64 = 0 173 AspenNetworkId uint64 = 1000 174 BaobabNetworkId uint64 = 1001 175 CypressNetworkId uint64 = 8217 176 ServiceChainDefaultNetworkId uint64 = 3000 177 178 TxGasValueTransfer uint64 = 21000 179 TxGasContractExecution uint64 = 21000 180 181 TxDataGas uint64 = 100 182 183 TxAccessListAddressGas uint64 = 2400 // Per address specified in EIP 2930 access list 184 TxAccessListStorageKeyGas uint64 = 1900 // Per storage key specified in EIP 2930 access list 185 186 // ZeroBaseFee exists for supporting Ethereum compatible data structure. 187 ZeroBaseFee uint64 = 0 188 ) 189 190 const ( 191 DefaultBlockGenerationInterval = int64(1) // unit: seconds 192 DefaultBlockGenerationTimeLimit = 250 * time.Millisecond 193 ) 194 195 var ( 196 // Dummy Randao fields to be used in a Randao-enabled Genesis block. 197 ZeroRandomReveal = make([]byte, 96) 198 ZeroMixHash = make([]byte, 32) 199 200 TxGasHumanReadable uint64 = 4000000000 // NOTE: HumanReadable related functions are inactivated now 201 202 // TODO-Klaytn Change the variables used in GXhash to more appropriate values for Klaytn Network 203 BlockScoreBoundDivisor = big.NewInt(2048) // The bound divisor of the blockscore, used in the update calculations. 204 GenesisBlockScore = big.NewInt(131072) // BlockScore of the Genesis block. 205 MinimumBlockScore = big.NewInt(131072) // The minimum that the blockscore may ever be. 206 DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether blockscore should go up or not. 207 ) 208 209 // Parameters for execution time limit 210 // These parameters will be re-assigned by init options 211 var ( 212 // Execution time limit for all txs in a block 213 BlockGenerationTimeLimit = DefaultBlockGenerationTimeLimit 214 215 // TODO-Klaytn-Governance Change the following variables to governance items which requires consensus of CCN 216 // Block generation interval in seconds. It should be equal or larger than 1 217 BlockGenerationInterval = DefaultBlockGenerationInterval 218 ) 219 220 // istanbul BFT 221 func GetMaximumExtraDataSize() uint64 { 222 return BFTMaximumExtraDataSize 223 } 224 225 // CodeFormat is the version of the interpreter that smart contract uses 226 type CodeFormat uint8 227 228 // Supporting CodeFormat 229 // CodeFormatLast should be equal or less than 16 because only the last 4 bits of CodeFormat are used for CodeInfo. 230 const ( 231 CodeFormatEVM CodeFormat = iota 232 CodeFormatLast 233 ) 234 235 func (t CodeFormat) Validate() bool { 236 if t < CodeFormatLast { 237 return true 238 } 239 return false 240 } 241 242 func (t CodeFormat) String() string { 243 switch t { 244 case CodeFormatEVM: 245 return "CodeFormatEVM" 246 } 247 248 return "UndefinedCodeFormat" 249 } 250 251 // VmVersion contains the information of the contract deployment time (ex. 0x0(constantinople), 0x1(istanbul,...)) 252 type VmVersion uint8 253 254 // Supporting VmVersion 255 const ( 256 VmVersion0 VmVersion = iota // Deployed at Constantinople 257 VmVersion1 // Deployed at Istanbul, ...(later HFs would be added) 258 ) 259 260 func (t VmVersion) String() string { 261 return "VmVersion" + string(t) 262 } 263 264 // CodeInfo consists of 8 bits, and has information of the contract code. 265 // Originally, codeInfo only contains codeFormat information(interpreter version), but now it is divided into two parts. 266 // First four bit contains the deployment time (ex. 0x00(constantinople), 0x10(istanbul,...)), so it is called vmVersion. 267 // Last four bit contains the interpreter version (ex. 0x00(EVM), 0x01(EWASM)), so it is called codeFormat. 268 type CodeInfo uint8 269 270 const ( 271 // codeFormatBitMask filters only the codeFormat. It means the interpreter version used by the contract. 272 // Mask result 1. [x x x x 0 0 0 1]. The contract uses EVM interpreter. 273 codeFormatBitMask = 0b00001111 274 275 // vmVersionBitMask filters only the vmVersion. It means deployment time of the contract. 276 // Mask result 1. [0 0 0 0 x x x x]. The contract is deployed at constantinople 277 // Mask result 2. [0 0 0 1 x x x x]. The contract is deployed after istanbulHF 278 vmVersionBitMask = 0b11110000 279 ) 280 281 func NewCodeInfo(codeFormat CodeFormat, vmVersion VmVersion) CodeInfo { 282 return CodeInfo(codeFormat&codeFormatBitMask) | CodeInfo(vmVersion)<<4 283 } 284 285 func NewCodeInfoWithRules(codeFormat CodeFormat, r Rules) CodeInfo { 286 var vmVersion VmVersion 287 switch { 288 // If new HF is added, please add new case below 289 // case r.IsNextHF: // If this HF is backward compatible with vmVersion1. 290 case r.IsLondon: 291 fallthrough 292 case r.IsIstanbul: 293 vmVersion = VmVersion1 294 default: 295 vmVersion = VmVersion0 296 } 297 return NewCodeInfo(codeFormat, vmVersion) 298 } 299 300 func (t CodeInfo) GetCodeFormat() CodeFormat { 301 return CodeFormat(t & codeFormatBitMask) 302 } 303 304 func (t CodeInfo) GetVmVersion() VmVersion { 305 return VmVersion(t & vmVersionBitMask >> 4) 306 } 307 308 func (t CodeInfo) String() string { 309 return fmt.Sprintf("[%s, %s]", t.GetCodeFormat().String(), t.GetVmVersion().String()) 310 }