tealish icon indicating copy to clipboard operation
tealish copied to clipboard

Replacing the value of a field of a structured box can keep parts of the replaced value

Open wenkanglu opened this issue 1 year ago • 1 comments

Describe the bug {box_name}.{field_name} = {value}. replaces the field {field_name} of box {box_name} created from a struct without considering the size of {value}. This issue tracks the bug when parts of the replaced value remain after replacing it with a byte array of a smaller size than the current value.

To Reproduce

#pragma version 8

struct UserInfo:
    favourite_colour: bytes[20]
end

if Txn.ApplicationID == 0:
    exit(1)
end

box<UserInfo> info_box = CreateBox("foo")
info_box.favourite_colour = "yellow"
info_box.favourite_colour = "red"
exit(1)

Expected behavior Field favourite_colour of box with key "foo" should have a value of "red" but is instead "redlow".

Additional context Related issue: #75

wenkanglu avatar Feb 06 '23 16:02 wenkanglu