Skip to content

Commit 3dc8f69

Browse files
feat: Add malicious contract interaction as an option (#356)
* feat: Add malicious contract interaction as an option * chore: add data for networks and update button details * chore: exclude base * chore: add base hex address * chore: refactor * chore: address review
1 parent ebc2ebf commit 3dc8f69

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

src/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,13 @@ <h5>Transactions</h5>
857857
>
858858
Malicious ERC20 Approval (BUSD)
859859
</button>
860+
<button
861+
class="btn btn-primary btn-lg btn-block mb-3"
862+
id="maliciousContractInteractionButton"
863+
disabled
864+
>
865+
Malicious Contract Interaction
866+
</button>
860867
<button
861868
class="btn btn-primary btn-lg btn-block mb-3"
862869
id="maliciousSetApprovalForAll"

src/index.js

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ERC20_SAMPLE_CONTRACTS,
1818
ERC721_SAMPLE_CONTRACTS,
1919
NETWORKS_BY_CHAIN_ID,
20+
MALICIOUS_CONTRACT_ADDRESSES,
2021
} from './onchain-sample-contracts';
2122
import { getPermissionsDisplayString, stringifiableToHex } from './utils';
2223

@@ -39,6 +40,11 @@ const {
3940
* Page
4041
*/
4142

43+
const SEPOLIA_NETWORK_ID_HEX = '0xaa36a7';
44+
const SEPOLIA_NETWORK_ID_DEC = '11155111';
45+
const BASE_NETWORK_ID = '8453';
46+
const BASE_NETWORK_ID_HEX = '0x2105';
47+
4248
const currentUrl = new URL(window.location.href);
4349
const forwarderOrigin =
4450
currentUrl.hostname === 'localhost' ? 'http://localhost:9010' : undefined;
@@ -309,6 +315,10 @@ const mintSepoliaERC20 = document.getElementById('mintSepoliaERC20');
309315
const maliciousApprovalButton = document.getElementById(
310316
'maliciousApprovalButton',
311317
);
318+
const maliciousContractInteractionButton = document.getElementById(
319+
'maliciousContractInteractionButton',
320+
);
321+
312322
const maliciousERC20TransferButton = document.getElementById(
313323
'maliciousERC20TransferButton',
314324
);
@@ -429,6 +439,7 @@ const allConnectedButtons = [
429439
signInvalidVerifyingContractType,
430440
eip747WatchButton,
431441
maliciousApprovalButton,
442+
maliciousContractInteractionButton,
432443
maliciousSetApprovalForAll,
433444
maliciousERC20TransferButton,
434445
maliciousRawEthButton,
@@ -482,6 +493,7 @@ const initialConnectedButtons = [
482493
signInvalidVerifyingContractType,
483494
eip747WatchButton,
484495
maliciousApprovalButton,
496+
maliciousContractInteractionButton,
485497
maliciousSetApprovalForAll,
486498
maliciousERC20TransferButton,
487499
maliciousRawEthButton,
@@ -708,16 +720,31 @@ const handleNewChain = (chainId) => {
708720
}
709721
};
710722

711-
const handleNewNetwork = (networkId) => {
723+
function isSepoliaNetworkId(networkId) {
724+
return (
725+
networkId === SEPOLIA_NETWORK_ID_DEC || networkId === SEPOLIA_NETWORK_ID_HEX
726+
);
727+
}
728+
729+
function isBaseNetworkId(networkId) {
730+
return networkId === BASE_NETWORK_ID || networkId === BASE_NETWORK_ID_HEX;
731+
}
732+
733+
function toggleSepoliaMintButton(networkId) {
734+
mintSepoliaERC20.hidden = !isSepoliaNetworkId(networkId);
735+
}
736+
737+
function toggleMaliciousContractInteractionButton(networkId) {
738+
maliciousContractInteractionButton.hidden =
739+
isBaseNetworkId(networkId) || isSepoliaNetworkId(networkId);
740+
}
741+
742+
function handleNewNetwork(networkId) {
712743
networkDiv.innerHTML = networkId;
713-
const isNetworkIdSepolia = networkId === ('11155111' || '0xaa36a7');
714744

715-
if (isNetworkIdSepolia) {
716-
mintSepoliaERC20.hidden = false;
717-
} else {
718-
mintSepoliaERC20.hidden = true;
719-
}
720-
};
745+
toggleSepoliaMintButton(networkId);
746+
toggleMaliciousContractInteractionButton(networkId);
747+
}
721748

722749
const getNetworkAndChainId = async () => {
723750
try {
@@ -1604,6 +1631,26 @@ const initializeFormElements = () => {
16041631
console.log(result);
16051632
};
16061633

1634+
// Malicious Contract interaction
1635+
maliciousContractInteractionButton.onclick = async () => {
1636+
const contractAddress =
1637+
MALICIOUS_CONTRACT_ADDRESSES[networkName] ||
1638+
MALICIOUS_CONTRACT_ADDRESSES.default;
1639+
1640+
const result = await provider.request({
1641+
method: 'eth_sendTransaction',
1642+
params: [
1643+
{
1644+
from: accounts[0],
1645+
to: contractAddress,
1646+
data: '0xef5cfb8c0000000000000000000000000b3e87a076ac4b0d1975f0f232444af6deb96c59',
1647+
value: '0x0',
1648+
},
1649+
],
1650+
});
1651+
console.log(result);
1652+
};
1653+
16071654
// Malicious ERC20 transfer
16081655
maliciousERC20TransferButton.onclick = async () => {
16091656
let erc20Contract;

src/onchain-sample-contracts.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ export const ERC721_SAMPLE_CONTRACTS = {
3131
base: '0x90997fc967e75b7e69f899133aab31d197beb802',
3232
opBnb: '0x61d7e121185b1d7902a3da7f3c8ac9faaee8863b',
3333
};
34+
35+
export const MALICIOUS_CONTRACT_ADDRESSES = {
36+
mainnet: '0x000062Accd1a9d62eF428eC86cA3dD4f45120000',
37+
default: '0x00008F1149168C1D2fa1eBa1Ad3e9cD644510000',
38+
};

0 commit comments

Comments
 (0)