Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:lukso-network/lsp-smart-contract…
Browse files Browse the repository at this point in the history
…s into lsp23/rename-contracts
  • Loading branch information
skimaharvey committed Aug 15, 2023
2 parents 66655ac + 3d9d893 commit b766075
Show file tree
Hide file tree
Showing 33 changed files with 9,036 additions and 355 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
"lsp9init",
"lsp11",
"lsp11init",
"lsp17",
"lsp20",
"lsp20init",
"lsp23",
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/solc_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ jobs:
"0.8.12",
"0.8.13",
"0.8.14",
# 0.8.15 skipped as default in hardhat.config.ts
"0.8.15",
"0.8.16",
"0.8.17",
# 0.8.17 skipped as default in hardhat.config.ts
"0.8.18",
"0.8.19",
"0.8.20",
"0.8.21",
]
steps:
- uses: actions/checkout@v3
Expand Down
65 changes: 21 additions & 44 deletions contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ abstract contract LSP0ERC725AccountCore is
*
* @custom:events {ValueReceived} event when receiving native tokens.
*/
fallback() external payable virtual {
fallback(
bytes calldata callData
) external payable virtual returns (bytes memory) {
if (msg.value != 0) {
emit ValueReceived(msg.sender, msg.value);
}

if (msg.data.length < 4) {
return;
return "";
}

_fallbackLSP17Extendable();
return _fallbackLSP17Extendable(callData);
}

/**
Expand Down Expand Up @@ -789,57 +791,32 @@ abstract contract LSP0ERC725AccountCore is
* If there is an extension for the function selector being called, it calls the extension with the
* CALL opcode, passing the `msg.data` appended with the 20 bytes of the `msg.sender` and
* 32 bytes of the `msg.value`
*
* Because the function uses assembly `return()`/`revert()` to terminate the call, it cannot be
* called before other codes in {fallback()}.
*
* Otherwise, the codes after {_fallbackLSP17Extendable()} may never be reached.
*/
function _fallbackLSP17Extendable() internal virtual override {
function _fallbackLSP17Extendable(
bytes calldata callData
) internal virtual override returns (bytes memory) {
// If there is a function selector
address extension = _getExtension(msg.sig);

// if no extension was found for bytes4(0) return don't revert
if (msg.sig == bytes4(0) && extension == address(0)) return;
if (msg.sig == bytes4(0) && extension == address(0)) return "";

// if no extension was found for other function selectors, revert
if (extension == address(0))
revert NoExtensionFoundForFunctionSelector(msg.sig);

// solhint-disable no-inline-assembly
// if the extension was found, call the extension with the msg.data
// appended with bytes20(address) and bytes32(msg.value)
assembly {
calldatacopy(0, 0, calldatasize())

// The msg.sender address is shifted to the left by 12 bytes to remove the padding
// Then the address without padding is stored right after the calldata
mstore(calldatasize(), shl(96, caller()))

// The msg.value is stored right after the calldata + msg.sender
mstore(add(calldatasize(), 20), callvalue())

// Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
let success := call(
gas(),
extension,
0,
0,
add(calldatasize(), 52),
0,
0
)

// Copy the returned data
returndatacopy(0, 0, returndatasize())

switch success
// call returns 0 on failed calls
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
(bool success, bytes memory result) = extension.call(
abi.encodePacked(callData, msg.sender, msg.value)
);

if (success) {
return result;
} else {
// `mload(result)` -> offset in memory where `result.length` is located
// `add(result, 32)` -> offset in memory where `result` data starts
assembly {
let resultdata_size := mload(result)
revert(add(result, 32), resultdata_size)
}
}
}
Expand Down
50 changes: 16 additions & 34 deletions contracts/LSP17ContractExtension/LSP17Extendable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,48 +83,30 @@ abstract contract LSP17Extendable is ERC165 {
*
* Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
*/
function _fallbackLSP17Extendable() internal virtual {
function _fallbackLSP17Extendable(
bytes calldata callData
) internal virtual returns (bytes memory) {
// If there is a function selector
address extension = _getExtension(msg.sig);

// if no extension was found, revert
if (extension == address(0))
revert NoExtensionFoundForFunctionSelector(msg.sig);

// solhint-disable no-inline-assembly
// if the extension was found, call the extension with the msg.data
// appended with bytes20(address) and bytes32(msg.value)
assembly {
calldatacopy(0, 0, calldatasize())

// The msg.sender address is shifted to the left by 12 bytes to remove the padding
// Then the address without padding is stored right after the calldata
mstore(calldatasize(), shl(96, caller()))

// The msg.value is stored right after the calldata + msg.sender
mstore(add(calldatasize(), 20), callvalue())

// Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
let success := call(
gas(),
extension,
0,
0,
add(calldatasize(), 52),
0,
0
)

// Copy the returned data
returndatacopy(0, 0, returndatasize())
(bool success, bytes memory result) = extension.call(
abi.encodePacked(callData, msg.sender, msg.value)
);

switch success
// call returns 0 on failed calls
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
if (success) {
return result;
} else {
// `mload(result)` -> offset in memory where `result.length` is located
// `add(result, 32)` -> offset in memory where `result` data starts
// solhint-disable no-inline-assembly
/// @solidity memory-safe-assembly
assembly {
let resultdata_size := mload(result)
revert(add(result, 32), resultdata_size)
}
}
}
Expand Down
Loading

0 comments on commit b766075

Please sign in to comment.