Commit Graph

601 Commits

Author SHA1 Message Date
KtorZ 53af366b59
Ensure uniqueness of intermediate variables in expect_type_assign
For recursive structures like Tuples, the span itself isn't enough to
  ensure uniqueness of elements (in particular tuples) holding elements
  of the same type.
2024-09-01 18:10:15 +02:00
KtorZ cd0a9440e8
Allow any expression as constants
This is only a start. It compiles, but with a few TODOs left open. In particular, it doesn't currently handle constants depending on other constants or functions; nor does it hoist constants.
2024-08-29 16:24:12 +02:00
KtorZ c21466831c
Bump versions to 1.1.0, in anticipation. 2024-08-29 09:12:37 +02:00
KtorZ d74e36d0bc
Introduce 'Never' type as a safe alternative to always None options
Unfortunately, as documented in:

  https://github.com/IntersectMBO/cardano-ledger/issues/4571

  Some Option fields in the script context certificates are going to
  remain set to None, at least until the next Hard fork. There's a risk
  that people permanently lock their funds if they expect deposits on
  registration credentials to ever be `Some`.

  So, we introduce a special type that emulate an `Option` that can only
  ever be `None`. We call it `Never` and it is the first type of this
  kind (i.e. with constructors indexes not starting at 0).
2024-08-27 14:40:39 +02:00
KtorZ af9a785d65
Provide default annotation to validators (incl. fallback)
Without that, we may encounter weird error messages when writing
  validators without an explicit `else`. Since we automatically fill it
  with a `fail`; without annotation, it unifies to a generic parameter.

  The existing check that would look for the body being an error term is
  ill-advised as it doesn't work as soon as one adds tracing, or make
  the validator a parameterized validator. Plus, it may simply trigger
  the wrong behavior as one can now annotate a validator with _whatever_
  and get pass the type-checker by plucking a `fail` keyword as body.
2024-08-25 17:12:11 +02:00
KtorZ 0c9ea196be
Format uplc crate 2024-08-25 16:20:45 +02:00
KtorZ 5943d94c6c
Finish re-working machine errors display. 2024-08-25 16:20:06 +02:00
rvcas e174532bfd
chore: add more redacted values to machine errors 2024-08-25 16:20:05 +02:00
KtorZ 823492c27b
Adjust v3 script context end-to-end tests to work with new syntax. 2024-08-25 16:20:04 +02:00
jmhrpr c98e32d3e9
optional costmodel in eval p2 raw 2024-08-24 18:28:08 +02:00
KtorZ 8dfaa1bf90
Fix parsing of v3 cost model
Closes #1002.
2024-08-24 18:26:37 +02:00
KtorZ 9aa9070f56
Revise desugaring following feedback
- We now consistently desugar an expect in the last position as
    `Void`. Regardless of the pattern. Desugaring to a boolean value is
    deemed too confusing.

  - This commit also removes the desugaring for let-binding. It's only
    ever allowed for _expect_ which then behaves like a side effect.

  - We also now allow tests to return either `Bool` or `Void`. A test
    that returns `Void` is treated the same as a test returning `True`.
2024-08-23 16:04:40 +02:00
KtorZ 0f905045e7
Rename mk_nil_data, mk_pair_data & mk_nil_pair_data builtins. 2024-08-23 10:39:37 +02:00
KtorZ 42784965d2
Implement new costing function for {divide,quotient,mod,remainder}_integer
As well as fixing a couple of other issues thanks to conformance
  tests. Some functions like multiply_integer or verify_ed25519_signature
  have also slightly changed their costing function.
2024-08-14 02:50:05 +02:00
KtorZ 2cb87f4f8f
Add PlutusV3 conformance tests and also control budgets
There were some odd discrepancy for `integerToByteString` on the mem
  side. Either 1 or about 1000 mem units off; which I couldn't quite
  figure out. Yet, it proves useful to validate builtin at large and
  ensure we have a valid cost model for v3.
2024-08-14 02:42:04 +02:00
KtorZ f879f6d183
Fix script context translations for withdrawals and validity intervals. 2024-08-13 23:43:47 +02:00
KtorZ 7501538053
Add script context translations for voting purpose. 2024-08-13 16:24:01 +02:00
KtorZ bfc93bf076
Add script context translation for new Conway certificates 2024-08-13 10:56:29 +02:00
KtorZ f244b9c496
Add support for protocol parameters (except cost models)
We can now simulate transactions with protocol parameters voting
  procedures. Cost models remain to be done, though.
2024-08-13 10:56:29 +02:00
KtorZ cfca0da4e9
Add (partial) support for simulating contract with proposal procedures
This covers every proposal procedures but protocol parameters, this
  one is yet to be done. It spans over 30+ fields, and felt like it is a
  big enough piece to tackle it on its own.
2024-08-13 10:56:29 +02:00
KtorZ 6b6bace8a5
test 'mint' purpose and script context creation.
Alongside a bunch of other stuff from the coverage list. In
  particular, the mint transaction contains:

  - reference inputs
  - multiple outputs, with assets, and type-0, type-1 and type-6
    addresses.
  - an output with a datum hash
  - an output with an inline script
  - carries an extra datum witness, preimage of the embedded hash
  - mint, with 2 policies purposely ordered wrongly, with 1 and 2
    assets purposely ordered wrong. One of the mint is actually a
    burn (i.e. negative quantity)
