Oil prices gained on Tuesday as attacks on shipping in the Strait of Hormuz offset signs of improving crude supply.