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

Add delimited continuations to UPLC #6772

Open
effectfully opened this issue Jan 4, 2025 · 0 comments
Open

Add delimited continuations to UPLC #6772

effectfully opened this issue Jan 4, 2025 · 0 comments

Comments

@effectfully
Copy link
Contributor

This is proposed by @SebastienGllmt and elaborated on by @colll78, whom I'm quoting verbatim:

"let's consider that if somebody shows us what exactly it's supposed to improve"

I think Sebastien Guillemot did so quite eloquently with his provided example:

*createFiniteMint() -> Generator<Bool> {
  const maxSupply = 10_000;
  for (let supply = 0; supply < maxSupply; supply++) {
    yield true; // yielding ends this UTXO and creates a new UTXO with the rest of the continuation
  }
  // here the function ends, which consumed the UTXO forever
}
 
function* mint10nfts() {
   for (let i = 0; i < 10; i++) {
       yield mintUtxo // this is the NFT mint script above
   }
}

If you look at how the same script is implemented in the original EUTxO paper it's significantly more painful from both an onchain and offchain code perspective (albeit the design of this script in that paper is not what anyone would use in production).

To do this in plutus you would need the following scripts:

  1. Minting Policy for state thread NFT
  2. Spending Policy for the state UTxO
  3. Minting Policy for the capped minting policy (mints up to N tokens).

Which you would then use as:

  1. Mint state thread NFT and put it into output with datum that keeps track of the total minted.
  2. Spend the state UTxO from spending script back to spending script.
    a. Check that the remaining canBeMinted amount in the state UTxO's datum is greater than or equal to the amount minted.
    b. Check that the output state UTxO datum canBeMinted is equal to the input state amount datum canBeMinted minus the minted amount.
    c. Check that the state thread NFT is included in the continuing output.

Clearly there is a lot more boilerplate than the delimited continuations example, but there is a lot of nuance in that boilerplate, and especially for non-trivial examples I fail to see how the checks above can be easily abstracted away without significant sacrifices in efficiency.

To be honest, I'm not sure how the example delimited continuations code would uniquely identify the state UTxO or handle the other required checks that I mentioned above. I assume it would just compile to UPLC that adds the checks for the state NFT (as the Plinth state machine used to), but if that's the case then that is where the hidden complexity of this solution lies, because generating such code efficiently is the biggest challenge of these types of abstractions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant