Cain and Abel had the knowledge of Ten commandments.
The key text to conclude this would be “Gen 4: 7 If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at the door. And unto thee shall be his desire, and thou shalt rule over him.”
Romans 3:20 for by the law is the knowledge of sin. (margin)
Bible tells us that by law is the knowledge of sin. Cain cannot be accused of doing sin if he has no knowledge of what is sin.
Also see Rom 7:7 What shall we say then? Is the law sin? God forbid. Nay, I had not known sin, but by the law: for I had not known lust, except the law had said, Thou shalt not covet.
Also Cain and Abel had the knowledge of ceremonial system which points to Christ who would die as the penalty for their sin(breaking law). Abel acknowledged this and gave a animal sacrifice.
Young’s Literal Translation
And it cometh to pass at the end of days that Cain bringeth from the fruit of the ground a present to Jehovah; Gen 4:3.
At the end of days. Cain and Abel came to worship on the end of days i.e., 7th day. Cain and Abel also kept Sabbath
Because that Abraham obeyed my voice, and kept my charge, my commandments, my statutes, and my laws. Gen 26: 5 Until Sinai there was knowledge of commandments,laws and ceremonies. Even the patriarchs paid tithe.