-
-
Notifications
You must be signed in to change notification settings - Fork 362
add: malicious send calls #401
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c803eef
malicious send calls
seaona 872c47d
tweaks
seaona 6624e7f
remove comments
seaona 02bd049
fix
seaona 7a9088e
text
seaona 3369feb
add connections
seaona 8df8935
tweaks
seaona 26c68b4
order
seaona 7df5030
3 malicious tx
seaona a7c17a7
add error section
seaona e89ed50
disable/enable button
seaona fb77c1c
order alphabetically
seaona e2eecde
malicious address
seaona 4d63aae
revert malicious address as its fixed
seaona d9f1884
Merge branch 'main' into eip5792-ppom
seaona 12fde2f
update version
seaona 5a6e84c
address Ariella's commentoptimization
seaona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
import globalContext from '../..'; | ||
import { DEFAULT_CALLS } from '../transactions/eip5792/sendCalls'; | ||
import { getMaliciousTransactions } from './sharedConstants'; | ||
|
||
export function ppomMaliciousSendCalls(parentContainer) { | ||
parentContainer.insertAdjacentHTML( | ||
'beforeend', | ||
`<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12 d-flex align-items-stretch"> | ||
<div class="card full-width"> | ||
<div class="card-body"> | ||
<h4 class="card-title"> | ||
PPOM - EIP 5792 - Malicious Send Calls | ||
</h4> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomSendMaliciousEthButton"> | ||
Send Calls with Malicious ETH Transfer | ||
</button> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomSendMaliciousERC20TransferButton"> | ||
Send Calls with Malicious ERC20 Transfer (USDC) | ||
</button> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomSendMaliciousERC20ApprovalButton"> | ||
Send Calls with Malicious ERC20 Approval (BUSDC) | ||
</button> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomSendMaliciousSetApprovalForAllButton"> | ||
Send Calls with Malicious Set Approval for All | ||
</button> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomSendMaliciousContractInteractionButton"> | ||
Send Calls with Malicious Contract Interaction | ||
</button> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomSendThreeMaliciousTxsButton"> | ||
Send Calls with 3 Malicious Transactions | ||
</button> | ||
<hr/> | ||
<div id="ppomRequestIdContainer" hidden> | ||
<label>Request ID:</label> | ||
<input type="text" id="ppomRequestIdInput" class="form-control" readonly /> | ||
</div> | ||
<p class="info-text alert alert-warning" id="ppomSendCallsErrorContainer" hidden> | ||
<span class="wrap" id="ppomSendCallsError"></span> | ||
</p> | ||
<button class="btn btn-primary btn-lg btn-block mb-3" id="ppomGetCallsStatusButton" disabled> | ||
Get Calls Status | ||
</button> | ||
<p class="info-text alert alert-success"> | ||
<span class="wrap" id="ppomGetCallsStatusResult">Status</span> | ||
</p> | ||
</div> | ||
</div> | ||
</div>`, | ||
); | ||
|
||
const ppomSendMaliciousEthButton = document.getElementById( | ||
'ppomSendMaliciousEthButton', | ||
); | ||
|
||
ppomSendMaliciousEthButton.onclick = async () => { | ||
await sendMaliciousCalls('eth'); | ||
}; | ||
|
||
const ppomSendMaliciousERC20TransferButton = document.getElementById( | ||
'ppomSendMaliciousERC20TransferButton', | ||
); | ||
|
||
ppomSendMaliciousERC20TransferButton.onclick = async () => { | ||
await sendMaliciousCalls('erc20Transfer'); | ||
}; | ||
|
||
const ppomSendMaliciousERC20ApprovalButton = document.getElementById( | ||
'ppomSendMaliciousERC20ApprovalButton', | ||
); | ||
|
||
ppomSendMaliciousERC20ApprovalButton.onclick = async () => { | ||
await sendMaliciousCalls('erc20Approval'); | ||
}; | ||
|
||
const ppomSendMaliciousSetApprovalForAllButton = document.getElementById( | ||
'ppomSendMaliciousSetApprovalForAllButton', | ||
); | ||
|
||
ppomSendMaliciousSetApprovalForAllButton.onclick = async () => { | ||
await sendMaliciousCalls('setApprovalForAll'); | ||
}; | ||
|
||
const ppomSendMaliciousContractInteractionButton = document.getElementById( | ||
'ppomSendMaliciousContractInteractionButton', | ||
); | ||
|
||
ppomSendMaliciousContractInteractionButton.onclick = async () => { | ||
await sendMaliciousCalls('maliciousContractInteraction'); | ||
}; | ||
|
||
const ppomSendThreeMaliciousTxsButton = document.getElementById( | ||
'ppomSendThreeMaliciousTxsButton', | ||
); | ||
|
||
ppomSendThreeMaliciousTxsButton.onclick = async () => { | ||
await sendThreeMaliciousCalls(); | ||
}; | ||
|
||
document.addEventListener('globalConnectionChange', function (e) { | ||
if (e.detail.connected) { | ||
// MetaMask is connected, enable the button | ||
ppomSendMaliciousEthButton.disabled = false; | ||
ppomSendMaliciousERC20TransferButton.disabled = false; | ||
ppomSendMaliciousERC20ApprovalButton.disabled = false; | ||
ppomSendMaliciousSetApprovalForAllButton.disabled = false; | ||
ppomSendMaliciousContractInteractionButton.disabled = false; | ||
ppomSendThreeMaliciousTxsButton.disabled = false; | ||
} | ||
}); | ||
|
||
document.addEventListener('disableAndClear', function () { | ||
ppomSendMaliciousEthButton.disabled = true; | ||
ppomSendMaliciousERC20TransferButton.disabled = true; | ||
ppomSendMaliciousERC20ApprovalButton.disabled = true; | ||
ppomSendMaliciousSetApprovalForAllButton.disabled = true; | ||
ppomSendMaliciousContractInteractionButton.disabled = true; | ||
ppomSendThreeMaliciousTxsButton.disabled = true; | ||
}); | ||
|
||
async function sendMaliciousCalls(type) { | ||
const maliciousTransactions = getMaliciousTransactions(globalContext); | ||
const calls = []; | ||
|
||
switch (type) { | ||
case 'eth': | ||
calls.push(maliciousTransactions.eth); | ||
break; | ||
case 'erc20Transfer': | ||
calls.push(maliciousTransactions.erc20Transfer); | ||
break; | ||
case 'erc20Approval': | ||
calls.push(maliciousTransactions.erc20Approval); | ||
break; | ||
case 'maliciousContractInteraction': | ||
calls.push(maliciousTransactions.maliciousContractInteraction); | ||
break; | ||
case 'setApprovalForAll': | ||
calls.push(maliciousTransactions.setApprovalForAll); | ||
break; | ||
default: | ||
// Do nothing | ||
break; | ||
} | ||
|
||
calls.push(...DEFAULT_CALLS); | ||
|
||
try { | ||
const result = await globalContext.provider.request({ | ||
method: 'wallet_sendCalls', | ||
params: [getParams(calls)], | ||
}); | ||
document.getElementById('ppomRequestIdInput').value = result.id; | ||
document.getElementById('ppomRequestIdContainer').hidden = false; | ||
document.getElementById('ppomGetCallsStatusButton').disabled = false; | ||
document.getElementById('ppomSendCallsErrorContainer').hidden = true; | ||
} catch (error) { | ||
console.error(error); | ||
document.getElementById('ppomSendCallsErrorContainer').hidden = false; | ||
document.getElementById( | ||
'ppomSendCallsError', | ||
).innerHTML = `Error: ${error.message}`; | ||
} | ||
} | ||
|
||
async function sendThreeMaliciousCalls() { | ||
const maliciousTransactions = getMaliciousTransactions(globalContext); | ||
|
||
const calls = [ | ||
maliciousTransactions.erc20Approval, | ||
maliciousTransactions.setApprovalForAll, | ||
maliciousTransactions.maliciousContractInteraction, | ||
]; | ||
|
||
try { | ||
const result = await globalContext.provider.request({ | ||
method: 'wallet_sendCalls', | ||
params: [getParams(calls)], | ||
}); | ||
document.getElementById('ppomRequestIdInput').value = result.id; | ||
document.getElementById('ppomRequestIdContainer').hidden = false; | ||
document.getElementById('ppomGetCallsStatusButton').disabled = false; | ||
document.getElementById('ppomSendCallsErrorContainer').hidden = true; | ||
} catch (error) { | ||
console.error(error); | ||
document.getElementById('ppomSendCallsErrorContainer').hidden = false; | ||
document.getElementById( | ||
'ppomSendCallsError', | ||
).innerHTML = `Error: ${error.message}`; | ||
} | ||
} | ||
|
||
// Get Calls Status functionality | ||
document.getElementById('ppomGetCallsStatusButton').onclick = async () => { | ||
const requestId = document.getElementById('ppomRequestIdInput').value; | ||
const resultOutput = document.getElementById('ppomGetCallsStatusResult'); | ||
|
||
try { | ||
const result = await globalContext.provider.request({ | ||
method: 'wallet_getCallsStatus', | ||
params: [requestId], | ||
}); | ||
|
||
resultOutput.innerHTML = JSON.stringify(result, null, 2); | ||
document.getElementById('ppomGetCallsStatusButton').disabled = false; | ||
} catch (error) { | ||
console.error(error); | ||
resultOutput.innerHTML = `Error: ${error.message}`; | ||
} | ||
}; | ||
|
||
function getParams(calls) { | ||
return { | ||
version: '1.0', | ||
from: globalContext.accounts[0], | ||
chainId: `0x${globalContext.chainIdInt.toString(16)}`, | ||
calls, | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './transactions'; | ||
export * from './batching'; | ||
export * from './bypasses'; | ||
export * from './eip5792'; | ||
export * from './transactions'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { maliciousAddress } from '../../sample-addresses'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved the malicious tx's in this file, so they can be used both in the ppom tx and in the ppom batch txs |
||
import { | ||
ERC20_SAMPLE_CONTRACTS, | ||
ERC721_SAMPLE_CONTRACTS, | ||
MALICIOUS_CONTRACT_ADDRESSES, | ||
NETWORKS_BY_CHAIN_ID, | ||
} from '../../onchain-sample-contracts'; | ||
|
||
export const getMaliciousTransactions = (globalContext) => { | ||
const chainId = globalContext.chainIdInt; | ||
const networkName = NETWORKS_BY_CHAIN_ID[chainId] || 'default'; | ||
|
||
return { | ||
eth: { | ||
to: maliciousAddress, | ||
value: '0x9184e72a000', | ||
}, | ||
erc20Transfer: { | ||
to: ERC20_SAMPLE_CONTRACTS[networkName], | ||
data: '0xa9059cbb0000000000000000000000005fbdb2315678afecb367f032d93f642f64180aa30000000000000000000000000000000000000000000000000000000000000064', | ||
value: '0x0', | ||
}, | ||
erc20Approval: { | ||
to: ERC20_SAMPLE_CONTRACTS[networkName], | ||
data: '0x095ea7b3000000000000000000000000e50a2dbc466d01a34c3e8b7e8e45fce4f7da39e6000000000000000000000000000000000000000000000000ffffffffffffffff', | ||
value: '0x0', | ||
}, | ||
setApprovalForAll: { | ||
to: ERC721_SAMPLE_CONTRACTS[networkName], | ||
data: '0xa22cb465000000000000000000000000b85492afc686d5ca405e3cd4f50b05d358c75ede0000000000000000000000000000000000000000000000000000000000000001', | ||
value: '0x0', | ||
}, | ||
maliciousContractInteraction: { | ||
to: | ||
MALICIOUS_CONTRACT_ADDRESSES[networkName] || | ||
MALICIOUS_CONTRACT_ADDRESSES.default, | ||
data: '0xef5cfb8c0000000000000000000000000b3e87a076ac4b0d1975f0f232444af6deb96c59', | ||
value: '0x0', | ||
}, | ||
}; | ||
}; | ||
digiwand marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove hardcoded malicious address, and use the const