From 102bc4ad909141eda842a6536fbd6e2e48da9e98 Mon Sep 17 00:00:00 2001 From: rodrigo-pino Date: Fri, 24 May 2024 10:14:40 +0000 Subject: [PATCH] deploy: d06219608da1516ec3531e72762c32051034603f --- 404.html | 4 ++-- assets/js/{843649a7.657ac262.js => 843649a7.5af18e1a.js} | 2 +- assets/js/{899184d6.d82424a2.js => 899184d6.3b2ded1d.js} | 2 +- assets/js/935f2afb.24285ccd.js | 1 - assets/js/935f2afb.7908caf6.js | 1 + assets/js/b2cbc7f8.8632e5ac.js | 1 - assets/js/b2cbc7f8.e0007bd0.js | 1 + ...runtime~main.c3cc8bb5.js => runtime~main.9e3ef53f.js} | 2 +- docs/category/vm---extras.html | 4 ++-- docs/category/vm---fundamentals.html | 6 +++--- docs/intro.html | 4 ++-- docs/vm-extras/resources.html | 4 ++-- docs/vm-extras/runner.html | 4 ++-- docs/vm-fundamentals/builtins.html | 9 +++++---- docs/vm-fundamentals/hints.html | 6 +++--- docs/vm-fundamentals/instructions.html | 6 +++--- docs/vm-fundamentals/intro.html | 6 +++--- docs/vm-fundamentals/layout.html | 6 +++--- index.html | 4 ++-- markdown-page.html | 4 ++-- 20 files changed, 39 insertions(+), 38 deletions(-) rename assets/js/{843649a7.657ac262.js => 843649a7.5af18e1a.js} (63%) rename assets/js/{899184d6.d82424a2.js => 899184d6.3b2ded1d.js} (87%) delete mode 100644 assets/js/935f2afb.24285ccd.js create mode 100644 assets/js/935f2afb.7908caf6.js delete mode 100644 assets/js/b2cbc7f8.8632e5ac.js create mode 100644 assets/js/b2cbc7f8.e0007bd0.js rename assets/js/{runtime~main.c3cc8bb5.js => runtime~main.9e3ef53f.js} (93%) diff --git a/404.html b/404.html index fc6c8acdd..2a11eda09 100644 --- a/404.html +++ b/404.html @@ -4,13 +4,13 @@ Page Not Found | Cairo-VM in Go - +
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

