Guest User

Untitled

a guest
Oct 26th, 2019
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/fift -s
  2. "TonUtil.fif" include
  3. "Asm.fif" include
  4.  
  5. "multisig.fif" include <s constant contract_code
  6. "multisig_init_storage.fift" include <s constant contract_storage_initializer // (uniq_token, min_signature_num, public_keys_dict) -> cell
  7.  
  8. // PARAMS
  9. 0 =: wc
  10. 16 =: keys_num
  11.  
  12. // CREATE KEYS
  13. {
  14. file>B dup Blen 32 <> abort"Private key must be exactly 32 bytes long"
  15. dup priv>pub swap
  16. } : load-keypair'
  17. // ( fname -- pubkey privkey )
  18. { dup file-exists?
  19. { load-keypair' }
  20. { dup newkeypair swap rot over swap B>file
  21. rot drop
  22. } cond
  23. } : load-generate-keypair'
  24. { load-generate-keypair' swap 256 B>u@ } : nkp
  25.  
  26. "p01.pk" nkp =: pub01 =: priv01
  27. "p02.pk" nkp =: pub02 =: priv02
  28. "p03.pk" nkp =: pub03 =: priv03
  29. "p04.pk" nkp =: pub04 =: priv04
  30. "p05.pk" nkp =: pub05 =: priv05
  31. "p06.pk" nkp =: pub06 =: priv06
  32. "p07.pk" nkp =: pub07 =: priv07
  33. "p08.pk" nkp =: pub08 =: priv08
  34. "p09.pk" nkp =: pub09 =: priv09
  35. "p0a.pk" nkp =: pub0a =: priv0a
  36. "p0b.pk" nkp =: pub0b =: priv0b
  37. "p0c.pk" nkp =: pub0c =: priv0c
  38. "p0d.pk" nkp =: pub0d =: priv0d
  39. "p0e.pk" nkp =: pub0e =: priv0e
  40. "p0f.pk" nkp =: pub0f =: priv0f
  41. "p10.pk" nkp =: pub10 =: priv10
  42.  
  43.  
  44. // CREATE ORDER
  45. -1 constant bounce
  46. <b b{01} s, bounce 1 i, b{000100} s, 0 4973788529520401637175306036311921661440676526367978167240186796235618131100 addr, 0 Gram, 0 9 64 32 + + 1+ u,
  47. 3 10 u,
  48. b> constant example_message_body
  49. 3 constant message_mode
  50. <b message_mode 8 u, example_message_body ref, b> <s constant example_message_root
  51.  
  52.  
  53. // CREATE LIST OF PUBKEYS
  54. pub01 pub02 pub03 pub04 pub05 pub06 pub07 pub08 pub09 pub0a pub0b pub0c pub0d pub0e pub0f pub10
  55. 1
  56. dictnew
  57. {
  58. swap 1+ dup
  59. <b swap 8 u, b> <s
  60. 3 -roll
  61. 3 -roll
  62. 256
  63. udict!
  64. drop
  65. } 16 times
  66. =: keys
  67.  
  68.  
  69. 10 constant min_signature_num
  70.  
  71. // INITIALIZE PERSISTENT STORAGE
  72. min_signature_num keys contract_storage_initializer runvmdict
  73. drop // TODO check execution code
  74. constant contract_storage
  75.  
  76. <b b{00110} s, <b contract_code s, b> ref, contract_storage ref, b>
  77. dup =: state_init
  78. dup hashu wc swap 2constant multisig_addr
  79.  
  80. multisig_addr
  81. 256 u>B swap
  82. 32 u>B
  83. min_signature_num 8 u>B
  84. keys_num 8 u>B
  85. B+ B+ B+ =: contract_description
  86. contract_description "multisig.ctr" B>file
  87. multisig_addr swap drop 6277101735386680763835789423207666416102355444464034512896 / =: uniq_token
  88.  
  89. <b 0 8 u, b> <s =: init_message
  90.  
  91. <b b{1000100} s, multisig_addr addr, b{000010} s, state_init <s s, b{0} s, init_message s, b>
  92. 2 boc+>B
  93. "multisig-init.boc" B>file
  94.  
  95.  
  96. 1 constant op_num
  97. 1 constant seq_no
  98. 0xFFFFFFFF constant unix_time_bound
  99.  
  100. 10 =: min_signatures_num
  101.  
  102. example_message_root
  103. 0 dictnew 7 udict! drop constant order_dict
  104.  
  105. <b op_num 8 u, seq_no 32 u, unix_time_bound 32 u, min_signatures_num 8 u, uniq_token 64 u,
  106. dup =: message_builder
  107. order_dict dict, =: main_order_data_slice
  108. 0 =: proof_token // can be arbitrary here
  109. main_order_data_slice proof_token 255 u, b> =: data_for_signing
  110.  
  111.  
  112. pub02 priv02
  113. pub03 priv03
  114. pub04 priv04
  115. pub05 priv05
  116. pub06 priv06
  117. pub07 priv07
  118. pub08 priv08
  119. pub09 priv09
  120. pub0a priv0a
  121. data_for_signing
  122. <b
  123. // SIGNING
  124. {
  125. swap dup hashu 3 roll ed25519_sign_uint // keys pubk prev_builder data_for_signing signature
  126. <b swap B, 3 roll 256 u, proof_token 255 u, rot b> ref,
  127. } 9 times
  128. b> =: signatures_stairs
  129.  
  130. message_builder signatures_stairs ref, order_dict dict, b> =: mbody
  131.  
  132. signatures_stairs hashu 1 >> =: proof_token // here it is not arbitrary, since cover all message
  133. main_order_data_slice proof_token 255 u, b> hashu priv01 ed25519_sign_uint constant header_signature
  134.  
  135. <b header_signature B,
  136. <b pub01 256 u, mbody <s s,
  137. b> ref,
  138. b> <s =: store_order_message
  139.  
  140. <b b{1000100} s, multisig_addr addr, 0 Gram, b{00} s, store_order_message s, b>
  141. 2 boc+>B
  142. "10signatures.boc" B>file
  143.  
  144.  
  145. ."new multisig wallet address = " multisig_addr .addr cr
  146. ."Non-bounceable address (for init): " multisig_addr 7 .Addr cr
  147. ."Bounceable address (for later access): " multisig_addr 6 .Addr cr
  148. ."(Saved multisig contract creating query to file multisig-init.boc)" cr
  149. ."(Saved order with 10 signatures to file 10signatures.boc)" cr
RAW Paste Data