Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/chatty-rice-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rhinestone/sdk": patch
---

contract remediation changes
22 changes: 8 additions & 14 deletions src/execution/compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ const COMPACT_TYPED_DATA_TYPES = {
],
Mandate: [
{ name: 'target', type: 'Target' },
{ name: 'v', type: 'uint8' },
{ name: 'minGas', type: 'uint128' },
{ name: 'originOps', type: 'Op[]' },
{ name: 'destOps', type: 'Op[]' },
{ name: 'originOps', type: 'Op' },
{ name: 'destOps', type: 'Op' },
{ name: 'q', type: 'bytes32' },
],
Target: [
Expand All @@ -42,6 +41,10 @@ const COMPACT_TYPED_DATA_TYPES = {
{ name: 'amount', type: 'uint256' },
],
Op: [
{ name: 'vt', type: 'bytes32' },
{ name: 'ops', type: 'Ops[]' },
],
Ops: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'data', type: 'bytes' },
Expand Down Expand Up @@ -80,18 +83,9 @@ function getCompactTypedData(intentOp: IntentOp) {
targetChain: BigInt(element.mandate.destinationChainId),
fillExpiry: BigInt(element.mandate.fillDeadline),
},
v: element.mandate.v,
minGas: BigInt(element.mandate.minGas),
originOps: element.mandate.preClaimOps.map((op) => ({
to: op.to,
value: BigInt(op.value),
data: op.data,
})),
destOps: element.mandate.destinationOps.map((op) => ({
to: op.to,
value: BigInt(op.value),
data: op.data,
})),
originOps: element.mandate.preClaimOps,
destOps: element.mandate.destinationOps,
q: keccak256(element.mandate.qualifier.encodedVal),
},
})),
Expand Down
24 changes: 9 additions & 15 deletions src/execution/permit2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ function getTypedData(
{ name: 'targetChain', type: 'uint256' },
{ name: 'fillExpiry', type: 'uint256' },
],
Op: [
Ops: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'data', type: 'bytes' },
],
Op: [
{ name: 'vt', type: 'bytes32' },
{ name: 'ops', type: 'Ops[]' },
],
Mandate: [
{ name: 'target', type: 'Target' },
{ name: 'v', type: 'uint8' },
{ name: 'minGas', type: 'uint128' },
{ name: 'originOps', type: 'Op[]' },
{ name: 'destOps', type: 'Op[]' },
{ name: 'originOps', type: 'Op' },
{ name: 'destOps', type: 'Op' },
{ name: 'q', type: 'bytes32' },
],
PermitBatchWitnessTransferFrom: [
Expand All @@ -100,18 +103,9 @@ function getTypedData(
targetChain: BigInt(mandate.destinationChainId),
fillExpiry: BigInt(mandate.fillDeadline),
},
v: mandate.v,
minGas: BigInt(mandate.minGas),
originOps: mandate.preClaimOps.map((op) => ({
to: op.to,
value: BigInt(op.value),
data: op.data,
})),
destOps: mandate.destinationOps.map((op) => ({
to: op.to,
value: BigInt(op.value),
data: op.data,
})),
originOps: mandate.preClaimOps,
destOps: mandate.destinationOps,
q: keccak256(mandate.qualifier.encodedVal),
},
},
Expand Down
24 changes: 18 additions & 6 deletions src/execution/singleChainOps.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Address } from 'viem'
import type { Execution, IntentOpElement } from '../orchestrator/types'
import { type Address, zeroAddress } from 'viem'
import type { IntentOpElement } from '../orchestrator/types'

function getTypedData(
account: Address,
intentExecutorAddress: Address,
element: IntentOpElement,
nonce: bigint,
) {
const ops: Execution[] = element.mandate.destinationOps

return {
domain: {
name: 'IntentExecutor',
Expand All @@ -20,9 +18,18 @@ function getTypedData(
SingleChainOps: [
{ name: 'account', type: 'address' },
{ name: 'nonce', type: 'uint256' },
{ name: 'ops', type: 'Op[]' },
{ name: 'op', type: 'Op' },
{ name: 'gasRefund', type: 'GasRefund' },
],
Op: [
{ name: 'vt', type: 'bytes32' },
{ name: 'ops', type: 'Ops[]' },
],
GasRefund: [
{ name: 'token', type: 'address' },
{ name: 'exchangeRate', type: 'uint256' },
],
Ops: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' },
{ name: 'data', type: 'bytes' },
Expand All @@ -32,7 +39,12 @@ function getTypedData(
message: {
account,
nonce,
ops,
op: element.mandate.destinationOps,
// todo
gasRefund: {
token: zeroAddress,
exchangeRate: 0n,
},
},
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/execution/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,7 @@ async function prepareTransactionAsIntent(
})),
recipient,
account: intentAccount,
destinationExecutions: calls.map((call) => ({
to: call.to,
value: call.value.toString(),
data: call.data,
})),
destinationExecutions: calls,
destinationGasUnits: gasLimit,
accountAccessList,
options: {
Expand Down
12 changes: 8 additions & 4 deletions src/orchestrator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface Claim {

interface Execution {
to: Address
value: string
value: bigint
data: Hex
}

Expand Down Expand Up @@ -146,13 +146,18 @@ interface IntentCost {
}
}

export interface Op {
vt: Hex
ops: Execution[]
}

interface IntentOpElementMandate {
recipient: Address
tokenOut: [[string, string]]
destinationChainId: string
fillDeadline: string
destinationOps: Execution[]
preClaimOps: Execution[]
destinationOps: Op
preClaimOps: Op
qualifier: {
settlementContext: {
settlementLayer: SettlementLayer
Expand All @@ -162,7 +167,6 @@ interface IntentOpElementMandate {
}
encodedVal: Hex
}
v: number
minGas: string
}

Expand Down
21 changes: 12 additions & 9 deletions test/orchestrator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { zeroHash } from 'viem'
import { vi } from 'vitest'

export function createOrchestratorMock() {
Expand Down Expand Up @@ -52,16 +53,18 @@ export function createOrchestratorMock() {
],
destinationChainId: '8453',
fillDeadline: '1751908044',
destinationOps: [
{
to: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
value: '3',
data: '0x',
},
],
v: 27,
destinationOps: {
vt: '0x0203000000000000000000000000000000000000000000000000000000000000',
ops: [
{
to: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
value: '3',
data: '0x',
},
],
},
minGas: 1000000000000000000n,
preClaimOps: [],
preClaimOps: { vt: zeroHash, ops: [] },
qualifier: {
settlementContext: {
settlementLayer: 'SAME_CHAIN',
Expand Down