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

Improve MessageCallGas documentation #904

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 9 additions & 8 deletions src/ethereum/arrow_glacier/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ class ExtendMemory:
@dataclass
class MessageCallGas:
"""
Define the gas cost and stipend for executing the call opcodes.
Define the gas cost and gas given to the sub-call for
executing the call opcodes.

`cost`: `ethereum.base_types.Uint`
The non-refundable portion of gas reserved for executing the
call opcode.
`stipend`: `ethereum.base_types.Uint`
The gas required to execute the call opcode, excludes
memory expansion costs.
`sub_call`: `ethereum.base_types.Uint`
The portion of gas available to sub-calls that is refundable
if not consumed
if not consumed.
"""

cost: Uint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to also rename cost to total or something similar? Looks like it excludes the memory expansion cost though, and that might be a tad misleading.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Added in a comment that it excludes memory expansion to be explicit.
  • Keeping cost in the variable name is good imo since it is added to some other cost afterwards, maybe total_cost would work?

charge_gas(evm, message_call_gas.cost + extend_memory.cost)

stipend: Uint
sub_call: Uint


def charge_gas(evm: Evm, amount: Uint) -> None:
Expand Down Expand Up @@ -189,8 +190,8 @@ def calculate_message_call_gas(
call_stipend: Uint = GAS_CALL_STIPEND,
) -> MessageCallGas:
"""
Calculates the MessageCallGas (cost and stipend) for
executing call Opcodes.
Calculates the MessageCallGas (cost and gas made available to the sub-call)
for executing call Opcodes.

Parameters
----------
Expand Down
12 changes: 6 additions & 6 deletions src/ethereum/arrow_glacier/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ def call(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -434,11 +434,11 @@ def callcode(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -551,7 +551,7 @@ def delegatecall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
evm.message.value,
evm.message.caller,
evm.message.current_target,
Expand Down Expand Up @@ -613,7 +613,7 @@ def staticcall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
U256(0),
evm.message.current_target,
to,
Expand Down
17 changes: 9 additions & 8 deletions src/ethereum/berlin/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ class ExtendMemory:
@dataclass
class MessageCallGas:
"""
Define the gas cost and stipend for executing the call opcodes.
Define the gas cost and gas given to the sub-call for
executing the call opcodes.

`cost`: `ethereum.base_types.Uint`
The non-refundable portion of gas reserved for executing the
call opcode.
`stipend`: `ethereum.base_types.Uint`
The gas required to execute the call opcode, excludes
memory expansion costs.
`sub_call`: `ethereum.base_types.Uint`
The portion of gas available to sub-calls that is refundable
if not consumed
if not consumed.
"""

cost: Uint
stipend: Uint
sub_call: Uint


def charge_gas(evm: Evm, amount: Uint) -> None:
Expand Down Expand Up @@ -190,8 +191,8 @@ def calculate_message_call_gas(
call_stipend: Uint = GAS_CALL_STIPEND,
) -> MessageCallGas:
"""
Calculates the MessageCallGas (cost and stipend) for
executing call Opcodes.
Calculates the MessageCallGas (cost and gas made available to the sub-call)
for executing call Opcodes.

Parameters
----------
Expand Down
12 changes: 6 additions & 6 deletions src/ethereum/berlin/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ def call(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -435,11 +435,11 @@ def callcode(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -562,7 +562,7 @@ def delegatecall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
evm.message.value,
evm.message.caller,
evm.message.current_target,
Expand Down Expand Up @@ -624,7 +624,7 @@ def staticcall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
U256(0),
evm.message.current_target,
to,
Expand Down
17 changes: 9 additions & 8 deletions src/ethereum/byzantium/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ class ExtendMemory:
@dataclass
class MessageCallGas:
"""
Define the gas cost and stipend for executing the call opcodes.
Define the gas cost and gas given to the sub-call for
executing the call opcodes.

`cost`: `ethereum.base_types.Uint`
The non-refundable portion of gas reserved for executing the
call opcode.
`stipend`: `ethereum.base_types.Uint`
The gas required to execute the call opcode, excludes
memory expansion costs.
`sub_call`: `ethereum.base_types.Uint`
The portion of gas available to sub-calls that is refundable
if not consumed
if not consumed.
"""

cost: Uint
stipend: Uint
sub_call: Uint


def charge_gas(evm: Evm, amount: Uint) -> None:
Expand Down Expand Up @@ -189,8 +190,8 @@ def calculate_message_call_gas(
call_stipend: Uint = GAS_CALL_STIPEND,
) -> MessageCallGas:
"""
Calculates the MessageCallGas (cost and stipend) for
executing call Opcodes.
Calculates the MessageCallGas (cost and gas made available to the sub-call)
for executing call Opcodes.

Parameters
----------
Expand Down
12 changes: 6 additions & 6 deletions src/ethereum/byzantium/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ def call(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -347,11 +347,11 @@ def callcode(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -463,7 +463,7 @@ def delegatecall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
evm.message.value,
evm.message.caller,
evm.message.current_target,
Expand Down Expand Up @@ -518,7 +518,7 @@ def staticcall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
U256(0),
evm.message.current_target,
to,
Expand Down
17 changes: 9 additions & 8 deletions src/ethereum/cancun/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,19 @@ class ExtendMemory:
@dataclass
class MessageCallGas:
"""
Define the gas cost and stipend for executing the call opcodes.
Define the gas cost and gas given to the sub-call for
executing the call opcodes.

`cost`: `ethereum.base_types.Uint`
The non-refundable portion of gas reserved for executing the
call opcode.
`stipend`: `ethereum.base_types.Uint`
The gas required to execute the call opcode, excludes
memory expansion costs.
`sub_call`: `ethereum.base_types.Uint`
The portion of gas available to sub-calls that is refundable
if not consumed
if not consumed.
"""

cost: Uint
stipend: Uint
sub_call: Uint


def charge_gas(evm: Evm, amount: Uint) -> None:
Expand Down Expand Up @@ -199,8 +200,8 @@ def calculate_message_call_gas(
call_stipend: Uint = GAS_CALL_STIPEND,
) -> MessageCallGas:
"""
Calculates the MessageCallGas (cost and stipend) for
executing call Opcodes.
Calculates the MessageCallGas (cost and gas made available to the sub-call)
for executing call Opcodes.

Parameters
----------
Expand Down
12 changes: 6 additions & 6 deletions src/ethereum/cancun/vm/instructions/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ def call(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -458,11 +458,11 @@ def callcode(evm: Evm) -> None:
if sender_balance < value:
push(evm.stack, U256(0))
evm.return_data = b""
evm.gas_left += message_call_gas.stipend
evm.gas_left += message_call_gas.sub_call
else:
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
value,
evm.message.current_target,
to,
Expand Down Expand Up @@ -577,7 +577,7 @@ def delegatecall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
evm.message.value,
evm.message.caller,
evm.message.current_target,
Expand Down Expand Up @@ -639,7 +639,7 @@ def staticcall(evm: Evm) -> None:
evm.memory += b"\x00" * extend_memory.expand_by
generic_call(
evm,
message_call_gas.stipend,
message_call_gas.sub_call,
U256(0),
evm.message.current_target,
to,
Expand Down
17 changes: 9 additions & 8 deletions src/ethereum/constantinople/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ class ExtendMemory:
@dataclass
class MessageCallGas:
"""
Define the gas cost and stipend for executing the call opcodes.
Define the gas cost and gas given to the sub-call for
executing the call opcodes.

`cost`: `ethereum.base_types.Uint`
The non-refundable portion of gas reserved for executing the
call opcode.
`stipend`: `ethereum.base_types.Uint`
The gas required to execute the call opcode, excludes
memory expansion costs.
`sub_call`: `ethereum.base_types.Uint`
The portion of gas available to sub-calls that is refundable
if not consumed
if not consumed.
"""

cost: Uint
stipend: Uint
sub_call: Uint


def charge_gas(evm: Evm, amount: Uint) -> None:
Expand Down Expand Up @@ -190,8 +191,8 @@ def calculate_message_call_gas(
call_stipend: Uint = GAS_CALL_STIPEND,
) -> MessageCallGas:
"""
Calculates the MessageCallGas (cost and stipend) for
executing call Opcodes.
Calculates the MessageCallGas (cost and gas made available to the sub-call)
for executing call Opcodes.

Parameters
----------
Expand Down
Loading