8000 Gasless ContractPublisher without chainid in typehash by nkrishang · Pull Request #235 · thirdweb-dev/contracts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Gasless ContractPublisher without chainid in typehash #235

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
Sep 7, 2022

Conversation

nkrishang
Copy link
Contributor

No description provided.

@nkrishang nkrishang added the enhancement New feature or request label Aug 31, 2022
@nkrishang nkrishang self-assigned this Aug 31, 2022
@nkrishang nkrishang changed the title [DO NOT MERGE] Gasless ContractPublisher without chainid in typehash Gasless ContractPublisher without chainid in typehash Sep 2, 2022
Comment on lines +56 to +81
function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
// require(req.chainid == block.chainid, "MinimalForwarder: invalid chainId");
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;

(bool success, bytes memory returndata) = req.to.call{ gas: req.gas, value: req.value }(
abi.encodePacked(req.data, req.from)
);

// Validate that the relayer has sent enough gas for the call.
// See https://ronan.eth.link/blog/ethereum-gas-dangers/
if (gasleft() <= req.gas / 63) {
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
// neither revert or assert consume all gas since Solidity 0.8.0
// https://docs.soliditylang.org/en/v0.8.0/control-structures.html#panic-via-assert-and-error-via-require
assembly {
invalid()
}
}

return (success, returndata);
}

Check failure

Code scanning / Slither

Functions that send Ether to arbitrary destinations

ForwarderChainlessDomain.execute(ForwarderChainlessDomain.ForwardRequest,bytes) (contracts/forwarder/ForwarderChainlessDomain.sol#56-81) sends eth to arbitrary user Dangerous calls: - (success,returndata) = req.to.call{gas: req.gas,value: req.value}(abi.encodePacked(req.data,req.from)) (contracts/forwarder/ForwarderChainlessDomain.sol#65-67)
Comment on lines +42 to +66
function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = req.to.call{ gas: req.gas, value: req.value }(
abi.encodePacked(req.data, req.from)
);

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 gas: https://ronan.eth.link/blog/ethereum-gas-dangers/
assert(gasleft() > req.gas / 63);
return (success, result);
}

Check failure

Code scanning / Slither

Functions that send Ether to arbitrary destinations

Forwarder.execute(Forwarder.ForwardRequest,bytes) (contracts/forwarder/Forwarder.sol#42-66) sends eth to arbitrary user Dangerous calls: - (success,result) = req.to.call{gas: req.gas,value: req.value}(abi.encodePacked(req.data,req.from)) (contracts/forwarder/Forwarder.sol#51-53)
Comment on lines +42 to +66
8000
function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = req.to.call{ gas: req.gas, value: req.value }(
abi.encodePacked(req.data, req.from)
);

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 gas: https://ronan.eth.link/blog/ethereum-gas-dangers/
assert(gasleft() > req.gas / 63);
return (success, result);
}

Check warning

Code scanning / Slither

Assembly usage

Forwarder.execute(Forwarder.ForwardRequest,bytes) (contracts/forwarder/Forwarder.sol#42-66) uses assembly - INLINE ASM (contracts/forwarder/Forwarder.sol#58-60)
Comment on lines +56 to +81
function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
// require(req.chainid == block.chainid, "MinimalForwarder: invalid chainId");
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;

(bool success, bytes memory returndata) = req.to.call{ gas: req.gas, value: req.value }(
abi.encodePacked(req.data, req.from)
);

// Validate that the relayer has sent enough gas for the call.
// See https://ronan.eth.link/blog/ethereum-gas-dangers/
if (gasleft() <= req.gas / 63) {
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
// neither revert or assert consume all gas since Solidity 0.8.0
// https://docs.soliditylang.org/en/v0.8.0/control-structures.html#panic-via-assert-and-error-via-require
assembly {
invalid()
}
}

return (success, returndata);
}

Check warning

Code scanning / Slither

Assembly usage

ForwarderChainlessDomain.execute(ForwarderChainlessDomain.ForwardRequest,bytes) (contracts/forwarder/ForwarderChainlessDomain.sol#56-81) uses assembly - INLINE ASM (contracts/forwarder/ForwarderChainlessDomain.sol#75-77)
Comment on lines +42 to +66
function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;

// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory result) = req.to.call{ gas: req.gas, value: req.value }(
abi.encodePacked(req.data, req.from)
);

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 gas: https://ronan.eth.link/blog/ethereum-gas-dangers/
assert(gasleft() > req.gas / 63);
return (success, result);
}

Check warning

Code scanning / Slither

Low-level calls

Low level call in Forwarder.execute(Forwarder.ForwardRequest,bytes) (contracts/forwarder/Forwarder.sol#42-66): - (success,result) = req.to.call{gas: req.gas,value: req.value}(abi.encodePacked(req.data,req.from)) (contracts/forwarder/Forwarder.sol#51-53)
Comment on lines +56 to +81
function execute(ForwardRequest calldata req, bytes calldata signature)
public
payable
returns (bool, bytes memory)
{
// require(req.chainid == block.chainid, "MinimalForwarder: invalid chainId");
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;

(bool success, bytes memory returndata) = req.to.call{ gas: req.gas, value: req.value }(
abi.encodePacked(req.data, req.from)
);

// Validate that the relayer has sent enough gas for the call.
// See https://ronan.eth.link/blog/ethereum-gas-dangers/
if (gasleft() <= req.gas / 63) {
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
// neither revert or assert consume all gas since Solidity 0.8.0
// https://docs.soliditylang.org/en/v0.8.0/control-structures.html#panic-via-assert-and-error-via-require
assembly {
invalid()
}
}

return (success, returndata);
}

Check warning

Code scanning / Slither

Low-level calls

Low level call in ForwarderChainlessDomain.execute(ForwarderChainlessDomain.ForwardRequest,bytes) (contracts/forwarder/ForwarderChainlessDomain.sol#56-81): - (success,returndata) = req.to.call{gas: req.gas,value: req.value}(abi.encodePacked(req.data,req.from)) (contracts/forwarder/ForwarderChainlessDomain.sol#65-67)
@jakeloo
Copy link
Member
jakeloo commented Sep 3, 2022

For chainless we should support salt instead

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md#definition-of-domainseparator

@nkrishang nkrishang merged commit 849e186 into main Sep 7, 2022
@nkrishang nkrishang deleted the contractPublisher-signature branch September 23, 2022 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0