ADD: PK Recover using Inline assembly
This commit is contained in:
parent
2db37c7eca
commit
d9cfcfa5a0
|
@ -18,17 +18,26 @@ from pyteal.ast import *
|
||||||
from pyteal.types import *
|
from pyteal.types import *
|
||||||
from pyteal.compiler import *
|
from pyteal.compiler import *
|
||||||
from pyteal.ir import *
|
from pyteal.ir import *
|
||||||
from globals import get_sig_count_in_step, get_group_size
|
from globals import *
|
||||||
|
from inlineasm import *
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
SLOTID_RECOVERED_PK_X = 240
|
||||||
|
SLOTID_RECOVERED_PK_Y = 241
|
||||||
|
|
||||||
|
|
||||||
@Subroutine(TealType.uint64)
|
@Subroutine(TealType.uint64)
|
||||||
def sig_check(signatures, digest, keys):
|
def sig_check(signatures, digest, keys):
|
||||||
si = ScratchVar(TealType.uint64)
|
si = ScratchVar(TealType.uint64)
|
||||||
ki = ScratchVar(TealType.uint64)
|
ki = ScratchVar(TealType.uint64)
|
||||||
|
rec_pk_x = ScratchVar(TealType.bytes, SLOTID_RECOVERED_PK_X)
|
||||||
|
rec_pk_y = ScratchVar(TealType.bytes, SLOTID_RECOVERED_PK_Y)
|
||||||
|
|
||||||
return Seq(
|
return Seq(
|
||||||
[
|
[
|
||||||
|
rec_pk_x.store(Bytes("")),
|
||||||
|
rec_pk_y.store(Bytes("")),
|
||||||
For(Seq([
|
For(Seq([
|
||||||
si.store(Int(0)),
|
si.store(Int(0)),
|
||||||
ki.store(Int(0))
|
ki.store(Int(0))
|
||||||
|
@ -38,12 +47,30 @@ def sig_check(signatures, digest, keys):
|
||||||
si.store(si.load() + Int(66)),
|
si.store(si.load() + Int(66)),
|
||||||
ki.store(ki.load() + Int(32)),
|
ki.store(ki.load() + Int(32)),
|
||||||
])).Do(
|
])).Do(
|
||||||
Seq(
|
Seq([
|
||||||
Assert(Ed25519Verify(
|
InlineAssembly(
|
||||||
|
"ecdsa_pk_recover 0",
|
||||||
digest,
|
digest,
|
||||||
Extract(signatures, si.load(), Int(66)),
|
Extract(signatures, si.load() + Int(64), Int(1)),
|
||||||
Extract(keys, ki.load(), Int(32)),))
|
Extract(signatures, si.load() + Int(32), Int(32)),
|
||||||
|
Extract(signatures, si.load(), Int(32)),
|
||||||
|
type=TealType.none),
|
||||||
|
|
||||||
|
# returned values in stack, pass to scratch-vars
|
||||||
|
|
||||||
|
InlineAssembly("store " + str(SLOTID_RECOVERED_PK_X)),
|
||||||
|
InlineAssembly("store " + str(SLOTID_RECOVERED_PK_Y)),
|
||||||
|
|
||||||
|
# Generate Ethereum-type public key, compare with guardian key.
|
||||||
|
|
||||||
|
Assert(
|
||||||
|
Extract(keys, ki.load(), Int(32)) ==
|
||||||
|
Extract(Keccak256(Concat(rec_pk_x.load(),
|
||||||
|
rec_pk_y.load())), Int(0), Int(20))
|
||||||
)
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
),
|
),
|
||||||
Return(Int(1))
|
Return(Int(1))
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue