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.
This commit is contained in:
parent
2cb87f4f8f
commit
42784965d2
|
@ -1320,116 +1320,84 @@ impl BuiltinCosts {
|
||||||
intercept: 0,
|
intercept: 0,
|
||||||
slope: 1,
|
slope: 1,
|
||||||
}),
|
}),
|
||||||
cpu: TwoArguments::AddedSizes(AddedSizes {
|
cpu: TwoArguments::MultipliedSizes(MultipliedSizes {
|
||||||
intercept: 90434,
|
intercept: 90434,
|
||||||
slope: 519,
|
slope: 519,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
// FIXME: Costing function for divide_integer has changed in v3
|
|
||||||
//
|
|
||||||
// "divideInteger-cpu-arguments-constant": 85848,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-c00": 123203,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-c01": 7305,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-c02": -900,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-c10": 1716,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-c11": 549,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-c20": 57,
|
|
||||||
// "divideInteger-cpu-arguments-model-arguments-minimum": 85848,
|
|
||||||
// "divideInteger-memory-arguments-intercept": 0,
|
|
||||||
// "divideInteger-memory-arguments-minimum": 1,
|
|
||||||
// "divideInteger-memory-arguments-slope": 1,
|
|
||||||
divide_integer: CostingFun {
|
divide_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
||||||
intercept: 0,
|
intercept: 0,
|
||||||
slope: 1,
|
slope: 1,
|
||||||
minimum: 1,
|
minimum: 1,
|
||||||
}),
|
}),
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
cpu: TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
constant: 196500,
|
85848,
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
TwoArgumentsQuadraticFunction {
|
||||||
intercept: 453240,
|
minimum: 85848,
|
||||||
slope: 220,
|
coeff_00: 123203,
|
||||||
})),
|
coeff_01: 7305,
|
||||||
}),
|
coeff_02: -900,
|
||||||
|
coeff_10: 1716,
|
||||||
|
coeff_11: 549,
|
||||||
|
coeff_20: 57,
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
// FIXME Costing function for quotient_integer has changed in v3
|
|
||||||
//
|
|
||||||
// "quotientInteger-cpu-arguments-constant": 85848,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-c00": 123203,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-c01": 7305,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-c02": -900,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-c10": 1716,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-c11": 549,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-c20": 57,
|
|
||||||
// "quotientInteger-cpu-arguments-model-arguments-minimum": 85848,
|
|
||||||
// "quotientInteger-memory-arguments-intercept": 0,
|
|
||||||
// "quotientInteger-memory-arguments-minimum": 1,
|
|
||||||
// "quotientInteger-memory-arguments-slope": 1,
|
|
||||||
quotient_integer: CostingFun {
|
quotient_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
||||||
intercept: 0,
|
intercept: 0,
|
||||||
slope: 1,
|
slope: 1,
|
||||||
minimum: 1,
|
minimum: 1,
|
||||||
}),
|
}),
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
cpu: TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
constant: 196500,
|
85848,
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
TwoArgumentsQuadraticFunction {
|
||||||
intercept: 453240,
|
minimum: 85848,
|
||||||
slope: 220,
|
coeff_00: 123203,
|
||||||
})),
|
coeff_01: 7305,
|
||||||
}),
|
coeff_02: -900,
|
||||||
|
coeff_10: 1716,
|
||||||
|
coeff_11: 549,
|
||||||
|
coeff_20: 57,
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
// FIXME Costing function for remainder_integer has changed in v3
|
|
||||||
//
|
|
||||||
// "remainderInteger-cpu-arguments-constant": 85848,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-c00": 123203,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-c01": 7305,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-c02": -900,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-c10": 1716,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-c11": 549,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-c20": 57,
|
|
||||||
// "remainderInteger-cpu-arguments-model-arguments-minimum": 85848,
|
|
||||||
// "remainderInteger-memory-arguments-intercept": 0,
|
|
||||||
// "remainderInteger-memory-arguments-slope": 1,
|
|
||||||
remainder_integer: CostingFun {
|
remainder_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: TwoArguments::LinearInY(LinearSize {
|
||||||
intercept: 0,
|
intercept: 0,
|
||||||
slope: 1,
|
slope: 1,
|
||||||
minimum: 1,
|
|
||||||
}),
|
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
|
||||||
constant: 196500,
|
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
|
||||||
intercept: 453240,
|
|
||||||
slope: 220,
|
|
||||||
})),
|
|
||||||
}),
|
}),
|
||||||
|
cpu: TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
|
85848,
|
||||||
|
TwoArgumentsQuadraticFunction {
|
||||||
|
minimum: 85848,
|
||||||
|
coeff_00: 123203,
|
||||||
|
coeff_01: 7305,
|
||||||
|
coeff_02: -900,
|
||||||
|
coeff_10: 1716,
|
||||||
|
coeff_11: 549,
|
||||||
|
coeff_20: 57,
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
// FIXME: Costing function for mod_integer has changed in v3
|
|
||||||
//
|
|
||||||
// "modInteger-cpu-arguments-constant": 85848,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-c00": 123203,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-c01": 7305,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-c02": -900,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-c10": 1716,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-c11": 549,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-c20": 57,
|
|
||||||
// "modInteger-cpu-arguments-model-arguments-minimum": 85848,
|
|
||||||
// "modInteger-memory-arguments-intercept": 0,
|
|
||||||
// "modInteger-memory-arguments-slope": 1,
|
|
||||||
mod_integer: CostingFun {
|
mod_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: TwoArguments::LinearInY(LinearSize {
|
||||||
intercept: 0,
|
intercept: 0,
|
||||||
slope: 1,
|
slope: 1,
|
||||||
minimum: 1,
|
|
||||||
}),
|
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
|
||||||
constant: 196500,
|
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
|
||||||
intercept: 453240,
|
|
||||||
slope: 220,
|
|
||||||
})),
|
|
||||||
}),
|
}),
|
||||||
|
cpu: TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
|
85848,
|
||||||
|
TwoArgumentsQuadraticFunction {
|
||||||
|
minimum: 85848,
|
||||||
|
coeff_00: 123203,
|
||||||
|
coeff_01: 7305,
|
||||||
|
coeff_02: -900,
|
||||||
|
coeff_10: 1716,
|
||||||
|
coeff_11: 549,
|
||||||
|
coeff_20: 57,
|
||||||
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
equals_integer: CostingFun {
|
equals_integer: CostingFun {
|
||||||
mem: TwoArguments::ConstantCost(1),
|
mem: TwoArguments::ConstantCost(1),
|
||||||
|
@ -1479,7 +1447,7 @@ impl BuiltinCosts {
|
||||||
}),
|
}),
|
||||||
cpu: ThreeArguments::LinearInZ(LinearSize {
|
cpu: ThreeArguments::LinearInZ(LinearSize {
|
||||||
intercept: 20467,
|
intercept: 20467,
|
||||||
slope: 0,
|
slope: 1,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
length_of_byte_string: CostingFun {
|
length_of_byte_string: CostingFun {
|
||||||
|
@ -1535,7 +1503,7 @@ impl BuiltinCosts {
|
||||||
},
|
},
|
||||||
verify_ed25519_signature: CostingFun {
|
verify_ed25519_signature: CostingFun {
|
||||||
mem: ThreeArguments::ConstantCost(10),
|
mem: ThreeArguments::ConstantCost(10),
|
||||||
cpu: ThreeArguments::LinearInZ(LinearSize {
|
cpu: ThreeArguments::LinearInY(LinearSize {
|
||||||
intercept: 53384111,
|
intercept: 53384111,
|
||||||
slope: 14333,
|
slope: 14333,
|
||||||
}),
|
}),
|
||||||
|
@ -3158,14 +3126,26 @@ pub fn initialize_cost_model(version: &Language, costs: &[i64]) -> CostModel {
|
||||||
.get("multiply_integer-mem-arguments-slope")
|
.get("multiply_integer-mem-arguments-slope")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
}),
|
}),
|
||||||
cpu: TwoArguments::AddedSizes(AddedSizes {
|
cpu: match version {
|
||||||
intercept: *cost_map
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
.get("multiply_integer-cpu-arguments-intercept")
|
TwoArguments::AddedSizes(AddedSizes {
|
||||||
.unwrap_or(&30000000000),
|
intercept: *cost_map
|
||||||
slope: *cost_map
|
.get("multiply_integer-cpu-arguments-intercept")
|
||||||
.get("multiply_integer-cpu-arguments-slope")
|
.unwrap_or(&30000000000),
|
||||||
.unwrap_or(&30000000000),
|
slope: *cost_map
|
||||||
}),
|
.get("multiply_integer-cpu-arguments-slope")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Language::PlutusV3 => TwoArguments::MultipliedSizes(MultipliedSizes {
|
||||||
|
intercept: *cost_map
|
||||||
|
.get("multiply_integer-cpu-arguments-intercept")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
slope: *cost_map
|
||||||
|
.get("multiply_integer-cpu-arguments-slope")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
}),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
divide_integer: CostingFun {
|
divide_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
||||||
|
@ -3179,19 +3159,51 @@ pub fn initialize_cost_model(version: &Language, costs: &[i64]) -> CostModel {
|
||||||
.get("divide_integer-mem-arguments-minimum")
|
.get("divide_integer-mem-arguments-minimum")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
}),
|
}),
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
cpu: match version {
|
||||||
constant: *cost_map
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
.get("divide_integer-cpu-arguments-constant")
|
TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
||||||
.unwrap_or(&30000000000),
|
constant: *cost_map
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
.get("divide_integer-cpu-arguments-constant")
|
||||||
intercept: *cost_map
|
.unwrap_or(&30000000000),
|
||||||
.get("divide_integer-cpu-arguments-model-arguments-intercept")
|
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
||||||
|
intercept: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-model-arguments-intercept")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
slope: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-model-arguments-slope")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Language::PlutusV3 => TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
|
*cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-constant")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
slope: *cost_map
|
TwoArgumentsQuadraticFunction {
|
||||||
.get("divide_integer-cpu-arguments-model-arguments-slope")
|
minimum: *cost_map
|
||||||
.unwrap_or(&30000000000),
|
.get("divide_integer-cpu-arguments-minimum")
|
||||||
})),
|
.unwrap_or(&30000000000),
|
||||||
}),
|
coeff_00: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-c00")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_10: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-c10")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_01: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-c01")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_20: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-c20")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_11: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-c11")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_02: *cost_map
|
||||||
|
.get("divide_integer-cpu-arguments-c02")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
quotient_integer: CostingFun {
|
quotient_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
||||||
|
@ -3205,71 +3217,193 @@ pub fn initialize_cost_model(version: &Language, costs: &[i64]) -> CostModel {
|
||||||
.get("quotient_integer-mem-arguments-minimum")
|
.get("quotient_integer-mem-arguments-minimum")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
}),
|
}),
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
cpu: match version {
|
||||||
constant: *cost_map
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
.get("quotient_integer-cpu-arguments-constant")
|
TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
||||||
.unwrap_or(&30000000000),
|
constant: *cost_map
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
.get("quotient_integer-cpu-arguments-constant")
|
||||||
intercept: *cost_map
|
.unwrap_or(&30000000000),
|
||||||
.get("quotient_integer-cpu-arguments-model-arguments-intercept")
|
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
||||||
|
intercept: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-model-arguments-intercept")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
slope: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-model-arguments-slope")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Language::PlutusV3 => TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
|
*cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-constant")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
slope: *cost_map
|
TwoArgumentsQuadraticFunction {
|
||||||
.get("quotient_integer-cpu-arguments-model-arguments-slope")
|
minimum: *cost_map
|
||||||
.unwrap_or(&30000000000),
|
.get("quotient_integer-cpu-arguments-minimum")
|
||||||
})),
|
.unwrap_or(&30000000000),
|
||||||
}),
|
coeff_00: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-c00")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_10: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-c10")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_01: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-c01")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_20: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-c20")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_11: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-c11")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_02: *cost_map
|
||||||
|
.get("quotient_integer-cpu-arguments-c02")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
remainder_integer: CostingFun {
|
remainder_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: match version {
|
||||||
intercept: *cost_map
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
.get("remainder_integer-mem-arguments-intercept")
|
TwoArguments::SubtractedSizes(SubtractedSizes {
|
||||||
.unwrap_or(&30000000000),
|
intercept: *cost_map
|
||||||
slope: *cost_map
|
.get("remainder_integer-mem-arguments-intercept")
|
||||||
.get("remainder_integer-mem-arguments-slope")
|
.unwrap_or(&30000000000),
|
||||||
.unwrap_or(&30000000000),
|
slope: *cost_map
|
||||||
minimum: *cost_map
|
.get("remainder_integer-mem-arguments-slope")
|
||||||
.get("remainder_integer-mem-arguments-minimum")
|
.unwrap_or(&30000000000),
|
||||||
.unwrap_or(&30000000000),
|
minimum: *cost_map
|
||||||
}),
|
.get("remainder_integer-mem-arguments-minimum")
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
.unwrap_or(&30000000000),
|
||||||
constant: *cost_map
|
})
|
||||||
.get("remainder_integer-cpu-arguments-constant")
|
}
|
||||||
.unwrap_or(&30000000000),
|
Language::PlutusV3 => TwoArguments::LinearInY(LinearSize {
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
|
||||||
intercept: *cost_map
|
intercept: *cost_map
|
||||||
.get("remainder_integer-cpu-arguments-model-arguments-intercept")
|
.get("remainder_integer-mem-arguments-intercept")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
slope: *cost_map
|
slope: *cost_map
|
||||||
.get("remainder_integer-cpu-arguments-model-arguments-slope")
|
.get("remainder_integer-mem-arguments-slope")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
})),
|
}),
|
||||||
}),
|
},
|
||||||
|
cpu: match version {
|
||||||
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
|
TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
||||||
|
constant: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-constant")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
||||||
|
intercept: *cost_map
|
||||||
|
.get(
|
||||||
|
"remainder_integer-cpu-arguments-model-arguments-intercept",
|
||||||
|
)
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
slope: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-model-arguments-slope")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Language::PlutusV3 => TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
|
*cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-constant")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
TwoArgumentsQuadraticFunction {
|
||||||
|
minimum: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-minimum")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_00: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-c00")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_10: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-c10")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_01: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-c01")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_20: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-c20")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_11: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-c11")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_02: *cost_map
|
||||||
|
.get("remainder_integer-cpu-arguments-c02")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mod_integer: CostingFun {
|
mod_integer: CostingFun {
|
||||||
mem: TwoArguments::SubtractedSizes(SubtractedSizes {
|
mem: match version {
|
||||||
intercept: *cost_map
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
.get("mod_integer-mem-arguments-intercept")
|
TwoArguments::SubtractedSizes(SubtractedSizes {
|
||||||
.unwrap_or(&30000000000),
|
intercept: *cost_map
|
||||||
slope: *cost_map
|
.get("mod_integer-mem-arguments-intercept")
|
||||||
.get("mod_integer-mem-arguments-slope")
|
.unwrap_or(&30000000000),
|
||||||
.unwrap_or(&30000000000),
|
slope: *cost_map
|
||||||
minimum: *cost_map
|
.get("mod_integer-mem-arguments-slope")
|
||||||
.get("mod_integer-mem-arguments-minimum")
|
.unwrap_or(&30000000000),
|
||||||
.unwrap_or(&30000000000),
|
minimum: *cost_map
|
||||||
}),
|
.get("mod_integer-mem-arguments-minimum")
|
||||||
cpu: TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
.unwrap_or(&30000000000),
|
||||||
constant: *cost_map
|
})
|
||||||
.get("mod_integer-cpu-arguments-constant")
|
}
|
||||||
.unwrap_or(&30000000000),
|
Language::PlutusV3 => TwoArguments::LinearInY(LinearSize {
|
||||||
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
|
||||||
intercept: *cost_map
|
intercept: *cost_map
|
||||||
.get("mod_integer-cpu-arguments-model-arguments-intercept")
|
.get("mod_integer-mem-arguments-intercept")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
slope: *cost_map
|
slope: *cost_map
|
||||||
.get("mod_integer-cpu-arguments-model-arguments-slope")
|
.get("mod_integer-mem-arguments-slope")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
})),
|
}),
|
||||||
}),
|
},
|
||||||
|
cpu: match version {
|
||||||
|
Language::PlutusV1 | Language::PlutusV2 => {
|
||||||
|
TwoArguments::ConstAboveDiagonal(ConstantOrTwoArguments {
|
||||||
|
constant: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-constant")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
model: Box::new(TwoArguments::MultipliedSizes(MultipliedSizes {
|
||||||
|
intercept: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-model-arguments-intercept")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
slope: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-model-arguments-slope")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Language::PlutusV3 => TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(
|
||||||
|
*cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-constant")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
TwoArgumentsQuadraticFunction {
|
||||||
|
minimum: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-minimum")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_00: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-c00")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_10: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-c10")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_01: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-c01")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_20: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-c20")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_11: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-c11")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
coeff_02: *cost_map
|
||||||
|
.get("mod_integer-cpu-arguments-c02")
|
||||||
|
.unwrap_or(&30000000000),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
equals_integer: CostingFun {
|
equals_integer: CostingFun {
|
||||||
mem: TwoArguments::ConstantCost(
|
mem: TwoArguments::ConstantCost(
|
||||||
|
@ -3493,14 +3627,21 @@ pub fn initialize_cost_model(version: &Language, costs: &[i64]) -> CostModel {
|
||||||
.get("verify_ed25519_signature-mem-arguments")
|
.get("verify_ed25519_signature-mem-arguments")
|
||||||
.unwrap_or(&30000000000),
|
.unwrap_or(&30000000000),
|
||||||
),
|
),
|
||||||
cpu: ThreeArguments::LinearInZ(LinearSize {
|
cpu: {
|
||||||
intercept: *cost_map
|
let sizes = LinearSize {
|
||||||
.get("verify_ed25519_signature-cpu-arguments-intercept")
|
intercept: *cost_map
|
||||||
.unwrap_or(&30000000000),
|
.get("verify_ed25519_signature-cpu-arguments-intercept")
|
||||||
slope: *cost_map
|
.unwrap_or(&30000000000),
|
||||||
.get("verify_ed25519_signature-cpu-arguments-slope")
|
slope: *cost_map
|
||||||
.unwrap_or(&30000000000),
|
.get("verify_ed25519_signature-cpu-arguments-slope")
|
||||||
}),
|
.unwrap_or(&30000000000),
|
||||||
|
};
|
||||||
|
|
||||||
|
match version {
|
||||||
|
Language::PlutusV1 | Language::PlutusV2 => ThreeArguments::LinearInZ(sizes),
|
||||||
|
Language::PlutusV3 => ThreeArguments::LinearInY(sizes),
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
verify_ecdsa_secp256k1_signature: CostingFun {
|
verify_ecdsa_secp256k1_signature: CostingFun {
|
||||||
mem: ThreeArguments::ConstantCost(
|
mem: ThreeArguments::ConstantCost(
|
||||||
|
@ -4238,6 +4379,7 @@ pub enum TwoArguments {
|
||||||
ConstAboveDiagonal(ConstantOrTwoArguments),
|
ConstAboveDiagonal(ConstantOrTwoArguments),
|
||||||
ConstBelowDiagonal(ConstantOrTwoArguments),
|
ConstBelowDiagonal(ConstantOrTwoArguments),
|
||||||
QuadraticInY(QuadraticFunction),
|
QuadraticInY(QuadraticFunction),
|
||||||
|
ConstAboveDiagonalIntoQuadraticXAndY(i64, TwoArgumentsQuadraticFunction),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TwoArguments {
|
impl TwoArguments {
|
||||||
|
@ -4275,6 +4417,21 @@ impl TwoArguments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TwoArguments::QuadraticInY(q) => q.coeff_0 + (q.coeff_1 * y) + (q.coeff_2 * y * y),
|
TwoArguments::QuadraticInY(q) => q.coeff_0 + (q.coeff_1 * y) + (q.coeff_2 * y * y),
|
||||||
|
TwoArguments::ConstAboveDiagonalIntoQuadraticXAndY(constant, q) => {
|
||||||
|
if x < y {
|
||||||
|
*constant
|
||||||
|
} else {
|
||||||
|
std::cmp::max(
|
||||||
|
q.minimum,
|
||||||
|
q.coeff_00
|
||||||
|
+ q.coeff_10 * x
|
||||||
|
+ q.coeff_01 * y
|
||||||
|
+ q.coeff_20 * x * x
|
||||||
|
+ q.coeff_11 * x * y
|
||||||
|
+ q.coeff_02 * y * y,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4380,6 +4537,17 @@ pub struct QuadraticFunction {
|
||||||
coeff_2: i64,
|
coeff_2: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
pub struct TwoArgumentsQuadraticFunction {
|
||||||
|
minimum: i64,
|
||||||
|
coeff_00: i64,
|
||||||
|
coeff_10: i64,
|
||||||
|
coeff_01: i64,
|
||||||
|
coeff_20: i64,
|
||||||
|
coeff_11: i64,
|
||||||
|
coeff_02: i64,
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum StepKind {
|
pub enum StepKind {
|
||||||
Constant = 0,
|
Constant = 0,
|
||||||
|
|
|
@ -63,8 +63,8 @@ pub enum Error {
|
||||||
Utf8(#[from] FromUtf8Error),
|
Utf8(#[from] FromUtf8Error),
|
||||||
#[error("Out of Bounds\n\nindex: {}\nbytestring: {}\npossible: 0 - {}", .0, hex::encode(.1), .1.len() - 1)]
|
#[error("Out of Bounds\n\nindex: {}\nbytestring: {}\npossible: 0 - {}", .0, hex::encode(.1), .1.len() - 1)]
|
||||||
ByteStringOutOfBounds(BigInt, Vec<u8>),
|
ByteStringOutOfBounds(BigInt, Vec<u8>),
|
||||||
#[error("Attempt to consByteString something bigger than one byte {0}")]
|
#[error("Attempt to consByteString something than isn't a byte between [0-255]: {0}")]
|
||||||
ByteStringConsBiggerThanOneByte(BigInt),
|
ByteStringConsNotAByte(BigInt),
|
||||||
#[error("Divide By Zero\n\n{0} / {1}")]
|
#[error("Divide By Zero\n\n{0} / {1}")]
|
||||||
DivideByZero(BigInt, BigInt),
|
DivideByZero(BigInt, BigInt),
|
||||||
#[error("Ed25519S PublicKey should be 32 bytes but it was {0}")]
|
#[error("Ed25519S PublicKey should be 32 bytes but it was {0}")]
|
||||||
|
|
|
@ -485,8 +485,8 @@ impl DefaultFunction {
|
||||||
wrap.try_into().unwrap()
|
wrap.try_into().unwrap()
|
||||||
}
|
}
|
||||||
BuiltinSemantics::V2 => {
|
BuiltinSemantics::V2 => {
|
||||||
if *arg1 > 255.into() {
|
if *arg1 > 255.into() || *arg1 < 0.into() {
|
||||||
return Err(Error::ByteStringConsBiggerThanOneByte(arg1.clone()));
|
return Err(Error::ByteStringConsNotAByte(arg1.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
arg1.try_into().unwrap()
|
arg1.try_into().unwrap()
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
use std::{ops::Neg, rc::Rc, str::FromStr};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Constant, Name, Program, Term, Type},
|
ast::{Constant, Name, Program, Term, Type},
|
||||||
builtins::DefaultFunction,
|
builtins::DefaultFunction,
|
||||||
machine::runtime::Compressable,
|
machine::{runtime::Compressable, value::to_pallas_bigint},
|
||||||
machine::value::to_pallas_bigint,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use interner::Interner;
|
use interner::Interner;
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
use pallas_primitives::alonzo::PlutusData;
|
use pallas_primitives::alonzo::PlutusData;
|
||||||
use peg::{error::ParseError, str::LineCol};
|
use peg::{error::ParseError, str::LineCol};
|
||||||
|
use std::{ops::Neg, rc::Rc, str::FromStr};
|
||||||
|
|
||||||
pub mod interner;
|
pub mod interner;
|
||||||
|
|
||||||
|
@ -195,10 +192,10 @@ peg::parser! {
|
||||||
= n:$(['0'..='9']+) {? n.parse().or(Err("usize")) }
|
= n:$(['0'..='9']+) {? n.parse().or(Err("usize")) }
|
||||||
|
|
||||||
rule number() -> isize
|
rule number() -> isize
|
||||||
= n:$("-"* ['0'..='9']+) {? n.parse().or(Err("isize")) }
|
= n:$(("-"/"+")* ['0'..='9']+) {? n.parse().or(Err("isize")) }
|
||||||
|
|
||||||
rule big_number() -> BigInt
|
rule big_number() -> BigInt
|
||||||
= n:$("-"* ['0'..='9']+) {? (if n.starts_with('-') { BigInt::parse_bytes(&n.as_bytes()[1..], 10).map(|i| i.neg()) } else { BigInt::parse_bytes(n.as_bytes(), 10) }).ok_or("BigInt") }
|
= n:$(("-"/"+")* ['0'..='9']+) {? (if n.starts_with('-') { BigInt::parse_bytes(&n.as_bytes()[1..], 10).map(|i| i.neg()) } else { BigInt::parse_bytes(n.as_bytes(), 10) }).ok_or("BigInt") }
|
||||||
|
|
||||||
rule boolean() -> bool
|
rule boolean() -> bool
|
||||||
= b:$("True" / "False") { b == "True" }
|
= b:$("True" / "False") { b == "True" }
|
||||||
|
@ -375,11 +372,12 @@ peg::parser! {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::{
|
||||||
|
ast::{Constant, Name, Program, Term, Type, Unique},
|
||||||
|
builtins::DefaultFunction,
|
||||||
|
};
|
||||||
use num_bigint::BigInt;
|
use num_bigint::BigInt;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use crate::ast::{Constant, Name, Program, Term, Type, Unique};
|
|
||||||
use crate::builtins::DefaultFunction;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -94,8 +94,13 @@ fn plutus_conformance_tests(language: Language) {
|
||||||
match eval {
|
match eval {
|
||||||
Ok((actual, cost)) => {
|
Ok((actual, cost)) => {
|
||||||
pretty_assertions::assert_eq!(expected, Ok(actual), "{}", path.display());
|
pretty_assertions::assert_eq!(expected, Ok(actual), "{}", path.display());
|
||||||
if let Ok(budget) = file_to_budget(&expected_budget_file) {
|
match language {
|
||||||
pretty_assertions::assert_eq!(budget, cost, "{}", path.display());
|
Language::PlutusV1 | Language::PlutusV2 => {}
|
||||||
|
Language::PlutusV3 => {
|
||||||
|
if let Ok(budget) = file_to_budget(&expected_budget_file) {
|
||||||
|
pretty_assertions::assert_eq!(budget, cost, "{}", path.display());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => pretty_assertions::assert_eq!(expected, Err(err), "{}", path.display()),
|
Err(err) => pretty_assertions::assert_eq!(expected, Err(err), "{}", path.display()),
|
||||||
|
|
Loading…
Reference in New Issue