You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detect if the value read from a storage variable is mutated, but the updated value is not written back to storage.
Associated example:
#[contract]modStorageVarNotUpdated{structStorage{_value:u128}#[external]fnbad(){letmut value = _value::read();
value += 1;}#[external]fngood(){letmut value = _value::read();
value += 1;
_value::write(value);}#[external]fngood2(){update_value();}// update value in a private functionfnupdate_value(){letmut value = _value::read();
value += 1;
_value::write(value);}}
This is probably a bit tricky to do at the Sierra level, because we don't know whether a storage variable is read as mut or not; which makes it hard to catch mutability intents at the Cairo level.
The text was updated successfully, but these errors were encountered:
Hi, thanks for the great idea. I looked into it and i think at the moment by using only sierra it's not possible to implement a detector without too many false positives because for example these two functions have the same sierra. I keep the issue open to revisit when there will be sierra to source code mapping.
#[external(v0)]
fn good(ref self: ContractState) {
let mut value = self.a.read();
value += 435;
self.a.write(value);
}
#[external(v0)]
fn good2(ref self: ContractState) {
let mut value = self.a.read();
let b = value + 435;
self.a.write(b);
}
Describe the desired feature
Detect if the value read from a storage variable is mutated, but the updated value is not written back to storage.
Associated example:
This is probably a bit tricky to do at the Sierra level, because we don't know whether a storage variable is read as mut or not; which makes it hard to catch mutability intents at the Cairo level.
The text was updated successfully, but these errors were encountered: