Guest User

Untitled

a guest
Oct 26th, 2019
154
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.fift" 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. dictnew
  56. {
  57. <b b> <s
  58. -rot
  59. 256
  60. udict!
  61. drop
  62. } 16 times
  63. =: keys
  64.  
  65. 10 constant min_signature_num
  66.  
  67. // INITIALIZE PERSISTENT STORAGE
  68. min_signature_num keys contract_storage_initializer runvmdict
  69. drop // TODO check execution code
  70. constant contract_storage
  71.  
  72. <b b{00110} s, <b contract_code s, b> ref, contract_storage ref, b>
  73. dup =: state_init
  74. dup hashu wc swap 2constant multisig_addr
  75.  
  76. multisig_addr
  77. 256 u>B swap
  78. 32 u>B
  79. min_signature_num 8 u>B
  80. keys_num 8 u>B
  81. B+ B+ B+ =: contract_description
  82. contract_description "multisig.ctr" B>file
  83. multisig_addr swap drop 6277101735386680763835789423207666416102355444464034512896 / =: uniq_token
  84.  
  85. <b 0 8 u, b> <s =: init_message
  86.  
  87. <b b{1000100} s, multisig_addr addr, b{000010} s, state_init <s s, b{0} s, init_message s, b>
  88. 2 boc+>B
  89. "multisig-init.boc" B>file
  90.  
  91.  
  92. 1 constant op_num
  93. 1 constant seq_no
  94. 0xFFFFFFFF constant unix_time_bound
  95.  
  96. 10 =: min_signatures_num
  97.  
  98. example_message_root
  99. 0 dictnew 7 udict! drop constant order_dict
  100.  
  101. <b op_num 8 u, seq_no 32 u, unix_time_bound 32 u, min_signatures_num 8 u, uniq_token 64 u,
  102. dup constant message_builder
  103. order_dict dict, b> constant data_for_signing
  104.  
  105.  
  106. pub01 priv01
  107. pub02 priv02
  108. pub03 priv03
  109. pub04 priv04
  110. pub05 priv05
  111. pub06 priv06
  112. pub07 priv07
  113. pub08 priv08
  114. pub09 priv09
  115. pub0a priv0a
  116. data_for_signing
  117. dictnew
  118. // SIGNING
  119. {
  120. swap dup hashu 3 roll ed25519_sign_uint // keys pubk dict data_for_signing signature
  121. <b swap B, b> <s
  122. // keys pubk dict data_for_signing <signature>
  123. 3 -roll 3 -roll
  124. 256 udict! drop // keys data_for_siging dict
  125. } 9 times
  126. =: provided_signatures
  127. hashu swap ed25519_sign_uint =: header_signature
  128.  
  129.  
  130.  
  131. message_builder swap 256 u, header_signature B, provided_signatures dict, order_dict dict, b> constant store_order_message
  132.  
  133. <b b{1000100} s, multisig_addr addr, 0 Gram, b{00} s, store_order_message ref, b>
  134. 2 boc+>B
  135. "10signatures.boc" B>file
  136.  
  137.  
  138. ."new multisig wallet address = " multisig_addr .addr cr
  139. ."Non-bounceable address (for init): " multisig_addr 7 .Addr cr
  140. ."Bounceable address (for later access): " multisig_addr 6 .Addr cr
  141. ."(Saved multisig contract creating query to file multisig-init.boc)" cr
  142. ."(Saved order with 10 signatures to file 10signatures.boc)" cr
RAW Paste Data