Skip to content

Commit b1463c6

Browse files
authored
fix: Added RUNVM return stack length restriction (#101)
1 parent d3e6899 commit b1463c6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

sources/contracts/utils/utils.tact

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,20 @@ asm fun calculateJettonWallet(owner: Address, jettonData: Cell, jettonCode: Cell
7171
2 PUSHINT // owner_addr c7 md mc args"
7272
103289 PUSHINT // owner_addr c7 md mc args get_jwa_method_id"
7373
5 0 REVERSE // owner_addr get_jwa_method_id args mc md c7"
74-
53 RUNVM // address exit_code c4' c5'"
75-
// TODO check RUNVM exit code
76-
3 BLKDROP // address";
74+
ONE 2 -ROLL // Moves the top stack value (ONE) to the third position: [A, B, C] -> [B, C, A]. We expect only 1 return value. Flag +256 for runvm enables this argument
75+
// Here is the full list of modes of RUNVM
76+
// +1 = same_c3 (set c3 to code)
77+
// +2 = push_0 (push an implicit 0 before running the code); only works with +1 enabled
78+
// +4 = load c4 (persistent data) from stack and return its final value
79+
// +8 = load gas limit from stack and return consumed gas
80+
// +16 = load c7 (smart-contract context)
81+
// +32 = return c5 (actions)
82+
// +64 = pop hard gas limit (enabled by ACCEPT) from stack as well
83+
// +128 = isolated gas consumption (separate set of visited cells, reset CHKSIGNU counter)
84+
// +256 = pop number N, return exactly N values from stack (only if res=0 or 1; if not enough then res=stk_und)
85+
//
86+
// We use only +1 +4 +16 +256 = 277
87+
// Mode 256 is crucial, because it ignores all stack values except the first one, and protects us from stack poisoning
88+
277 RUNVM // address exit_code c4'"
89+
2 BLKDROP // address";
7790
}

0 commit comments

Comments
 (0)