From 2a747305f77ab3f5983b957f87ae11b15a0be167 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 5 Jul 2023 18:52:14 +0200 Subject: [PATCH] Fixes evaluation of large positive bigint in the UPLC machine Fixes #511. --- crates/uplc/src/machine/value.rs | 6 ++-- examples/acceptance_tests/087/aiken.lock | 13 +++++++++ examples/acceptance_tests/087/aiken.toml | 8 ++++++ examples/acceptance_tests/087/lib/tests.ak | 9 ++++++ examples/acceptance_tests/087/plutus.json | 32 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 examples/acceptance_tests/087/aiken.lock create mode 100644 examples/acceptance_tests/087/aiken.toml create mode 100644 examples/acceptance_tests/087/lib/tests.ak create mode 100644 examples/acceptance_tests/087/plutus.json diff --git a/crates/uplc/src/machine/value.rs b/crates/uplc/src/machine/value.rs index 45a7d363..dcefaed6 100644 --- a/crates/uplc/src/machine/value.rs +++ b/crates/uplc/src/machine/value.rs @@ -316,10 +316,8 @@ pub fn from_pallas_bigint(n: &pallas::BigInt) -> BigInt { } pub fn to_pallas_bigint(n: &BigInt) -> pallas::BigInt { - if n.bits() <= 64 { - let regular_int: i64 = n.try_into().unwrap(); - let pallas_int: pallas_codec::utils::Int = regular_int.into(); - + if let Ok(i) = <&BigInt as TryInto>::try_into(n) { + let pallas_int: pallas_codec::utils::Int = i.into(); pallas::BigInt::Int(pallas_int) } else if n.is_positive() { let (_, bytes) = n.to_bytes_be(); diff --git a/examples/acceptance_tests/087/aiken.lock b/examples/acceptance_tests/087/aiken.lock new file mode 100644 index 00000000..0423f31b --- /dev/null +++ b/examples/acceptance_tests/087/aiken.lock @@ -0,0 +1,13 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +[[requirements]] +name = "aiken-lang/stdlib" +version = "main" +source = "github" + +[[packages]] +name = "aiken-lang/stdlib" +version = "main" +requirements = [] +source = "github" diff --git a/examples/acceptance_tests/087/aiken.toml b/examples/acceptance_tests/087/aiken.toml new file mode 100644 index 00000000..c2c9c00d --- /dev/null +++ b/examples/acceptance_tests/087/aiken.toml @@ -0,0 +1,8 @@ +name = "aiken-lang/acceptance_test_087" +version = "0.0.0" +description = "" + +[[dependencies]] +name = 'aiken-lang/stdlib' +version = 'main' +source = 'github' diff --git a/examples/acceptance_tests/087/lib/tests.ak b/examples/acceptance_tests/087/lib/tests.ak new file mode 100644 index 00000000..0c11a588 --- /dev/null +++ b/examples/acceptance_tests/087/lib/tests.ak @@ -0,0 +1,9 @@ +use aiken/cbor.{diagnostic, serialise} + +test cbor_serialise_large_num() { + serialise(18446744073709551615) == #"c248ffffffffffffffff" +} + +test cbor_diagnostic_large_num() { + diagnostic(18446744073709551615) == @"18446744073709551615" +} diff --git a/examples/acceptance_tests/087/plutus.json b/examples/acceptance_tests/087/plutus.json new file mode 100644 index 00000000..415663f0 --- /dev/null +++ b/examples/acceptance_tests/087/plutus.json @@ -0,0 +1,32 @@ +{ + "preamble": { + "title": "aiken-lang/acceptance_test_086", + "version": "0.0.0", + "plutusVersion": "v2" + }, + "validators": [ + { + "title": "other.validate", + "datum": { + "title": "raw_datum", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "redeemer": { + "title": "_redeemer", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "5901fd01000032323232323232323232222533300832323232533300c3370e9000000899251300a00214a06014002601c002600e008664464a66601666e1d20000011323253330103012002132498c94ccc038cdc3a400000226464a666026602a0042649319299980899b87480000044c8c94ccc058c0600084c9263253330143370e9000000899191919299980d980e8010991924c64a66603466e1d200000113232533301f3021002132498c94ccc074cdc3a400000226464a666044604800426493180b8008b1811000980d8010a99980e99b87480080044c8c8c8c8c8c94ccc098c0a000852616375a604c002604c0046eb4c090004c090008dd69811000980d8010b180d8008b180f800980c0018a99980d19b874800800454ccc074c06000c52616163018002301000316301b001301b00230190013012002163012001163016001300f00216300f001163013001300c0021533300e3370e90010008a99980898060010a4c2c2c60180022c602000260120042c6012002464a66601466e1d200000113232533300f3011002149858dd7180780098040010a99980519b87480080044c8c94ccc03cc04400852616375c601e00260100042c60100020062930b19800800a40004444666600e66e1c00400c02c8cccc014014cdc000224004601a0020040044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba15745", + "hash": "6a76fed919611638154fbaf78bd7a37f98b77e42eebc615f2d2d0f32" + } + ], + "definitions": { + "Data": { + "title": "Data", + "description": "Any Plutus data." + } + } +} \ No newline at end of file