Either one of those would be correct. When using to, it is understood that there is an implied verb (the secret to attaining perfection is, etc). In the second, the understanding would be that the secret to the condition of perfection is paying attention to the smallest details.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.