Skip to content

Commit

Permalink
chore: change whitelisted caller type from address to bytes (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
npty authored Aug 14, 2023
1 parent 152ace9 commit e031b47
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
12 changes: 6 additions & 6 deletions contracts/InterchainProposalExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { InterchainCalls } from './lib/InterchainCalls.sol';
*/
contract InterchainProposalExecutor is IInterchainProposalExecutor, AxelarExecutable, Ownable {
// Whitelisted proposal callers. The proposal caller is the contract that calls the `InterchainProposalSender` at the source chain.
mapping(string => mapping(address => bool)) public whitelistedCallers;
mapping(string => mapping(bytes => bool)) public whitelistedCallers;

// Whitelisted proposal senders. The proposal sender is the `InterchainProposalSender` contract address at the source chain.
mapping(string => mapping(string => bool)) public whitelistedSenders;
Expand Down Expand Up @@ -50,9 +50,9 @@ contract InterchainProposalExecutor is IInterchainProposalExecutor, AxelarExecut
}

// Decode the payload
(address sourceCaller, InterchainCalls.Call[] memory calls) = abi.decode(
(bytes memory sourceCaller, InterchainCalls.Call[] memory calls) = abi.decode(
payload,
(address, InterchainCalls.Call[])
(bytes, InterchainCalls.Call[])
);

// Check that the caller is whitelisted
Expand Down Expand Up @@ -97,7 +97,7 @@ contract InterchainProposalExecutor is IInterchainProposalExecutor, AxelarExecut
*/
function setWhitelistedProposalCaller(
string calldata sourceChain,
address sourceCaller,
bytes memory sourceCaller,
bool whitelisted
) external override onlyOwner {
whitelistedCallers[sourceChain][sourceCaller] = whitelisted;
Expand Down Expand Up @@ -135,7 +135,7 @@ contract InterchainProposalExecutor is IInterchainProposalExecutor, AxelarExecut
function _beforeProposalExecuted(
string calldata sourceChain,
string calldata sourceAddress,
address caller,
bytes memory caller,
InterchainCalls.Call[] memory calls
) internal virtual {
// You can add your own logic here to handle the payload before the proposal is executed.
Expand All @@ -152,7 +152,7 @@ contract InterchainProposalExecutor is IInterchainProposalExecutor, AxelarExecut
function _onProposalExecuted(
string calldata /* sourceChain */,
string calldata /* sourceAddress */,
address /* caller */,
bytes memory /* caller */,
bytes calldata payload
) internal virtual {
// You can add your own logic here to handle the payload after the proposal is executed.
Expand Down
2 changes: 1 addition & 1 deletion contracts/InterchainProposalSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract InterchainProposalSender is IInterchainProposalSender {
}

function _sendProposal(InterchainCalls.InterchainCall memory interchainCall) internal {
bytes memory payload = abi.encode(msg.sender, interchainCall.calls);
bytes memory payload = abi.encode(abi.encodePacked(msg.sender), interchainCall.calls);

if (interchainCall.gas > 0) {
gasService.payNativeGasForContractCall{ value: interchainCall.gas }(
Expand Down
8 changes: 6 additions & 2 deletions contracts/interfaces/IInterchainProposalExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;

interface IInterchainProposalExecutor {
// An event emitted when the proposal caller is whitelisted
event WhitelistedProposalCallerSet(string indexed sourceChain, address indexed sourceCaller, bool whitelisted);
event WhitelistedProposalCallerSet(string indexed sourceChain, bytes indexed sourceCaller, bool whitelisted);

// An event emitted when the proposal sender is whitelisted
event WhitelistedProposalSenderSet(string indexed sourceChain, string sourceSender, bool whitelisted);
Expand Down Expand Up @@ -39,5 +39,9 @@ interface IInterchainProposalExecutor {
* @param sourceCaller The source interchain caller address
* @param whitelisted The whitelisted status
*/
function setWhitelistedProposalCaller(string calldata sourceChain, address sourceCaller, bool whitelisted) external;
function setWhitelistedProposalCaller(
string calldata sourceChain,
bytes memory sourceCaller,
bool whitelisted
) external;
}
2 changes: 1 addition & 1 deletion test/e2e/e2e-multi-dest-chains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('Interchain Governance Executor for Multiple Destination Chains [ @skip
// Wait for the proposal to be executed on the destination chain
// Encode the payload for the destination chain
const payload = ethers.utils.defaultAbiCoder.encode(
['address', '(address target, uint256 value, bytes callData)[]'],
['bytes', '(address target, uint256 value, bytes callData)[]'],
[timelock.address, xCalls[0].calls],
);

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/e2e-single-dest-chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Interchain Governance Executor For Single Destination Chain [ @skip-on
// Wait for the proposal to be executed on the destination chain
// Encode the payload for the destination chain
const payload = ethers.utils.defaultAbiCoder.encode(
['address', '(address target, uint256 value, bytes callData)[]'],
['bytes', '(address target, uint256 value, bytes callData)[]'],
[timelock.address, calls],
);

Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Interchain Governance Executor For Single Destination Chain [ @skip-on

// Wait for the proposal to be executed on the destination chain
const payload = ethers.utils.defaultAbiCoder.encode(
['address', '(address target, uint256 value, bytes callData)[]'],
['bytes', '(address target, uint256 value, bytes callData)[]'],
[timelock.address, calls],
);
await waitProposalExecuted(
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('Interchain Governance Executor For Single Destination Chain [ @skip-on
// Wait for the proposal to be executed on the destination chain
// Encode the payload for the destination chain
const payload = ethers.utils.defaultAbiCoder.encode(
['address', '(address target, uint256 value, bytes callData)[]'],
['bytes', '(address target, uint256 value, bytes callData)[]'],
[timelock.address, calls],
);

Expand Down Expand Up @@ -386,7 +386,7 @@ describe('Interchain Governance Executor For Single Destination Chain [ @skip-on

// Wait for the proposal to be executed on the destination chain
const payload = ethers.utils.defaultAbiCoder.encode(
['address', '(address target, uint256 value, bytes callData)[]'],
['bytes', '(address target, uint256 value, bytes callData)[]'],
[deployer.address, calls],
);
await waitProposalExecuted(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/utils/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const waitProposalExecuted = (
executorContract.filters.ProposalExecuted(
ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
['string', 'string', 'address', 'bytes'],
['string', 'string', 'bytes', 'bytes'],
[sourceChain, sourceAddress, caller, payload],
),
),
Expand Down
11 changes: 6 additions & 5 deletions test/unit/interchain-proposal-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('InterchainProposalExecutor', function () {
signerAddress,
true,
);

await executor.setWhitelistedProposalSender(
chains.ethereum,
signerAddress,
Expand All @@ -81,7 +82,7 @@ describe('InterchainProposalExecutor', function () {
];

const payload = ethers.utils.defaultAbiCoder.encode(
['address', 'tuple(address target, uint256 value, bytes callData)[]'],
['bytes', 'tuple(address target, uint256 value, bytes callData)[]'],
[signerAddress, calls],
);

Expand All @@ -93,7 +94,7 @@ describe('InterchainProposalExecutor', function () {
.withArgs(
ethers.utils.keccak256(
ethers.utils.defaultAbiCoder.encode(
['string', 'string', 'address', 'bytes'],
['string', 'string', 'bytes', 'bytes'],
[chains.ethereum, signerAddress, signerAddress, payload],
),
),
Expand Down Expand Up @@ -131,7 +132,7 @@ describe('InterchainProposalExecutor', function () {
];

const payload = ethers.utils.defaultAbiCoder.encode(
['address', 'tuple(address target, uint256 value, bytes callData)[]'],
['bytes', 'tuple(address target, uint256 value, bytes callData)[]'],
[signerAddress, calls],
);

Expand Down Expand Up @@ -161,7 +162,7 @@ describe('InterchainProposalExecutor', function () {
];

const payload = ethers.utils.defaultAbiCoder.encode(
['address', 'tuple(address target, uint256 value, bytes callData)[]'],
['bytes', 'tuple(address target, uint256 value, bytes callData)[]'],
[signerAddress, calls],
);

Expand Down Expand Up @@ -194,7 +195,7 @@ describe('InterchainProposalExecutor', function () {
];

const payload = ethers.utils.defaultAbiCoder.encode(
['address', 'tuple(address target, uint256 value, bytes callData)[]'],
['bytes', 'tuple(address target, uint256 value, bytes callData)[]'],
[signerAddress, calls],
);

Expand Down
4 changes: 2 additions & 2 deletions test/unit/interchain-proposal-sender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('InterchainProposalSender', function () {
);

const payload = ethers.utils.defaultAbiCoder.encode(
['address', 'tuple(address target, uint256 value, bytes callData)[]'],
['bytes', 'tuple(address target, uint256 value, bytes callData)[]'],
[signerAddress, calls],
);

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('InterchainProposalSender', function () {
const broadcast = () => sender.sendProposals(xCalls, { value: 2 });

const payload = ethers.utils.defaultAbiCoder.encode(
['address', 'tuple(address target, uint256 value, bytes callData)[]'],
['bytes', 'tuple(address target, uint256 value, bytes callData)[]'],
[signerAddress, calls],
);

Expand Down

0 comments on commit e031b47

Please sign in to comment.