Skip to content

Commit

Permalink
feat[lang]: introduce mana as an alias for gas (#3713)
Browse files Browse the repository at this point in the history
per EIP-6789 (https://eips.ethereum.org/EIPS/eip-6789), add `msg.mana`
as an alias for `msg.gas`

---------

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
  • Loading branch information
pcaversaccio and charles-cooper authored Jul 27, 2024
1 parent a1af967 commit 9e51684
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/constants-and-vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Name Type Value
``chain.id`` ``uint256`` Chain ID
``msg.data`` ``Bytes`` Message data
``msg.gas`` ``uint256`` Remaining gas
``msg.mana`` ``uint256`` Remaining gas (alias for ``msg.gas``)
``msg.sender`` ``address`` Sender of the message (current call)
``msg.value`` ``uint256`` Number of wei sent with the message
``tx.origin`` ``address`` Sender of the transaction (full call chain)
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/codegen/features/test_mana.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def test_mana_call(get_contract):
mana_call = """
@external
def foo() -> uint256:
return msg.mana
"""

c = get_contract(mana_call)

assert c.foo(gas=50000) < 50000
assert c.foo(gas=50000) > 25000
3 changes: 2 additions & 1 deletion vyper/codegen/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ def parse_Attribute(self):
return IRnode.from_list(["~calldata"], typ=BytesT(0))
elif key == "msg.value" and self.context.is_payable:
return IRnode.from_list(["callvalue"], typ=UINT256_T)
elif key == "msg.gas":
elif key in ("msg.gas", "msg.mana"):
# NOTE: `msg.mana` is an alias for `msg.gas`
return IRnode.from_list(["gas"], typ=UINT256_T)
elif key == "block.prevrandao":
if not version_check(begin="paris"):
Expand Down
8 changes: 7 additions & 1 deletion vyper/semantics/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class _Chain(_EnvType):

class _Msg(_EnvType):
_id = "msg"
_type_members = {"data": BytesT(), "gas": UINT256_T, "sender": AddressT(), "value": UINT256_T}
_type_members = {
"data": BytesT(),
"gas": UINT256_T,
"mana": UINT256_T,
"sender": AddressT(),
"value": UINT256_T,
}


class _Tx(_EnvType):
Expand Down

0 comments on commit 9e51684

Please sign in to comment.