8000 Add payable by cburgdorf · Pull Request #1340 · argotorg/fe · GitHub
[go: up one dir, main page]

Skip to content

Add payable#1340

Merged
sbillig merged 2 commits intoargotorg:masterfrom
cburgdorf:add_payable
Mar 20, 2026
Merged

Add payable#1340
sbillig merged 2 commits intoargotorg:masterfrom
cburgdorf:add_payable

Conversation

@cburgdorf
Copy link
Collaborator

Summary

This PR adds a #[payable] attribute for contract init blocks and recv arms, addressing two problems:

Safety: Fe contracts currently accept ETH silently on all entrypoints. Users can lose funds by sending ETH to functions that don't handle it. With #[payable], the compiler injects a CALLVALUE check that
reverts non-payable calls.

ABI correctness: Without an explicit payable signal, JSON ABI generation (planned in a follow-up) would have to mark every function as "stateMutability": "payable" — even pure views and read-only
accessors — since the compiler couldn't distinguish intent. With #[payable], the ABI can correctly derive "payable", "nonpayable", "view", and "pure", which is required for proper integration with
wallets, block explorers, and tools like Foundry or ethers.js.

What's included

  • Parser: Attribute lists are now parsed before init blocks and recv arms/blocks, with lookahead to distinguish field attributes from init/recv attributes
  • HIR: attributes field propagated on ContractInit and ContractRecvArm with is_payable() helpers
  • MIR: New IntrinsicOp::Callvalue wired through ir, fmt, escape analysis, intrinsics mapping, and both codegen backends (Sonatina + Yul)
  • MIR lowering: CALLVALUE != 0 → revert guards emitted in both lower_init_entrypoint and lower_runtime_entrypoint for non-payable entrypoints
  • Formatter: fe fmt preserves #[payable] placement on init and recv arms
  • Validation: Full diagnostic pipeline (PayableErrorPayableAttrPassDiagnosticVoucher) rejects #[payable] on unsupported items (fn, struct, enum, msg variant, recv block, const, extern fn,
    etc.) and malformed forms like #[payable(foo)] or #[payable = 1]
  • Test harness: RuntimeInstance::fund_contract() gives deployed test contracts ETH balance so tests can exercise payable semantics with non-zero value

Example

pub contract Vault {
    #[payable]
    init() {}

    recv VaultMsg {
        #[payable]
        Deposit {} { ... }          // accepts ETH → ABI: "payable"

        GetBalance {} -> u256 { 0 } // reverts if ETH sent → ABI: "pure"
    }
}

Test plan

- Non-payable recv arm works with zero value
- Non-payable recv arm reverts with non-zero value (should_revert)
- Payable recv arm works with zero value
- Payable recv arm accepts non-zero ETH
- Non-payable init reverts with non-zero value (should_revert)
- Payable init accepts non-zero ETH
- Contract without init deploys with zero value
- Contract without init reverts with non-zero value (should_revert)
- MIR snapshot verifies CALLVALUE guards present/absent as expected
- UI tests for #[payable] on unsupported items (fn, struct, enum, const, extern fn)
- UI tests for #[payable] on msg variant (targeted error message)
- UI tests for #[payable] on recv block (targeted error message)
- UI tests for malformed #[payable(foo)] and #[payable = 1]
- All existing tests pass (cargo test --workspace)

@cburgdorf cburgdorf marked this pull request as ready for review March 18, 2026 21:38
Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09eed45aca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09eed45aca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf cburgdorf marked this pull request as draft March 19, 2026 23:43
@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27431b53b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fdf84f7ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf cburgdorf force-pushed the add_payable branch 2 times, most recently from aad3577 to 3c97dcf Compare March 20, 2026 11:32
@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c97dcfc84

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfc6904e35

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74c51904d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4414f94e14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c26b8cbff7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18abf5740d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf
Copy link
Collaborator Author

@codex review

Copy link
@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0eccd92a61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Add a `#[payable]` attribute that explicitly opts contract init blocks
and recv arms into accepting ETH. Non-payable entrypoints now get a
compiler-injected CALLVALUE check that reverts when msg.value > 0,
preventing accidental fund loss.

- Parser: parse attribute lists before `init` and recv arm patterns,
  with lookahead to distinguish field attributes from init/recv attributes
- HIR: propagate `attributes` on ContractInit and ContractRecvArm,
  add `is_payable()` helpers
- MIR: add `IntrinsicOp::Callvalue` across ir, fmt, escape analysis,
  intrinsics mapping, and both codegen backends (Sonatina + Yul)
- MIR lowering: emit CALLVALUE != 0 → abort guards in both
  `lower_init_entrypoint` and `lower_runtime_entrypoint`
- Formatter: preserve `#[payable]` on init and recv arms
@cburgdorf
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cburgdorf cburgdorf marked this pull request as ready for review March 20, 2026 23:05
@cburgdorf cburgdorf requested a review from sbillig March 20, 2026 23:05
@sbillig sbillig merged commit 8389f9e into argotorg:master Mar 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0