mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
initial commit
This commit is contained in:
commit
c2da007f40
1610 changed files with 398047 additions and 0 deletions
85
crypto/func/test/a6.fc
Normal file
85
crypto/func/test/a6.fc
Normal file
|
@ -0,0 +1,85 @@
|
|||
(int, int) f(int a, int b, int c, int d, int e, int f) {
|
||||
;; solve a 2x2 linear equation
|
||||
int D = a * d - b * c;
|
||||
int Dx = e * d - b * f;
|
||||
int Dy = a * f - e * c;
|
||||
return (Dx / D, Dy / D);
|
||||
}
|
||||
|
||||
int calc_phi() {
|
||||
var n = 1;
|
||||
repeat (70) { n *= 10; }
|
||||
var p = var q = 1;
|
||||
do {
|
||||
(p, q) = (q, p + q);
|
||||
} until (q > n);
|
||||
return muldivr(p, n, q);
|
||||
}
|
||||
|
||||
int calc_sqrt2() {
|
||||
var n = 1;
|
||||
repeat (70) { n *= 10; }
|
||||
var p = var q = 1;
|
||||
do {
|
||||
var t = p + q;
|
||||
(p, q) = (q, t + q);
|
||||
} until (q > n);
|
||||
return muldivr(p, n, q);
|
||||
}
|
||||
|
||||
var calc_root(m) {
|
||||
int base = 1;
|
||||
repeat(70) { base *= 10; }
|
||||
var (a, b, c) = (1, 0, - m);
|
||||
var (p1, q1, p2, q2) = (1, 0, 0, 1);
|
||||
do {
|
||||
int k = -1;
|
||||
var (a1, b1, c1) = (0, 0, 0);
|
||||
do {
|
||||
k += 1;
|
||||
(a1, b1, c1) = (a, b, c);
|
||||
c += b;
|
||||
c += b += a;
|
||||
} until (c > 0);
|
||||
(a, b, c) = (- c1, - b1, - a1);
|
||||
(p1, q1) = (k * p1 + q1, p1);
|
||||
(p2, q2) = (k * p2 + q2, p2);
|
||||
} until (p1 > base);
|
||||
return (p1, q1, p2, q2);
|
||||
}
|
||||
|
||||
{-
|
||||
operator _/%_ infix 20;
|
||||
|
||||
(int, int) ((int x) /% (int y)) {
|
||||
return (x / y, x % y);
|
||||
}
|
||||
|
||||
(int, int) _/%_ (int x, int y) {
|
||||
return (x / y, x % y);
|
||||
}
|
||||
-}
|
||||
{-
|
||||
< type A, type B, type C >
|
||||
(B, C, A) rot (A x, B y, C z) {
|
||||
return (y, z, x);
|
||||
}
|
||||
-}
|
||||
int ataninv(int base, int q) { ;; computes base*atan(1/q)
|
||||
base /~= q;
|
||||
q *= - q;
|
||||
int sum = 0;
|
||||
int n = 1;
|
||||
do {
|
||||
sum += base /~ n;
|
||||
base /~= q;
|
||||
n += 2;
|
||||
} until base == 0;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int calc_pi() {
|
||||
int base = 64;
|
||||
repeat (70) { base *= 10; }
|
||||
return (ataninv(base << 2, 5) - ataninv(base, 239)) >>~ 4;
|
||||
}
|
75
crypto/func/test/a6.fp
Normal file
75
crypto/func/test/a6.fp
Normal file
|
@ -0,0 +1,75 @@
|
|||
f(int a, int b, int c, int d, int e, int f) : (int, int) {
|
||||
var D = a * d - b * c;
|
||||
var Dx : int = e * d - b * f;
|
||||
var Dy : int = a * f - e * c;
|
||||
return (Dx / D, Dy / D);
|
||||
}
|
||||
|
||||
calc_phi() : int = {
|
||||
var n : int = 1;
|
||||
repeat (10) {
|
||||
n *= 10;
|
||||
}
|
||||
var p = var q = 1;
|
||||
do {
|
||||
(p, q) = (q, p + q);
|
||||
} until q > n;
|
||||
return muldivr(p, n, q);
|
||||
}
|
||||
|
||||
calc_sqrt2() : int = {
|
||||
var n = 1;
|
||||
repeat (70) { n *= 10; }
|
||||
var p = var q = 1;
|
||||
do {
|
||||
var t = p + q;
|
||||
(p, q) = (q, t + q);
|
||||
} until q > n;
|
||||
return muldivr(p, n, q);
|
||||
}
|
||||
|
||||
calc_phi() : int = {
|
||||
var n = 1;
|
||||
repeat (70) { n *= 10; }
|
||||
var p = var q = 1;
|
||||
do {
|
||||
(p, q) = (q, p + q);
|
||||
} until q > n;
|
||||
return muldivr(p, n, q);
|
||||
}
|
||||
|
||||
operator _/%_ infix 20;
|
||||
|
||||
(x : int) /% (y : int) : (int, int) = {
|
||||
return (x / y, x % y);
|
||||
}
|
||||
|
||||
{-
|
||||
_/%_ (int x, int y) : (int, int) = {
|
||||
return (x / y, x % y);
|
||||
}
|
||||
-}
|
||||
|
||||
rot < A : type, B : type, C : type >
|
||||
(x : A, y : B, z : C) : (B, C, A) {
|
||||
return (y, z, x);
|
||||
}
|
||||
|
||||
ataninv(base : int, q : int) : int { ;; computes base*atan(1/q)
|
||||
base /~= q;
|
||||
q *= - q;
|
||||
var sum : int = 0;
|
||||
var n = 1;
|
||||
do {
|
||||
sum += base /~ n;
|
||||
base /~= q;
|
||||
n += 2;
|
||||
} while base;
|
||||
return sum;
|
||||
}
|
||||
|
||||
calc_pi() : int {
|
||||
var base = 64;
|
||||
repeat (70) { base *= 10; }
|
||||
return (ataninv(base << 2, 5) - ataninv(base, 239)) >>~ 4;
|
||||
}
|
6
crypto/func/test/a6_1.fc
Normal file
6
crypto/func/test/a6_1.fc
Normal file
|
@ -0,0 +1,6 @@
|
|||
(int, int) f(int a, int b, int c, int d, int e, int f) {
|
||||
int D = a * d - b * c;
|
||||
int Dx = e * d - b * f;
|
||||
int Dy = a * f - e * c;
|
||||
return (Dx / D, Dy / D);
|
||||
}
|
130
crypto/func/test/a6_2.fc
Normal file
130
crypto/func/test/a6_2.fc
Normal file
|
@ -0,0 +1,130 @@
|
|||
var f(a, b, c, d, e, f) {
|
||||
var D = a * d - b * c;
|
||||
var Dx = e * d - b * f;
|
||||
var Dy = a * f - e * c;
|
||||
return (Dx / D, Dy / D);
|
||||
}
|
||||
|
||||
var test8() {
|
||||
return -4;
|
||||
}
|
||||
|
||||
var test3(a) {
|
||||
int x = a * 10;
|
||||
a += 1;
|
||||
int x = x + 3;
|
||||
{
|
||||
int y = x + 2;
|
||||
x = y + a;
|
||||
}
|
||||
int z = 5;
|
||||
return x * (z + a);
|
||||
}
|
||||
|
||||
var test2(a) {
|
||||
(var x, var y) = a /% 10;
|
||||
return x + y;
|
||||
}
|
||||
|
||||
var test2a(a) {
|
||||
var (x, y) = a /% 10;
|
||||
return x + y;
|
||||
}
|
||||
|
||||
var test2b(a) {
|
||||
var z = a /% 10;
|
||||
return _+_ z;
|
||||
}
|
||||
|
||||
var test2c(a) {
|
||||
return _+_ (a /% 10);
|
||||
}
|
||||
|
||||
var twice(f, x) {
|
||||
return f (f x);
|
||||
}
|
||||
|
||||
var test() {
|
||||
return f(1, 2, 3, 4, 7, 17);
|
||||
}
|
||||
|
||||
var rot(a, b, c) {
|
||||
return (b, c, a);
|
||||
}
|
||||
|
||||
var rot_int(int a, int b, int c) {
|
||||
return (b, c, a);
|
||||
}
|
||||
|
||||
(int, _) dup_int(x) {
|
||||
return (x, x);
|
||||
}
|
||||
|
||||
var calc_phi() {
|
||||
var n = 10;
|
||||
n *= n;
|
||||
n *= n;
|
||||
n *= n;
|
||||
n *= n;
|
||||
n *= n;
|
||||
n *= n;
|
||||
var p = var q = 1;
|
||||
(p, q) = (q, p + q);
|
||||
(p, q) = (q, p + q);
|
||||
(p, q) = (q, p + q);
|
||||
(p, q) = (q, p + q);
|
||||
(p, q) = (q, p + q);
|
||||
(p, q) = (q, p + q);
|
||||
(p, q) = (q, p + q);
|
||||
return muldivr(p, n, q);
|
||||
}
|
||||
|
||||
var t0() {
|
||||
var x = 1;
|
||||
return x;
|
||||
}
|
||||
|
||||
var t1() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
var t2(int x) {
|
||||
return 2;
|
||||
return x += 1;
|
||||
}
|
||||
|
||||
var t3(int x, var y) {
|
||||
int z = (x + y) * (x - y);
|
||||
}
|
||||
|
||||
var t3b(int x, var y) {
|
||||
int z = (x + y) * (x - y);
|
||||
return z;
|
||||
}
|
||||
|
||||
var t4((int, int, int) z) {
|
||||
var (_, u, _) = z;
|
||||
return u;
|
||||
}
|
||||
|
||||
int foo(int t);
|
||||
|
||||
var t5(x) {
|
||||
var f = t2;
|
||||
return twice(f, x) * f(x);
|
||||
}
|
||||
|
||||
var proj1(a, b) { return a; }
|
||||
var proj1a(a, b) { var c = a; return c; }
|
||||
var proj1b(a, b) { int c = a; return c; }
|
||||
var proj1c(a, b) { var c = a + 2; return c; }
|
||||
var proj1d(a, b) { return a + 2; }
|
||||
var proj1e(int a, _) { return a; }
|
||||
int proj1f(_ a, int) { return a; }
|
||||
int proj1g(int, a) { return a; }
|
||||
|
||||
var test1(a) {
|
||||
a = a + 1;
|
||||
return a;
|
||||
}
|
||||
|
12
crypto/func/test/a7.fc
Normal file
12
crypto/func/test/a7.fc
Normal file
|
@ -0,0 +1,12 @@
|
|||
int steps(int x) {
|
||||
var n = 0;
|
||||
while (x > 1) {
|
||||
n += 1;
|
||||
if (x & 1) {
|
||||
x = 3 * x + 1;
|
||||
} else {
|
||||
x >>= 1;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
28
crypto/func/test/a8.fc
Normal file
28
crypto/func/test/a8.fc
Normal file
|
@ -0,0 +1,28 @@
|
|||
int A(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(d, e, f);
|
||||
}
|
||||
|
||||
int B(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(b, d, e) + f;
|
||||
}
|
||||
|
||||
int C(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(b, d, c) + muldiv(d, d, f);
|
||||
}
|
||||
|
||||
int D(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(b, d, c) + muldiv(e, e, f);
|
||||
}
|
||||
|
||||
int E(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(c, d, e) + muldiv(c, c, f);
|
||||
}
|
||||
|
||||
int F(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(a, d, c) + muldiv(f, f, e);
|
||||
}
|
||||
|
||||
int G(int a, int b, int c, int d, int e, int f) {
|
||||
return muldiv(a, b, c) + muldiv(b, c, d) + muldiv(b, c, e) + f;
|
||||
}
|
||||
|
23
crypto/func/test/a9.fc
Normal file
23
crypto/func/test/a9.fc
Normal file
|
@ -0,0 +1,23 @@
|
|||
int f(int x) {
|
||||
if (2 * x + 1 == 7) {
|
||||
return x + 17;
|
||||
} else {
|
||||
return 239;
|
||||
}
|
||||
}
|
||||
|
||||
int f2(int x) {
|
||||
return 2 * x + 1 == 6 ? x + 17 : 239;
|
||||
}
|
||||
|
||||
int g(int x) {
|
||||
return x & 1 ? 3 * x + 1 : x / 2;
|
||||
}
|
||||
|
||||
_ H(int x, int y) {
|
||||
return (x < y, x <= y, x == y, x >= y, x > y, x != y, x <=> y);
|
||||
}
|
||||
|
||||
int q() {
|
||||
return 4;
|
||||
}
|
28
crypto/func/test/a9_1.fc
Normal file
28
crypto/func/test/a9_1.fc
Normal file
|
@ -0,0 +1,28 @@
|
|||
_ F(int x) {
|
||||
x = 2;
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
_ G(x) {
|
||||
var y = x + 1;
|
||||
x = 2;
|
||||
return (x - 1, y);
|
||||
}
|
||||
|
||||
_ H(x) {
|
||||
var y = x + 1;
|
||||
x = 2;
|
||||
return (x * y, y);
|
||||
}
|
||||
|
||||
_ I(x) {
|
||||
int y = 17;
|
||||
int z = x - y;
|
||||
return (z, y);
|
||||
}
|
||||
|
||||
_ J(x) {
|
||||
int y = 239;
|
||||
int z = x - y;
|
||||
return (z, y);
|
||||
}
|
63
crypto/func/test/b1.fc
Normal file
63
crypto/func/test/b1.fc
Normal file
|
@ -0,0 +1,63 @@
|
|||
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";
|
||||
(cell, slice) load_ref(slice s) asm "LDREF";
|
||||
(int, slice) zload_int(slice s, int len) asm "LDIX";
|
||||
(int, slice) zload_uint(slice s, int len) asm "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 "LDSLICEX";
|
||||
slice preload_bits(slice s, int len) asm "PLDSLICEX";
|
||||
cell set_idict_ref(cell value, int index, cell dict, int key_len) asm "DICTISETREF";
|
||||
builder begin_cell() asm "NEWC";
|
||||
builder store_ref(cell c, builder b) asm "STREF";
|
||||
builder zstore_uint(int x, builder b, int len) asm "STUX";
|
||||
builder zstore_int(int x, builder b, int len) asm "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 (signature, cs0) = load_bits(begin_parse(in_msg), 512);
|
||||
var (msg_seqno, cs) = zload_uint(cs0, 32);
|
||||
(var valid_until, cs) = zload_uint(cs, 32);
|
||||
throw_if(35, valid_until < now());
|
||||
var (cfg_dict, cs2) = load_ref(begin_parse(get_data()));
|
||||
(var stored_seqno, cs2) = zload_uint(cs2, 32);
|
||||
(var public_key, cs2) = 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();
|
||||
(var param_index, cs) = zload_uint(cs, 32);
|
||||
(var param_value, cs) = load_ref(cs);
|
||||
end_parse(cs);
|
||||
;; cfg_dict = set_idict_ref(param_value, param_index, cfg_dict, 32);
|
||||
;; var cb = begin_cell();
|
||||
;; cb = store_ref(cfg_dict, cb);
|
||||
var cb = store_ref(set_idict_ref(param_value, param_index, cfg_dict, 32), begin_cell());
|
||||
cb = zstore_uint(stored_seqno + 1, cb, 32);
|
||||
cb = zstore_uint(public_key, cb, 256);
|
||||
set_data(end_cell(cb));
|
||||
}
|
60
crypto/func/test/b2.fc
Normal file
60
crypto/func/test/b2.fc
Normal file
|
@ -0,0 +1,60 @@
|
|||
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));
|
||||
}
|
63
crypto/func/test/b2_0.fc
Normal file
63
crypto/func/test/b2_0.fc
Normal file
|
@ -0,0 +1,63 @@
|
|||
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));
|
||||
}
|
62
crypto/func/test/b2_1.fc
Normal file
62
crypto/func/test/b2_1.fc
Normal file
|
@ -0,0 +1,62 @@
|
|||
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";
|
||||
(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 cs = begin_parse(in_msg);
|
||||
var signature = cs~load_bits(512);
|
||||
var cs0 = cs;
|
||||
int msg_seqno = cs~load_uint(32);
|
||||
var valid_until = cs~load_uint(32);
|
||||
throw_if(35, valid_until < now());
|
||||
var cs2 = begin_parse(get_data());
|
||||
var cfg_dict = cs2~load_ref();
|
||||
var stored_seqno = cs2~load_uint(32);
|
||||
var public_key = cs2~load_uint(256);
|
||||
cs2.end_parse();
|
||||
throw_unless(33, msg_seqno == stored_seqno);
|
||||
throw_unless(34, check_signature(slice_hash(cs0), signature, public_key));
|
||||
accept_message();
|
||||
var param_index = cs~load_uint(32);
|
||||
var param_value = cs~load_ref();
|
||||
cs.end_parse();
|
||||
cfg_dict~set_idict_ref(32, param_index, param_value);
|
||||
set_data(begin_cell().store_ref(cfg_dict).store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell());
|
||||
}
|
58
crypto/func/test/b2_2.fc
Normal file
58
crypto/func/test/b2_2.fc
Normal file
|
@ -0,0 +1,58 @@
|
|||
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);
|
||||
set_data(begin_cell().store_ref(cfg_dict.set_idict_ref(32, param_index, param_value))
|
||||
.store_uint(stored_seqno + 1, 32).store_uint(public_key, 256).end_cell());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue