1
0
mirror of https://github.com/danog/ton.git synced 2024-12-12 09:09:37 +01:00
ton/crypto/func/test/b2.fc

61 lines
2.1 KiB
Plaintext
Raw Normal View History

2019-09-07 12:03:22 +02:00
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) load_int(slice s, int len) asm(s len -> 1 0) "LDIX";
;; (slice, int) load_uint(slice s, int len) asm( -> 1 0) "LDUX";
;; int preload_int(slice s, int len) asm "PLDIX";
;; int preload_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 store_uint(builder b, int x, int len) asm(x b len) "STUX";
;; builder store_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) = load_uint(cs0, 32);
(cs, var valid_until) = load_uint(cs, 32);
throw_if(35, valid_until < now());
var (cs2, cfg_dict) = load_ref(begin_parse(get_data()));
(cs2, var stored_seqno) = load_uint(cs2, 32);
(cs2, var public_key) = load_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) = load_uint(cs, 32);
(cs, var param_value) = load_ref(cs);
end_parse(cs);
var cb = store_ref(begin_cell(), set_idict_ref(cfg_dict, 32, param_index, param_value));
cb = store_uint(cb, stored_seqno + 1, 32);
cb = store_uint(cb, public_key, 256);
set_data(end_cell(cb));
}