- + \ No newline at end of file diff --git a/assets/js/843649a7.657ac262.js b/assets/js/843649a7.5af18e1a.js similarity index 63% rename from assets/js/843649a7.657ac262.js rename to assets/js/843649a7.5af18e1a.js index 8f9202bad..237fdc808 100644 --- a/assets/js/843649a7.657ac262.js +++ b/assets/js/843649a7.5af18e1a.js @@ -1 +1 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[227],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>d});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var c=r.createContext({}),l=function(e){var t=r.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},u=function(e){var t=l(e.components);return r.createElement(c.Provider,{value:t},e.children)},p="mdxType",f={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,c=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),p=l(n),m=a,d=p["".concat(c,".").concat(m)]||p[m]||f[m]||o;return n?r.createElement(d,i(i({ref:t},u),{},{components:n})):r.createElement(d,i({ref:t},u))}));function d(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[p]="string"==typeof e?e:a,i[1]=s;for(var l=2;l{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>f,frontMatter:()=>o,metadata:()=>s,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={sidebar_position:3},i="Hints",s={unversionedId:"vm-fundamentals/hints",id:"vm-fundamentals/hints",title:"Hints",description:"There are several hints, explain each of them here. How they interact with the VM and affects it.",source:"@site/docs/vm-fundamentals/hints.md",sourceDirName:"vm-fundamentals",slug:"/vm-fundamentals/hints",permalink:"/docs/vm-fundamentals/hints",draft:!1,editUrl:"https://github.com/NethermindEth/cairo-vm-go/tree/main/docs/docs/vm-fundamentals/hints.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"Builtins",permalink:"/docs/vm-fundamentals/builtins"},next:{title:"VM - Extras",permalink:"/docs/category/vm---extras"}},c={},l=[],u={toc:l},p="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"hints"},"Hints"),(0,a.kt)("p",null,"There are several hints, explain each of them here. How they interact with the VM and affects it."))}f.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[227],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>d});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=r.createContext({}),l=function(e){var t=r.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},u=function(e){var t=l(e.components);return r.createElement(s.Provider,{value:t},e.children)},p="mdxType",f={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,o=e.originalType,s=e.parentName,u=c(e,["components","mdxType","originalType","parentName"]),p=l(n),m=a,d=p["".concat(s,".").concat(m)]||p[m]||f[m]||o;return n?r.createElement(d,i(i({ref:t},u),{},{components:n})):r.createElement(d,i({ref:t},u))}));function d(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=n.length,i=new Array(o);i[0]=m;var c={};for(var s in t)hasOwnProperty.call(t,s)&&(c[s]=t[s]);c.originalType=e,c[p]="string"==typeof e?e:a,i[1]=c;for(var l=2;l{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>i,default:()=>f,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var r=n(7462),a=(n(7294),n(3905));const o={sidebar_position:3},i="Hints",c={unversionedId:"vm-fundamentals/hints",id:"vm-fundamentals/hints",title:"Hints",description:"There are several hints, explain each of them here. How they interact with the VM and affects it.",source:"@site/docs/vm-fundamentals/hints.md",sourceDirName:"vm-fundamentals",slug:"/vm-fundamentals/hints",permalink:"/docs/vm-fundamentals/hints",draft:!1,editUrl:"https://github.com/NethermindEth/cairo-vm-go/tree/main/docs/docs/vm-fundamentals/hints.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"Builtins Documentation",permalink:"/docs/vm-fundamentals/builtins"},next:{title:"VM - Extras",permalink:"/docs/category/vm---extras"}},s={},l=[],u={toc:l},p="wrapper";function f(e){let{components:t,...n}=e;return(0,a.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,a.kt)("h1",{id:"hints"},"Hints"),(0,a.kt)("p",null,"There are several hints, explain each of them here. How they interact with the VM and affects it."))}f.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/899184d6.d82424a2.js b/assets/js/899184d6.3b2ded1d.js similarity index 87% rename from assets/js/899184d6.d82424a2.js rename to assets/js/899184d6.3b2ded1d.js index 40dfb5be1..b45d3bba1 100644 --- a/assets/js/899184d6.d82424a2.js +++ b/assets/js/899184d6.3b2ded1d.js @@ -1 +1 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[420],{3905:(t,e,n)=>{n.d(e,{Zo:()=>l,kt:()=>d});var r=n(7294);function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function i(t){for(var e=1;e=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}var s=r.createContext({}),u=function(t){var e=r.useContext(s),n=e;return t&&(n="function"==typeof t?t(e):i(i({},e),t)),n},l=function(t){var e=u(t.components);return r.createElement(s.Provider,{value:e},t.children)},p="mdxType",m={inlineCode:"code",wrapper:function(t){var e=t.children;return r.createElement(r.Fragment,{},e)}},f=r.forwardRef((function(t,e){var n=t.components,o=t.mdxType,a=t.originalType,s=t.parentName,l=c(t,["components","mdxType","originalType","parentName"]),p=u(n),f=o,d=p["".concat(s,".").concat(f)]||p[f]||m[f]||a;return n?r.createElement(d,i(i({ref:e},l),{},{components:n})):r.createElement(d,i({ref:e},l))}));function d(t,e){var n=arguments,o=e&&e.mdxType;if("string"==typeof t||o){var a=n.length,i=new Array(a);i[0]=f;var c={};for(var s in e)hasOwnProperty.call(e,s)&&(c[s]=e[s]);c.originalType=t,c[p]="string"==typeof t?t:o,i[1]=c;for(var u=2;u{n.r(e),n.d(e,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>c,toc:()=>u});var r=n(7462),o=(n(7294),n(3905));const a={sidebar_position:1},i="Instructions",c={unversionedId:"vm-fundamentals/instructions",id:"vm-fundamentals/instructions",title:"Instructions",description:"Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here.",source:"@site/docs/vm-fundamentals/instructions.md",sourceDirName:"vm-fundamentals",slug:"/vm-fundamentals/instructions",permalink:"/docs/vm-fundamentals/instructions",draft:!1,editUrl:"https://github.com/NethermindEth/cairo-vm-go/tree/main/docs/docs/vm-fundamentals/instructions.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{sidebar_position:1},sidebar:"tutorialSidebar",previous:{title:"Layout",permalink:"/docs/vm-fundamentals/layout"},next:{title:"Builtins",permalink:"/docs/vm-fundamentals/builtins"}},s={},u=[],l={toc:u},p="wrapper";function m(t){let{components:e,...n}=t;return(0,o.kt)(p,(0,r.Z)({},l,n,{components:e,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"instructions"},"Instructions"),(0,o.kt)("p",null,"Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here."))}m.isMDXComponent=!0}}]); \ No newline at end of file +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[420],{3905:(t,e,n)=>{n.d(e,{Zo:()=>l,kt:()=>d});var r=n(7294);function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function i(t){for(var e=1;e=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}var s=r.createContext({}),u=function(t){var e=r.useContext(s),n=e;return t&&(n="function"==typeof t?t(e):i(i({},e),t)),n},l=function(t){var e=u(t.components);return r.createElement(s.Provider,{value:e},t.children)},p="mdxType",m={inlineCode:"code",wrapper:function(t){var e=t.children;return r.createElement(r.Fragment,{},e)}},f=r.forwardRef((function(t,e){var n=t.components,o=t.mdxType,a=t.originalType,s=t.parentName,l=c(t,["components","mdxType","originalType","parentName"]),p=u(n),f=o,d=p["".concat(s,".").concat(f)]||p[f]||m[f]||a;return n?r.createElement(d,i(i({ref:e},l),{},{components:n})):r.createElement(d,i({ref:e},l))}));function d(t,e){var n=arguments,o=e&&e.mdxType;if("string"==typeof t||o){var a=n.length,i=new Array(a);i[0]=f;var c={};for(var s in e)hasOwnProperty.call(e,s)&&(c[s]=e[s]);c.originalType=t,c[p]="string"==typeof t?t:o,i[1]=c;for(var u=2;u{n.r(e),n.d(e,{assets:()=>s,contentTitle:()=>i,default:()=>m,frontMatter:()=>a,metadata:()=>c,toc:()=>u});var r=n(7462),o=(n(7294),n(3905));const a={sidebar_position:1},i="Instructions",c={unversionedId:"vm-fundamentals/instructions",id:"vm-fundamentals/instructions",title:"Instructions",description:"Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here.",source:"@site/docs/vm-fundamentals/instructions.md",sourceDirName:"vm-fundamentals",slug:"/vm-fundamentals/instructions",permalink:"/docs/vm-fundamentals/instructions",draft:!1,editUrl:"https://github.com/NethermindEth/cairo-vm-go/tree/main/docs/docs/vm-fundamentals/instructions.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{sidebar_position:1},sidebar:"tutorialSidebar",previous:{title:"Layout",permalink:"/docs/vm-fundamentals/layout"},next:{title:"Builtins Documentation",permalink:"/docs/vm-fundamentals/builtins"}},s={},u=[],l={toc:u},p="wrapper";function m(t){let{components:e,...n}=t;return(0,o.kt)(p,(0,r.Z)({},l,n,{components:e,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"instructions"},"Instructions"),(0,o.kt)("p",null,"Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here."))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/935f2afb.24285ccd.js b/assets/js/935f2afb.24285ccd.js deleted file mode 100644 index cbbfef6ed..000000000 --- a/assets/js/935f2afb.24285ccd.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[53],{1109:e=>{e.exports=JSON.parse('{"pluginId":"default","version":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","isLast":true,"docsSidebars":{"tutorialSidebar":[{"type":"link","label":"Cairo VM Docs","href":"/docs/intro","docId":"intro"},{"type":"category","label":"VM - Fundamentals","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Intro","href":"/docs/vm-fundamentals/intro","docId":"vm-fundamentals/intro"},{"type":"link","label":"Layout","href":"/docs/vm-fundamentals/layout","docId":"vm-fundamentals/layout"},{"type":"link","label":"Instructions","href":"/docs/vm-fundamentals/instructions","docId":"vm-fundamentals/instructions"},{"type":"link","label":"Builtins","href":"/docs/vm-fundamentals/builtins","docId":"vm-fundamentals/builtins"},{"type":"link","label":"Hints","href":"/docs/vm-fundamentals/hints","docId":"vm-fundamentals/hints"}],"href":"/docs/category/vm---fundamentals"},{"type":"category","label":"VM - Extras","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Cairo Runner","href":"/docs/vm-extras/runner","docId":"vm-extras/runner"},{"type":"link","label":"Execution Resources","href":"/docs/vm-extras/resources","docId":"vm-extras/resources"}],"href":"/docs/category/vm---extras"}]},"docs":{"intro":{"id":"intro","title":"Cairo VM Docs","description":"A general description of what we will be presenting on this documentation:","sidebar":"tutorialSidebar"},"vm-extras/resources":{"id":"vm-extras/resources","title":"Execution Resources","description":"Explain what are execution resources, what are they needed etc, and how they work","sidebar":"tutorialSidebar"},"vm-extras/runner":{"id":"vm-extras/runner","title":"Cairo Runner","description":"Explain the cairo runner and what it accomplishes","sidebar":"tutorialSidebar"},"vm-fundamentals/builtins":{"id":"vm-fundamentals/builtins","title":"Builtins","description":"Explain each builtin here. How do they work and what do they accomplish.","sidebar":"tutorialSidebar"},"vm-fundamentals/hints":{"id":"vm-fundamentals/hints","title":"Hints","description":"There are several hints, explain each of them here. How they interact with the VM and affects it.","sidebar":"tutorialSidebar"},"vm-fundamentals/instructions":{"id":"vm-fundamentals/instructions","title":"Instructions","description":"Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here.","sidebar":"tutorialSidebar"},"vm-fundamentals/intro":{"id":"vm-fundamentals/intro","title":"Intro","description":"An introduction to fundamentals. Which core concepts we will be seeing, what are their purpose etc. Maybe a little description of each one.","sidebar":"tutorialSidebar"},"vm-fundamentals/layout":{"id":"vm-fundamentals/layout","title":"Layout","description":"Explain the VM layout. Its write once memory model (perhaps also include the reason behind it)","sidebar":"tutorialSidebar"}}}')}}]); \ No newline at end of file diff --git a/assets/js/935f2afb.7908caf6.js b/assets/js/935f2afb.7908caf6.js new file mode 100644 index 000000000..f52a0c34e --- /dev/null +++ b/assets/js/935f2afb.7908caf6.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[53],{1109:e=>{e.exports=JSON.parse('{"pluginId":"default","version":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","isLast":true,"docsSidebars":{"tutorialSidebar":[{"type":"link","label":"Cairo VM Docs","href":"/docs/intro","docId":"intro"},{"type":"category","label":"VM - Fundamentals","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Intro","href":"/docs/vm-fundamentals/intro","docId":"vm-fundamentals/intro"},{"type":"link","label":"Layout","href":"/docs/vm-fundamentals/layout","docId":"vm-fundamentals/layout"},{"type":"link","label":"Instructions","href":"/docs/vm-fundamentals/instructions","docId":"vm-fundamentals/instructions"},{"type":"link","label":"Builtins Documentation","href":"/docs/vm-fundamentals/builtins","docId":"vm-fundamentals/builtins"},{"type":"link","label":"Hints","href":"/docs/vm-fundamentals/hints","docId":"vm-fundamentals/hints"}],"href":"/docs/category/vm---fundamentals"},{"type":"category","label":"VM - Extras","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Cairo Runner","href":"/docs/vm-extras/runner","docId":"vm-extras/runner"},{"type":"link","label":"Execution Resources","href":"/docs/vm-extras/resources","docId":"vm-extras/resources"}],"href":"/docs/category/vm---extras"}]},"docs":{"intro":{"id":"intro","title":"Cairo VM Docs","description":"A general description of what we will be presenting on this documentation:","sidebar":"tutorialSidebar"},"vm-extras/resources":{"id":"vm-extras/resources","title":"Execution Resources","description":"Explain what are execution resources, what are they needed etc, and how they work","sidebar":"tutorialSidebar"},"vm-extras/runner":{"id":"vm-extras/runner","title":"Cairo Runner","description":"Explain the cairo runner and what it accomplishes","sidebar":"tutorialSidebar"},"vm-fundamentals/builtins":{"id":"vm-fundamentals/builtins","title":"Builtins Documentation","description":"Regular Cairo instructions are like regular Legos, they work, but for complex things they can be slow. Builtins are special Lego pieces that snap together easily, like pre-built wheels or doors. This makes building things much faster. In a Cairo context, builtins help write clean and efficient Cairo programs, just like these special Lego pieces help build cool things faster.","sidebar":"tutorialSidebar"},"vm-fundamentals/hints":{"id":"vm-fundamentals/hints","title":"Hints","description":"There are several hints, explain each of them here. How they interact with the VM and affects it.","sidebar":"tutorialSidebar"},"vm-fundamentals/instructions":{"id":"vm-fundamentals/instructions","title":"Instructions","description":"Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here.","sidebar":"tutorialSidebar"},"vm-fundamentals/intro":{"id":"vm-fundamentals/intro","title":"Intro","description":"An introduction to fundamentals. Which core concepts we will be seeing, what are their purpose etc. Maybe a little description of each one.","sidebar":"tutorialSidebar"},"vm-fundamentals/layout":{"id":"vm-fundamentals/layout","title":"Layout","description":"Explain the VM layout. Its write once memory model (perhaps also include the reason behind it)","sidebar":"tutorialSidebar"}}}')}}]); \ No newline at end of file diff --git a/assets/js/b2cbc7f8.8632e5ac.js b/assets/js/b2cbc7f8.8632e5ac.js deleted file mode 100644 index d6035db66..000000000 --- a/assets/js/b2cbc7f8.8632e5ac.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[556],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>f});var r=n(7294);function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},u=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var n=e.components,o=e.mdxType,i=e.originalType,l=e.parentName,u=c(e,["components","mdxType","originalType","parentName"]),p=s(n),d=o,f=p["".concat(l,".").concat(d)]||p[d]||m[d]||i;return n?r.createElement(f,a(a({ref:t},u),{},{components:n})):r.createElement(f,a({ref:t},u))}));function f(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var i=n.length,a=new Array(i);a[0]=d;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c[p]="string"==typeof e?e:o,a[1]=c;for(var s=2;s{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>m,frontMatter:()=>i,metadata:()=>c,toc:()=>s});var r=n(7462),o=(n(7294),n(3905));const i={sidebar_position:2},a="Builtins",c={unversionedId:"vm-fundamentals/builtins",id:"vm-fundamentals/builtins",title:"Builtins",description:"Explain each builtin here. How do they work and what do they accomplish.",source:"@site/docs/vm-fundamentals/builtins.md",sourceDirName:"vm-fundamentals",slug:"/vm-fundamentals/builtins",permalink:"/docs/vm-fundamentals/builtins",draft:!1,editUrl:"https://github.com/NethermindEth/cairo-vm-go/tree/main/docs/docs/vm-fundamentals/builtins.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"Instructions",permalink:"/docs/vm-fundamentals/instructions"},next:{title:"Hints",permalink:"/docs/vm-fundamentals/hints"}},l={},s=[],u={toc:s},p="wrapper";function m(e){let{components:t,...n}=e;return(0,o.kt)(p,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"builtins"},"Builtins"),(0,o.kt)("p",null,"Explain each builtin here. How do they work and what do they accomplish."))}m.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/b2cbc7f8.e0007bd0.js b/assets/js/b2cbc7f8.e0007bd0.js new file mode 100644 index 000000000..5c010e17a --- /dev/null +++ b/assets/js/b2cbc7f8.e0007bd0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[556],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>d});var i=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function s(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var l=i.createContext({}),p=function(e){var t=i.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},u=function(e){var t=p(e.components);return i.createElement(l.Provider,{value:t},e.children)},c="mdxType",h={inlineCode:"code",wrapper:function(e){var t=e.children;return i.createElement(i.Fragment,{},t)}},m=i.forwardRef((function(e,t){var n=e.components,r=e.mdxType,a=e.originalType,l=e.parentName,u=o(e,["components","mdxType","originalType","parentName"]),c=p(n),m=r,d=c["".concat(l,".").concat(m)]||c[m]||h[m]||a;return n?i.createElement(d,s(s({ref:t},u),{},{components:n})):i.createElement(d,s({ref:t},u))}));function d(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var a=n.length,s=new Array(a);s[0]=m;var o={};for(var l in t)hasOwnProperty.call(t,l)&&(o[l]=t[l]);o.originalType=e,o[c]="string"==typeof e?e:r,s[1]=o;for(var p=2;p{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>s,default:()=>h,frontMatter:()=>a,metadata:()=>o,toc:()=>p});var i=n(7462),r=(n(7294),n(3905));const a={sidebar_position:2},s="Builtins Documentation",o={unversionedId:"vm-fundamentals/builtins",id:"vm-fundamentals/builtins",title:"Builtins Documentation",description:"Regular Cairo instructions are like regular Legos, they work, but for complex things they can be slow. Builtins are special Lego pieces that snap together easily, like pre-built wheels or doors. This makes building things much faster. In a Cairo context, builtins help write clean and efficient Cairo programs, just like these special Lego pieces help build cool things faster.",source:"@site/docs/vm-fundamentals/builtins.md",sourceDirName:"vm-fundamentals",slug:"/vm-fundamentals/builtins",permalink:"/docs/vm-fundamentals/builtins",draft:!1,editUrl:"https://github.com/NethermindEth/cairo-vm-go/tree/main/docs/docs/vm-fundamentals/builtins.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"Instructions",permalink:"/docs/vm-fundamentals/instructions"},next:{title:"Hints",permalink:"/docs/vm-fundamentals/hints"}},l={},p=[{value:"What is builtins in cairo?",id:"what-is-builtins-in-cairo",level:3},{value:"Builtins and Cairo memory",id:"builtins-and-cairo-memory",level:3},{value:"Some specific builtins in Cairo VM",id:"some-specific-builtins-in-cairo-vm",level:3}],u={toc:p},c="wrapper";function h(e){let{components:t,...n}=e;return(0,r.kt)(c,(0,i.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"builtins-documentation"},"Builtins Documentation"),(0,r.kt)("p",null,"Regular Cairo instructions are like regular Legos, they work, but for complex things they can be slow. Builtins are special Lego pieces that snap together easily, like pre-built wheels or doors. This makes building things much faster. In a Cairo context, builtins help write clean and efficient Cairo programs, just like these special Lego pieces help build cool things faster."),(0,r.kt)("p",null,"This section provides an overview of the builtins functions available in the Cairo Virtual Machine (Cairo VM)."),(0,r.kt)("h3",{id:"what-is-builtins-in-cairo"},"What is builtins in cairo?"),(0,r.kt)("p",null,"Builtins are predefined optimized low-level execution units which are added to the Cairo CPU board to perform predefined computations which are expensive to perform in Cairo."),(0,r.kt)("h3",{id:"builtins-and-cairo-memory"},"Builtins and Cairo memory"),(0,r.kt)("p",null,"Communication between the CPU and built-in functionalities occurs via memory-mapped I/O. Each builtin is allocated a contiguous memory region and enforces specific constraints on the data residing within that area. The Pedersen builtin is a good example to explain this."),(0,r.kt)("p",null,"Pedersen builtin establishes that:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"[p + 2] = hash([p + 0], [p + 1])\n[p + 5] = hash([p + 3], [p + 4])\n[p + 8] = hash([p + 6], [p + 7])\n")),(0,r.kt)("p",null,"The Cairo code may read or write from this memory cells to \u201cinvoke\u201d the builtin. The following code verifies that\xa0",(0,r.kt)("inlineCode",{parentName:"p"},"hash(x,\xa0y)\xa0==\xa0z")),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"// Write the value of x to [p + 0].\nx=[p]; // Write the value of y to [p + 1].\ny=[p + 1]; // The builtin makes that [p + 2] == hash([p + 0], [p + 1]).\nz=[p + 2];\n")),(0,r.kt)("p",null,"Cairo memory immutability requires a careful usage of builtin instances because memory locations like ",(0,r.kt)("inlineCode",{parentName:"p"},"[p + 0]"),", ",(0,r.kt)("inlineCode",{parentName:"p"},"[p + 1]"),", and ",(0,r.kt)("inlineCode",{parentName:"p"},"[p + 2]")," are used for a single hash computation, they cannot be reused for subsequent calculations and needs to tracking an unused memory location pointer (",(0,r.kt)("inlineCode",{parentName:"p"},"hash_ptr"),")."),(0,r.kt)("p",null,"By convention, the functions that utilizing builtins receive a pointer to the unused memory location as an argument and return an updated pointer reflecting the next available memory slot. For example:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"func hash2(hash_ptr: felt*, x, y) -> (hash_ptr: felt*, z: felt) {\n // Invoke the hash function.\n x = [hash_ptr];\n y = [hash_ptr + 1];\n // Update pointer (increment by 3) and return result.\n return (hash_ptr=hash_ptr + 3, z=[hash_ptr + 2]);\n}\n")),(0,r.kt)("p",null,"On the other hand, Starkware Cairo library provides typed references for improved readability. Here's the code rewritten with ",(0,r.kt)("inlineCode",{parentName:"p"},"HashBuiltin")," type like this example:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"from starkware.cairo.common.cairo_builtins import HashBuiltin\n\nfunc hash2(hash_ptr: HashBuiltin*, x, y) -> (hash_ptr: HashBuiltin*, z: felt) {\n let hash = hash_ptr;\n // Invoke the hash function using typed access.\n hash.x = x;\n hash.y = y;\n // Update pointer and return result.\n return (hash_ptr=hash_ptr + HashBuiltin.SIZE, z=hash.result);\n}\n")),(0,r.kt)("h3",{id:"some-specific-builtins-in-cairo-vm"},"Some specific builtins in Cairo VM"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"output")," The output builtin, accessed with a pointer to type felt, is used for writing program outputs.",(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre",className:"language-rust"},"%builtins output \n//allows the program to write this output to a designated memory location.\nfrom starkware.cairo.common.serialize import serialize_word\nfunc main{output_ptr: felt*}() { \n//the output here indicate that parameter is a pointer to a memory location of \n//type felt*. The location is used to store the program output \n serialize_word(1234);\n serialize_word(4321);\n return ();\n}\n"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"pedersen")," The pedersen builtin, accessed with a pointer to type HashBuiltin, is used for pedersen hashing computations.",(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre",className:"language-rust"},"// %builtins directive specifies which builtins are used by the program\n%builtins output pedersen \n\n//Import necessary built-in functions for cryptographic hashing.\nfrom starkware.cairo.common.cairo_builtins import HashBuiltin\nfrom starkware.cairo.common.hash import hash2\n\n//It takes two pointers: output_ptr and pedersen_ptr.\n//output_ptr points to the output built-in function.\n//pedersen_ptr points to the pedersen built-in function.\nfunc main{output_ptr, pedersen_ptr: HashBuiltin*}() {\n // This line implicitly updates the pedersen_ptr reference to pedersen_ptr + 3.\n let (res) = hash2{hash_ptr=pedersen_ptr}(1, 2);\n assert [output_ptr] = res;\n\n //Update the output builtin pointer.\n let output_ptr = output_ptr + 1;\n\n // output_ptr and pedersen_ptr will be implicitly returned.\n return ();\n}\n"))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"range_check")," The range-check builtin is utilized to ensure that a field element falls within the specified range ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"[0, 2^128)")),". This check is performed by examining three elements located at consecutive addresses starting from ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"p")),", ensuring each falls within the range."," ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 <= [p + 0] < 2^128"))," ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 <= [p + 1] < 2^128"))," ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 <= [p + 2] < 2^128"))," Here, ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"p"))," represents the starting address of the built-in."," To check if a value ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"x"))," falls within a smaller range ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"[0,BOUND]"))," where ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"BOUND"))," is less than ",(0,r.kt)("strong",{parentName:"li"},(0,r.kt)("inlineCode",{parentName:"strong"},"2^128")),", two instances of the range-check are used:",(0,r.kt)("ol",{parentName:"li"},(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"One instance confirms ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 \u2264 x < 2^128")),".")),(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"Another instance validates ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 \u2264 BOUND - x < 2^128")),"."),(0,r.kt)("p",{parentName:"li"},"This approach facilitates computing integer division with a remainder using the range-check built-in. The objective is to calculate ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"q = [x/y]"))," and ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"r = x mod y")),", rewritten as ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"x = q*y + r")),", ensuring ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 \u2264 r < y"))," holds true.\nCare must be taken to prevent overflow during the ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"x = q*y + r"))," calculation. For simplicity, it's assumed that ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 \u2264 x, y < 2^64")),". Adjustments can be made to the code based on specific constraints if this assumption doesn't hold true."),(0,r.kt)("p",{parentName:"li"},"The provided code computes ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"q"))," and ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"r")),", while ensuring ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"0 \u2264 x, y < 2^64")),", provided ",(0,r.kt)("strong",{parentName:"p"},(0,r.kt)("inlineCode",{parentName:"strong"},"|F| > 2^128")),"."),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre",className:"language-rust"},"%builtins range_check\nfunc div{range_check_ptr}(x, y) -> (q: felt, r: felt) {\n alloc_locals;\n local q;\n local r;\n %{ ids.q, ids.r = ids.x // ids.y, ids.x % ids.y %}\n\n // Check that 0 <= x < 2**64.\n [range_check_ptr] = x;\n assert [range_check_ptr + 1] = 2 ** 64 - 1 - x;\n\n // Check that 0 <= y < 2**64.\n [range_check_ptr + 2] = y;\n assert [range_check_ptr + 3] = 2 ** 64 - 1 - y;\n\n // Check that 0 <= q < 2**64.\n [range_check_ptr + 4] = q;\n assert [range_check_ptr + 5] = 2 ** 64 - 1 - q;\n\n // Check that 0 <= r < y.\n [range_check_ptr + 6] = r;\n assert [range_check_ptr + 7] = y - 1 - r;\n\n // Verify that x = q * y + r.\n assert x = q * y + r;\n\n let range_check_ptr = range_check_ptr + 8;\n return (q=q, r=r);\n}\n"))))),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"ecdsa"))),(0,r.kt)("p",null,"A structure defines the memory layout for the signature builtin. It's employed by various functions in the common library, including the ecdsa builtin. For instance, in the verify_ecdsa_signature() function, there's an implicit argument of type ",(0,r.kt)("inlineCode",{parentName:"p"},"*SignatureBuiltin"),", which aids in tracking the next available builtin instance."),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"The struct comprises two members of type felt:\n\n- **pub_key**: Represents an ECDSA public key.\n- **message**: Denotes a message signed by the pub_key.\n\nAdditionally, there's a pointer named ecdsa_ptr, which is of type SignatureBuiltin. This pointer is used to manage the signature builtin instances internally.\n\n```rust\nfrom starkware.cairo.common.bool import FALSE, TRUE\nfrom starkware.cairo.common.cairo_builtins import EcOpBuiltin, SignatureBuiltin\nfrom starkware.cairo.common.ec import StarkCurve, ec_add, ec_mul, ec_sub, is_x_on_curve, recover_y\nfrom starkware.cairo.common.ec_point import EcPoint\n\n// Verifies that the prover knows a signature of the given public_key on the given message.\n// Prover assumption: (signature_r, signature_s) is a valid signature for the given public_key\n// on the given message.\nfunc verify_ecdsa_signature{ecdsa_ptr: SignatureBuiltin*}(\n message, public_key, signature_r, signature_s\n) {\n %{ ecdsa_builtin.add_signature(ids.ecdsa_ptr.address_, (ids.signature_r, ids.signature_s)) %}\n assert ecdsa_ptr.message = message;\n assert ecdsa_ptr.pub_key = public_key;\n\n let ecdsa_ptr = ecdsa_ptr + SignatureBuiltin.SIZE;\n return ();\n}\n\n// Checks if (signature_r, signature_s) is a valid signature for the given public_key\n// on the given message.\n// Arguments:\n// message - the signed message.\n// public_key - the public key corresponding to the key with which the message was signed.\n// signature_r - the r component of the ECDSA signature.\n// signature_s - the s component of the ECDSA signature.\n// Returns:\n// res - TRUE if the signature is valid, FALSE otherwise.\nfunc check_ecdsa_signature{ec_op_ptr: EcOpBuiltin*}(\n message, public_key, signature_r, signature_s\n) -> (res: felt) {\n alloc_locals;\n // Check that s != 0 (mod StarkCurve.ORDER).\n if (signature_s == 0) {\n return (res=FALSE);\n }\n if (signature_s == StarkCurve.ORDER) {\n return (res=FALSE);\n }\n if (signature_r == StarkCurve.ORDER) {\n return (res=FALSE);\n }\n\n // Check that the public key is the x coordinate of a point on the curve.\n let on_curve: felt = is_x_on_curve(public_key);\n if (on_curve == FALSE) {\n return (res=FALSE);\n }\n // Check that r is the x coordinate of a point on the curve.\n // Note that this ensures that r != 0.\n let on_curve: felt = is_x_on_curve(signature_r);\n if (on_curve == FALSE) {\n return (res=FALSE);\n }\n\n // To verify ECDSA, obtain:\n // zG = z * G, where z is the message and G is a generator of the EC.\n // rQ = r * Q, where Q.x = public_key.\n // sR = s * R, where R.x = r.\n // and check that:\n // zG +/- rQ = +/- sR, or more efficiently that:\n // (zG +/- rQ).x = sR.x.\n let (zG: EcPoint) = ec_mul(m=message, p=EcPoint(x=StarkCurve.GEN_X, y=StarkCurve.GEN_Y));\n let (public_key_point: EcPoint) = recover_y(public_key);\n let (rQ: EcPoint) = ec_mul(signature_r, public_key_point);\n let (signature_r_point: EcPoint) = recover_y(signature_r);\n let (sR: EcPoint) = ec_mul(signature_s, signature_r_point);\n\n let (candidate: EcPoint) = ec_add(zG, rQ);\n if (candidate.x == sR.x) {\n return (res=TRUE);\n }\n\n let (candidate: EcPoint) = ec_sub(zG, rQ);\n if (candidate.x == sR.x) {\n return (res=TRUE);\n }\n\n return (res=FALSE);\n}\n```\n")),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("strong",{parentName:"li"},"bitwise")," This structure defines the memory organization for the bitwise built-in. It's utilized by functions in the common library that leverage the bitwise built-in functionality. For example, in the bitwise_xor() function, there's an implicit argument of type BitwiseBuiltin*, which internally manages the next available built-in instance."," The struct consists of members of type felt:",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"x"),": Represents the first operand.")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"y"),": Represents the second operand.")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"x_and_y"),": Holds the result of the bitwise AND operation between x and y.")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"x_xor_y"),": Stores the result of the bitwise XOR operation between x and y.")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("strong",{parentName:"p"},"x_or_y"),": Holds the result of the bitwise OR operation between x and y."),(0,r.kt)("p",{parentName:"li"},"Additionally, there's a pointer named bitwise_ptr, which is of type BitwiseBuiltin*. This pointer facilitates internal management of the bitwise built-in instances."),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre",className:"language-rust"},"from starkware.cairo.common.cairo_builtins import BitwiseBuiltin\n\nconst ALL_ONES = -1;\n\n// Computes the bitwise operations and, xor and or.\n// Arguments:\n// bitwise_ptr - the bitwise builtin pointer.\n// x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit\n// integers, and are taken as unsigned ints.\n// Returns:\n// x_and_y = x & y (bitwise and).\n// x_xor_y = x ^ y (bitwise xor).\n// x_or_y = x | y (bitwise or).\nfunc bitwise_operations{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (\n x_and_y: felt, x_xor_y: felt, x_or_y: felt\n) {\n bitwise_ptr.x = x;\n bitwise_ptr.y = y;\n let x_and_y = bitwise_ptr.x_and_y;\n let x_xor_y = bitwise_ptr.x_xor_y;\n let x_or_y = bitwise_ptr.x_or_y;\n let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;\n return (x_and_y=x_and_y, x_xor_y=x_xor_y, x_or_y=x_or_y);\n}\n\n// Computes the bitwise and of two inputs.\n// Arguments:\n// bitwise_ptr - the bitwise builtin pointer.\n// x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit\n// integers, and are taken as unsigned ints.\n// Returns:\n// x_and_y = x & y (bitwise and).\nfunc bitwise_and{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (x_and_y: felt) {\n bitwise_ptr.x = x;\n bitwise_ptr.y = y;\n let x_and_y = bitwise_ptr.x_and_y;\n let x_xor_y = bitwise_ptr.x_xor_y;\n let x_or_y = bitwise_ptr.x_or_y;\n let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;\n return (x_and_y=x_and_y);\n}\n\n// Computes the bitwise xor of two inputs.\n// Arguments:\n// bitwise_ptr - the bitwise builtin pointer.\n// x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit\n// integers, and are taken as unsigned ints.\n// Returns:\n// x_xor_y = x ^ y (bitwise xor).\nfunc bitwise_xor{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (x_xor_y: felt) {\n bitwise_ptr.x = x;\n bitwise_ptr.y = y;\n let x_and_y = bitwise_ptr.x_and_y;\n let x_xor_y = bitwise_ptr.x_xor_y;\n let x_or_y = bitwise_ptr.x_or_y;\n let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;\n return (x_xor_y=x_xor_y);\n}\n\n// Computes the bitwise or of two inputs.\n// Arguments:\n// bitwise_ptr - the bitwise builtin pointer.\n// x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit\n// integers, and are taken as unsigned ints.\n// Returns:\n// x_or_y = x | y (bitwise or).\nfunc bitwise_or{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (x_or_y: felt) {\n bitwise_ptr.x = x;\n bitwise_ptr.y = y;\n let x_and_y = bitwise_ptr.x_and_y;\n let x_xor_y = bitwise_ptr.x_xor_y;\n let x_or_y = bitwise_ptr.x_or_y;\n let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;\n return (x_or_y=x_or_y);\n}\n\n// Computes the bitwise not of a single 251-bit integer.\n// Argument:\n// x - the field element to operate on. The input should be a 251-bit\n// integer, and is taken as unsigned int.\n// Returns:\n// not_x = ~x (bitwise not).\nfunc bitwise_not(x: felt) -> (not_x: felt) {\n return (not_x=ALL_ONES - x);\n}\n")))))))}h.isMDXComponent=!0}}]); \ No newline at end of file diff --git a/assets/js/runtime~main.c3cc8bb5.js b/assets/js/runtime~main.9e3ef53f.js similarity index 93% rename from assets/js/runtime~main.c3cc8bb5.js rename to assets/js/runtime~main.9e3ef53f.js index 89b677a24..7306cc1a6 100644 --- a/assets/js/runtime~main.c3cc8bb5.js +++ b/assets/js/runtime~main.9e3ef53f.js @@ -1 +1 @@ -(()=>{"use strict";var e,t,r,o,a,n={},c={};function f(e){var t=c[e];if(void 0!==t)return t.exports;var r=c[e]={id:e,loaded:!1,exports:{}};return n[e].call(r.exports,r,r.exports,f),r.loaded=!0,r.exports}f.m=n,f.c=c,e=[],f.O=(t,r,o,a)=>{if(!r){var n=1/0;for(b=0;b=a)&&Object.keys(f.O).every((e=>f.O[e](r[i])))?r.splice(i--,1):(c=!1,a0&&e[b-1][2]>a;b--)e[b]=e[b-1];e[b]=[r,o,a]},f.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return f.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,f.t=function(e,o){if(1&o&&(e=this(e)),8&o)return e;if("object"==typeof e&&e){if(4&o&&e.__esModule)return e;if(16&o&&"function"==typeof e.then)return e}var a=Object.create(null);f.r(a);var n={};t=t||[null,r({}),r([]),r(r)];for(var c=2&o&&e;"object"==typeof c&&!~t.indexOf(c);c=r(c))Object.getOwnPropertyNames(c).forEach((t=>n[t]=()=>e[t]));return n.default=()=>e,f.d(a,n),a},f.d=(e,t)=>{for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.f={},f.e=e=>Promise.all(Object.keys(f.f).reduce(((t,r)=>(f.f[r](e,t),t)),[])),f.u=e=>"assets/js/"+({53:"935f2afb",85:"1f391b9e",158:"d4a35ebc",195:"c4f5d8e4",225:"cf89b3ac",227:"843649a7",284:"48bfc241",285:"51128525",414:"393be207",420:"899184d6",422:"af08202c",514:"1be78505",556:"b2cbc7f8",667:"9860d876",671:"0e384e19",731:"2b1b0772",762:"e9d27675",817:"14eb3368",918:"17896441"}[e]||e)+"."+{53:"24285ccd",85:"53e11c87",158:"1d97d152",195:"880e66d5",225:"288e4362",227:"657ac262",284:"2a37dabb",285:"2cd2891c",414:"6d991e03",420:"d82424a2",422:"3ad0ab74",455:"98acbaa8",514:"6bc278f4",556:"8632e5ac",667:"d6709ccd",671:"fb1a1b7e",731:"c7460e9a",762:"579b8814",817:"c7ea74c3",918:"ad508cc9",972:"d5cc17b1"}[e]+".js",f.miniCssF=e=>{},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o={},a="docs:",f.l=(e,t,r,n)=>{if(o[e])o[e].push(t);else{var c,i;if(void 0!==r)for(var d=document.getElementsByTagName("script"),b=0;b{c.onerror=c.onload=null,clearTimeout(s);var a=o[e];if(delete o[e],c.parentNode&&c.parentNode.removeChild(c),a&&a.forEach((e=>e(r))),t)return t(r)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=l.bind(null,c.onerror),c.onload=l.bind(null,c.onload),i&&document.head.appendChild(c)}},f.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.p="/",f.gca=function(e){return e={17896441:"918",51128525:"285","935f2afb":"53","1f391b9e":"85",d4a35ebc:"158",c4f5d8e4:"195",cf89b3ac:"225","843649a7":"227","48bfc241":"284","393be207":"414","899184d6":"420",af08202c:"422","1be78505":"514",b2cbc7f8:"556","9860d876":"667","0e384e19":"671","2b1b0772":"731",e9d27675:"762","14eb3368":"817"}[e]||e,f.p+f.u(e)},(()=>{var e={303:0,532:0};f.f.j=(t,r)=>{var o=f.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else if(/^(303|532)$/.test(t))e[t]=0;else{var a=new Promise(((r,a)=>o=e[t]=[r,a]));r.push(o[2]=a);var n=f.p+f.u(t),c=new Error;f.l(n,(r=>{if(f.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var a=r&&("load"===r.type?"missing":r.type),n=r&&r.target&&r.target.src;c.message="Loading chunk "+t+" failed.\n("+a+": "+n+")",c.name="ChunkLoadError",c.type=a,c.request=n,o[1](c)}}),"chunk-"+t,t)}},f.O.j=t=>0===e[t];var t=(t,r)=>{var o,a,n=r[0],c=r[1],i=r[2],d=0;if(n.some((t=>0!==e[t]))){for(o in c)f.o(c,o)&&(f.m[o]=c[o]);if(i)var b=i(f)}for(t&&t(r);d{"use strict";var e,t,r,o,a,n={},c={};function f(e){var t=c[e];if(void 0!==t)return t.exports;var r=c[e]={id:e,loaded:!1,exports:{}};return n[e].call(r.exports,r,r.exports,f),r.loaded=!0,r.exports}f.m=n,f.c=c,e=[],f.O=(t,r,o,a)=>{if(!r){var n=1/0;for(b=0;b=a)&&Object.keys(f.O).every((e=>f.O[e](r[i])))?r.splice(i--,1):(c=!1,a0&&e[b-1][2]>a;b--)e[b]=e[b-1];e[b]=[r,o,a]},f.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return f.d(t,{a:t}),t},r=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,f.t=function(e,o){if(1&o&&(e=this(e)),8&o)return e;if("object"==typeof e&&e){if(4&o&&e.__esModule)return e;if(16&o&&"function"==typeof e.then)return e}var a=Object.create(null);f.r(a);var n={};t=t||[null,r({}),r([]),r(r)];for(var c=2&o&&e;"object"==typeof c&&!~t.indexOf(c);c=r(c))Object.getOwnPropertyNames(c).forEach((t=>n[t]=()=>e[t]));return n.default=()=>e,f.d(a,n),a},f.d=(e,t)=>{for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.f={},f.e=e=>Promise.all(Object.keys(f.f).reduce(((t,r)=>(f.f[r](e,t),t)),[])),f.u=e=>"assets/js/"+({53:"935f2afb",85:"1f391b9e",158:"d4a35ebc",195:"c4f5d8e4",225:"cf89b3ac",227:"843649a7",284:"48bfc241",285:"51128525",414:"393be207",420:"899184d6",422:"af08202c",514:"1be78505",556:"b2cbc7f8",667:"9860d876",671:"0e384e19",731:"2b1b0772",762:"e9d27675",817:"14eb3368",918:"17896441"}[e]||e)+"."+{53:"7908caf6",85:"53e11c87",158:"1d97d152",195:"880e66d5",225:"288e4362",227:"5af18e1a",284:"2a37dabb",285:"2cd2891c",414:"6d991e03",420:"3b2ded1d",422:"3ad0ab74",455:"98acbaa8",514:"6bc278f4",556:"e0007bd0",667:"d6709ccd",671:"fb1a1b7e",731:"c7460e9a",762:"579b8814",817:"c7ea74c3",918:"ad508cc9",972:"d5cc17b1"}[e]+".js",f.miniCssF=e=>{},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o={},a="docs:",f.l=(e,t,r,n)=>{if(o[e])o[e].push(t);else{var c,i;if(void 0!==r)for(var d=document.getElementsByTagName("script"),b=0;b{c.onerror=c.onload=null,clearTimeout(s);var a=o[e];if(delete o[e],c.parentNode&&c.parentNode.removeChild(c),a&&a.forEach((e=>e(r))),t)return t(r)},s=setTimeout(l.bind(null,void 0,{type:"timeout",target:c}),12e4);c.onerror=l.bind(null,c.onerror),c.onload=l.bind(null,c.onload),i&&document.head.appendChild(c)}},f.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.p="/",f.gca=function(e){return e={17896441:"918",51128525:"285","935f2afb":"53","1f391b9e":"85",d4a35ebc:"158",c4f5d8e4:"195",cf89b3ac:"225","843649a7":"227","48bfc241":"284","393be207":"414","899184d6":"420",af08202c:"422","1be78505":"514",b2cbc7f8:"556","9860d876":"667","0e384e19":"671","2b1b0772":"731",e9d27675:"762","14eb3368":"817"}[e]||e,f.p+f.u(e)},(()=>{var e={303:0,532:0};f.f.j=(t,r)=>{var o=f.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else if(/^(303|532)$/.test(t))e[t]=0;else{var a=new Promise(((r,a)=>o=e[t]=[r,a]));r.push(o[2]=a);var n=f.p+f.u(t),c=new Error;f.l(n,(r=>{if(f.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var a=r&&("load"===r.type?"missing":r.type),n=r&&r.target&&r.target.src;c.message="Loading chunk "+t+" failed.\n("+a+": "+n+")",c.name="ChunkLoadError",c.type=a,c.request=n,o[1](c)}}),"chunk-"+t,t)}},f.O.j=t=>0===e[t];var t=(t,r)=>{var o,a,n=r[0],c=r[1],i=r[2],d=0;if(n.some((t=>0!==e[t]))){for(o in c)f.o(c,o)&&(f.m[o]=c[o]);if(i)var b=i(f)}for(t&&t(r);d VM - Extras | Cairo-VM in Go - + - + \ No newline at end of file diff --git a/docs/category/vm---fundamentals.html b/docs/category/vm---fundamentals.html index 765a32265..9c476674f 100644 --- a/docs/category/vm---fundamentals.html +++ b/docs/category/vm---fundamentals.html @@ -4,13 +4,13 @@ VM - Fundamentals | Cairo-VM in Go - + - + + \ No newline at end of file diff --git a/docs/intro.html b/docs/intro.html index 62042d5ec..f3784951d 100644 --- a/docs/intro.html +++ b/docs/intro.html @@ -4,13 +4,13 @@ Cairo VM Docs | Cairo-VM in Go - +

Cairo VM Docs

A general description of what we will be presenting on this documentation:

  • the core fundamentals of a vm, what they are
  • the other stuff that surrounds the vm that is equally necesary
- + \ No newline at end of file diff --git a/docs/vm-extras/resources.html b/docs/vm-extras/resources.html index 53392c671..1ca27d98c 100644 --- a/docs/vm-extras/resources.html +++ b/docs/vm-extras/resources.html @@ -4,13 +4,13 @@ Execution Resources | Cairo-VM in Go - +

Execution Resources

Explain what are execution resources, what are they needed etc, and how they work

- + \ No newline at end of file diff --git a/docs/vm-extras/runner.html b/docs/vm-extras/runner.html index d50f39a05..365a8ebbb 100644 --- a/docs/vm-extras/runner.html +++ b/docs/vm-extras/runner.html @@ -4,13 +4,13 @@ Cairo Runner | Cairo-VM in Go - +
- + \ No newline at end of file diff --git a/docs/vm-fundamentals/builtins.html b/docs/vm-fundamentals/builtins.html index b48113518..283c210bb 100644 --- a/docs/vm-fundamentals/builtins.html +++ b/docs/vm-fundamentals/builtins.html @@ -3,14 +3,15 @@ -Builtins | Cairo-VM in Go - +Builtins Documentation | Cairo-VM in Go +
-
- +

Builtins Documentation

Regular Cairo instructions are like regular Legos, they work, but for complex things they can be slow. Builtins are special Lego pieces that snap together easily, like pre-built wheels or doors. This makes building things much faster. In a Cairo context, builtins help write clean and efficient Cairo programs, just like these special Lego pieces help build cool things faster.

This section provides an overview of the builtins functions available in the Cairo Virtual Machine (Cairo VM).

What is builtins in cairo?

Builtins are predefined optimized low-level execution units which are added to the Cairo CPU board to perform predefined computations which are expensive to perform in Cairo.

Builtins and Cairo memory

Communication between the CPU and built-in functionalities occurs via memory-mapped I/O. Each builtin is allocated a contiguous memory region and enforces specific constraints on the data residing within that area. The Pedersen builtin is a good example to explain this.

Pedersen builtin establishes that:

[p + 2] = hash([p + 0], [p + 1])
[p + 5] = hash([p + 3], [p + 4])
[p + 8] = hash([p + 6], [p + 7])

The Cairo code may read or write from this memory cells to “invoke” the builtin. The following code verifies that hash(x, y) == z

// Write the value of x to [p + 0].
x=[p]; // Write the value of y to [p + 1].
y=[p + 1]; // The builtin makes that [p + 2] == hash([p + 0], [p + 1]).
z=[p + 2];

Cairo memory immutability requires a careful usage of builtin instances because memory locations like [p + 0], [p + 1], and [p + 2] are used for a single hash computation, they cannot be reused for subsequent calculations and needs to tracking an unused memory location pointer (hash_ptr).

By convention, the functions that utilizing builtins receive a pointer to the unused memory location as an argument and return an updated pointer reflecting the next available memory slot. For example:

func hash2(hash_ptr: felt*, x, y) -> (hash_ptr: felt*, z: felt) {
// Invoke the hash function.
x = [hash_ptr];
y = [hash_ptr + 1];
// Update pointer (increment by 3) and return result.
return (hash_ptr=hash_ptr + 3, z=[hash_ptr + 2]);
}

On the other hand, Starkware Cairo library provides typed references for improved readability. Here's the code rewritten with HashBuiltin type like this example:

from starkware.cairo.common.cairo_builtins import HashBuiltin

func hash2(hash_ptr: HashBuiltin*, x, y) -> (hash_ptr: HashBuiltin*, z: felt) {
let hash = hash_ptr;
// Invoke the hash function using typed access.
hash.x = x;
hash.y = y;
// Update pointer and return result.
return (hash_ptr=hash_ptr + HashBuiltin.SIZE, z=hash.result);
}

Some specific builtins in Cairo VM

  • output The output builtin, accessed with a pointer to type felt, is used for writing program outputs.
    %builtins output 
    //allows the program to write this output to a designated memory location.
    from starkware.cairo.common.serialize import serialize_word
    func main{output_ptr: felt*}() {
    //the output here indicate that parameter is a pointer to a memory location of
    //type felt*. The location is used to store the program output
    serialize_word(1234);
    serialize_word(4321);
    return ();
    }
  • pedersen The pedersen builtin, accessed with a pointer to type HashBuiltin, is used for pedersen hashing computations.
    // %builtins directive specifies which builtins are used by the program
    %builtins output pedersen

    //Import necessary built-in functions for cryptographic hashing.
    from starkware.cairo.common.cairo_builtins import HashBuiltin
    from starkware.cairo.common.hash import hash2

    //It takes two pointers: output_ptr and pedersen_ptr.
    //output_ptr points to the output built-in function.
    //pedersen_ptr points to the pedersen built-in function.
    func main{output_ptr, pedersen_ptr: HashBuiltin*}() {
    // This line implicitly updates the pedersen_ptr reference to pedersen_ptr + 3.
    let (res) = hash2{hash_ptr=pedersen_ptr}(1, 2);
    assert [output_ptr] = res;

    //Update the output builtin pointer.
    let output_ptr = output_ptr + 1;

    // output_ptr and pedersen_ptr will be implicitly returned.
    return ();
    }
  • range_check The range-check builtin is utilized to ensure that a field element falls within the specified range [0, 2^128). This check is performed by examining three elements located at consecutive addresses starting from p, ensuring each falls within the range. 0 <= [p + 0] < 2^128 0 <= [p + 1] < 2^128 0 <= [p + 2] < 2^128 Here, p represents the starting address of the built-in. To check if a value x falls within a smaller range [0,BOUND] where BOUND is less than 2^128, two instances of the range-check are used:
    1. One instance confirms 0 ≤ x < 2^128.

    2. Another instance validates 0 ≤ BOUND - x < 2^128.

      This approach facilitates computing integer division with a remainder using the range-check built-in. The objective is to calculate q = [x/y] and r = x mod y, rewritten as x = q*y + r, ensuring 0 ≤ r < y holds true. +Care must be taken to prevent overflow during the x = q*y + r calculation. For simplicity, it's assumed that 0 ≤ x, y < 2^64. Adjustments can be made to the code based on specific constraints if this assumption doesn't hold true.

      The provided code computes q and r, while ensuring 0 ≤ x, y < 2^64, provided |F| > 2^128.

      %builtins range_check
      func div{range_check_ptr}(x, y) -> (q: felt, r: felt) {
      alloc_locals;
      local q;
      local r;
      %{ ids.q, ids.r = ids.x // ids.y, ids.x % ids.y %}

      // Check that 0 <= x < 2**64.
      [range_check_ptr] = x;
      assert [range_check_ptr + 1] = 2 ** 64 - 1 - x;

      // Check that 0 <= y < 2**64.
      [range_check_ptr + 2] = y;
      assert [range_check_ptr + 3] = 2 ** 64 - 1 - y;

      // Check that 0 <= q < 2**64.
      [range_check_ptr + 4] = q;
      assert [range_check_ptr + 5] = 2 ** 64 - 1 - q;

      // Check that 0 <= r < y.
      [range_check_ptr + 6] = r;
      assert [range_check_ptr + 7] = y - 1 - r;

      // Verify that x = q * y + r.
      assert x = q * y + r;

      let range_check_ptr = range_check_ptr + 8;
      return (q=q, r=r);
      }
  • ecdsa

A structure defines the memory layout for the signature builtin. It's employed by various functions in the common library, including the ecdsa builtin. For instance, in the verify_ecdsa_signature() function, there's an implicit argument of type *SignatureBuiltin, which aids in tracking the next available builtin instance.

The struct comprises two members of type felt:

- **pub_key**: Represents an ECDSA public key.
- **message**: Denotes a message signed by the pub_key.

Additionally, there's a pointer named ecdsa_ptr, which is of type SignatureBuiltin. This pointer is used to manage the signature builtin instances internally.

```rust
from starkware.cairo.common.bool import FALSE, TRUE
from starkware.cairo.common.cairo_builtins import EcOpBuiltin, SignatureBuiltin
from starkware.cairo.common.ec import StarkCurve, ec_add, ec_mul, ec_sub, is_x_on_curve, recover_y
from starkware.cairo.common.ec_point import EcPoint

// Verifies that the prover knows a signature of the given public_key on the given message.
// Prover assumption: (signature_r, signature_s) is a valid signature for the given public_key
// on the given message.
func verify_ecdsa_signature{ecdsa_ptr: SignatureBuiltin*}(
message, public_key, signature_r, signature_s
) {
%{ ecdsa_builtin.add_signature(ids.ecdsa_ptr.address_, (ids.signature_r, ids.signature_s)) %}
assert ecdsa_ptr.message = message;
assert ecdsa_ptr.pub_key = public_key;

let ecdsa_ptr = ecdsa_ptr + SignatureBuiltin.SIZE;
return ();
}

// Checks if (signature_r, signature_s) is a valid signature for the given public_key
// on the given message.
// Arguments:
// message - the signed message.
// public_key - the public key corresponding to the key with which the message was signed.
// signature_r - the r component of the ECDSA signature.
// signature_s - the s component of the ECDSA signature.
// Returns:
// res - TRUE if the signature is valid, FALSE otherwise.
func check_ecdsa_signature{ec_op_ptr: EcOpBuiltin*}(
message, public_key, signature_r, signature_s
) -> (res: felt) {
alloc_locals;
// Check that s != 0 (mod StarkCurve.ORDER).
if (signature_s == 0) {
return (res=FALSE);
}
if (signature_s == StarkCurve.ORDER) {
return (res=FALSE);
}
if (signature_r == StarkCurve.ORDER) {
return (res=FALSE);
}

// Check that the public key is the x coordinate of a point on the curve.
let on_curve: felt = is_x_on_curve(public_key);
if (on_curve == FALSE) {
return (res=FALSE);
}
// Check that r is the x coordinate of a point on the curve.
// Note that this ensures that r != 0.
let on_curve: felt = is_x_on_curve(signature_r);
if (on_curve == FALSE) {
return (res=FALSE);
}

// To verify ECDSA, obtain:
// zG = z * G, where z is the message and G is a generator of the EC.
// rQ = r * Q, where Q.x = public_key.
// sR = s * R, where R.x = r.
// and check that:
// zG +/- rQ = +/- sR, or more efficiently that:
// (zG +/- rQ).x = sR.x.
let (zG: EcPoint) = ec_mul(m=message, p=EcPoint(x=StarkCurve.GEN_X, y=StarkCurve.GEN_Y));
let (public_key_point: EcPoint) = recover_y(public_key);
let (rQ: EcPoint) = ec_mul(signature_r, public_key_point);
let (signature_r_point: EcPoint) = recover_y(signature_r);
let (sR: EcPoint) = ec_mul(signature_s, signature_r_point);

let (candidate: EcPoint) = ec_add(zG, rQ);
if (candidate.x == sR.x) {
return (res=TRUE);
}

let (candidate: EcPoint) = ec_sub(zG, rQ);
if (candidate.x == sR.x) {
return (res=TRUE);
}

return (res=FALSE);
}
```
  • bitwise This structure defines the memory organization for the bitwise built-in. It's utilized by functions in the common library that leverage the bitwise built-in functionality. For example, in the bitwise_xor() function, there's an implicit argument of type BitwiseBuiltin*, which internally manages the next available built-in instance. The struct consists of members of type felt:
    • x: Represents the first operand.

    • y: Represents the second operand.

    • x_and_y: Holds the result of the bitwise AND operation between x and y.

    • x_xor_y: Stores the result of the bitwise XOR operation between x and y.

    • x_or_y: Holds the result of the bitwise OR operation between x and y.

      Additionally, there's a pointer named bitwise_ptr, which is of type BitwiseBuiltin*. This pointer facilitates internal management of the bitwise built-in instances.

      from starkware.cairo.common.cairo_builtins import BitwiseBuiltin

      const ALL_ONES = -1;

      // Computes the bitwise operations and, xor and or.
      // Arguments:
      // bitwise_ptr - the bitwise builtin pointer.
      // x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit
      // integers, and are taken as unsigned ints.
      // Returns:
      // x_and_y = x & y (bitwise and).
      // x_xor_y = x ^ y (bitwise xor).
      // x_or_y = x | y (bitwise or).
      func bitwise_operations{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (
      x_and_y: felt, x_xor_y: felt, x_or_y: felt
      ) {
      bitwise_ptr.x = x;
      bitwise_ptr.y = y;
      let x_and_y = bitwise_ptr.x_and_y;
      let x_xor_y = bitwise_ptr.x_xor_y;
      let x_or_y = bitwise_ptr.x_or_y;
      let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;
      return (x_and_y=x_and_y, x_xor_y=x_xor_y, x_or_y=x_or_y);
      }

      // Computes the bitwise and of two inputs.
      // Arguments:
      // bitwise_ptr - the bitwise builtin pointer.
      // x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit
      // integers, and are taken as unsigned ints.
      // Returns:
      // x_and_y = x & y (bitwise and).
      func bitwise_and{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (x_and_y: felt) {
      bitwise_ptr.x = x;
      bitwise_ptr.y = y;
      let x_and_y = bitwise_ptr.x_and_y;
      let x_xor_y = bitwise_ptr.x_xor_y;
      let x_or_y = bitwise_ptr.x_or_y;
      let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;
      return (x_and_y=x_and_y);
      }

      // Computes the bitwise xor of two inputs.
      // Arguments:
      // bitwise_ptr - the bitwise builtin pointer.
      // x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit
      // integers, and are taken as unsigned ints.
      // Returns:
      // x_xor_y = x ^ y (bitwise xor).
      func bitwise_xor{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (x_xor_y: felt) {
      bitwise_ptr.x = x;
      bitwise_ptr.y = y;
      let x_and_y = bitwise_ptr.x_and_y;
      let x_xor_y = bitwise_ptr.x_xor_y;
      let x_or_y = bitwise_ptr.x_or_y;
      let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;
      return (x_xor_y=x_xor_y);
      }

      // Computes the bitwise or of two inputs.
      // Arguments:
      // bitwise_ptr - the bitwise builtin pointer.
      // x, y - the two field elements to operate on, in this order. Both inputs should be 251-bit
      // integers, and are taken as unsigned ints.
      // Returns:
      // x_or_y = x | y (bitwise or).
      func bitwise_or{bitwise_ptr: BitwiseBuiltin*}(x: felt, y: felt) -> (x_or_y: felt) {
      bitwise_ptr.x = x;
      bitwise_ptr.y = y;
      let x_and_y = bitwise_ptr.x_and_y;
      let x_xor_y = bitwise_ptr.x_xor_y;
      let x_or_y = bitwise_ptr.x_or_y;
      let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;
      return (x_or_y=x_or_y);
      }

      // Computes the bitwise not of a single 251-bit integer.
      // Argument:
      // x - the field element to operate on. The input should be a 251-bit
      // integer, and is taken as unsigned int.
      // Returns:
      // not_x = ~x (bitwise not).
      func bitwise_not(x: felt) -> (not_x: felt) {
      return (not_x=ALL_ONES - x);
      }
+ \ No newline at end of file diff --git a/docs/vm-fundamentals/hints.html b/docs/vm-fundamentals/hints.html index 1687cf8f2..cc549a628 100644 --- a/docs/vm-fundamentals/hints.html +++ b/docs/vm-fundamentals/hints.html @@ -4,13 +4,13 @@ Hints | Cairo-VM in Go - +
-
- + + \ No newline at end of file diff --git a/docs/vm-fundamentals/instructions.html b/docs/vm-fundamentals/instructions.html index e39f6bff0..61c44be26 100644 --- a/docs/vm-fundamentals/instructions.html +++ b/docs/vm-fundamentals/instructions.html @@ -4,13 +4,13 @@ Instructions | Cairo-VM in Go - +
-

Instructions

Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here.

- +

Instructions

Go for each of the instructions. Explain their strucutre and what they accomplish. A lot to talk about here.

+ \ No newline at end of file diff --git a/docs/vm-fundamentals/intro.html b/docs/vm-fundamentals/intro.html index f85c674aa..5e1376e5e 100644 --- a/docs/vm-fundamentals/intro.html +++ b/docs/vm-fundamentals/intro.html @@ -4,13 +4,13 @@ Intro | Cairo-VM in Go - +
-

Intro

An introduction to fundamentals. Which core concepts we will be seeing, what are their purpose etc. Maybe a little description of each one.

- +

Intro

An introduction to fundamentals. Which core concepts we will be seeing, what are their purpose etc. Maybe a little description of each one.

+ \ No newline at end of file diff --git a/docs/vm-fundamentals/layout.html b/docs/vm-fundamentals/layout.html index 90298c1ab..a85151b05 100644 --- a/docs/vm-fundamentals/layout.html +++ b/docs/vm-fundamentals/layout.html @@ -4,13 +4,13 @@ Layout | Cairo-VM in Go - +
-

Layout

Explain the VM layout. Its write once memory model (perhaps also include the reason behind it)

Explain registries as well.

Then what happens when there is proof mode involved

- +

Layout

Explain the VM layout. Its write once memory model (perhaps also include the reason behind it)

Explain registries as well.

Then what happens when there is proof mode involved

+ \ No newline at end of file diff --git a/index.html b/index.html index 9b31f2a50..943be82b8 100644 --- a/index.html +++ b/index.html @@ -4,13 +4,13 @@ Hello from Cairo-VM in Go | Cairo-VM in Go - +

Cairo-VM in Go

A virtual machine for Cairo 1 written in Go

Easy to Use

Easy to Use

Docusaurus was designed from the ground up to be easily installed and used to get your website up and running quickly.

Focus on What Matters

Focus on What Matters

Docusaurus lets you focus on your docs, and we'll do the chores. Go ahead and move your docs into the docs directory.

Powered by React

Powered by React

Extend or customize your website layout by reusing React. Docusaurus can be extended while reusing the same header and footer.

- + \ No newline at end of file diff --git a/markdown-page.html b/markdown-page.html index ec18db265..ac654c564 100644 --- a/markdown-page.html +++ b/markdown-page.html @@ -4,13 +4,13 @@ Markdown page example | Cairo-VM in Go - +

Markdown page example

You don't need React to write simple standalone pages.

- + \ No newline at end of file