IntersectMBO / IntersectMBO/plutus
Add builtins: `assert`, `assertOrTrace`, `assertAndContinue` and `assertAndContinueOrTrace`
- Dominant language
- Haskell
- Stars
- 1.6k
- Forks
- 508
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 22
Description
### Describe the feature you'd like
since plutus V3 scripts are forced to return a `unit` to be considered succesful, and in reality this was already considered standard for plutus V1 and V2, but not enforced.
Despite UPLC being functional, there are 2 side effects that can be triggered: tracing and throwing an error.
on a higher level, most languages will instead allow to write contracts that return booleans, and even in the languages who don't the developer will write the logic using booleans and finally convert to a unit.
today to convert from booleans to unit, a function like the one below is used (`ifThenElse` is a variable, assuming the compiler hoisted the forced builtin)
```
(lam bool_var
(force
[
[
[
ifThenElse
bool_var
]
(delay (con unit ()))
]
(delay (error))
]
)
)
```
because this is such a common operation a few new builtins could be introduced
```haskell
assert :: bool -> unit
assertOrTrace :: string -> bool -> unit
assertAndContinue :: bool -> a -> a
assertAndContinueOrTrace :: string -> bool -> a -> a
```
`assert` would act as the uplc function above
`OrTrace` variants would take a string as first parameter, potentially to take advantage of partial function applications, and in case of error it would add the string to the traces of the contract exectuting before failing.
`AndContinue` variants are polymorphic in the return type, so that these can be used to assert properties before execution of other parts of the contract
for example
```
(force
[
[
(force (builtin assertAndContinue))
someCondition
]
(delay
continuation_body
)
]
)
```
if the implementation of `AndContinue` variants would make it so that the polymorphic argument is not strictly evaluated by default (given the nature of the builtin) it would make it an even better tool!
for example, the uplc below would behave the same exact way of the uplc above:
```
[
[
(force (builtin assertAndContinue))
someCondition
]
continuation_body
]
```
### Describe alternatives you've considered
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.