2024-08-13 10:56:29 +02:00
KtorZ eea8dc7d0a
Support multi-validator in script context accept test. 2024-08-13 10:56:28 +02:00
KtorZ b158469144
Improve / fix machine and uplc error reporting. 2024-08-13 10:56:28 +02:00
KtorZ 62b1b932f9
Write down first e2e script context test for v3. 2024-08-13 10:56:28 +02:00
KtorZ 821f7bd8c7
Fix ToPlutusData serializer for V3
This is intense, as we still want to preserve the serializer for V1 &
  V2, and I've tried as much as possible to avoid polluting the
  application layer with many enum types such as:

  ```
  pub enum TxOut {
    V1(TransactionOutput),
    V2(TransactionOutput),
    V3(TransactionOutput),
  }
  ```

  Those types make working with the script context cumbersome, and are
  only truly required to provide different serialisation strategies. So
  instead, we keep one top-level `TxInfo V1/V2/V3` type, and we ensure
  to pass serialization strategies as type wrappers.

  This way, the strategy propagates through the structure up until it's
  eliminated when it reaches the relevant types.

  All-in-all, this strikes a correct balance between maintainability and
  repetition; and it makes it possible to define _different but mostly
  identical_ encoders for the various versions.

  With it, I've been able to successfully encode a V3 script context and
  match it against one produced using the Haskell libraries. More to
  come.
2024-08-13 10:55:23 +02:00
KtorZ f848bad3f2
define UPLC machine default cost models for Plutus V3. 2024-08-13 10:55:23 +02:00
KtorZ fdf7a81288
implement a strict subset of PlutusV3 transaction info
More specifically, that is simply mimicking the script context from
  v2, minus the new governance features.
2024-08-13 10:55:23 +02:00
KtorZ c454dc72eb
Actually decode Conway transaction in 'aiken tx simulate' 2024-08-13 10:55:22 +02:00
KtorZ 508d88035b
Fix Plutus v3 validator hash calculation in blueprint. 2024-08-13 10:55:22 +02:00
KtorZ 445ffc483d
Further remove todos for v3, and reduce duplication in transaction evaluation 2024-08-13 10:55:22 +02:00
KtorZ ff4a480242
Upgrade pallas to v0.0.29, and start support for simulating transactions carrying Plutus v3 scripts. 2024-08-13 10:55:22 +02:00
microproofs 6fd9b34b92 Running examples as doc tests is not gonna work 2024-08-08 00:39:44 -04:00
microproofs 53c461294b Fix example that was throwing an error 2024-08-08 00:39:44 -04:00
microproofs 31627897d7 Fix example that was throwing an error 2024-08-08 00:39:44 -04:00
microproofs 8a461d5bd5 Few minor changes, clippy fixes, and test fixes 2024-08-08 00:39:44 -04:00
microproofs d7e9fef4d3 Create new helper functions to take care of force and delaying branch terms 2024-08-08 00:39:44 -04:00
KtorZ 23a3134642 Rework choose_data_xxx API to include force/delay inside functions. 2024-08-08 00:39:44 -04:00
KtorZ 021679b8ac Force unwrap_xxx_or inside function body
Otherwise, it becomes the responsibility of the caller to force the result; which may be easily forgotten.
2024-08-08 00:39:44 -04:00
microproofs a132a2e486 Fix unwrap issues 2024-08-08 00:39:44 -04:00
KtorZ 93a141bfa4 Test and fix 'unwrap_void_or' 2024-08-08 00:39:44 -04:00
KtorZ 49ddcccd12 Revert checking for negative constr on bool
It is impossible to serialize/deserialize a Data with a negative
  constructor. So the only way this can happen is by programmatically
  construct a value using builtin constr_data.

  While possible, it is entirely at the responsibility of the
  programmer, but not malleable from an attacker who can only provide
  values as 'Data' (and thus, must be decoded like others).
2024-08-08 00:39:44 -04:00
KtorZ aefbc6e1b9 Define a safer API for unwrap_xxx_or and choose_data_xxx
Cloning a 'Term' is potentially dangerous, so we don't want this to
  happen by mistake. So instead, we pass in var names and turn them into
  terms when necessary.
2024-08-08 00:39:44 -04:00
KtorZ 846c16087e Test (and fix) unwrap_or helpers. 2024-08-08 00:39:44 -04:00
KtorZ ea8003af8f Fix bool soft-casting.
While the ledger doesn't allow deserializing negative constr value,
  they are still possible at the machine level. So, we better make sure
  that we don't make assumptions regarding this.
2024-08-08 00:39:44 -04:00
KtorZ 9610237616 Refactor unknown_data_to_type, break down into smaller functions. 2024-08-08 00:39:44 -04:00
KtorZ c3a61706b5 Factor out common UPLC logic for converting Data to Bool. 2024-08-08 00:39:44 -04:00
microproofs 0be5229f1c Only 2 errors and todos left to finish 2024-08-08 00:39:44 -04:00
KtorZ 4645257e62
Prune pallas dependencies.
Using 'pallas' as a dependency brings utxo-rpc other annoying dependencies such as _tokyo_. This not only makes the overall build longer, but it also prevents it to even work when targetting wasm.
2024-08-03 14:14:49 +02:00
KtorZ 643e43f8aa Fix zero-arg builtins invokations.
There are currently two zero-arg builtins:

  - mkNilData
  - mkNilPairData

  And while they have strictly speaking no arguments, the VM still
  requires that they are called with an extra unit argument applied.
2024-08-02 00:17:16 -04:00
KtorZ b28d4a6e9f
Add input reference to ReferenceInputNotFound error.
Fixes #974.
2024-08-01 15:29:39 +02:00