mirror of
https://github.com/danog/toncontest.git
synced 2024-11-29 20:19:11 +01:00
Update
This commit is contained in:
parent
46d3d2e053
commit
e0dcaa0551
@ -17,16 +17,8 @@ wrappedMessage$_ expires_at:uint32 seqno:uint32 body:(ModeMessage X) = WrappedMe
|
||||
multiSigWrapper$0 signatures:(HashmapE 4 ^Signature) message:(WrappedMessage X) = MultiSigWrapper X;
|
||||
//multiSigFuture$1 = MultiSigWrapper X;
|
||||
|
||||
// Message constructor for wallet storage
|
||||
// No seqno: we can't regenerate the hash of a stored message.
|
||||
// That's a tradeoff to save grams on storage (and storing the seqno would be pointless anyway,
|
||||
// since all integrity checks were already made when the message was first stored).
|
||||
//
|
||||
// But do we __have to__ store the body?
|
||||
// I mean, each incoming order already has the full message body, why store it if you can reuse it?
|
||||
// Anyway, for now I'm storing the body. (Scratch that, it's a waste of storage, just store the hash)
|
||||
//
|
||||
storedMessage$_ expires_at:uint32 signatures:(HashmapE 4 ^Signature) = StoredMessage X;
|
||||
// For internal storage
|
||||
multiSigWrapperStorage$_ signatures:(HashmapE 4 ^Signature) message:(WrappedMessage X) = MultiSigWrapperStorage X;
|
||||
|
||||
|
||||
// Not doing explicit versioning here, since the structure of the storage can only change after an update of the onchain wallet code
|
||||
@ -34,7 +26,7 @@ storedMessage$_ expires_at:uint32 signatures:(HashmapE 4 ^Signature) = StoredMes
|
||||
// Min 3 signatures per message
|
||||
// ^StoredMessage because 256*(40+) > 1023
|
||||
//
|
||||
storage$_ seqno:uint32 minSigs:(## 4) keys:(HashmapE 4 ^PubKey) messages:(HashmapE 256 ^(StoredMessage X))
|
||||
storage$_ seqno:uint32 minSigs:(## 4) keys:(HashmapE 4 ^PubKey) messages:(HashmapE 256 ^(MultiSigWrapperStorage X))
|
||||
{k:(## 4)} { k > 0 } { k >= 3 } { n >= k } { n <= 10 } = Storage X;
|
||||
|
||||
// TON stuff
|
||||
|
@ -2,19 +2,26 @@
|
||||
|
||||
;; Cleanup expired partial orders
|
||||
;; messages
|
||||
(cell) collect_garbage(cell messages) {
|
||||
(cell, ()) ~collect_garbage(cell messages) {
|
||||
var hash = -1;
|
||||
do {
|
||||
(hash, var cs, var ok) = messages.udict_get_next?(256, hash);
|
||||
if (ok) {
|
||||
|
||||
;; modeMessage$_ mode:uint8 body:^(Message X) = ModeMessage X;
|
||||
;; wrappedMessage$_ expires_at:uint32 seqno:uint32 body:(ModeMessage X) = WrappedMessage X;
|
||||
;; multiSigWrapperStorage$_ signatures:(HashmapE 4 ^Signature) message:(WrappedMessage X) = MultiSigWrapperStorage X;
|
||||
;;
|
||||
;; Skip signatures, check expiry
|
||||
;;
|
||||
;; expiry <= now
|
||||
if (cs~load_uint(32) <= now()) {
|
||||
if (cs.skip_dict().preload_uint(32) <= now()) {
|
||||
messages~udict_delete?(256, hash);
|
||||
}
|
||||
}
|
||||
} until (~ ok);
|
||||
|
||||
return messages;
|
||||
return (messages, ());
|
||||
}
|
||||
|
||||
() store_db(int seqno, cell keys, cell messages) {
|
||||
@ -62,16 +69,10 @@
|
||||
;; Throw if old message and doesn't exist in db
|
||||
throw_unless(35, ok);
|
||||
|
||||
;; storedMessage$_ expires_at:uint32 signatures:(HashmapE 4 ^Signature) = StoredMessage X;
|
||||
;;
|
||||
;; Skip expiry
|
||||
;;
|
||||
;; No seqno: we can't regenerate the hash of a stored message.
|
||||
;; That's a tradeoff to save grams on storage (and storing the seqno would be pointless anyway,
|
||||
;; since all integrity checks were already made when the message was first stored).
|
||||
;; multiSigWrapperStorage$_ signatures:(HashmapE 4 ^Signature) message:(WrappedMessage X) = MultiSigWrapperStorage X;
|
||||
;;
|
||||
;; Load signatures
|
||||
var storedMessageSignatures = storedMessage~load_ref().begin_parse().skip_bits(32).preload_dict();
|
||||
var storedMessageSignatures = storedMessage~load_ref().begin_parse().preload_dict();
|
||||
storedMessage.end_parse();
|
||||
}
|
||||
|
||||
@ -117,16 +118,14 @@
|
||||
}
|
||||
} until (~ ok);
|
||||
|
||||
;; storedMessage$_ expires_at:uint32 signatures:(HashmapE 4 ^Signature) = StoredMessage X;
|
||||
;;
|
||||
;; But do we __have to__ store the body?
|
||||
;; I mean, each incoming order already has the full message body, why store it if you can reuse it?
|
||||
;; Anyway, for now I'm storing the body. (Scratch that, it's a waste of storage, just store the hash)
|
||||
;; modeMessage$_ mode:uint8 body:^(Message X) = ModeMessage X;
|
||||
;; wrappedMessage$_ expires_at:uint32 seqno:uint32 body:(ModeMessage X) = WrappedMessage X;
|
||||
;; multiSigWrapperStorage$_ signatures:(HashmapE 4 ^Signature) message:(WrappedMessage X) = MultiSigWrapperStorage X;
|
||||
;;
|
||||
if (count < min_sigs) {
|
||||
messages~udict_set_ref(256, hash, begin_cell().store_uint(expires_at, 32).store_dict(storedMessageSignatures).end_cell());
|
||||
messages~udict_set_ref(256, hash, begin_cell().store_dict(storedMessageSignatures).store_uint(expires_at, 32).store_uint(msg_seqno, 32).store_uint(mode, 8).store_ref(message).end_cell());
|
||||
}
|
||||
messages = collect_garbage(messages);
|
||||
messages~collect_garbage();
|
||||
|
||||
;; storage$_ seqno:uint32 minSigs:(## 4) keys:(HashmapE 4 ^PubKey) messages:(HashmapE 256 ^(Message X)) = Storage X;
|
||||
set_data(begin_cell().store_uint(stored_seqno + 1, 32).store_uint(min_sigs, 4).store_dict(keys).store_dict(messages).end_cell());
|
||||
|
@ -1,12 +1,12 @@
|
||||
"Asm.fif" include
|
||||
// automatically generated from `/home/daniil/repos/contest/lib/crypto/smartcont/stdlib.fc` `wallet-code.fc`
|
||||
PROGRAM{
|
||||
DECLPROC collect_garbage
|
||||
DECLPROC ~collect_garbage
|
||||
DECLPROC store_db
|
||||
DECLPROC recv_internal
|
||||
DECLPROC recv_external
|
||||
85143 DECLMETHOD seqno
|
||||
collect_garbage PROC:<{
|
||||
~collect_garbage PROC:<{
|
||||
-1 PUSHINT
|
||||
UNTIL:<{
|
||||
OVER
|
||||
@ -17,8 +17,8 @@ PROGRAM{
|
||||
DUP
|
||||
IF:<{
|
||||
s0 s2 XCHG
|
||||
32 LDU
|
||||
DROP
|
||||
SKIPDICT
|
||||
32 PLDU
|
||||
NOW
|
||||
LEQ
|
||||
IF:<{
|
||||
@ -75,15 +75,14 @@ PROGRAM{
|
||||
LDDICT
|
||||
LDDICT
|
||||
ENDS
|
||||
s3 PUSH
|
||||
NEWDICT
|
||||
s0 s7 XCHG
|
||||
s4 s6 PUSH2
|
||||
EQUAL
|
||||
IF:<{
|
||||
s0 s3 XCHG
|
||||
s0 s4 XCHG
|
||||
INC
|
||||
}>ELSE<{
|
||||
s4 s0 PUSH2
|
||||
s5 s1 PUSH2
|
||||
8 PUSHPOW2
|
||||
DICTUGET
|
||||
NULLSWAPIFNOT
|
||||
@ -91,20 +90,20 @@ PROGRAM{
|
||||
LDREF
|
||||
NIP
|
||||
ENDS
|
||||
s0 s3 XCHG
|
||||
s0 s4 XCHG
|
||||
}>
|
||||
ACCEPT
|
||||
s0 s7 XCHG
|
||||
s0 s8 XCHG
|
||||
-1 PUSHINT
|
||||
UNTIL:<{
|
||||
s9 PUSH
|
||||
s10 PUSH
|
||||
4 PUSHINT
|
||||
DICTUGETNEXT
|
||||
NULLSWAPIFNOT
|
||||
NULLSWAPIFNOT
|
||||
DUP
|
||||
IF:<{
|
||||
s1 s4 PUSH2
|
||||
s1 s5 PUSH2
|
||||
4 PUSHINT
|
||||
DICTUGET
|
||||
NULLSWAPIFNOT
|
||||
@ -122,30 +121,30 @@ PROGRAM{
|
||||
ENDS
|
||||
s0 s2 XCHG
|
||||
ENDS
|
||||
s9 s(-1) s4 PUXC2
|
||||
s10 s(-1) s4 PUXC2
|
||||
CHKSIGNU
|
||||
37 THROWIFNOT
|
||||
s1 s2 XCHG
|
||||
4 PUSHINT
|
||||
s3 s9 s9 PUXC2
|
||||
s3 s8 s8 PUXC2
|
||||
DICTUSETREF
|
||||
}>ELSE<{
|
||||
s1 s8 s8 XCHG3
|
||||
s1 s7 s7 XCHG3
|
||||
DROP
|
||||
}>
|
||||
s0 s7 XCHG
|
||||
s0 s6 XCHG
|
||||
NOT
|
||||
}>
|
||||
DROP
|
||||
s8 POP
|
||||
s0 s7 XCHG
|
||||
s9 POP
|
||||
s0 s8 XCHG
|
||||
8 LDU
|
||||
LDREF
|
||||
ENDS
|
||||
0 PUSHINT
|
||||
-1 PUSHINT
|
||||
UNTIL:<{
|
||||
s7 PUSH
|
||||
s6 PUSH
|
||||
4 PUSHINT
|
||||
DICTUGETNEXT
|
||||
NULLSWAPIFNOT
|
||||
@ -155,45 +154,51 @@ PROGRAM{
|
||||
IF:<{
|
||||
s0 s2 XCHG
|
||||
INC
|
||||
s0 s5 PUSH2
|
||||
s0 s6 PUSH2
|
||||
GEQ
|
||||
IF:<{
|
||||
NIP
|
||||
s2 s3 PUSH2
|
||||
SENDRAWMSG
|
||||
8 PUSHPOW2
|
||||
s7 s6 s6 PUXC2
|
||||
s8 s12 s12 PUXC2
|
||||
DICTUDEL
|
||||
DROP
|
||||
0 PUSHINT
|
||||
}>ELSE<{
|
||||
s6 s6 XCHG2
|
||||
s12 s12 XCHG2
|
||||
}>
|
||||
}>ELSE<{
|
||||
s0 s6 s6 XCHG3
|
||||
s0 s12 s12 XCHG3
|
||||
}>
|
||||
NOT
|
||||
s6 s6 s0 XCHG3
|
||||
s12 s12 s0 XCHG3
|
||||
}>
|
||||
s1 s3 XCHG
|
||||
3 BLKDROP
|
||||
OVER
|
||||
DROP
|
||||
s4 PUSH
|
||||
LESS
|
||||
IF:<{
|
||||
NEWC
|
||||
s1 s5 XCHG
|
||||
32 STU
|
||||
s1 s3 XCHG
|
||||
STDICT
|
||||
s1 s7 XCHG
|
||||
32 STU
|
||||
s1 s5 XCHG
|
||||
32 STU
|
||||
s1 s5 XCHG
|
||||
8 STU
|
||||
STREF
|
||||
ENDC
|
||||
s0 s2 XCHG
|
||||
s0 s1 s5 XCHG3
|
||||
8 PUSHPOW2
|
||||
DICTUSETREF
|
||||
}>ELSE<{
|
||||
s3 s4 XCHG2
|
||||
3 BLKDROP
|
||||
s2 s9 XCHG
|
||||
s3 s7 XCHG
|
||||
s2 s6 XCHG
|
||||
6 BLKDROP
|
||||
}>
|
||||
collect_garbage CALLDICT
|
||||
~collect_garbage CALLDICT
|
||||
s0 s2 XCHG
|
||||
INC
|
||||
NEWC
|
||||
|
Loading…
Reference in New Issue
Block a user