wormhole/algorand/globals.py

61 lines
1.4 KiB
Python
Raw Normal View History

#!/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 *
Pricecaster V2-alpha (#716) * Removed unnecessary file. Change-Id: Ic85cb42fef37028bc99d266148fae35107d2cf5f * Update sample pyth VAA information on README Change-Id: I2a4d3b23bfbc525d25f3f0360605aece0c104f4b * Test and lib fixes. Change-Id: I4af5e0313ba04b322f428a15a19bc7b30c6ae027 * Check owner balance + Feed ALGOs to stateless account address. Change-Id: Ibf57c66b24153b917f5d33febff97a002c163b59 * Working VAA verification test. Change-Id: Ib44e96ce8979161cdf703b1c4c92742cdc3e9cae * Lot of new tests and a little refactoring. Change-Id: Ic1da9be0a91fc3ace136c80cc5b2329cb3bf2e77 * Removed parts of old Pricekeeper logic Change-Id: Id77f4366d30dac2b89d039cea9b115a46a189e2d * Proper fetching, parsing and unpacking of Pyth-Wormhole data Change-Id: Id3b5002f072873d8161fa619f387171483a3e66c * Pricekeeper V2 PyTEAL contract. Change-Id: Idc1771e1ade371f51befdfd36ab6add55b3081fc * Streamlined and refac support library. Removed old code. Change-Id: I1f9633700527b1e0ca5ea9a38d24d3960e3e2341 * Changes to successfully publish price in target contract. Change-Id: Ie346648cec5b7b0b70786c2a99373df9bf71633d * pclib: Concurrent internal group TXs supported. Change-Id: I78e16d0dbf71c86fbb6be61e956aa370a4c48130 * Fetching and publishing from Wormhole/Spy. Removed most of old Pricekeeper V1 functionality. Simplified code. Change-Id: I197436c52460c04143501a60e3db9609159e9f25 * README + Deployment tool updated Change-Id: Iaf1f76ce69ea303f734c2a79f529f60ebf55a4ca * Modifications to use compiled stateless program. Change-Id: Ibc294412728052c1e29c7df929b3d9e481d714be * Removed old settings file. Change-Id: I1b8ca64426983b0a56f55f99a69304aaca702fee * Implements Randlabs Logger (C3PROT-92) Change-Id: Ia527169dc56bb2622fcde2fcfad53ed2efb5f399 * STEPS updated to 8. Change-Id: I9b092bb321231cde003e12b5a68cf90404f670f8 * Fixed handling double-hashing Change-Id: I5695e2783d439a85a61af44cab03ba99898cb16b * Added option to dump failed TX and diagnostic information in README Change-Id: If3d7b068d8d408851bcaae443ff412dc9cc30c69 * Fixed chainId handling. Change-Id: Id798a2e7afc0d646a179e3bd682204ba738fa53a * Successfully push prices to priceKeeper V2. Change-Id: Ib04da78b819e17579677e0187c9f5bd6bb1e2feb * Fixed price output log Change-Id: I99df39a05c667b5eb1af6cda988326cd768f89ee * Update WIP Tests. Change-Id: I4c2f94306dcaab578c30e487ceb6c140ea902ac3 * Support for VAAs with minimal quorum (> 2/3+1 signers ) Change-Id: I65dc52f6ef531cd24f7d080108451c5302e08524 * Remove old files. Change-Id: I9fd2127d9374617f53cb1cc6f721a2a655b79385 * Removed unnecessary entries in gitignore file Change-Id: I498ee2e192eb87d090767d8a12fd59ac679c8579 Co-authored-by: Josh Siegel <jsiegel@jumptrading.com> Co-authored-by: jumpsiegel <83408952+jumpsiegel@users.noreply.github.com>
2022-01-21 06:37:49 -08:00
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))))