Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenwang1996 committed Mar 18, 2024
1 parent bdedc83 commit 8b39ab5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions neps/nep-0536.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ Refund receipts create nontrivial overhead: they need to be merklized and sent a

## Specification

Pessimistic gas pricing is removed as a part of this change. This means that transactions that do not involve function calls will not generate gas refund receipts as a result. For function calls, this proposal changes the gas refund to be
Pessimistic gas pricing is removed as a part of this change. This means that transactions that do not involve function calls will not generate gas refund receipts as a result. For function calls, this proposal introduces cost of refund to be
```

Check failure on line 24 in neps/nep-0536.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines [Context: "```"]

neps/nep-0536.md:24 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

Check failure on line 24 in neps/nep-0536.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should have a language specified [Context: "```"]

neps/nep-0536.md:24 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
refund = max(0, gas_refund - 5Tgas);
REFUND_FIXED_COST = action_receipt_creation + action_transfer + action_add_function_call_key
refund_cost = max(REFUND_FIXED_COST, 0.05 * gas_refund);
```

Check failure on line 27 in neps/nep-0536.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Fenced code blocks should be surrounded by blank lines [Context: "```"]

neps/nep-0536.md:27 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
per receipt. In other words, for each gas refund, there is a 5Tgas penalty that is applied. The penalty is added to gas burnt. This means that for receipts that involve gas refund less than 5Tgas, there will be no gas refunds.
per receipt. The refund fixed cost includes consideration for implicit accounts (created on transfer) and refund for access key allowance, which requires an access key update. The design of refund cost is supposed to penalize developers from attaching too much gas
and creating unnecessary refunds. Some examples:
* If the contract wants to refund 280Tgas, burning 5% of it would be about 14Tgas, which is a significant cost and developers would be encouraged to optimize it on the frontend.

Check failure on line 30 in neps/nep-0536.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Lists should be surrounded by blank lines [Context: "* If the contract wants to ref..."]

neps/nep-0536.md:30 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "* If the contract wants to ref..."]
* If refund is 100Tgas, then 5% is 5Tgas, which is still significant and discourages developers from doing so.
* If the refund is <10Tgas (very common case for cross-contract call self-callbacks), the penalty should be just 500Ggas, which is less than the gas refund cost. So only the fixed refund cost will be charged from gas to spawn the gas refund receipt. No UX will be broken for legacy cross-contract call contracts, so long as frontend correctly estimates the required gas in worst case scenario.


## Reference Implementation

The protocol changes are as follows:
* When a transaction is converted to a receipt, there is no longer a `pessmistic_gas_price` multiplier when the signer balance is deducted. Instead, the signer is charged `transaction_gas_cost * gas_price`. There is no gas refund for actions other than function calls.

Check failure on line 38 in neps/nep-0536.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Lists should be surrounded by blank lines [Context: "* When a transaction is conver..."]

neps/nep-0536.md:38 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "* When a transaction is conver..."]
* For function calls, if X gas is attached during the execution of a receipt and Y gas is burnt, then max(0, X-Y-5Tgas) is refunded at the original gas price.
* For function calls, if X gas is attached during the execution of a receipt and Y gas is burnt, then `max(0, X-Y-refund_cost)` is refunded at the original gas price where `refund_cost = max(REFUND_FIXED_COST, 0.05 * X-Y)`.
* Tokens burnt on refund cost is counted towards tx_balance_burnt and the part over `REFUND_FIXED_COST` is not counted towards gas limit to avoid artificially limiting throughput.
* Because refund cost is now separate, action costs do not need to account for refund and therefore should be recalculated and reduced.

## Security Implications

Expand All @@ -43,7 +51,7 @@ The approach outlined in this proposal has less impact on developer and user exp

## Future possibilities

Burning all prepaid gas is a natural extension to this proposal, which would completely get rid of gas refunds. This, however, would be a major change to the developer experience of NEAR and should be treated cautiously.
* Burning all prepaid gas is a natural extension to this proposal, which would completely get rid of gas refunds. This, however, would be a major change to the developer experience of NEAR and should be treated cautiously.
At the very least, developers should be able to easily estimate how much gas a function within a smart contract is going to consume during execution.

## Consequences
Expand All @@ -64,8 +72,7 @@ At the very least, developers should be able to easily estimate how much gas a f

### Backwards Compatibility

This proposal changes how gas refund works today and as a result, users may need to pay slightly more when they send a function call transaction. However, the difference is quite small (0.0005N at most).

Developers may need to change the amount of gas they attach when they write client side code that interacts with smart contracts to avoid getting penalized. However, this is not too difficult to do.

## Changelog

Expand Down

0 comments on commit 8b39ab5

Please sign in to comment.