Skip to content

Commit 92874f0

Browse files
committed
Ensure new changes do not change previous behavior
1 parent 80d0964 commit 92874f0

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

substrate/frame/revive/src/wasm/runtime.rs

+33-34
Original file line numberDiff line numberDiff line change
@@ -983,47 +983,46 @@ impl<'a, E: Ext, M: ?Sized + Memory<E::T>> Runtime<'a, E, M> {
983983
if let Some(value) = outcome {
984984
self.adjust_gas(charged, costs(value.len() as u32));
985985

986-
// For fixed-size operations use write_fixed_sandbox_output
987-
if out_len_ptr == SENTINEL {
988-
let mut fixed_output = [0u8; 32];
989-
let len = core::cmp::min(value.len(), 32);
990-
fixed_output[..len].copy_from_slice(&value[..len]);
986+
match read_mode {
987+
StorageReadMode::ZeroIfMissing => {
988+
let mut fixed_output = [0u8; 32];
989+
let len = core::cmp::min(value.len(), 32);
990+
fixed_output[..len].copy_from_slice(&value[..len]);
991991

992-
self.write_fixed_sandbox_output(
993-
memory,
994-
out_ptr,
995-
&fixed_output,
996-
false,
997-
already_charged,
998-
)?;
999-
} else {
1000-
self.write_sandbox_output(
1001-
memory,
1002-
out_ptr,
1003-
out_len_ptr,
1004-
&value,
1005-
false,
1006-
already_charged,
1007-
)?;
992+
self.write_fixed_sandbox_output(
993+
memory,
994+
out_ptr,
995+
&fixed_output,
996+
false,
997+
already_charged,
998+
)?;
999+
Ok(ReturnErrorCode::Success)
1000+
},
1001+
StorageReadMode::ErrorIfMissing => {
1002+
// preserve original behavior
1003+
self.write_sandbox_output(
1004+
memory,
1005+
out_ptr,
1006+
out_len_ptr,
1007+
&value,
1008+
false,
1009+
already_charged,
1010+
)?;
1011+
Ok(ReturnErrorCode::Success)
1012+
},
10081013
}
1009-
1010-
Ok(ReturnErrorCode::Success)
10111014
} else {
10121015
self.adjust_gas(charged, costs(0));
10131016

10141017
match read_mode {
10151018
StorageReadMode::ZeroIfMissing => {
1016-
if out_len_ptr == SENTINEL {
1017-
self.write_fixed_sandbox_output(
1018-
memory,
1019-
out_ptr,
1020-
&[0u8; 32],
1021-
false,
1022-
already_charged,
1023-
)?;
1024-
} else {
1025-
memory.write(out_len_ptr, &0u32.encode())?;
1026-
}
1019+
self.write_fixed_sandbox_output(
1020+
memory,
1021+
out_ptr,
1022+
&[0u8; 32],
1023+
false,
1024+
already_charged,
1025+
)?;
10271026
Ok(ReturnErrorCode::Success)
10281027
},
10291028
StorageReadMode::ErrorIfMissing => Ok(ReturnErrorCode::KeyNotFound),

0 commit comments

Comments
 (0)