11package gov
22
33import (
4+ "fmt"
5+
46 "github.com/ethereum/go-ethereum/accounts/abi"
7+ "github.com/ethereum/go-ethereum/common"
58 "github.com/ethereum/go-ethereum/core/vm"
69
10+ cmn "github.com/cosmos/evm/precompiles/common"
11+
712 sdk "github.com/cosmos/cosmos-sdk/types"
13+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
14+ govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
815)
916
1017const (
@@ -26,6 +33,8 @@ const (
2633 GetParamsMethod = "getParams"
2734 // GetConstitutionMethod defines the method name for the get constitution precompile request.
2835 GetConstitutionMethod = "getConstitution"
36+ // GetAuthorityMethod defines the method name for the get authority precompile request.
37+ GetAuthorityMethod = "getAuthority"
2938)
3039
3140// GetVotes implements the query logic for getting votes for a proposal.
@@ -233,3 +242,31 @@ func (p *Precompile) GetConstitution(
233242
234243 return method .Outputs .Pack (res .Constitution )
235244}
245+
246+ // GetAuthority returns the governance module account address in both
247+ // Bech32 and EVM hex formats. This address must be used as the `authority`
248+ // field in parameter-change and software-upgrade proposal messages.
249+ func (p * Precompile ) GetAuthority (
250+ ctx sdk.Context ,
251+ method * abi.Method ,
252+ _ * vm.Contract ,
253+ args []interface {},
254+ ) ([]byte , error ) {
255+ if len (args ) != 0 {
256+ return nil , fmt .Errorf (cmn .ErrInvalidNumberOfArgs , 0 , len (args ))
257+ }
258+
259+ // Derive the governance module account address.
260+ moduleAddr := authtypes .NewModuleAddress (govtypes .ModuleName )
261+
262+ // Convert to Bech32 string using the chain's account prefix.
263+ authorityBech32 , err := p .addrCdc .BytesToString (moduleAddr .Bytes ())
264+ if err != nil {
265+ return nil , fmt .Errorf ("failed to encode authority address: %w" , err )
266+ }
267+
268+ // Convert to EVM hex address.
269+ authorityHex := common .BytesToAddress (moduleAddr .Bytes ())
270+
271+ return method .Outputs .Pack (authorityBech32 , authorityHex )
272+ }
0 commit comments