I'm designing a proxy smart contract that will be filled with eth by users so that anyone has an incentive to perform transactions 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);

    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);
        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"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.