@@ -17,6 +17,7 @@ import {
17
17
ERC20_SAMPLE_CONTRACTS ,
18
18
ERC721_SAMPLE_CONTRACTS ,
19
19
NETWORKS_BY_CHAIN_ID ,
20
+ MALICIOUS_CONTRACT_ADDRESSES ,
20
21
} from './onchain-sample-contracts' ;
21
22
import { getPermissionsDisplayString , stringifiableToHex } from './utils' ;
22
23
@@ -39,6 +40,11 @@ const {
39
40
* Page
40
41
*/
41
42
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
+
42
48
const currentUrl = new URL ( window . location . href ) ;
43
49
const forwarderOrigin =
44
50
currentUrl . hostname === 'localhost' ? 'http://localhost:9010' : undefined ;
@@ -309,6 +315,10 @@ const mintSepoliaERC20 = document.getElementById('mintSepoliaERC20');
309
315
const maliciousApprovalButton = document . getElementById (
310
316
'maliciousApprovalButton' ,
311
317
) ;
318
+ const maliciousContractInteractionButton = document . getElementById (
319
+ 'maliciousContractInteractionButton' ,
320
+ ) ;
321
+
312
322
const maliciousERC20TransferButton = document . getElementById (
313
323
'maliciousERC20TransferButton' ,
314
324
) ;
@@ -429,6 +439,7 @@ const allConnectedButtons = [
429
439
signInvalidVerifyingContractType ,
430
440
eip747WatchButton ,
431
441
maliciousApprovalButton ,
442
+ maliciousContractInteractionButton ,
432
443
maliciousSetApprovalForAll ,
433
444
maliciousERC20TransferButton ,
434
445
maliciousRawEthButton ,
@@ -482,6 +493,7 @@ const initialConnectedButtons = [
482
493
signInvalidVerifyingContractType ,
483
494
eip747WatchButton ,
484
495
maliciousApprovalButton ,
496
+ maliciousContractInteractionButton ,
485
497
maliciousSetApprovalForAll ,
486
498
maliciousERC20TransferButton ,
487
499
maliciousRawEthButton ,
@@ -708,16 +720,31 @@ const handleNewChain = (chainId) => {
708
720
}
709
721
} ;
710
722
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 ) {
712
743
networkDiv . innerHTML = networkId ;
713
- const isNetworkIdSepolia = networkId === ( '11155111' || '0xaa36a7' ) ;
714
744
715
- if ( isNetworkIdSepolia ) {
716
- mintSepoliaERC20 . hidden = false ;
717
- } else {
718
- mintSepoliaERC20 . hidden = true ;
719
- }
720
- } ;
745
+ toggleSepoliaMintButton ( networkId ) ;
746
+ toggleMaliciousContractInteractionButton ( networkId ) ;
747
+ }
721
748
722
749
const getNetworkAndChainId = async ( ) => {
723
750
try {
@@ -1604,6 +1631,26 @@ const initializeFormElements = () => {
1604
1631
console . log ( result ) ;
1605
1632
} ;
1606
1633
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
+
1607
1654
// Malicious ERC20 transfer
1608
1655
maliciousERC20TransferButton . onclick = async ( ) => {
1609
1656
let erc20Contract ;
0 commit comments