Repository: LNP-BP/client_side_validation (language: rust)

Issue:
MerkleBlock conceal_except clarification
While trying to better understand the inner details of the `MerkleBlock` conceal procedure, I've inspected the [`conceal_except` method](https://github.com/LNP-BP/client_side_validation/blob/master/commit_verify/src/mpc/block.rs#L273), noticing that it gets an array of `ProtocolId`s. But looking at all calls made to this method I've also noticed that the method gets called either with an empty array or with an array containing a single `ProtocolId`. Therefore I've tried to change the method signature to get instead an `Option<ProtocolId>`, adjusted the caller methods and confirmed this still produces a valid commitment ID for the merkle block.

So I'm wondering if the array in the method signature is a leftover and, if so, if we can change the method signature and implementation, for the sake of simplifying the code and its auditing.



Discussion / hints:
Well, I am always trying to design modules and libraries such that they do not assume anything about their callers. Thus, MPC doesn't know how RGB protocol works or that `ProtocolId` is a `ContractId`. So I just have made a generic function which can work with any protocol on top, including protocols needing concealing multiple ids at the same time.

But I agree that better API is possible. Probably adding methods `conceal_all` taking zero args, renaming `conceal_except` into `conceal_except_all`, and do a new `conceal_except` method taking a single protocol id is the right way to do.

Fix patch:
diff --git a/commit_verify/src/mpc/block.rs b/commit_verify/src/mpc/block.rs
index 5acb27c0..d8470309 100644
--- a/commit_verify/src/mpc/block.rs
+++ b/commit_verify/src/mpc/block.rs
@@ -258,6 +258,19 @@ impl MerkleBlock {
         })
     }
 
+    /// Conceals all commitments in the block except for the commitment under
+    /// given `protocol_id`. Also removes information about the entropy value
+    /// used.
+    ///
+    /// # Error
+    ///
+    /// If leaf with the given `protocol_id` is not found (absent or already
+    /// concealed), errors with [`LeafNotKnown`] error.
+    pub fn conceal_other(&mut self, protocol: ProtocolId) -> Result<(), LeafNotKnown> {
+        self.conceal_except([protocol])?;
+        Ok(())
+    }
+
     /// Conceals all commitments in the block except for the commitment under
     /// given `protocol_id`s. Also removes information about the entropy value
     /// used.
@@ -516,7 +529,7 @@ Changed commitment id: {}",
         mut self,
         protocol_id: ProtocolId,
     ) -> Result<MerkleProof, LeafNotKnown> {
-        self.conceal_except([protocol_id])?;
+        self.conceal_other(protocol_id)?;
         let mut map = BTreeMap::<u5, MerkleHash>::new();
         for node in &self.cross_section {
             match node {


Test patch: