From d6000e80f21e8c3c57bbf9adca4ce92b5aa910f2 Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar <61404772+jeetabhi01@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:53:50 +0530 Subject: [PATCH 01/13] Delete abiBuiltins.ts --- src/passes/abiBuiltins.ts | 65 --------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 src/passes/abiBuiltins.ts diff --git a/src/passes/abiBuiltins.ts b/src/passes/abiBuiltins.ts deleted file mode 100644 index 15d94cf02..000000000 --- a/src/passes/abiBuiltins.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { ExternalReferenceType, FunctionCall, FunctionCallKind } from 'solc-typed-ast'; -import { AST } from '../ast/ast'; -import { ASTMapper } from '../ast/mapper'; -import { TranspileFailedError } from '../utils/errors'; - -/** - * Swap any builtin call to abi.encode | encodePacked | encodeWithSelector | encodeWithSignature - * for a cairo generated one. - * - * Warning: - * - * Special care needs to be taken when encoding addresses since in Ethereum they - * take 20 byte but in Starknet they take the whole felt space. - * An address whose size fits in 20 bytes will have the exact same encoding as - * solidity, but not the same packed encoding. - * - ABI encoding will behave normally since it will have the whole 32 byte slot to - * encode the address, but if tried to decode as an address in Ethereum an exception will - * be thrown since it won't fit in a Solidity address type - * - ABI packed encoding will encode it as 32 bytes instead of the usual 20 bytes, producing - * a different result than solidity in all cases where an address is involved. - */ -export class ABIBuiltins extends ASTMapper { - // Function to add passes that should have been run before this pass - addInitialPassPrerequisites(): void { - const passKeys: Set = new Set([ - 'I', // Implicit conversion to explicit needed to handle literal types (int_const, string_const) - ]); - passKeys.forEach((key) => this.addPassPrerequisite(key)); - } - - visitFunctionCall(node: FunctionCall, ast: AST): void { - if ( - node.kind !== FunctionCallKind.FunctionCall || - node.vFunctionCallType !== ExternalReferenceType.Builtin || - !['decode', 'encodePacked', 'encode', 'encodeWithSelector', 'encodeWithSignature'].includes( - node.vFunctionName, - ) - ) { - return this.visitExpression(node, ast); - } - - let replacement: FunctionCall; - switch (node.vFunctionName) { - case 'decode': - replacement = ast.getUtilFuncGen(node).abi.decode.gen(node.vArguments); - break; - case 'encode': - replacement = ast.getUtilFuncGen(node).abi.encode.gen(node.vArguments); - break; - case 'encodePacked': - replacement = ast.getUtilFuncGen(node).abi.encodePacked.gen(node.vArguments); - break; - case 'encodeWithSelector': - replacement = ast.getUtilFuncGen(node).abi.encodeWithSelector.gen(node.vArguments); - break; - case 'encodeWithSignature': - replacement = ast.getUtilFuncGen(node).abi.encodeWithSignature.gen(node.vArguments); - break; - default: - throw new TranspileFailedError(`Unknown abi function: ${node.vFunctionName}`); - } - ast.replaceNode(node, replacement); - this.visitExpression(node, ast); - } -} From fd5e3d88d678d11eca6e16328e1e00ccdc9ac6f4 Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar <61404772+jeetabhi01@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:54:49 +0530 Subject: [PATCH 02/13] Create abiBuiltins.ts --- src/passes/builtinHandler/abiBuiltins.ts | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/passes/builtinHandler/abiBuiltins.ts diff --git a/src/passes/builtinHandler/abiBuiltins.ts b/src/passes/builtinHandler/abiBuiltins.ts new file mode 100644 index 000000000..15d94cf02 --- /dev/null +++ b/src/passes/builtinHandler/abiBuiltins.ts @@ -0,0 +1,65 @@ +import { ExternalReferenceType, FunctionCall, FunctionCallKind } from 'solc-typed-ast'; +import { AST } from '../ast/ast'; +import { ASTMapper } from '../ast/mapper'; +import { TranspileFailedError } from '../utils/errors'; + +/** + * Swap any builtin call to abi.encode | encodePacked | encodeWithSelector | encodeWithSignature + * for a cairo generated one. + * + * Warning: + * + * Special care needs to be taken when encoding addresses since in Ethereum they + * take 20 byte but in Starknet they take the whole felt space. + * An address whose size fits in 20 bytes will have the exact same encoding as + * solidity, but not the same packed encoding. + * - ABI encoding will behave normally since it will have the whole 32 byte slot to + * encode the address, but if tried to decode as an address in Ethereum an exception will + * be thrown since it won't fit in a Solidity address type + * - ABI packed encoding will encode it as 32 bytes instead of the usual 20 bytes, producing + * a different result than solidity in all cases where an address is involved. + */ +export class ABIBuiltins extends ASTMapper { + // Function to add passes that should have been run before this pass + addInitialPassPrerequisites(): void { + const passKeys: Set = new Set([ + 'I', // Implicit conversion to explicit needed to handle literal types (int_const, string_const) + ]); + passKeys.forEach((key) => this.addPassPrerequisite(key)); + } + + visitFunctionCall(node: FunctionCall, ast: AST): void { + if ( + node.kind !== FunctionCallKind.FunctionCall || + node.vFunctionCallType !== ExternalReferenceType.Builtin || + !['decode', 'encodePacked', 'encode', 'encodeWithSelector', 'encodeWithSignature'].includes( + node.vFunctionName, + ) + ) { + return this.visitExpression(node, ast); + } + + let replacement: FunctionCall; + switch (node.vFunctionName) { + case 'decode': + replacement = ast.getUtilFuncGen(node).abi.decode.gen(node.vArguments); + break; + case 'encode': + replacement = ast.getUtilFuncGen(node).abi.encode.gen(node.vArguments); + break; + case 'encodePacked': + replacement = ast.getUtilFuncGen(node).abi.encodePacked.gen(node.vArguments); + break; + case 'encodeWithSelector': + replacement = ast.getUtilFuncGen(node).abi.encodeWithSelector.gen(node.vArguments); + break; + case 'encodeWithSignature': + replacement = ast.getUtilFuncGen(node).abi.encodeWithSignature.gen(node.vArguments); + break; + default: + throw new TranspileFailedError(`Unknown abi function: ${node.vFunctionName}`); + } + ast.replaceNode(node, replacement); + this.visitExpression(node, ast); + } +} From dd2af93197f63e0f7bc3a9e917604e35a63ce058 Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar <61404772+jeetabhi01@users.noreply.github.com> Date: Sat, 8 Apr 2023 12:32:13 +0530 Subject: [PATCH 03/13] Update test-behaviour.yml --- .github/workflows/test-behaviour.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-behaviour.yml b/.github/workflows/test-behaviour.yml index 44454c495..fbf11eca5 100644 --- a/.github/workflows/test-behaviour.yml +++ b/.github/workflows/test-behaviour.yml @@ -1,6 +1,7 @@ name: Behaviour tests on: + workflow_dispatch: push: branches: - main From bc1eba03faac1b1c0d941fe54414587f429db97b Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar <61404772+jeetabhi01@users.noreply.github.com> Date: Sat, 8 Apr 2023 12:32:30 +0530 Subject: [PATCH 04/13] Update test-cli.yml --- .github/workflows/test-cli.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-cli.yml b/.github/workflows/test-cli.yml index c0d718361..c5b38fba2 100644 --- a/.github/workflows/test-cli.yml +++ b/.github/workflows/test-cli.yml @@ -1,6 +1,7 @@ name: CLI tests on: + workflow_dispatch: push: branches: - main From fcac6a757ba3b46bd85f6e1c80afeb6f8bb0d15a Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar <61404772+jeetabhi01@users.noreply.github.com> Date: Sat, 8 Apr 2023 12:32:51 +0530 Subject: [PATCH 05/13] Update test-semantic.yml --- .github/workflows/test-semantic.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-semantic.yml b/.github/workflows/test-semantic.yml index ae1efbdb0..af3381014 100644 --- a/.github/workflows/test-semantic.yml +++ b/.github/workflows/test-semantic.yml @@ -1,6 +1,7 @@ name: Semantic tests on: + workflow_dispatch: push: branches: - main From b220259cd654e30ad49432e51163d4d53cb983eb Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar <61404772+jeetabhi01@users.noreply.github.com> Date: Sat, 8 Apr 2023 13:01:45 +0530 Subject: [PATCH 06/13] Update abiBuiltins.ts --- src/passes/builtinHandler/abiBuiltins.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/passes/builtinHandler/abiBuiltins.ts b/src/passes/builtinHandler/abiBuiltins.ts index 15d94cf02..219a8e9dd 100644 --- a/src/passes/builtinHandler/abiBuiltins.ts +++ b/src/passes/builtinHandler/abiBuiltins.ts @@ -1,7 +1,7 @@ import { ExternalReferenceType, FunctionCall, FunctionCallKind } from 'solc-typed-ast'; -import { AST } from '../ast/ast'; -import { ASTMapper } from '../ast/mapper'; -import { TranspileFailedError } from '../utils/errors'; +import { AST } from '../../ast/ast'; +import { ASTMapper } from '../../ast/mapper'; +import { TranspileFailedError } from '../../utils/errors'; /** * Swap any builtin call to abi.encode | encodePacked | encodeWithSelector | encodeWithSignature From faf69d8e9ecb5a8bc487bef287587887d20c7475 Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar Date: Sat, 8 Apr 2023 13:51:58 +0530 Subject: [PATCH 07/13] updated relative paths --- src/passes/export.ts | 2 +- src/passes/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/passes/export.ts b/src/passes/export.ts index f62848442..4a312b1ed 100644 --- a/src/passes/export.ts +++ b/src/passes/export.ts @@ -1,4 +1,4 @@ -export * from './abiBuiltins'; +export * from './builtinHandler/abiBuiltins'; export * from './annotateImplicits'; export * from './argBoundChecker'; export * from './builtinHandler/export'; diff --git a/src/passes/index.ts b/src/passes/index.ts index a78768dc7..ec57a0fab 100644 --- a/src/passes/index.ts +++ b/src/passes/index.ts @@ -1,4 +1,4 @@ -export * from './abiBuiltins'; +export * from './builtinHandler/abiBuiltins'; export * from './annotateImplicits'; export * from './argBoundChecker'; export * from './builtinHandler'; From c2c1b861bc582d119d3a400b5ef16101575be77d Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar Date: Tue, 11 Apr 2023 11:36:33 +0530 Subject: [PATCH 08/13] restore yml files --- .github/workflows/test-behaviour.yml | 1 - .github/workflows/test-cli.yml | 1 - .github/workflows/test-semantic.yml | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/workflows/test-behaviour.yml b/.github/workflows/test-behaviour.yml index fbf11eca5..44454c495 100644 --- a/.github/workflows/test-behaviour.yml +++ b/.github/workflows/test-behaviour.yml @@ -1,7 +1,6 @@ name: Behaviour tests on: - workflow_dispatch: push: branches: - main diff --git a/.github/workflows/test-cli.yml b/.github/workflows/test-cli.yml index c5b38fba2..c0d718361 100644 --- a/.github/workflows/test-cli.yml +++ b/.github/workflows/test-cli.yml @@ -1,7 +1,6 @@ name: CLI tests on: - workflow_dispatch: push: branches: - main diff --git a/.github/workflows/test-semantic.yml b/.github/workflows/test-semantic.yml index af3381014..ae1efbdb0 100644 --- a/.github/workflows/test-semantic.yml +++ b/.github/workflows/test-semantic.yml @@ -1,7 +1,6 @@ name: Semantic tests on: - workflow_dispatch: push: branches: - main From 0c8bfafe79edbc1dd1950657ffe53d45c330a2e1 Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar Date: Wed, 12 Apr 2023 10:24:05 +0530 Subject: [PATCH 09/13] Remove abibuiltin pass from transpiler.ts and initialize from builtinHander/index.ts --- src/passes/builtinHandler/index.ts | 1 + src/transpiler.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/passes/builtinHandler/index.ts b/src/passes/builtinHandler/index.ts index 7ac946193..f1381c232 100644 --- a/src/passes/builtinHandler/index.ts +++ b/src/passes/builtinHandler/index.ts @@ -7,6 +7,7 @@ import { ThisKeyword } from './thisKeyword'; import { Ecrecover } from './ecrecover'; import { Keccak } from './keccak'; import { BlockMethods } from './blockMethods'; +import { ABIBuiltins } from './abiBuiltins'; export class BuiltinHandler extends ASTMapper { // Function to add passes that should have been run before this pass diff --git a/src/transpiler.ts b/src/transpiler.ts index 9357917db..925ea0f0b 100644 --- a/src/transpiler.ts +++ b/src/transpiler.ts @@ -4,7 +4,7 @@ import { AST } from './ast/ast'; import { ASTMapper } from './ast/mapper'; import { CairoASTMapping } from './cairoWriter'; import { - ABIBuiltins, + // ABIBuiltins, AnnotateImplicits, ArgBoundChecker, BuiltinHandler, @@ -139,7 +139,7 @@ function applyPasses( ['Vs', VariableDeclarationExpressionSplitter], ['Ntd', NewToDeploy], ['I', ImplicitConversionToExplicit], - ['Abi', ABIBuiltins], + // ['Abi', ABIBuiltins], ['Ev', Events], ['Dh', DeleteHandler], ['Rf', References], From 88c0b424838c79bb3c09473151bb12ddea697a63 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Apr 2023 10:36:27 -0400 Subject: [PATCH 10/13] Bump webpack from 5.73.0 to 5.76.1 in /docs (#992) Bumps [webpack](https://github.com/webpack/webpack) from 5.73.0 to 5.76.1. - [Release notes](https://github.com/webpack/webpack/releases) - [Commits](https://github.com/webpack/webpack/compare/v5.73.0...v5.76.1) --- updated-dependencies: - dependency-name: webpack dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/yarn.lock | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/yarn.lock b/docs/yarn.lock index fb2397c5d..e7196d2d0 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -2266,11 +2266,16 @@ acorn@^6.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.2.tgz#35866fd710528e92de10cf06016498e47e39e1e6" integrity sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ== -acorn@^8.0.4, acorn@^8.4.1, acorn@^8.5.0: +acorn@^8.0.4, acorn@^8.5.0: version "8.8.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w== +acorn@^8.7.1: + version "8.8.2" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a" + integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw== + address@^1.0.1, address@^1.1.2: version "1.2.0" resolved "https://registry.yarnpkg.com/address/-/address-1.2.0.tgz#d352a62c92fee90f89a693eccd2a8b2139ab02d9" @@ -3501,10 +3506,10 @@ end-of-stream@^1.1.0: dependencies: once "^1.4.0" -enhanced-resolve@^5.9.3: - version "5.10.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz#0dc579c3bb2a1032e357ac45b8f3a6f3ad4fb1e6" - integrity sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ== +enhanced-resolve@^5.10.0: + version "5.12.0" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634" + integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -7392,7 +7397,7 @@ wait-on@^6.0.0: minimist "^1.2.5" rxjs "^7.5.4" -watchpack@^2.3.1: +watchpack@^2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.0.tgz#fa33032374962c78113f93c7f2fb4c54c9862a5d" integrity sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg== @@ -7500,20 +7505,20 @@ webpack-sources@^3.2.2, webpack-sources@^3.2.3: integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== webpack@^5.61.0: - version "5.73.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.73.0.tgz#bbd17738f8a53ee5760ea2f59dce7f3431d35d38" - integrity sha512-svjudQRPPa0YiOYa2lM/Gacw0r6PvxptHj4FuEKQ2kX05ZLkjbVc5MnPs6its5j7IZljnIqSVo/OsY2X0IpHGA== + version "5.76.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.76.1.tgz#7773de017e988bccb0f13c7d75ec245f377d295c" + integrity sha512-4+YIK4Abzv8172/SGqObnUjaIHjLEuUasz9EwQj/9xmPPkYJy2Mh03Q/lJfSD3YLzbxy5FeTq5Uw0323Oh6SJQ== dependencies: "@types/eslint-scope" "^3.7.3" "@types/estree" "^0.0.51" "@webassemblyjs/ast" "1.11.1" "@webassemblyjs/wasm-edit" "1.11.1" "@webassemblyjs/wasm-parser" "1.11.1" - acorn "^8.4.1" + acorn "^8.7.1" acorn-import-assertions "^1.7.6" browserslist "^4.14.5" chrome-trace-event "^1.0.2" - enhanced-resolve "^5.9.3" + enhanced-resolve "^5.10.0" es-module-lexer "^0.9.0" eslint-scope "5.1.1" events "^3.2.0" @@ -7526,7 +7531,7 @@ webpack@^5.61.0: schema-utils "^3.1.0" tapable "^2.1.1" terser-webpack-plugin "^5.1.3" - watchpack "^2.3.1" + watchpack "^2.4.0" webpack-sources "^3.2.3" webpackbar@^5.0.2: From e821bc10ef22417569558d4a2e36db330b1243e4 Mon Sep 17 00:00:00 2001 From: Alejandro Labourdette <66191544+AlejandroLabourdette@users.noreply.github.com> Date: Tue, 11 Apr 2023 11:11:46 -0400 Subject: [PATCH 11/13] Refactor on BytesConverter pass (#1005) * refactor * case typo in import * comments * comments on replaceIndexAccessBytesConverter * changes in utils * lint * changes in updateTypeStringBytesConverter * `selectWarplibFunction` receive `typeNode` arguments --- src/passes/bytesConverter.ts | 183 ------------------ src/passes/bytesConverter/index.ts | 21 ++ .../replaceIndexAccessBytesConverter.ts | 80 ++++++++ .../updateTypeStringBytesConverter.ts | 67 +++++++ src/passes/bytesConverter/utils.ts | 47 +++++ 5 files changed, 215 insertions(+), 183 deletions(-) delete mode 100644 src/passes/bytesConverter.ts create mode 100644 src/passes/bytesConverter/index.ts create mode 100644 src/passes/bytesConverter/replaceIndexAccessBytesConverter.ts create mode 100644 src/passes/bytesConverter/updateTypeStringBytesConverter.ts create mode 100644 src/passes/bytesConverter/utils.ts diff --git a/src/passes/bytesConverter.ts b/src/passes/bytesConverter.ts deleted file mode 100644 index d235c0fd3..000000000 --- a/src/passes/bytesConverter.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { - ArrayType, - ElementaryTypeName, - Expression, - FixedBytesType, - generalizeType, - IntType, - PointerType, - TupleType, - VariableDeclaration, - FunctionType, - MappingType, - TypeNameType, - TypeNode, - TypeName, - IndexAccess, - Literal, - BytesType, - StringType, - StringLiteralType, -} from 'solc-typed-ast'; -import { AST } from '../ast/ast'; -import { ASTMapper } from '../ast/mapper'; -import { createCallToFunction } from '../utils/functionGeneration'; -import { generateExpressionTypeString } from '../utils/getTypeString'; -import { typeNameFromTypeNode } from '../utils/utils'; -import { - createNumberLiteral, - createUint8TypeName, - createUint256TypeName, - createArrayTypeName, -} from '../utils/nodeTemplates'; -import { safeGetNodeType } from '../utils/nodeTypeProcessing'; - -/* Convert fixed-size byte arrays (e.g. bytes2, bytes8) to their equivalent unsigned integer. - This pass does not handle dynamically-sized bytes arrays (i.e. bytes). -*/ - -export class BytesConverter extends ASTMapper { - // Function to add passes that should have been run before this pass - addInitialPassPrerequisites(): void { - const passKeys: Set = new Set([]); - passKeys.forEach((key) => this.addPassPrerequisite(key)); - } - - visitExpression(node: Expression, ast: AST): void { - const typeNode = safeGetNodeType(node, ast.inference); - if (typeNode instanceof StringLiteralType) { - return; - } - node.typeString = generateExpressionTypeString(replaceBytesType(typeNode)); - this.commonVisit(node, ast); - } - - visitVariableDeclaration(node: VariableDeclaration, ast: AST): void { - const typeNode = replaceBytesType(safeGetNodeType(node, ast.inference)); - node.typeString = generateExpressionTypeString(typeNode); - this.commonVisit(node, ast); - } - - visitElementaryTypeName(node: ElementaryTypeName, ast: AST): void { - const typeNode = ast.inference.typeNameToTypeNode(node); - if (typeNode instanceof StringType || typeNode instanceof BytesType) { - ast.replaceNode(node, createArrayTypeName(createUint8TypeName(ast), ast)); - return; - } - const replacementTypeNode = replaceBytesType(typeNode); - if (typeNode.pp() !== replacementTypeNode.pp()) { - const typeString = replacementTypeNode.pp(); - node.typeString = typeString; - node.name = typeString; - } - this.commonVisit(node, ast); - } - - visitIndexAccess(node: IndexAccess, ast: AST): void { - if ( - !( - node.vIndexExpression && - generalizeType(safeGetNodeType(node.vBaseExpression, ast.inference))[0] instanceof - FixedBytesType - ) - ) { - this.visitExpression(node, ast); - return; - } - - const baseTypeName = typeNameFromTypeNode( - safeGetNodeType(node.vBaseExpression, ast.inference), - ast, - ); - - const width: string = baseTypeName.typeString.slice(5); - - const indexTypeName = - node.vIndexExpression instanceof Literal - ? createUint256TypeName(ast) - : typeNameFromTypeNode(safeGetNodeType(node.vIndexExpression, ast.inference), ast); - - const stubParams: [string, TypeName][] = [ - ['base', baseTypeName], - ['index', indexTypeName], - ]; - const callArgs = [node.vBaseExpression, node.vIndexExpression]; - if (baseTypeName.typeString !== 'bytes32') { - stubParams.push(['width', createUint8TypeName(ast)]); - callArgs.push(createNumberLiteral(width, ast, 'uint8')); - } - - const importedFunc = ast.registerImport( - node, - 'warplib.maths.bytes_access', - selectWarplibFunction(baseTypeName, indexTypeName), - stubParams, - [['res', createUint8TypeName(ast)]], - ); - - const call = createCallToFunction(importedFunc, callArgs, ast); - ast.replaceNode(node, call, node.parent); - const typeNode = replaceBytesType(safeGetNodeType(call, ast.inference)); - call.typeString = generateExpressionTypeString(typeNode); - this.commonVisit(call, ast); - } - - visitTypeName(node: TypeName, ast: AST): void { - const typeNode = safeGetNodeType(node, ast.inference); - const replacementTypeNode = replaceBytesType(typeNode); - if (typeNode.pp() !== replacementTypeNode.pp()) { - const typeString = replacementTypeNode.pp(); - node.typeString = typeString; - } - this.commonVisit(node, ast); - } -} - -function replaceBytesType(type: TypeNode): TypeNode { - if (type instanceof ArrayType) { - return new ArrayType(replaceBytesType(type.elementT), type.size, type.src); - } else if (type instanceof FixedBytesType) { - return new IntType(type.size * 8, false, type.src); - } else if (type instanceof FunctionType) { - return new FunctionType( - type.name, - type.parameters.map(replaceBytesType), - type.returns.map(replaceBytesType), - type.visibility, - type.mutability, - type.implicitFirstArg, - type.src, - ); - } else if (type instanceof MappingType) { - return new MappingType( - replaceBytesType(type.keyType), - replaceBytesType(type.valueType), - type.src, - ); - } else if (type instanceof PointerType) { - return new PointerType(replaceBytesType(type.to), type.location, type.kind, type.src); - } else if (type instanceof TupleType) { - return new TupleType(type.elements.map(replaceBytesType), type.src); - } else if (type instanceof TypeNameType) { - return new TypeNameType(replaceBytesType(type.type), type.src); - } else if (type instanceof BytesType) { - return new ArrayType(new IntType(8, false, type.src), undefined, type.src); - } else if (type instanceof StringType) { - return new ArrayType(new IntType(8, false, type.src), undefined, type.src); - } else { - return type; - } -} - -function selectWarplibFunction(baseTypeName: TypeName, indexTypeName: TypeName): string { - if (indexTypeName.typeString === 'uint256' && baseTypeName.typeString === 'bytes32') { - return 'byte256_at_index_uint256'; - } - if (indexTypeName.typeString === 'uint256') { - return 'byte_at_index_uint256'; - } - if (baseTypeName.typeString === 'bytes32') { - return 'byte256_at_index'; - } - return 'byte_at_index'; -} diff --git a/src/passes/bytesConverter/index.ts b/src/passes/bytesConverter/index.ts new file mode 100644 index 000000000..f43920bf6 --- /dev/null +++ b/src/passes/bytesConverter/index.ts @@ -0,0 +1,21 @@ +import { AST } from '../../ast/ast'; +import { ASTMapper } from '../../ast/mapper'; +import { ReplaceIndexAccessBytesConverter } from './replaceIndexAccessBytesConverter'; +import { UpdateTypeStringBytesConverter } from './updateTypeStringBytesConverter'; + +/* Convert fixed-size byte arrays (e.g. bytes2, bytes8) to their equivalent unsigned integer. + This pass does not handle dynamically-sized bytes arrays (i.e. bytes). +*/ +export class BytesConverter extends ASTMapper { + // Function to add passes that should have been run before this pass + addInitialPassPrerequisites(): void { + const passKeys: Set = new Set([]); + passKeys.forEach((key) => this.addPassPrerequisite(key)); + } + + static map(ast: AST): AST { + ast = ReplaceIndexAccessBytesConverter.map(ast); + ast = UpdateTypeStringBytesConverter.map(ast); + return ast; + } +} diff --git a/src/passes/bytesConverter/replaceIndexAccessBytesConverter.ts b/src/passes/bytesConverter/replaceIndexAccessBytesConverter.ts new file mode 100644 index 000000000..28e474e5a --- /dev/null +++ b/src/passes/bytesConverter/replaceIndexAccessBytesConverter.ts @@ -0,0 +1,80 @@ +import { + FixedBytesType, + generalizeType, + TypeName, + IndexAccess, + Literal, + IntType, + TypeNode, +} from 'solc-typed-ast'; +import { AST } from '../../ast/ast'; +import { ASTMapper } from '../../ast/mapper'; +import { createCallToFunction } from '../../utils/functionGeneration'; +import { generateExpressionTypeString } from '../../utils/getTypeString'; +import { typeNameFromTypeNode } from '../../utils/utils'; +import { + createNumberLiteral, + createUint8TypeName, + createUint256TypeName, +} from '../../utils/nodeTemplates'; +import { safeGetNodeType } from '../../utils/nodeTypeProcessing'; +import { replaceBytesType } from './utils'; + +export class ReplaceIndexAccessBytesConverter extends ASTMapper { + visitIndexAccess(node: IndexAccess, ast: AST): void { + const baseNodeType = safeGetNodeType(node.vBaseExpression, ast.inference); + const baseExprType = generalizeType(baseNodeType)[0]; + if (node.vIndexExpression === undefined || !(baseExprType instanceof FixedBytesType)) { + this.visitExpression(node, ast); + return; + } + const baseTypeName = typeNameFromTypeNode(baseNodeType, ast); + + const indexNodeType = safeGetNodeType(node.vIndexExpression, ast.inference); + const indexTypeName = + node.vIndexExpression instanceof Literal + ? createUint256TypeName(ast) + : typeNameFromTypeNode(indexNodeType, ast); + + const stubParams: [string, TypeName][] = [ + ['base', baseTypeName], + ['index', indexTypeName], + ]; + const callArgs = [node.vBaseExpression, node.vIndexExpression]; + if (baseExprType.size !== 32) { + stubParams.push(['width', createUint8TypeName(ast)]); + callArgs.push(createNumberLiteral(baseExprType.size, ast, 'uint8')); + } + + const importedFunc = ast.registerImport( + node, + 'warplib.maths.bytes_access', + selectWarplibFunction(baseExprType, indexNodeType), + stubParams, + [['res', createUint8TypeName(ast)]], + ); + + const call = createCallToFunction(importedFunc, callArgs, ast); + ast.replaceNode(node, call, node.parent); + const callNodeType = replaceBytesType(safeGetNodeType(call, ast.inference)); + call.typeString = generateExpressionTypeString(callNodeType); + this.commonVisit(call, ast); + } +} + +function selectWarplibFunction(baseType: TypeNode, indexType: TypeNode): string { + const isIndexUint256 = + indexType instanceof IntType && indexType.signed === false && indexType.nBits === 256; + const isBaseBytes32 = baseType instanceof FixedBytesType && baseType.size === 32; + + if (isIndexUint256 && isBaseBytes32) { + return 'byte256_at_index_uint256'; + } + if (isIndexUint256) { + return 'byte_at_index_uint256'; + } + if (isBaseBytes32) { + return 'byte256_at_index'; + } + return 'byte_at_index'; +} diff --git a/src/passes/bytesConverter/updateTypeStringBytesConverter.ts b/src/passes/bytesConverter/updateTypeStringBytesConverter.ts new file mode 100644 index 000000000..b2cc2e7c6 --- /dev/null +++ b/src/passes/bytesConverter/updateTypeStringBytesConverter.ts @@ -0,0 +1,67 @@ +import { + ElementaryTypeName, + Expression, + VariableDeclaration, + TypeName, + BytesType, + StringType, + StringLiteralType, +} from 'solc-typed-ast'; +import { AST } from '../../ast/ast'; +import { ASTMapper } from '../../ast/mapper'; +import { generateExpressionTypeString } from '../../utils/getTypeString'; +import { createUint8TypeName, createArrayTypeName } from '../../utils/nodeTemplates'; +import { safeGetNodeType } from '../../utils/nodeTypeProcessing'; +import { replaceBytesType } from './utils'; + +/* Convert fixed-size byte arrays (e.g. bytes2, bytes8) to their equivalent unsigned integer. + This pass does not handle dynamically-sized bytes arrays (i.e. bytes). +*/ + +export class UpdateTypeStringBytesConverter extends ASTMapper { + // Function to add passes that should have been run before this pass + addInitialPassPrerequisites(): void { + const passKeys: Set = new Set([]); + passKeys.forEach((key) => this.addPassPrerequisite(key)); + } + + visitExpression(node: Expression, ast: AST): void { + const typeNode = safeGetNodeType(node, ast.inference); + if (typeNode instanceof StringLiteralType) { + return; + } + node.typeString = generateExpressionTypeString(replaceBytesType(typeNode)); + this.commonVisit(node, ast); + } + + visitVariableDeclaration(node: VariableDeclaration, ast: AST): void { + const typeNode = replaceBytesType(safeGetNodeType(node, ast.inference)); + node.typeString = generateExpressionTypeString(typeNode); + this.commonVisit(node, ast); + } + + visitElementaryTypeName(node: ElementaryTypeName, ast: AST): void { + const typeNode = ast.inference.typeNameToTypeNode(node); + if (typeNode instanceof StringType || typeNode instanceof BytesType) { + ast.replaceNode(node, createArrayTypeName(createUint8TypeName(ast), ast)); + return; + } + const replacementTypeNode = replaceBytesType(typeNode); + if (typeNode.pp() !== replacementTypeNode.pp()) { + const typeString = generateExpressionTypeString(replacementTypeNode); + node.typeString = typeString; + node.name = typeString; + } + this.commonVisit(node, ast); + } + + visitTypeName(node: TypeName, ast: AST): void { + const typeNode = safeGetNodeType(node, ast.inference); + const replacementTypeNode = replaceBytesType(typeNode); + if (typeNode.pp() !== replacementTypeNode.pp()) { + const typeString = replacementTypeNode.pp(); + node.typeString = typeString; + } + this.commonVisit(node, ast); + } +} diff --git a/src/passes/bytesConverter/utils.ts b/src/passes/bytesConverter/utils.ts new file mode 100644 index 000000000..8385a96ec --- /dev/null +++ b/src/passes/bytesConverter/utils.ts @@ -0,0 +1,47 @@ +import { + ArrayType, + FixedBytesType, + IntType, + PointerType, + TupleType, + FunctionType, + MappingType, + TypeNameType, + TypeNode, + BytesType, + StringType, +} from 'solc-typed-ast'; + +export function replaceBytesType(type: TypeNode): TypeNode { + if (type instanceof ArrayType) { + return new ArrayType(replaceBytesType(type.elementT), type.size, type.src); + } else if (type instanceof FixedBytesType) { + return new IntType(type.size * 8, false, type.src); + } else if (type instanceof FunctionType) { + return new FunctionType( + type.name, + type.parameters.map(replaceBytesType), + type.returns.map(replaceBytesType), + type.visibility, + type.mutability, + type.implicitFirstArg, + type.src, + ); + } else if (type instanceof MappingType) { + return new MappingType( + replaceBytesType(type.keyType), + replaceBytesType(type.valueType), + type.src, + ); + } else if (type instanceof PointerType) { + return new PointerType(replaceBytesType(type.to), type.location, type.kind, type.src); + } else if (type instanceof TupleType) { + return new TupleType(type.elements.map(replaceBytesType), type.src); + } else if (type instanceof TypeNameType) { + return new TypeNameType(replaceBytesType(type.type), type.src); + } else if (type instanceof BytesType || type instanceof StringType) { + return new ArrayType(new IntType(8, false, type.src), undefined, type.src); + } else { + return type; + } +} From c5f162f5c32796f8a9c0f46600982cc146caf951 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Wed, 12 Apr 2023 09:42:31 -0400 Subject: [PATCH 12/13] Fix readme pr (#1008) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test2 * discordbadgeee * added discord and twitter badges * created installation.md * created contributing.md * Rename contributing.md to contributingg.md * Update readme.md * Update and rename contributingg.md to contributing, devloping tips and testing.md * Update readme.md * Rename contributing, devloping tips and testing.md to Contributing and testing.md * Rename Contributing and testing.md to Contributing.md * Update readme.md * Update readme.md * Merge Contributing.md and CONTRIBUTING.md * Contributing.md -> contributing.md * Fix links * Add note * Update readmesssss * Some fixes * Changes * Update contributing.md Co-authored-by: Jorik Schellekens * Update contributing.md Co-authored-by: Jorik Schellekens * Update contributing.md * More changes" * Behaviour Co-authored-by: Piotr Piwoński * Behaviour II Co-authored-by: Piotr Piwoński * remove rogue ñ Co-authored-by: Piotr Piwoński * generic path Co-authored-by: Piotr Piwoński * Minor update to contributing * Update readme * interpreted modes Co-authored-by: Piotr Piwoński * Update contributing.md Co-authored-by: Piotr Piwoński * Update contributing.md Co-authored-by: Piotr Piwoński * Update contributing.md * fixes * in a separate terminal Co-authored-by: Carmen Irene Cabrera Rodríguez <49727740+cicr99@users.noreply.github.com> --------- Co-authored-by: coeuskoalemoss Co-authored-by: Siddhi kommuri <84127077+coeuskoalemoss@users.noreply.github.com> Co-authored-by: Jorik Schellekens Co-authored-by: Piotr Piwoński Co-authored-by: Carmen Irene Cabrera Rodríguez <49727740+cicr99@users.noreply.github.com> --- CONTRIBUTING.md | 22 ----- contributing.md | 153 ++++++++++++++++++++++++++++++++++ dependencies.md | 52 ++++++++++++ installation.md | 35 ++++++++ readme.md | 216 ++---------------------------------------------- 5 files changed, 248 insertions(+), 230 deletions(-) delete mode 100644 CONTRIBUTING.md create mode 100644 contributing.md create mode 100644 dependencies.md create mode 100644 installation.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 13222a95a..000000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,22 +0,0 @@ -# Contributing - -You can contribute to Warp by raising issues and PRs. Simply filing issues for problems you encounter is a great way to contribute. Contributing implementations is greatly appreciated. - -## DOs and DON'Ts - -Please do: - -- **DO** give priority to the current style of the project or file you're changing even if it diverges from the general guidelines. -- **DO** include tests for both, new features and bug fixes -- **DO** keep the discussions focused on the initial topic - -Please do not: - -- **DON'T** raise PRs with style changes -- **DON'T** surprise us with big pull requests. It's better to first raise it as an issue and have it discussed -- **DON'T** commit code that you didn't author. This may breach IP -- **DON'T** submit PRs that alter licensing, contributing guide lines or code of conduct - -## PR - CI Process - -The project uses GitHub Actions to build its artifacts and run tests. We do our best to keep the suite fast and stable. For incoming PRs, builds and test runs must be clean. diff --git a/contributing.md b/contributing.md new file mode 100644 index 000000000..95a44dabe --- /dev/null +++ b/contributing.md @@ -0,0 +1,153 @@ +# Contributing + +You can contribute to Warp by raising issues and PRs. Simply filing issues for problems you encounter is a great way to contribute. Contributing implementations is greatly appreciated. + +## DOs and DON'Ts + +Please do: + +- **DO** give priority to the current style of the project or file you're changing even if it diverges from the general guidelines. +- **DO** include tests for both, new features and bug fixes +- **DO** keep the discussions focused on the initial topic + +Please do not: + +- **DON'T** raise PRs with style changes +- **DON'T** surprise us with big pull requests. It's better to first raise it as an issue and have it discussed +- **DON'T** commit code that you didn't author. This may breach IP +- **DON'T** submit PRs that alter licensing, contributing guide lines or code of conduct + +## Installation + +First, please make sure you have all the required external [dependencies](dependencies.md) installed. + +Then, with a Python3.9 virtual environment activated, perform the following instructions: + +1. Clone this repo and change directory into the `warp` folder. + +2. Install the JavaScript dependencies: + +```bash +yarn +``` + +3. Install the Python dependencies: + +```bash +pip install -r requirements.txt +``` + +If you are using a M1 chipped Mac and getting a `'gmp.h' file not found` error when installing Cairo run the following: + +```bash +CFLAGS=-I`brew --prefix gmp`/include LDFLAGS=-L`brew --prefix gmp`/lib pip install ecdsa fastecdsa sympy +``` + +Then run the pip command above again. + +4. Compile the project: + +```bash +yarn build +``` + +5. Compile Warp libraries + +```bash +yarn warplib +``` + +6. Test the installation worked by transpiling an example ERC20 contract: + +```bash +bin/warp transpile exampleContracts/ERC20.sol +``` + +## First steps :feet: + +To look what features we are currently working on or tasks that are pending to do, please checkout the [project on github](https://github.com/orgs/NethermindEth/projects/30/views/3). + +## Developing tips :honey_pot: + +It can be tedious to manually recompile the project after every minor change. You can automate the process of recompiling by executing the following command in a separate terminal: + +```bash +yarn dev +``` + +Alternatively to `yarn dev` you can run typescript in interpreted mode to achieve the same. This is an example using `transpile` command: + +```bash +npx ts-node src transpile example_contracts/ERC20.sol +``` + +### Testing for contributors :stethoscope: + +Warp includes three sets of tests: + +- Compilation Tests: These tests ensure that transpiled contracts are valid Cairo code. + +- Behaviour Tests: These tests verify the correct functionality of transpiled contracts. + +- Semantic Tests: These tests involve transpiling Solidity's semantic tests and checking that the runtime behaviour remains consistent. + +#### Compilation Tests + +Start by running the compilation tests to verify that your contribution doesn't break any fundamental features. These tests are also the quickest to execute. + +```bash +yarn test:examples +``` + +#### Behaviour Tests + +Behaviour tests involve transpiling a set of Solidity contracts and deploying them to a testnet. Each deployed contract undergoes testing for all of its runtime functionality. + +1. Run the setup script (Required only once): + +```bash +tests/behaviour/setup.sh +``` + +2. In a separate terminal, start a StarkNet testnet server (make sure cairo-lang is installed in the environment): + +```bash +yarn testnet +``` + +3. Run the tests: + +```bash +yarn test +``` + +
+ +To generate benchmarks locally during development: + +```bash +yarn testnet:benchmark +yarn test +``` + +```python +python starknet-testnet/generateMarkdown.py +``` + +This saves the benchmarks at `benchmark/stats/data.md` + +#### Semantic Tests + +Semantic tests involve transpiling each of Solidity's behaviour tests and deploying them. Each test is executed, and its result is compared to the output of its Solidity counterpart. + +Execute instructions _1_ and _2_ from [Behaviour Tests](#behaviour-tests) if you haven't already. Then: + +3. Run semantic tests: + +```bash +yarn test:semantic +``` + +## PR - CI Process + +The project uses GitHub Actions to build its artifacts and run tests. We do our best to keep the suite fast and stable. For incoming PRs, builds and test runs must be clean. diff --git a/dependencies.md b/dependencies.md new file mode 100644 index 000000000..46820f321 --- /dev/null +++ b/dependencies.md @@ -0,0 +1,52 @@ +# Dependencies + +1. You will need [z3](https://github.com/Z3Prover/z3) and [gmp](https://gmplib.org/#DOWNLOAD) + installed to use Warp. + +- Install command on macOS: + +```bash +brew install z3 gmp +``` + +If you're on an arm based Apple machine (m1/m2 mac) you'll need to install `gmp` and export some +environment variables + +``` +export CFLAGS=-I`brew --prefix gmp`/include +export LDFLAGS=-L`brew --prefix gmp`/lib +``` + +- Install command on Ubuntu: + +```bash +sudo apt install libz3-dev libgmp3-dev +``` + +2. Install Python3.9 with dev dependencies (`python3.9 python3.9-venv python3.9-dev`) into your base env. + If you do not have the dev dependencies installed the installation will fail. +
+ +- Install commands on MacOS: + +```bash +brew install python@3.9 +``` + +With python3.9 already installed you have venv covered: + +> If you are using Python 3.3 or newer (...) venv is included in the Python standard library and requires no additional installation. + +Then you can install dev package using pip: + +```bash +pip install python-dev-tools +``` + +- Install commands on Ubuntu: + +```bash +sudo apt install python3.9 python3.9-venv python3.9-dev +``` + +Or you can just install python3.9 and then install python-dev-tools using pip. diff --git a/installation.md b/installation.md new file mode 100644 index 000000000..b36de0c91 --- /dev/null +++ b/installation.md @@ -0,0 +1,35 @@ +# Installation + +The first step is to make sure you have all required external [dependencies](dependencies.md) installed. + +Then perform the following instructions in order: + +1. Add the warp package from npm. + +```bash +yarn global add @nethermindeth/warp +``` + +2. Ensure the package was added by checking the version number: + +```bash +warp version +``` + +3. Install the dependencies: + +```bash +warp install --verbose +``` + +Use the `--python` flag to pass the path to `python3.9` binary, if the above command complains. + +```bash +warp install --python --verbose +``` + +4. Test the installation worked by transpiling an example ERC20 contract: + +```bash +warp transpile +``` diff --git a/readme.md b/readme.md index 64e356efa..c9d610fe9 100644 --- a/readme.md +++ b/readme.md @@ -5,12 +5,14 @@ Warp brings Solidity to Starknet, making it possible to transpile Ethereum smart contracts to Starknet Cairo Contracts. +:warning: **Note**: Cairo 1 support is being developed at this [branch](https://github.com/NethermindEth/warp/tree/cairo-1.0). + ## Quickstart Docker compose provides a ready to use environment featuring warp and devnet. > **Note:** -> Execute Warp using Docker works only for x86 architecture, x64 architectures will be supported soon. +> Executing Warp using Docker works only for x86 architecture, ARM architectures (such as Apple's M1) will be supported soon. ### Build and run containers @@ -39,138 +41,9 @@ You can read the documentation [here](https://nethermindeth.github.io/warp/). ## Installation :gear: -### Dependencies - -
- -1. You will need [z3](https://github.com/Z3Prover/z3) and [gmp](https://gmplib.org/#DOWNLOAD) - installed to use Warp. - -- Install command on macOS: -```bash -brew install z3 gmp -``` - -If you're on an arm based Apple machine (m1/m2 mac) you'll need to install `gmp` and export some -environment variables - -``` -export CFLAGS=-I`brew --prefix gmp`/include -export LDFLAGS=-L`brew --prefix gmp`/lib -``` - -- Install command on Ubuntu: - -```bash -sudo apt install libz3-dev libgmp3-dev -``` - -2. Install Python3.9 with dev dependencies (`python3.9 python3.9-venv python3.9-dev`) into your base env. - If you do not have the dev dependencies installed the installation will fail. -
- -- Install commands on MacOS: - -```bash -brew install python@3.9 -``` - -With python3.9 already installed you have venv covered: - -> If you are using Python 3.3 or newer (...) venv is included in the Python standard library and requires no additional installation. - -Then you can install dev package using pip: - -```bash -pip install python-dev-tools -``` - -- Install commands on Ubuntu: - -```bash -sudo apt install python3.9 python3.9-venv python3.9-dev -``` - -Or you can just install python3.9 and then install python-dev-tools using pip. - -### Warp Installation Method 1: - -
-Without any virtual environment activated perform the following in order: - -1. Add the warp package from npm. - -```bash -yarn global add @nethermindeth/warp -``` - -2. Ensure the package was added by checking the version number: - -```bash -warp version -``` - -3. Install the dependencies: - -```bash -warp install --verbose -``` - -Use the `--python` flag to pass the path to `python3.9` binary, if the above command complains. +To install Warp follow the installation instructions [here](installation.md). -```bash -warp install --python --verbose -``` - -4. Test the installation worked by transpiling an example ERC20 contract: - -```bash -warp transpile exampleContracts/ERC20.sol -``` - -
- -### Warp Installation Method 2 (from source/for devs): - -
- -Make sure you have the [dependencies](#dependencies) installed first. - -With a virtual environment (recommended Python3.9) activated: - -1. Clone this repo and change directory into the `warp` folder. - -2. Install the JavaScript dependencies: - -```bash -yarn -``` - -3. Install the Python dependencies: - -```bash -pip install -r requirements.txt -``` - -If you are using a M1 chipped Mac and getting a `'gmp.h' file not found` error when installing Cairo run the following: - -```bash -CFLAGS=-I`brew --prefix gmp`/include LDFLAGS=-L`brew --prefix gmp`/lib pip install ecdsa fastecdsa sympy -``` - -Then run the pip command above again. - -4. Compile the project: - -```bash -yarn warplib -``` - -5. Test the installation worked by transpiling an example ERC20 contract: - -```bash -bin/warp transpile exampleContracts/ERC20.sol -``` +To build Warp for development see the [contributing guidelines](contributing.md). ## Usage :computer: @@ -280,7 +153,7 @@ Note: We have changed the return of `ecrecover` to be `uint160` because we use t ## Docker :whale: > **Note:** -> Execute Warp using Docker works only for x86 architecture, x64 architectures will be supported soon. +> Executing Warp using Docker works only for x86 architecture, ARM architectures (such as Apple's M1) will be supported soon. Build the image from source: @@ -296,81 +169,8 @@ docker run --rm -v $PWD:/dapp --user $(id -u):$(id -g) warp transpile exampleCon ## Contributing -### First steps :feet: - -If you like to contribute, the first step is to install Warp from source for devs [steps here](#warp-installation-method-2-from-sourcefor-devs) - -To look what features we are currently working on or tasks that are pending to do, please checkout the project on github [here](https://github.com/orgs/NethermindEth/projects/30/views/3) - -Also, please take a look through our [Contribution Guidelines](CONTRIBUTING.md) - -### Developing tips :honey_pot: - -While developing your code, remembering to compile the project every time some minor changes are applied could be annoying. You could start a process that watch for changes and automatically recompile it. - -In a separate terminal execute: - -```bash -yarn dev -``` - -Developers could run warp instructions using docker. This is an example using `transpile` command: - -```bash -docker-compose exec warp npx ts-node src transpile exampleContracts/ERC20.sol -``` - -### Testing for contributors :stethoscope: - -To test that your contribution doesn't break any features you can test that all previous example contracts transpile and then cairo compile by running the following: - -```bash -yarn test:examples -``` - -For this to work, you must have the cairo-lang package installed. -To test try: - -```bash -starknet-compile -v -``` - -Instructions to set this up can be found at -https://www.cairo-lang.org/docs/quickstart.html - -Then to see that your contribution doesn't break the behaviour tests follow these steps: - -1. Run the setup script: - -```bash -tests/behaviour/setup.sh -``` - -2. In a separate terminal, start a Starknet testnet server (in an environment with cairo-lang installed): - -```bash -yarn testnet -``` - -3. Run the tests: - -```bash -yarn test -``` - -To generate benchmarks locally during development: - -```bash -yarn testnet:benchmark -yarn test -``` - -```python -python starknet-testnet/generateMarkdown.py -``` - -This saves the benchmarks at `benchmark/stats/data.md` +You can read about contributing, first steps, development tips and testing for contributors [here](contributing.md) ## Contact Us :phone: -If you run into any problems please raise an issue or contact us on our Nethermind discord server: https://discord.com/invite/PaCMRFdvWT +[![Discord](https://img.shields.io/badge/discord-0A66C2?style=for-the-badge&logo=Discord&logoColor=white)](https://discord.com/invite/PaCMRFdvWT) [![twitter](https://img.shields.io/badge/twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white)](https://twitter.com/nethermindeth) From 6d664e02102270cba6765a24ee74d6decc05ea07 Mon Sep 17 00:00:00 2001 From: Abhijeet Khopkar Date: Thu, 13 Apr 2023 20:23:22 +0530 Subject: [PATCH 13/13] Add pass in map function --- src/passes/builtinHandler/index.ts | 1 + src/passes/export.ts | 1 - src/passes/index.ts | 1 - src/transpiler.ts | 2 -- 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/passes/builtinHandler/index.ts b/src/passes/builtinHandler/index.ts index f1381c232..01b8b3797 100644 --- a/src/passes/builtinHandler/index.ts +++ b/src/passes/builtinHandler/index.ts @@ -24,6 +24,7 @@ export class BuiltinHandler extends ASTMapper { ast = ExplicitConversionToFunc.map(ast); ast = MathsOperationToFunction.map(ast); ast = ThisKeyword.map(ast); + ast = ABIBuiltins.map(ast); return ast; } } diff --git a/src/passes/export.ts b/src/passes/export.ts index 4a312b1ed..0700e9308 100644 --- a/src/passes/export.ts +++ b/src/passes/export.ts @@ -1,4 +1,3 @@ -export * from './builtinHandler/abiBuiltins'; export * from './annotateImplicits'; export * from './argBoundChecker'; export * from './builtinHandler/export'; diff --git a/src/passes/index.ts b/src/passes/index.ts index ec57a0fab..fd26b0720 100644 --- a/src/passes/index.ts +++ b/src/passes/index.ts @@ -1,4 +1,3 @@ -export * from './builtinHandler/abiBuiltins'; export * from './annotateImplicits'; export * from './argBoundChecker'; export * from './builtinHandler'; diff --git a/src/transpiler.ts b/src/transpiler.ts index 925ea0f0b..893792cfb 100644 --- a/src/transpiler.ts +++ b/src/transpiler.ts @@ -4,7 +4,6 @@ import { AST } from './ast/ast'; import { ASTMapper } from './ast/mapper'; import { CairoASTMapping } from './cairoWriter'; import { - // ABIBuiltins, AnnotateImplicits, ArgBoundChecker, BuiltinHandler, @@ -139,7 +138,6 @@ function applyPasses( ['Vs', VariableDeclarationExpressionSplitter], ['Ntd', NewToDeploy], ['I', ImplicitConversionToExplicit], - // ['Abi', ABIBuiltins], ['Ev', Events], ['Dh', DeleteHandler], ['Rf', References],