Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add contract creation execution functions #61

Merged
merged 13 commits into from
May 31, 2024
Prev Previous commit
Next Next commit
fix: memory-safety for IR optimizer
Zer0dot committed May 27, 2024
commit 3191aa01986dc3bc864f97731d4b1478db8cb7ae
15 changes: 9 additions & 6 deletions src/common/BaseLightAccount.sol
Original file line number Diff line number Diff line change
@@ -82,9 +82,10 @@ abstract contract BaseLightAccount is BaseAccount, TokenCallbackHandler, UUPSUpg
function create(bytes calldata initCode, uint256 value) external payable virtual onlyAuthorized {
Zer0dot marked this conversation as resolved.
Show resolved Hide resolved
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)
Zer0dot marked this conversation as resolved.
Show resolved Hide resolved

// If the creation fails, revert
if iszero(succ) {
@@ -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) {
@@ -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())
}
}
}