Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

Commit 1f63dec

Browse files
committed
fix: remaining cost models (mod integer)
Also, separate the extra conformance tsts to avoid accidentally overriding them when re-generating new tests."
1 parent da76072 commit 1f63dec

20 files changed

Lines changed: 137 additions & 42 deletions

crates/uplc/src/machine/cost_model/builtin_costs/builtin_costs_v3.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ impl Default for BuiltinCostsV3 {
169169
),
170170
mod_integer: TwoArgumentsCosting::new(
171171
TwoArgumentsCosting::linear_in_y(0, 1),
172-
TwoArgumentsCosting::above_and_below_diagonal_into_quadratic_x_and_y(
173-
85848, 123203, 7305, -900, 1716, 960, 57,
172+
TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y(
173+
85848, 85848, 123203, 7305, -900, 1716, 960, 57,
174174
),
175175
),
176176
equals_integer: TwoArgumentsCosting::new(
@@ -782,7 +782,8 @@ impl BuiltinCostModel for BuiltinCostsV3 {
782782
cost_map["mod_integer-mem-arguments-intercept"],
783783
cost_map["mod_integer-mem-arguments-slope"],
784784
),
785-
TwoArgumentsCosting::above_and_below_diagonal_into_quadratic_x_and_y(
785+
TwoArgumentsCosting::const_above_diagonal_into_quadratic_x_and_y(
786+
cost_map["mod_integer-cpu-arguments-constant"],
786787
cost_map["mod_integer-cpu-arguments-minimum"],
787788
cost_map["mod_integer-cpu-arguments-c00"],
788789
cost_map["mod_integer-cpu-arguments-c01"],

crates/uplc/src/machine/cost_model/costing.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pub enum TwoArguments {
7272
ConstAboveDiagonalIntoQuadraticXAndY(i64, TwoArgumentsQuadraticFunction),
7373
ConstAboveDiagonalIntoMultipliedSizes(i64, MultipliedSizes),
7474
WithInteraction(WithInteraction),
75-
AboveAndBelowDiagonalIntoQuadraticXAndY(TwoArgumentsQuadraticFunction),
7675
}
7776

7877
pub type TwoArgumentsCosting = Costing<2, TwoArguments>;
@@ -155,27 +154,6 @@ impl TwoArgumentsCosting {
155154
})
156155
}
157156

158-
#[allow(clippy::too_many_arguments)]
159-
pub fn above_and_below_diagonal_into_quadratic_x_and_y(
160-
minimum: i64,
161-
coeff_00: i64,
162-
coeff_01: i64,
163-
coeff_02: i64,
164-
coeff_10: i64,
165-
coeff_11: i64,
166-
coeff_20: i64,
167-
) -> TwoArguments {
168-
TwoArguments::AboveAndBelowDiagonalIntoQuadraticXAndY(TwoArgumentsQuadraticFunction {
169-
minimum,
170-
coeff_00,
171-
coeff_01,
172-
coeff_02,
173-
coeff_10,
174-
coeff_11,
175-
coeff_20,
176-
})
177-
}
178-
179157
pub fn const_above_diagonal_into_multiplied_sizes(
180158
constant: i64,
181159
intercept: i64,
@@ -237,19 +215,6 @@ impl Cost<2> for TwoArguments {
237215
}
238216
}
239217
TwoArguments::WithInteraction(w) => w.c00 + w.c10 * x + w.c01 * y + w.c11 * x * y,
240-
TwoArguments::AboveAndBelowDiagonalIntoQuadraticXAndY(q) => {
241-
let max_arg = x.max(y);
242-
let min_arg = x.min(y);
243-
std::cmp::max(
244-
q.minimum,
245-
q.coeff_00
246-
+ q.coeff_10 * max_arg
247-
+ q.coeff_01 * min_arg
248-
+ q.coeff_20 * max_arg * max_arg
249-
+ q.coeff_11 * max_arg * min_arg
250-
+ q.coeff_02 * min_arg * min_arg,
251-
)
252-
}
253218
}
254219
}
255220
}

crates/uplc/src/syn/term.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub fn builtin_from_str<'a>(arena: &'a Arena, name: &str) -> Option<&'a Term<'a,
212212
"blake2b_256" => Some(Term::blake2b_256(arena)),
213213
"keccak_256" => Some(Term::keccak_256(arena)),
214214
"blake2b_224" => Some(Term::blake2b_224(arena)),
215-
"verifyEd25519Signature" => Some(Term::verify_ed25519_signature(arena)),
215+
"verifySignature" | "verifyEd25519Signature" => Some(Term::verify_ed25519_signature(arena)),
216216
"verifyEcdsaSecp256k1Signature" => Some(Term::verify_ecdsa_secp256k1_signature(arena)),
217217
"verifySchnorrSecp256k1Signature" => Some(Term::verify_schnorr_secp256k1_signature(arena)),
218218
"appendString" => Some(Term::append_string(arena)),

