statechannels / SCBridge-Wallet

MIT License
2 stars 3 forks source link

Allow "gasless transactions" (make Irene the paymaster?) #142

Open geoknee opened 1 year ago

geoknee commented 1 year ago

If she isn't already.

Basically we want to be elligible for a prize from polygon around "gasless transactions" https://ethglobal.com/events/ethonline2023/prizes#polygon

geoknee commented 1 year ago

I wonder if in we are already in fact doing gasless transactions? W manually deposited funds into the entrypoint(s) on behalf of alice and bob (using hardhat signer 0, or presumably some manually funded EOA we span up). Neither Alice nor Bob pays gas in our demo (from what I can make out).

In theory, in our demo Irene acts as bundler and can get reimbursed for spending the gas on submitting to the entrypoint. However, doing some experiments, it seems that Irene is not getting reimbursed (at least not directly). More investigation needed.

lalexgap commented 1 year ago

There definitely is some reimbursement going on, which gets paid out to the beneficiary address passed into HandleUserOps. Originally that address was point to Alice's SCW wallet, so we'd see Alice get a balance of 9.000000003473999872 when performing an L1 pay.

I think the amount that gets refunded is based on preVerificationGas. Based on my reading of ERC-4337 preverificatonGas is a fixed value (IE: it doesn't scale with the actual gas costs), so I suspect our preverificatonGas is just too low to compensate Irene fully for the cost of submitting the transaction.

In the real world preVerificationGas would be an amount to compensate the bundler for submitting the UserOp (probably in a batch) and any other overheads they have running the bundler.

lalexgap commented 1 year ago

Another important thing to note is that as part of our deploy we deposit into the entrypoint for Alice and Bob's SCW.

So that is most likely where the fees are being paid out from and why we don't see the gas fees coming out from the account balance.

geoknee commented 1 year ago

Thanks for the input @lalexgap. I'll try and increase the preverificationGas and see whether we can make it free or net positive for Irene to submit transactions.

lalexgap commented 1 year ago

I think if we want proper "gasless" transactions we need to use a paymaster, since right now Alice and Bob do end up paying for "gas" (if my assumption from above is correct, and the gas is being deducted from their entrypoint balance).

For a "gasless transaction"

lalexgap commented 1 year ago

I think this would implementing a paymaster contract. The Entrypoint is designed to call into this contract