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:
Fang 2021-09-18 20:14:26 +02:00
parent c5393bcf8c
commit 0c1e999cdb
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
2 changed files with 21 additions and 8 deletions

View File

@ -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

View File

@ -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