Skip to content

Commit

Permalink
gas golfing: update types for more efficient code (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgercarder committed Apr 4, 2022
1 parent ce0b778 commit ebc6d70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/CommandBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ library CommandBuilder {
bytes1 index,
bytes memory output
) internal view {
uint8 idx = uint8(index);
uint256 idx = uint256(uint8(index));
if (idx == IDX_END_OF_ARGS) return;

bytes memory entry = state[idx] = new bytes(output.length + 32);
Expand Down
18 changes: 9 additions & 9 deletions contracts/VM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pragma solidity ^0.8.11;

import "./CommandBuilder.sol";

uint8 constant FLAG_CT_DELEGATECALL = 0x00;
uint8 constant FLAG_CT_CALL = 0x01;
uint8 constant FLAG_CT_STATICCALL = 0x02;
uint8 constant FLAG_CT_VALUECALL = 0x03;
uint8 constant FLAG_CT_MASK = 0x03;
uint8 constant FLAG_EXTENDED_COMMAND = 0x80;
uint8 constant FLAG_TUPLE_RETURN = 0x40;
uint256 constant FLAG_CT_DELEGATECALL = 0x00;
uint256 constant FLAG_CT_CALL = 0x01;
uint256 constant FLAG_CT_STATICCALL = 0x02;
uint256 constant FLAG_CT_VALUECALL = 0x03;
uint256 constant FLAG_CT_MASK = 0x03;
uint256 constant FLAG_EXTENDED_COMMAND = 0x80;
uint256 constant FLAG_TUPLE_RETURN = 0x40;

uint256 constant SHORT_COMMAND_FILL = 0x000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

Expand All @@ -34,7 +34,7 @@ abstract contract VM {
internal returns (bytes[] memory)
{
bytes32 command;
uint8 flags;
uint256 flags;
bytes32 indices;

bool success;
Expand All @@ -43,7 +43,7 @@ abstract contract VM {
uint256 commandsLength = commands.length;
for (uint256 i; i < commandsLength; i=_uncheckedIncrement(i)) {
command = commands[i];
flags = uint8(bytes1(command << 32));
flags = uint256(uint8(bytes1(command << 32)));

if (flags & FLAG_EXTENDED_COMMAND != 0) {
indices = commands[i++];
Expand Down

0 comments on commit ebc6d70

Please sign in to comment.