Smart contract design for gas refund

by Amxx   Last Updated November 12, 2018 15:28 PM

I'm designing a proxy smartcontract that will be filled by users so that anyone has an incentive to can perform a transaction useful to the user. I won't go into the detail of "usefulness" here.

My contract is a proxy that calls a function XXX(data). So far I've got this:

contract Broker
{
    using SafeMathOZ for uint256;
    Target                      public target;
    mapping(address => uint256) public m_balance;
    mapping(address => uint256) public m_reward;

    constructor(address _target) public {
        target = Target(_target);
    }

    function () public payable {
        m_balance[msg.sender] = m_balance[msg.sender].add(msg.value);
    }

    function deposit() public payable {
        m_balance[msg.sender] = m_balance[msg.sender].add(msg.value);
    }

    function depositFor(address _account) public payable {
        m_balance[_account] = m_balance[_account].add(msg.value);
    }

    function withdraw(uint256 _amount) public {
        m_balance[msg.sender] = m_balance[msg.sender].sub(_amount);
        msg.sender.transfer(_amount);
    }

    function setReward(uint256 _reward) public {
        m_reward[msg.sender] = _reward;
    }

    function XXX(Data data) public returns (bytes32) {
        uint256 gasBefore = gasleft();
        bytes32 result = target.XXX(data);
        address payer = data.requester;
        uint256 price = tx.gasprice * (87000 + gasBefore - gasleft()) + m_reward[payer];
        m_balance[payer] = m_balance[payer].sub(price);
        msg.sender.transfer(price);
        return result;
    }
}

It works as expected and rewards the sender as I expect. What I am worried about is the possibility of a message sender to provide a very high gas price, thus draining the user balance and "giving" it to the miner :/

Any idea on how to solve this issue? Is there a better way then having the user specify a "maximum gas cost"?



Related Questions


Upgradeable smart contracts

Updated October 01, 2017 15:28 PM

Updating content o af smart contract

Updated July 10, 2018 22:28 PM


Design pattern for game development

Updated November 30, 2018 18:28 PM