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: Add a new allowed selector (sponserdCallV2) for committee txn inputs #112

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
# Cache dependencies as `npm ci` takes like 6 minutes to run.
# https://github.com/actions/cache/blob/main/examples.md#node---npm
- id: npm-cache-dir
Expand Down
26 changes: 22 additions & 4 deletions src/handlers/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ export function handleRescueItem(event: RescueItem): void {
if ((isNewContent && event.block.number.gt(block)) || event.block.number.equals(block)) {
// Create curation
let txInput = event.transaction.input.toHexString()
// forwardMetaTx(address _target, bytes calldata _data) or manageCollection(address,address,address,bytes[]) selector
if (txInput.startsWith('0x07bd3522') || txInput.startsWith('0x81c9308e')) {
if (isAllowedCommitteeTxInput(txInput)) {
let curationId = getCurationId(collectionAddress, event.transaction.hash.toHexString(), event.logIndex.toString())
let curation = new Curation(curationId)
let curator = ''
Expand Down Expand Up @@ -517,8 +516,7 @@ export function handleSetApproved(event: SetApproved): void {
if (event.block.number.lt(block)) {
// Create curation
let txInput = event.transaction.input.toHexString()
// forwardMetaTx(address _target, bytes calldata _data) or manageCollection(address,address,address,bytes[]) selector
if (txInput.startsWith('0x07bd3522') || txInput.startsWith('0x81c9308e')) {
if (isAllowedCommitteeTxInput(txInput)) {
let curationId = getCurationId(collectionAddress, event.transaction.hash.toHexString(), event.logIndex.toString())
let curation = new Curation(curationId)
let curator = ''
Expand Down Expand Up @@ -592,3 +590,23 @@ export function handleTransferOwnership(event: OwnershipTransferred): void {
collection.save()
}
}

// List of allowed committee function selectors
// 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data)
// 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs)
// 0x81c9308e: manageCollection(address,address,address,bytes[]) selector
const ALLOWED_SELECTORS: string[] = ['0x07bd3522', '0xad718d2a', '0x81c9308e']

/**
* Verify if it's an allowed committee transaction input.
* @param txInput - The transaction input data as a hexadecimal string.
* @returns True if the input starts with an allowed selector, false otherwise.
*/
function isAllowedCommitteeTxInput(txInput: string): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (let i = 0; i < ALLOWED_SELECTORS.length; i++) {
if (txInput.startsWith(ALLOWED_SELECTORS[i])) {
return true
}
}
return false
}
Loading