{"id":29406963,"url":"https://github.com/peeramid-labs/smaug","last_synced_at":"2025-09-05T20:44:31.812Z","repository":{"id":284259816,"uuid":"954337232","full_name":"peeramid-labs/smaug","owner":"peeramid-labs","description":"Dragon to protect your gold (safe wallet plugin)","archived":false,"fork":false,"pushed_at":"2025-03-26T16:52:20.000Z","size":305,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-20T03:08:13.643Z","etag":null,"topics":["guardian-plugin","multisig","safe","wallets","web3-wallets"],"latest_commit_sha":null,"homepage":"https://solutions.peeramid.xyz","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peeramid-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-24T23:39:40.000Z","updated_at":"2025-04-10T11:00:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"14cb65c0-778c-40bb-9035-5522f1a95c96","html_url":"https://github.com/peeramid-labs/smaug","commit_stats":null,"previous_names":["peeramid-labs/onchain_solutions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peeramid-labs/smaug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peeramid-labs%2Fsmaug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peeramid-labs%2Fsmaug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peeramid-labs%2Fsmaug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peeramid-labs%2Fsmaug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peeramid-labs","download_url":"https://codeload.github.com/peeramid-labs/smaug/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peeramid-labs%2Fsmaug/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273818463,"owners_count":25173836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["guardian-plugin","multisig","safe","wallets","web3-wallets"],"created_at":"2025-07-11T00:03:19.423Z","updated_at":"2025-09-05T20:44:31.766Z","avatar_url":"https://github.com/peeramid-labs.png","language":"TypeScript","readme":"# Smaug - Safe Guard Contract Review\n\n## Overview\nSmaug is a guard contract for [Safe](https://safe.global/) multi-signature wallets that implements budget controls and transaction approval mechanisms. It's designed to protect assets by enforcing spending limits based on various timeframes:\n\n- Daily limits\n- Block limits\n- Per-transaction limits\n- Total (lifetime) limits\n\n## Key Features\n- Budget enforcement for multiple assets\n- Transaction pre-approval mechanism\n- Time-locked policy updates\n- Support for ERC20 tokens and native ETH\n- End-of-transaction balance tracking (not intra-transaction monitoring)\n\n## Implementation Details\n\n### Balance Tracking Mechanism\nSmaug only monitors the **net balance change** at the end of transaction execution, not intermediate transfers during execution. This means:\n\n- Only the final token/ETH outflow is considered when checking budget limits\n- Internal transfers within a transaction can temporarily exceed budget limits\n- As long as the final balance after transaction execution is within budget limits, the transaction will not be restricted\n- This design allows for complex transactions with multiple internal transfers while still enforcing overall budget controls\n\n## Time-To-Live (TTL) Mechanism\n\nSmaug uses a Time-To-Live (TTL) mechanism that affects several aspects of the contract's behavior:\n\n### How TTL Works\n\n- **Definition**: TTL is a time period (in seconds) that determines how long it takes for various approvals and scheduled changes to become valid\n- **Default**: The TTL is set during contract initialization (typically 86400 seconds or 1 day)\n- **Scope**: The TTL value applies globally to all assets protected by the contract\n\n### TTL Effects\n\n- **Pre-approved transactions**: The TTL acts as a maturity period for pre-approved transactions. When a transaction is pre-approved, it is still subject to budget checks until the TTL period has passed. Only after this waiting period does it bypass budget checks. The exact check is: `if (block.timestamp - preApprovalTimestamp \u003c TTL)`, then budget checks apply.\n- **Policy updates**: Changes to asset policies (budget limits) are scheduled and only applied after the TTL period has passed from the time of scheduling.\n- **TTL updates**: Changes to the TTL value itself are also time-locked and only take effect after waiting for the current TTL period from when the update was scheduled.\n\n### Changing TTL\n\nTo schedule a TTL update:\n\n```solidity\n// Schedule a change to the TTL value (will take effect after the current TTL period)\nsmaug.scheduleTTLUpdate(43200); // Change TTL to 12 hours (43200 seconds)\n```\n\n### Important Notes\n\n- **Pre-approved transactions require maturity**: The TTL acts as a maturity period for pre-approved transactions. When a transaction is pre-approved by hash, it is still subject to budget checks until the TTL period has passed. Only after this waiting period does it bypass budget checks.\n- **Pre-approvals mature after TTL period**: After the TTL period passes from when a transaction was pre-approved, that transaction becomes exempt from standard budget checks and limits.\n- **TTL is a mandatory waiting period**: For pre-approved transactions, TTL defines the minimum waiting period before the pre-approval takes effect and can bypass budget checks.\n- **All updates respect TTL**: Policy changes, TTL changes, and pre-approval maturity all follow the same time-based TTL mechanism.\n\n## Testing Summary\nTests were conducted to verify the core functionality of the Smaug contract. Key findings:\n\n1. ✅ **Budget Enforcement**: Successfully restricts transactions exceeding configured limits\n2. ✅ **Pre-approval Bypass**: Correctly allows pre-approved transactions to bypass budget checks\n3. ✅ **Pre-approval Expiration**: Pre-approved transactions correctly expire after the TTL period\n4. ✅ **Pre-approval Revocation**: Pre-approval can be revoked before activation\n5. ✅ **Asset Protection**: Multiple assets can be protected with independent budgets\n6. ✅ **TTL Updates**: TTL updates are correctly applied after the TTL period\n\n## Usage\n\n### Protecting Assets\nTo protect an asset with budget controls:\n\n```solidity\n// Add protection for an ERC20 token\nsmaug.addProtectedAsset(\n  tokenAddress, // Zero address for ETH\n  {\n    inDay: 1000 ether,    // 1000 tokens per day\n    inBlock: 100 ether,   // 100 tokens per block\n    inTX: 50 ether,       // 50 tokens per transaction\n    inTotal: 10000 ether  // 10000 tokens total lifetime limit\n  }\n);\n```\n\n### Pre-approving Transactions\nTo bypass budget controls for specific transactions:\n\n```solidity\n// Pre-approve a transaction hash\nbytes32 txHash = keccak256(\"Your transaction hash here\");\nsmaug.preApproveTx(txHash);\n```\n\n### Revoking Pre-approved Transactions\nIf a pre-approved transaction needs to be canceled or revoked:\n\n```solidity\n// Revoke a previously pre-approved transaction\nbytes32 txHash = keccak256(\"Your transaction hash here\");\nsmaug.revokePreApprovedTx(txHash);\n```\n\nThis will **immediately** invalidate the pre-approval, causing any subsequent executions of the transaction to be subject to normal budget checks, even if the TTL period has passed.\n\n### Scheduling Policy Updates\nTo update budget controls with a time-lock:\n\n```solidity\n// Schedule a policy update\nsmaug.schedulePolicyUpdate(\n  tokenAddress,\n  {\n    inDay: 2000 ether,    // Updated limits\n    inBlock: 200 ether,\n    inTX: 150 ether,\n    inTotal: 20000 ether\n  }\n);\n```\n\n### Code Security Review\n\nThe code was reviewed internally for security issues and best practices. No critical issues were found.\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeeramid-labs%2Fsmaug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeeramid-labs%2Fsmaug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeeramid-labs%2Fsmaug/lists"}