Add a length restriction to rescue_hash_orders
This is to prevent errorneous usage of the function
with messages of different length.
Same messages with different number of 0-bits at the end
will result in a collision.
@@ -383,10 +383,12 @@ pub fn rescue_hash_tx_msg(msg: &[u8]) -> Vec<u8> {
// This differs from `rescue_hash_tx_msg` in several ways:
// - It does not constrain its input to be <= 92 bytes
+// In fact, it only accepts inputs of 168 bytes (2 * order_size)
// - It does not pad its message
// - It encodes the resulting Fr a bit differently
// - It returns 31 byte instead of 32
pub fn rescue_hash_orders(msg: &[u8]) -> Vec<u8> {
+ assert_eq!(msg.len(), 168);
let msg_bits = BitConvert::from_be_bytes(msg);
let hasher = &params::RESCUE_HASHER as &BabyRescueHasher;
let hash_fr = hasher.hash_bits(msg_bits.into_iter());
