Skip to content

Commit

Permalink
feat: update ops with AVM 11 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx committed Jan 16, 2025
1 parent 5150bfe commit 62da1ab
Show file tree
Hide file tree
Showing 102 changed files with 6,644 additions and 1,815 deletions.
7 changes: 4 additions & 3 deletions examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
asset/Reference 272 225 - | 146 131 -
auction/Auction 593 506 467 | 323 273 259
augmented_assignment/Augmented 241 228 - | 143 135 -
avm_11 181 140 133 | 121 87 84
avm_11/avm_11_sig 6 - - | 4 - -
avm_11 171 130 123 | 114 80 77
avm_12 92 72 65 | 51 38 35
avm_12/avm_12_sig 6 - - | 4 - -
avm_types_in_abi/Test 380 308 279 | 233 173 160
biguint_binary_ops/BiguintBinaryOps 186 8 - | 100 4 -
boolean_binary_ops/BooleanBinaryOps 1098 261 - | 666 136 -
Expand Down Expand Up @@ -136,4 +137,4 @@
unssa/UnSSA 420 266 - | 237 153 -
voting/VotingRoundApp 1584 1426 1415 | 725 624 625
with_reentrancy/WithReentrancy 245 214 - | 126 108 -
Total 70327 39009 36124 | 33189 18196 16926
Total 70409 39071 36179 | 33233 18227 16954
62 changes: 55 additions & 7 deletions langspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": 11,
"LogicSigVersion": 10,
"Version": 12,
"LogicSigVersion": 11,
"NamedTypes": [
{
"Name": "[]byte",
Expand Down Expand Up @@ -1628,8 +1628,8 @@
"Whether block proposal payouts are enabled.",
"The fee required in a keyreg transaction to make an account incentive eligible.",
"The percentage of transaction fees in a block that can be paid to the block proposer.",
"The minimum algo balance an account must have in the agreement round to receive block payouts in the proposal round.",
"The maximum algo balance an account can have in the agreement round to receive block payouts in the proposal round."
"The minimum balance an account must have in the agreement round to receive block payouts in the proposal round.",
"The maximum balance an account can have in the agreement round to receive block payouts in the proposal round."
],
"ArgEnumTypes": [
"uint64",
Expand Down Expand Up @@ -4482,7 +4482,7 @@
2
],
"ArgEnumVersion": [
6,
11,
11
],
"DocCost": "1",
Expand Down Expand Up @@ -4663,7 +4663,7 @@
"Size": 1,
"DocCost": "1700",
"Doc": "for (data A, compressed-format signature B, pubkey C) verify the signature of data against the pubkey",
"IntroducedVersion": 11,
"IntroducedVersion": 12,
"Groups": [
"Cryptography"
],
Expand All @@ -4682,7 +4682,7 @@
"Size": 1,
"DocCost": "150 + 7 per 4 bytes of A",
"Doc": "sumhash512 of value A, yields [64]byte",
"IntroducedVersion": 11,
"IntroducedVersion": 12,
"Groups": [
"Cryptography"
],
Expand Down Expand Up @@ -7820,6 +7820,54 @@
"Cryptography"
],
"Modes": 3
},
{
"Opcode": 230,
"Name": "mimc",
"Cost": "BN254Mp110=10 + 550 per 32 bytes of A; BLS12_381Mp111=10 + 550 per 32 bytes of A",
"Args": [
"[]byte"
],
"Returns": [
"[32]byte"
],
"Size": 2,
"ArgEnum": [
"BN254Mp110",
"BLS12_381Mp111"
],
"ArgEnumDoc": [
"MiMC configuration for the BN254 curve with Miyaguchi-Preneel mode, 110 rounds, exponent 5, seed \"seed\"",
"MiMC configuration for the BLS12-381 curve with Miyaguchi-Preneel mode, 111 rounds, exponent 5, seed \"seed\""
],
"ArgEnumBytes": [
0,
1
],
"ArgModes": [
0,
0
],
"ArgEnumVersion": [
11,
11
],
"DocCost": "BN254Mp110=10 + 550 per 32 bytes of A; BLS12_381Mp111=10 + 550 per 32 bytes of A",
"Doc": "MiMC hash of scalars A, using curve and parameters specified by configuration C",
"DocExtra": "A is a list of concatenated 32 byte big-endian unsigned integer scalars. Fail if A's length is not a multiple of 32 or any element exceeds the curve modulus.\n\nThe MiMC hash function has known collisions since any input which is a multiple of the elliptic curve modulus will hash to the same value. MiMC is thus not a general purpose hash function, but meant to be used in zero knowledge applications to match a zk-circuit implementation.",
"ImmediateNote": [
{
"Comment": "configuration index",
"Encoding": "uint8",
"Name": "C",
"Reference": "Mimc Configurations"
}
],
"IntroducedVersion": 11,
"Groups": [
"Cryptography"
],
"Modes": 3
}
]
}
73 changes: 68 additions & 5 deletions langspec.puya.json
Original file line number Diff line number Diff line change
Expand Up @@ -4090,7 +4090,7 @@
"value": 1700,
"doc": "1700"
},
"min_avm_version": 11,
"min_avm_version": 12,
"halts": false,
"mode": "any",
"groups": [
Expand Down Expand Up @@ -5616,6 +5616,51 @@
],
"stack_outputs": []
},
"mimc": {
"name": "mimc",
"code": 230,
"size": 2,
"doc": [
"MiMC hash of scalars A, using curve and parameters specified by configuration C",
"A is a list of concatenated 32 byte big-endian unsigned integer scalars. Fail if A's length is not a multiple of 32 or any element exceeds the curve modulus.",
"",
"The MiMC hash function has known collisions since any input which is a multiple of the elliptic curve modulus will hash to the same value. MiMC is thus not a general purpose hash function, but meant to be used in zero knowledge applications to match a zk-circuit implementation."
],
"cost": {
"value": null,
"doc": "BN254Mp110=10 + 550 per 32 bytes of A; BLS12_381Mp111=10 + 550 per 32 bytes of A"
},
"min_avm_version": 11,
"halts": false,
"mode": "any",
"groups": [
"Cryptography"
],
"stack_inputs": [
{
"name": "A",
"stack_type": "[]byte",
"doc": null
}
],
"immediate_args": [
{
"name": "C",
"immediate_type": "arg_enum",
"arg_enum": "Mimc Configurations",
"modifies_stack_input": null,
"modifies_stack_output": null,
"doc": "configuration index"
}
],
"stack_outputs": [
{
"name": "X",
"stack_type": "[32]byte",
"doc": null
}
]
},
"min_balance": {
"name": "min_balance",
"code": 120,
Expand Down Expand Up @@ -6603,7 +6648,7 @@
"value": null,
"doc": "150 + 7 per 4 bytes of A"
},
"min_avm_version": 11,
"min_avm_version": 12,
"halts": false,
"mode": "any",
"groups": [
Expand Down Expand Up @@ -8324,15 +8369,15 @@
},
{
"name": "PayoutsMinBalance",
"doc": "The minimum algo balance an account must have in the agreement round to receive block payouts in the proposal round.",
"doc": "The minimum balance an account must have in the agreement round to receive block payouts in the proposal round.",
"stack_type": "uint64",
"mode": "any",
"value": 21,
"min_avm_version": 11
},
{
"name": "PayoutsMaxBalance",
"doc": "The maximum algo balance an account can have in the agreement round to receive block payouts in the proposal round.",
"doc": "The maximum balance an account can have in the agreement round to receive block payouts in the proposal round.",
"stack_type": "uint64",
"mode": "any",
"value": 22,
Expand Down Expand Up @@ -8775,14 +8820,32 @@
"min_avm_version": 7
}
],
"Mimc Configurations": [
{
"name": "BN254Mp110",
"doc": "MiMC configuration for the BN254 curve with Miyaguchi-Preneel mode, 110 rounds, exponent 5, seed \"seed\"",
"stack_type": null,
"mode": "any",
"value": 0,
"min_avm_version": 11
},
{
"name": "BLS12_381Mp111",
"doc": "MiMC configuration for the BLS12-381 curve with Miyaguchi-Preneel mode, 111 rounds, exponent 5, seed \"seed\"",
"stack_type": null,
"mode": "any",
"value": 1,
"min_avm_version": 11
}
],
"voter_params": [
{
"name": "VoterBalance",
"doc": "Online stake in microalgos",
"stack_type": "uint64",
"mode": "app",
"value": 0,
"min_avm_version": 6
"min_avm_version": 11
},
{
"name": "VoterIncentiveEligible",
Expand Down
8 changes: 7 additions & 1 deletion scripts/generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
VCS_ROOT = Path(__file__).parent.parent
MIN_SUPPORTED_VERSION = min(SUPPORTED_AVM_VERSIONS)


PYTHON_ENUM_CLASS = {
"Mimc Configurations": "MiMCConfigurations",
}
PYTYPE_TO_LITERAL: dict[pytypes.PyType, pytypes.LiteralOnlyType | None] = {
pytypes.BytesType: pytypes.BytesLiteralType,
pytypes.UInt64Type: pytypes.IntLiteralType,
Expand Down Expand Up @@ -602,6 +604,10 @@ def get_op_doc(op: Op) -> list[str]:


def get_python_enum_class(arg_enum: str) -> str:
try:
return PYTHON_ENUM_CLASS[arg_enum]
except KeyError:
pass
# don't change acronyms
if arg_enum.isupper():
return arg_enum
Expand Down
2 changes: 1 addition & 1 deletion src/puya/algo_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
# Which language versions does this version of puya support targeting
# This will typically just be the current mainnet version and potentially the vNext if it doesn't
# contain breaking changes
SUPPORTED_AVM_VERSIONS = [10, 11]
SUPPORTED_AVM_VERSIONS = [10, 11, 12]
# Which language version is currently deployed to mainnet
MAINNET_AVM_VERSION = 10
35 changes: 30 additions & 5 deletions src/puya/ir/avm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,11 +1952,11 @@ def get_variant(self, immediates: Sequence[str | int]) -> Variant:
),
enum=None,
supported_modes=RunMode.any,
min_avm_version=11,
min_avm_version=12,
),
immediate_types=(),
cost=1700,
min_avm_version=11,
min_avm_version=12,
supported_modes=RunMode.any,
)
"""
Expand Down Expand Up @@ -5151,6 +5151,31 @@ def get_variant(self, immediates: Sequence[str | int]) -> Variant:
integers
"""

