Skip to content

Cairo add security contract field #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
27ebf04
Before running with prettier
CoveMB Feb 21, 2025
7c7828e
After running with prettier
CoveMB Feb 21, 2025
ce5fcd3
Add consistent-type-imports rule
CoveMB Feb 21, 2025
3cd0b59
Add lint step in ci action
CoveMB Feb 21, 2025
31f0c78
resolve prettier conflict
CoveMB Feb 21, 2025
365421b
After running with prettier
CoveMB Feb 21, 2025
cedaeaa
resolve prettier conflict
CoveMB Feb 21, 2025
98bd8af
Add lint step in ci action
CoveMB Feb 21, 2025
a9098d0
resolve prettier conflict
CoveMB Feb 21, 2025
6e9df26
resolve prettier conflict
CoveMB Feb 21, 2025
574a739
Remove .vscode directory from Git tracking
CoveMB Feb 21, 2025
c0e9002
move linter action in it's own job
CoveMB Feb 21, 2025
86c65dc
add lint note in readme
CoveMB Feb 21, 2025
a1111d3
Update .github/workflows/test.yml
CoveMB Feb 21, 2025
abbd5a4
Merge remote-tracking branch 'upstream/master'
CoveMB Feb 21, 2025
beffa34
Merge branch 'master' into master
ericglau Feb 21, 2025
d6bec2a
lint script files
CoveMB Feb 21, 2025
315b775
Merge branch 'master' of github.com:CoveMB/contracts-wizard
CoveMB Feb 21, 2025
6ed6e4f
Merge remote-tracking branch 'upstream/master'
CoveMB Feb 24, 2025
ea90cd1
Merge remote-tracking branch 'upstream/master'
CoveMB Feb 28, 2025
abf687a
Merge remote-tracking branch 'upstream/master'
CoveMB Mar 4, 2025
426b62d
Merge remote-tracking branch 'upstream/master'
CoveMB Mar 20, 2025
ea25cc1
Merge remote-tracking branch 'upstream/master'
CoveMB Mar 20, 2025
0911f87
Merge remote-tracking branch 'upstream/master'
CoveMB Mar 25, 2025
4914083
Merge remote-tracking branch 'upstream/master'
CoveMB Mar 27, 2025
5ce527f
Merge remote-tracking branch 'upstream/master'
CoveMB Apr 4, 2025
03a32fc
Merge remote-tracking branch 'upstream/master'
CoveMB Apr 7, 2025
b3c0347
Merge remote-tracking branch 'upstream/master'
CoveMB Apr 12, 2025
0a52a65
Merge remote-tracking branch 'upstream/master'
CoveMB May 13, 2025
9e74342
Merge remote-tracking branch 'upstream/master'
CoveMB May 19, 2025
d727f51
Merge remote-tracking branch 'upstream/master'
CoveMB May 21, 2025
7016fd9
Add security info tag for cairo
CoveMB May 26, 2025
3b191da
add changeset
CoveMB May 26, 2025
7c7628a
add security input for cairo alpha
CoveMB Jun 5, 2025
46d7354
Add securityContact to ai agent
CoveMB Jun 6, 2025
e9dc412
update changeset
CoveMB Jun 6, 2025
6544073
default empty array tags
CoveMB Jun 6, 2025
6979cde
fix alpha version
CoveMB Jun 6, 2025
b6e8ef9
Use simple documentation(vs key value)
CoveMB Jun 13, 2025
0c4e998
Use simple documentation(vs key value)
CoveMB Jun 13, 2025
dc89af8
Update snapshots
CoveMB Jun 13, 2025
20b9dcf
remove tag from variable name
CoveMB Jun 13, 2025
d964b5a
pluralise printDocumentations
CoveMB Jun 13, 2025
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
6 changes: 6 additions & 0 deletions .changeset/whole-buses-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@openzeppelin/wizard-cairo': patch
---

Add security contact in contract info

7 changes: 7 additions & 0 deletions packages/core/cairo/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import test from 'ava';
import type { BaseFunction, BaseImplementedTrait, Component } from './contract';
import { ContractBuilder } from './contract';
import { printContract } from './print';
import { TAG_SECURITY_CONTACT } from './set-info';

