aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
477 stars 94 forks source link

`to_ex_mem` wrong for `Constant::ByteString` #58

Closed christianschmitz closed 2 years ago

christianschmitz commented 2 years ago

According to https://github.com/input-output-hk/plutus/blob/master/plutus-core/plutus-core/src/PlutusCore/Evaluation/Machine/ExMemory.hs, lines 217-221, a zero-length bytestring should have ex_mem size of 0. It also states that truncating division should be avoided because ex_mem would be 1 in that case (truncates from -1/8 to 0, then adds 1).

In aiken, crates/uplc/src/machine.rs, truncating division is however used, thus giving a wrong result for this edge case.

I suggest checking for zero-length bytestrings, and returning 0 explicitly in that edge case. (similar to the if-else expression for Constant::Integer)

rvcas commented 2 years ago

closed by #50