mimc = AVMOpData(
op_code="mimc",
variants=Variant(
signature=OpSignature(args=[StackType.bytes], returns=[StackType.bytes]),
enum=None,
supported_modes=RunMode.any,
min_avm_version=11,
),
immediate_types=(ImmediateKind.arg_enum,),
cost=None,
min_avm_version=11,
supported_modes=RunMode.any,
)
"""
MiMC hash of scalars A, using curve and parameters specified by configuration C
A is a list of concatenated 32 byte big-endian unsigned integer scalars. Fail if A's length is
not a multiple of 32 or any element exceeds the curve modulus.
The MiMC hash function has known collisions since any input which is a multiple of the elliptic
curve modulus will hash to the same value. MiMC is thus not a general purpose hash function,
but meant to be used in zero knowledge applications to match a zk-circuit implementation.
"""

min_balance = AVMOpData(
op_code="min_balance",
variants=Variant(
Expand Down Expand Up @@ -5696,11 +5721,11 @@ def get_variant(self, immediates: Sequence[str | int]) -> Variant:
signature=OpSignature(args=[StackType.bytes], returns=[StackType.bytes]),
enum=None,
supported_modes=RunMode.any,
min_avm_version=11,
min_avm_version=12,
),
immediate_types=(),
cost=None,
min_avm_version=11,
min_avm_version=12,
supported_modes=RunMode.any,
)
"""
Expand Down Expand Up @@ -6263,7 +6288,7 @@ def get_variant(self, immediates: Sequence[str | int]) -> Variant:
),
enum="VoterBalance",
supported_modes=RunMode.app,
min_avm_version=6,
min_avm_version=11,
),
"VoterIncentiveEligible": Variant(
signature=OpSignature(
Expand Down
5 changes: 5 additions & 0 deletions src/puya/ussemble/op_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,4 +986,9 @@
ImmediateEnum(codes={"BN254g1": 0, "BN254g2": 1, "BLS12_381g1": 2, "BLS12_381g2": 3})
],
),
"mimc": OpSpec(
name="mimc",
code=230,
immediates=[ImmediateEnum(codes={"BN254Mp110": 0, "BLS12_381Mp111": 1})],
),
}
15 changes: 15 additions & 0 deletions src/puyapy/awst_build/intrinsic_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
Secp256k1="Secp256k1",
Secp256r1="Secp256r1",
),
MiMCConfigurations=dict(
BN254Mp110="BN254Mp110",
BLS12_381Mp111="BLS12_381Mp111",
),
VrfVerify=dict(
VrfAlgorand="VrfAlgorand",
),
Expand Down Expand Up @@ -429,6 +433,17 @@
),
],
),
mimc=OpMappingWithOverloads(
result=pytypes.BytesType,
arity=2,
overloads=[
FunctionOpMapping(
"mimc",
immediates=[str],
args=[0, (pytypes.BytesType,)],
),
],
),
min_balance=OpMappingWithOverloads(
result=pytypes.UInt64Type,
arity=1,
Expand Down
2 changes: 1 addition & 1 deletion src/puyapy/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

# this should contain the lowest version number that this compiler does NOT support
# i.e. the next minor version after what is defined in stubs/pyproject.toml:tool.poetry.version
MAX_SUPPORTED_ALGOPY_VERSION_EX = version.parse("2.5.0")
MAX_SUPPORTED_ALGOPY_VERSION_EX = version.parse("2.6.0")
MIN_SUPPORTED_ALGOPY_VERSION = version.parse(f"{MAX_SUPPORTED_ALGOPY_VERSION_EX.major}.0.0")

logger = log.get_logger(__name__)
Expand Down
Loading

0 comments on commit 62da1ab

Please sign in to comment.