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

Plutus v3 #83

Merged
merged 29 commits into from
Aug 28, 2024
Merged

Plutus v3 #83

merged 29 commits into from
Aug 28, 2024

Conversation

logicalmechanism
Copy link
Contributor

Beginning of the v2 to v3 transition. This branch is pure Plutus V3. It contains breaking changes.

Each new type needs a review and double check but it at least lays down the groundwork for this transition.

New types are generated from: v1.22.1.0 Context

I tried to group types where they should be going so some movement might be needed.

@logicalmechanism
Copy link
Contributor Author

logicalmechanism commented Mar 1, 2024

test validator for sancho net:

validator {
  fn params(_datum: Void, _redeemer: Void, context: ScriptContext) -> Bool {
    when context.purpose is {
      Spend(_) -> {
       let d = #"97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"
        let g1 = builtin.bls12_381_g1_uncompress(d)
        let x = g1 |> builtin.bls12_381_g1_compress
        x == d
      }
      _ -> False
    }
  }
}

Should be able to compile the script, create a reference script utxo, and spend into and out of that contract.
aiken --version
aiken v1.0.24-alpha+d698f76

Copy link
Member

@KtorZ KtorZ left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for doing this. I have made a few naming suggestion essentially trying to explicit some of the guidelines / conventions that we've been following in the standard library.

I'd be nice to get also extend those acceptance tests here: https://github.com/aiken-lang/aiken/tree/main/examples/acceptance_tests/script_context with Conway transactions, though this requires having already updated Aiken's simulate command and internals with the ability to create full Plutus V3 script contexts. In the meantime, using Ogmios for evaluating transactions is a viable option.

.github/workflows/continuous-integration.yml Outdated Show resolved Hide resolved
lib/aiken/transaction.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/certificate.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/certificate.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/credential.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/governance.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/governance.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/governance.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/governance.ak Outdated Show resolved Hide resolved
lib/aiken/transaction/governance.ak Outdated Show resolved Hide resolved
@MicroProofs MicroProofs mentioned this pull request Mar 3, 2024
52 tasks
@logicalmechanism
Copy link
Contributor Author

With Aiken 1.0.26, the use of the Dict type was discouraged.

https://github.com/logicalmechanism/stdlib/blob/plutus-v3/lib/aiken/transaction.ak#L67-L87

Does this mean all of these Dicts should be turned into lists of tuples too? like List<(x,y)> @KtorZ

@KtorZ
Copy link
Member

KtorZ commented Apr 7, 2024

With Aiken 1.0.26, the use of the Dict type was discouraged.

Not really. It wasn't discourage, but simply made safer. We will still use Dict in the standard library in places that make sense. But We'll also use type Map<k, v> = List<Pair<k, v>> in other places as soon as the new Pair type lands in.

@logicalmechanism
Copy link
Contributor Author

With Aiken 1.0.26, the use of the Dict type was discouraged.

Not really. It wasn't discourage, but simply made safer. We will still use Dict in the standard library in places that make sense. But We'll also use type Map<k, v> = List<Pair<k, v>> in other places as soon as the new Pair type lands in.

Well when the Pair type comes out in 1.0.27 I think I will revisit this and see what to change or update. I am attempting to use this branch on SanchoNet with some interesting errors so I was assuming something may be went wrong because of the Dict type.

@logicalmechanism
Copy link
Contributor Author

New types are generated from: v1.30.0.0 Context.

Key changes:

ScriptContext using ScriptInfo now and has the redeemer field.

There are naming conflicts introduced here so to avoid any issues, the ScriptPurpose uses the verb form of the action and the ScriptInfo will use the present tense verb form.

The new types need an additional review due to the introduction of Pair/Pairs type. I want to make sure everything still agrees with the current branch of both the stdlib and plutus.

logicalmechanism and others added 21 commits August 9, 2024 17:41
ChangedParameters -> ChangedProtocolParameters

Co-authored-by: Matthias Benkort <[email protected]>
ParameterChange -> ProtocolParameterChange

Co-authored-by: Matthias Benkort <[email protected]>
return_addr -> return_address

Co-authored-by: Matthias Benkort <[email protected]>
constitution -> guardrails

Co-authored-by: Matthias Benkort <[email protected]>
KtorZ added 6 commits August 10, 2024 23:45
  Unfortunately, we cannot simply map those as a large record because it
  is encoded as a cbor Map, and not as a constructor. We can't also just
  provide it as a Dict or Pairs because the resulting types are:

  (1) non-canonical (rationales are encoded as arrays instead of a
  constructor with two fields, unlike in other places....)

  (2) heterogeneous (protocol parameters have different types).

  Providing accessors like so will play nicely with future updates as
  well. One big downside: we traverse the map for every access x_x ...

  In the long-run, we might to provide some method to fold over
  parameters and traverse the map only _once_. This would require to
  temporarily store parameters inside an ADT which users can
  pattern-match on at the call site.

  ```
  pub fn fold(self, zero: b, with: fn(ProtocolParameter, b) -> b) -> b {
    ...
  }

  pub type ProtocolParameter {
    MinFeeCoefficient(Int),
    MinFeeConstant(Int),
    ...
  }
  ```

  This would provide some kind of optimal traversal of the parameters,
  modulo the creation of the intermediate ADT. Having the ability to use
  case/constr here would be nice.
@KtorZ KtorZ merged commit a010169 into aiken-lang:main Aug 28, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ In Next Release
Development

Successfully merging this pull request may close these issues.

2 participants