const FOO_COMPONENT: Component = {
name: 'FooComponent',
Expand Down Expand Up @@ -106,3 +107,9 @@ test('contract with sorted use clauses', t => {
Foo.addUseClause('another::library', 'Foo', { alias: 'Custom1' });
t.snapshot(printContract(Foo));
});

test('contract with info', t => {
const Foo = new ContractBuilder('Foo');
Foo.addDocumentationTag(TAG_SECURITY_CONTACT, '[email protected]');
t.snapshot(printContract(Foo));
});
16 changes: 16 additions & 0 deletions packages/core/cairo/src/contract.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ Generated by [AVA](https://avajs.dev).
}␊
}␊
`

## contract with info

> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Contracts for Cairo ^1.0.0␊
/// @custom:security-contact [email protected]
#[starknet::contract]␊
mod Foo {␊
#[storage]␊
struct Storage {␊
}␊
}␊
`
Binary file modified packages/core/cairo/src/contract.test.ts.snap
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/core/cairo/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { toIdentifier } from './utils/convert-strings';

export interface Contract {
license: string;
documentationTags: DocumentationTag[];
name: string;
account: boolean;
useClauses: UseClause[];
Expand Down Expand Up @@ -97,12 +98,19 @@ export interface Argument {
type?: string;
}

export interface DocumentationTag {
key: string;
value: string;
}

export class ContractBuilder implements Contract {
readonly name: string;
readonly account: boolean;
license = 'MIT';
upgradeable = false;

readonly documentationTags: DocumentationTag[] = [];

readonly constructorArgs: Argument[] = [];
readonly constructorCode: string[] = [];

Expand Down Expand Up @@ -298,4 +306,10 @@ export class ContractBuilder implements Contract {
addInterfaceFlag(flag: string): void {
this.interfaceFlagsSet.add(flag);
}

addDocumentationTag(key: string, value: string) {
// eslint-disable-next-line no-useless-escape
if (!/^(@custom:)?[a-z][a-z\-]*$/.exec(key)) throw new Error(`Invalid documentation key: ${key}`);
this.documentationTags.push({ key, value });
}
}
6 changes: 6 additions & 0 deletions packages/core/cairo/src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ContractFunction,
ImplementedTrait,
UseClause,
DocumentationTag,
} from './contract';

import { formatLines, spaceBetween } from './utils/format-lines';
Expand All @@ -29,6 +30,7 @@ export function printContract(contract: Contract): string {
],
printSuperVariables(contract),
[
...printDocumentationTags(contract.documentationTags),
`${contractAttribute}`,
`mod ${contract.name} {`,
spaceBetween(
Expand Down Expand Up @@ -427,3 +429,7 @@ function printArgument(arg: Argument): string {
return `${arg.name}`;
}
}

function printDocumentationTags(tags: DocumentationTag[]): string[] {
return tags.map(({ key, value }) => `/// ${key} ${value}`);
}
9 changes: 8 additions & 1 deletion packages/core/cairo/src/set-info.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import type { ContractBuilder } from './contract';

export const TAG_SECURITY_CONTACT = `@custom:security-contact`;

export const infoOptions = [{}, { license: 'WTFPL' }] as const;

export const defaults: Info = { license: 'MIT' };

export type Info = {
license?: string;
securityContact?: string;
};

export function setInfo(c: ContractBuilder, info: Info): void {
const { license } = info;
const { securityContact, license } = info;

if (securityContact) {
c.addDocumentationTag(TAG_SECURITY_CONTACT, securityContact);
}

if (license) {
c.license = license;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/cairo_alpha/src/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import test from 'ava';
import type { BaseFunction, BaseImplementedTrait, Component } from './contract';
import { ContractBuilder } from './contract';
import { printContract } from './print';
import { TAG_SECURITY_CONTACT } from './set-info';

const FOO_COMPONENT: Component = {
name: 'FooComponent',
Expand Down Expand Up @@ -106,3 +107,9 @@ test('contract with sorted use clauses', t => {
Foo.addUseClause('another::library', 'Foo', { alias: 'Custom1' });
t.snapshot(printContract(Foo));
});

test('contract with info', t => {
const Foo = new ContractBuilder('Foo');
Foo.addDocumentationTag(TAG_SECURITY_CONTACT, '[email protected]');
t.snapshot(printContract(Foo));
});
16 changes: 16 additions & 0 deletions packages/core/cairo_alpha/src/contract.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ Generated by [AVA](https://avajs.dev).
}␊
}␊
`

## contract with info

> Snapshot 1

`// SPDX-License-Identifier: MIT␊
// Compatible with OpenZeppelin Contracts for Cairo ^2.0.0-alpha.1␊
/// @custom:security-contact [email protected]
#[starknet::contract]␊
mod Foo {␊
#[storage]␊
struct Storage {␊
}␊
}␊
`
Binary file modified packages/core/cairo_alpha/src/contract.test.ts.snap
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/core/cairo_alpha/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { toIdentifier } from './utils/convert-strings';

export interface Contract {
license: string;
documentationTags: DocumentationTag[];
name: string;
account: boolean;
useClauses: UseClause[];
Expand Down Expand Up @@ -97,12 +98,19 @@ export interface Argument {
type?: string;
}

export interface DocumentationTag {
key: string;
value: string;
}

export class ContractBuilder implements Contract {
readonly name: string;
readonly account: boolean;
license = 'MIT';
upgradeable = false;

readonly documentationTags: DocumentationTag[] = [];

readonly constructorArgs: Argument[] = [];
readonly constructorCode: string[] = [];

Expand Down Expand Up @@ -298,4 +306,10 @@ export class ContractBuilder implements Contract {
addInterfaceFlag(flag: string): void {
this.interfaceFlagsSet.add(flag);
}

addDocumentationTag(key: string, value: string) {
// eslint-disable-next-line no-useless-escape
if (!/^(@custom:)?[a-z][a-z\-]*$/.exec(key)) throw new Error(`Invalid documentation key: ${key}`);
this.documentationTags.push({ key, value });
}
}
6 changes: 6 additions & 0 deletions packages/core/cairo_alpha/src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ContractFunction,
ImplementedTrait,
UseClause,
DocumentationTag,
} from './contract';

import { formatLines, spaceBetween } from './utils/format-lines';
Expand All @@ -29,6 +30,7 @@ export function printContract(contract: Contract): string {
],
printSuperVariables(contract),
[
...printDocumentationTags(contract.documentationTags),
`${contractAttribute}`,
`mod ${contract.name} {`,
spaceBetween(
Expand Down Expand Up @@ -427,3 +429,7 @@ function printArgument(arg: Argument): string {
return `${arg.name}`;
}
}

function printDocumentationTags(tags: DocumentationTag[]): string[] {
return tags.map(({ key, value }) => `/// ${key} ${value}`);
}
9 changes: 8 additions & 1 deletion packages/core/cairo_alpha/src/set-info.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import type { ContractBuilder } from './contract';

export const TAG_SECURITY_CONTACT = `@custom:security-contact`;

export const infoOptions = [{}, { license: 'WTFPL' }] as const;

export const defaults: Info = { license: 'MIT' };

export type Info = {
license?: string;
securityContact?: string;
};

export function setInfo(c: ContractBuilder, info: Info): void {
const { license } = info;
const { securityContact, license } = info;

if (securityContact) {
c.addDocumentationTag(TAG_SECURITY_CONTACT, securityContact);
}

if (license) {
c.license = license;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/cairo_alpha/src/utils/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const scarbVersion = '2.11.4';
/**
* Semantic version string representing of the minimum compatible version of Contracts to display in output.
*/
export const compatibleContractsSemver = '2.0.0-alpha.1';
export const compatibleContractsSemver = '^2.0.0-alpha.1';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const commonContractFunctionDescription = {
type: 'object',
description: 'Metadata about the contract and author',
properties: {
securityContact: {
type: 'string',
description:
'Email where people can contact you to report security issues. Will only be visible if contract metadata is verified.',
},

license: {
type: 'string',
description: 'The license used by the contract, default is "MIT"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const commonContractFunctionDescription = {
type: 'object',
description: 'Metadata about the contract and author',
properties: {
securityContact: {
type: 'string',
description:
'Email where people can contact you to report security issues. Will only be visible if contract metadata is verified.',
},

license: {
type: 'string',
description: 'The license used by the contract, default is "MIT"',
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/cairo/InfoSection.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { Info } from '@openzeppelin/wizard-cairo';
import { infoDefaults } from '@openzeppelin/wizard-cairo';
import HelpTooltip from '../common/HelpTooltip.svelte';

export let info: Info;
</script>
Expand All @@ -13,6 +14,16 @@
</label>
</h1>

<label class="labeled-input">
<span class="flex justify-between pr-2">
Security Contact
<HelpTooltip>
Where people can contact you to report security issues. Will only be visible if contract metadata is verified.
</HelpTooltip>
</span>
<input bind:value={info.securityContact} placeholder="[email protected]" />
</label>

<label class="labeled-input">
<span>License</span>
<input bind:value={info.license} placeholder={infoDefaults.license} />
Expand Down
Loading