Skip to content

Minimal factory #288

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

Merged
merged 11 commits into from
Feb 22, 2023
Merged

Minimal factory #288

merged 11 commits into from
Feb 22, 2023

Conversation

kumaryash90
Copy link
Member

No description provided.

Comment on lines 9 to 38
constructor(
address _implementation,
bytes memory _data,
bytes32 _salt
) payable {
address instance;
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, _implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, _salt)
}

if (_data.length > 0) {
// instance.call{ value: msg.value }(_data);

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = instance.call{ value: msg.value }(_data);

if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert("Transaction reverted silently");
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
}
}

Check warning

Code scanning / Slither

Assembly usage

TWMinimalFactory.constructor(address,bytes,bytes32) (contracts/TWMinimalFactory.sol#9-38) uses assembly - INLINE ASM (contracts/TWMinimalFactory.sol#15-21) - INLINE ASM (contracts/TWMinimalFactory.sol#32-34)
Comment on lines 9 to 38
constructor(
address _implementation,
bytes memory _data,
bytes32 _salt
) payable {
address instance;
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, _implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, _salt)
}

if (_data.length > 0) {
// instance.call{ value: msg.value }(_data);

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = instance.call{ value: msg.value }(_data);

if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert("Transaction reverted silently");
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
}
}

Check warning

Code scanning / Slither

Low-level calls

Low level call in TWMinimalFactory.constructor(address,bytes,bytes32) (contracts/TWMinimalFactory.sol#9-38): - (success,result) = instance.call{value: msg.value}(_data) (contracts/TWMinimalFactory.sol#27)
Comment on lines 9 to 38
constructor(
address _implementation,
bytes memory _data,
bytes32 _salt
) payable {
address instance;
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, _implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, _salt)
}

if (_data.length > 0) {
// instance.call{ value: msg.value }(_data);

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = instance.call{ value: msg.value }(_data);

if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert("Transaction reverted silently");
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
}
}

Check warning

Code scanning / Slither

Too many digits

TWMinimalFactory.constructor(address,bytes,bytes32) (contracts/TWMinimalFactory.sol#9-38) uses literals with too many digits: - mstore(uint256,uint256)(ptr_constructor_asm_0,0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) (contracts/TWMinimalFactory.sol#17)
Comment on lines 9 to 38
constructor(
address _implementation,
bytes memory _data,
bytes32 _salt
) payable {
address instance;
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, _implementation))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, _salt)
}

if (_data.length > 0) {
// instance.call{ value: msg.value }(_data);

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = instance.call{ value: msg.value }(_data);

if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert("Transaction reverted silently");
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
}
}

Check warning

Code scanning / Slither

Too many digits

TWMinimalFactory.constructor(address,bytes,bytes32) (contracts/TWMinimalFactory.sol#9-38) uses literals with too many digits: - mstore(uint256,uint256)(ptr_constructor_asm_0 + 0x28,0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) (contracts/TWMinimalFactory.sol#19)
@nkrishang nkrishang merged commit 779afd8 into main Feb 22, 2023
@kumaryash90 kumaryash90 deleted the revised-architecture branch April 24, 2023 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants