diff --git a/algorithms/src/polycommit/sonic_pc/data_structures.rs b/algorithms/src/polycommit/sonic_pc/data_structures.rs index 532d79d53c3..8230be4d789 100644 --- a/algorithms/src/polycommit/sonic_pc/data_structures.rs +++ b/algorithms/src/polycommit/sonic_pc/data_structures.rs @@ -223,7 +223,6 @@ impl FromBytes for CommitterKey { impl ToBytes for CommitterKey { fn write_le(&self, mut writer: W) -> io::Result<()> { // Serialize `powers`. - // u32::try_from(*degree_bound).map_err(|e| error(e.to_string()))?.write_le(&mut writer)?; try_write_as::(self.powers_of_beta_g.len(), &mut writer)?; for power in &self.powers_of_beta_g { power.write_le(&mut writer)?; diff --git a/synthesizer/coinbase/src/helpers/coinbase_solution/bytes.rs b/synthesizer/coinbase/src/helpers/coinbase_solution/bytes.rs index bbc973432bc..f0fe95acb28 100644 --- a/synthesizer/coinbase/src/helpers/coinbase_solution/bytes.rs +++ b/synthesizer/coinbase/src/helpers/coinbase_solution/bytes.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::*; +use snarkvm_utilities::try_write_as; impl FromBytes for CoinbaseSolution { /// Reads the coinbase solution from the buffer. @@ -34,7 +35,7 @@ impl FromBytes for CoinbaseSolution { impl ToBytes for CoinbaseSolution { /// Writes the coinbase solution to the buffer. fn write_le(&self, mut writer: W) -> IoResult<()> { - (u32::try_from(self.partial_solutions.len()).map_err(|e| error(e.to_string()))?).write_le(&mut writer)?; + try_write_as::(self.partial_solutions.len(), &mut writer)?; for individual_puzzle_solution in &self.partial_solutions { individual_puzzle_solution.write_le(&mut writer)?; diff --git a/synthesizer/src/block/transaction/deployment/bytes.rs b/synthesizer/src/block/transaction/deployment/bytes.rs index 88df477b4ef..9a964e3339b 100644 --- a/synthesizer/src/block/transaction/deployment/bytes.rs +++ b/synthesizer/src/block/transaction/deployment/bytes.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::*; +use snarkvm_utilities::try_write_as; impl FromBytes for Deployment { /// Reads the deployment from a buffer. @@ -59,7 +60,7 @@ impl ToBytes for Deployment { // Write the program. self.program.write_le(&mut writer)?; // Write the number of entries in the bundle. - (u16::try_from(self.verifying_keys.len()).map_err(|e| error(e.to_string()))?).write_le(&mut writer)?; + try_write_as::(self.verifying_keys.len(), &mut writer)?; // Write each entry. for (function_name, (verifying_key, certificate)) in &self.verifying_keys { // Write the function name. diff --git a/synthesizer/src/block/transaction/execution/bytes.rs b/synthesizer/src/block/transaction/execution/bytes.rs index e2475d7ef1f..5a664862666 100644 --- a/synthesizer/src/block/transaction/execution/bytes.rs +++ b/synthesizer/src/block/transaction/execution/bytes.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use snarkvm_utilities::try_write_as; + use super::*; impl FromBytes for Execution { @@ -54,7 +56,7 @@ impl ToBytes for Execution { // Write the version. 0u8.write_le(&mut writer)?; // Write the number of transitions. - (u8::try_from(self.transitions.len()).map_err(|e| error(e.to_string()))?).write_le(&mut writer)?; + try_write_as::(self.transitions.len(), &mut writer)?; // Write the transitions. for transition in self.transitions.values() { transition.write_le(&mut writer)?; diff --git a/synthesizer/src/block/transactions/confirmed/bytes.rs b/synthesizer/src/block/transactions/confirmed/bytes.rs index 4959a7ced67..6991ccc177f 100644 --- a/synthesizer/src/block/transactions/confirmed/bytes.rs +++ b/synthesizer/src/block/transactions/confirmed/bytes.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::*; +use snarkvm_utilities::try_write_as; impl FromBytes for ConfirmedTransaction { /// Reads the confirmed transaction from a buffer. @@ -82,7 +83,7 @@ impl ToBytes for ConfirmedTransaction { // Write the transaction. transaction.write_le(&mut writer)?; // Write the number of finalize operations. - NumFinalizeSize::try_from(finalize.len()).map_err(|e| error(e.to_string()))?.write_le(&mut writer)?; + try_write_as::(finalize.len(), &mut writer)?; // Write the finalize operations. finalize.iter().try_for_each(|finalize| finalize.write_le(&mut writer)) } @@ -94,7 +95,7 @@ impl ToBytes for ConfirmedTransaction { // Write the transaction. transaction.write_le(&mut writer)?; // Write the number of finalize operations. - NumFinalizeSize::try_from(finalize.len()).map_err(|e| error(e.to_string()))?.write_le(&mut writer)?; + try_write_as::(finalize.len(), &mut writer)?; // Write the finalize operations. finalize.iter().try_for_each(|finalize| finalize.write_le(&mut writer)) } diff --git a/synthesizer/src/block/transition/bytes.rs b/synthesizer/src/block/transition/bytes.rs index 385fb84d987..d1fed62d619 100644 --- a/synthesizer/src/block/transition/bytes.rs +++ b/synthesizer/src/block/transition/bytes.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use snarkvm_utilities::try_write_as; + use super::*; impl FromBytes for Transition { @@ -98,12 +100,12 @@ impl ToBytes for Transition { self.function_name.write_le(&mut writer)?; // Write the number of inputs. - (u8::try_from(self.inputs.len()).map_err(|e| error(e.to_string()))?).write_le(&mut writer)?; + try_write_as::(self.inputs.len(), &mut writer)?; // Write the inputs. self.inputs.write_le(&mut writer)?; // Write the number of outputs. - (u8::try_from(self.outputs.len()).map_err(|e| error(e.to_string()))?).write_le(&mut writer)?; + try_write_as::(self.outputs.len(), &mut writer)?; // Write the outputs. self.outputs.write_le(&mut writer)?; @@ -117,7 +119,7 @@ impl ToBytes for Transition { // Write the finalize variant. 1u8.write_le(&mut writer)?; // Write the number of inputs to finalize. - (u8::try_from(finalize.len()).map_err(|e| error(e.to_string()))?).write_le(&mut writer)?; + try_write_as::(finalize.len(), &mut writer)?; // Write the inputs to finalize. finalize.write_le(&mut writer)?; }