eosiosg / eos-challenge-contract

ISC License
3 stars 0 forks source link

Transfer gas fee计算 #17

Closed Frank-AFN closed 4 years ago

Frank-AFN commented 4 years ago

如果raw function是transfer. 需要增加计算 storage的gas fee.

Frank-AFN commented 4 years ago

The cost of the SSTORE opcode, which sets values in account storage, is either: (i) 20000 gas when changing a zero value to a nonzero value, (ii) 5000 gas when changing a zero value to a zero value or a nonzero value to a nonzero value, or (iii) 5000 gas when changing a nonzero value to a zero value, plus a 15000 gas refund to be given at the end of successful transaction execution (ie. NOT an execution leading to an out-of-gas exception). Refunds are capped at 50% of the total gas spent by a transaction. This provides a small incentive to clear storage, as we noticed that lacking such an incentive many contracts would leave storage unused, leading to quickly increasing bloat, providing most of the benefits of "charging rent" for storage without the cost of losing the assurance that a contract once placed will continue to exist forever. The delayed refund mechanism is necessary to prevent denial-of-service attacks where the attacker sends a transaction with a low amount of gas that repeatedly clears a large number of storage slots as part of a long-running loop, and then runs out of gas, consuming a large amount of verifiers' computing power without actually clearing storage or spending a lot of gas. The 50% cap is needed to ensure that a miner given a transaction with some quantity of gas can still determine an upper bound on the computational time to execute the transaction.

reference: https://github.com/ethereum/wiki/wiki/Design-Rationale#gas-and-fees

Frank-AFN commented 4 years ago

不需要增加 add storage gas fee. 如果是transfer value. gas fee = 21000. 在intrinsic gas fee中有这部分的逻辑.

Frank-AFN commented 4 years ago

intrinsic gas fee already include message call 21000 and contract creation 53000 base gas fee

refer: #17