Ok, I have (again) some problems with the wording.
I mean, the card on the top of the ruin pile costs $0. Not all copies of it, only the one on top of the ruin pile.
Hope it mades things clearer.
I think that was clear from the wording, the problem is that you sound like you want it to still cost $0 after it is gained. If a Silver is on top of the Ruins pile, it costs, $0, which is fine. But then after you gain it, it is completely impossible to know which Silver in your deck costs $0, and which are the regular Silvers costing $3.
Anyway, it's not clear where the card costing up to $4 comes from. From your hand? From another supply pile?
Either way, this card doesn't seem like it's necessary to have it deal with Ruins at all. The main thing it accomplishes is to make 1 specific card cost $0 instead of its normal cost. I guess it also acts as a defense against Attack-Looters, but there's only 2 of those cards in existence. It would play almost the same if it said
"You may trash a card from your hand. Gain a card from the digging pile, putting it in your hand. Place a card costing up to $4 on the digging pile. This card costs $0.
Setup: Make a digging pile by taking a card costing up to $4 and setting it aside. The digging pile is not in the supply."