Cyfrin / foundry-smart-contract-lottery-cu

48 stars 42 forks source link

**Wrong keyhash** for sepolia network - make the lottery stuck in `CALC` status #56

Closed worca333 closed 4 months ago

worca333 commented 4 months ago

In advance, I'd like to thank @PatrickAlphaC for an fast & productive course!

I found an issue with the keyHash of VRF subscription for the sepolia network.

After successfully deploying Raffle contract, subscribing to a chainlink VRF, and creating a chainlink upkeep timer, it seemed everything was in place and ready to work correctly. But somehow the lottery didn't award the winner at the last step - choosing the winner by a random number which is provided by VRFCoordinatorV2_5. Why? There was an error occurred within the s_vrfCoordinator.requestRandomWords request. What is irony though, the request itself came out as a successful one so that the performUpkeep method passed while updating the lottery status to CALC. Our contract never got a call to fulfillRandomWords which means it stuck with CALC status and all funds entered.

Deep inside, it was the problem with the keyHash (gasLane) of the config. Since we're using VRF v2.5, it should be 0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae from https://docs.chain.link/vrf/v2-5/supported-networks#sepolia-testnet But current codebase had 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c from https://docs.chain.link/vrf/v2/subscription/supported-networks#sepolia-testnet

Should it be fixed to a correct keyHash, it worked perfect!

Hope this helps.

cromewar commented 4 months ago

Hello @worca333, this is pretty interesting. Can you please share the lesson link on the updraft you are referring to? That way, we can add and update the written lesson in that section.

Cheers.

worca333 commented 4 months ago

Hi @cromewar,

Sure here is the lesson link: https://updraft.cyfrin.io/courses/foundry/smart-contract-lottery/setup And here is the git repo link: https://github.com/Cyfrin/foundry-smart-contract-lottery-cu/blob/main/script/HelperConfig.s.sol#L87

cromewar commented 4 months ago

Sorry, @worca333, but the lesson you mention is the beginning of it. Can you point me to the actual lesson video, please?

worca333 commented 4 months ago

@cromewar This is the lesson where Patrick makes up those values in HelperConfig.s.sol. Interestingly, it looks correct in the video while it isn't in the codebase.

PatrickAlphaC commented 4 months ago

Ah! I've fixed it here.

https://github.com/Cyfrin/foundry-smart-contract-lottery-cu/blob/main/script/HelperConfig.s.sol

Thanks! We will update the written lessons too.