1
0
mirror of https://github.com/danog/ton.git synced 2024-12-04 02:18:00 +01:00
ton/crypto/func/test/b2_0.fc
2019-09-07 14:33:36 +04:00

64 lines
2.3 KiB
Plaintext

int now() asm "NOW";
int cell_hash(cell c)
asm "HASHCU";
int slice_hash(slice s)
asm "HASHSU";
int check_signature(int hash, slice signature, int public_key)
asm "CHKSIGNU";
;; () throw_if(int excno, int cond) impure
;; asm "THROWARGIF";
cell get_data() asm "c4 PUSH";
() set_data(cell c) impure asm "c4 POP";
() accept_message() impure asm "ACCEPT";
slice begin_parse(cell c) asm "CTOS";
() end_parse(slice s) impure asm "ENDS";
(slice, cell) load_ref(slice s) asm( -> 1 0) "LDREF";
(slice, int) zload_int(slice s, int len) asm(s len -> 1 0) "LDIX";
(slice, int) zload_uint(slice s, int len) asm( -> 1 0) "LDUX";
int zpreload_int(slice s, int len) asm "PLDIX";
int zpreload_uint(slice s, int len) asm "PLDUX";
(slice, slice) load_bits(slice s, int len) asm(s len -> 1 0) "LDSLICEX";
slice preload_bits(slice s, int len) asm "PLDSLICEX";
cell set_idict_ref(cell dict, int key_len, int index, cell value) asm(value index dict key_len) "DICTISETREF";
builder begin_cell() asm "NEWC";
builder store_ref(builder b, cell c) asm(c b) "STREF";
builder zstore_uint(builder b, int x, int len) asm(x b len) "STUX";
builder zstore_int(builder b, int x, int len) asm(x b len) "STIX";
cell end_cell(builder b) asm "ENDC";
;; Simple configuration smart contract
() recv_internal(cell in_msg) impure {
;; do nothing for internal messages
}
() recv_external(cell in_msg) impure {
var (cs0, signature) = load_bits(begin_parse(in_msg), 512);
var (cs, msg_seqno) = zload_uint(cs0, 32);
(cs, var valid_until) = zload_uint(cs, 32);
throw_if(35, valid_until < now());
var (cs2, cfg_dict) = load_ref(begin_parse(get_data()));
(cs2, var stored_seqno) = zload_uint(cs2, 32);
(cs2, var public_key) = zload_uint(cs2, 256);
end_parse(cs2);
throw_unless(33, msg_seqno == stored_seqno);
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
accept_message();
(cs, var param_index) = zload_uint(cs, 32);
(cs, var param_value) = load_ref(cs);
end_parse(cs);
;; cfg_dict = set_idict_ref(cfg_dict, 32, param_index, param_value);
;; var cb = begin_cell();
;; cb = store_ref(cb, cfg_dict);
var cb = store_ref(begin_cell(), set_idict_ref(cfg_dict, 32, param_index, param_value));
cb = zstore_uint(cb, stored_seqno + 1, 32);
cb = zstore_uint(cb, public_key, 256);
set_data(end_cell(cb));
}