Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(contracts): restrict AgentPayments.createAgent to the owner and floor portfolio rebalance timing

nirholasfd08959cfdce
diff --git a/contracts/AGENT_PAYMENTS.md b/contracts/AGENT_PAYMENTS.md
index 918c3beff..0034cfc05 100644
--- a/contracts/AGENT_PAYMENTS.md
+++ b/contracts/AGENT_PAYMENTS.md
@@ -28,7 +28,7 @@ sentinel `0xEee…EeE`.
| Function | Access | Effect |
| --- | --- | --- |
-| `createAgent(agentToken, agentAuthority, buybackBps)` | owner **or** `agentAuthority` | Register an agent token once |
+| `createAgent(agentToken, agentAuthority, buybackBps)` | owner only | Register an agent token once |
| `acceptPayment(agentToken, currency, amount, memo, startTime, endTime)` | anyone | Pull ERC-20, credit payment vault, settle invoice |
| `acceptPaymentNative(agentToken, memo, startTime, endTime)` | anyone (payable) | Same, native currency |
| `distributePayments(agentToken, currency)` | anyone | Split payment vault → buyback + withdraw vaults by `buybackBps` |
diff --git a/contracts/hood-portfolios/src/Portfolio.sol b/contracts/hood-portfolios/src/Portfolio.sol
index c377fd15f..ca210c47d 100644
--- a/contracts/hood-portfolios/src/Portfolio.sol
+++ b/contracts/hood-portfolios/src/Portfolio.sol
@@ -106,6 +106,15 @@ contract Portfolio is ERC20, ReentrancyGuard {
/// a property of the deployed vault rather than a parameter anyone can raise later.
uint16 public constant MAX_END_PAYOUT_BPS = 10_100;
+ /// @notice Shortest timelock between a rebalance proposal and its auction opening.
+ /// @dev The creator picks the target basket and anyone may fill it, so without a floor a creator
+ /// could propose skewed targets and fill them in the same transaction. This window is what lets
+ /// holders redeem before an unfavourable rebalance opens.
+ uint32 public constant MIN_REBALANCE_DELAY = 1 days;
+
+ /// @notice Shortest gap between two rebalance proposals.
+ uint32 public constant MIN_REBALANCE_INTERVAL = 1 days;
+
/// @notice Shares minted for the very first issuance, per unit of `seedUnits`.
uint256 public constant ONE = 1e18;
@@ -164,6 +173,8 @@ contract Portfolio is ERC20, ReentrancyGuard {
error SeedUnitRequired(address token);
error FeeTooHigh(uint16 bps);
error PayoutOutOfRange(uint16 startBps, uint16 endBps);
+ error RebalanceDelayTooShort(uint32 delay);
+ error RebalanceIntervalTooShort(uint32 interval);
error ZeroShares();
error ConstituentHalted(address token);
error NotYetDue(uint64 nextAt);
@@ -203,6 +214,8 @@ contract Portfolio is ERC20, ReentrancyGuard {
if (n > 32) revert TooManyConstituents(n);
if (c.seedUnits.length != n) revert BadArrayLength();
if (c.feeBps > MAX_FEE_BPS) revert FeeTooHigh(c.feeBps);
+ if (c.rebalanceDelay < MIN_REBALANCE_DELAY) revert RebalanceDelayTooShort(c.rebalanceDelay);
+ if (c.rebalanceInterval < MIN_REBALANCE_INTERVAL) revert RebalanceIntervalTooShort(c.rebalanceInterval);
if (c.startPayoutBps > 10_000 || c.endPayoutBps < c.startPayoutBps || c.endPayoutBps > MAX_END_PAYOUT_BPS) {
revert PayoutOutOfRange(c.startPayoutBps, c.endPayoutBps);
}
diff --git a/contracts/hood-portfolios/test/HoodPortfolios.t.sol b/contracts/hood-portfolios/test/HoodPortfolios.t.sol
index ff0b8a9ee..cf6b21b76 100644
--- a/contracts/hood-portfolios/test/HoodPortfolios.t.sol
+++ b/contracts/hood-portfolios/test/HoodPortfolios.t.sol
@@ -614,4 +614,31 @@ contract PortfolioFeeTest is PortfolioFixture {
);
factory.deploy(c);
}
+
+ function test_rebalanceTimingFloorsAreEnforcedAtConstruction() public {
+ uint256 id = _publish(keccak256("instant"), 0, creator);
+ Portfolio.Config memory c = Portfolio.Config({
+ name: "Instant",
+ symbol: "INST",
+ registry: address(registry),
+ manifestId: id,
+ constituents: _constituents(),
+ seedUnits: _seedUnits(),
+ feeBps: 100,
+ rebalanceInterval: 30 days,
+ rebalanceDelay: 0,
+ auctionDuration: 6 hours,
+ startPayoutBps: 9_700,
+ endPayoutBps: 10_000
+ });
+ vm.prank(creator);
+ vm.expectRevert(abi.encodeWithSelector(Portfolio.RebalanceDelayTooShort.selector, uint32(0)));
+ factory.deploy(c);
+
+ c.rebalanceDelay = 1 days;
+ c.rebalanceInterval = 0;
+ vm.prank(creator);
+ vm.expectRevert(abi.encodeWithSelector(Portfolio.RebalanceIntervalTooShort.selector, uint32(0)));
+ factory.deploy(c);
+ }
}
diff --git a/contracts/src/AgentPayments.sol b/contracts/src/AgentPayments.sol
index ed680102e..6e542e0f6 100644
--- a/contracts/src/AgentPayments.sol
+++ b/contracts/src/AgentPayments.sol
@@ -129,14 +129,15 @@ contract AgentPayments is ReentrancyGuard, Ownable {
// ── Agent registration ───────────────────────────────────────────────────
/**
- * @notice Register an agent token. Callable by the platform owner (on behalf
- * of a user) or self-registered when `agentAuthority == msg.sender`,
- * which prevents registration front-running with a foreign authority.
+ * @notice Register an agent token. Platform owner only: the owner verifies
+ * off-chain that `agentAuthority` controls `agentToken` and registers
+ * on the user's behalf. Open self-registration would let anyone claim
+ * any token first and receive its payments.
*/
function createAgent(address agentToken, address agentAuthority, uint16 buybackBps) external {
if (agentToken == address(0) || agentAuthority == address(0)) revert ZeroAddress();
if (buybackBps > BPS_DENOMINATOR) revert InvalidBps();
- if (msg.sender != owner() && msg.sender != agentAuthority) revert NotAgentAuthority();
+ if (msg.sender != owner()) revert NotAgentAuthority();
if (_agents[agentToken].exists) revert AgentExists();
_agents[agentToken] = AgentConfig({authority: agentAuthority, buybackBps: buybackBps, exists: true});
diff --git a/contracts/test/AgentPayments.t.sol b/contracts/test/AgentPayments.t.sol
index cbc2399e1..cf7f300d3 100644
--- a/contracts/test/AgentPayments.t.sol
+++ b/contracts/test/AgentPayments.t.sol
@@ -173,8 +173,8 @@ contract AgentPaymentsTest is Test {
vm.prank(owner);
ap.setRouterAllowed(address(router), true);
- // Register the agent (self-registration: authority == msg.sender).
- vm.prank(authority);
+ // Register the agent (owner-only registration).
+ vm.prank(owner);
ap.createAgent(address(agentTok), authority, BUYBACK_BPS);
usdc.mint(payer, 1_000e18);
@@ -195,11 +195,26 @@ contract AgentPaymentsTest is Test {
}
function testCannotDoubleRegister() public {
- vm.prank(authority);
+ vm.prank(owner);
vm.expectRevert(AgentPayments.AgentExists.selector);
ap.createAgent(address(agentTok), authority, 0);
}
+ function testAttackerCannotSquatTokenByNamingThemself() public {
+ MockERC20 other = new MockERC20("Q", "Q");
+ address attacker = address(0xBAD);
+ vm.prank(attacker);
+ vm.expectRevert(AgentPayments.NotAgentAuthority.selector);
+ ap.createAgent(address(other), attacker, 0);
+
+ // The platform owner can still register the real authority.
+ vm.prank(owner);
+ ap.createAgent(address(other), authority, 0);
+ (address auth,, bool exists) = ap.getAgentConfig(address(other));
+ assertEq(auth, authority);
+ assertTrue(exists);
+ }
+
function testForeignAuthorityCannotRegister() public {
MockERC20 other = new MockERC20("X", "X");
vm.prank(payer);
@@ -612,7 +627,7 @@ contract AgentPaymentsTest is Test {
function testZeroBpsSendsEverythingToTheAuthority() public {
MockERC20 other = new MockERC20("N", "N");
- vm.prank(authority);
+ vm.prank(owner);
ap.createAgent(address(other), authority, 0);
vm.startPrank(payer);
@@ -628,7 +643,7 @@ contract AgentPaymentsTest is Test {
function testFullBpsSendsEverythingToBuyback() public {
MockERC20 other = new MockERC20("F", "F");
- vm.prank(authority);
+ vm.prank(owner);
ap.createAgent(address(other), authority, 10_000);
vm.startPrank(payer);