What if i make a smart contract that does modify the state, but the all its functions are constant.(it will still compile) It means that i can use my smart contract for free without paying for the gas. Wouldn't this be a lose to the miners? How does Ethereum handles this situation?
You cannot change contract state without a blockchain transaction.
The reason it still compiles is because the Solidity compiler does not yet figure out with 100% accuracy which functions modify contract state. When I try to compile it, I do get this compiler warning:
Warning: Function declared as view, but this expression (potentially) modifies the state (...)