H1B - 1 Year Contract on W2 basis

Hello everyone,

Is it legal to sign a contract with a consultancy who is ready to sponsor H1B (For sure I have to bear the filing cost).
The consultancy claim that I cannot leave them within that one year period. I heard it is not legal. Any inputs in this regard is much appreciated.