forked from ton-rocks/general-ton-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-zerostate.sandbox.fif
239 lines (215 loc) · 8.15 KB
/
gen-zerostate.sandbox.fif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/create-state -s
"TonUtil.fif" include
"Asm.fif" include
"Lists.fif" include
def? $1 { @' $1 } { "" } cond constant suffix
{ suffix $+ } : +suffix
256 1<<1- 15 / constant AllOnes
wc_master setworkchain
-239 setglobalid // negative value means a test instance of the blockchain
// Initial state of Workchain 0 (Basic workchain)
0 mkemptyShardState
cr ."initial basechain state is:" cr dup <s csr. cr
dup dup 31 boc+>B dup Bx. cr
dup "basestate0" +suffix +".boc" tuck B>file
."(Initial basechain state saved to file " type .")" cr
Bhashu dup =: basestate0_fhash
."file hash=" dup 64x. space 256 u>B dup B>base64url type cr
"basestate0" +suffix +".fhash" B>file
hashu dup =: basestate0_rhash
."root hash=" dup 64x. space 256 u>B dup B>base64url type cr
"basestate0" +suffix +".rhash" B>file
basestate0_rhash basestate0_fhash now 0 1 32 0 add-std-workchain
config.workchains!
// SmartContract #1 (Simple wallet)
<{ SETCP0 DUP IFNOTRET // return if recv_internal
DUP 85143 INT EQUAL IFJMP:<{ // "seqno" get-method
DROP c4 PUSHCTR CTOS 32 PLDU // cnt
}>
INC 32 THROWIF // fail unless recv_external
512 INT LDSLICEX DUP 32 PLDU // sign cs cnt
c4 PUSHCTR CTOS 32 LDU 256 LDU ENDS // sign cs cnt cnt' pubk
s1 s2 XCPU // sign cs cnt pubk cnt' cnt
EQUAL 33 THROWIFNOT // ( seqno mismatch? )
s2 PUSH HASHSU // sign cs cnt pubk hash
s0 s4 s4 XC2PU // pubk cs cnt hash sign pubk
CHKSIGNU // pubk cs cnt ?
34 THROWIFNOT // signature mismatch
ACCEPT
SWAP 32 LDU NIP 8 LDU LDREF ENDS // pubk cnt mode msg
SWAP SENDRAWMSG // pubk cnt ; ( message sent )
INC NEWC 32 STU 256 STU ENDC c4 POPCTR
}>c
// code
<b 0 32 u,
"main-wallet" +suffix +".pk" load-generate-keypair drop
B,
b> // data
Libs{
x{ABACABADABACABA} s>c public_lib
x{1234} x{5678} |_ s>c private_lib
}Libs // libraries
GR$4999990000 // balance
0 // split_depth
0 // ticktock
AllOnes 0 * // address
6 // mode: create+setaddr
register_smc
dup make_special dup constant smc1_addr
Masterchain over
2dup ."wallet address = " .addr cr 2dup 6 .Addr cr
"main-wallet" +suffix +".addr" save-address-verbose
// SmartContract #3
PROGRAM{
recv_internal x{} PROC
run_ticktock PROC:<{
c4 PUSHCTR CTOS 32 LDU 256 LDU ENDS
NEWC ROT INC 32 STUR OVER 256 STUR ENDC
c4 POPCTR
// first 32 bits of persistent data have been increased
// remaining 256 bits with an address have been fetched
// create new empty message with 0.1 Grams to that address
NEWC b{00100010011111111} STSLICECONST TUCK 256 STU
100000000 INT STGRAMS // store 0.1 Grams
1 4 + 4 + 64 + 32 + 1+ 1+ INT STZEROES ENDC
// send raw message from Cell
ZERO SENDRAWMSG
-17 INT 256 STIR 130000000 INT STGRAMS
107 INT STZEROES ENDC
ZERO // another message with 0.13 Grams to account -17
NEWC b{11000100100000} "test" $>s |+ STSLICECONST
123456789 INT STGRAMS
107 INT STZEROES "Hello, world!" $>s STSLICECONST ENDC
ZERO SENDRAWMSG SENDRAWMSG // external message to address "test"
}>
}END>c
// code
<b x{11EF55AA} s, smc1_addr 256 u, b> // data
// empty_cell // libraries
Libs{
x{ABACABADABACABA} s>c public_lib
x{1234} x{5678} |_ s>c public_lib
}Libs // libraries
GR$1 // balance
0 // split_depth
3 // ticktock: tick
2 // mode: create
register_smc
dup make_special dup constant smc3_addr
."address = " 64x. cr
/*
*
* SmartContract #4 (elector)
*
*/
"auto/elector-code.fif" include // code in separate source file
<b 0 1 1+ 1+ 4 + 32 + u, 0 256 u, b> // data: dict dict dict grams uint32 uint256
empty_cell // libraries
GR$10 // balance: 10 grams
0 // split_depth
2 // ticktock: tick
AllOnes 3 * // address: -1:333...333
6 // mode: create + setaddr
register_smc
dup make_special dup constant smc4_addr dup constant elector_addr
Masterchain swap
."elector smart contract address = " 2dup .addr cr 2dup 7 .Addr cr
"elector" +suffix +".addr" save-address-verbose
/*
*
* Configuration Parameters
*
*/
// version capabilities
1 capCreateStats capBounceMsgBody or capReportVersion or capShortDequeue or config.version!
// max-validators max-main-validators min-validators
1000 100 3 config.validator_num!
// min-stake max-stake min-total-stake max-factor
GR$10000 GR$10000000 GR$30000 sg~3 config.validator_stake_limits!
// elected-for elect-start-before elect-end-before stakes-frozen-for
// 400000 200000 4000 400000 config.election_params!
4096 2048 512 4096 config.election_params! // DEBUG
// config-addr = -1:5555...5555
AllOnes 5 * constant config_addr
config_addr config.config_smc!
// elector-addr
elector_addr config.elector_smc!
// 1 sg* 100 sg* 1000 sg* 1000000 sg* config.storage_prices! // old values (too high)
1 500 1000 500000 config.storage_prices!
config.special!
// gas_price gas_limit special_gas_limit gas_credit block_gas_limit freeze_due_limit delete_due_limit flat_gas_limit flat_gas_price --
1000 sg* 1 *M dup 10000 10 *M GR$0.1 GR$1.0 1000 1000000 config.gas_prices!
10000 sg* 1 *M 10 *M 10000 10 *M GR$0.1 GR$1.0 1000 10000000 config.mc_gas_prices!
// lump_price bit_price cell_price ihr_factor first_frac next_frac
1000000 1000 sg* 100000 sg* 3/2 sg*/ 1/3 sg*/ 1/3 sg*/ config.fwd_prices!
10000000 10000 sg* 1000000 sg* 3/2 sg*/ 1/3 sg*/ 1/3 sg*/ config.mc_fwd_prices!
// mc-cc-lifetime sh-cc-lifetime sh-val-lifetime sh-val-num mc-shuffle
250 250 5500 7 true config.catchain_params!
// round-candidates next-cand-delay-ms consensus-timeout-ms fast-attempts attempt-duration cc-max-deps max-block-size max-collated-size new-cc-ids
3 1000 16000 3 8 4 2 *Mi 2 *Mi true config.consensus_params!
128 *Ki 512 *Ki 1 *Mi triple // [ underload soft hard ] : block bytes limit
100000 500000 1000000 triple // gas limits
1000 5000 10000 triple // lt limits
triple dup untriple config.mc_block_limits!
untriple config.block_limits!
GR$1.7 GR$1 config.block_create_fees!
// smc1_addr config.collector_smc!
smc1_addr config.minter_smc!
1000000000000 -17 of-cc 666666666666 239 of-cc cc+ config.to_mint!
( 0 1 9 10 12 14 15 16 17 18 20 21 22 23 24 25 28 34 ) config.mandatory_params!
( -999 -1000 -1001 0 1 9 10 12 14 15 16 17 32 34 36 ) config.critical_params!
// [ min_tot_rounds max_tot_rounds min_wins max_losses min_store_sec max_store_sec bit_pps cell_pps ]
// first for ordinary proposals, then for critical proposals
_( 2 3 2 2 1000000 10000000 1 500 )
_( 4 7 4 2 5000000 20000000 2 1000 )
config.param_proposals_setup!
// deposit bit_pps cell_pps
GR$100 1 500 config.complaint_prices!
"validator-keys" +suffix +".pub" file>B
{ dup Blen } { 32 B| swap dup ."Validator public key = " Bx. cr
17 add-validator } while drop
// newkeypair nip dup ."Validator #1 public key = " Bx. cr
// 17 add-validator
// newkeypair nip dup ."Validator #2 public key = " Bx. cr
// 239 add-validator
2048 =: orig_vset_valid_for // original validator set valid 2000 seconds
now dup orig_vset_valid_for + 0 config.validators!
/*
*
* SmartContract #5 (Configuration smart contract)
*
*/
"auto/config-code.fif" include // code in separate source file
<b configdict ref, // initial configuration
0 32 u, // seqno
"config-master" +suffix +".pk" load-generate-keypair drop
B,
dictnew dict, // vote dict
b> // data
empty_cell // libraries
GR$10 // balance
0 1 config_addr 6 register_smc // tock
dup set_config_smc
Masterchain swap
."config smart contract address = " 2dup .addr cr 2dup 7 .Addr cr
"config-master" +suffix +".addr" save-address-verbose
// Other data
/*
*
* Create state
*
*/
create_state
cr cr ."new state is:" cr dup <s csr. cr
dup 31 boc+>B dup Bx. cr
dup "zerostate" +suffix +".boc" tuck B>file
."(Initial masterchain state saved to file " type .")" cr
Bhashu dup =: zerostate_fhash
."file hash= " dup X. space 256 u>B dup B>base64url type cr
"zerostate" +suffix +".fhash" B>file
hashu dup =: zerostate_rhash ."root hash= " dup X. space 256 u>B dup B>base64url type cr
"zerostate" +suffix +".rhash" B>file
basestate0_rhash ."Basestate0 root hash= " dup X. space 256 u>B B>base64url type cr
basestate0_fhash ."Basestate0 file hash= " dup X. space 256 u>B B>base64url type cr
zerostate_rhash ."Zerostate root hash= " dup X. space 256 u>B B>base64url type cr
zerostate_fhash ."Zerostate file hash= " dup X. space 256 u>B B>base64url type cr