I worked on this a while ago at Mozilla. There was a presentation at ACM CCS '16 on what we did. Unfortunately the effort was discontinued, but we definitely solved a lot of the technical issues.
Wasn't that how ads were actually implemented on Firefox's homepage several years ago? IIRC, Mozilla developed it in cooperation with IAB as a solution to privacy (the ad-funded web being practically unavoidable), deployed it (maybe only in alpha or beta), and then people went ballistic over advertising in Firefox - without realizing it was a huge privacy gain - and Mozilla pulled it. Here's one article I found quickly; note that ads are based on local browser history.