1

I have an ERC20 test contract, also I did multicall with delegatecall function instead of call. I have a three accounts: account1, account2, and account3. account1 can spend tokens from account2 (I did transaction here, and this is works)

Then I tried to send the same transaction with multicall contract, and I got an error: ERC20: insufficient allowance, here a callstack

So I see in both transactions allowance call, but in the second transaction I see allowance as 0. How to fix that? and why that happened?

anguser
  • 25
  • 2
  • Can you share the source code of the contracts involved? DELEGATECALL can't replace CALL in most cases see the differences here https://ethereum.stackexchange.com/questions/3667/difference-between-call-callcode-and-delegatecall. – Ismael Mar 17 '23 at 03:16
  • @Ismael technically it's copy of multicall contract https://paste.ee/p/EqfsW#s=0&l=102 where I replaced call to delegatecall – anguser Mar 17 '23 at 07:26

1 Answers1

0

Delegatecall requires target and source to have compatible storage layouts. You'll be executing the target's bytecode in the source contract's storage. If the Multicall contracts delegatecalls to the ERC20 it will not work as you are expecting

  1. they don't have compatible layouts,
  2. it will be modifying the Multicall storage and not the ERC20 storage.

Check the answer for the Difference between CALL, CALLCODE and DELEGATECALL to understand the details.

Ismael
  • 30,570
  • 21
  • 53
  • 96