@@ -65,7 +65,7 @@ https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transact
6565During the first pass (` apply_transaction_first_pass ` ), the payment transaction:
6666
67671 . ** Validates the fee payer account**
68- - Checks account exists
68+ - Checks account exists (transaction rejected if it doesn't)
6969 - Verifies sufficient balance for fee
7070 - Validates nonce matches
7171
@@ -91,9 +91,23 @@ The second pass finalizes the transaction after SNARK proof verification.
9191
9292## Account creation
9393
94+ ### Fee payer account must exist
95+
96+ The fee payer (sender) account ** must already exist** in the ledger. If it
97+ doesn't exist, the transaction is rejected with error "The fee-payer account
98+ does not exist".
99+
100+ <!-- CODE_REFERENCE: ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs#L1341-L1343 -->
101+
102+ ``` rust reference title="ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs"
103+ https : // github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs#L1341-L1343
104+ ```
105+
106+ ### Receiver account creation
107+
94108If the receiver account doesn't exist, a new account is created automatically.
95109The account creation fee (1 MINA by default) is deducted from the amount being
96- transferred:
110+ transferred to the receiver :
97111
98112``` rust
99113// Constraint constants
@@ -103,7 +117,7 @@ account_creation_fee: 1_000_000_000 // 1 MINA in nanomina
103117** Example:**
104118
105119- Sender sends 10 MINA to a new account with 1 MINA fee
106- - Sender pays: ` 10 MINA + 1 MINA (fee) + 1 MINA (account creation) = 12 MINA `
120+ - Sender pays: ` 10 MINA + 1 MINA (fee) = 11 MINA `
107121- Receiver gets: ` 10 MINA - 1 MINA (account creation) = 9 MINA `
108122
109123## Balance constraints
@@ -113,10 +127,19 @@ account_creation_fee: 1_000_000_000 // 1 MINA in nanomina
113127The sender must have sufficient balance to cover:
114128
115129```
116- sender_balance >= amount + fee + (account_creation_fee if creating account)
130+ sender_balance >= amount + fee
117131```
118132
119- If insufficient, the transaction fails with error: ` "insufficient funds" `
133+ Note: The account creation fee (if needed) is deducted from the amount being
134+ transferred to the receiver, not charged to the sender.
135+
136+ If the sender has insufficient funds, the transaction fails. The exact error
137+ depends on whether the sender can pay the fee:
138+
139+ - If sender cannot pay fee: Transaction rejected with "insufficient funds"
140+ (ledger unchanged)
141+ - If sender can pay fee but not amount: Fee charged, then error
142+ "Source_insufficient_balance" (payment not transferred)
120143
121144### Receiver balance limits
122145
@@ -208,13 +231,17 @@ assert_eq!(
208231
209232## Fee calculation
210233
211- Users should calculate required funds as:
234+ Users should calculate required sender balance as:
212235
213236``` rust
214- let required_balance = if receiver_exists {
215- amount + fee
237+ // Sender must have enough for amount + fee
238+ let required_sender_balance = amount + fee ;
239+
240+ // Receiver will get amount minus account creation fee (if account is new)
241+ let receiver_will_get = if receiver_exists {
242+ amount
216243} else {
217- amount + fee + account_creation_fee
244+ amount - account_creation_fee
218245};
219246```
220247
@@ -233,11 +260,13 @@ Comprehensive tests are available in
233260` tests/test_transaction_logic_first_pass.rs ` :
234261
235262- ` test_apply_payment_success ` - Successful payment between existing accounts
236- - ` test_apply_payment_creates_account ` - Payment creating a new account
237- - ` test_apply_payment_insufficient_balance ` - Insufficient funds error
263+ - ` test_apply_payment_creates_receiver_account ` - Payment creating new receiver
264+ account
265+ - ` test_apply_payment_insufficient_balance ` - Insufficient funds for payment
266+ (fee charged)
238267- ` test_apply_payment_invalid_nonce ` - Nonce mismatch error
239- - ` test_apply_payment_nonexistent_source ` - Nonexistent sender error
240- - ` test_apply_payment_receiver_overflow ` - Receiver balance overflow error
268+ - ` test_apply_payment_nonexistent_fee_payer ` - Nonexistent sender error
269+ (transaction rejected)
241270
242271## Related files
243272
0 commit comments