Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Introduces V2 programs. #2634

Open
wants to merge 5 commits into
base: feat/cycle-protections
Choose a base branch
from

Conversation

d0cd
Copy link
Collaborator

@d0cd d0cd commented Mar 6, 2025

This PR introduces the syntax for V2 programs.
At a high level, V2 programs:

  • start with a program$2 keyword
  • allow struct, record, mapping, function, closure, and import.
  • introduce an optional constructor via the _init keyword. Constructors must be specified after the above constructs.
  • introduce user-defined $metadata to the program. Metadata must be specified after the constructor.

Here is an example of a V2 program.

import eth.aleo;
import usdc.aleo;

program$2 swap.aleo;

function swap:
    input r0 as eth.aleo/eth.record;
    input r1 as usdc.aleo/usdc.record;
    call eth.aleo/transfer r0 r1.owner r0.amount into r2 r3;
    call usdc.aleo/transfer r1 r0.owner r1.amount into r4 r5;
    output r2 as eth.aleo/eth.record;
    output r4 as usdc.aleo/usdc.record;

_init:
    assert.eq true true;
    
$metadata edition: 0u8;
$metadata owner: aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px;
$metadata upgradable: false;

The implementation for V2 programs will be included in a following PR.

Testing

  • Regressions checking that V1 programs still (de)serialize correctly can be found here under test_program_serde

@d0cd d0cd mentioned this pull request Mar 6, 2025
2 tasks
@d0cd d0cd requested review from raychu86 and vicsn March 7, 2025 03:40
@vicsn vicsn requested a review from kpandl March 10, 2025 13:46
#[test]
fn test_bytes() -> Result<()> {
let program = r"
program$2 token.aleo;
Copy link
Collaborator

@vicsn vicsn Mar 10, 2025

Choose a reason for hiding this comment

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

From my humble POV, I'm not a fan of adding a new symbol $ to the syntax - even if we don't typically expose aleo instructions to end users. Also because it doesn't work the same way like it does in the other syntax everyone knows (shell scripts).

  • For program version: what about a new keyword like version which we declare after import and before program? Related: I think metadata.version in the PR description should be changed to metadata.edition.
  • For metadata we could simply drop the $.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't have strong opinions here. I'll leave it to the reviewers to arbitrate on syntax.
FWIW, I feel like the version keyword doesn't create enough of a conceptual separation but I can be convinced if I stare at some programs long enough.

@d0cd d0cd requested a review from vicsn March 10, 2025 16:06
@d0cd d0cd force-pushed the feat/cycle-protections branch from 674c7e2 to ef33b61 Compare March 11, 2025 16:41
@d0cd d0cd force-pushed the feat/program-v2 branch from c07406c to 4406ae0 Compare March 11, 2025 16:57
@d0cd d0cd force-pushed the feat/cycle-protections branch from ef33b61 to aa91004 Compare March 11, 2025 17:04
@d0cd d0cd force-pushed the feat/program-v2 branch from 4406ae0 to bdde292 Compare March 11, 2025 17:09
@d0cd d0cd force-pushed the feat/cycle-protections branch from aa91004 to 2250f82 Compare March 11, 2025 19:44
@d0cd d0cd force-pushed the feat/program-v2 branch from 4ff96ef to 7f6a901 Compare March 11, 2025 19:48
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