Skip to content

Commit

Permalink
update optimization runs and use one more optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Oct 19, 2024
1 parent fe52797 commit cfadafd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ solc = '0.8.28'
evm_version='cancun'
via_ir = true
# optimizer_runs = 4_294_967_295
optimizer_runs = 25_000
optimizer_runs = 20_000
bytecode_hash = 'none'
src = "src"
out = "out"
Expand Down
40 changes: 10 additions & 30 deletions src/TheCompact.sol
Original file line number Diff line number Diff line change
Expand Up @@ -993,20 +993,11 @@ contract TheCompact is ITheCompact, ERC6909, Extsload {
amount := calldataload(add(calldataPointerWithOffset, 0x60))
}

address sponsor = _validate(id.toAllocatorId(), messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator);

assembly {
if iszero(or(iszero(sponsorDomainSeparator), iszero(shr(255, id)))) {
// revert InvalidScope(id)
mstore(0, 0xa06356f5)
mstore(0x20, id)
revert(0x1c, 0x24)
}
}
_ensureValidScope(sponsorDomainSeparator, id);

amount.withinAllocated(allocatedAmount);

return operation(sponsor, claimant, id, amount);
return operation(_validate(id.toAllocatorId(), messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator), claimant, id, amount);
}

function _processSplitClaimWithQualificationAndSponsorDomain(
Expand All @@ -1033,6 +1024,12 @@ contract TheCompact is ITheCompact, ERC6909, Extsload {

address sponsor = _validate(id.toAllocatorId(), messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator);

_ensureValidScope(sponsorDomainSeparator, id);

return _verifyAndProcessSplitComponents(sponsor, id, allocatedAmount, claimants, operation);
}

function _ensureValidScope(bytes32 sponsorDomainSeparator, uint256 id) internal pure {
assembly {
if iszero(or(iszero(sponsorDomainSeparator), iszero(shr(255, id)))) {
// revert InvalidScope(id)
Expand All @@ -1041,8 +1038,6 @@ contract TheCompact is ITheCompact, ERC6909, Extsload {
revert(0x1c, 0x24)
}
}

return _verifyAndProcessSplitComponents(sponsor, id, allocatedAmount, claimants, operation);
}

function _processBatchClaimWithQualificationAndSponsorDomain(
Expand Down Expand Up @@ -1102,14 +1097,7 @@ contract TheCompact is ITheCompact, ERC6909, Extsload {
component = claims[i];
component.amount.withinAllocated(component.allocatedAmount);
id = component.id;
assembly {
if iszero(or(iszero(sponsorDomainSeparator), iszero(shr(255, id)))) {
// revert InvalidScope(id)
mstore(0, 0xa06356f5)
mstore(0x20, id)
revert(0x1c, 0x24)
}
}
_ensureValidScope(sponsorDomainSeparator, component.id);
}

assembly {
Expand Down Expand Up @@ -1157,15 +1145,7 @@ contract TheCompact is ITheCompact, ERC6909, Extsload {

if (errorBuffer.asBool()) {
for (uint256 i = 0; i < totalClaims; ++i) {
id = claims[i].id;
assembly {
if iszero(or(iszero(sponsorDomainSeparator), iszero(shr(255, id)))) {
// revert InvalidScope(id)
mstore(0, 0xa06356f5)
mstore(0x20, id)
revert(0x1c, 0x24)
}
}
_ensureValidScope(sponsorDomainSeparator, claims[i].id);
}

assembly {
Expand Down

0 comments on commit cfadafd

Please sign in to comment.