Cyfrin / foundry-smart-contract-lottery-cu

47 stars 38 forks source link

Stack Too Deep #10

Closed JordGreer closed 4 months ago

JordGreer commented 1 year ago

I am getting a "Stack too deep" error after compiling. This occurred right after adding in the deployer key configuration in the video around the 6:50:00 mark of "Learn Solidity, Blockchain Development, & Smart Contracts | Powered By AI - Full Course (7 - 11)"

I am aware of this error in that the EVM stack is limited and is being filled by too many opcodes. I believe this error is occurring from the test RaffleTest.t.sol file since it is very meaty. I attempted to resolve this by combining state variables into a single network config struct, however I still getting this error. My hunch is that I actually need to reduce the number of local variables in some function.

I was wondering if anyone else was getting a stack too deep error, or could give some insight. @PatrickAlphaC

Repo: https://github.com/JordGreer/Foundry-Raffle

Thanks, Jordan

inallhonesty commented 1 year ago

I also got the same error, from the get-go I wanted to add a fee + a way of transferring overpaid funds to the owner of the contract (I know, greedy lottery). The moment that NetworkConfig struct gets an 8th entry you get "Stack too deep". I solved it by including the --via-ir tag in any forge command. Takes a bit more time but it fixes the error.

Interesting read: https://docs.soliditylang.org/en/latest/ir-breaking-changes.html

JordGreer commented 1 year ago

Hey @inallhonesty, I'll need to go look at how many times the NetworkConfig struct gets used. I guess its using up all 1024 slots on the stack.

I also saw the suggestion to use --via-ir. I read a little about how this could change how some of the logic could be different at compilation time. I don't think that this is an issue here, but a consideration in the future.

Slavchew commented 1 year ago

@JordGreer @inallhonesty Refer to this https://github.com/Cyfrin/foundry-smart-contract-lottery-f23/issues/9#issuecomment-1637113381

PatrickAlphaC commented 4 months ago

Going to close this, the code as written doesn't run into this. Curious what you're adding to get this.