Skip to content

Commit 8667336

Browse files
committed
Merge remote-tracking branch 'origin/ruslan/language-encoding-fix' into babbage
2 parents cec2dd7 + be172e5 commit 8667336

File tree

5 files changed

+69
-10
lines changed

5 files changed

+69
-10
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "11.0.0-rc.6",
3+
"version": "11.0.0-rc.8",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack) && npm run js:flowgen",

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "11.0.0-rc.6"
3+
version = "11.0.0-rc.8"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"

rust/src/plutus.rs

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,9 @@ impl Costmdls {
283283
if l.kind() == LanguageKind::PlutusV1 {
284284
let mut serializer = Serializer::new_vec();
285285
serializer.write_bytes(l.to_bytes()).unwrap();
286-
serializer.finalize().len()
287-
} else {
288-
l.to_bytes().len()
286+
return serializer.finalize().len();
289287
}
288+
l.to_bytes().len()
290289
}
291290
let mut keys: Vec<Language> = self.0.iter().map(|(k, _v)| k.clone()).collect();
292291
// keys must be in canonical ordering first
@@ -313,9 +312,7 @@ impl Costmdls {
313312
serializer.serialize(self.0.get(&key).unwrap()).unwrap();
314313
}
315314
}
316-
let out = serializer.finalize();
317-
println!("language_views = {}", hex::encode(out.clone()));
318-
out
315+
serializer.finalize()
319316
}
320317
}
321318

@@ -1596,4 +1593,66 @@ mod tests {
15961593
let costmodels = TxBuilderConstants::plutus_vasil_cost_models();
15971594
assert_eq!(costmodels, Costmdls::from_bytes(costmodels.to_bytes()).unwrap());
15981595
}
1596+
1597+
#[test]
1598+
fn test_known_plutus_data_hash() {
1599+
use crate::tx_builder_constants::TxBuilderConstants;
1600+
let pdata = PlutusList::from(vec![
1601+
PlutusData::new_constr_plutus_data(
1602+
&ConstrPlutusData::new(
1603+
&BigNum::zero(),
1604+
&PlutusList::from(vec![
1605+
PlutusData::new_constr_plutus_data(
1606+
&ConstrPlutusData::new(
1607+
&BigNum::zero(),
1608+
&PlutusList::from(vec![
1609+
PlutusData::new_bytes(hex::decode("A183BF86925F66C579A3745C9517744399679B090927B8F6E2F2E1BB").unwrap()),
1610+
PlutusData::new_bytes(hex::decode("6164617065416D616E734576616E73").unwrap())
1611+
]),
1612+
),
1613+
),
1614+
PlutusData::new_constr_plutus_data(
1615+
&ConstrPlutusData::new(
1616+
&BigNum::zero(),
1617+
&PlutusList::from(vec![
1618+
PlutusData::new_bytes(hex::decode("9A4E855293A0B9AF5E50935A331D83E7982AB5B738EA0E6FC0F9E656").unwrap()),
1619+
PlutusData::new_bytes(hex::decode("4652414D455F38333030325F4C30").unwrap())
1620+
]),
1621+
),
1622+
),
1623+
PlutusData::new_bytes(hex::decode("BEA1C521DF58F4EEEF60C647E5EBD88C6039915409F9FD6454A476B9").unwrap()),
1624+
]),
1625+
),
1626+
),
1627+
]);
1628+
let redeemers = Redeemers(vec![
1629+
Redeemer::new(
1630+
&RedeemerTag::new_spend(),
1631+
&BigNum::one(),
1632+
&PlutusData::new_empty_constr_plutus_data(&BigNum::zero()),
1633+
&ExUnits::new(&to_bignum(7000000), &to_bignum(3000000000)),
1634+
),
1635+
]);
1636+
let lang = Language::new_plutus_v1();
1637+
let lang_costmodel = TxBuilderConstants::plutus_vasil_cost_models().get(&lang).unwrap();
1638+
let mut retained_cost_models = Costmdls::new();
1639+
retained_cost_models.insert(&lang, &lang_costmodel);
1640+
let hash = hash_script_data(
1641+
&redeemers,
1642+
&retained_cost_models,
1643+
Some(pdata),
1644+
);
1645+
assert_eq!(hex::encode(hash.to_bytes()), "357041b88b914670a3b5e3b0861d47f2ac05ed4935ea73886434d8944aa6dfe0");
1646+
}
1647+
1648+
#[test]
1649+
fn test_same_datum_in_different_formats_with_expected_hashes() {
1650+
// This is a known datum with indefinite arrays and a known expected hash
1651+
let pdata1 = PlutusData::from_bytes(hex::decode("d8799fd8799f581ca183bf86925f66c579a3745c9517744399679b090927b8f6e2f2e1bb4f616461706541696c656e416d61746fffd8799f581c9a4e855293a0b9af5e50935a331d83e7982ab5b738ea0e6fc0f9e6564e4652414d455f36353030335f4c30ff581cbea1c521df58f4eeef60c647e5ebd88c6039915409f9fd6454a476b9ff").unwrap()).unwrap();
1652+
assert_eq!(hex::encode(hash_plutus_data(&pdata1).to_bytes()), "ec3028f46325b983a470893a8bdc1b4a100695b635fb1237d301c3490b23e89b");
1653+
// This is the same exact datum manually converted to definite arrays
1654+
// and it produces a different known expected hash because the format is preserved after deserialization
1655+
let pdata2 = PlutusData::from_bytes(hex::decode("d87983d87982581ca183bf86925f66c579a3745c9517744399679b090927b8f6e2f2e1bb4f616461706541696c656e416d61746fd87982581c9a4e855293a0b9af5e50935a331d83e7982ab5b738ea0e6fc0f9e6564e4652414d455f36353030335f4c30581cbea1c521df58f4eeef60c647e5ebd88c6039915409f9fd6454a476b9").unwrap()).unwrap();
1656+
assert_eq!(hex::encode(hash_plutus_data(&pdata2).to_bytes()), "816cdf6d4d8cba3ad0188ca643db95ddf0e03cdfc0e75a9550a72a82cb146222");
1657+
}
15991658
}

0 commit comments

Comments
 (0)