GHSA-mjfq-3qr2-6g84
Cosmos EVM Allows Partial Precompile State Writes
GHSA-mjfq-3qr2-6g84 is a high vulnerability (CVSS 8.3) in github.com/cosmos/evm, published May 14, 2025. No source lists public exploit code. No source names a fixed version.
- Severity
- 8.3 HighCVSS 4.0, GitHub Advisories
- Exploit chance
- UnscoredNo EPSS score yet
- Exploitation
- None knownNot on CISA’s or ENISA’s lists
- Fixed in
- No fix listedNo source names one
Description
Impact
Setting lower EVM call gas allows users to partially execute precompiles and error at specific points in the precompile code without reverting the partially written state.
If executed on the distribution precompile when claiming funds, it could cause funds to be transferred to a user without resetting the claimable rewards to 0. The vulnerability could also be used to cause indeterministic execution by failing at other points in the code, halting validators.
Any evmOS or Cosmos EVM chain using precompiles is affected.
Patches
The vulnerability was patched by wrapping each precompile execution into an atomic function that reverts any partially committed state on error.
For chains using a different file structure, you must manually apply the diff:
In x/evm/statedb.go:
Add the following function:
func (s *StateDB) RevertMultiStore(cms storetypes.CacheMultiStore, events sdk.Events) {
s.cacheCtx = s.cacheCtx.WithMultiStore(cms)
s.writeCache = func() {
// rollback the events to the ones
// on the snapshot
s.ctx.EventManager().EmitEvents(events)
cms.Write()
}
}
In x/evm/statedb/journal.go:
Replace the Revert function with the following:
func (pc precompileCallChange) Revert(s *StateDB) {
// rollback multi store from cache ctx to the previous
// state stored in the snapshot
s.RevertMultiStore(pc.multiStore, pc.events)
}
In precompiles/common/precompile.go:
Change the function signature in HandleGasError to:
func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas storetypes.Gas, err *error, stateDB *statedb.StateDB, snapshot snapshot) func() {
...
}
In the HandleGasError function, add the following line in the switch statement in the case storetypes.ErrorOutOfGas: case:
stateDB.RevertMultiStore(snapshot.MultiStore, snapshot.Events)
Add the following function:
// RunAtomic is used within the Run function of each Precompile implementation.
// It handles rolling back to the provided snapshot if an error is returned from the core precompile logic.
// Note: This is only required for stateful precompiles.
func (p Precompile) RunAtomic(s snapshot, stateDB *statedb.StateDB, fn func() ([]byte, error)) ([]byte, error) {
bz, err := fn()
if err != nil {
// revert to snapshot on error
stateDB.RevertMultiStore(s.MultiStore, s.Events)
}
return bz, err
}
All Precompiles:
Finally, in each precompile, locate the Run function, and wrap each switch statement and return values into p.RunAtomic. For example:
// Run executes the precompiled contract IBC transfer methods defined in the ABI.
func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error) {
ctx, stateDB, snapshot, method, initialGas, args, err := p.RunSetup(evm, contract, readOnly, p.IsTransaction)
if err != nil {
return nil, err
}
// This handles any out of gas errors that may occur during the execution of a precompile tx or query.
// It avoids panics and returns the out of gas error so the EVM can continue gracefully.
defer cmn.HandleGasError(ctx, contract, initialGas, &err, stateDB, snapshot)()
// === WRAP HERE ===
return p.RunAtomic(snapshot, stateDB, func() ([]byte, error) {
switch method.Name {
// TODO Approval transactions => need cosmos-sdk v0.46 & ibc-go v6.2.0
// Authorization Methods:
case exampleCase:
bz, err = p.example(ctx, evm.Origin, stateDB, method, args)
default:
return nil, fmt.Errorf(cmn.ErrUnknownMethod, method.Name)
}
if err != nil {
return nil, err
}
cost := ctx.GasMeter().GasConsumed() - initialGas
if !contract.UseGas(cost) {
return nil, vm.ErrOutOfGas
}
if err := p.AddJournalEntries(stateDB, snapshot); err != nil {
return nil, err
}
return bz, nil
})
}
Workarounds
There are no workarounds for chains that make use of precompiles. A coordinated upgrade is necessary to patch the issue.
Testing
A test was introduced in the distribution precompile to ensure that partial state writes no longer occur when a lower gas amount is set.
Attack profile
How easy it is to exploit
- Attack vector
- Network
- Complexity
- Low
- Privileges needed
- None
- User interaction
- None
What an attacker can affect
- Confidentiality
- None
- Integrity
- High
- Availability
- Low
Affected packages
| Package | Affected | Fixed |
|---|---|---|
github.com/cosmos/evmGo | 0.1.0 to 0.1.0 | None known |
github.com/cosmos/evmGo | Listed versions 0.1.0 | None known |
github.com/cosmos/evmGo | All versions | None known |
What each source reports
GitHub Advisories Score used 8.3
Cosmos EVM Allows Partial Precompile State Writes
Impact
Setting lower EVM call gas allows users to partially execute precompiles and error at specific points in the precompile code without reverting the partially written state.
If executed on the distribution precompile when claiming funds, it could cause funds to be transferred to a user without resetting the claimable rewards to 0. The vulnerability could also be used to cause indeterministic execution by failing at other points in the code, halting validators.
Any evmOS or Cosmos EVM chain using precompiles is affected.
Patches
The vulnerability was patched by wrapping each precompile execution into an atomic function that reverts any partially committed state on error.
For chains using a different file structure, you must manually apply the diff:
In x/evm/statedb.go:
Add the following function:
func (s *StateDB) RevertMultiStore(cms storetypes.CacheMultiStore, events sdk.Events) {
s.cacheCtx = s.cacheCtx.WithMultiStore(cms)
s.writeCache = func() {
// rollback the events to the ones
// on the snapshot
s.ctx.EventManager().EmitEvents(events)
cms.Write()
}
}
In x/evm/statedb/journal.go:
Replace the Revert function with the following:
func (pc precompileCallChange) Revert(s *StateDB) {
// rollback multi store from cache ctx to the previous
// state stored in the snapshot
s.RevertMultiStore(pc.multiStore, pc.events)
}
In precompiles/common/precompile.go:
Change the function signature in HandleGasError to:
func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas storetypes.Gas, err *error, stateDB *statedb.StateDB, snapshot snapshot) func() {
...
}
In the HandleGasError function, add the following line in the switch statement in the case storetypes.ErrorOutOfGas: case:
stateDB.RevertMultiStore(snapshot.MultiStore, snapshot.Events)
Add the following function:
// RunAtomic is used within the Run function of each Precompile implementation.
// It handles rolling back to the provided snapshot if an error is returned from the core precompile logic.
// Note: This is only required for stateful precompiles.
func (p Precompile) RunAtomic(s snapshot, stateDB *statedb.StateDB, fn func() ([]byte, error)) ([]byte, error) {
bz, err := fn()
if err != nil {
// revert to snapshot on error
stateDB.RevertMultiStore(s.MultiStore, s.Events)
}
return bz, err
}
All Precompiles:
Finally, in each precompile, locate the Run function, and wrap each switch statement and return values into p.RunAtomic. For example:
// Run executes the precompiled contract IBC transfer methods defined in the ABI.
func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error) {
ctx, stateDB, snapshot, method, initialGas, args, err := p.RunSetup(evm, contract, readOnly, p.IsTransaction)
if err != nil {
return nil, err
}
// This handles any out of gas errors that may occur during the execution of a precompile tx or query.
// It avoids panics and returns the out of gas error so the EVM can continue gracefully.
defer cmn.HandleGasError(ctx, contract, initialGas, &err, stateDB, snapshot)()
// === WRAP HERE ===
return p.RunAtomic(snapshot, stateDB, func() ([]byte, error) {
switch method.Name {
// TODO Approval transactions => need cosmos-sdk v0.46 & ibc-go v6.2.0
// Authorization Methods:
case exampleCase:
bz, err = p.example(ctx, evm.Origin, stateDB, method, args)
default:
return nil, fmt.Errorf(cmn.ErrUnknownMethod, method.Name)
}
if err != nil {
return nil, err
}
cost := ctx.GasMeter().GasConsumed() - initialGas
if !contract.UseGas(cost) {
return nil, vm.ErrOutOfGas
}
if err := p.AddJournalEntries(stateDB, snapshot); err != nil {
return nil, err
}
return bz, nil
})
}
Workarounds
There…
- Record
GHSA-mjfq-3qr2-6g84- CVSS 4.0
- 8.3 High
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:H/VA:L/SC:N/SI:N/SA:N - Weakness
- CWE-94
- Updated
- 2026-11-02
OSV 8.3
Cosmos EVM Allows Partial Precompile State Writes
Impact
Setting lower EVM call gas allows users to partially execute precompiles and error at specific points in the precompile code without reverting the partially written state.
If executed on the distribution precompile when claiming funds, it could cause funds to be transferred to a user without resetting the claimable rewards to 0. The vulnerability could also be used to cause indeterministic execution by failing at other points in the code, halting validators.
Any evmOS or Cosmos EVM chain using precompiles is affected.
Patches
The vulnerability was patched by wrapping each precompile execution into an atomic function that reverts any partially committed state on error.
For chains using a different file structure, you must manually apply the diff:
In x/evm/statedb.go:
Add the following function:
func (s *StateDB) RevertMultiStore(cms storetypes.CacheMultiStore, events sdk.Events) {
s.cacheCtx = s.cacheCtx.WithMultiStore(cms)
s.writeCache = func() {
// rollback the events to the ones
// on the snapshot
s.ctx.EventManager().EmitEvents(events)
cms.Write()
}
}
In x/evm/statedb/journal.go:
Replace the Revert function with the following:
func (pc precompileCallChange) Revert(s *StateDB) {
// rollback multi store from cache ctx to the previous
// state stored in the snapshot
s.RevertMultiStore(pc.multiStore, pc.events)
}
In precompiles/common/precompile.go:
Change the function signature in HandleGasError to:
func HandleGasError(ctx sdk.Context, contract *vm.Contract, initialGas storetypes.Gas, err *error, stateDB *statedb.StateDB, snapshot snapshot) func() {
...
}
In the HandleGasError function, add the following line in the switch statement in the case storetypes.ErrorOutOfGas: case:
stateDB.RevertMultiStore(snapshot.MultiStore, snapshot.Events)
Add the following function:
// RunAtomic is used within the Run function of each Precompile implementation.
// It handles rolling back to the provided snapshot if an error is returned from the core precompile logic.
// Note: This is only required for stateful precompiles.
func (p Precompile) RunAtomic(s snapshot, stateDB *statedb.StateDB, fn func() ([]byte, error)) ([]byte, error) {
bz, err := fn()
if err != nil {
// revert to snapshot on error
stateDB.RevertMultiStore(s.MultiStore, s.Events)
}
return bz, err
}
All Precompiles:
Finally, in each precompile, locate the Run function, and wrap each switch statement and return values into p.RunAtomic. For example:
// Run executes the precompiled contract IBC transfer methods defined in the ABI.
func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error) {
ctx, stateDB, snapshot, method, initialGas, args, err := p.RunSetup(evm, contract, readOnly, p.IsTransaction)
if err != nil {
return nil, err
}
// This handles any out of gas errors that may occur during the execution of a precompile tx or query.
// It avoids panics and returns the out of gas error so the EVM can continue gracefully.
defer cmn.HandleGasError(ctx, contract, initialGas, &err, stateDB, snapshot)()
// === WRAP HERE ===
return p.RunAtomic(snapshot, stateDB, func() ([]byte, error) {
switch method.Name {
// TODO Approval transactions => need cosmos-sdk v0.46 & ibc-go v6.2.0
// Authorization Methods:
case exampleCase:
bz, err = p.example(ctx, evm.Origin, stateDB, method, args)
default:
return nil, fmt.Errorf(cmn.ErrUnknownMethod, method.Name)
}
if err != nil {
return nil, err
}
cost := ctx.GasMeter().GasConsumed() - initialGas
if !contract.UseGas(cost) {
return nil, vm.ErrOutOfGas
}
if err := p.AddJournalEntries(stateDB, snapshot); err != nil {
return nil, err
}
return bz, nil
})
}
Workarounds
There…
- Record
GHSA-mjfq-3qr2-6g84- CVSS 4.0
- 8.3 High
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:H/VA:L/SC:N/SI:N/SA:N - Weakness
- CWE-94
- Updated
- 2026-11-02
OSVGO-2025-3684No score
Cosmos EVM Allows Partial Precompile State Writes in github.com/cosmos/evm
Cosmos EVM Allows Partial Precompile State Writes in github.com/cosmos/evm
- Record
GO-2025-3684- Updated
- 2026-11-02
History
| Recorded | Changed | Sources |
|---|---|---|
| first indexed | GitHub Advisories, OSV |
Dates are when Every CVE recorded each change. Upstream dates may differ.
References
Left out here: the rest of 2 source descriptions. The JSON record has them.