  We show how the topological string partition function, which is known to
capture the degeneracies of a gas of BPS spinning M2-branes in M-theory
compactified to 5 dimensions, is related to a 4-dimensional D-brane system that
consists of single D6-brane bound to lower-dimensional branes. This system is
described by a topologically twisted U(1) gauge theory, that has been
conjecturally identified with quantum foam models and topological strings. This
also explains, assuming the identification of Donaldson-Thomas invariants with
this U(1) gauge theory, the conjectural relation between DT invariants and
topological strings. Our results provide further mathematical evidence for the
recently found connection between 4d and 5d black holes.
