Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contracts/solidity/precompiles/gov/IGov.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,15 @@ interface IGov {
/// @dev getConstitution returns the current constitution.
/// @return constitution The current constitution
function getConstitution() external view returns (string memory constitution);

/// @dev getAuthority returns the governance module account address.
/// This address must be used as the `authority` field in parameter-change
/// and software-upgrade proposal messages.
/// @return authorityBech32 The governance module account address in Bech32 format
/// @return authorityHex The governance module account address as an EVM address
function getAuthority()
external
view
returns (string memory authorityBech32, address authorityHex);
}

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ contract GovCaller {
return gov.GOV_CONTRACT.getParams();
}

function getAuthority()
external
view
returns (string memory authorityBech32, address authorityHex)
{
return gov.GOV_CONTRACT.getAuthority();
}

function testDepositWithTransfer(
uint64 _proposalId,
types.Coin[] calldata _deposit,
Expand Down
10 changes: 10 additions & 0 deletions precompiles/gov/IGov.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,15 @@ interface IGov {
/// @dev getConstitution returns the current constitution.
/// @return constitution The current constitution
function getConstitution() external view returns (string memory constitution);

/// @dev getAuthority returns the governance module account address.
/// This address must be used as the `authority` field in parameter-change
/// and software-upgrade proposal messages.
/// @return authorityBech32 The governance module account address in Bech32 format
/// @return authorityHex The governance module account address as an EVM address
function getAuthority()
external
view
returns (string memory authorityBech32, address authorityHex);
}

18 changes: 18 additions & 0 deletions precompiles/gov/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1103,5 +1103,23 @@
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getAuthority",
"outputs": [
{
"internalType": "string",
"name": "authorityBech32",
"type": "string"
},
{
"internalType": "address",
"name": "authorityHex",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]
2 changes: 2 additions & 0 deletions precompiles/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func (p Precompile) Execute(ctx sdk.Context, stateDB vm.StateDB, contract *vm.Co
bz, err = p.GetParams(ctx, method, contract, args)
case GetConstitutionMethod:
bz, err = p.GetConstitution(ctx, method, contract, args)
case GetAuthorityMethod:
bz, err = p.GetAuthority(ctx, method, contract, args)
default:
return nil, fmt.Errorf(cmn.ErrUnknownMethod, method.Name)
}
Expand Down
37 changes: 37 additions & 0 deletions precompiles/gov/query.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package gov

import (
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"

cmn "github.com/cosmos/evm/precompiles/common"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

const (
Expand All @@ -26,6 +33,8 @@ const (
GetParamsMethod = "getParams"
// GetConstitutionMethod defines the method name for the get constitution precompile request.
GetConstitutionMethod = "getConstitution"
// GetAuthorityMethod defines the method name for the get authority precompile request.
GetAuthorityMethod = "getAuthority"
)

// GetVotes implements the query logic for getting votes for a proposal.
Expand Down Expand Up @@ -233,3 +242,31 @@ func (p *Precompile) GetConstitution(

return method.Outputs.Pack(res.Constitution)
}

// GetAuthority returns the governance module account address in both
// Bech32 and EVM hex formats. This address must be used as the `authority`
// field in parameter-change and software-upgrade proposal messages.
func (p *Precompile) GetAuthority(
ctx sdk.Context,
method *abi.Method,
_ *vm.Contract,
args []interface{},
) ([]byte, error) {
if len(args) != 0 {
return nil, fmt.Errorf(cmn.ErrInvalidNumberOfArgs, 0, len(args))
}

// Derive the governance module account address.
moduleAddr := authtypes.NewModuleAddress(govtypes.ModuleName)

// Convert to Bech32 string using the chain's account prefix.
authorityBech32, err := p.addrCdc.BytesToString(moduleAddr.Bytes())
if err != nil {
return nil, fmt.Errorf("failed to encode authority address: %w", err)
}

// Convert to EVM hex address.
authorityHex := common.BytesToAddress(moduleAddr.Bytes())

return method.Outputs.Pack(authorityBech32, authorityHex)
}
Loading