Skip to content

Commit

Permalink
CIP-145: Fix Incorrect Receipts upon NotEnoughBalance Error (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenxingLi authored May 17, 2024
1 parent 902769c commit 5f9343b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions CIPs/cip-145.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
CIP No.: 145
Title: Fix Receipts upon `NotEnoughBalance` Error
Author: Chenxing Li (@ChenxingLi)
Status: Draft
Type: Spec Breaking
Created: 2024-05-16
---

## Simple Summary
Correct the `gas_sponsored` field when a transaction fails due to the sender not having enough balance.

## Abstract
If user A is sponsored by contract B and initiates a transaction to contract B, but it fails due to insufficient balance to cover the transaction value, user A must pay the transaction fee, not the contract, even if sponsored.

At the Conflux mainnet launch, this behavior was correct. However, [CIP-78](cip-78.md) unintentionally affected this case while fixing other receipt errors, causing the `gas_sponsored` field to incorrectly show as true in such cases.

This CIP will correct this error.

## Motivation
Bug fix.

## Specification

**Definition: sender_intended_cost.** The `sender_intended_cost` is defined as the anticipated expense the sender should foresee. It consists of three parts:
1. Transaction transferred balance.
2. Gas cost (tx.price * tx.gas_limit, with effective_gas_price replacing gas_price after CIP-1559), which is 0 if the sender is eligible for as sponsorship.
3. Storage collateral cost, which is 0 if the sender is eligible for storage collateral sponsorship.

In the current Conflux mainnet, if at the start of transaction execution the sender's balance is insufficient to cover the sender_intended_cost, the sender's nonce is incremented by 1, the sender pays the gas cost (if the balance is insufficient, the entire balance is deducted), and no storage collateral cost is incurred. This CIP will correct the `gas_sponsored` field from `true` to `false` in such cases.

## Rationale
N/A

## Backwards Compatibility
This CIP is Spec Breaking.

## Test Cases
<!--Test cases for an implementation are mandatory for CIPs that are affecting consensus changes. Other CIPs can choose to include links to test cases if applicable.-->
N/A

## Implementation
<!--The implementations must be completed before any CIP is given status "Final", but it need not be completed before the CIP is accepted. While there is merit to the approach of reaching consensus on the specification and rationale before writing code, the principle of "rough consensus and running code" is still useful when it comes to resolving many discussions of API details.-->
N/A

## Security Considerations
<!--All CIPs must contain a section that discusses the security implications/considerations relevant to the proposed change. Include information that might be important for security discussions, surfaces risks and can be used throughout the life cycle of the proposal. E.g. include security-relevant design decisions, concerns, important discussions, implementation-specific guidance and pitfalls, an outline of threats and risks and how they are being addressed. CIP submissions missing the "Security Considerations" section will be rejected. a CIP cannot proceed to status "Final" without a Security Considerations discussion deemed sufficient by the reviewers.-->
N/A

## Copyright
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ These CIPs are either in the midst of active development or have been fully deve
| [142](CIPs/cip-142.md) | Transient Storage Opcodes | Draft |
| [143](CIPs/cip-143.md) | `MCOPY (0x5e)` Opcode for Efficient Memory Copy | Draft |
| [144](CIPs/cip-144.md) | Point Evaluation Precompile from EIP-4844 | Draft |
| [145](CIPs/cip-145.md) | Fix Receipts upon `NotEnoughBalance` Error | Draft |
| [1559](CIPs/cip-1559.md) | Fee market change for Conflux | Developed |

### Activated
Expand Down

0 comments on commit 5f9343b

Please sign in to comment.