Skip to content

Commit

Permalink
fix: memory-safety for IR optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0dot committed May 27, 2024
1 parent cd5609f commit 3191aa0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/common/BaseLightAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ abstract contract BaseLightAccount is BaseAccount, TokenCallbackHandler, UUPSUpg
function create(bytes calldata initCode, uint256 value) external payable virtual onlyAuthorized {
assembly ("memory-safe") {
// Copy the initCode to memory, then deploy the contract
let ptr := mload(64)
let len := initCode.length
calldatacopy(0, initCode.offset, len)
let succ := create(value, 0, len)
calldatacopy(ptr, initCode.offset, len)
let succ := create(value, ptr, len)

// If the creation fails, revert
if iszero(succ) {
Expand All @@ -97,9 +98,10 @@ abstract contract BaseLightAccount is BaseAccount, TokenCallbackHandler, UUPSUpg
function create2(bytes calldata initCode, bytes32 salt, uint256 value) external payable virtual onlyAuthorized {
assembly ("memory-safe") {
// Copy the initCode to memory, then deploy the contract
let ptr := mload(64)
let len := initCode.length
calldatacopy(0, initCode.offset, len)
let succ := create2(value, 0, len, salt)
calldatacopy(ptr, initCode.offset, len)
let succ := create2(value, ptr, len, salt)

// If the creation fails, revert
if iszero(succ) {
Expand Down Expand Up @@ -161,8 +163,9 @@ abstract contract BaseLightAccount is BaseAccount, TokenCallbackHandler, UUPSUpg
let succ := call(gas(), target, value, add(data, 32), mload(data), 0, 0)
if iszero(succ) {
// We can overwrite memory since we're going to revert out of this call frame anyway
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
let ptr := mload(64)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
}
}
Expand Down

0 comments on commit 3191aa0

Please sign in to comment.