Logging events with bytes array do not work as expected
When declaring an event with a bytes array parameter, like so;
Newgreeting: __log__({_sender: indexed(address), _newgreeting: bytes <= 20})
One would expect that when you would log a bytes array value into the log line;
@public
@payable
def setGreeting(_greeting: bytes <= 20) -> bool:
self.greeting = _greeting
log.Newgreeting( msg.sender, _greeting)
return True
So with _greeting = "Hello" the expected payload of the event call back argument should be:
0x48656c6c6f000000000000000000000000000000
The code however returns
0x0000000000000000000000000000000000000000
Setting the log line with a string literal "Hello", so;
@public
@payable
def setGreeting(_greeting: bytes <= 20) -> bool:
self.greeting = _greeting
log.Newgreeting( msg.sender, "Hello")
return True
results in the right string in the payload of the event call back argument.
Diving a bit deeper into this issue with a viper -f ir <filename.v.py> call shows that the compiler tries to convert the bytes array into a number of some kind. This is not expected, one would expect a simple byte-4-byte memory copy from one bytes array to the other.
# Line 16
[mstore,
448,
/* bytearray to number, verify no leading zbytes */
[with,
_sub,
352 <_greeting>,
[with,
_el1,
[mload, [add, 32, _sub]],
[with,
_len,
[clamp, 0, [mload, _sub], 32],
[seq,
[assert, [or, [iszero, _len], [div, _el1, [exp, 256, 31]]]],
[div, _el1, [exp, 256, [sub, 3, _len]]]]]]]],
I guess this is where you insert a cute animal picture ;-)
The problem appears that the String passed as a byte array is seen as a Str value and again converted in a byte array. I expect this to deliver a string that is seen as an empty string and hence padding that empty string with 00 for each byte in the byte array delivers 0x0000000000000000000000000000000000000000
