Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Delegation through Proxy Pallet #2533

Merged
merged 9 commits into from
Oct 31, 2023
Merged
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
2 changes: 2 additions & 0 deletions runtime/common/src/weights/pallet_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ impl<T: frame_system::Config> pallet_proxy::WeightInfo for WeightInfo<T> {
// Standard Error: 1_006
.saturating_add(Weight::from_parts(45_679, 0).saturating_mul(p.into()))
.saturating_add(T::DbWeight::get().reads(2))
// Manually adding 1 DB read that happen when filtering the proxy call transaction
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(Weight::from_parts(0, 25).saturating_mul(p.into()))
}
/// Storage: Proxy Proxies (r:1 w:0)
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,9 @@ impl Contains<RuntimeCall> for NormalFilter {
RuntimeCall::Proxy(method) => match method {
pallet_proxy::Call::create_pure { .. } => false,
pallet_proxy::Call::kill_pure { .. } => false,
pallet_proxy::Call::proxy { real, .. } => {
!pallet_evm::AccountCodes::<Runtime>::contains_key(H160::from(*real))
}
_ => true,
},
// Filtering the EVM prevents possible re-entrancy from the precompiles which could
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ impl Contains<RuntimeCall> for NormalFilter {
RuntimeCall::Proxy(method) => match method {
pallet_proxy::Call::create_pure { .. } => false,
pallet_proxy::Call::kill_pure { .. } => false,
pallet_proxy::Call::proxy { real, .. } => {
!pallet_evm::AccountCodes::<Runtime>::contains_key(H160::from(*real))
}
_ => true,
},
// Filtering the EVM prevents possible re-entrancy from the precompiles which could
Expand Down
3 changes: 3 additions & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,9 @@ impl Contains<RuntimeCall> for NormalFilter {
RuntimeCall::Proxy(method) => match method {
pallet_proxy::Call::create_pure { .. } => false,
pallet_proxy::Call::kill_pure { .. } => false,
pallet_proxy::Call::proxy { real, .. } => {
!pallet_evm::AccountCodes::<Runtime>::contains_key(H160::from(*real))
}
_ => true,
},
// Filtering the EVM prevents possible re-entrancy from the precompiles which could
Expand Down
2 changes: 2 additions & 0 deletions scripts/benchmarking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function bench {
--output "${OUTPUT}"
}

echo -e "\e[33m**Warning**: The benchmarking script will overwrite the pallet_proxy.rs file in runtime/common/src/weights. This file was manually modified to include an additional DB Read for proxy.proxy. Make sure to add it again after running the benchmarking script.\e[0m"

if [[ "${@}" =~ "--help" ]]; then
help
else
Expand Down
52 changes: 52 additions & 0 deletions test/contracts/src/ProxyForContractsDemo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

interface IProxy{
enum ProxyType {
Any,
NonTransfer,
Governance,
Staking,
CancelProxy,
Balances,
AuthorMapping,
IdentityJudgement
}
function addProxy(
address delegate,
ProxyType proxyType,
uint32 delay
) external;
function isProxy(
address real,
address delegate,
ProxyType proxyType,
uint32 delay
) external view returns (bool exists);
function proxy(
address real,
address callTo,
bytes memory callData
) external payable;
}

contract ProxyForContractsDemo {

address immutable PROXY_ADDRESS = 0x000000000000000000000000000000000000080b;
// for debugging purpose
//
constructor() payable{
// payable because you need some funds to be resereved
// add Alice as delegate for this newly created contract
PROXY_ADDRESS.call(abi.encodeWithSelector(IProxy.addProxy.selector, 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac, IProxy.ProxyType.Any, 0));
}

// shortcut function to check if Alice is a delegate of this contract
function isYouMyProxy() external view returns(bool){
return IProxy(PROXY_ADDRESS).isProxy(address(this), 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac, IProxy.ProxyType.Any, 0);
}

fallback() external payable{}
receive() external payable{}

}
41 changes: 41 additions & 0 deletions test/suites/dev/test-proxy/test-proxy-for-contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import "@moonbeam-network/api-augment";
import { deployCreateCompiledContract, describeSuite, beforeAll, expect } from "@moonwall/cli";
import { ALITH_ADDRESS, GLMR } from "@moonwall/util";
import { alith } from "@moonwall/util";

describeSuite({
id: "D4007",
title: "Proxy Call for Contract",
foundationMethods: "dev",
testCases: ({ context, it, log }) => {
let contractAddress: `0x${string}`;

beforeAll(async () => {
const { contractAddress: deployedAddr } = await deployCreateCompiledContract(
context,
"ProxyForContractsDemo",
{ value: 1000n * GLMR }
);
contractAddress = deployedAddr;
});

it({
id: `T01`,
title: `Proxy Call to Smart Contract account should fail`,
test: async function () {
await expect(
context.createBlock(
context
.polkadotJs()
.tx.proxy.proxy(
contractAddress,
"Any",
context.polkadotJs().tx.balances.transferAll(ALITH_ADDRESS, true)
)
.signAsync(alith)
)
).rejects.toThrow("Invalid Transaction: Transaction call is not expected");
},
});
},
});
Loading