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