-
-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Hash
for MapObserver
#1989
Conversation
* Rename the hash utility function (in MapObserver) to hash_easy * Use hash_slice as a helper function to impl Hash trait
I've also tried implement |
@addisoncrump want to take a look? |
error[E0277]: the trait bound `observers::map::pybind::PythonMapObserverI8: core::hash::Hash` is not satisfied
--> libafl/src/observers/map.rs:2720:34
|
2501 | / macro_rules! define_python_map_observer {
2502 | | ($struct_name1:ident, $py_name1:tt, $struct_name2:ident, $py_name2:tt, $struct_name_trait:ident, $py_name_trait:tt, $datatype:ty,...
2503 | |
2504 | | #[pyclass(unsendable, name = $py_name1)]
... |
2720 | | impl MapObserver for $struct_name_trait {
| | ^^^^^^^^^^^^^^^^^^ the trait `core::hash::Hash` is not implemented for `observers::map::pybind::PythonMapObserverI8`
... |
2794 | | };
2795 | | }
| |_____- in this expansion of `define_python_map_observer!`
2796 |
2797 | / define_python_map_observer!(
2798 | | PythonStdMapObserverI8,
2799 | | "StdMapObserverI8",
2800 | | PythonOwnedMapObserverI8,
... |
2805 | | PythonMapObserverWrapperI8
2806 | | );
| |_____- in this macro invocation
|
note: required by a bound in `observers::map::MapObserver`
--> libafl/src/observers/map.rs:85:83
|
85 | pub trait MapObserver: HasLen + Named + Serialize + serde::de::DeserializeOwned + Hash
| ^^^^ required by this bound in `MapObserver` |
libafl/src/observers/map.rs
Outdated
@@ -70,8 +70,7 @@ fn init_count_class_16() { | |||
} | |||
|
|||
/// Compute the hash of a slice | |||
fn hash_slice<T>(slice: &[T]) -> u64 { | |||
let mut hasher = RandomState::with_seeds(0, 0, 0, 0).build_hasher(); | |||
fn hash_slice<T, H: Hasher>(slice: &[T], hasher: &mut H) -> u64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire function may replaced with .as_slice().hash(&mut hasher)
, and should be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hash_slice
should be renamed to hash_helper
. Its used to define the hash
function. I can't see how to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addisoncrump any last words on this? Otherwise we'll merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be removed. One sec.
* Also rename hash_easy to hash_simple
Isn't there a way to trigger the CI pipeline? I can't get |
* hash_helper is used to define the implementation of hash function/trait
Again! python ..🤦 |
if you make this PR ready for review. then CI will run. else it won't |
There are still some Errors in CI such as error[E0407]: method `hash` is not a member of trait `MapObserver`
--> libafl_targets/src/sancov_8bit.rs:199:9
|
199 | / fn hash(&self) -> u64 {
200 | | let mut hasher = RandomState::with_seeds(0, 0, 0, 0).build_hasher();
201 | | for map in unsafe { &*addr_of!(COUNTERS_MAPS) } {
202 | | let slice = map.as_slice();
... |
209 | | hasher.finish()
210 | | }
| |_________^ not a member of trait `MapObserver` |
Hi, I was wondering if the commit messages are alright. I thought maybe a rebase might be necessary
|
* Use hash_one function to make hash_simple a one-liner
hasher.finish() | ||
#[inline] | ||
fn hash_simple(&self) -> u64 { | ||
RandomState::with_seeds(0, 0, 0, 0).hash_one(self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the hash_std method here that can use xxh3 (but probably we don't need to)
LibAFL/libafl_bolts/src/lib.rs
Line 283 in 8bce605
pub fn hash_std(input: &[u8]) -> u64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this method even exist? We should just have a type
definition for StdHash or something, probably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not even sure if it implements any rust traits tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hash_simple
does not implement any rust traits. If hash_std is okay then can use that instead. I don't really like it but Hash
trait in rust doesn't seem to provide any default hashing function, so I made this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, we don't actually want a default hashing function. This should be specified by the user, which is why we wanted the Hash
impl (as this allows us to use a generic Hasher
).
Hash
for MapObserver
@domenukk I think this is good to go now. Please review latest changes and then merge it up when you're satisfied with it. |
Happy if you are. Thanks y'all :) |
I'll merge this when CI finishes, then 🙂 |
Rename the hash utility function (in MapObserver) to hash_easy
Use hash_slice as a helper function to impl Hash trait