[proofplan]
Given two connections $d_A, d_B$ on $E$, we interpolate linearly between them via $d_t := t\, d_A + (1-t)\, d_B$ and examine how $\mathrm{tr}(F_t^m)$ varies with $t$. The difference $L := d_A - d_B$ is $C^\infty$-linear (a bundle endomorphism-valued $1$-form), and differentiating the curvature yields $\partial_t F_t = d_t L$. Using the Second Bianchi identity $d_t F_t = 0$ together with the Leibniz rule and the identity $d \circ \mathrm{tr} = \mathrm{tr} \circ d_t$, the integrand rewrites as a total exterior derivative. Integrating from $t = 0$ to $t = 1$ expresses $\mathrm{tr}(F_A^m) - \mathrm{tr}(F_B^m)$ as the exterior derivative of a global form, showing the cohomology class is independent of the connection.
[/proofplan]
[step:Construct the affine family of connections interpolating $A$ and $B$]
Let $d_A, d_B: \Gamma(E) \to \Omega^1(M; E)$ be two connections on $E$. Define the difference
\begin{align*}
L: \Gamma(E) &\to \Omega^1(M; E) \\
s &\mapsto d_A s - d_B s.
\end{align*}
A standard computation shows $L(fs) = f\, L(s)$ for every $f \in C^\infty(M)$: both $d_A$ and $d_B$ satisfy the Leibniz rule, so the $df \otimes s$ terms cancel. Hence $L \in \Omega^1(M; \mathrm{End}(E))$ is a tensorial $1$-form with values in endomorphisms.
For each $t \in [0,1]$ set
\begin{align*}
d_t: \Gamma(E) &\to \Omega^1(M; E) \\
s &\mapsto t\, d_A s + (1-t)\, d_B s = d_B s + t\, L(s).
\end{align*}
Since the space of connections on $E$ is an affine space modelled on $\Omega^1(M; \mathrm{End}(E))$, $d_t$ is a connection for every $t \in \mathbb{R}$. Its curvature $F_t \in \Omega^2(M; \mathrm{End}(E))$ is defined by $F_t = d_t \circ d_t$ (extended to $E$-valued forms in the usual way), with $F_0 = F_B$ and $F_1 = F_A$.
[guided]
Let $d_A, d_B: \Gamma(E) \to \Omega^1(M; E)$ be two connections on $E$. A key structural fact we will exploit is that the space of connections on a fixed bundle is an **affine space**: any convex combination of connections is again a connection, and the difference of two connections is a $C^\infty$-linear object. Let us verify this carefully. Define
\begin{align*}
L: \Gamma(E) &\to \Omega^1(M; E) \\
s &\mapsto d_A s - d_B s.
\end{align*}
Why is $L$ tensorial, and not merely $\mathbb{R}$-linear? For $f \in C^\infty(M)$ and $s \in \Gamma(E)$, both $d_A$ and $d_B$ satisfy the Leibniz rule:
\begin{align*}
d_A(fs) - d_B(fs) = (df \otimes s + f\, d_A s) - (df \otimes s + f\, d_B s) = f(d_A s - d_B s) = f\, L(s).
\end{align*}
The "inhomogeneous" $df \otimes s$ terms cancel exactly because they are the same for both connections. Hence $L$ is $C^\infty(M)$-linear, which means $L$ is a global section of $T^*M \otimes \mathrm{End}(E)$, i.e. $L \in \Omega^1(M; \mathrm{End}(E))$.
Now we build the family. For each $t \in [0,1]$ define
\begin{align*}
d_t: \Gamma(E) &\to \Omega^1(M; E) \\
s &\mapsto t\, d_A s + (1-t)\, d_B s = d_B s + t\, L(s).
\end{align*}
Is $d_t$ a connection? We check the Leibniz rule: $d_t(fs) = d_B(fs) + t\, L(fs) = df \otimes s + f\, d_B s + tf\, L(s) = df \otimes s + f\, d_t s$. So yes. We have constructed a smooth $1$-parameter family of connections with $d_0 = d_B$ and $d_1 = d_A$. Its curvature $F_t := d_t \circ d_t \in \Omega^2(M; \mathrm{End}(E))$ satisfies $F_0 = F_B$ and $F_1 = F_A$.
[/guided]
[/step]
[step:Compute $\partial_t F_t = d_t L$ via the structure equation]
The curvature of a connection $d = d_B + \alpha$, with $\alpha \in \Omega^1(M; \mathrm{End}(E))$, satisfies the structure equation
\begin{align*}
F_d = F_B + d_B \alpha + \alpha \wedge \alpha,
\end{align*}
where $d_B$ here denotes the induced connection on $\Omega^\bullet(M; \mathrm{End}(E))$. Applying this with $\alpha = tL$:
\begin{align*}
F_t = F_B + t\, d_B L + t^2 (L \wedge L).
\end{align*}
Differentiating in $t$:
\begin{align*}
\frac{\partial F_t}{\partial t} = d_B L + 2t (L \wedge L) = d_B L + t\, [L, L]_\wedge,
\end{align*}
where we used that for $L \in \Omega^1(M; \mathrm{End}(E))$ one has $2(L \wedge L) = [L, L]_\wedge$ in the graded-commutator sense. On the other hand, for any $M \in \Omega^k(M; \mathrm{End}(E))$ the induced connection $d_t$ acts as $d_t M = d_B M + t\, [L, M]_\wedge$. Applied to $M = L$:
\begin{align*}
d_t L = d_B L + t\, [L, L]_\wedge = \frac{\partial F_t}{\partial t}.
\end{align*}
[guided]
We want to understand how $F_t$ changes with $t$. The cleanest way is via the structure equation: if $d = d_B + \alpha$ is any connection differing from $d_B$ by $\alpha \in \Omega^1(M; \mathrm{End}(E))$, then a direct computation (expand $d \circ d$ and use $d_B \circ d_B = F_B$) gives
\begin{align*}
F_d = F_B + d_B \alpha + \alpha \wedge \alpha,
\end{align*}
where $d_B$ on the right-hand side is the induced connection on $\mathrm{End}(E)$-valued forms and $\alpha \wedge \alpha$ is the wedge-composition product (wedge of forms, composition of endomorphisms). Applying this to $\alpha = tL$, so that $d_t = d_B + tL$, we read off
\begin{align*}
F_t = F_B + t\, d_B L + t^2 (L \wedge L).
\end{align*}
This is a polynomial in $t$ with coefficients in $\Omega^2(M; \mathrm{End}(E))$. Differentiating:
\begin{align*}
\frac{\partial F_t}{\partial t} = d_B L + 2t (L \wedge L).
\end{align*}
Now we recognize $2(L \wedge L)$ as the graded commutator $[L, L]_\wedge$: for $L$ of form-degree $1$, the Koszul sign is $(-1)^{1 \cdot 1} = -1$, so $[L, L]_\wedge = L \wedge L - (-1) L \wedge L = 2 L \wedge L$.
The key observation: for **any** $M \in \Omega^k(M; \mathrm{End}(E))$, the connection $d_t$ acts on $\mathrm{End}(E)$-valued forms by $d_t M = d_B M + t\, [L, M]_\wedge$ — the tensorial part twists by the commutator. Applied to $M = L$:
\begin{align*}
d_t L = d_B L + t\, [L, L]_\wedge = d_B L + 2t\, (L \wedge L) = \frac{\partial F_t}{\partial t}.
\end{align*}
This compact identity $\partial_t F_t = d_t L$ is the analytic engine of the whole proof.
[/guided]
[/step]
[step:Differentiate $\mathrm{tr}(F_t^m)$ and pull the trace through]
The form $\mathrm{tr}(F_t^m) \in \Omega^{2m}(M)$ depends smoothly on $t$. Differentiating and using the cyclic invariance of the trace (which applies since $F_t$ is an $\mathrm{End}(E)$-valued form of even form-degree, so factors commute under the trace without sign):
\begin{align*}
\frac{\partial}{\partial t} \mathrm{tr}(F_t^m) = \mathrm{tr}\!\left( \sum_{k=0}^{m-1} F_t^k \cdot \frac{\partial F_t}{\partial t} \cdot F_t^{m-1-k} \right) = m\, \mathrm{tr}\!\left( F_t^{m-1} \cdot \frac{\partial F_t}{\partial t} \right).
\end{align*}
Substituting $\partial_t F_t = d_t L$ from the previous step:
\begin{align*}
\frac{\partial}{\partial t} \mathrm{tr}(F_t^m) = m\, \mathrm{tr}\!\left( F_t^{m-1} \cdot d_t L \right).
\end{align*}
[/step]
[step:Apply the Second Bianchi identity and the Leibniz rule to express the integrand as $d_t$ of a form]
The Second Bianchi identity for the connection $d_t$ states $d_t F_t = 0$ in $\Omega^3(M; \mathrm{End}(E))$. Since $d_t$ is a derivation on $\Omega^\bullet(M; \mathrm{End}(E))$, iterating gives $d_t(F_t^{m-1}) = 0$ by the graded Leibniz rule (each factor contributes a $d_t F_t = 0$ term). Therefore, again by the graded Leibniz rule applied to the product $L \cdot F_t^{m-1}$:
\begin{align*}
d_t(L \cdot F_t^{m-1}) = (d_t L) \cdot F_t^{m-1} + (-1)^1 L \cdot d_t(F_t^{m-1}) = (d_t L) \cdot F_t^{m-1}.
\end{align*}
Taking the trace and using cyclic invariance (valid because all factors are even-degree forms except $L$, but the trace cyclicity for $\mathrm{End}(E)$-valued forms respects the total form-degree signs; here the product $(d_t L) F_t^{m-1}$ has the same form-degree as $F_t^{m-1} (d_t L)$, and the cyclic rotation of the odd-degree factor $d_t L$ across the even-degree factor $F_t^{m-1}$ introduces no sign):
\begin{align*}
\mathrm{tr}\!\left( F_t^{m-1} \cdot d_t L \right) = \mathrm{tr}\!\left( (d_t L) \cdot F_t^{m-1} \right) = \mathrm{tr}\!\left( d_t(L \cdot F_t^{m-1}) \right).
\end{align*}
[guided]
The **Second Bianchi identity** says $d_t F_t = 0$ as an $\mathrm{End}(E)$-valued $3$-form, where $d_t$ denotes the connection induced by $d_t$ on $\mathrm{End}(E)$-valued forms. Why is this true? In local frames, $F_t = d\omega_t + \omega_t \wedge \omega_t$ for the connection $1$-form $\omega_t$, and $d_t F_t = dF_t + [\omega_t, F_t]_\wedge$. Direct computation using $d^2 = 0$ and the Jacobi identity yields $d_t F_t = 0$.
Iterating: $d_t$ is a graded derivation on $\Omega^\bullet(M; \mathrm{End}(E))$, so
\begin{align*}
d_t(F_t^{m-1}) = \sum_{k=0}^{m-2} (-1)^{2k} F_t^k (d_t F_t) F_t^{m-2-k} = 0,
\end{align*}
every term vanishing by Bianchi.
Now apply the graded Leibniz rule to the product $L \cdot F_t^{m-1}$, where $L$ has form-degree $1$:
\begin{align*}
d_t(L \cdot F_t^{m-1}) = (d_t L) \cdot F_t^{m-1} + (-1)^1 L \cdot d_t(F_t^{m-1}) = (d_t L) \cdot F_t^{m-1} - 0.
\end{align*}
We want the integrand $\mathrm{tr}(F_t^{m-1} \cdot d_t L)$ to match $\mathrm{tr}(d_t(L \cdot F_t^{m-1})) = \mathrm{tr}((d_t L) \cdot F_t^{m-1})$. This requires cyclic invariance of the trace. For matrix-valued forms $\alpha \in \Omega^a$, $\beta \in \Omega^b$ one has $\mathrm{tr}(\alpha \beta) = (-1)^{ab} \mathrm{tr}(\beta \alpha)$. Here $a = 2(m-1)$ is even, so the Koszul sign is $(-1)^{2(m-1) \cdot 1} = 1$:
\begin{align*}
\mathrm{tr}(F_t^{m-1} \cdot d_t L) = \mathrm{tr}((d_t L) \cdot F_t^{m-1}).
\end{align*}
Combining:
\begin{align*}
\mathrm{tr}(F_t^{m-1} \cdot d_t L) = \mathrm{tr}(d_t(L \cdot F_t^{m-1})).
\end{align*}
[/guided]
[/step]
[step:Replace $d_t$ by $d$ under the trace via the invariance identity $d \circ \mathrm{tr} = \mathrm{tr} \circ d_t$]
For any $M \in \Omega^k(M; \mathrm{End}(E))$ one has the compatibility identity
\begin{align*}
d(\mathrm{tr}(M)) = \mathrm{tr}(d_t M),
\end{align*}
where $d$ on the left is the ordinary exterior derivative on $\Omega^\bullet(M)$ and $d_t$ on the right is the induced connection on $\mathrm{End}(E)$-valued forms. This follows because locally $d_t M = dM + [\omega_t, M]_\wedge$, and the trace of the commutator $[\omega_t, M]_\wedge$ vanishes by cyclic invariance. Applying this with $M = L \cdot F_t^{m-1}$:
\begin{align*}
\mathrm{tr}(d_t(L \cdot F_t^{m-1})) = d\, \mathrm{tr}(L \cdot F_t^{m-1}).
\end{align*}
Combining with the previous step and the formula $\partial_t \mathrm{tr}(F_t^m) = m\, \mathrm{tr}(F_t^{m-1} d_t L)$:
\begin{align*}
\frac{\partial}{\partial t} \mathrm{tr}(F_t^m) = m\, d\, \mathrm{tr}(L \cdot F_t^{m-1}).
\end{align*}
[/step]
[step:Integrate from $0$ to $1$ to exhibit $\mathrm{tr}(F_A^m) - \mathrm{tr}(F_B^m)$ as exact]
The form $\mathrm{tr}(F_t^m) \in \Omega^{2m}(M)$ depends smoothly on $t \in [0,1]$, and by the previous step its $t$-derivative is $d$ of a smooth $t$-dependent form. By the Fundamental Theorem of Calculus applied pointwise and interchange of $d$ with the $t$-integral (justified by smoothness of the integrand):
\begin{align*}
\mathrm{tr}(F_A^m) - \mathrm{tr}(F_B^m) = \int_0^1 \frac{\partial}{\partial t} \mathrm{tr}(F_t^m) \, d\mathcal{L}^1(t) = m\, d\!\left( \int_0^1 \mathrm{tr}(L \cdot F_t^{m-1}) \, d\mathcal{L}^1(t) \right).
\end{align*}
Define the transgression form
\begin{align*}
\mathrm{TP}(A, B) := m \int_0^1 \mathrm{tr}(L \cdot F_t^{m-1}) \, d\mathcal{L}^1(t) \in \Omega^{2m-1}(M).
\end{align*}
Then
\begin{align*}
\mathrm{tr}(F_A^m) - \mathrm{tr}(F_B^m) = d\, \mathrm{TP}(A, B),
\end{align*}
so $\mathrm{tr}(F_A^m)$ and $\mathrm{tr}(F_B^m)$ differ by an exact form and therefore define the same de Rham cohomology class in $H^{2m}_{dR}(M)$. This completes the proof.
[/step]