Fixes assembly bug and adds tests to cover it.

This commit is contained in:
Erik Kundt
2018-05-30 17:46:43 +02:00
parent 98d52beba3
commit fea0d116f7
2 changed files with 50 additions and 29 deletions
+4 -5
View File
@@ -848,9 +848,9 @@ void ArrayUtils::popStorageArrayElement(ArrayType const& _type) const
}
case 1 {
// long byte array
mstore(0, ref)
let length := div(slot_value, 2)
let slot := keccak256(0, 0x20)
mstore(0, ref)
switch length
case 32
{
@@ -861,14 +861,13 @@ void ArrayUtils::popStorageArrayElement(ArrayType const& _type) const
}
default
{
let slot_offset := div(sub(length, 1), 32)
let length_offset := and(sub(length, 1), 0x1f)
slot := add(slot, slot_offset)
let offset_inside_slot := and(sub(length, 1), 0x1f)
slot := add(slot, div(sub(length, 1), 32))
let data := sload(slot)
// Zero-out the suffix of the byte array by masking it.
// ((1<<(8 * (32 - offset))) - 1)
let mask := sub(exp(0x100, sub(32, length_offset)), 1)
let mask := sub(exp(0x100, sub(32, offset_inside_slot)), 1)
data := and(not(mask), data)
sstore(slot, data)