-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.py
More file actions
60 lines (44 loc) · 1.43 KB
/
Copy pathglobals.py
File metadata and controls
60 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
# The maximum number of signatures verified by each transaction in the group.
# the total count of required transactions to verify all guardian signatures is
#
# floor(guardian_count / SIGNATURES_PER_TRANSACTION)
#
from pyteal.types import *
from pyteal.ast import *
MAX_SIGNATURES_PER_VERIFICATION_STEP = 8
"""
Math ceil function.
"""
@Subroutine(TealType.uint64)
def ceil(n, d):
q = n / d
r = n % d
return Seq([
If(r != Int(0)).Then(Return(q + Int(1))).Else(Return(q))
])
"""
Return the minimum Uint64 of A,B
"""
@Subroutine(TealType.uint64)
def min(a, b):
If(Int(a) < Int(b), Return(a), Return(b))
"""
Let G be the guardian count, N number of signatures per verification step, group must have CEIL(G/N) transactions.
"""
@Subroutine(TealType.uint64)
def get_group_size(num_guardians):
return ceil(num_guardians, Int(MAX_SIGNATURES_PER_VERIFICATION_STEP))
"""
Get the number of signatures to verify in current step
"""
@Subroutine(TealType.uint64)
def get_sig_count_in_step(step, num_guardians):
r = num_guardians % Int(MAX_SIGNATURES_PER_VERIFICATION_STEP)
return Seq(
If(r == Int(0)).Then(Return(Int(MAX_SIGNATURES_PER_VERIFICATION_STEP)))
.ElseIf(step < get_group_size(num_guardians) - Int(1))
.Then(
Return(Int(MAX_SIGNATURES_PER_VERIFICATION_STEP)))
.Else(
Return(num_guardians % Int(MAX_SIGNATURES_PER_VERIFICATION_STEP))))