-
Notifications
You must be signed in to change notification settings - Fork 156
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
Remove use of usize
from the VM core struct
#1498
Comments
I don't really understand this part. Why not just make the offset |
Re: execution on different architectures: AFAICT, in the cases we could observe overflows in the offsets execution would fail due to exceeding the addressable space anyway, so |
It would work, but next time you want to change, lets say to u32, it will be hell again. With the correct encapsulation it is easier to change in the future.
I think you are correct on this one. But it mean that it work "by luck" and it will be okay until it isn't. So yes I would prefer the more restrictive architecture. Also some traits like parity-scale-codec::{Encode, Decode} are not implemented on usize. So getting rid of it would be more handy.. |
Same goes with |
Sounds reasonable. |
Hello! |
Yeah that sound like a bad design. It should be a u64 or a u128 or whatever. But it should be defined by the starknet spec, not by the machine the program runs on. Otherwise the virtual machine is not that virtual, it end up being tied up to the actual hardware. When are you planning to solve all of this @fmoletta? As I say, it could be great to have it before 1.0.0 release |
What I meant by that line is that the maximum capacity of a vector in rust is usize::MAX, therefore the maximum capacity for a memory segment is usize::MAX. It's not something we can change without changing the whole structure of the memory |
Well, that is a bad design. The max size of a segment should be decided by the VM specs. Not by some implementation details which makes it depend on the hardware it is running on. Once you decide that the max size of a segment is x (maybe 2^251-1, or something else), you implement it in a way that makes it respect the specs, regardless of the hardware. Not the other way around. |
Regardless, this is a very specific edge case that most likely will never happen in an actual run. |
Problem
The VM execution should be deterministic regardless of if it is executed on a 16, 32 or 64 bit processor.
Having
usize
being used in order to define some of the core VM types (segment offset, ap, fp) is problematic because it could lead to different execution on different machines. Which, in a decentralized blockchain architecture will lead to hard forks.Recomandation
Get rid of all the
usize
in the cairo-vm stuct. I think it's still okay to useusize
when we call language method likelen()
but we should convert those as soon as possible to types that have a fixed behaviour regardless of the machine.Ban the use of
as
.as
silence the value overflows. This is not something we want at all in a blockchain context. We should use the very explicittry_from/into
instead and handle errors accordingly.Impl
I would reccomand we introduce a new wrapper struct:
SegmentOffset(u64)
that will be used instead ofusize
in allRelocatable
,ap
andfp
. This will require impl a lot of conversion methods on it, but it will give us the level of security we need for such a core component of our infrastructure.The text was updated successfully, but these errors were encountered: