Skip to content

Commit

Permalink
feat: improve comments and apply changes to cancun
Browse files Browse the repository at this point in the history
  • Loading branch information
trocher committed Jul 16, 2024
1 parent ef5e25b commit 6c337f7
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 53 deletions.
7 changes: 4 additions & 3 deletions src/ethereum/arrow_glacier/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
7 changes: 4 additions & 3 deletions src/ethereum/berlin/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
7 changes: 4 additions & 3 deletions src/ethereum/byzantium/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
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
7 changes: 4 additions & 3 deletions src/ethereum/constantinople/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
3 changes: 2 additions & 1 deletion src/ethereum/dao_fork/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum/frontier/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down
7 changes: 4 additions & 3 deletions src/ethereum/gray_glacier/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
3 changes: 2 additions & 1 deletion src/ethereum/homestead/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down
7 changes: 4 additions & 3 deletions src/ethereum/istanbul/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down Expand Up @@ -192,8 +193,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
7 changes: 4 additions & 3 deletions src/ethereum/london/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
7 changes: 4 additions & 3 deletions src/ethereum/muir_glacier/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down Expand Up @@ -192,8 +193,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
7 changes: 4 additions & 3 deletions src/ethereum/paris/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
7 changes: 4 additions & 3 deletions src/ethereum/shanghai/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
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
7 changes: 4 additions & 3 deletions src/ethereum/spurious_dragon/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down Expand Up @@ -188,8 +189,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
7 changes: 4 additions & 3 deletions src/ethereum/tangerine_whistle/vm/gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class MessageCallGas:
executing the call opcodes.
`cost`: `ethereum.base_types.Uint`
The gas required to execute the call opcode.
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.
Expand Down Expand Up @@ -188,8 +189,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

0 comments on commit 6c337f7

Please sign in to comment.