From 29f0389705934ced41346bd26609dce231f46b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Fri, 27 Oct 2023 14:18:39 +0200 Subject: [PATCH 1/3] piecrust: upgrade to `dusk-merkle@0.5` --- piecrust/CHANGELOG.md | 1 + piecrust/Cargo.toml | 2 +- piecrust/src/store.rs | 5 ++- piecrust/src/store/session.rs | 6 ++- piecrust/src/store/tree.rs | 83 +++++------------------------------ 5 files changed, 20 insertions(+), 77 deletions(-) diff --git a/piecrust/CHANGELOG.md b/piecrust/CHANGELOG.md index 331b9ecf..df6a327c 100644 --- a/piecrust/CHANGELOG.md +++ b/piecrust/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Changed +- Upgrade `dusk-merkle` to version `0.5` - Change contract tree to be arity 4 and height 17 [#159] - Maximum contract size is now 4TiB [#159] - Change `Error::RuntimeError` variant to contain `dusk_wasmtime::Error`, diff --git a/piecrust/Cargo.toml b/piecrust/Cargo.toml index 63624584..c0a937e2 100644 --- a/piecrust/Cargo.toml +++ b/piecrust/Cargo.toml @@ -28,7 +28,7 @@ tempfile = "3" thiserror = "1" rand = "0.8" hex = "0.4" -dusk-merkle = { version = "0.1", features = ["rkyv-impl"] } +dusk-merkle = { version = "0.5", features = ["rkyv-impl"] } const-decoder = "0.3" [dev-dependencies] diff --git a/piecrust/src/store.rs b/piecrust/src/store.rs index 5eec6c8f..6bbf47d2 100644 --- a/piecrust/src/store.rs +++ b/piecrust/src/store.rs @@ -157,7 +157,8 @@ fn read_all_commits>( let entry = entry?; if entry.path().is_dir() { let commit = read_commit(entry.path())?; - commits.insert(*commit.index.root(), commit); + let root = *commit.index.root(); + commits.insert(root, commit); } } @@ -430,7 +431,7 @@ fn write_commit_inner>( bytecode_dir, memory_dir, base: base.map(|inner| { - let base_root = inner.index.root(); + let base_root = *inner.index.root(); let base_hex = hex::encode(base_root); let base_dir = root_dir.join(base_hex); diff --git a/piecrust/src/store/session.rs b/piecrust/src/store/session.rs index ddfab141..62a084be 100644 --- a/piecrust/src/store/session.rs +++ b/piecrust/src/store/session.rs @@ -74,7 +74,9 @@ impl ContractSession { for (contract, entry) in &self.contracts { commit.index.insert(*contract, &entry.memory); } - *commit.index.root() + let root = commit.index.root(); + + *root } /// Commits the given session to disk, consuming the session and adding it @@ -137,7 +139,7 @@ impl ContractSession { match base_commit.index.contains_key(&contract) { true => { - let base_hex = hex::encode(base); + let base_hex = hex::encode(*base); let base_dir = self.root_dir.join(base_hex); let contract_hex = hex::encode(contract); diff --git a/piecrust/src/store/tree.rs b/piecrust/src/store/tree.rs index f42a12d7..aff4656e 100644 --- a/piecrust/src/store/tree.rs +++ b/piecrust/src/store/tree.rs @@ -4,7 +4,10 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use std::collections::{BTreeMap, BTreeSet}; +use std::{ + cell::Ref, + collections::{BTreeMap, BTreeSet}, +}; use bytecheck::CheckBytes; use piecrust_uplink::ContractId; @@ -74,7 +77,7 @@ impl ContractIndex { .insert(position_from_contract(&contract), *element.tree.root()); } - pub fn root(&self) -> &Hash { + pub fn root(&self) -> Ref { self.tree.root() } @@ -140,14 +143,10 @@ impl AsRef<[u8]> for Hash { } } -impl dusk_merkle::Aggregate for Hash { - const EMPTY_SUBTREES: [Hash; C_HEIGHT] = C_EMPTY_SUBTREES; +impl dusk_merkle::Aggregate for Hash { + const EMPTY_SUBTREE: Self = Hash([0; blake3::OUT_LEN]); - fn aggregate<'a, I>(items: I) -> Self - where - Self: 'a, - I: Iterator, - { + fn aggregate(items: [&Self; C_ARITY]) -> Self { let mut hasher = Hasher::new(); for item in items { hasher.update(item.as_bytes()); @@ -156,14 +155,10 @@ impl dusk_merkle::Aggregate for Hash { } } -impl dusk_merkle::Aggregate for Hash { - const EMPTY_SUBTREES: [Hash; P_HEIGHT] = P_EMPTY_SUBTREES; +impl dusk_merkle::Aggregate for Hash { + const EMPTY_SUBTREE: Self = Hash([0; blake3::OUT_LEN]); - fn aggregate<'a, I>(items: I) -> Self - where - Self: 'a, - I: Iterator, - { + fn aggregate(items: [&Self; P_ARITY]) -> Self { let mut hasher = Hasher::new(); for item in items { hasher.update(item.as_bytes()); @@ -218,59 +213,3 @@ pub fn position_from_contract(contract: &ContractId) -> u64 { pos as u64 } - -const P_EMPTY_SUBTREES: [Hash; P_HEIGHT] = subtrees(); -const C_EMPTY_SUBTREES: [Hash; C_HEIGHT] = subtrees(); - -const fn subtrees() -> [Hash; N] { - let mut subtrees = [Hash([0; blake3::OUT_LEN]); N]; - - let mut i = 0; - while i < N { - subtrees[i] = EMPTY_SUBTREES[i]; - i += 1; - } - - subtrees -} - -const EMPTY_SUBTREES: [Hash; C_HEIGHT] = [ - h2h("452b8b91767b270a61db2159db2dd6d411ce560f4a34230d70928950fdda3a88"), - h2h("f588290692a4d73ba016dee67a00e928f38e381b8eb5ca8c01d8b8c9bee32211"), - h2h("0b69ae637dbf590e15b9e06b4195341087cb3f60e95a43a1a8c459a5d321b1ff"), - h2h("4087415c8d818403a4b52dcb9fc1c100ac72c3b52dba28181924cc394f39d873"), - h2h("d426e95515107709df948c05a45cf9257c03510fe89ed6e81c0f34bd02c67a1f"), - h2h("f71910e10293859199e9ce0a9eb553d9a332b9931b0516842ff4528143493789"), - h2h("19af8e0debcf1f9ed745a87e264e0930ac0163066b4a78bba42660252bf888d0"), - h2h("82b948b894a90ff6b6b5ff728e2f4e4d5442d40e52a8920ef4fb6922469032a1"), - h2h("7a6b33825bf9cb46f03a4db60821f811679b3b2ea0bc62e92b2c70a55b207be7"), - h2h("ba58322ab8cdb81e2d3e5f48c56d016c94fa03d37559e1fe2f6ce5e1947c1b11"), - h2h("2a6f776446db67a81008cc0d39a59c65456dfc0de7119158dcb593fceda81def"), - h2h("fcc45ccc66aef0862029fc21785cbc1de4f15f4a1de5f6ed2458b1061093de18"), - h2h("c20f6e2e047be3bccbfbc9a66352ee30a6b664a03da6df415fa2fde67e174c60"), - h2h("a0abd3f2694a3518379cd1df96701eb10d94f1025732796f28c1f6eb7a197282"), - h2h("ee20a233662e859c2af6a3feff6f1de5cea6d3421074d7a5fd2a472ba8083f51"), - h2h("d47a16c4ebfebe96fe29a5df123992c17f092f990cf4403a3f5b9c3d86219105"), - h2h("71c0c670191c8b1b7389d83b6da3e6a00f467ccc477ef0eabfbee4ab7b4b0087"), - h2h("136ce719e0a7865f0f39715a85e97a44284dc20fc86edff441b52d523f9c8aa5"), - h2h("5149df3556905068c59c3e5a35691b77dc31f411106802c29b4924009b95d953"), - h2h("b5b17224a6b2965cb162319dbc0a9ff87d3eee8f84fcc35e568fcf034e257601"), - h2h("1f23b1ebdb969ed8f77520d17e5c49b09c2becb73f65807ce548fac20705fb99"), - h2h("31bc05ea5dc0009352ddb2af607fddbf7605a314411aa77b18b1e00caef0109a"), - h2h("e895bc877f2c61c066e5e742b5e6e3b054e0e50c2f97cf6b1ff3d70830964765"), - h2h("5002d9b6c51486682cf6d109ebcacad9662bbaca1ce80fcdc38d4b5a3bde4f7f"), - h2h("3fe9023a11950dcbd3be3da7023f006369832ee531fbe25b4068bb9d3fc86878"), - h2h("8505d1e1aaac1592fe422ab50ed6d7e08a8f4ec1935be058f7fba446ffbf6868"), - h2h("513fef2ba48aadea5347054c866e9a1101475a9616badbdca1e8d38e76fa01a7"), - h2h("b1cbaba537ce45006efc736dbaa54d325cd9d5b7c03a796cc50b91ba06216fbf"), - h2h("d5e03be0716d41ef6cb9a2e7a761fba03c7e2df1e3c9c5a73560ed0f82900795"), - h2h("cc84fcaddbb73c6dc3803fb015a27e8aca4cb5783c1da7f0f1af353311b447d0"), - h2h("0ebcb81ff4a62dcd965ea581fffead4dbecf308ac7400eb13dbad6d4c253e3c0"), - h2h("88ade4a900cb56d9dbbef5e4f4e15cb0bbc40f2fcbabd916926b6b1481acfdc4"), -]; - -const fn h2h(s: &str) -> Hash { - use const_decoder::Decoder; - let bytes = Decoder::Hex.decode(s.as_bytes()); - Hash(bytes) -} From 7835287d6f93473afa87b01c7404d6677120a207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Fri, 27 Oct 2023 14:21:07 +0200 Subject: [PATCH 2/3] piecrust: remove `colored` dependency --- piecrust/CHANGELOG.md | 1 + piecrust/Cargo.toml | 1 - piecrust/src/instance.rs | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/piecrust/CHANGELOG.md b/piecrust/CHANGELOG.md index df6a327c..def792b0 100644 --- a/piecrust/CHANGELOG.md +++ b/piecrust/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Removed +- Remove `colored` dependency - Remove 4 page - 256KiB - minimum memory requirement for contracts - Remove `Clone` derivation for `Error` - Remove some `Error` variants, along with `From` implementations: diff --git a/piecrust/Cargo.toml b/piecrust/Cargo.toml index c0a937e2..2a1b7abd 100644 --- a/piecrust/Cargo.toml +++ b/piecrust/Cargo.toml @@ -22,7 +22,6 @@ rkyv = { version = "0.7", features = ["size_32", "validation"] } once_cell = "1.18" parking_lot = "0.12" blake3 = "1" -colored = "2" memmap2 = "0.7" tempfile = "3" thiserror = "1" diff --git a/piecrust/src/instance.rs b/piecrust/src/instance.rs index d738abd9..5aa6408b 100644 --- a/piecrust/src/instance.rs +++ b/piecrust/src/instance.rs @@ -7,7 +7,6 @@ use std::io; use std::ops::{Deref, DerefMut}; -use colored::*; use dusk_wasmtime::{Instance, Module, Mutability, Store, ValType}; use piecrust_uplink::{ContractId, Event, ARGBUF_LEN}; @@ -325,7 +324,7 @@ impl WrappedInstance { let buf_end = buf_start + ARGBUF_LEN; if ofs + i >= buf_start && ofs + i < buf_end { - print!("{}", format!("{byte:02x}").green()); + print!("{byte:02x}"); print!(" "); } else { print!("{byte:02x} ") From e806b66693567184c2278e62782eb1c0cfda8131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Fri, 27 Oct 2023 14:24:46 +0200 Subject: [PATCH 3/3] piecrust: remove `parking_lot` dependency --- piecrust/CHANGELOG.md | 1 + piecrust/Cargo.toml | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/piecrust/CHANGELOG.md b/piecrust/CHANGELOG.md index def792b0..88d7e7c0 100644 --- a/piecrust/CHANGELOG.md +++ b/piecrust/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Removed +- Remove `parking_lot` dependency - Remove `colored` dependency - Remove 4 page - 256KiB - minimum memory requirement for contracts - Remove `Clone` derivation for `Error` diff --git a/piecrust/Cargo.toml b/piecrust/Cargo.toml index 2a1b7abd..e3898d87 100644 --- a/piecrust/Cargo.toml +++ b/piecrust/Cargo.toml @@ -20,7 +20,6 @@ dusk-wasmtime = { version = "14", default-features = false, features = ["craneli bytecheck = "0.6" rkyv = { version = "0.7", features = ["size_32", "validation"] } once_cell = "1.18" -parking_lot = "0.12" blake3 = "1" memmap2 = "0.7" tempfile = "3"