What is the definition of "First Best", "Second Best", etc. in contract theory? What is the definition of "First Best", "Second Best", etc. in contract theory?

Especially, what is the difference between "First Best" in contract theory and "ex-post efficient" in mechanism design?
In contract theory

The first-best refers to the best you could do if you knew agents' preferences over labor an income (i.e., if you did not have to impose the incentive compatibility constraint), and the second-best is the best you can do if agents have to reveal their preferences themselves.

In mechanism design

A useful reference is Galichon, Alfred, Ex-Ante vs. Ex-Post Efficiency in Matching (May 21, 2011). Available at SSRN: http://ssrn.com/abstract=1837321 or http://dx.doi.org/10.2139/ssrn.1837321  :


  "an assignment is called ex-post efficient if no other deterministic assignment is improving on it in a Pareto sense; and ex-ante efficient if no lottery over deterministic assignments is." (my emphasis)


Difference between the two

There is not much connexion between the two notions as defined above. Every combination of the two notions is a priori possible. Both a mechanism and a contract can be


First-best ex-post efficient (i.e., efficient when incentive compatibility constraint is not imposed and the outcome of the mechanism/contract must be deterministic)
First-best ex-ante efficient (i.e., efficient when incentive compatibility constraint is not imposed and the outcome of the mechanism/contract can be random)
Second-best ex-post efficient (i.e., efficient when incentive compatibility constraint is imposed and the outcome of the mechanism/contract must be deterministic)
Second-best ex-ante efficient (i.e., efficient when incentive compatibility constraint is imposed and the outcome of the mechanism/contract can be random)


In the literature

Yet, in general, you are be more likely to find the first-best/second-best terminology in contract theory (random contracts are not that common in contract theory), and the ex-post/ex-ante efficiency in mechanism design (knowledge of the preferences is rarely assumed in a mechanism: the fact that we do not know agents preferences is the raison d'être of mechanism design). 

Thus you can expect to see 3. and 4. being discussed in the mechanism design literature, and 1. and 3. being discussed in contract theory.

Beware

This being said, the notions of second-best and first-best are often used outside of contract theory in a rather permissive way, which may be confusing. 

For some people, first-best simply means "if we do not impose some constraint $X$" and second-best means "if we do impose constraint $X$". 

Thus you may hear people talk about (beware this is where it gets confusing) 


an ex-post efficient mechanism as "second-best" efficient, because it is "efficient under the constraint that the assignment be deterministic". 
an ex-ante efficient mechanism as "first-best" efficient, that is "efficient if we do not impose constraint $X$".


Hope that clarifies it (or at least does not confuse you more).