Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ed25519Verify_Bare #426

Merged
merged 4 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyteal/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ __all__ = [
"EcdsaRecover",
"EcdsaVerify",
"Ed25519Verify",
"Ed25519Verify_Bare",
michaeldiamant marked this conversation as resolved.
Show resolved Hide resolved
"EnumInt",
"Eq",
"Err",
Expand Down
9 changes: 8 additions & 1 deletion pyteal/ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@
)

# ternary ops
from pyteal.ast.ternaryexpr import Divw, Ed25519Verify, SetBit, SetByte
from pyteal.ast.ternaryexpr import (
Divw,
Ed25519Verify,
Ed25519Verify_Bare,
SetBit,
SetByte,
)
from pyteal.ast.substring import Substring, Extract, Suffix

# more ops
Expand Down Expand Up @@ -218,6 +224,7 @@
"GetBit",
"GetByte",
"Ed25519Verify",
"Ed25519Verify_Bare",
"Substring",
"Extract",
"Suffix",
Expand Down
18 changes: 18 additions & 0 deletions pyteal/ast/ternaryexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ def Ed25519Verify(data: Expr, sig: Expr, key: Expr) -> TernaryExpr:
)


def Ed25519Verify_Bare(data: Expr, sig: Expr, key: Expr) -> TernaryExpr:
"""Verify the ed25519 signature of the data against the public key.

Args:
data: The data signed by the public key. Must evalutes to bytes.
jdtzmn marked this conversation as resolved.
Show resolved Hide resolved
sig: The proposed 64-byte signature of the data. Must evalute to bytes.
key: The 32 byte public key that produced the signature. Must evaluate to bytes.
"""
return TernaryExpr(
Op.ed25519verify_bare,
(TealType.bytes, TealType.bytes, TealType.bytes),
TealType.uint64,
data,
sig,
key,
)


def SetBit(value: Expr, index: Expr, newBitValue: Expr) -> TernaryExpr:
"""Set the bit value of an expression at a specific index.

Expand Down
36 changes: 36 additions & 0 deletions pyteal/ast/ternaryexpr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
teal4Options = pt.CompileOptions(version=4)
teal5Options = pt.CompileOptions(version=5)
teal6Options = pt.CompileOptions(version=6)
teal7Options = pt.CompileOptions(version=7)


def test_ed25519verify():
Expand Down Expand Up @@ -41,6 +42,41 @@ def test_ed25519verify_invalid():
pt.Ed25519Verify(pt.Bytes("data"), pt.Bytes("sig"), pt.Int(0))


def test_ed25519verify_bare():
args = [pt.Bytes("data"), pt.Bytes("sig"), pt.Bytes("key")]
expr = pt.Ed25519Verify_Bare(args[0], args[1], args[2])
assert expr.type_of() == pt.TealType.uint64

expected = pt.TealSimpleBlock(
[
pt.TealOp(args[0], pt.Op.byte, '"data"'),
pt.TealOp(args[1], pt.Op.byte, '"sig"'),
pt.TealOp(args[2], pt.Op.byte, '"key"'),
pt.TealOp(expr, pt.Op.ed25519verify_bare),
]
)

actual, _ = expr.__teal__(teal7Options)
actual.addIncoming()
actual = pt.TealBlock.NormalizeBlocks(actual)

assert actual == expected

with pytest.raises(pt.TealInputError):
expr.__teal__(teal6Options)


def test_ed25519verify_bare_invalid():
with pytest.raises(pt.TealTypeError):
pt.Ed25519Verify_Bare(pt.Int(0), pt.Bytes("sig"), pt.Bytes("key"))

with pytest.raises(pt.TealTypeError):
pt.Ed25519Verify_Bare(pt.Bytes("data"), pt.Int(0), pt.Bytes("key"))

with pytest.raises(pt.TealTypeError):
pt.Ed25519Verify_Bare(pt.Bytes("data"), pt.Bytes("sig"), pt.Int(0))


def test_set_bit_int():
args = [pt.Int(0), pt.Int(2), pt.Int(1)]
expr = pt.SetBit(args[0], args[1], args[2])
Expand Down
1 change: 1 addition & 0 deletions pyteal/ir/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def min_version(self) -> int:
gitxnas = OpType("gitxnas", Mode.Application, 6)
gloadss = OpType("gloadss", Mode.Application, 6)
acct_params_get = OpType("acct_params_get", Mode.Application, 6)
ed25519verify_bare = OpType("ed25519verify_bare", Mode.Signature | Mode.Application, 7)
# fmt: on


Expand Down