Skip to content

Commit

Permalink
Merge pull request #123 from gnosisguild/fix-permission-check
Browse files Browse the repository at this point in the history
fix issues in roles permissions check
  • Loading branch information
jfschwarz authored Jul 21, 2024
2 parents 4844b4c + 82630b8 commit 35255c9
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 22 deletions.
1 change: 1 addition & 0 deletions extension/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"arbitrum",
"barnbridge",
"bitshift",
"Bitmask",
"Blockhash",
"blockie",
"blockies",
Expand Down
28 changes: 15 additions & 13 deletions extension/.pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
"@gnosis.pm/zodiac": "^4.0.3",
"@noble/hashes": "^1.4.0",
"@safe-global/api-kit": "^2.4.2",
"@safe-global/protocol-kit": "^4.0.2",
"@safe-global/safe-apps-sdk": "^9.1.0",
Expand Down Expand Up @@ -79,7 +80,7 @@
"react-select": "^5.2.1",
"react-toastify": "^9.0.8",
"rimraf": "^3.0.2",
"ser-kit": "^0.3.9",
"ser-kit": "^0.3.10",
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.0",
"typescript-plugin-css-modules": "^5.1.0",
Expand Down
49 changes: 47 additions & 2 deletions extension/src/browser/Drawer/RolePermissionCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTenderlyProvider } from '../../providers'
import { TenderlyProvider } from '../../providers/ProvideTenderly'
import { TransactionState } from '../../state'
import { MetaTransactionData } from '@safe-global/safe-core-sdk-types'
import { ZeroAddress } from 'ethers'
import { toQuantity, ZeroAddress } from 'ethers'
import {
ExecutionActionType,
parsePrefixedAddress,
Expand All @@ -43,7 +43,11 @@ const simulateRolesTransaction = async (
}

const [, from] = parsePrefixedAddress(plan[0].from)
const tx = { ...plan[0].transaction, from }
const tx = {
...plan[0].transaction,
from,
value: toQuantity(BigInt(plan[0].transaction.value || 0)),
}

try {
await tenderlyProvider.request({
Expand All @@ -56,6 +60,9 @@ const simulateRolesTransaction = async (
decodeRolesV2Error(e as JsonRpcError)

if (decodedError) {
if (decodedError.name === 'ConditionViolation') {
return RolesV2Status[decodedError.args.status]
}
return decodedError.name
} else {
const genericError = decodeGenericError(e as JsonRpcError)
Expand Down Expand Up @@ -149,3 +156,41 @@ const RolePermissionCheck: React.FC<{
}

export default RolePermissionCheck

enum RolesV2Status {
Ok,
/** Role not allowed to delegate call to target address */
DelegateCallNotAllowed,
/** Role not allowed to call target address */
TargetAddressNotAllowed,
/** Role not allowed to call this function on target address */
FunctionNotAllowed,
/** Role not allowed to send to target address */
SendNotAllowed,
/** Or condition not met */
OrViolation,
/** Nor condition not met */
NorViolation,
/** Parameter value is not equal to allowed */
ParameterNotAllowed,
/** Parameter value less than allowed */
ParameterLessThanAllowed,
/** Parameter value greater than maximum allowed by role */
ParameterGreaterThanAllowed,
/** Parameter value does not match */
ParameterNotAMatch,
/** Array elements do not meet allowed criteria for every element */
NotEveryArrayElementPasses,
/** Array elements do not meet allowed criteria for at least one element */
NoArrayElementPasses,
/** Parameter value not a subset of allowed */
ParameterNotSubsetOfAllowed,
/** Bitmask exceeded value length */
BitmaskOverflow,
/** Bitmask not an allowed value */
BitmaskNotAllowed,
CustomConditionViolation,
AllowanceExceeded,
CallAllowanceExceeded,
EtherAllowanceExceeded,
}
13 changes: 7 additions & 6 deletions extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ __metadata:
languageName: node
linkType: hard

"@noble/hashes@npm:1.4.0, @noble/hashes@npm:^1.3.3, @noble/hashes@npm:~1.4.0":
"@noble/hashes@npm:1.4.0, @noble/hashes@npm:^1.3.3, @noble/hashes@npm:^1.4.0, @noble/hashes@npm:~1.4.0":
version: 1.4.0
resolution: "@noble/hashes@npm:1.4.0"
checksum: 10/e156e65794c473794c52fa9d06baf1eb20903d0d96719530f523cc4450f6c721a957c544796e6efd0197b2296e7cd70efeb312f861465e17940a3e3c7e0febc6
Expand Down Expand Up @@ -8826,15 +8826,15 @@ __metadata:
languageName: node
linkType: hard

"ser-kit@npm:^0.3.9":
version: 0.3.9
resolution: "ser-kit@npm:0.3.9"
"ser-kit@npm:^0.3.10":
version: 0.3.10
resolution: "ser-kit@npm:0.3.10"
dependencies:
"@safe-global/api-kit": "npm:^2.4.2"
"@safe-global/protocol-kit": "npm:^4.0.2"
"@safe-global/safe-core-sdk-types": "npm:^5.0.2"
viem: "npm:^2.13.8"
checksum: 10/2dbbf79d74d8d6d52db0fbf0421aef8dc80fdc537a135017947c7b37ff1ba686c920245ecf21854edb88de371e0a388d1ad0b4c27675d61379f5289881b5807f
checksum: 10/cf9788b578a2b8c38748028cee29d99ce201effdc564690dc9bc6c14411ca16a8d95cb5099314ec186fbc8188a6bb2bc04ba8f638fe1a00a997966ea26232518
languageName: node
linkType: hard

Expand Down Expand Up @@ -10670,6 +10670,7 @@ __metadata:
"@eslint/eslintrc": "npm:^3.1.0"
"@eslint/js": "npm:^9.7.0"
"@gnosis.pm/zodiac": "npm:^4.0.3"
"@noble/hashes": "npm:^1.4.0"
"@safe-global/api-kit": "npm:^2.4.2"
"@safe-global/protocol-kit": "npm:^4.0.2"
"@safe-global/safe-apps-sdk": "npm:^9.1.0"
Expand Down Expand Up @@ -10723,7 +10724,7 @@ __metadata:
react-select: "npm:^5.2.1"
react-toastify: "npm:^9.0.8"
rimraf: "npm:^3.0.2"
ser-kit: "npm:^0.3.9"
ser-kit: "npm:^0.3.10"
typescript: "npm:^5.5.3"
typescript-eslint: "npm:^7.16.0"
typescript-plugin-css-modules: "npm:^5.1.0"
Expand Down

0 comments on commit 35255c9

Please sign in to comment.