mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-04 13:19:48 +03:00
ethereum: fix bug with rlp encoding of zero bytes
Null bytes in lists were getting eaten during concatenation. To avoid this, we track encoded item widths (which are always 1 or higher) and +can them all together. This likely did not affect any of the other Ethereum code, considering it nearly always measures atoms, and the null byte would be seen as no bytes in that case.
This commit is contained in:
parent
c5393bcf8c
commit
0c1e999cdb
@ -76,12 +76,17 @@
|
||||
(encode-length wid.b.in 0x80)
|
||||
::
|
||||
%l
|
||||
=/ out=@
|
||||
%+ roll l.in
|
||||
|= [ni=item en=@]
|
||||
(cat 3 (encode ni) en)
|
||||
%^ cat 3 out
|
||||
(encode-length (met 3 out) 0xc0)
|
||||
:: we +can because b+1^0x0 encodes to 0x00
|
||||
::
|
||||
=/ l=(list byts)
|
||||
%+ turn l.in
|
||||
|= ni=item
|
||||
=+ (encode ni)
|
||||
[(max 1 (met 3 -)) -]
|
||||
%+ can 3
|
||||
%+ snoc (flop l)
|
||||
=- (met 3 -)^-
|
||||
(encode-length (roll (turn l head) add) 0xc0)
|
||||
==
|
||||
::
|
||||
++ encode-length
|
||||
|
@ -36,6 +36,14 @@
|
||||
:+ "set of three"
|
||||
0xc7c0.c1c0.c3c0.c1c0
|
||||
l+[l+~ l+[l+~ ~] l+[l+~ l+[l+~ ~] ~] ~]
|
||||
::
|
||||
:+ "list with zero byte"
|
||||
0xc311.0022
|
||||
l+~[b+1^0x11 b+1^0x0 b+1^0x22]
|
||||
::
|
||||
:+ "list of zero bytes"
|
||||
0xc300.0000
|
||||
l+~[b+1^0x0 b+1^0x0 b+1^0x0]
|
||||
==
|
||||
::
|
||||
|%
|
||||
@ -48,8 +56,8 @@
|
||||
%+ weld
|
||||
%+ category "encode"
|
||||
%+ expect-eq
|
||||
!> dat
|
||||
!> (encode rlp)
|
||||
!> `@ux`dat
|
||||
!> `@ux`(encode rlp)
|
||||
%+ category "decode"
|
||||
%+ expect-eq
|
||||
!> rlp
|
||||
|
Loading…
Reference in New Issue
Block a user