# GSN Gas overhead? 10%?

**URL:** <https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202>\
**Category:** Contracts\
**Created:** [February 2, 2020, 4:10pm UTC](https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202 "2020-02-02T16:10:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steeve](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/steeve/32/3627_2.png) [@Steeve](https://forum.openzeppelin.com/u/Steeve)\
**Post date:** [February 2, 2020, 4:10pm UTC](https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202/1 "2020-02-02T16:10:30Z")

</div>

I was curious to know what the gas overhead is for Dapps using the GSN . Im not considering the cost to the developer, only the EVM costs when a given function is called in both non-GSN and GSN enabled contract. I deployed two instances of a SimpleStorage contract that stores an integer on the Ganache test chain:

**instance 1:** simple storage contract with no OZ library:  
Set function Gas usage: 26684

**instance 2:** same contract with OZ libs (`GSNRecipient.sol" Initializable.sol";`):  
Set function Gas usage: 29364 or 10.043% more

I think for now that it is a reasonable overhead when one considers the benefits of GSN. Did anyone get similar results and or do such tests?

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [February 3, 2020, 6:45am UTC](https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202/2 "2020-02-03T06:45:32Z")

</div>

Hi @Steeve,

Thanks for sharing. 🙏

I haven’t tried this test. I assume that you were calling the RelayHub contract when you tested with GSN.

On top of this will also be the gas cost of the GSN Strategy being used to determine whether to accept the relayed call: [https://docs.openzeppelin.com/contracts/2.x/gsn-strategies](https://docs.openzeppelin.com/contracts/2.x/gsn-strategies)

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [February 26, 2020, 4:47am UTC](https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202/3 "2020-02-26T04:47:07Z")

</div>

Hi @Steeve,

Using [Building a GSN-powered DApp](https://docs.openzeppelin.com/learn/sending-gasless-transactions#building-a-gsn-dapp) guide (but with regular contracts rather than upgradeable)

I ran a simple test to call the `increase` function of the `Counter` contract. No GSN strategies were used (all relayed calls were accepted).

This is a simple function call, so would consider the overhead more of a fixed amount rather than a percentage.

## Direct transaction

Calling `increase` via the CLI

```auto
$ npx oz send-tx
? Pick a network rinkeby
? Pick an instance Counter at 0x9839516a22b383267c4d31DCFD66b4794Df94527
? Select which function increase()
✓ Transaction successful. Transaction hash: 0x620e598d4a40b3a5bdd61e269b2e34e46ec8d62472c54ae890d8bc8af75043ed

```

[https://rinkeby.etherscan.io/tx/0x620e598d4a40b3a5bdd61e269b2e34e46ec8d62472c54ae890d8bc8af75043ed](https://rinkeby.etherscan.io/tx/0x620e598d4a40b3a5bdd61e269b2e34e46ec8d62472c54ae890d8bc8af75043ed)  
Gas Used by Transaction: 27,107

## Relayed via the GSN

[https://rinkeby.etherscan.io/tx/0x0ab9f5aea672e294fc60f6149b4f4bfd6290db0cd3e2ac9cbe096aa181a7ae80](https://rinkeby.etherscan.io/tx/0x0ab9f5aea672e294fc60f6149b4f4bfd6290db0cd3e2ac9cbe096aa181a7ae80)  
Gas Used by Transaction: 82,691

---

<div class="post-metadata">

**Author:** ![Steeve](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/steeve/32/3627_2.png) [@Steeve](https://forum.openzeppelin.com/u/Steeve)\
**Post date:** [February 26, 2020, 12:47pm UTC](https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202/4 "2020-02-26T12:47:58Z")

</div>

When i did it i used Ganache. Would the cases you ran, result in the same each time? 3x ?

My example was for a simple storage that stores an integer. My result i guess didn’t show the relaying overhead.

Is your analysis for the function + the relay?  
Or two separate calls : one to function without relay and the other same with relay call?

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [February 27, 2020, 7:26am UTC](https://forum.openzeppelin.com/t/gsn-gas-overhead-10/2202/5 "2020-02-27T07:26:09Z")

</div>

Hi @Steeve,

The direct transaction was a single call directly to the `increase` function.  
The GSN transaction was via a Relayer and the cost shown by Etherscan to call the `increase` function via the GSN.

I suggest trying it yourself on a public testnet using the [Building a GSN-powered DApp](https://docs.openzeppelin.com/learn/sending-gasless-transactions#building-a-gsn-dapp) guide. You can then modify the contract to experiment with different options.

The `increase` function is very basic, so I would expect more complex functions to be a greater part of the gas cost of a GSN transaction.

## Counter.sol

```auto
// contracts/Counter.sol
pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";

contract Counter is GSNRecipient {
    uint256 public value;

    function increase() public {
        value += 1;
    }

    function acceptRelayedCall(
        address relay,
        address from,
        bytes calldata encodedFunction,
        uint256 transactionFee,
        uint256 gasPrice,
        uint256 gasLimit,
        uint256 nonce,
        bytes calldata approvalData,
        uint256 maxPossibleCharge
    ) external view returns (uint256, bytes memory) {
        return _approveRelayedCall();
    }

    // We won't do any pre or post processing, so leave _preRelayedCall and _postRelayedCall empty
    function _preRelayedCall(bytes memory context) internal returns (bytes32) {
    }

    function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
    }
}

```
