|
| 1 | +/** |
| 2 | + * Copyright Soramitsu Co., Ltd. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +#ifndef CPP_FILECOIN_CORE_VM_RUNTIME_GAS_COST_HPP |
| 7 | +#define CPP_FILECOIN_CORE_VM_RUNTIME_GAS_COST_HPP |
| 8 | + |
| 9 | +#include "primitives/big_int.hpp" |
| 10 | + |
| 11 | +namespace fc::vm::runtime { |
| 12 | + |
| 13 | + using primitives::BigInt; |
| 14 | + |
| 15 | + // TODO (a.chernyshov) https://soramitsu.atlassian.net/browse/FIL-131 Assign |
| 16 | + // after spec is updated. All constants that are not defined in Lotus are |
| 17 | + // initialized with this value. |
| 18 | + inline static const BigInt kGasAmountPlaceholder{0}; |
| 19 | + |
| 20 | + /** |
| 21 | + * Gas cost charged to the originator of an on-chain message (regardless of |
| 22 | + * whether it succeeds or fails in application) is given by: |
| 23 | + * OnChainMessageBase + len(serialized message) * OnChainMessagePerByte |
| 24 | + * Together, these account for the cost of message propagation and validation, |
| 25 | + * up to but excluding any actual processing by the VM. |
| 26 | + * This is the cost a block producer burns when including an invalid message. |
| 27 | + */ |
| 28 | + inline static const BigInt kOnChainMessageBaseGasCost{kGasAmountPlaceholder}; |
| 29 | + inline static const BigInt kOnChainMessagePerByteGasCharge{2}; |
| 30 | + |
| 31 | + /** |
| 32 | + * Gas cost charged to the originator of a non-nil return value produced by an |
| 33 | + * on-chain message is given by: |
| 34 | + * len(return value)*OnChainReturnValuePerByte |
| 35 | + */ |
| 36 | + inline static const BigInt kOnChainReturnValuePerByteGasCost{ |
| 37 | + kGasAmountPlaceholder}; |
| 38 | + |
| 39 | + /** |
| 40 | + * Gas cost for any message send execution (including the top-level one |
| 41 | + * initiated by an on-chain message). This accounts for the cost of loading |
| 42 | + * sender and receiver actors and (for top-level messages) incrementing the |
| 43 | + * sender's sequence number. Load and store of actor sub-state is charged |
| 44 | + * separately. |
| 45 | + */ |
| 46 | + inline static const BigInt kSendBaseGasCost{kGasAmountPlaceholder}; |
| 47 | + |
| 48 | + /** |
| 49 | + * Gas cost charged, in addition to SendBase, if a message send is accompanied |
| 50 | + * by any nonzero currency amount. Accounts for writing receiver's new balance |
| 51 | + * (the sender's state is already accounted for). |
| 52 | + */ |
| 53 | + inline static const BigInt kSendTransferFundsGasCost{10}; |
| 54 | + |
| 55 | + /** |
| 56 | + * Gas cost charged, in addition to SendBase, if a message invokes a method on |
| 57 | + * the receiver. Accounts for the cost of loading receiver code and method |
| 58 | + * dispatch. |
| 59 | + */ |
| 60 | + inline static const BigInt kSendInvokeMethodGasCost{5}; |
| 61 | + |
| 62 | + /** |
| 63 | + * Gas cost (Base + len * PerByte) for any Get operation to the IPLD store in |
| 64 | + * the runtime VM context. |
| 65 | + */ |
| 66 | + inline static const BigInt kIpldGetBaseGasCost{10}; |
| 67 | + inline static const BigInt kIpldGetPerByteGasCost{1}; |
| 68 | + |
| 69 | + /** |
| 70 | + * Gas cost (Base + len * PerByte) for any Put operation to the IPLD store in |
| 71 | + * the runtime VM context. |
| 72 | + * Note: these costs should be significantly higher than the costs for Get |
| 73 | + * operations, since they reflect not only serialization/deserialization but |
| 74 | + * also persistent storage of chain data. |
| 75 | + */ |
| 76 | + inline static const BigInt kIpldPutBaseGasCost{20}; |
| 77 | + inline static const BigInt kIpldPutPerByteGasCost{2}; |
| 78 | + |
| 79 | + /** |
| 80 | + * Gas cost for updating an actor's substate (i.e., UpdateRelease). This is in |
| 81 | + * addition to a per-byte fee for the state as for IPLD Get/Put. |
| 82 | + */ |
| 83 | + inline static const BigInt kUpdateActorSubstateGasCost{kGasAmountPlaceholder}; |
| 84 | + |
| 85 | + /** |
| 86 | + * Gas cost for creating a new actor (via InitActor's Exec method). Actor |
| 87 | + * sub-state is charged separately. |
| 88 | + */ |
| 89 | + inline static const BigInt kExecNewActorGasCost{kGasAmountPlaceholder}; |
| 90 | + |
| 91 | + /** |
| 92 | + * Gas cost for deleting an actor. |
| 93 | + */ |
| 94 | + inline static const BigInt kDeleteActorGasCost{kGasAmountPlaceholder}; |
| 95 | + |
| 96 | + /** |
| 97 | + * Gas cost charged per public-key cryptography operation (e.g., signature |
| 98 | + * verification). |
| 99 | + */ |
| 100 | + inline static const BigInt kPublicKeyCryptoOperationGasCost{ |
| 101 | + kGasAmountPlaceholder}; |
| 102 | + |
| 103 | + /** |
| 104 | + * Gas cost of new state commit |
| 105 | + */ |
| 106 | + inline static const BigInt kCommitGasCost{50}; |
| 107 | + |
| 108 | +} // namespace fc::vm::runtime |
| 109 | + |
| 110 | +#endif // CPP_FILECOIN_CORE_VM_RUNTIME_GAS_COST_HPP |
0 commit comments