The law is good and the ten commandments are good but there was a flaw and the flaw was with us. The first problem of sin was not the wrong doing but the consciousness of sin and the condemnation it brought.
Moral uprightness is not a requirement of your salvation, it is a product of your salvation.
Righteousness means to be in right standing on accordance to God's terms. If God doesn't keep your sins neither should you. It's God's display of righteousness that he justifies you.