OpenZeppelin / openzeppelin-contracts

OpenZeppelin Contracts is a library for secure smart contract development.
https://openzeppelin.com/contracts
MIT License
24.79k stars 11.76k forks source link

Add CanRefundGas contract #749

Closed medvedev1088 closed 5 years ago

medvedev1088 commented 6 years ago

πŸŽ‰ Description

Something like this:

pragma solidity^0.4.11;

contract CanRefundGas {

    modifier refundGasCost() {
        uint remainingGasStart = msg.gas;

        _;

        uint remainingGasEnd = msg.gas;
        uint usedGas = remainingGasStart - remainingGasEnd;
        // Add intrinsic gas and transfer gas. Need to account for gas stipend as well.
        usedGas += 21000 + 9700;
        // Possibly need to check max gasprice and usedGas here to limit 
        // possibility for abuse.
        uint gasCost = usedGas * tx.gasprice;
        // Refund gas cost
        tx.origin.transfer(gasCost);
    }
}
contract SomeContract is CanRefundGas {

    event SomeEvent(address sender);

    // Need to allow depositing ether to the contract
    function() public payable {
    }

    function doSomething() external refundGasCost {
        SomeEvent(msg.sender);  
    }
}

Originally discussed here https://ethereum.stackexchange.com/questions/38479/how-to-make-someone-else-pay-for-gas/38517#38517

nventuro commented 5 years ago

Hm, this is rather interesting indeed! Closing due to perceived lack of interest, and the fact that we'll probably move forward with some sort of metatx solution, but we'll be keeping this in the back of our minds, thanks!