The value of X is calculated only once, as Consuming Corruption resolves.

Artwork
Loading artwork…
Consuming Corruption
Foundations Commander · #93 · EN
Nonfoil—Foil—
Card rules
Consuming Corruption deals X damage to target creature or planeswalker and you gain X life, where X is the number of Swamps you control.
While crossing the mire, Lort the Sneaky found the perfect shortcut to the end of his life.
Uncommon · Illustrated by Andrew Theophilopoulos
Format legality
Brawl Legal
Commander Legal
Competitive Brawl Legal
Duel Legal
Gladiator Legal
Historic Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Timeless Legal
Tlr Legal
Vintage Legal
Alchemy Not Legal
Future Not Legal
Old School Not Legal
Pauper Not Legal
Pauper Commander Not Legal
Penny Not Legal
Pioneer Not Legal
PreDH Not Legal
Premodern Not Legal
Standard Not Legal
Standard Brawl Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions
If the target creature or planeswalker is an illegal target as Consuming Corruption tries to resolve, it won't resolve and none of its effects will happen. You won't gain life.