I had created a DAO smart contract where around 20 people vote for proposals. They each make new Tx.

Offline signing is nice to minimize gas cost. Wondering how offline signing works with contract functions, that too with multiple people signing different votes?

I heard that multiple people signs their balance in lighting network channel state.


You use signing in the same way that you would if one person was signing. Each person will have to pay the transactions costs needed to submit their signature. However you could create a single function that will automatically parse all signed messages for slightly cheaper than if you were to submit a new transaction to parse each signed message. You could potentially implement something like merkle airdrops (https://blog.ricmoo.com/merkle-air-drops-e6406945584d)

There are a few gotchas that come with verifying signed messages, I have a set of contracts and python signer program which demonstrate the workflow needed to sign messages:

When signing messages they get prepended with the following data: https://github.com/postables/Postables-Payment-Channel/blob/7d2f91bb060f80b139cab72b5fdff79d116f6210/solidity/ChannelsV4.sol#L12

I also have a python script which can be used to sign messages: https://github.com/postables/Postables-Payment-Channel/blob/develop/python/signer.py

The following solidity function details how to verify the ORIGINAL message that was signed, along with the signer of the signed message: https://github.com/postables/Postables-Payment-Channel/blob/7d2f91bb060f80b139cab72b5fdff79d116f6210/solidity/ChannelsV4.sol#L257

The following solidity function details how to verify the signer of a message: https://github.com/postables/Postables-Payment-Channel/blob/7d2f91bb060f80b139cab72b5fdff79d116f6210/solidity/ChannelsV4.sol#L192

  • You said "for slightly cheaper". Proportionately, how much gas cost can be saved with this stated method? May 26 '18 at 10:25
  • The exact amount I haven't been able to calculate, however each transaction you submit must include a gas of 21000, so theoretically you would save 21K gas for each transaction you don't submit. Granted it won't work out exactly like that but you'll save some.
    – hextet
    May 26 '18 at 23:18

Yes, you can have people sign offline, gather all the signatures together and send them as part of the data section of a single transaction and have the contract check the number of valid signatures. This should save you gas, and it will often allow for a simpler contract.

See this example of a multisig wallet that works like this: https://medium.com/@ChrisLundkvist/exploring-simpler-ethereum-multisig-contracts-b71020c19037

However, do bear in mind that each signature you add will increase the gas cost of the transaction that sends them, and the total gas you can use in a single transaction is limited by the block gas limit, which may change. So if the number of signatures that may be required is high or unbounded, you may still need to write the contract so that the signatures can be split across multiple transactions.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.