Skip to content

Instantly share code, notes, and snippets.

@hrkrshnn
Created September 28, 2021 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrkrshnn/81b8e54f7bcc8f8a9f467c84d8ef1ff8 to your computer and use it in GitHub Desktop.
Save hrkrshnn/81b8e54f7bcc8f8a9f467c84d8ef1ff8 to your computer and use it in GitHub Desktop.
The new file is after the storateBytes fix.
diff -u /tmp/old.yul /tmp/new.yul
--- /tmp/old.yul 2021-09-28 13:41:14.873051780 +0200
+++ /tmp/new.yul 2021-09-28 13:39:28.096229030 +0200
@@ -53,8 +53,8 @@
}
- function update_byte_slice_32_shift_0(value, toInsert) -> result {
- let mask := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ function update_byte_slice_1_shift_0(value, toInsert) -> result {
+ let mask := 255
toInsert := shift_left_0(toInsert)
value := and(value, not(mask))
result := or(value, and(toInsert, mask))
@@ -70,7 +70,7 @@
function update_storage_value_offset_0t_userDefinedValueType$_MyInt8_$2_to_t_userDefinedValueType$_MyInt8_$2(slot, value_0) {
let convertedValue_0 := convert_t_int8_to_t_int8(value_0)
- sstore(slot, update_byte_slice_32_shift_0(sload(slot), prepare_store_t_userDefinedValueType$_MyInt8_$2(convertedValue_0)))
+ sstore(slot, update_byte_slice_1_shift_0(sload(slot), prepare_store_t_userDefinedValueType$_MyInt8_$2(convertedValue_0)))
}
function cleanup_t_uint256(value) -> cleaned {
@@ -104,13 +104,27 @@
converted := cleanup_t_bytes2(value)
}
+ function shift_left_8(value) -> newValue {
+ newValue :=
+
+ shl(8, value)
+
+ }
+
+ function update_byte_slice_2_shift_1(value, toInsert) -> result {
+ let mask := 16776960
+ toInsert := shift_left_8(toInsert)
+ value := and(value, not(mask))
+ result := or(value, and(toInsert, mask))
+ }
+
function prepare_store_t_userDefinedValueType$_MyBytes2_$4(value) -> ret {
ret := value
}
- function update_storage_value_offset_0t_userDefinedValueType$_MyBytes2_$4_to_t_userDefinedValueType$_MyBytes2_$4(slot, value_0) {
+ function update_storage_value_offset_1t_userDefinedValueType$_MyBytes2_$4_to_t_userDefinedValueType$_MyBytes2_$4(slot, value_0) {
let convertedValue_0 := convert_t_bytes2_to_t_bytes2(value_0)
- sstore(slot, update_byte_slice_32_shift_0(sload(slot), prepare_store_t_userDefinedValueType$_MyBytes2_$4(convertedValue_0)))
+ sstore(slot, update_byte_slice_2_shift_1(sload(slot), prepare_store_t_userDefinedValueType$_MyBytes2_$4(convertedValue_0)))
}
/// @src 0:47:166 "contract C {..."
@@ -131,7 +145,7 @@
let expr_23 := convert_t_uint16_to_t_bytes2(expr_22)
/// @src 0:123:163 "MyBytes2.wrap(bytes2(uint16(msg.value)))"
let expr_24 := convert_t_bytes2_to_t_bytes2(expr_23)
- update_storage_value_offset_0t_userDefinedValueType$_MyBytes2_$4_to_t_userDefinedValueType$_MyBytes2_$4(0x01, expr_24)
+ update_storage_value_offset_1t_userDefinedValueType$_MyBytes2_$4_to_t_userDefinedValueType$_MyBytes2_$4(0x00, expr_24)
}
/// @src 0:47:166 "contract C {..."
@@ -209,7 +223,7 @@
}
function cleanup_from_storage_t_userDefinedValueType$_MyInt8_$2(value) -> cleaned {
- cleaned := value
+ cleaned := and(value, 0xff)
}
function extract_from_storage_value_dynamict_userDefinedValueType$_MyInt8_$2(slot_value, offset) -> value {
@@ -256,8 +270,15 @@
}
+ function shift_left_240(value) -> newValue {
+ newValue :=
+
+ shl(240, value)
+
+ }
+
function cleanup_from_storage_t_userDefinedValueType$_MyBytes2_$4(value) -> cleaned {
- cleaned := value
+ cleaned := shift_left_240(value)
}
function extract_from_storage_value_dynamict_userDefinedValueType$_MyBytes2_$4(slot_value, offset) -> value {
@@ -273,8 +294,8 @@
/// @src 0:103:163 "MyBytes2 public b = MyBytes2.wrap(bytes2(uint16(msg.value)))"
function getter_fun_b_25() -> ret {
- let slot := 1
- let offset := 0
+ let slot := 0
+ let offset := 1
ret := read_from_storage_split_dynamic_t_userDefinedValueType$_MyBytes2_$4(slot, offset)
@@ -306,7 +327,7 @@
}
- data ".metadata" hex"a3646970667358221220830db95fbd84fb1cc4b735fb6b29aed22e28f47972858f202afb14c55cecfe3f6c6578706572696d656e74616cf564736f6c637827302e382e382d646576656c6f702e323032312e392e32382b636f6d6d69742e65323430383361320066"
+ data ".metadata" hex"a3646970667358221220712910874786da4c91f145be60bbefba50ad86b846cf1dcb03da1d794167b6916c6578706572696d656e74616cf564736f6c63430008080041"
}
}
Diff finished. Tue Sep 28 13:41:22 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment