Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

[KIP-68] Increase Gcallstipend gas in the CALL OPCODE #69

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions KIPs/kip-34.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,11 @@ The `TransactionDecoder` class decodes the RLP-encoded string using the `decode`
| ----------- | ----------- |
| type: String | The type string of the transaction. |
| from: String | The address of the sender. |
| nonce: String | A value used to uniquely identify a sender’s transaction. If omitted when creating a transaction, [klay_getTransactionCount](https://docs.klaytn.com/bapp/json-rpc/api-references/klay/account#klay_gettransactioncount) will be used to set an appropriate nonce. |
| nonce: String | A value used to uniquely identify a sender’s transaction. If omitted when creating a transaction, [klay_getTransactionCount](https://docs.klaytn.com/dapp/json-rpc/api-references/klay/account#klay_gettransactioncount) will be used to set an appropriate nonce. |
| gas: String | The maximum amount of the transaction fee allowed to use. |
| gasPrice: String | A multiplier to get how much the sender will pay in KLAY. If omitted when creating a transaction, [klay_gasPrice](https://docs.klaytn.com/bapp/json-rpc/api-references/klay/config#klay_gasprice) will be used to set this value. |
| gasPrice: String | A multiplier to get how much the sender will pay in KLAY. If omitted when creating a transaction, [klay_gasPrice](https://docs.klaytn.com/dapp/json-rpc/api-references/klay/config#klay_gasprice) will be used to set this value. |
| signatures: List<SignatureData> | An array of signatures. The result of signing the transaction is appended to these signatures. When appending a signature, duplicate signatures are not appended. |
| chainId: String | The chain id of the Klaytn network. If omitted when creating a transaction, [klay_chainID](https://docs.klaytn.com/bapp/json-rpc/api-references/klay/config#klay_chainid) will be used to set this value. |
| chainId: String | The chain id of the Klaytn network. If omitted when creating a transaction, [klay_chainID](https://docs.klaytn.com/dapp/json-rpc/api-references/klay/config#klay_chainid) will be used to set this value. |

##### Methods

Expand Down Expand Up @@ -1288,7 +1288,7 @@ deploy and execute [KIP-7] token contracts on Klaytn. `KIP7` maps all functions
The `KIP17` class provides the functions to interact with [KIP-17] token contracts on Klaytn. This class allows users to easily
deploy and execute [KIP-17] token contracts on Klaytn. `KIP17` maps all functions defined in [KIP-17] and provides them as class methods.

More token standards defined in [KCT](http://kips.klaytn.com/token) can be implemented here. For other KCT implementations can be found in the SDK references ([caver-js](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.kct), [caver-java](https://javadoc.io/doc/com.klaytn.caver/core/latest/index.html)).
More token standards defined in [KCT](http://kips.klaytn.com/token) can be implemented here. For other KCT implementations can be found in the SDK references ([caver-js](https://docs.klaytn.com/dapp/sdk/caver-js/api-references/caver.kct), [caver-java](https://javadoc.io/doc/com.klaytn.caver/core/latest/index.html)).

#### Contract

Expand Down Expand Up @@ -1329,7 +1329,7 @@ More token standards defined in [KCT](http://kips.klaytn.com/token) can be imple
| name: String | The name of the function in a smart contract. |
| inputs: List&#60;[ContractIOType](#contractiotype)&#62; | The input values of the function. In the list, each parameter of the function is defined as ContractIOType. When the `call` or `send` function is called, this is used to encode the parameter to create the input field of a transaction. |
| outputs: List&#60;[ContractIOType](#contractiotype)&#62; | The output values of the function. This is used to decode the value returned as the result of executing the function. |
| signature: String | The [function signature](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.contract#cf-function-signature-function-selector) (function selector). The first four bytes of the input data for specifying the function to be called (or executed). It is the first (left, high-order in big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature of the function. |
| signature: String | The [function signature](https://docs.klaytn.com/dapp/sdk/caver-js/api-references/caver.contract#cf-function-signature-function-selector) (function selector). The first four bytes of the input data for specifying the function to be called (or executed). It is the first (left, high-order in big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature of the function. |
| nextMethods: List&#60;ContractMethod&#62; | nextMethods stores functions with the same name implemented in a smart contract. If the parameter passed by the user is different from the input of this contractMethod, it traverses the contractMethods defined in nextMethods to find the contractMethod to be called. |

##### Methods
Expand Down Expand Up @@ -1705,10 +1705,10 @@ Copyright and related rights waived via [CC0](https://creativecommons.org/public
[klaytn design - transactions]: https://docs.klaytn.com/klaytn/design/transactions
[kip-7]: ./kip-7.md
[kip-17]: ./kip-17.md
[klay]: https://docs.klaytn.com/bapp/json-rpc/api-references/klay
[klay namespace of the node api]: https://docs.klaytn.com/bapp/json-rpc/api-references/klay
[net]: https://docs.klaytn.com/bapp/json-rpc/api-references/network
[net namespace of the node api]: https://docs.klaytn.com/bapp/json-rpc/api-references/network
[json-rpc apis]: https://docs.klaytn.com/bapp/json-rpc/api-references
[klay_logs]: https://docs.klaytn.com/bapp/json-rpc/api-references/klay/filter#klay_getlogs
[klay_call]: https://docs.klaytn.com/bapp/json-rpc/api-references/klay/transaction#klay_call
[klay]: https://docs.klaytn.com/dapp/json-rpc/api-references/klay
[klay namespace of the node api]: https://docs.klaytn.com/dapp/json-rpc/api-references/klay
[net]: https://docs.klaytn.com/dapp/json-rpc/api-references/network
[net namespace of the node api]: https://docs.klaytn.com/dapp/json-rpc/api-references/network
[json-rpc apis]: https://docs.klaytn.com/dapp/json-rpc/api-references
[klay_logs]: https://docs.klaytn.com/dapp/json-rpc/api-references/klay/filter#klay_getlogs
[klay_call]: https://docs.klaytn.com/dapp/json-rpc/api-references/klay/transaction#klay_call
58 changes: 58 additions & 0 deletions KIPs/kip-68.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
kip: 68
title: Increase Gcallstipend gas in the CALL OPCODE
author: Jasper Lee <@astean1001>
discussions-to: https://github.com/klaytn/kips/issues/68
status: Draft
type: Standards Track
category: Core
created: 2022-03-15
---

## Simple Summary
Increase the Gcallstipend fee parameter in the CALL OPCODE from 2,300 to 3,500 gas units.

## Abstract
Currently, the CALL OPCODE forwards a stipend of 2,300 gas units for a non zero value CALL operations where a contract is called.
This stipend is given to the contract to allow execution of its fallback function.
The stipend given is intentionally small in order to prevent the called contract from spending the call gas or performing an attack (like re-entrancy).
While the stipend is small it should still give the sufficient gas required for some cheap OPCODES like LOG,
but it's not enough for some more complex and modern logics to be implemented.
This KIP proposes to increase the given stipend from 2,300 to 3,500 to increase the usability of the fallback function.

## Motivation
The main motivation behind this KIP is to allow simple fallback functions to be implemented for contracts following the "Proxy" pattern.
Simply explained, a "Proxy Contract" is a contract which use DELEGATECALL in its fallback function to behave according to the logic of
another contract and serve as an independent instance for the logic of the contract it points to.
This pattern is very useful for saving gas per deployment (as Proxy contracts are very lean) and
it opens the ability to experiment with upgradability of contracts.
On average, the DELEGATECALL functionality of a proxy contract costs about 1,000 gas units.
When a contract transfers KLAY to a proxy contract, the proxy logic will consume about 1,000 gas
units before the fallback function of the logic contract will be executed. This leaves merely about 1,300 gas units for the execution of the logic.
This is a severe limitation as it is not enough for an average LOG operation (it might be enough for a LOG with one parameter).
By slightly increasing the gas units given in the stipend we allow proxy contracts have proper fallback logic without increasing
the attack surface of the calling contract.

## Specification
Increase the Gcallstipend fee parameter in the CALL OPCODE from 2,300 to 3,500 gas units (further specification will be provided later).

## Rationale
The rational for increasing the Gcallstipend gas parameter by 1,200 gas units comes from the cost of performing DELEGATECALL 
and SLOAD with a small margin for some small additional operations. All while still keeping the stipend relatively small.

## Backwards Compatibility
This KIP requires a backwards incompatible change for the Gcallstipend gas parameter in the CALL OPCODE.

## Test Cases
Test case will be provided later

## Implementation
Implementation will be provided later

## Reference
- https://eips.ethereum.org/EIPS/eip-1285
- [Proxy Call Overhead](https://gist.github.com/GNSPS/ba7b88565c947cfd781d44cf469c2ddb#gistcomment-2383950)
- https://forum.klaytn.com/t/gas-fee-baobab-transfer/4364

## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).