Skip to content
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

Fix crash while removing values from maps containing complex types #2225

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Addressed review feedback
bzawisto committed Jan 27, 2025
commit 6decc6cb14b9d109b4f90f0b8905490f9d833392
39 changes: 6 additions & 33 deletions zilliqa/src/scilla.rs
Original file line number Diff line number Diff line change
@@ -931,39 +931,12 @@ impl ActiveCall {
} else {
// Remove multiple elements from storage having the same prefix specified by `indices`

// Collect all paths of indices up to a value that is not of a map type
fn collect_indices(
map: BTreeMap<Vec<u8>, StorageValue>,
path: Vec<Vec<u8>>,
all_paths: &mut Vec<Vec<Vec<u8>>>,
) {
for (key, value) in map {
let mut path = path.clone();
path.push(key);
match value {
StorageValue::Map { map, .. } => {
collect_indices(map, path, all_paths);
}
StorageValue::Value(_) => {
all_paths.push(path.clone());
}
}
}
}

let load_map_from_prefix =
self.state
.load_storage_by_prefix(self.sender, &name, &indices)?;

let mut all_indices = Vec::new();
let path = Vec::new();

collect_indices(load_map_from_prefix, path, &mut all_indices);

for path in all_indices {
self.state
.set_storage(self.sender, &name, &path, StorageValue::Value(None))?
}
let complete_empty_map = StorageValue::Map {
map: BTreeMap::new(),
complete: true,
};
self.state
.set_storage(self.sender, &name, &indices, complete_empty_map)?;
}
} else if indices.len() == depth {
let Some(ValType::Bval(value)) = value.val_type else {
2 changes: 1 addition & 1 deletion zilliqa/tests/it/zil.rs
Original file line number Diff line number Diff line change
@@ -341,7 +341,7 @@ pub fn scilla_test_contract_code() -> String {
field welcome_map : Map Uint32 (Map Uint32 String) = Emp Uint32 (Map Uint32 String)
transition removeHello()
delete welcome_map[one][two];
delete welcome_map[one];
e = {_eventname : "removeHello"};
event e
end
Loading