-
Notifications
You must be signed in to change notification settings - Fork 69
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
Mark unsound public methods as private utility functions #445
Conversation
definitions/src/asm.rs
Outdated
/// valid for the lifetime of the returned slice. | ||
/// | ||
/// Failing to satisfy these conditions results in undefined behavior. | ||
pub unsafe fn cast_ptr_to_slice(&self, ptr: u64, offset: usize, size: usize) -> &[u8] { |
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 unsafe
causes breaking changes. We can improve it by moving it to ckb-vm internal and marking it as pub(crate)
. This is also a breaking change but more intuitive.
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.
Break changes involving unsoundness can be made without break versions, this is a safety fix
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.
I would suggest taking a step back here: why are those 2 methods of AsmCoreMachine, when they can just be utility functions? Also, why are they made public? I don't see a use case exposing them to the public.
Maybe we should just make them private functions. To me, current changes simply shift the unsafe block from one place to another, they don't really address the fundamental problem.
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 notation actually implies that
&[u8]
and&self
have the same lifetime. cast_ptr_to_slice
is defined in the ckb-vm-definitions crate, but will be used from the ckb-vm crate.
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.
To me a change like this solves the issue.
We can also then decide if we want to keep the unsafe part internally in cast_ptr_to_slice
's function body, or expose the unsafe part in the function signature. Either way, it will only affect the internal implementation of ckb-vm, no visible part will be exposed to the outside.
2a96898
to
4119bfc
Compare
Fix #444