Skip to content

Commit

Permalink
[#754] Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jul 11, 2024
1 parent 31798cb commit 42b216e
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions modules/4337/test/erc4337/ReferenceEntryPoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,39 +382,57 @@ describe('Safe4337Module - Reference EntryPoint', () => {
)

const opData = calculateSafeOperationData(await validator.getAddress(), safeOp, await chainId())
const signature = buildSignatureBytes([

const parentSafeSignature = await user.signTypedData(
{
signer: parentSafe.address,
data: await user.signTypedData(
{
verifyingContract: parentSafe.address,
chainId: await chainId(),
},
{
SafeMessage: [{ type: 'bytes', name: 'message' }],
},
{
message: opData,
},
),
dynamic: true,
verifyingContract: parentSafe.address,
chainId: await chainId(),
},
{
SafeMessage: [{ type: 'bytes', name: 'message' }],
},
{
message: opData,
},
)

// Here signature contains additional bytes in between signatures
const signature = ethers.concat([
ethers.zeroPadValue(parentSafe.address, 32), // address of the signer
ethers.toBeHex(65 + 'padding'.length, 32), // offset of the start of the signature
'0x00', // contract signature type
ethers.toUtf8Bytes('padding'), // extra illegal padding between signatures
ethers.toBeHex(ethers.dataLength(parentSafeSignature), 32), // length of the dynamic signature
parentSafeSignature,
])

const userOp = buildPackedUserOperationFromSafeUserOperation({
safeOp,
// Replace the 2nd word of static part of signature containing the pointer to dynamic part with invalid pointer value
signature:
signature.slice(0, 66) +
((signature.length - 2) / 2).toString(16).padStart(64, '0') +
'00' +
signature.slice(132) +
signature.slice(132),
signature,
})

await expect(entryPoint.handleOps([userOp], await relayer.getAddress()))
.to.be.revertedWithCustomError(entryPoint, 'FailedOp')
.withArgs(0, 'AA24 signature error')

// Here signature contains additional bytes in between signatures along with invalid length value
const signature2 = ethers.concat([
ethers.zeroPadValue(parentSafe.address, 32), // address of the signer
ethers.toBeHex(65 + 'padding'.length, 32), // offset of the start of the signature
'0x00', // contract signature type
ethers.toUtf8Bytes('padding'), // extra illegal padding between signatures
ethers.toBeHex(ethers.dataLength(parentSafeSignature) + 'padding'.length, 32), // length of the dynamic signature
parentSafeSignature,
])

const userOp2 = buildPackedUserOperationFromSafeUserOperation({
safeOp,
signature: signature2,
})

await expect(entryPoint.handleOps([userOp2], await relayer.getAddress()))
.to.be.revertedWithCustomError(entryPoint, 'FailedOp')
.withArgs(0, 'AA24 signature error')
})

function isEventLog(log: Log): log is EventLog {
Expand Down

0 comments on commit 42b216e

Please sign in to comment.