Skip to content

Fix: Update deployment scripts for reciprocal contract configuration and domain-bound signatures - #12

Open
mertcano wants to merge 3 commits into
Consensys:mainfrom
mertcano:mertcano-patch-2
Open

mertcano wants to merge 3 commits into
Consensys:mainfrom
mertcano:mertcano-patch-2

Conversation

@mertcano

@mertcano mertcano commented Aug 20, 2026 •

Copy link
Copy Markdown

Description

This PR updates the deployment scripts and test fixtures within the ai-cns/smart-contract package to align with the newly hardened governance contracts and resolve testing configuration failures.

Vulnerabilities & Security Defects Remediated:

  • Test Fixtures and Contract Configuration (scripts/deploy.ts, scripts/deploy-Agreement.ts, scripts/deploy-Initiatives.ts): The deployment sequence was previously misconfigured and failed to set up the agreement dependency. The scripts now correctly deploy the Initiatives contract first, deploy the Agreement contract against the real deployed address, and successfully configure the reciprocal relationship by calling setAgreementContract.
  • Domain-Bound Signature Payloads (scripts/deploy-Agreement.ts): The data-fill routines and test payloads have been updated to properly sign the new domain-bound payload. The signAgreementPayload helper now accurately hashes the contract address, chain ID, caller, profile, agent nature, and constitution hash, directly satisfying the hardened ECDSA recovery requirements introduced in NetworkStateAgreement.

Note

High Risk
Changes on-chain access control, ETH movement, and credit/voting eligibility. The new INetworkStateAgreement interface also includes a function body, which will not compile as written.

Overview
Hardens NetworkStateInitiatives so voting, credits, funding, and team updates are gated and fail closed, then deploys it in lockstep with the agreement contract.

Voting now requires a configured agreement contract and a signed membership check. Credits can only be set by the owner or that agreement contract. Status updates are owner-only; team membership is limited to owner/ideator/instigator. Initiative IDs use a nonce plus chain/contract domain instead of block entropy. ETH withdrawals use call plus nonReentrant, and lookups revert if the initiative is missing.

Deploy scripts now create Initiatives first, pass its address into Agreement, then call setAgreementContract. Seed signatures hash contract, chain, signer, profile, nature, and constitution instead of signing the constitution hash alone.

Reviewed by Cursor Bugbot for commit 1b20a83. Bugbot is set up for automated code reviews on this repo. Configure here.

…and domain-bound signatures

### Description
This PR updates the deployment scripts and test fixtures within the `ai-cns/smart-contract` package to align with the newly hardened governance contracts and resolve testing configuration failures.

**Vulnerabilities & Security Defects Remediated:**
* **Test Fixtures and Contract Configuration (`scripts/deploy.ts`, `scripts/deploy-Agreement.ts`, `scripts/deploy-Initiatives.ts`):** The deployment sequence was previously misconfigured and failed to set up the agreement dependency. The scripts now correctly deploy the Initiatives contract first, deploy the Agreement contract against the real deployed address, and successfully configure the reciprocal relationship by calling `setAgreementContract`.
* **Domain-Bound Signature Payloads (`scripts/deploy-Agreement.ts`):** The data-fill routines and test payloads have been updated to properly sign the new domain-bound payload. The `signAgreementPayload` helper now accurately hashes the contract address, chain ID, caller, profile, agent nature, and constitution hash, directly satisfying the hardened `ECDSA` recovery requirements introduced in `NetworkStateAgreement`.
Comment thread smart-contract/scripts/deploy.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f98575f. Configure here.

function _requireAgreement() internal view {
require(agreementContract != address(0), "Agreement contract not configured");
require(INetworkStateAgreement(agreementContract).hasAgreed(msg.sender), "Agreement not signed");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing agreement membership check

High Severity

_requireAgreement calls hasAgreed(address) on the agreement contract, but NetworkStateAgreement never exposes that function. Membership lives only as a field on userInformation, so upvote and downvote revert once agreementContract is configured and voting stays unusable in production.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f98575f. Configure here.

//TODO: Call NetworkStateAgreement contract to check that the user has signed the agreement
for (uint256 i = 0; i < initiatives.length; i++) {
if (initiatives[i].id == _initiativeId) {
initiatives[i].upvotes += _votesNumber;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Owner captures initiative funding

Medium Severity

updateStatus is now onlyOwner, but still assigns instigator to msg.sender when the vote threshold is met. That makes the contract owner the only possible instigator, so raised initiative funds can only be withdrawn by the owner rather than an initiative lead.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f98575f. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant