Skip to content

Commit

Permalink
Saving bytecode by moving moduleOnly access modifier into authorize f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
cristovaoth committed Oct 30, 2023
1 parent b0f8d47 commit edf3d97
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/evm/contracts/AllowanceTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ abstract contract AllowanceTracker is Core {
return (allowance.balance, allowance.timestamp);
}

uint64 elapsedIntervals = (blockTimestamp -
allowance.timestamp) / allowance.period;
uint64 elapsedIntervals = (blockTimestamp - allowance.timestamp) /
allowance.period;

if (allowance.balance < allowance.maxRefill) {
balance = allowance.balance + allowance.refill * elapsedIntervals;
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/contracts/PermissionChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract contract PermissionChecker is Core, Periphery {
uint256 value,
bytes calldata data,
Enum.Operation operation
) internal view returns (Consumption[] memory) {
) internal moduleOnly returns (Consumption[] memory) {
// We never authorize the zero role, as it could clash with the
// unassigned default role
if (roleKey == 0) {
Expand Down
13 changes: 4 additions & 9 deletions packages/evm/contracts/Roles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ contract Roles is
uint256 value,
bytes calldata data,
Enum.Operation operation
) public override moduleOnly returns (bool success) {
) public override returns (bool success) {
Consumption[] memory consumptions = _authorize(
defaultRoles[msg.sender],
to,
Expand All @@ -129,12 +129,7 @@ contract Roles is
uint256 value,
bytes calldata data,
Enum.Operation operation
)
public
override
moduleOnly
returns (bool success, bytes memory returnData)
{
) public override returns (bool success, bytes memory returnData) {
Consumption[] memory consumptions = _authorize(
defaultRoles[msg.sender],
to,
Expand Down Expand Up @@ -162,7 +157,7 @@ contract Roles is
Enum.Operation operation,
bytes32 roleKey,
bool shouldRevert
) public moduleOnly returns (bool success) {
) public returns (bool success) {
Consumption[] memory consumptions = _authorize(
roleKey,
to,
Expand Down Expand Up @@ -193,7 +188,7 @@ contract Roles is
Enum.Operation operation,
bytes32 roleKey,
bool shouldRevert
) public moduleOnly returns (bool success, bytes memory returnData) {
) public returns (bool success, bytes memory returnData) {
Consumption[] memory consumptions = _authorize(
roleKey,
to,
Expand Down
20 changes: 8 additions & 12 deletions packages/evm/contracts/WriteOnce.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,22 @@ library WriteOnce {
*/
function store(bytes memory data) internal returns (address pointer) {
bytes memory creationBytecode = creationBytecodeFor(data);
address calculatedAddress = addressFor(creationBytecode);
pointer = addressFor(creationBytecode);

uint256 size;
assembly {
size := extcodesize(calculatedAddress)
size := extcodesize(pointer)
}

address actualAddress;
if (size == 0) {
actualAddress = ISingletonFactory(SINGLETON_FACTORY).deploy(
creationBytecode,
SALT
assert(
pointer ==
ISingletonFactory(SINGLETON_FACTORY).deploy(
creationBytecode,
SALT
)
);
} else {
actualAddress = calculatedAddress;
}

assert(calculatedAddress == actualAddress);

pointer = calculatedAddress;
}

/**
Expand Down

0 comments on commit edf3d97

Please sign in to comment.