crates/uplc/tests/conformance/textual/builtin/semantics/equalsByteString/v3-off-diagonal-intercept/v3-off-diagonal-intercept.uplc.budget.expected

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
use amaru_uplc::{
2+
arena::Arena,
3+
machine::{ExBudget, PlutusVersion},
4+
syn::parse_program,
5+
};
6+
7+
const EXTRA_V3_COSTS: &[i64] = &[
8+
100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4, 16000, 100,
9+
16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100, 16000, 100, 94375, 32,
10+
132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189, 769, 4, 2, 85848, 123203, 7305, -900,
11+
1716, 549, 57, 85848, 0, 1, 1, 1000, 42921, 4, 2, 24548, 29498, 38, 1, 898148, 27279, 1, 51775,
12+
558, 1, 39184, 1000, 60594, 1, 141895, 32, 83150, 32, 15299, 32, 76049, 1, 13169, 4, 22100, 10,
13+
28999, 74, 1, 28999, 74, 1, 43285, 552, 1, 44749, 541, 1, 33852, 32, 68246, 32, 72362, 32,
14+
7243, 32, 7391, 32, 11546, 32, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 90434,
15+
519, 0, 1, 74433, 32, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 85848, 123203,
16+
7305, -900, 1716, 549, 57, 85848, 0, 1, 955506, 213312, 0, 2, 270652, 22588, 4, 1457325, 64566,
17+
4, 20467, 1, 4, 0, 141992, 32, 100788, 420, 1, 1, 81663, 32, 59498, 32, 20142, 32, 24588, 32,
18+
20744, 32, 25933, 32, 24623, 32, 43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, 16000,
19+
100, 16000, 100, 962335, 18, 2780678, 6, 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006,
20+
8868, 18, 52948122, 18, 1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, 36, 284546, 36,
21+
158221314, 26549, 36, 74698472, 36, 333849714, 1, 254006273, 72, 2174038, 72, 2261318, 64571,
22+
4, 207616, 8310, 4, 1293828, 28716, 63, 0, 1, 1006041, 43623, 251, 0, 1, 100181, 726, 719, 0,
23+
1, 100181, 726, 719, 0, 1, 100181, 726, 719, 0, 1, 107878, 680, 0, 1, 95336, 1, 281145, 18848,
24+
0, 1, 180194, 159, 1, 1, 158519, 8942, 0, 1, 159378, 8813, 0, 1, 107490, 3298, 1, 106057, 655,
25+
1, 1964219, 24520, 3,
26+
];
27+
28+
fn run_conformance_with_params(file_contents: &str, expected_output: &str, expected_budget: &str) {
29+
let arena = Arena::new();
30+
31+
let Ok(program) = parse_program(&arena, file_contents).into_result() else {
32+
pretty_assertions::assert_eq!("parse error", expected_output.trim_end());
33+
pretty_assertions::assert_eq!("parse error", expected_budget.trim_end());
34+
return;
35+
};
36+
37+
let result = program.eval_with_params(
38+
&arena,
39+
PlutusVersion::V3,
40+
EXTRA_V3_COSTS,
41+
ExBudget::default(),
42+
);
43+
44+
let info = result.info;
45+
46+
let Ok(term) = result.term else {
47+
pretty_assertions::assert_eq!("evaluation failure", expected_output.trim_end());
48+
pretty_assertions::assert_eq!("evaluation failure", expected_budget.trim_end());
49+
return;
50+
};
51+
52+
let expected = parse_program(&arena, expected_output)
53+
.into_result()
54+
.unwrap();
55+
56+
pretty_assertions::assert_eq!(expected.term, term);
57+
58+
let consumed_budget = format!(
59+
"({{cpu: {}\n| mem: {}}})",
60+
info.consumed_budget.cpu, info.consumed_budget.mem
61+
);
62+
63+
pretty_assertions::assert_eq!(consumed_budget, expected_budget.trim_end());
64+
}
65+
66+
macro_rules! regression_case {
67+
($name:ident, $path:literal) => {
68+
#[test]
69+
fn $name() {
70+
run_conformance_with_params(
71+
include_str!($path),
72+
include_str!(concat!($path, ".expected")),
73+
include_str!(concat!($path, ".budget.expected")),
74+
);
75+
}
76+
};
77+
}
78+
79+
regression_case!(
80+
builtin_semantics_divideinteger_v3_below_diagonal_constant_regression,
81+
"conformance_extra/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc"
82+
);
83+
regression_case!(
84+
builtin_semantics_divideinteger_v3_diagonal_c11_regression,
85+
"conformance_extra/textual/builtin/semantics/divideInteger/v3-diagonal-c11/v3-diagonal-c11.uplc"
86+
);
87+
regression_case!(
88+
builtin_semantics_modinteger_v3_below_diagonal_constant_regression,
89+
"conformance_extra/textual/builtin/semantics/modInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc"
90+
);
91+
regression_case!(
92+
builtin_semantics_equalsbytestring_v3_off_diagonal_intercept_regression,
93+
"conformance_extra/textual/builtin/semantics/equalsByteString/v3-off-diagonal-intercept/v3-off-diagonal-intercept.uplc"
94+
);
95+
regression_case!(
96+
builtin_semantics_verifysignature_legacy_alias_test_vector_25_regression,
97+
"conformance_extra/textual/builtin/semantics/verifySignature/legacy-alias-test-vector-25/legacy-alias-test-vector-25.uplc"
98+
);

crates/uplc/tests/conformance/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc renamed to crates/uplc/tests/conformance_extra/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc

File renamed without changes.

crates/uplc/tests/conformance/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc.budget.expected renamed to crates/uplc/tests/conformance_extra/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc.budget.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
({cpu: 165948
2-
| mem: 601})
2+
| mem: 601})

crates/uplc/tests/conformance/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc.expected renamed to crates/uplc/tests/conformance_extra/textual/builtin/semantics/divideInteger/v3-below-diagonal-constant/v3-below-diagonal-constant.uplc.expected

File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(program 1.0.0
2+
[
3+
[
4+
(builtin divideInteger)
5+
(con integer 1)
6+
]
7+
(con integer 1)
8+
]
9+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
({cpu: 212030
2+
| mem: 601})

0 commit comments

Comments
 (0)