From 6146cf16c6e8636e0c35202484b7da26f6962212 Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 10:38:47 +0100 Subject: [PATCH 01/13] Add test for incorrect version --- utils/bitfield/src/rleplus/mod.rs | 31 ++++++++++++++++++++-------- utils/bitfield/src/rleplus/writer.rs | 12 +++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index 86919eb16a00..f0a3545a0b97 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -182,7 +182,19 @@ mod tests { #[test] fn test() { for (bits, expected) in vec![ - (vec![], bitfield![]), + ( + vec![], + Ok(bitfield![]), + ), + ( + vec![ + 1, 0, // incorrect version + 1, // starts with 1 + 0, 1, // fits into 4 bits + 0, 0, 0, 1, // 8 - 1 + ], + Err("incorrect version"), + ), ( vec![ 0, 0, // version @@ -190,7 +202,7 @@ mod tests { 0, 1, // fits into 4 bits 0, 0, 0, 1, // 8 - 1 ], - bitfield![1, 1, 1, 1, 1, 1, 1, 1], + Ok(bitfield![1, 1, 1, 1, 1, 1, 1, 1]), ), ( vec![ @@ -202,7 +214,7 @@ mod tests { 0, 1, // fits into 4 bits 1, 1, 0, 0, // 3 - 1 ], - bitfield![1, 1, 1, 1, 0, 1, 1, 1], + Ok(bitfield![1, 1, 1, 1, 0, 1, 1, 1]), ), ( vec![ @@ -211,9 +223,9 @@ mod tests { 0, 0, // does not fit into 4 bits 1, 0, 0, 1, 1, 0, 0, 0, // 25 - 1 ], - bitfield![ + Ok(bitfield![ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - ], + ]), ), // when a length of 0 is encountered, the rest of the encoded bits should be ignored ( @@ -225,15 +237,16 @@ mod tests { 0, 0, 0, 0, // 0 - 0 1, // 1 - 1 ], - bitfield![1], + Ok(bitfield![1]), ), ] { let mut writer = BitWriter::new(); - for bit in bits { + for bit in bits.into_iter() { + assert!(bit < 2, "must be a binary digit"); writer.write(bit, 1); } - let bf = BitField::from_bytes(&writer.finish()).unwrap(); - assert_eq!(bf, expected); + let res = BitField::from_bytes(&writer.finish_test()); + assert_eq!(res, expected); } } diff --git a/utils/bitfield/src/rleplus/writer.rs b/utils/bitfield/src/rleplus/writer.rs index 973cfb018ea9..06fe67922884 100644 --- a/utils/bitfield/src/rleplus/writer.rs +++ b/utils/bitfield/src/rleplus/writer.rs @@ -69,6 +69,18 @@ impl BitWriter { } self.bytes } + + /// Writes any remaining bits to the buffer and returns it. + /// We write remaining bits even if they are are 0s. + /// This method is for testing purpose only. + #[cfg(test)] + pub fn finish_test(mut self) -> Vec { + if self.num_bits > 0 { + self.bytes.push(self.bits as u8); + } + + self.bytes + } } #[cfg(test)] From a3fd90d35141a4f9daba620c8845276b8cbdc616 Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 10:52:11 +0100 Subject: [PATCH 02/13] Fix when last block is a varint that is not minimally encoded --- utils/bitfield/src/rleplus/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index f0a3545a0b97..cdac5f1f9c49 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -106,6 +106,10 @@ impl<'de> Deserialize<'de> for BitField { impl BitField { /// Decodes RLE+ encoded bytes into a bit field. pub fn from_bytes(bytes: &[u8]) -> Result { + if !bytes.is_empty() && (*bytes.last().unwrap() == 0) { + return Err("not minimally encoded"); + } + let mut reader = BitReader::new(bytes); let version = reader.read(2); @@ -239,6 +243,18 @@ mod tests { ], Ok(bitfield![1]), ), + // when the last byte is zero, this should fail + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 1, // fits into 4 bits + 1, 0, 1, // 5 - 1 + 0, 0, + 0, 0, 0, 0, 0, 0 + ], + Err("not minimally encoded") + ) ] { let mut writer = BitWriter::new(); for bit in bits.into_iter() { From d07a80e9fdd45dfc28147fdf7190c35843436638 Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 11:03:48 +0100 Subject: [PATCH 03/13] Fix when a varint is not minimally encoded --- utils/bitfield/src/rleplus/mod.rs | 16 +++++++++++++++- utils/bitfield/src/rleplus/reader.rs | 10 ++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index cdac5f1f9c49..de262c0aa932 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -254,7 +254,21 @@ mod tests { 0, 0, 0, 0, 0, 0 ], Err("not minimally encoded") - ) + ), + // a varint that is not minimally encoded + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 0, // fits into a varint + 1, 1, 0, 0, 0, 0, 0, 1, // 3 - 1 + 0, 0, 0, 0, 0, 0, 0, 0, + 1, + 1, + 1, + ], + Err("Invalid varint"), + ), ] { let mut writer = BitWriter::new(); for bit in bits.into_iter() { diff --git a/utils/bitfield/src/rleplus/reader.rs b/utils/bitfield/src/rleplus/reader.rs index 8381b44f56c2..69b61e593860 100644 --- a/utils/bitfield/src/rleplus/reader.rs +++ b/utils/bitfield/src/rleplus/reader.rs @@ -84,12 +84,18 @@ impl<'a> BitReader<'a> { // strip off the most significant bit and add // it to the output - len |= (byte as usize & 0x7f) << (i * 7); + let masked_byte = byte as usize & 0x7f; + len |= masked_byte << (i * 7); // if the most significant bit is a 0, we've // reached the end of the varint if byte & 0x80 == 0 { - return Ok(len); + if i == 0 || byte != 0 { + // only the first byte can be zero in a varint + return Ok(len); + } + // not minimally encoded + break; } } From 8254d2375f73b54a539f9d0742a8e34a466296f8 Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 11:10:15 +0100 Subject: [PATCH 04/13] Add test that checks if a varint takes more than 9 bytes --- utils/bitfield/src/rleplus/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index de262c0aa932..1e5db4a456eb 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -269,6 +269,25 @@ mod tests { ], Err("Invalid varint"), ), + // a varint must not take more than 9 bytes + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 0, // fits into a varint + 1, 0, 0, 0, 0, 0, 0, 1, // 1 - 1 + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, + ], + Err("Invalid varint"), + ), ] { let mut writer = BitWriter::new(); for bit in bits.into_iter() { From e7d15276879ed7aa67a03fd94f4294c82a454311 Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 11:24:56 +0100 Subject: [PATCH 05/13] Fix total running length that could overflow --- utils/bitfield/src/rleplus/mod.rs | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index 1e5db4a456eb..fe6e1d3f492f 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -120,8 +120,15 @@ impl BitField { let mut next_value = reader.read(1) == 1; let mut ranges = Vec::new(); let mut index = 0; + let mut total_len: u64 = 0; while let Some(len) = reader.read_len()? { + let (new_total_len, ovf) = total_len.overflowing_add(len as u64); + if ovf { + return Err("RLE+ overflow"); + } + total_len = new_total_len; + let start = index; index += len; let end = index; @@ -288,6 +295,36 @@ mod tests { ], Err("Invalid varint"), ), + // total running length should not overflow + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 0, // fits into a varint + 1, 1, 1, 1, 1, 1, 1, 1, // 9223372036854775807 - 1 + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, // fits into a varint + 1, 1, 1, 1, 1, 1, 1, 1, // 9223372036854775807 - 0 + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0, + 0, 1, // fits into 4 bits + 0, 1, 0, 0 // 2 - 1 + ], + Err("RLE+ overflow"), + ), ] { let mut writer = BitWriter::new(); for bit in bits.into_iter() { From 5ba23179f3840cae0accc36f0e24874166cb9fcb Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 11:31:05 +0100 Subject: [PATCH 06/13] Add test of a valid varint taking one byte --- utils/bitfield/src/rleplus/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index fe6e1d3f492f..82c4bc3fa0a6 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -262,6 +262,17 @@ mod tests { ], Err("not minimally encoded") ), + // a valid varint + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 0, // fits into a varint + 1, 0, 0, 0, 1, 0, 0, 0, // 17 - 1 + 0, 0, 0 + ], + Ok(bitfield![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), + ), // a varint that is not minimally encoded ( vec![ From f8534201e1d507919ee3ff647663b76300b2b973 Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 11:37:16 +0100 Subject: [PATCH 07/13] Add test when a varint has a length of 0 --- utils/bitfield/src/rleplus/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index 82c4bc3fa0a6..53f472278c8e 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -250,6 +250,18 @@ mod tests { ], Ok(bitfield![1]), ), + // when a length of 0 is encountered, the rest of the encoded bits should be ignored + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 1, // 1 - 1 + 0, 0, // fits into a varint + 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 0 + 1, // 1 - 1 + ], + Ok(bitfield![1]), + ), // when the last byte is zero, this should fail ( vec![ From 24a0d730c8ea5177b46676d0bac99bbcea41fe1d Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 11:44:15 +0100 Subject: [PATCH 08/13] Add tests related to uniqueness of RLE+ encoding --- utils/bitfield/src/rleplus/mod.rs | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index 53f472278c8e..161dc1cb12c5 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -348,6 +348,49 @@ mod tests { ], Err("RLE+ overflow"), ), + // block_long that could have fit on block_short. TODO: is this legit? + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 0, // fits into a varint + 1, 1, 0, 0, 0, 0, 0, 0, // 3 - 1 + 1, + 1, + 1, + ], + Ok(bitfield![1, 1, 1, 0, 1, 0]), + ), + // block_long that could have fit on block_single. TODO: is this legit? + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 0, // fits into a varint + 1, 0, 0, 0, 0, 0, 0, 0, // 1 - 1 + 1, + 1, + 1, + ], + Ok(bitfield![1, 0, 1, 0]), + ), + // block_short that could have fit on block_single. TODO: is this legit? + ( + vec![ + 0, 0, // version + 1, // starts with 1 + 0, 1, // fits into 4 bits + 1, 0, 0, 0, // 1 - 1 + 1, + 1, + 1, + 1, + 1, + 1, + 1, + ], + Ok(bitfield![1, 0, 1, 0, 1, 0, 1, 0]), + ), ] { let mut writer = BitWriter::new(); for bit in bits.into_iter() { From d628ba7f3e0eb12581b0858ae941fbeb7ad9472a Mon Sep 17 00:00:00 2001 From: elmattic Date: Mon, 22 Nov 2021 12:26:47 +0100 Subject: [PATCH 09/13] Fix invalid error code and use the same message as in specification --- vm/actor/src/builtin/miner/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/actor/src/builtin/miner/mod.rs b/vm/actor/src/builtin/miner/mod.rs index e61b787033a9..97429fba2486 100644 --- a/vm/actor/src/builtin/miner/mod.rs +++ b/vm/actor/src/builtin/miner/mod.rs @@ -682,7 +682,7 @@ impl Actor { let sector_numbers = params .sector_numbers .validate() - .map_err(|e| actor_error!(ErrIllegalArgument, "Invalid Bitfield argument:{}", e))?; + .map_err(|e| actor_error!(ErrIllegalState, "fail to count aggregated sectors: {}", e))?; let agg_sectors_count = sector_numbers.len(); if agg_sectors_count > MAX_AGGREGATED_SECTORS { From 48ecdbe82d2a5ed6807c83bda537689b9c78121f Mon Sep 17 00:00:00 2001 From: elmattic Date: Wed, 24 Nov 2021 09:26:20 +0100 Subject: [PATCH 10/13] Refactor test to use more idiomatic code --- utils/bitfield/src/rleplus/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index 161dc1cb12c5..f37435421634 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -106,8 +106,10 @@ impl<'de> Deserialize<'de> for BitField { impl BitField { /// Decodes RLE+ encoded bytes into a bit field. pub fn from_bytes(bytes: &[u8]) -> Result { - if !bytes.is_empty() && (*bytes.last().unwrap() == 0) { - return Err("not minimally encoded"); + if let Some(value) = bytes.last() { + if *value == 0 { + return Err("not minimally encoded"); + } } let mut reader = BitReader::new(bytes); From b6263958e51e375de87e5ba0134def6a0ee89e32 Mon Sep 17 00:00:00 2001 From: elmattic Date: Wed, 24 Nov 2021 09:27:41 +0100 Subject: [PATCH 11/13] Remove unnecessary assert --- utils/bitfield/src/rleplus/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index f37435421634..a9a6cd538f94 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -395,8 +395,7 @@ mod tests { ), ] { let mut writer = BitWriter::new(); - for bit in bits.into_iter() { - assert!(bit < 2, "must be a binary digit"); + for bit in bits { writer.write(bit, 1); } let res = BitField::from_bytes(&writer.finish_test()); From 9fc5615d4691a424538cced28137de88a59f4c3b Mon Sep 17 00:00:00 2001 From: elmattic Date: Wed, 24 Nov 2021 09:29:03 +0100 Subject: [PATCH 12/13] Remove unnecessary temporary binding --- utils/bitfield/src/rleplus/reader.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/bitfield/src/rleplus/reader.rs b/utils/bitfield/src/rleplus/reader.rs index 69b61e593860..7f4e6e387b14 100644 --- a/utils/bitfield/src/rleplus/reader.rs +++ b/utils/bitfield/src/rleplus/reader.rs @@ -84,8 +84,7 @@ impl<'a> BitReader<'a> { // strip off the most significant bit and add // it to the output - let masked_byte = byte as usize & 0x7f; - len |= masked_byte << (i * 7); + len |= (byte as usize & 0x7f) << (i * 7); // if the most significant bit is a 0, we've // reached the end of the varint From 42c7d8dcaea1e48353b205a301cc307bd1c02628 Mon Sep 17 00:00:00 2001 From: noot Date: Tue, 7 Dec 2021 12:50:03 -0500 Subject: [PATCH 13/13] fmt --- utils/bitfield/src/rleplus/mod.rs | 71 ++++++++----------------------- vm/actor/src/builtin/miner/mod.rs | 7 ++- 2 files changed, 21 insertions(+), 57 deletions(-) diff --git a/utils/bitfield/src/rleplus/mod.rs b/utils/bitfield/src/rleplus/mod.rs index a9a6cd538f94..1b77735197d0 100644 --- a/utils/bitfield/src/rleplus/mod.rs +++ b/utils/bitfield/src/rleplus/mod.rs @@ -195,10 +195,7 @@ mod tests { #[test] fn test() { for (bits, expected) in vec![ - ( - vec![], - Ok(bitfield![]), - ), + (vec![], Ok(bitfield![])), ( vec![ 1, 0, // incorrect version @@ -271,10 +268,9 @@ mod tests { 1, // starts with 1 0, 1, // fits into 4 bits 1, 0, 1, // 5 - 1 - 0, 0, - 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, ], - Err("not minimally encoded") + Err("not minimally encoded"), ), // a valid varint ( @@ -283,7 +279,7 @@ mod tests { 1, // starts with 1 0, 0, // fits into a varint 1, 0, 0, 0, 1, 0, 0, 0, // 17 - 1 - 0, 0, 0 + 0, 0, 0, ], Ok(bitfield![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), ), @@ -294,10 +290,7 @@ mod tests { 1, // starts with 1 0, 0, // fits into a varint 1, 1, 0, 0, 0, 0, 0, 1, // 3 - 1 - 0, 0, 0, 0, 0, 0, 0, 0, - 1, - 1, - 1, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, ], Err("Invalid varint"), ), @@ -308,15 +301,9 @@ mod tests { 1, // starts with 1 0, 0, // fits into a varint 1, 0, 0, 0, 0, 0, 0, 1, // 1 - 1 - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, ], Err("Invalid varint"), ), @@ -327,26 +314,14 @@ mod tests { 1, // starts with 1 0, 0, // fits into a varint 1, 1, 1, 1, 1, 1, 1, 1, // 9223372036854775807 - 1 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 0, - 0, 0, // fits into a varint + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, // fits into a varint 1, 1, 1, 1, 1, 1, 1, 1, // 9223372036854775807 - 0 - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 0, - 0, 1, // fits into 4 bits - 0, 1, 0, 0 // 2 - 1 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, // fits into 4 bits + 0, 1, 0, 0, // 2 - 1 ], Err("RLE+ overflow"), ), @@ -357,9 +332,7 @@ mod tests { 1, // starts with 1 0, 0, // fits into a varint 1, 1, 0, 0, 0, 0, 0, 0, // 3 - 1 - 1, - 1, - 1, + 1, 1, 1, ], Ok(bitfield![1, 1, 1, 0, 1, 0]), ), @@ -370,9 +343,7 @@ mod tests { 1, // starts with 1 0, 0, // fits into a varint 1, 0, 0, 0, 0, 0, 0, 0, // 1 - 1 - 1, - 1, - 1, + 1, 1, 1, ], Ok(bitfield![1, 0, 1, 0]), ), @@ -383,13 +354,7 @@ mod tests { 1, // starts with 1 0, 1, // fits into 4 bits 1, 0, 0, 0, // 1 - 1 - 1, - 1, - 1, - 1, - 1, - 1, - 1, + 1, 1, 1, 1, 1, 1, 1, ], Ok(bitfield![1, 0, 1, 0, 1, 0, 1, 0]), ), diff --git a/vm/actor/src/builtin/miner/mod.rs b/vm/actor/src/builtin/miner/mod.rs index 97429fba2486..402ccea7264d 100644 --- a/vm/actor/src/builtin/miner/mod.rs +++ b/vm/actor/src/builtin/miner/mod.rs @@ -679,10 +679,9 @@ impl Actor { BS: BlockStore, RT: Runtime, { - let sector_numbers = params - .sector_numbers - .validate() - .map_err(|e| actor_error!(ErrIllegalState, "fail to count aggregated sectors: {}", e))?; + let sector_numbers = params.sector_numbers.validate().map_err(|e| { + actor_error!(ErrIllegalState, "fail to count aggregated sectors: {}", e) + })?; let agg_sectors_count = sector_numbers.len(); if agg_sectors_count > MAX_AGGREGATED_SECTORS {