naive: convert can -> cad

Avoid bugs where we miscount the length of assembled atoms.
This commit is contained in:
Philip Monk 2021-04-28 19:19:50 -07:00
parent 5d52171a47
commit 36a10eb083
No known key found for this signature in database
GPG Key ID: B66E1F02604E44EC
3 changed files with 29 additions and 18 deletions

View File

@ -376,10 +376,16 @@
%vote voting-proxy.own.u.point
%transfer transfer-proxy.own.u.point
==
:: We include a domain separator to avoid letting signatures be
:: accidentally reused with other applications. We include the name
:: UrbitID, a signature format version number, and the EIP-155 chain
:: ID.
::
:: We also include a nonce so that a transaction cannot be
:: rebroadcast.
::
=/ prepared-data=octs
:- :(add 12 (met 3 chain-t) 1 4 p.raw.raw-tx)
%: can 3
%: cad 3
14^'UrbitIDV1Chain'
(met 3 chain-t)^chain-t
1^':'
@ -387,10 +393,12 @@
raw.raw-tx
~
==
:: Wallets which support personal_sign include this preamble to avoid
:: letting personal_sign be used to sign ethereum transactions
::
=/ signed-data=octs
=/ len (ud-to-ascii p.prepared-data)
:- :(add 26 (met 3 len) p.prepared-data)
%: can 3
%: cad 3
26^'\19Ethereum Signed Message:\0a'
(met 3 len)^len
prepared-data

View File

@ -225,6 +225,16 @@
?~ b 0
(add (end [a p.i.b] q.i.b) (lsh [a p.i.b] $(b t.b)))
::
++ cad :: assemble specific
~/ %cad
|= [a=bloq b=(list [p=step q=@])]
^- [=step @]
:_ (can a b)
|-
?~ b
0
(add p.i.b $(b t.b))
::
++ rep :: assemble fixed
~/ %rep
|= [a=bite b=(list @)]

View File

@ -67,8 +67,7 @@
|= [pk=@ nonce=@ud tx=octs] ^- octs
=/ prepared-data=octs
=/ chain-t (rsh [3 2] (scot %ui 1.337))
:- :(add 12 (met 3 chain-t) 1 4 p.tx)
%: can 3
%: cad:naive 3
14^'UrbitIDV1Chain'
(met 3 chain-t)^chain-t
1^':'
@ -79,16 +78,14 @@
=/ sign-data
=/ len (rsh [3 2] (scot %ui p.prepared-data))
%- keccak-256:keccak:crypto
:- :(add 26 (met 3 len) p.prepared-data)
%: can 3
%: cad:naive 3
26^'\19Ethereum Signed Message:\0a'
(met 3 len)^len
prepared-data
~
==
=+ (ecdsa-raw-sign:secp256k1:secp:crypto sign-data pk)
:- :(add 1 32 32 p.tx)
(can 3 1^v 32^s 32^r tx ~)
(cad:naive 3 1^v 32^s 32^r tx ~)
::
++ l1
|%
@ -173,8 +170,7 @@
++ transfer-point
|= [nonce=@ud =ship pk=@ =address proxy=@tas reset=?] ^- octs
%^ sign-tx pk nonce
:- :(add 1 4 1 4 20)
%: can 3
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^(can 0 7^%0 1^reset ~) :: %transfer-point
@ -189,8 +185,7 @@
==
^- octs
%^ sign-tx pk nonce
:- :(add 1 4 1 4 32 32 4)
%: can 3
%: cad:naive 3
(from-proxy:bits proxy)
4^ship
1^(can 0 7^%2 1^breach ~) :: %configure-keys
@ -258,8 +253,7 @@
%reject %6
%detach %7
==
:- :(add 1 4 1 4 4)
%: can 3
%: cad:naive 3
(from-proxy proxy)
4^child
1^(can 0 7^op 1^0 ~)
@ -277,8 +271,7 @@
%set-spawn-proxy %9
%set-transfer-proxy %10
==
:- :(add 1 4 1 4 20)
%: can 3
%: cad:naive 3
(from-proxy proxy)
4^from
1^(can 0 7^op 1^0 ~)