diff --git a/.exrc b/.exrc new file mode 100644 index 0000000..9105e34 --- /dev/null +++ b/.exrc @@ -0,0 +1,198 @@ +let s:cpo_save=&cpo +set cpo&vim +cnoremap lua require("which-key").show("\18", {mode = "c", auto = true}) +inoremap Þ +inoremap lua require("which-key").show("\7", {mode = "i", auto = true}) +inoremap lua require("which-key").show("\18", {mode = "i", auto = true}) +inoremap S (nvim-surround-insert-line) +inoremap s (nvim-surround-insert) +inoremap +inoremap +inoremap ^i +inoremap +inoremap +inoremap u +inoremap u +nnoremap  %y+  +nnoremap  h +nnoremap j +nnoremap  k +nnoremap  l +nnoremap  NvimTreeToggle  +nnoremap  w  +nnoremap Þ +nnoremap  lua require("which-key").show("\23", {mode = "n", auto = true}) +tnoremap   +nnoremap  :noh  +nnoremap  Þ +nnoremap  lua require("which-key").show(" ", {mode = "n", auto = true}) +xnoremap  Þ +xnoremap  lua require("which-key").show(" ", {mode = "v", auto = true}) +nnoremap  pÞ +nnoremap  mÞ +nnoremap  rÞ +nnoremap  wÞ +nnoremap  gÞ +nnoremap  cÞ +nnoremap  fÞ +nnoremap  tÞ +vnoremap  / lua require('Comment.api').toggle.linewise(vim.fn.visualmode()) +nnoremap  fz Telescope current_buffer_fuzzy_find  +nnoremap  th Telescope themes  +nnoremap  fb Telescope buffers  +nnoremap  fo Telescope oldfiles  +nnoremap  fw Telescope live_grep  +nnoremap  cm Telescope git_commits  +nnoremap  fa Telescope find_files follow=true no_ignore=true hidden=true  +nnoremap  gt Telescope git_status  +nnoremap  ff Telescope find_files  +nnoremap  ma Telescope marks  +nnoremap  pt Telescope terms  +nnoremap  fh Telescope help_tags  +nnoremap  e NvimTreeFocus  +nnoremap  b enew  +nnoremap  n set nu!  +nnoremap  ch NvCheatsheet  +nnoremap  rn set rnu!  +nnoremap !aÞ +nnoremap !iÞ +nnoremap +nnoremap ! lua require("which-key").show("!", {mode = "n", auto = true}) +xnoremap " lua require("which-key").show("\"", {mode = "v", auto = true}) +nnoremap " lua require("which-key").show("\"", {mode = "n", auto = true}) +xnoremap # y?\V" +nnoremap & :&& +nnoremap ' lua require("which-key").show("'", {mode = "n", auto = true}) +xnoremap * y/\V" +nnoremap  +nnoremap  +nnoremap <Þ +nnoremap < lua require("which-key").show("<", {mode = "n", auto = true}) +nnoremap >aÞ +nnoremap >iÞ +nnoremap +nnoremap > lua require("which-key").show(">", {mode = "n", auto = true}) +nnoremap +nnoremap @ lua require("which-key").show("@", {mode = "n", auto = true}) +xnoremap S (nvim-surround-visual) +nnoremap Y y$ +nnoremap +nnoremap [ lua require("which-key").show("[", {mode = "n", auto = true}) +nnoremap +nnoremap ] lua require("which-key").show("]", {mode = "n", auto = true}) +nnoremap ` lua require("which-key").show("`", {mode = "n", auto = true}) +nnoremap ciÞ +nnoremap ci lua require("which-key").show("ci", {mode = "n", auto = true}) +nnoremap +nnoremap c lua require("which-key").show("c", {mode = "n", auto = true}) +nnoremap caÞ +nnoremap cS (nvim-surround-change-line) +nnoremap cs (nvim-surround-change) +nnoremap +nnoremap d lua require("which-key").show("d", {mode = "n", auto = true}) +nnoremap daÞ +nnoremap diÞ +nnoremap ds (nvim-surround-delete) +xnoremap +xnoremap g lua require("which-key").show("g", {mode = "v", auto = true}) +nnoremap gUaÞ +nnoremap gUiÞ +nnoremap gUÞ +nnoremap gbÞ +nnoremap gcÞ +nnoremap g~aÞ +nnoremap g~iÞ +nnoremap g~Þ +nnoremap guaÞ +nnoremap guiÞ +nnoremap guÞ +nnoremap +nnoremap g lua require("which-key").show("g", {mode = "n", auto = true}) +xnoremap gS (nvim-surround-visual-line) +nnoremap j v:count || mode(1)[0:1] == "no" ? "j" : "gj" +xnoremap j v:count || mode(1)[0:1] == "no" ? "j" : "gj" +nnoremap k v:count || mode(1)[0:1] == "no" ? "k" : "gk" +xnoremap k v:count || mode(1)[0:1] == "no" ? "k" : "gk" +xnoremap p p:let @+=@0 :let @"=@0 +nnoremap viÞ +nnoremap vi lua require("which-key").show("vi", {mode = "n", auto = true}) +nnoremap +nnoremap v lua require("which-key").show("v", {mode = "n", auto = true}) +nnoremap vaÞ +nnoremap +nnoremap y lua require("which-key").show("y", {mode = "n", auto = true}) +nnoremap yiÞ +nnoremap yi lua require("which-key").show("yi", {mode = "n", auto = true}) +nnoremap yaÞ +nnoremap ySS (nvim-surround-normal-cur-line) +nnoremap yS (nvim-surround-normal-line) +nnoremap yss (nvim-surround-normal-cur) +nnoremap ys (nvim-surround-normal) +nnoremap zfaÞ +nnoremap zfiÞ +nnoremap zfÞ +nnoremap +nnoremap z lua require("which-key").show("z", {mode = "n", auto = true}) +nnoremap Þ +nnoremap lua require("which-key").show("\23", {mode = "n", auto = true}) +xnoremap (nvim-surround-visual-line) lua require'nvim-surround'.visual_surround({ line_mode = true }) +xnoremap (nvim-surround-visual) lua require'nvim-surround'.visual_surround({ line_mode = false }) +nnoremap NvimTreeToggle  +tnoremap  +vnoremap v:count || mode(1)[0:1] == "no" ? "k" : "gk" +vnoremap v:count || mode(1)[0:1] == "no" ? "j" : "gj" +nnoremap %y+  +nnoremap w  +nnoremap k +nnoremap j +nnoremap v:count || mode(1)[0:1] == "no" ? "j" : "gj" +nnoremap h +nnoremap v:count || mode(1)[0:1] == "no" ? "k" : "gk" +nnoremap l +inoremap  ^i +inoremap Þ +inoremap  lua require("which-key").show("\7", {mode = "i", auto = true}) +inoremap S (nvim-surround-insert-line) +inoremap s (nvim-surround-insert) +inoremap  +inoremap +inoremap  +inoremap  +cnoremap  lua require("which-key").show("\18", {mode = "c", auto = true}) +inoremap  lua require("which-key").show("\18", {mode = "i", auto = true}) +inoremap  u +inoremap  u +inoremap kj  +let &cpo=s:cpo_save +unlet s:cpo_save +set clipboard=unnamedplus +set expandtab +set fillchars=eob:\ +set helplang=en +set ignorecase +set indentkeys=0{,0},0),0],:,0#,!^F,o,O,e,[,(,{,),},],&,=^s*\\bibitem,=\\item +set laststatus=3 +set noloadplugins +set mouse=a +set packpath=/usr/share/nvim/runtime +set noruler +set runtimepath=~/.config/nvim,~/.local/share/nvim/lazy/lazy.nvim,~/.local/share/nvim/lazy/base46,~/.local/share/nvim/lazy/nvterm,~/.local/share/nvim/lazy/which-key.nvim,~/.local/share/nvim/lazy/cmp-path,~/.local/share/nvim/lazy/cmp-buffer,~/.local/share/nvim/lazy/cmp-nvim-lsp,~/.local/share/nvim/lazy/cmp-nvim-lua,~/.local/share/nvim/lazy/cmp_luasnip,~/.local/share/nvim/lazy/nvim-autopairs,~/.local/share/nvim/lazy/friendly-snippets,~/.local/share/nvim/lazy/LuaSnip,~/.local/share/nvim/lazy/nvim-cmp,~/.local/share/nvim/lazy/nvim-lspconfig,~/.local/share/nvim/lazy/gitsigns.nvim,~/.local/share/nvim/lazy/nvim-colorizer.lua,~/.local/share/nvim/lazy/indent-blankline.nvim,~/.local/share/nvim/lazy/nvim-treesitter,~/.local/share/nvim/lazy/nvim-web-devicons,~/.local/share/nvim/lazy/nvim-tree.lua,~/.local/share/nvim/lazy/nvim-surround,~/.local/share/nvim/lazy/ui,/usr/share/nvim/runtime,~/.local/state/nvim/lazy/readme,~/.local/share/nvim/lazy/cmp-path/after,~/.local/share/nvim/lazy/cmp-buffer/after,~/.local/share/nvim/lazy/cmp-nvim-lsp/after,~/.local/share/nvim/lazy/cmp-nvim-lua/after,~/.local/share/nvim/lazy/cmp_luasnip/after +set shiftwidth=2 +set shortmess=ifnITFstOolx +set noshowmode +set showtabline=2 +set smartcase +set smartindent +set softtabstop=2 +set splitbelow +set splitright +set statusline=%!v:lua.require('nvchad_ui.statusline.default').run() +set tabline=%!v:lua.require('nvchad_ui.tabufline.modules').run() +set tabstop=2 +set termguicolors +set timeoutlen=400 +set undofile +set updatetime=250 +set whichwrap=<>[]hl,b,s +set window=37 +" vim: set ft=vim : diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml new file mode 100644 index 0000000..03e3ac6 --- /dev/null +++ b/.github/workflows/compile.yml @@ -0,0 +1,31 @@ +name: Build & Upload the Specification +on: + push: + branches: [ main ] + +jobs: + archive-build-spec: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install JetBrainsMono # https://www.guyrutenberg.com/2020/01/29/install-jetbrains-mono-in-debian-ubuntu/ + run: mkdir JetBrainsMono + && cd JetBrainsMono + && wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/JetBrainsMono.zip + && unzip JetBrainsMono.zip + && sudo mv JetBrainsMono*.ttf /usr/share/fonts/ + && cd - + - name: Install fontawesome + run: sudo apt-get install fonts-font-awesome + - name: Install tectonic + run: curl --proto '=https' --tlsv1.2 -fsSL https://drop-sh.fullyjustified.net |sh + - name: Install lualatex + # run: sudo apt-get install texlive-latex-base && sudo apt install texlive-luatex && sudo apt-get install texlive-latex-extra + run: sudo apt install texlive-full + - name: Compile Specification + run: make ospec + - name: Upload the Specification + uses: actions/upload-artifact@v3 + with: + name: specification.pdf + path: spec/_all_spec.pdf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71b684f --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.pdf +*.fls +*.aux +*.log +*.out +*.toc +*.synctex.gz +*.bib +*.xml +*.fdb_latexmk +*.blg diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d6dd3b0 --- /dev/null +++ b/Makefile @@ -0,0 +1,106 @@ +.PHONY: alu bin exp gas oob + +view-%: lua_build + cd $* && tectonic -X compile _all_$*.tex && evince _all_$*.pdf + +recompile-%: lua_build + cd $* && tectonic -X compile _all_$*.tex + +buildOnGithub-%: lua_build + cd $* && ../tectonic -X compile _all_$*.tex + +alu: view-alu +blake: view-blake_data +block_data: view-block_data +block_hash: view-block_hash +btc: view-btc_data +bin: view-bin +exp: view-exp +euc: view-euc +formal: view-formal +gas: view-gas +hash_data: view-hash_data +hash_info: view-hash_info +hub: view-hub +lex: view-lex +logd_data: view-log_data +logi_info: view-log_info +mmio: view-mmio +modexp: view-modexp_data +mmu: view-mmu +mxp: view-mxp +oob: view-oob +prc: view-prc +rlp_addr: view-rlp_addr +rlp_txn: view-rlp_txn +rlp_txnrcpt: view-rlp_txnrcpt +rom: view-rom +rom_lex: view-rom_lex +shf: view-shf +spec: view-spec +stp: view-stp +trm: view-trm +txn_data: view-txn_data +wcp: view-wcp + +ralu: recompile-alu +rblake: recompile-blake_data +rblock_data: recompile-block_data +rblock_hash: recompile-block_hash +rbtc: recompile-btc_data +rbin: recompile-bin +rexp: recompile-exp +reuc: recompile-euc +rformal: recompile-formal +rgas: recompile-gas +rhashd: recompile-hash_data +rhashi: recompile-hash_info +rhub: recompile-hub +rlex: recompile-lex +rlogd: recompile-log_data +rlogi: recompile-log_info +rmmio: recompile-mmio +rmodexp: recompile-modexp_data +rmmu: recompile-mmu +rmxp: recompile-mxp +roob: recompile-oob +rprc: recompile-prc +rrlp_addr: recompile-rlp_addr +rrlp_txn: recompile-rlp_txn +rrlp_txnrcpt: recompile-rlp_txnrcpt +rrom: recompile-rom +rrom_lex: recompile-rom_lex +rshf: recompile-shf +rspec: recompile-spec +rstp: recompile-stp +rtrm: recompile-trm +rtxn_data: recompile-txn_data +rwcp: recompile-wcp + +ospec: buildOnGithub-spec + +# ============================================================================== +# Lualatex Generation +# ============================================================================== + +# Find all luatex files +LUATEX_FILES=$(shell find * -name "*.lua.tex" -type f) +# Determine target PDFS +LUATEX_PDFS=$(LUATEX_FILES:%.lua.tex=%.pdf) + +lua_build: $(LUATEX_PDFS) + +%.pdf : %.lua.tex + $(eval DIR := $(shell dirname "$<")) + $(eval LUAPDF := $(shell echo "$@" | sed -e "s/\.pdf/\.lua\.pdf/")) + lualatex --output-directory=$(DIR) "$<" + mv "$(LUAPDF)" "$@" + rm $(DIR)/*.log $(DIR)/*.aux + +lua_clean: + rm $(LUATEX_PDFS) + +# adding e.g. +# alias pdf='make -C ~/Documents/latex/zk-evm-notes/' +# (or whatever your path is to the zk-evm-notes folder) to ~/.bashrc +# allows one to execute commands like 'pdf oob' to view the oob module pdf from anywhere. diff --git a/README.md b/README.md new file mode 100644 index 0000000..21157a8 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# zk-evm-notes +Home of Linea's zk-evm specification. diff --git a/alu/_all_alu.maf b/alu/_all_alu.maf new file mode 100644 index 0000000..653309a --- /dev/null +++ b/alu/_all_alu.maf @@ -0,0 +1,7 @@ +_all_alu.mtc +_all_alu.mtc0 +_all_alu.mtc5 +_all_alu.mtc4 +_all_alu.mtc3 +_all_alu.mtc2 +_all_alu.mtc1 diff --git a/alu/_all_alu.mtc b/alu/_all_alu.mtc new file mode 100644 index 0000000..e69de29 diff --git a/alu/_all_alu.mtc0 b/alu/_all_alu.mtc0 new file mode 100644 index 0000000..e69de29 diff --git a/alu/_all_alu.mtc1 b/alu/_all_alu.mtc1 new file mode 100644 index 0000000..7bc8274 --- /dev/null +++ b/alu/_all_alu.mtc1 @@ -0,0 +1,10 @@ +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.1}Introduction}{\reset@font\mtcSfont 5}{section.1.1}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.2}Notations}{\reset@font\mtcSfont 5}{section.1.2}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.3}\texttt {setAbsoluteValue}{} i.e. constraints for taking absolute values}{\reset@font\mtcSfont 6}{section.1.3}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.4}\texttt {setNegative}{} i.e. constraints for taking negatives}{\reset@font\mtcSfont 7}{section.1.4}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.5}\texttt {setAddition}{} and \texttt {setSubtraction}{} i.e. constraints for addition and subtraction}{\reset@font\mtcSfont 8}{section.1.5}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.6}\texttt {setMultiplication}{} i.e. constraints for multiplying \texttt {uint256}'s}{\reset@font\mtcSfont 9}{section.1.6}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.7}Verifying a euclidean division}{\reset@font\mtcSfont 9}{section.1.7}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Verifying ${0 \leq \mathsf {R} < \mathsf {B}}$.}{\reset@font\mtcPfont 10}{section*.3}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Verifying ${\mathsf {A}} = {\mathsf {Q} \cdot \mathsf {B}} + {\mathsf {R}}$ over the integers.}{\reset@font\mtcPfont 10}{section*.4}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {1.8}Verifying extended modular arithmetic}{\reset@font\mtcSfont 11}{section.1.8}} diff --git a/alu/_all_alu.mtc2 b/alu/_all_alu.mtc2 new file mode 100644 index 0000000..0f43b27 --- /dev/null +++ b/alu/_all_alu.mtc2 @@ -0,0 +1,8 @@ +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.1}Introduction}{\reset@font\mtcSfont 13}{section.2.1}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.2}Column descriptions}{\reset@font\mtcSfont 13}{section.2.2}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.3}Stamp constancies}{\reset@font\mtcSfont 14}{section.2.3}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.4}Heartbeat}{\reset@font\mtcSfont 14}{section.2.4}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.5}``Type'' constraints}{\reset@font\mtcSfont 14}{section.2.5}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.6}Byte decomposition constraints}{\reset@font\mtcSfont 15}{section.2.6}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.7}Target constraints}{\reset@font\mtcSfont 15}{section.2.7}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {2.8}Graphical representation}{\reset@font\mtcSfont 15}{section.2.8}} diff --git a/alu/_all_alu.mtc3 b/alu/_all_alu.mtc3 new file mode 100644 index 0000000..926a713 --- /dev/null +++ b/alu/_all_alu.mtc3 @@ -0,0 +1,24 @@ +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.1}Introduction}{\reset@font\mtcSfont 19}{section.3.1}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.2}Column descriptions}{\reset@font\mtcSfont 20}{section.3.2}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.3}Heartbeat}{\reset@font\mtcSfont 21}{section.3.3}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {3.3.1}Regimes}{\reset@font\mtcSSfont 21}{subsection.3.3.1}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {3.3.2}Constraints}{\reset@font\mtcSSfont 22}{subsection.3.3.2}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {3.3.3}Intention}{\reset@font\mtcSSfont 25}{subsection.3.3.3}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.4}Constancy constraints}{\reset@font\mtcSfont 25}{section.3.4}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.5}Binary and bytehood constraints}{\reset@font\mtcSfont 26}{section.3.5}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.6}Byte decompositions}{\reset@font\mtcSfont 26}{section.3.6}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.7}\textsf {TINYB}{}, \textsf {TINYE}{}, \textsf {OLI}{} and \textsf {RESV}{} constraints}{\reset@font\mtcSfont 26}{section.3.7}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.8}Trivial regime}{\reset@font\mtcSfont 27}{section.3.8}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.9}Aliases}{\reset@font\mtcSfont 28}{section.3.9}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.10}Nontrivial \texttt {MUL} regime}{\reset@font\mtcSfont 28}{section.3.10}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.11}Nontrivial \texttt {EXP} regime --- zero result regime}{\reset@font\mtcSfont 29}{section.3.11}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {3.11.1}High level approach}{\reset@font\mtcSSfont 29}{subsection.3.11.1}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {3.11.2}Low level approach i.e. \texttt {prepareLowerBoundOnTwoAdicity}{}}{\reset@font\mtcSSfont 29}{subsection.3.11.2}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {3.11.3}Constraint system}{\reset@font\mtcSSfont 31}{subsection.3.11.3}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Target constraints.}{\reset@font\mtcPfont 31}{section*.8}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Remark.}{\reset@font\mtcPfont 31}{section*.9}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Special constraints for $\textsf {BYTE\_C\_0}$.}{\reset@font\mtcPfont 31}{section*.10}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Preparation of a lower bound.}{\reset@font\mtcPfont 32}{section*.11}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Remarks.}{\reset@font\mtcPfont 32}{section*.12}} +{\reset@font\mtcPfont\mtc@string\contentsline{paragraph}{\noexpand \leavevmode Proving the vanishing of \texttt {EXP}.}{\reset@font\mtcPfont 33}{section*.13}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {3.12}Nontrivial \texttt {EXP} regime --- nonzero result regime}{\reset@font\mtcSfont 33}{section.3.12}} diff --git a/alu/_all_alu.mtc4 b/alu/_all_alu.mtc4 new file mode 100644 index 0000000..f4bdbbf --- /dev/null +++ b/alu/_all_alu.mtc4 @@ -0,0 +1,17 @@ +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.1}Introduction}{\reset@font\mtcSfont 35}{section.4.1}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.2}Column descriptions}{\reset@font\mtcSfont 35}{section.4.2}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.3}Binary constraints}{\reset@font\mtcSfont 36}{section.4.3}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.4}Shorthands}{\reset@font\mtcSfont 37}{section.4.4}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.5}Instruction decoding}{\reset@font\mtcSfont 37}{section.4.5}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.6}\textsf {OLI}{} and \textsf {MLI}{} constraints}{\reset@font\mtcSfont 37}{section.4.6}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.7}Heartbeat}{\reset@font\mtcSfont 38}{section.4.7}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.8}Stamp constancy}{\reset@font\mtcSfont 38}{section.4.8}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.9}Bytehood and byte decomposition constraints}{\reset@font\mtcSfont 38}{section.4.9}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.10}Automatic vanishing}{\reset@font\mtcSfont 39}{section.4.10}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.11}Data organization}{\reset@font\mtcSfont 39}{section.4.11}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {4.12}Constraints}{\reset@font\mtcSfont 40}{section.4.12}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {4.12.1}Aliases}{\reset@font\mtcSSfont 40}{subsection.4.12.1}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {4.12.2}Setting absolute values}{\reset@font\mtcSSfont 40}{subsection.4.12.2}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {4.12.3}Target constraints}{\reset@font\mtcSSfont 41}{subsection.4.12.3}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {4.12.4}Comparison constraints}{\reset@font\mtcSSfont 41}{subsection.4.12.4}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {4.12.5}Result constraints}{\reset@font\mtcSSfont 42}{subsection.4.12.5}} diff --git a/alu/_all_alu.mtc5 b/alu/_all_alu.mtc5 new file mode 100644 index 0000000..3d8c066 --- /dev/null +++ b/alu/_all_alu.mtc5 @@ -0,0 +1,20 @@ +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.1}Introduction}{\reset@font\mtcSfont 43}{section.5.1}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.1.1}Instructions}{\reset@font\mtcSSfont 43}{subsection.5.1.1}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.1.2}Verifiying the integer product of 256-bit integers}{\reset@font\mtcSSfont 44}{subsection.5.1.2}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.1.3}Verifiying a ``large'' euclidean division}{\reset@font\mtcSSfont 44}{subsection.5.1.3}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.2}Column descriptions}{\reset@font\mtcSfont 45}{section.5.2}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.3}Heartbeat}{\reset@font\mtcSfont 46}{section.5.3}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.4}Stamp constancies}{\reset@font\mtcSfont 46}{section.5.4}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.5}Binary and bytehood constraints}{\reset@font\mtcSfont 46}{section.5.5}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.6}Byte decomposition constraints}{\reset@font\mtcSfont 47}{section.5.6}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.7}\textsf {OLI}{} constraints}{\reset@font\mtcSfont 47}{section.5.7}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.8}Trivial constraints}{\reset@font\mtcSfont 48}{section.5.8}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.9}Aliases}{\reset@font\mtcSfont 48}{section.5.9}} +{\reset@font\mtcSfont\mtc@string\contentsline{section}{\noexpand \leavevmode \numberline {5.10}Nontrivial constraints}{\reset@font\mtcSfont 50}{section.5.10}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.1}Disclaimer}{\reset@font\mtcSSfont 50}{subsection.5.10.1}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.2}Target constraints}{\reset@font\mtcSSfont 50}{subsection.5.10.2}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.3}Comparison constraints}{\reset@font\mtcSSfont 50}{subsection.5.10.3}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.4}General constraints}{\reset@font\mtcSSfont 50}{subsection.5.10.4}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.5}Euclidean division}{\reset@font\mtcSSfont 51}{subsection.5.10.5}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.6}Constraints for \texttt {ADDMOD}}{\reset@font\mtcSSfont 51}{subsection.5.10.6}} +{\reset@font\mtcSSfont\mtc@string\contentsline{subsection}{\noexpand \leavevmode \numberline {5.10.7}Constraints for \texttt {MULMOD}}{\reset@font\mtcSSfont 51}{subsection.5.10.7}} diff --git a/alu/_all_alu.tex b/alu/_all_alu.tex new file mode 100644 index 0000000..35a1f93 --- /dev/null +++ b/alu/_all_alu.tex @@ -0,0 +1,55 @@ +\documentclass{book} +\usepackage{xkeyval} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{xkeyval} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/stack} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/common_shorthands} +\usepackage{multirow} +\usepackage{hhline} +\usepackage[nohints]{minitoc} +\usepackage{../pkg/draculatheme} + +\newcounter{alu_ext_counter} + +\title{Alu module} +\author{Rollup team} +\date{December 2022} + +\begin{document} + +\maketitle +\dominitoc +\setcounter{tocdepth}{0} +\tableofcontents +\setcounter{tocdepth}{5} + +\input{_inputs} + +\end{document} diff --git a/alu/_inputs.tex b/alu/_inputs.tex new file mode 100644 index 0000000..359127d --- /dev/null +++ b/alu/_inputs.tex @@ -0,0 +1,5 @@ +\chapter{Primitives for arithmetic modules} \label{alu: primitives} \minitoc \input{primitives/_inputs} +\chapter{The \addMod{} module} \label{alu: add} \minitoc \input{add/_inputs} +\chapter{The \mulMod{} module} \label{alu: mul} \minitoc \input{mul/_inputs} +\chapter{The \modMod{} module} \label{alu: mod} \minitoc \input{mod/_inputs} +\chapter{The \extMod{} module} \label{alu: ext} \minitoc \input{ext/_inputs} diff --git a/alu/add/_inputs.tex b/alu/add/_inputs.tex new file mode 100644 index 0000000..213ef8f --- /dev/null +++ b/alu/add/_inputs.tex @@ -0,0 +1,8 @@ +\section{Introduction} \label{alu: add: intro} \input{add/intro} +\section{Column descriptions} \label{alu: add: columns} \input{add/columns} +\section{Stamp constancies} \label{alu: add: constancies} \input{add/constancies} +\section{Heartbeat} \label{alu: add: heartbeat} \input{add/heartbeat} +\section{``Type'' constraints} \label{alu: add: type} \input{add/type} +\section{Byte decomposition constraints} \label{alu: add: byte decompositions} \input{add/byteDec} +\section{Target constraints} \label{alu: add: target} \input{add/target} +\section{Graphical representation} \label{alu: add: representation} \input{add/representation} diff --git a/alu/add/byteDec.tex b/alu/add/byteDec.tex new file mode 100644 index 0000000..9ca2380 --- /dev/null +++ b/alu/add/byteDec.tex @@ -0,0 +1,5 @@ +We impose, for $k = 1, 2$, the following byte decomposition constraints: +\begin{enumerate}[resume] + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_{i}$ + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i - 1} + \byteCol{k}_{i}$ +\end{enumerate} diff --git a/alu/add/columns.tex b/alu/add/columns.tex new file mode 100644 index 0000000..b881c6d --- /dev/null +++ b/alu/add/columns.tex @@ -0,0 +1,30 @@ +The following are the columns of the adder module. +\begin{enumerate} + \item \addStamp: + module stamp; + \item \maxCt: + stamp-constant column; + indicates the value at which \ct{} must reset; + \item \ct: + counter column; + counts monotonically from $0$ to \maxCt{} then resets; + \item \INST: + stamp-constant instruction column; + \item $\argOneHi$, $\argOneLo$: + stamp-constant column; + contains the high and low parts of an instruction's first argument; + \item $\argTwoHi$, $\argTwoLo$: + stamp-constant column; + contains the high and low parts of an instruction's second argument; + \item $\resHi$, $\resLo$: + stamp-constant column; + contains the high and low parts of an instruction's output; + \item \byteCol{k} and \acc{k}, for $k = 1, 2$: + byte columns and associated accumulator columns; + \item \overflow: + binary column; + used to catch overflows; + % \item \witness: + % column which witnesses the fact that for all row indices $i$, $\ct_{i} \neq \llarge$; +\end{enumerate} + diff --git a/alu/add/constancies.tex b/alu/add/constancies.tex new file mode 100644 index 0000000..c5fe1d8 --- /dev/null +++ b/alu/add/constancies.tex @@ -0,0 +1,18 @@ +As per usual we declare a column \col{X} to be \textbf{stamp-constant} if it satisfies +\[ + \If \addStamp_{i + 1} \neq 1 + \addStamp_{i} ~ \Then \col{X}_{i + 1} = \col{X}_{i}. +\] +We impose stamp-constancy onto the following columns: +\begin{multicols}{4} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resHi$ + \item $\resLo$ + \item $\INST$ + \item $\maxCt$ + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/alu/add/heartbeat.tex b/alu/add/heartbeat.tex new file mode 100644 index 0000000..477cd93 --- /dev/null +++ b/alu/add/heartbeat.tex @@ -0,0 +1,30 @@ +We impose the following constraints: +\begin{enumerate} + \item $\addStamp_{0} = 0$ + \item \If $\addStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \INST_{i} & = & 0 \\ + \maxCt_{i} & = & 0 & (\trash) \\ + \ct_{i} & = & 0 & (\trash) \\ + \end{array} \right. + \] + \item $\addStamp_{i + 1} \in \{ \addStamp_{i}, 1 + \addStamp_{i} \}$ + \item \If $\addStamp_{i + 1} \neq \addStamp_{i}$ \Then $\ct_{i + 1} = 0$ + \item \If $\addStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item $\INST_{i} \in \{ \inst{ADD}, \inst{SUB} \}$ + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then $\addStamp_{i + 1} = 1 + \addStamp_{i}$ + \item $\big( \ct_{i} - \llarge \big) \cdot \maxCt_{i} \neq 0$ + \end{enumerate} + \item $\ct_{N} = \maxCt_{N}$ +\end{enumerate} +\saNote{} The above enforces that both +(\emph{a}) on all rows $0 \leq \ct_i \leq \maxCt_i < \llarge$ and +(\emph{b}) on non-padding rows $\maxCt_i \not\equiv 0$. +Recall that a row with row index $i$ is deemed +a \textbf{padding-row} if $\wcpStamp_{i} = 0$ and +a \textbf{non-padding-row} if $\wcpStamp_{i} \neq 0$. +The latter constraint is there to prevent one instruction's ``overflow'' bits to pollute the next instruction. +This could happen whenever the next instruction is e.g. the addition of two bytes. diff --git a/alu/add/intro.tex b/alu/add/intro.tex new file mode 100644 index 0000000..d5f532e --- /dev/null +++ b/alu/add/intro.tex @@ -0,0 +1,7 @@ +The \textbf{adder submodule} deals with the following instructions: +\begin{multicols}{2} +\begin{enumerate} + \item \col{ADD} + \item \col{SUB} +\end{enumerate} +\end{multicols} diff --git a/alu/add/lua/layout.lua.tex b/alu/add/lua/layout.lua.tex new file mode 100644 index 0000000..5356e28 --- /dev/null +++ b/alu/add/lua/layout.lua.tex @@ -0,0 +1,62 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} +|-------+--------+-----+------| +| ADD_ | CT_MAX | CT | INST | +|-------+--------+-----+------| +| 0 | 0 | 0 | 0 | +| ... | ... | ... | ... | +| 0 | 0 | 0 | 0 | +|-------+--------+-----+------| +| 1 | 3 | 0 | ADD | +| 1 | 3 | 1 | ADD | +| 1 | 3 | 2 | ADD | +| 1 | 3 | 3 | ADD | +|-------+--------+-----+------| +| 2 | 1 | 0 | SUB | +| 2 | 1 | 1 | SUB | +|-------+--------+-----+------| +| 3 | 1 | 0 | ADD | +| 3 | 1 | 1 | ADD | +|-------+--------+-----+------| +| 4 | 15 | 0 | ADD | +| 4 | 15 | 1 | ADD | +| 4 | 15 | 2 | ADD | +| ... | ... | ... | ... | +| 4 | 15 | 14 | ADD | +| 4 | 15 | 15 | ADD | +|-------+--------+-----+------| +| 5 | 2 | 0 | ADD | +| 5 | 2 | 1 | ADD | +| 5 | 2 | 2 | ADD | +|-------+--------+-----+------| +| 6 | 7 | 0 | SUB | +| 6 | 7 | 1 | SUB | +| 6 | 7 | 2 | SUB | +| ... | ... | ... | ... | +| 6 | 7 | 6 | SUB | +| 6 | 7 | 7 | SUB | +|-------+--------+-----+------| +| ... | ... | ... | ... | +Recall that on non-padding rows +we impose CT_MAX ≠ 0. Thus all +instructions take anywhere from +2 to 16 rows. +\end{verbatim} +\end{document} diff --git a/alu/add/lua/small.lua.tex b/alu/add/lua/small.lua.tex new file mode 100644 index 0000000..217ac89 --- /dev/null +++ b/alu/add/lua/small.lua.tex @@ -0,0 +1,68 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} +|-------+--------+-----+------+---------+-------------+---------+----------+--------+-------------+-------+-------------+-----| +| ADD_ | CT_MAX | CT | INST | ARG1_HI | ARG1_LO | ARG2_HI | ARG2_LO | RES_HI | RES_LO | ACC_1 | ACC_2 | OF | +|------:+:------:+----:+:----:+--------:+------------:+--------:+---------:+-------:+------------:+------:+------------:+-----| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+--------+-----+------+---------+-------------+---------+----------+--------+-------------+-------+-------------+-----| +| 391 | 3 | 0 | ADD | 0 | 0x a3 ca b1 | 0 | 63 5e 15 | 0 | 01 07 28 c6 | 0 | 01 | ... | +| 391 | 3 | 1 | ADD | 0 | 0x a3 ca b1 | 0 | 63 5e 15 | 0 | 01 07 28 c6 | 0 | 01 07 | ... | +| 391 | 3 | 2 | ADD | 0 | 0x a3 ca b1 | 0 | 63 5e 15 | 0 | 01 07 28 c6 | 0 | 01 07 28 | 0 | +| 391 | 3 | 3 | ADD | 0 | 0x a3 ca b1 | 0 | 63 5e 15 | 0 | 01 07 28 c6 | 0 | 01 07 28 c6 | 0 | +|-------+--------+-----+------+---------+-------------+---------+----------+--------+-------------+-------+-------------+-----| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | + +The above represents the following addition (of very small) hex integers: + + a3 ca b1 ++ 63 5e 15 +------------ += 01 07 28 c6 +\end{verbatim} + +\begin{verbatim} +|-------+--------+-----+------+-------------------------------------------------------+-------------------------------------------------------+---------+---------+--------+--------+-------+-------+-----| +| ADD_ | CT_MAX | CT | INST | ARG1_HI | ARG1_LO | ARG2_HI | ARG2_LO | RES_HI | RES_LO | ACC_1 | ACC_2 | OF | +|------:+:------:+----:+:----:+------------------------------------------------------:+------------------------------------------------------:+--------:+--------:+-------:+-------:+------:+------:+-----| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+--------+-----+------+-------------------------------------------------------+-------------------------------------------------------+---------+---------+--------+--------+-------+-------+-----| +| 401 | 1 | 0 | ADD | 0x ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff | 0x ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff | 0 | 0x 01 | 0 | 0 | 0 | 0 | 1 | +| 401 | 1 | 1 | ADD | 0x ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff | 0x ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff | 0 | 0x 01 | 0 | 0 | 0 | 0 | 1 | +|-------+--------+-----+------+-------------------------------------------------------+-------------------------------------------------------+---------+---------+--------+--------+-------+-------+-----| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | + +A surprisingly short addition (given the size of the inputs.) +\end{verbatim} + +\begin{verbatim} +|-------+--------+-----+------+---------+-------------------------------------------------------+---------+-------------------------------------------------------+--------+----------+-------+----------+-----| +| ADD_ | CT_MAX | CT | INST | ARG1_HI | ARG1_LO | ARG2_HI | ARG2_LO | RES_HI | RES_LO | ACC_1 | ACC_2 | OF | +|------:+:------:+----:+:----:+--------:+------------------------------------------------------:+--------:+------------------------------------------------------:+-------:+---------:+------:+---------:+-----| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+--------+-----+------+---------+-------------------------------------------------------+---------+-------------------------------------------------------+--------+----------+-------+----------+-----| +| 2018 | 1 | 0 | ADD | 0 | 0x f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 9a | 0 | 0x 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f d7 | 1 | 0x 0d ad | 0 | 0x 0d | 0 | +| 2018 | 1 | 1 | ADD | 0 | 0x f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 f0 9a | 0 | 0x 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f 0f d7 | 1 | 0x 0d ad | 0x 01 | 0x 0d ad | 1 | +|-------+--------+-----+------+---------+-------------------------------------------------------+---------+-------------------------------------------------------+--------+----------+-------+----------+-----| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +Yet another surprisingly short addition (given the size of the inputs.) +\end{verbatim} + +\end{document} + diff --git a/alu/add/lua/sparse.lua.tex b/alu/add/lua/sparse.lua.tex new file mode 100644 index 0000000..fdee01d --- /dev/null +++ b/alu/add/lua/sparse.lua.tex @@ -0,0 +1,50 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} +|-------+--------+-----+------+---------+---------+---------+---------+--------+--------+-------+-------| +| ADD_ | CT_MAX | CT | INST | ARG1_HI | ARG1_LO | ARG2_HI | ARG2_LO | RES_HI | RES_LO | ACC_1 | ACC_2 | +|------:+:------:+----:+:----:+--------:+--------:+--------:+--------:+-------:+-------:+------:+------:| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+--------+-----+------+---------+---------+---------+---------+--------+--------+-------+-------| +| 12 | 1 | 0 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 12 | 1 | 1 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0a | 10 | +|-------+--------+-----+------+---------+---------+---------+---------+--------+--------+-------+-------| +| 13 | 7 | 0 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 1 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 2 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 3 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 4 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 5 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 6 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0 | 0 | +| 13 | 7 | 7 | ADD | 01 | 01 | 09 | 0f | 0a | 10 | 0a | 10 | +|-------+--------+-----+------+---------+---------+---------+---------+--------+--------+-------+-------| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | + + +The above represents two LEGITIMATE ways of performing the addition of two (very sparse) hex integers: + + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f (ARG2) ++ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 (ARG1) +-------------------------------------------------------------------------------------------------------- += 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 (RES) + +The first method takes up two rows, the second method occupies eight rows, making the first more efficient. +Implementions are free to choose the most efficient way of performing additions / subtractions. +\end{verbatim} +\end{document} diff --git a/alu/add/representation.tex b/alu/add/representation.tex new file mode 100644 index 0000000..9d75437 --- /dev/null +++ b/alu/add/representation.tex @@ -0,0 +1,3 @@ +\includepdf[fitpaper=true, pages={1}]{add/lua/layout.pdf} +\includepdf[fitpaper=true, pages={1}]{add/lua/small.pdf} +\includepdf[fitpaper=true, pages={1}]{add/lua/sparse.pdf} diff --git a/alu/add/target.tex b/alu/add/target.tex new file mode 100644 index 0000000..dc564a8 --- /dev/null +++ b/alu/add/target.tex @@ -0,0 +1,42 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \left\{ \begin{array}{lcl} + \addStamp_{i} & \neq & 0 \\ + \ct_{i} & = & \maxCt_{i} \\ + \end{array} \right. } +\] +We impose the following constraints: +\begin{enumerate} + \item We fix target constraints for the accumulators: + \[ + \left\{ \begin{array}{lcl} + \resHi_{i} & \!\!\! = \!\!\! & \acc{1}_{i} \\ + \resLo_{i} & \!\!\! = \!\!\! & \acc{2}_{i} \\ + \end{array} \right. + \] + \item \If $\INST_{i} = \inst{ADD}$\footnote{in the implementation we may replace this with ``\If $\INST_{i} \neq \inst{SUB}$ \Then''} + \Then + \[ + \setAddition + \left( \begin{array}{c} + \argOneHi_{i}, \argOneLo_{i}, + \argTwoHi_{i}, \argTwoLo_{i}; \\ + \resHi_{i}, \resLo_{i}; + \overflow_{i}, + \overflow_{i-1}; + \end{array} \right) + \] + \item \If $\INST_{i} = \inst{SUB}$\footnote{in the implementation we may replace this with ``\If $\INST_{i} \neq \inst{ADD}$ \Then''} + \Then + \[ + \setSubtraction + \left( \begin{array}{c} + \argOneHi_{i}, \argOneLo_{i}, + \argTwoHi_{i}, \argTwoLo_{i}; \\ + \resHi_{i}, \resLo_{i}; + \overflow_{i}, + \overflow_{i-1}; + \end{array} \right) + \] +\end{enumerate} + diff --git a/alu/add/type.tex b/alu/add/type.tex new file mode 100644 index 0000000..545f361 --- /dev/null +++ b/alu/add/type.tex @@ -0,0 +1,5 @@ +We impose that +\begin{enumerate} + \item $\overflow$ is binary + \item $\byteCol{k}$ contains bytes for for $k = 1, 2$ +\end{enumerate} diff --git a/alu/ext/_inputs.tex b/alu/ext/_inputs.tex new file mode 100644 index 0000000..45b1a59 --- /dev/null +++ b/alu/ext/_inputs.tex @@ -0,0 +1,20 @@ +\section{Introduction} \label{sec: (alu) intro} +\subsection{Instructions} \input{ext/intro} +\subsection{Verifiying the integer product of 256-bit integers} \label{subsec (alu/ext): integer product of 256-bit integers} \input{ext/prod} +\subsection{Verifiying a ``large'' euclidean division} \label{subsec (alu/ext): large euclidean divisions} \input{ext/euclidean} +\section{Column descriptions} \input{ext/columns} +\section{Heartbeat} \input{ext/heartbeat} +\section{Stamp constancies} \input{ext/stamp_constancies} +\section{Binary and bytehood constraints} \input{ext/binary} +\section{Byte decomposition constraints} \input{ext/byteDec} +\section{\oli{} constraints} \input{ext/oli} +\section{Trivial constraints} \input{ext/target_oli} +\section{Aliases} \input{ext/aliases} +\section{Nontrivial constraints} +\subsection{Disclaimer} \input{ext/disclaimer} +\subsection{Target constraints} \input{ext/target} +\subsection{Comparison constraints} \label{subsec (alu/ext): comparison constraints} \input{ext/comparison} +\subsection{General constraints} \input{ext/general} +\subsection{Euclidean division} \input{ext/euc} +\subsection{Constraints for \inst{ADDMOD}} \input{ext/target_addmod} +\subsection{Constraints for \inst{MULMOD}} \input{ext/target_mulmod} diff --git a/alu/ext/aliases.tex b/alu/ext/aliases.tex new file mode 100644 index 0000000..9ec16c7 --- /dev/null +++ b/alu/ext/aliases.tex @@ -0,0 +1,101 @@ +For the sake of clarity we introduce some \emph{aliases} for certain \emph{values}. These aliases are meant to capture the value of certain columns at the final row of a counter-cycle i.e. rows with $\ct_{i} = \mmediumMO$. Thus whenever one of these aliases appears in the sequel \emph{there is an implicit assumption that} $\ct_{i} = \mmediumMO$. +\begin{multicols}{3} +\begin{enumerate} + \item $\col{A\_\red{k}} = \acc{A\_\red{k}}_{i}$ + \item $\col{B\_\red{k}} = \acc{B\_\red{k}}_{i}$ + \item $\col{C\_\red{k}} = \acc{C\_\red{k}}_{i}$ + \item $\col{R\_\red{k}} = \acc{R\_\red{k}}_{i}$ + \item $\col{Q\_\red{r}} = \acc{Q\_\red{r}}_{i}$ + \item $\col{$\Delta$\_\red{k}} = \acc{$\Delta$\_\red{k}}_{i}$ + \item $\col{H\_\red{p}} = \acc{H\_\red{p}}_{i}$ + \item $\col{I\_\red{q}} = \acc{I\_\red{q}}_{i}$ + \item $\col{J\_\red{r}} = \acc{J\_\red{r}}_{i}$ + \item $\col{lt\_\red{k}} = \CMP_{i - 7 + \red{k}}$ + \item $\col{eq\_\red{k}} = \CMP_{i - 3 + \red{k}}$ + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\noindent for +$0 \leq \red{k} \leq 3$, +$0 \leq \red{p} \leq 5$, +$0 \leq \red{q} \leq 6$ and +$0 \leq \red{r} \leq 7$. +Furthermore we set +%\begin{multicols}{2} +%\begin{enumerate} +%\end{enumerate} +%\end{multicols} +\noindent and +\begin{multicols}{3} +\begin{enumerate} + \item $\alpha = \of{H}_{i - 7}$ + \item $\gamma = \of{H}_{i - 4}$ + \item $\beta\col{\_0} = \of{H}_{i - 6}$ + \item $\beta\col{\_1} = \of{H}_{i - 5}$ + \item $\beta = 2 \cdot \beta\col{\_1} + \beta\col{\_0}$ +\end{enumerate} +\end{multicols} +\noindent and +\begin{multicols}{4} +\begin{enumerate} + \item $\tau\col{\_0} = \of{I}_{i - 6}$ + \item $\tau\col{\_1} = \of{I}_{i - 5}$ + \item $\tau = 2 \cdot \tau\col{\_1} + \tau\col{\_0}$ + \item $\sigma = \of{I}_{i - 7}$ + \item $\rho\col{\_0} = \of{I}_{i - 4}$ + \item $\rho\col{\_1} = \of{I}_{i - 3}$ + \item $\rho = 2 \cdot \rho\col{\_1} + \rho\col{\_0}$ +\end{enumerate} +\end{multicols} +\noindent and +\begin{multicols}{4} +\begin{enumerate} + \item $\varphi\col{\_0} = \of{J}_{i - 7}$ + \item $\varphi\col{\_1} = \of{J}_{i - 6}$ + \item $\varphi = 2 \cdot \varphi\col{\_1} + \varphi\col{\_0}$ + \item $\psi\col{\_0} = \of{J}_{i - 5}$ + \item $\psi\col{\_1} = \of{J}_{i - 4}$ + \item $\psi\col{\_2} = \of{J}_{i - 3}$ + \item $\chi\col{\_0} = \of{J}_{i - 2}$ + \item $\chi\col{\_1} = \of{J}_{i - 1}$ + \item $\chi\col{\_2} = \of{J}_{i}$ + \item $\psi = 4 \cdot \psi\col{\_2} + 2 \cdot \psi\col{\_1} + \psi\col{\_0}$ + \item $\chi = 4 \cdot \chi\col{\_2} + 2 \cdot \chi\col{\_1} + \chi\col{\_0}$ +\end{enumerate} +\end{multicols} +\noindent and +\begin{multicols}{3} +\begin{enumerate} + \item $\mu\col{\_0} = \of{RES}_{i - 6}$ + \item $\mu\col{\_1} = \of{RES}_{i - 5}$ + \item $\mu = 2 \cdot \mu\col{\_1} + \mu\col{\_0}$ + \item $\nu\col{\_0} = \of{RES}_{i - 4}$ + \item $\nu\col{\_1} = \of{RES}_{i - 3}$ + \item $\nu = 2 \cdot \nu\col{\_1} + \nu\col{\_0}$ + \item $\lambda = \of{RES}_{i - 7}$ +\end{enumerate} +\end{multicols} + +\begin{figure} +\[ +\def\orng{{\cellcolor{solarized-orange}}} +\renewcommand{\arraystretch}{1.5} +\begin{array}{|c|c|c|c|c||c|} +\hline +\ct{} & \col{CMP} & \of{H} & \of{I} & \of{J} & \of{RES} \\ \hline +0 & \col{lt}_{0} & \alpha & \sigma & \varphi_{0} & \lambda \\ \hline +1 & \col{lt}_{1} & \beta_{0} & \tau_{0} & \varphi_{1} & \mu_{0} \\ \hline +2 & \col{lt}_{2} & \beta_{1} & \tau_{1} & \psi_{0} & \mu_{1} \\ \hline +3 & \col{lt}_{3} & \gamma & \rho_{0} & \psi_{1} & \nu_{0} \\ \hline +4 & \col{eq}_{0} & \orng{} & \rho_{1} & \psi_{2} & \nu_{1} \\ \hline +5 & \col{eq}_{1} & \orng{} & \orng{} & \chi_{0} & \orng{} \\ \hline +6 & \col{eq}_{2} & \orng{} & \orng{} & \chi_{1} & \orng{} \\ \hline +\mmediumMO & \col{eq}_{3} & \orng{} & \orng{} & \chi_{2} & \orng{} \\ \hline +\end{array} +\] +\caption{% +The above represents the desired layout of data across the +$\CMP{}$, $\of{H}$, $\of{I}$, $\of{J}$ and $\of{RES}$ columns. \\ +The orange cells are left unused. +It is clear that if one wanted to one could pack everything into 2 binary columns and a byte column.} +\end{figure} diff --git a/alu/ext/binary.tex b/alu/ext/binary.tex new file mode 100644 index 0000000..f33a134 --- /dev/null +++ b/alu/ext/binary.tex @@ -0,0 +1,29 @@ +We impose binary constraints on the following columns: +\begin{multicols}{5} +\begin{enumerate} + \item $\oli$ + \item $\CMP$ + \item $\of{H}$ + \item $\of{I}$ + \item $\of{J}$ + \item $\of{INST}$ + \item $\bit{1}$ + \item $\bit{2}$ + \item $\bit{3}$ +\end{enumerate} +\end{multicols} +\noindent \ob{TODO: make sure this list is complete.} We impose bytehood constraints on the following columns: +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{A\_k}$, for $k=0,1,2,3$; + \item $\byteCol{B\_k}$, for $k=0,1,2,3$; + \item $\byteCol{C\_k}$, for $k=0,1,2,3$; + \item $\byteCol{R\_k}$, for $k=0,1,2,3$; + \item $\byteCol{Q\_k}$, for $k=0,1,\dots,7$; + \item $\byteCol{$\Delta$\_k}$, for $k=0,1,2,3$; + \item $\byteCol{H\_k}$, for $k=0,1,\dots,5$; + \item $\byteCol{I\_k}$, for $k=0,1,\dots,6$; + \item $\byteCol{J\_k}$, for $k=0,1,\dots,7$; + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} diff --git a/alu/ext/byteDec.tex b/alu/ext/byteDec.tex new file mode 100644 index 0000000..b7af2c1 --- /dev/null +++ b/alu/ext/byteDec.tex @@ -0,0 +1,20 @@ +We impose the standard byte decomposition constraints: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\ACC_{i} = \col{BYTE}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\ACC_{i} = 256 \cdot \ACC_{i - 1} + \col{BYTE}_{i}$; +\end{enumerate} +on the following byte/accumulator pairs +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{A\_k}$/$\acc{A\_k}$ for $k=0,1,2,3$; + \item $\byteCol{B\_k}$/$\acc{B\_k}$ for $k=0,1,2,3$; + \item $\byteCol{C\_k}$/$\acc{C\_k}$ for $k=0,1,2,3$; + \item $\byteCol{R\_k}$/$\acc{R\_k}$ for $k=0,1,2,3$; + \item $\byteCol{Q\_k}$/$\acc{Q\_k}$ for $k=0,1,\dots, 7$; + \item $\byteCol{$\Delta$\_k}$/$\acc{$\Delta$\_k}$ for $k=0,1,2,3$; + \item $\byteCol{H\_k}$/$\acc{H\_k}$ for $k=0,1,\dots, 5$; + \item $\byteCol{I\_k}$/$\acc{I\_k}$ for $k=0,1,\dots, 6$; + \item $\byteCol{J\_k}$/$\acc{J\_k}$ for $k=0,1,\dots, 7$; + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} diff --git a/alu/ext/columns.tex b/alu/ext/columns.tex new file mode 100644 index 0000000..0630ef6 --- /dev/null +++ b/alu/ext/columns.tex @@ -0,0 +1,50 @@ +The following are the columns of the adder module. +\begin{enumerate} + \item $\extSTAMP$: extended modular arithmetic module time stamp column; abbreviated to $\extStamp$; + \item $\OLI$: binary column; abbreviated to $\oli$; + \item $\CT$: counter column; either hovers around $0$ or counts monotonically from $0$ to $\mmediumMO$ then resets to $0$; abbreviated to $\ct$; + \item $\iInst$: imported instruction column; + \item $\iArgOneHi$, $\iArgOneLo$: + imported column containing the high and low parts of an instruction's first argument; + \item $\iArgTwoHi$, $\iArgTwoLo$: + imported column containing the high and low parts of an instruction's second argument; + \item $\iArgTreHi$, $\iArgTreLo$: + imported column containing the high and low parts of an instruction's third argument; + \item $\iResHi$, $\iResLo$: + imported column containing the high and low parts of an instruction's output; + \item $\CMP$: binary column pertaining to comparisons; + \item $\of{H}$, $\of{I}$, $\of{J}$: binary columns pertaining to overflows; + \item $\of{INST}$: binary column pertaining to instruction specific overflows; + \item $\bit{1},\bit{2},\bit{3}$: binary columns from which $\oli$ is deduced; +\end{enumerate} +\noindent We now list some \textbf{byte columns} +\begin{multicols}{2} +\begin{enumerate}[resume] + \item $\byteCol{A\_k}$, for $k=0,1,2,3$; + \item $\byteCol{B\_k}$, for $k=0,1,2,3$; + \item $\byteCol{C\_k}$, for $k=0,1,2,3$; + \item $\byteCol{R\_k}$, for $k=0,1,2,3$; + \item $\byteCol{Q\_k}$, for $k=0,1,\dots,7$; + \item $\byteCol{$\Delta$\_k}$, for $k=0,1,2,3$; + \item $\byteCol{H\_k}$, for $k=0,1,\dots,5$; + \item $\byteCol{I\_k}$, for $k=0,1,\dots,6$; + \item $\byteCol{J\_k}$, for $k=0,1,\dots,7$; + \item[\vspace{\fill}] + \setcounter{alu_ext_counter}{\value{enumi}} +\end{enumerate}\end{multicols} +\noindent and associated \textbf{accumulator columns} +\begin{multicols}{2} +\begin{enumerate}[resume]\setcounter{enumi}{\value{alu_ext_counter}} + \item $\acc{A\_k}$, for $k=0,1,2,3$; + \item $\acc{B\_k}$, for $k=0,1,2,3$; + \item $\acc{C\_k}$, for $k=0,1,2,3$; + \item $\acc{R\_k}$, for $k=0,1,2,3$; + \item $\acc{Q\_k}$, for $k=0,1,\dots,7$; + \item $\acc{$\Delta$\_k}$, for $k=0,1,2,3$; + \item $\acc{H\_k}$, for $k=0,1,\dots,5$; + \item $\acc{I\_k}$, for $k=0,1,\dots,6$; + \item $\acc{J\_k}$, for $k=0,1,\dots,7$; + \setcounter{alu_ext_counter}{\value{enumi}} + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} diff --git a/alu/ext/comparison.tex b/alu/ext/comparison.tex new file mode 100644 index 0000000..ed157e2 --- /dev/null +++ b/alu/ext/comparison.tex @@ -0,0 +1,85 @@ +This section is nearly identical with section~\ref{subsubsec (aly/mod): comparisons} about justifying the comparison bits $\col{lt\_\red{k}}$ and $\col{eq\_\red{k}}$. +We thus impose the following constraints for $\col{\red{k}} \in \{0,1,2,3\}$: +\[ +\left\{ +\begin{array}{l} + \big(2 \cdot \col{lt\_\red{k}} - 1\big) \cdot + \big(\col{C\_\red{k}} - \col{R\_\red{k}}\big) + = \colm{\Delta\_\red{k}} + \col{lt\_\red{k}} \vspace{2mm} \\ + \If \col{C\_\red{k}} = \col{R\_\red{k}} ~ \Then \col{eq\_\red{k}} = 1 \\ + \If \col{C\_\red{k}} \neq \col{R\_\red{k}} ~ \Then \col{eq\_\red{k}} = 0 \\ +\end{array} +\right. +\] +The interpretation is as previously +$\col{lt\_\red{k}} = 1 \iff \col{C\_\red{k}} > \col{R\_\red{k}}$ and +$\col{eq\_\red{k}} = 1 \iff \col{C\_\red{k}} = \col{R\_\red{k}}$. +Finally we enforce the comparison constraint of euclidean division, that is, that the remainder be $<$ than what one divides by: +\[ + \col{lt\_3} ~ + ~ \col{eq\_3} \cdot \col{lt\_2} ~ + ~ \col{eq\_3} \cdot \col{eq\_2} \cdot \col{lt\_1} ~ + ~ \col{eq\_3} \cdot \col{eq\_2} \cdot \col{eq\_1} \cdot \col{lt\_0} = 1 +\] +Considering the target constraints from section~\ref{subsec (alu/ext): comparison constraints} the above constraint amounts to imposing $0 \leq \iRes < \iArgTre$. +\iffalse +This section is nearly identical with section~\ref{subsubsec (aly/mod): comparisons} about justifying the comparison bits $\col{lt\_k}$ and $\col{eq\_k}$, $k=0,1,2,3$. +To do so we impose the following constraints: +\[ +\left\{ +\begin{array}{lcl} + \big(2 \cdot \col{lt\_3} - 1\big) \cdot + \big(\col{C\_3} - \col{R\_3}\big) + & \!\!\! = \!\!\! & \colm{\Delta\_3} + \col{lt\_3} \\ + % + \big(2 \cdot \col{lt\_2} - 1\big) \cdot + \big(\col{C\_2} - \col{R\_2}\big) + & \!\!\! = \!\!\! & \colm{\Delta\_2} + \col{lt\_2} \\ + % + \big(2 \cdot \col{lt\_1} - 1\big) \cdot + \big(\col{C\_1} - \col{R\_1}\big) + & \!\!\! = \!\!\! & \colm{\Delta\_1} + \col{lt\_1} \\ + % + \big(2 \cdot \col{lt\_0} - 1\big) \cdot + \big(\col{C\_0} - \col{R\_0}\big) + & \!\!\! = \!\!\! & \colm{\Delta\_0} + \col{lt\_0} \\ +\end{array} +\right. +\] +The interpretation is as follows: +\[ +\left\{ +\begin{array}{lcl} + \col{lt\_3} = 1 & \!\!\! \iff \!\!\! & + \col{C\_3} > \col{R\_3} \\ + % + \col{lt\_2} = 1 & \!\!\! \iff \!\!\! & + \col{C\_2} > \col{R\_2} \\ + % + \col{lt\_1} = 1 & \!\!\! \iff \!\!\! & + \col{C\_1} > \col{R\_1} \\ + % + \col{lt\_0} = 1 & \!\!\! \iff \!\!\! & + \col{C\_0} > \col{R\_0} \\ + % +\end{array} +\right. +\] +``Equality bits'' are stored in the first half of $\cmp{2}$. We constrain these values as follows: +\[ +\left\{ +\begin{array}{l} + \If \col{C\_3} = \col{R\_3} ~ \Then \col{eq\_3} = 1 \\ + \If \col{C\_3} \neq \col{R\_3} ~ \Then \col{eq\_3} = 0 \vspace{2mm} \\ + \If \col{C\_2} = \col{R\_2} ~ \Then \col{eq\_2} = 1 \\ + \If \col{C\_2} \neq \col{R\_2} ~ \Then \col{eq\_2} = 0 \vspace{2mm} \\ + \If \col{C\_1} = \col{R\_1} ~ \Then \col{eq\_1} = 1 \\ + \If \col{C\_1} \neq \col{R\_1} ~ \Then \col{eq\_1} = 0 \vspace{2mm} \\ + \If \col{C\_0} = \col{R\_0} ~ \Then \col{eq\_0} = 1 \\ + \If \col{C\_0} \neq \col{R\_0} ~ \Then \col{eq\_0} = 0 \\ +\end{array} +\right. +\] +Finally we enforce the comparison constraint of euclidean division, that is, that the remainder be $<$ than what one divides by: +\[ + \col{lt\_3} ~ + ~ \col{eq\_3} \cdot \col{lt\_2} ~ + ~ \col{eq\_3} \cdot \col{eq\_2} \cdot \col{lt\_1} ~ + ~ \col{eq\_3} \cdot \col{eq\_2} \cdot \col{eq\_1} \cdot \col{lt\_0} = 1 +\] +This amounts to imposing $0 \leq \iRes < \iArgTre$. +\fi diff --git a/alu/ext/disclaimer.tex b/alu/ext/disclaimer.tex new file mode 100644 index 0000000..2b7853e --- /dev/null +++ b/alu/ext/disclaimer.tex @@ -0,0 +1,4 @@ +\begin{center} +\framebox{All constraints from now until section are written under the assumption that $\ct_{i} = \mmediumMO$.} +\end{center} +We will thus use aliases as we see fit. \ No newline at end of file diff --git a/alu/ext/euc.tex b/alu/ext/euc.tex new file mode 100644 index 0000000..8c85687 --- /dev/null +++ b/alu/ext/euc.tex @@ -0,0 +1,4 @@ +This section deals with the algebraic part of the euclidean division i.e. +\[ + "\col{C} \cdot \col{Q} + \col{R}" +\] \ No newline at end of file diff --git a/alu/ext/euclidean.tex b/alu/ext/euclidean.tex new file mode 100644 index 0000000..c8c9175 --- /dev/null +++ b/alu/ext/euclidean.tex @@ -0,0 +1,147 @@ +\begin{lem}[euclidean division of a $512$-bit integer by a $256$-bit integer] +Let +$\colm{J} \equiv [\colm{J}_{7} \,|\, \cdots \,|\, \colm{J}_{1} \,|\, \colm{J}_{0}]$ be a $512$-bit integer +and let +$\colm{C}\equiv[\colm{C}_{3} \,|\, \colm{C}_{2} \,|\, \colm{C}_{1} \,|\, \colm{C}_{0}]$, +be a \emph{nonzero} $256$-bit integer. +Suppose furthermore that +$\colm{Q} \equiv [\colm{Q}_{7} \,|\, \cdots \,|\, \colm{Q}_{1} \,|\, \colm{Q}_{0}]$ +and +$\colm{R}\equiv[\colm{R}_{3} \,|\, \colm{R}_{2} \,|\, \colm{R}_{1} \,|\, \colm{R}_{0}]$ +are a $512$-bit integer and a $256$-bit integer respectively. + +Define, for $k = 0, 1, 2, 3$, bits +$\colm{eq}_{k}$ and +$\colm{lt}_{k}$ by imposing that +\[ + \left\{ + \begin{array}{lcc} + \colm{eq}_{k} = 1 & \iff & \colm{R}_{k} = \colm{C}_{k}\\ + \colm{lt}_{k} = 1 & \iff & \colm{R}_{k} < \colm{C}_{k}\\ + \end{array} + \right. +\] + +The following are equivalent: +\begin{enumerate} + \item $(\colm{Q}, \colm{R})$ is the euclidean division of $\colm{J}$ by $\colm{C}$, i.e. + $\colm{J} = \colm{Q} \cdot \colm{C} + \colm{R}$ as integers and + $0\leq \colm{R} < \colm{C}$; + \item there exist $64$-bit integers $\colm{I}_{6}, \colm{I}_{5}, \colm{I}_{4}, \colm{I}_{3}, \colm{I}_{2}, \colm{I}_{1}$ and $\colm{I}_{0}$ + as well as + $\sigma \in \{ 0, 1 \}$, + $\tau \in \{ 0, 1, 2, 3\}$, + $\rho \in \{ 0, 1, 2, 3\}$, + $\varphi \in \{ 0, 1, 2\}$, + $\psi \in \{ 0, 1, 2, 3, 4\}$ and + $\chi \in \{ 0, 1, 2, 3, 4\}$ such that + \[ + \left\{ + \begin{array}{lcr} + \colm{Q}_{1} \cdot \colm{C}_{0} + + \colm{Q}_{0} \cdot \colm{C}_{1} & \!\!\! = \!\!\! & + \theta^2 \cdot \sigma + + \,\, \theta \cdot \colm{I}_{1} + \colm{I}_{0} \\ + \colm{Q}_{3} \cdot \colm{C}_{0} + + \colm{Q}_{2} \cdot \colm{C}_{1} + + \colm{Q}_{1} \cdot \colm{C}_{2} + + \colm{Q}_{0} \cdot \colm{C}_{3} & \!\!\! = \!\!\! & + \theta^2 \cdot \tau + + \,\, \theta \cdot \colm{I}_{3} + \colm{I}_{2} \\ + \colm{Q}_{5} \cdot \colm{C}_{0} + + \colm{Q}_{4} \cdot \colm{C}_{1} + + \colm{Q}_{3} \cdot \colm{C}_{2} + + \colm{Q}_{2} \cdot \colm{C}_{3} & \!\!\! = \!\!\! & + \theta^2 \cdot \rho + + \,\, \theta \cdot \colm{I}_{5} + \colm{I}_{4} \\ + \colm{Q}_{7} \cdot \colm{C}_{0} + + \colm{Q}_{6} \cdot \colm{C}_{1} + + \colm{Q}_{5} \cdot \colm{C}_{2} + + \colm{Q}_{4} \cdot \colm{C}_{3} & \!\!\! = \!\!\! & + \colm{I}_{6} \\ + \end{array} + \right. + \] + and + \[ + \left\{ + \begin{array}{lll} + \colm{Q}_{7} \cdot \colm{C}_{1} = 0, + & \colm{Q}_{6} \cdot \colm{C}_{2} = 0, + & \colm{Q}_{5} \cdot \colm{C}_{3} = 0, \\ + \colm{Q}_{7} \cdot \colm{C}_{2} = 0, + & \colm{Q}_{6} \cdot \colm{C}_{3} = 0, + & \colm{Q}_{7} \cdot \colm{C}_{3} = 0, + \end{array} + \right\} + \] + and + \[ +\left\{ +\begin{array}{cclcr} + & + \colm{Q}_{0} \cdot \colm{C}_{0} + & + \!\!\!\!\! + + \,\, \theta \cdot \colm{I}_{0} + + \Big[\theta \cdot \colm{R}_{1} + \colm{R}_{0}\Big] + & \!\!\!\! = \!\!\!\! & + \theta^2 \cdot \varphi + \theta \cdot \colm{J}_{1} + \colm{J}_{0} \vspace{1mm} \\ + \varphi + + \colm{I}_{1} + + \theta\cdot\sigma + & + + \Big[\colm{Q}_{2} \cdot \colm{C}_{0} + + \colm{Q}_{1} \cdot \colm{C}_{1} + + \colm{Q}_{0} \cdot \colm{C}_{2}\Big] + & + \!\!\!\!\! + + \,\, \theta \cdot \colm{I}_{2} + + \Big[\theta \cdot \colm{R}_{3} + \colm{R}_{2}\Big] + & \!\!\!\! = \!\!\!\! & + \theta^2 \cdot \psi + \theta \cdot \colm{J}_{3} + \colm{J}_{2} \vspace{1mm} \\ + \psi + + \colm{I}_{3} + + \theta\cdot\tau + & + \!\!\!\! + + \Big[\colm{Q}_{4} \cdot \colm{C}_{0} + + \colm{Q}_{3} \cdot \colm{C}_{1} + + \colm{Q}_{2} \cdot \colm{C}_{2} + + \colm{Q}_{1} \cdot \colm{C}_{3}\Big] + & + \!\!\!\!\! + + \,\, \theta \cdot \colm{I}_{4} + & \!\!\!\! = \!\!\!\! & + \theta^2 \cdot \chi + \theta \cdot \colm{J}_{5} + \colm{J}_{4} \vspace{1mm} \\ + \chi + + \colm{I}_{5} + + \theta\cdot\rho + & + \!\!\!\! + + \Big[\colm{Q}_{6} \cdot \colm{C}_{0} + + \colm{Q}_{5} \cdot \colm{C}_{1} + + \colm{Q}_{4} \cdot \colm{C}_{2} + + \colm{Q}_{3} \cdot \colm{C}_{3}\Big] + & + \!\!\!\!\! + + \,\, \theta \cdot \colm{I}_{6} + & \!\!\!\! = \!\!\!\! & + \theta \cdot \colm{J}_{7} + \colm{J}_{6} \\ +\end{array} +\right. +\] +and finally +\[ + \colm{lt}_{3} + + + \colm{eq}_{3} \cdot \colm{lt}_{2} + + + \colm{eq}_{3} \cdot \colm{eq}_{2} \cdot \colm{lt}_{1} + + + \colm{eq}_{3} \cdot \colm{eq}_{2} \cdot \colm{eq}_{1} \cdot \colm{lt}_{0} + = + 1 +\] +\end{enumerate} +\end{lem} \ No newline at end of file diff --git a/alu/ext/general.tex b/alu/ext/general.tex new file mode 100644 index 0000000..eb24d30 --- /dev/null +++ b/alu/ext/general.tex @@ -0,0 +1,135 @@ +The following constraints are imposed regardless of the instruction $\argOne \cdot \argTwo$. +The first one relates to the product $\argOne \cdot \argTwo$. +\[ +\left\{ +\begin{array}{lcr} + \col{A\_1} \cdot \col{B\_0} + + \col{A\_0} \cdot \col{B\_1} & \!\!\! = \!\!\! & + \theta^2 \cdot \alpha + \theta \cdot \col{H\_1} + \col{H\_0} \\ + \col{A\_3} \cdot \col{B\_0} + + \col{A\_2} \cdot \col{B\_1} + + \col{A\_1} \cdot \col{B\_2} + + \col{A\_0} \cdot \col{B\_3} & \!\!\! = \!\!\! & + \theta^2 \cdot \beta + \theta \cdot \col{H\_3} + \col{H\_2} \\ + \col{A\_3} \cdot \col{B\_2} + + \col{A\_2} \cdot \col{B\_3} & \!\!\! = \!\!\! & + \theta^2 \cdot \gamma + \theta \cdot \col{H\_5} + \col{H\_4} \\ +\end{array} +\right. +\] +\noindent The next roster of constraints is related to extracting certain parameters needed to justify the base-$\theta$ representation of an expression of the form $\col{Q} \cdot \col{C} + \col{R}$ where +$\col{Q}$ is a 512 bit integer and +$\col{C}, \col{R}$ are 256 bit integers. +\[ +\left\{ +\begin{array}{lcr} + \col{Q\_1} \cdot \col{C\_0} + + \col{Q\_0} \cdot \col{C\_1} & \!\!\! = \!\!\! & + \theta^2 \cdot \sigma + + \,\, \theta \cdot \col{I\_1} + \col{I\_0} \\ + \col{Q\_3} \cdot \col{C\_0} + + \col{Q\_2} \cdot \col{C\_1} + + \col{Q\_1} \cdot \col{C\_2} + + \col{Q\_0} \cdot \col{C\_3} & \!\!\! = \!\!\! & + \theta^2 \cdot \tau + + \,\, \theta \cdot \col{I\_3} + \col{I\_2} \\ + \col{Q\_5} \cdot \col{C\_0} + + \col{Q\_4} \cdot \col{C\_1} + + \col{Q\_3} \cdot \col{C\_2} + + \col{Q\_2} \cdot \col{C\_3} & \!\!\! = \!\!\! & + \theta^2 \cdot \rho + + \,\, \theta \cdot \col{I\_5} + \col{I\_4} \\ + \col{Q\_7} \cdot \col{C\_0} + + \col{Q\_6} \cdot \col{C\_1} + + \col{Q\_5} \cdot \col{C\_2} + + \col{Q\_4} \cdot \col{C\_3} & \!\!\! = \!\!\! & + \col{I\_6} \\ +\end{array} +\right. +\] +and +\[ +\left\{ +\begin{array}{l} + \col{Q\_7} \cdot \col{C\_1} + + \col{Q\_6} \cdot \col{C\_2} + + \col{Q\_5} \cdot \col{C\_3} \\ + \phantom{\col{Q\_7} \cdot \col{C\_1}} + + \col{Q\_7} \cdot \col{C\_2} + + \col{Q\_6} \cdot \col{C\_3} \\ + \phantom{\col{Q\_7} \cdot \col{C\_1} + \col{Q\_7} \cdot \col{C\_1}} + + \col{Q\_7} \cdot \col{C\_3} +\end{array} +\right\} = 0 +\] +\noindent The following constraints establish the base-$\theta$ representation +$ +\col{Q} \cdot \col{C} + \col{R} +\equiv +[\col{J\_7} \,|\, \col{J\_6} \,|\, \col{J\_5} \,|\, \col{J\_4} \,|\, +\col{J\_3} \,|\, \col{J\_2} \,|\, \col{J\_1} \,|\, \col{J\_0}] +$ +\[ +\left\{ +\begin{array}{crlcr} + & + \col{Q\_0} \cdot \col{C\_0} + & + \!\!\!\!\! + + \,\, \theta \cdot \col{I\_0} + + \Big[\theta \cdot \col{R\_1} + \col{R\_0}\Big] + & \!\!\!\! = \!\!\!\! & + \theta^2 \cdot \varphi + \theta \cdot \col{J\_1} + \col{J\_0} \vspace{1mm} \\ + \varphi + + \col{I\_1} + + \theta\cdot\sigma + & + + + \left[\begin{array}{r} + \col{Q\_2} \cdot \col{C\_0} \\ + + \col{Q\_1} \cdot \col{C\_1} \\ + + \col{Q\_0} \cdot \col{C\_2} \\ + \end{array}\right] + & + \!\!\!\!\! + + \,\, \theta \cdot \col{I\_2} + + \Big[\theta \cdot \col{R\_3} + \col{R\_2}\Big] + & \!\!\!\! = \!\!\!\! & + \theta^2 \cdot \psi + \theta \cdot \col{J\_3} + \col{J\_2} \vspace{1mm} \\ + \psi + + \col{I\_3} + + \theta\cdot\tau + & + \!\!\!\! + + + \left[\begin{array}{r} + \col{Q\_4} \cdot \col{C\_0} \\ + + \col{Q\_3} \cdot \col{C\_1} \\ + + \col{Q\_2} \cdot \col{C\_2} \\ + + \col{Q\_1} \cdot \col{C\_3} \\ + \end{array}\right] + & + \!\!\!\!\! + + \,\, \theta \cdot \col{I\_4} + & \!\!\!\! = \!\!\!\! & + \theta^2 \cdot \chi + \theta \cdot \col{J\_5} + \col{J\_4} \vspace{1mm} \\ + \chi + + \col{I\_5} + + \theta\cdot\rho + & + \!\!\!\! + + + \left[\begin{array}{r} + \col{Q\_6} \cdot \col{C\_0} \\ + + \col{Q\_5} \cdot \col{C\_1} \\ + + \col{Q\_4} \cdot \col{C\_2} \\ + + \col{Q\_3} \cdot \col{C\_3} \\ + \end{array}\right] + & + \!\!\!\!\! + + \,\, \theta \cdot \col{I\_6} + & \!\!\!\! = \!\!\!\! & + \theta \cdot \col{J\_7} + \col{J\_6} \\ +\end{array} +\right. +\] \ No newline at end of file diff --git a/alu/ext/heartbeat.tex b/alu/ext/heartbeat.tex new file mode 100644 index 0000000..96e21e4 --- /dev/null +++ b/alu/ext/heartbeat.tex @@ -0,0 +1,35 @@ +The heartbeat of the modular arithmetic module is simple and familiar. There is a counter that either hovers around $0$ (if $\oli = 1$) or counts monotonically from $0$ to $\mmediumMO$ if $\oli = 1$. +\begin{enumerate} + \item $\extStamp_{0} = 0$; + \item $\extStamp_{i + 1} \in \{ \extStamp_{i}, 1 + \extStamp_{i} \}$; + \item \If $\extStamp_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{lcl} + \iInst_{i} & \!\!\! = \!\!\! & 0 \\ + \ct_{i} & \!\!\! = \!\!\! & 0 \\ + \oli_{i} & \!\!\! = \!\!\! & 0 + \end{array} + \right. + \] + \item \If $\extStamp_{i} \neq \extStamp_{i - 1}$ \Then $\ct_{i} = 0$; + \item \If $\extStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\oli_{i} = 1$ \Then $\extStamp_{i + 1} = 1 + \extStamp_{i}$ + \item \If $\oli_{i} = 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \mmediumMO$ \Then + \[ + \left\{ + \begin{array}{lcl} + \oli_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \ct_{i + 1} & \!\!\! = \!\!\! & 1 + \ct_{i} \\ + \end{array} + \right. + \] + \item \If $\ct_{i} = \mmediumMO$ \Then $\extStamp_{i + 1} = 1 + \extStamp_{i}$; + \end{enumerate} + \end{enumerate} + \item \If $\extStamp_{i} \neq 0$ \Then $\iInst_{i} \in \{\inst{MULMOD}, \inst{MULMOD}\}$\footnote{i.e. $(\iInst_{i} - \inst{ADDMOD}) \cdot (\iInst_{i} - \inst{MULMOD}) = 0$}; + \item \If \big($\extStamp_{N} \neq 0$ \et $\oli_{N} = 0$\big) \Then $\ct_{N} = \mmediumMO$; +\end{enumerate} diff --git a/alu/ext/intro.tex b/alu/ext/intro.tex new file mode 100644 index 0000000..0d1e136 --- /dev/null +++ b/alu/ext/intro.tex @@ -0,0 +1,13 @@ +The present section deals with the following two instructions: +\begin{multicols}{2} +\begin{enumerate} + \item \inst{ADDMOD} + \item \inst{MULMOD} +\end{enumerate} +\end{multicols} +\noindent In the following sections we provide details as to how we will constrain these instructions. Doing so requires finding +constraints for the \emph{integer product of two $256$-bit integers}, +see section~\ref{subsec (alu/ext): integer product of 256-bit integers}, +as well as +constraints for the \emph{euclidean division of a $512$-bit integer by a $256$-bit integer}, +see section~\ref{subsec (alu/ext): large euclidean divisions}. diff --git a/alu/ext/oli.tex b/alu/ext/oli.tex new file mode 100644 index 0000000..45287c5 --- /dev/null +++ b/alu/ext/oli.tex @@ -0,0 +1,62 @@ +We constrain the $\OLI{}$ column. For an \inst{ADDMOD} or \inst{MULMOD} instruction to be a one line instruction we require one of the instruction's arguments to be 0. +\begin{center} +\framebox{All constraints in this section are written under the assumption that $\extStamp_{i} \neq 0$.} +\end{center} +\begin{enumerate} + \item \If $\iInst_{i} = \inst{ADDMOD}$ \Then $\bit{1}_{i} = 0$\footnote{In the implementation one may impose \If $\iInst_{i} \neq \inst{MULMOD}$ \Then $\bit{1}_{i} = 0$ instead.} + \item \If $\iArgOneHi_{i} \neq 0$ \Then $\bit{1}_{i} = 0$ + \item \If \Big($\iArgOneHi_{i} = 0$ \et $\iInst_{i} = \inst{MULMOD}$\Big) \Then + \begin{enumerate} +% \item \If $\iArgOneLo_{i} \cdot (1 - \iArgOneLo_{i}) \neq 0$ \Then $\bit{1}_{i} = 0$ +% \item \If $\iArgOneLo_{i} \cdot (1 - \iArgOneLo_{i}) = 0$ \Then $\bit{1}_{i} = 1$ + \item \If $\iArgOneLo_{i} \neq 0$ \Then $\bit{1}_{i} = 0$ + \item \If $\iArgOneLo_{i} = 0$ \Then $\bit{1}_{i} = 1$ + \end{enumerate} +\end{enumerate} +similarly, +\begin{enumerate} + \item \If $\iInst_{i} = \inst{ADDMOD}$ \Then $\bit{2}_{i} = 0$\footnote{In the implementation one may impose \If $\iInst_{i} \neq \inst{MULMOD}$ \Then $\bit{2}_{i} = 0$ instead.} + \item \If $\iArgTwoHi_{i} \neq 0$ \Then $\bit{2}_{i} = 0$ + \item \If \Big($\iArgTwoHi_{i} = 0$ \et $\iInst_{i} = \inst{MULMOD}$\Big) \Then + \begin{enumerate} +% \item \If $\iArgTwoLo_{i} \cdot (1 - \iArgTwoLo_{i}) \neq 0$ \Then $\bit{2}_{i} = 0$ +% \item \If $\iArgTwoLo_{i} \cdot (1 - \iArgTwoLo_{i}) = 0$ \Then $\bit{2}_{i} = 1$ + \item \If $\iArgTwoLo_{i} \neq 0$ \Then $\bit{2}_{i} = 0$ + \item \If $\iArgTwoLo_{i} = 0$ \Then $\bit{2}_{i} = 1$ + \end{enumerate} +\end{enumerate} +and +\begin{enumerate} + \item \If $\iArgTreHi_{i} \neq 0$ \Then $\bit{3}_{i} = 0$ + \item \If $\iArgTreHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\iArgTreLo_{i} \cdot (1 - \iArgTreLo_{i}) \neq 0$ \Then $\bit{3}_{i} = 0$ + \item \If $\iArgTreLo_{i} \cdot (1 - \iArgTreLo_{i}) = 0$ \Then $\bit{3}_{i} = 1$ +% \item \If $\iArgTreLo_{i} \neq 0$ \Then $\bit{2}_{i} = 0$ +% \item \If $\iArgTreLo_{i} = 0$ \Then $\bit{2}_{i} = 1$ + \end{enumerate} +\end{enumerate} +We use these binary flags to constrain $\oli$: +\begin{IEEEeqnarray}{RCL} + \oli_{i} + & = & \bit{1}_{i} + \bit{2}_{i} + \bit{3}_{i} \\ + & & - \bit{1}_{i} \cdot \bit{2}_{i} + - \bit{2}_{i} \cdot \bit{3}_{i} + - \bit{3}_{i} \cdot \bit{1}_{i} \\ + & & + \bit{1}_{i} \cdot \bit{2}_{i} \cdot \bit{3}_{i} \\ +\end{IEEEeqnarray} +In other words +\[ +\left\{ +\begin{array}{lcl} + \bit{1} = 1 & \iff & \iArgOne = 0 ~ \et \iInst = \inst{MULMOD} \\ + \bit{2} = 1 & \iff & \iArgTwo = 0 ~ \et \iInst = \inst{MULMOD} \\ + \bit{3} = 1 & \iff & \iArgTre \in \{ 0, 1 \} \\ + \oli = 1 & \iff & \text{one of the previous conditions is satisfied} +\end{array} +\right. +\] +\iffalse +Note that in the implementation one may replace +``$\iInst_{i} = \inst{ADDMOD}$'' with ``$\iInst_{i} \neq \inst{MULMOD}$''. +\fi \ No newline at end of file diff --git a/alu/ext/prod.tex b/alu/ext/prod.tex new file mode 100644 index 0000000..35fbbc9 --- /dev/null +++ b/alu/ext/prod.tex @@ -0,0 +1,114 @@ +\begin{lem}[integer multiplication of $256$-bit integers] +Let +$\colm{A}\equiv[\colm{A}_{3} \,|\, \colm{A}_{2} \,|\, \colm{A}_{1} \,|\, \colm{A}_{0}]$, +$\colm{B}\equiv[\colm{B}_{3} \,|\, \colm{B}_{2} \,|\, \colm{B}_{1} \,|\, \colm{B}_{0}]$ +be $256$-bit integers and let +and +$\colm{J} \equiv [\colm{J}_{7} \,|\, \cdots \,|\, \colm{J}_{1} \,|\, \colm{J}_{0}]$ +% $\colm{J} \equiv [\colm{J}\high \,\|\, \colm{J}\low]$ +be a $512$-bit integer. The following are equivalent: +\begin{enumerate} + \item $\colm{A} \cdot \colm{B} = \colm{J}$ as integers; + \item there exist $64$-bit integers $\colm{H}_{5}, \colm{H}_{4}, \colm{H}_{3}, \colm{H}_{2}, \colm{H}_{1}$ and $\colm{H}_{0}$ + as well as + $\alpha \in \{ 0, 1 \}$, + $\beta \in \{ 0, 1, 2, 3 \}$, + $\gamma \in \{ 0, 1 \}$, + $\lambda \in \{ 0, 1 \}$, + $\mu \in \{ 0, 1, 2, 3 \}$ and + $\nu \in \{ 0, 1, 2, 3 \}$ such that + \[ + \left\{ + \begin{array}{ccccr} + \multicolumn{3}{l}{% + \colm{A}_{1} \cdot \colm{B}_{0} + + \colm{A}_{0} \cdot \colm{B}_{1}} + & \!\!\! = \!\!\! & + \theta^2 \cdot \alpha + + \theta \cdot \colm{H}_{1} + + \colm{H}_{0} + \\ + %%%%% + \multicolumn{3}{l}{% + \colm{A}_{3} \cdot \colm{B}_{0} + + \colm{A}_{2} \cdot \colm{B}_{1} + + \colm{A}_{1} \cdot \colm{B}_{2} + + \colm{A}_{0} \cdot \colm{B}_{3}} + & \!\!\! = \!\!\! & + \theta^2 \cdot \beta + + \theta \cdot \colm{H}_{3} + + \colm{H}_{2} + \\ + %%%%% + \multicolumn{3}{l}{% + \colm{A}_{3} \cdot \colm{B}_{2} + + \colm{A}_{2} \cdot \colm{B}_{3}} + & \!\!\! = \!\!\! & + \theta^2 \cdot \gamma + + \theta \cdot \colm{H}_{5} + + \colm{H}_{4} \\ + \end{array} + \right. + \] + and + \[ + \left\{ + \begin{array}{ccccr} + %%%%% + & + \colm{A}_{0} \cdot \colm{B}_{0} + & + + \theta \cdot \colm{H}_{0} + & \!\!\! = \!\!\! & + \theta^2 \cdot \lambda + + \theta \cdot \colm{J}_{1} + + \colm{J}_{0} + \\ + %%%%% + \lambda + + \colm{H}_{1} + + \theta \cdot \alpha + & + + \Big[ + \colm{A}_{2} \cdot \colm{B}_{0} + + \colm{A}_{1} \cdot \colm{B}_{1} + + \colm{A}_{0} \cdot \colm{B}_{2} \Big] + & + + \theta \cdot \colm{H}_{2} + & \!\!\! = \!\!\! & + \theta^2 \cdot \mu + + \theta \cdot \colm{J}_{3} + + \colm{J}_{2} + \\ + %%%%% + \mu + + \colm{H}_{3} + + \theta \cdot \beta + & + + \Big[ + \colm{A}_{3} \cdot \colm{B}_{1} + + \colm{A}_{2} \cdot \colm{B}_{2} + + \colm{A}_{1} \cdot \colm{B}_{3} \Big] + & + + \theta \cdot \colm{H}_{4} + & \!\!\! = \!\!\! & + \theta^2 \cdot \nu + + \theta \cdot \colm{J}_{5} + + \colm{J}_{4} + \\ + %%%%% + \nu + + \colm{H}_{5} + + \theta \cdot \gamma + & + + \Big[\colm{A}_{3} \cdot \colm{B}_{3}\Big] + & + & \!\!\! = \!\!\! & + \theta \cdot \colm{J}_{7} + + \colm{J}_{6} + \\ + \end{array} + \right. + \] +\end{enumerate} +\end{lem} \ No newline at end of file diff --git a/alu/ext/stamp_constancies.tex b/alu/ext/stamp_constancies.tex new file mode 100644 index 0000000..cbfb85f --- /dev/null +++ b/alu/ext/stamp_constancies.tex @@ -0,0 +1,20 @@ +As always we say that a column $\col{X}$ is \textbf{stamp-constant} if it satisfies +\[ + \extStamp_{i} = \extStamp_{i - 1} + \implies + \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose stamp-constancy on the following columns +\begin{multicols}{5} +\begin{enumerate} + \item $\iArgOneHi$ + \item $\iArgOneLo$ + \item $\iArgTwoHi$ + \item $\iArgTwoLo$ + \item $\iArgTreHi$ + \item $\iArgTreLo$ + \item $\iResHi$ + \item $\iResLo$ + \item $\iInst$ +\end{enumerate} +\end{multicols} \ No newline at end of file diff --git a/alu/ext/target.tex b/alu/ext/target.tex new file mode 100644 index 0000000..1c6eec9 --- /dev/null +++ b/alu/ext/target.tex @@ -0,0 +1,15 @@ +We impose the following target constraints: +\[ +\left\{ +\begin{array}{lcl} + \theta \cdot \col{A\_3} + \col{A\_2} & \!\!\! = \!\!\! & \iArgOneHi_{i} \\ + \theta \cdot \col{A\_1} + \col{A\_0} & \!\!\! = \!\!\! & \iArgOneLo_{i} \vspace{2mm} \\ + \theta \cdot \col{B\_3} + \col{B\_2} & \!\!\! = \!\!\! & \iArgTwoHi_{i} \\ + \theta \cdot \col{B\_1} + \col{B\_0} & \!\!\! = \!\!\! & \iArgTwoLo_{i} \vspace{2mm} \\ + \theta \cdot \col{C\_3} + \col{C\_2} & \!\!\! = \!\!\! & \iArgTreHi_{i} \\ + \theta \cdot \col{C\_1} + \col{C\_0} & \!\!\! = \!\!\! & \iArgTreLo_{i} \vspace{2mm} \\ + \theta \cdot \col{R\_3} + \col{R\_2} & \!\!\! = \!\!\! & \iResHi_{i} \\ + \theta \cdot \col{R\_1} + \col{R\_0} & \!\!\! = \!\!\! & \iResLo_{i} \\ +\end{array} +\right. +\] \ No newline at end of file diff --git a/alu/ext/target_addmod.tex b/alu/ext/target_addmod.tex new file mode 100644 index 0000000..bc38f6c --- /dev/null +++ b/alu/ext/target_addmod.tex @@ -0,0 +1,29 @@ +\iffalse +\begin{center} +\framebox{All constraints in this section are written under the assumption that $ +\begin{cases} +\ct_{i} = \mmediumMO \\ +\iInst_{i} = \inst{ADDMOD} \\ +\end{cases}$.} +\end{center} +\fi +We impose the following: +\begin{enumerate} + \item \If + \Big($\ct_{i} = \mmediumMO$ + \et + $\iInst_{i} = \inst{ADDMOD}$\footnote{May be replaced by $\iInst_{i} \neq \inst{MULMOD}$ in implementations.}\Big) + \Then + \[ + \left\{ + \begin{array}{rcl} + \iArgOneLo_{i} + \iArgTwoLo_{i} + & = & \theta^2 \cdot \lambda + \theta \cdot \col{J\_1} + \col{J\_0} \\ + \lambda + \iArgOneHi_{i} + \iArgTwoHi_{i} + & = & \theta^2 \cdot \mu + \theta \cdot \col{J\_3} + \col{J\_2} \vspace{2mm} \\ + \mu & = & \col{J\_4} \\ + 0 & = & \col{J\_5} + \col{J\_6} + \col{J\_7} \\ + \end{array} + \right. + \] +\end{enumerate} \ No newline at end of file diff --git a/alu/ext/target_mulmod.tex b/alu/ext/target_mulmod.tex new file mode 100644 index 0000000..5356bd3 --- /dev/null +++ b/alu/ext/target_mulmod.tex @@ -0,0 +1,50 @@ +\begin{enumerate} + \item \If \Big($\ct_{i} = \mmediumMO$ \et $\iInst_{i} = \inst{MULMOD}$\footnote{May be replaced by $\iInst_{i} \neq \inst{ADDMOD}$ in implementations.}\Big) \Then + \[ + \left\{ + \begin{array}{ccccr} + & + \col{A\_0}\cdot\col{B\_0} + & + \!\!\!\! + + \,\, \theta \cdot \col{H\_0} + & \!\!\! = \!\!\! & \theta^2 \cdot \lambda + + \theta \cdot \col{J\_1} + \col{J\_0} \vspace{1mm} \\ + \lambda + + \col{H\_1} + + \theta \cdot \alpha + & + \!\!\!\! + + \Big[\col{A\_2}\cdot\col{B\_0} + + \col{A\_1}\cdot\col{B\_1} + + \col{A\_0}\cdot\col{B\_2}\Big] + & + \!\!\!\! + + \,\, \theta \cdot \col{H\_2} + & \!\!\! = \!\!\! & \theta^2 \cdot \mu + + \theta \cdot \col{J\_3} + \col{J\_2} \vspace{1mm} \\ + \mu + + \col{H\_3} + + \theta \cdot \beta + & + \!\!\!\! + + \Big[\col{A\_3}\cdot\col{B\_1} + + \col{A\_2}\cdot\col{B\_2} + + \col{A\_1}\cdot\col{B\_3}\Big] + & + \!\!\!\! + + \,\, \theta \cdot \col{H\_4} + & \!\!\! = \!\!\! & \theta^2 \cdot \nu + + \theta \cdot \col{J\_5} + \col{J\_4} \vspace{1mm} \\ + \nu + + \col{H\_5} + + \theta \cdot \gamma + & + + \col{A\_3}\cdot\col{B\_3} + & + & \!\!\! = \!\!\! & + \theta \cdot \col{J\_7} + \col{J\_6} \\ + \end{array} + \right. + \] +\end{enumerate} \ No newline at end of file diff --git a/alu/ext/target_oli.tex b/alu/ext/target_oli.tex new file mode 100644 index 0000000..b69f42b --- /dev/null +++ b/alu/ext/target_oli.tex @@ -0,0 +1,55 @@ +We start out with the case of one line instructions: +\begin{enumerate} + \item \If $\oli_{i} = 1$ \Then + \[ + \begin{cases} + \iResHi_{i} = 0 \\ + \iResLo_{i} = 0 \\ + \end{cases} + \] + \iffalse + \item \If \Big($\oli_{i} = 1$ \et $\bit{3}_{i} = 1$\Big) ~ \Then + \[ + \begin{cases} + \iResHi_{i} = 0 \\ + \iResLo_{i} = 0 \\ + \end{cases} + \] + \item \If \Big($\oli_{i} = 1$ \et $\bit{3}_{i} = 0$\Big) \Then + \[ + \begin{cases} + \iResHi_{i} = 0 \\ + \iResLo_{i} = 0 \\ + \end{cases} + \] + \begin{enumerate} + \item \If $\iInst_{i} = \inst{MULMOD}$ + \[ + \begin{cases} + \iResHi_{i} = 0 \\ + \iResLo_{i} = 0 \\ + \end{cases} + \] + \end{enumerate} + \item \If \Big($\oli_{i} = 1$ \et $\iInst_{i} \neq \inst{MULMOD}$\Big) ~ \Then + \begin{enumerate} + \item \If $\bit{1}_{i} = 1$ \Then + \[ + \begin{cases} + \iResHi_{i} = \iArgTwoHi_{i} \\ + \iResLo_{i} = \iArgTwoLo_{i} \\ + \end{cases} + \] + \item \If $\bit{1}_{i} = 0$ \Then + \[ + \begin{cases} + \iResHi_{i} = \iArgOneHi_{i} \\ + \iResLo_{i} = \iArgOneLo_{i} \\ + \end{cases} + \] + \end{enumerate} + \fi +\end{enumerate} +Note that in the implementation one may replace +``\If $\iInst_{i} = \inst{MULMOD}$'' with ``\If $\iInst_{i} \neq \inst{ADDMOD}$'' and +``\If $\iInst_{i} = \inst{ADDMOD}$'' with ``\If $\iInst_{i} \neq \inst{MULMOD}$'' \ No newline at end of file diff --git a/alu/mod/_inputs.tex b/alu/mod/_inputs.tex new file mode 100644 index 0000000..28030d2 --- /dev/null +++ b/alu/mod/_inputs.tex @@ -0,0 +1,17 @@ +\section{Introduction} \label{alu: mod: intro} \input{mod/intro} +\section{Column descriptions} \label{alu: mod: col desc} \input{mod/columns} +\section{Binary constraints} \label{alu: mod: binary} \input{mod/binary} +\section{Shorthands} \label{alu: mod: shorthands} \input{mod/shorthands} +\section{Instruction decoding} \label{alu: mod: instruction decoding} \input{mod/decoding} +\section{\oli{} and \mli{} constraints} \label{alu: mod: oli} \input{mod/oli_mli} +\section{Heartbeat} \label{alu: mod: heartbeat} \input{mod/heartbeat} +\section{Stamp constancy} \label{alu: mod: stamp constancy} \input{mod/constancies} +\section{Bytehood and byte decomposition constraints} \label{alu: mod: byte dec} \input{mod/bytehood} \input{mod/byteDec} +\section{Automatic vanishing} \label{alu: mod: automatic vanishing} \input{mod/res_trivial} +\section{Data organization} \label{alu: mod: orga} \input{mod/organization} +\section{Constraints} \label{alu: mod: constraints} \input{mod/constraints} +\subsection{Aliases} \label{alu: mod: aliases} \input{mod/aliases} +\subsection{Setting absolute values} \label{alu: mod: absolute values} \input{mod/absolute_values} +\subsection{Target constraints} \label{alu: mod: target} \input{mod/target} +\subsection{Comparison constraints} \label{alu: mod: comparisons} \input{mod/comparisons} \input{mod/eq} \input{mod/lt} \input{mod/h} +\subsection{Result constraints} \label{alu: mod: result} \input{mod/res} diff --git a/alu/mod/absolute_values.tex b/alu/mod/absolute_values.tex new file mode 100644 index 0000000..a783abb --- /dev/null +++ b/alu/mod/absolute_values.tex @@ -0,0 +1,23 @@ +We define four more aliases +$\col{A\_HI}$, $\col{A\_LO}$ +and +$\col{B\_HI}$, $\col{B\_LO}$. Note that, for $k=1,=2$, the condition $\instSigned_{i} \cdot \col{sgn\_k} = 1$ is equivalent to +$\instSigned_{i} = 1$ and +$\col{sgn\_k} = 1$ +i.e. the current instruction is a signed instruction (\inst{SMOD} or \inst{SDIV}) +and its $k$-th argument represents a negative integer. With this and our discussion about absolute values in +section~\ref{alu: mod: absolute values} we impose +\begin{enumerate} + \item $\setAbsoluteValue + \Big( + \col{A\_HI}, \col{A\_LO}; + \argOneHi_{i}, \argOneLo_{i}, + \instSigned_{i} \cdot \col{sgn\_1} + \Big)$ + \item $\setAbsoluteValue + \Big( + \col{B\_HI}, \col{B\_LO}; + \argTwoHi_{i}, \argTwoLo_{i}, + \instSigned_{i} \cdot \col{sgn\_2} + \Big)$ +\end{enumerate} diff --git a/alu/mod/aliases.tex b/alu/mod/aliases.tex new file mode 100644 index 0000000..976bce0 --- /dev/null +++ b/alu/mod/aliases.tex @@ -0,0 +1,27 @@ +For the sake of clarity and connecting the constraints of this section with the strategy for proving a euclidean division outlined in section~(\ref{subsec (alu/mod): verif}) we introduce some \emph{aliases} for certain \emph{values}. We emphasize that these don't represent new columns. They are only meant to capture the value of the accumulators at the final row of the byte accumulation process i.e. rows with $\ct_{i} = \mmediumMO$. They thus represent the target values these accumulators strive for. +\begin{multicols}{3} +\begin{enumerate} + \item $\col{ARG1\_3} = \acc{1\_3}_{i}$ + \item $\col{ARG1\_2} = \acc{1\_2}_{i}$ + \item $\col{ARG2\_3} = \acc{2\_3}_{i}$ + \item $\col{ARG2\_2} = \acc{2\_2}_{i}$ + \item $\col{B\_\red{k}} = \acc{B\_\red{k}}_{i}$ + \item $\col{Q\_\red{k}} = \acc{Q\_\red{k}}_{i}$ + \item $\col{R\_\red{k}} = \acc{R\_\red{k}}_{i}$ + \item $\col{$\Delta$\_\red{k}} = \acc{$\Delta$\_\red{k}}_{i}$ + \item $\col{R\_HI} = \theta \cdot \col{R\_3} + \col{R\_2}$ + \item $\col{R\_LO} = \theta \cdot \col{R\_1} + \col{R\_0}$ + \item $\col{Q\_HI} = \theta \cdot \col{Q\_3} + \col{Q\_2}$ + \item $\col{Q\_LO} = \theta \cdot \col{Q\_1} + \col{Q\_0}$ + \item $\col{lt\_\red{k}} = \cmp{1}_{i - 7 + \red{k}}$ + \item $\col{eq\_\red{k}} = \cmp{2}_{i - 7 + \red{k}}$ + \item $\col{sgn\_1} = \msb{1}_{i - 7}$ + \item $\col{sgn\_2} = \msb{2}_{i - 7}$ + \item $\col{H\_\red{n}} = \acc{H\_\red{n}}_{i}$ + \item $\alpha = \cmp{2}_{i - 3}$ + \item $\beta\col{\_0} = \cmp{2}_{i - 2}$ + \item $\beta\col{\_1} = \cmp{2}_{i - 1}$ + \item $\beta = 2 \cdot \beta\col{\_1} + \beta\col{\_0}$ +\end{enumerate} +\end{multicols} +\noindent where $\col{\red{k}}\in\{0,1,2,3\}$ and $\col{\red{n}}\in\{0,1,2\}$. \ No newline at end of file diff --git a/alu/mod/binary.tex b/alu/mod/binary.tex new file mode 100644 index 0000000..55f2cbf --- /dev/null +++ b/alu/mod/binary.tex @@ -0,0 +1,16 @@ +We impose binary constraints on the following columns +\begin{multicols}{5} +\begin{enumerate} + \item \isSmod {} + \item \isMod {} + \item \isSdiv {} + \item \isDiv {} + \item \oli{} + \item \mli{} + \item \cmp{1} + \item \cmp{2} + \item \msb{1} + \item \msb{2}. +\end{enumerate} +\end{multicols} +\saNote{} Further constraints will implicitly impose binaryness on \instSigned{}. We don't need to impose it. diff --git a/alu/mod/byteDec.tex b/alu/mod/byteDec.tex new file mode 100644 index 0000000..e535d07 --- /dev/null +++ b/alu/mod/byteDec.tex @@ -0,0 +1,19 @@ +\noindent We impose the standard byte decomposition constraints: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\ACC_{i} = \col{BYTE}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\ACC_{i} = 256 \cdot \ACC_{i - 1} + \col{BYTE}_{i}$; +\end{enumerate} +for the following byte/accumulator pairs +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{B\_k}$/$\acc{B\_k}$ for $k=0,1,2,3$; + \item $\byteCol{Q\_k}$/$\acc{Q\_k}$ for $k=0,1,2,3$; + \item $\byteCol{R\_k}$/$\acc{R\_k}$ for $k=0,1,2,3$; + \item $\byteCol{$\Delta$\_k}$/$\acc{$\Delta$\_k}$ for $k=0,1,2,3$; + \item $\byteCol{H\_k}$/$\acc{H\_k}$ for $k=0,1,2$; + \item $\byteCol{1\_k}$/$\acc{1\_k}$ for $k=2,3$; + \item $\byteCol{2\_k}$/$\acc{2\_k}$ for $k=2,3$; + \item[\vspace{\fill}] + %\item[\vspace{\fill}] +\end{enumerate} +\end{multicols} diff --git a/alu/mod/bytehood.tex b/alu/mod/bytehood.tex new file mode 100644 index 0000000..7ee0133 --- /dev/null +++ b/alu/mod/bytehood.tex @@ -0,0 +1,13 @@ +We impose \textbf{bytehood constraints} on all of the following (families of) columns +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{B\_k}$, for $k=0,1,2,3$ + \item $\byteCol{Q\_k}$, for $k=0,1,2,3$ + \item $\byteCol{R\_k}$, for $k=0,1,2,3$ + \item $\byteCol{$\Delta$\_k}$, for $k=0,1,2,3$ + \item $\byteCol{H\_k}$, for $k=0,1,2$ + \item $\byteCol{1\_k}$, $k = 2, 3$ + \item $\byteCol{2\_k}$, $k = 2, 3$ + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} diff --git a/alu/mod/columns.tex b/alu/mod/columns.tex new file mode 100644 index 0000000..b20ec9b --- /dev/null +++ b/alu/mod/columns.tex @@ -0,0 +1,62 @@ +The following are the columns of the adder module. +\begin{enumerate} + \item $\modSTAMP$: + modular arithmetic module time stamp column; abbreviated to $\modStamp$; + \item \oli{} and \mli{}: + exclusive (\emph{de facto}) counter-constant binary columns indicating whether an instruction is a \OLI{} or a \MLI{} respectively; + \item $\CT$: + counter column; either hovers around $0$ or counts monotonically from $0$ to $\mmediumMO$ then resets to $0$; abbreviated to $\ct$; + \item $\INST$: + imported instruction column; + \item \isDiv {}: + instruction-decoded bit column; + \item \isSdiv {}: + instruction-decoded bit column; + \item \isMod {}: + instruction-decoded bit column; + \item \isSmod {}: + instruction-decoded bit column; + \item $\instSigned$: + binary column which lights up precisely for signed instructions (i.e. \inst{SMOD} and \inst{SDIV}); + % \item $\decInstOutput$: + % instruction decoded binary column; + \item $\argOneHi$, $\argOneLo$: + imported column containing the high and low parts of an instruction's first argument; + \item $\argTwoHi$, $\argTwoLo$: + imported column containing the high and low parts of an instruction's second argument; + \item $\resHi$, $\resLo$: + imported column containing the high and low parts of an instruction's output; + \item $\byteCol{1\_3}$, $\byteCol{1\_2}$: + byte columns required to extract the sign bit of $\argOne$; + \item $\byteCol{2\_3}$, $\byteCol{2\_2}$: + byte columns required to extract the sign bit of $\argTwo$; + \item $\byteCol{B\_k}$, for $k=0,1,2,3$: + byte columns; + \item $\byteCol{Q\_k}$, for $k=0,1,2,3$: + byte columns; + \item $\byteCol{R\_k}$, for $k=0,1,2,3$: + byte columns; + \item $\byteCol{$\Delta$\_k}$, for $k=0,1,2,3$: + byte columns; + \item $\byteCol{H\_k}$, for $k=0,1,2$: + byte columns; + \item $\acc{1\_2}$, $\acc{1\_3}$: + associated accumulator columns; + \item $\acc{2\_2}$, $\acc{2\_3}$: + associated accumulator columns; + \item $\acc{B\_k}$, for $k=0,1,2,3$: + associated accumulator columns; + \item $\acc{Q\_k}$, for $k=0,1,2,3$: + associated accumulator columns; + \item $\acc{R\_k}$, for $k=0,1,2,3$: + associated accumulator columns; + \item $\acc{$\Delta$\_k}$, for $k=0,1,2,3$: + associated accumulator columns; + \item $\acc{H\_k}$, for $k=0,1,2$: + associated accumulator columns; + \item $\cmp{1}, \cmp{2}$: + binary columns pertaining to certain comparisons and overflows; + \item $\msb{1}, \msb{2}$: + binary columns pertaining to certain bit decompositions; + contain the sign bit of the instruction arguments; +\end{enumerate} diff --git a/alu/mod/comparisons.tex b/alu/mod/comparisons.tex new file mode 100644 index 0000000..1e19095 --- /dev/null +++ b/alu/mod/comparisons.tex @@ -0,0 +1,43 @@ +This section is about justifying the comparison bits $\col{lt\_k}$ and $\col{eq\_k}$, $k=0,1,2,3$. +To do so we impose the following constraints: +\[ +\left\{ +\begin{array}{lcl} + \big(2 \cdot \col{lt\_3} - 1\big) \cdot \big(\col{B\_3} - \col{R\_3}\big) & \!\!\! = \!\!\! & \col{$\Delta$\_3} + \col{lt\_3} \\ + \big(2 \cdot \col{lt\_2} - 1\big) \cdot \big(\col{B\_2} - \col{R\_2}\big) & \!\!\! = \!\!\! & \col{$\Delta$\_2} + \col{lt\_2} \\ + \big(2 \cdot \col{lt\_1} - 1\big) \cdot \big(\col{B\_1} - \col{R\_1}\big) & \!\!\! = \!\!\! & \col{$\Delta$\_1} + \col{lt\_1} \\ + \big(2 \cdot \col{lt\_0} - 1\big) \cdot \big(\col{B\_0} - \col{R\_0}\big) & \!\!\! = \!\!\! & \col{$\Delta$\_0} + \col{lt\_0} \\ +\end{array} +\right. +\] +The interpretation is as follows: +\[ +\left\{ +\begin{array}{lcl} + \col{lt\_3} = 1 & \!\!\! \iff \!\!\! & \col{B\_3} > \col{R\_3} \\ + \col{lt\_2} = 1 & \!\!\! \iff \!\!\! & \col{B\_2} > \col{R\_2} \\ + \col{lt\_1} = 1 & \!\!\! \iff \!\!\! & \col{B\_1} > \col{R\_1} \\ + \col{lt\_0} = 1 & \!\!\! \iff \!\!\! & \col{B\_0} > \col{R\_0} \\ +\end{array} +\right. +\] +``Equality bits'' are stored in the first half of $\cmp{2}$. We constrain these values as follows: +\[ +\left\{ +\begin{array}{l} + \If \col{B\_3} = \col{R\_3} ~ \Then \col{eq\_3} = 1 \\ + \If \col{B\_3} \neq \col{R\_3} ~ \Then \col{eq\_3} = 0 \vspace{2mm} \\ + \If \col{B\_2} = \col{R\_2} ~ \Then \col{eq\_2} = 1 \\ + \If \col{B\_2} \neq \col{R\_2} ~ \Then \col{eq\_2} = 0 \vspace{2mm} \\ + \If \col{B\_1} = \col{R\_1} ~ \Then \col{eq\_1} = 1 \\ + \If \col{B\_1} \neq \col{R\_1} ~ \Then \col{eq\_1} = 0 \vspace{2mm} \\ + \If \col{B\_0} = \col{R\_0} ~ \Then \col{eq\_0} = 1 \\ + \If \col{B\_0} \neq \col{R\_0} ~ \Then \col{eq\_0} = 0 \\ +\end{array} +\right. +\] +Finally we enforce the comparison constraint of euclidean division, that is, that the remainder be $<$ than what one divides by: +\[ + \col{lt\_3} ~ + ~ \col{eq\_3} \cdot \col{lt\_2} ~ + ~ \col{eq\_3} \cdot \col{eq\_2} \cdot \col{lt\_1} ~ + ~ \col{eq\_3} \cdot \col{eq\_2} \cdot \col{eq\_1} \cdot \col{lt\_0} = 1 +\] +This amounts to imposing $0 \leq \res < \argTwo$. diff --git a/alu/mod/constancies.tex b/alu/mod/constancies.tex new file mode 100644 index 0000000..28a251c --- /dev/null +++ b/alu/mod/constancies.tex @@ -0,0 +1,17 @@ +As always we say that a column $\col{X}$ is \textbf{stamp-constant} if it satisfies +\[ + \If \modStamp_{i} \neq 1 + \modStamp_{i - 1} ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We impose stamp-constancy on the following columns: +\begin{multicols}{4} +\begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resHi$ + \item $\resLo$ + \item $\INST$ +\end{enumerate} +\end{multicols} +Note also that $\oli$ is stamp-constant by construction. diff --git a/alu/mod/constraints.tex b/alu/mod/constraints.tex new file mode 100644 index 0000000..b0e3a0e --- /dev/null +++ b/alu/mod/constraints.tex @@ -0,0 +1,6 @@ +\[ + \framebox{\emph{All} constraints in this section assume $\ct_{i} = \mmediumMO$.} +\] +i.e. we jump straight to the final row of a (multi line) instruction. + +\saNote{} The above has implicit consequences such as $\modStamp_{i} \neq 0$ and $\mli_{i} = 1$. diff --git a/alu/mod/decoding.tex b/alu/mod/decoding.tex new file mode 100644 index 0000000..b98da54 --- /dev/null +++ b/alu/mod/decoding.tex @@ -0,0 +1,16 @@ +This section enforces the instruction decoding by means of the +\begin{enumerate} + \item \If $\modStamp_{i} = 0$ \Then $\locFlagSum_{i} = 0$ + \item \If $\modStamp_{i} \neq 0$ \Then $\locFlagSum_{i} = 1$ + \item We impose the following unique decoding constraint: + \[ + \left\{ \begin{array}{lcl} + \INST_{i} & = & \locWeightedFlagSum_{i} \\ + \instSigned_{i} & = & \locSignedInst_{i} \\ + % \oli_{i} & = & \locOli_{i} \\ + % \mli_{i} & = & \locMli_{i} \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{} Since \locFlagSum{} is a sum of binary columns the above enforces that at any row at most one of these may be on. + diff --git a/alu/mod/eq.tex b/alu/mod/eq.tex new file mode 100644 index 0000000..e69de29 diff --git a/alu/mod/h.tex b/alu/mod/h.tex new file mode 100644 index 0000000..7962494 --- /dev/null +++ b/alu/mod/h.tex @@ -0,0 +1,19 @@ +We now constrain the ``$\col{H}$'s'': +\[ +\left\{ +\begin{array}{lcl} + \theta^2 \cdot \cmp{2}_{i-3} \\ + \quad + \, \theta \cdot \acc{H\_1}_{i} \\ + \quad \quad + \, \acc{H\_0}_{i} + & = & + \acc{B\_0}_{i} \cdot \acc{Q\_1}_{i} + \acc{B\_1}_{i} \cdot \acc{Q\_0}_{i} \vspace{2mm} \\ + \acc{H\_2}_{i} + & = & + \acc{B\_0}_{i} \cdot \acc{Q\_3}_{i} + + \acc{B\_1}_{i} \cdot \acc{Q\_2}_{i} \\ + & & \quad + + \, \acc{B\_2}_{i} \cdot \acc{Q\_1}_{i} + + \acc{B\_3}_{i} \cdot \acc{Q\_0}_{i} \\ +\end{array} +\right. +\] \ No newline at end of file diff --git a/alu/mod/heartbeat.tex b/alu/mod/heartbeat.tex new file mode 100644 index 0000000..08517e3 --- /dev/null +++ b/alu/mod/heartbeat.tex @@ -0,0 +1,15 @@ +The heartbeat of the modular arithmetic module is simple. +There is a counter that either hovers around $0$ if $\oli = 1$ or counts monotonically from $0$ to $\mmediumMO$ if $\mli = 1$. +\begin{enumerate} + \item $\modStamp_{0} = 0$ + \item $\modStamp_{i + 1} \in \{ \modStamp_{i}, 1 + \modStamp_{i} \}$ + \item \If $\modStamp_{i} = 0$ \Then $\ct_{i} = 0$ \quad (\trash) + \item \If $\modStamp_{i} \neq \modStamp_{i - 1}$ \Then $\ct_{i} = 0$ + \item \If $\oli_{i} = 1$ \Then $\modStamp_{i + 1} = 1 + \modStamp_{i}$ + \item \If $\mli_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \mmediumMO$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \mmediumMO$ \Then $\modStamp_{i + 1} = 1 + \modStamp_{i}$ + \end{enumerate} + \item \If $\mli_{N} = 1$ \Then $\ct_{N} = \mmediumMO$ +\end{enumerate} diff --git a/alu/mod/intro.tex b/alu/mod/intro.tex new file mode 100644 index 0000000..e4fc292 --- /dev/null +++ b/alu/mod/intro.tex @@ -0,0 +1,9 @@ +The \textbf{modular arithmetic} module deals with the following instructions: +\begin{multicols}{2} +\begin{enumerate} + \item \col{MOD} + \item \col{DIV} + \item \col{SMOD} + \item \col{SDIV} +\end{enumerate} +\end{multicols} \ No newline at end of file diff --git a/alu/mod/lt.tex b/alu/mod/lt.tex new file mode 100644 index 0000000..e69de29 diff --git a/alu/mod/oli_mli.tex b/alu/mod/oli_mli.tex new file mode 100644 index 0000000..b183c96 --- /dev/null +++ b/alu/mod/oli_mli.tex @@ -0,0 +1,16 @@ +The present section describes the constraints imposed on the $\oli$ and $\mli$ columns. We begin with a general constraint: +\begin{enumerate} + \item $\oli_{i} + \mli_{i} = \locFlagSum_{i}$ +\end{enumerate} +The above enforces in particular that $\oli, \mli \equiv 0$ along padding-rows (i.e. rows where $\modStamp\equiv 0$.) +\begin{enumerate}[resume] + \item \If $\modStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If \big($\argTwoHi_{i} = 0$ \et $\argTwoLo_{i} = 0$\big) \Then $\oli_{i} = 1$ + \item \If \big($\argTwoHi_{i} \neq 0$ \OR $\argTwoLo_{i} \neq 0$\big) \Then $\mli_{i} = 1$. + \end{enumerate} +\end{enumerate} +% \begin{center} +% \framebox{All constraints in this section assume that $\modStamp_{i}\neq0$.} +% \end{center} +% As specified in the \textsc{evm yellowpaper} \ob{TODO: reference it} there are certain scenarios that are special with respect to the instructions dealt with in the present module. Our arithmetization doesn't need to deal with the ``overflow semantic'' of the \inst{SDIV} instruction. We thus specify $\oli$ as follows. diff --git a/alu/mod/organization.tex b/alu/mod/organization.tex new file mode 100644 index 0000000..b49dbb3 --- /dev/null +++ b/alu/mod/organization.tex @@ -0,0 +1,29 @@ +This section contains describes the desired layout of data in certain columns when $\mli \equiv 1$. +\begin{figure}[!h] +\[ +\renewcommand{\arraystretch}{1.5} +\begin{array}{|c|c|c|c|c|c|c|} +\hline +\ct{} & \cmp{1} & \cmp{2} & \msb{1} & \msb{2} & +\byteCol{1\_3} & \byteCol{2\_3} \\ \hline +0 & \col{lt}_{0} & \col{eq}_{0} & \col{sgn}_{1} & \col{sgn}_{2} & \col{B}_{7} & \col{B}_{7}' \\ \hline +1 & \col{lt}_{1} & \col{eq}_{1} & \col{b}_{6} & \col{b}_{6}' & \multirow{6}{*}{$\vdots$} & \multirow{6}{*}{$\vdots$} \\ \cline{1-5} +2 & \col{lt}_{2} & \col{eq}_{2} & \col{b}_{5} & \col{b}_{5}' & & \\ \cline{1-5} +3 & \col{lt}_{3} & \col{eq}_{3} & \col{b}_{4} & \col{b}_{4}' & & \\ \hhline{|-|-|-|-|-|} +4 & {\cellcolor{solarized-orange}} & \alpha & \col{b}_{3} & \col{b}_{3}' & & \\ \hhline{|-|-|-|-|-|} +5 & {\cellcolor{solarized-orange}} & \beta_{0} & \col{b}_{2} & \col{b}_{2}' & & \\ \hhline{|-|-|-|-|-|} +6 & {\cellcolor{solarized-orange}} & \beta_{1} & \col{b}_{1} & \col{b}_{1}' & & \\ \hline +\mmediumMO & {\cellcolor{solarized-orange}} & {\cellcolor{solarized-orange}} & \col{b}_{0} & \col{b}_{0}' & \col{B}_{0} & \col{B}_{0}' \\ \hline +\end{array} +\] +\caption{% +The above represents the desired layout of data across the +$\cmp{1}$, $\cmp{2}$, $\msb{1}$, $\msb{2}$ columns. +The binary columns $\cmp{1}$, $\cmp{2}$ contain bits encoding information relative to certain comparisons (the $\col{lt}_{k}$'s and $\col{eq}_{k}$'s) as well as certain bits that capture overflows ($\alpha$ and $\beta_{0}$, $\beta_{1}$.) +$\byteCol{1\_3}$ and $\byteCol{2\_3}$ contain the byte decomposition of $\argOne_{3}$ and $\argTwo_{3}$ respectively (both of which are $\mmedium$-byte integers.) +$\msb{1}$ and $\msb{1}$ contain the bit decomposition of $\argOne$ and $\argTwo$'s most significant byte, written here $\col{B}_{7}$ and $\col{B}_{7}'$ respectively. +Our notation singles out their respective most significant bit. +Thus $\col{sgn}_{1}$ and $\col{sgn}_{2}$ are the sign bit of $\argOne$ and $\argTwo$ respectively. +The sign bits play a role whenever the instruction's arguments are to be understood as 2's complement signed integers. \\ +The orange cells are left unused.} +\end{figure} diff --git a/alu/mod/res.tex b/alu/mod/res.tex new file mode 100644 index 0000000..a0f8b34 --- /dev/null +++ b/alu/mod/res.tex @@ -0,0 +1,49 @@ +We finally constrain the results: +\begin{enumerate} + \item \If $\isMod_{i} = 1$ \Then + \[ + \begin{cases} + \resHi_{i} = \col{R\_HI} \\ + \resLo_{i} = \col{R\_LO} \\ + \end{cases} + \] + \item \If $\isDiv_{i} = 1$ \Then + \[ + \begin{cases} + \resHi_{i} = \col{Q\_HI} \\ + \resLo_{i} = \col{Q\_LO} \\ + \end{cases} + \] + \item \If $\isSmod_{i} = 1$ \Then + \begin{enumerate} + \item \If $\col{sgn\_1} = 0$ \Then + \[ + \begin{cases} + \resHi_{i} = \col{R\_HI} \\ + \resLo_{i} = \col{R\_LO} \\ + \end{cases} + \] + \item \If $\col{sgn\_1} = 1$ \Then + $\setNegative + \Big( + \resHi, \resLo; + \col{R\_HI}, \col{R\_LO} + \Big)$ + \end{enumerate} + \item \If $\isSdiv_{i} = 1$ \Then + \begin{enumerate} + \item \If $\col{sgn\_1} = \col{sgn\_2}$ \Then + \[ + \begin{cases} + \resHi_{i} = \col{Q\_HI} \\ + \resLo_{i} = \col{Q\_LO} \\ + \end{cases} + \] + \item \If $\col{sgn\_1} \neq \col{sgn\_2}$ \Then + $\setNegative + \Big( + \resHi, \resLo; + \col{Q\_HI}, \col{Q\_LO} + \Big)$ + \end{enumerate} +\end{enumerate} diff --git a/alu/mod/res_trivial.tex b/alu/mod/res_trivial.tex new file mode 100644 index 0000000..7153e29 --- /dev/null +++ b/alu/mod/res_trivial.tex @@ -0,0 +1,11 @@ +One line instructions occur precisely when computing $\mod 0$. The results must then vanish. +As such we impose that +\begin{enumerate} + \item \If $\oli_{i} = 1$ \Then + \[ + \begin{cases} + \resHi_{i} = 0 \\ + \resLo_{i} = 0 \\ + \end{cases} + \] +\end{enumerate} diff --git a/alu/mod/shorthands.tex b/alu/mod/shorthands.tex new file mode 100644 index 0000000..57205be --- /dev/null +++ b/alu/mod/shorthands.tex @@ -0,0 +1,29 @@ +We use the following shorthands +\[ + \locFlagSum_{i} + \equiv + \left[ \begin{array}{cr} + + & \isSmod _{i} \\ + + & \isMod _{i} \\ + + & \isSdiv _{i} \\ + + & \isDiv _{i} \\ + \end{array} \right] + \quad\text{and}\quad + \locWeightedFlagSum_{i} + \equiv + \left[ \begin{array}{crcl} + + & \inst{SMOD} & \cdot & \isSmod _{i} \\ + + & \inst{MOD} & \cdot & \isMod _{i} \\ + + & \inst{SDIV} & \cdot & \isSdiv _{i} \\ + + & \inst{DIV} & \cdot & \isDiv _{i} \\ + \end{array} \right] +\] +We further set +\[ + \locSignedInst_{i} + \equiv + \left[ \begin{array}{cr} + + & \isSmod _{i} \\ + + & \isSdiv _{i} \\ + \end{array} \right] +\] diff --git a/alu/mod/target.tex b/alu/mod/target.tex new file mode 100644 index 0000000..8b84149 --- /dev/null +++ b/alu/mod/target.tex @@ -0,0 +1,42 @@ +We impose the following target constraints: +\[ +\left\{ \begin{array}{lcl} + \argOneHi_{i} & \!\!\! = \!\!\! & \theta \cdot \col{ARG1\_3} + \col{ARG1\_2} \\ + \argTwoHi_{i} & \!\!\! = \!\!\! & \theta \cdot \col{ARG2\_3} + \col{ARG2\_2} \vspace{2mm} \\ + % + \multicolumn{3}{l}{\byteCol{1\_3}_{i - 7} = \sum_{k = 0}^7 2^{k} \cdot \msb{1}_{i - k}} \\ + % + \multicolumn{3}{l}{\byteCol{2\_3}_{i - 7} = \sum_{k = 0}^7 2^{k} \cdot \msb{2}_{i - k}} \vspace{2mm} \\ + % + \col{B\_HI} & \!\!\! = \!\!\! & \theta \cdot \col{B\_3} + \col{B\_2} \\ + \col{B\_LO} & \!\!\! = \!\!\! & \theta \cdot \col{B\_1} + \col{B\_0} \vspace{2mm} \\ + % + \multicolumn{3}{l}{% + \col{B\_0} \cdot \col{Q\_1} + \col{B\_1} \cdot \col{Q\_0} = \theta^2 \cdot \alpha + \theta \cdot \col{H\_1} + \col{H\_0}} \\ + % + \multicolumn{3}{l}{% + \col{B\_0} \cdot \col{Q\_3} + \col{B\_1} \cdot \col{Q\_2} + \col{B\_2} \cdot \col{Q\_1} + \col{B\_3} \cdot \col{Q\_0} = \col{H\_2}} \vspace{2mm} \\ + % + \multicolumn{3}{l}{ \col{B\_0} \cdot \col{Q\_0} + \theta \cdot \col{H\_0} + \col{R\_LO} = \col{A\_LO} + \theta^2 \cdot \beta} \\ + % + \multicolumn{3}{l}{% + \beta + \col{H\_1} + \theta \cdot \alpha + + \big(\col{B\_0} \cdot \col{Q\_2} + \col{B\_1} \cdot \col{Q\_1} + \col{B\_2} \cdot \col{Q\_0}\big) + + \theta \cdot \col{H\_2} + \col{R\_HI} + = + \col{A\_HI}} \vspace{2mm} \\ + \multicolumn{3}{l}{% + \col{B\_1} \cdot \col{Q\_3} + \col{B\_2} \cdot \col{Q\_2} + \col{B\_3} \cdot \col{Q\_1} + + \col{B\_2} \cdot \col{Q\_3} + \col{B\_3} \cdot \col{Q\_2} + + \col{B\_3} \cdot \col{Q\_3} = 0} \\ +\end{array} \right. +\] +The interpretation is as follows: +\begin{itemize} + \item $\byteCol{1\_3}$ and $\byteCol{1\_2}$ are the byte decompositions of $\argOne_{3}$ and $\argOne_{2}$ respectively; taken together they provide the byte decomposition of $\argOne\high$; + \item $\byteCol{2\_3}$ and $\byteCol{2\_2}$ are the byte decompositions of $\argTwo_{3}$ and $\argTwo_{2}$ respectively; taken together they provide the byte decomposition of $\argTwo\high$; + \item $\msb{1}$ is the bit decomposition of the most significant byte of $\argOne$; + \item $\msb{2}$ is the bit decomposition of the most significant byte of $\argTwo$; + \item $\col{B\_0} \cdot \col{Q\_1} + \col{B\_1} \cdot \col{Q\_0} \equiv [0 \,|\, \alpha \,|\, \col{H\_1} \,|\, \col{H\_0}]$ + \item $\col{B\_0} \cdot \col{Q\_0} + \theta \cdot \col{H\_0} + \col{R\_HI} \equiv [\beta \,\|\, \col{A\_LO}]$ +\end{itemize} diff --git a/alu/mul/_inputs.tex b/alu/mul/_inputs.tex new file mode 100644 index 0000000..1dfd2d0 --- /dev/null +++ b/alu/mul/_inputs.tex @@ -0,0 +1,18 @@ +\section{Introduction} \input{mul/intro} +\section{Column descriptions} \label{alu: mul: columns} \input{mul/columns} +\section{Heartbeat} +\subsection{Regimes} \input{mul/regimes} +\subsection{Constraints} \input{mul/heartbeat} +\subsection{Intention} \input{mul/intended} +\section{Constancy constraints} \label{alu: mul: constancies} \input{mul/constancies} +\section{Binary and bytehood constraints} \label{alu: mul: bits and bytes} \input{mul/binary_and_bytehood} +\section{Byte decompositions} \label{alu: mul: byte decompositions} \input{mul/byteDec} +\section{\tinyBase{}, \tinyExponent{}, \oli{} and \resVanishes{} constraints} \label{alu: mul: tiny base, tiny exponent, oli and result vanishes binary columns} \input{mul/oli} +\section{Trivial regime} \label{alu: mul: trivial regime} \input{mul/regime_trivial} +\section{Aliases} \label{alu: mul: aliases} \input{mul/aliases} +\section{Nontrivial \inst{MUL} regime} \label{alu: mul: nontrivial mul regime} \input{mul/regime_mul} +\section{Nontrivial \inst{EXP} regime --- zero result regime} \label{alu: mul: nontrivial mul regime: zero result} +\subsection{High level approach} \label{alu: mul: nontrivial mul regime: zero result approach} \input{mul/regime_exp_zero_approach_hi} +\subsection{Low level approach i.e. \prepareLowerBoundOnTwoAdicity{}} \label{alu: mul: nontrivial mul regime: zero result approach} \input{mul/regime_exp_zero_approach_lo} +\subsection{Constraint system} \label{alu: mul: nontrivial mul regime: zero result constraints} \input{mul/regime_exp_zero_constraints} +\section{Nontrivial \inst{EXP} regime --- nonzero result regime} \label{alu: mul: nontrivial mul regime: small exponent} \input{mul/regime_exp_small} diff --git a/alu/mul/aliases.tex b/alu/mul/aliases.tex new file mode 100644 index 0000000..1f3990f --- /dev/null +++ b/alu/mul/aliases.tex @@ -0,0 +1,23 @@ +In the sequel many constraints will be stated at final rows of counter-cycles i.e. rows $i$ satisfying $\ct_{i} = \mmediumMO$. For such row indices $i$ (and no other) we allow ourselves the following notational shorthands: +\[ + \left\{ + \begin{array}{lclr} + \col{A\_k} & \!\!\! = \!\!\! & \acc{A\_k}_{i}, & k = 0,1,2,3;\\ + \col{B\_k} & \!\!\! = \!\!\! & \acc{B\_k}_{i}, & k = 0,1,2,3;\\ + \col{C\_k} & \!\!\! = \!\!\! & \acc{C\_k}_{i}, & k = 0,1,2,3;\\ + \col{C'\_k} & \!\!\! = \!\!\! & \acc{C\_k}_{i- 8}, & k = 0,1,2,3;\\ + \col{H\_k} & \!\!\! = \!\!\! & \acc{H\_k}_{i}, & k = 0,1,2,3;\\ + \end{array} + \right. + \quad\text{and}\quad + \left\{ + \begin{array}{lcl} + \alpha & \!\!\! = \!\!\! & \bits_{i-5} \\ + \beta_{0} & \!\!\! = \!\!\! & \bits_{i-4} \\ + \beta_{1} & \!\!\! = \!\!\! & \bits_{i-3} \\ + \eta & \!\!\! = \!\!\! & \bits_{i-2} \\ + \mu_{0} & \!\!\! = \!\!\! & \bits_{i-1} \\ + \mu_{1} & \!\!\! = \!\!\! & \bits_{i} \\ + \end{array} + \right. +\] \ No newline at end of file diff --git a/alu/mul/binary_and_bytehood.tex b/alu/mul/binary_and_bytehood.tex new file mode 100644 index 0000000..a5f5063 --- /dev/null +++ b/alu/mul/binary_and_bytehood.tex @@ -0,0 +1,24 @@ +We impose that the following columns be binary: +\begin{multicols}{4} +\begin{enumerate} + \item $\oli{}$ + \item $\expBit{}$ + \item $\expBitSrc{}$ + \item $\snm{}$ + \item $\bits{}$ + \item $\tinyBase{}$ + \item $\tinyExponent{}$ + \item $\resVanishes{}$ +% \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\noindent We also impose bytehood constraints on the following columns: +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{A\_k}$, for $k=0,1,2,3$ + \item $\byteCol{B\_k}$, for $k=0,1,2,3$ + \item $\byteCol{C\_k}$, for $k=0,1,2,3$ + \item $\byteCol{H\_k}$, for $k=0,1,2,3$ +\end{enumerate} +\end{multicols} +\noindent\ob{TODO: make sure the the $\byteCol{H\_3}/\acc{H\_3}$ is required.} \ No newline at end of file diff --git a/alu/mul/byteDec.tex b/alu/mul/byteDec.tex new file mode 100644 index 0000000..c3db651 --- /dev/null +++ b/alu/mul/byteDec.tex @@ -0,0 +1,16 @@ +We impose the standard byte decomposition constraints: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\ACC_{i} = \col{BYTE}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\ACC_{i} = 256 \cdot \ACC_{i - 1} + \col{BYTE}_{i}$; +\end{enumerate} +on the following byte/accumulator pairs +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{A\_k}$/$\acc{A\_k}$ for $k=0,1,2,3$; + \item $\byteCol{B\_k}$/$\acc{B\_k}$ for $k=0,1,2,3$; + \item $\byteCol{C\_k}$/$\acc{C\_k}$ for $k=0,1,2,3$; + \item $\byteCol{H\_k}$/$\acc{H\_k}$ for $k=0,1,2,3$; + %\item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\noindent\ob{TODO: make sure the the $\byteCol{H\_3}/\acc{H\_3}$ is required.} \ No newline at end of file diff --git a/alu/mul/columns.tex b/alu/mul/columns.tex new file mode 100644 index 0000000..bcd3683 --- /dev/null +++ b/alu/mul/columns.tex @@ -0,0 +1,50 @@ +\begin{enumerate} + \item $\mulSTAMP$: multiplier module time stamp; abbreviated to $\mulStamp$; + \item $\CT$: counter column; either hovers around $0$ or counts monotonically from $0$ to $\mmediumMO$ then resets to $0$; abbreviated to $\ct$; + \item $\OLI$: binary column; equals $1$ \emph{iff} $\iInst = \inst{EXP}$ and the exponent is zero; abbreviated to $\oli$; + \item $\TINYBASE$: binary column; equals one \emph{iff} $\iArgOne \in \{0, 1\}$; abbreviated to $\tinyBase$; + \item $\TINYEXPONENT$: binary column; equals one \emph{iff} $\iArgTwo \in \{0, 1\}$; abbreviated to $\tinyExponent$; + \item $\RESVANISHES$: binary column; equals one \emph{iff} the result of a nontrivial \inst{EXP} instruction is zero; abbreviated to $\resVanishes$ +\end{enumerate} +\noindent We define a \textbf{counter-cycle} to be $\mmedium$ consecutive rows where $\ct$ goes from $0$ to $\mmediumMO$. The $\ct$ column either hovers around $0$ or performs counter-cycles. It will engage in a counter-cycle \emph{iff} $\oli = 0$ and $\mulStamp \neq 0$. We set $\oli = 1$ whenever the inputs of the instruction are such (section~\ref{subsec (alu/exp): tiny base, tiny exponent, oli and result vanishes binary columns}) that the result is clear without any computation (section~\ref{alu: mul: trivial regime}.) +% and one could also have a \col{FAST} flag which equals $1$ \emph{iff} $\iInst = \inst{EXP}$, the base $\iArgOne$ is even and the exponent $\iArgTwo$ is $\geq 256$. We presently won't implement these optimizations. +\begin{enumerate}[resume] + \item $\iInst$: imported instruction column; + \item $\iArgOneHi$, $\iArgOneLo$: + imported high and low parts of an instruction's first argument; + \item $\iArgTwoHi$, $\iArgTwoLo$: + imported high and low parts of an instruction's second argument; + \item $\iResHi$, $\iResLo$: + imported high and low parts of an instruction's output; +\end{enumerate} +Given the stack pattern associated with $\inst{MUL}$ and $\inst{EXP}$ (which is $\stdSP$) we will impose that +$\iArgOneHi$, $\iArgOneLo$ be imports of $\sValHi{1}$ and $\sValLo{1}$, +$\iArgTwoHi$, $\iArgTwoLo$ be imports of $\sValHi{3}$ and $\sValLo{3}$ and +$\iResHi$, $\iResLo$ be imports of $\sValHi{4}$ and $\sValLo{4}$ respectively. +\begin{enumerate}[resume] + \item $\bits$: binary column containing bits whose interpretation pertains to overflows; + \item $\byteCol{A\_k}$, for $k=0,1,2,3$: byte columns; + \item $\byteCol{B\_k}$, for $k=0,1,2,3$: byte columns; + \item $\byteCol{C\_k}$, for $k=0,1,2,3$: byte columns; + \item $\byteCol{H\_k}$, for $k=0,1,2$: byte columns; + \item $\acc{A\_k}$, for $k=0,1,2,3$: associated accumulator columns; + \item $\acc{B\_k}$, for $k=0,1,2,3$: associated accumulator columns; + \item $\acc{C\_k}$, for $k=0,1,2,3$: associated accumulator columns; + \item $\acc{H\_k}$, for $k=0,1,2,3$: associated accumulator columns; \ob{TODO: make sure the last one is required} +\end{enumerate} +The following columns pertain to the arithmetization of the \inst{EXP} instruction. +\begin{enumerate}[resume] + \item $\SNM$: counter-constant binary column pertaining to \inst{EXP} instructions; the ``square and multiply'' bit abbreviated to \snm{}; \ob{TODO: this column is technically useless, could be merged into the \bits{} column \dots{}} + \item $\EXPBIT$: binary column containing bits of the exponent; abbreviated to $\expBit$; + \item $\EXPBITACC$: column accumulating the bits of either the high or low part of the exponent; abbreviated to $\expBitAcc$; + \item $\EXPBITSRC$: binary column indicating the ``source'' (i.e. high or low part of the exponent) of the exponent bit; abbreviated to $\expBitSrc$; + \item $\nBits$: counter-constant colunm with values in the range $\{0, 1, \dots, \oneTwoSeven \}$ +\end{enumerate} +We provide more details for the above. +Exponentiation happens in one or two phases depending on whether the high part of the exponent is zero or nonzero. +% +If the high part of the exponent is \emph{zero} then $\EXPBITSRC$ starts off at $1$ (and remains $=1$ throughout.) In this scenario exponentiation immediately starts using (up to $\oneTwoEight$) bits from the low part of the exponent i.e. ``$\EXPBIT\in$ bits of $\iArgTwoLo$'s bit decomposition.'' The process stops as soon as either the low part of the exponent is reconstructed in $\EXPBITACC$ or an intermediate value of the ``square and multiply'' process results in zero. +% +If the high part of the exponent is \emph{nonzero} then $\EXPBITSRC$ starts off at $0$ and at some point switches to $1$/. Exponentiation first uses (up to $\oneTwoEight$) bits from the high part of the expnonent and then (precisely $\oneTwoEight$) bits from the low part of the exponent. +The $\EXPBITSRC$ column indicates which bits are currently in use in an \inst{EXP} instruction. +An \inst{EXP} instruction is currently dealing with bits belonging to the high part of the exponent \emph{iff} $\expBitSrc = 0$ and with bits belonging to the low part of the exponent \emph{iff} $\expBitSrc = 1$. diff --git a/alu/mul/constancies.tex b/alu/mul/constancies.tex new file mode 100644 index 0000000..9738757 --- /dev/null +++ b/alu/mul/constancies.tex @@ -0,0 +1,33 @@ +As always, we say that a column $\col{X}$ is \textbf{stamp-constant} if it satisfies +\[ + \If \mulStamp_{i - 1} = \mulStamp_{i} + ~ \Then + \col{X}_{i - 1} = \col{X}_{i}. +\] +%Note that the \emph{stamp column isn't imported}. +We impose stamp-constancy conditions on the following columns\footnote{\ob{TODO: remove. Note: if $\mulStamp$ were imported from the stack (which was the original design), all other imported columns would automatically be stamp-constant. Not importing the stamp allows us to re-use previous computations to justify the current one. Surprisingly enough there is a lot of repetition in the \inst{EXP} instructions performed in a typical block.}}: +\begin{multicols}{4} +\begin{itemize} + \item $\iArgOneHi$; + \item $\iArgOneLo$; + \item $\iArgTwoHi$; + \item $\iArgTwoLo$; + \item $\iResHi$; + \item $\iResLo$; + \item $\iInst$; + \item[\vspace{\fill}] +\end{itemize} +\end{multicols} +\noindent Note that $\tinyExponent$, $\tinyBase$, $\oli$ and $\resVanishes$ are automatically stamp-constant seeing as they are directly derived from imported columns (see section~\ref{subsec (alu/exp): tiny base, tiny exponent, oli and result vanishes binary columns}.) + +We also say that a column $\col{X}$ is \nBytes{}-constant if it satisfies +\[ + \Big( + \iModStamp_{i} = \iModStamp_{i - 1} + \et + \nBytes_{i} = \nBytes_{i - 1} + \Big) + \implies + \col{X}_{i} = \col{X}_{i - 1}. +\] +\ob{TODO: is \nBytes{}-constancy correctly defined ? \nBytes{} should be zero for \col{MUL} ? Do we even need it ? \dots{}} \ No newline at end of file diff --git a/alu/mul/heartbeat.tex b/alu/mul/heartbeat.tex new file mode 100644 index 0000000..eb8aa31 --- /dev/null +++ b/alu/mul/heartbeat.tex @@ -0,0 +1,345 @@ +We now state the heartbeat constraints proper. The module stamp follows a familiar pattern: +\begin{enumerate} + \item $\mulStamp_{0} = 0$; + \item $\mulStamp_{i + 1} \in \{ \mulStamp_{i}, 1 + \mulStamp_{i} \}$; +\end{enumerate} +The constraints below pertains to the \textbf{padding regime}. +\begin{enumerate}[resume] + \item \If $\mulStamp_{i} = 0$ \Then + \[ + \begin{cases} + \ct_{i} = 0 \\ + \oli_{i} = 0 \\ + \iInst_{i} = 0 \\ + \end{cases} + \] + \item \If $\mulStamp_{i} \neq 0$ \Then $\iInst_{i} \in \{ \inst{MUL}, \inst{EXP} \}$; + \item \If $\mulStamp_{i + 1} \neq \mulStamp_{i}$ \Then + \[ + \begin{cases} + \ct_{i + 1} = 0, \\ + \nBits_{i + 1} = 0, \\ + % \snm_{i + 1} = 0; \\ will clash with EXP's first instruction + \end{cases} + \] +\end{enumerate} +\noindent The constraint below pertains to the \textbf{trivial regime} that always last a single counter row. +\begin{enumerate}[resume] + \item \If $\oli_{i} = 1$ \Then $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$; +\end{enumerate} +\noindent The constraints below enforce familiar cyclical constraints on $\ct$ which enforce that in nontrivial regimes the counter always counts from $0$ to $\mmediumMO$ and resets. +\begin{enumerate}[resume] + \item \If \Big($\mulStamp_{i} \neq 0$ \et $\oli_{i} = 0$ \et $\ct_{i} \neq \mmediumMO$\Big) \Then + $\ct_{i + 1} = 1 + \ct_{i}$. +% \[ +% \left\{ +% \begin{array}{lcl} +% \ct_{i + 1} & \!\!\! = \!\!\! & 1 + \ct_{i} \\ +% \nBits_{i + 1} & \!\!\! = \!\!\! & \nBits_{i} \\ +% \snm_{i + 1} & \!\!\! = \!\!\! & \snm_{i} \\ +% \expBitSrc_{i + 1} & \!\!\! = \!\!\! & \expBitSrc_{i} \\ +% \expBit_{i + 1} & \!\!\! = \!\!\! & \expBit_{i} \\ +% \end{array} +% \right. +% \] +% \item \If $\mulStamp_{i} \neq 0$ \Then +% \begin{enumerate} +% \item \If $\oli_{i} = 1$ \Then $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$ +% \item \If $\oli_{i} = 0$ \Then +% \begin{enumerate} +% \item \If $\ct_{i} \neq \mmediumMO$ \Then +% \[ +% \begin{cases} +% \oli_{i + 1} = 0 \\ +% \ct_{i + 1} = 1 + \ct_{i} \\ +% \end{cases} +% \] +% \end{enumerate} +% \end{enumerate} + \item \If $\ct_{i} = \mmediumMO$ \Then $\ct_{i + 1} = 0$ +\end{enumerate} +\noindent We say that a column $\col{X}$ is \textbf{counter-constant} if it satisfies +\[ + \ct_{i} \neq 0 + \implies + \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose that the following columns be counter-constant: +\begin{multicols}{3} +\begin{itemize} + \item \snm{} + \item \nBits{} + \item \expBitSrc{} + \item \expBit{} + \item \expBitAcc{} + \item[\vspace{\fill}] + %\item[\vspace{\fill}] +\end{itemize} +\end{multicols} +\noindent The constraints below pertain to the first two \textbf{nontrivial regimes}. +\begin{enumerate}[resume] + \item \If $\ct_{i} = \mmediumMO$ + \begin{enumerate} + \item \If $\iInst_{i} = \inst{MUL}$ \Then $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$; + \item \If \Big($\iInst_{i} = \inst{EXP}$ \et $\resVanishes = 1$\Big) \Then + $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$ +% \begin{enumerate} +% \item \If $\resVanishes = 1$ \Then $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$; +% \item \If $\resVanishes = 0$ \Then +% \begin{enumerate} +% \item \If $\snm_{i} \neq \expBit_{i}$ \Then +% \[ +% \left\{ +% \begin{array}{lcl} +% \nBits_{i + 1} & \!\!\! = \!\!\! & \nBits_{i} \\ +% \snm_{i + 1} & \!\!\! = \!\!\! & 1 + \snm_{i} \\ +% \expBitSrc_{i + 1} & \!\!\! = \!\!\! & \expBitSrc_{i} \\ +% \expBit_{i + 1} & \!\!\! = \!\!\! & \expBit_{i} \\ +% \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 1 + \expBitAcc_{i} \\ +% \end{array} +% \right. +% \] +% \item \If $\snm_{i} = \expBit_{i}$ \Then +% \begin{enumerate} +% \item \If $\mulStamp_{i + 1} = \mulStamp_{i}$ \Then +% \[ +% \left\{ +% \begin{array}{lcl} +% \nBits_{i + 1} & \!\!\! = \!\!\! & 1 + \nBits_{i} \red{~FALSE!}\\ +% \snm_{i + 1} & \!\!\! = \!\!\! & 0 \\ +% \end{array} +% \right. +% \] +% \end{enumerate} +% \end{enumerate} +% \end{enumerate} + \end{enumerate} +% \item \If \big($\mulStamp_{N} \neq 0$ \et $\oli_{N} = 0$\big) \Then $\ct_{N} = \mmediumMO$; +% \item \If $\mulStamp_{i} \neq 0$ \Then +% \begin{enumerate} +% \item \If $\oli_{i} = 1$ \Then $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$ +% \item \If $\oli_{i} = 0$ \Then +% \begin{enumerate} +% \item \If $\ct_{i} \neq \mmediumMO$ \Then +% \[ +% \begin{cases} +% \oli_{i + 1} = 0 \\ +% \ct_{i + 1} = 1 + \ct_{i} \\ +% \end{cases} +% \] +% \item \If $\ct_{i} = \mmediumMO$ \Then $\mulStamp_{i + 1} = 1 + \mulStamp_{i}$; +% \end{enumerate} +% \end{enumerate} +% \item \If \big($\mulStamp_{N} \neq 0$ \et $\oli_{N} = 0$\big) \Then $\ct_{N} = \mmediumMO$; +\end{enumerate} +In other words, nontrivial \inst{MUL} instructions and nontrivial \inst{EXP} instructions with $\iRes = 0$ take up a single counter-cycle. + +We now deal with the nontrivial, nonzero \inst{EXP} instructions. The first (along with other constraints to come) enforces that $\nBits$ always remains $\in\{0,1,\dots, \oneTwoSeven\}$. +\begin{enumerate}[resume] + \item $\nBits_{i} \neq \oneTwoEight$; +\end{enumerate} +We settle conditions pertaining to the final row. Note that the present module is under no obligation to follow chronological order of instructions and may even add superfluous instructions along the way. We choose to do this for the last row. This provides us with a substantial simplification of the final row constraints since we won't have to contend with the possibility of the last instruction being a nontrivial \inst{EXP} instruction. Our choice of final instruction is guided by the fact that the instruction computing $\mathtt{0x0\,\,\^\,0x100}$ is empirically relatively common. We thus impose the following +\begin{enumerate}[resume] + \item \If $\mulStamp_{N} \neq 0$ \Then + \[ + \left\{ + \begin{array}{lclr} + \oli_{N} & \!\!\! = \!\!\! & 1 & \trash \\ + \iInst_{N} & \!\!\! = \!\!\! & \inst{EXP} & \\ + \iArgOneHi_{N} & \!\!\! = \!\!\! & 0 & \\ + \iArgOneLo_{N} & \!\!\! = \!\!\! & 0 & \\ + \iArgTwoHi_{N} & \!\!\! = \!\!\! & 0 & \\ + \iArgTwoLo_{N} & \!\!\! = \!\!\! & 256 & \\ + \iResHi_{N} & \!\!\! = \!\!\! & 0 & \trash \\ + \iResLo_{N} & \!\!\! = \!\!\! & 0 & \trash \\ + \end{array} + \right. + \] +\end{enumerate} +Though we dealt with the final we are not done with the heartbeat. +We now settle the\textbf{nontrivial \inst{EXP} regime with nonzero result}. +\[ + \framebox{All constraints written below assume that + $\left\{ + \begin{array}{lcl} + \iInst_{i} & \!\!\! = \!\!\! & \inst{EXP} \\ + \oli_{i} & \!\!\! = \!\!\! & 0 \\ + \resVanishes_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right.$} +\] +The first set of constraints imposes the \emph{first row} of a \textbf{nontrivial \inst{EXP} regime with nonzero result} +\begin{enumerate}[resume] + \item \If $\mulStamp_{i - 1} \neq \mulStamp_{i}$ \Then + \[ + \left\{ + \begin{array}{lclr} + \snm_{i} & \!\!\! = \!\!\! & 1 & (1) \\ + \expBit_{i} & \!\!\! = \!\!\! & 1 & (2) \\ + \expBitAcc_{i} & \!\!\! = \!\!\! & 1 & (3) \\ + \multicolumn{3}{l}{\If \iArgTwoHi_{i} = 0 ~ \Then \expBitSrc_{i} = 1} & (4) \\ + \multicolumn{3}{l}{\If \iArgTwoHi_{i} \neq 0 ~ \Then \expBitSrc_{i} = 0} & (4') \\ + % \nBits_{i} & \!\!\! = \!\!\! & 0 & (5) \\ + \end{array} + \right. + \] + The interpretation is as follows: + $(1)$ means that the first operation is always a multiplication (rather than a squaring); + $(2)$ means that the first bit of the exponenent is always nonzero; + $(3)$ means that the exponent bit accumulator starts out at $1$; + $(4)$ and $(4')$ set the source of bits depending on whether the high part of the exponent is zero or not; + %$(5)$ means that during the first round of ``square and multiply'' zero bits of the exponent have been processed; + \item \If $\ct_{i} = \mmediumMO$ \Then + \begin{enumerate} + \item \If $\snm_{i} \neq \expBit_{i}$ \Then + \[ + \left\{ + \begin{array}{lclr} + \mulStamp_{i + 1} & \!\!\! = \!\!\! & \mulStamp_{i} & () \\ + \snm_{i + 1} & \!\!\! = \!\!\! & 1 + \snm_{i} & () \\ + \expBit_{i + 1} & \!\!\! = \!\!\! & \expBit_{i} & () \\ + \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 1 + \expBitAcc_{i} & () \\ + \expBitSrc_{i + 1} & \!\!\! = \!\!\! & \expBitSrc_{i} & () \\ + \nBits_{i + 1} & \!\!\! = \!\!\! & \nBits_{i} & () \\ + \end{array} + \right. + \] + \item \If $\snm_{i} = \expBit_{i}$ \Then + \begin{enumerate} + \item \If $\expBitSrc_{i} = 0$ + \begin{enumerate} + \item $\mulStamp_{i + 1} = \mulStamp_{i}$ + \item $\snm_{i + 1} = 0$ + \item \If $\expBitAcc_{i} \neq \iArgTwoHi_{i}$ \Then + \[ + \left\{ + \begin{array}{lclr} + \expBitSrc_{i + 1} & \!\!\! = \!\!\! & 0 & () \\ + \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 2 \cdot \expBitAcc_{i} & () \\ + \nBits_{i + 1} & \!\!\! = \!\!\! & 1 + \nBits_{i} & () \\ + \end{array} + \right. + \] + \item \If $\expBitAcc_{i} = \iArgTwoHi_{i}$ \Then + \[ + \left\{ + \begin{array}{lclr} + \expBitSrc_{i + 1} & \!\!\! = \!\!\! & 1 & () \\ + \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 0 & () \\ + \nBits_{i + 1} & \!\!\! = \!\!\! & 0 & () \\ + \end{array} + \right. + \] + \end{enumerate} + \item \If $\expBitSrc_{i} = 1$ \Then + \begin{enumerate} + \item \If $\iArgTwoHi_{i} \neq 0$ \et $\nBits_{i} \neq \oneTwoSeven$ \Then + \[ + \left\{ + \begin{array}{lclr} + \snm_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \mulStamp_{i + 1} & \!\!\! = \!\!\! & \mulStamp_{i} & () \\ + \expBitSrc_{i + 1} & \!\!\! = \!\!\! & 1 & () \\ + \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 2 \cdot \expBitAcc_{i} & () \\ + \nBits_{i + 1} & \!\!\! = \!\!\! & 1 + \nBits_{i} & () \\ + \end{array} + \right. + \] + \item \If $\iArgTwoHi_{i} \neq 0$ \et $\nBits_{i} = \oneTwoSeven$ \Then + \[ + \left\{ + \begin{array}{lclr} + %\snm_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \mulStamp_{i + 1} & \!\!\! = \!\!\! & 1 + \mulStamp_{i} & () \\ + \expBitAcc_{i} & \!\!\! = \!\!\! & \iArgTwoLo_{i} \\ + \end{array} + \right. + \] + \item \If $\iArgTwoHi_{i} = 0$ \et $\expBitAcc_{i} \neq \iArgTwoLo_{i}$ \Then + \[ + \left\{ + \begin{array}{lclr} + \snm_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \mulStamp_{i + 1} & \!\!\! = \!\!\! & \mulStamp_{i} & () \\ + \expBitSrc_{i + 1} & \!\!\! = \!\!\! & 1 & () \\ + \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 2 \cdot \expBitAcc_{i} & () \\ + \nBits_{i + 1} & \!\!\! = \!\!\! & 1 + \nBits_{i} & () \\ + \end{array} + \right. + \] + \item \If $\iArgTwoHi_{i} = 0$ \et $\expBitAcc_{i} = \iArgTwoLo_{i}$ \Then + \[ + \mulStamp_{i + 1} = 1 + \mulStamp_{i} + %\left\{ + %\begin{array}{lclr} + % \mulStamp_{i + 1} & \!\!\! = \!\!\! & 1 + \mulStamp_{i} & () \\ + %\end{array} + %\right. + \] + \end{enumerate} +% \[ +% \left\{ +% \begin{array}{lclr} +% \mulStamp_{i + 1} & \!\!\! = \!\!\! & \mulStamp_{i} & () \\ +% \snm_{i + 1} & \!\!\! = \!\!\! & 1 + \snm_{i} & () \\ +% \expBit_{i + 1} & \!\!\! = \!\!\! & \expBit_{i} & () \\ +% \expBitAcc_{i + 1} & \!\!\! = \!\!\! & 1 + \expBitAcc_{i} & () \\ +% \expBitSrc_{i + 1} & \!\!\! = \!\!\! & \expBitSrc_{i} & () \\ +% \nBits_{i + 1} & \!\!\! = \!\!\! & \nBits_{i} & () \\ +% \end{array} +% \right. +% \] + \end{enumerate} + \end{enumerate} +\end{enumerate} +We must also settle conditions pertaining to the final row. The present module is under no obligation to follow chronological order of instructions and may even add superfluous instructions along the way. We choose to do this for the last row. This provides us with a substantial simplification of the final row constraints since we won't have to contend with the possibility of the last instruction being a nontrivial \inst{EXP} instruction. Our choice of final instruction is guided by the fact that the instruction computing $\mathtt{0x0\,\,\^\,0x100}$ is empirically relatively common. We thus impose the following +\begin{enumerate}[resume] + \item \If $\mulStamp_{N} \neq 0$ \Then + \[ + \left\{ + \begin{array}{lclr} + \oli_{N} & \!\!\! = \!\!\! & 1 & \trash \\ + \iInst_{N} & \!\!\! = \!\!\! & \inst{EXP} & \\ + \iArgOneHi_{N} & \!\!\! = \!\!\! & 0 & \\ + \iArgOneLo_{N} & \!\!\! = \!\!\! & 0 & \\ + \iArgTwoHi_{N} & \!\!\! = \!\!\! & 0 & \\ + \iArgTwoLo_{N} & \!\!\! = \!\!\! & 256 & \\ + \iResHi_{N} & \!\!\! = \!\!\! & 0 & \trash \\ + \iResLo_{N} & \!\!\! = \!\!\! & 0 & \trash \\ + \end{array} + \right. + \] + \iffalse + \begin{enumerate} + \item $\ct_{N} = \mmediumMO$ + \item \If $\iInst_{N} = \inst{EXP}$ \et $\resVanishes_{N} = 0$ \Then + \begin{enumerate} + \item $\expBitSrc_{N} = 1$ + \item $\snm_{N} = \expBit_{N}$ + \item $\expBitAcc_{N} = \iArgTwoLo_{N}$ + \item \If $\iArgTwoHi_{N} \neq 0$ \Then $\nBits_{N} = \oneTwoSeven$ + \item and the \textbf{target constraint} + \[ + \begin{cases} + \iResHi_{N} = \theta \cdot \col{C\_3}_{N} + \col{C\_2}_{N} \\ + \iResLo_{N} = \theta \cdot \col{C\_1}_{N} + \col{C\_0}_{N} \\ + \end{cases} + \] + where $\col{C\_k}$, for $k=3,2,1,0$, are aliases defined in section~\ref{subsec: (alu/mul) aliases}. + \end{enumerate} + \end{enumerate} + \fi +\end{enumerate} +\iffalse +Some notes: +\begin{enumerate} + \item $\oli$ will be stamp-constant (section~\ref{subsec (alu/exp): constancies}) by construction (section~\ref{subsec (alu/exp): tiny base, tiny exponent, oli and result vanishes binary columns}) +\end{enumerate} +\noindent We say that an instruction is +\emph{trivial} if $\oli_{i} = 1$ and +\emph{nontrivial} if $\oli_{i} = 0$. Trivial instructions thus take up a single row of processing. + +Note that the following two facts (a) $\mulStamp_{i} = 0 \implies \iInst_{i} = 0$ and (b) the multiplier only deals with two instructions, imply that we may replace conditions such as +``\If $\mulStamp_{i} \neq 0$ \et $\iInst_{i} = \inst{MUL}$'' with ``\If $\mulStamp_{i} \neq 0$ \et $\iInst_{i} \neq \inst{EXP}$'' and similarly +``\If $\mulStamp_{i} \neq 0$ \et $\iInst_{i} = \inst{EXP}$'' with ``\If $\mulStamp_{i} \neq 0$ \et $\iInst_{i} \neq \inst{MUL}$''. +\fi diff --git a/alu/mul/intended.tex b/alu/mul/intended.tex new file mode 100644 index 0000000..5a32fd7 --- /dev/null +++ b/alu/mul/intended.tex @@ -0,0 +1,45 @@ +The intended behaviour of the unfolding of an $\inst{EXP}$ instruction is captured in the figure~\ref{fig: intention of mul heartbeat}. +\begin{figure} +\centering +\[ + \begin{array}{|c|c|c|c|c|c|} + \hline + \iInst{} & \ct{} & \nBits{} & \mul{} & \snm{} & \ACC{} \\ \hline + & & & & & \\ + \multicolumn{5}{c}{} \\ + \vdots & \vdots & 12 & \vdots & \vdots & \col{c} \\ \hline\hline + \inst{EXP} & 0 & 13 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{0} } & 2 \col{c} \\ \hline + \inst{EXP} & 1 & 13 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{0} } & 2 \col{c} \\ \hline + \inst{EXP} & 2 & 13 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{0} } & 2 \col{c} \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \inst{EXP} & 6 & 13 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{0} } & 2 \col{c} \\ \hline + \inst{EXP} & \mmediumMO & 13 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{0} } & 2 \col{c} \\ \hline\hline + \vdots & 0 & 14 & 0 & \vdots & 4 \col{c} \\ \hline + & & & & & \\ + \end{array} + \qquad + \begin{array}{|c|c|c|c|c|c|} + \hline + \iInst{} & \ct{} & \nBits{} & \mul{} & \snm{} & \ACC{} \\ \hline + & & & & & \\ + \multicolumn{5}{c}{} \\ + \vdots & \vdots & 96 & \vdots & \vdots & \col{c} \\ \hline\hline + \inst{EXP} & 0 & 97 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} \\ \hline + \inst{EXP} & 1 & 97 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} \\ \hline + \inst{EXP} & 2 & 97 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \inst{EXP} & 6 & 97 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} \\ \hline + \inst{EXP} & \mmediumMO & 97 & {\cellcolor{\stackCol} 0} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} \\ \hline\hline + \inst{EXP} & 0 & 97 & {\cellcolor{\romCol} \bm{1}} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} + 1 \\ \hline + \inst{EXP} & 1 & 97 & {\cellcolor{\romCol} \bm{1}} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} + 1 \\ \hline + \inst{EXP} & 2 & 97 & {\cellcolor{\romCol} \bm{1}} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} + 1 \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \inst{EXP} & 6 & 97 & {\cellcolor{\romCol} \bm{1}} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} + 1 \\ \hline + \inst{EXP} & \mmediumMO & 97 & {\cellcolor{\romCol} \bm{1}} & {\cellcolor{\ramCol} \bm{1}} & 2 \col{c} + 1 \\ \hline\hline + \vdots & 0 & 98 & 0 & \vdots & 4 \col{c} + 2 \\ \hline + & & & & & \\ + \end{array} +\] +\caption{The above represents two intermediate steps of computing an exponentiation. On the left hand side the ``13th bit'' of the exponent (which can mean several things depending on context) is $0$ so that $\snm \equiv 0$. As such the first (and only) computation associated with that bit is a \textbf{squaring}. It is taken care of in the course of $\mmedium$ lines (characterized by $\mul \equiv 0$.) On the right hand side the ``97th bit'' is $1$ so that $\snm \equiv 1$. As such the this intermediate step requires two computations. The first is a squaring. It is characterized by $\mul \equiv 0$ and takes place over $\mmedium$ lines. The second is a multiplication by the base. It is characterized by $\mul \equiv 1$ and (again) takes place over $\mmedium$ lines.} +\label{fig: intention of mul heartbeat} +\end{figure} diff --git a/alu/mul/intro.tex b/alu/mul/intro.tex new file mode 100644 index 0000000..642d05d --- /dev/null +++ b/alu/mul/intro.tex @@ -0,0 +1,10 @@ +The \textbf{multiplier submodule} deals with the following instructions: +\begin{multicols}{2} +\begin{enumerate} + \item \col{MUL} + \item \col{EXP} +\end{enumerate} +\end{multicols} +\noindent \col{EXP} is dealt with in a sequence of ``square and multiply's'' unless (a) the result can be guessed in advance (i.e. $\oli = 1$) or (b) the result is $0$. + +\red{Note. It used to be the case, in a previous draft, that $\oli = 1$ was equivalent to $\iArgTwo = 0$ and that the $\oli$ would only intervene for \inst{EXP} instructions (and spit out $1$.)} \ No newline at end of file diff --git a/alu/mul/oli.tex b/alu/mul/oli.tex new file mode 100644 index 0000000..d951278 --- /dev/null +++ b/alu/mul/oli.tex @@ -0,0 +1,48 @@ +The present section constrains the following binary columns: $\tinyBase$, $\tinyExponent$, $\oli{}$ and $\resVanishes$. +\begin{center} +\framebox{All constraints are written under the assumption that $\mulStamp_{i} \neq 0$.} +\end{center} +%\ob{TODO: maybe we should instead impose vanishing conditions when $\mulStamp_{i} = 0$. Probably not \dots{}} +We impose the following: +\begin{enumerate} + \item \If $\iArgOneHi_{i} \neq 0$ \Then $\TINYBASE_{i} = 0$, + \item \If $\iArgOneHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\iArgOneLo_{i} \cdot (1 - \iArgOneLo_{i}) \neq 0$ \Then $\TINYBASE_{i} = 0$; + \item \If $\iArgOneLo_{i} \cdot (1 - \iArgOneLo_{i}) = 0$ \Then $\TINYBASE_{i} = 1$, + \end{enumerate} +\end{enumerate} +similarly +\begin{enumerate} + \item \If $\iArgTwoHi_{i} \neq 0$ \Then $\TINYEXPONENT_{i} = 0$; + \item \If $\iArgTwoHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\iArgTwoLo_{i} \cdot (\iArgTwoLo_{i} - 1) \neq 0$ \Then $\TINYEXPONENT_{i} = 1$; + \item \If $\iArgTwoLo_{i} \cdot (\iArgTwoLo_{i} - 1) = 0$ \Then $\TINYEXPONENT_{i} = 0$. + \end{enumerate} +\end{enumerate} +further set +\begin{enumerate} + \item \If $\iResHi_{i} \neq 0$ \Then $\RESVANISHES_{i} = 0$; + \item \If $\iResHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\iResLo_{i} \neq 0$ \Then $\RESVANISHES_{i} = 0$; + \item \If $\iResLo_{i} = 0$ \Then $\RESVANISHES_{i} = 1$. + \end{enumerate} +\end{enumerate} +In other words +\[ + \left\{ + \begin{array}{lcl} + \tinyBase = 1 & \iff & \iArgOne \in \{0,1\} \\ + \tinyExponent = 1 & \iff & \iArgTwo \in \{0,1\} \\ + \resVanishes = 1 & \iff & \iRes = 0 \\ + \end{array} + \right. +\] +%\red{Note: we don't know at this point that $\iResHi$ and $\iResLo$ are indeed $\llarge$-byte integers. We thus \emph{can't} replace this by the simpler condition that $\resVanishes_{i} = 1$ \emph{iff} $\iResHi_{i} + \iResLo_{i} = 0$ as one might be tempted to do.} +Finally we set $\oli$ via $\oli = 1$ \emph{iff} \big($\tinyBase_{i} = 1$ \OR{} $\tinyExponent_{i} = 1$\big) i.e. +\[ + \oli_{i} = + \tinyBase_{i} + \tinyExponent_{i} - \tinyBase_{i} \cdot \tinyExponent_{i} +\] \ No newline at end of file diff --git a/alu/mul/regime_exp_small.tex b/alu/mul/regime_exp_small.tex new file mode 100644 index 0000000..0bcda63 --- /dev/null +++ b/alu/mul/regime_exp_small.tex @@ -0,0 +1,80 @@ +\begin{center} +\framebox{% +All constraints in this section are written under the assumption that +$\begin{cases} +\iInst_{i} = \inst{EXP} \\ +% \oli_{i} = 0 \\ % useless given that we also impose \ct_{i} = \mmediumMO +\resVanishes_{i} = 0 \\ +\ct_{i} = \mmediumMO \\ +\end{cases}$} +\end{center} +\begin{description} + \item[Target constraint.] The following is \emph{always} true: + \[ + \begin{cases} + \iArgOneHi_{i} = \theta \cdot \col{A\_3}_{i} + \col{A\_2}_{i} \\ + \iArgOneLo_{i} = \theta \cdot \col{A\_1}_{i} + \col{A\_0}_{i} \\ + \end{cases} + \] + \item[First instruction.] \If $\mulStamp_{i-8} \neq \mulStamp_{i}$ \Then we initialize the $\acc{C\_k}$: + \[ + \begin{cases} + \iArgOneHi_{i} = \theta \cdot \col{C\_3}_{i} + \col{C\_2}_{i} \\ + \iArgOneLo_{i} = \theta \cdot \col{C\_1}_{i} + \col{C\_0}_{i} \\ + \end{cases} + \] + \item[Square and multiply instructions.] \If $\mulStamp_{i-8} = \mulStamp_{i}$ \Then + \iffalse + we define the following aliases + \[ + \begin{cases} + \col{C'\_3} := \acc{C\_3}_{i-8} \\ + \col{C'\_2} := \acc{C\_2}_{i-8} \\ + \col{C'\_1} := \acc{C\_1}_{i-8} \\ + \col{C'\_0} := \acc{C\_0}_{i-8} \\ + \end{cases} + \] + \fi + there are two cases: + \begin{enumerate} + \item \If $\snm_{i} = 0$ \Then + \[ + \setMultiplication + \left( + \begin{array}{c} + \col{C'\_3}, \col{C'\_2}, \col{C'\_1}, \col{C'\_0}; \\ + \col{C'\_3}, \col{C'\_2}, \col{C'\_1}, \col{C'\_0}; \\ + \col{C\_3}, \col{C\_2}, \col{C\_1}, \col{C\_0}; \\ + \col{H\_3}, \col{H\_2}, \col{H\_1}, \col{H\_0}; \\ + \alpha, 2\beta_{1} + \beta_{0}; + \eta, 2\mu_{1} + \mu_{0}; \\ + \end{array} + \right) + \] + i.e. the current step is a squaring step + \item \If $\snm_{i} = 1$ \Then + \[ + \setMultiplication + \left( + \begin{array}{c} + \col{C'\_3}, \col{C'\_2}, \col{C'\_1}, \col{C'\_0}; \\ + \col{A\_3}, \col{A\_2}, \col{A\_1}, \col{A\_0}; \\ + \col{C\_3}, \col{C\_2}, \col{C\_1}, \col{C\_0}; \\ + \col{H\_3}, \col{H\_2}, \col{H\_1}, \col{H\_0}; \\ + \alpha, 2\beta_{1} + \beta_{0}; + \eta, 2\mu_{1} + \mu_{0}; \\ + \end{array} + \right) + \] + i.e. the current step is a ``multiplication by $\iArgOne$'' step + \end{enumerate} + \item[Final row.] % \If \Big($\expBitSrc_{i} = 1$ \et $\snm_{i} = \expBit_{i}$ \et $\expBitAcc_{i} = \iArgTwoLo_{i}$\Big) \Then + \If $\mulStamp_{i + 1} \neq \mulStamp_{i}$ \Then + \[ + \begin{cases} + \iResHi_{i} = \theta \cdot \col{C\_3}_{i} + \col{C\_2}_{i} \\ + \iResLo_{i} = \theta \cdot \col{C\_1}_{i} + \col{C\_0}_{i} \\ + \end{cases} + \] + Note that we don't have to take extra precautions in case $i$ is the final row index $N$. Given the constraints imposed on the final row the final instruction is \emph{always} a trivial exponentiation. +\end{description} \ No newline at end of file diff --git a/alu/mul/regime_exp_zero_approach_hi.tex b/alu/mul/regime_exp_zero_approach_hi.tex new file mode 100644 index 0000000..0f36818 --- /dev/null +++ b/alu/mul/regime_exp_zero_approach_hi.tex @@ -0,0 +1,16 @@ +Recall that the nontrivial \inst{EXP} regime with zero result corresponds to the following case: $\iInst = \inst{EXP}$, $\oli = 0$ and $\resVanishes = 1$. Note that $\oli = 0$ implies\footnote{is equivalent to, actually} that both $\argOne \geq 2$ and $\argTwo \geq 2$. As already mentioned earlier, the only way that a (nontrivial) \inst{EXP} instruction results in $0$ is if +\[ + \nu_{2} \cdot \iArgTwo \geq 256 +\] +where $\nu_{2}$ denotes the $2$-adicity of the base $\iArgOne$ (which is nonzero) i.e. the greatest exponent $n$ such that $2^n \mid \iArgOne$. Also, since $\oli_{i} = 0$, we know that $\iArgTwo \geq 2$ so that it suffices to have +\[ + \min\Big\{\nu_{2}, \oneTwoEight \Big\} \cdot \iArgTwo \geq 256 +\] +furthermore it is sufficient to find some exponent $k$ such that +\[ +\begin{cases} + 2 ^ k \mid \iArgOne \\ + k \cdot \iArgTwo \geq 256 \\ +\end{cases} +\] +The following subsection explains how one might extract such a $k$ in a constraint system. \ No newline at end of file diff --git a/alu/mul/regime_exp_zero_approach_lo.tex b/alu/mul/regime_exp_zero_approach_lo.tex new file mode 100644 index 0000000..bca34d4 --- /dev/null +++ b/alu/mul/regime_exp_zero_approach_lo.tex @@ -0,0 +1,130 @@ +Suppose we are given: +\begin{enumerate} + \item a ``counter'' column $\col{ct}{}$, + \item a ``bytes'' column $\col{bytes}$, + \item a binary colum $\col{bits}$, + \item a ``constant'' column $\col{cst}$, + \item other columns + $\col{X}$, + $\col{Y}$, + $\Sigma\col{X}$, + $\Sigma\col{Y}$. +\end{enumerate} +The interpreation/desired behaviour is as follows: +$\col{ct}{}$ is expected to count from $0$ to $\mmediumMO$ i.e. we will work within a given counter-cycle; +$\col{bytes}$ contains the byte decomposition of some $\mmedium$-byte integer $\col{A}$; +in applications $\col{bytes}$ will either be $\byteCol{A\_1}$ or $\byteCol{A\_0}$; +$\col{X}$ and $\col{Y}$ will both be \emph{nondecreasing}\footnote{within the current counter-cycle} binary columns which start off at $0$; +$\Sigma\col{X}$ and +$\Sigma\col{Y}$ will contain the running total of the +$\col{X}$ and +$\col{Y}$ columns; +$\col{cst}$ will be required to be constant along the present counter-cycle; +the value of the $\col{cst}$ column is set as the value of $\col{bytes}$ at the index at which $\col{X}$ jumps from $0$ to $1$ (or, if $\col{X}_{i} = 0$ throughout, the final value of $\col{bytes}$); +\col{bits} will be a binary column containing the bit decomposition of the value within $\col{cst}$. + +The conclusion is then as follows: if \col{bytes} contains the byte decomposition of a nonzero $\mmedium$-byte integer $\col{A}$ then the value +\( \relof := \mmedium \cdot \Sigma\col{X}_{i} + \Sigma\col{Y}_{i} \), +computed at row $i$ where $\col{ct}_{i} = \mmediumMO$, has +\[ + \relof \leq \nu_{2}(\col{A}). +\] + +\noindent We formalize this in the following constraint system: +\begin{enumerate} + \item $\col{X}$ and $\Sigma\col{X}$ satisfy the following: + \begin{enumerate} + \item $\col{X}_{i}\cdot(1-\col{X}_{i}) = 0$; + \item \If $\col{ct}_{i} = 0$ \Then + \[ + \begin{cases} + \col{X}_{i} = 0 \\ + \Sigma\col{X}_{i} = 0 \\ + \end{cases} + \] + \item \If $\col{ct}_{i} \neq \mmediumMO$ \Then + \[ + \begin{cases} + \col{X}_{i + 1} \in \{\col{X}_{i}, 1+ \col{X}_{i}\} \\ + \Sigma\col{X}_{i + 1} = \Sigma\col{X}_{i} + \col{X}_{i + 1} \\ + \end{cases} + \] + \end{enumerate} + in other words $\col{X}$ is binary nondecreasing (along the counter-cycle), starts off at $0$ and $\Sigma\col{X}$ is its running total; + \item $\col{Y}$ and $\Sigma\col{Y}$ satisfy the same collection of constraints; + \item \If $\col{X}_{i} = 1$ \Then $\col{bytes}_{i} = 0$ + \item \If $\col{Y}_{i} = 1$ \Then $\col{bits}_{i} = 0$ + \item \If $\col{ct}_{i} \neq \mmediumMO$ \Then $\col{cst}_{i + 1} = \col{cst}_{i}$ + \item \If \Big($\col{ct}_{i} \neq \mmediumMO$ \et $\col{X}_{i} = 0$ \et $\col{X}_{i + 1} = 1$\Big) \Then + \[ + \col{cst}_{i} = \col{bytes}_{i} + \] + \item \If $\col{ct}_{i} = \mmediumMO$ + \begin{enumerate} + \item \If $\col{X}_{i} = 0$ \Then + \[ + \col{cst}_{i} = \col{bytes}_{i} + \] + \item we have the bit decomposition + \[ + \col{cst}_{i} + = + \sum_{a = 0}^{\mmediumMO} + 2^a \cdot \col{bits}_{i - a} + \] + \end{enumerate} +\end{enumerate} + +\begin{figure} +\[ +\begin{array}{|c|c|c|c|c|c|c|c|} +\hline +\col{ct}{} & \Sigma\colm{X} & \col{X} & \col{bytes} & \col{cst} & \col{bits} & \col{Y} & \Sigma\colm{Y} +\\\hline +0 & 0 & 0 & \cdots & {\cellcolor{\romCol}\clubsuit} & +\col{b}_{7} & 0 & 0 +\\ \hline +1 & 0 & 0 & \cdots & {\cellcolor{\romCol}\clubsuit} & +\col{b}_{6} & 0 & 0 +\\ \hline +2 & 0 & 0 & \cdots & {\cellcolor{\romCol}\clubsuit} & +{\cellcolor{\ramCol} 0} & {\cellcolor{\ramCol} 1} & {\cellcolor{\ramCol} 1} +\\ \hline +3 & 0 & 0 & \cdots & {\cellcolor{\romCol}\clubsuit} & +{\cellcolor{\ramCol} 0} & {\cellcolor{\ramCol} 1} & {\cellcolor{\ramCol} 2} +\\ \hline +4 & 0 & 0 & \cdots & {\cellcolor{\romCol}\clubsuit} & +{\cellcolor{\ramCol} 0} & {\cellcolor{\ramCol} 1} & {\cellcolor{\ramCol} 3} +\\ \hline +5 & 0 & 0 & {\cellcolor{\romCol}\clubsuit} & {\cellcolor{\romCol}\clubsuit} & +{\cellcolor{\ramCol} 0} & {\cellcolor{\ramCol} 1} & {\cellcolor{\ramCol} 4} +\\ \hline +6 & {\cellcolor{\stackCol}~1~} & {\cellcolor{\stackCol}1} & {\cellcolor{\stackCol}0} & {\cellcolor{\romCol}\clubsuit} & +{\cellcolor{\ramCol} 0} & {\cellcolor{\ramCol} 1} & {\cellcolor{\ramCol} 5} +\\ \hline +\mmediumMO & {\cellcolor{\stackCol}~\bm{2}~} & {\cellcolor{\stackCol}1} & {\cellcolor{\stackCol}0} & {\cellcolor{\romCol}\clubsuit} & +{\cellcolor{\ramCol} 0} & {\cellcolor{\ramCol} 1} & {\cellcolor{\ramCol} ~\bm{6}~} +\\ \hline +\end{array} +\] +\caption{The \col{bytes} column contains the byte decomposition of some $\mmedium$-byte integer \col{A}. In applications \col{A} will either be $\col{A}_{0}$ or $\col{A}_{1}$ where +$\argOne\equiv [\col{A}_{3} \,|\, \col{A}_{2} \,|\, \col{A}_{1} \,|\, \col{A}_{0}]$. In the example above its $\redm{2}$ least significant bytes are $=0$, and the third least significant byte (whose value is represented by $\redm{\clubsuit}$ in the above) has its $\redm{6}$ least significant bits of of its bit decomposition are $=0$. As such a \emph{lower bound} for the $2$-adicity of $\col{A}$ is given by $8\cdot \redm{2} + \redm{6}$. \\ +Note that we don't enforce nonzeroness on either $\redm{\clubsuit}$ or $\col{b}_6$. +If the ``jump points'' (\red{2} and \red{6} respectively in the example above) of the nondecreasing binary columns $\col{X}$ and $\col{Y}$ are chosen appropriately one may extract the exact $2$-adicity of $\col{A}$. This isn't necessary for our present purpose but could easily be enforced through extra constraints enforcing nonzero-ness of both the byte $\redm{\clubsuit}$ and of the bit $\col{b}_6$.} +\end{figure} +\noindent We collect this collection of constraints under the moniker $\prepareLowerBoundOnTwoAdicity$ and write +\[ + \prepareLowerBoundOnTwoAdicity + \left( + \begin{array}{c} + \col{bytes}, + \col{cst}, + \col{bits}; \\ + \col{X}, + \Sigma\col{X}; + \col{Y}, + \Sigma\col{Y}; + \col{ct}{}; + \end{array} + \right) +\] \ No newline at end of file diff --git a/alu/mul/regime_exp_zero_constraints.tex b/alu/mul/regime_exp_zero_constraints.tex new file mode 100644 index 0000000..f1ddda8 --- /dev/null +++ b/alu/mul/regime_exp_zero_constraints.tex @@ -0,0 +1,297 @@ +\begin{center} +\framebox{% +All constraints in this section are written under the assumption that +$\begin{cases} +\iInst_{i} = \inst{EXP} \\ +% \oli_{i} = 0 \\ % useless given that we also impose \ct_{i} = \mmediumMO +\oli_{i} = 0 \\ +\resVanishes_{i} = 1 \\ +\end{cases}$} +\end{center} + +\paragraph{Target constraints.} We impose the following regardless of anything else: +\begin{enumerate} + \item \If $\ct_{i} = \mmediumMO$ \Then + \[ + \begin{cases} + \iArgOneHi_{i} = \theta \cdot \col{A\_3} + \col{A\_2} \\ + \iArgOneLo_{i} = \theta \cdot \col{A\_1} + \col{A\_0} \vspace{2mm} \\ + \iArgTwoHi_{i} = \theta \cdot \col{B\_3} + \col{B\_2} \\ + \iArgTwoLo_{i} = \theta \cdot \col{B\_1} + \col{B\_0} \\ + \end{cases} + \] + i.e. we enforce + $\iArgOne \equiv + [\col{A\_3} \,|\, \col{A\_2} \,|\, \col{A\_1} \,|\, \col{A\_0} ]$ and + $\iArgTwo \equiv + [\col{B\_3} \,|\, \col{B\_2} \,|\, \col{B\_1} \,|\, \col{B\_0} ]$. +\end{enumerate} + +\paragraph{Remark.} Note that if $\iArgOneLo = 0$ the result of the \inst{EXP} instruction is necessarily zero. +Indeed $\iArgOneLo = 0$ is equivalent to $2^\oneTwoEight \mid \iArgOne$ i.e. $\nu_{2} \geq \oneTwoEight$. Furthermore $\oli_{i} = 0$ forces $\iArgTwo \geq 2$. The desired bound ($\nu_{2} \cdot \argTwo \geq 256$) is thus necessarily achieved. Thus +\begin{center} +\framebox{% +All constraints below make the further assumption that $\iArgOneLo_{i} \neq 0$. +} +\end{center} + +\paragraph{Special constraints for $\col{BYTE\_C\_0}$.} The $\col{BYTE\_C\_0}$ column serves an entirely different purpose from elsewhere in the module: +\begin{enumerate}[resume] + \item \If $\ct_{i} \neq \mmediumMO$ \Then $\byteCol{C\_0}_{i} = \byteCol{C\_0}_{i + 1}$ + \item \If $\ct_{i} = \mmediumMO$ \Then + \[ + \begin{cases} + \If \col{A\_0} = 0 ~ \Then \col{BYTE\_C\_0} = 0 \\ + \If \col{A\_0} \neq 0 ~ \Then \col{BYTE\_C\_0} = 1 \\ + \end{cases} + \] +\end{enumerate} +\noindent We have thus constrained $\byteCol{C\_0}$: +\begin{itemize} + \item to be constant along the present counter-cycle; + \item to be binary along the present counter-cycle; + \item to retain the information whether $2^{8\cdot\mmedium} \mid \iArgOne$ or not. +\end{itemize} +Indeed, the previous set of target constraints enforces $\argOne \equiv +[\col{A\_3} \,|\, \col{A\_2} \,|\, \col{A\_1} \,|\, \col{A\_0} ]$. +Therefore +$2^{8\cdot\mmedium} \mid \iArgOne +\iff \col{A\_0} = 0 +\iff \col{BYTE\_C\_0} = 0$. +More precisely (and given that $\iArgOneLo \neq 0$) we see that +if $\col{A\_0} = 0$ then $\nu_{2} = 8\cdot\mmedium + \text{(the $2$-adicity of $\col{A\_1}$)}$ +while +if $\col{A\_0} \neq 0$ then $\nu_{2} = \text{(the $2$-adicity of $\col{A\_0}$.)}$ This should explain the next set of constraints: +% Thus $\col{BYTE\_C\_0} = 0$ \emph{iff} $\col{A\_0} = 0$. column to be a constant bit along the present counter-cycle and retain the information whether $\col{A}_{0}$ is zero or not, where we write + +\paragraph{Preparation of a lower bound.} +The constraints in this paragraph allow us to extract parameters which are later assembled into a lower bound for the $2$-adicity of the base $\iArgOne$. +\begin{enumerate}[resume] + \item + \If $\byteCol{C\_0}_{i} = 1$\footnote{Given the above this is equivalent to $\byteCol{C\_0}_{i} \neq 0$, which one may choose instead for the implementation.} \Then + \[ + \prepareLowerBoundOnTwoAdicity + \left( + \begin{array}{c} + \byteCol{A\_0}, + \byteCol{C\_1}, + \bits; \\ + \byteCol{C\_3}, + \byteCol{H\_3}; \\ + \byteCol{C\_2}, + \byteCol{H\_2}; + \ct{}; + \end{array} + \right) \\ + \] + \item \If $\byteCol{C\_0}_{i} = 0$\footnote{Given the above this is equivalent to $\byteCol{C\_0}_{i} \neq 1$, which one may choose instead for the implementation.} \Then + \[ + \prepareLowerBoundOnTwoAdicity + \left( + \begin{array}{c} + \byteCol{A\_1}, + \byteCol{C\_1}, + \bits; \\ + \byteCol{C\_3}, + \byteCol{H\_3}; \\ + \byteCol{C\_2}, + \byteCol{H\_2}; + \ct{}; + \end{array} + \right) + \] +\end{enumerate} + +\paragraph{Remarks.} +Note that some columns +%$\byteCol{C\_1}$, +%$\byteCol{C\_2}$, +%$\byteCol{H\_2}$, +%$\byteCol{C\_3}$, +%$\byteCol{H\_3}$ +were completely repurposed from their standard use case. +In all other cases +$\byteCol{C\_0}$, +$\byteCol{C\_1}$, +$\byteCol{C\_2}$, +$\byteCol{H\_2}$, +$\byteCol{C\_3}$ and +$\byteCol{H\_3}$ +are used to establish some product $\mod 2^{256}$. Here they are repurposed as binary columns, stores for particular pivot bytes etc \dots{} More precisely: +\begin{itemize} + \item $\byteCol{C\_0}$ is repurposed as a constant bit that distinguishes between the two cases $2^{\mmedium \cdot 8} \mid \iArgOneLo_{i}$ (i.e. $\byteCol{C\_0} = 0$) and $2^{8\cdot\mmedium} \nmid \iArgOneLo_{i}$ (i.e. $\byteCol{C\_0} = 1$); + \item $\byteCol{C\_1}$ is repurposed as a constant column that contains one of the bytes of either + $\col{A\_1}$ (if $\byteCol{C\_0} = 0$) or + $\col{A\_0}$ (if $\byteCol{C\_0} = 1$) + beyond which all remaining bytes of that $\mmedium$-byte integer are zero; + \item $\bits$ contains the bit decomposition of the constant value in $\byteCol{C\_1}$; + \item $\byteCol{C\_3}$ is repurposed as a nondecreasing binary column indicating \emph{a} cut-off point beyond which the bytes from either + $\col{A\_1}$ (if $\byteCol{C\_0} = 0$) or + $\col{A\_0}$ (if $\byteCol{C\_0} = 1$) are zero; + \item $\byteCol{H\_3}$ is repurposed as its running total; + \item $\byteCol{C\_2}$ is repurposed as a nondecreasing binary column indicating \emph{a} cut-off point beyond which the bits of $\bits$ are zero; + \item $\byteCol{H\_2}$ is repurposed as its running total; +\end{itemize} +Note that using values found in the final row of the present counter-cycle (i.e. the row with $\ct_{i} = \mmediumMO$) we can construct a lower bound \col{lb} for the $2$-adicity of $\iArgOne$. Indeed +\[ + \col{lb} := + \begin{cases} + \If \byteCol{C\_0}_{i} = 1: & 8 \displaystyle \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} \vspace{2mm}\\ + \If \byteCol{C\_0}_{i} = 0: & 8 \displaystyle \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} + \mmedium \cdot 8 + \end{cases} +\] +is such a lower bound. +\iffalse +\begin{itemize} + \item \If $\byteCol{C\_0}_{i} = 1$ \Then $8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i}$ is a lower bound on the $2$-adicity of $\iArgOne$; + \item \If $\byteCol{C\_0}_{i} = 0$ \Then $8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} + \mmedium \cdot 8$ is a lower bound on the $2$-adicity of $\iArgOne$. +\end{itemize} +\fi + +\paragraph{Proving the vanishing of \inst{EXP}.} Now that we have a lower bound (which can be an exact bound if we so choose) we are in position to verify that $\nu_{2} \cdot \iArgTwo \geq 256$ (or more precisely $k \cdot \iArgTwo \geq 256$ for our lower bound $k$.) +Note the following: assuming (as we shortly will) that $\ct_{i} = \mmediumMO$) one has +\[ + \iArgTwo \geq 256 \iff \theta \cdot \Big(\col{B\_3} + \col{B\_2} + \col{B\_1}\Big) + + \col{B\_0} + \neq + \byteCol{B\_0}_{i} +\] +Indeed +given that +$\iArgTwo \equiv [\col{B\_3} \,|\, \col{B\_2} \,|\, \col{B\_1} \,|\, \col{B\_0} ]$ +it follows that +$\iArgTwo \geq 256$ \emph{iff} one of the $\mmedium$-byte integers $\col{B\_3}$, $\col{B\_2}$, $\col{B\_1}$ is $\neq 0$ or they are all $=0$ so that $\iArgTwo = \col{B\_0}$ but (the $\mmedium$-byte integer) $\col{B\_0}$ isn't a byte i.e. (since $\byteCol{B\_0}$ contains its byte decomposition by virtue of section~\ref{subsec (alu/exp): byte decompositions}) +$\col{B\_0} \neq \byteCol{B\_0}_{i}$. With this in mind we further impose + +\begin{enumerate}[resume] + \item \If $\ct_{i} = \mmediumMO$ \Then + \begin{enumerate} + \item \If + $\theta \cdot \Big(\col{B\_3} + \col{B\_2} + \col{B\_1}\Big) + + \col{B\_0} + \neq + \byteCol{B\_0}_{i}$ + \Then + \[ + \left\{ + \begin{array}{lr} + \displaystyle + \If \byteCol{C\_0}_{i} = 1 ~ \Then + 8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} = 1 + \col{H\_1} \vspace{2mm}\\ + \displaystyle + \If \byteCol{C\_0}_{i} = 0 ~ \Then + 8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} + \mmedium \cdot 8 = 1 + \col{H\_1} & (\trash) \\ + \end{array} + \right. + \] + Note that the second constraint may be safely removed altogether as the left hand side is necessarily $\geq \mmedium \cdot 8 = 64$. + \item \If + $\theta \cdot \Big(\col{B\_3} + \col{B\_2} + \col{B\_1}\Big) + + \col{B\_0} + = + \byteCol{B\_0}_{i}$ + \Then + \[ + \begin{cases} + \If \byteCol{C\_0}_{i} = 1 ~ \Then + \col{B\_0} \cdot \Big(8 \cdot \byteCol{H\_3} + \byteCol{H\_2} \Big) + = 256 + \col{H\_1} \\ + \If \byteCol{C\_0}_{i} = 0 ~ \Then + \col{B\_0} \cdot \Big(8 \cdot \byteCol{H\_3} + \byteCol{H\_2} + \mmedium \cdot 8 \Big) + = 256 + \col{H\_1} \\ + \end{cases} + \] + \iffalse + \item \If $\col{B\_3} + \col{B\_2} + \col{B\_1} = 0$ \Then + \begin{enumerate} + \item \If $\col{B\_0} \neq \byteCol{B\_0}_{i}$ \Then + \[ + \begin{cases} + \If \byteCol{C\_0}_{i} = 1 ~ \Then + 8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} = 1 + \col{H\_1} \\ + \If \byteCol{C\_0}_{i} = 0 ~ \Then + 8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} + \mmedium \cdot 8 = 1 + \col{H\_1} \\ + \end{cases} + \] + i.e. the lower bound on $2$-adicity that was extracted is nonzero; + no further constraints are required since $\iArgTwo = \col{B\_0}$ is automatically $\geq 256$ by virtue of the two preceding hypotheses; + furthermore the same remark as above applies here too. + \item \If $\col{B\_0} = \byteCol{B\_0}_{i}$ \Then + \[ + \begin{cases} + \If \byteCol{C\_0}_{i} = 1 ~ \Then + \col{B\_0} \cdot \Big(8 \cdot \byteCol{H\_3} + \byteCol{H\_2} \Big) + = 256 + \col{H\_1} \\ + \If \byteCol{C\_0}_{i} = 0 ~ \Then + \col{B\_0} \cdot \Big(8 \cdot \byteCol{H\_3} + \byteCol{H\_2} + \mmedium \cdot 8 \Big) + = 256 + \col{H\_1} \\ + \end{cases} + \] + \end{enumerate} + \fi + \end{enumerate} +\end{enumerate} +The first set of constraints may \emph{altnernatively} be replaced with +\[ +\begin{cases} + \If \byteCol{C\_0}_{i} = 1 ~ \Then + 8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} \neq 0 \\ + \If \byteCol{C\_0}_{i} = 0 ~ \Then + 8 \cdot \byteCol{H\_3}_{i} + \byteCol{H\_2}_{i} + \mmedium \cdot 8 \neq 0 \\ +\end{cases} +\] +these constraints are the true intent. They say that the lower bound on the 2-adicity (Again the second constraint may safely be removed for the same reasons.) + +\iffalse +The parts about +``\ct_{i} = \mmediumMO ~ \Then + 8 \cdot \col{H\_2} + + + \col{H\_3} = 256 + \col{H\_1}'' +are wrong. We need to multiply by the lowest byte etc ... + \item + \If $\byteCol{C\_0}_{i} = 1$\footnote{Given the above this is equivalent to $\byteCol{C\_0}_{i} \neq 0$, which one may choose instead for the implementation.} \Then + \[ + \begin{cases} + \prepareLowerBoundOnTwoAdicity + \left( + \begin{array}{c} + \byteCol{A\_1}, + \byteCol{C\_1}, + \bits; \\ + \byteCol{C\_2}, + \byteCol{H\_2}; \\ + \byteCol{C\_3}, + \byteCol{H\_3}; + \ct{}; + \end{array} + \right) \\ + \If \ct_{i} = \mmediumMO ~ \Then + 8 \cdot \col{H\_2} + + + \col{H\_3} = 256 + \col{H\_1} + \end{cases} + \] + \item \If $\byteCol{C\_0}_{i} = 0$\footnote{Given the above this is equivalent to $\byteCol{C\_0}_{i} \neq 1$, which one may choose instead for the implementation.} \Then + \[ + \begin{cases} + \prepareLowerBoundOnTwoAdicity + \left( + \begin{array}{c} + \byteCol{A\_1}, + \byteCol{C\_1}, + \bits; \\ + \byteCol{C\_2}, + \byteCol{H\_2}; \\ + \byteCol{C\_3}, + \byteCol{H\_3}; + \ct{}; + \end{array} + \right) \\ + \If \ct_{i} = \mmediumMO ~ \Then + 8 \cdot \col{H\_2} + + + \col{H\_3} + \mmedium \cdot 8 = 256 + \col{H\_1} + \end{cases} + \] +\fi \ No newline at end of file diff --git a/alu/mul/regime_exp_zero_constraints_conclusion.tex b/alu/mul/regime_exp_zero_constraints_conclusion.tex new file mode 100644 index 0000000..b18e0a0 --- /dev/null +++ b/alu/mul/regime_exp_zero_constraints_conclusion.tex @@ -0,0 +1,10 @@ +\begin{center} +\framebox{% +All constraints in this section are written under the assumption that +$\begin{cases} +\iInst_{i} = \inst{EXP} \\ +% \oli_{i} = 0 \\ % useless given that we also impose \ct_{i} = \mmediumMO +\resVanishes_{i} = 1 \\ +\ct_{i} = \mmediumMO \\ +\end{cases}$} +\end{center} \ No newline at end of file diff --git a/alu/mul/regime_mul.tex b/alu/mul/regime_mul.tex new file mode 100644 index 0000000..557d92c --- /dev/null +++ b/alu/mul/regime_mul.tex @@ -0,0 +1,58 @@ +\begin{center} +\framebox{% +All constraints in this section are written under the assumption that +$\begin{cases} +\iInst_{i} = \inst{MUL} \\ +% \oli_{i} = 0 \\ % useless given that we also impose \ct_{i} = \mmediumMO +\ct_{i} = \mmediumMO \\ +\end{cases}$} +\end{center} +i.e. we jump straight to the last row of a nontrivial \inst{MUL} instruction\footnote{% +given that $\ct_{i} \neq 0$ and thus $\mulStamp_{i}\neq0$ the condition +``$\iInst_{i} = \inst{MUL}$'' is equivalent to +``$\iInst_{i} \neq \inst{EXP}$''}. +\begin{description} + \iffalse + \item[Aliases.] To simplify notations we introduce some aliases which are only valid in the present context: + \[ + \begin{cases} + \alpha = \bits_{i-5} \\ + \beta_{0} = \bits_{i-4} \\ + \beta_{1} = \bits_{i-3} \\ + \end{cases} + \quad\text{and}\quad + \begin{cases} + \eta = \bits_{i-2} \\ + \mu_{0} = \bits_{i-1} \\ + \mu_{1} = \bits_{i} \\ + \end{cases} + \] + \fi + \item[Target constraints.] We impose that + \[ + \left\{ + \begin{array}{lcl} + \iArgOneHi_{i} & \!\!\! = \!\!\! & \theta \cdot \col{A\_3}_{i} + \col{A\_2}_{i} \\ + \iArgOneLo_{i} & \!\!\! = \!\!\! & \theta \cdot \col{A\_1}_{i} + \col{A\_0}_{i} \vspace{2mm} \\ + \iArgTwoHi_{i} & \!\!\! = \!\!\! & \theta \cdot \col{B\_3}_{i} + \col{B\_2}_{i} \\ + \iArgTwoLo_{i} & \!\!\! = \!\!\! & \theta \cdot \col{B\_1}_{i} + \col{B\_0}_{i} \vspace{2mm} \\ + \iResHi_{i} & \!\!\! = \!\!\! & \theta \cdot \col{C\_3}_{i} + \col{C\_2}_{i} \\ + \iResLo_{i} & \!\!\! = \!\!\! & \theta \cdot \col{C\_1}_{i} + \col{C\_0}_{i} \\ + \end{array} + \right. + \] + \item[Multiplication constraints.] We impose that + \[ + \setMultiplication + \left( + \begin{array}{c} + \col{A\_3}_{i}, \col{A\_2}_{i}, \col{A\_1}_{i}, \col{A\_0}_{i}; \\ + \col{B\_3}_{i}, \col{B\_2}_{i}, \col{B\_1}_{i}, \col{B\_0}_{i}; \\ + \col{C\_3}_{i}, \col{C\_2}_{i}, \col{C\_1}_{i}, \col{C\_0}_{i}; \\ + \col{H\_3}_{i}, \col{H\_2}_{i}, \col{H\_1}_{i}, \col{H\_0}_{i}; \\ + \alpha, 2\beta_{1} + \beta_{0}; + \eta, 2\mu_{1} + \mu_{0}; \\ + \end{array} + \right) + \] +\end{description} \ No newline at end of file diff --git a/alu/mul/regime_trivial.tex b/alu/mul/regime_trivial.tex new file mode 100644 index 0000000..2ff6f1b --- /dev/null +++ b/alu/mul/regime_trivial.tex @@ -0,0 +1,64 @@ +As stated in section~\ref{subsec (alu/exp): columns} +the goal is to have $\oli = 1$ whenever the output of an instruction is clear without computation. +By construction, $\oli = 1$ \emph{iff} \big($\iArgOne \in \{0,1\}$ \OR $\iArgTwo \in \{0,1\}$\big). +Thus whenever $\oli = 1$ one can deduce the result on sight. +% We can easily constrain the result, both for $\inst{MUL}$ and $\inst{EXP}$ instructions, when $\oli = 1$ i.e. when +% $\tinyExponent = 1$ or +% $\tinyBase = 1$. Indeed +%if +Indeed, if one of the arguments of a \inst{MUL} instruction is $0$ or $1$ then the output is $0$ or the other argument. +Similarly, if the exponent $\iArgTwo$ of an \inst{EXP} instruction is zero then $\iRes = 1$; +if the exponent is one then $\iRes = \iArgOne$; if the exponent is $\neq 0, 1$ but the base $\iArgOne$ is equal to $0$ or $1$ then $\iRes = \iArgOne$. +\begin{center} +\framebox{All constraints in this section assume that $\oli_{i} = 1$.} +\end{center} +We thus impose the following constraints: +%\begin{center} +%\framebox{All constraints in the present section are written under the assumption that $\oli_{i} = 1$.} +%\end{center} +\begin{enumerate} + \item \If $\iInst_{i} = \inst{MUL}$\footnote{given that $\oli_{i} = 1$ and thus $\iMulStamp_{i} \neq 0$ this is equivalent to $\iInst_{i} \neq \inst{EXP}$} \Then + \begin{enumerate} + \item \If $\tinyExponent_{i} = 1$ (i.e. $\iArgTwo = \iArgTwoLo \in \{ 0, 1 \}$) \Then + \[ + \begin{cases} + \iResHi_{i} = \iArgTwoLo_{i} \cdot \iArgOneHi_{i} \\ + \iResLo_{i} = \iArgTwoLo_{i} \cdot \iArgOneLo_{i} \\ + \end{cases} + \] + \item \If $\tinyBase_{i} = 1$ (i.e. $\iArgOne = \iArgOneLo \in \{ 0, 1 \}$) \Then + \[ + \begin{cases} + \iResHi_{i} = \iArgOneLo_{i} \cdot \iArgTwoHi_{i} \\ + \iResLo_{i} = \iArgOneLo_{i} \cdot \iArgTwoLo_{i} \\ + \end{cases} + \] + \end{enumerate} + \item \If $\iInst_{i} = \inst{EXP}$\footnote{given that $\oli_{i} = 1$ and thus $\iMulStamp_{i} \neq 0$ this is equivalent to $\iInst_{i} \neq \inst{MUL}$} \Then + \begin{enumerate} + \item \If $\tinyExponent_{i} = 1$ \Then + \begin{enumerate} + \item \If $\iArgTwoLo_{i} = 0$\footnote{in the implementation we can replace this with \If $\iArgTwoLo_{i} \neq 1$} \Then + \[ + \begin{cases} + \iResHi_{i} = 0 \\ + \iResLo_{i} = 1 \\ + \end{cases} + \] + \item \If $\iArgTwoLo_{i} = 1$\footnote{in the implementation we can replace this with \If $\iArgTwoLo_{i} \neq 0$} \Then + \[ + \begin{cases} + \iResHi_{i} = \iArgOneHi_{i} \\ + \iResLo_{i} = \iArgOneLo_{i} \\ + \end{cases} + \] + \end{enumerate} + \item \If $\tinyExponent_{i} = 0$\footnote{and thus $\tinyBase_{i} = 1$} \Then + \[ + \begin{cases} + \iResHi_{i} = \iArgOneHi_{i} \\ + \iResLo_{i} = \iArgOneLo_{i} \\ + \end{cases} + \] + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/alu/mul/regimes.tex b/alu/mul/regimes.tex new file mode 100644 index 0000000..535395a --- /dev/null +++ b/alu/mul/regimes.tex @@ -0,0 +1,27 @@ +The heartbeat of the multiplication module is more complex than that of the other arithmetic modules. The explanation lies in the fact that the present module has different ``regimes'' (with the ``(nontrivial) \inst{EXP} regime'' being split into 3 ``sub-regimes.'') There are the two following ``trivial'' regimes +\begin{enumerate} + \item[0.] The \textbf{padding regime} is characterized by $\mulStamp \equiv 0$; nothing of import happens. + \item[1.] The \textbf{trivial regime} is characterized by $\oli \equiv 1$. + In this regime the result is obvious on sight and a single line suffices to write it. +\end{enumerate} +The following are more involved +\begin{enumerate} + \item[2.] The \textbf{nontrivial \inst{MUL} regime} is characterized by $\oli \equiv 0$ \et $\iInst \equiv \inst{MUL}$. This regime occupies a single counter-cycle + \item[3.] The \textbf{nontrivial \inst{EXP} regime} applies in the remaining case i.e. $\oli \equiv 0$ \et $\iInst \equiv \inst{EXP}$. It is split into three different ``sub-regimes''. + \begin{enumerate} + \item + The \textbf{zero result regime} is characterized by $\iRes \equiv 0$ i.e. $\resVanishes \equiv 1$. + Given that we are dealing with a \emph{nontrivial} exponentiation (since $\oli \neq 1$) this happens \emph{iff} + \[ \nu_2 \cdot \iArgTwo \geq 256 \] + where we define $\nu_2 := \min\Big\{2\text{-adicity of the base }\iArgOne, \oneTwoEight \Big\}$. This case can be justified in a single counter-cycle (i.e. in $\mmedium$ rows.) + \item + The \textbf{nonzero result regime} is characterized by $\iRes \not\equiv 0$ i.e. $\resVanishes \equiv 0$. + There are two subcases: + (\emph{a}) that of a \emph{(relatively) small} exponent $\iArgTwo$ i.e. $\iArgTwoHi = 0$; + (\emph{b}) that of a \emph{large} exponent $\iArgTwo$ i.e. $\resVanishes_{i} = 0$ \et $\iArgTwoHi \neq 0$. + In the first case the result is computed as a sequence of $1 \leq k \leq \oneTwoEight$ ``square and multiply's''. + In the second case the result is computed as a sequence of $k + \oneTwoEight$ ``square and multiply's'', for some $1 \leq k \leq \oneTwoEight$, + \end{enumerate} +\end{enumerate} + +Note that each ``square and multiply'' occupies $\mmedium$ or $2\cdot\mmedium$ rows (depending on whether one only ``squares'' or also ``multiplies.'') diff --git a/alu/primitives/_inputs.tex b/alu/primitives/_inputs.tex new file mode 100644 index 0000000..d69b969 --- /dev/null +++ b/alu/primitives/_inputs.tex @@ -0,0 +1,8 @@ +\section{Introduction} \label{alu: introduction} \input{primitives/intro} +\section{Notations} \label{alu: notations} \input{primitives/notations} +\section{\setAbsoluteValue{} i.e. constraints for taking absolute values} \label{alu: absolute value} \input{primitives/absolute_value} +\section{\setNegative{} i.e. constraints for taking negatives} \label{alu: negatives} \input{primitives/negatives} +\section{\setAddition{} and \setSubtraction{} i.e. constraints for addition and subtraction} \label{alu: addition and subtraction } \input{primitives/addition} +\section{\setMultiplication{} i.e. constraints for multiplying \texttt{uint256}'s} \label{alu: multiplication} \input{primitives/multiplication} +\section{Verifying a euclidean division} \label{alu: euclidean division} \input{primitives/modular} +\section{Verifying extended modular arithmetic} \label{alu: extended modular arithmetic} \input{primitives/extended} diff --git a/alu/primitives/absolute_value.tex b/alu/primitives/absolute_value.tex new file mode 100644 index 0000000..c365f2a --- /dev/null +++ b/alu/primitives/absolute_value.tex @@ -0,0 +1,106 @@ +We explain how to extract the base $\theta^2$-representation of the absolute value of an integer given in its $2$'s complement representation as a $256$-bit integer. Suppose $\col{X} \equiv [\col{X}\high \,\|\, \col{X}\low]$ is $256$-bit integer. Interpreted as a signed integer it represents the number $\tilde{\col{X}}$ +\begin{IEEEeqnarray*}{RCL} + \tilde{\col{X}} + & = & + \displaystyle + - 2^{255} \cdot \col{sgn} + + + \Big( + \theta^2 \cdot (\col{X}\high - 2^{127} \cdot \col{sgn}) + + \col{X}\low + \Big) \\ + & = & + \displaystyle + - \theta^4 \cdot \col{sgn} + + \theta^2 \cdot \col{X}\high + + \col{X}\low + \in + \big[\!\!\!\:\big[-2^{255}, 2^{255}\big[\!\!\!\:\big[ +\end{IEEEeqnarray*} +where $\col{sgn} \in \{ 0, 1 \}$ is the most significant bit of $\col{X}\high$ defined by +\[ + \col{sgn} = 1 \iff \col{X}\high \geq 2^{127} +\] +It follows that +\begin{IEEEeqnarray*}{RCL} + | \tilde{\col{X}} | + & = & + \begin{cases} + \If \col{sgn} = 0 ~ \Then & + \theta^2 \cdot \col{X}\high + \col{X}\low \\ + \If \col{sgn} = 1 ~ \Then & + \theta^2 \cdot (\theta^2 - \col{X}\high) - \col{X}\low + \end{cases} \vspace{2mm} \\ + & = & + \begin{cases} + \If \phantom{\big(} \col{sgn} = 0 \phantom{\big(} ~ \Then & + \theta^2 \cdot \col{X}\high + \col{X}\low \\ + \If \big( \col{sgn} = 1 ~ \et \col{X}\low = 0 \big) ~ \Then & + \theta^2 \cdot (\theta^2 - \col{X}\high) \\ + \If \big( \col{sgn} = 1 ~ \et \col{X}\low \neq 0 \big) ~ \Then & + \theta^2 \cdot (\theta^2 - \col{X}\high - 1) + (\theta^2 - \col{X}\low) \\ + \end{cases} +\end{IEEEeqnarray*} +Therefore +\[ + \begin{cases} + \If \phantom{\big(}\col{sgn} = 0 \phantom{\big(} ~ \Then + & | \tilde{\col{X}} | \equiv [\col{X}\high \,\|\, \col{X}\low] \\ + \If \big(\col{sgn} = 1 ~ \et \col{X}\low = 0\big) ~ \Then + & | \tilde{\col{X}} | \equiv [\theta^2 - \col{X}\high \,\|\, 0] \\ + \If \big(\col{sgn} = 1 ~ \et \col{X}\low \neq 0\big) ~ \Then + & | \tilde{\col{X}} | \equiv [\theta^2 - \col{X}\high - 1 \,\|\, \theta^2 - \col{X}\low] \\ + \end{cases} +\] +\begin{lem}[absolute values] +Let +$\colm{X} \equiv [\colm{X}\high \,\|\, \colm{X}\low]$ and +$\colm{A} \equiv [\colm{A}\high \,\|\, \colm{A}\low]$ be $256$-bit integers and let $\colm{sgn}$ be the sign bit of $\colm{X}$\footnote{i.e. the most significant bit of $\colm{X}\high$}. The following are equivalent +\begin{enumerate} + \item $\colm{A}$ represents the absolute value of the signed integer represented by $\colm{X}$ + \item the following set of constraints is satisfied + \begin{enumerate} + \item \If $\colm{sgn} = 0$ \Then + \[ + \begin{cases} + \colm{A}\high = \colm{X}\high \\ + \colm{A}\low = \colm{X}\low \\ + \end{cases} + \] + \item \If $\colm{sgn} = 1$ \Then + \begin{enumerate} + \item \If $\colm{X}\low = 0$ + \[ + \begin{cases} + \colm{A}\high = \theta^2 - \colm{X}\high \\ + \colm{A}\low = 0 \\ + \end{cases} + \] + \item \If $\colm{X}\low \neq 0$ + \[ + \begin{cases} + \colm{A}\high = \theta^2 - \colm{X}\high - 1 \\ + \colm{A}\low = \theta^2 - \colm{X}\low \\ + \end{cases} + \] + \end{enumerate} + \end{enumerate} +\end{enumerate} +\end{lem} +We subsume these constraints under the moniker +\[ + \setAbsoluteValue\Big( + \col{A}\high, + \col{A}\low; + \col{X}\high, + \col{X}\low, + \col{sgn} + \Big) +\] +\saNote{} There are \emph{implicit assumptions} that aren't part of the constraint itself: +\begin{enumerate} + \item $\colm{X}\high$ and $\colm{X}\low$ are $\llarge$-byte integers; + \item $\colm{A}\high$ and $\colm{A}\low$ are $\llarge$-byte integers; + \item $\colm{sgn}$ is a bit and represents $\colm{X}$'s sign bit; +\end{enumerate} +Everytime the $\setAbsoluteValue$ will be invoked in the sequel the assumption on $\colm{X}\high$ and $\colm{X}\low$ will be met (it's a stack item) and re-verified in a byte decomposition. This byte decomposition is then used to justify the value of $\colm{sgn}$. The above constraint is used to \emph{set} $\colm{A}\high$ and $\colm{A}\low$. The smallness constraint will thus automatically be satisfied. diff --git a/alu/primitives/addition.tex b/alu/primitives/addition.tex new file mode 100644 index 0000000..cfc37f6 --- /dev/null +++ b/alu/primitives/addition.tex @@ -0,0 +1,76 @@ +We explain how to verify an addition and a subtraction instruction of the \textsc{evm}. Recall that these operations are carried out $\mod 2^{256}$. +\begin{lem}[addition and subtraction] +Let +$\colm{A} \equiv [\colm{A}\high \,\|\, \colm{A}\low]$, +$\colm{B} \equiv [\colm{B}\high \,\|\, \colm{B}\low]$ and +$\colm{R} \equiv [\colm{R}\high \,\|\, \colm{R}\low]$ +be $256$-bit integers. The following are equivalent +\begin{enumerate} + \item $\colm{R}$ represents the sum $\col{A} + \col{B}$ i.e. $\col{A} + \col{B} = \col{R} \mod 2^{256}$; + \item there exists two bits $\epsilon,\eta\in\{0,1\}$ such that the following constraints are satisfied: + \[ + \begin{cases} + \col{A}\low + \col{B}\low = \col{R}\low + \epsilon \theta^2 \\ + \col{A}\high + \col{B}\high + \epsilon = \col{R}\high + \eta \theta^2 \\ + \end{cases} + \] +% for some bits $\epsilon,\eta\in\{0,1\}$ +% i.e. $\col{A}\low + \col{B}\low \equiv [\epsilon \,\|\, \col{R}\low]$ +% and $\col{A}\high + \col{B}\high + \epsilon \equiv [\eta \,\|\, \col{R}\high]$; +\end{enumerate} +Similarly we have +\begin{enumerate} + \item $\colm{R}$ represents the difference $\col{A} - \col{B}$ i.e. $\col{A} - \col{B} = \col{R} \mod 2^{256}$;% i.e. $\col{R} + \col{B} = \col{A} \mod 2^{256}$; + \item there exists two bits $\epsilon,\eta\in\{0,1\}$ such that the following constraints are satisfied: + \[ + \begin{cases} + \col{R}\low + \col{B}\low = \col{A}\low + \epsilon \theta^2 \\ + \col{R}\high + \col{B}\high + \epsilon = \col{A}\high + \eta \theta^2 \\ + \end{cases} + \] +% for some bits $\epsilon,\eta\in\{0,1\}$ +% i.e. $\col{R}\low + \col{B}\low \equiv [\epsilon \,\|\, \col{A}\low]$ +% and $\col{R}\high + \col{B}\high + \epsilon \equiv [\eta \,\|\, \col{A}\high]$. +\end{enumerate} +\end{lem} +We subsume these constraints under the respective monikers +\[ + \setAddition\Big( + \begin{array}{c} + \col{A}\high, + \col{A}\low, + \col{B}\high, + \col{B}\low; \\ + \col{R}\high, \col{R}\low; + \epsilon, + \eta; + \end{array} + \Big) + \quad\text{and}\quad + \setSubtraction\Big( + \begin{array}{c} + \col{A}\high, + \col{A}\low, + \col{B}\high, + \col{B}\low; \\ + \col{R}\high, \col{R}\low; + \epsilon, + \eta; + \end{array} + \Big) +\] +\saNote{} There are \emph{implicit assumptions} that aren't part of the constraint itself: +\begin{enumerate} + \item $\colm{A}\high$ and $\colm{A}\low$ are $\llarge$-byte integers; + \item $\colm{B}\high$ and $\colm{B}\low$ are $\llarge$-byte integers; + \item $\colm{R}\high$ and $\colm{R}\low$ are $\llarge$-byte integers; + \item $\epsilon$ and $\eta$ are bits; +\end{enumerate} +Everytime either +$\setAddition$ or +$\setSubtraction$ +will be invoked in the sequel the assumptions will be enforced by other constraints. More explicitly +$\colm{A}\high$, $\colm{A}\low$ and +$\colm{B}\high$, $\colm{B}\low$ +will be imports of the high and low part of stack items; +$\colm{R}\high$ and $\colm{R}\low$ will be provided with a byte decomposition to verify that, indeed, they are $\llarge$-byte integers, and $\epsilon$ and $\eta$ will be extracted from a binary column. diff --git a/alu/primitives/extended.tex b/alu/primitives/extended.tex new file mode 100644 index 0000000..9b83a3b --- /dev/null +++ b/alu/primitives/extended.tex @@ -0,0 +1,104 @@ +We explain how to verify modular addition and multiplication instructions of the \textsc{evm}. Recall that these instructions require adding and multiplying \emph{integers} (rather than integers $\mod 2^{256}$.) +\begin{lem}[$4\times4$ multiplication] + Consider + $\colm{A}\equiv [\colm{A}_{3} \,|\, \colm{A}_{2} \,|\, \colm{A}_{1} \,|\, \colm{A}_{0}]$ and + $\colm{B}\equiv [\colm{B}_{3} \,|\, \colm{B}_{2} \,|\, \colm{B}_{1} \,|\, \colm{B}_{0}]$ two (unsigned) $256$-bit integers + and + $\colm{P}\equiv [\colm{P}_{3} \,\|\, \colm{P}_{2} \,\|\, \colm{P}_{1} \,\|\, \colm{P}_{0}]$, + a $512$-bit integer. Let us set + \[ + \left\{ \begin{array}{lcl} + \colm{A}_{1}\cdot\colm{B}_{0} + \colm{A}_{0}\cdot\colm{B}_{1} & \!\!\! \equiv \!\!\! & [0 \,|\, \alpha \,|\, \colm{H}_{1} \,|\, \colm{H}_{0}]\\ + \colm{A}_{3}\cdot\colm{B}_{0} + \colm{A}_{2}\cdot\colm{B}_{1} + \colm{A}_{1}\cdot\colm{B}_{2} + \colm{A}_{0}\cdot\colm{B}_{3} & \!\!\! \equiv \!\!\! & [0 \,|\, \beta \,|\, \colm{H}_{3} \,|\, \colm{H}_{2}]\\ + \colm{A}_{3}\cdot\colm{B}_{2} + \colm{A}_{2}\cdot\colm{B}_{3} & \!\!\! \equiv \!\!\! & [0 \,|\, \gamma \,|\, \colm{H}_{5} \,|\, \colm{H}_{4}]\\ + \end{array} \right. + \] + for some + $\alpha \in \{ 0, 1 \}$, + $\beta \in \{ 0, 1, 2, 3 \}$ + and + $\gamma \in \{ 0, 1 \}$. Then $\colm{A} \cdot \colm{B} = \colm{P}$ \emph{iff} + \[ + \left\{ \begin{array}{rccclcl} + && \colm{A}_{0}\cdot\colm{B}_{0} & \!\!\!\! + \!\!\!\! & \theta \cdot \colm{H}_{0} + & \!\!\! = \!\!\! & + \colm{P}_{0} + \theta^2 \cdot \lambda + \vspace{1mm} \\ + \lambda + \colm{H}_{1} + \theta \cdot \alpha & \!\!\!\! + \!\!\!\! & \big[\colm{A}_{2}\cdot\colm{B}_{0} + \colm{A}_{1}\cdot\colm{B}_{1} + \colm{A}_{0}\cdot\colm{B}_{2} \big] & \!\!\!\! + \!\!\!\! & \theta \cdot \colm{H}_{2} + & \!\!\! = \!\!\! & + \colm{P}_{1} + \theta^2 \cdot \mu + \vspace{1mm} \\ + \mu + \colm{H}_{3} + \theta \cdot \beta & \!\!\!\! + \!\!\!\! & \big[\colm{A}_{3}\cdot\colm{B}_{1} + \colm{A}_{2}\cdot\colm{B}_{2} + \colm{A}_{1}\cdot\colm{B}_{3} \big] & \!\!\!\! + \!\!\!\! & \theta \cdot \colm{H}_{4} + & \!\!\! = \!\!\! & + \colm{P}_{2} + \theta^2 \cdot \nu + \vspace{1mm} \\ + \nu + \colm{H}_{5} + \theta \cdot \gamma & \!\!\!\! + \!\!\!\! & \colm{A}_{3}\cdot\colm{B}_{3} & & + & \!\!\! = \!\!\! & + \colm{P}_{3} + \\ + \end{array} \right. + \] + for some + $\lambda \in \{0, 1\}$ + and + $\mu, \nu \in \{0, 1, 2, 3\}$. +\end{lem} +\begin{lem}[$4\times8$ multiplication] + Let + $\colm{C}\equiv [\colm{C}_{3} \,|\, \colm{C}_{2} \,|\, \colm{C}_{1} \,|\, \colm{C}_{0}]$ and + $\colm{R} + \equiv [\colm{R}_{3} \,|\, \colm{R}_{2} \,|\, \colm{R}_{1} \,|\, \colm{R}_{0}] + \equiv [\colm{R}\high \,\|\, \colm{R}\low]$ be two $256$-bit integers and let + $\colm{Q}\equiv [ + \colm{Q}_{7} \,|\, \cdots \,|\, \colm{Q}_{1} \,|\, \colm{Q}_{0}]$ + and + $\colm{P}\equiv [\colm{P}_{3} \,\|\, \colm{P}_{2} \,\|\, \colm{P}_{1} \,\|\, \colm{P}_{0}]$ be $512$-bit integers. + Define, for $k = 0, 1, 2, 3$, bits + $\colm{eq}_{k}$ and + $\colm{lt}_{k}$ by imposing that + \[ + \left\{ \begin{array}{lcc} + \colm{eq}_{k} = 1 & \iff & \colm{R}_{k} = \colm{C}_{k}\\ + \colm{lt}_{k} = 1 & \iff & \colm{R}_{k} < \colm{C}_{k}\\ + \end{array} \right. + \] + Suppose furthermore we have base $\theta$ decompositions + \[ + \left\{ \begin{array}{rcl} + \colm{C}_{1} \cdot \colm{Q}_{0} + + \colm{C}_{0} \cdot \colm{Q}_{1} + & \equiv & [0 \,|\, \rho \,|\, \colm{G}_{1} \,|\, \colm{G}_{0}] \\ + \colm{C}_{3} \cdot \colm{Q}_{0} + + \colm{C}_{2} \cdot \colm{Q}_{1} + + \colm{C}_{1} \cdot \colm{Q}_{2} + + \colm{C}_{0} \cdot \colm{Q}_{3} + & \equiv & [0 \,|\, \sigma \,|\, \colm{G}_{3} \,|\, \colm{G}_{2}] \\ + \colm{C}_{3} \cdot \colm{Q}_{2} + + \colm{C}_{2} \cdot \colm{Q}_{3} + + \colm{C}_{1} \cdot \colm{Q}_{4} + + \colm{C}_{0} \cdot \colm{Q}_{5} + & \equiv & [0 \,|\, \tau \,|\, \colm{G}_{5} \,|\, \colm{G}_{4}] \\ + \colm{C}_{3} \cdot \colm{Q}_{4} + + \colm{C}_{2} \cdot \colm{Q}_{5} + + \colm{C}_{1} \cdot \colm{Q}_{6} + + \colm{C}_{0} \cdot \colm{Q}_{7} + & \equiv & [0 \,|\, 0 \,|\, 0 \,|\, \colm{G}_{6}] \\ + \end{array} \right. + \] + where $\rho \in \{ 0, 1\}$ $\sigma \in \{ 0, 1, 2, 3\}$ $\tau \in \{ 0, 1, 2, 3\}$. + + Then the pair $(\colm{Q}, \colm{R})$ represents the euclidean division of $\colm{P}$ by $\colm{C}$\footnote{i.e. $\colm{C} \cdot \colm{Q} + \colm{R} = \colm{P}$ (as integers) and $0 \leq \colm{R} < \colm{C}$.} \emph{iff} + \[ + \colm{lt}_{3} + + + \colm{eq}_{3} \cdot \colm{lt}_{2} + + + \colm{eq}_{3} \cdot \colm{eq}_{2} \cdot \colm{lt}_{1} + + + \colm{eq}_{3} \cdot \colm{eq}_{2} \cdot \colm{eq}_{1} \cdot \colm{lt}_{0} + = + 1 + \tag{$\bigstar$} + \] + and +\end{lem} diff --git a/alu/primitives/intro.tex b/alu/primitives/intro.tex new file mode 100644 index 0000000..f55b042 --- /dev/null +++ b/alu/primitives/intro.tex @@ -0,0 +1,7 @@ +The \textbf{Arithmetic and Logic Unit} module, or \textbf{alu} module for short, deals with most arithmetic instructions. It isn't a single module, we have simply chosen to corral the following four sub-modules under a common umbrella. Each specializes in different tasks: +\begin{enumerate} + \item the \textbf{adder} module deals with addition and subtraction; + \item the \textbf{multiplier} module deals with multiplication and exponentiation; + \item the \textbf{modular arithmetic} module deals with the \emph{two-argument} modular instructions; + \item the \textbf{extended modular arithmetic} module deals with \emph{three-argument} modular instructions. +\end{enumerate} \ No newline at end of file diff --git a/alu/primitives/modular.tex b/alu/primitives/modular.tex new file mode 100644 index 0000000..d2ed941 --- /dev/null +++ b/alu/primitives/modular.tex @@ -0,0 +1,283 @@ +Suppose we are given two unsigned $256$-bit integers +$0 \leq \col{A}, \col{B} < 2^{256}$ with $\col{B} \neq 0$. +We explain how to verify a quotient and remainder pair $(\col{Q}, \col{R})$ (two $256$-bit integers) representing the (supposed) euclidean division of $\col{A}$ by $\col{B}$. Recall that $\col{Q}$ and $\col{R}$ must satisfy the following: +\[ + \left\{ + \begin{array}{lr} + 0 \leq \col{R} < \col{B} + & \qquad (1) \\ + A = \col{Q} \cdot \col{B} + \col{R} + & \qquad (2) \\ + \end{array} + \right. +\] +where $(2)$ is supposed to hold \emph{over the integers} rather than the $\text{mod} ~ 2^{256}$ arithmetic of the \textsc{evm}. The verification procedure is contained in the following: +\begin{lem} +Let $\col{A}$, $\col{B} \neq 0$, $\col{Q}$ and $\col{R}$ be $256$-bit integers. +Define, for $k = 0, 1, 2, 3$, bits +$\col{eq}_{k}$ and +$\col{lt}_{k}$ by imposing that +\[ + \left\{ + \begin{array}{lcc} + \col{eq}_{k} = 1 & \iff & \col{R}_{k} = \col{B}_{k}\\ + \col{lt}_{k} = 1 & \iff & \col{R}_{k} < \col{B}_{k}\\ + \end{array} + \right. +\] +Then the pair $(\col{Q}, \col{R})$ represents the quotient and remainder respectively of the euclidean division of $\col{A}$ by $\col{B}$ \emph{iff} +\[ + \col{lt}_{3} + + + \col{eq}_{3} \cdot \col{lt}_{2} + + + \col{eq}_{3} \cdot \col{eq}_{2} \cdot \col{lt}_{1} + + + \col{eq}_{3} \cdot \col{eq}_{2} \cdot \col{eq}_{1} \cdot \col{lt}_{0} + = + 1 + \tag{$\bigstar$} +\] +and +\[ + \renewcommand{\arraystretch}{1.5} + \left(\begin{array}{crcl} + & \col{R}\high \\ + + & \beta + \col{H}_{1} + \theta \cdot \alpha\\ + + & + \Big( + \col{Q}_{0}\col{B}_{2} + + + \col{Q}_{1}\col{B}_{1} + + + \col{Q}_{2}\col{B}_{0} + \Big) \\ + + & + \theta \cdot \Big( + \col{Q}_{0}\col{B}_{3} + + + \col{Q}_{1}\col{B}_{2} + + + \col{Q}_{2}\col{B}_{1} + + + \col{Q}_{3}\col{B}_{0} + \Big) \\ + \hline + = & + \col{A}\high + \end{array}\right) + \quad\text{and}\quad + \left( + \begin{array}{crcl} + & \col{Q}_{3}\col{B}_{1} + \col{Q}_{2}\col{B}_{2} + \col{Q}_{1}\col{B}_{3} \\ + + & \col{Q}_{3}\col{B}_{2} + \col{Q}_{2}\col{B}_{3}\\ + + & \col{Q}_{3}\col{B}_{3} \\ + \hline + = & 0 \\ + \end{array} + \right) +\] +where $0 \leq \col{H}_{0}, \col{H}_{1} < \theta$ and $0 \leq \alpha \leq 1$, $0 \leq \beta \leq 2$ are defined by +\[ + \left\{ + \begin{array}{lcl} + \col{Q}_{1}\col{B}_{0} + + + \col{Q}_{0}\col{B}_{1} + & \equiv & + [0 + \,|\, \alpha + \,|\, \col{H}_{1} + \,|\, \col{H}_{0} + ] \\ + \col{Q}_{0}\col{B}_{0} + + + \theta \cdot \col{H}_{0} + + + \col{R}\low + & \equiv & + [ + \beta \,\|\, \col{A}\low + ] + \end{array} + \right. +\] +\end{lem} + +\paragraph{Verifying ${0 \leq \colm{R} < \colm{B}}$.} +Note that the condition $0 \leq \col{R} < \col{B}$ is equivalent to +\[ + \left\{ + \begin{array}{lc} + \phantom{\big(} + \col{lt}_{3} = 1 & \OR \\ + \big( \col{eq}_{3} = 1 \et \col{lt}_{2} = 1 \big) & \OR \\ + \big( \col{eq}_{3} = 1 \et \col{eq}_{2} = 1 \et \col{lt}_{1} = 1 \big) & \OR \\ + \big( \col{eq}_{3} = 1 \et \col{eq}_{2} = 1 \et \col{eq}_{1} = 1 \et \col{lt}_{0} = 1 \big) & \OR \\ + \end{array} + \right. +\] +Seeing as all these options are mutually exclusive this boils down to +\( + \col{lt}_{3} + + + \col{eq}_{3} \cdot \col{lt}_{2} + + + \col{eq}_{3} \cdot \col{eq}_{2} \cdot \col{lt}_{1} + + + \col{eq}_{3} \cdot \col{eq}_{2} \cdot \col{eq}_{1} \cdot \col{lt}_{0} + = + 1 +\) i.e. we recover $(\bigstar)$. + +\paragraph{Verifying ${\colm{A}} = {\colm{Q} \cdot \colm{B}} + {\colm{R}}$ over the integers.} +For the second condition consider the multiplication table +\[ + \renewcommand{\arraystretch}{1.5} + \begin{array}{|c|c|c|c|c|} + \cline{2-5} + \multicolumn{1}{c|}{} & \col{B}_{0} & \col{B}_{1} & \col{B}_{2} & \col{B}_{3} \\ + \hline + \col{Q}_{0} & {\cellcolor{\romCol}\col{Q}_{0}\col{B}_{0}} & {\cellcolor{\stackCol}\col{Q}_{0}\col{B}_{1}} & {\cellcolor{\txcdCol}\col{Q}_{0}\col{B}_{2}} & {\cellcolor{\shaCol}\col{Q}_{0}\col{B}_{3}} \\ + \hline + \col{Q}_{1} & {\cellcolor{\stackCol}\col{Q}_{1}\col{B}_{0}} & {\cellcolor{\txcdCol}\col{Q}_{1}\col{B}_{1}} & {\cellcolor{\shaCol}\col{Q}_{1}\col{B}_{2}} & \col{Q}_{1}\col{B}_{3} \\ + \hline + \col{Q}_{2} & {\cellcolor{\txcdCol}\col{Q}_{2}\col{B}_{0}} & {\cellcolor{\shaCol}\col{Q}_{2}\col{B}_{1}} & \col{Q}_{2}\col{B}_{2} & \col{Q}_{2}\col{B}_{3} \\ + \hline + \col{Q}_{3} & {\cellcolor{\shaCol}\col{Q}_{3}\col{B}_{0}} & \col{Q}_{3}\col{B}_{1} & \col{Q}_{3}\col{B}_{2} & \col{Q}_{3}\col{B}_{3} \\ + \hline + \end{array} +\] +One has the equality over the \emph{integers} +\begin{IEEEeqnarray*}{RCL} + \col{Q} \cdot \col{B} + \col{R} + & = & + \col{Q}_{0}\col{B}_{0} \\ + & & + + \theta\cdot + \big( + \col{Q}_{1}\col{B}_{0} + + \col{Q}_{0}\col{B}_{1} + \big) \\ + & & + + \theta^{2}\cdot + \big( + \col{Q}_{2}\col{B}_{0} + + \col{Q}_{1}\col{B}_{1} + + \col{Q}_{0}\col{B}_{2} + \big) \\ + & & + + \theta^{3}\cdot + \big( + \col{Q}_{3}\col{B}_{0} + + \col{Q}_{2}\col{B}_{1} + + \col{Q}_{1}\col{B}_{2} + + \col{Q}_{0}\col{B}_{3} + \big) \\ + & & + + \theta^{4}\cdot + \big( + \col{Q}_{3}\col{B}_{1} + + \col{Q}_{2}\col{B}_{2} + + \col{Q}_{1}\col{B}_{3} + \big) \\ + & & + + \theta^{5}\cdot + \big( + \col{Q}_{3}\col{B}_{2} + + \col{Q}_{2}\col{B}_{3} + \big) \\ + & & + + \theta^{6}\cdot + \col{Q}_{3}\col{B}_{3} + \\ + & & + + \col{R}\low + + \theta^2 \cdot \col{R}\high +\end{IEEEeqnarray*} +If we intend to have $\col{Q} \cdot \col{B} + \col{R} = \col{A}$ then the terms preceded by $\theta^{4}$, $\theta^{5}$ and $\theta^{6}$ must vanish. Furthermore the term +$\col{Q}_{0}\col{B}_{0} ++ \theta\cdot +\big( +\col{Q}_{1}\col{B}_{0} ++ \col{Q}_{0}\col{B}_{1} +\big)$ determines $\col{Q} \cdot \col{B} + \col{R} \mod 2^{128}$ which would then be $\col{A}\low$. +We thus introduce more notation. Let us write +\[ + \col{Q}_{1}\col{B}_{0} + + + \col{Q}_{0}\col{B}_{1} + \equiv + [0 + \,|\, \alpha + \,|\, \col{H}_{1} + \,|\, \col{H}_{0} + ] +\] +Note that $0 \leq \col{Q}_{k},\col{B}_{k} \leq \theta - 1$ implies that $0 \leq \col{Q}_{1}\col{B}_{0} + \col{Q}_{0}\col{B}_{1} \leq 2 \theta^2 - 4\cdot\theta + 2 < 2 \theta^2$ so that $\alpha\in\{0,1\}$. The first constraint we must impose is therefore +\[ + \col{Q}_{0}\col{B}_{0} + + + \theta \cdot \col{H}_{0} + + + \col{R}\low + = + \col{A}\low + \theta^2 \cdot \beta +\] +where +\[ + \left\{ + \begin{array}{ccccl} + 0 & \!\!\! \leq \!\!\! & \col{Q}_{0}\col{B}_{0} & \!\!\! \leq \!\!\! & \theta^2 - 2\theta + 1 \\ + 0 & \!\!\! \leq \!\!\! & \theta \cdot \col{H}_{0} & \!\!\! \leq \!\!\! & \theta^2 - \theta \\ + 0 & \!\!\! \leq \!\!\! & \col{R}\low & \!\!\! \leq \!\!\! & \theta^2 - 1 \\ + \end{array} + \right\} + \text{ imply } + \beta\in\{0,1,2\}. +\] +Similarly we could write +\[ + \col{Q}_{0}\col{B}_{3} + + + \col{Q}_{1}\col{B}_{2} + + + \col{Q}_{2}\col{B}_{1} + + + \col{Q}_{3}\col{B}_{0} + \equiv + [0 \,|\, + \zeta \,|\, + \col{H}_{3} \,|\, + \col{H}_{2} ]. +\] +for some $\zeta\in\{0, 1, 2, 3\}$ (where one expects to have $\zeta = 0$ and $\col{H}_{3} = 0$.) One would then impose +\[ + \left\{\begin{array}{l} + \zeta = 0 \\ + \col{H}_{3} = 0 \\ + \beta + \col{H}_{1} + \theta \cdot \alpha + \theta\col{H}_{2} \\ + \quad + + \col{Q}_{0}\col{B}_{2} + + + \col{Q}_{1}\col{B}_{1} + + + \col{Q}_{2}\col{B}_{0} + \col{R}\high = \col{A}\high + + \theta^2 \cdot \gamma \\ + \text{for some }\gamma\in\{0,1,2,3,4\} \\ + \gamma = 0 \\ + \end{array} + \right. + \quad\text{and}\quad + \left\{ + \begin{array}{l} + \col{Q}_{3}\col{B}_{1} = 0 \\ + \col{Q}_{2}\col{B}_{2} = 0 \\ + \col{Q}_{1}\col{B}_{3} = 0 \vspace{2mm} \\ + \col{Q}_{3}\col{B}_{2} = 0 \\ + \col{Q}_{2}\col{B}_{3} = 0 \vspace{2mm} \\ + \col{Q}_{3}\col{B}_{3} = 0 \\ + \end{array} + \right. +\] +Given the ranges of the integers at play we can add up all equations $\cdots = 0$ and get an equivalent system. This leads us to the following conclusion \dots{} \ob{TODO: finish this mess} diff --git a/alu/primitives/multiplication.tex b/alu/primitives/multiplication.tex new file mode 100644 index 0000000..d5d547b --- /dev/null +++ b/alu/primitives/multiplication.tex @@ -0,0 +1,96 @@ +We present in the present section a set of constraints \setMultiplication{} that encodes multiplication $\mod 2^{256}$. +\begin{lem}[multiplication $\text{mod }2^{256}$] +Let +$\col{A}\equiv[\col{A}_{3} \,|\, \col{A}_{2} \,|\, \col{A}_{1} \,|\, \col{A}_{0}]$, +$\col{B}\equiv[\col{B}_{3} \,|\, \col{B}_{2} \,|\, \col{B}_{1} \,|\, \col{B}_{0}]$ +and +$\col{P} \equiv [\col{P}_{3} \,|\, \col{P}_{2} \,|\, \col{P}_{1} \,|\, \col{P}_{0}]$ +% $\col{P} \equiv [\col{P}\high \,\|\, \col{P}\low]$ +be $256$-bit integers. The following are equivalent: +\begin{enumerate} + \item $\col{A} \cdot \col{B} = \col{P} \mod 2^{256}$; + \item there exists a $256$-bit integer $\col{H} \equiv [\col{H}_{3} \,|\, \col{H}_{2} \,|\, \col{H}_{1} \,|\, \col{H}_{0}]$ + and $\alpha \in \{ 0, 1 \}$, + $\beta \in \{ 0, 1, 2, 3 \}$, + $\eta \in \{ 0, 1 \}$, + $\mu \in \{ 0, 1, 2, 3 \}$ such that + \[ + \left\{ + \begin{array}{lcl} + \col{A}_{1} \cdot \col{B}_{0} + + \col{A}_{0} \cdot \col{B}_{1} + & \!\!\! = \!\!\! & + \theta^2 \cdot \alpha + + \theta \cdot \col{H}_{1} + + \col{H}_{0} + \\ + %%%%% + \col{A}_{3} \cdot \col{B}_{0} + + \col{A}_{2} \cdot \col{B}_{1} + + \col{A}_{1} \cdot \col{B}_{2} + + \col{A}_{0} \cdot \col{B}_{3} + & \!\!\! = \!\!\! & + \theta^2 \cdot \beta + + \theta \cdot \col{H}_{3} + + \col{H}_{2} + \vspace{2mm} \\ + %%%%% + \col{A}_{0} \cdot \col{B}_{0} + + \theta \cdot \col{H}_{0} + & \!\!\! = \!\!\! & + \theta^2 \cdot \eta + + \theta \cdot \col{P}_{1} + + \col{P}_{0} + \\ + %%%%% + \eta + + \col{H}_{1} + + \theta \cdot \alpha + + \Big( + \col{A}_{2} \cdot \col{B}_{0} + + \col{A}_{1} \cdot \col{B}_{1} + + \col{A}_{0} \cdot \col{B}_{2} \Big) + + \theta \cdot \col{H}_{2} + & \!\!\! = \!\!\! & + \theta^2 \cdot \mu + + \theta \cdot \col{P}_{3} + + \col{P}_{2} + \\ + %%%%% + \end{array} + \right. + \] +\end{enumerate} +\end{lem} +We subsume these four equality constraints under the moniker +\[ + \setMultiplication + \left( + \begin{array}{c} + \col{A}_{3}, + \col{A}_{2}, + \col{A}_{1}, + \col{A}_{0}; \\ + \col{B}_{3}, + \col{B}_{2}, + \col{B}_{1}, + \col{B}_{0}; \\ + \col{P}_{3}, + \col{P}_{2}, + \col{P}_{1}, + \col{P}_{0}; \\ + \col{H}_{3}, + \col{H}_{2}, + \col{H}_{1}, + \col{H}_{0}; \\ + \alpha, \beta; \eta, \mu; \\ + \end{array} + \right) +\] +\saNote{} There are \emph{implicit assumptions} that aren't part of the constraint itself: +\begin{enumerate} + \item the $\col{A}_{k}$'s, $\col{B}_{k}$'s, $\col{P}_{k}$'s and $\col{H}_{k}$'s are $\mmedium$-byte integers; + \item $\alpha$ and $\eta$ are bits; + \item $\beta$ and $\mu$ are $2$-bit integers. +\end{enumerate} +Everytime the $\setMultiplication$ will be invoked in the sequel these assumptions will be enforced by other constraints and thus met. diff --git a/alu/primitives/negatives.tex b/alu/primitives/negatives.tex new file mode 100644 index 0000000..1a4b30e --- /dev/null +++ b/alu/primitives/negatives.tex @@ -0,0 +1,85 @@ +Let $y$ be an integer in the range $\big[\!\!\!\:\big[-2^{255}, 2^{255}\big[\!\!\!\:\big[$. Recall that under \emph{overflow semantics}\footnote{\ob{TODO: reference the \inst{SDIV} specification of the yellow paper}} its negative $y.\col{Neg()}\in \big[\!\!\!\:\big[-2^{255}, 2^{255}\big[\!\!\!\:\big[$ is defined as follows: +\[ + \begin{cases} + \If y = -2^{255}:& y.\col{Neg()} = -2^{255}, \\ + \If y \neq -2^{255}:& y.\col{Neg()} = - y. \\ + \end{cases} +\] +Note that $-2^{255}$ is its own negative\footnote{as is $0$.}. + +\begin{lem}[negatives] +Let +$\colm{Y} \equiv [\colm{Y}\high \,\|\, \colm{Y}\low]$ and +$\colm{Z} \equiv [\colm{Z}\high \,\|\, \colm{Z}\low]$ be $256$-bit integers where $\colm{Y}$, interpreted as a $2$'s complement signed integer, represents an integer $\imported{\colm{Y}} \in \big[\!\!\!\:\big[-2^{255}, 2^{255}\big[\!\!\!\:\big[$. The following are equivalent +\begin{enumerate} + \item $\colm{Z}$, interpreted as a $2$'s complement signed integer, represents an integer ``$\imported{\colm{Y}}.\colm{Neg()}$'' + \item the following system of constraints is satisfied: + \begin{enumerate} + \item \If $\colm{Y}\low \neq 0$ \Then + \[ + \begin{cases} + \colm{Z}\high = \theta^2 - \colm{Y}\high - 1\\ + \colm{Z}\low = \theta^2 - \colm{Y}\low \\ + \end{cases} + \] + \item \If $\colm{Y}\low = 0$: + \begin{enumerate} + \item \If \Big($\colm{Y}\high = 0$ \OR $\colm{Y}\high = 2^{127}$\Big) \Then + \[ + \begin{cases} + \colm{Z}\high = \colm{Y}\high \\ + \colm{Z}\low = 0 \\ + \end{cases} + \] + \item \If \Big($\colm{Y}\high \neq 0$ \et $\colm{Y}\high \neq 2^{127}$\Big) \Then + \[ + \begin{cases} + \colm{Z}\high = \theta^2 - \colm{Y}\high \\ + \colm{Z}\low = 0 \\ + \end{cases} + \] + \end{enumerate} + \end{enumerate} +\end{enumerate} +\end{lem} +\iffalse +Now let $\col{Y} \equiv [\col{Y}\high\,\|\, \col{Y}\low]$ be a $256$-bit integer. +Interpreted as a $2$'s complement signed integer it represents an integer $\imported{\col{Y}} \in \big[\!\!\!\:\big[-2^{255}, 2^{255}\big[\!\!\!\:\big[$. +The $256$-bit integer $\col{Z}\equiv [ \col{Z}\high \,\|\, \col{Z}\low ]$ representing its negative satisfies the following: +\begin{enumerate} + \item \If $\col{Y}\low \neq 0$ \Then + \[ + \begin{cases} + \col{Z}\high = \theta^2 - \col{Y}\high - 1\\ + \col{Z}\low = \theta^2 - \col{Y}\low \\ + \end{cases} + \] + \item \If $\col{Y}\low = 0$: + \begin{enumerate} + \item \If \Big($\col{Y}\high = 0$ \OR $\col{Y}\high = 2^{127}$\Big) \Then + \[ + \begin{cases} + \col{Z}\high = \col{Y}\high \\ + \col{Z}\low = 0 \\ + \end{cases} + \] + \item \If \Big($\col{Y}\high \neq 0$ \et $\col{Y}\high \neq 2^{127}$\Big) \Then + \[ + \begin{cases} + \col{Z}\high = \theta^2 - \col{Y}\high \\ + \col{Z}\low = 0 \\ + \end{cases} + \] + \end{enumerate} +\end{enumerate} +\fi +We subsume the preceding constraints under the name \setNegative{} and write +\[ + \setNegative + \Big( + \col{Z}\high, + \col{Z}\low; + \col{Y}\high, + \col{Y}\low + \Big) +\] \ No newline at end of file diff --git a/alu/primitives/notations.tex b/alu/primitives/notations.tex new file mode 100644 index 0000000..9f6c518 --- /dev/null +++ b/alu/primitives/notations.tex @@ -0,0 +1,31 @@ +Throughout we set +\[ + \framebox{% + $\theta = 2^{64} = + 256^\mmedium$.} + \] +Note that $\theta^2 = 2^{128} = 256^\llarge$ and $\theta^4 = 2^{256}$. +If $0\leq \col{X} < 2^{256}$ is an \emph{unsigned $256$-bit integer} we write +$\col{X} \equiv [\col{X}\high \,\|\, \col{X}\low]$ and +$\col{X} \equiv [\col{X}_{3} \,|\, \col{X}_{2} \,|\, \col{X}_{1} \,|\, \col{X}_{0}]$ to mean the base $\theta^2$ and base $\theta$ representations of $\col{X}$ respectively: +\[ + \left\{ + \begin{array}{lclcl} + \col{X} + & \!\!\! = \!\!\! & \theta^2 \cdot \col{X}\high + \col{X}\low \\ + \multicolumn{3}{l}{\text{with } 0 \leq \col{X}\high, \col{X}\low < \theta^2} \vspace{2mm} \\ + \col{X}& \!\!\! = \!\!\! & + \theta^3 \cdot \col{X}_{3} + + \theta^2 \cdot \col{X}_{2} + + \theta \cdot \col{X}_{1} + + \col{X}_{0} \\ + \multicolumn{3}{l}{\text{with } 0 \leq \col{X}_{3}, \col{X}_{2}, \col{X}_{1}, \col{X}_{0} < \theta} \\ + \end{array} + \right. +\] +Note that $\col{X}\high = \theta \cdot \col{X}_{3} + \col{X}_{2}$ and $\col{X}\low = \theta \cdot \col{X}_{1} + \col{X}_{0}$. When manipulating $512$-bit integers $\col{Y}$ (as one must for $\inst{MULMOD}$) we naturally extend notation as one would expect: +$\col{Y} \equiv [\col{Y}_{3} \,\|\, \col{Y}_{2} \,\|\, \col{Y}_{1} \,\|\, \col{Y}_{0}]$ +and +$\col{Y} \equiv [\col{Y}_{7} \,|\, \cdots \,|\, \col{Y}_{1} \,|\, \col{Y}_{0}]$. \vspace{2mm} + +\noindent \saNote{} These two notations are at odds with one another. However they will never apply to the \emph{same} underlying $512$-bit integer. Note furthermore that the only time we require manipulation of $512$-bit integers is when dealing with \inst{MULMOD} which we deal with in the extended modular arithmetic module. diff --git a/bin/_all_bin.tex b/bin/_all_bin.tex new file mode 100644 index 0000000..58d6bdb --- /dev/null +++ b/bin/_all_bin.tex @@ -0,0 +1,34 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/common_shorthands} +\usepackage{../pkg/wc3} +\usepackage{../pkg/iomf_done} + +\title{Binary module} +\author{Rollup team} +\date{November 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/bin/_inputs.tex b/bin/_inputs.tex new file mode 100644 index 0000000..d3d0458 --- /dev/null +++ b/bin/_inputs.tex @@ -0,0 +1,21 @@ +\section{Binary module} +\subsection{Introduction} \label{bin: intro} \input{introduction} +\subsection{Columns} \label{bin: columns} \input{columns} + +\section{Constraints} +\subsection{Binary constraints} \label{bin: binary} \input{binary} +\subsection{Shorthands} \label{bin: shorthands} \input{shorthands} +\subsection{Instruction decoding} \label{bin: instruction decoding} \input{decoding} +\subsection{Heartbeat} \label{bin: heartbeat} \input{heartbeat} +\subsection{Constancy constraints} \label{bin: stamp constancies} \input{constancy} +\subsection{Byte decompositions} \label{bin: byte decompositions and bytehood} \input{byteDec} +\subsection{Target constraints} \label{bin: target constraints} \input{target} +\subsection{Binary column constraints} +\subsubsection{\BITS{} and related columns} \label{bin: bits and related columns constraints} \input{bits} +\subsubsection{$\bit{1}$ constraints} \label{bin: bit_1} \input{plateau} +\subsubsection{\smallness{} constraints} \label{bin: smallness} \input{smallness} +\subsection{\pivotByte{} constraints} \label{bin: pibot byte} \input{pivot} +\subsection{Result constraints} \label{bin: result constraints} \input{result} + +\section{Lookups} +\subsection{Lookups to the binary reference table} \label{bin: lookup} \input{lookup} diff --git a/bin/binary.tex b/bin/binary.tex new file mode 100644 index 0000000..cff7ccc --- /dev/null +++ b/bin/binary.tex @@ -0,0 +1,18 @@ +We impose that the following columns be binary: +\begin{multicols}{3} + \begin{enumerate} + \item \isAnd{} + \item \isOr{} + \item \isXor{} + \item \isNot{} + \item \isByte{} + \item \isSignextend{} + \item \smallness + \item \BITS + \item \NEG + \item $\bit{b_4}$ + \item $\bit{1}$ + \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/bin/bits.tex b/bin/bits.tex new file mode 100644 index 0000000..2c955d1 --- /dev/null +++ b/bin/bits.tex @@ -0,0 +1,14 @@ +The $\BITS$ column is constrained by the first two constraints below; the columns $\NEG$, $\pivotByte$, $\lowFour$ and $\bit{b_4}$ are deduced from it. +\begin{enumerate} + \item \If ($\isByte_{i} + \isSignextend_{i}=1$) \et $\ct_{i} = \llargeMO$ \Then + \begin{enumerate} + \item $\pivotByte_{i} = \sum_{k=0}^7 2^{7-k} \cdot \bits_{i - \llargeMO + k}$ + \item $\byteCol{2}_{i} = \sum_{k=0}^7 2^k \cdot \bits_{i-k}$ + \item $\lowFour_{i} = \sum_{k=0}^3 2^k \cdot \bits_{i-k}$ + \item $\bit{b_4}_{i} = \bits_{i-4}$ + \item $\NEG_{i} = \BITS_{i - \llargeMO}$ + \end{enumerate} +\end{enumerate} +\saNote{} We employ the precondition +``\If $\ct_{i} = \llargeMO$'' rather than the usual +``\If $\ct_{i} = \maxCt$'' to enforce that the above only hold when the underlying instruction may not be dealt with in a single row, see constraint~(\ref{bin: heartbeat: maxCt for BYTE and SIGNEXTEND}) diff --git a/bin/byteDec.tex b/bin/byteDec.tex new file mode 100644 index 0000000..9280260 --- /dev/null +++ b/bin/byteDec.tex @@ -0,0 +1,6 @@ +We enforce ``byte accumulation constraints'' for $k=1, \dots, 6$: +\begin{enumerate} + \item $\byteCol{k}$, for $k=1, \dots, 6$, contain bytes; + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i - 1} + \byteCol{k}_{i}$; +\end{enumerate} diff --git a/bin/columns.tex b/bin/columns.tex new file mode 100644 index 0000000..2a03e72 --- /dev/null +++ b/bin/columns.tex @@ -0,0 +1,71 @@ +The first columns dictate the present module's heartbeat. This heartbeat is nearly identical to that of the \textbf{word comparison module}. +\begin{enumerate} + \item $\binStamp$: + imported column containing the word comparison stamp; + \item \maxCt{}: indicates the value at which \ct{} must reset; + \item \ct{}: + counts continuously from $0$ to $\maxCt{}$ and then resets; +\end{enumerate} +The following are imported values (opcode, arguments and results) obtained from the hub. +\begin{enumerate}[resume] + \item $\INST{}$: + \godGiven{} + imported column; contains the instruction; + \item $\argOneHi$, $\argOneLo$: + \godGiven{} + contains the high and low part of the first instruction argument; + \item $\argTwoHi$, $\argTwoLo$: + \godGiven{} + contains the high and low part of the second instruction argument; + \item $\resHi$, $\resLo$: + \godGiven{} + contains the high and low part of the instruction output; + \item \isAnd{}, \isOr{}, \isXor{}, \isNot{}, \isByte{} and \isSignextend{}: + exclusive \emph{de facto} counter-constant binary columns; + light up for the associated \binMod{} module instruction; +\end{enumerate} +The following columns are only of import for the processing of the +\inst{BYTE} and +\inst{SIGNEXTEND} +instructions. +\begin{enumerate}[resume] + \item $\smallness$: + stamp-constant binary column; + \item $\BITS$: + binary column; + \item $\bit{b_4}$: + stamp-constant binary column; + \item $\lowFour$: + stamp-constant column with values in $\{0,1,\dots,\llargeMO\}$; + \item $\NEG$: + counter-constant binary column; +\end{enumerate} +$\smallness$ \emph{may} determine whether $\argOne$ is a byte. +$\BITS$ \emph{may} contain the bits of the bit decomposition of the least significant byte of $\argOne$ +as well as the bit decomposition of a particular byte of $\argTwo$. +From the former bit decomposition we extract the 5 least significant bits, of those the most significant bit is recorded in $\bit{b_4}$ and the remaining 4 are assembled into $\lowFour$. +From the latter bit decomposition we extract $\NEG$ which contains the sign bit of a particular byte of $\argTwo$. +The \inst{SIGNEXTEND} instructions \emph{may} require this sign bit. + +The following two columns allow us to extract the desired byte from $\argTwo$: +\begin{enumerate}[resume] + \item $\bit{1}$: + binary column; + \item $\pivotByte$: + stamp-constant column containing a byte; +\end{enumerate} +$\bit{1}$ satisfies a particular plateau constraint +(with jump at $\ct = \lowFour$ for \inst{BYTE} instructions and +with jump at $\ct = \llargeMO - \lowFour$ for \inst{SIGNEXTEND} instructions, repectively.) + +The following decoded columns contain the result of bitwise binary operations on bytes: +\begin{enumerate}[resume] + \item $\byteCol{1}, \dots{}, \byteCol{6}$: + byte columns; + \item $\acc{1}, \dots{}, \acc{6}$: + ``(byte) accumulator'' columns; + % \item $\decAND{HI}, \decAND{LO}$, $\decNOT{HI}, \decNOT{LO}$, $\decOR{HI}, \decOR{LO}$, $\decXOR{HI}, \decXOR{LO}$: + % decoded byte columns; + \item $\decXXX{HI}, \decXXX{LO}$: + columns obtained through a lookup argument; contain the high and low parts respectively of the bitwise operations on the current pair of (high or low) bytes; +\end{enumerate} diff --git a/bin/constancy.tex b/bin/constancy.tex new file mode 100644 index 0000000..60461c7 --- /dev/null +++ b/bin/constancy.tex @@ -0,0 +1,22 @@ +\noindent As usual, we define a column $\col{X}$ to be \textbf{counter-constant} if it satisfies +\[ + \ct_{i} \neq 0 \implies \col{X}_{i} = \col{X}_{i - 1}. +\] +The following columns are required to be counter-constant: +\begin{multicols}{4} +\begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resHi$ + \item $\resLo$ + \item $\INST$ + \item $\maxCt$ + \item $\pivotByte$ + \item $\bit{b_4}$ + \item $\lowFour$ + \item $\NEG$ + \item $\smallness$ +\end{enumerate} +\end{multicols} diff --git a/bin/decoding.tex b/bin/decoding.tex new file mode 100644 index 0000000..6e90fba --- /dev/null +++ b/bin/decoding.tex @@ -0,0 +1,14 @@ +This section enforces the instruction decoding by means of the +\begin{enumerate} + \item \If $\binStamp_{i} = 0$ \Then $\locFlagSum_{i} = 0$ + \item \If $\binStamp_{i} \neq 0$ \Then $\locFlagSum_{i} = 1$ + \item We impose the following unique decoding constraint: $\INST_{i} = \locWeightedFlagSum_{i}$ + % \[ + % \left\{ \begin{array}{lcl} + % \INST_{i} & = & \locWeightedFlagSum_{i} \\ + % \oli_{i} & = & \locOli_{i} \\ + % \mli_{i} & = & \locMli_{i} \\ + % \end{array} \right. + % \] +\end{enumerate} +\saNote{} Since \locFlagSum{} is a sum of binary columns the above enforces that at any row at most one of these may be on. diff --git a/bin/heartbeat.tex b/bin/heartbeat.tex new file mode 100644 index 0000000..7c370f3 --- /dev/null +++ b/bin/heartbeat.tex @@ -0,0 +1,25 @@ +The heartbeat of the binary module is straightforward: the \ct{} columns counts continuously from $0$ to \maxCt{} whereupon it resets. +\begin{enumerate} + \item $\binStamp_{0} = 0$; + \item $\binStamp$ is nondecreasing in the sense that $\binStamp_{i + 1} \in \{ \binStamp_{i}, 1 + \binStamp_{i} \}$; + \item \If $\binStamp_{i + 1} \neq \binStamp_{i}$ \Then $\ct_{i + 1} = 0$; + \item \If $\isNot_{i} = 1$ \Then $\maxCt_{i}=\llargeMO$ + \item \label{bin: heartbeat: maxCt for BYTE and SIGNEXTEND} + \If $\isByte_{i} + \isSignextend_{i}=1$ \Then: + \[ + \begin{cases} + \If \argOneHi_{i} = 0 ~ \Then \maxCt_{i}=\llargeMO \\ + \If \argOneHi_{i} \neq 0 ~ \Then \maxCt_{i}= 0\\ + \end{cases} + \] + \item $\ct_{i} \neq \llarge$ + \item \If $\binStamp_{i} \neq 0$ + \begin{enumerate} + \item + \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item + \If $\ct_{i} = \maxCt_{i}$ \Then $\binStamp_{i + 1} = 1 + \binStamp_{i}$ + \end{enumerate} + \item $\ct_{N} = \maxCt_{N}$. +\end{enumerate} +The above enforce that $0 \leq \ct_i \leq \maxCt_i < \llarge$ holds on non-padding rows (i.e. when $\wcpStamp_{i} \neq 0$). This is achieved through the above constraint imposing that \ct{} never be equal to $\llarge$ and counter-constancy of \maxCt{}, see section~(\ref{bin: stamp constancies}). diff --git a/bin/introduction.tex b/bin/introduction.tex new file mode 100644 index 0000000..0a97fa5 --- /dev/null +++ b/bin/introduction.tex @@ -0,0 +1,20 @@ +The \textbf{binary module} deals with the following instructions +\begin{multicols}{3} +\begin{enumerate} + \item \inst{AND} + \item \inst{OR} + \item \inst{XOR} + \item \inst{NOT} + \item \inst{BYTE} + \item \inst{SIGNEXTEND} +\end{enumerate} +\end{multicols} +There are two distinct patterns at play: one for the binary operations +\inst{AND}, +\inst{OR}, +\inst{XOR}, +\inst{NOT} +and another for +\inst{BYTE}, +\inst{SIGNEXTEND} +which need to extract a particular byte from their second argument. \ No newline at end of file diff --git a/bin/lookup.tex b/bin/lookup.tex new file mode 100644 index 0000000..00b530a --- /dev/null +++ b/bin/lookup.tex @@ -0,0 +1,26 @@ +The \binMod{} module requires two lookups to a \textbf{binary reference table}. +Both lookups follow the same structure. +The first lookup deals with the bytes from the high parts of both arguments, the second with the low parts. +We thus require the following lookups for both pairs +\begin{description} + \item[\underline{Selector:}] we use the selector $\col{sel}_{i} = \big( \isAnd_{i} + \isOr_{i} + \isXor_{i} + \isNot_{i} \big)$; + \item[\underline{Source columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\INST_{i}$ + \item $\decXXX{HI/LO}_{i}$ + \item $\byteCol{a}_{i}$ + \item $\byteCol{b}_{i}$ + \end{enumerate} + \end{multicols} + \saNote{} We use $(a,b) = (1,3)$ for the lookup associated to the \col{HI}-parts and $(a,b) = (2,4)$ for the lookup associated to the \col{LO}-parts. + \item[\underline{Target columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\INST_{j}$ + \item $\col{RESULT\_BYTE}_{j}$ + \item $\col{INPUT\_BYTE\_1}_{j}$ + \item $\col{INPUT\_BYTE\_2}_{j}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/bin/pivot.tex b/bin/pivot.tex new file mode 100644 index 0000000..c4dab8e --- /dev/null +++ b/bin/pivot.tex @@ -0,0 +1,41 @@ +This subsection is about the $\pivotByte$ column; this counter-constant column is made to contain one of the bytes from $\argTwo$. The pivot byte is meaningless for \inst{AND}, \inst{OR}, \inst{XOR} and \inst{NOT} instructions. It comes into play for \inst{BYTE} and \inst{SIGNEXTEND} instructions. +\begin{enumerate} + \item \If $\maxCt_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\isByte_{i} = 1$ \Then + \begin{enumerate} + \item \If \Big($\lowFour_{i} = 0$ \et $\ct_{i} = 0$\Big) \Then + \[ + \begin{cases} + \If \bit{b_{4}}_{i} = 0 ~ \Then \pivotByte_{i} = \byteCol{3}_{i} \\ + \If \bit{b_{4}}_{i} = 1 ~ \Then \pivotByte_{i} = \byteCol{4}_{i} \\ + \end{cases} + \] + \item \If \Big($\lowFour_{i} \neq 0$ \et $\bit{1}_{i - 1} = 0$ \et $\bit{1}_{i} = 1$\Big) \Then + \[ + \begin{cases} + \If \bit{b_{4}}_{i} = 0 ~ \Then \pivotByte_{i} = \byteCol{3}_{i} \\ + \If \bit{b_{4}}_{i} = 1 ~ \Then \pivotByte_{i} = \byteCol{4}_{i} \\ + \end{cases} + \] + \end{enumerate} + \item \If $\isSignextend_{i} = 1$ \Then + \begin{enumerate} + \item \If \Big($\lowFour_{i} = \llargeMO$ \et $\ct_{i} = 0$\Big) \Then + \[ + \begin{cases} + \If \bit{b_{4}}_{i} = 0 ~ \Then \pivotByte_{i} = \byteCol{4}_{i} \\ + \If \bit{b_{4}}_{i} = 1 ~ \Then \pivotByte_{i} = \byteCol{3}_{i} \\ + \end{cases} + \] + \item \If $\lowFour_{i} \neq \llargeMO$ \et $\bit{1}_{i - 1} = 0$ \et $\bit{1}_{i} = 1$ \Then + \[ + \begin{cases} + \If \bit{b_{4}}_{i} = 0 ~ \Then \pivotByte_{i} = \byteCol{4}_{i} \\ + \If \bit{b_{4}}_{i} = 1 ~ \Then \pivotByte_{i} = \byteCol{3}_{i} \\ + \end{cases} + \] + \end{enumerate} + \end{enumerate} +\end{enumerate} +\saNote{} The same remark on the precondition applies as in section~(\ref{precondition equivalent to CTMAX = 15}). diff --git a/bin/plateau.tex b/bin/plateau.tex new file mode 100644 index 0000000..b264094 --- /dev/null +++ b/bin/plateau.tex @@ -0,0 +1,13 @@ +The $\bit{1}$ column should sometimes satisfy a plateau constraint: +\begin{enumerate} + \item \If $\maxCt_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\isByte_{i} = 1$ \Then $\plateau(\bit{1}, \lowFour)$ + \item \If $\isSignextend_{i} = 1$ \Then $\plateau(\bit{1}, \llargeMO - \lowFour)$ + \end{enumerate} +\end{enumerate} +\saNote{} The ``\plateau'' constraint is defined in section~(\ref{mmio: specialized constraints: plateau}). + +\saNote{} \label{precondition equivalent to CTMAX = 15} +Since for \inst{BYTE} and \inst{SIGNEXTEND} the value of \maxCt{} is one of $0$ or $\llargeMO$, see section~(\ref{bin: heartbeat: maxCt for BYTE and SIGNEXTEND}), +the precondition ``\If $\maxCt_{i} \neq 0$ \Then'' is equivalent to the precondition ``\If $\maxCt_{i} = \llargeMO$ \Then''. diff --git a/bin/result.tex b/bin/result.tex new file mode 100644 index 0000000..8f0199f --- /dev/null +++ b/bin/result.tex @@ -0,0 +1,70 @@ +This section constrains on the result columns. +For \inst{BYTE} and \inst{SIGNEXTEND} instructions satisfying $\maxCt \equiv 0$ the result can be constrained on sight. +Otherwise one has to constrain their byte decompositions, i.e. $\byteCol{5}$ and $\byteCol{6}$. +\begin{enumerate} + \item \If $\isByte_{i} = 1$ \Then + \begin{enumerate} + \item \If $\maxCt_{i} = 0$ \Then + \[ + \begin{cases} + \resHi_{i} = 0 \\ + \resLo_{i} = 0 \\ + \end{cases} + \] + \item \If $\maxCt_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \resHi_{i} = 0 \\ + \resLo_{i} = \smallness_{i} \cdot \pivotByte_{i} \\ + \end{array} \right. + \] + \end{enumerate} + \item \If $\isSignextend_{i} = 1$ \Then + \begin{enumerate} + \item \If $\maxCt_{i} = 0$ \Then + \[ + \begin{cases} + \resHi_{i} = \argTwoHi \\ + \resLo_{i} = \argTwoLo \\ + \end{cases} + \] + \item \If $\maxCt_{i} \neq 0$ + \begin{enumerate} + \item \If $\smallness_{i} = 0$ \Then + \[ + \begin{cases} + \resHi_{i} = \argTwoHi_{i} \\ + \resLo_{i} = \argTwoLo_{i} \\ + \end{cases} + \] + \item \If $\smallness_{i} = 1$ \Then + \[ + \begin{cases} + \If \bit{b_4}_{i} = 0 ~ \Then + \begin{cases} + \byteCol{5}_{i} = \NEG_{i}\cdot 255 \\ + \begin{cases} + \If \bit{1}_{i} = 0 ~ \Then \byteCol{6}_{i} = \NEG_{i} \cdot 255 \\ + \If \bit{1}_{i} = 1 ~ \Then \byteCol{6}_{i} = \byteCol{4}_{i} \\ + \end{cases} \\ + \end{cases} \vspace{2mm} \\ + \If \bit{b_4}_{i} = 1 ~ \Then + \begin{cases} + \begin{cases} + \If \bit{1}_{i} = 0 ~ \Then \byteCol{5}_{i} = \NEG_{i} \cdot 255 \\ + \If \bit{1}_{i} = 1 ~ \Then \byteCol{5}_{i} = \byteCol{3}_{i} \\ + \end{cases} \\ + \resLo_{i} = \argTwoLo_{i} \\ + \end{cases} + \end{cases} + \] + \end{enumerate} + \end{enumerate} + \item \If $\isAnd_{i} + \isOr_{i} + \isXor_{i} + \isNot_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \byteCol{5}_{i} & \!\!\! = \!\!\! & \decXXX{HI}_{i} \\ + \byteCol{6}_{i} & \!\!\! = \!\!\! & \decXXX{LO}_{i} \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/bin/shorthands.tex b/bin/shorthands.tex new file mode 100644 index 0000000..7ff82ab --- /dev/null +++ b/bin/shorthands.tex @@ -0,0 +1,24 @@ +We use the following shorthands +\[ + \locFlagSum_{i} + \equiv + \left[ \begin{array}{cr} + + & \isAnd _{i} \\ + + & \isOr _{i} \\ + + & \isXor _{i} \\ + + & \isNot _{i} \\ + + & \isByte _{i} \\ + + & \isSignextend _{i} \\ + \end{array} \right] + \quad\text{and}\quad + \locWeightedFlagSum_{i} + \equiv + \left[ \begin{array}{crcl} + + & \inst{AND} & \cdot & \isAnd _{i} \\ + + & \inst{OR} & \cdot & \isOr _{i} \\ + + & \inst{XOR} & \cdot & \isXor _{i} \\ + + & \inst{NOT} & \cdot & \isNot _{i} \\ + + & \inst{BYTE} & \cdot & \isByte _{i} \\ + + & \inst{SIGNEXTEND} & \cdot & \isSignextend _{i} \\ + \end{array} \right] +\] diff --git a/bin/smallness.tex b/bin/smallness.tex new file mode 100644 index 0000000..e79ed9e --- /dev/null +++ b/bin/smallness.tex @@ -0,0 +1,11 @@ +The $\smallness{}$ column records whether $\argOneLo < 32$ or not. +\begin{enumerate} + \item \If ($\isByte_{i} + \isSignextend_{i}=1$) \et $\ct_{i} = \llargeMO$ \Then + \[ + \begin{cases} + \If \sum_{k = 0}^4 2^{k} \cdot \BITS_{i - k} = \argOneLo_{i} ~ \Then \smallness = 1 \\ + \If \sum_{k = 0}^4 2^{k} \cdot \BITS_{i - k} \neq \argOneLo_{i} ~ \Then \smallness = 0 \\ + \end{cases} + \] +\end{enumerate} +\saNote{} The same remark on the precondition applies as in section~(\ref{bin: bits and related columns constraints}). diff --git a/bin/target.tex b/bin/target.tex new file mode 100644 index 0000000..2491f9b --- /dev/null +++ b/bin/target.tex @@ -0,0 +1,29 @@ +We fix the targets of the accumulator columns: +\begin{enumerate} + \item \If $\opRequiresByteDecomposition_{i} \neq 0$ \et $\ct_{i} = \maxCt$ \Then + \[ + \left\{ + \begin{array}{lcl} + \acc{1}_{i} & \!\!\! = \!\!\! & \argOneHi_{i} \\ + \acc{2}_{i} & \!\!\! = \!\!\! & \argOneLo_{i} \vspace{2mm} \\ + \acc{3}_{i} & \!\!\! = \!\!\! & \argTwoHi_{i} \\ + \acc{4}_{i} & \!\!\! = \!\!\! & \argTwoLo_{i} \vspace{2mm} \\ + \acc{5}_{i} & \!\!\! = \!\!\! & \resHi_{i} \\ + \acc{6}_{i} & \!\!\! = \!\!\! & \resLo_{i} \\ + \end{array} + \right. + \] +\end{enumerate} + +Where we defined +\[ + \opRequiresByteDecomposition_{i} \define + \left[ \begin{array}{rcl} + + 1 & \!\!\!\cdot\!\!\! & \isAnd _{i} \\ + + 1 & \!\!\!\cdot\!\!\! & \isOr _{i} \\ + + 1 & \!\!\!\cdot\!\!\! & \isXor _{i} \\ + + 1 & \!\!\!\cdot\!\!\! & \isNot _{i} \\ + + \maxCt_{i} & \!\!\!\cdot\!\!\! & \isByte _{i} \\ + + \maxCt_{i} & \!\!\!\cdot\!\!\! & \isSignextend _{i} \\ + \end{array} \right] +\] diff --git a/block_data/_all_block_data.tex b/block_data/_all_block_data.tex new file mode 100644 index 0000000..4e2cbfb --- /dev/null +++ b/block_data/_all_block_data.tex @@ -0,0 +1,39 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/block_hash} +\usepackage{../pkg/txn_data} + +\title{Block data module} +\author{Rollup team} +\date{March 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/block_data/_inputs.tex b/block_data/_inputs.tex new file mode 100644 index 0000000..2551f6c --- /dev/null +++ b/block_data/_inputs.tex @@ -0,0 +1,13 @@ +\section{Block data module} +\subsection{Introduction} \label{block data: intro} \input{intro} +\subsection{Columns} \label{block data: columns} \input{columns} + +\section{Constraints} +\subsection{Heartbeat} \label{block data: heartbeat} \input{heartbeat} +\subsection{Constancies} \label{block data: constancies} \input{constancies} +\subsection{Bytehood and byte decomposition constraints} \label{block data: byte decomposition} \input{byteDec} +\subsection{Value Constraints} \label{block data: timestamp monotony} \input{value_constraint} + +\section{Lookups} \label{block data: lookups} \input{lookups/_inputs} + + diff --git a/block_data/byteDec.tex b/block_data/byteDec.tex new file mode 100644 index 0000000..585e3cc --- /dev/null +++ b/block_data/byteDec.tex @@ -0,0 +1,22 @@ +We impose bytehood constraints on the following columns +\begin{multicols}{2} + \begin{enumerate} + \item $\byteCol{HI\_k}$, $k = 0, 1, \dots, \llargeMO$ + \item $\byteCol{LO\_k}$, $k = 0, 1, \dots, \llargeMO$ + \end{enumerate} +\end{multicols} +\noindent We impose horizontal byte decomposition constraints: +\[ + \left\{ \begin{array}{lcl} + \blockDataHi _{i} + & \!\!\! = \!\!\! & + \displaystyle \sum_{k = 0}^{\llargeMO} 256^(\llargeMO - k) \cdot \byteCol{HI\_k}_{i} \\ + \blockDataLo _{i} + & \!\!\! = \!\!\! & + \displaystyle \sum_{k = 0}^{\llargeMO} 256^(\llargeMO - k) \cdot \byteCol{LO\_k}_{i} \\ + \end{array} \right. +\] + +% evm.codes ≡ 1636704767 +% etherscan ≡ 1714989956 +% 0x 6638AB84 diff --git a/block_data/columns.tex b/block_data/columns.tex new file mode 100644 index 0000000..a7c76fd --- /dev/null +++ b/block_data/columns.tex @@ -0,0 +1,21 @@ +\begin{enumerate} + \item \blockNumberOfFirstBlockInConflation{}: + block number\footnote{In the sense of the \evm{}} of the first block of this batch; + \item $\ct$: + counter column; hovers around zero and then cycles from $0$ to $\maxCtBtcData$; + \item $\relBlock$: + counter-constant column containing the relative block number; + \item $\relTxMax$: + counter-constant column containing the number of transaction in this block; + \item $\INST$: + instruction column; initially $0$ then cycles from \texttt{0x\,10} (i.e. \inst{COINBASE}) to \texttt{0x\,46} (i.e. \inst{CHAINID}); + \item $\blockDataHi$, $\blockDataLo$: + columns containing batch data; + \item $\coinbase\high$ and $\coinbase\low$: + coinbase address; + \item \blockGasLimit{}: + \item \basefee{}: + \item $\byteCol{HI\_k}$, and $\byteCol{LO\_k}$, $k = 0, 1, \dots, \llargeMO$: + \item $\wcpFlag$: + binary flags used as selector for lookups; +\end{enumerate} diff --git a/block_data/constancies.tex b/block_data/constancies.tex new file mode 100644 index 0000000..e200ee1 --- /dev/null +++ b/block_data/constancies.tex @@ -0,0 +1,14 @@ +As per usual we declare a column \col{X} to be \textbf{counter-constant} if it satisfies +\[ + \If \ct _{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose that the following columns be counter-constant +\begin{multicols}{2} + \begin{enumerate} + \item $\relTxMax$ + \item $\coinbase\high$ + \item $\coinbase\low$ + \item \blockGasLimit + \item \basefee + \end{enumerate} +\end{multicols} diff --git a/block_data/heartbeat.tex b/block_data/heartbeat.tex new file mode 100644 index 0000000..3eb1dac --- /dev/null +++ b/block_data/heartbeat.tex @@ -0,0 +1,23 @@ +The heartbeat is standard and simple: +\begin{enumerate} + \item $\relBlock_{0} = 0$ + \item \If $\relBlock_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \blockNumberOfFirstBlockInConflation & \!\!\! = \!\!\! & 0 \\ + \INST_{i} & \!\!\! = \!\!\! & 0 \\ + \ct_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\ + \end{array} \right. + \] + \item $\relBlock_{i + 1} \in \{ \relBlock_{i}, 1 + \relBlock_{i} \}$ + \item \If $\relBlock_{i} \neq \relBlock_{i-1}$ \Then $\ct_{i} = 0$ + \item \If $\relBlock_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \blockNumberOfFirstBlockInConflation_{i+1} & = & \blockNumberOfFirstBlockInConflation_{i} \\ + \If \ct_{i} \neq \maxCtBtcData ~ \Then \ct_{i + 1} & = & 1 + \ct_{i} \\ + \If \ct_{i} = \maxCtBtcData ~ \Then \relBlock_{i + 1} & = & 1 + \relBlock_{i} \vspace{2mm} \\ + \end{array} \right. + \] + \item $\ct_{N} = \maxCtBtcData$ +\end{enumerate} diff --git a/block_data/intro.tex b/block_data/intro.tex new file mode 100644 index 0000000..0785fc9 --- /dev/null +++ b/block_data/intro.tex @@ -0,0 +1,14 @@ +The \textbf{block data} module \btcMod{} is a repository for data which relates to the batch of transactions and which may find itself loaded into the stack. As such it serves data to the following instructions: +\begin{multicols}{3} +\begin{enumerate} + %\item \inst{BLOCKHASH} + \item \inst{COINBASE} + \item \inst{TIMESTAMP} + \item \inst{NUMBER} + \item \inst{PREVRANDAO} + \item \inst{GASLIMIT} + \item \inst{CHAINID} +% \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +Along with the \textsc{rom} and the \textsc{transaction data} module it serves as an entry point of outside data into the \zkEvm{}. As such one of its duties is to make sure the data it serves is correctly segmented (i.e. satisfies size constraints.) diff --git a/block_data/lookups/_inputs.tex b/block_data/lookups/_inputs.tex new file mode 100644 index 0000000..46f1371 --- /dev/null +++ b/block_data/lookups/_inputs.tex @@ -0,0 +1,2 @@ +\subsection{Into \wcpMod{}} \label{batch_data: lookups: into_wcp} \input{lookups/btcdata_into_wcp} +\subsection{Into \txnDataMod{}} \label{batch_data: lookups: into_txnDAta} \input{lookups/btcdata_into_txndata} \ No newline at end of file diff --git a/block_data/lookups/btcdata_into_txndata.tex b/block_data/lookups/btcdata_into_txndata.tex new file mode 100644 index 0000000..4b43e8c --- /dev/null +++ b/block_data/lookups/btcdata_into_txndata.tex @@ -0,0 +1,16 @@ +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] none required. + \item[\underline{Source columns:}] --- + \begin{multicols}{1} + \begin{enumerate} + \item $\relBlock$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{1} + \begin{enumerate} + \item $\relBlock$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/block_data/lookups/btcdata_into_wcp.tex b/block_data/lookups/btcdata_into_wcp.tex new file mode 100644 index 0000000..1304358 --- /dev/null +++ b/block_data/lookups/btcdata_into_wcp.tex @@ -0,0 +1,27 @@ +The purpose of the present lookup argument is to delegate the proof of the lexicographic order of the timestamp of the block in a given batch to the \wcpMod{} module. +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] we use $\col{wcp\_selector} \define \wcpFlag$ + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\blockDataHi_{i}$ + \item $\blockDataLo_{i}$ + \item $\blockDataHi_{i - (\maxCtBtcData + 1)}$ + \item $\blockDataLo_{i - (\maxCtBtcData + 1)}$ + \item $1$ + \item $\inst{GT}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/block_data/lua/layout.lua.tex b/block_data/lua/layout.lua.tex new file mode 100644 index 0000000..f19e06a --- /dev/null +++ b/block_data/lua/layout.lua.tex @@ -0,0 +1,74 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + +███████\ ██\ +██ __██\ ██ | +██ | ██ | ██████\ ██████\ ██████\ +██ | ██ | \____██\\_██ _| \____██\ +██ | ██ | ███████ | ██ | ███████ | +██ | ██ |██ __██ | ██ |██\ ██ __██ | +███████ |\███████ | \████ |\███████ | +\_______/ \_______| \____/ \_______| + +██\ ██\ +██ | ██ | +██ | ██████\ ██\ ██\ ██████\ ██\ ██\ ██████\ +██ | \____██\ ██ | ██ |██ __██\ ██ | ██ |\_██ _| +██ | ███████ |██ | ██ |██ / ██ |██ | ██ | ██ | +██ |██ __██ |██ | ██ |██ | ██ |██ | ██ | ██ |██\ +██ |\███████ |\███████ |\██████ |\██████ | \████ | +\__| \_______| \____██ | \______/ \______/ \____/ + ██\ ██ | + \██████ | + \______/ + + +|-------+-----+----------+----+-------------------+----------------+-----------------| +| BTC_∞ | BTC | REL_∞ | CT | INST | BTC_DATA_HI | BTC_DATA_LO | +|:-----:+:---:+:--------:+:--:+:------------------+:--------------:+:---------------:| +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | a | r_∞[b-1] | ⋯ | ⋯ | ⋯ | ⋯ | +|-------+-----+----------+----+-------------------+----------------+-----------------| +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 0 | 0x40 (BLOCKHASH) | 0 | 0 | +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 1 | 0x41 (COINBASE) | COINBASE_HI | COINBASE_HI | +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 2 | 0x42 (TIMESTAMP) | 0 | TIME_STAMP | +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 3 | 0x43 (NUMBER) | 0 | BLOCK_NUMBER | +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 4 | 0x44 (PREVRANDAO) | PREV_RANDAO_HI | PREV_RANDAO_LO | +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 5 | 0x45 (GASLIMIT) | 0 | BLOCK_GAS_LIMIT | +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | b | r_∞[b] | 6 | 0x46 (CHAINID) | 0 | LINEA_CHAIN_ID | +|-------+-----+----------+----+-------------------+----------------+-----------------| +|-------+-----+----------+----+-------------------+----------------+-----------------| +| b_∞ | c | r_∞[b-1] | ⋯ | ⋯ | ⋯ | ⋯ | + +NOTE. The above contains BLOCKHASH which is incorrect. This opcode is dealt with +differently. Atm the design is "spit out the correct (unjustified) result." We could +easily improve on this design (see #382) but for now we will just deal with the opcode +as specified in the design docs. +\end{verbatim} +\end{document} diff --git a/block_data/value_constraint.tex b/block_data/value_constraint.tex new file mode 100644 index 0000000..554eec7 --- /dev/null +++ b/block_data/value_constraint.tex @@ -0,0 +1,64 @@ +\begin{center} + \boxed{\text{In all this section, it is assumed that $\relBlock_{i} \neq \relBlock_{i-1}$.}} +\end{center} +\begin{enumerate} + \item Setting $\inst{COINBASE}$: + \begin{enumerate} + \item $\INST{i + \rowShiftCoinbase} = \inst{COINBASE}$ + \item $\sum_{k = 0}^{\llargeMO-4} \byteCol{HI\_k}_{i + \rowShiftCoinbase} = 0$ + \saNote{} This imposes that $\blockDataHi_{i + \rowShiftCoinbase}$ be a $4$ byte integer, thus the high part of an address. + \item $\blockDataHi _{i + \rowShiftCoinbase} = \coinbase\high_{i}$ + \item $\blockDataLo _{i + \rowShiftCoinbase} = \coinbase\low_{i}$ + \end{enumerate} + \item Setting $\inst{TIMESTAMP}$: + \begin{enumerate}[resume] + \item $\INST{i + \rowShiftTimestamp} = \inst{TIMESTAMP}$ + \item \If $\relBlock_{i} \neq 1$ \Then $\wcpFlag_{i + \rowShiftTimestamp} = 1$ + \end{enumerate} + \saNote{} This imposes a lookup to the \wcpMod{} module, constraining the timestamp to be greater than the previous one. We don't need it for the first block of the batch. + \begin{enumerate}[resume] + \item $\blockDataHi _{i + \rowShiftTimestamp} = 0$ + \item $\sum_{k = 0}^{\llargeMO-6} \byteCol{LO\_k}_{i + \rowShiftTimestamp} = 0$ + \end{enumerate} + \saNote{} + The above imposes that \inst{TIMESTAMP}'s are ``small'' (in the sense that they are 6 byte integers.) + \item Setting $\inst{NUMBER}$: + \begin{enumerate}[resume] + \item $\INST{i + \rowShiftNumber} = \inst{NUMBER}$ + \item $\blockDataHi_{i + \rowShiftNumber} = 0$ + \item $\sum_{k = 0}^{\llargeMO-6} \byteCol{LO\_k}_{i + \rowShiftNumber} = 0$ + \item $\blockDataLo_{i + \rowShiftNumber} = \blockNumberOfFirstBlockInConflation_{i} + \relBlock_{i} - 1$ + \end{enumerate} + \saNote{} + The same remark applies as in the \inst{TIMESTAMP} case. + \item Setting $\inst{DIFFICULTY}$: + \begin{enumerate}[resume] + \item $\INST{i + \rowShiftDifficulty} = \inst{DIFFICULTY}$ + \item $\blockDataHi_{i + \rowShiftDifficulty} = 0$ + \item $\blockDataHi_{i + \rowShiftDifficulty} = \lineaDifficulty$ + \end{enumerate} + \item Setting $\inst{GASLIMIT}$: + \begin{enumerate}[resume] + \item $\INST{i + \rowShiftGaslimit} = \inst{GASLIMIT}$ + \item $\blockDataHi _{i + \rowShiftGaslimit} = 0$ + \item $\blockDataLo _{i + \rowShiftGaslimit} = \lineaBlockGasLimit$ + \item $\blockGasLimit_{i} = \blockDataLo _{i + \rowShiftGaslimit}$ + \end{enumerate} + \item Setting $\inst{CHAINID}$: + \begin{enumerate}[resume] + \item $\INST{i + \rowShiftChainId} = \inst{CHAINID}$ + \item $\blockDataHi_{i + \rowShiftChainId} = 0$ + % \item $\blockDataLo_{i + \rowShiftChainId} = \lineaChainId$ + \end{enumerate} + \item Setting $\inst{BASEFEE}$: + \begin{enumerate}[resume] + \item $\INST{i + \rowShiftBaseFee} = \inst{BASEFEE}$ + \item $\blockDataHi _{i + \rowShiftBaseFee} = 0$ + \item $\blockDataLo _{i + \rowShiftBaseFee} = \lineaBaseFee$ + \item $\basefee_{i} = \blockDataLo _{i + \rowShiftBaseFee}$ + \end{enumerate} +\end{enumerate} +\saNote{} +$\lineaBlockGasLimit{}$, +$\lineaChainId{}$ and +$\lineaBaseFee{}$ are network constants. diff --git a/block_hash/_all_block_hash.tex b/block_hash/_all_block_hash.tex new file mode 100644 index 0000000..2bfe7d3 --- /dev/null +++ b/block_hash/_all_block_hash.tex @@ -0,0 +1,40 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/block_hash} +\usepackage{../pkg/iomf_done} +\usepackage{../pkg/offset_processor} + +\title{\blockHashMod{} module} +\author{Rollup team} +\date{May 2024} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/block_hash/_inputs.tex b/block_hash/_inputs.tex new file mode 100644 index 0000000..946575d --- /dev/null +++ b/block_hash/_inputs.tex @@ -0,0 +1,10 @@ +\section{\blockHashMod{} module} +\subsection{Introduction} \label{block hash: intro} \input{intro} +\subsection{Columns} \label{block hash: columns} \input{columns} + +\section{Constraints} +\subsection{Heartbeat} \label{block hash: heartbeat} \input{heartbeat} +\subsection{Byte Decomposition} \label{block hash: byte decomposition} \input{byte_decomposition} +\subsection{Consistency constraint} \label{block hash: consistency} \input{consistency} + +\section{Lookups} \label{block hash lookups} \input{lookups/_inputs} diff --git a/block_hash/byte_decomposition.tex b/block_hash/byte_decomposition.tex new file mode 100644 index 0000000..754d632 --- /dev/null +++ b/block_hash/byte_decomposition.tex @@ -0,0 +1,21 @@ +We impose bytehood constraints on the following columns +\begin{multicols}{2} +\begin{enumerate} + \item $\byteCol{HI\_k}$, $k = 0, 1, \dots, \llargeMO$ + \item $\byteCol{LO\_k}$, $k = 0, 1, \dots, \llargeMO$ +% \item $\byteCol{$\Delta$}$ +\end{enumerate} +\end{multicols} +\noindent We impose horizontal byte decomposition constraints: +\[ +\left\{ +\begin{array}{lcl} + \blockHash\high_{i} + & \!\!\! = \!\!\! & + \displaystyle \sum_{k = 0}^{\llargeMO} 256^(\llargeMO - k) \cdot \byteCol{HI\_k}_{i} \\ + \blockHash\low_{i} + & \!\!\! = \!\!\! & + \displaystyle \sum_{k = 0}^{\llargeMO} 256^(\llargeMO - k) \cdot \byteCol{LO\_k}_{i} \\ +\end{array} +\right. +\] diff --git a/block_hash/columns.tex b/block_hash/columns.tex new file mode 100644 index 0000000..1e14fb2 --- /dev/null +++ b/block_hash/columns.tex @@ -0,0 +1,24 @@ +\begin{enumerate} + \item \iomf: + monotonous bit column that lights up for non-padding rows; + \item $\blockNumber\high$ and $\blockNumber\low$: + the high and low part of \inst{BLOCKHASH} opcode argument; + \item $\resHi$ and $\resLo$: + The high and low part of \inst{BLOCKHASH} opcode result; + \item \relBlock{}: + the relative block number in a given batch, starts at $1$; + \item \absBlock{}: + the absolute block number; + \item \lowerBoundCheck{}: + bit column that lights up if \blockNumber{} is big enough; + \item \upperBoundCheck{}: + bit column that lights up if \blockNumber{} is small enough; + \item \inRange{}: + bit column that lights up if the input is in the range + $[\![ \, \inst{NUMBER} - \blockHashInstMaxHistory, \inst{NUMBER} - 1 \, ]\!]$ + %\item \blockShift{}: + %is between $1$ and $256$ for well-formed argument of the $\inst{BLOCKHASH}$ opcode; + \item $\blockHash\high$ and $\blockHash\low$: + high and low part of the block hash of the block; + \item $\byteCol{HI\_k}$, and $\byteCol{LO\_k}$, $k = 0, 1, \dots, \llargeMO$: +\end{enumerate} diff --git a/block_hash/consistency.tex b/block_hash/consistency.tex new file mode 100644 index 0000000..7ff0fac --- /dev/null +++ b/block_hash/consistency.tex @@ -0,0 +1,11 @@ +We impose that: +\begin{enumerate} + \item $\inRange_{i} = \lowerBoundCheck_{i} \cdot \upperBoundCheck_{i}$ + \item $\resHi_{i} = \inRange_{i} \cdot \blockHash\high_{i}$ + \item $\resLo_{i} = \inRange_{i} \cdot \blockHash\low_{i}$ + \item \If $\blockNumber\low_{i} = \blockNumber\low_{i-1}$ \Then: + \begin{enumerate} + \item $\blockHash\high_{i} = \blockHash\high_{i-1}$ + \item $\blockHash\low _{i} = \blockHash\low _{i-1}$ + \end{enumerate} +\end{enumerate} diff --git a/block_hash/heartbeat.tex b/block_hash/heartbeat.tex new file mode 100644 index 0000000..d221fd9 --- /dev/null +++ b/block_hash/heartbeat.tex @@ -0,0 +1,15 @@ +The heartbeat is very simple: +\begin{enumerate} + \item $\iomf_{0} = 0$ + \item \If $\iomf_{i} = 0$ \Then: + \begin{enumerate} + \item $\inRange _{i} = 0$ + \item $\blockNumber\high_{i}=0$ + \item $\blockNumber\low_{i}=0$ + \end{enumerate} + \item \If $\iomf_{i} \neq 0$ \Then: + \begin{enumerate} + \item $\iomf _{i} = 1$ + \item $\iomf_{i+1} = \iomf_{i}$ + \end{enumerate} +\end{enumerate} diff --git a/block_hash/intro.tex b/block_hash/intro.tex new file mode 100644 index 0000000..25611e8 --- /dev/null +++ b/block_hash/intro.tex @@ -0,0 +1,6 @@ +The purpose of this module is twofold: +(\emph{a}) it stores the various nontrivial \inst{BLOCKHASH}'es that may be accessed by means of the eponymous opcode in a conflation +(\emph{b}) it determines the result of any invocation of said opcode. +Recall that the \inst{BLOCKHASH} opcode returns (the actual) \inst{BLOCKHASH} if its argument is in the range +$[\![ \, \inst{NUMBER} - \blockHashInstMaxHistory, \inst{NUMBER} - 1 \, ]\!]$ +and $0$ otherwise. diff --git a/block_hash/lookups/_inputs.tex b/block_hash/lookups/_inputs.tex new file mode 100644 index 0000000..93f1e64 --- /dev/null +++ b/block_hash/lookups/_inputs.tex @@ -0,0 +1,4 @@ +\subsection{\blockHashMod{} $\hookrightarrow$ \wcpMod{} module: lower bound of $\blockNumber$} \label{block hash: lookups: wcp: lower bound} \input{lookups/into_wcp_lower_bound} +\subsection{\blockHashMod{} $\hookrightarrow$ \wcpMod{} module: upper bound of $\blockNumber$} \label{block hash: lookups: wcp: upper bound} \input{lookups/into_wcp_upper_bound} +\subsection{\blockHashMod{} $\hookrightarrow$ \wcpMod{} module: lexicographic ordering of $\blockNumber$} \label{block hash: lookups: wcp: lexicographic ordering} \input{lookups/into_wcp_lex_ordering} +\subsection{\blockHashMod{} $\hookrightarrow$ \btcMod{} module: $\blockNumber$ extraction} \label{block hash: lookups: block data: (block)number extraction} \input{lookups/into_block_data} diff --git a/block_hash/lookups/into_block_data.tex b/block_hash/lookups/into_block_data.tex new file mode 100644 index 0000000..c1e00bb --- /dev/null +++ b/block_hash/lookups/into_block_data.tex @@ -0,0 +1,23 @@ +The purpose of the present lookup argument is to extract the true \inst{NUMBER} as defined by the \btcMod{} module. +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] non required: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item \relBlock{}: + \item \absBlock{}: + \item $\iomf \cdot \inst{NUMBER}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item \relBlock{} + \item \blockDataLo{} + \item \INST{} + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +The numerical value of \inst{NUMBER} is \texttt{0x\,43}. diff --git a/block_hash/lookups/into_wcp_lex_ordering.tex b/block_hash/lookups/into_wcp_lex_ordering.tex new file mode 100644 index 0000000..fc4ef7c --- /dev/null +++ b/block_hash/lookups/into_wcp_lex_ordering.tex @@ -0,0 +1,27 @@ +The purpose of the present lookup argument is to delegate the proof of lexicographic ordering of $\blockNumber\low$ to the \wcpMod{} module. +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\iomf$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\blockNumber\high_{i}$ + \item $\blockNumber\low_{i}$ + \item $\blockNumber\high_{i-1}$ + \item $\blockNumber\low_{i-1}$ + \item $1$ + \item $\inst{GEQ}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/block_hash/lookups/into_wcp_lower_bound.tex b/block_hash/lookups/into_wcp_lower_bound.tex new file mode 100644 index 0000000..6fb22d4 --- /dev/null +++ b/block_hash/lookups/into_wcp_lower_bound.tex @@ -0,0 +1,27 @@ +The purpose of the present lookup argument is to delegate the proof of the lower bond of \blockNumber{} to the \wcpMod{} module. +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\iomf$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\blockNumber\high_{i}$ + \item $\blockNumber\low_{i}$ + \item $0$ + \item $\absBlock_{i}-\blockHashInstMaxHistory$ + \item $\lowerBoundCheck_{i}$ + \item $\inst{GEQ}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/block_hash/lookups/into_wcp_upper_bound.tex b/block_hash/lookups/into_wcp_upper_bound.tex new file mode 100644 index 0000000..c949ba8 --- /dev/null +++ b/block_hash/lookups/into_wcp_upper_bound.tex @@ -0,0 +1,27 @@ +The purpose of the present lookup argument is to delegate the proof of the lower bond of \blockNumber{} to the \wcpMod{} module. +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\iomf$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\blockNumber\high_{i}$ + \item $\blockNumber\low_{i}$ + \item $0$ + \item $\absBlock_{i}$ + \item $\upperBoundCheck_{i}$ + \item $\inst{LT}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/bytecodes/bytecode1 b/bytecodes/bytecode1 new file mode 100644 index 0000000..bec5f74 --- /dev/null +++ b/bytecodes/bytecode1 @@ -0,0 +1,24 @@ +{ + "functionDebugData": {}, + "generatedSources": [], + "linkReferences": {}, + "object": "608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100d9565b60405180910390f35b610073600480360381019061006e919061009d565b61007e565b005b60008054905090565b8060008190555050565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea26469706673582212209a159a4f3847890f10bfb87871a61eba91c5dbf5ee3cf6398207e292eee22a1664736f6c63430008070033", + "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH2 0x150 DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x36 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x2E64CEC1 EQ PUSH2 0x3B JUMPI DUP1 PUSH4 0x6057361D EQ PUSH2 0x59 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x43 PUSH2 0x75 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x50 SWAP2 SWAP1 PUSH2 0xD9 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x73 PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 PUSH2 0x6E SWAP2 SWAP1 PUSH2 0x9D JUMP JUMPDEST PUSH2 0x7E JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 POP SWAP1 JUMP JUMPDEST DUP1 PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 CALLDATALOAD SWAP1 POP PUSH2 0x97 DUP2 PUSH2 0x103 JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xB3 JUMPI PUSH2 0xB2 PUSH2 0xFE JUMP JUMPDEST JUMPDEST PUSH1 0x0 PUSH2 0xC1 DUP5 DUP3 DUP6 ADD PUSH2 0x88 JUMP JUMPDEST SWAP2 POP POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH2 0xD3 DUP2 PUSH2 0xF4 JUMP JUMPDEST DUP3 MSTORE POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 ADD SWAP1 POP PUSH2 0xEE PUSH1 0x0 DUP4 ADD DUP5 PUSH2 0xCA JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x10C DUP2 PUSH2 0xF4 JUMP JUMPDEST DUP2 EQ PUSH2 0x117 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 SWAP11 ISZERO SWAP11 0x4F CODESIZE SELFBALANCE DUP10 0xF LT 0xBF 0xB8 PUSH25 0x71A61EBA91C5DBF5EE3CF6398207E292EEE22A1664736F6C63 NUMBER STOP ADDMOD SMOD STOP CALLER ", + "sourceMap": "199:356:0:-:0;;;;;;;;;;;;;;;;;;;" +} + +PUSH1 0x80 +PUSH1 0x40 +MSTORE +CALLVALUE +DUP1 +ISZERO +PUSH2 0x10 +JUMPI +PUSH1 0x0 +DUP1 +REVERT +JUMPDEST +POP +PUSH2 0x150 +DUP1 PUSH2 0x20 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN INVALID PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x4 CALLDATASIZE LT PUSH2 0x36 JUMPI PUSH1 0x0 CALLDATALOAD PUSH1 0xE0 SHR DUP1 PUSH4 0x2E64CEC1 EQ PUSH2 0x3B JUMPI DUP1 PUSH4 0x6057361D EQ PUSH2 0x59 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x43 PUSH2 0x75 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH2 0x50 SWAP2 SWAP1 PUSH2 0xD9 JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST PUSH2 0x73 PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 PUSH2 0x6E SWAP2 SWAP1 PUSH2 0x9D JUMP JUMPDEST PUSH2 0x7E JUMP JUMPDEST STOP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 POP SWAP1 JUMP JUMPDEST DUP1 PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 CALLDATALOAD SWAP1 POP PUSH2 0x97 DUP2 PUSH2 0x103 JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 DUP5 SUB SLT ISZERO PUSH2 0xB3 JUMPI PUSH2 0xB2 PUSH2 0xFE JUMP JUMPDEST JUMPDEST PUSH1 0x0 PUSH2 0xC1 DUP5 DUP3 DUP6 ADD PUSH2 0x88 JUMP JUMPDEST SWAP2 POP POP SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH2 0xD3 DUP2 PUSH2 0xF4 JUMP JUMPDEST DUP3 MSTORE POP POP JUMP JUMPDEST PUSH1 0x0 PUSH1 0x20 DUP3 ADD SWAP1 POP PUSH2 0xEE PUSH1 0x0 DUP4 ADD DUP5 PUSH2 0xCA JUMP JUMPDEST SWAP3 SWAP2 POP POP JUMP JUMPDEST PUSH1 0x0 DUP2 SWAP1 POP SWAP2 SWAP1 POP JUMP JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH2 0x10C DUP2 PUSH2 0xF4 JUMP JUMPDEST DUP2 EQ PUSH2 0x117 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP JUMP INVALID LOG2 PUSH5 0x6970667358 0x22 SLT KECCAK256 SWAP11 ISZERO SWAP11 0x4F CODESIZE SELFBALANCE DUP10 0xF LT 0xBF 0xB8 PUSH25 0x71A61EBA91C5DBF5EE3CF6398207E292EEE22A1664736F6C63 NUMBER STOP ADDMOD SMOD STOP CALLER \ No newline at end of file diff --git a/bytecodes/call gas test (the stipend is refunded).md b/bytecodes/call gas test (the stipend is refunded).md new file mode 100644 index 0000000..1a11583 --- /dev/null +++ b/bytecodes/call gas test (the stipend is refunded).md @@ -0,0 +1,129 @@ +# Tests around CALL's and gas + +In all tests below we provide the current context with `0x01` Wei ("off-camera".) + +## The Gas stipend is recovered by the caller + +We prewarm the target address through an EXTCODEHASH. +The CALL tries to pay `0xff` Wei so the CALL is aborted. +The resulting address still doesn't exist as witnessed by the EXTCODEHASH returning 0. + +```rust +GAS // costs 2 +PUSH1 0xad // costs 3 +EXTCODEHASH // warms 0xad up + // should cost 2600 + // should return 0 (0xad doesn't exist in the state) +PUSH1 0 // return data size +PUSH1 0 // return data offset +PUSH1 0 // call data size +PUSH1 0 // call data offset +PUSH1 0xff // value +PUSH1 0xad // address +PUSH2 0xffff // gas + // total cost = 2 + 3 + 2600 + 7 * 3 = 2626 + // 23626 gas (21000 + 2626) +CALL // 100 (warm access) + 9000 (transfer) + 25000 (new account) + // upfront cost = 34100 + // callee would get gas stipend --- are we reimbursed of 2300 ? costs should then be 31800 + // (a) either 23626 + 34100 = 57726 + // (b) either 23626 + (34100 - 2300) = 55426 + // + // RESULTS: option (b) (as expected :D) +PUSH1 0xad // costs 3 +EXTCODEHASH // 0xad is already warm (for two "reasons") so the cost is 100 + // the output should be 0 still. +``` + +## Same deal but no pre-warming + +Since the CALL tries to pay `0xff` Wei the CALL is aborted. +The target address `0xad` is cold at the time of the CALL. +The resulting address still doesn't exist as witnessed by the EXTCODEHASH returning 0 but is now warm. + +```rust +PUSH1 0 // return data size +PUSH1 0 // return data offset +PUSH1 0 // call data size +PUSH1 0 // call data offset +PUSH1 0xff // value +PUSH1 0xad // address +PUSH2 0xffff // gas + // total cost = 7 * 3 = 21 + // 21021 gas (21000 + 21) +CALL // 2600 (cold access) + 9000 (transfer) + 25000 (new account) + // upfront cost = 36600 + // callee would get gas stipend --- are we reimbursed of 2300 ? costs should then be 34300 + // total cost = 21021 + (36600 - 2300) = 55321 +PUSH1 0xad // costs 3 +EXTCODEHASH // 0xad is already warm (for two "reasons") so the cost is 100 + // the output should be 0 still. +``` + +## The target of a successful (value transfering) CALL now exists as witnessed by its EXTCODEHASH and BALANCE + +The CALL tries to pay `0x01` Wei so the CALL isn't aborted. +We transfer **some** value to a nonexistent account (which thus starts existing.) +The second EXTCODEHASH will thus return `KEC(( ))` (and cost 100 Gas.) + +```rust +GAS // costs 2 +PUSH1 0xad // costs 3 +EXTCODEHASH // warms 0xad up (and should return 0 as 0xad doesn't even exist) + // should cost 2600 +SELFBALANCE // expected: 0xff +PUSH1 0 // return data size +PUSH1 0 // return data offset +PUSH1 0 // call data size +PUSH1 0 // call data offset +PUSH1 0x01 // value +PUSH1 0xad // address +PUSH2 0xffff // gas + // total cost = 2 + 3 + 2600 + 7 * 3 = 2626 + // 23626 gas (21000 + 2626) +CALL // 100 (warm access) + 9000 (transfer) + 25000 (new account) + // upfront cost = 34100 + // callee would get gas stipend --- are we reimbursed of 2300 ? costs should then be 31800 + // total cost = 23626 + (34100 - 2300) = 55426 +SELFBALANCE // expected: 0xfe +PUSH1 0xad // costs 3 +BALANCE // warm so cost is 100 + // the output should be 1 +PUSH1 0xad // costs 3 +EXTCODEHASH // 0xad is already warm (for two "reasons") so the cost is 100 + // the output should be KEC(( )) now (account has nonzero balance of 1 Wei) +``` + +## The target of a successful (value transferring) CALL doesn't exist as witnessed by its EXTCODEHASH and BALANCE + +The CALL tries to pay `0x00` Wei so the CALL isn't aborted. +We transfer **no** value to a nonexistent account (which thus starts existing.) +The second EXTCODEHASH will thus return `KEC(( ))` (and cost 100 Gas.) + +```rust +GAS // costs 2 +PUSH1 0xad // costs 3 +EXTCODEHASH // warms 0xad up (and should return 0 as 0xad doesn't even exist) + // should cost 2600 +SELFBALANCE // expected: 0xff +PUSH1 0 // return data size +PUSH1 0 // return data offset +PUSH1 0 // call data size +PUSH1 0 // call data offset +PUSH1 0 // value +PUSH1 0xad // address +PUSH2 0xffff // gas + // total cost = 2 + 3 + 2600 + 7 * 3 = 2626 + // 23626 gas (21000 + 2626) +CALL // 100 (warm access) + 9000 (transfer) + 25000 (new account) + // upfront cost = 34100 + // callee would get gas stipend --- are we reimbursed of 2300 ? costs should then be 31800 + // total cost = 23626 + (34100 - 2300) = 55426 +SELFBALANCE // expected: 0xff +PUSH1 0xad // costs 3 +BALANCE // warm so cost is 100 + // the output should be 0 +PUSH1 0xad // costs 3 +EXTCODEHASH // 0xad is already warm (for two "reasons") so the cost is 100 + // the output should be 0 (still) +``` diff --git a/bytecodes/ecRecover test b/bytecodes/ecRecover test new file mode 100644 index 0000000..a8fd729 --- /dev/null +++ b/bytecodes/ecRecover test @@ -0,0 +1,88 @@ +================================================================================ +// secp1kn = fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 + +// MSTOREing h +// h = 0x0123456789abcdef to 4th or 5th power IIRC (mod 2**256) +PUSH32 0xad5d179fa1525bc473f4f6d09efdfa875b8c34bd4a6c30aaef2c31b0d2ca22c1 +PUSH1 0x00 +MSTORE + +// MSTOREing v +// requirement: v = 27 or v = 28 +PUSH1 0x1b // v = 27 +PUSH1 0x20 +MSTORE + +// MSTOREing r +// requirement: 0 < r < secp1kn +// PUSH32 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 +PUSH32 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0360000 +PUSH1 0x40 +MSTORE + +// MSTOREing s +// which requirement must hold ? +// 0 < r < secp1kn ? +// 0 < r < (secp1kn/2) + 1 ? +PUSH31 0xfffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 +PUSH1 0x60 +MSTORE + +// memory at this point: +// +// ad5d179fa1525bc473f4f6d09efdfa875b8c34bd4a6c30aaef2c31b0d2ca22c1 <- h +// 000000000000000000000000000000000000000000000000000000000000001b <- v +// fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0360000 <- r +// 00fffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 <- s + +// preparing for the call +PUSH1 0x20 +PUSH1 0x00 +PUSH1 0x80 // 128 bytes +PUSH1 0x00 +PUSH1 0x00 // value +PUSH1 0x01 // address = ecRecover +PUSH3 0xffffff // gas + +CALL +================================================================================ + + + + + + +================================================================================ +// secp1kn = fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 +// +// h = 0x0123456789abcdef to 4th or 5th power IIRC (mod 2**256) +PUSH32 0xad5d179fa1525bc473f4f6d09efdfa875b8c34bd4a6c30aaef2c31b0d2ca22c1 +PUSH1 0x00 +MSTORE + +// v = 27 or 28 +PUSH1 0x1b // v = 27 +PUSH1 0x20 +MSTORE + +// 0 < r < secp1kn +// removed 0x4141 from secp1kn +PUSH32 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0360000 +PUSH1 0x40 +MSTORE + +// 0 < s < secp1kn or 0 < s < 1 + secp1kn/2 ??? +PUSH32 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140 +PUSH1 0x60 +MSTORE + +PUSH1 0x20 +PUSH1 0x00 +PUSH1 0x80 // 128 bytes +PUSH1 0x00 +// +PUSH1 0x00 // value +PUSH1 0x01 // address = ecRecover +PUSH3 0xffffff // gas +CALL +================================================================================ \ No newline at end of file diff --git a/bytecodes/empty account vs empty hash in EXTCODEHASH b/bytecodes/empty account vs empty hash in EXTCODEHASH new file mode 100644 index 0000000..d992334 --- /dev/null +++ b/bytecodes/empty account vs empty hash in EXTCODEHASH @@ -0,0 +1,65 @@ +// SELFBALANCE // self check out +// POP + +PUSH1 0x02 + +// reference address +// currently: SHA2-256 precompile +// precompile doesn't EXIST in the state trie +// precompile doesn't EXIST in the state trie + +DUP1 +BALANCE +DUP2 +EXTCODESIZE +DUP3 +EXTCODEHASH + + +POP // clean up +POP // clean up +POP // clean up + +PUSH1 5 // rds +PUSH1 0 // rdo +PUSH1 0 // cds +PUSH1 0 // cdo +PUSH1 0x0a // value +DUP6 // to = reference address +PUSH2 0xffff // gas +CALL +POP // clean up + +// RETURNDATASIZE +// POP // clean up +// +// SELFBALANCE +// POP // clean up +// +// PUSH1 0x02 +// BALANCE +// POP // clean up + +DUP1 +BALANCE +DUP2 +EXTCODESIZE +DUP3 +EXTCODEHASH + +POP // clean up +POP // clean up +POP // clean up + +// empty account vs empty code + +ADDRESS +EXTCODEHASH // will never return KEC(()) since can only be run if account has *some* code + +ADDRESS +PUSH1 0x01 +ADD +EXTCODEHASH + +POP // clean up +POP // clean up \ No newline at end of file diff --git a/bytecodes/extcodehash_while_deploying b/bytecodes/extcodehash_while_deploying new file mode 100644 index 0000000..93c5367 --- /dev/null +++ b/bytecodes/extcodehash_while_deploying @@ -0,0 +1,48 @@ +**Question:** what should happen if you call `EXTCODEHASH` on yourself while you are deploying ? + +**Answer:** there seems to be a simple answer. By definition `EXTCODEHASH` returns `0` for empty accounts and the codehash of non-empty accounts. When a deployment is under way the new address starts out with a nonce of `1` and its codehash set to `KEC(( ))`. Thus the address is nonempty. `EXTCODEHASH` thus returns the actual codehash, i.e. `KEC(( )) = c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470`. + +We are going to test this on using the following initcode: + +```bash +init code: +========== + +ADDRESS +EXTCODEHASH +PUSH1 0x00 +MSTORE +PUSH1 0x20 +PUSH1 0x00 +REVERT +``` + +- associated bytecode: 0x30 3f 60 00 52 60 20 60 00 fd +- codesize: 10 bytes + +We will run the above. Deployment ends in a `REVERT` and we use `RETURNDATACOPY` to read the return data. + +```bash +code to run: +============ + +PUSH10 0x303f60005260206000fd +PUSH1 0xb0 +SHL +// +PUSH1 0x00 +MSTORE +// +PUSH1 0x0a // size (initcode is 10 bytes) +PUSH1 0x00 // offset +PUSH1 0x00 // value +CREATE +// +RETURNDATASIZE +PUSH1 0x00 +PUSH1 0x00 +RETURNDATACOPY +// +PUSH1 0x00 +MLOAD +``` \ No newline at end of file diff --git a/bytecodes/failed CREATEs and nonces b/bytecodes/failed CREATEs and nonces new file mode 100644 index 0000000..2be276c --- /dev/null +++ b/bytecodes/failed CREATEs and nonces @@ -0,0 +1,18 @@ +PUSH1 0xfe // INVALID opcode +PUSH1 0xf0 // shift by this much +SHL +PUSH1 0 +MSTORE + +// memory: +// 00fe000000000000000000000000000000000000000000000000000000000000 + +PUSH1 0x01 // init code size +PUSH1 0 // offset +PUSH1 0x01 // value +CREATE // -> 43a61f3f4c73ea0d444c5c1c1a8544067a86219b + +PUSH1 0x01 // init code size +PUSH1 0 // offset +PUSH1 0x01 // value +CREATE // -> 3fa89944e11022fc67d12a9d2bf35ebe1164f7ef \ No newline at end of file diff --git a/bytecodes/random b/bytecodes/random new file mode 100644 index 0000000..1011216 --- /dev/null +++ b/bytecodes/random @@ -0,0 +1,70 @@ +PC 1 | PUSH1 32 +PC 2 | CALLDATASIZE +PC 4 | PUSH1 31 +PC 5 | ADD +PC 6 | DIV // | N ] where N = ceil(CDS/32) +PC 8 | PUSH1 0 // | N | 0 ] +PC 9 | JUMPDEST // offset = 0x09 +PC 11 | PUSH 1 // | N | 0 | 1 ] +PC 12 | DUP3 // | N | 0 | 1 | N ] +PC 13 | SUB // | N | 0 | N-1 ] +PC 14 | SWAP2 // | N-1 | 0 | N ] +PC 15 | POP // | N-1 | 0 ] +PC 16 | DUP1 +PC 17 | DUP1 // | N-1 | 0 | 0 | 0 ] +PC 18 | CALLDATALOAD // | N-1 | 0 | 0 | # ] +PC 19 | SWAP1 // | N-1 | 0 | # | 0 ] +PC 20 | MSTORE // | N-1 | 0 ] +PC 22 | PUSH1 32 // | N-1 | 0 | 32 ] +PC 23 | ADD // | N-1 | 32 ] +PC 24 | SWAP1 // | 32 | N-1 ] +PC 25 | DUP1 // | 32 | N-1 | N-1 ] +PC 26 | ISZERO // | 32 | N-1 | is0 ] +PC 28 | PUSH1 J // | 32 | N-1 | is0 | J ] what follows is what happens if N-1 != 0, J = 0x40 +PC 29 | JUMPI // | 32 | N-1 ] +PC 30 | SWAP1 // | N-1 | 32 ] +PC 32 | PUSH1 9 // | N-1 | 32 | 9 ] +PC 33 | JUMP // | N-1 | 32 ] +PC 34 | STOP +... +PC 63 | STOP +PC 64 | JUMPDEST +PC 65 | POP +PC 66 | POP +PC 67 | CALLDATASIZE // size +PC 69 | PUSH1 0 // offset +PC 71 | PUSH1 0 // value +PC 72 | CREATE // deploys the call data as bytecode +------------------------------------ +Randomized type 1 // stack at the end = | address ] +------------------------------------ + | DUP1 // | address | address ] + | PUSH1 (arg1) // | address | address | retSize ] + | PUSH1 (arg2) // | address | address | retSize | retOffset ] + | PUSH1 0 // | address | address | retSize | retOffset | argSize ] + | PUSH1 0 // | address | address | retSize | retOffset | argSize | argOffset ] + | PUSH1 0 // | address | address | retSize | retOffset | argSize | argOffset | value ] + | DUP6 // | address | address | retSize | retOffset | argSize | argOffset | value | address ] + | PUSH2 0xffff // | address | address | retSize | retOffset | argSize | argOffset | value | address | gas ] + | CALL // | address | 1 ] (empty stack) + | POP // +------------------------------------ +Randomized type 1 // stack at the end = | address ] +------------------------------------ + + +The call data will be something like + + | PUSH32 (random crap) + | PUSH1 0 + | MSTORE + | PUSH32 (random crap) + | PUSH1 32 + | MSTORE + ... + | PUSH32 (random crap) + | PUSH1 k x 32 // k = 15 will do + | MSTORE + | PUSH1 (arg3) // size + | PUSH1 (arg4) // offset + | RETURN \ No newline at end of file diff --git a/bytecodes/selfdestruct b/bytecodes/selfdestruct new file mode 100644 index 0000000..d9a4f24 --- /dev/null +++ b/bytecodes/selfdestruct @@ -0,0 +1,71 @@ +code to deploy: +=============== + + PUSH1 0x00 + CALLDATALOAD + SELFDESTUCT + + ==> 0x600035ff + +init code: +========== + + PUSH4 0x600035ff + PUSH1 0xe0 [0xe0 = 8 * 28, 38 = 32 - 4, 4 from PUSH4] + SHL + PUSH1 0x00 + MSTORE [mem = 0x60 00 35 ff 00 00 00 00 ...] + PUSH1 0x04 + PUSH1 0x00 + RETURN + + ==> 0x 63 60 00 35 ff 60 e0 1b 60 00 52 60 04 60 00 f3 + +PUSH16 0x63600035ff60e01b60005260046000f3 +PUSH1 0x80 +SHL +PUSH1 0x00 +MSTORE + +PUSH1 0x10 // init code size +PUSH1 0x00 // init code offset +PUSH1 0x10 // value +CREATE + +DUP1 +BALANCE + +DUP2 +EXTCODEHASH + +DUP3 +EXTCODESIZE + +DUP4 + +PUSH1 0x00 // rds +PUSH1 0x00 // rdo +PUSH1 0x10 // cds +PUSH1 0x00 // cdo +PUSH1 0x10 // value +DUP6 // address +PUSH2 0xffff // gas + +// stack now = | addr | 0 | 0 | 16 | 0 | 16 | addr | 0xffff ] + +CALL + +// stack now = | addr | 1 ] + +POP + +DUP1 +BALANCE + +DUP2 +EXTCODEHASH + +DUP3 +EXTCODESIZE + +Running this on the [evm.codes playground](https://www.evm.codes/playground) produces the following stack \ No newline at end of file diff --git a/bytecodes/selfdestruct_with_empty_beneficiary b/bytecodes/selfdestruct_with_empty_beneficiary new file mode 100644 index 0000000..e431b20 --- /dev/null +++ b/bytecodes/selfdestruct_with_empty_beneficiary @@ -0,0 +1,60 @@ +Deployed code: +============== + +PUSH1 0xad // address +SELFDESTRUCT + +associated bytecode: 0x 60 ad ff +has p := 3 bytes + +Initialization code: +==================== + +PUSH3 0x60adff // PUSH3 = PUSHp +PUSH1 0xe8 // 0xe8 = 256 - 8 * p +SHL +PUSH1 0x00 +MSTORE +PUSH1 0x03 // size +PUSH1 0x00 // offset +RETURN + +associated bytecode: 0x 62 60 ad ff 60 e8 1b 60 00 52 60 03 60 00 f3 + op op op op op op op op +has q := 15 bytes + +Code to run on evm.codes/playground: +==================================== + +PUSH15 0x6260adff60e81b60005260036000f3 // PUSH15 = PUSHq +PUSH1 0x88 // 0x = 256 - 8 * q +SHL +PUSH1 0X00 +MSTORE +PUSH1 0x0f // size, f = 15 = q +PUSH1 0x00 // offset +PUSH1 0x?? // value +CREATE + +PUSH1 0x00 +PUSH1 0x00 +PUSH1 0x00 +PUSH1 0x00 +PUSH1 0x00 // value +DUP6 // address +PUSH2 0xffff // gas +CALL + +PUSH1 0xad // should contain 0x?? Wei +BALANCE +POP + +PUSH1 0xad // should contain 0x?? Wei +EXTCODEHASH +POP + +Conclusion: +=========== + +- running this with zero value (i.e. 0x?? = 0x00) will produce an EXTCODEHASH for the address 0xad equal to 0 +- running this with zero value (i.e. 0x?? = 0x01) will produce an EXTCODEHASH for the address 0xad equal to c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 i.e. KEC(( )) diff --git a/euc/_all_euc.tex b/euc/_all_euc.tex new file mode 100644 index 0000000..7b39eff --- /dev/null +++ b/euc/_all_euc.tex @@ -0,0 +1,36 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/common_shorthands} +\usepackage{../pkg/alu} +\usepackage{../pkg/euc} +\usepackage{../pkg/iomf_done} + + +\title{The Euclidean Division module \eucMod{}} +\author{Rollup team} +\date{January 2024} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/euc/_inputs.tex b/euc/_inputs.tex new file mode 100644 index 0000000..dd49426 --- /dev/null +++ b/euc/_inputs.tex @@ -0,0 +1,11 @@ +\section{Tiny Euclidean Module} +\subsection{Introduction} \label{euc: intro} \input{intro} +\subsection{Columns} \label{euc: columns} \input{columns} + +\section{Constraints} +\subsection{Binary constraints} \label{euc: binary} \input{binary} +\subsection{Counter constancies} \label{euc: counter constancies} \input{constancies} +\subsection{Heartbeat} \label{euc: heartbeat} \input{heartbeat} +\subsection{Byte decompositions, bytehood} \label{euc: byteDec and bytehood} \input{byteDec} +\subsection{Result constraints} \label{euc: result constraints} \input{result} +\subsection{Lookup} \label{euc: lookup} \input{lookup} diff --git a/euc/binary.tex b/euc/binary.tex new file mode 100644 index 0000000..7983425 --- /dev/null +++ b/euc/binary.tex @@ -0,0 +1,9 @@ +We impose binary constraints on the following columns: +\begin{multicols}{2} + \begin{enumerate} + \item $\iomf$ + \item $\done$ \quad (\trash) + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} The \done{} column is binary \textbf{by construction} and there is no need to enforce the above constraint in the constraints. diff --git a/euc/byteDec.tex b/euc/byteDec.tex new file mode 100644 index 0000000..eae9ffd --- /dev/null +++ b/euc/byteDec.tex @@ -0,0 +1,22 @@ +We remind the reader that a pair of columns $(\col{byte}, \col{acc})$ satisfies a byte decomposition constraint with respect to the counter column \ct{} if it satisfies the following constraint system: +\begin{enumerate} + \item $\col{byte}$ is a byte column; + \item \If $\ct_{i} = 0$ \Then $\col{acc}_{i} = \col{byte}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\col{acc}_{i} = 256 \cdot \col{acc}_{i - 1} + \col{byte}_{i}$; +\end{enumerate} +We enforce ``byte accumulation constraints'' for the following pairs of columns: +\begin{multicols}{3} + \begin{enumerate} +% \item \dividendByte{} +% \item \dividend{} + \item \divisorByte{} + \item \divisor{} + \item \quotientByte{} + \item \quotient{} + \item \remainderByte{} + \item \remainder{} + \end{enumerate} +\end{multicols} +\saNote{} +We do not require the byte decomposition of the \dividend{}. +The dividend is connected to the \divisor{}, \quotient{} and \remainder{} by equation~(\ref{euc: result: euclidean division equation}) thereby implicitly enforcing its smallness. diff --git a/euc/columns.tex b/euc/columns.tex new file mode 100644 index 0000000..eca6075 --- /dev/null +++ b/euc/columns.tex @@ -0,0 +1,42 @@ +We list the named columns of the \eucMod{} module. The first few are useful for the (simple) heartbeat. +\begin{enumerate} + \item \iomf: + monotonous bit column that lights up for non-padding rows; + \item \ct: + counter column; + counts continuously from 0 to \maxCt whereupon it resets to 0; + \item \maxCt: + counter-constant column; + indicates the value at which \ct must reset; + \item \done: + bit column that lights up precisely at the last row of all counter-loop; +\end{enumerate} +The following columns contain input values (at rows where $\done_{i}=1$). +\begin{enumerate}[resume] + \item \dividend: + assumed to be less than 8 bytes long + \item \divisor: + assumed to be less than 8 bytes long +\end{enumerate} +The following columns contain output of the computation (at rows where $\done_{i}=1$). +\begin{enumerate}[resume] + \item \quotient: + \item \remainder: + \item \ceiling: + computes the ceiling $\left\lceil \dividend / \divisor \right \rceil$; +\end{enumerate} +\saNote{} The previous columns are actually byte accumulator columns. +Only the value present on the final row of the counter-cycle (characterized by $\done \equiv 1$) can be interpreted as the eponymous \dividend{} / \divisor{} / \quotient{} / \remainder{} of the euclidean division. +Note furthermore that, while \ceiling{} is deduced from \quotient{} and \remainder{}, the only value that is explicitly constrained is its final value along counter-cycles. + +\noindent The following columns contain the bytes that the previous columns accumulate: +\begin{enumerate}[resume] + \item + \divisorByte, + \quotientByte{} and + \remainderByte: + byte columns containing the bytes accumulated by + \divisor, + \quotient{} and + \remainder respectively; +\end{enumerate} diff --git a/euc/constancies.tex b/euc/constancies.tex new file mode 100644 index 0000000..0f1271c --- /dev/null +++ b/euc/constancies.tex @@ -0,0 +1,9 @@ +As usual we declare a column \col{X} to be \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We impose \textbf{counter-constancy} on the following columns: +\begin{enumerate} + \item \ctMax +\end{enumerate} + diff --git a/euc/heartbeat.tex b/euc/heartbeat.tex new file mode 100644 index 0000000..82ef405 --- /dev/null +++ b/euc/heartbeat.tex @@ -0,0 +1,39 @@ +\begin{enumerate} + \item $\iomf_{0} = 0$ + \item \If $\iomf_{i} = 0$ \Then + \begin{enumerate} + \item $\done_{i}=0$ + \item $\ct_{i+1}=0$ + \end{enumerate} + \item \If $\iomf_{i} = 1$ \Then + \begin{enumerate} + \item \label{euc: heartbeat: iomf monotony} $\iomf_{i+1} = 1$ + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then + \begin{enumerate} + \item $\done_{i} = 0$ + \item $\ct_{i + 1} = 1 + \ct_{i}$ + \end{enumerate} + \item \If $\ct_{i} = \maxCt_{i}$ \Then + \begin{enumerate} + \item $\done_{i} = 1$ + \item $\ct_{i + 1} = 0$ + \end{enumerate} + \end{enumerate} +\item \label{euc: heartbeat: ct not 8} $\ct_{i} \neq \mmedium$ + \item \If $\iomf_{N} = 1$ \Then $\done_{N} = 1$ \quad (\trash) +\end{enumerate} +\saNote{} It isn't strictly speaking necessary to enforce that ``\If $\iomf_{N} = 1$ \Then $\done_{N} = 1$.'' +Indeed, if this constraint is omitted the final computation may only be partially performed yet will remain inaccessible to any lookup targeting the \eucMod{} module as such lookups are systematically required to land on rows where $\done \equiv 1$. + +The constraint~(\ref{euc: heartbeat: iomf monotony}) enforces that \iomf{} be monotonous (in the sense of \textbf{nondecreasing}.) +We say that a row with row index $i$ is a +\textbf{non-padding-row} if $\iomf_{i} = 1$ and that it is a +\textbf{padding-row} if $\iomf_{i} = 0$. + +The constraint~(\ref{euc: heartbeat: ct not 8}) on the other hand enforces, in conjunction with the remaining heartbeat constraints and the counter-constancy of \ctMax, that on non-padding-rows one always has: +\[ + \left\{ \begin{array}{l} + 0 \leq \ct \leq \maxCt \\ + \ct < \mmedium \\ + \end{array} \right. +\] diff --git a/euc/intro.tex b/euc/intro.tex new file mode 100644 index 0000000..6f79466 --- /dev/null +++ b/euc/intro.tex @@ -0,0 +1,20 @@ +The \textbf{Tiny Euclidean Division Module} \eucMod{} computes \quotient{}'s and \remainder{}'s of euclidean divisions with tiny inputs, +i.e. where both arguments, +\dividend{} and +\divisor{}, are (at most) 8 byte integers and +\divisor{} is \textbf{nonzero} +\[ + \left\{ \begin{array}{l} + \col{a} = \col{b} \cdot \col{q} + \col{r} \text{ with } 0 \leq \col{r} < \col{b} \vspace{2mm} \\ + + 0 \leq \col{a} < 256 ^ \mmedium \\ + 0 < \col{b} < 256 ^ \mmedium \\ + \end{array} \right. +\] +Such computations may be required by other modules (e.g. the \mmuMod{} module) where it may prove cheaper to offload said computations rather than to perform them \emph{in situ}. +% TODO: \mxpMod{}, \modMod{} + +\saNote{} As already pointed out, the present module is only equipped to deal with divisions where the \divisor{} is \textbf{nonzero}. +This limitation has to be taken into account by modules which defer computations to the present module. +This inability to deal by division by zero stems from the specification of the lookup to the \wcpMod{} module which expects the comparison (\inst{LT}) between the \remainder{} and the \divisor{} to return a result of one, see section~(\ref{euc: lookup}). +% TODO: update description whenever we offload MOD instructions to it ... diff --git a/euc/lookup.tex b/euc/lookup.tex new file mode 100644 index 0000000..dff7bcb --- /dev/null +++ b/euc/lookup.tex @@ -0,0 +1,27 @@ +The purpose of the present lookup argument is to delegate to the \wcpMod{} module the proof of the smallness of \remainder{} compared to \divisor{}. +\begin{description} + \item[\underline{Selector:}] $\done_{i}=1$ + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $0$ + \item $\remainder_{i}$ + \item $0$ + \item $\divisor_{i}$ + \item $1$ + \item $\inst{LT}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\res$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/euc/result.tex b/euc/result.tex new file mode 100644 index 0000000..6eab400 --- /dev/null +++ b/euc/result.tex @@ -0,0 +1,11 @@ +We impose on the last row of the \ct{}-loop: +\begin{enumerate} + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item \label{euc: result: euclidean division equation} $\dividend_{i} = \divisor_{i} \cdot \quotient_{i} + \remainder_{i}$ + \item \If $\remainder_{i}=0$ \Or $\dividend_{i}=0$ \Then $\ceiling_{i} = \quotient_{i}$ + \item \If $\remainder_{i} \neq 0$ \et $\dividend_{i} \neq 0$ \Then $\ceiling_{i} = \quotient_{i}+1$ + \item $\divisor_{i} \neq 0$ \quad (\trash) + \end{enumerate} +\end{enumerate} +The proof of the smallness of $\remainder$ is made through a lookup to WCP module. diff --git a/exp/_all_exp.tex b/exp/_all_exp.tex new file mode 100644 index 0000000..5becf5b --- /dev/null +++ b/exp/_all_exp.tex @@ -0,0 +1,29 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/expansion} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/mmu} +\usepackage{../pkg/exponent} +\usepackage{../pkg/wc3} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/IEEEtrantools} +\usepackage{fontawesome} + +\usepackage{../pkg/draculatheme} + +\title{The \inst{EXP} module} +\author{Rollup team} +\date{September 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/exp/_inputs.tex b/exp/_inputs.tex new file mode 100644 index 0000000..75f4370 --- /dev/null +++ b/exp/_inputs.tex @@ -0,0 +1,20 @@ +\input{../oob/_local} +\input{_local} +\section{Introduction} \label{exp: intro} \input{intro} +\section{Columns} \label{exp: columns} \input{columns/_inputs} +\section{General constraints} \label{exp: general} +\subsection{Shorthands} \label{exp: general: shorthands} \input{shorthands} +\subsection{Binary constraints} \label{exp: general: binary} \input{binary} +\subsection{Flag sum perspectives} \label{exp: general: flag sums} \input{flag_sum} +\subsection{Instruction decoding} \label{exp: general: instruction decoding} \input{decoding} +\subsection{Constancies} \label{exp: general: constancies} \input{constancies} +\subsection{Heartbeat} \label{exp: general: heartbeat} \input{heartbeat} +\subsection{Byte decomposition constraints} \label{exp: general: byte decompositions} \input{byteDec} +\subsection{Bit decomposition constraints} \label{exp: general: bit decompositions} \input{bitDec} +\subsection{Plateau bit constraints} \label{exp: general: plateau bit} \input{plateau} +\subsection{Counting nonzeroness constraints} \label{exp: general: conting nonzeroness} \input{counting_nonzeroness} +\subsection{Most significant byte constraints} \label{exp: general: most significant byte} \input{msb} +\subsection{Word comparisons utilities} \label{exp: general: word comparison utilities} \input{utils} +\section{The $\expInstExpLog$ case} \label{exp: exp log base 256} \input{exp_log/_inputs} +\section{The $\expInstModexpLog$ case} \label{exp: modexp log base 2} \input{modexp_log/_inputs} +\section{Lookups} \label{exp: general: lookups} \input{lookups/_inputs} diff --git a/exp/_local.tex b/exp/_local.tex new file mode 100644 index 0000000..9dc1a41 --- /dev/null +++ b/exp/_local.tex @@ -0,0 +1,47 @@ +\def\hi {\col{\_hi}} +\def\lo {\col{\_lo}} +\def\locRaw {\col{raw\_}} +\def\locExponent {\col{exponent}} +\def\locExponentHi {\locExponent\hi} +\def\locExponentLo {\locExponent\lo} +\def\locExponentLog {\locExponent\col{\_log}} +\def\locDynamicCost {\col{dyn\_cost}} +\def\locExponentHiIsZero {\col{expn\_hi\_is\_zero}} +\def\locExponentLoIsZero {\col{expn\_lo\_is\_zero}} + +\def\locRawByteSize {\col{raw\_byte\_size}} +\def\locRawByteSizeHi {\locRawByteSize\hi} +\def\locRawByteSizeLo {\locRawByteSize\lo} +\def\locByteSize {\col{byte\_size}} +\def\locByteSizeHi {\locByteSize\hi} +\def\locByteSizeLo {\locByteSize\lo} +\def\locCdsCutoff {\col{cds\_cutoff}} +\def\locEbsCutoff {\col{byte\_size}} +\def\locEbsCutoff {\locEbs\col{\_cutoff}} +\def\locRawLeadingWord {\locRaw\col{lead}} +\def\locRawLeadingWordHi {\locRawLeadingWord\hi} +\def\locRawLeadingWordLo {\locRawLeadingWord\lo} +\def\locLeadingWord {\col{lead}} +\def\locTrim {\col{trim}} +\def\locTrimAcc {\col{trim\_acc}} +\def\locNBytesExcludingLeading {\col{nbytes\_excluding\_leading\_byte}} +\def\locExponentByteLength {\col{exponent\_byte\_length}} +\def\locNBitsExcludingLeading {\col{nbits\_of\_leading\_byte\_excluding\_leading\_bit}} +\def\locLeadingWordLog {\locLeadingWord\col{\_log}} +\def\locModexpExponentLog {\col{modexp\_exp\_log}} +\def\locRawBbs {\locRaw\locBbs} +\def\locRawBbsHi {\locRawBbs\hi} +\def\locRawBbsLo {\locRawBbs\lo} +\def\locRawEbs {\locRaw\locEbs} +\def\locRawEbsHi {\locRawEbs\hi} +\def\locRawEbsLo {\locRawEbs\lo} +\def\locRawMbs {\locRaw\locMbs} +\def\locRawMbsHi {\locRawMbs\hi} +\def\locRawMbsLo {\locRawMbs\lo} +\def\locMinCutoff {\col{min\_cutoff}} +\def\locMinCutoffLEQSixteen {\col{min\_cutoff\_leq\_16}} +\def\locEbsCutoffLEQSixteen {\col{ebs\_cutoff\_leq\_16}} +\def\locComp {\col{comp}} +\def\locRawHiIsZero {\col{raw\_hi\_part\_is\_zero}} +\def\locTrivialTrim {\col{trivial\_trim}} +\def\locPaddedLogBaseTwo {\col{padded\_base\_2\_log}} diff --git a/exp/binary.tex b/exp/binary.tex new file mode 100644 index 0000000..7a25e23 --- /dev/null +++ b/exp/binary.tex @@ -0,0 +1,10 @@ +We impose binary constraints on the following columns: +\begin{multicols}{3} + \begin{enumerate} + \item \isExpLog{} + \item \isModexpLog{} + \item $\isComputation$ + \item $\isMacro$ + \item $\isPreprocessing$ + \end{enumerate} +\end{multicols} diff --git a/exp/bitDec.tex b/exp/bitDec.tex new file mode 100644 index 0000000..d8664e2 --- /dev/null +++ b/exp/bitDec.tex @@ -0,0 +1,25 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isModexpLog _{i} = 1 \\ + \isComputation _{i} = 1 \\ + \end{cases}} +\] + +We remind the reader that a pair of columns $(\col{BIT}, \ACC)$ satisfies a +\textbf{bit decomposition constraint} with respect to the counter column \ct{} if it satisfies the following: +\begin{enumerate} + \item $\col{BIT}$ contains only bits; + \item \If $\ct_{i} = 0$ \Then $\ACC_{i} = \col{BIT}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\ACC_{i} = 2 \cdot \ACC_{i - 1} + \col{BIT}_{i}$; +\end{enumerate} +We will impose bit decomposition constraints for the following pairs of columns: +\begin{multicols}{2} + \begin{enumerate} + \item $\compMsbBit$ + \item $\compMsbAcc$ + \end{enumerate} +\end{multicols} + +%\saNote{} We do not yet specify the ``target'' values that these accumulation constraints aim for. +%This will happen in the relevant ``linking'' constraints below, and is \expMod{}-instruction dependent. diff --git a/exp/byteDec.tex b/exp/byteDec.tex new file mode 100644 index 0000000..a73ba83 --- /dev/null +++ b/exp/byteDec.tex @@ -0,0 +1,21 @@ +\[ + \boxed{\text{All constraints in this subsection assume } \isComputation _{i} = 1.} +\] +We remind the reader that a pair of columns $(\BYTE, \ACC)$ satisfies a +\textbf{byte decomposition constraint} with respect to the counter column \ct{} if it satisfies the following: +\begin{enumerate} + \item $\BYTE$ contains only bytes; + \item \If $\ct_{i} = 0$ \Then $\ACC_{i} = \BYTE_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\ACC_{i} = 256 \cdot \ACC_{i - 1} + \BYTE_{i}$; +\end{enumerate} +We will impose byte decomposition constraints for the following pairs of columns: +\begin{multicols}{2} + \begin{enumerate} + \item \compRawByte + \item \compRawAcc + \item \compTrimByte + \item \compTrimAcc + \end{enumerate} +\end{multicols} +\saNote{} We do not yet specify the ``target'' values that these accumulation constraints aim for. +This will happen in the relevant ``linking'' constraints below, and is \expMod{}-instruction dependent. diff --git a/exp/columns/_inputs.tex b/exp/columns/_inputs.tex new file mode 100644 index 0000000..882fa11 --- /dev/null +++ b/exp/columns/_inputs.tex @@ -0,0 +1,4 @@ +\subsection{Shared columns} \label{exp: columns: Shared} \input{columns/shared} +\subsection{Computation columns} \label{exp: columns: Computation} \input{columns/computation} +\subsection{Macro instruction columns} \label{exp: columns: Macro} \input{columns/macro} +\subsection{Preprocessing columns} \label{exp: columns: Preprocessing} \input{columns/preprocessing} diff --git a/exp/columns/computation.tex b/exp/columns/computation.tex new file mode 100644 index 0000000..435ac8b --- /dev/null +++ b/exp/columns/computation.tex @@ -0,0 +1,20 @@ +\begin{enumerate}[resume] + \item $\compPlateauBit$ and $\compPlateauJmp$: + binary ``plateau bit'' column and its associated computation-constant ``jump value'' column; + \item $\compRawByte$ and $\compRawAcc$: + byte column, containing the bytes of either $\locRawLeadingWordHi$ or $\locRawLeadingWordLo$ based on the value of \locMinCutoff{}, and the associated ``accumulator'' column; + \item $\compTrimByte$ and $\compTrimAcc$: + byte column, containing the ``trimmed'' bytes of some limb, and its associated ``accumulator'' column; + \item $\compTanzb$ and $\compTanzbAcc$ + binary column which turns on \emph{iff} \compTrimAcc{} is nonzero and its associated ``accumulator'' column; +\end{enumerate} +The acronym ``\col{TANZB}'' stands for ``\textbf{t}rimmed \textbf{a}ccumulator \textbf{n}on\textbf{z}eroness \textbf{b}it.'' +\begin{enumerate}[resume] + \item $\compMsb$: + the most significant byte of $\locTrim$; + \item $\compMsbBit$ and $\compMsbAcc$: + bit column, containing the bits of the most significant byte of $\locTrim$, and the associated ``accumulator'' column; + \item $\compManzb$ and $\compManzbAcc$ + binary column which turns on \emph{iff} $\compMsbAcc$ is nonzero and its associated ``accumulator'' column; +\end{enumerate} +The acronym ``\col{MANZB}'' stands for ``\textbf{m}ost significant byte \textbf{a}ccumulator \textbf{n}on\textbf{z}eroness \textbf{b}it.'' diff --git a/exp/columns/macro.tex b/exp/columns/macro.tex new file mode 100644 index 0000000..b522152 --- /dev/null +++ b/exp/columns/macro.tex @@ -0,0 +1,6 @@ +\begin{enumerate}[resume] + \item \expMacroInst{}: \godGiven{} + \expMod{}-specific instruction column; + \item \expMacroData{k}, for $k = 1,\dots, 5$: \godGiven{} + incoming data columns; +\end{enumerate} diff --git a/exp/columns/preprocessing.tex b/exp/columns/preprocessing.tex new file mode 100644 index 0000000..66c1be7 --- /dev/null +++ b/exp/columns/preprocessing.tex @@ -0,0 +1,14 @@ +The following columns are used for pre-processing purposes, specifically pertain to word comparison operations.. +\begin{enumerate}[resume] + \item \ppWcpFlag: + binary column; + lights up precisely on those pre-processing-rows that require the \wcpMod{} to perform a comparison; + \item \ppWcpArgOneHi{} and \ppWcpArgOneLo{}: + high and low parts of the first argument to send to the \wcpMod{} module; + \item \ppWcpArgTwoHi{} and \ppWcpArgTwoLo{}: + high and low parts of the second argument to send to the \wcpMod; + \item \ppWcpRes: + result of the instruction (0 or 1); + \item \ppWcpInst: + may contain a \wcpMod{} instruction, e.g. \inst{LT}, \inst{EQ} or \inst{ISZERO}; +\end{enumerate} diff --git a/exp/columns/shared.tex b/exp/columns/shared.tex new file mode 100644 index 0000000..f8fdc4d --- /dev/null +++ b/exp/columns/shared.tex @@ -0,0 +1,27 @@ +\begin{enumerate} + \item $\isComputation$: + binary column; + \expComputationSymbol{} stands for ``computation''; + \item $\isMacro$: + binary column; + \expMacroSymbol{} stands for ``macro-instruction''; + \item $\isPreprocessing$: + binary column; + \expPreprocessingSymbol{} stands for ``preprocessing'' + \item $\expStamp$: + module stamp; + \item $\ct$: counter column; + \item $\maxCt$: containing the maximum value of the counter column; + \item \isExpLog{} and \isModexpLog{}: + exclusive binary colunmns; +\end{enumerate} + +We say that a row $i$ with +$\expStamp_{i} = 0$ is a \textbf{padding-row} and that +$\expStamp_{i} \neq 0$ is a \textbf{non-padding-row}. +We say that a row $i$ with $\isComputation_{i} = 1$ is a \textbf{computation-row}, +that a row $i$ with $\isMacro_{i} = 1$ is a \textbf{macro-instruction-row} +and that a row $i$ with $\isPreprocessing_{i} = 1$ is a \textbf{preprocessing-row}. +% Computation rows are used to execute certain computations. +% Macro-instruction rows receive ``macro-instructions'' from the \hubMod{}. +% Preprocessing-rows carry out certain comparisons that are required to ... diff --git a/exp/constancies.tex b/exp/constancies.tex new file mode 100644 index 0000000..c034bef --- /dev/null +++ b/exp/constancies.tex @@ -0,0 +1,40 @@ +We define the usual notion of \textbf{stamp-constancy}. A column $\col{X}$ is \textbf{stamp-constant} if it satisfies +\[ + \If \expStamp_{i} \neq 1 + \expStamp_{i - 1} ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose stamp-constancy on the following columns: +\begin{multicols}{2} + \begin{enumerate} + \item \isExpLog{} + \item \isModexpLog{} + \end{enumerate} +\end{multicols} +\saNote{} In the implementation it is sufficient to impose the stamp-constancy of $\isExpLog{} + 2 \cdot \isModexpLog$. + +\noindent We define the usual notion of \textbf{counter-constancy}. A column $\col{X}$ is \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +\begin{multicols}{3} + \begin{enumerate} + \item $\isComputation$ + \item $\isMacro$ + \item $\isPreprocessing$ + \end{enumerate} +\end{multicols} +\saNote{} The constancies presented above enforce counter-constancy of \maxCt{}. + +\saNote{} In the implementation it is sufficient to impose the stamp-constancy of $\isComputation + 2 \cdot \isMacro + 4 \cdot \isPreprocessing$. + +\noindent We define a column \col{X} to be \textbf{computation-constancy} if it satisfies the following: +\[ + \If \Big( \isComputation_{i} = 1 \et ~ \isComputation_{i - 1} = 1\Big) ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose that the following columns be computation-constant: +\begin{multicols}{3} + \begin{enumerate} + \item $\compPlateauJmp$ + \item $\compMsb$ + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/exp/counting_nonzeroness.tex b/exp/counting_nonzeroness.tex new file mode 100644 index 0000000..0c55b20 --- /dev/null +++ b/exp/counting_nonzeroness.tex @@ -0,0 +1,40 @@ +\[ + \boxed{\text{All constraints in this subsection assume } \isComputation _{i} = 1.} +\] +\begin{enumerate} + \item we filter the raw bytes using the \compPlateauBit{} column: + \[ \compTrimByte_{i} = \compRawByte_{i} \cdot (1 - \compPlateauBit_{i}) \] + \item we impose + \[ + \left\{ \begin{array}{l} + \If \compTrimAcc_{i} = 0 ~ \Then \compTanzb_{i} = 0 \\ + \If \compTrimAcc_{i} \neq 0 ~ \Then \compTanzb_{i} = 1 \\ + \end{array} \right. + \] + \item we impose + \[ + \left\{ \begin{array}{l} + \If \compMsbAcc_{i} = 0 ~ \Then \compManzb_{i} = 0 \\ + \If \compMsbAcc_{i} \neq 0 ~ \Then \compManzb_{i} = 1 \\ + \end{array} \right. + \] +\end{enumerate} +We further impose ``counting'' constraints for the pair $(\compTanzb, \compTanzbAcc)$: +\begin{enumerate}[resume] + \item \If $\ct_{i} = 0$ \Then $\compTanzbAcc_{i} = \compTanzb_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\compTanzbAcc_{i} = \compTanzbAcc_{i - 1} + \compTanzb_{i}$; +\end{enumerate} +Moreover we impose ``counting'' constraints for the pair $(\compManzb, \compManzbAcc)$: +\begin{enumerate}[resume] + \item \If $\ct_{i} = 0$ \Then $\compManzbAcc_{i} = \compManzb_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\compManzbAcc_{i} = \compManzbAcc_{i - 1} + \compManzb_{i}$; +\end{enumerate} +\saNote{} +In the \expInstModexpLog{} case +\compManzbAcc{} targets the $\lfloor \log_{2} (\cdots) \rfloor$ of the leading byte and +\compTanzbAcc{} targets the $\lfloor \log_{256} (\cdots) \rfloor$ of the leading word of the exponent. + +\saNote{} +In the \expInstExpLog{} case +\compManzbAcc{} is irrelevant and +\compTanzbAcc{} targets the $\lfloor \log_{256} (\cdots) \rfloor$ of the exponent. diff --git a/exp/decoding.tex b/exp/decoding.tex new file mode 100644 index 0000000..a18af1e --- /dev/null +++ b/exp/decoding.tex @@ -0,0 +1,13 @@ +We impose the following: +\begin{enumerate} + \item $\flagSumMacro$ is binary \quad (\trash) + \item \If $\expStamp_{i} = 0$ \Then $\flagSumMacro_{i} = 0$ + \item \If $\expStamp_{i} \neq 0$ \Then $\flagSumMacro_{i} = 1$ + \item Furthermore + \[ + \expMacroInst_{i} = \weightedFlagSumMacro_{i} + \] +\end{enumerate} +\saNote{} The above enforces that \isExpLog{} and \isModexpLog{} are mutually exclusive binary columns. + + diff --git a/exp/exp_log/_inputs.tex b/exp/exp_log/_inputs.tex new file mode 100644 index 0000000..a144bd2 --- /dev/null +++ b/exp/exp_log/_inputs.tex @@ -0,0 +1,5 @@ +\subsection{Introduction} \label{exp: exp log: intro} \input{exp_log/intro} +\subsection{Shorthands} \label{exp: exp log: shorthands} \input{exp_log/shorthands} +\subsection{Preprocessing} \label{exp: exp log: preprocessing} \input{exp_log/preprocessing} +\subsection{Linking constraints} \label{exp: exp log: linking} \input{exp_log/linking} +\subsection{Justification of the $\hubMod$ prediction} \input{exp_log/justification.tex} diff --git a/exp/exp_log/intro.tex b/exp/exp_log/intro.tex new file mode 100644 index 0000000..86ee8e8 --- /dev/null +++ b/exp/exp_log/intro.tex @@ -0,0 +1,18 @@ +The present section deals with the $\expInstExpLog$ instruction. +Its purpose is as follows. +One is given the following data: +(\emph{a}) an \evm{} word \locExponent{} split into high and low parts, \locExponentHi{} and \locExponentLo{} respectively; +one is tasked with computing (an approximation to) its $\log_{256}$ as defined below +\begin{IEEEeqnarray*}{LCL} + \locExponentLog & \equiv & + \left\{ \begin{array}{ll} + 0 & \If \exponent = 0 \\ + 1 + \lfloor \log_{256}(\exponent) \rfloor & \If \exponent \neq 0 \\ + \end{array} \right. \\ + & \equiv & + \left\{ \begin{array}{ll} + 0 & \If \big(\ehi = 0 ~ \et \elo = 0\big) \\ + 1 + \lfloor \log_{256}(\elo) \rfloor & \If \big(\ehi = 0 ~ \et \elo \neq 0\big) \\ + 1 + \lfloor \log_{256}(\ehi) \rfloor + \llarge & \If \ehi \neq 0 \\ + \end{array} \right. \\ +\end{IEEEeqnarray*} diff --git a/exp/exp_log/justification.tex b/exp/exp_log/justification.tex new file mode 100644 index 0000000..0af36a5 --- /dev/null +++ b/exp/exp_log/justification.tex @@ -0,0 +1,15 @@ +We also justify the dynamic gas cost \hubMod{} module prediction for the \inst{EXP} opcode: +\begin{enumerate}[resume] + \item \If $\locExponentHiIsZero = 0$ \Then + \[ + \locDynamicCost + = + G_\text{expbytes} \cdot \big( \locExponentByteLength + \llarge \big) + \] + \item \If $\locExponentHiIsZero = 1$ \Then + \[ + \locDynamicCost + = + G_\text{expbytes} \cdot \locExponentByteLength + \] +\end{enumerate} diff --git a/exp/exp_log/linking.tex b/exp/exp_log/linking.tex new file mode 100644 index 0000000..fc04e81 --- /dev/null +++ b/exp/exp_log/linking.tex @@ -0,0 +1,13 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isExpLog _{i} = 1 \\ + \isMacro _{i} = 1 \\ + \end{cases}} +\] +We are now in position to enforce some constraints which connect the preprocessing to the computation: +\begin{enumerate} + \item we require $\compPlateauJmp_{i - 1} = \llarge$ + \item \If $\locExponentHiIsZero = 1$ \Then $\compRawAcc_{i - 1} = \locExponentLo$ + \item \If $\locExponentHiIsZero = 0$ \Then $\compRawAcc_{i - 1} = \locExponentHi$ +\end{enumerate} \ No newline at end of file diff --git a/exp/exp_log/preprocessing.tex b/exp/exp_log/preprocessing.tex new file mode 100644 index 0000000..b4f382a --- /dev/null +++ b/exp/exp_log/preprocessing.tex @@ -0,0 +1,19 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isExpLog _{i} = 1 \\ + \isMacro _{i} = 1 \\ + \end{cases}} +\] +We deal with the preprocessing required by the $\expInstModexpLog$ instruction. +\begin{description} + \def\rowNum{1} \item[Preprocessing row $n^\circ (i + \rowNum)$:] + we impose + \[ + \callToIszero + {i}{\rowNum} + {0}{$\locExponentHi$} + \] + we define the shorthand $\locExponentHiIsZero \define \ppWcpRes_{i + \rowNum}$ and +\end{description} + diff --git a/exp/exp_log/shorthands.tex b/exp/exp_log/shorthands.tex new file mode 100644 index 0000000..6c3d94e --- /dev/null +++ b/exp/exp_log/shorthands.tex @@ -0,0 +1,26 @@ +% TODO: split into different files +\[ + \boxed{\text{All shorthands introduced in this subsection should only be used given that } + \begin{cases} + \isExpLog _{i} = 1 \\ + \isMacro _{i} = 1 \\ + \end{cases}} +\] +\noindent We use the shorthands defined below: +\[ + \left\{ \begin{array}{lcl} + \locExponentHi & \define & \expMacroData {1} _{i} \\ + \locExponentLo & \define & \expMacroData {2} _{i} \\ + \locDynamicCost & \define & \expMacroData {5} _{i} \\ + \locExponentByteLength & \define & \compTanzbAcc _{i - 1} \\ + \end{array} \right. +\] + +We represent the desired data lay out in the table below: + +\[ + % \hspace*{-1.5cm} + \input{vision/_start} \\ \hline \hline + \input{vision/exp_log} \\ \hline + \end{array} +\] diff --git a/exp/flag_sum.tex b/exp/flag_sum.tex new file mode 100644 index 0000000..f0b517e --- /dev/null +++ b/exp/flag_sum.tex @@ -0,0 +1,12 @@ +We impose the following: +\begin{enumerate} + \item $\flagSumPerspective$ is binary \quad (\trash) + \item \If $\expStamp_{i} = 0$ \Then $\flagSumPerspective_{i} = 0$ + \item \If $\expStamp_{i} \neq 0$ \Then $\flagSumPerspective_{i} = 1$ +\end{enumerate} +The above thus enforces that +$\isComputation$, +$\isMacro$ and +$\isPreprocessing$ +are indeed exclusive binary columns. +It also enforces that every non-padding-row is part of precisely one of these perspectives. diff --git a/exp/heartbeat.tex b/exp/heartbeat.tex new file mode 100644 index 0000000..341bf3d --- /dev/null +++ b/exp/heartbeat.tex @@ -0,0 +1,53 @@ +\begin{enumerate} + \item $\expStamp_{0} = 0$; + \item \If $\expStamp_{i} = 0$ \Then $\ct_{i} = 0$ + \item $\expStamp_{i + 1} = \expStamp_{i} + \isComputation_{i + 1} \cdot (1 - \isComputation_{i})$ + \item $\maxCt_{i} = \maxCtFlagSum_{i}$. + % \item \If + % \[ + % \left[ \begin{array}{lrcl} + % + & \isComputation_{i + 1} & \!\!\! \cdot \!\!\! & (1 - \isComputation_{i}) \\ + % + & \isMacro_{i + 1} & \!\!\! \cdot \!\!\! & (1 - \isMacro_{i}) \\ + % + & \isPreprocessing_{i + 1} & \!\!\! \cdot \!\!\! & (1 - \isPreprocessing_{i}) \\ + % \end{array} \right] + % \neq 0 + % \] + % \Then $\ct_{i + 1} = 0$ \quad(\trash); + \item we unconditionally impose + \[ + \left[ \begin{array}{lrcl} + + & \isComputation_{i} & \!\!\! \cdot \!\!\! & \isPreprocessing_{i + 1} \\ + + & \isMacro_{i} & \!\!\! \cdot \!\!\! & (\isMacro_{i + 1} + \isComputation _{i + 1}) \\ + + & \isPreprocessing_{i} & \!\!\! \cdot \!\!\! & \isMacro _{i + 1} \\ + \end{array} \right] + = 0 + \] + to define the unallowed perspective transitions. +\end{enumerate} +\saNote{} The above enforces implicitly that the ``$\isMacro$'' phase may only last one row. +\begin{enumerate}[resume] + \item We also impose + + \If \Big($\expStamp_{i} \neq 0$ \et $\ct_{i} = \maxCt_{i}$\Big) \Then + \[ + \left[ \begin{array}{lrcl} + + & \isComputation_{i} & \!\!\! \cdot \!\!\! & \isMacro _{i + 1} \\ + + & \isMacro_{i} & \!\!\! \cdot \!\!\! & \isPreprocessing _{i + 1} \\ + + & \isPreprocessing_{i} & \!\!\! \cdot \!\!\! & \isComputation _{i + 1} \\ + \end{array} \right] + = 1. + \] + to define the allowed perspective transitions. + \item we specify how the counter evolves: + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then $\ct_{i + 1} = 0$ + \end{enumerate} +\end{enumerate} +\saNote{} The constraint imposes the vanishing of the next counter whenever the counter reaches its maximum value is mostly redundant with the previous constraints. +Note that this constraint is also active on the final padding-row i.e. at the transition point from padding-rows to non-padding-rows (since $\expStamp_{i} = \ct_{i} = \maxCt_{i} = \maxCtFlagSum_{i} = 0$). + +% \saNote{} The heartbeat imposes in particular that if $\expStamp_{i} = 0$ the exponent is zero as is the dynamic cost. This is compatible with \inst{EXP}'s dynamic pricing model. + +\saNote{} The above implies that $\expStamp$ is nondecreasing in the sense that $\expStamp_{i + 1} \in \{ \expStamp_{i}, 1 + \expStamp_{i} \}$. + diff --git a/exp/intro.tex b/exp/intro.tex new file mode 100644 index 0000000..b3d8717 --- /dev/null +++ b/exp/intro.tex @@ -0,0 +1,42 @@ +The \expMod{} module is a tiny module which carries out several computations required either by the \inst{EXP} opcode or the \inst{MODEXP} precompile. +Despite its name it carries out neither the \inst{EXP} instruction nor the modular exponentiation of \inst{MODEXP}. +Most of what it does is actually somewhat the polar opposite of computing an exponentiation, i.e. computing logs. +We give a brief overview of the computations carried out in the present module. +\begin{description} + \item[Dynamic gas cost of \inst{EXP} opcode:] + recall the definition of the (dynamic) cost of \inst{EXP} instructions with exponent $\exponent \in \mathbb{B}_{\evmWordSize}$ (i.e. $(\ehi, \elo)$ in terms of its high and low parts): + \[ + \locDynamicCost \equiv G_\text{expbyte} \cdot \col{size\_in\_bytes} + \] + the present module is tasked with computing this quantity; + the main task is thus to compute \col{size\_in\_bytes} as defined by + \begin{IEEEeqnarray*}{LCL} + \col{size\_in\_bytes} + & \equiv & + \left\{ \begin{array}{ll} + 0 & \If \exponent = 0 \\ + 1 + \lfloor \log_{256}(\exponent) \rfloor & \If \exponent \neq 0 \\ + \end{array} \right. \\ + & \equiv & + \left\{ \begin{array}{ll} + 0 & \If \big(\ehi = 0 ~ \et \elo = 0\big) \\ + 1 + \lfloor \log_{256}(\elo) \rfloor & \If \big(\ehi = 0 ~ \et \elo \neq 0\big) \\ + 1 + \lfloor \log_{256}(\ehi) \rfloor + \llarge & \If \ehi \neq 0 \\ + \end{array} \right. \\ + \end{IEEEeqnarray*} +\end{description} +\saNote{} Recall that $G_{\text{expbyte}} = 50$. + +\saNote{} The above \textbf{deliberately doesn't include} the static cost $G_\text{exp} = 10$. +\begin{description} + \item[Base $2$ log of leading word of exponent for \inst{MODEXP}:] + still for \inst{MODEXP} pricing requires one to compute $\locExponentLogEYP = \lfloor \log_{2}(\col{lead}) \rfloor$ of the leading word of the exponent; + one is initially provided with a raw \evm{} word $\col{raw\_lead} \in \mathbb{B}_{32}$ and two cutoff parameters: + \locEbsCutoff{} and \locCdsCutoff{}; + both are in the range $[\![ 1, 32 ]\!]$; + one must then compute the (rounded up) $\log_{2}$ of the word of size \locEbsCutoff{} extracted from \col{raw\_lead} by considering only the first \locCdsCutoff{} bytes of \col{raw\_lead} and setting to \utt{00} all bytes of the resulting word with index $\geq \locCdsCutoff{}$; +\end{description} + +\input{vision/_table} + +We then define $\locMinCutoff \define \min{(\locCdsCutoff,\locEbsCutoff)}$. diff --git a/exp/lookups/_inputs.tex b/exp/lookups/_inputs.tex new file mode 100644 index 0000000..e83e048 --- /dev/null +++ b/exp/lookups/_inputs.tex @@ -0,0 +1,2 @@ +\subsection{Lookup to the \wcpMod{} module} \label{exp: lookups: wcp} \input{lookups/wcp} + diff --git a/exp/lookups/wcp.tex b/exp/lookups/wcp.tex new file mode 100644 index 0000000..be4d59a --- /dev/null +++ b/exp/lookups/wcp.tex @@ -0,0 +1,26 @@ +The lookup to the $\wcpMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] \ppWcpFlag{} + \item[\underline{Source columns:}] from the \expMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item \ppWcpArgOneHi{} + \item \ppWcpArgOneLo{} + \item \ppWcpArgTwoHi{} + \item \ppWcpArgTwoLo{} + \item \ppWcpRes{} + \item \ppWcpInst{} + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \wcpMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/exp/modexp_log/_inputs.tex b/exp/modexp_log/_inputs.tex new file mode 100644 index 0000000..5821b11 --- /dev/null +++ b/exp/modexp_log/_inputs.tex @@ -0,0 +1,5 @@ +\subsection{Introduction} \label{exp: modexp log: intro} \input{modexp_log/intro} +\subsection{Shorthands} \label{exp: modexp log: shorthands} \input{modexp_log/shorthands} +\subsection{Preprocessing} \label{exp: modexp log: preprocessing} \input{modexp_log/preprocessing} +\subsection{Linking constraints} \label{exp: modexp log: constraints} \input{modexp_log/linking} +\subsection{Justification of the $\hubMod$ prediction} \input{modexp_log/justification.tex} diff --git a/exp/modexp_log/intro.tex b/exp/modexp_log/intro.tex new file mode 100644 index 0000000..3890432 --- /dev/null +++ b/exp/modexp_log/intro.tex @@ -0,0 +1,30 @@ +The present section deals with the $\expInstModexpLog$ instruction. +Its purpose is as follows. +One is given the following data: +(\emph{a}) an \evm{} word $\locRawLeadingWord \in \mathbb{B}_{32}$ split into high and low parts, \locRawLeadingWordHi{} and \locRawLeadingWordLo{} respectively +(\emph{b}) two integers $\locCdsCutoff$ and $\locEbsCutoff$ which are guaranteed to be in the range $[\![ 1, 32\, ]\!]$ +one is tasked with computing $\lfloor \log_{2}(\locLeadingWord) \rfloor$ where we define $\locLeadingWord$ using the following slice of bytes: +\[ + \left\{ \begin{array}{l} + \locLeadingWord \in \mathbb{B}_{\locEbsCutoff} \\ + \locLeadingWord[i] = + \begin{cases} + \If i < \locCdsCutoff: & \locRawLeadingWord[i] \\ + \If i \geq \locCdsCutoff: & 0 \\ + \end{cases} + \end{array} \right. + \quad\text{and}\quad + \begin{cases} + \locTrim \in \mathbb{B}_{\evmWordSize} \\ + \locTrim[i] = + \begin{cases} + \If i < \locEbsCutoff: & \locLeadingWord[i] \\ + \If i \geq \locEbsCutoff: & 0 \\ + \end{cases} + \end{cases} +\] +using the standard convention that $\log_{2}(0) = 0$ and where we use the notation $\col{B}[i]$ to access the $i$-th byte of a slice of bytes $\col{B}\in\mathbb{B}^*$. + +\saNote{} There are two different cutoff: \locEbsCutoff{} and \locCdsCutoff{}. The present module will have to compare the two. + +\saNote{} The value which we are building with \compTrimAcc{} targets a $\llarge$-byte integer which is either the high or the low part of \locTrim{} depending on context. diff --git a/exp/modexp_log/justification.tex b/exp/modexp_log/justification.tex new file mode 100644 index 0000000..b15aeca --- /dev/null +++ b/exp/modexp_log/justification.tex @@ -0,0 +1,59 @@ +We now go on to justify the \hubMod{} module prediction of \locLeadingWordLog{}. +\begin{enumerate} + \item \If $\locTrivialTrim = 1$ \Then + \begin{enumerate} + \item \If $\locRawHiIsZero = 1$ \Then $ \locLeadingWordLog = 0 $ + \item \If $\locRawHiIsZero = 0$ \Then + \begin{enumerate} + \item \If $\locEbsCutoffLEQSixteen = 1$ \Then + $ \locLeadingWordLog = 0 $\footnote{and $\locTrim$ is extracted from $\locRawLeadingWordHi$} + \item \If $\locEbsCutoffLEQSixteen = 0$ \Then + $ \locLeadingWordLog = 8 \cdot (\locEbsCutoff - \llarge) $\footnote{and $\locTrim$ is extracted from $\locRawLeadingWordHi$} + \end{enumerate} + \end{enumerate} + \item \If $\locTrivialTrim = 0$ \Then + \begin{enumerate} + \item \If $\locEbsCutoffLEQSixteen = 1$ \Then + \[ \locLeadingWordLog = \locPaddedLogBaseTwo - 8 \cdot (\llarge - \locEbsCutoff)\footnote{and $\locTrim$ is extracted from $\locRawLeadingWordHi$} \] + \item \If $\locEbsCutoffLEQSixteen = 0$ \Then + \begin{enumerate} + \item \If $\locRawHiIsZero = 1$ \Then + \[ \locLeadingWordLog = \locPaddedLogBaseTwo - 8 \cdot (\evmWordSize - \locEbsCutoff)\footnote{and $\locTrim$ is extracted from $\locRawLeadingWordLo$} \] + \item \If $\locRawHiIsZero = 0$ \Then + \[ \locLeadingWordLog = \locPaddedLogBaseTwo + 8 \cdot (\locEbsCutoff - \llarge)\footnote{and $\locTrim$ is extracted from $\locRawLeadingWordHi$} \] + \end{enumerate} + \end{enumerate} +\end{enumerate} +\saNote{} +Special care has to be taken for the following edge case: the underlying \evm{} word is of the form +\[ + \locRawLeadingWord + \;\equiv + \overbrace{ + \underbrace{ + \phantom{\bigg|} + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{00}\; + \utt{01} + \phantom{\bigg|} + }_{\displaystyle \in \mathbb{B}_{\llarge}} + \utt{??}\; \cdots \; \underline{\texttt{??}}}^{\displaystyle \in \mathbb{B}_{\evmWordSize}}, +\] +the exponent byte size (cutoff) \locEbsCutoff{} is $> \llarge$ and $\locCdsCutoff$ is $\geq \llarge$. This is the only configuration wherein the high part gets trimmed and after trimming equals 1. +When $\locEbsCutoff > \llarge$ the \locLeadingWord{} is a singular $\utt{01}$ followed by $\locEbsCutoff - \llarge$ many bytes so that (the floor of) its logarithm base $2$ is $8 \cdot (\locEbsCutoff - \llarge)$. +This is the purpose of the subcase ``\If $\locTrivialTrim = 1$ \et $\locRawHiIsZero = 0$.'' + +\saNote{} Similar precautions are taken in the \shfMod{} module. diff --git a/exp/modexp_log/linking.tex b/exp/modexp_log/linking.tex new file mode 100644 index 0000000..2da3c70 --- /dev/null +++ b/exp/modexp_log/linking.tex @@ -0,0 +1,34 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isModexpLog _{i} = 1 \\ + \isMacro _{i} = 1 \\ + \end{cases}} +\] +We are now in position to enforce some constraints which connect the preprocessing to the computation: +\begin{enumerate} + \item \If $\locMinCutoffLEQSixteen = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \compRawAcc_{i - 1} & = & \locRawLeadingWordHi \\ + \compPlateauJmp_{i - 1} & = & \locMinCutoff \\ + \end{array} \right. + \] + \item \If $\locMinCutoffLEQSixteen = 0$ \Then + \begin{enumerate} + \item \If $\locRawHiIsZero = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \compRawAcc_{i - 1} & = & \locRawLeadingWordHi \\ + \compPlateauJmp_{i - 1} & = & \llarge \\ + \end{array} \right. + \] + \item \If $\locRawHiIsZero = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \compRawAcc_{i - 1} & = & \locRawLeadingWordLo \\ + \compPlateauJmp_{i - 1} & = & \locMinCutoff - \llarge \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} diff --git a/exp/modexp_log/preprocessing.tex b/exp/modexp_log/preprocessing.tex new file mode 100644 index 0000000..4d730b9 --- /dev/null +++ b/exp/modexp_log/preprocessing.tex @@ -0,0 +1,68 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isModexpLog _{i} = 1 \\ + \isMacro _{i} = 1 \\ + \end{cases}} +\] +We deal with the preprocessing required by the $\expInstModexpLog$ instruction. +\begin{description} + \def\rowNum{1} \item[Preprocessing row $n^\circ (i + \rowNum)$:] + we impose + \[ + \callToLt + {i}{\rowNum} + {0}{\locCdsCutoff} + {\locEbsCutoff} + \] + we define the shorthand $\locComp \define \ppWcpRes_{i + \rowNum}$ and + \begin{enumerate} + \item \If $\locComp = 1$ \Then $\locMinCutoff \define \locCdsCutoff$ + \item \If $\locComp = 0$ \Then $\locMinCutoff \define \locEbsCutoff$ + \end{enumerate} + \def\rowNum{2} \item[Preprocessing row $n^\circ (i + \rowNum)$:] + we impose + \[ + \callToLt + {i}{\rowNum} + {0}{\locMinCutoff} + {\llarge + 1} + \] + and we define the shorthand $\locMinCutoffLEQSixteen \define \ppWcpRes_{i + \rowNum}$ + \def\rowNum{3} \item[Preprocessing row $n^\circ (i + \rowNum)$:] + we impose + \[ + \callToLt + {i}{\rowNum} + {0}{\locEbsCutoff} + {\llarge + 1} + \] + and we define the shorthand $\locEbsCutoffLEQSixteen \define \ppWcpRes_{i + \rowNum}$ + \def\rowNum{4} \item[Preprocessing row $n^\circ (i + \rowNum)$:] + we impose + \[ + \callToIszero + {i}{\rowNum} + {0}{\locRawLeadingWordHi} + \] + and we define the shorthand $\locRawHiIsZero \define \ppWcpRes_{i + \rowNum}$ + \def\rowNum{5} \item[Preprocessing row $n^\circ (i + \rowNum)$:] + we impose + \[ + \callToIszero + {i}{\rowNum} + {0}{\locPaddedLogBaseTwo} + \] + and we define (and have used) the shorthands + \[ + \left\{ \begin{array}{lcl} + \locPaddedLogBaseTwo & \define & 8 \cdot \locNBytesExcludingLeading + \locNBitsExcludingLeading \\ + \locTrivialTrim & \define & \ppWcpRes_{i + \rowNum} \\ + \end{array} \right. + \] +\end{description} +\saNote{} By construction one has that +\begin{IEEEeqnarray*}{LCL} + \locTrivialTrim = 1 & \iff & \locPaddedLogBaseTwo = 0 \\ + & \iff & \locTrimAcc < 2 \\ +\end{IEEEeqnarray*} diff --git a/exp/modexp_log/shorthands.tex b/exp/modexp_log/shorthands.tex new file mode 100644 index 0000000..716a3c9 --- /dev/null +++ b/exp/modexp_log/shorthands.tex @@ -0,0 +1,34 @@ +% TODO: split into different files +\[ + \boxed{\text{All shorthands introduced in this subsection should only be used given that } + \begin{cases} + \isModexpLog _{i} = 1 \\ + \isMacro _{i} = 1 \\ + \end{cases}} +\] +\noindent We use the shorthands defined below: +\[ + \left\{ \begin{array}{lcl} + \locRawLeadingWordHi & \define & \expMacroData {1} _{i} \\ + \locRawLeadingWordLo & \define & \expMacroData {2} _{i} \\ + \locCdsCutoff & \define & \expMacroData {3} _{i} \\ + \locEbsCutoff & \define & \expMacroData {4} _{i} \\ + \locLeadingWordLog & \define & \expMacroData {5} _{i} \\ + \locTrimAcc & \define & \compTrimAcc _{i - 1} \\ + \locNBytesExcludingLeading & \define & \compTanzbAcc _{i - 2} \\ + \locNBitsExcludingLeading & \define & \compManzbAcc _{i - 2} \\ + \end{array} \right. +\] + +% add shorthand for trim_lead and msnb potentially + +We represent the desired data lay out in the table below: + +\[ + % \hspace*{-1.5cm} + \input{vision/_start} \\ \hline \hline + \input{vision/modexp_log} \\ \hline + \end{array} +\] + +We then define $\locMinCutoff \define \min{(\locCdsCutoff,\locEbsCutoff)}$. diff --git a/exp/msb.tex b/exp/msb.tex new file mode 100644 index 0000000..eeb8393 --- /dev/null +++ b/exp/msb.tex @@ -0,0 +1,13 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isModexpLog _{i} = 1 \\ + \isComputation _{i} = 1 \\ + \end{cases}} +\] +The following constraints extract the most significant byte of the trimmed version of $\locRawLeadingWord$, i.e. $\locTrim$: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \et $\compTanzbAcc_{i} \neq 0$ \Then $\compMsb_{i} = \compTrimByte_{i}$; + \item \If $\ct_{i} \neq 0$ \et $\compTanzbAcc_{i} \neq 0$ \et $\compTanzbAcc_{i-1} = 0$ \Then $\compMsb_{i} = \compTrimByte_{i}$; + \item \If $\ct_{i} = \llargeMO $ \et $\compTanzbAcc_{i} = 0$ \Then $\compMsb_{i} = 0$; +\end{enumerate} diff --git a/exp/nonzeroExponent.tex b/exp/nonzeroExponent.tex new file mode 100644 index 0000000..2cee80a --- /dev/null +++ b/exp/nonzeroExponent.tex @@ -0,0 +1,9 @@ +We set the $\nonzeroExponent$ flag: $\nonzeroExponent = 1 \iff$ the exponent is nonzero, i.e.: +\begin{enumerate} + \item \If $\expHi_{i} \neq 0$ \Then $\nonzeroExponent_{i} = 1$; + \item \If $\expHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\expLo_{i} \neq 0$ \Then $\nonzeroExponent_{i} = 1$; + \item \If $\expLo_{i} = 0$ \Then $\nonzeroExponent_{i} = 0$; + \end{enumerate} +\end{enumerate} diff --git a/exp/plateau.tex b/exp/plateau.tex new file mode 100644 index 0000000..e93ab6b --- /dev/null +++ b/exp/plateau.tex @@ -0,0 +1,12 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \begin{cases} + \isModexpLog _{i} = 1 \\ + \isComputation _{i} = 1 \\ + \end{cases}} +\] +\begin{enumerate} + \item $\compPlateauBit$ is binary; + \item we impose $\plateau( \compPlateauBit, \compPlateauJmp)$ +\end{enumerate} +We refer the reader to section~(\ref{mmio: specialized constraints: plateau}) in the \mmioMod{} module for the definition of the \plateau{} constraint. diff --git a/exp/shorthands.tex b/exp/shorthands.tex new file mode 100644 index 0000000..6edcb3d --- /dev/null +++ b/exp/shorthands.tex @@ -0,0 +1,46 @@ +We define the following shorthands +\[ + \left\{ \begin{array}{lcl} + \flagSumPerspective_{i} & \define & + \left[ \begin{array}{cr} + + & \isComputation_{i} \\ + + & \isMacro_{i} \\ + + & \isPreprocessing_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \flagSumMacro_{i} & \define & + \left[ \begin{array}{cr} + + & \isExpLog_{i} \\ + + & \isModexpLog_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedFlagSumMacro_{i} & \define & + \left[ \begin{array}{crcl} + + & \expInstExpLog & \!\!\! \cdot \!\!\! & \isExpLog_{i} \\ + + & \expInstModexpLog & \!\!\! \cdot \!\!\! & \isModexpLog_{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +We further set +\[ + \begin{array}{lcl} + \maxCtFlagSum_{i} & \define & + \left[ \begin{array}{cl} + +& (\expCtMaxComputationExpLog \cdot \isExpLog_{i} \\ + +& ~\expCtMaxComputationModexpLog \cdot \isModexpLog_{i}) \cdot \isComputation_{i} \\ + +& (\expCtMaxMacroExpLog \cdot \isExpLog_{i} \\ + +& ~\expCtMaxMacroModexpLog \cdot \isModexpLog_{i}) \cdot \isMacro_{i} \\ + +& (\expCtMaxPreprocessingExpLog \cdot \isExpLog_{i} \\ + +& ~\expCtMaxPreprocessingModexpLog \cdot \isModexpLog_{i}) \cdot \isPreprocessing_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \end{array} +\] +where +\[ + \left\{ \begin{array}{lcl} + \expCtMaxComputationExpLog & = & \llargeMO \\ + \expCtMaxMacroExpLog & = & 0 \\ + \expCtMaxPreprocessingExpLog & = & 0 \\ + \expCtMaxComputationModexpLog & = & \llargeMO \\ + \expCtMaxMacroModexpLog & = & 0 \\ + \expCtMaxPreprocessingModexpLog & = & 4 \\ + \end{array} \right. +\] diff --git a/exp/todo b/exp/todo new file mode 100644 index 0000000..a5066ef --- /dev/null +++ b/exp/todo @@ -0,0 +1,16 @@ +- TRM_BYTE / TRM_ACC byte decomposition +- RAW_BYTE / RAW_ACC byte decomposition + +EXP case: +- TRM_BYTE = RAW_BYTE +- [TRM_ACC ≠ 0] + - associated accumulator +- its accumulator + +MODEXP case: +- TRM_BYTE / TRM_ACC + - requires the relevant LEAD (ok) + - plateau bit (ok) +- TRM_BYTE = RAW_BYTE * (1 - PLT_BIT) +- [TRM_ACC ≠ 0] + - associated accumulator diff --git a/exp/utils.tex b/exp/utils.tex new file mode 100644 index 0000000..26888f8 --- /dev/null +++ b/exp/utils.tex @@ -0,0 +1,52 @@ +The present section define constraints for pre-processing rows. +Specifically they provide the facilities to trigger the \wcpMod{} module. +We define the following constraint +\[ + \left\{ \begin{array}{l} + \callToLt + {i}{\relof} + {\col{a}}{\col{b}} + {\col{c}}{\col{d}} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \ppWcpFlag _{i} & = & 1 \\ + \ppWcpInst _{i} & = & \inst{LT} \\ + \ppWcpArgOneHi _{i} & = & \col{a} \\ + \ppWcpArgOneLo _{i} & = & \col{b} \\ + \ppWcpArgTwoHi _{i} & = & \col{c} \\ + \ppWcpArgTwoLo _{i} & = & \col{d} \\ + \end{array} \right. + \end{array} \right. +\] +% and +% \[ +% \left\{ \begin{array}{l} +% \callToEq{i}{\col{a}}{\col{b}}{\col{c}}{\col{d}} \vspace{4mm} \\ +% \qquad \qquad \iff +% \left\{ \begin{array}{lcl} +% \ppWcpFlag _{i} & = & 1 \\ +% \ppWcpInst _{i} & = & \inst{EQ} \\ +% \ppWcpArgOneHi _{i} & = & \col{a} \\ +% \ppWcpArgOneLo _{i} & = & \col{b} \\ +% \ppWcpArgTwoHi _{i} & = & \col{c} \\ +% \ppWcpArgTwoLo _{i} & = & \col{d} \\ +% \end{array} \right. +% \end{array} \right. +% \] +and +\[ + \left\{ \begin{array}{l} + \callToIszero + {i}{\relof} + {\col{a}}{\col{b}} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \ppWcpFlag _{i + \relof} & = & 1 \\ + \ppWcpInst _{i + \relof} & = & \inst{ISZERO} \\ + \ppWcpArgOneHi _{i + \relof} & = & \col{a} \\ + \ppWcpArgOneLo _{i + \relof} & = & \col{b} \\ + \ppWcpArgTwoHi _{i + \relof} & = & 0 \quad (\trash) \\ + \ppWcpArgTwoLo _{i + \relof} & = & 0 \quad (\trash) \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/exp/vision/_start.tex b/exp/vision/_start.tex new file mode 100644 index 0000000..6b180bf --- /dev/null +++ b/exp/vision/_start.tex @@ -0,0 +1,4 @@ +% \newcommand{\x}[1]{\cellcolor{solarized-green!40!yellow}#1} +\renewcommand{\arraystretch}{1.3} +\begin{array}{|c|c|c|c|c|c||c|} \hline +\expMacroData{1} & \expMacroData{2} & \expMacroData{3} & \expMacroData{4} & \expMacroData{5} & \expMacroInst diff --git a/exp/vision/_table.tex b/exp/vision/_table.tex new file mode 100644 index 0000000..b1f2a41 --- /dev/null +++ b/exp/vision/_table.tex @@ -0,0 +1,7 @@ +\[ + \hspace*{-1.5cm} + \input{vision/_start} \\ \hline \hline + \input{vision/exp_log} \\ \hline + \input{vision/modexp_log} \\ \hline + \end{array} +\] diff --git a/exp/vision/exp_log.tex b/exp/vision/exp_log.tex new file mode 100644 index 0000000..a516235 --- /dev/null +++ b/exp/vision/exp_log.tex @@ -0,0 +1 @@ +\x\locExponentHi & \x\locExponentLo & \nothing & \nothing & \locDynamicCost & \expInstExpLog diff --git a/exp/vision/modexp_log.tex b/exp/vision/modexp_log.tex new file mode 100644 index 0000000..18c553b --- /dev/null +++ b/exp/vision/modexp_log.tex @@ -0,0 +1,2 @@ +\x\locRawLeadingWordHi & \x\locRawLeadingWordLo & \x\locCdsCutoff & \x\locEbsCutoff & \locLeadingWordLog & \expInstModexpLog + diff --git a/formal/_all_formal.tex b/formal/_all_formal.tex new file mode 100644 index 0000000..d24ddc7 --- /dev/null +++ b/formal/_all_formal.tex @@ -0,0 +1,49 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/oob} +\usepackage{../pkg/stp} +\usepackage{../pkg/stack} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/log_info} +\usepackage{fancyvrb} +\usepackage{listings} +\lstset{ + basicstyle=\ttfamily, + mathescape +} + +\title{Formal verification workhop notes} +\author{Arithmetization team and Alex Vlasov} +\date{September 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/formal/_inputs.tex b/formal/_inputs.tex new file mode 100644 index 0000000..ad43737 --- /dev/null +++ b/formal/_inputs.tex @@ -0,0 +1,58 @@ +\newcommand{\alexV} {\red{\texttt{@Alex.Vlasov}}} +\newcommand{\joanneF} {\red{\texttt{@Joanne.Fuller}}} +\newcommand{\olivierB} {\red{\texttt{@Olivier.Bégassat}}} +\newcommand{\franklinD} {\red{\texttt{@Franklin.Delehelle}}} +\newcommand{\francoisB} {\red{\texttt{@François.Bojarski}}} +\newcommand{\lorenzoG} {\red{\texttt{@Lorenzo.Gentile}}} + +\newcommand{\prover} {\texttt{Prover}} +\newcommand{\corset} {\texttt{Corset}} +\newcommand{\go} {\texttt{Go}} +\newcommand{\python} {\texttt{Python}} +\newcommand{\rust} {\texttt{Rust}} +\newcommand{\coq} {\texttt{Coq}} +\newcommand{\isbell} {\texttt{Isbell}} +\newcommand{\hol} {\texttt{HOL}} + +\newcommand{\mProver} {\mathtt{Prover}} +\newcommand{\mCorset} {\mathtt{Corset}} +\newcommand{\mGo} {\mathtt{Go}} +\newcommand{\mPython} {\mathtt{Python}} +\newcommand{\mRust} {\mathtt{Rust}} +\newcommand{\mCoq} {\mathtt{Coq}} +\newcommand{\mIsbell} {\mathtt{Isbell}} +\newcommand{\mHol} {\mathtt{HOL}} + +\section{Introduction} +\subsection{Two work streams} \input{intro} \label{formal: intro} +\subsection{From proofs to traces} \input{proofs_to_traces} \label{formal: proofs_to_traces} +\subsection{Relation} \input{relation} \label{formal: relation} +\subsection{Tracers} \input{tracers} \label{formal: tracers} +\subsection{Satisfiability, canonical traces, essential uniqueness / functionality and extractability} \label{formal: } +\subsubsection{Satisfiability} \input{satisfiability} \label{formal: satisfiability} +\subsubsection{Canonical trace validity} \input{canonical} \label{formal: canonical} +\subsubsection{Essential uniqueness} \input{uniqueness} \label{formal: uniqueness} +\subsubsection{Extractability} \input{extractability} \label{formal: extractability} + +\section{Levels of analysis} +\subsection{Structural properties} \input{structural} \label{formal: structural} +\subsection{Consistency properties} \input{consistency} \label{formal: consistency} +\subsection{Local properties} \input{local} \label{formal: local} +\subsection{Type safety} \input{types} \label{formal: types} +\subsection{Low hanging fruit} \input{fruit} \label{formal: fruit} + +\section{The ``What''} +\subsection{Formal verification of flattening} \input{sea} \label{formal: sea} +\subsection{Direction} \input{direction} \label{formal: direction} +\subsection{Meaning} \input{meaning} \label{formal: meaning} +\subsection{``Eindeutigkeit'' or definiteness} \input{eindeutigkeit} \label{formal: eindeutigkeit} + +\section{Automation} +\subsection{Corset annotations and hints} \input{annotations} \label{formal: annotations} + \input{hints} \label{formal: hints} +\subsection{Toy-example} \input{toy} \label{formal: toy} +\subsection{Toy-example of connections to Python} \input{python} \label{formal: python} +\subsection{Toy-example of desired output} \input{output} \label{formal: output} + +\section{Pie in the sky} +\subsection{Groebner basis for minimal constraint systems} \input{groebner} \label{formal: groebner} diff --git a/formal/annotations.tex b/formal/annotations.tex new file mode 100644 index 0000000..467e223 --- /dev/null +++ b/formal/annotations.tex @@ -0,0 +1,29 @@ +\textbf{Annotations} already exist in \corset{} e.g. for types. These may serve different purposes: simplify constraint systems, provide implicit assumptions to the prover for specialized verification. See below. But we could add more annotations. For instance we could add annotations to help the transpiler to set up theorem stumps and prove intermeidary lemmas by itself: +\begin{Verbatim}[commandchars=\\\{\}] +(module toy-example) + +(defcolumns + COMP \textcolor{gray!75}{:boolean} + \textcolor{gray!75}{;; \color{solarized-yellow}{helps \corset{} simplify constraints}} + + ( BYTES [5] ) \textcolor{gray!75}{:byte} + \textcolor{gray!75}{;; \color{solarized-yellow}{helps \prover{} identify implicit range proofs}} + + ARG_1_HI \textcolor{gray!75}{:hint (god-given CT 0)} + \textcolor{gray!75}{:hint (module-requires-smallness 16)} + ARG_1_LO \textcolor{gray!75}{:hint (god-given CT 0)} + \textcolor{gray!75}{:hint (module-requires-smallness 16)} + \textcolor{gray!75}{;; \color{solarized-yellow}{should help theorem prover find entry points}} + \textcolor{gray!75}{;; \color{solarized-yellow}{and make module specific assumptions}} + \textcolor{gray!75}{;; \color{solarized-yellow}{these columns should be believed whenever CT_i = 0}} + + ARG_2_HI \textcolor{gray!75}{;; \color{solarized-yellow}{same}} + ARG_2_LO \textcolor{gray!75}{;; \color{solarized-yellow}{same}} + + RES_HI \textcolor{gray!75}{:hint (module-ensures-smallness 16)} + \textcolor{gray!75}{:hint (module-ensures-uniqueness)} + RES_LO \textcolor{gray!75}{:hint (module-ensures-smallness 16)} + \textcolor{gray!75}{:hint (module-ensures-uniqueness)} + \textcolor{gray!75}{;; \color{solarized-yellow}{should help theorem prover deduce which theorems to prove}} +) +\end{Verbatim} diff --git a/formal/canonical.tex b/formal/canonical.tex new file mode 100644 index 0000000..2a35479 --- /dev/null +++ b/formal/canonical.tex @@ -0,0 +1,11 @@ +\begin{thm}[Canonical completeness] + For any valid state transition $\state \rightsquigarrow \state'$ associated with the execution of transactions the ``canonical $\mPython{}$ trace'' $\mPython\emph{\text{-}}\fullTrace$ should satisfy + \[ + \zkEvmConstRel + \Big[ \state, \big(\text{tx}_a\big)_{a}; + \mPython \emph{\text{-}}\fullTrace; + \state' \Big] + \equiv \mTrue. + \] +\end{thm} + diff --git a/formal/consistency.tex b/formal/consistency.tex new file mode 100644 index 0000000..06455f8 --- /dev/null +++ b/formal/consistency.tex @@ -0,0 +1 @@ +Consistency properties, like structural properties, are macroscopic properties of traces, but nonlocal ones. Their enforcement is typically done with local constraints that apply to a row-permutation of the underlying trace. Examples include: stack, storage, account, context consistencies in the \hubMod; revert data consistency in the \hubMod{} module; memory consistency in the \mmioMod{}; memory size consistency in the \mxpMod{} module; etc \dots{} diff --git a/formal/constraints.tex b/formal/constraints.tex new file mode 100644 index 0000000..e69de29 diff --git a/formal/direction.tex b/formal/direction.tex new file mode 100644 index 0000000..ccaab24 --- /dev/null +++ b/formal/direction.tex @@ -0,0 +1,12 @@ +Cosntraints, when flattened, lose all direction which is present initially in the constraints, e.g. both constraints below +\begin{Verbatim} + (if-not-zero A (vanishes! B)) + (if-not-zero B (vanishes! A)) +\end{Verbatim} +compile down to the same equation: +\begin{Verbatim} + A * B = 0 +\end{Verbatim} +Yet the \textbf{intention} of the first constraint is to \textbf{set the contents} of the \texttt{B} column under certain circumstances where one assumes \texttt{A} already known (and in case of vanishing.) Data flows from cells that are understood to be \godGiven{} to others that aren't. + +Other constraints implicitly diff --git a/formal/eindeutigkeit.tex b/formal/eindeutigkeit.tex new file mode 100644 index 0000000..e69de29 diff --git a/formal/extractability.tex b/formal/extractability.tex new file mode 100644 index 0000000..dba49fc --- /dev/null +++ b/formal/extractability.tex @@ -0,0 +1,39 @@ +I actually believe we have a much stronger property: +\begin{conjecture}[Extraction] + Given a trace \fullTrace{} which satisfies $\fullConstraints$\footnote{and appropriate type hypotheses on module specific ``\godGiven'' inputs} there exists a unique minimal initial state $\state_0$ with the property that \emph{if well-formed} there exist (implicit, valid) transactions $(\text{tx}_a)_a$ (given in full, including transaction receipt) and a unique minimal partial terminal state $\state_1$ such that + \[ + \zkEvmConstRel + \Big[ \state_{0}, \big(\text{tx}_a\big)_{a}; + \fullTrace; + \state_{1} \Big] + = + \mTrue + \] + Furthermore if for some states $\state$ and $\state'$ and some transactions $(\widehat{\text{tx}}_b)_b$ the relation + \[ + \zkEvmConstRel + \Big[ \state, \big(\widehat{\text{tx}}_b\big)_{b}; + \fullTrace; + \state' \Big] + = + \mTrue + \] + holds then $\sigma_0 \subset \sigma$, $\sigma_1 \subset \sigma'$, $\big(\text{tx}_a\big)_{a} = \big(\widehat{\text{tx}}_b\big)_{b}$. + % Furthermore if $\widehat{\state}$ and $\widehat{\state}'$ satisfy that same relation + % \[ + % \zkEvmConstRel + % \Big[ \widehat{\state}, \big(\text{tx}_a\big)_{a}; + % \fullTrace; + % \widehat{\state}' \Big] + % = + % \mTrue + % \] + % then $\sigma \setminus \sigma_0 = \widehat{\sigma} \setminus \sigma_0$ + % and $\sigma' \setminus \sigma_1 = \widehat{\sigma}' \setminus \sigma_1$. +\end{conjecture} +\saNote{} This partial substate will be \emph{well-formed}\footnote{in the sense that storage values are correctly separated into high and low parts and committed byte code chunks are $\llarge$-byte integers} but not necessarily \emph{accessible}, e.g.: +\begin{enumerate} + \item it may contain addresses with empty byte code but nonempty storage; + \item it may contain addresses with nonempty byte code containing neither \inst{CREATE(2)} instructions nor \inst{CALLCODE} / \inst{DELEGATECALL} instructions yet having a nonce $\geq 2$; + \item \dots{} +\end{enumerate} diff --git a/formal/fruit.tex b/formal/fruit.tex new file mode 100644 index 0000000..e69de29 diff --git a/formal/groebner.tex b/formal/groebner.tex new file mode 100644 index 0000000..4443a80 --- /dev/null +++ b/formal/groebner.tex @@ -0,0 +1,11 @@ +There is the possibility to optimize the prover as follows: +(\emph{a}) +compute the flattened constraint system $\mathcal{C}_\moduleName$ of a module $\moduleName$ with columns $\col{A}$, $\col{B}$, $\col{C}$, \dots{} +(\emph{b}) +these are multivariate polynomials in as many columns as there are columns in the module +(\emph{c}) +these multivariate polynomials define an ideal $\langle\mathcal{C}_\moduleName\rangle$ in some polynomial ring $\mathbb{F}[\col{A}, \col{B}, \col{C}, \dots]$ equipped with some ``shift operator'' $\sigma$; Groebner basis techniques could extract from them a Groebner basis which should represent a minimal set of constraints for the present module; +(\emph{d}) +a valid module trace represents in some sense a ``parametrized solution'' to the above along a subset of the base field; the parametrization space being e.g. some group of roots of unity and the aforementioned ``shift operator'' should correspond under paramatrization to the ``argument translation by a fixed primitive root'' operator; +(\emph{e}) +not all minimal systems should have the same utility, and one can imagine a weight function being used to rank one minimal system agains another; this weight function should be correlated to actual prover costs. diff --git a/formal/hints.tex b/formal/hints.tex new file mode 100644 index 0000000..e677e06 --- /dev/null +++ b/formal/hints.tex @@ -0,0 +1,24 @@ +\corset{} could be augmented in several ways. \textbf{Hints} could impose, if at all relevant, directionality and intent. For instance we could have hints à la +\begin{Verbatim}[commandchars=\\\{\}] +(defconstraint setting-B (:guard A) + (vanishes! B) \textcolor{gray!75}{:hint (expect-known A)} + \textcolor{gray!75}{:hint (sets B)} + \textcolor{gray!75}{ ;; \color{solarized-yellow}{intent and directionality}} +) +\end{Verbatim} + +\begin{Verbatim}[commandchars=\\\{\}] +(defconstraint byte-decompositions () + (begin + (byte-decomposition CT BYTE_1 ACC_1 VAL_1) \textcolor{gray!75}{:hint (expect-known VAL_1)} + \textcolor{gray!75}{ :hint (implicitly-defines BYTE_1 ACC_1)} + \textcolor{gray!75}{ ;; \color{solarized-yellow}{intent and directionality}} + + (byte-decomposition CT BYTE_2 ACC_2 VAL_2) \textcolor{gray!75}{:hint (expect-known BYTE_2)} + \textcolor{gray!75}{ :hint (implicitly-defines VAL_2 ACC_2)} + \textcolor{gray!75}{ :hint (imposes-smallness VAL_2 16)} + \textcolor{gray!75}{ ;; \color{solarized-yellow}{intermediary lemmas}} + ) +) +\end{Verbatim} +And when patterns emerge (as they very quickly will) we can start factorizing them into \corset{} functions that produce the hints for us. diff --git a/formal/intro.tex b/formal/intro.tex new file mode 100644 index 0000000..5541be7 --- /dev/null +++ b/formal/intro.tex @@ -0,0 +1 @@ +The work which the arithmetization team does happens on two distinct levels. On one level we are \textbf{specifying a vast constraint system} $\fullConstraints$. On the other hand we are \textbf{implementing (so-called) tracers}. The two workstreams are closely related and in dome sense dual to one another. diff --git a/formal/levels.tex b/formal/levels.tex new file mode 100644 index 0000000..e69de29 diff --git a/formal/local.tex b/formal/local.tex new file mode 100644 index 0000000..f90d189 --- /dev/null +++ b/formal/local.tex @@ -0,0 +1 @@ +Local properties are typically the properties that ensure, given well-behaved and predictable scaffolding, that the detail that populate the scaffolding perform a given computation and potentially set up the next computation. These are exemplified by the non-heartbeat constraints of terminal modules such as the stateless ones. diff --git a/formal/meaning.tex b/formal/meaning.tex new file mode 100644 index 0000000..e69de29 diff --git a/formal/notes_2023_10_20.md b/formal/notes_2023_10_20.md new file mode 100644 index 0000000..cca4ade --- /dev/null +++ b/formal/notes_2023_10_20.md @@ -0,0 +1,71 @@ +# Updates + +Alex worked on implementing the ADD module in Dafny and SMT +what ADD verification would look like in Dafny (valid inputs, specification of validity) +There are two approaches: **column** and **row** based implementations + +**row** based approach: +- Soundness and completeness theorems are formulatable +- Drawback: it needs to access other rows (shifts) + +**column** based approach: +- better suited in this regard (shifts) +- the theorems in this case look like Corset: almost one to one translation of Corset, and ability to talk about shifts +Harder for Dafny vs SMT solver +Theorem for one request in the column model + - DAFNY is able to find a proof for one chunk of rows + - chunk = 1 padding row + 16 rows for an instruction +Theorem for many requests / arbitrary length traces in the row model + +outcome: ISBELL/HOL better suited for arbitrary traces, SMT for simple stuff +DAFNY has issues with mathematics, in particular finite field operations (though doable @joanne) +(interactive) theorem provers have FFA (finite fied arithmetic) encoded +There are SMT solvers that support FFA and nonlinear operations +DAFNY will be a problem (e.g. OR <=> multiplication in our arithmetization and loobeans) + +When starting with valid traces (i.e. assuming that the constraints hold) functional correctness holds. +In the column based model he can prove that computation matches specification for ADD/SUB (so functional correctness) +Essential uniqueness follows from the lemma, by duplicating the inputs. + +Joanne: +using FFA in DAFNY possible +primary focus is finite fields (working modulo some prime) +some success in proving completeness +Update on architecture and individual modules: +- idea: ``trace mechanism`` + - goal is to describe arbitrary sequence of instructions for a module + - proof by induction + - starts with the empty (i.e. trivial) trace + - theorem establishes that the trivial trace is valid + - the trace mechanism embodies the induction + - it takes as input an existing (valid) trace `T` + (e.g.) wcpData object `d` + - it outputs an updated trace `T'` + - proving that valid input traces remain valid after mechanism i.e. `validWcp(T')` +- set up this **mechanism** for several modules +- validity check (theorem?) `validXXX` works with single constraints at a time, e.g. 73 for WCP module +- works with _arbitrary_ (e.g.) wcpData objects +- builds a ``canonical trace`` from a sequence of (e.g.) wcpData objects + - Dafny does a lot of data type checking in the background + - proves completeness of entire module + - was able to find a missing constraint from older version of spec + - should help with functional correctness + - what are the requirements for the wcpData object ? relationship between obcopde and arguemnt ? is the output part of the wcpData ? + - with David automate the empty file and update function, predicate (i.e. DAFNY version of constraints) + - summary: + - WCP tracing, mechanism, constraints, empty proofs verified, verified 53 of 73 constraints update proofs + - shifting is an issue, esp. 8 bit shifting for SLT, SGT + - shift by 1 is conquered, others should follow + - result constraints of the spec + - ADD similar state (missing 2 constraints) + - SHF, BIN trace mechanism + - soundness / functional correctness possible (but in this trace update mechanism) + - it's basically showing completeness + - references stack ... it's really about the building of the trace of a sequence of requested instructions + +could be used to prove soundness once we have the scaffolding +except for the fact that we may lose type constraints in the general case (for never called computations) + + +Note: + - completeness (Joanne) and + - soundness (Alex) could be used in a synthesis where starting from a constraint valid trace we extract with scaffolding instuctions and inputs, and with Joann's stuff diff --git a/formal/notes_2023_111_17.md b/formal/notes_2023_111_17.md new file mode 100644 index 0000000..e69de29 diff --git a/formal/notes_day_1.md b/formal/notes_day_1.md new file mode 100644 index 0000000..dbde0c9 --- /dev/null +++ b/formal/notes_day_1.md @@ -0,0 +1,154 @@ +- [Preliminary questions](#preliminary-questions) +- [More detailed questions](#more-detailed-questions) + - [Simple constraint systems perform computations as advertized](#simple-constraint-systems-perform-computations-as-advertized) + - [Type system](#type-system) + - [ROLLBACK-yoga:](#rollback-yoga) + - [DEPLOYMENT\_NUMBERS, DEPLOYMENT\_STATUS handles reverts, selfdestructs correctly](#deployment_numbers-deployment_status-handles-reverts-selfdestructs-correctly) + - [Evolving spec \& formal verification](#evolving-spec--formal-verification) + - [Lofty goals](#lofty-goals) + + +# Preliminary questions + +- What do we **want** formally verified ? +- What questions **can** and **should** formal verification methods be applied to ? +- When is testing **better** ? + +# More detailed questions + +## Simple constraint systems perform computations as advertized + +- arithmetic, comparisons, binary, trimming, ... +- oob, mxp, ... + +## Availability (lookups work) + +- DATA is available elsewhere +- Some modules should ONLY do some determined things (how to prevent phantom tx's etc ...) + +## Type system + +(boolean, bytes, various kinds of smallness of integers: $\leq 4, 8, 16)$-byte integers) + +## ROLLBACK-yoga: + +- handling several different REVERT stamps and offsets +- standard offsets e.g. for reverting account / storage operations, for enacting SELFDESTRUCTs after everything else has been done (dom, sub) = (tau * stamp + offset, tau * hub + small) + - strange example: the COINBASE is a smartcontract and it is SELFDESTRUCT'ed: which wins: the refund ? the wiping of the account ? +- revert through the COLUMN, COLUMN_NEW paradigm +- revert through the paradigm of "don't change it if it will be reverted (refunds)" +- **Question.** To what extent can simple designs like those below be formally verified pre-implementation ? + +without reverts: + +| REV_STAMP | STAMP | DOM | SUB | VAL | VAL_NEW | WAL | WAL_NEW | +| --------- | ----- | --------------- | --- | --- | ------- | --- | ------- | +| 0 | h | $\tau \cdot$ h | 0 | v | v' | w | w' | +| ... | ... | ... | ... | ... | ... | ... | ... | +| 0 | h' | $\tau \cdot$ h' | 0 | v' | v'' | w' | w'' | + +with reverts + +| REV_STAMP | STAMP | DOM | SUB | VAL | VAL_NEW | WAL | WAL_NEW | +| --------- | ----- | ----------------- | --------------- | --- | ------- | --- | ------- | +| $\rho$ | h | $\tau \cdot$ h | 0 | v | v' | w | w' | +| $\rho$ | h | $\tau \cdot \rho$ | $\tau \cdot$ h | v' | v | w' | w' | +| ... | ... | ... | ... | ... | ... | ... | ... | +| $\rho$ | h' | $\tau \cdot$ h' | 0 | v' | v'' | w' | w' | +| $\rho$ | h' | $\tau \cdot$ h' | $\tau \cdot$ h' | v'' | v' | w' | w' | + +with several revert stamps + +| REV_STAMP_1 | REV_STAMP_2 | STAMP | DOM | SUB | VAL | VAL_NEW | WAL | WAL_NEW | +| ----------- | ----------- | ----- | -------------------- | ------------------ | --- | ------- | --- | ------- | +| $\rho\_1$ | $\rho\_2$ | h | $\tau \cdot$ h | 0 | v | v' | w | w' | +| $\rho\_1$ | $\rho\_2$ | h | $\tau \cdot \rho\_1$ | $\tau \cdot$ h + 1 | v' | v | w' | w' | +| $\rho\_1$ | $\rho\_2$ | h | $\tau \cdot \rho\_2$ | $\tau \cdot$ h + 2 | v | v | w' | w | +| ... | ... | ... | ... | ... | ... | ... | ... | ... | +| $\rho\_1$ | 0 | h' | $\tau \cdot$ h' | 0 | v' | v'' | w' | w' | +| $\rho\_1$ | 0 | h' | $\tau \cdot\rho\_1$ | $\tau \cdot$ h' | v'' | v' | w' | w' | + +![Flowchart for CREATE-type instructions](https://hackmd.io/_uploads/Bk_sggBy6.png) + +![Flowchart for CALL-type instructions (not to precompile)](https://hackmd.io/_uploads/HJN0xlBk6.png) + +## DEPLOYMENT_NUMBERS, DEPLOYMENT_STATUS handles reverts, selfdestructs correctly + +- they transit as expected from ACCOUNT-rows to CONTEXT-rows to STORAGE-rows + +## Evolving spec & formal verification + +- what is the role of formal verification with an evolving spec ? with an evolving back end ? + - bug fixing in spec + - philosophy changes (counter-constancy vs. IOMF/DONE) paradigm) + - major updates (e.g. v1 -> v2) of modules + - reinterpretation of constraints (field change) + - field agnostic zk-evm + - **Question** To what extent is the formal verification dependent on the constraints ? Joanne's approach isn't scalable --- what approach is ? What are the properties that can a more or less implementation independent formal proof which can be updated as spec changes roll in ? + - How to **automatize** lisp -> (dafny / coq / ...) so that formal verification of properties survives ? +- when is an appropriate time to think of formal verification ? + - e.g. recent redesign of CALL's CREATE's + - simplified design underpinned by less contrived constraints + +## Lofty goals + +- catching the possibility of valid yet **undesirable traces** (i.e. catching underconstrained systems with negative consequences: recent example of a monotone column that could respect nondecreasing conditions but behave badly because of the possibility of starting out negative +- **Completeness** (lofty goal): + - valid traces are always producible given a valid input state and valid (''relatively cheap'') transactions + - for all Soundness, "compliance with the EVM", control flow of complex opcodes (e.g. CALLs, CREATEs, precompiles) ... +- **Soundness** (lofty goal): +- Can we use the zk-evm as a kind of **execution client** ? + - Comparisons with other clients, e.g. + - abstract away the hashing and other precompiles + + +# Notes + +Using firsts order logic to test the logic of a program before implementation. +- prove existence / non existence of solutions. +- working with finite universes of possibilities + + +## Ever evolving spec + +- transpilation +- 2 main theorems: soundness and completeness +- rather than function, think of relations (several outputs are alright);w + +## Automation + +- EVM execution spec + - If statements + - 3 loops or so in total +- ZKEVM corset constraints + - while loops (RLP while nonzero, MMU: for (i = 0; i < ...; i++) + +Have a path from both to a CL (common logic) ? +- Using 1st order logic (for simple modules: Exists unique trace) + +## Proof automation strategy + +Suppose we can transform theorem to CNF + +Modal logic: has an intrinsic notion of state and a notion of temporality. + +Question: is there a duality between constraints and computations (CT columns are while loops) + +Computations: +- essential uniqueness of traces +- modeling the computation as a DAG + Note: we have some circularity in the constraints: + - CFI is referenced in the CALL's + - CFI is only resolved at the end of the computation + - reflection of the result in the TRACE (HUB) +- actually: there is some circularity +- notion of essential uniqueness, see PIC 1 + +Incremental approach producing trusted black boxes: +- outside ones (ECRECOVER, SHA3, ...) +- ones that are formally verified from our arithmetization + + +Using constraints to generate irectd graph of computational dependencies between columns. +Use this to generate traces automatically. +Constraints satisfaction problems and finding solutions to constraints diff --git a/formal/output.tex b/formal/output.tex new file mode 100644 index 0000000..e69de29 diff --git a/formal/proofs_to_traces.tex b/formal/proofs_to_traces.tex new file mode 100644 index 0000000..0aa2114 --- /dev/null +++ b/formal/proofs_to_traces.tex @@ -0,0 +1,34 @@ +The purpose of the paragraph below is for us to transition from proofs $\pi$ to traces $\fullTrace$. + +Proofs of \zkEvm{} execution are built using polynomial commitment schemes. The prover is supposed to commit to large matrices, and the proof verifies that they satisfy specific constraints. Given a \textbf{valid} \zkEvm{} proof $\pi$ transitioning the \zkEvm{} from a valid initial state to some other state it seems reasonable to conclude that, unless some cryptographic assumptions are broken: +\begin{description} + \item[\quad \underline{Underlying valid trace assumption:}] take on faith that + \begin{description} + \item[\quad Trace existence:] $\pi$ was constructed from an underlying trace \fullTrace{}; + \item[\quad Constraint satisfaction:] this trace should be a solution to the \zkEvm{} constraint system; + \item[\quad Size bounds:] this trace should satisfy appropriate (verifier circuit imposed) size bounds; + \end{description} +\end{description} +These propositions should be consequences of the following facts: +(\emph{a}) +proofs are built on top of \textbf{polynomial commitment schemes} and likely require random openings from which \textbf{knowledge}, and existence in particular, of an underlying trace object \fullTrace{} should follow +(\emph{b}) +standard arguments based on randomized openings and collisions (i.e. Schwartz-Zippel etc\dots{}) say that unless constraints are satisfied, the proof shouldn't go through, +(\emph{c}) +prover circuits have limited capacity (so-called \textbf{limits}) from which size bounds should follow. + +The \zkEvm{} constraint system $\fullConstraints$ is made of autonomous constraint systems (i.e. \textbf{modules} \moduleName{}) that apply to associated traces and lookup arguments to transfer data from one place to another. Traces that are accepted $\fullTrace$ have the following form: +\[ \fullTrace \equiv (\moduleTrace_{\moduleName})_{\moduleName \in \modules} \] +We continue deducing reasonable consequences for the underlying traces: +\begin{description} + \item[\quad \underline{Well formedness assumption:}] \fullTrace{} should be a collection of matrices with coefficients in the arithmetization's prime field $\mathbb{F}$ and having the right format: + \begin{description} + \item[\quad Depth:] all columns within a give module have the same depth; + \item[\quad Width:] the number of columns in $\moduleTrace_{\moduleName}$ is determined by the module $\moduleName$ and coincides with that from the relevant module specification\footnote{alternatively: that produced by Corset after trace expansion; though using this as our starting point is undesirable since it depends on implementation details of Corset wrt how it performs trace expansion etc\dots{}}; + \item[\quad Identification:] we have, for every module $\moduleName$ a one-to-one mapping from the columns between the columns of $\moduleTrace_\moduleName$ and those in the specification which is compatible with the associated constraints; + \end{description} +\end{description} +In any case, we may as well take these hypothesis for granted, otherwise we wouldn't get very far. + + + diff --git a/formal/python.tex b/formal/python.tex new file mode 100644 index 0000000..4ab4c10 --- /dev/null +++ b/formal/python.tex @@ -0,0 +1 @@ +There is a need for connecting \python{} variables to diff --git a/formal/relation.tex b/formal/relation.tex new file mode 100644 index 0000000..f5360a9 --- /dev/null +++ b/formal/relation.tex @@ -0,0 +1,38 @@ +In view of future decentralization it seems that the only assumptions we may (reasonably) make about \zkEvm{} proofs $\pi$ is that they are derived from \emph{some} underlying trace \fullTrace{} satisfying the constraint system $\fullConstraints$ and abiding by the well-formedness requirements from the previous section. + +Let us say that families of matrices abiding by these well-formedness properties are elements of the \textbf{trace space} $\mathcal{T}$. We may then, from our constraint system $\mathcal{C}_\zkEvm{}$ define a \textbf{parametrized family of relations} on the trace space +\[ +\zkEvmConstRel +\Big[ + \underbrace{\state, \big(\text{tx}_a\big)_{a}}_{\text{``inputs''}}; + \underbrace{\fullTrace}_{\text{``auxiliary''}}; + \underbrace{\state'}_{\text{``ouputs''}} + \Big] +\] +Where $\state$ is the \textbf{initial state} parameter, $(\text{tx}_a)_{a}$ the \textbf{valid transactions}\footnote{transaction validity being an incremental notion in the sense that transaction ordering is important and a transaction validity depends on the history of transactions} parameter (which can be considered as \textbf{input} parameters), $\state'$ is the \textbf{final state} parameter. +\begin{IEEEeqnarray*}{LCL} + \texttt{valid-state}(\state) + & \equiv & \mTrue \\ + \texttt{valid-txs}\Big(\state, \big(\text{tx}_a\big)_{a}\Big) + & \equiv & \mTrue \\ + \zkEvmConstRel + \Big[ + \state, \big(\text{tx}_a\big)_{a}; + \fullTrace; + \state' + \Big] + & = & + \left[ \bigwedge_{\moduleName \in \modules} \zkEvmModuleRel_{\moduleName} \Big[ \moduleTrace_{\moduleName} \Big] \right] + \wedge + \left[\bigwedge_{\lambda : \moduleName \hookrightarrow \moduleName' \in \lookups} \zkEvmLookupRel_{\lambda} \Big[ \moduleTrace_{\moduleName}, \moduleTrace_{\moduleName'} \Big] \right] \\ + & \equiv & \mTrue / \mFalse +\end{IEEEeqnarray*} +\ob{Note: the above doesn't involve $\state'$ \dots{} while it should.} +Depending on the module pair $\moduleName$, $\moduleName'$ the relation $\zkEvmLookupRel_{\moduleName, \moduleName'}$ may be +(\emph{a}) +\textbf{trivial} e.g. the modules in question aren't connected by means of a lookup and so the relation should be trivially satisfied; +(\emph{b}) +an \textbf{inclusion} statement e.g. ``every call from \moduleName{} to $\moduleName'$ is dealt with in $\moduleName'$''; +(\emph{c}) +a \textbf{full inclusion} statement e.g. ``every call from \moduleName{} to $\moduleName'$ is dealt with in $\moduleName'$ and no other instructions are executed within $\moduleName'$ than those requested by module \moduleName{}.'' + diff --git a/formal/satisfiability.tex b/formal/satisfiability.tex new file mode 100644 index 0000000..3626459 --- /dev/null +++ b/formal/satisfiability.tex @@ -0,0 +1,11 @@ +We want a satisfiability / completeness theorem à la +\begin{thm}[Completeness] + For any valid state transition $\state \rightsquigarrow \state'$ associated with the execution of transactions there ought to exist a trace $\fullTrace$ such taht + \[ + \zkEvmConstRel + \Big[ \state, \big(\text{tx}_a\big)_{a}; + \fullTrace; + \state' \Big] + \equiv \mTrue. + \] +\end{thm} diff --git a/formal/sea.tex b/formal/sea.tex new file mode 100644 index 0000000..cf5ec92 --- /dev/null +++ b/formal/sea.tex @@ -0,0 +1,16 @@ +In the end the \zkEvm's constraint system is ``flattened'' to a vast collection of constraints for processing by the prover. This step removes all ``direction'' and ``intention'' with which the constraint \constraintAst{} is imbued. This tells us that the formal verification of \evm{} semantics should take place at the \constraintAst{} level. + +But it also opens a completely different opportunity for formal verification: formally verifying the \textbf{corset constraint flattening rulebook and implementation}. The main points of inquiry (though my faith in the rulebook and its implementation is strong) would be: +\begin{enumerate} + \item correctly flattening nested constraints (e.g. no ``forgotten terms''); + \item correctly dealing with special constraints: + \begin{Verbatim}[commandchars=\\\{\}] +(if-zero CONDITION + \textcolor{gray!75}{;; CONDITION == 0 case} + ZERO_CASE + \textcolor{gray!75}{;; CONDITION != 0 case (optional)} + NONZERO_CASE) + \end{Verbatim} + (and similarly for \texttt{(if-not-zero ...)} and \texttt{(if-eq-else ...)} constraints) in terms of producing the right auxiliary columns satisfying the right constraints; +\end{enumerate} +\alexV{} was mentioning that this could be achieved through testing. One implements the rulebook in \coq, uses it to compile down constraints to the target (\go) and compares the output with that generated by the \corset{} flattening. This can then be done on a large sample of constraints (e.g. the entire \zkEvm{} constraint system.) diff --git a/formal/structural.tex b/formal/structural.tex new file mode 100644 index 0000000..180006c --- /dev/null +++ b/formal/structural.tex @@ -0,0 +1,7 @@ +Some constraints work on a very high level and dictate the ``global shape'' of the module. +They are macroscopic properties of modules that are typiclally defined using local rule. +Their purpose is to provide an unambiguous \textbf{scaffolding} for finer structures to sit in. +These are typically constraints to be found in the ``heartbeat'' section of the specification / \corset{} files. +For instance for stateless modules à la \wcpMod, \addMod, \shfMod, \dots{} they dictate the large scale structure of the trace which dictates what rows are part of the processing of a given instruction, what separates these chunks of rows that pertain to a given instruction processing etc\dots{} + +For these large scale constraints we want a \textbf{uniqueness of scaffolding} property. diff --git a/formal/toy.tex b/formal/toy.tex new file mode 100644 index 0000000..d0d3729 --- /dev/null +++ b/formal/toy.tex @@ -0,0 +1,28 @@ +We considered the following toy example for a first hand-written draft. The purpose is to do formal verification of the adder module and the \inst{ADD} operation in particular. When confronting our (trivial) implementation in constraints to what is happening in some big integer \python{} library there is a need to connect the \zkEvm{} variables (i.e. its columns) to \python{} variables. For the toy example we consider the \textbf{toy-example} of $2$-byte integer addition where the high / low parts are single bytes. Then we must have some correspondence à la +\begin{lstlisting} +py_arg_1 $~\longleftrightarrow~$ zk_arg_1_hi, zk_arg_1_lo +py_arg_2 $~\longleftrightarrow~$ zk_arg_2_hi, zk_arg_2_lo +py_res $~\longleftrightarrow~$ zk_res_hi, zk_res_lo +\end{lstlisting} +We also need to make a connection between the case analysis. Python likely uses some big integer library and does something à la +\begin{Verbatim} +py_comp = py_arg_1 + py_arg_2 >= 256 ** 32 + +if py_comp { + py_res = py_arg_1 + py_arg_2 - 256 ** 32 +} else { + py_res = py_arg_1 + py_arg_2 +} +\end{Verbatim} +While on the \corset{} side we are computing overflows +\begin{Verbatim} +requires( + is_binary(zk_of_0) && + is_binary(zk_of_1) && + is_small(zk_res_hi, 16) && + is_small(zk_res_lo, 16) +) + + zk_arg_1_lo + zk_arg_2_lo = zk_of_0 * 256 ** 16 + zk_res_lo +zk_of_0 + zk_arg_1_hi + zk_arg_2_hi = zk_of_1 * 256 ** 16 + zk_res_hi +\end{Verbatim} diff --git a/formal/tracers.tex b/formal/tracers.tex new file mode 100644 index 0000000..e15651b --- /dev/null +++ b/formal/tracers.tex @@ -0,0 +1,5 @@ +Note that our implementation of the tracers is, modulo implementation errors and spec errors, \textbf{one} way to construct traces which satisfy $\zkEvmConstRel(\fullTrace) \equiv 1$. We produce valid tracing by pegging ourselves to an \evm{} execution client. In a future where the prover is decentralized we must ask: are the traces produced by our tracer implementation essentially unique ? Or are there fundamentally different ways to produce traces $\fullTrace'$ with +\[ + \zkEvmConstRel(\fullTrace') = \mTrue / \mFalse +\] +Our Java implementation of the tracer is \textbf{but one way} to construct objects in the trace space. There is obviously no shortage of objects in the trace space, but the contention is that in some sense there should be, modulo some caveats expounded upon in section~\ref{formal: uniqueness} diff --git a/formal/types.tex b/formal/types.tex new file mode 100644 index 0000000..397c399 --- /dev/null +++ b/formal/types.tex @@ -0,0 +1,11 @@ +Type safety properties must be investigated to a degree where we can ensure the correct behaviour of the \zkEvm{}. The first point is that of \textbf{data provenance}. Data arrives into the \zkEvm{} from different places: +\begin{description} + \item[Block header:] time stamps, coinbase address, block number etc \dots{} arrive through the block data module where they are byte decomposed to prove smallness and well-formedness; + \item[Transactions:] the constraints of the \rlpTxnMod{} ensure that all data contained in the \rlp{} of a transaction are well formed: nonces are $8$-byte integers, addresses are comprised of a $4$-byte high part and a $16$-byte low part, values are $12$-byte integers, gas parameters are $8$ byte integers, call data is split into $16$-byte integers left aligned on the $16$-th byte, transaction types are $0$, $1$ or $2$ (no support for blob transactions), etc \dots{} + \item[State:] and within state data there are several sources: + \begin{description} + \item[Byte code:] upon loading (e.g. in case of a message call transaction into the account, or a \inst{CALL}-type instruction, or a gas-funded \inst{EXTCODECOPY} instruction) relevant bytecode into the \romMod{} it is systematically byte decomposed (to access the bytes directly, label them with the appropriate program counter and perform jump destination analysis); + \item[Account data:] e.g. nonce, balance, codehash, codesize (which we add to the state); + \item[Storage values:] these aren't byte decomposed when loading them; the idea is that the values that end up in storage are either values extracted from the previous state (which are assumed to be fine) or values produced during execution (where all modules that produce data are required to produce data in high and low parts that are $\llarge$-byte integers); + \end{description} +\end{description} diff --git a/formal/uniqueness.tex b/formal/uniqueness.tex new file mode 100644 index 0000000..429d9bf --- /dev/null +++ b/formal/uniqueness.tex @@ -0,0 +1,33 @@ +There are obvious difficulties with uniqueness notions for module traces. Here are some: +\begin{description} + \item[Shape and interpretation:] this is really the purview of the ``levels of analysis'' thread; module constraints should be sufficiently constricting so as to assure a unique scaffolding structure wherein instruction processing may be inserted; + \item[Interpretation:] a related question is that of uniqueness of interpreation: the scaffolding ought to be sufficiently constricting so as to impose a unique interpretation as to what is going on and to prevent situations such as two legitimate readings of a trace where one reading sees one set of instructions with one set of arguments being carried out and another reading sees another set of instructions with another set of arguments; + \item[Order of instructions:] for stateless modules there is no canonical order in which operations have to be tackled; in order to be part of a larger valid proof these modules must perform a minimal set of computations; + \item[Un-requested instructions:] nothing prevents stateless modules from executing junk instructions that no other module requested; this ought not to be a problem as even instructions with inputs that don't conform to constraints shouldn't infect other modules (connected to the present module via lookups) nor should they infect other instructions in the trace; +\end{description} +In its earliest formulation the notion of ``\textbf{essential uniqueness}'' was defined as such, on a module per module basis. Let us come back to the first attempt of defining ``essential uniqueness'' of traces. Take a module \moduleName{} with associated constraint system $\mathcal{C}_\moduleName$. Take a trace $\fullTrace_\moduleName$ which satisfies: +\begin{enumerate} + \item type constraints for \godGiven{} inputs; + \item $\zkEvmModuleRel_{\moduleName}(\fullTrace_\moduleName) = \mTrue$ +\end{enumerate} +Let us assumed that we have established \textbf{uniqueness of scaffolding}. Then we can focus on the computations that fit inside the scaffolding. You can have the following notion of \textbf{essential uniqueness}: the cells that actively participate in the computation are determined by inputs alone. Here we superimpose on the computation which is hopefully captured by the constraint system the idea that some cells represent ``\textbf{inputs}'' while others represent ``\textbf{outputs}''. This is of course a natural point of view but breaks down when you consider the detail of how modules function. Modules typically get their instrutions served with inputs \emph{and} predicted outputs. And in that sense they aren't producing outputs, rather verifying that predicted outputs fit into a constraint system. + +Here is a slightly more precise notion. For a given computation performed by a given module one can, given scaffolding guarantees, identify individual cells as carrying ``inputs'' and others as carrying ``outputs''. Constraints apply globally throughout the trace but may be ``prescriptive'' only in certain circumstances e.g. +\begin{Verbatim}[commandchars=\\\{\}] +(defconstraint set-res-bit () + (begin + \textcolor{gray!75}{;; LT case} + (if-not-zero LT_FLAG + (if-zero COMP_HI + (=! RES_LO COMP_LO) + (=! RES_LO COMP_HI))) + \textcolor{gray!75}{;; GT case} + (if-not-zero GT_FLAG + (if-zero COMP_HI + (=! RES_LO COMP_LO) + (=! RES_LO COMP_HI))) + \textcolor{gray!75}{;; etc ...} +\end{Verbatim} +These constraints will be ``prescriptive'' in the sense that they participate in the definition of an output in case the \col{LT\_FLAG} is on. Then the above constraint is \textbf{active} and \textbf{prescriptive}, while the second constraint isn't. + +The idea is that there should be some sort of \textbf{directed structure}, maybe a directed labeled graph (where the labels are the constraints, and the directedness could be deduced from \corset{} annotations) that ideally digs a directed and uniquely prescriptive path from inputs to outputs. The claim of essential uniqueness is then that the cells of this graph (which are individual cells in a constraint system that fits into the scaffolding) should be uniquely fillable with values that satisfy the constraints labeling the graph with the given ``inputs'' and ``outputs.'' diff --git a/formal/zzz.tex b/formal/zzz.tex new file mode 100644 index 0000000..31b667b --- /dev/null +++ b/formal/zzz.tex @@ -0,0 +1,53 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/thm_env} + +\title{Formal verification of the zk-evm} +\author{Rollup team} +\date{July 2022} + +\begin{document} + +\maketitle +\tableofcontents + +Here's a short list of some things that are crucial for the proper functioning of the zk-evm. These could be interaction points for our teams --- regardless of what collaboration might look like. The first few issues are rather simple, the last one would probably be difficult. Some of these really read like requiring mathematical proof, some of them have the aura of formal verification. +\begin{description} + \item[Correctness of heartbeat constraints.] Every module that cares about temporality (e.g. Stack, RAM, \dots{}) has some \textbf{heartbeat} constraint system. The heartbeat imposes the cadence of operations and columns over different modules behave as expected. Most often it is rather simple, sometimes it's a little more involved (e.g. that of RAM pre-processing). The fact that the constraints achieve precisely the desired outcome is quite crucial to the zk-evm. + \item[Micro-instruction writing.] The Ram preprocessor takes a unique correctness of macro-instruction conversion to a sequence of micro-instructions in the RAM pre-processor. This was painstakingly defined by hand and will soon be implemented. The ``micro-instruction''-writing and the argumentation for it should be formally verifiable; as should be the connection between the prep-processing and the data manipulation. + \item[Existence and essential uniqueness of lexicographic orders.] The zk-evm uses reordering arguments all over the place. Just off of the top of my head: + \begin{enumerate} + \item to prove stack, call stack, memory, storage consistency + \item to justify present knowledge of future events such as reverts / exceptions and the associated time stamps, + \item to establish ``warmth'' of storage keys, + \item to justify the current ``nonce delta'' of an account, + \item to justify running initialization code \emph{before} running any \emph{currently} deployed code, + \item the list goes on \dots{} + \end{enumerate} + The validity of these consistency arguments relies on the essential uniqueness of certain orders defined on row indices in execution traces. These orderings are defined using collections of columns constructed and constrained by the zk-evm. It is crucial that we have certitude that certain subsets of such zk-evm-constructed-sets-of-columns have properties such as ``essential uniqueness of associated lexicographic orders.'' Here by essential uniqueness we mean ''unique up to some `zero-rows'''. + \item[Size constraints.] It is crucial that the zk-evm have perfect control over the size (in bytes) of the data that it computes with. Everything within the zk-evm is represented as field elements (currently the inner field $\Bbb{F} = \Bbb{Z} / r\Bbb{Z}$ of \texttt{bn254}). Representing evm words (256 bit integers) unambiguously requires us to split evm words into subcomponents (limbs) of 16 bytes. Thus the zk-evm should manipulate field elements that are of the form $n\cdot 1_\Bbb{F}$ where $1_\Bbb{F}$ is the unit and $0\leq n < 2^{128}$. Data that enters the zk-evm is expected to be ``small''. Data entry points include: + \begin{enumerate} + \item the ROM (program counter, opcodes, push values), + \item transaction call data + \item block data + \item state data + \end{enumerate} + It seems rather uncontroversial that this data will always be correctly formed (mostly because it undergoes byte-wise construction in, say, the ROM, the Transaction Calldata module etc\dots{}) + + However, this data can at times undergo drastic modificaitons (e.g. in the ALU.) At times ``small'' field elements must be combined in ways that produce large ones (addition, multiplication but also inversion for \texttt{If/Then/Else} statements). It is crucial for the functioning of the zk-evm that these excesses remain confined and that none of these make it onto the stack, into memory, into storage, into the permanent state etc \dots{}. + + Furthermore this formal verification should be field agnostic, in the sense that it should ``easily'' be portable to a different base field (say the Goldilocks field) with a different arithmetization following the same patterns. + % \item[Tricks of the trade.] There's a small set of tricks that we constantly re-use that are the back bone of the arithmetization. These are used for instance for proving stack overflow / underflow, performing comparisons between elements in a short range etc\dots{} + \item[Correctness of the back-end.] We have a back-end that uses gnark field arithmetic to perform column / expression computations. Examples include branching behaviour (with slightly different names, things like \texttt{BOOL.BoolIfTrueElse(CONCLUSION\_IF\_TRUE, CONCLUSION\_IF\_FALSE)}, \texttt{COL.IfZeroElse(CONCLUSION\_IF\_ZERO, CONCLUSION\_IF\_NONZERO)}, \dots{}). Our entire arithmetization relies on this set of methods. It's rather small. + \item[Zk-evm workflow.] We have had to make choices in the zk-evm design. Some of the deeper ones are about the workflow: how and when instructions get executed, when exceptions are raised, by whom etc\dots{} The totality of these choices determine the progression from instruction reading to execution and what to do next. Some of these choices \emph{seem} inconsequential, e.g. how we handle out of bounds jumps or jumps to anything other than a \inst{JUMPDEST} opcode that isn't shadowed by a \inst{PUSH\_X} instruction. The order in which we check for exceptions, and which exception the zk-evm throws and in what order. Our choice (not yet spec-ed out but present in our minds) of \emph{when} to compute gas in the life span of a transaction. The validity of these decisions is clearly important. But this issue is really more about the congruence between our zk-evm $\longleftrightarrow$ Ethereum Yellow Paper. +\end{description} + +\end{document} \ No newline at end of file diff --git a/gas/_all_gas.tex b/gas/_all_gas.tex new file mode 100644 index 0000000..7c37ec7 --- /dev/null +++ b/gas/_all_gas.tex @@ -0,0 +1,59 @@ +\documentclass{article} +\usepackage{xkeyval} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/env} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/oob} +\usepackage{../pkg/warm} +\usepackage{../pkg/misc} +\usepackage{../pkg/scenario} +\usepackage{../pkg/wc3} +\usepackage{../pkg/stp} +\usepackage{../pkg/storage} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/expansion} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/abort} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/txn_data} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/nsr_constants} +\usepackage{marvosym} +\usepackage[normalem]{ulem} +\usepackage{csquotes} +\newcommand{\mSout}[1]{\ifmmode\text{\sout{\ensuremath{#1}}}\else\sout{#1}\fi} + +\usepackage{tocloft} +\addtolength{\cftsecnumwidth}{0pt} +\addtolength{\cftsubsecnumwidth}{10pt} +\addtolength{\cftsubsubsecnumwidth}{10pt} + +\title{\gasMod{} module (v\,2)} +\author{Rollup team} +\date{July 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\renewcommand{\arraystretch}{1.3} + +\input{_inputs} + +\end{document} + + +% Vertical names in columns +% \rotatebox{90}{column name} + diff --git a/gas/_inputs.tex b/gas/_inputs.tex new file mode 100644 index 0000000..4ab1524 --- /dev/null +++ b/gas/_inputs.tex @@ -0,0 +1,7 @@ +\section{Introduction} \label{gas: purpose} \input{intro} +\section{Columns} \label{gas: columns} \input{columns} +\section{Constraints} +\subsection{Heartbeat} \label{gas: heartbeat} \input{heartbeat} +\subsection{Constancy constraints} \label{gas: constancies} \input{constancies} +\subsection{Byte decompositions} \label{gas: byte decompositions} \input{byteDec} +\subsection{Target constraints} \label{gas: target constraints} \input{target} diff --git a/gas/byteDec.tex b/gas/byteDec.tex new file mode 100644 index 0000000..078d126 --- /dev/null +++ b/gas/byteDec.tex @@ -0,0 +1,6 @@ +We impose byte decomposition constraints for the pairs $(\byteCol{k}, \acc{k})$, where $k = 1, 2$: +\begin{enumerate} + \item $\byteCol{k}$ contains bytes; + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i - 1} + \byteCol{k}_{i}$; +\end{enumerate} diff --git a/gas/columns.tex b/gas/columns.tex new file mode 100644 index 0000000..135b913 --- /dev/null +++ b/gas/columns.tex @@ -0,0 +1,16 @@ +\begin{enumerate} + \item \gasStamp: + stamp column of the present module; + \item \ct: + counter column; + \item \gasActual: \godGiven{} + \ccc{} containing the gas amount (a small integer) available to the instruction triggering the present module; + \item \gasCost: \godGiven{} + small integer containing the (preliminary) gas cost of the instruction triggering the present module; + \item \oogx: \godGiven{} + binary column indicating whether or not the present instruction will trigger an \oogxSH{}; + \item \byteCol{1} and \byteCol{2}: + byte columns; + \item \acc{1} and \acc{2}: + associated accumulator columns; +\end{enumerate} diff --git a/gas/constancies.tex b/gas/constancies.tex new file mode 100644 index 0000000..6549ed1 --- /dev/null +++ b/gas/constancies.tex @@ -0,0 +1,12 @@ +As usual we declare a column \col{X} to be \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We impose \textbf{counter-constancy} on the following columns: +\begin{multicols}{3} +\begin{enumerate} + \item \gasActual{} + \item \gasCost{} + \item \oogx{} +\end{enumerate} +\end{multicols} diff --git a/gas/heartbeat.tex b/gas/heartbeat.tex new file mode 100644 index 0000000..0e4d74a --- /dev/null +++ b/gas/heartbeat.tex @@ -0,0 +1,30 @@ +The heartbeat of the present module is simple: every call to it occupies $\eight{}$ rows. +\begin{enumerate} + \item $\gasStamp_{0} = 0$; + \item \If $\gasStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \ct _{i} & = & 0 \\ + \byteCol{1} _{i} & = & 0 \\ + \byteCol{2} _{i} & = & 0 \\ + \end{array} \right. + \qquad\text{and}\qquad + \left\{ \begin{array}{lcl} + \gasActual _{i} & = & 0 \\ + \gasCost _{i} & = & 0 \\ + \oogx _{i} & = & 0 \\ + \end{array} \right. + \] + \item $\gasStamp$ is nondecreasing in the sense that $\gasStamp_{i + 1} \in \{ \gasStamp_{i}, 1 + \gasStamp_{i} \}$; + \item \If $\gasStamp_{i + 1} \neq \gasStamp_{i}$ \Then $\ct_{i + 1} = 0$; + \item \If $\gasStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \eightMO$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \eightMO$ \Then $\gasStamp_{i + 1} = 1 + \gasStamp_{i}$ + \end{enumerate} + \item \If $\gasStamp_{N} \neq 0$ \Then $\ct_{N} = \eightMO$. +\end{enumerate} +On an unrelated note: +\begin{enumerate}[resume] + \item we further impose that \oogx{} be binary. +\end{enumerate} diff --git a/gas/intro.tex b/gas/intro.tex new file mode 100644 index 0000000..ccaf8e5 --- /dev/null +++ b/gas/intro.tex @@ -0,0 +1,6 @@ +The purpose of the present \gasMod{} module is very simple. +Whenever the \cmc{} flag lights up in the \hubMod{}, the present module is called upon and tasked with checking that +(\emph{a}) +the currently available gas after any potential refunds (i.e. \gasActual{}) is nonnegative +(\emph{b}) +checking the \stackOogx{} flag in terms of \gasActual{} and \gasCost{}. The only \emph{actual} work carried out by the present module are byte decompositions. diff --git a/gas/target.tex b/gas/target.tex new file mode 100644 index 0000000..51906a4 --- /dev/null +++ b/gas/target.tex @@ -0,0 +1,10 @@ +We impose the following: +\begin{enumerate} + \item \If $\ct_{i} = \eightMO$ \Then + \[ + \left\{ \begin{array}{lcl} + \acc{1}_{i} & = & \gasActual_{i} \\ + \acc{2}_{i} & = & \big(2 \cdot \oogx_{i} - 1\big) \cdot \Big[ \gasCost_{i} - \gasActual_{i}\Big] - \oogx_{i} \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/generic/data/_all_generic_data.tex b/generic/data/_all_generic_data.tex new file mode 100644 index 0000000..134e041 --- /dev/null +++ b/generic/data/_all_generic_data.tex @@ -0,0 +1,30 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../../pkg/common} +% \usepackage{../../pkg/dark_theme} +\usepackage{../../pkg/std} +\usepackage{../../pkg/IEEEtrantools} +\usepackage{../../pkg/rom} +\usepackage{../../pkg/ram} +\usepackage{../../pkg/comparisons} +\usepackage{../../pkg/call_stack} +\usepackage{../../pkg/stack} +\usepackage{../../pkg/expansion} +\usepackage{../../pkg/precompiles} +\usepackage{../../pkg/public} +\usepackage{../../pkg/offset_processor} +\usepackage{../../pkg/flags_stamps_selectors} +\usepackage{../../pkg/env} + +\title{Generic data module} +\author{Rollup team} +\date{August 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/generic/data/_inputs.tex b/generic/data/_inputs.tex new file mode 100644 index 0000000..0047173 --- /dev/null +++ b/generic/data/_inputs.tex @@ -0,0 +1,3 @@ +\section{Purpose} \input{purpose} +\section{Columns} \input{columns} +\section{Heartbeat} \input{heartbeat} diff --git a/generic/data/columns.tex b/generic/data/columns.tex new file mode 100644 index 0000000..d6c4765 --- /dev/null +++ b/generic/data/columns.tex @@ -0,0 +1,7 @@ +\begin{enumerate} +\item $\gms$: generic module stamp; +\item $\index$: index column; the index counts monotonically up from $0$ to arbitrary values; +\item $\limb$: limb column; limbs are 16 byte integers; +\item $\nBytes$: size parameter; +\end{enumerate} +There may be more columns (e.g. columns signaling the nature of the data being recorded if several different interpretations are possible, such as differentiating inputs of \texttt{SHA2-256} from inputs to \texttt{RIPEMD-160}.) diff --git a/generic/data/heartbeat.tex b/generic/data/heartbeat.tex new file mode 100644 index 0000000..5e64913 --- /dev/null +++ b/generic/data/heartbeat.tex @@ -0,0 +1,20 @@ + +The heartbeat of the present module falls in line with that of many other modules: it has a stamp that counts monotonically up from 0 jumping by 1 every time an instruction has been dealt with. We further have a counter column with a cycle length of $\ssmall$. + +\begin{enumerate} + \item $\gms_{0} = 0$ + \item \If $\gms_{i} = 0$ \Then + \[ + \begin{cases} + \index_{i} = 0 \\ + \limb{i} = 0 \\ + \nBytes{i} = 0 \\ + \end{cases} + \] +\end{enumerate} +There are two use possibilites for the module stamp: either its jumps are predictable and always $=1$ (i.e. $\gms_{i + 1} \in \{\gms_{i}, 1 + \gms_{i}\}$) or they may be erratic but small. When this is the case a module may add a byte column and an accumulator column to accumulate (say) 4 bytes and express the jumps in $\gms$ as positive 4 byte integers (i.e. \If $\gms_{i + 1} \neq \gms_{i} $ \Then $\gms_{i + 1} = \gms_{i} + 1 + \ACC_{i + 4}$ or similar.) +\begin{enumerate}[resume] + \item \If $\gms_{i} \neq \gms_{i + 1}$ \Then $\index{i + 1} = 0$; + \item \If $\gms_{i} \neq 0$ \et $\gms_{i} = \gms_{i + 1}$ \Then $\index{i + 1} = 1 + \index_{i}$. +\end{enumerate} + diff --git a/generic/data/purpose.tex b/generic/data/purpose.tex new file mode 100644 index 0000000..63f8584 --- /dev/null +++ b/generic/data/purpose.tex @@ -0,0 +1,3 @@ +The purpose of this generic data module is to provide a framework which is applicable to most data module that are left unspecified in the present specification. The purpose of a data module is to store data with a common destiny or purpose. For instance all data that is to be passed onto the \texttt{KECCAK} circuit, or the data of all logs. Most of these data modules are generic and fall into a set pattern. Others are more involved (the prime example being the +\ecDataMod{} which does a lot of data processing before sending it off to the Elliptic Curve circuits.) Data modules usually work in conjunction with Info modules. These will record the outputs of the operations performed on the data from the associated data module. Such info modules may also record special events (such as the primitive in question encountering an error, typically this means that it returns +``$\varnothing$''.) diff --git a/generic/info/_all_generic_info.tex b/generic/info/_all_generic_info.tex new file mode 100644 index 0000000..1e07fd2 --- /dev/null +++ b/generic/info/_all_generic_info.tex @@ -0,0 +1,29 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../../pkg/common} +% \usepackage{../../pkg/dark_theme} +\usepackage{../../pkg/std} +\usepackage{../../pkg/IEEEtrantools} +\usepackage{../../pkg/rom} +\usepackage{../../pkg/ram} +\usepackage{../../pkg/comparisons} +\usepackage{../../pkg/call_stack} +\usepackage{../../pkg/stack} +\usepackage{../../pkg/expansion} +\usepackage{../../pkg/precompiles} +\usepackage{../../pkg/public} +\usepackage{../../pkg/offset_processor} +\usepackage{../../pkg/env} + +\title{Generic info module} +\author{Rollup team} +\date{July 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/generic/info/_inputs.tex b/generic/info/_inputs.tex new file mode 100644 index 0000000..701686e --- /dev/null +++ b/generic/info/_inputs.tex @@ -0,0 +1,3 @@ +\section{Purpose} \input{purpose} +\section{Columns} \input{columns} +% \section{Heartbeat} \input{heartbeat} diff --git a/generic/info/columns.tex b/generic/info/columns.tex new file mode 100644 index 0000000..e578748 --- /dev/null +++ b/generic/info/columns.tex @@ -0,0 +1,13 @@ +\begin{enumerate} +\item $\gms$: generic module stamp; +\end{enumerate} +This is the same as the one from the associated data module. There may be discrepancies between the two stamps: instructions that for instance don't require touching RAM (say because they have a zero size parameter) may not trigger the associated data module. This applies for instance to hash functions but also logs with zero size parameter. + +The other columns that appear in generic info modules depend on the module at hand. They may include the following: +\begin{enumerate}[resume] +\item $\size$: a size parameter; +\item $\addr$: an address parameter; +\item $\col{VAL}\high, \col{VAL}\low$: some value parameter, e.g. the output of a hash; +\item other parameters (e.g. log topics etc \dots). +\end{enumerate} +There may be more columns (e.g. columns signaling the nature of the data being recorded if several different interpretations are possible, such as differentiating inputs of \texttt{SHA2-256} from inputs to \texttt{RIPEMD-160}.) diff --git a/generic/info/heartbeat.tex b/generic/info/heartbeat.tex new file mode 100644 index 0000000..e69de29 diff --git a/generic/info/purpose.tex b/generic/info/purpose.tex new file mode 100644 index 0000000..d7d50d9 --- /dev/null +++ b/generic/info/purpose.tex @@ -0,0 +1,6 @@ +The purpose of \textbf{info} modules is to +\begin{enumerate} +\item record the output associated with a data slice from the associated data module; +\item record the output whenever the output is known in advance (e.g. the data slice provided is empty and the output is known in advance, this applies to certain precompiles such as \texttt{ECRECOVER}, \texttt{ECPAIRING}, \texttt{SHA2-256}, \texttt{RIPEMD} and opcodes such as \texttt{KEC}) +\item record auxiliary data associated (e.g. for logs the associated \col{LogMod} module records the logger address, the 0 to 4 topics and the data size of the data to be logged.) +\end{enumerate} diff --git a/hash_data/_all_hash_data.tex b/hash_data/_all_hash_data.tex new file mode 100644 index 0000000..c500deb --- /dev/null +++ b/hash_data/_all_hash_data.tex @@ -0,0 +1,41 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/wc3} +\usepackage{../pkg/stack} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/modexp} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/expansion} +\usepackage{../pkg/iomf_done} +\usepackage{fontawesome} +\usepackage{../pkg/exponent} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/flags_stamps_selectors} +%\usepackage{twemoji} +%\usepackage{marvosym} +%\usepackage{../pkg/emoji} + +\title{The \hashDataMod{} module} +\author{Rollup team} +\date{September 2022} + +\begin{document} +%\setemojifont{TwemojiMozilla} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} + + + diff --git a/hash_data/_inputs.tex b/hash_data/_inputs.tex new file mode 100644 index 0000000..6b63b44 --- /dev/null +++ b/hash_data/_inputs.tex @@ -0,0 +1,8 @@ +\section{The \hashDataMod{} module} +% +\subsection{Introduction} \label{hash data: introduction} \input{intro} +\subsection{Columns} \label{hash data: columns} \input{columns} +% +\section{General constraints} +\subsection{Constraints} \label{hash data: constraints} \input{constraints} +\subsection{Graphical representation} \label{hash info: representation} \input{representation} diff --git a/hash_data/columns.tex b/hash_data/columns.tex new file mode 100644 index 0000000..bdd8eec --- /dev/null +++ b/hash_data/columns.tex @@ -0,0 +1,17 @@ +\begin{enumerate} + \item \hashInfoStamp{}: + stamp of the present module; + increments by one with every new hash request; + \item \hashInfoSize{}: + column containing the size in bytes of the data to hash; + \item \limb{}: + data limb extracted from \textsc{ram}; + \item \index{}: + associated index in the overall slice of bytes to be hashed; + \item \nBytes{}: + number of relevant bytes in the limb; + with values in $\{ 1, 2, \dots, \llarge \}$ + \item \nBytesAcc{}: + accumulator of the \nBytes{} column; +\end{enumerate} + diff --git a/hash_data/constraints.tex b/hash_data/constraints.tex new file mode 100644 index 0000000..ac7b894 --- /dev/null +++ b/hash_data/constraints.tex @@ -0,0 +1,32 @@ +We impose the following constraints: +\begin{enumerate} + \item $\hashInfoStamp_{0} = 0$ + \item \If $\hashInfoStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \hashInfoSize _{i} & = & 0 \\ + \limb _{i} & = & 0 \\ + \nBytes _{i} & = & 0 \\ + \nBytesAcc _{i} & = & 0 \\ + \end{array} \right. + \] + \item $\hashInfoStamp_{i + 1} \in \{ \hashInfoStamp_{i}, 1 + \hashInfoStamp_{i} \}$ + \item \If $\hashInfoStamp_{i} \neq \hashInfoStamp_{i - 1}$\footnote{In other words: \If $\hashInfoStamp_{i} = 1 + \hashInfoStamp_{i - 1}$} \Then + \begin{enumerate} + \item $\hashInfoSize_{i - 1} = \nBytesAcc_{i - 1}$ + \item $\nBytesAcc_{i} = \nBytes_{i}$ + \item $\index_{i} = 0$ + \end{enumerate} + \item \If $\hashInfoStamp_{i} \neq 1 + \hashInfoStamp_{i - 1}$\footnote{In other words: \If $\hashInfoStamp_{i} = \hashInfoStamp_{i - 1}$} \Then + \begin{enumerate} + \item $\nBytesAcc_{i} = \nBytesAcc_{i - 1} + \nBytes_{i}$ + \item $\hashInfoSize_{i} = \hashInfoSize_{i - 1}$ + \item \If $\hashInfoStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item $\nBytes_{i - 1} = \llarge$ \quad (\trash) + \item $\index_{i} = 1 + \index_{i - 1}$ + \end{enumerate} + \end{enumerate} + \item $\hashInfoSize_{N} = \nBytesAcc_{N}$ +\end{enumerate} +\saNote{} We \emph{could} add a ``nontriviality'' constraint such as ``\If $\hashInfoStamp_{i} \neq 0$ \Then $\hashInfoSize_{i} \neq 0$'', but there is no real point in doing so. diff --git a/hash_data/intro.tex b/hash_data/intro.tex new file mode 100644 index 0000000..95282fc --- /dev/null +++ b/hash_data/intro.tex @@ -0,0 +1,2 @@ +The present module is the sister module to the \hashInfoMod{}. +It collects the data limbs of nontrivial (\texttt{KECCAK}) hashes that the \zkEvm{} has to perform. diff --git a/hash_data/lua/layout.lua.tex b/hash_data/lua/layout.lua.tex new file mode 100644 index 0000000..036ad62 --- /dev/null +++ b/hash_data/lua/layout.lua.tex @@ -0,0 +1,89 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} +| HASH_ | SIZE | KEC_HI | KEC_LO | +|--------+------+----------------------------------+----------------------------------| +| 0 | 0 | 0 | 0 | +| ... | ... | ... | ... | +| 0 | 0 | 0 | 0 | +|--------+------+----------------------------------+----------------------------------| +| 1 | 64 | 55c1c6f5e77d1fdeb61b40a6175870ec | f7d1534484d68c4c4516ce7ff4ae62bf | +|--------+------+----------------------------------+----------------------------------| +| 2 | 4 | 814ebd544fae2430fa8b259db3fbbc10 | 26a7a4e4d37bc1b12f14619c3af648f3 | +|--------+------+----------------------------------+----------------------------------| +| 3 | 12 | 2dfcd1cff4187119cab28b825ad73410 | 1c0108261b3189e039d011a07388c625 | +|--------+------+----------------------------------+----------------------------------| +| 4 | 38 | 892f994800ab29336cf88e9478d79789 | 47b44675b3a4962486d6a1bcf2a93ff3 | +|--------+------+----------------------------------+----------------------------------| +| 5 | 13 | 29bcc98ecae373e25c67a4bbd97bc114 | a7524dc68fcfc6bbe178d90412a30726 | +|--------+------+----------------------------------+----------------------------------| +| 6 | 1 | e3f0ae350ee09657933cd8202a4dd563 | c5af941f8054e6d7191e3246be378290 | +|--------+------+----------------------------------+----------------------------------| +| 7 | 16 | 3ab96d3f576e4b3858295aa57b9c7264 | 6b0b8b03c77643ff67749ccc5ade3a7d | +|--------+------+----------------------------------+----------------------------------| +| ... | ... | ... | ... | +\end{verbatim} + +\begin{verbatim} +| HASH_ | SIZE | LIMB | INDEX | nBYTES | nBYTES_ACC | +|--------+------+----------------------------------+-------+--------+------------| +| 0 | 0 | 0 | 0 | 0 | 0 | +| ... | ... | ... | ... | ... | ... | +| 0 | 0 | 0 | 0 | 0 | 0 | +|--------+------+----------------------------------+-------+--------+------------| +| 1 | 64 | f1329f5e816bb16421863dfcc505b144 | 0 | 16 | 16 | +| 1 | 64 | 4e264b6c68f3224f098bb510000eb18e | 1 | 16 | 32 | +| 1 | 64 | 9664577b9f593da0cc8fb905e852e6c3 | 2 | 16 | 48 | +| 1 | 64 | 9fbf1efe57bfb71f8fe9f2b462bac394 | 3 | 16 | 64 | +|--------+------+----------------------------------+-------+--------+------------| +| 2 | 4 | 31373839000000000000000000000000 | 0 | 4 | 4 | +|--------+------+----------------------------------+-------+--------+------------| +| 3 | 12 | 47726f7468656e646965636b00000000 | 0 | 12 | 12 | +|--------+------+----------------------------------+-------+--------+------------| +| 4 | 38 | a8f07526a6f60178d7535820352e655e | 0 | 16 | 16 | +| 4 | 38 | d5243059e52686509aa11898f12d6795 | 1 | 16 | 32 | +| 4 | 38 | f6adfb03999100000000000000000000 | 2 | 6 | 38 | +|--------+------+----------------------------------+-------+--------+------------| +| 5 | 13 | 636174656e6172792072696e67000000 | 13 | 13 | 13 | +|--------+------+----------------------------------+-------+--------+------------| +| 6 | 1 | 00000000000000000000000000000000 | 0 | 1 | 1 | +|--------+------+----------------------------------+-------+--------+------------| +| 7 | 16 | 00000000000000000000000000000000 | 0 | 16 | 16 | +|--------+------+----------------------------------+-------+--------+------------| +| ... | ... | ... | ... | | | +\end{verbatim} +\end{document} + +\iffalse +random' <=> f1329f5e816bb16421863dfcc505b144 4e264b6c68f3224f098bb510000eb18e 9664577b9f593da0cc8fb905e852e6c3 9fbf1efe57bfb71f8fe9f2b462bac394 +1789 <=> 31373839 +Grothendieck <=> 47726f7468656e646965636b +random <=> a8f07526a6f60178d7535820352e655e d5243059e52686509aa11898f12d6795 f6adfb039991 +catenary ring <=> 636174656e6172792072696e67 +oneZero <=> 00 +sixteenZeros <=> 00000000000000000000000000000000 + +KECCAK256(random') = 55c1c6f5e77d1fdeb61b40a6175870ec | f7d1534484d68c4c4516ce7ff4ae62bf +KECCAK256(1789) = 814ebd544fae2430fa8b259db3fbbc10 | 26a7a4e4d37bc1b12f14619c3af648f3 +KECCAK256(Grothendieck) = 2dfcd1cff4187119cab28b825ad73410 | 1c0108261b3189e039d011a07388c625 +KECCAK256(random) = 892f994800ab29336cf88e9478d79789 | 47b44675b3a4962486d6a1bcf2a93ff3 +KECCAK256(catenary ring) = 29bcc98ecae373e25c67a4bbd97bc114 | a7524dc68fcfc6bbe178d90412a30726 +KECCAK256(oneZero) = e3f0ae350ee09657933cd8202a4dd563 | c5af941f8054e6d7191e3246be378290 +KECCAK256(sixteenZeros) = 3ab96d3f576e4b3858295aa57b9c7264 | 6b0b8b03c77643ff67749ccc5ade3a7d +\fi diff --git a/hash_data/representation.tex b/hash_data/representation.tex new file mode 100644 index 0000000..60f99e2 --- /dev/null +++ b/hash_data/representation.tex @@ -0,0 +1 @@ +\includepdf[fitpaper=true, pages={2}]{lua/layout.pdf} diff --git a/hash_info/_all_hash_info.tex b/hash_info/_all_hash_info.tex new file mode 100644 index 0000000..07abb69 --- /dev/null +++ b/hash_info/_all_hash_info.tex @@ -0,0 +1,40 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/wc3} +\usepackage{../pkg/stack} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/modexp} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/expansion} +\usepackage{../pkg/iomf_done} +\usepackage{fontawesome} +\usepackage{../pkg/exponent} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/flags_stamps_selectors} +%\usepackage{twemoji} +%\usepackage{marvosym} +%\usepackage{../pkg/emoji} + +\title{The \hashInfoMod{} module} +\author{Rollup team} +\date{September 2022} + +\begin{document} +%\setemojifont{TwemojiMozilla} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} + + diff --git a/hash_info/_inputs.tex b/hash_info/_inputs.tex new file mode 100644 index 0000000..7ebe3b3 --- /dev/null +++ b/hash_info/_inputs.tex @@ -0,0 +1,9 @@ +\section{The \hashInfoMod{} module} +% +\subsection{Introduction} \label{hash info: introduction} \input{intro} +\subsection{Columns} \label{hash info: columns} \input{columns} +% +\section{General constraints} +\subsection{Constraints} \label{hash info: constraints} \input{constraints} +\subsection{Lookup to \hashDataMod{}} \label{hash info: lookup} \input{lookup} +\subsection{Graphical representation} \label{hash info: representation} \input{representation} diff --git a/hash_info/columns.tex b/hash_info/columns.tex new file mode 100644 index 0000000..438b787 --- /dev/null +++ b/hash_info/columns.tex @@ -0,0 +1,9 @@ +\begin{enumerate} + \item \hashInfoStamp{}: + stamp of the present module; + increments by one with every new hash request; + \item \hashInfoSize{}: + column containing the size in bytes of the data to hash; + \item \hashInfoValHi{}, \hashInfoValLo{}: + column containing the high and low part respectively of the hash of the input data; +\end{enumerate} diff --git a/hash_info/constraints.tex b/hash_info/constraints.tex new file mode 100644 index 0000000..38393bc --- /dev/null +++ b/hash_info/constraints.tex @@ -0,0 +1,14 @@ +We impose the following constraints: +\begin{enumerate} + \item $\hashInfoStamp_{0} = 0$ + \item \If $\hashInfoStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \hashInfoSize _{i} & = & 0 \\ + \hashInfoValHi _{i} & = & 0 \\ + \hashInfoValLo _{i} & = & 0 \\ + \end{array} \right. + \] + \item $\hashInfoStamp_{i + 1} \in \{ \hashInfoStamp_{i}, 1 + \hashInfoStamp_{i} \}$ +\end{enumerate} +\saNote{} We \emph{could} add a ``nontriviality'' constraint such as ``\If $\hashInfoStamp_{i} \neq 0$ \Then $\hashInfoSize_{i} \neq 0$'', but there is no real point in doing so. diff --git a/hash_info/intro.tex b/hash_info/intro.tex new file mode 100644 index 0000000..c7e61e9 --- /dev/null +++ b/hash_info/intro.tex @@ -0,0 +1,5 @@ +The present \hashInfoMod{} module is a tiny and very simple module used only to record the (predicted) output of various (nontrivial) \texttt{KECCAK} hashes required by the \zkEvm{}. +There are three scenarios that require such hashes: +(\emph{a}) the execution of an \textbf{unexceptional} \inst{SHA3} opcode provided with \textbf{nonempty input data} +(\emph{b}) the execution of an \textbf{unexceptional} and \textbf{unaborted} \inst{CREATE2} opcode provided with \textbf{nonempty initialization code} +(\emph{c}) the execution of an \textbf{unexceptional} \inst{RETURN} opcode in a deployment context which deploys \textbf{nonempty byte code}. diff --git a/hash_info/lookup.tex b/hash_info/lookup.tex new file mode 100644 index 0000000..41396b9 --- /dev/null +++ b/hash_info/lookup.tex @@ -0,0 +1,18 @@ +For coherence we impose the following lookup to the \hashDataMod{} module +\begin{description} + \item[\underline{Selector:}] none is required; + \item[\underline{Source columns:}] + \begin{multicols}{2} + \begin{enumerate} + \item \hashInfoStamp + \item \hashInfoSize + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] + \begin{multicols}{2} + \begin{enumerate} + \item \hashDataStamp + \item \hashInfoSize + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hash_info/representation.tex b/hash_info/representation.tex new file mode 100644 index 0000000..51ab3a1 --- /dev/null +++ b/hash_info/representation.tex @@ -0,0 +1 @@ +\includepdf[fitpaper=true, pages={2}]{../hash_data/lua/layout.pdf} diff --git a/how_to_hub.md b/how_to_hub.md new file mode 100644 index 0000000..2ec97a4 --- /dev/null +++ b/how_to_hub.md @@ -0,0 +1,21 @@ +Adding more and more constraints to the mix: +- github issue per instruction family +- échaffaudage (heartbeat) +- triggering modules through the HUB rather than module by module with TracePreOpCode() + - Q: what is the impact of doing this module by module ? + - Concretely: more signals + - Clear advantage: closer to the constraints and the expected triggering conditions +- update the instruction decoder + - certain things changed in the DECODED_FLAG's +- DOM / SUB stamps +- connexions: + - OOB + - MXP + - STP + - EXP + - MMU +- simple instruction families: + - everything arithmetic + - batch data & BLOCKHASH + - +- duplicate the HUB spec's setXxxInstructionBlaBla methods in the Java implementation diff --git a/hub/_all_hub.tex b/hub/_all_hub.tex new file mode 100644 index 0000000..8a1c233 --- /dev/null +++ b/hub/_all_hub.tex @@ -0,0 +1,77 @@ +\documentclass[fleqn]{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{fontspec} +\usepackage{xkeyval} +\usepackage{../pkg/std} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/env} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/oob} +\usepackage{../pkg/warm} +\usepackage{../pkg/misc} +\usepackage{../pkg/xkeyval_macros/context} +\usepackage{../pkg/xkeyval_macros/dom_sub_stamps} +\usepackage{../pkg/xkeyval_macros/mmu_instructions} +\usepackage{../pkg/xkeyval_macros/mxp_instructions} +\usepackage{../pkg/xkeyval_macros/oob_instructions} +\usepackage{../pkg/xkeyval_macros/stp_instructions} +\usepackage{../pkg/scenario} +\usepackage{../pkg/wc3} +\usepackage{../pkg/stp} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/block_hash} +\usepackage{../pkg/exponent} +\usepackage{../pkg/storage} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/stack} +\usepackage{../pkg/expansion} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/prc} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/abort} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/txn_data} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/log_info} +\usepackage{../pkg/nsr_constants} +\usepackage{../pkg/subsubsubsection} +\usepackage{../pkg/mmu} +\usepackage{../pkg/mmu_custom_instructions} +\usepackage{marvosym} +\usepackage[normalem]{ulem} +\usepackage{csquotes} +\usepackage{tabularx} +\usepackage{svg} +\newcommand{\mSout}[1]{\ifmmode\text{\sout{\ensuremath{#1}}}\else\sout{#1}\fi} + +\usepackage{../pkg/draculatheme} +% \usepackage{darkmode}[enable=true] + +\usepackage{tocloft} +\addtolength{\cftsecnumwidth}{0pt} +\addtolength{\cftsubsecnumwidth}{10pt} +\addtolength{\cftsubsubsecnumwidth}{10pt} + +\title{The \hubMod{} module} +\author{Rollup team} +\date{July 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\renewcommand{\arraystretch}{1.3} + +\input{_inputs} + +\end{document} diff --git a/hub/_inputs.tex b/hub/_inputs.tex new file mode 100644 index 0000000..089d090 --- /dev/null +++ b/hub/_inputs.tex @@ -0,0 +1,24 @@ +\input{_local} +\input{../exp/_local} +\input{../oob/_local} +\input{instruction_handling/call/precompiles/_local} +\input{scenario/tables/_local} + +\section{Introduction} \label{hub: intro} \input{intro} + +\input{columns/_inputs} % Done +\input{heartbeat/_inputs} % Done +\input{generalities/_inputs} % Done +\input{stack/_inputs} % Done +\input{context/_inputs} % Done +\input{account/_inputs} % Done +\input{storage/_inputs} % Done +\input{misc/_inputs} % Todo +\input{scenario/_inputs} % Wip +\input{tx_skip/_inputs} % Done +\input{tx_prewarm/_inputs} % Done +\input{tx_init/_inputs} % Done +\input{instruction_handling/_inputs} % Wip +\input{tx_finl/_inputs} % Done +\input{consistencies/_inputs} % Wip +\input{lookups/_inputs} % Wip diff --git a/hub/_local.tex b/hub/_local.tex new file mode 100644 index 0000000..c998475 --- /dev/null +++ b/hub/_local.tex @@ -0,0 +1,64 @@ +\def\locCallX {\col{call\_exception}} +\def\gZero {\graym{0}} +\def\rZero {\redm{0}} +\def\one {\redm{1}} + +\def\locCallAborts {\col{call\_aborts}} +\def\locCalleeIsPrecompile {\col{callee\_is\_precompile}} +\def\locCalleeHasCode {\col{callee\_has\_code}} +\def\locCalleeWarmth {\col{callee\_warmth}} +\def\locCalleeExists {\col{callee\_exists}} +\def\locCalleeSelfReverts {\col{callee\_self\_reverts}} +\def\locCalleeRevertStamp {\col{callee\_revert\_stamp}} +\def\locCallerWillRevert {\col{caller\_will\_revert}} +\def\locCallerRevertStamp {\col{caller\_revert\_stamp}} + +\def\locValue {\col{transfer\_value}} +\def\locUpfrontCallCost {\col{caller\_upfront\_gas\_cost}} +\def\locCalleeGasPoop {\col{callee\_63/64\_ths}} +\def\locCalleeGasStipend {\col{callee\_gas\_stipend}} +\def\locValue {\col{value\_param}} +\def\locValueHi {\locValue\col{\_hi}} +\def\locValueLo {\locValue\col{\_lo}} +\def\locGas {\col{gas\_param}} +\def\locGasHi {\locGas\col{\_hi}} +\def\locGasLo {\locGas\col{\_lo}} +\def\locSuccessBit {\col{success\_bit}} +\def\locSuccessBitHi {\locSuccessBit\col{\_hi}} +\def\locSuccessBitLo {\locSuccessBit\col{\_lo}} +\def\locRawAddr {\col{raw\_address}} +\def\locRawAddrLo {\locRawAddr\col{\_lo}} +\def\locRawAddrHi {\locRawAddr\col{\_hi}} + +\def\locCallersAccountAddressHi {\col{caller's\_account\_addr\_hi}} +\def\locCallersAccountAddressLo {\col{caller's\_account\_addr\_lo}} +\def\locCallersAccountDepNumber {\col{caller's\_account\_dep\_num}} +\def\locCallersCallerAddressHi {\col{caller's\_caller\_addr\_hi}} +\def\locCallersCallerAddressLo {\col{caller's\_caller\_addr\_lo}} +\def\locCallersCallValue {\col{caller's\_call\_value}} +\def\locToAddressHi {\col{to\_addr\_hi}} +\def\locToAddressLo {\col{to\_addr\_lo}} +\def\locToDepNumber {\col{to\_dep\_number}} +\def\locToDepStatus {\col{to\_dep\_status}} + +\def\locInstIsCall {\col{inst\_is\_call}} +\def\locInstIsCallcode {\col{inst\_is\_callcode}} +\def\locInstIsDelegatecall {\col{inst\_is\_delegatecall}} +\def\locInstIsStaticcall {\col{inst\_is\_staticcall}} + +\def\locIsStatic {\col{caller\_context\_is\_static}} + +\def\locCdo {\col{cdo}} +\def\locCds {\col{cds}} +\def\locRao {\col{r@o}} +\def\locRac {\col{r@c}} + +\def\locInst {\col{instruction}} +\def\locCdoLo {\locCdo\col{\_param\_lo}} +\def\locCdoHi {\locCdo\col{\_param\_hi}} +\def\locCdsLo {\locCds\col{\_param\_lo}} +\def\locCdsHi {\locCds\col{\_param\_hi}} +\def\locRaoLo {\locRao\col{\_param\_lo}} +\def\locRaoHi {\locRao\col{\_param\_hi}} +\def\locRacLo {\locRac\col{\_param\_lo}} +\def\locRacHi {\locRac\col{\_param\_hi}} diff --git a/hub/account/_inputs.tex b/hub/account/_inputs.tex new file mode 100644 index 0000000..0c3159c --- /dev/null +++ b/hub/account/_inputs.tex @@ -0,0 +1,4 @@ +\section{Account-rows} +\subsection{Specialized constraints \lispTodo{}} \label{hub: account: state access} \input{account/specialized_constraints/_inputs} +\subsection{Code ownership (\accHasCode) constraints \lispDone{}} \label{hub: account: empty code} \input{account/empty_code} +\subsection{Account existence (\accExists{} and $\accExists\new$) constraints \lispDone{}} \label{hub: account: account existence} \input{account/existence} diff --git a/hub/account/_local.tex b/hub/account/_local.tex new file mode 100644 index 0000000..e69de29 diff --git a/hub/account/empty_code.tex b/hub/account/empty_code.tex new file mode 100644 index 0000000..d319231 --- /dev/null +++ b/hub/account/empty_code.tex @@ -0,0 +1,21 @@ +\begin{center} +\boxed{\text{All constraints in this subsection assume that $\peekAccount_{i} = 1$.}} +\end{center} +We specify the behaviour of the columns $\accHasCode$ which indicate code emptyness: +\begin{enumerate} + \item \If $\accCodehash\high_{i} \neq \emptyKeccakHi$ \Then $\accHasCode_{i} = 1$ + \item \If $\accCodehash\high_{i} = \emptyKeccakHi$ \Then + \begin{enumerate} + \item \If $\accCodehash\low_{i} \neq \emptyKeccakLo$ \Then $\accHasCode_{i} = 1$ + \item \If $\accCodehash\low_{i} = \emptyKeccakLo$ \Then $\accHasCode_{i} = 0$ + \end{enumerate} +\end{enumerate} +We enforce the analogous constraints for $\accHasCode\new$: +\begin{enumerate} + \item \If $\accCodehash\new{}\high_{i} \neq \emptyKeccakHi$ \Then $\accHasCode\new_{i} = 1$ + \item \If $\accCodehash\new{}\high_{i} = \emptyKeccakHi$ \Then + \begin{enumerate} + \item \If $\accCodehash\new{}\low_{i} \neq \emptyKeccakLo$ \Then $\accHasCode\new_{i} = 1$ + \item \If $\accCodehash\new{}\low_{i} = \emptyKeccakLo$ \Then $\accHasCode\new_{i} = 0$ + \end{enumerate} +\end{enumerate} diff --git a/hub/account/existence.tex b/hub/account/existence.tex new file mode 100644 index 0000000..6312246 --- /dev/null +++ b/hub/account/existence.tex @@ -0,0 +1,30 @@ +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\peekAccount_{i} = 1$.}} +\end{center} +We specify the behaviour of the existence columns $\accExists$ and $\accExists\new$. As of EIP-\ob{TODO: find EIP number}, an account is non-existent \emph{if and only if} it is empty i.e. has zero balance, zero nonce and empty bytecode. Therefore we set the following +\begin{enumerate} + \item $\accExists_{i} \cdot (1 - \accExists_{i}) = 0 \qquad (\trash)$ + \item \If $\accNonce_{i} \neq 0$ \Then $\accExists_{i} = 1$ + \item \If $\accBalance_{i} \neq 0$ \Then $\accExists_{i} = 1$ + % \item \If $\accCodesize_{i} \neq 0$ \Then $\accExists_{i} = 1 \qquad (\trash)$ \ob{TODO: we should kick this out} + \item \If $\accHasCode_{i} \neq 0$\footnote{along account-rows $\accHasCode_{i} \in \{0, 1\}$ so that \emph{here} ``$\neq 0$'' effectively means ``$=1$''} \Then $\accExists_{i} = 1$ + \item On the contrary, %\ob{TODO: kick out} $\redm{\accCodesize}$ + \[ + \If + \left\{ \begin{array}{llclr} + & \accNonce_{i} & = & 0 \\ + \et & \accBalance_{i} & = & 0 \\ + % \et & \accCodesize_{i} & = & 0 & (\trash) \\ + \et & \accHasCode_{i} & = & 0 \\ + \end{array} \right\} + \Then + \accExists_{i} = 0. + \] +\end{enumerate} + +We impose the analoguous constraints for updated values +$\accNonce\new$, +$\accBalance\new$, +$\accHasCode\new$, +and +$\accExists\new$. diff --git a/hub/account/specialized_constraints/_conventions.tex b/hub/account/specialized_constraints/_conventions.tex new file mode 100644 index 0000000..7f13c07 --- /dev/null +++ b/hub/account/specialized_constraints/_conventions.tex @@ -0,0 +1,20 @@ +We use the following conventions/abbreviations: +\begin{description} + \item[\qquad$\relof$:] + short for \texttt{relative offset}; + \item[\qquad$\reldo$:] + short for \texttt{relative ``doing'' offset}; + \item[\qquad$\reluo$:] + short for \texttt{relative ``undoing'' offset}; +\end{description} +They are placeholder variables that are replaced with small nonnegative integers in applications. +In applications we will have +\[ + 0 \leq \relof, \qquad 0\leq \reldo < \reluo +\] +small nonnegative integers. With instructions that take two parameters, typically written +\[ + \texttt{perspectiveNameUndoXxxUpdate}\big[\reluo, \reldo\big]_{i} +\] +the interpretation is that such constraints $\reluo$ppend a row at row index $i + \reluo$ that $\reldo$eprecates the action performed at row $i + \reldo$ on some \texttt{xxx} field belonging to some given perspective. +It will implicitly require that both rows in question belong to a particular perspective where said operations make sense. diff --git a/hub/account/specialized_constraints/_inputs.tex b/hub/account/specialized_constraints/_inputs.tex new file mode 100644 index 0000000..857eb9b --- /dev/null +++ b/hub/account/specialized_constraints/_inputs.tex @@ -0,0 +1,11 @@ +\subsubsection{Introduction} \label{hub: account: specialized constraints: intro} \input{account/specialized_constraints/_intro} +\subsubsection{Conventions for offset parameters} \label{hub: account: specialized constraints: conventions} \input{account/specialized_constraints/_conventions} +\subsubsection{\accNonce{} constraints \lispDone{}} \label{hub: account: specialized constraints: nonce} \input{account/specialized_constraints/nonce} +\subsubsection{\accBalance{} constraints \lispDone{}} \label{hub: account: specialized constraints: balance} \input{account/specialized_constraints/balance} +\subsubsection{Account code constraints \lispDone{}} \label{hub: account: specialized constraints: code} \input{account/specialized_constraints/code} +\subsubsection{\accWarmth{} constraints \lispDone{}} \label{hub: account: specialized constraints: warmth} \input{account/specialized_constraints/warmth} +\subsubsection{Deployment status constraints \lispDone{}} \label{hub: account: specialized constraints: deployment} \input{account/specialized_constraints/deployment} +\subsubsection{\accMarkedForSelfdestruct{} constraints \lispDone{}} \label{hub: account: specialized constraints: marked for selfdestruct} \input{account/specialized_constraints/selfdestruct} +\subsubsection{Account inspection \lispTodo{}} \label{hub: account: specialized constraints: inspection} \input{account/specialized_constraints/inspection} +\subsubsection{Code fragment index and trimming \lispDone{}} \label{hub: account: specialized constraints: CFI and trim} \input{account/specialized_constraints/cfi_and_trimming} +\subsubsection{Precompile flag related \lispDone{}} \label{hub: account: specialized constraints: precompile flag related} \input{account/specialized_constraints/precompile} diff --git a/hub/account/specialized_constraints/_intro.tex b/hub/account/specialized_constraints/_intro.tex new file mode 100644 index 0000000..f929756 --- /dev/null +++ b/hub/account/specialized_constraints/_intro.tex @@ -0,0 +1,11 @@ +In this section we define certain (parametrized) constraint families applicable to account rows. +The introduction of said named constraint families will simplify the specification process as well as enhance readability. + +\saNote{} Whenever we write $\texttt{constraintName}\Hori$ the implied interpretation is that the constraint in question is \textbf{horizontal} i.e. internal to a given row. +Such constraints will typically involve pairs of ``account-row-columns'' of the form $\accountSignifier\col{COL}$ and $\accountSignifier\col{COL}\new$. + +\saNote{} Similarly, whenever we write $\texttt{constraintName}\Verti$ the implied interpretation is that the constraint in question will span two (or more) consecutive rows, making it \textbf{vertical}. +Such constraints will typically be used in constraints which undo others. + +\saNote{} Special care must be taken to ensure that any constraint involving some ``account-row-columns'' value only be applied when all values in sight in fact live on account-rows. +In other words if a constraint involves a value $\accountSignifier\col{COL}_{j}$ then $j$ should be the row index of an account-row i.e. should satisfy $\peekAccount_{j} = 1$. diff --git a/hub/account/specialized_constraints/balance.tex b/hub/account/specialized_constraints/balance.tex new file mode 100644 index 0000000..fbbbf29 --- /dev/null +++ b/hub/account/specialized_constraints/balance.tex @@ -0,0 +1,16 @@ +Below we define some simple constraint systems for account balance operations. +\[ +\left\{ \begin{array}{lcl} + \accSameBalance {i}{\relof} & \!\!\! \iff \!\!\! & \accBalance\new_{i + \relof} = \accBalance_{i + \relof} \\ + \accIncrementBalance {i}{\relof}{\col{value}} & \!\!\! \iff \!\!\! & \accBalance\new_{i + \relof} = \accBalance_{i + \relof} + \col{value} \\ + \accDecrementBalance {i}{\relof}{\col{value}} & \!\!\! \iff \!\!\! & \accBalance\new_{i + \relof} = \accBalance_{i + \relof} - \col{value} \\ + \accUndoBalanceUpdate {i}{\reluo}{\reldo} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accBalance _{i + \reluo} & \!\!\! = \!\!\! & \accBalance\new _{i + \reldo} \\ + \accBalance\new _{i + \reluo} & \!\!\! = \!\!\! & \accBalance _{i + \reldo} \\ + \end{array} \right. \\ +\end{array} \right. +\] +\saNote{} +The ``$\accUndoBalanceUpdate {i}{\reluo}{\reldo}$'' constraint undoes on row $i + \reluo$ (i.e. the row with relative offset $\reluo$) changes made to the account's balance on row $i + \reldo$ (i.e. the row with relative offset $\reldo$). +This constraints should only be applied when $\peekAccount_{i} = \peekAccount_{i - \relof} = 1$ (and the underlying account is the same on both rows.) diff --git a/hub/account/specialized_constraints/cfi_and_trimming.tex b/hub/account/specialized_constraints/cfi_and_trimming.tex new file mode 100644 index 0000000..376620f --- /dev/null +++ b/hub/account/specialized_constraints/cfi_and_trimming.tex @@ -0,0 +1,16 @@ +We define the following parametrized constraints +\[ + \left\{ \begin{array}{l} + \accRetrieveCodeFragmentIndex {i}{\relof} \quad \iff \quad \accRomLexFlag _{i + \relof} = \rOne \vspace{2mm} \\ + \accTrimAddress + {i}{\relof} + {\col{raw\_addr\_hi}} + {\col{raw\_addr\_lo}} + \\ + \qquad \iff \left\{ \begin{array}{lcl} + \accTrmFlag _{i + \relof} & = & \rOne \\ + \accTrmRawAddrHi _{i + \relof} & = & {\col{raw\_addr\_hi}} \\ + \accAddressLo _{i + \relof} & = & {\col{raw\_addr\_lo}} \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/hub/account/specialized_constraints/code.tex b/hub/account/specialized_constraints/code.tex new file mode 100644 index 0000000..782a7de --- /dev/null +++ b/hub/account/specialized_constraints/code.tex @@ -0,0 +1,41 @@ +Below $\relof$ is a (small) positive integer. +\[ + \left\{ \begin{array}{lcl} + \accSameCodeSize {i}{\relof} & \!\!\! \iff \!\!\! & \accCodesize\new_{i + \relof} = \accCodesize_{i + \relof} \\ + \accSameCodeHash {i}{\relof} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accCodehashHi\new_{i + \relof} & \!\!\! = \!\!\! & \accCodehashHi_{i + \relof} \\ + \accCodehashLo\new_{i + \relof} & \!\!\! = \!\!\! & \accCodehashLo_{i + \relof} \\ + \end{array} \right. \vspace{1mm} \\ + \accSameCode {i}{\relof} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accSameCodeSize {i}{\relof} \\ + \accSameCodeHash {i}{\relof} \\ + \end{array} \right. \\ + \end{array} \right. +\] +We also introduce ``undoing'' constraints: +\[ + \left\{ \begin{array}{lcl} + \accUndoCodeSizeUpdate {i}{\reluo}{\reldo} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accCodesize _{i + \reluo} & \!\!\! = \!\!\! & \accCodesize\new _{i + \reldo} \\ + \accCodesize\new _{i + \reluo} & \!\!\! = \!\!\! & \accCodesize _{i + \reldo} \\ + \end{array} \right. \vspace{1mm} \\ + \accUndoCodeHashUpdate {i}{\reluo}{\reldo} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accCodehashHi _{i + \reluo} & \!\!\! = \!\!\! & \accCodehashHi\new _{i + \reldo} \\ + \accCodehashHi\new _{i + \reluo} & \!\!\! = \!\!\! & \accCodehashHi _{i + \reldo} \vspace{1mm} \\ + \accCodehashLo _{i + \reluo} & \!\!\! = \!\!\! & \accCodehashLo\new _{i + \reldo} \\ + \accCodehashLo\new _{i + \reluo} & \!\!\! = \!\!\! & \accCodehashLo _{i + \reldo} \\ + \end{array} \right. \vspace{1mm} \\ + \accUndoCodeUpdate {i}{\reluo}{\reldo} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accUndoCodeSizeUpdate {i}{\reluo}{\reldo} \\ + \accUndoCodeHashUpdate {i}{\reluo}{\reldo} \\ + \end{array} \right. + \end{array} \right. +\] + +\saNote{} +It may seem surprising on first glance to have both a constraint system for the code hash not changing and another one for the code size not changing. The distinction is there for contract deployments. While the intialization code is running the account is initialized with empty code (i.e. $\sigma[\textsf{a}]_c = \emptyKeccak$) yet \inst{CODESIZE} returns the size of its initialization code. Thus when deploying a contract the arithmetization will set a code size to the size of the initialization code while keeping the code hash equal to that of the empty byte array. diff --git a/hub/account/specialized_constraints/deployment.tex b/hub/account/specialized_constraints/deployment.tex new file mode 100644 index 0000000..4290528 --- /dev/null +++ b/hub/account/specialized_constraints/deployment.tex @@ -0,0 +1,53 @@ +Below $\relof$ is a (small) positive integer. +\[ + \left\{ \begin{array}{lcl} + \accSameDeploymentNumber {i}{\relof} & \!\!\! \iff \!\!\! & \accDepNumber\new_{i + \relof} = \accDepNumber_{i + \relof} \\ + \accSameDeploymentStatus {i}{\relof} & \!\!\! \iff \!\!\! & \accDepStatus\new_{i + \relof} = \accDepStatus_{i + \relof} \\ + \accSameDeployment {i}{\relof} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\relof} } \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\relof} } \\ + \end{array} \right. \vspace{1mm} \\ + \accIncrementDeploymentNumber {i}{\relof} & \!\!\! \iff \!\!\! & \accDepNumber\new_{i + \relof} = 1 + \accDepNumber_{i + \relof} \\ + \accTurnOnDepStatus {i}{\relof} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accDepStatus _{i + \relof} & = & 0 \\ + \accDepStatus\new _{i + \relof} & = & 1 \\ + \end{array} \right. \\ + \multicolumn{3}{l}{ + \accUndoDeploymentStatusAndNumberUpdate {i}{\reluo}{\reldo} \iff + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\reluo}} \\ + \accDepNumber _{i + \reluo} & = & \accDepNumber\new _{i + \reldo} \\ + \accDepStatus _{i + \reluo} & = & \accDepStatus\new _{i + \reldo} \\ + \accDepStatus\new _{i + \reluo} & = & \accDepStatus _{i + \reldo} \\ + \end{array} \right. } \\ + \end{array} \right. +\] +We will also use larger compound constraints: +\[ + \left\{ \begin{array}{l} + \accInitiateForDeployment + {i}{\relof} + {\col{init\_code\_size}} + {\col{value}} + \vspace{2mm} \\ + \qquad \iff + \left\{ \begin{array}{lclr} + \accNonce _{i + \relof} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \accNonce\new _{i + \relof} & \!\!\! = \!\!\! & 1 \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\relof}{\col{value}}} \\ + \accCodesize _{i + \relof} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \accCodesize\new _{i + \relof} & \!\!\! = \!\!\! & \col{init\_code\_size} \\ + \accHasCode _{i + \relof} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \accCodehashHi _{i + \relof} & \!\!\! = \!\!\! & \emptyKeccakHi & (\trash) \\ + \accCodehashLo _{i + \relof} & \!\!\! = \!\!\! & \emptyKeccakLo & (\trash) \\ + \accHasCode\new _{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \accCodehashHi\new _{i + \relof} & \!\!\! = \!\!\! & \emptyKeccakHi & (\trash) \\ + \accCodehashLo\new _{i + \relof} & \!\!\! = \!\!\! & \emptyKeccakLo & (\trash) \\ + \multicolumn{3}{l}{\accIncrementDeploymentNumber {i}{\relof}} \\ + \multicolumn{3}{l}{\accTurnOnDepStatus {i}{\relof}} \\ + \multicolumn{3}{l}{\accTurnOnWarmth {i}{\relof}} \\ + \end{array} \right. \\ + \end{array} \right. +\] diff --git a/hub/account/specialized_constraints/inspection.tex b/hub/account/specialized_constraints/inspection.tex new file mode 100644 index 0000000..c28c828 --- /dev/null +++ b/hub/account/specialized_constraints/inspection.tex @@ -0,0 +1,85 @@ +\paragraph*{Account opening constraints.} The following set of constraints applies whenever an account is opened either to receive or spend funds. +\[ + \accOpening {\relof} _{i} + \iff + \left\{ \begin{array}{lcl} + \accSameNonce {i}{\relof} \\ + \accSameCode {i}{\relof} \\ + \accSameDeployment {i}{\relof} \\ + \end{array} \right. +\] + +\paragraph*{Account viewing constraints.} The following set of constraints imposes that account variables are only read but not modified +\[ + \accViewing {\relof} _{i} + \iff + \left\{ \begin{array}{lcl} + \accOpening {\relof} _{i} \\ + \accSameBalance {i}{\relof} \\ + \end{array} \right. +\] + +\paragraph*{Account deletion constraints.} The following set of constraints imposes the deletion of an account: +\[ + \accDeletion {i}{\relof} + \iff + \left\{ \begin{array}{lclr} + \accNonce\new _{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \accBalance\new _{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \accCodesize\new _{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \accHasCode\new _{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \accCodehashHi\new _{i + \relof} & \!\!\! = \!\!\! & \emptyKeccakHi & (\trash) \\ + \accCodehashLo\new _{i + \relof} & \!\!\! = \!\!\! & \emptyKeccakLo & (\trash) \\ + \multicolumn{3}{l}{\accFreshNewDeploymentStatusAndNumber{\relof}_{i}} \\ + \end{array} \right. +\] + +\paragraph*{Working with the same account.} +The following collection of constraints which spans two consecutive rows impose that the \zkEvm{} has a view into the same deployment over two consecutive rows: +\[ + \accSameAddr {i}{\reluo}{\reldo} + \iff + \left\{ \begin{array}{lcl} + \accAddress\high_{i + \reluo} & \!\!\! = \!\!\! & \accAddress\high_{i + \reldo} \\ + \accAddress\low _{i + \reluo} & \!\!\! = \!\!\! & \accAddress\low _{i + \reldo} \\ + \end{array} \right. +\] +and +\[ + \accSameAddrAndDepNum {i}{\reluo}{\reldo} + \iff + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\reluo}{\reldo}} \\ + \accDepNumber_{i + \reluo} & \!\!\! = \!\!\! & \accDepNumber\new_{i + \reldo} \\ + \end{array} \right. +\] +and +\[ + \accSameAddrDepNumAndDepStage {i}{\reluo}{\reldo} + \iff + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddrAndDepNum {i}{\reluo}{\reldo}} \\ + \accDepStatus_{i + \reluo} & \!\!\! = \!\!\! & \accDepStatus\new_{i + \reldo} \\ + \end{array} \right. +\] +\saNote{} These constraints should only be applied when (it is known that) $\peekAccount_{i} = \peekAccount_{i - \relof} = 1$. + + +% TODO: fix this +% \paragraph*{Deploying empty bytecode.} +% The following collection of constraints applies whenever one deploys empty byte code (e.g. when encountering a \inst{STOP} in a deployment context or when \inst{RETURN}ing with zero size in a deployment context.) +% \[ +% \accDeployEmptyBytecode{\relof} +% \iff +% \left\{ \begin{array}{lclr} +% \accAddress\high _{i + \relof} + & \!\!\! = \!\!\! & \codeAddress\high_{i} \\ +% \accAddress\low _{i + \relof} + & \!\!\! = \!\!\! & \codeAddress\low_{i} \\ +% \accDepNumber _{i + \relof} + & \!\!\! = \!\!\! & \codeDepNum_{i} \\ +% \accDepStatus _{i + \relof} + & \!\!\! = \!\!\! & 1 & (\trash) \\ +% \accDepStatus\new _{i + \relof} + & \!\!\! = \!\!\! & 0 & (\trash) \\ +% \accDepStatus\new _{i + \relof} + & \!\!\! = \!\!\! & \accDepStatus_{i} - 1 \\ +% \accCodesize\new _{i + \relof} + & \!\!\! = \!\!\! & 0 \\ +% \accHasCode\new _{i + \relof} + & \!\!\! = \!\!\! & 0 \\ +% \multicolumn{3}{l}{\accSameCodeHash_{i}} & (\trash) \\ +% \end{array} \right. +% \] diff --git a/hub/account/specialized_constraints/intro.tex b/hub/account/specialized_constraints/intro.tex new file mode 100644 index 0000000..e69de29 diff --git a/hub/account/specialized_constraints/nonce.tex b/hub/account/specialized_constraints/nonce.tex new file mode 100644 index 0000000..c28fc7c --- /dev/null +++ b/hub/account/specialized_constraints/nonce.tex @@ -0,0 +1,17 @@ +Below we define some simple constraint systems. +In particular we define a parametrized family of constraints $\accUndoNonceUpdate {i}{\reluo}{\reldo}$. +This family is parametrized in terms of parameters $\reluo$, $\reldo$ which are (small, nonnegative) integers. +The interpretation of $\accUndoNonceUpdate {i}{\reluo}{\reldo}$ is that this constraint peeks $\reluo$ rows into the future (relative to the present row) and undoes changes performed $\reldo$ rows from now (relative to the present row.) +\[ + \left\{ \begin{array}{lcl} + \accSameNonce {i}{\relof} & \!\!\! \iff \!\!\! & \accNonce\new_{i + \relof} = \accNonce_{i + \relof} \\ + \accIncrementNonce {i}{\relof} & \!\!\! \iff \!\!\! & \accNonce\new_{i + \relof} = \accNonce_{i + \relof} + 1 \\ + \accUndoNonceUpdate {i}{\reluo}{\reldo} & \!\!\! \iff \!\!\! & + \left\{\begin{array}{lcl} + \accNonce _{i + \reluo} & \!\!\! = \!\!\! & \accNonce\new_{i + \reldo} \\ + \accNonce\new_{i + \reluo} & \!\!\! = \!\!\! & \accNonce _{i + \reldo} \\ + \end{array}\right.\\ + \end{array} \right. +\] +These constraints should only be applied when $\peekAccount_{i + \relof} = 1$ +and $\peekAccount_{i + \reluo} = \peekAccount_{i + \reldo} = 1$ (and the underlying account is the same on both rows.) diff --git a/hub/account/specialized_constraints/precompile.tex b/hub/account/specialized_constraints/precompile.tex new file mode 100644 index 0000000..5168994 --- /dev/null +++ b/hub/account/specialized_constraints/precompile.tex @@ -0,0 +1,7 @@ +We further define the following self-explanatory parametrized constraints +\[ + \left\{ \begin{array}{lcl} + \accIsntPrecompile {i}{\relof} & \iff & \accTrmIsPrecompile _{i + \relof} = 0 \\ + \accIsPrecompile {i}{\relof} & \iff & \accTrmIsPrecompile _{i + \relof} = 1 \\ + \end{array} \right. +\] diff --git a/hub/account/specialized_constraints/selfdestruct.tex b/hub/account/specialized_constraints/selfdestruct.tex new file mode 100644 index 0000000..6e7c527 --- /dev/null +++ b/hub/account/specialized_constraints/selfdestruct.tex @@ -0,0 +1,15 @@ +We introduce a few constraints pertaining to the $\accMarkedForSelfdestruct$ and $\accMarkedForSelfdestruct\new$ flags. +The constraints defined here only ``make sense'' on row indices $i$ such that $i + \relof$ is an account-row i.e. +$\peekAccount_{i + \relof} = 1$. +\[ + \left\{ \begin{array}{lcl} + \accSameMarkedForSelfdestructFlag {i}{\relof} & \iff \\ + \multicolumn{3}{l}{ + \qquad \accMarkedForSelfdestruct\new _{i + \relof} + = + \accMarkedForSelfdestruct _{i + \relof} + } + \vspace{2mm} \\ + \accTurnOnMarkedForSelfdestructFlag {i}{\relof} & \iff & \accMarkedForSelfdestruct\new _{i + \relof} = 1 \\ + \end{array} \right. +\] diff --git a/hub/account/specialized_constraints/warmth.tex b/hub/account/specialized_constraints/warmth.tex new file mode 100644 index 0000000..e9640be --- /dev/null +++ b/hub/account/specialized_constraints/warmth.tex @@ -0,0 +1,15 @@ +Below we define some simple constraint systems. +We also define a parametrized family of constraints $\accUndoWarmthUpdate {i}{\reluo}{\reldo}$. +This family is parametrized in terms of a parameter $\relof$ which must be a small positive integer. +\[ + \left\{ \begin{array}{lcl} + \accSameWarmth {i}{\relof} & \!\!\! \iff \!\!\! & \accWarmth\new_{i + \relof} = \accWarmth_{i + \relof} \\ + \accTurnOnWarmth {i}{\relof} & \!\!\! \iff \!\!\! & \accWarmth\new_{i + \relof} = 1 \\ + \accUndoWarmthUpdate {i}{\reluo}{\reldo} & \!\!\! \iff \!\!\! & + \left\{ \begin{array}{lcl} + \accWarmth _{i + \reluo} & \!\!\! = \!\!\! & \accWarmth\new _{i + \reldo} \\ + \accWarmth\new _{i + \reluo} & \!\!\! = \!\!\! & \accWarmth _{i + \reldo} \\ + \end{array} \right. \\ + \end{array} \right. +\] +\saNote{} The ``$\accTurnOnWarmth {i}{\relof}$'' constraint says nothing about the \textbf{current} warmth of the address. diff --git a/hub/columns/_inputs.tex b/hub/columns/_inputs.tex new file mode 100644 index 0000000..0f483ba --- /dev/null +++ b/hub/columns/_inputs.tex @@ -0,0 +1,13 @@ +\input{columns/_local} + +\section{Column descriptions \lispDone{}} \label{hub: columns} +\subsection{Column blending and perspectives} \label{hub: perspectives} \input{columns/perspectives} +\subsection{Shared columns \lispDone{}} \label{hub: shared columns} \input{columns/shared} +\subsection{Column names for stack-rows \lispDone{}} \label{hub: stack columns} \input{columns/stack} +\subsection{Column names for context-rows \lispDone{}} \label{hub: context columns} \input{columns/context} +\subsection{Column names for account-rows \lispDone{}} \label{hub: account columns} \input{columns/account} +\subsection{Column names for storage-rows \lispDone{}} \label{hub: storage columns} \input{columns/storage} +\subsection{Column names for transaction-rows \lispDone{}} \label{hub: transaction columns} \input{columns/transaction} +\subsection{Column names for miscellaneous-rows \lispDone{}} \label{hub: miscellaneous columns} \input{columns/miscellaneous/_inputs} +\subsection{Column names for scenario-rows \lispDone{}} \label{hub: scenario columns} \input{columns/scenarios/_inputs} +\subsection{Column names for consistency arguments \lispTodo{}} \label{hub: consistency argument columns} \input{columns/_opt_consistency} diff --git a/hub/columns/_local.tex b/hub/columns/_local.tex new file mode 100644 index 0000000..cac0470 --- /dev/null +++ b/hub/columns/_local.tex @@ -0,0 +1,24 @@ +\def\one {\bm{1}} +\def\One {\redm{1}} +\def\zero {\gray{0}} +\def\lllight {60} +\def\llight {72} +\def\light {85} +\def\twRow {\cellcolor{solarized-magenta!\lllight} \one & \zero & \zero & \zero} +\def\twDots {\cellcolor{solarized-magenta!\lllight} \bm{\vdots} & \vdots & \vdots & \vdots} +\def\tiRow {\zero & \cellcolor{solarized-magenta!\llight} \one & \zero & \zero} +\def\teRow {\zero & \zero & \cellcolor{solarized-magenta!\light} \one & \zero} +\def\teDots {\gray{\vdots} & \gray{\vdots} & \cellcolor{solarized-magenta!\light} \bm{\vdots} & \gray{\vdots}} +\def\tfRow {\zero & \zero & \zero & \cellcolor{solarized-magenta} \one} +\def\bt {\col{b} & \col{t}} +\def\btP {\col{b'} & \col{t'}} +\def\btPP {\col{b''} & \col{t''}} +\def\btDots {\col{\vdots} & \col{\vdots}} +\def\stkRow {\multicolumn{8}{c||}{\cellcolor{solarized-yellow} } & \zero & \cellcolor{solarized-yellow} \one & \zero & \zero & \zero} +\def\conRow {\multicolumn{6}{c|}{\cellcolor{solarized-cyan}} & \multicolumn{2}{c||}{}& \cellcolor{solarized-cyan} \one & \zero & \zero & \zero & \zero} +\def\accRow {\multicolumn{5}{c|}{\cellcolor{solarized-green}} & \multicolumn{3}{c||}{} & \zero & \zero & \cellcolor{solarized-green} \one & \zero & \zero} +\def\stoRow {\multicolumn{4}{c|}{\cellcolor{solarized-blue}} & \multicolumn{4}{c||}{} & \zero & \zero & \zero & \cellcolor{solarized-blue} \one & \zero} +\def\txnRow {\multicolumn{3}{c|}{\cellcolor{solarized-orange}} & \multicolumn{5}{c||}{} & \zero & \zero & \zero & \zero & \cellcolor{solarized-orange} \one} +\def\allVdots {\vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots} +\def\allCdots {\cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots} + diff --git a/hub/columns/_opt_consistency.tex b/hub/columns/_opt_consistency.tex new file mode 100644 index 0000000..b4e71a0 --- /dev/null +++ b/hub/columns/_opt_consistency.tex @@ -0,0 +1,33 @@ +We include several columns that will be used in consistency constraints. +The first batch will be used in account consistency constraints, see section~(\ref{hub: consistencies: account}) +\begin{multicols}{2} + \begin{enumerate}[resume] + \item $\accAddressFirst$ + \item $\accAbsTxNumFirst$ + \item $\accAddressAgain$ + \item $\accAbsTxNumAgain$ + \end{enumerate} +\end{multicols} +\noindent The second batch will be used in context consistency constraints, see section~(\ref{hub: consistencies: context}) +\begin{multicols}{2} + \begin{enumerate}[resume] + \item $\conContextFirst$ + \item $\conContextAgain$ + \end{enumerate} +\end{multicols} +\noindent The third batch will be used in stack consistency constraints, see section~(\ref{hub: consistencies: stack}) +\begin{multicols}{2} + \begin{enumerate}[resume] + \item $\stackContextFirst$ + \item $\stackHeightFirst$ + \item $\stackSpotFirst$ + \item $\stackContextAgain$ + \item $\stackHeightAgain$ + \item $\stackSpotAgain$ + \end{enumerate} +\end{multicols} +\saNote{} +Their names suggest that these are ``permuted columns'' but note that there are no corresponding ``time-ordered'' columns of which they would be a row permutation. +Their names also suggest that they belong to a particular perspective such as $\accountSignifier$, $\contextSignifier$, \dots{} yet they don't properly belong to a particular perspective. +These columns exist purely in the permuted realm as helper columns to achieve degree reduction. + diff --git a/hub/columns/account.tex b/hub/columns/account.tex new file mode 100644 index 0000000..c40a0f7 --- /dev/null +++ b/hub/columns/account.tex @@ -0,0 +1,84 @@ +\textbf{Account-rows} are characterized by $\peekAccount \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\accountSignifier$. The following are names for certain columns on account-rows. +\begin{enumerate} + \item $\accAddress\high$ and $\accAddress\low$: + high and low parts of the address of the account which the arithmetization is currently peeking into; + \item $\accNonce$ and $\accNonce\new$: + account nonce and its updated value; + \item $\accBalance$ and $\accBalance\new$: + account balance and its updated value; + \item $\accCodesize$ and $\accCodesize\new$: + account code size and its updated value; + \item $\accCodehashHi$ and $\accCodehashHi\new$, $\accCodehashLo$ and $\accCodehashLo\new$: + account code hash and its updated value; + \item $\accHasCode$ and $\accHasCode\new$: + binary columns indicating whether the account has empty code; + \item $\accCfi$: + the \CFI{} of the account's code; only listed if necessary; + \item $\accRomLexFlag$: + binary column which lights up whenever the account's \CFI{} is required; +\end{enumerate} +% \saNote{} $\accCodehash$ and $\accCodehash\new$ are (both) split into high and low parts. + +\saNote{} The constraints will implement $\accHasCode = 1 \iff \accCodehash \neq \emptyKeccak$ i.e. we don't use the $\accCodesize$; recall that while a contract is deploying its code is empty from the point of view of the world state yet its code size is that of the initialization code. +\begin{enumerate}[resume] + \item $\accExists$ and $\accExists\new$: + binary columns indicating the account's existence and its updated value; +\end{enumerate} +Recall that post EIP-\ob{TODO: What's the number?} an address $\textsf{a}$ is deemed to be \textbf{non-existent} in the world state $\sigma$ if +its nonce $\sigma[\textsf{a}]_\text{n}$ and balance $\sigma[\textsf{a}]_\text{b}$ vanish and +its code is empty i.e. $\sigma[\textsf{a}]_\text{c} = \texttt{KEC}\big((~)\big)$. +\begin{enumerate}[resume] + \item $\accWarmth$ and $\accWarmth\new$: + binary columns containing the account's warmth and its updated value; +\end{enumerate} +The above columns track the address' \emph{warmth} (which impacts the pricing of certain opcodes.) +We furthermore introduce a binary column which will allow us to recognize addresses that were marked for \inst{SELFDESTRUCT} within a given transaction. +\begin{enumerate}[resume] + \item $\accMarkedForSelfdestruct$ and $\accMarkedForSelfdestruct\new$: + binary columns; + track whether an address was successfullly marked for selfdestruction within a given transaction; +\end{enumerate} +The following columns are \textsc{zk-evm} specific columns. We explain their purpose in section~\ob{TODO: write section and point to it}. +\begin{enumerate}[resume] + \item $\accDepNumber$ and $\accDepNumber\new$: + deployment number of the current address $\accAddress$ pre-instruction and the updated deployment number; + \item $\accDepStatus$ and $\accDepStatus\new$: + binary columns indicating the deployment status ($1 \iff$ under deployment, $0 \iff $ (currenly) deployed) of the current address $\accAddress$ pre-instruction and its updated value; +\end{enumerate} +The following columns are used when an account has its balance decremented either at the onset of a transaction or when performing a \inst{CALL}-type or \inst{CREATE}-type transaction. +The following column turns on \emph{if and only if} the account on the present row is about to create a new address either at the beginning of transaction processing (if $T_\text{t} = \varnothing$ i.e. $\txIsDeployment = 1$) or through a \inst{CREATE} instruction. \ob{TODO: for the \inst{CREATE2} path we can surely do it in terms of the create flag and flag 1.} +\begin{enumerate}[resume] + \item \ob{TODO: unconstrained as of yet}$\accDepNumber^\infty$ and $\accExists^\infty$: + address-constant columns; +\end{enumerate} +These are $\accAddress$-constant columns that contain, respectively, the larges deployment number of that address and its final existence status: $\accExists^\infty = 1$ means that the address will exist in the world state once all the batches of transactions are dealt with. Both are set the very last time the address is ``seen in the trace.'' They exist for one reason and one reason only: for \emph{storage-rows} to have access to that information. Indeed one needs to distinguish between values written in storage during a failed previous attempt of deployment vs others \dots{} \red{I think this may be useless after all. Failed attempts are reverted, and so are the changes that would have applied to that address's storage \dots{} Phew, this means that this may just end up being useless after all \dots} \ob{TODO: CORRECTION: These account-columns aren't useless \emph{at all} ! We use them in the storage. The only storage values to be committed are those for accounts with $\accExists^\infty = 1$ and only for those values that are committed at $\accDepNumber = \accDepNumber^\infty$.} + +The next batch of columns allow us to perform certain operations using as inputs fields from an account or stack arguments. We start with data required for trimming stack items ($32$-byte integers split as a pair of high and low parts) which ought to be interpreted as addresses of their leading $12$ bytes: +(\emph{b}) +\begin{enumerate}[resume] + \item \accTrmFlag: binary column which turns on whenever a stack argument has to be interpreted as an address; used as a selector bit for lookup arguments; + \item $\accTrmRawAddrHi$: duplicate of the relevant high part of the stack argument to be interpreted as an address; + \item $\accTrmIsPrecompile$: + binary column which $=1$ if and only if the address is that of a precompile\footnote{i.e. $\accAddress \in \{1, 2, \dots, 9 \}$}; + : disjoint binary columns that turn on for accounts which raise the \accTrmIsPrecompile{} flag; they are used when dealing with \inst{CALL}-type instructions to precompiles; +\end{enumerate} +\saNote{} The \trmMod{} module requires the following inputs from the \hubMod{}: +$\rawAddrHi$ and $\rawAddrLo$, +$\trmAddrHi$, +$\isPrecompile$. +All fields in question already have their equivalent on the current account row, except for the raw high part of the address field, for which we introduced the $\accTrmRawAddrHi$ column above. + +The next collection of columns is required for computing deployment addresses of \inst{CREATE}-type instructions. +\begin{enumerate}[resume] + \item $\accRlpAddrFlag$: + binary column which switches on whenever a deployment address has to be computed; + \item $\accRlpAddrRecipe$: + ``recipe'' column which distinguishes between the two ``recipes'' for computing a deployment address; see \ob{TODO: add reference to \rlpAddrMod{} module chapter}; + \item $\accRlpAddrDepAddrHi$ and $\accRlpAddrDepAddrLo$: + high and low part of the deployment address as verified in the \rlpAddrMod{} module; + \item $\accRlpAddrSaltHi$ and $\accRlpAddrSaltLo$: + high and low part of the relevant stack argument to be interpreted as \textbf{salt}; + \item $\accRlpAddrKecHi$ and $\accRlpAddrKecLo$: + high and low part of the hash of initialization code (if relevant); +\end{enumerate} +\saNote{} The \rlpAddrMod{} module further requires the creator address' (high and low parts) and the current nonce (pre-deployment); these fields are already present on the current account row. diff --git a/hub/columns/context.tex b/hub/columns/context.tex new file mode 100644 index 0000000..50921fa --- /dev/null +++ b/hub/columns/context.tex @@ -0,0 +1,92 @@ +\begin{center} + \boxed{\text{We abbreviate ``context-constant (binary) column'' to \cncc{} + (resp. \cncbc{}.)}} +\end{center} +\textbf{Context-rows}\label{def: stack row} are characterized by $\peekContext \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\contextSignifier$. +Note that \textbf{context data is immutable} (except for those which concerns return data, see below.) +\begin{enumerate} + \item $\cnCn$: + column containing the $\CN$ of the context beeing peeked into currently; + \item $\cnCsd$: + \cncc{} containing the \CSD{}; + \item \cnIsRootContext{}: + \cncc{} binary column; indicates whether the current context is the root context of a transaction; logically equivalent to $\big[ \cnCsd = 1 \big]$; + \item $\cnStatic$: + \cncbc{} indicating whether the present context is static; +\end{enumerate} +% The \textbf{context type} of an execution context is defined to be +% $\cnType = 0$ for message call contexts and +% $\cnType = 1$ for deployment contexts. +The following columns pertain to the \textbf{account} whose balance and storage are accessible in the current execution context. +\begin{enumerate}[resume] + \item $\cnAccountAddress\high$, $\cnAccountAddress\low$: + \cncc{} containing the high and low part of the address of the underlying account; + \item $\cnAccDepNum$: + \cncc{} containing the deployment number of $\cnAccountAddress$ in the present execution context; +\end{enumerate} +The following columns pertain to the account whose \textbf{bytecode} is being run in the current execution context. +\begin{enumerate}[resume] + \item $\cnCodeAddress\high$, $\cnCodeAddress\low$: + \cncc{} containing the high and low part of the address of the bytecode running in the current execution context; + \item $\cnCodeDepNum$: + \cncc{} containing the deployment number of $\cnCodeAddress$ in the present execution frame; + \item $\cnCodeDepStatus$: + \cncbc{} containing the deployment status of $\cnCodeAddress$ in the present execution frame; + \item $\cnCodeCfi$: + \cncc{} containing the \CFI{} of the bytecode running in the current execution frame; +\end{enumerate} +The following columns contains a partial reflection of the \textbf{caller} context. +\begin{enumerate}[resume] + \item $\cnCallerAddress\high$, $\cnCallerAddress\low$: + \cncc{} containing the high and low part of the caller's address as returned by the \inst{CALLER} opcode; + \item $\cnCallValue$: + \cncc{} containing the value in Gwei provided in the message call / deployment operation which spawned the present context; +\end{enumerate} +The following columns contain information pertaining to call data: +\begin{enumerate}[resume] + \item $\cnCallDataContextNumber$: + \cncc{} containing the caller context's context number; + \item $\cnCdo$: + \cncc{} containing the \CDO{}; + \item $\cnCds$: + \cncc{} containing the \CDS{}; + \item $\cnRao$: + \cncc{} containing the \RAO{}; + specified by the caller context at the moment the present context was spawned; + \item $\cnRac$: + \cncc{} containing the \RAC{}; + specified by the caller context at the moment the present context was spawned; +\end{enumerate} +\saNote{} \cnCdo{} and \cnCds{} vanish for deployment contexts. +\saNote{} \cnRao{} and \cnRac{} vanish for deployment contexts and the root context of message call transactions. + +The following columns pertain to the returner context i.e. the most recent execution context spawned by the present context from which execution has returned. +\begin{enumerate}[resume] + \item $\cnUpdate$: + binary column; + \item $\cnReturner$: + contains the context number of; + % \item \ob{TODO: is this obsolete ?} $\cnReturnerIsPrecompile$: + % binary column indicating whether the returner is a precompile; + \item $\cnRdo$: + column containing the \RDO{}; specified by \cnReturner{} at "re-entry"; + \item $\cnRds$: + column containing the \RDS{}; specified by \cnReturner{} at "re-entry"; +\end{enumerate} +As already stated: all context data is \textbf{immutable} except for ``return data'' related columns. This immutability isn't (readily) apparent in the time-ordered traces. Rather it has to be enforced in a reordered version of the execution trace which juxtaposes in consecutive rows all \textbf{context-rows} ordered by context number $\cnCn$ and by \hubStamp{}. +The binary flag $\cnUpdate$ indicates when the mutable context data $\cnReturner$, $\cnRdo$, $\cnRds$ are allowed to change. +Let us provide further details. +When an execution context resumes after a child context finishes executing it receives return data% +\footnote{Said return data may be empty e.g. after a successful deployment, if the child context ended on a \inst{STOP} or a \inst{SELFDESTRUCT}, if the child context ended on a \inst{RETURN}/\inst{REVERT} with empty data, if the child context terminated on an exception, when returning from a \inst{CALL} to a precompile which triggered an internal error, \dots} That data lives in the child context's RAM (whose \cn{} will be stored \cnReturner{}) starting at some offset (stored in \cnRdo{}) and comprising a number of bytes (stored in \cnRds{}.) Contrary to the offset / size parameters introduced previously these parameters need not be context-constant. They are updated every time execution of the present context resumes after a message call or deployment. + +\saNote{} The above will hold true for \inst{CALL}'s to precompiled contracts, too. \inst{CALL}'s to these contracts \emph{do not} produce tangible execution contexts in the present arithmetization i.e. the \hubMod{} module never enters an execution context with $\cnCodeAddress \in \{ 1, 2, \dots, 9 \}$. Yet \textsc{ram} may have to undergo modifications. Typically (and along the happy path) +(\emph{a}) +extraction of a slice of bytes from the current execution context's \textsc{ram} to be stored in some dedicated \col{DATA} module (e.g. +\ecDataMod{}, +\hashDataMod{}, +\romMod{}, +\dots{}) +(\emph{b}) +producing a full copy of the result (extracted from a dedicated \col{INFO} module, e.g. \hashInfoMod{}) onto the \textsc{ram} of a ``fictitious execution context \col{fec}'' +(\emph{c}) +copying the relevant slice of bytes from the return data which was just inserted into \col{fec}'s \textsc{ram} into the current execution context's \textsc{ram}. The ``fictitious execution context \col{fec}'' will be granted a \cn{} deduced from the current \hubStamp{}. It will be stored as the \cnReturner{} of the current execution context, and various return-data-related fields of the current execution context will be set appropriately. diff --git a/hub/columns/miscellaneous/_inputs.tex b/hub/columns/miscellaneous/_inputs.tex new file mode 100644 index 0000000..20ede75 --- /dev/null +++ b/hub/columns/miscellaneous/_inputs.tex @@ -0,0 +1,6 @@ +\subsubsection{\miscSignifier\expMod{} columns \lispDone{}} \label{hub: columns: miscellaneous: exp} \input{columns/miscellaneous/exp} +\subsubsection{\miscSignifier\mmuMod{} columns \lispDone{}} \label{hub: columns: miscellaneous: mmu} \input{columns/miscellaneous/mmu} +\subsubsection{\miscSignifier\mxpMod{} columns \lispDone{}} \label{hub: columns: miscellaneous: mxp} \input{columns/miscellaneous/mxp} +\subsubsection{\miscSignifier\oobMod{} columns \lispDone{}} \label{hub: columns: miscellaneous: oob} \input{columns/miscellaneous/oob} +\subsubsection{\miscSignifier\stpMod{} columns \lispDone{}} \label{hub: columns: miscellaneous: stp} \input{columns/miscellaneous/stp} +\subsubsection{Truly miscellaneous columns \lispDone{}} \label{hub: columns: miscellaneous: other} \input{columns/miscellaneous/other} diff --git a/hub/columns/miscellaneous/exp.tex b/hub/columns/miscellaneous/exp.tex new file mode 100644 index 0000000..10e64cb --- /dev/null +++ b/hub/columns/miscellaneous/exp.tex @@ -0,0 +1,6 @@ +\begin{enumerate}[resume] + \item $\miscExpInstruction$: + dynamic gas cost of an \inst{EXP} instruction; + \item $\miscExpDataCol{k}$ for $k=1,2,\dots,5$: + inputs to the \expMod{} module; +\end{enumerate} diff --git a/hub/columns/miscellaneous/flags.tex b/hub/columns/miscellaneous/flags.tex new file mode 100644 index 0000000..c4ce922 --- /dev/null +++ b/hub/columns/miscellaneous/flags.tex @@ -0,0 +1,27 @@ +\textbf{Miscellaneous-rows} are characterized by $\peekMisc \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\miscSignifier$. +Their purpose is to simplify the writing of certain lookup arguments, specifically those involving +the \mmuMod{} module, +the \stpMod{} module, +the \oobMod{} module and +the \mxpMod{} module. +We therefore introduce the following binary flags: +\begin{enumerate} + \item $\miscExpFlag$: + binary flag; + \item $\miscMmuFlag$: + binary flag; + \item $\miscMxpFlag$: + binary flag; + \item $\miscOobFlag$: + binary flag; + \item $\miscStpFlag$: + binary flag; +\end{enumerate} +These light up \emph{iff} the current miscellaneous-row triggers a call to +the \stpMod{} module, +the \mxpMod{} module, +the \oobMod{} module and/or +the \mmuMod{}; several of these flags may be on simultaneously. +The columns in this perspective duplicate pieces of data available in the immediate vicinity within the trace. +All the requisite data \emph{is} available \emph{nearby}, but it is scattered about in a complex way which depends on the instruction. +The goal of miscellaneous-rows is to make the requisite data available in a \emph{straightforward} way on \emph{a single row}. We introduce the columns of the present perspective by ``topic''. diff --git a/hub/columns/miscellaneous/mmu.tex b/hub/columns/miscellaneous/mmu.tex new file mode 100644 index 0000000..b0d144d --- /dev/null +++ b/hub/columns/miscellaneous/mmu.tex @@ -0,0 +1,46 @@ +\begin{enumerate}[resume] + \item \miscMmuInst{}: + custom \mmuMod{} instruction column; + \item \miscMmuSrcId{}: + a ``source ID'' column; + \item \miscMmuTgtId{}: + a ``target ID'' column; + \item \miscMmuAuxId{}: + an ``auxiliary ID'' column; + \item \miscMmuSrcOffsetHi{} and \miscMmuSrcOffsetLo{}: + high and low part of a (relative) source offset; + \item \miscMmuTgtOffsetLo{}: + low part of a (relative) target offset; + \item \miscMmuSize{}: + size parameter; + \item \miscMmuRefOffset{}: + may contain a ``reference offset'' + \item \miscMmuRefSize{}: + may contain a ``reference size'' + \item \miscMmuSuccessBit{}: + binary column; + \item \miscMmuLimbOne{} and \miscMmuLimbTwo{}: + may contain data limbs; + \item \miscMmuExoSum{}: + weighted sum of certain ``exo flags''; + the \mmioMod{} may interpret it as a bitfield; + \item \miscMmuPhase{}: + may contain a ``phase number''; +\end{enumerate} +Depending on circumstances the data limbs may either be interpreted +as traveling from the \hubMod{} module to the \mmuMod{} module (e.g. in case of an \inst{MSTORE} or \inst{MSTORE8}) or +as traveling in the opposite direction from the \mmuMod{} module to the \hubMod{} module (e.g. in case of an \inst{MLOAD}, \inst{CALLDATALOAD}.) +These data limbs don't necessarily contain the high and low parts of a \evm{} word (as the previous examples may suggest.) +The \hubMod{}'s processing of \inst{CALL}'s to precompiles also makes use of these columns. +For instance the \inst{MODEXP} precompile uses these fields to transfer various values from \textsc{ram} to the \hubMod{} for further processing +(e.g. byte size parameters $\locBase$, $\locExponent$, $\locModulus$ but also the leading word of the exponent.) +Similarly the \inst{BLAKE} precompile uses these fields to transit +the rounds parameter $r = I_\textbf{d}[0\text{..}4]$ and +the final block indicator flag $f = I_\textbf{d}[212]$ +to the \hubMod{} module. + +\miscMmuExoSum{} and \miscMmuPhase{} are used in communication with so-called \textbf{exo data stores}. +These are ``data-modules'' with which the \mmioMod{} module can exchange data. +The first of these columns serves as an identifier for \textbf{(zero,) one or more} target/source exo modules. + +\saNote{} We don't include a miscellaneous \mmuStamp{} column: such a column is readily available at all times as a shared column. diff --git a/hub/columns/miscellaneous/mxp.tex b/hub/columns/miscellaneous/mxp.tex new file mode 100644 index 0000000..934b900 --- /dev/null +++ b/hub/columns/miscellaneous/mxp.tex @@ -0,0 +1,26 @@ +\begin{enumerate}[resume] + \item \miscMxpMxpx{}: + bit indicating whether a \mxpxSH{} has taken place; + \item \miscMxpInst{}: + \mxpMod{} instruction; + \item \miscMxpCodeDeployment{}: + bit that indicates whether the current context is a deployment context; used to price the ``linear gas cost'' of \inst{RETURN}'s; + \item \miscMxpOffsetOneHi{} and \miscMxpOffsetOneLo{}: + high and low part of a first offset parameter; + \item \miscMxpOffsetTwoHi{} and \miscMxpOffsetTwoLo{}: + high and low part of a second offset parameter (for \inst{CALL}-type instructions); + \item \miscMxpSizeOneHi{} and \miscMxpSizeOneLo{}: + high and low part of a first size parameter; + \item \miscMxpSizeTwoHi{} and \miscMxpSizeTwoLo{}: + high and low part of a second size parameter (for \inst{CALL}-type instructions); + \item \miscMxpWords{}: + ``the active number of words in memory (counting continuously from position $0$)'' \ob{TODO: reference to EYP, 9.4.1. Machine State}; + \item \miscMxpGasMxp{}: + memory expansion cost + whatever ``linear'' cost the instruction may incur; + \item \miscMxpTypeFourInstMayTriggerMmu{} + binary column which may only light up for \mxpMod{} instruction of ``\textbf{type 4}''; + see section~(\ref{mxp: may trigger non trivial operation}); +\end{enumerate} +\saNote{} We don't include a miscellaneous \mxpStamp{} column: such a column is readily available as a shared column. + +\saNote{} ``Linear'' costs come in two flavors: gas cost may be proportional to either the size in bytes of one of the parameters or the size in \textsc{evm} words. diff --git a/hub/columns/miscellaneous/oob.tex b/hub/columns/miscellaneous/oob.tex new file mode 100644 index 0000000..48c26ea --- /dev/null +++ b/hub/columns/miscellaneous/oob.tex @@ -0,0 +1,6 @@ +\begin{enumerate}[resume] + \item $\miscOobInst$: + \oobMod{} instruction column; see \ob{TODO: add reference to the \oobMod{} module}; + \item $\miscOobDataCol{k}$, $k=1, 2, \dots, 8$: + data columns which carry both ``trusted'' inputs and ``predictions'' to the \oobMod{} module; +\end{enumerate} diff --git a/hub/columns/miscellaneous/other.tex b/hub/columns/miscellaneous/other.tex new file mode 100644 index 0000000..b20636a --- /dev/null +++ b/hub/columns/miscellaneous/other.tex @@ -0,0 +1,14 @@ +The following are ``truly miscellaneous'' columns. They will be used to record information locally with no intention of sending it to other modules for further processing. These columns will be used for dealing with \inst{CALL}'s and \inst{CREATE}'s. +\begin{enumerate}[resume] + \item $\miscChildSelfReverts$: + binary column; used for both \inst{CALL}-type and \inst{CREATE}-type instructions; prediction of whether or not the \textbf{C}hild \textbf{C}ontext will \textbf{S}elf-\textbf{R}evert; + \item $\miscChildRevertStamp$: + prediction of the \textbf{C}hild \textbf{C}ontext \textbf{R}evert time \textbf{S}tamp of a child context \emph{given that it self-reverts}; +\end{enumerate} +We provide some insight into the the significance of these columns. +The acronym \miscChildSelfReverts{} stands for ``\textbf{C}hild \textbf{C}ontext \textbf{S}elf \textbf{R}everts''. +As the name implies this bit represents information (a prediction, really) about \emph{some} child context: whether this child context will self revert or not. +We do not specify at this point \emph{which} child context to consider, what to make of this knowledge nor how to verify this prediction. +We simply assert that this bit will be of importance in the processing of +\inst{CREATE}-type instructions, see section~(\ref{}) \ob{TODO: add reference}, and of +\inst{CALL}-type instructions, see section~(\ref{}) \ob{TODO: add reference}. diff --git a/hub/columns/miscellaneous/stp.tex b/hub/columns/miscellaneous/stp.tex new file mode 100644 index 0000000..9ebb56e --- /dev/null +++ b/hub/columns/miscellaneous/stp.tex @@ -0,0 +1,24 @@ +\begin{enumerate}[resume] + \item $\miscStpInst$: + instruction which triggers the \stpMod{} module; \inst{CREATE}/\inst{CALL}-type; + \item $\miscStpGasHi$ and $\miscStpGasLo$: + gas parameter of the instruction; used for \inst{CALL}'s; + \item $\miscStpValueHi$ and $\miscStpValueLo$: + value parameter of the instruction (if present) + \item $\miscStpAccExists$: + bit specifying if an account exists or not; used for pricing \inst{CALL}'s + \item $\miscStpAccWarmth$: + bit specifying if an account is warm or not; used for \inst{CALL} pricing; + \item $\miscStpOogx$: + bit specifying if the instruction produces an \oogxSH{}; + \item $\miscStpGasMxp$: + memory expansion gas incurred by the instruction (in addition to any linear cost); + \item $\miscStpGasUpfront$: + the amount of gas a \inst{CREATE}/\inst{CALL}-type instruction costs upfront; + \item $\miscStpGasPoop$: + the amount of gas ``\textbf{p}aid \textbf{o}ut \textbf{o}f \textbf{p}ocket'' by the \creator{}/\callerr{} to the child context (in case of no \oogxSH{}); + \item $\miscStpGasStipend$: + the gas stipend that is provided to the \calleee{}/\createe{} in case of a \inst{CALL}-type instruction with nonzero value; either $0$ or $G_\text{callstipend} = 2300$; +\end{enumerate} +\saNote{} The \stpMod{} also requires ``actual gas'' and ``mxp gas'' fields. +These columns are readily available as shared columns (except for the ``mxp gas'' which is available in the same miscellaneous-row.) diff --git a/hub/columns/perspectives.tex b/hub/columns/perspectives.tex new file mode 100644 index 0000000..9e5a103 --- /dev/null +++ b/hub/columns/perspectives.tex @@ -0,0 +1,151 @@ +Due to the sheer number of different functions it fulfills, the \hubMod{} module contains a large amount of columns. +Its traces are therefore very \textbf{wide}, in fact, the \hubMod{} module is the widest module in our arithmetization. +With instruction processing typically requiring several rows in the \hubMod{} trace\footnote{usually one to five, though on rare occasions that number can go up to about twenty, see the processing of \inst{CALL}'s to the \inst{MODEXP} precompile, section (\ref{hub: instruction handling: call: precompiles: modexp: success})} its traces are also very \textbf{deep}. +As a consequence a typical trace for the \hubMod{} module occupies a large surface area (as measured by the number of cells that make up the trace matrix.) +On the other hand, most opcodes can be processed using only a fraction of the data available to the \hubMod{} module at any point in time. + +\textbf{Column blending} allows the arithmetization to save space by packing more data into a given ``trace footprint'', thereby reducing redundancy. +The idea is simple: certain ``physical'' columns \col{X} in the trace output ought to be understood as ``\textbf{the row-wise blending of several row-disjoint sparse virtual columns}'' $\col{C}^1, \col{C}^2, \col{C}^3, \dots{}$. +Concretely we mean that such a column \col{X} is constructed from other columns as follows: +(\emph{a}) there is a collection of sparse columns of depth $d$, say $\col{C}^1, \col{C}^2, \col{C}^3, \dots{}$ with the property that for any row-index $i$ at most one of the values $\col{C}^1_{i}, \col{C}^2_{i}, \col{C}^3_{i}, \dots{}$ is nonzero and +(\emph{b}) the column $\col{X}$, also of depth $d$, is such that +(\emph{i}) for any row-index $i$ there is some column-index $j$ with $\col{X}_{i} = \col{C}^{j}_{i}$ and +(\emph{ii}) $\col{X}_{i} = \col{C}^{j}_{i}$ whenever $\col{C}^{j}_{i} \neq 0$. +Traces will contain many such blended columns. + +The actual setup is a slight generalization of the above. +We will work with a small number $r$ of \textbf{perspectives}, i.e. families of sparse columns, +$\big \{ \col{C}^{1, k} \big| 1\leq k \leq n_{1}\big \}$, +$\big \{ \col{C}^{2, k} \big| 1\leq k \leq n_{2}\big \}$, +\dots, +$\big \{ \col{C}^{r, k} \big| 1\leq k \leq n_{r}\big \}$ +with the property any two members from different families are row-disjoint as defined above. +The \hubMod{} module traces will contain a great many columns obtained through blending of columns from these families. +\saNote{} For the above to make sense it is not necessary to require that all perspectives contain the same number of columns. +And as will become apparent when we introduce the various perspectives below, some perspectives contain more columns than others. + +The groupings of (virtual) columns which together define the various perspectives are such that they group related data together. +The idea being that, together, the columns of a perspective provide insight into a particular subcomponent of the \evm{}, whence the name ``perspective.'' +For instance we will introduce a \textbf{storage} perspective made up of several (virtual) columns which house data related to \textbf{storage} (e.g. storage keys, original, current and updated storage values, storage key warmth, \dots{}). +Another perspective we will introduce will contain data related to \textbf{execution contexts} (e.g. return data / call data pointers, underlying account addresses, call values, static bits etc\dots). +Yet another perspective we will introduce will contain data related to \textbf{inter module communication} (e.g. complex data to be sent to other modules such as the \textsc{ram} preprocessing module \mmuMod{}, the out of bounds module \oobMod{}, the stipend module \stpMod{} etc\dots). +\saNote{} A direct corollary of this approach is that we will define far more (virtual) columns than there are ``physical'' columns in the traces. + +While blended columns are plentiful in the traces, we will thankfully never have to manipulate them by hand. +Nor will we ever explicitly define which columns are blended together to define the associated ``physical'' columns in the trace. +We will consistently work with the underlying virtual columns belonging to the relevant perspective. +The only requirement for this approach to work is for the mapping taking any one (virtual) column from a given perspective to the blended column ``containing it as a subcolumn'' to be \textbf{set in stone in the circuit}, which it is. +\saNote{} There are various criteria and optimizations one may want to take into account when defining which columns to blend together in the traces. +One may, for instance, want to form blended columns of the same type i.e. by blending binary or byte columns together as much as posible, say. + +This puts a burden on the specification itself as we will have to ensure that whenever we refer to the value in a (virtual) column from a given perspective at a given point in time (i.e. on a given row $i$) we are certain that the corresponding value is the value present in the associated blended column. +We will make sure of this as follows. +Perspectives will be associated with \textbf{eponymous exclusive binary flags} $\peekAccount, \peekContext, \peekMisc, \peekScenario, \peekStack, \peekStorage, \peekTransaction$. +Exclusivity means that at most one of these may be on (i.e. $=1$) on any row. +Thus to ensure that the correct data will be available at the right place we will often enforce constraints which impose, given some precondition, that a certain sum of these shifted flags be equal to the number of terms intervening in this sum. For instance a constraint terminating with, e.g. +\[ + \left[ \begin{array}{cr} + + & \peekAccount_{i} \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} \\ + + & \peekContext_{i + 3} \\ + \end{array} \right] + = + 4 +\] +will make sure that, given the right preconditions, row $n^\circ~i$ is an account row, the following two rows are miscellaneous-rows followed by a context-row. +Enforcing such constraints legitimizes our usage of values from columns in the account perspective on row $i$ such as $\accAddressHi_{i}, \accNonce_{i}, \accWarmth_{i}$, +values from the miscellaneous perspective on rows $i + 1$ and $i + 2$, e.g. $\miscMmuInst_{i + 1}$ or $\miscStpGasStipend_{i + 2}$, +as well as values from the context perspective on row $i + 3$, e.g. $\cnCdo_{i + 3}$, $\cnCodeCfi_{i + 3}$ etc\dots{} +\saNote{} Perspectives have associated symbols which we use to prefix columns from that perspective and disambiguate columns which otherwise may have the same or very similar names (address columns are a prime example of this.) +Thus the names of (virtual) columns belonging to e.g. context perspective are of the form $\contextSignifier\col{ABC}$, scenario columns are of the form $\scenarioSignifier\col{ABC}$ and similarly for all other perspectives. + +The exclusive binary flags which we mentioned earlier are examples of so-called \textbf{shared} columns, i.e. ``standard'' or ``unblended'' columns. +The contents of such columns are available on every row of the trace and their interpretation is context independent. +They comprise data which is of constant use such as the \hubMod{} stamp \hubStamp{}, the current program counter \pc{}, the code fragment index \cfi{} of the code which is currently executing or gas parameters such as $\gasCost$ and $\gasActual$. +We shall begin by introducing these shared columns. + +\begin{figure} + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{% + |c|c| % batch & tx + |c|c|c|c| % TX phases (except for TX_SKIP_EXECUTION) + |c|c|c|c|c|c|c|c| % data columns + |c|c|c|c|c| % peeking columns + |c|} % hub stamp + \hline + \col{bt\#} & + \col{tx\#} & + % + \cellcolor{solarized-magenta!\lllight} \col{tw} & + \cellcolor{solarized-magenta!\llight} \col{ti} & + \cellcolor{solarized-magenta!\light} \col{te} & + \cellcolor{solarized-magenta} \col{tf} & + % + \!\star\! & + \!\star\! & + \!\star\! & + \!\star\! & + \!\star\! & + \!\star\! & + \!\star\! & + \!\star\! & + % + \cellcolor{solarized-cyan} \col{con}^\eye & + \cellcolor{solarized-yellow} \col{stk}^\eye & + \cellcolor{solarized-green} \col{acc}^\eye & + \cellcolor{solarized-blue} \col{sto}^\eye & + \cellcolor{solarized-orange} \col{tx}^\eye & \hubStamp \\\hline + \multicolumn{2}{c}{\vdots} + & + \multicolumn{4}{c}{\vdots} + & + \multicolumn{8}{c}{\vdots} + & + \multicolumn{5}{c}{\vdots} + & + \multicolumn{1}{c}{\vdots} + \\ + \btP & \allCdots & 12 \\\hline\hline + \bt & \twRow & \accRow & 13 \\\hline + \bt & \twRow & \stoRow & 13 \\\hline + \bt & \twDots & \allVdots \\\hline + \bt & \twRow & \stoRow & 13 \\\hline + \bt & \twRow & \accRow & 13 \\\hline + \bt & \twRow & \accRow & 13 \\\hline + \bt & \twRow & \stoRow & 13 \\\hline\hline + \bt & \tiRow & \accRow & 14 \\\hline + \bt & \tiRow & \accRow & 14 \\\hline + \bt & \tiRow & \conRow & 14 \\\hline + \bt & \tiRow & \txnRow & 14 \\\hline\hline + \bt & \teRow & \stkRow & 15 \\\hline + \bt & \teRow & \stkRow & 16 \\\hline + \bt & \teRow & \accRow & 16 \\\hline + \bt & \teRow & \stkRow & 17 \\\hline + \bt & \teRow & \conRow & 17 \\\hline + \bt & \teRow & \accRow & 17 \\\hline + \btDots & \teDots & \allVdots \\\hline + \bt & \teRow & \stkRow & 79 \\\hline + \bt & \teRow & \stoRow & 79 \\\hline + \bt & \teRow & \stkRow & 80 \\\hline + \bt & \teRow & \txnRow & 80 \\\hline + \bt & \teRow & \stkRow & 81 \\\hline + \bt & \teRow & \accRow & 81 \\\hline + \bt & \teRow & \accRow & 81 \\\hline + \bt & \teRow & \stkRow & 82 \\\hline + \bt & \teRow & \stkRow & 83 \\\hline + \bt & \teRow & \conRow & 83 \\\hline\hline + \bt & \tfRow & \accRow & 84 \\\hline + \bt & \tfRow & \accRow & 84 \\\hline + \bt & \tfRow & \txnRow & 84 \\\hline\hline + \btPP & \allCdots & 85 \\ + \end{array} + \] + \caption{Graphical representation of + \colorbox{solarized-cyan}{\textbf{context-rows}}, + \colorbox{solarized-yellow}{\textbf{stack-rows}}, + \colorbox{solarized-green}{\textbf{account-rows}}, + \colorbox{solarized-blue}{\textbf{storage-rows}} and + \colorbox{solarized-orange}{\textbf{transaction-rows}}.} + \end{figure} diff --git a/hub/columns/scenarios/_inputs.tex b/hub/columns/scenarios/_inputs.tex new file mode 100644 index 0000000..08da9d4 --- /dev/null +++ b/hub/columns/scenarios/_inputs.tex @@ -0,0 +1,6 @@ +\subsubsection{Introduction \lispDone{}} \label{hub: descriptions: scenarios: intro} \input{columns/scenarios/intro} +\subsubsection{\scenCall{} columns \lispDone{}} \label{hub: descriptions: scenarios: call} \input{columns/scenarios/call} +\subsubsection{\scenCreate{} columns \lispDone{}} \label{hub: descriptions: scenarios: create} \input{columns/scenarios/create} +\subsubsection{\scenReturn{} columns \lispDone{}} \label{hub: descriptions: scenarios: return} \input{columns/scenarios/return} +\subsubsection{\scenPrecompile{} columns \lispDone{}} \label{hub: descriptions: scenarios: precompile} \input{columns/scenarios/precompiles} +\subsubsection{\scenSelfdestruct{} columns \lispDone{}} \label{hub: descriptions: scenarios: selfdestruct} \input{columns/scenarios/selfdestruct} diff --git a/hub/columns/scenarios/call.tex b/hub/columns/scenarios/call.tex new file mode 100644 index 0000000..ba39b48 --- /dev/null +++ b/hub/columns/scenarios/call.tex @@ -0,0 +1,41 @@ +The following define a vast number of \textbf{exclusive binary columns}. The first batch of them deal with \inst{CALL}-type instructions: +% CALL scenarios: +\begin{enumerate} + \item \scenCallException: + turns on for \inst{CALL}-type instructions that raise an exception \emph{other than} \suxSH{}; + \item \scenCallAbortWillRevert: + turns on for unexceptional \inst{CALL}-type instructions that abort and which will be rolled back; + \item \scenCallAbortWontRevert: + turns on for unexceptional \inst{CALL}-type instructions that abort and which won't be rolled back; +\end{enumerate} +The columns below pertain to unexceptional, unaborted \inst{CALL}-type instrutions i.e. \inst{CALL}'s that are entered. +For the sake of clarity we provide our working definition of \textbf{precompiles}, \textbf{externally owned accounts} and \textbf{smart contracts}. +A \textbf{precompile} is an account whose address is in the range $\{\texttt{0x01},\texttt{0x02},\dots, \texttt{0x09}\}$. +A \textbf{smart contract} is any account with nonempty bytecode. +An \textbf{externally owned account} is any account that is neither a \textbf{precompile} nor a \textbf{smart contract}. +This includes accounts that were created through deployments but whose bytecode is empty. +Being a smart contract vs. an externally owned account isn't an inherent property of the underlying address but rather a property of an address with respect to the some state. + +\saNote{} The address space is partitioned according to this trichotomy. As a consequence so is the processing of \inst{CALL}-type instructions. + +\saNote{} We shall use the acronyms \textsc{prc} (resp. \textsc{smc}, \textsc{eoa}) for columns related to precompile (resp. smart contract, externally owned account) \inst{CALL}-processing. +\begin{enumerate}[resume] + \item \scenCallPrcFailure: + turns on for unsuccessful \inst{CALL}'s to precompiles; + \item \scenCallPrcSuccessWillRevert: + turns on for successful \inst{CALL}'s to precompiles that are rolled back later; + \item \scenCallPrcSuccessWontRevert: + turns on for successful \inst{CALL}'s to precompiles that aren't rolled back later; + \item \scenCallSmcFailureWillRevert: + turns on for unsuccessful \inst{CALL}'s to smart contracts that are later rolled back; + \item \scenCallSmcFailureWontRevert: + turns on for unsuccessful \inst{CALL}'s to smart contracts that aren't later rolled back; + \item \scenCallSmcSuccessWillRevert: + turns on for successful \inst{CALL}'s to smart contracts that are later rolled back; + \item \scenCallSmcSuccessWontRevert: + turns on for successful \inst{CALL}'s to smart contracts that aren't later rolled back; + \item \scenCallEoaSuccessWillRevert: + turns on for (successful) \inst{CALL}'s externally owned accounts that are rolled back later; + \item \scenCallEoaSuccessWontRevert: + turns on for (successful) \inst{CALL}'s externally owned accounts that aren't rolled back later; +\end{enumerate} diff --git a/hub/columns/scenarios/create.tex b/hub/columns/scenarios/create.tex new file mode 100644 index 0000000..ce9363b --- /dev/null +++ b/hub/columns/scenarios/create.tex @@ -0,0 +1,27 @@ +The following scenarios are used to deal with \inst{CREATE}-type instructions. \textbf{All columns below are binary}. +\begin{enumerate}[resume] + % CREATE scenarios: + \item \scenCreateException: + lights up precisely for \inst{CREATE}-type instructions that raise a (non \staticxSH{}) exception; + \item \scenCreateAbort: + lights up precisely for \inst{CREATE}-type instructions that don't raise an exception but are aborted; + \item \scenCreateFCondWillRevert: + lights up precisely for \inst{CREATE}-type instructions that don't raise an exception, aren't aborted but raise a failure condition; + on top of that the current execution context will (eventually) revert; + \item \scenCreateFCondWontRevert: + lights up precisely for \inst{CREATE}-type instructions that don't raise an exception, aren't aborted but raise a failure condition; + on top of that the current execution context won't revert; +\end{enumerate} +Let us say that a \inst{CREATE}-instruction +\textbf{gets executed}\label{hub: instruction handling: create: definition of 'get executed'} +if it is \textbf{unexceptional}, \textbf{isn't aborted} and \textbf{doesn't trigger a failure condition}. +The following columns are triggered for \inst{CREATE}-instructions that get executed. These scenarios are self describing. +\begin{enumerate}[resume] + \item \scenCreateEmptyInitCodeWontRevert{} + \item \scenCreateEmptyInitCodeWillRevert{} + \item \scenCreateNonEmptyInitCodeFailureWontRevert{} + \item \scenCreateNonEmptyInitCodeFailureWillRevert{} + \item \scenCreateNonEmptyInitCodeSuccessWontRevert{} + \item \scenCreateNonEmptyInitCodeSuccessWillRevert{} +\end{enumerate} + diff --git a/hub/columns/scenarios/intro.tex b/hub/columns/scenarios/intro.tex new file mode 100644 index 0000000..19b9cf4 --- /dev/null +++ b/hub/columns/scenarios/intro.tex @@ -0,0 +1,16 @@ +\textbf{Scenario-rows} are characterized by $\peekScenario \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\scenarioSignifier$. +The purpose of scenario-rows is to simplify the processing of certain instructions, most notably +\inst{RETURN} instructions, +\inst{CALL}-type instructions, and +\inst{CREATE}-type instructions. +These instructions are complex and give rise to a plethora of possible processing scenarios. +These scenarios will be captured by means of binary flags of the present perspective. +Using scenario-rows the present arithmetization is able to convert \textbf{complex (and numerous) pre-conditions} triggering a particular execution path into the following: +(\emph{a}) +a \textbf{single prediction} in the form of a scenario flag turning on +(\emph{b}) +a \textbf{verification} that the requisite (former pre-)conditions are met +(\emph{c}) +the adequate instruction processing over the next few rows. +The upshot of this approach is a considerable \textbf{degree reduction} in processing constraints. +Indeed, high degree ``condition prefixes'' become low degree ``scenario announcements'' followed by constraints justifying the particular scenario and enforcing the requisite conditions relating to execution. diff --git a/hub/columns/scenarios/old.tex b/hub/columns/scenarios/old.tex new file mode 100644 index 0000000..bcc9882 --- /dev/null +++ b/hub/columns/scenarios/old.tex @@ -0,0 +1,123 @@ +\textbf{Scenario-rows} are characterized by $\peekScenario \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\scenarioSignifier$. +The purpose of scenario-rows is to simplify the processing of certain instructions, most notably +\inst{RETURN} instructions, +\inst{CALL}-type instructions, and +\inst{CREATE}-type instructions. +These instructions are complex and give rise to a plethora of possible processing scenarios. +These scenarios will be captured by means of binary flags of the present perspective. +Using scenario-rows the present arithmetization is able to convert \textbf{complex (and numerous) pre-conditions} triggering a particular execution path into the following: +(\emph{a}) a \textbf{single prediction} in the form of a scenario flag turning on +(\emph{b}) a \textbf{verification} that the requisite (former pre-)conditions are met +(\emph{c}) the adequate instruction processing over the next few rows. +The upshot of this approach is a considerable \textbf{degree reduction} in processing constraints. +Indeed, high degree ``condition prefixes'' become low degree constraints involving + +The following define a vast number of \textbf{exclusive binary columns}. The first batch of them deal with \inst{CALL}-type instructions: +% CALL scenarios: +\begin{enumerate} + \item \scenCallAbort: + \item \scenCallToEoaCallerWontRevert: + \item \scenCallToEoaCallerWillRevert: + \item \scenCallToSmartContractCallerWontRevertCalleeSuccess: + \item \scenCallToSmartContractCallerWontRevertCalleeFailure: + \item \scenCallToSmartContractCallerWillRevertCalleeSuccess: + \item \scenCallToSmartContractCallerWillRevertCalleeFailure: + \item \scenCallToPrecompileSuccessCallerWontRevert: + \item \scenCallToPrecompileSuccessCallerWillRevert: + \item \scenCallToPrecompileFailureCallerWontRevert: + \item \scenCallToPrecompileFailureCallerWillRevert: + % \item \scenCallToPrecompileCallerWontRevertPrecompileSuccess: + % \item \scenCallToPrecompileCallerWontRevertPrecompileFailure: + % \item \scenCallToPrecompileCallerWillRevertPrecompileSuccess: + % \item \scenCallToPrecompileCallerWillRevertPrecompileFailure: +\end{enumerate} +\saNote{} In applications the +\scenCallToPrecompileFailureCallerWontRevert{} and \scenCallToPrecompileFailureCallerWillRevert{} +are very similar. + + +More \inst{CALL}-related scenarios. But the following scenarios will be used to deal with the \textsc{ram} operations triggered by precompiles: +\begin{enumerate}[resume] + \item \scenEcrecover: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECRECOVER} precompile; + \item \scenShaTwo: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{SHATWO} precompile; + \item \scenRipemd: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{RIPEMD} precompile; + \item \scenIdentity: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{IDENTITY} precompile; + \item \scenModexp: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{MODEXP} precompile; + \item \scenEcadd: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECADD} precompile; + \item \scenEcmul: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECMUL} precompile; + \item \scenEcpairing: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECPAIRING} precompile; + \item \scenBlake: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{BLAKE} precompile; +\end{enumerate} + +The following scenarios are used to deal with \inst{CREATE}-type instructions: +\begin{enumerate}[resume] + % CREATE scenarios: + \item \scenCreateException: + \item \scenCreateAbort: + \item \scenCreateFCondHasCodeWontRevert: + \item \scenCreateFCondHasCodeWillRevert: + \item \scenCreateFCondHasNonceWontRevert: + \item \scenCreateFCondHasNonceWillRevert: + \item \scenCreateWithInitCodeCurrWontRevertChildFailure: + \item \scenCreateWithInitCodeCurrWontRevertChildSuccess: + \item \scenCreateWithInitCodeCurrWillRevertChildFailure: + \item \scenCreateWithInitCodeCurrWillRevertChildSuccess: + \item \scenCreateSansInitCodeCurrWontRevert: + \item \scenCreateSansInitCodeCurrWillRevert: +\end{enumerate} + +The following scenario column simplifies dealing with \textbf{exceptional} \inst{RETURN} instructions: +\begin{enumerate}[resume] + \item \scenReturnException: + binary column; + lights up for unexceptional \inst{RETURN} instructions that \textbf{require} modifying the caller context's \textsc{ram}; +\end{enumerate} +The following scenarios are used to deal with \textbf{unexceptional} \inst{RETURN} instructions. +The first batch pertain to \inst{RETURN} instructions executed in a context spawned through a message call. +\begin{enumerate}[resume] + \item \scenReturnFromMessageCallWillTouchRam: + binary column; + lights up for unexceptional \inst{RETURN} instructions that \textbf{require} modifying the caller context's \textsc{ram}; + \item \scenReturnFromMessageCallWontTouchRam: + binary column; + lights up for unexceptional \inst{RETURN} instructions that \textbf{don't require} modifying the caller context's \textsc{ram}; +\end{enumerate} +\saNote{} An \textbf{unexceptional} \inst{RETURN} instruction in a message call context may modify the \textsc{ram} of its caller context \emph{iff} +(\emph{a}) the current context isn't the root context of the transaction +(\emph{b}) its size parameter is nonzero +(\emph{c}) the caller context provided the current context with a nonzero \rac{}. + +The next batch pertain to \inst{RETURN} instructions executed in a deployment context. +\begin{enumerate}[resume] + \item \scenReturnFromDeploymentEmptyByteCodeWillRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{will be rolled back}; + \item \scenReturnFromDeploymentEmptyByteCodeWontRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{won't be rolled back}; + \item \scenReturnFromDeploymentNonemptyByteCodeWillRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{will be rolled back}; + \item \scenReturnFromDeploymentNonemptyByteCodeWontRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{won't be rolled back}; +\end{enumerate} +\saNote{} We distinguish between ``empty'' deployments and ``nonempty'' deployments for two reasonss: +(\emph{a}) deploying nonempty bytecode requires checking the first byte of the memory segment as \texttt{0xEF} is prohibited +(\emph{b}) deploying nonempty bytecode requires reading data from \textsc{ram} and sending it boto the the \romMod{} module for (temporary) deployment and to the \hashDataMod{} module +(\emph{c}) deploying nonempty bytecode requires turning on the \hashInfoMod{} module. +None of these are required for (temporary) deployments of empty bytecode. + +\begin{enumerate}[resume] + \item \scenSelfdestruct: + binary column; lights up whenever the \zkEvm{} is about to attempt to run a \inst{SELFDESTRUCT} instruction; +\end{enumerate} diff --git a/hub/columns/scenarios/precompiles.tex b/hub/columns/scenarios/precompiles.tex new file mode 100644 index 0000000..b47fcfb --- /dev/null +++ b/hub/columns/scenarios/precompiles.tex @@ -0,0 +1,76 @@ +More \inst{CALL}-related scenarios. But the following scenarios will be used to deal with the \textsc{ram} operations triggered by precompiles: +\begin{enumerate}[resume] + \item \scenEcrecover: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECRECOVER} precompile; + \item \scenShaTwo: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{SHATWO} precompile; + \item \scenRipemd: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{RIPEMD} precompile; + \item \scenIdentity: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{IDENTITY} precompile; + \item \scenModexp: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{MODEXP} precompile; + \item \scenEcadd: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECADD} precompile; + \item \scenEcmul: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECMUL} precompile; + \item \scenEcpairing: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{ECPAIRING} precompile; + \item \scenBlake: + binary column; lights up whenever the \zkEvm{} is about to deal with the memory operations pertaining to the \texttt{BLAKE} precompile; +\end{enumerate} +We continue with columns that will be made to contain a local copy of data relevant to the pricing and execution of precompiles. +\begin{enumerate}[resume] + \item \scenPrcCurrentlyValidCallerGas: + contains the currently valid gas amount of the caller context; + \item \scenPrcGasAllowance : + contains the gas amount available to the execution of the precompile; + \item \scenPrcGasOwedToCaller : + contains the gas amount owed to the caller context after the precompile is done executing; +\end{enumerate} +\def\hereInitial {\col{initial}} +\def\hereUpfront {\col{upfront}} +\def\herePoop {\col{poop}} +\def\hereStipend {\col{stipend}} +\def\hereOwed {\col{owed}} +\def\herePostCall {\col{post}} +These column descriptions require more ample detail. +Let us set up some context. +Suppose that +(\emph{a}) \emph{prior} to the \inst{CALL}-type instruction the caller context was in possession of \hereInitial{} gas +(\emph{b}) the instruction has an upfront gas cost of \hereUpfront{} (which \hereInitial{} is able to cover i.e. $\hereInitial \geq \hereUpfront$) +(\emph{c}) the caller provides the callee (a precompile) an amount \herePoop{} of gas ``paid out of pocket'' +(\emph{d}) the callee receives a ``gas stipend'' \hereStipend{} (either $G_\text{callstipend} = 2300$ or $0$ depending on whether the call transfers value or not) +(\emph{e}) execution leaves the precompile in possession of \hereOwed{} gas (a quantity which is necessarily \emph{nonnegative}, $0$ being the correct value in case of a ``precompile specific failure'') +(\emph{f}) as the \inst{CALL} is done the caller context resumes execution with \gasNext{} gas. +Then the spec will ensure that +\[ + \left\{ \begin{array}{lcl} + \scenPrcCurrentlyValidCallerGas & \longleftarrow & \hereInitial - \big[ \hereUpfront + \herePoop \big] \\ + \scenPrcGasAllowance & \longleftarrow & \herePoop + \hereStipend \\ + \scenPrcGasOwedToCaller & \longleftarrow & \hereOwed{} \\ + \gasNext & \longleftarrow & \Big[ \hereInitial - \big[ \hereUpfront + \herePoop \big] \Big] + \hereOwed{} \\ + \end{array} \right. +\] +Let us further assume that execution of the precompile costs leaves the callee context with \hereOwed{} +Then we we will have +\begin{enumerate}[resume] + \item \scenPrcCdo: + contains the \CDO{} as defined by the \inst{CALL} instruction; + \item \scenPrcCds: + contains the \CDS{} as defined by the \inst{CALL} instruction; + \item \scenPrcRao: + contains the \RAO{} as defined by the \inst{CALL} instruction; + \item \scenPrcRac: + contains the \RAC{} as defined by the \inst{CALL} instruction; + \item \scenPrcFailureKnownToHub: + \textbf{prediction} that the precompile will fail and that the \hubMod{} can justify this failure without digging into \textsc{ram}; + \item \scenPrcFailureKnownToRam: + \textbf{prediction} that the precompile will fail but that justifying this failure will require interacting with \textsc{ram}; + \item \scenPrcSuccessWillRevert: + \textbf{prediction} that the precompile will succeed plus the information that the caller will revert; + \item \scenPrcSuccessWontRevert: + \textbf{prediction} that the precompile will succeed plus the information that the caller won't revert; +\end{enumerate} +\saNote{} We explain the meaning we ascribe to \textbf{precompile failure} and \textbf{precompile success} in definitions found in section~(\ref{hub: instruction handling: call: precompiles: failures vs. successes}). +We deliberately didn't choose the term ``exception'' to avoid any overlap with the standard \evm{} exceptions. diff --git a/hub/columns/scenarios/return.tex b/hub/columns/scenarios/return.tex new file mode 100644 index 0000000..f84cf80 --- /dev/null +++ b/hub/columns/scenarios/return.tex @@ -0,0 +1,41 @@ +The following scenario column simplifies dealing with \textbf{exceptional} \inst{RETURN} instructions: +\begin{enumerate}[resume] + \item \scenReturnException: + binary column; + lights up for unexceptional \inst{RETURN} instructions that \textbf{require} modifying the caller context's \textsc{ram}; +\end{enumerate} +The following scenarios are used to deal with \textbf{unexceptional} \inst{RETURN} instructions. +The first batch pertain to \inst{RETURN} instructions executed in a context spawned through a message call. +\begin{enumerate}[resume] + \item \scenReturnFromMessageCallWillTouchRam: + binary column; + lights up for unexceptional \inst{RETURN} instructions that \textbf{require} modifying the caller context's \textsc{ram}; + \item \scenReturnFromMessageCallWontTouchRam: + binary column; + lights up for unexceptional \inst{RETURN} instructions that \textbf{don't require} modifying the caller context's \textsc{ram}; +\end{enumerate} +\saNote{} An \textbf{unexceptional} \inst{RETURN} instruction in a message call context may modify the \textsc{ram} of its caller context \emph{iff} +(\emph{a}) the current context isn't the root context of the transaction +(\emph{b}) its size parameter is nonzero +(\emph{c}) the caller context provided the current context with a nonzero \rac{}. + +The next batch pertain to \inst{RETURN} instructions executed in a deployment context. +\begin{enumerate}[resume] + \item \scenReturnFromDeploymentEmptyByteCodeWillRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{will be rolled back}; + \item \scenReturnFromDeploymentEmptyByteCodeWontRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{won't be rolled back}; + \item \scenReturnFromDeploymentNonemptyByteCodeWillRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{will be rolled back}; + \item \scenReturnFromDeploymentNonemptyByteCodeWontRevert: + binary column; + lights up for unexceptional \inst{RETURN} deployments of empty bytecode which \textbf{won't be rolled back}; +\end{enumerate} +\saNote{} We distinguish between ``empty'' deployments and ``nonempty'' deployments for two reasonss: +(\emph{a}) deploying nonempty bytecode requires checking the first byte of the memory segment as \texttt{0xEF} is prohibited +(\emph{b}) deploying nonempty bytecode requires reading data from \textsc{ram} and sending it boto the the \romMod{} module for (temporary) deployment and to the \hashDataMod{} module +(\emph{c}) deploying nonempty bytecode requires turning on the \hashInfoMod{} module. +None of these are required for (temporary) deployments of empty bytecode. diff --git a/hub/columns/scenarios/selfdestruct.tex b/hub/columns/scenarios/selfdestruct.tex new file mode 100644 index 0000000..709e715 --- /dev/null +++ b/hub/columns/scenarios/selfdestruct.tex @@ -0,0 +1,10 @@ +\begin{enumerate}[resume] + \item \scenSelfdestructException: + binary column; lights up whenever the \zkEvm{} is about to attempt to run a \inst{SELFDESTRUCT} instruction and it raises an exception; + \item \scenSelfdestructWillRevert: + binary column; lights up whenever the \zkEvm{} runs an unexceptional \inst{SELFDESTRUCT} instruction which will get reverted; + \item \scenSelfdestructWontRevertAlreadyMarked: + binary column; lights up whenever the \zkEvm{} runs an unexceptional \inst{SELFDESTRUCT} instruction which won't get reverted on an account already $\accMarkedForSelfdestruct$; + \item \scenSelfdestructWontRevertNotYetMarked: + binary column; lights up whenever the \zkEvm{} runs an unexceptional \inst{SELFDESTRUCT} instruction which won't get reverted on an account not yet $\accMarkedForSelfdestruct$; +\end{enumerate} diff --git a/hub/columns/shared.tex b/hub/columns/shared.tex new file mode 100644 index 0000000..331f33a --- /dev/null +++ b/hub/columns/shared.tex @@ -0,0 +1,165 @@ +\begin{enumerate} + \item \absTxNum{}: monotone column containing the \ABSTXNUM{}; + \item \batchNum{}: transaction-constant column containing the \BATCHNUM{}; +\end{enumerate} +\saNote{} The \batchNum{} is extracted through a lookup to the \textbf{transaction data} module, see section~\ref{hub: heartbeat: absTxNum and batchNum}. + +\noindent The following are binary colums indicating the transaction processing phase currently unfolding. +\begin{enumerate}[resume] + \item \TXSKIP{}: + binary column which is on \emph{if and only if} a transaction processing requires no code execution; abbreviated to \txSkip{}; + \item \TXWARM{}: + binary column which is on \emph{if and only if} a transaction is currently is in the prewarming phase; abbreviated to \txWarm{}; + \item \TXINIT{}: + binary column which is on \emph{if and only if} a transaction is currently is in the initialization phase; abbreviated to \txInit{}; + \item \TXEXEC{}: + binary column which is on \emph{if and only if} a transaction is currently is in the execution phase; abbreviated to \txExec{}; + \item \TXFINL{}: + binary column which is on \emph{if and only if} a transaction is currently is in the finalization phase; abbreviated to \txFinl{}; +\end{enumerate} +Rows $i$ that satisfy $\txSkip_{i} = 1$ are called \textbf{skipping rows}. We similarly define +\textbf{prewarming rows} ($\txWarm_{i} = 1$), +\textbf{initialization rows} ($\txInit_{i} = 1$), +\textbf{execution rows} ($\txExec_{i} = 1$) and +\textbf{finalization rows} ($\txFinl_{i} = 1$]. +The following columns, starting with $\hubStamp$ provide a finer comb with which to sift through rows. +\begin{enumerate}[resume] + \item $\hubSTAMP$: module stamp for the hub; abbreviated to \hubStamp{}; + \item \TXENDSTAMP{}: transaction-constant column logging the final \hubStamp{} which appears in the hub executing a particular transaction; abbreviated to \txEndStamp{}; +\end{enumerate} +The following columns pertain to execution contexts. Every execution context has a unique identifier, a nonzero context number, and several environment variables. +\begin{enumerate}[resume] + \item $\CONTEXTMAYCHANGE$: + $\hubStamp{}$-constant binary column which turns on \emph{if and only if} the present execution context may change as a result of the present instruction; abbreviated to \cmc{}; + \item $\XAHOY$: + $\hubStamp{}$-constant binary column which turns on \emph{if and only if} the present instruction triggers an exception; abbreviated to $\xAhoy$; +\end{enumerate} +Within execution rows context numbers \emph{may} only change when the $\cmc$ flag is set. This happens \emph{precisely} when encountering an \textbf{exceptional halting condition} (henceforth simply \textbf{exception}), a \textbf{halting instruction}, a \textbf{\inst{CALL}-type} or \textbf{\inst{CREATE}-type} instruction, see section~\ref{hub: generalities: execution context may change flag}, executing on a \inst{CREATE} or \inst{CREATE2} instruction. + +We introduce stamp columns that pertain to memory expansion and to calls to \textsc{ram} +\begin{enumerate}[resume] + \item $\logStamp$: + stamp column; increments with every (unexceptional, unreverted) \inst{LOG}-type instruction; + \item $\mmuStamp$: + stamp column; increments when an instruction is launched which triggers the memory management unit module (i.e. the \mmuMod{} module); + \item $\mxpStamp$: + stamp column; increments when an instruction is launched which triggers the memory expansion module (i.e. the \mxpMod{} module); + \item $\domStamp$ and $\subStamp$: + pair of stamp columns; used to prepare events for future execution; +\end{enumerate} +The $\oobFlag$ may only turn on for instructions that may go out of bounds. These instructions are +(\emph{a}) \inst{CALLDATALOAD} where the comparison is done against the call data size; +(\emph{b}) \inst{RETURNDATALOAD} where the comparison is done against the return data size; +(\emph{c}) \inst{JUMP} and \inst{JUMPI} where the comparison is done against the code size; +\ob{TODO: make sure list is exhaustive} +\begin{enumerate}[resume] + \item $\cn{}$ and $\cn{}\new$: + $\hubStamp{}$-constant columns containing the current and upcoming context number; + \item $\caller{}$: + context-constant column containing the context number of the caller; +\end{enumerate} +In most circumstances one has $\cn{} = \cn{}\new$: that is: the (execution) context wherein the next instruction is executed coincides with the current one. In fact, unless the \CONTEXTMAYCHANGE{} flag is set the above always holds. The cases where those two differ is whenever properly entering a new execution context (e.g. when starting a transaction, or when entering a new context with a \inst{CREATE}-type or \inst{CALL}-type instruction) or, on the other hand, when (permanently) exiting an execution context (e.g. when encountering an exception or a halting instruction.) +\begin{enumerate}[resume] + \item $\cnWillRev$, $\cnGetsRev$, $\cnSelfRev$: + context-constant binary columns; + \item $\cnRevStamp$: + context-constant column containing the time stamp at which the present context reverts; $\cnRevStamp \neq 0 \iff \cnWillRev = 1$; +\end{enumerate} +We will impose that +$\cnWillRev = 1$ \emph{iff} the present execution contexts reverts, for one reason or another; +$\cnGetsRev = 1$ \emph{iff} the parent execution contexts reverts; +$\cnSelfRev = 1$ \emph{iff} the present execution contexts reverts through its own fault (eiter by encountering an exception or successfully executing on a \inst{REVERT}). We will impose the following constraints: +\begin{IEEEeqnarray*}{LCL} + \cnWillRev = 1 + & \iff & \big[\cnGetsRev = 1\big] \vee \big[\cnSelfRev = 1\big] \\ + & \iff & \cnRevStamp \neq 0 +\end{IEEEeqnarray*} +Knowing whether a rollback of all changes resulting from the execution of a particular (execution) context is the ``fault'' of that context or of some parent context isn't, \emph{a priori}, as important as knowing whether these changes should be rolled back or not. What \emph{is} important, though, is knowing \emph{when} to undo said changes. This crucial piece of information is deduced, in our arithmetization, from $\cnRevStamp$. The purpose of this colums is to record the $\hubStamp{}$ at the point at which the relevant reverting condition (an exception or the \inst{REVERT} opcode) is encountered. Note that when an execution context ``inherits'' a rollback from a parent context (i.e. $\cnGetsRev = 1$ \et $\cnSelfRev = 0$) \textbf{it inherits its parent's $\cnRevStamp$}. On the other hand when an execution context is ``responsible'' for its own rollback (i.e. $\cnSelfRev = 1$) \textbf{it sets its own $\cnRevStamp$}\footnote{and passes it on to each of its direct descendant context(s) who will similarly revert, either by virtue of their parent reverting or at their own hand.} Our arithmetization ensures all relevant (i.e. revertible) changes are undone precisely when $\hubStamp = \cnRevStamp$ and in \emph{reverse chronological order of occurrence}. The arithmetization achieves this by earmarking revertible events as they happen. This is the purpose of the $\domStamp{}$ / $\subStamp{}$ pair. +\begin{enumerate}[resume] + \item \cfi: context-constant column; contains the code fragment index of the bytecode being run in the current execution context; + \item \pc{} and $\pc\new$: stamp-constant columns containing the current \textbf{program counter} and its (expected) next value; + \item \height{} and $\height\new$: + contains the current and updated stack heights of the current execution context; + the height is in the range $\{0,1,\dots,1024\}$; $\stackHeight{}=0$ signifies an empty stack; +\end{enumerate} +The \CFI{} is an integer uniquely associated, in the \romLexMod{} module, with an \textbf{address}, a \textbf{deployment number} and a \textbf{deployment status}. It uniquely identifies a code fragment in the \romMod{} module. The $\pc\new$ column is included for sheer convenience. The temporal execution of the \textsc{evm} has all required data to justify the next value of the program counter (which may change non trivially with \inst{JUMP} and \inst{JUMPI} instructions and will need to resume correctly when resuming execution after a \inst{CALL}-type or \inst{CREATE}-type instruction.) +The following binary columns serve as indicators of what data is on display on any non-padding row. Every row either displays (and may modify) data from one of several data stores: +(\emph{a}) \textbf{context-rows} display \textbf{context data} and are characterized by $\peekContext \equiv 1$ +(\emph{b}) \textbf{account-rows} display \textbf{account data} and are characterized by $\peekAccount \equiv 1$ +(\emph{c}) \textbf{storage-rows} display \textbf{storage data} and are characterized by $\peekStorage \equiv 1$ +(\emph{d}) \textbf{stack rows} display \textbf{stack data} and are characterized by $\peekStack \equiv 1$ +(\emph{e}) \textbf{transaction-rows} display \textbf{transaction data} and are characterized by $\peekTransaction \equiv 1$ +(\emph{f}) \textbf{miscellaneous-rows} log data to be externalized for further processing to other modules; they are characterized by $\peekMisc \equiv 1$ +(\emph{g}) \textbf{scenario-rows} are used to simplify the control flow of complex instructions. +\begin{enumerate}[resume] + \item $\PEEKSTACK$: + binary column which switches on \emph{if and only if} the current row peeks into stack data; + abbreviated to $\peekStack$; + \item $\PEEKCONTEXT$: + binary column which switches on \emph{if and only if} the current row peeks into context data; + abbreviated to $\peekContext$; + \item $\PEEKACCOUNT$: + binary column which switches on \emph{if and only if} the current row peeks into account data (from which we \emph{exclude} storage data); + abbreviated to $\peekAccount$; + \item $\PEEKSTORAGE$: + binary column which switches on \emph{if and only if} the current row peeks into the (presently executing) account's storage; + abbreviated to $\peekStorage$; + \item $\PEEKTRANSACTION$: + binary column which switches on \emph{if and only if} the current row peeks into transaction data; + abbreviated to $\peekTransaction$; + \item $\PEEKMISC$: + binary column which switches on \emph{if and only if} the current row peeks into transaction data; + abbreviated to $\peekMisc$; + \item $\PEEKSCENARIO$: + binary column which switches on \emph{if and only if} the current row peeks into transaction data; + abbreviated to $\peekScenario$; +\end{enumerate} +\noindent We list some gas columns: +\begin{enumerate}[resume] + \item $\gasExpected$: + stamp-constant column; contains the ``expected'' currently available gas amount prior to instruction processing; + \item $\gasActual$: + stamp-constant column; contains the ``actual'' available gas amount prior to instruction processing; + \item $\gasCost$: + stamp-constant column; contains the ``upfront'' gas cost of an instruction; + \item $\gasNext$: + stamp-constant column; contains the gas amount which is expected to remain after instruction processing\footnote{and prior to any ``remaining gas refunds''} + \item $\refund$, $\refund\new$: + stamp-constant columns; contain the cumulative gas refund up to this point as well as the updated value; +\end{enumerate} +The idea behind these gas columns is as follows. +Anytime an instruction begins processing the current execution context (CEC) has an expectation as to how much gas it ``currently owns\footnote{i.e. prior to any refunds or expenses}.'' This is $\gasExpected$. +As we shall explain shortly, this \emph{expected} gas amount may not always reflect to the \emph{actual} gas amount available to the instruction. The $\gasActual$ column thus contains this ``actual gas amount.'' +The $\gasCost$ column holds the \emph{upfront gas cost} of an instruction. This gas cost is the sum of various gas expenses\footnote{Static and dynamic gas costs e.g. memory expansion cost, costs related to address / storage key warmth, any gas endowment passed on to a child contexts spawned by the current instruction \dots{}}. Thus when we check for $\oogxSH$ we shall always compare $\gasActual$ and $\gasCost$. +The $\gasNext$ column contains the gas amount the CEC expects to have at its disposal the next time an instruction executes. Whenever it makes sense it stores $\gasActual- \gasCost$, but it may also be set to 0 under certain conditions\ob{TODO: now that I've spelled it out in full, it seems this column is completely and utterly useless.} +Finally the \gasStipend{} column contains the amount of gas which may be provided to a child context spawned through a \inst{CALL}-type or \inst{CREATE}-type instruction. + +We now go into slightly more detail. Whenever a new execution context is spawned $\gasExpected$ is set \emph{manually}. This can happen in two ways: +(\emph{a}) +at the start of a transaction +(\emph{b}) +through a \inst{CALL}-type or \inst{CREATE}-type instruction. +In all other cases it is set using the previously valid value of $\gasNext$. Let us expand on this point. There are two cases. +The first (and most common) case is that the current instruction \emph{and} the previously executed instruction take place in the same execution context. In this case we set $\gasExpected$ is set to the previous value of $\gasNext$ (which can be found in the \emph{previous row}.) +The second (and final) case happens when the present row marks the reprisal of execution\footnote{within the current context} after a direct descendant context encountered a halting condition. In that case the value of $\gasExpected$ is set to $\gasNext$ from the last instruction executed in the present context (and which spawned the execution context from whence execution just returned.) This value (which may be \emph{anywhere among past rows} of the trace) must be confirmed by means of a row permutation. This permutation must juxtapose, in order of ascending context numbers and in chronological order, all rows pertaining to a given execution context. +We further note that it is the perview of the \stpMod{} module to compute the \gasStipend{} column whenever applicable. + +Note that the "the reprisal of execution" case is also when $\gasExpected$ may differ from $\gasActual$, as this is when ``remaining gas refunds'' can be added to $\gasExpected$. + +The following are two sets of ``counter/maximal counter value'' columns. Within execution rows the counters $\ct$ and $\nonStackRowsCounter$ impose at what point the \hubStamp{} changes (i.e. increases by $1$.) +\begin{enumerate}[resume] + \item $\tli{}$: + stamp-constant binary column; + \item $\ct$: + binary counter column; + \item $\nonStackRows$: + stamp-constant column containing the number of non stack-rows required for the present instruction; + \item $\nonStackRowsCounter$: + counter; remains constant while $\ct\neq\tli$ and the counts up until $\nonStackRows$; +\end{enumerate} +The pairs +$\ct$/$\tli$ and $\nonStackRowsCounter$/$\nonStackRows$ pairs only matter along execution rows. Along execution rows an instruction occupies precisely +\[ + \big( 1 + \tli \big) + \nonStackRows +\] +individual rows. $\tli$ is instruction decoded (on stack rows.) It indicates whether dealing with the instruction requires one stack row or two. Thus, along stack rows $\ct$ counts from $0$ to $\tli$. $\nonStackRows$ is constructed by hand on stack rows ($\tli$ is shorthand for $\TLI{}$.) It indicates how many (if any) non stack-rows are required to deal with the instruction at hand. As soon as $\ct$ reaches $\tli$ the $\nonStackRowsCounter$ column starts counting up from $1$ to $\nonStackRows$. diff --git a/hub/columns/stack.tex b/hub/columns/stack.tex new file mode 100644 index 0000000..dc234c9 --- /dev/null +++ b/hub/columns/stack.tex @@ -0,0 +1,143 @@ +\begin{center} + \boxed{\phantom{\Big|}\ob{TODO: get relevant stack columns from the hub}\phantom{\Big|}} +\end{center} +\textbf{Stack rows}\label{def: stack row} are characterized by $\peekStack \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\stackSignifier$. +The following are names for certain columns on stack rows. The first batch of columns names pertain to stack height. +The columns below are needed to justify stack underflow/overflow exceptions. They work in conjunction with the instruction decoded $\decDelta$ $\decAlpha$ +\begin{enumerate}[resume] + \item $\stackAlpha$ and $\stackDelta$: + \item $\stackNbRemove$ and $\stackNbAdd$: +\end{enumerate} +A stack row can peek into up to 4 \textbf{stack items} (parametrized by $k=1,2,3,4$). Two line instructions can peek into up to 8 (which, however, are placed on two consecutive stack rows.) +The next 20 (!) columns contain information about the stack items an instruction touches. +These 20 columns are comprised of 4 batches of 5 columns. +\begin{enumerate}[resume] + \item $\stackItemHeight{k}$: + column containing the height $\in\{1,\dots,1024\}$\footnote{Note the range difference between the $\stackItemHeight{k}$ columns and the \stackHeight{} column.} of the $k$-th touched stack item; + \item $\stackItemValHi{k}$, $\stackItemValLo{k}$: + high and low part of a stack value which is either found in the stack at height $\stackItemHeight{k}$ (if $\stackItemPop{k} = 1$) or which is placed at that height (if $\stackItemPop{k} = 0$); + \item $\stackItemPop{k}$: + binary column; $\stackItemPop{k} = 1$ indicates that the item at height $\stackItemHeight{k}$ was popped; $\stackItemPop{k} = 0$ indicates that the item at height $\stackItemHeight{k}$ was peeked at or pushed; + \item $\stackItemStamp{k}$: + stack stamp; +\end{enumerate} +How many \textbf{stack items} an instruction touches depends on the instruction itself; consecutive values of $\sStamp{}$ may jump by any value in the range $\{0,1,2,3,4,5,6,7,8\}$; the precise amount by which it jumps is decided by the \textbf{stack pattern} which the instruction follows. +\begin{enumerate}[resume] + \item $\stackInst{}$: + instruction column; loaded from the ROM; + \item $\stackSTATICGAS$: + instruction decoded static gas cost of instruction; + abbreviated to $\stackStaticGas{}$; +\end{enumerate} +What follows is a collection of (instruction decoded) binary flags that identify instruction families. +\begin{multicols}{4} + \begin{enumerate}[resume] + \item $\stackDecAccFlag$ + \item $\stackDecAddFlag$ + \item $\stackDecBinFlag$ + \item $\stackDecBtcFlag$ + \item $\stackDecCallFlag$ + \item $\stackDecConFlag$ + \item $\stackDecCopyFlag$ + \item $\stackDecCreateFlag$ + \item $\stackDecDupFlag$ + \item $\stackDecExtFlag$ + \item $\stackDecHaltFlag$ + \item $\stackDecInvalidFlag$ + \item $\stackDecJumpFlag$ + \item $\stackDecKecFlag$ + \item $\stackDecLogFlag$ + \item $\stackDecMachineStateFlag$ + \item $\stackDecModFlag$ + \item $\stackDecMulFlag$ + \item $\stackDecPushPopFlag$ + \item $\stackDecShfFlag$ + \item $\stackDecStackRamFlag$ + \item $\stackDecStoFlag$ + \item $\stackDecSwapFlag$ + \item $\stackDecTxnFlag$ + \item $\stackDecWcpFlag$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +The following flags allow us to simply distinguish instructions within a given instruction family. +\begin{multicols}{4} + \begin{enumerate}[resume] + \item $\decFlag{1}$ + \item $\decFlag{2}$ + \item $\decFlag{3}$ + \item $\decFlag{4}$ + \end{enumerate} +\end{multicols} +The following flags aren't strictly necessary. +They are useful in that they allow the \zkEvm{} to easily prevent certain exception flags from being switched on by certain opcodes, see section~(\ref{hub: generalities: exceptions: automatic vanishing}). +\begin{multicols}{2} + \begin{enumerate}[resume] + \item $\stackDecMxpFlag$ + \item $\stackDecStaticFlag$ + \end{enumerate} +\end{multicols} +The following columns contain values extracted from the \romMod{} module. +\begin{enumerate}[resume] + \item $\stackPushParamHi$ and $\stackPushParamLo$: + instruction argument loaded from the ROM; matters only for \inst{PUSH\_X} instructions; + \item $\stackJUMPDESTINATIONVETTING$: + binary column; lights up precisely when a \inst{JUMP}-type instruction requires jump destination vetting; abbreviated to \stackJumpDestinationVetting{}; +\end{enumerate} +The following column names relate to \textsc{evm}-exceptions. +They are all stack-row-constant binary columns. +\begin{enumerate}[resume] + \item \stackOpcx{}: + records the occurrence of \opcxSH{}; + \item \stackSux{}: + records the occurrence of \suxSH{}; + \item \stackSox{}: + records the occurrence of \soxSH{}; + \item \stackMxpx{}: + records the occurrence of \mxpxSH{}; + \item \stackOogx{}: + records the occurrence of \oogxSH{}; + \item \stackRdcx{}: + records the occurrence of \rdcxSH{}; + \item \stackJumpx{}: + records the occurrence of \jumpxSH{}; + \item \stackStaticx{}: + records the occurrence of \staticxSH{}; + \item \stackSstorex{}: + records the occurrence of \sstorexSH{}; + \item \stackIcpx{}: + records the occurrence of \icpxSH{}; + \item \stackMaxcsx{}: + records the occurrence of \maxcsxSH{}; +\end{enumerate} +\saNote{} The $\stackOpcx{} \equiv \stackDecInvalidFlag{}$ flag is unique among all flags in that it is instruction decoded. The \mxpxSH{} is an exception type which we added. It represents a \emph{subcase} of the \oogxSH{}: the subcase where the gas costs stemming from memory expansion alone has been identified by the \textbf{memory expansion module} (\mxpMod{}) as large enough to force an \oogxSH{}. +\begin{enumerate}[resume] + \item \stackHashInfoFlag{}: + binary column that ligts up precisely for those instructions that require a \emph{nontrivial} \inst{KECCAK} hash to be performed; + this column is strongly tied to the (shared) \hashInfoStamp{} column; + % \item \stackHashInfoSize{}: + % (nonzero) size of (nonempty) message to hash; + \item \stackHashInfoValHi{} and \stackHashInfoValLo{}: + columns that may at times contain (the high and low parts of) a \inst{KECCAK} hash; + \item \stackLogFlag{}: + binary column that lights up precisely for (unexceptional, unreverted) \inst{LOG}-type instructions; +\end{enumerate} + +\ob{TODO: I don't think we need this many exception flags --- i.e. we may alias them. We should (must) keep individual exception columns such as +\sux{}, +\sox{}, +\oogx{}, +$\decopcx{}$. +They hey will nearly always apply and are justified directly in the stack. Also $\opcx$ will be justified through instruction decoding so I imagine we require a dedicated column. The following exceptions +\rdcx{}, +\jumpx{}, +\staticx{}, +\sstorex{}, +\icpx{}, +\maxcsx{} +are in a sense nearly disjoint. There are pairs that may be triggered by one instruction: +$(\staticx{}, \sstorex{})$ and +$(\icpx{}, \maxcsx{})$. They could very well share a single column which is semantically overloaded.} diff --git a/hub/columns/storage.tex b/hub/columns/storage.tex new file mode 100644 index 0000000..830f1f3 --- /dev/null +++ b/hub/columns/storage.tex @@ -0,0 +1,37 @@ +\textbf{Storage-rows} are characterized by $\peekStorage \equiv 1$ and columns pertaining to that perspective are prefixed with the following symbol: $\storageSignifier$. +\begin{enumerate} + \item $\stoAddressHi$, $\stoAddressLo$: + high and low parts of an account address; + \item $\stoDeploymentNumber$: + currently valid deployment number of said account address; + \item $\stoKeyHi$, $\stoKeyLo$: + high and low parts of a storage key of said account address; + \item $\stoOrigValueHi$, $\stoOrigValueLo$: + high and low parts of the value originally found in storage at the beginning of the transaction; + \item $\stoCurrValueHi$, $\stoCurrValueLo$: + high and low parts of the value currently found at the storage key; + \item $\stoNextValueHi$, $\stoNextValueLo$: + high and low parts of the updated value in storage; + \item $\stoWarmth$, $\stoWarmth\new$: + binary columns containing the storage key's warmth and its updated warmth; + \item + $\stoOrigValueIsZero$, + $\stoCurrValueIsOrig$, + $\stoCurrValueIsZero$, + $\stoNextValueIsCurr$, + $\stoNextValueIsZero$, + $\stoNextValueIsOrig$: + binary columns whose purpose is to streamline the computation of gas costs of \inst{SSTORE} instructions. +\end{enumerate} +The desired interpretation is straightfoward: +\[ + \left\{ \begin{array}{lclclcl} + \stoOrigValueIsZero & \!\!\! = \!\!\! & 1 & \iff & \stoOrigValue & \!\!\! = \!\!\! & 0 \\ + \stoCurrValueIsZero & \!\!\! = \!\!\! & 1 & \iff & \stoCurrValue & \!\!\! = \!\!\! & 0 \\ + \stoNextValueIsZero & \!\!\! = \!\!\! & 1 & \iff & \stoNextValue & \!\!\! = \!\!\! & 0 \\ + \stoCurrValueIsOrig & \!\!\! = \!\!\! & 1 & \iff & \stoCurrValue & \!\!\! = \!\!\! & \stoOrigValue \\ + \stoNextValueIsOrig & \!\!\! = \!\!\! & 1 & \iff & \stoNextValue & \!\!\! = \!\!\! & \stoOrigValue \\ + \stoNextValueIsCurr & \!\!\! = \!\!\! & 1 & \iff & \stoCurrValue & \!\!\! = \!\!\! & \stoNextValue \\ + \end{array} \right. +\] +See section~\ref{hub: storage-rows: gas cost binary columns}. diff --git a/hub/columns/transaction.tex b/hub/columns/transaction.tex new file mode 100644 index 0000000..8beba88 --- /dev/null +++ b/hub/columns/transaction.tex @@ -0,0 +1,87 @@ +\textbf{Transaction-rows} are characterized by $\peekTransaction_{i} \equiv 1$. +Transations specify a number of parameter that influence the execution of transaction. +Transactions go through initial vetting. +Some of that vetting is carried out in the \hubMod{}, some of it is carried out in the \txnDataMod{}. +One must check that +(\emph{a}) that the account's balance is sufficient to pay for gas and value to transfer +(\emph{b}) taht the nonce provided in the transaction coincides with that of the sender account as found in the state. +Transaction data is further used to set some initial parameters of the execution environment (such as the address of the account whose bytecode is executed or setting the initial available gas.) +Furthermore transaction data makes its way directly into the execution through opcodes such as \inst{} +\begin{enumerate} + \item $\txBatchNum$: + \godGiven{} + batch number of the batch containing the present transaction; + \item $\txFrom\high$, $\txFrom\low$: + \godGiven{} + high and low parts of the sender address of the transaction; deduced from the signature; + \item $\txNonce$: + \godGiven{} + account nonce $T_\text{n}$ as specified in the transaction; + \item $\txInitialBalance$: + \markAsJustifiedHere{} + \godGiven{} + value available in the sender just as the current transaction is about to start processing; confirmed at transaction start; + \item $\txValue$: + \godGiven{} + transfer value of the transaction; + \item $\txTo\high$, $\txTo\low$: + \godGiven{} + high and low part of the recipient address; + if the transaction is a message call transaction (i.e. $T_{\text{t}} \neq \varnothing$) this is $T_{\text{t}}$; + if the transaction is a contract creation transaction (i.e. $T_{\text{t}} = \varnothing$) this is the address deduced from the account nonce $T_\text{n}$ and the sender address; + \item $\txRequiresEvmExecution$: + \markAsPartiallyJustifiedHere{} + \godGiven{} + binary column which lights for transactions that trigger \emph{nontrivial} \evm{} execution; + \ob{TODO: not quite God Given, actually entirely computed in the skipping/initialization phases} + \item $\txCopyTxcd$: + \godGiven{} + binary column which lights up for message call transactions requiring \evm{} execution and being provided with nonempty call data; + \item $\txIsDeployment$: + \godGiven{} + binary column; equals $0$ \emph{iff} the transaction is a message call ($T_\text{t} \neq \varnothing$); equals $1$ if and only if the transaction is a contract deployment transaction ($T_{\text{t}} = \varnothing$.) + \item $\txIsTypeTwo$: + \godGiven{} + binary column which equals $1$ for \textsc{eip1559} transactions only; + \item $\txGasLimit$: + \godGiven{} + contains the transaction's gas limit $T_\text{g}$; + \item $\txInitialGas$: + \godGiven{} + intial gas provided to execution; + \item $\txGasPrice$: + \godGiven{} + gas price as returned by the \inst{GASPRICE} opcode; + \item $\txPriorityFeePerGas$: + \godGiven{} + rate at which the \inst{COINBASE} address is paid for consumed gas; + \item $\txBasefee$: + \godGiven{} + the transaction's (i.e. batch's) base fee; + \item $\txCallDataSize$: + \godGiven{} + contains the size of the call data $\|T_\textbf{d}\|$ when $\txIsDeployment \equiv 0$; + \item $\txInitCodeSize$: + \godGiven{} + contains the size of the initialization code $\|T_\textbf{i}\|$ when $\txIsDeployment \equiv 1$; + \item $\txStatusCode$: + \markAsJustifiedHere{} + \godGiven{} + status code of the transaction; confirmed at the end of transaction processing; + \item $\txLeftoverGas$: + \markAsJustifiedHere{} + \godGiven{} + left over gas of the transaction; confirmed at the end of transaction processing; + \item $\txFinalRefundCounter$: + \markAsJustifiedHere{} + \godGiven{} + sum total of all (non reverted) gas refunds accumulated during transaction execution; confirmed at transaction end; + \item $\txEffectiveRefund$: + \godGiven{} + amount of gas to be refunded to the sender $S(T)$ at transaction end; + \item $\txCoinbase\high$, $\txCoinbase\low$: + \godGiven{} + high and low part of the coinbase address; +\end{enumerate} +\saNote{} More transaction fields are available in the \txnDataMod{} module. The above represents the only fields which are needed in the \hubMod{} module. +\saNote{} Some of the above are fields that are \emph{extracted} from the \hubMod{} module (at various stages of execution) rather than being provided to it, e.g. $\txRequiresEvmExecution$, $\txStatusCode{}$, $\txLeftoverGas{}$ or $\txFinalRefundCounter{}$. diff --git a/hub/consistencies/_inputs.tex b/hub/consistencies/_inputs.tex new file mode 100644 index 0000000..615d0a0 --- /dev/null +++ b/hub/consistencies/_inputs.tex @@ -0,0 +1,9 @@ +\input{consistencies/_local} + +\section{Consistencies} \label{hub: consistencies} +\subsection{Introduction} \label{hub: consistencies: intro} \input{consistencies/intro} \newpage +\subsection{Execution environment consistency constraints \lispDone{}} \label{hub: consistencies: environment} \input{consistencies/environment/_inputs} \newpage +\subsection{Context consistency constraints \lispDone{}} \label{hub: consistencies: context} \input{consistencies/context/_inputs} \newpage +\subsection{Stack consistency constraints \lispWip {}} \label{hub: consistencies: stack} \input{consistencies/stack/_inputs} \newpage +\subsection{Account consistency constraints \lispDone{}} \label{hub: consistencies: account} \input{consistencies/account/_inputs} \newpage +\subsection{Storage consistency constraints \lispDone{}} \label{hub: consistencies: storage} \input{consistencies/storage/_inputs} \newpage diff --git a/hub/consistencies/_local.tex b/hub/consistencies/_local.tex new file mode 100644 index 0000000..5891544 --- /dev/null +++ b/hub/consistencies/_local.tex @@ -0,0 +1 @@ +\def\locOrderedFullAddress {\order{\col{full\_address}}} diff --git a/hub/consistencies/account/_inputs.tex b/hub/consistencies/account/_inputs.tex new file mode 100644 index 0000000..3d2afc7 --- /dev/null +++ b/hub/consistencies/account/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsection{Properties of the permutation} \label{hub: consistencies: account: permutation} \input{consistencies/account/permutation} +\subsubsection{Permuted columns} \label{hub: consistencies: account: columns to permute} \input{consistencies/account/columns} +\subsubsection{Constraints for $\accFirst$ and $\accFinal$} \label{hub: consistencies: account: permutation} \input{consistencies/account/first_final} +\subsubsection{Constraints} \label{hub: consistencies: account: constraints} \input{consistencies/account/constraints} diff --git a/hub/consistencies/account/_opt.tex b/hub/consistencies/account/_opt.tex new file mode 100644 index 0000000..a2679af --- /dev/null +++ b/hub/consistencies/account/_opt.tex @@ -0,0 +1,117 @@ +We present the consistency constraints that apply to account data. +Consider a row permutation $\col{X} \rightsquigarrow \order{\col{X}}$ such that +\[ + \left[\begin{array}{l} + \order{\peekAccount}, \\ + \quad\quad\quad \order{\accAddress\high}, \\ + \quad\quad\quad \quad\quad\quad \order{\accAddress\low}, \\ + % \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\accDepNumber \cdot \peekAccount}, \\ + \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\domStamp}, \\ + \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad\order{\subStamp} \\ + \end{array}\right] +\] +\noindent is $(+, +, +, +, -)$-lexicographically ordered. +In particular the rows where $\peekAccount \equiv 0$ appear before the rows where $\peekAccount \equiv 1$. +We define the following shorthand +\[ + \locOrderedFullAddress_{i} + \define + 256^\llarge \cdot \order{\accAddress\high}_{i} + \order{\accAddress\low}_{i} +\] +We impose the following consistency constraint: +\begin{description} + \item[Setting $\accAddressAgain$ and $\accAddressFirst$:] + we impose that + \begin{enumerate} + \item $\accAddressAgain$ and $\accAddressFirst$ are binary + \item $\accAddressAgain_{i} + \accAddressFirst_{i} = \order{\peekAccount}_{i}$ + \item \If $\order{\peekAccount}_{i} = 0$ \Then $\accAddressFirst_{i + 1} = \order{\peekAccount}_{i + 1}$ + \item \If $\order{\peekAccount}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\accAddressFirst_{i + 1} = 1$ \Then $ \locOrderedFullAddress_{i + 1} \neq \locOrderedFullAddress_{i} $ + \item \If $\accAddressAgain_{i + 1} = 1$ \Then $ \locOrderedFullAddress_{i + 1} = \locOrderedFullAddress_{i} $ + \end{enumerate} + \end{enumerate} + The above fully characterizes $\accAddressAgain$ and $\accAddressFirst$. + \item[Setting $\accAbsTxNumAgain$ and $\accAbsTxNumFirst$:] + we impose that + \begin{enumerate} + \item $\accAbsTxNumAgain$ and $\accAbsTxNumFirst$ are binary + \item \If $\order{\absTxNum}_{i} = 0$ \Then $\accAbsTxNumAgain_{i} + \accAbsTxNumFirst_{i} = 0$ + \item \If $\order{\absTxNum}_{i} \neq 0$ \Then $\accAbsTxNumAgain_{i} + \accAbsTxNumFirst_{i} = 1$ + \item \If $\accAddressFirst_{i} = 1$ \Then $\order{\absTxNum}_{i} \neq \order{\absTxNum}_{i - 1}$ + \item \If $\accAddressAgain_{i} = 1$ \Then $\order{\absTxNum}_{i} = \order{\absTxNum}_{i - 1}$ + \end{enumerate} + \item[Simple linking constraints:] + \If $\accAddressAgain _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\accNonce }_{i} & = & \order{\accNonce \new }_{i - 1} \\ + \order{\accBalance }_{i} & = & \order{\accBalance \new }_{i - 1} \\ + \order{\accCodesize }_{i} & = & \order{\accCodesize \new }_{i - 1} \\ + \order{\accCodehash }_{i} & = & \order{\accCodehash \new }_{i - 1} \\ + \order{\accDepNumber }_{i} & = & \order{\accDepNumber \new }_{i - 1} \\ + \order{\accDepStatus }_{i} & = & \order{\accDepStatus \new }_{i - 1} \\ + \order{\accHasCode }_{i} & = & \order{\accHasCode \new }_{i - 1} \\ + \order{\accExists }_{i} & = & \order{\accExists \new }_{i - 1} \\ + \end{array} \right. + \] + \item[Other linking constraints:] + we impose that + \begin{enumerate} + \item \If $\accAddressFirst _{i} = 1$ \Then + \begin{enumerate} + \item $\order{\accTrmFlag}_{i} = 1$ \ob{TODO: is the raw address set ?} + \item $\order{\accWarmth}_{i} = \order{\accTrmIsPrecompile}_{i}$ + \item $\order{\accMarkedForSelfdestruct}_{i} = 0$ + \item $\order{\accDepNumber }_{i} = 0$ + \item $\order{\accDepStatus }_{i} = 0$ + \end{enumerate} + \item \If $\accAddressAgain _{i} = 1$ \Then + \begin{enumerate} + \item \If $\accAbsTxNumAgain_{i} = 1$ \Then + \begin{enumerate} + \item $ \order{\accWarmth}_{i} = \order{\accWarmth\new}_{i - 1} $ + \item $ \order{\accMarkedForSelfdestruct}_{i} = \order{\accMarkedForSelfdestruct\new}_{i - 1} $ + \end{enumerate} + \item \If $\accAbsTxNumFirst_{i} = 1$ \Then $\order{\accWarmth}_{i} = \order{\accTrmIsPrecompile}_{i}$ + \begin{enumerate} + \item $ \order{\accWarmth}_{i} = \order{\accTrmIsPrecompile}_{i}$ + \item $ \order{\accMarkedForSelfdestruct}_{i} = 0 $ + \item $\order{\accDepStatus }_{i} = 0$ + \end{enumerate} + \item $\order{\accTrmIsPrecompile}_{i} = \order{\accTrmIsPrecompile}_{i - 1}$ + \end{enumerate} + \end{enumerate} + \item[Monotony constraints:] + \If $\order{\peekAccount}_{i} = 1$ \Then + we impose that + \begin{enumerate} + \item $ \order{\accDepNumber \new }_{i} \in \{ \order{\accDepNumber }_{i}, 1 + \order{\accDepNumber }_{i} \} $ + \item \If $ \order{\accDepNumber \new }_{i} \neq 1 + \order{\accDepNumber }_{i} $ \\ + {} \qquad\qquad \Then $\order{\accDepStatus \new }_{i} \in \{ \order{\accDepStatus }_{i}, - 1 + \order{\accDepStatus }_{i} \} $ + \item \If $ \order{\accMarkedForSelfdestruct}_{i} = 1$ \\ + \Then $\order{\accMarkedForSelfdestruct\new}_{i} = 1 $ + \end{enumerate} + \item[Constancy and finalization conditions:] + \begin{enumerate} + \item \If $\accAddressAgain _{i} = 1$ \Then + we impose that + \begin{enumerate} + \item $\order{\accDepNumber^\infty}_{i} = \order{\accDepNumber^\infty}_{i - 1}$ + \item $\order{\accDepStatus^\infty}_{i} = \order{\accDepStatus^\infty}_{i - 1}$ + \end{enumerate} + \item \If $\order{\peekAccount}_{i} = 1$ \et $\accAddressFirst _{i + 1} = 1$ \Then + we impose that + \begin{enumerate} + \item $\order{\accDepNumber^\infty}_{i} = \order{\accDepNumber}_{i}$ + \item $\order{\accDepStatus^\infty}_{i} = \order{\accDepStatus}_{i}$ + \end{enumerate} + \item \If $\order{\peekAccount}_{N} = 1$ \Then + we impose that + \begin{enumerate} + \item $\order{\accDepNumber^\infty}_{N} = \order{\accDepNumber}_{N}$ + \item $\order{\accDepStatus^\infty}_{N} = \order{\accDepStatus}_{N}$ + \end{enumerate} + \end{enumerate} +\end{description} diff --git a/hub/consistencies/account/columns.tex b/hub/consistencies/account/columns.tex new file mode 100644 index 0000000..7670dad --- /dev/null +++ b/hub/consistencies/account/columns.tex @@ -0,0 +1,29 @@ +We list the columns that must be row-permuted according to the previously described row-permutation. +\begin{multicols}{3} + \begin{enumerate} + \item $\order{\peekAccount}$ + \item $\order{\accAddress\high}$ + \item $\order{\accAddress\low}$ + \item $\order{\domStamp}$ + \item $\order{\subStamp}$ + % + \item $\order{\accTrmFlag}$ + \item $\order{\accTrmIsPrecompile}$ + \item $\order{\accWarmth}$ + \item $\order{\accWarmth\new}$ + \item $\order{\accCodesize}$ + \item $\order{\accCodesize\new}$ + \item $\order{\accCodehashHi}$ + \item $\order{\accCodehashLo}$ + \item $\order{\accCodehashHi\new}$ + \item $\order{\accCodehashLo\new}$ + \item $\order{\accDepNumber}$ + \item $\order{\accDepNumber\new}$ + \item $\order{\accDepNumber^\infty}$ + \item $\order{\accDepStatus}$ + \item $\order{\accDepStatus\new}$ + \item $\order{\accMarkedForSelfdestruct}$ + \item $\order{\accMarkedForSelfdestruct\new}$ + \item $\order{\absTxNum}$ + \end{enumerate} +\end{multicols} diff --git a/hub/consistencies/account/constraints.tex b/hub/consistencies/account/constraints.tex new file mode 100644 index 0000000..f42ae42 --- /dev/null +++ b/hub/consistencies/account/constraints.tex @@ -0,0 +1,78 @@ +We impose the following consistency constraint: +\begin{description} + \item[Initialization constraints (1):] + \If $\accFirst_{i} = 1$ + \Then we impose that + \begin{enumerate} + \item $\order{\accTrmFlag}_{i} = \rOne$ + \item $\order{\accWarmth}_{i} = \order{\accTrmIsPrecompile}_{i}$ + \item $\order{\accMarkedForSelfdestruct}_{i} = 0$ + \item $\order{\accDepNumber}_{i} = 0$ + \item $\order{\accDepStatus}_{i} = 0$ + \end{enumerate} + \saNote{} + The first time execution encounters a given address the \zkEvm{} is required to make a call to the \trmMod{}. + This call justifies the \accTrmIsPrecompile{} flag. + Below we enforce constancy of that flag along account-rows of a given address. + \item[Simple linking constraints:] + \If + \[ + \left\{ \begin{array}{lclc} + \order{\peekAccount} _{i} & = & 1 & \et \\ + \accFirst_{i} & = & 0 \\ + \end{array} \right. + \] + \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \order{\accNonce }_{i} & = & \order{\accNonce \new }_{i - 1} \\ + \order{\accBalance }_{i} & = & \order{\accBalance \new }_{i - 1} \\ + \order{\accCodesize }_{i} & = & \order{\accCodesize \new }_{i - 1} \\ + \order{\accCodehash\col{\_HI} }_{i} & = & \order{\accCodehash\col{\_HI} \new }_{i - 1} \\ + \order{\accCodehash\col{\_LO} }_{i} & = & \order{\accCodehash\col{\_LO} \new }_{i - 1} \\ + \order{\accTrmIsPrecompile }_{i} & = & \order{\accTrmIsPrecompile }_{i - 1} \vspace{2mm} \\ + \order{\accDepNumber }_{i} & = & \order{\accDepNumber \new }_{i - 1} \\ + \order{\accDepStatus }_{i} & = & \order{\accDepStatus \new }_{i - 1} \\ + \order{\accDepNumber^\infty }_{i} & = & \order{\accDepNumber^\infty }_{i - 1} \\ + \order{\accDepStatus^\infty }_{i} & = & \order{\accDepStatus^\infty }_{i - 1} \\ + \end{array} \right. + \] + \item[Linking and resetting constraints:] + \If + \[ + \left\{ \begin{array}{lclc} + \order{\peekAccount} _{i} & = & 1 & \et \\ + \accFirst_{i} & = & 0 \\ + \end{array} \right. + \] + \Then we impose + \begin{enumerate} + \item \If $\order{\absTxNum}_{i} = \order{\absTxNum}_{i - 1}$ \Then + \begin{enumerate} + \item $ \order{\accWarmth}_{i} = \order{\accWarmth\new}_{i - 1} $ + \item $ \order{\accMarkedForSelfdestruct}_{i} = \order{\accMarkedForSelfdestruct\new}_{i - 1} $ + \end{enumerate} + \item \If $\order{\absTxNum}_{i} \neq \order{\absTxNum}_{i - 1}$ \Then + \begin{enumerate} + \item $\order{\accWarmth}_{i} = \order{\accTrmIsPrecompile}_{i}$ + \item $\order{\accMarkedForSelfdestruct}_{i} = 0 $ + \item $\order{\accDepStatus}_{i} = 0$ \quad (\trash) + \end{enumerate} + \saNote{} In conjunction with the previous set of constraints the above enforces that by the end of any transaction the deployment status of any address must be $0$. + \end{enumerate} + \item[Constancy and finalization conditions:] + \If $\accFinal_{i} = 1$ \Then + we impose the following + \begin{enumerate} + \item $\order{\accDepNumber^\infty}_{i} = \order{\accDepNumber}_{i}$ + \item $\order{\accDepStatus^\infty}_{i} = \order{\accDepStatus}_{i}$ + \end{enumerate} + \item[Monotony constraints:] + \If $\order{\peekAccount}_{i} = 1$ \Then + we impose that + \begin{enumerate} + \item $ \order{\accDepNumber \new }_{i} \in \{ \order{\accDepNumber }_{i}, 1 + \order{\accDepNumber }_{i} \} $ + \item \If $ \order{\accMarkedForSelfdestruct}_{i} = 1$ \\ + \Then $\order{\accMarkedForSelfdestruct\new}_{i} = 1 $ + \end{enumerate} +\end{description} diff --git a/hub/consistencies/account/first_final.tex b/hub/consistencies/account/first_final.tex new file mode 100644 index 0000000..6871520 --- /dev/null +++ b/hub/consistencies/account/first_final.tex @@ -0,0 +1,64 @@ +We define the following shorthand +\[ + \locOrderedFullAddress_{i} + \define + 256^\llarge \cdot \order{\accAddress\high}_{i} + \order{\accAddress\low}_{i} +\] +We start by describing the $\accFirst$ and $\accFinal$ columns. +Contrary to what their name suggests these columns aren't a permutation of existing columns. +We provide a full specification of these columns here. +\begin{description} + \item[Generalities:] + we impose the following + \begin{enumerate} + \item $\accFirst$ and $\accFinal$ are binary + \item $\If \order{\peekAccount} _{i} = 0$ \Then $\accFirst_{i} + \accFinal_{i} = 0$ + \end{enumerate} + \item[First account row:] + \If + \[ + \left\{ \begin{array}{lclc} + \order{\peekAccount} _{i - 1} & = & 0 & \et \\ + \order{\peekAccount} _{i} & = & 1 \\ + \end{array} \right. + \] + \Then $\accFirst_{i} = 1$ + \item[Repeat account encounter:] + \If + \[ + \left\{ \begin{array}{lclc} + \order{\peekAccount} _{i - 1} & = & 1 & \et \\ + \order{\peekAccount} _{i} & = & 1 \\ + \end{array} \right. + \] + \Then we impose that + \begin{enumerate} + \item \If $\locOrderedFullAddress _{i} = \locOrderedFullAddress_{i - 1}$ \Then + $ \accFinal_{i - 1} + \accFirst_{i} = 0$ + % \begin{enumerate} + % \item $\accFinal_{i - 1} = 0$ + % \item $\accFirst_{i} = 0$ + % \end{enumerate} + % Equivalently we may impose + % $ \accFinal_{i - 1} + \accFirst_{i} = 0$ + \item \If $\locOrderedFullAddress _{i} \neq \locOrderedFullAddress_{i - 1}$ \Then + $ \accFinal_{i - 1} + \accFirst_{i} = 2$ + % \begin{enumerate} + % \item $\accFinal_{i - 1} = 1$ + % \item $\accFirst_{i} = 1$ + % \end{enumerate} + % Equivalently we may impose + % $ \accFinal_{i - 1} + \accFirst_{i} = 2$ + \end{enumerate} + \item[Final account row (1):] + \If + \[ + \left\{ \begin{array}{lclc} + \order{\peekAccount} _{i - 1} & = & 1 & \et \\ + \order{\peekAccount} _{i} & = & 0 \\ + \end{array} \right. + \] + \Then $\accFinal_{i - 1} = 1$ + \item[Final account row (2):] + \If $\order{\peekAccount} _{N} = 1$ \Then $\accFinal_{N} = 1$ +\end{description} diff --git a/hub/consistencies/account/permutation.tex b/hub/consistencies/account/permutation.tex new file mode 100644 index 0000000..46e7d53 --- /dev/null +++ b/hub/consistencies/account/permutation.tex @@ -0,0 +1,16 @@ +We consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that within the row-permuted columns +\[ + \left[\begin{array}{l} + \order{\peekAccount}, \\ + \quad\quad\quad \order{\accAddress\high}, \\ + \quad\quad\quad \quad\quad\quad \order{\accAddress\low}, \\ + % \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\accDeploymentNumber \cdot \peekAccount}, \\ + \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\domStamp}, \\ + \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad\order{\subStamp} \\ + \end{array}\right] +\] +(\emph{a}) padding-rows precede all non-padding-rows and +(\emph{b}) all \textbf{(reordered) account-rows}\footnote{by extension rows where $\order{\peekAccount} \equiv 1$} are contiguous +(\emph{c}) along the (reordered) account-rows the remaining columns are $(+, +, +, -)$-lexicographically ordered. +In particular the rows where $\peekAccount \equiv 0$ appear before the rows where $\peekAccount \equiv 1$. + diff --git a/hub/consistencies/context/_inputs.tex b/hub/consistencies/context/_inputs.tex new file mode 100644 index 0000000..4c4f605 --- /dev/null +++ b/hub/consistencies/context/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Properties of the permutation} \label{hub: consistencies: context: permutation} \input{consistencies/context/permutation} +\subsubsection{Permuted columns} \label{hub: consistencies: context: columns} \input{consistencies/context/columns} +\subsubsection{Constraints} \label{hub: consistencies: context: constraints} \input{consistencies/context/constraints} diff --git a/hub/consistencies/context/_opt.tex b/hub/consistencies/context/_opt.tex new file mode 100644 index 0000000..4ef1e52 --- /dev/null +++ b/hub/consistencies/context/_opt.tex @@ -0,0 +1,85 @@ +Consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that within the row-permuted columns +\[ + \Big( \order{\peekContext}, \order{\cnCn} , \order{\hubStamp} \Big) +\] +all \textbf{(reordered) context-rows}\footnote{by extension: rows where $\order{\peekContext} \equiv 1$} are contiguous +and along those the rows of the remaining columns are $(+, +)$-lexicographically ordered. We require that the following constraints hold: +\begin{description} + \item[Nontrivial contexts:] + \If $\order{\peekContext}_{i} = 1$ \Then $\order{\cnCn}_{i} \neq 0$ \quad (\trash) + \item[Setting $\conContextFirst$ and $\conContextAgain$:] + we impose the following + \begin{enumerate} + \item $\conContextFirst$ and $\conContextAgain$ are binary + \item $\conContextFirst_{i} + \conContextAgain_{i} = \order{\peekContext}_{i}$ + \item \If $\order{\peekContext}_{i} = 0$ \Then $\conContextFirst_{i + 1} = \order{\peekContext}_{i + 1}$ + \item \If $\order{\peekContext}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\conContextFirst_{i + 1} = 1$ \Then $\order{\cnCn}_{i + 1} \neq \order{\cnCn}_{i}$ + \item \If $\conContextAgain_{i + 1} = 1$ \Then $\order{\cnCn}_{i + 1} = \order{\cnCn}_{i}$ + \end{enumerate} + \end{enumerate} + \item[Immutability constraints:] + \If $\conContextAgain_{i + 1} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + % \order{\cnCn } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCn } _{i} \\ + \order{\cnCsd } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCsd } _{i} \\ + \order{\cnIsRootContext } _{i + 1} & \!\!\! = \!\!\! & \order{\cnIsRootContext } _{i} \\ + \order{\cnStatic } _{i + 1} & \!\!\! = \!\!\! & \order{\cnStatic } _{i} \\ + \order{\cnAccountAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\high } _{i} \\ + \order{\cnAccountAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\low } _{i} \\ + \order{\cnAccDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccDepNum } _{i} \\ + \order{\cnCodeAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\high } _{i} \\ + \order{\cnCodeAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\low } _{i} \\ + \order{\cnCodeDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepNum } _{i} \\ + \order{\cnCodeDepStatus } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepStatus } _{i} \\ + \order{\cnCodeCfi } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeCfi } _{i} \\ + \order{\cnCallerAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\high } _{i} \\ + \order{\cnCallerAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\low } _{i} \\ + \order{\cnCallValue } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallValue } _{i} \\ + \order{\cnCallDataContextNumber} _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallDataContextNumber} _{i} \\ + \order{\cnCdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCdo } _{i} \\ + \order{\cnCds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCds } _{i} \\ + \order{\cnRao } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRao } _{i} \\ + \order{\cnRac } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRac } _{i} \\ + % \order{\cnUpdate } _{i + 1} & \!\!\! = \!\!\! & \order{\cnUpdate } _{i} \\ + % \order{\cnReturner } _{i + 1} & \!\!\! = \!\!\! & \order{\cnReturner } _{i} \\ + % \order{\cnRdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRdo } _{i} \\ + % \order{\cnRds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRds } _{i} \\ + \end{array} \right. + \] + \item[Immutability constraints for return data:] + \If $\conContextAgain_{i + 1} = 1$ \et $\order{\cnUpdate}_{i + 1} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + % \order{\cnCn } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCn } _{i} \\ + % \order{\cnCsd } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCsd } _{i} \\ + % \order{\cnIsRootContext } _{i + 1} & \!\!\! = \!\!\! & \order{\cnIsRootContext } _{i} \\ + % \order{\cnStatic } _{i + 1} & \!\!\! = \!\!\! & \order{\cnStatic } _{i} \\ + % \order{\cnAccountAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\high } _{i} \\ + % \order{\cnAccountAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\low } _{i} \\ + % \order{\cnAccDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccDepNum } _{i} \\ + % \order{\cnCodeAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\high } _{i} \\ + % \order{\cnCodeAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\low } _{i} \\ + % \order{\cnCodeDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepNum } _{i} \\ + % \order{\cnCodeDepStatus } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepStatus } _{i} \\ + % \order{\cnCodeCfi } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeCfi } _{i} \\ + % \order{\cnCallerAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\high } _{i} \\ + % \order{\cnCallerAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\low } _{i} \\ + % \order{\cnCallValue } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallValue } _{i} \\ + % \order{\cnCallDataContextNumber} _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallDataContextNumber} _{i} \\ + % \order{\cnCdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCdo } _{i} \\ + % \order{\cnCds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCds } _{i} \\ + % \order{\cnRao } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRao } _{i} \\ + % \order{\cnRac } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRac } _{i} \\ + % \order{\cnUpdate } _{i + 1} & \!\!\! = \!\!\! & \order{\cnUpdate } _{i} \\ + \order{\cnReturner } _{i + 1} & \!\!\! = \!\!\! & \order{\cnReturner } _{i} \\ + \order{\cnRdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRdo } _{i} \\ + \order{\cnRds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRds } _{i} \\ + \end{array} \right. + \] +\end{description} +The above enforces that a given execution context always runs the same code (same address, same deployment number and same deployment status), that its caller context remains constant throughout, and that the data indicating whether or not it will revert (and if so whether it is self induced and/or inherited from a parent context reverting) and at what point in time a revert may trigger --- that all this be constants of the execution context. + +\saNote{} Since $\peekContext$ is binary we are thus requiring that all rows with $\peekContext \equiv 0$ be listed consecutively followed by all rows with $\peekContext \equiv 1$. diff --git a/hub/consistencies/context/columns.tex b/hub/consistencies/context/columns.tex new file mode 100644 index 0000000..a99b55a --- /dev/null +++ b/hub/consistencies/context/columns.tex @@ -0,0 +1,32 @@ +We list the columns that must be row-permuted according to the previously described row-permutation. +\begin{multicols}{3} + \begin{enumerate} + \item $\order{\peekContext}$ + \item $\order{\cnCn}$ + \item $\order{\hubStamp}$ + % + \item $\order{\cnCsd}$ + \item $\order{\cnIsRootContext}$ + \item $\order{\cnStatic}$ + \item $\order{\cnAccountAddress\high}$ + \item $\order{\cnAccountAddress\low}$ + \item $\order{\cnAccDepNum}$ + \item $\order{\cnCodeAddress\high}$ + \item $\order{\cnCodeAddress\low}$ + \item $\order{\cnCodeDepNum}$ + \item $\order{\cnCodeDepStatus}$ + \item $\order{\cnCodeCfi}$ + \item $\order{\cnCallerAddress\high}$ + \item $\order{\cnCallerAddress\low}$ + \item $\order{\cnCallValue}$ + \item $\order{\cnCallDataContextNumber}$ + \item $\order{\cnCdo}$ + \item $\order{\cnCds}$ + \item $\order{\cnRao}$ + \item $\order{\cnRac}$ + \item $\order{\cnUpdate}$ + \item $\order{\cnReturner}$ + \item $\order{\cnRdo}$ + \item $\order{\cnRds}$ + \end{enumerate} +\end{multicols} diff --git a/hub/consistencies/context/constraints.tex b/hub/consistencies/context/constraints.tex new file mode 100644 index 0000000..ba0adbd --- /dev/null +++ b/hub/consistencies/context/constraints.tex @@ -0,0 +1,80 @@ +We require that the following constraints hold: +\begin{description} + \item[Nontrivial contexts:] + \If $\order{\peekContext}_{i} = 1$ \Then $\order{\cnCn}_{i} \neq 0$ \quad (\trash) + \item[Setting $\conContextFirst$ and $\conContextAgain$:] + we impose the following + \begin{enumerate} + \item $\conContextFirst$ and $\conContextAgain$ are binary + \item $\conContextFirst_{i} + \conContextAgain_{i} = \order{\peekContext}_{i}$ + \item \If $\order{\peekContext}_{i} = 0$ \Then $\conContextFirst_{i + 1} = \order{\peekContext}_{i + 1}$ + \item \If $\order{\peekContext}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\conContextFirst_{i + 1} = 1$ \Then $\order{\cnCn}_{i + 1} \neq \order{\cnCn}_{i}$ + \item \If $\conContextAgain_{i + 1} = 1$ \Then $\order{\cnCn}_{i + 1} = \order{\cnCn}_{i}$ + \end{enumerate} + \end{enumerate} + \item[Immutability constraints:] + \If $\conContextAgain_{i + 1} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + % \order{\cnCn } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCn } _{i} \\ + \order{\cnCsd } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCsd } _{i} \\ + \order{\cnIsRootContext } _{i + 1} & \!\!\! = \!\!\! & \order{\cnIsRootContext } _{i} \\ + \order{\cnStatic } _{i + 1} & \!\!\! = \!\!\! & \order{\cnStatic } _{i} \\ + \order{\cnAccountAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\high } _{i} \\ + \order{\cnAccountAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\low } _{i} \\ + \order{\cnAccDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccDepNum } _{i} \\ + \order{\cnCodeAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\high } _{i} \\ + \order{\cnCodeAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\low } _{i} \\ + \order{\cnCodeDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepNum } _{i} \\ + \order{\cnCodeDepStatus } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepStatus } _{i} \\ + \order{\cnCodeCfi } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeCfi } _{i} \\ + \order{\cnCallerAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\high } _{i} \\ + \order{\cnCallerAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\low } _{i} \\ + \order{\cnCallValue } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallValue } _{i} \\ + \order{\cnCallDataContextNumber} _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallDataContextNumber} _{i} \\ + \order{\cnCdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCdo } _{i} \\ + \order{\cnCds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCds } _{i} \\ + \order{\cnRao } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRao } _{i} \\ + \order{\cnRac } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRac } _{i} \\ + % \order{\cnUpdate } _{i + 1} & \!\!\! = \!\!\! & \order{\cnUpdate } _{i} \\ + % \order{\cnReturner } _{i + 1} & \!\!\! = \!\!\! & \order{\cnReturner } _{i} \\ + % \order{\cnRdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRdo } _{i} \\ + % \order{\cnRds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRds } _{i} \\ + \end{array} \right. + \] + \item[Immutability constraints for return data:] + \If $\conContextAgain_{i + 1} = 1$ \et $\order{\cnUpdate}_{i + 1} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + % \order{\cnCn } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCn } _{i} \\ + % \order{\cnCsd } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCsd } _{i} \\ + % \order{\cnIsRootContext } _{i + 1} & \!\!\! = \!\!\! & \order{\cnIsRootContext } _{i} \\ + % \order{\cnStatic } _{i + 1} & \!\!\! = \!\!\! & \order{\cnStatic } _{i} \\ + % \order{\cnAccountAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\high } _{i} \\ + % \order{\cnAccountAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccountAddress\low } _{i} \\ + % \order{\cnAccDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnAccDepNum } _{i} \\ + % \order{\cnCodeAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\high } _{i} \\ + % \order{\cnCodeAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeAddress\low } _{i} \\ + % \order{\cnCodeDepNum } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepNum } _{i} \\ + % \order{\cnCodeDepStatus } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeDepStatus } _{i} \\ + % \order{\cnCodeCfi } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCodeCfi } _{i} \\ + % \order{\cnCallerAddress\high } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\high } _{i} \\ + % \order{\cnCallerAddress\low } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallerAddress\low } _{i} \\ + % \order{\cnCallValue } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallValue } _{i} \\ + % \order{\cnCallDataContextNumber} _{i + 1} & \!\!\! = \!\!\! & \order{\cnCallDataContextNumber} _{i} \\ + % \order{\cnCdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCdo } _{i} \\ + % \order{\cnCds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnCds } _{i} \\ + % \order{\cnRao } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRao } _{i} \\ + % \order{\cnRac } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRac } _{i} \\ + % \order{\cnUpdate } _{i + 1} & \!\!\! = \!\!\! & \order{\cnUpdate } _{i} \\ + \order{\cnReturner } _{i + 1} & \!\!\! = \!\!\! & \order{\cnReturner } _{i} \\ + \order{\cnRdo } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRdo } _{i} \\ + \order{\cnRds } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRds } _{i} \\ + \end{array} \right. + \] +\end{description} +The above enforces that a given execution context always runs the same code (same address, same deployment number and same deployment status), that its caller context remains constant throughout, and that the data indicating whether or not it will revert (and if so whether it is self induced and/or inherited from a parent context reverting) and at what point in time a revert may trigger --- that all this be constants of the execution context. + +\saNote{} Since $\peekContext$ is binary we are thus requiring that all rows with $\peekContext \equiv 0$ be listed consecutively followed by all rows with $\peekContext \equiv 1$. diff --git a/hub/consistencies/context/permutation.tex b/hub/consistencies/context/permutation.tex new file mode 100644 index 0000000..8e959d9 --- /dev/null +++ b/hub/consistencies/context/permutation.tex @@ -0,0 +1,11 @@ +We consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that within the row-permuted columns +\[ + \Big( + \order{\peekContext}, + \order{\cnCn}, + \order{\hubStamp} + \Big) +\] +(\emph{a}) padding-rows precede all non-padding rows +(\emph{b}) all \textbf{(reordered) context rows}\footnote{by extension rows where $\order{\peekContext} \equiv 1$} are contiguous +(\emph{c}) along the (reordered) context rows the remaining columns are $(+, +)$-lexicographically ordered. diff --git a/hub/consistencies/environment.tex b/hub/consistencies/environment.tex new file mode 100644 index 0000000..98decbf --- /dev/null +++ b/hub/consistencies/environment.tex @@ -0,0 +1,37 @@ +Consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that the row-permuted pair of columns +\[ + \Big( \order{\cn} , \order{\hubStamp} \Big) +\] +has its entries $(+,+)$-lexicographically ordered. We require that the following constraints hold: +\begin{description} + \item[Constancy constraints:] + \If $\order{\cn}_{i} \neq 0$ \et $\order{\cn}_{i + 1} = \order{\cn}_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\cfi } _{i + 1} & \!\!\! = \!\!\! & \order{\cfi } _{i} \\ + \order{\caller } _{i + 1} & \!\!\! = \!\!\! & \order{\caller } _{i} \\ + \order{\cnWillRev } _{i + 1} & \!\!\! = \!\!\! & \order{\cnWillRev } _{i} \\ + \order{\cnGetsRev } _{i + 1} & \!\!\! = \!\!\! & \order{\cnGetsRev } _{i} \\ + \order{\cnSelfRev } _{i + 1} & \!\!\! = \!\!\! & \order{\cnSelfRev } _{i} \\ + \order{\cnRevStamp } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRevStamp } _{i} \\ + \end{array} \right. + \] + \item[Linking constraints:] + \If $\order{\cn}_{i} \neq 0$ \et $\order{\cn}_{i + 1} = \order{\cn}_{i}$ \et $\order{\hubStamp}_{i + 1} \neq \order{\hubStamp}_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\pc } _{i + 1} & \!\!\! = \!\!\! & \order{\pc\new } _{i} \\ + \order{\height } _{i + 1} & \!\!\! = \!\!\! & \order{\height\new } _{i} \\ + \order{\gasExpected } _{i + 1} & \!\!\! = \!\!\! & \order{\gasNext } _{i} \\ + \end{array} \right. + \] + \item[Initialization constraints:] + \If $\order{\cn}_{i + 1} \neq \order{\cn}_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\pc } _{i + 1} & \!\!\! = \!\!\! & 0 \\ + \order{\height } _{i + 1} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right. + \] +\end{description} +The above enforces that a given execution context always runs the same code (same address, same deployment number and same deployment status), that its caller context remains constant throughout, and that the data indicating whether or not it will revert (and if so whether it is self induced and/or inherited from a parent context reverting) and at what point in time a revert may trigger --- that all this be constants of the execution context. diff --git a/hub/consistencies/environment/_inputs.tex b/hub/consistencies/environment/_inputs.tex new file mode 100644 index 0000000..b43a17b --- /dev/null +++ b/hub/consistencies/environment/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Properties of the permutation} \label{hub: consistencies: execution environment: permutation} \input{consistencies/environment/permutation} +\subsubsection{Permuted columns} \label{hub: consistencies: execution environment: columns} \input{consistencies/environment/columns} +\subsubsection{Constraints} \label{hub: consistencies: execution environment: constraints} \input{consistencies/environment/constraints} diff --git a/hub/consistencies/environment/columns.tex b/hub/consistencies/environment/columns.tex new file mode 100644 index 0000000..32e2b30 --- /dev/null +++ b/hub/consistencies/environment/columns.tex @@ -0,0 +1,21 @@ +We list the columns that must be row-permuted according to the previously described row-permutation. +\begin{multicols}{4} + \begin{enumerate} + \item $\order{\cn}$ + \item $\order{\hubStamp}$ + \item $\order{\cfi}$ + \item $\order{\caller}$ + \item $\order{\cnWillRev}$ + \item $\order{\cnGetsRev}$ + \item $\order{\cnSelfRev}$ + \item $\order{\cnRevStamp}$ + \item $\order{\pc}$ + \item $\order{\pc\new}$ + \item $\order{\height}$ + \item $\order{\height\new}$ + \item $\order{\gasExpected}$ + \item $\order{\gasNext}$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/hub/consistencies/environment/constraints.tex b/hub/consistencies/environment/constraints.tex new file mode 100644 index 0000000..fb39478 --- /dev/null +++ b/hub/consistencies/environment/constraints.tex @@ -0,0 +1,33 @@ +We require that the following constraints hold: +\begin{description} + \item[Constancy constraints:] + \If $\order{\cn}_{i} \neq 0$ \et $\order{\cn}_{i + 1} = \order{\cn}_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\cfi } _{i + 1} & \!\!\! = \!\!\! & \order{\cfi } _{i} \\ + \order{\caller } _{i + 1} & \!\!\! = \!\!\! & \order{\caller } _{i} \\ + \order{\cnWillRev } _{i + 1} & \!\!\! = \!\!\! & \order{\cnWillRev } _{i} \\ + \order{\cnGetsRev } _{i + 1} & \!\!\! = \!\!\! & \order{\cnGetsRev } _{i} \\ + \order{\cnSelfRev } _{i + 1} & \!\!\! = \!\!\! & \order{\cnSelfRev } _{i} \\ + \order{\cnRevStamp } _{i + 1} & \!\!\! = \!\!\! & \order{\cnRevStamp } _{i} \\ + \end{array} \right. + \] + \item[Linking constraints:] + \If $\order{\cn}_{i} \neq 0$ \et $\order{\cn}_{i + 1} = \order{\cn}_{i}$ \et $\order{\hubStamp}_{i + 1} \neq \order{\hubStamp}_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\pc } _{i + 1} & \!\!\! = \!\!\! & \order{\pc\new } _{i} \\ + \order{\height } _{i + 1} & \!\!\! = \!\!\! & \order{\height\new } _{i} \\ + \order{\gasExpected } _{i + 1} & \!\!\! = \!\!\! & \order{\gasNext } _{i} \\ + \end{array} \right. + \] + \item[Initialization constraints:] + \If $\order{\cn}_{i + 1} \neq \order{\cn}_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\pc } _{i + 1} & \!\!\! = \!\!\! & 0 \\ + \order{\height } _{i + 1} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right. + \] +\end{description} +The above enforces that a given execution context always runs the same code (same address, same deployment number and same deployment status), that its caller context remains constant throughout, and that the data indicating whether or not it will revert (and if so whether it is self induced and/or inherited from a parent context reverting) and at what point in time a revert may trigger --- that all this be constants of the execution context. diff --git a/hub/consistencies/environment/permutation.tex b/hub/consistencies/environment/permutation.tex new file mode 100644 index 0000000..096e9f6 --- /dev/null +++ b/hub/consistencies/environment/permutation.tex @@ -0,0 +1,5 @@ +We consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that the row-permuted pair of columns +\[ + \Big( \order{\cn} , \order{\hubStamp} \Big) +\] +has its entries $(+,+)$-lexicographically ordered. Such a row permutation allows us to list context data displayed among \textbf{shared} in such a way that all data relatitve to a given (nonzero) context number is contiguous and listed chronologically. diff --git a/hub/consistencies/intro.tex b/hub/consistencies/intro.tex new file mode 100644 index 0000000..1258ad6 --- /dev/null +++ b/hub/consistencies/intro.tex @@ -0,0 +1,2 @@ +The present section centralizes all consistency arguments used in the \hubMod{}. +Since the \hubMod{} module is responsible for various book-keeping tasks there are several such consistency arguments. diff --git a/hub/consistencies/stack/_inputs.tex b/hub/consistencies/stack/_inputs.tex new file mode 100644 index 0000000..68cf817 --- /dev/null +++ b/hub/consistencies/stack/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsection{Interleaved columns} \label{hub: consistencies: stack: interleavings} \input{consistencies/stack/interleaved} +\subsubsection{Properties of the permutation} \label{hub: consistencies: stack: permutation} \input{consistencies/stack/permutation} +\subsubsection{Permuted columns} \label{hub: consistencies: stack: columns} \input{consistencies/stack/columns} +\subsubsection{Constraints} \label{hub: consistencies: stack: constraints} \input{consistencies/stack/constraints} + diff --git a/hub/consistencies/stack/columns.tex b/hub/consistencies/stack/columns.tex new file mode 100644 index 0000000..5e4c891 --- /dev/null +++ b/hub/consistencies/stack/columns.tex @@ -0,0 +1,14 @@ +We list the columns that must be row-permuted according to the previously described row-permutation. +\begin{multicols}{3} + \begin{enumerate} + \item $\order{\peekStackFour}$ + \item $\order{\cn^{\cc4}}$ + \item $\order{\stackItemHeight{\col{1234}}}$ + \item $\order{\stackItemStamp{\col{1234}}}$ + % + \item $\order{\stackItemPop{\col{1234}}}$ + \item $\order{\stackItemValHi{\col{1234}}}$ + \item $\order{\stackItemValLo{\col{1234}}}$ + \end{enumerate} +\end{multicols} + diff --git a/hub/consistencies/stack/constraints.tex b/hub/consistencies/stack/constraints.tex new file mode 100644 index 0000000..65cb52f --- /dev/null +++ b/hub/consistencies/stack/constraints.tex @@ -0,0 +1,59 @@ +We then impose the following constraints: +\begin{description} + \item[Nontrivial contexts:] \If $\order{\peekStackFour}_{i} = 1$ \Then $\order{\cn^{\cc4}}_{i} \neq 0$ \quad (\trash) + \item[Setting $\stackContextFirst$ and $\stackContextAgain$:] + we impose + \begin{enumerate} + \item $\stackContextFirst$ and $\stackContextAgain$ are binary + \item $\stackContextFirst_{i} + \stackContextAgain_{i} = \order{\peekStackFour}_{i}$ + \item \If $\order{\peekStackFour}_{i} = 0$ \Then $\stackContextFirst_{i + 1} = \order{\peekStackFour}_{i + 1}$ + \item \If $\order{\peekStackFour}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\stackContextFirst_{i + 1} = 1$ \Then $\cn^{\cc4}_{i + 1} \neq \cn^{\cc4}_{i}$ + \item \If $\stackContextAgain_{i + 1} = 1$ \Then $\cn^{\cc4}_{i + 1} = \cn^{\cc4}_{i}$ + \end{enumerate} + \end{enumerate} + \item[Setting $\stackHeightFirst$ and $\stackHeightAgain$:] + we impose + \begin{enumerate} + \item $\stackHeightFirst$ and $\stackHeightAgain$ are binary + \item $\stackHeightFirst_{i} + \stackHeightAgain_{i} = \order{\peekStackFour}_{i}$ + \item \If $\order{\peekStackFour}_{i} = 0$ \Then $\stackHeightFirst_{i + 1} = \order{\peekStackFour}_{i + 1}$ + \item \If $\order{\peekStackFour}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\stackHeightFirst_{i + 1} = 1$ \Then $\order{\stackItemHeight{\col{1234}}}_{i + 1} \neq \order{\stackItemHeight{\col{1234}}}_{i}$ + \item \If $\stackHeightAgain_{i + 1} = 1$ \Then $\order{\stackItemHeight{\col{1234}}}_{i + 1} = \order{\stackItemHeight{\col{1234}}}_{i}$ + \end{enumerate} + \end{enumerate} + \item[Setting $\stackSpotFirst$ and $\stackSpotAgain$:] + we impose + \begin{enumerate} + \item $\stackSpotFirst$ and $\stackSpotAgain$ are binary + \item $\stackSpotFirst_{i} + \stackSpotAgain_{i} = \order{\peekStackFour}_{i}$ + \item $\stackSpotAgain_{i} = \stackContextAgain_{i} \cdot \stackHeightAgain_{i}$ + \end{enumerate} + \item[First and repeat context encounter:] + we impose + \begin{enumerate} + \item \If $\stackContextFirst_{i} = 1$ \Then $\order{\stackItemHeight{\col{1234}}}_{i} = 0$ + \item \If $\stackContextAgain_{i} = 1$ \Then $\order{\stackItemHeight{\col{1234}}}_{i} + \in \left \{ \order{\stackItemHeight{\col{1234}}}_{i - 1}, 1 + \order{\stackItemHeight{\col{1234}}}_{i - 1} \right \}$ + \end{enumerate} + \item[First and repeat spot encounter:] + we impose + \begin{enumerate} + \item \If $\stackSpotFirst_{i} = 1$ \Then $\order{\stackItemPop{\col{1234}}}_{i} = 0$ + \item \If $\stackSpotAgain_{i} = 1$ \et $\order{\stackItemHeight{\col{1234}}}_{i} \neq 0$ \Then + \begin{enumerate} + \item $\order{\stackItemPop{\col{1234}}}_{i} + \order{\stackItemPop{\col{1234}}}_{i - 1} = 1$, + \item \If $\order{\stackItemPop{\col{1234}}}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{l} + \order{\stackItemValHi{\col{1234}}}_{i} = \order{\stackItemValHi{\col{1234}}}_{i - 1} \\ + \order{\stackItemValLo{\col{1234}}}_{i} = \order{\stackItemValLo{\col{1234}}}_{i - 1} \\ + \end{array} \right. + \] + \end{enumerate} + \end{enumerate} +\end{description} +In other words, the binary flag column $\order{\stackItemPop{\col{1234}}}$ at a given height oscillates (we push, pop, push, pop, push, etc\dots{}); when popping an item (i.e. when $\order{\stackItemPop{\col{1234}}}_{i+1} = 1$), we retrieve the value previously pushed at that height; diff --git a/hub/consistencies/stack/interleaved.tex b/hub/consistencies/stack/interleaved.tex new file mode 100644 index 0000000..cee7420 --- /dev/null +++ b/hub/consistencies/stack/interleaved.tex @@ -0,0 +1,15 @@ +This section describes the consistency constraints that ensure that any stack item excavated from the stack of a given execution context at a given height coincides with the last stack item pushed onto the same execution context's stack at the same height. +We now introduce some interleaved columns: +\[ + \left\{ \begin{array}{lcl} + \peekStackFour & \define & \peekStack \cc \peekStack \cc \peekStack \cc \peekStack \\ + \cn ^{\cc4} & \define & \cn \cc \cn \cc \cn \cc \cn \\ + \stackItemHeight {\col{1234}} & \define & \stackItemHeight {1} \cc \stackItemHeight {2} \cc \stackItemHeight {3} \cc \stackItemHeight {4} \\ + \stackItemStamp {\col{1234}} & \define & \stackItemStamp {1} \cc \stackItemStamp {2} \cc \stackItemStamp {3} \cc \stackItemStamp {4} \\ + \stackItemPop {\col{1234}} & \define & \stackItemPop {1} \cc \stackItemPop {2} \cc \stackItemPop {3} \cc \stackItemPop {4} \\ + \stackItemValHi {\col{1234}} & \define & \stackItemValHi {1} \cc \stackItemValHi {2} \cc \stackItemValHi {3} \cc \stackItemValHi {4} \\ + \stackItemValLo {\col{1234}} & \define & \stackItemValLo {1} \cc \stackItemValLo {2} \cc \stackItemValLo {3} \cc \stackItemValLo {4} \\ + \end{array} \right. +\] +Since on every row the stack is available through four different stack items a consistency proof for the stack must take all four of these views into the stack into account. +This is achieved by interleaving columns as indicated above. diff --git a/hub/consistencies/stack/permutation.tex b/hub/consistencies/stack/permutation.tex new file mode 100644 index 0000000..76a96c3 --- /dev/null +++ b/hub/consistencies/stack/permutation.tex @@ -0,0 +1,13 @@ +We consider a row permutation $\col{X}\mapsto\order{\col{X}}$ +\[ + \Big( + \order{\peekStackFour}, + \order{\cn^{\cc4}}, + \order{\stackItemHeight{\col{1234}}}, + \order{\stackItemStamp{\col{1234}}} + \Big) +\] +\noindent such that +(\emph{a}) padding-rows precede all non-padding-rows and +(\emph{b}) all \textbf{(reordered interleaved) stack-rows}\footnote{by extension rows where $\order{\peekStackFour} \equiv 1$} are contiguous +(\emph{c}) along the (reordered interleaved) stack-rows the remaining columns are $(+, +, +)$-lexicographically ordered. diff --git a/hub/consistencies/storage/_inputs.tex b/hub/consistencies/storage/_inputs.tex new file mode 100644 index 0000000..64ea028 --- /dev/null +++ b/hub/consistencies/storage/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsection{Properties of the permutation} \label{hub: consistencies: storage: permutation} \input{consistencies/storage/permutation} +\subsubsection{Permuted columns} \label{hub: consistencies: storage: columns} \input{consistencies/storage/columns} +\subsubsection{Constraints for $\stoFirst$ and $\stoFinal$} \label{hub: consistencies: storage: permutation} \input{consistencies/storage/first_final} +\subsubsection{Constraints} \label{hub: consistencies: storage: constraints} \input{consistencies/storage/constraints} diff --git a/hub/consistencies/storage/columns.tex b/hub/consistencies/storage/columns.tex new file mode 100644 index 0000000..89ebf9c --- /dev/null +++ b/hub/consistencies/storage/columns.tex @@ -0,0 +1,30 @@ +We list the columns that must be row-permuted according to the previously described row-permutation. +\begin{multicols}{3} + \begin{enumerate} + \item $\order{\peekStorage}$ + \item $\order{\stoAddressHi}$ + \item $\order{\stoAddressLo}$ + \item $\order{\stoKeyHi}$ + \item $\order{\stoKeyLo}$ + \item $\order{\domStamp}$ + \item $\order{\subStamp}$ + \item $\order{\absTxNum}$ + \item $\order{\stoOrigValueHi}$ + \item $\order{\stoOrigValueLo}$ + \item $\order{\stoCurrValueHi}$ + \item $\order{\stoCurrValueHi}$ + \item $\order{\stoNextValueLo}$ + \item $\order{\stoNextValueLo}$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item $\order{\stoWarmth}$ + \item $\order{\stoWarmth\new}$ + \item $\order{\stoDeploymentNumber}$ + \item $\order{\stoDeploymentNumber^\infty}$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/hub/consistencies/storage/constraints.tex b/hub/consistencies/storage/constraints.tex new file mode 100644 index 0000000..cb88fe4 --- /dev/null +++ b/hub/consistencies/storage/constraints.tex @@ -0,0 +1,74 @@ +We now go on to consistency constraints proper. +\begin{description} + \item[Setting the original storage value:] + \If $\stoFirst_{i} = 1$ \Then + we impose that + \[ + \left\{ \begin{array}{lcl} + \order{\stoOrigValueHi}_{i} & = & \order{\stoCurrValueHi}_{i} \\ + \order{\stoOrigValueLo}_{i} & = & \order{\stoCurrValueLo}_{i} \\ + \end{array} \right. + \] + \item[Resetting and resetting the original storage value:] + \If $\order{\peekStorage}_{i} = 1$ \et $\stoFirst_{i} = 0$ \Then + \begin{enumerate} + \item \If $\order{\absTxNum}_{i} = \order{\absTxNum}_{i - 1}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\stoOrigValueHi}_{i} & = & \order{\stoOrigValueHi}_{i - 1} \\ + \order{\stoOrigValueLo}_{i} & = & \order{\stoOrigValueLo}_{i - 1} \\ + \end{array} \right. + \] + \item \If $\order{\absTxNum}_{i} \neq \order{\absTxNum}_{i - 1}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\stoOrigValueHi}_{i} & = & \order{\stoCurrValueHi}_{i} \\ + \order{\stoOrigValueLo}_{i} & = & \order{\stoCurrValueLo}_{i} \\ + \end{array} \right. + \] + \end{enumerate} + \item[Setting and resetting of storage values:] + we impose that + \begin{enumerate} + \item \If $\stoFirst_{i} = 1$ \Then + \begin{enumerate} + \item \If $\order{\stoDeploymentNumber}_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\stoCurrValueHi}_{i} & = & 0 \\ + \order{\stoCurrValueLo}_{i} & = & 0 \\ + \end{array} \right. + \] + \end{enumerate} + \item \If $\order{\peekStorage}_{i} = 1$ \et $\stoFirst_{i} = 0$ \Then + \begin{enumerate} + \item \If $\order{\stoDeploymentNumber}_{i} \neq \order{\stoDeploymentNumber}_{i - 1}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\stoCurrValueHi}_{i} & = & 0 \\ + \order{\stoCurrValueLo}_{i} & = & 0 \\ + \end{array} \right. + \] + \item \If $\order{\stoDeploymentNumber}_{i} = \order{\stoDeploymentNumber}_{i - 1}$ \Then + \[ + \left\{ \begin{array}{lcl} + \order{\stoCurrValueHi}_{i} & = & \order{\stoNextValueHi}_{i - 1} \\ + \order{\stoCurrValueLo}_{i} & = & \order{\stoNextValueLo}_{i - 1} \\ + \end{array} \right. + \] + \end{enumerate} + \end{enumerate} + \item[Setting and resetting of storage key warmth:] + we impose that + \begin{enumerate} + \item \If $\stoFirst_{i} = 1$ \Then $\order{\stoWarmth}_{i} = 0$ + \item \If $\order{\peekStorage}_{i} = 1$ \et $\stoFirst_{i} = 0$ \Then + \begin{enumerate} + \item \If $\order{\absTxNum}_{i} = \order{\absTxNum}_{i - 1}$ \Then $ \order{\stoWarmth}_{i} = \order{\stoWarmth\new}_{i - 1} $ + \item \If $\order{\absTxNum}_{i} \neq \order{\absTxNum}_{i - 1}$ \Then $ \order{\stoWarmth}_{i} = 0 $ + \end{enumerate} + \end{enumerate} + \item[Maintaining the final deployment number:] + we impose that + \item \If $\order{\peekStorage}_{i} = 1$ \et $\stoFirst_{i} = 0$ \Then $ \order{\stoDeploymentNumber^\infty}_{i} = \order{\stoDeploymentNumber^\infty}_{i - 1} $ +\end{description} diff --git a/hub/consistencies/storage/first_final.tex b/hub/consistencies/storage/first_final.tex new file mode 100644 index 0000000..99cd040 --- /dev/null +++ b/hub/consistencies/storage/first_final.tex @@ -0,0 +1,57 @@ +We define the following shorthand +\[ + \locOrderedFullAddress_{i} + \define + 256^\llarge \cdot \order{\stoAddressHi}_{i} + \order{\stoAddressLo}_{i} +\] +\begin{description} + \item[Generalities:] + we impose the following + \begin{enumerate} + \item $\stoFirst$ and $\stoFinal$ are binary + \item \If $\order{\peekStorage} _{i} = 0$ \Then $\stoFirst_{i} + \stoFinal_{i} = 0$ + \item \If $\order{\peekStorage} _{i - 1} = 0$ \et $\order{\peekStorage} _{i} = 1$ \Then $\stoFirst_{i} = 1$ + \item \If $\order{\peekStorage} _{i - 1} = 1$ \et $\order{\peekStorage} _{i} = 1$ \Then + \begin{enumerate} + \item \If $\locOrderedFullAddress _{i - 1} \neq \locOrderedFullAddress _{i} $ \Then + \[ + \left\{ \begin{array}{lcl} + \stoFinal_{i - 1} & = & 1 \\ + \stoFirst_{i } & = & 1 \\ + \end{array} \right. + \] + \item \If $\order{\stoKeyHi} _{i - 1} \neq \order{\stoKeyHi }_{i} $ \Then + \[ + \left\{ \begin{array}{lcl} + \stoFinal_{i - 1} & = & 1 \\ + \stoFirst_{i } & = & 1 \\ + \end{array} \right. + \] + \item \If $\order{\stoKeyLo} _{i - 1} \neq \order{\stoKeyLo }_{i} $ \Then + \[ + \left\{ \begin{array}{lcl} + \stoFinal_{i - 1} & = & 1 \\ + \stoFirst_{i } & = & 1 \\ + \end{array} \right. + \] + \item \If + \[ + \left\{ \begin{array}{llcl} + \locOrderedFullAddress _{i - 1} & \!\!\! = \!\!\! & \locOrderedFullAddress _{i} & \et \\ + \order{\stoKeyHi }_{i - 1} & \!\!\! = \!\!\! & \order{\stoKeyHi }_{i} & \et \\ + \order{\stoKeyLo }_{i - 1} & \!\!\! = \!\!\! & \order{\stoKeyLo }_{i} & \\ + \end{array} \right. + \] + \Then + \[ + \left\{ \begin{array}{lcl} + \stoFinal_{i - 1} & = & 0 \\ + \stoFirst_{i } & = & 0 \\ + \end{array} \right. + \] + \end{enumerate} + \item \If $\order{\peekStorage} _{i - 1} = 1$ \et $\order{\peekStorage} _{i} = 0$ \Then $\stoFinal_{i - 1} = 1$ + \item \If $\order{\peekStorage} _{N} = 1$ \Then $\stoFinal_{N} = 1$ + \end{enumerate} +\end{description} + diff --git a/hub/consistencies/storage/permutation.tex b/hub/consistencies/storage/permutation.tex new file mode 100644 index 0000000..996283b --- /dev/null +++ b/hub/consistencies/storage/permutation.tex @@ -0,0 +1,19 @@ +We consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ with the property that within the row-permuted columns +\[ + \left[ \begin{array}{l} + \order{\peekStorage}, \\ + \quad\quad\quad \order{\stoAddressHi}, \\ + \quad\quad\quad \quad\quad\quad \order{\stoAddressLo}, \\ + \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\stoKeyHi}, \\ + \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\stoKeyLo}, \\ + % \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\stoDeploymentNumber}, \\ % TODO: I believe this is useless in the lex. argument + % \quad\quad\quad + \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\domStamp}, \\ + % \quad\quad\quad + \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \quad\quad\quad \order{\subStamp}, \\ + \end{array} \right] +\] +\noindent +(\emph{a}) padding-rows precede all non-padding-rows and +(\emph{b}) all \textbf{(reordered) storage-rows}\footnote{by extension rows where $\order{\peekStorage} \equiv 1$} are contiguous +(\emph{c}) along the (reordered) storage-rows the remaining columns are $(+, +, +, +, +, +, -)$-lexicographically ordered. diff --git a/hub/context/_inputs.tex b/hub/context/_inputs.tex new file mode 100644 index 0000000..58fe2f9 --- /dev/null +++ b/hub/context/_inputs.tex @@ -0,0 +1,4 @@ +\section{Context-rows} +\subsection{Setting the next context number \lispDone{}} \label{hub: context-rows: context constraints} \input{context/next_context} +\subsection{Initializing an execution context \lispDone{}} \label{hub: context-rows: initialize context} \input{context/initialize} +\subsection{Specialized constraints \lispDone{}} \label{hub: context-rows: specialized constraints} \input{context/specialized_constraints} diff --git a/hub/context/initialize.tex b/hub/context/initialize.tex new file mode 100644 index 0000000..a694fda --- /dev/null +++ b/hub/context/initialize.tex @@ -0,0 +1,95 @@ +The present section presents a \textbf{parametrized collection of constraints} that serve to initialize an execution context. Such an initialization is required whenever a new execution context is spawned by either +\begin{enumerate} + \item transaction intialization; + \item entering a \inst{CALL}-type instruction; + \item entering a \inst{CREATE}-type instruction; +\end{enumerate} +Caveats apply to all of these scenarios. +% a \inst{CALL}-type instruction which +% (\emph{a}) produces no exception, +% (\emph{b}) isn't aborted and +% (\emph{c}) targets an account with nonempty byte code (in particular not a precompiled contract.) + +The constraint systems we present are parametrized by a \textbf{fixed positive integer} $\bm{\relof}$. We shall subsume under the following moniker +\[ + \initializeContext{ + anchorRow = i , + relOffset = \relof , + contextNumber = \col{context\_number} , + callStackDepth = \col{call\_stack\_depth} , + isRoot = \col{is\_root} , + isStatic = \col{is\_static} , + accountAddressHigh = \col{account\_address\_hi} , + accountAddressLow = \col{account\_address\_lo} , + accountDeploymentNumber = \col{account\_deployment\_number} , + byteCodeAddressHi = \col{byte\_code\_address\_hi} , + byteCodeAddressLo = \col{byte\_code\_address\_lo} , + byteCodeDeploymentNumber = \col{byte\_code\_deployment\_number} , + byteCodeDeploymentStatus = \col{byte\_code\_deployment\_status} , + byteCodeCodeFragmentIndex = \col{code\_fragment\_index} , + callerAddressHi = \col{caller\_address\_hi} , + callerAddressLo = \col{caller\_address\_lo} , + callValue = \col{call\_value} , + callDataContextNumber = \col{call\_data\_context\_number} , + callDataOffset = \col{call\_data\_offset} , + callDataSize = \col{call\_data\_size} , + returnAtOffset = \col{return\_at\_offset} , + returnAtCapacity = \col{return\_at\_capacity} , + } + % \initializeContext{\relof}_{i} + % \left[ \begin{array}{llr} + % \utt{context number:} & \col{context\_number} \\ + % \utt{call stack depth:} & \col{call\_stack\_depth} \\ + % \utt{is root:} & \col{is\_root} \\ + % \utt{is static:} & \col{is\_static} \\ + % \utt{account address high:} & \col{account\_address\_hi} \\ + % \utt{account address low:} & \col{account\_address\_lo} \\ + % \utt{account deployment number:} & \col{account\_deployment\_number} \\ + % \utt{byte code address high:} & \col{byte\_code\_address\_hi} \\ + % \utt{byte code address low:} & \col{byte\_code\_address\_lo} \\ + % \utt{byte code deployment number:} & \col{byte\_code\_deployment\_number} \\ + % \utt{byte code deployment status:} & \col{byte\_code\_deployment\_status} \\ + % \utt{byte code code fragment index:} & \col{code\_fragment\_index} & (\trash) \\ + % \utt{caller address high:} & \col{caller\_address\_hi} \\ + % \utt{caller address low:} & \col{caller\_address\_lo} \\ + % \utt{call value:} & \col{call\_value} \\ + % \utt{call data context number:} & \col{call\_data\_context\_number} & (\trash) \\ + % \utt{call data offset:} & \col{call\_data\_offset} \\ + % \utt{call data size:} & \col{call\_data\_size} \\ + % \utt{return at offset:} & \col{return\_at\_offset} \\ + % \utt{return at capacity:} & \col{return\_at\_size} \\ + % % \utt{returner context:} & \col{returnerCn} \\ + % % \utt{return data offset:} & \col{returnDataOffset} \\ + % % \utt{return data size:} & \col{returnDataSize} \\ + % \end{array} \right] +\] +the following collection of constraints: +\[ + \left\{ \begin{array}{lclr} + \cnCn _{i + \relof} & \!\!\! = \!\!\! & \col{context\_number} \\ + \cnCsd _{i + \relof} & \!\!\! = \!\!\! & \col{call\_stack\_depth} \\ + \cnIsRootContext _{i + \relof} & \!\!\! = \!\!\! & \col{is\_root} \\ + \cnStatic _{i + \relof} & \!\!\! = \!\!\! & \col{is\_static} \\ + \cnAccountAddress\high _{i + \relof} & \!\!\! = \!\!\! & \col{account\_address\_hi} \\ + \cnAccountAddress\low _{i + \relof} & \!\!\! = \!\!\! & \col{account\_address\_lo} \\ + \cnAccDepNum _{i + \relof} & \!\!\! = \!\!\! & \col{account\_deployment\_number} \\ + \cnCodeAddress\high _{i + \relof} & \!\!\! = \!\!\! & \col{byte\_code\_address\_hi} \\ + \cnCodeAddress\low _{i + \relof} & \!\!\! = \!\!\! & \col{byte\_code\_address\_lo} \\ + \cnCodeDepNum _{i + \relof} & \!\!\! = \!\!\! & \col{byte\_code\_deployment\_number} \\ + \cnCodeDepStatus _{i + \relof} & \!\!\! = \!\!\! & \col{byte\_code\_deployment\_status} \\ + \cnCodeCfi _{i + \relof} & \!\!\! = \!\!\! & \col{code\_fragment\_index} & (\trash) \\ + \cnCallerAddress\high _{i + \relof} & \!\!\! = \!\!\! & \col{caller\_address\_hi} \\ + \cnCallerAddress\low _{i + \relof} & \!\!\! = \!\!\! & \col{caller\_address\_lo} \\ + \cnCallValue _{i + \relof} & \!\!\! = \!\!\! & \col{call\_value} \\ + \cnCallDataContextNumber _{i + \relof} & \!\!\! = \!\!\! & \col{call\_data\_context\_number} & (\trash) \\ + \cnCdo _{i + \relof} & \!\!\! = \!\!\! & \col{call\_data\_offset} \\ + \cnCds _{i + \relof} & \!\!\! = \!\!\! & \col{call\_data\_size} \\ + \cnRao _{i + \relof} & \!\!\! = \!\!\! & \col{return\_at\_offset} \\ + \cnRac _{i + \relof} & \!\!\! = \!\!\! & \col{return\_at\_size} \\ + \cnUpdate _{i + \relof} & \!\!\! = \!\!\! & \rZero \\ + \cnReturner _{i + \relof} & \!\!\! = \!\!\! & \rZero \\ + \cnRdo _{i + \relof} & \!\!\! = \!\!\! & \rZero \\ + \cnRds _{i + \relof} & \!\!\! = \!\!\! & \rZero \\ + \end{array} \right. +\] + diff --git a/hub/context/next_context.tex b/hub/context/next_context.tex new file mode 100644 index 0000000..efff66b --- /dev/null +++ b/hub/context/next_context.tex @@ -0,0 +1,8 @@ +We introduce some named constraints to simplify the processing of \inst{CALL}-type instructions: +\[ + \left\{ \begin{array}{lcl} + \nextContextIsNew _{i} & \!\!\! \iff \!\!\! & \cn\new_{i} = 1 + \hubStamp_{i} \\ + \nextContextIsCurrent _{i} & \!\!\! \iff \!\!\! & \cn\new_{i} = \cn_{i} \\ + \nextContextIsCaller _{i} & \!\!\! \iff \!\!\! & \cn\new_{i} = \caller_{i} \\ + \end{array} \right. +\] diff --git a/hub/context/specialized_constraints.tex b/hub/context/specialized_constraints.tex new file mode 100644 index 0000000..b788716 --- /dev/null +++ b/hub/context/specialized_constraints.tex @@ -0,0 +1,102 @@ +We introduce some specialized constraints for context-rows. +The first specialized constraint of interest is that which allows us to \textbf{read context data without affecting any change}. +This constraint applies whenever context data is required (e.g. when acting on a \inst{RETURNDATASIZE}, \inst{RETURNDATACOPY}, \inst{CALLER}, \dots{}) +Recall that all context data is immutable with the exception of ``return data and returner context'' related context data. +As such the following suffices: +\[ + \readContextData {i}{\relof}{\col{context\_number}} + \iff + \left\{ \begin{array}{lcl} + \cnCn _{i + \relof} & \!\!\! = \!\!\! & \col{context\_number} \\ + \cnUpdate_{i + \relof} & \!\!\! = \!\!\! & \rZero \\ + \end{array} \right. +\] +The next specialized constraint is the opposite of the preceding, it allows us to \textbf{modify return data related fields}: +\[ + \left\{ \begin{array}{l} + \provideReturnData { + anchorRow = i , + relOffset = \relof , + returnDataReceiver = \col{rcv\_cn} , + returnDataProvider = \col{pvd\_cn} , + returnDataOffset = \col{rdo} , + returnDataSize = \col{rds} , + } + % \provideReturnData + % {i}{\relof} + % {\col{rcv\_cn}} % Return data receiver + % {\col{pvd\_cn}} % Return data provider + % {\col{rdo} } % Return data offset + % {\col{rds} } % Return data size + \vspace{4mm} \\ + \qquad\qquad\qquad \iff + \left\{ \begin{array}{lcl} + \cnCn _{i + \relof} & \!\!\! = \!\!\! & \col{rcv\_cn} \\ + \cnUpdate _{i + \relof} & \!\!\! = \!\!\! & \one \\ + \cnReturner _{i + \relof} & \!\!\! = \!\!\! & \col{pvd\_cn} \\ + \cnRdo _{i + \relof} & \!\!\! = \!\!\! & \col{rdo} \\ + \cnRds _{i + \relof} & \!\!\! = \!\!\! & \col{rds} \\ + \end{array} \right. + \end{array} \right. +\] +The following special cases are of interest: +\[ + \left\{ \begin{array}{lcl} + \executionProvidesEmptyReturnData {i}{\relof} \\ + \qquad\qquad\qquad \iff + \provideReturnData { + anchorRow = i , + relOffset = \relof , + returnDataReceiver = \caller_{i} , + returnDataProvider = \cn_{i} , + returnDataOffset = \rZero , + returnDataSize = \rZero , + } + % \provideReturnData + % {i}{\relof} + % {\caller_{i}} % Return data receiver + % {\cn_{i} } % Return data provider + % {\rZero } % Return data offset + % {\rZero } % Return data size + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \nonContextProvidesEmptyReturnData {i}{\relof} \\ + \qquad\qquad\qquad \iff + \provideReturnData { + anchorRow = i , + relOffset = \relof , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = \rZero , + returnDataSize = \rZero , + } + % \provideReturnData + % {i}{\relof} + % {\cn_{i} } % Return data receiver + % {1 + \hubStamp_{i}} % Return data provider + % {\rZero } % Return data offset + % {\rZero } % Return data size + \\ + \end{array} \right. +\] +We provide some details. +% +The $\executionProvidesEmptyReturnData {i}{\relof}$ constraint system is useful whenever an execution context halts through either an exception or a halting instruction which returns no return data (i.e. \inst{STOP} and \inst{SELFDESTRUCT}) and its parent resumes execution with the thusly updated return data. +% +The $\nonContextProvidesEmptyReturnData {i}{\relof}$ constraint system is useful whenever a \inst{CALL}-type or \inst{CREATE}-type instruction produces no exception in its current execution context but the operation is aborted for other reasons. \saNote{} Had this instruction not been aborted it would have spawned an execution context with $\cn = 1 + \hubStamp$. +That is, when \inst{CALL}'ing an account and not failing at the (\inst{CALL}-type) instruction level +(i.e. no \suxSH{}, \oogxSH{}, \staticxSH{}) +but instead encountering an aborting condition +(\csdAbortSH{}, +\balAbortSH{}, +\precAbortSH{}, +\dots{}) +the present execution context resumes execution with empty return data. +The same happens +when \inst{CREATE}'ing an account and not failing at the (\inst{CREATE}-type) instruction level +(i.e. no \suxSH{}, \oogxSH{}, \staticxSH{}) +but instead encountering an aborting condition +(\csdAbortSH{}, \balAbortSH{}, \deadAbortSH{}, \dots{}) diff --git a/hub/figures/batch_num_tx_num_progression.tex b/hub/figures/batch_num_tx_num_progression.tex new file mode 100644 index 0000000..1e50bb9 --- /dev/null +++ b/hub/figures/batch_num_tx_num_progression.tex @@ -0,0 +1,63 @@ +\begin{figure} +\centering +\[ +\renewcommand{\arraystretch}{1.5} +\begin{array}{|c|c||c|c|c|c|} + \hline + \batchNum & \txNum & ~ \col{tw} ~ & ~ \col{ti} ~ & ~ \col{te} ~ & ~ \col{tf} ~\\ + \hline\hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + \hline\hline + 1 & 1 & \dots & \dots & \dots & \dots \\ + 1 & 1 & \dots & \dots & \dots & \dots \\ + 1 & 1 & \dots & \dots & \dots & \dots \\ + \hline + 1 & 2 & \dots & \dots & \dots & \dots \\ + \hline + 1 & 3 & \dots & \dots & \dots & \dots \\ + 1 & 3 & \dots & \dots & \dots & \dots \\ + \hline + 1 & 4 & \dots & \dots & \dots & \dots \\ + 1 & 4 & \dots & \dots & \dots & \dots \\ + 1 & 4 & \dots & \dots & \dots & \dots \\ + 1 & 4 & \dots & \dots & \dots & \dots \\ + \hline + 1 & 5 & \dots & \dots & \dots & \dots \\ + \hline\hline + 2 & 1 & \dots & \dots & \dots & \dots \\ + \hline + 2 & 2 & \dots & \dots & \dots & \dots \\ + 2 & 2 & \dots & \dots & \dots & \dots \\ + \hline\hline + 3 & 1 & \dots & \dots & \dots & \dots \\ + 3 & 1 & \dots & \dots & \dots & \dots \\ + 3 & 1 & \dots & \dots & \dots & \dots \\ + 3 & 1 & \dots & \dots & \dots & \dots \\ + 3 & 1 & \dots & \dots & \dots & \dots \\ + 3 & 1 & \dots & \dots & \dots & \dots \\ + \hline\hline + 4 & 1 & \dots & \dots & \dots & \dots \\ + \hline + 4 & 2 & \dots & \dots & \dots & \dots \\ + \hline + 4 & 3 & \dots & \dots & \dots & \dots \\ + 4 & 3 & \dots & \dots & \dots & \dots \\ + 4 & 3 & \dots & \dots & \dots & \dots \\ + 4 & 3 & \dots & \dots & \dots & \dots \\ + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ +\end{array} +\] +\caption{Typical succession of $[ \batchNum, \txNum ]$ pairs. The numbers of times a \emph{nonzero} pair $[\col{b}, \col{t}]$ appears is always $\geq \ob{TODO}$ according to constraints on the +$\txWarm$, +$\txInit$, +$\txExec$ and +$\txFinl$ (which we have abbreviated to +\col{tw}, +\col{ti}, +\col{te} and +\col{tf} respectively for succinctness.) The succession represented above doesn't respect this condition. It's purely there to illustrate the fact that the pairs $[ \batchNum, \txNum ]$ are necessarily listed in the natural lexicographic order on $\mathbb{N}^2$. Changes in the $[ \col{b}, \col{t} ]$ pair are either +$[ \col{b}, \col{t} ]\rightsquigarrow [ \col{b}, \col{t} + 1]$ or +$[ \col{b}, \col{t} ]\rightsquigarrow [ \col{b} + 1, 1]$. } +\end{figure} \ No newline at end of file diff --git a/hub/figures/processing_phase_transition_graph.tex b/hub/figures/processing_phase_transition_graph.tex new file mode 100644 index 0000000..9b8a4d6 --- /dev/null +++ b/hub/figures/processing_phase_transition_graph.tex @@ -0,0 +1,41 @@ +\begin{figure}[!h] +\centering +\begin{tikzpicture}[node distance={3cm}, thick, main/.style = {draw, rectangle, rounded corners=1mm}] +\node[main, color = solarized-green] (warm) {$\txWarm$}; +\node[main, color = solarized-green] (init) [right of=warm] {$\txInit$}; +\node[main, color = solarized-yellow] (exec) [right of=init] {$\txExec$}; +\node[main, color = solarized-orange] (finl) [below of=warm] {$\txFinl$}; +\node[main, color = solarized-orange] (skip) [above left of=warm] {$\txSkip$}; +% \node[main, shading = axis, rectangle, left color=solarized-green, right color=solarized-orange, shading angle=135, anchor=north] (skip) [above left of=warm] {$\txSkip$}; +\draw[-latex] (warm) -- (init); +\draw[-latex] (init) -- (exec); +\draw[-latex] (exec) -- (finl); +\draw[-latex, dashed, color = solarized-blue] (finl) -- (warm); +\draw[-latex, dashed, color = solarized-blue] (finl) -- (init); +\draw (finl) edge [-latex, out=135,in=-90, dashed, color = solarized-blue] (skip); +\draw (warm) edge [-latex, out=135,in=45,looseness=5] node [above right] {$> 0$} (warm); +\draw (init) edge [-latex, out=135,in=45,looseness=5] node [above right] {$\nsrTransactionInitializationPhase$} (init); +\draw (exec) edge [-latex, out=135,in=45,looseness=5] node [above right] {$> 0$} (exec); +\draw (finl) edge [-latex, out=-135,in=-45,looseness=5] node [below] {$\nsrTransactionFinalizationPhaseWillRevert$ \OR $\nsrTransactionFinalizationPhaseWontRevert$} (finl); +\draw (skip) edge [-latex, out=135,in=45,looseness=5] node [above] {$\nsrTransactionSkippingPhase^*$} (skip); + \draw (skip) edge [-latex, dashed, color = solarized-blue, out=245,in=155,looseness=5] (skip); +\draw (skip.315) edge [-latex, dashed, color = solarized-blue] (warm.155); +\draw (skip) edge [-latex, dashed, out = -10, in = 135, color = solarized-blue] (init.155); +\end{tikzpicture} +\caption{% + The above is the transition graph of the boolean flags $\txSkip$, $\txWarm$, $\txInit$, $\txExec$ and $\txFinl$. + To occupy a node in this graph at time (i.e. row index) $i$ is to have the associated boolean flag $=1$ on that row. + Every non-padding row $i$ occupies a single vertex of the above graph. + To move along an oriented edge is to have the source node's boolean flag $=1$ at time $i$ and have the target node's boolean flag $=1$ at time $i+1$. \vspace{1mm} \\ + % + Consider the collection of row indices $i$ along which $\absTxNum_{i} \equiv \col{a}_{0}$ for some fixed \emph{nonzero} $\col{a}_{0}$. + These indices form an integer interval $[\![\,i_{0}, j_{0}[\![$. + If ``transaction $\col{a}_{0}$'' skips \textsc{evm}-execution then its processing occupies $\nsrTransactionSkippingPhase$ rows (and occupies the $\txSkip$ node throughout) i.e. $j_{0} = i_{0} + \nsrTransactionSkippingPhase$. + Several transactions in a row may skip execution (whence the asterisk $\nsrTransactionSkippingPhase^*$.) + If ``transaction $\col{a}_{0}$'' requires \textsc{evm}-execution one either has $\txWarm_{i_{0}} = 1$ or $\txInit_{i_{0}} = 1$. + There can be an arbitrary number of prewarming rows. + There are $\nsrTransactionInitializationPhase$ initialization rows. + There is then an arbitrary \emph{positive} number of execution rows and $\nsrTransactionFinalizationPhaseWillRevert$ or $\nsrTransactionFinalizationPhaseWontRevert$ finalization rows depending on if the transaction reverts or not. Crossing from a finalization row to another type of row (i.e. transitioning along one of the dashed blue edges ${\color{solarized-blue}\dashrightarrow}$) takes $\absTxNum$ to $1 + \col{a}_{0}$. + Similarly hitting a transaction row on a \txSkip-row also raises the absolute transaction number to $1 + \col{a}_{0}$} +\label{fig: processing phase transition graph} +\end{figure} diff --git a/hub/generalities/_inputs.tex b/hub/generalities/_inputs.tex new file mode 100644 index 0000000..c052145 --- /dev/null +++ b/hub/generalities/_inputs.tex @@ -0,0 +1,12 @@ +\input{generalities/_local} +\section{Generalities} \label{hub: generalities} +\subsection{Program counter columns \pc{} and $\pc\new$ \lispDone{}} \label{hub: generalities: program counter} \input{generalities/program_counter} +\subsection{Exception flags and \XAHOY{ \lispDone{}}} \label{hub: generalities: exceptions} \input{generalities/exceptions/_inputs} +\subsection{Context numbers and context changes \lispDone{}} \label{hub: generalities: context changes} \input{generalities/context/_inputs} +\subsection{Revert data specific constraints \lispDone{}} \label{hub: generalities: revert} \input{generalities/revert/_inputs} +\subsection{Gas \lispDone{}} \label{hub: generalities: gas} \input{generalities/gas/_inputs} +\subsection{Refunds \lispDone{}} \label{hub: generalities: refunds} \input{generalities/refunds/_inputs} +\subsection{Setting \stackJUMPDESTINATIONVETTING{} \lispDone{}} \label{hub: generalities: setting the jump destination vetting flag} \input{generalities/jump_destination_vetting} +\subsection{Auxiliary stamps and flags \lispDone{}} \label{hub: generalities: auxiliary stamps and flags} \input{generalities/stamps/_inputs} +\subsection{Setting \txEndStamp{} \lispDone{}} \label{hub: generalities: tx end stamp} \input{generalities/tx_end_stamp} +\subsection{Setting environment of new context $\firstRowOfNewContext {i}{\relof}$ \lispDone{}} \label{hub: generalities: first row of new context} \input{generalities/context_entry} diff --git a/hub/generalities/_local.tex b/hub/generalities/_local.tex new file mode 100644 index 0000000..f247386 --- /dev/null +++ b/hub/generalities/_local.tex @@ -0,0 +1,2 @@ +\def\locExceptionFlagSum {\col{exception\_flag\_sum}} +\def\locWeightedExceptionFlagSum {\col{wght\_}\locExceptionFlagSum} diff --git a/hub/generalities/abort.tex b/hub/generalities/abort.tex new file mode 100644 index 0000000..dae6bef --- /dev/null +++ b/hub/generalities/abort.tex @@ -0,0 +1,48 @@ +This section (partially) constrains the \abort{} and $\fCond$ flags. They exist purely to assist with the processing of \inst{CALL}-type and \inst{CREATE}-type instructions. These families of instructions share a unique property in that \textbf{their execution may be aborted despite them not raising an exception}. This is the case if any of the following conditions apply: +\begin{description} + \item[\csdAbortSH{}:] the caller / \creator{} context has call stack depth 1024; + \item[\balAbortSH{}:] the caller / \creator{} account has insufficient balance for the desired transfer; +\end{description} +(the latter applying only to \inst{CALL} and \inst{CALLCODE} instructions since \inst{DELEGATECALL} and \inst{STATICCALL} don't attempt to transfer value.) The purpose of the \abort{} flag is to signal when either of these \textbf{generic aborting conditions} applies. + +If the instruction produces neither an exception nor is aborted for the above reasons, it may still not lead to no execution. There are indeed \textbf{pre-execution failure conditions} which are triggered early in the processing of $\Lambda$ or $\Theta$ ($\Xi$, really.) \inst{CALL}-type instructions may come to a premature end if the callee is a precompile and either it is provided with insufficient gas or a precompile specific failure condition is satisfied. \inst{CREATE}-type instructions may come to a premature end if the \createe{} address has nonzero nonce or nonempty code (\deadAbortSH{}.) +The purpose of the $\fCond$ is to signal when one of these \textbf{instruction specific failure conditions} is satisfied. The ones pertaining to \inst{CREATE(2)} can be justified in the present module. Those pertaining to exceptional behaviour for precompiles require a module of their own to justify \ob{TODO: I love the clarity though --- things are falling into place : )} + +The following are generic constraints that enforce when \emph{not} to turn these flags on. +\begin{enumerate} + \item (\trash) $\abort$ and $\fCond$ are $\hubStamp$-constant \ob{TODO: in ``constancies'' section}; + \item (\trash) $\abort$ and $\fCond$ are binary \ob{TODO: in ``binary constraints'' section}; + \item \If $\txExec_{i} = 0$ \Then + \[ + \begin{cases} + \abort_{i} = 0 \\ + \fCond_{i} = 0 \\ + \end{cases} + \] + \item \If $\xAhoy_{i} = 1$ \Then + \[ + \begin{cases} + \abort_{i} = 0 \\ + \fCond_{i} = 0 \\ + \end{cases} + \] + \item \If $\abort_{i} = 1$ \Then $\fCond_{i} = 0$; + % \end{enumerate} + % \saNote{} One may sum up these conditions as follows: + % \[ + % \left\{ + % \begin{array}{rcl} + % \big[ (1 - \txExec_{i}) + \xAhoy_{i} \big] & \!\!\! \cdot \!\!\! & \abort_{i} = 0 \vspace{2mm} \\ + % \big[ (1 - \txExec_{i}) + \xAhoy_{i} + \abort_{i} \big] & \!\!\! \cdot \!\!\! & \fCond_{i} = 0 \vspace{2mm} \\ + % \end{array} + % \right. + % \] + % \begin{enumerate}[resume] + \item \If $\peekStack_{i} = 1$ \et $\stackDecCallFlag_{i} + \stackDecCreateFlag_{i} = 0$\footnote{Along stack-rows the $\stackDecCallFlag$ and $\stackDecCreateFlag$ are mutually exclusive binary flags; thus condition $\stackDecCallFlag + \stackDecCreateFlag = 0$ is equivalent to $\stackDecCallFlag + \stackDecCreateFlag \neq 1$} \Then $\abort_{i} = 0$; + \item \If $\peekStack_{i} = 1$ \et $\stackDecCreateFlag_{i} = 0$ \Then $\fCond_{i} = 0$; +\end{enumerate} + +\saNote{} \label{note: xahoy + abort + fcond are mutually exclusive binary flags} By construction $\xAhoy$, $\abort$, $\fCond$ are mutually exclusive (\hubStamp{}-constant) binary flags. + + +\ob{TODO: for future notice: we will use the $\fCond$ flag in case of \inst{CALL}-type instructions to deal with precompile specific failure conditions.} diff --git a/hub/generalities/context/_inputs.tex b/hub/generalities/context/_inputs.tex new file mode 100644 index 0000000..fbfc179 --- /dev/null +++ b/hub/generalities/context/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Introduction} \label{hub: generalities: context: intro} \input{generalities/context/intro} +\subsubsection{Setting the \cmc{} flag} \label{hub: generalities: context: cmc flag} \input{generalities/context/cmc_flag} +\subsubsection{Context numbers} \label{hub: generalities: context: context numbers} \input{generalities/context/numbers} diff --git a/hub/generalities/context/cmc_flag.tex b/hub/generalities/context/cmc_flag.tex new file mode 100644 index 0000000..6814837 --- /dev/null +++ b/hub/generalities/context/cmc_flag.tex @@ -0,0 +1,17 @@ +Below are the associated constraints: +\begin{enumerate} + \item $\cmc$ is binary + \item $\cmc$ is $\hubStamp$-constant + \item \If $\txExec_{i} = 0$ \Then $\cmc_{i} = 0$ +\end{enumerate} +Thus the only rows where $\cmc$ may be nonzero are execution rows. Given the $\hubStamp$-constancy condition and the fact that every execution step contains one (or two) stack row(s)\footnote{depending on whether $\tli = 0$ or $\tli = 1$} it suffices to settle its value along $\peekStack$ rows, which is what we do below. +\begin{enumerate}[resume] + \item \If $\peekStack_{i} = 1$ \Then + \[ + \left\{ \begin{array}{l} + \If \xAhoy_{i} + \stackDecHaltFlag_{i} +\stackDecCallFlag_{i} + \stackDecCreateFlag_{i} \neq 0 ~ \Then \cmc_{i} = 1 \\ + \If \xAhoy_{i} + \stackDecHaltFlag_{i} +\stackDecCallFlag_{i} + \stackDecCreateFlag_{i} = 0 ~ \Then \cmc_{i} = 0 \\ + \end{array} \right. + \] +\end{enumerate} + diff --git a/hub/generalities/context/intro.tex b/hub/generalities/context/intro.tex new file mode 100644 index 0000000..e49f1c5 --- /dev/null +++ b/hub/generalities/context/intro.tex @@ -0,0 +1,86 @@ +The present section deals with several context number and context change related columns, in particular +\begin{multicols}{4} + \begin{enumerate} + \item \cmc + \item \cn + \item $\cn\new$ + \item \caller + \end{enumerate} +\end{multicols} +Context numbers only bear any real significance during the execution phase of a transaction. +Their main purpose is to provide a unique identifier to execution context data. +This includes a reference to the caller context (\caller) and a reference to the bytecode which is executing in the present context (\cfi.) +It also includes environment variables, the stack and memory. + +For various reasons the execution context may switch during execution. +Note that there are circumstances where the execution context \textbf{is guaranteed to change} e.g. whenever +(\emph{a}) an \textbf{exception} occurs or +(\emph{b}) the current instruction is a \textbf{halting instruction}. +At times the execution context is \textbf{poised to change} but may or may not actually change. +This happens whenever the current instruction is either +(\emph{c}) of \textbf{\inst{CALL}-type} or +(\emph{d}) of \textbf{\inst{CREATE}-type}. +Determining when a context change may happen is therfore comparatively easy. +This is the purpose of the \cmc{}. + +\saNote{} Whenever the execution context \emph{may change} the \zkEvm{} \textbf{must} perform various sanity checks (such as making sure that its gas supply pre-opcode is nonnegative.) + +Determining when there is a change in execution contexts is trickier. +Consider the following possibilities: +\begin{description} + \item[Exception:] + if an exception of any sort occurs (i.e. $\xAhoy_{i} = 1$), the \zkEvm{} resets the \caller{}'s return data + and resumes its exeuction (unless the current context is the root context); + \item[Unexceptional halting instruction:] + no exception occurs (i.e. $\xAhoy_{i} = 0$) and the present instruction is a halting instruction (i.e. $\haltFlag_{i} = 1$); + the \zkEvm{} sets the caller context's return data accordingly (which include the case of a \inst{RETURN} in a deployment context) + and resumes its exeuction (unless the current context is the root context); + \item[Unexceptional \inst{CALL}-type instruction:] + no exception has occurred (i.e. $\xAhoy_{i} = 0$) and the present instruction is a \inst{CALL}-type (i.e. $\callFlag \equiv 1$); + then either: + \begin{enumerate} + \item + the call is aborted due to either \balAbortSH{} or \csdAbortSH{}; + the current execution context continues execution; + the \zkEvm{} resets its return data to be empty; + \item + the call isn't aborted; + the \zkEvm{} \emph{could} enter a new context but doesn't because this is a call to a precompile; + the \zkEvm{} sets the current execution context's return data to the relevant values depending on whether the precompile succeeds or not; + the current execution context continues execution; + \item + the call isn't aborted; + the \zkEvm{} \emph{could} enter a new context but doesn't because the \inst{CALL} is a simple transfer i.e. the target account has empty code (but isn't a precompile); + the \zkEvm{} resets the current execution context's return data to be empty; + the current execution context continues execution; + \item + the call isn't aborted; + the target address has nonempty byte code; + the \zkEvm{} spawns (i.e. initializes) a ``child'' message call context; + in this case the new child context starts executing at the next \hubStamp{}; + \end{enumerate} + \item[Unexceptional \inst{CREATE}-type instruction:] + no exception has occurred (i.e. $\xAhoy_{i} = 0$) and the present instruction is a \inst{CREATE}-type instruction; + then either + \begin{enumerate} + \item + the deployment is aborted due to either \balAbortSH{} or \csdAbortSH{}; + the current execution context continues execution; + the \zkEvm{} resets its return data to be empty; + \item + the deployment isn't aborted but raises a failure condition (the deployment address either has a nonzero nonce or nonempty byte code); + the current execution context resumes execution; + the \zkEvm{} resets its return data to be empty; + \item + deployment is neither aborted nor does it raise a failure condition; + but the instruction is provided with empty initialization code and no deployment context is spawned; + the current execution context then resumes execution; + the \zkEvm{} must reset its return data to be empty; + \item + deployment is neither aborted nor does it raise a failure condition; + the instruction is provided with nonempty initialization code; + the \zkEvm{} spawns (i.e. initializes) a ``child'' deployment context; + in this case the new child context starts executing at the next \hubStamp{}; + \end{enumerate} +\end{description} +\saNote{} From the \zkEvm{}'s point of view the execution context \textbf{does, infact, change} \emph{if and only if} $\cn \not\equiv \cn\new$. diff --git a/hub/generalities/context/numbers.tex b/hub/generalities/context/numbers.tex new file mode 100644 index 0000000..f0664d8 --- /dev/null +++ b/hub/generalities/context/numbers.tex @@ -0,0 +1,32 @@ +This section presents some of the basic constraints pertaining to the context number columns $\cn$ and $\cn\new$. +Recall that both are stamp-constant, see section~\ref{hub: constancy conditions}. +\begin{enumerate} + \item $\cn$ and $\cn\new$ are hub-stamp-constant + \item \If $\txInit_{i} = 1$ \Then + \begin{enumerate} + \item $\cn _{i} = 0$ + \item $\cn\new _{i} = 1 + \hubStamp_{i}$ + \end{enumerate} + \item \If $\txExec_{i} = 1$ \Then + \begin{enumerate} + \item\label{next context number} + $\cn\new_{i} \in \{ \cn_{i}, \caller_{i}, 1 + \hubStamp_{i} \}$ + \item \If $\hubStamp_{i} \neq \hubStamp_{i - 1}$ \Then $\cn_{i} = \cn\new_{i - 1}$ + \item \If $\cmc_{i} = 0$ \Then $\cn\new_{i} = \cn_{i}$ + \end{enumerate} + \item \If $\hubStamp_{i + 1} \neq \hubStamp_{i}$ \Then + \begin{enumerate} + \item \If $\cmc_{i} = 1$ \Then $\peekContext_{i} = 1$ + \item \If $\xAhoy_{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{0} $ + \item\label{hub: generalitiles: context: how to trigger finalization phase} \If $\txExec_{i} = 1$ + \begin{enumerate} + \item \If $\cn\new_{i} \neq 0$ \Then $\txExec_{i + 1} = 1$ + \item \If $\cn\new_{i} = 0$ \Then $\txFinl_{i + 1} = 1$ + \end{enumerate} + \end{enumerate} + \item \If $\xAhoy_{i} = 1$ \Then $\cn\new_{i} = \caller_{i}$ + \item \If \big($\peekStack_{i} = 1$ \et $\haltFlag_{i} = 1$\big) \Then $\cn\new_{i} = \caller_{i}$ +\end{enumerate} +\saNote{} Constraint~(\ref{hub: generalitiles: context: how to trigger finalization phase}) settles the question of when execution stops and the finalization phase starts. + +\saNote{} We refer to section~\ref{hub: generalities: context: context constraints} for the definition of $\executionProvidesEmptyReturnData {i}{\relof}$. diff --git a/hub/generalities/context_entry.tex b/hub/generalities/context_entry.tex new file mode 100644 index 0000000..a750534 --- /dev/null +++ b/hub/generalities/context_entry.tex @@ -0,0 +1,24 @@ +We define the following parametrized constraint systems. These will be used to set some parameters of a new execution context. +\[ + \left\{ \begin{array}{l} + \firstRowOfNewContext {i}{\relof} + \left[ \begin{array}{llr} + \utt{Next caller context number:} & \col{new\_caller\_context\_number} \\ + \utt{Next code fragment index:} & \col{new\_cfi} \\ + \utt{Available gas in new frame:} & \col{new\_initial\_gas} \\ + \end{array} \right] + \vspace{4mm} \\ + \qquad \iff + \left\{ \begin{array}{lclr} + \cn _{i + \relof} & \!\!\! = \!\!\! & \cn\new _{i} & (\trash) \\ + \caller _{i + \relof} & \!\!\! = \!\!\! & \col{new\_caller\_context\_number} \\ + \cfi _{i + \relof} & \!\!\! = \!\!\! & \col{new\_cfi} \\ + \gasExpected _{i + \relof} & \!\!\! = \!\!\! & \col{new\_initial\_gas} \\ + \pc _{i + \relof} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \height _{i + \relof} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \end{array} \right. + \end{array} \right. +\] +\saNote{} There is no reason to constrain \cn{} given that \cn{} will be inherited from $\cn\new$ on the final row of the previous \hubStamp{}, see section~(\ref{hub: generalities: context: context numbers}). + +\saNote{} There is no reason to constrain either \pc{} nor \height{} given that consistency arguments from section~(\ref{hub: consistencies: environment}) already impose vanishing. diff --git a/hub/generalities/exceptions/_inputs.tex b/hub/generalities/exceptions/_inputs.tex new file mode 100644 index 0000000..348c979 --- /dev/null +++ b/hub/generalities/exceptions/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Binarity and constancy constraints} \label{hub: generalities: exceptions: binarity and constancy} \input{generalities/exceptions/binarity_and_constancy} +\subsubsection{Automatic vanishing conditions} \label{hub: generalities: exceptions: automatic vanishing} \input{generalities/exceptions/vanishing} +\subsubsection{The \XAHOY{} flag} \label{hub: generalities: exceptions: xAhoy} \input{generalities/exceptions/xahoy} diff --git a/hub/generalities/exceptions/binarity_and_constancy.tex b/hub/generalities/exceptions/binarity_and_constancy.tex new file mode 100644 index 0000000..d7043d7 --- /dev/null +++ b/hub/generalities/exceptions/binarity_and_constancy.tex @@ -0,0 +1,76 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekStack_{i} = 1.} +\end{center} + +\noindent The present section imposes some general constraints on the exception flags. We use the following shorthands +\[ + \hspace*{-1.5cm} + \locExceptionFlagSum_{i} + \define + \left[ \begin{array}{cr} + + & \stackSux{} \\ + + & \stackSox{} \\ + + & \stackOogx{} \\ + + & \stackMxpx{} \\ + + & \stackOpcx{} \\ + + & \stackRdcx{} \\ + + & \stackJumpx{} \\ + + & \stackStaticx{} \\ + + & \stackSstorex{} \\ + + & \stackIcpx{} \\ + + & \stackMaxcsx{} \\ + \end{array} \right] + \quad\text{and}\quad + \locWeightedExceptionFlagSum_{i} + \define + \left[ \begin{array}{crcl} + + & 2^{0} & \!\!\!\cdot\!\!\! & \stackSux _{i} \\ + + & 2^{1} & \!\!\!\cdot\!\!\! & \stackSox _{i} \\ + + & 2^{2} & \!\!\!\cdot\!\!\! & \stackOogx _{i} \\ + + & 2^{3} & \!\!\!\cdot\!\!\! & \stackMxpx _{i} \\ + + & 2^{4} & \!\!\!\cdot\!\!\! & \stackOpcx _{i} \\ + + & 2^{5} & \!\!\!\cdot\!\!\! & \stackRdcx _{i} \\ + + & 2^{6} & \!\!\!\cdot\!\!\! & \stackJumpx _{i} \\ + + & 2^{7} & \!\!\!\cdot\!\!\! & \stackStaticx _{i} \\ + + & 2^{8} & \!\!\!\cdot\!\!\! & \stackSstorex _{i} \\ + + & 2^{9} & \!\!\!\cdot\!\!\! & \stackIcpx _{i} \\ + + & 2^{10} & \!\!\!\cdot\!\!\! & \stackMaxcsx _{i} \\ + \end{array} \right] +\] +We require the following: +\begin{enumerate} + \item we impose \textbf{binarity constraints} on all exception flags + \begin{multicols}{4} + \begin{enumerate} + \item $\stackSux_{i}$ + \item $\stackSox_{i}$ + \item $\stackOogx_{i}$ + \item $\stackMxpx_{i}$ + \item $\stackOpcx_{i}$ + \item $\stackRdcx_{i}$ + \item $\stackJumpx_{i}$ + \item $\stackStaticx_{i}$ + \item $\stackSstorex_{i}$ + \item $\stackIcpx_{i}$ + \item $\stackMaxcsx_{i}$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item we impose a binarity constraint on $\locExceptionFlagSum$; + \item we impose \textbf{stack-row-constancy} on $\locWeightedExceptionFlagSum$; +\end{enumerate} + +\saNote{} The above imposes that the exception flags be \textbf{exclusive, stack-row-constant binary columns}, see section~(\ref{hub: heartbeat: constancy conditions}) for the definition of stack-row-constancy. +This has important consequences for the arithmetization, as well as for the implementation. +Exclusivity of exception flags means that from the \zkEvm{}'s perspective \textbf{only one exception may be triggered at any point in time}. +Yet most \evm{} opcodes can trigger several exceptions at once. +For instance a great many instructions can trigger either \suxSH{} and \oogxSH{}. +Certain opcodes may trigger several complex exceptions. +\inst{CALL} instructions, for instance, can trigger any of the following +\suxSH's, +\staticxSH's, +\mxpxSH's and +\oogxSH's. +The way that the arithmetization deals with this complexity is that it deals with exception in a instruction family specific order\footnote{and in the unexceptional case it must justify the absence of any exception}. + +\saNote{} The one exception to that are \opcxSH{}, \suxSH{} and \soxSH{} which always get checked first. diff --git a/hub/generalities/exceptions/vanishing.tex b/hub/generalities/exceptions/vanishing.tex new file mode 100644 index 0000000..ebcd4f4 --- /dev/null +++ b/hub/generalities/exceptions/vanishing.tex @@ -0,0 +1,17 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekStack_{i} = 1.} +\end{center} +What follows are constraints preventing certain instruction families from triggering certain exceptions. +Thus reducing the complexity of the ``exception analysis'' required in the instruction handling. +\begin{enumerate} + \item $\stackOpcx _{i} = \stackDecInvalidFlag_{i}$ + \item \If $\stackDecMxpFlag_{i} = 0$ \Then $\stackMxpx _{i} = 0$ + \item \If $\stackDecJumpFlag_{i} = 0$ \Then $\stackJumpx _{i} = 0$ + \item \If $\decStaticInst_{i} = 0$ \Then $\stackStaticx _{i} = 0$ + \item \If $\stackInst_{i} \neq \inst{RETURNDATACOPY}$ \Then $ \stackRdcx_{i} = 0 $ + \item \If $\stackInst_{i} \neq \inst{SSTORE}$ \Then $ \stackSstorex_{i} = 0 $ + \item \If $\stackInst_{i} \neq \inst{RETURN}$ \Then $ \stackIcpx_{i} + \stackMaxcsx_{i} = 0 $ +\end{enumerate} +\saNote{} +More details will be given about $\stackIcpx$ and $\stackMaxcsx$ in section~(\ref{hub: instruction handling: halt: revert}). +Indeed, these exceptions can only apply in deployment contexts and the first one requires a nonzero \col{size} argument for the \inst{RETURN} instruction. diff --git a/hub/generalities/exceptions/xahoy.tex b/hub/generalities/exceptions/xahoy.tex new file mode 100644 index 0000000..af4ffd1 --- /dev/null +++ b/hub/generalities/exceptions/xahoy.tex @@ -0,0 +1,15 @@ +The arithmetization requires, at various points during opcode processing, access to the knowledge of whether an instruction produces an exception or not. +Yet, the various exception flags for which we produced some preliminary constraints in section~(\ref{hub: generalities: exceptions: binarity and constancy}) belong to the stack perspective. +In other words they are only ``readily available'' along stack-rows i.e. rows with $\peekStack = 1$. +The purpose of the \xAhoy{} flag is to make a summary of that information available outside of stack rows for as long as required, i.e. along all rows with a given \hubStamp{}. + +The constraints for \xAhoy{} are as follows: +\begin{enumerate} + \item \xAhoy{} is binary + \item \xAhoy{} is hub-stamp-constant + \item \If $\txExec_{i} = 0$ \Then $\xAhoy_{i} = 0$ + \item \If $\peekStack_{i} = 1$ \Then $\xAhoy_{i} = \locExceptionFlagSum_{i}$ +\end{enumerate} +\saNote{} Hub-stamp-constancy was already imposed in section~(\ref{hub: heartbeat: constancy conditions}). + +\saNote{} The \xAhoy{} flag is a refinement of the \cmc{} flag which we define in section~(\ref{hub: generalities: context: cmc flag}) in the sense that whenever $\xAhoy = 1$ then $\cmc = 1$, too. diff --git a/hub/generalities/gas/_inputs.tex b/hub/generalities/gas/_inputs.tex new file mode 100644 index 0000000..c2e52d3 --- /dev/null +++ b/hub/generalities/gas/_inputs.tex @@ -0,0 +1,2 @@ +\subsubsection{Gas column generalities} \label{hub: generalities: gas and refunds: generalities} \input{generalities/gas/generalities} +\subsubsection{Gas transition constraints} \label{hub: generalities: gas and refunds: gas transition constraints} \input{generalities/gas/constraints} diff --git a/hub/generalities/gas/constraints.tex b/hub/generalities/gas/constraints.tex new file mode 100644 index 0000000..73acb9a --- /dev/null +++ b/hub/generalities/gas/constraints.tex @@ -0,0 +1,42 @@ +The following constraints enforce some of the relationships between gas columns. +\begin{enumerate} + \item \If $\txExec_{i} = 1$ \Then + \begin{enumerate} + \item \If $\xAhoy_{i} = 0$ \Then $\gasNext_{i} = \gasActual_{i} - \gasCost_{i}$ + \item \If $\xAhoy_{i} = 1$ \Then $\gasNext_{i} = 0$\footnote{The ``\If $\txExec_{i} = 1$ \Then \dots'' precondition may be dropped here.} + \end{enumerate} + \item \If + \[ + \left\{ \begin{array}{lcl} + \hubStamp_{i + 1} & \neq & \hubStamp_{i} \\ + \txExec_{i} & = & 1 \\ + \txExec_{i + 1} & = & 1 \\ + \end{array} \right. + \] + \Then we impose + \begin{enumerate} + \item\label{hub: generalities: gas: could blow up} \If $\cn\new_{i} = \cn_{i}$ \Then $\gasActual_{i + 1} = \gasExpected_{i + 1}$ + \item\label{hub: generalities: gas: resuming execution gas constraint} \If $\cn\new_{i} = \caller_{i}$ \Then + $\gasActual_{i + 1} = \gasExpected_{i + 1} + \gasNext_{i}$ + \item\label{hub: generalities: gas: spawning new context} \If $\cn\new_{i} = 1 + \hubStamp_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \gasExpected_{i + 1} & = & \relevantValue \\ + \gasActual_{i + 1} & = & \gasExpected_{i + 1} \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} +Some details: +(\ref{hub: generalities: gas: resuming execution gas constraint}) asserts that when an execution context reaches its conclusion (as witnessed by $\cn\new_{i} = \caller_{i}$) the $\gasNext$ column on that row must contain the left over gas in the present context. +We are unable to settle the ``call gas'' or ``create gas'' provided to a child context spawned through a \inst{CREATE}-type or \inst{CALL}-type instruction at this level of generatlity, whence the \relevantValue{} in constraint~(\ref{hub: generalities: gas: spawning new context}). It is a complex question and will be settled when we deal with the processing of those instruction families. + +\issue{Constraint~(\ref{hub: generalities: gas: could blow up}) could blow up if we don't handle precompiles, pure transfers and deployments with empty code correctly.} + +We further impose that +\begin{enumerate}[resume] + \item + \If $\peekStack _{i} = 1$ \et $\stackOogx _{i} + (1 - \xAhoy_{i}) \neq 1$ \Then $\gasCost _{i} = 0$. +\end{enumerate} +\saNote{} Along stack-rows it holds that $\col{cond} \equiv \stackOogx _{i} + (1 - \xAhoy_{i})$ is actually \textbf{binary} so that $\col{cond} \neq 1$ really means $\col{cond} = 0$. +Indeed, by construction, and along stack-rows, $0 \leq \stackOogx _{i} \leq \xAhoy_{i} \leq 1$ so that if $\stackOogx _{i} \equiv 1$ then $(1 - \xAhoy_{i}) \equiv 0$. diff --git a/hub/generalities/gas/generalities.tex b/hub/generalities/gas/generalities.tex new file mode 100644 index 0000000..3515e06 --- /dev/null +++ b/hub/generalities/gas/generalities.tex @@ -0,0 +1,14 @@ +We impose the following general constraints on gas columns: +\begin{enumerate} + \item the following columns are hub-stamp-constant + \begin{multicols}{3} + \begin{enumerate} + \item \gasExpected + \item \gasNext + \item \gasActual + \item \gasCost + \item \refund + \item $\refund\new$ + \end{enumerate} + \end{multicols} +\end{enumerate} diff --git a/hub/generalities/jump_destination_vetting.tex b/hub/generalities/jump_destination_vetting.tex new file mode 100644 index 0000000..cb8307d --- /dev/null +++ b/hub/generalities/jump_destination_vetting.tex @@ -0,0 +1,15 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekStack_{i} = 1.} +\end{center} +We specify the \stackJumpDestinationVetting{} flag. The idea is that this flag should only light up for \inst{JUMP}-type instructions that +(\emph{a}) don't produce a \suxSH{} +(\emph{b}) don't produce an \oogxSH{} +(\emph{c}) don't produce an ``out of bounds event'' (i.e. whenever the proposed new program counter \col{pnpc} satisfies $\col{pnpc} \geq \col{code\_size}$.) +The constraints are as follows: +\begin{enumerate} + \item \stackJumpDestinationVetting{} is binary ~ (\trash); + \item \If $\stackDecJumpFlag_{i} = 0$ \Then $\stackJumpDestinationVetting_{i} = 0$; + \item \If $\stackSux_{i} + \stackSox_{i} + \stackOogx_{i} \neq 0$ \Then $\stackJumpDestinationVetting_{i} = 0$; + \item \If $\stackDecJumpFlag_{i} = 1$ \Then see section~(\ref{hub: instruction handling: jump}); +\end{enumerate} +For the remaining case ``\If \Big($\stackDecJumpFlag_{i} = 1$ \et $\stackSux_{i} + \stackSox_{i} + \stackOogx_{i} = 0$\Big)'' see section~(\ref{hub: instruction handling: jump}). diff --git a/hub/generalities/program_counter.tex b/hub/generalities/program_counter.tex new file mode 100644 index 0000000..ec6a205 --- /dev/null +++ b/hub/generalities/program_counter.tex @@ -0,0 +1,20 @@ +We provide partial constraints for the $\pc$ and $\pc\new$ colunms. +These constraints are \emph{partial} in that special care will be taken for \inst{PUSHX}, $\inst{X} = 1, 2, \dots, 32$, and \inst{JUMP(I)} instructions, see +section~(\ref{hub: instruction handling: pushPop}) and +section~(\ref{hub: instruction handling: jump}) respectively. +We also impose consistency conditions on these columns, see +section~(\ref{hub: consistencies: execution environment: constraints}). +We impose the general constraints following +\begin{enumerate} + \item $\pc$ and $\pc\new$ are hub-stamp-constant; + \item \If $\txExec_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \pc_{i} & = & 0 \\ + \pc\new_{i} & = & 0 \\ + \end{array} \right. + \] + \item \If $\peekStack_{i} = 1$ \et $\stackDecPushPopFlag_{i} + \stackDecJumpFlag_{i} = 0$ \Then $\pc\new_{i} = 1 + \pc_{i}$ + \item \If $\peekStack_{i} = 1$ \et $\stackDecPushPopFlag_{i} = 1$ \Then $\pc\new_{i} = \cdots$ see section~(\ref{hub: instruction handling: pushPop}) + \item \If $\peekStack_{i} = 1$ \et $ \stackDecJumpFlag_{i} = 1$ \Then $\pc\new_{i} = \cdots$ see section~(\ref{hub: instruction handling: jump}) +\end{enumerate} diff --git a/hub/generalities/refunds/_inputs.tex b/hub/generalities/refunds/_inputs.tex new file mode 100644 index 0000000..78ba1dd --- /dev/null +++ b/hub/generalities/refunds/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Introduction} \label{hub: generalities: refunds: introduction} \input{generalities/refunds/intro} +\subsubsection{Generalities} \label{hub: generalities: refunds: generalities} \input{generalities/refunds/generalities} +\subsubsection{Constraints} \label{hub: generalities: refunds: refunds} \input{generalities/refunds/constraints} diff --git a/hub/generalities/refunds/constraints.tex b/hub/generalities/refunds/constraints.tex new file mode 100644 index 0000000..c55417f --- /dev/null +++ b/hub/generalities/refunds/constraints.tex @@ -0,0 +1,38 @@ + +The constraints below enforce the behavior described above. +\begin{enumerate} + \item \If $\txExec_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \refund_{i} & = & 0 \\ + \refund\new_{i} & = & 0 \\ + \end{array} \right. + \] + \item \If $\hubStamp_{i} \neq \hubStamp_{i - 1}$ \et $\txExec_{i} = 1$ \Then $\refund_{i} = \refund\new_{i - 1}$ +\end{enumerate} +The above is the transition constraint for gas refunds. +Recall that \textbf{along stack-rows} one has +\[ + \begin{cases} + \stackDecStoFlag \cdot \decFlag{1} \equiv 1 & \text{precisely for \inst{SSTORE}, see section~\ref{hub: instruction handling: sto};} \\ + \stackDecHaltFlag \cdot \decFlag{4} \equiv 1 & \text{precisely for \inst{SELFDESTRUCT}, see section~\ref{hub: instruction handling: halt};} \\ + \end{cases} +\] +and that $\stackDecStoFlag$ and $\stackDecHaltFlag$ are mutually exclusive binary flags. +\begin{enumerate}[resume] + \item \If $\cnWillRev_{i} = 1$ \Then $\refund\new_{i} = \refund_{i}$ + \item \If $\peekStack_{i} = 1$ \et $ + \left[ \begin{array}{cr} + + & \stackDecStoFlag _{i} \cdot \decFlag{1}_{i} \\ + + & \stackDecHaltFlag _{i} \cdot \decFlag{4}_{i} \\ + \end{array} \right] + = 0$ \Then $\refund\new_{i} = \refund_{i}$ + \item \If $\cnWillRev_{i} = 0$ \et $\peekStack_{i} = 1$ \Then + \begin{enumerate} + \item \If $\stackDecStoFlag_{i} \cdot \decFlag{1}_{i} = 1$ \Then \dots{} see section~(\ref{hub: instruction handling: sto}) + \item \If $\stackDecHaltFlag_{i} \cdot \decFlag{4}_{i} = 1$ \Then \dots{} see section~(\ref{hub: instruction handling: halt}) + \end{enumerate} +\end{enumerate} +\saNote{} In the implementation one may replace condition +``\If $\stackDecStoFlag_{i} \cdot \decFlag{1}_{i} + \stackDecHaltFlag_{i} \cdot \decFlag{4}_{i} = 0$'' with condition +``\If $\stackDecStoFlag_{i} \cdot \decFlag{1}_{i} + \stackDecHaltFlag_{i} \cdot \decFlag{4}_{i} \neq 1$''. diff --git a/hub/generalities/refunds/generalities.tex b/hub/generalities/refunds/generalities.tex new file mode 100644 index 0000000..bddef05 --- /dev/null +++ b/hub/generalities/refunds/generalities.tex @@ -0,0 +1,10 @@ +We impose the following general constraints on refund columns: +\begin{enumerate} + \item the following columns are hub-stamp-constant + \begin{multicols}{2} + \begin{enumerate} + \item \refund + \item $\refund\new$ + \end{enumerate} + \end{multicols} +\end{enumerate} diff --git a/hub/generalities/refunds/intro.tex b/hub/generalities/refunds/intro.tex new file mode 100644 index 0000000..5fdbc2f --- /dev/null +++ b/hub/generalities/refunds/intro.tex @@ -0,0 +1,27 @@ +The present section sets some of the constraints for the ``refund columns''. +Refunds may only be accrued during the execution phase of a transaction. +To simplify processing we introduce \textbf{two} refund counters, \refund{} and $\refund\new$\footnote{Though one column would suffice}. +The underlying idea is simple: $\refund\new$ contains the refund counter post opcode execution. +Recall that gas refunds may only be granted for +\inst{SSTORE} and +\inst{SELFDESTRUCT} opcodes. +We shall therefore impose for all instructions other than these two that $\refund \new \equiv \refund$. +The precise conditions which lead to gas refunds being granted will be described when we deal with the processing of \inst{SSTORE} and \inst{SELFDESTRUCT} in sections +\ref{hub: instruction handling: sto} and +\ref{hub: instruction handling: halt} respectively. + +When an execution context reverts all refunds accrued through the execution of said execution context are discarded. +Implementations of the \evm{} typically achieve this by reverting to a snapshot (including environment variables) taken before the \inst{CALL} or \inst{CREATE} that spawned said execution environment. +This resets refunds related to \inst{SSTORE}'s as well as purges addresses from the \inst{SELFDESTRUCT} set added by any descendant context. +Rather than roll back said refunds and purge addresses from a \inst{SELFDESTRUCT} set our \zkEvm{} design simply does not tally refunds generated by execution contexts that will revert. +Recall that execution contexts which will end up reverting are characterized by (the context-constant bit) $\cnWillRev \equiv 1$. +Our \zkEvm{} design thus has has present knowledge of future rollbakcs and can decide on that basis which refunds to grant and which to ignore. + +Things are sligtly tricky when it comes to \inst{SELFDESTRUCT}'s. +Indeed refunds associated with \inst{SELFDESTRUCT}'s are accounted for immediately with every (unreverted and unexceptional) \inst{SELFDESTRUCT}. +Yet an address can \inst{SELFDESTRUCT} several times within a single transaction but should only generate one refund. +Instead of \inst{SELFDESTRUCT} sets our \zkEvm{} design has an \textbf{address tagging mechanism} that serves the same purpose. +We attach a monotone bit to every account that distinguishes addresses marked for \inst{SELFDESTRUCT} within a given transaction. +This bit then allows us to detect multiple (unreverted) \inst{SELFDESTRUCT}'s happening at a given address within a single transaction, and prevents the \zkEvm{} from granting multiple refunds as a consequence. + +\saNote{} The \inst{SELFDESTRUCT} opcode has been simplified in more recent versions\footnote{e.g. \texttt{c74b55f}} of the \evm{}. diff --git a/hub/generalities/revert/_inputs.tex b/hub/generalities/revert/_inputs.tex new file mode 100644 index 0000000..a7144ea --- /dev/null +++ b/hub/generalities/revert/_inputs.tex @@ -0,0 +1,7 @@ +\input{generalities/revert/_local} +\subsubsection{Introduction} \label{hub: generalities: revert: intro} \input{generalities/revert/intro} +\subsubsection{Generalities and setting \cnWillRev{}} \label{hub: generalities: revert: will revert} \input{generalities/revert/will_revert} +\subsubsection{Setting \cnSelfRev{}} \label{hub: generalities: revert: self revert} \input{generalities/revert/self_revert} +\subsubsection{Setting \cnGetsRev{}} \label{hub: generalities: revert: gets reverted} \input{generalities/revert/gets_reverted} +\subsubsection{Special purpose constants} \label{hub: generalities: revert: constants} \input{generalities/revert/constants} +\subsubsection{$\domStamp$ and $\subStamp$ constraints} \label{hub: generalities: revert: dom and sub stamps} \input{generalities/revert/dom_and_sub} diff --git a/hub/generalities/revert/_local.tex b/hub/generalities/revert/_local.tex new file mode 100644 index 0000000..63534c3 --- /dev/null +++ b/hub/generalities/revert/_local.tex @@ -0,0 +1,8 @@ +\def\locSelfRevertTrigger {\col{self\_revert\_trigger}} +\def\locTrue {\texttt{true}} +\def\locFalse {\texttt{false}} +\def\locRevertStamp {\texttt{h\_self\_rev}} +\def\locCurrentContext {\texttt{context}} +\def\locParentContext {\texttt{parent}} +\def\locRootContext {\texttt{root}} +\def\locBedrockContext {\texttt{bedrock}} diff --git a/hub/generalities/revert/constants.tex b/hub/generalities/revert/constants.tex new file mode 100644 index 0000000..380149e --- /dev/null +++ b/hub/generalities/revert/constants.tex @@ -0,0 +1,14 @@ +The re-ordering arguments involving dominant and subordinate stamps (i.e. $\domStamp$ and $\subStamp$) rely on some constants which we define here: +\begin{itemize} + \item $\hubLambda = 64$ + \item $\revertEpsilon = 15$ + \item $\selfdestructEpsilon = 31$ +\end{itemize} +It is important that +$0 \leq \revertEpsilon < \selfdestructEpsilon < \hubLambda$. +Indeed reverting should happen before gas refunds and before enacting any \inst{SELFDESTRUCT}'s. +\begin{itemize} + \item $\emptyKeccakHi = \texttt{0xc5d2460186f7233c927e7db2dcc703c0}$ + \item $\emptyKeccakLo = \texttt{0xe500b653ca82273b7bfad8045d85a470}$ +\end{itemize} +Where $\texttt{KEC}\big(()\big) = \texttt{0x\,c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470}$ is the \texttt{Keccak-256} hash of the empty byte array. diff --git a/hub/generalities/revert/dom_and_sub.tex b/hub/generalities/revert/dom_and_sub.tex new file mode 100644 index 0000000..0e808ec --- /dev/null +++ b/hub/generalities/revert/dom_and_sub.tex @@ -0,0 +1,137 @@ +We collect certain collections of constraints which may apply to the $(\domStamp, \subStamp)$ pair at certain times. Let \col{c} some value, in practice a small constant (e.g. $1, 2, 3, 4, \dots$) and let $\col{revst}$ represent an arbitrary ($\llarge$-byte integer) ``revert stamp.'' +\[ + % TODO update the macros ! + \left\{ \begin{array}{l} + \zeroDomSubStamps {i}{\relof} + \vspace{2mm} \\ \qquad \qquad \iff + \left\{\begin{array}{lcl} + \domStamp_{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \subStamp_{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \end{array}\right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \standardDomSubStamps { + anchorRow = i, + relOffset = \relof, + domOffset = \col{d}, + } + \vspace{2mm} \\ \qquad \qquad \iff + \left\{\begin{array}{lcl} + \domStamp_{i + \relof} & \!\!\! = \!\!\! & \hubLambda \cdot \hubStamp_{i} + \col{d} \\ + \subStamp_{i + \relof} & \!\!\! = \!\!\! & 0 \\ + \end{array}\right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \genericUndoingDomSubStamps { + anchorRow = i, + relOffset = \relof, + revertStamp = \rho, + domOffset = \epsilon, + subOffset = \col{s}, + } + % \genericUndoingDomSubStamps {\relof} \big[\rho, \epsilon, \col{s}\big]_{i} + \vspace{2mm} \\ \qquad \qquad \iff + \left\{\begin{array}{lcl} + \domStamp_{i + \relof} & \!\!\! = \!\!\! & \hubLambda \cdot \rho + \epsilon \\ + \subStamp_{i + \relof} & \!\!\! = \!\!\! & \hubLambda \cdot \hubStamp_{i} + \col{s} \\ + \end{array}\right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \revertDomSubStamps { + anchorRow = i, + relOffset = \relof, + subOffset = \col{s}, + } + \vspace{2mm} \\ \qquad \qquad \iff + \genericUndoingDomSubStamps { + anchorRow = i, + relOffset = \relof, + revertStamp = \cnRevStamp_{i}, + domOffset = \revertEpsilon, + subOffset = \col{s}, + } + % \genericUndoingDomSubStamps\big[\cnRevStamp_{i}, \revertEpsilon, \col{s}\big]_{i} + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \revertWithChildFailureDomSubStamps { + anchorRow = i, + relOffset = \relof, + subOffset = \col{s}, + childRevertStamp = \col{revst}, + } + \vspace{2mm} \\ \qquad \qquad \iff + \genericUndoingDomSubStamps { + anchorRow = i, + relOffset = \relof, + revertStamp = \col{revst}, + domOffset = \revertEpsilon, + subOffset = \col{s}, + } + % \genericUndoingDomSubStamps\big[\col{revstp}, \revertEpsilon, \col{s}\big]_{i} + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \selfdestructDomSubStamps {i}{\relof} + \vspace{2mm} \\ \qquad \qquad \iff + \genericUndoingDomSubStamps { + anchorRow = i, + relOffset = \relof, + revertStamp = \txEndStamp _{i}, + domOffset = \selfdestructEpsilon, + subOffset = 0, + } + % \genericUndoingDomSubStamps {\relof} \big[\txEndStamp_{i}, \selfdestructEpsilon, 0 \big]_{i} \\ + \end{array} \right. +\] +Some form of +\[ + \standardDomSubStamps { + anchorRow = i, + relOffset = \relof, + domOffset = \col{d}, + } +\] +applies to all rows in need of the $\domStamp$ and $\subStamp$. +\[ +\revertDomSubStamps { + anchorRow = i, + relOffset = \relof, + subOffset = \col{s}, + } +\] +(typically) allows us to schedule the undoing of certain modifications for execution at a later point. +The $\selfdestructDomSubStamps{i}{\relof}$ follows the same principle; it's only use case is for scheduling a \inst{SELFDESTRUCT}. \saNote{} Given that the \zkEvm{} uses the $(+,-)$ lexicographic ordering of the pair $\big[\domStamp, \subStamp\big]$\footnote{whereby $[\col{d}, \col{s}] \prec [\col{d'}, \col{s'}] \iff \col{d} < \col{d'}$ or $\col{d} = \col{d'}$ and \col{s} > \col{s'}} it follows that (for a given \hubStamp) +\begin{itemize} + \item the larger \col{d}, the \textbf{later} the command labeled with the $(\domStamp, \subStamp)$ time stamp + \[ + \standardDomSubStamps { + anchorRow = i, + relOffset = \relof, + domOffset = \col{d}, + } + \] + is carried out; + \item the larger \col{s}, the \textbf{earlier} the command labeled with the $(\domStamp, \subStamp)$ time stamp + \[ + \revertDomSubStamps { + anchorRow = i, + relOffset = \relof, + subOffset = \col{s}, + } + \] + is carried out; +\end{itemize} diff --git a/hub/generalities/revert/gets_reverted.tex b/hub/generalities/revert/gets_reverted.tex new file mode 100644 index 0000000..1c77688 --- /dev/null +++ b/hub/generalities/revert/gets_reverted.tex @@ -0,0 +1,24 @@ + +Indeed within execution execution-rows $\cn\new$ is set to the $1 + \hubStamp$ precisely when entering a new execution context spawned through a \inst{CALL} or \inst{CREATE} type instruction. +The following constraint takes place at the interface between the parent context and the child context's first row. +\begin{enumerate} + \item \If \big($\txInit_{i - 1} = 1$ \et $\txExec_{i} = 1$\big) \Then $\cnGetsRev_{i} = 0$; +\end{enumerate} +I.e. \locRootContext{}'s fictitious parent context, \locBedrockContext{}, doesn't impose a rollback. +The following constraint takes place within the execution phase of a transaction when transitioning to a child context. +\begin{enumerate}[resume] + \item \If + \[ + \left\{ \begin{array}{lcl} + \hubStamp _{i - 1} & \!\!\! \neq \!\!\! & \hubStamp_{i} \\ + \txExec _{i - 1} & \!\!\! = \!\!\! & 1 \\ + \txExec _{i} & \!\!\! = \!\!\! & 1 \\ + \cn\new _{i - 1} & \!\!\! = \!\!\! & 1 + \hubStamp_{i - 1} \\ + \end{array} \right. + \] + \Then + \begin{enumerate} + \item $\cnGetsRev_{i} = \cnWillRev_{i - 1}$ + \item \If $\cnSelfRev_{i} = 0$ \Then $\cnRevStamp_{i} = \cnRevStamp_{i - 1}$ + \end{enumerate} +\end{enumerate} diff --git a/hub/generalities/revert/intro.tex b/hub/generalities/revert/intro.tex new file mode 100644 index 0000000..3264bc5 --- /dev/null +++ b/hub/generalities/revert/intro.tex @@ -0,0 +1,57 @@ +The purpose of (the context-constant columns) +\begin{multicols}{4} + \begin{enumerate} + \item \cnGetsRev{} + \item \cnSelfRev{} + \item \cnWillRev{} + \item \cnRevStamp{} + \end{enumerate} +\end{multicols} +\noindent +is to record several facts about the potential roll backs of execution contexts. +The present section explains the logic governing these columns. +The purpose of (the binary flag) \cnWillRev{} is to record whether an execution context reverts --- whatever the reason. +The purpose of (the binary flag) \cnSelfRev{} is to record whether an execution context reverts for ``self-inflicted'' reasons. +The purpose of (the binary flag) \cnGetsRev{} is to record whether an execution context gets reverted by virtue of its parent context reverting. +Finally, the purpose of \cnRevStamp{} is to record the time stamp (i.e. the \hubStamp{}) at which the revert happens (with the convention that it is set to $0$ if the context doesn't revert.) + +To simplify the discussion we introduce a fictitious \textbf{bedrock context} \locBedrockContext{} which will serve as the parent context of the \textbf{root context} \locRootContext{} of the transaction. +We impose, for that context +\[ + \left\{ \begin{array}{lcl} + \cnGetsRev (\locBedrockContext) & \longleftarrow & \locFalse \\ + \cnSelfRev (\locBedrockContext) & \longleftarrow & \locFalse \\ + \cnWillRev (\locBedrockContext) & \longleftarrow & \locFalse \\ + \cnRevStamp (\locBedrockContext) & \longleftarrow & 0 \\ + \end{array} \right. +\] +Now consider an arbitrary execution context \locCurrentContext{} spawned during transaction processing (starting with the root context \locRootContext) with parent context \locParentContext{}. +We impose that +\[ + \cnGetsRev(\locCurrentContext) \longleftarrow \cnWillRev(\locParentContext) +\] +If at $\hubStamp = \locRevertStamp$ the execution context \locCurrentContext{} raises an exception or executes the \inst{REVERT} opcode we set +\[ + \left\{ \begin{array}{lcl} + \cnSelfRev (\locCurrentContext) & \longleftarrow & \locTrue \\ + \cnRevStamp (\locCurrentContext) & \longleftarrow & \locRevertStamp \\ + \end{array} \right. +\] +otherwise (i.e. if during the lifetime of the execution context \locCurrentContext{} no exception is raised and no \inst{REVERT} opcode is executed) we set +\[ + \left\{ \begin{array}{lcl} + \cnSelfRev (\locCurrentContext) & \longleftarrow & \locFalse \\ + \cnRevStamp (\locCurrentContext) & \longleftarrow & \cnRevStamp(\locParentContext) \\ + \end{array} \right. +\] +Furthermore an execution context \locCurrentContext{} reverts \emph{iff} its parent reverts or it self-reverts, therefore +\[ + \cnWillRev(\locCurrentContext) \longleftarrow \cnGetsRev(\locCurrentContext) \vee \cnSelfRev(\locCurrentContext) +\] +The following sections implement the above in terms of constraints. + +\saNote{} +An important feature of these columns is that they are ``execution-environment constant'', see section~(\ref{hub: consistencies: environment}). +This means that it is sufficient to set their values \textbf{once per execution context}. +This ``one time setting'' must happen at very specific points in time. +We describe the process in the upcoming sections. diff --git a/hub/generalities/revert/self_revert.tex b/hub/generalities/revert/self_revert.tex new file mode 100644 index 0000000..fe0b21a --- /dev/null +++ b/hub/generalities/revert/self_revert.tex @@ -0,0 +1,47 @@ +\begin{center} + \boxed{% + \text{The constraints below are written under assuming that } \peekStack_{i} = 1.} +\end{center} +We define the conditions under which an execution context may raise the \cnSelfRev{} flag. +This can only happen if it encounters an exception and/or executes the \inst{REVERT} opcode. +It is easiest to detect the latter of these conditions along stack-rows (whence the overarching initial assumption.) +Indeed, \textbf{on stack rows} we have +\[ + \stackInst = \inst{REVERT} \iff \stackDecHaltFlag \cdot \decFlag{2} \equiv 1, +\] +see section~\ref{hub: instruction handling: halt: instruction flags}. +Either of these conditions happening is therefore captured by (the conjuction of $\peekStack_{i} = 1$ and) $\xAhoy_{i} + \stackDecHaltFlag_{i} \cdot \decFlag{2}_{i} \neq 0$. + +We introduce the following shorthand +\[ + \locSelfRevertTrigger_{i} + \define + \left[ \begin{array}{cr} + + & \xAhoy_{i} \\ + + & \stackDecHaltFlag_{i} \cdot \decFlag{2}_{i} \\ + - & \xAhoy_{i} \cdot \stackDecHaltFlag_{i} \cdot \decFlag{2}_{i} \\ + \end{array} \right] +\] +\saNote{} \textbf{On stack rows} all terms in sight are binary; the above therefore computes the logical \OR{} of both self-revert conditions; its value is binary. +\begin{enumerate} + \item \If $\locSelfRevertTrigger_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \cnSelfRev_{i} & \!\!\! = \!\!\! & 1 \\ + \cnRevStamp_{i} & \!\!\! = \!\!\! & \hubStamp_{i} \\ + \end{array} \right. + \] + \item \If + \[ + \left\{ \begin{array}{lclr} + \stackDecHaltFlag_{i} & \!\!\! = \!\!\! & 1 \\ + \locSelfRevertTrigger_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right. + \] + \Then $\cnSelfRev_{i} = 0$; +\end{enumerate} +\saNote{} Given that the present row is a stack-row ($\peekStack_{i} = 1$) we have $\stackDecHaltFlag_{i} \cdot \decFlag{2}_{i} \in \{0, 1\}$ with +(\emph{a}) +an exception occurred (and/) or +(\emph{b}) +the the current instruction is a \inst{REVERT}. diff --git a/hub/generalities/revert/will_revert.tex b/hub/generalities/revert/will_revert.tex new file mode 100644 index 0000000..2b4c84e --- /dev/null +++ b/hub/generalities/revert/will_revert.tex @@ -0,0 +1,42 @@ +The purpose of the \cnWillRev{} flag is to record whether or not the current context will revert or not, either because its parent reverts or because it reverts on its own (or possibly both.) +In other words we wish to enforce that +\[ + \Big[\cnWillRev = 1\Big] + \iff + \Big[ \cnGetsRev = 1 \Big] \vee + \Big[ \cnSelfRev = 1 \Big]. +\] +The constraints are as follows: +\begin{enumerate} + \item the following columns are binary + \begin{multicols}{3} + \begin{enumerate} + \item \cnWillRev{} \quad(\trash) + \item \cnGetsRev{} + \item \cnSelfRev{} + \end{enumerate} + \end{multicols} + \item \If $\txExec_{i} = 0$ \Then + \[ + \left[ \begin{array}{cl} + + & \cnGetsRev_{i} \\ + + & \cnSelfRev_{i} \\ + \end{array} \right] + = 0 + \] + \item we unconditionnally impose + \[ + \cnWillRev_{i} = + \left[ \begin{array}{cl} + + & \cnGetsRev_{i} \\ + + & \cnSelfRev_{i} \\ + - & \cnGetsRev_{i} \cdot \cnSelfRev_{i} \\ + \end{array} \right] + \] + \item \If $\cnWillRev_{i} = 0$ \Then $\cnRevStamp_{i} = 0$ +\end{enumerate} +\saNote{} Binaryness of +\cnGetsRev{}, +\cnSelfRev{} and +\cnWillRev{} +entails the desired property for \cnWillRev{}. diff --git a/hub/generalities/stamps/_inputs.tex b/hub/generalities/stamps/_inputs.tex new file mode 100644 index 0000000..9448bd1 --- /dev/null +++ b/hub/generalities/stamps/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{\logStamp{} and \logFlag{} constraints} \label{hub: generalities: stamps: log stamp generalities} \input{generalities/stamps/log} +\subsubsection{\mxpStamp{} and \mxpFlag{} constraints} \label{hub: generalities: stamps: mxp stamp generalities} \input{generalities/stamps/mxp} +\subsubsection{\mmuStamp{} and \mmuFlag{} constraints} \label{hub: generalities: stamps: mmu stamp generalities} \input{generalities/stamps/mmu} diff --git a/hub/generalities/stamps/kec.tex b/hub/generalities/stamps/kec.tex new file mode 100644 index 0000000..af990c8 --- /dev/null +++ b/hub/generalities/stamps/kec.tex @@ -0,0 +1,29 @@ +The only instructions which \emph{may} trigger the \stackHashInfoFlag{} flag are +(\emph{a}) \inst{SHA3} (self explanatory) +(\emph{b}) \inst{CREATE2} (for computing the \inst{KECCAK} hash of the initialization code) +(\emph{c}) \inst{RETURN} (for computing the \inst{KECCAK} hash of a newly deployed bytecode fragment.) + +We provide some details pertaining to the \stackHashInfoFlag{} flag: +\begin{enumerate}[resume] + \item \If $\peekStack_{i} = 1$ \Then + \begin{enumerate} + \item \stackHashInfoFlag{} is binary; + \item \If $\stackHashInfoFlag_{i} = 1$ \Then + \[ + \left[ \begin{array}{r} + + \stackDecKecFlag_{i} \\ + + \stackDecCreateFlag_{i} \cdot \decFlag{2}_{i} \\ + + \stackDecHaltFlag_{i} \cdot \decFlag{1}_{i} \\ + \end{array} \right] + \cdot \big(1 - \xAhoy_{i} \big) + = 1 + \] + \end{enumerate} +\end{enumerate} +\saNote{} +In other words: in order to raise the $\stackHashInfoFlag$ it is \textbf{necessary (though not sufficient)} that the instruction be \textbf{unexceptional} and one of \inst{SHA3}, \inst{CREATE2} or \inst{RETURN}. +The \inst{SHA3} case is self explanatory. +The \inst{CREATE2} case corresponds to hashing the initialization code. +The \inst{RETURN} case corresponds to deployments at which point it may be necessary to compute a code hash. +We will provide more details on the triggering of this flag in the relevant sections. +\ob{TODO! make sure it's up to date, too.} diff --git a/hub/generalities/stamps/log.tex b/hub/generalities/stamps/log.tex new file mode 100644 index 0000000..d794a29 --- /dev/null +++ b/hub/generalities/stamps/log.tex @@ -0,0 +1,24 @@ +The present section constrains the \logStamp{} and partially constrains the \stackLogFlag{} column; +We shall impose the following constraints: +\begin{enumerate} + \item $\logStamp_{0} = 0$ + \item $\logStamp_{i} \in \{ \logStamp_{i - 1}, 1 + \logStamp_{i - 1} \}$ (\trash) + \item \logStamp{} is \hubStamp{}-constant + \item \If $\hubStamp_{i} \neq \hubStamp_{i - 1}$ \Then $\logStamp_{i} = \logStamp_{i - 1} + \peekStack_{i} \cdot \stackLogFlag_{i}$ +\end{enumerate} +In other words the $\logStamp$ may only change from its previous value when the \hubStamp{} changes and then only if the current row is a stack-row raising the \stackLogFlag{} flag. + +We now provide some details pertaining to that flag: +\begin{enumerate}[resume] + \item \If $\peekStack_{i} = 1$ \Then + \begin{enumerate} + \item \stackLogFlag{} is binary (\trash) + \item \If $\xAhoy_{i} = 1$ \Then $\stackLogFlag_{i} = 0$ \quad (\trash) + \item \If $\cnWillRev_{i} = 1$ \Then $\stackLogFlag_{i} = 0$ \quad (\trash) + \item \If $\stackDecLogFlag_{i} = 0$ \Then $\stackLogFlag_{i} = 0$ \quad (\trash) + \item we impose $\stackLogFlag_{i} = \stackDecLogFlag_{i} \cdot \Big( 1 - \cnWillRev_{i} \Big)$ + \end{enumerate} +\end{enumerate} +\saNote{} +In other words: a \inst{LOG}-type instruction only ``counts'' if it isn't undone at a later point by a rollback. +Furthermore \textbf{all such logging operations count} (though not all need be processed by \texttt{ram}. diff --git a/hub/generalities/stamps/mmu.tex b/hub/generalities/stamps/mmu.tex new file mode 100644 index 0000000..9e3b5f3 --- /dev/null +++ b/hub/generalities/stamps/mmu.tex @@ -0,0 +1,7 @@ +The \mmuStamp{} keeps a running tally of all the times some memory instruction is to be carried out and requires a call to the \mmuMod{} module. The present section lays down some general constraints for the \mmuStamp{}. +\begin{enumerate} + \item $\mmuStamp_{0} = 0$; + \item $\mmuStamp_{i + 1} \in \{ \mmuStamp_{i}, 1 + \mmuStamp_{i} \}$ (\trash) + \item $\mmuStamp_{i} = \mmuStamp_{i - 1} + \peekMisc_{i} \cdot \miscMmuFlag_{i}$ +\end{enumerate} +% In other words, the only time the \mmuStamp{} changes is when dealing with an instruction that isn't squashed by a \suxSH{} or \soxSH{}. The precise conditions which lead to an increment in $\mmuStamp$ will be dealt with in a case by case fashion in section~\ref{hub: classifiers}. diff --git a/hub/generalities/stamps/mxp.tex b/hub/generalities/stamps/mxp.tex new file mode 100644 index 0000000..4d7d668 --- /dev/null +++ b/hub/generalities/stamps/mxp.tex @@ -0,0 +1,7 @@ +The \mxpSTAMP{} (abbreviated to \mxpStamp{}) keeps a running tally of all the times a (potentially) memory expanding instruction was carried out and required a call to the \mxpMod{} module. The present section lays down some general constraints for the \mxpStamp{}. We mostly specify when \emph{not} to increment it. +\begin{enumerate} + \item $\mxpStamp_{0} = 0$; + \item $\mxpStamp_{i + 1} \in \{ \mxpStamp_{i}, 1 + \mxpStamp_{i} \}$ (\trash) + \item $\mxpStamp_{i} = \mxpStamp_{i - 1} + \peekMisc_{i} \cdot \miscMxpFlag_{i}$ +\end{enumerate} +In other words, the only time the \mxpStamp{} \emph{may} change is when dealing with a memory expansion inducing instruction that isn't squashed by a \suxSH{} or \soxSH{}. The precise conditions which lead to an increment in $\mxpStamp$ will be dealt with in a case by case fashion in section~\ref{hub: classifiers}. diff --git a/hub/generalities/tx_end_stamp.tex b/hub/generalities/tx_end_stamp.tex new file mode 100644 index 0000000..c37beb9 --- /dev/null +++ b/hub/generalities/tx_end_stamp.tex @@ -0,0 +1,5 @@ +We impose the following: +\begin{enumerate} + \item \txEndStamp{} is \textbf{transaction-constant}, see section~(\ref{hub: heartbeat: constancy conditions}) + \item \If $\txExec_{i} = 1$ \et $\txFinl_{i + 1} = 1$ \Then $\txEndStamp_{i} = 1 + \hubStamp_{i}$ +\end{enumerate} diff --git a/hub/heartbeat/_inputs.tex b/hub/heartbeat/_inputs.tex new file mode 100644 index 0000000..6ff33fd --- /dev/null +++ b/hub/heartbeat/_inputs.tex @@ -0,0 +1,11 @@ +\section{Heartbeat \lispDone{}} +\subsection{Introduction} \label{hub: heartbeat: intro} \input{heartbeat/intro} +\subsubsection{Transaction which don't require \evm{} execution} \label{hub: heartbeat: transactions that don't require EVM execution} \input{heartbeat/execution_not_required} +\subsubsection{Transaction which do require \evm{} execution} \label{hub: heartbeat: transactions requiring EVM execution} \input{heartbeat/execution_required} +\subsection{Constancy conditions \lispDone{}} \label{hub: heartbeat: constancy conditions} \input{heartbeat/constancies} +\subsection{Constraints for \absTxNum{} and \batchNum{} \lispDone{}} \label{hub: heartbeat: absTxNum and batchNum} \input{heartbeat/batch_num_and_tx_num} +\subsection{Constraints for transaction phase flags \lispDone{}} \label{hub: heartbeat: transaction phase boolean flags} \input{heartbeat/phase_flags} +\subsection{Constraints for peeking flags \lispDone{}} \label{hub: heartbeat: peeking flags} \input{heartbeat/peeking_flags} +\subsection{Constraints for the \hubStamp{} \lispDone{}} \label{hub: heartbeat: hub stamp} \input{heartbeat/hub_stamp} +\subsection{Constraints for the final row \lispDone{}} \label{hub: heartbeat: final row} \input{heartbeat/end} + diff --git a/hub/heartbeat/batch_num_and_tx_num.tex b/hub/heartbeat/batch_num_and_tx_num.tex new file mode 100644 index 0000000..6690993 --- /dev/null +++ b/hub/heartbeat/batch_num_and_tx_num.tex @@ -0,0 +1,44 @@ +When transactions arrive for processing in the \textbf{transaction data module} \txnDataMod{}, see chapter~(\ref{chap: txn data}), they are uniquely identified by a pair of \emph{nonzero} integers +\[ + [\col{b}, \col{t}] \equiv \big[\batchNum, \txNum\big]. +\] +The order of transaction processing in the \txnDataMod{} module (and in the \hubMod{} module) is that induced by the standard \textbf{lexicographic order} $\prec_\text{lex.}$ on $\mathbb{N}^2$ whereby +\[ + [\col{b}, \col{t}] \prec_\text{lex.} [\col{b}', \col{t}'] \iff + \left\{ \begin{array}{l} + \col{b} < \col{b'} \\ + \quad \OR \\ + \col{b} = \col{b'} \et \col{t} < \col{t'} \\ + \end{array} \right. +\] +In other words the \txnDataMod{} module (as well as the \hubMod{} module) processes the transaction $T$ before processing $T'$ \emph{if and only if} +$[\col{b}, \col{t}] \prec_\text{lex.} [\col{b}', \col{t}']$, where $[\col{b}, \col{t}]$ and $[\col{b}, \col{t}]$ identify $T$ and $T'$ respectively. +To simplify transaction ordering the \txnDataMod{} module produces the so-called \textbf{absolute transaction number}. +This is a positive integer $\absTxNum \equiv \col{a}$ which uniquely identifies transactions. +It is defined to be compatible with transaction ordering in the sense that +if $[\col{b}, \col{t}]$ corresponds to $\col{a}$ and +if $[\col{b'}, \col{t'}]$ corresponds to $\col{a'}$ then +\[ + [\col{b}, \col{t}] \prec_\text{lex.} [\col{b}', \col{t}'] \iff \col{a} < \col{a'}. +\] +It furthermore counts from $1$ to the total number of transactions to be proven (with $0$ on padding rows.) + +The \hubMod{} module uses the \absTxNum{} to identify transactions. +In order to ensure that transactions are processed in the correct order the \hubMod{} module simply enforces \textbf{monotony} on the \absTxNum{} column with ``small, predictable jumps'': +\begin{enumerate} + \item $\absTxNum_{0} = 0$ + \item $\absTxNum_{i + 1} \in \{ \absTxNum_{i}, 1 + \absTxNum_{i} \}$ \quad (\trash) +\end{enumerate} +\saNote{} We will provide a full characterization of the increments of the \absTxNum{} column later, see constraint~(\ref{hub: heartbeat: abs tx num increments}). + +Rows $i$ with $\absTxNum_{i} = 0$ are \textbf{padding rows}. Rows $i$ with $\absTxNum_{i} \neq 0$ are \textbf{non-padding rows} and pertain to transaction execution. + +Some instructions require knowledge of the batch number (all instructions which raise the \btcFlag{}, e.g. \inst{TIMESTAMP}, \inst{COINBASE}, \dots{}) The hub has no way to reconstruct the batch number $\batchNum$ \emph{on its own}; rather, the $\batchNum$ is imported (using $\absTxNum$ for reference) and set at the start of every new transaction. To ensure its validity throughout the transaction we impose that +\begin{enumerate}[resume] + \item $\batchNum$ be transaction-constant; +\end{enumerate} +Note that as $\absTxNum$ grows monotonically so does $\batchNum$ \emph{in the transaction data module.} Since the hub imports it in the same order as it appears in the transaction data module this column inherits the following properties (that don't need to be enforced through extra constraints, whence why we preface them with (\trash)) +\begin{enumerate}[resume] + \item $\batchNum_{0} = 0$ \quad (\trash) + \item $\batchNum_{i + 1} \in \{ \batchNum_{i}, 1 + \batchNum_{i} \}$ \quad (\trash) +\end{enumerate} diff --git a/hub/heartbeat/constancies.tex b/hub/heartbeat/constancies.tex new file mode 100644 index 0000000..da197d9 --- /dev/null +++ b/hub/heartbeat/constancies.tex @@ -0,0 +1,81 @@ +In this section we define certain constancy conditions. We say that a column $\col{X}$ +\begin{description} + \item[\textbf{batch-constant}] if it satisfies + \[ + \If + \batchNum_{i} \neq 1 + \batchNum_{i - 1} + ~\Then + \col{X}_{i} = \col{X}_{i - 1} + \] + \item[\textbf{transaction-constant}] if it satisfies + \[ + \If + \absTxNum_{i} \neq 1 + \absTxNum_{i - 1} + ~\Then + \col{X}_{i} = \col{X}_{i - 1} + \] + \item[\textbf{stamp-constant}] if it satisfies + \[ + \If + \hubStamp_{i} \neq 1 + \hubStamp_{i - 1} + ~\Then + \col{X}_{i} = \col{X}_{i - 1} + \] + \item[\textbf{stack-row-constant}] if it satisfies + \[ + \If + \left\{ \begin{array}{lcl} + \peekStack_{i} & \!\!\! = \!\!\! & 1 \\ + \ct_{i} & \!\!\! = \!\!\! & 1 \\ + \end{array} \right\} + ~\Then + \col{X}_{i} = \col{X}_{i - 1} + \] + \saNote{} Stack-rows always occupy the first one or two rows of the processing of any instruction, as such $\peekStack_{i} = 1$ really means $\peekStack_{i} = \peekStack_{i - 1} = 1$. + \item[\textbf{context-constant}] if it satisfies + \[ + \If + \cn_{i} = \cn_{i - 1} + ~\Then + \col{X}_{i} = \col{X}_{i - 1} + \] + \ob{TODO: context-constanct should be defined after re-ordering \dots{} Not sure this is the right notion.} +\end{description} + +Given the monotony constraints imposed on \absTxNum{} and \batchNum{} in section~\ref{hub: heartbeat: absTxNum and batchNum} and on \hubStamp{} in section~\ref{hub: heartbeat: hub stamp}, these constancy conditions are equivalent to +\If $\col{NUM}_{i} = \col{NUM}_{i - 1}$ \Then $\col{X}_{i} = \col{X}_{i - 1}$ where +$\col{NUM} = \batchNum, \absTxNum, \hubStamp$ respectively. + +\noindent \ob{TODO: is there \emph{any} batch-constant column other than $\batchNum$ itself?} + +\noindent \ob{TODO: find all transaction-constant columns} + +\noindent \ob{TODO: find all stamp-constant columns} + +\noindent We impose transaction-constancy conditions on the following columns: +\begin{multicols}{2} +\begin{itemize} + \item \batchNum{} + \item[\vspace{\fill}] +\end{itemize} +\end{multicols} + +\noindent We impose stamp-constancy condition on the following columns: +\begin{multicols}{4} +\begin{itemize} + \item $\cn$ + \item $\cn\new$ + \item $\pc$ + \item $\pc\new$ + \item $\gasExpected$ + \item $\gasActual$ + \item $\gasCost$ + \item $\gasNext$ + \item $\tli$ + \item $\nonStackRows$ + \item $\cmc$ + \item $\xAhoy$ + \item[\vspace{\fill}] + %\item[\vspace{\fill}] +\end{itemize} +\end{multicols} diff --git a/hub/heartbeat/end.tex b/hub/heartbeat/end.tex new file mode 100644 index 0000000..ab2039d --- /dev/null +++ b/hub/heartbeat/end.tex @@ -0,0 +1,9 @@ +There is a single finalization constraint: +\begin{enumerate} + \item \If $\absTxNum_{N} \neq 0$ \Then $\txSkip_{N} + \txFinl_{N} + \peekTransaction_{N} = 2$ +\end{enumerate} +\saNote{} Given that on every row \emph{at most one} of +$\txSkip$ and $\txFinl$ may be on this equality is a compressed way of stating that +\[ + \Big( \txSkip_{N} = 1 ~\OR \txFinl_{N} = 1 \Big) ~ \et \peekTransaction_{N} = 1. +\] diff --git a/hub/heartbeat/execution_not_required.tex b/hub/heartbeat/execution_not_required.tex new file mode 100644 index 0000000..7f1e72c --- /dev/null +++ b/hub/heartbeat/execution_not_required.tex @@ -0,0 +1,16 @@ +Transaction processing doesn't require \evm{}-execution precisely when: +\begin{itemize} + \item the transaction is a \textbf{message call} and the recipient account has \textbf{empty code} + \item the transaction is a \textbf{contract deployment} with \textbf{empty initialization code}; +\end{itemize} +In other words whenever $\txIsDeployment = 0$ (i.e. $T_\text{t} \neq \varnothing$) and $\sigma[\txTo]_c = \emptyKeccak$ or $\txIsDeployment = 1$ (i.e. $T_\text{t} = \varnothing$) and $\txDataSize = 0$. When $\txSkip$ is set transaction processing requires five rows in the hub trace: four rows to perform account changes (transfer value and gas cost deduction from sender balance, adding transfer value to recipient, reimbursing left over gas to the sender, paying the coinbase address in gas fees) and one row containing transaction data (e.g. various gas prices or transfer values.) + +\saNote{} The present version of the \zkEvm{} forbids transactions which are message calls to a precompile. + +\saNote{} There is a similar distinction for \inst{CALL}-type and \inst{CREATE}-type instructions. +Indeed we distinguish between +\inst{CALL}'s to addresses that have nonempty byte code and +\inst{CALL}'s to addresses with empty bytecode (and among those we further distinguish between \inst{CALL}'s to \textsc{eoa}'s in a transaction that actually requires \textsc{evm}-execution.) +Similarly we distinguish between +\inst{CREATE}'s which are provided with empty initialization code and +\inst{CREATE}'s i.e. those that are provided with nonempty initialization code i.e. the nontrivial ones. diff --git a/hub/heartbeat/execution_required.tex b/hub/heartbeat/execution_required.tex new file mode 100644 index 0000000..d3df053 --- /dev/null +++ b/hub/heartbeat/execution_required.tex @@ -0,0 +1,129 @@ +We explain the remaing cases i.e. those cases where \evm{} execution is required. These are: +\begin{itemize} + \item the transaction is a \textbf{message call} and the recipient account has \textbf{nonempty code}; + \item the transaction is a \textbf{contract deployment} with \textbf{nonempty initialization code}; +\end{itemize} +Transaction processing goes through four distinct \textbf{processing phases}. +The first of these phases (and only optional phase) is the \textbf{prewarming phase}. +It is characterized by $\txWarm \equiv 1$. +In that phase all \emph{addresses} to be prewarmed as well as all \emph{storage keys} to be prewarmed (as declared in the transaction) are loaded into the \hubMod{} and their warmth is switched on. +There are thus as many rows in the prewarming phase as there are addresses to prewarm \emph{plus} storage keys to prewarm. +Every row of the prewarming phase peeks either +into the state (i.e. $\peekAccount \equiv 1$) if it is prewarming an address or +into storage (i.e. $\peekStorage \equiv 1$) if it is prewarming a storage key. +If there are no addresses (and thus no storage keys) to prewarm this phase is skipped (i.e. it occupies zero rows and $\txWarm \equiv 0$ throughout the transaction.) +The arithmetization ensures sure that \textit{all addresses and storage keys} to prewarm are indeed prewarmed and no others can be prewarmed. +\ob{TODO: connect to the relevant module linking section.} + +The second phase is the \textbf{initialization phase}. +It is characterized by $\txInit \equiv 1$ and occupies $\nsrTransactionInitializationPhase$ rows. +The first two rows peek into accounts (i.e. $\peekAccount \equiv 1$) +and the third row peeks into transaction data (i.e. $\peekTransaction \equiv 1$.) +% +The first row peeks into the \texttt{from} address. +It reduces the balance by the value field of the transaction ($T_\textbf{v}$ i.e. $\txValue$), +pays for the gas limit ($T_\textbf{g}$ i.e. $\txGasLimit$) at the effective gas price ($\txGasPrice$), +compares the nonce $\accNonce$ to that provided in the transaction ($T_\textbf{n}$ i.e. $\txNonce$) and increased by 1; +it also switches on the account's warmth. +Paying for gas and value requires sufficient balance and we thus raise $\debit \equiv 1$ with $\balx \equiv 0$. +The second row peeks into the \texttt{to} address. +It raises its balance by $T_\textbf{v}$, +raises its nonce from $0$ to $1$ in case of a deployment transaction +and switches on the recipient account's warmth. + +The third phase is the \textbf{execution phase}. +It is characterized by $\txExec \equiv 1$. This is the phase where instructions are read from bytecode and executed upon. Besides updating the stack and calling on other modules, dealing with certain instructions may at times require us to either +peek either into the stack (i.e. have rows with $\peekStack \equiv 1$), +peek either into the state (i.e. have rows with $\peekAccount \equiv 1$) or +peek either into the transaction (i.e. have rows with $\peekTransaction \equiv 1$.) +Within the execution phase there can be a myriad of view changes. For instance carrying out an \inst{(EXT)CODEHASH} requires peeking into account data, carrying out a \inst{COINBASE} instruction requires us peeking into batch data, carrying out a \inst{GASPRICE} instruction requires us peeking into transaction data. Also every instruction dealt with peeks into the stack. This peeking can take up one or two rows in the trace (depending on whether $\tli \equiv 0$ or $\tli \equiv 1$.) + +The fourth and final phase is the \textbf{finalization phase}. +It is characterized by $\txFinl \equiv 1$. This is the time when the \zkEvm{} ties up loose ends in transaction processing: returning left over gas (+ gas refunds up to the limit specified by the Ethereum Yellow Paper) to the \texttt{from} address and paying the \texttt{coinbase} address; furthermore, in case of a reverting transaction, refunding the initial value transfer. As such, this phase occupies 3 or 5 rows depending on whether the transaction reverts (5 rows) or not (3 rows.) In either case, the first two rows are account rows (i.e. $\peekAccount \equiv 1$) and perform the refunds / payments mentioned above. The first row \emph{always} peeks into the \texttt{from} address' account and proceeds to refund the remaining gas\footnote{The value in Wei to to be refunded is a function of +(\emph{a}) the gas limit, +(\emph{b}) the left over gas, +(\emph{c}) the refund counter and +(\emph{d}) the effective gas price. +That information is computed in the \txnDataMod{} module. It makes its way into the present \hubMod{} by means of the transaction row yet to come.}. Similarly, the second row \emph{always} peeks into the \texttt{coinbase} address' account and pays it in consumed gas at the effective gas price of the transaction. In case of a transaction which isn't reverted (i.e. which returns status code $\Upsilon^{z}(\bm{\sigma}, T) \equiv 1$) the third and final finalization row is a transaction row (i.e. $\peekAccount \equiv 1$.) If the transaction reverts (i.e. if $\Upsilon^{z}(\bm{\sigma}, T) \equiv 0$) there are two additional account rows: the third and fourth rows are again account rows. They respectively peek into the \texttt{from} and \texttt{to} accounts. The purpose of these rows is to undo the initial value transfer that happened during the initialization phase. The fifth (and final) finalization row peeks into the transaction (i.e. $\peekTransaction \equiv 1$.) + +We refer the reader to section~(\ref{hub: finalization phase}) for more details. + +The conditions imposed on +$\absTxNum$, +$\txSkip$, +$\txWarm$, +$\txInit$, +$\txExec$, and +$\txFinl$ +impose that each set of row indices $i$ where $\absTxNum$ takes on a particular value $\col{t}_{0}$ is an integer interval and that the four phase bits evolve as in figure~\ref{fig: typical progression of the [b,t] pair}. + +\begin{figure} +\centering +\[ +\renewcommand{\arraystretch}{1.5} +\def\greenOne{{\cellcolor{solarized-green}\bm{1}}} +\def\yellowOne{{\cellcolor{solarized-yellow}\bm{1}}} +\def\orangeOne{{\cellcolor{solarized-orange}\bm{1}}} +\def\greenDots{{\cellcolor{solarized-green}\bm{\vdots}}} +\def\yellowDots{{\cellcolor{solarized-yellow}\bm{\vdots}}} +\def\orangeDots{{\cellcolor{solarized-orange}\bm{\vdots}}} +\def\greenQuestionmark{{\cellcolor{solarized-green}?}} +\begin{array}{|c||c|c|c|c|} \hline + \absTxNum & ~ \col{tw} ~ & ~ \col{ti} ~ & ~ \col{te} ~ & ~ \col{tf} ~ \\ \hline\hline + \vdots & \vdots & \vdots & \vdots & \vdots \\ + \col{t} - 1 & 0 & 0 & 0 & \orangeOne \\ \hline\hline + \col{t} & \greenOne & 0 & 0 & 0 \\ + \col{t} & \greenOne & 0 & 0 & 0 \\ + \col{t} & \greenDots & 0 & 0 & 0 \\ + \col{t} & \greenOne & 0 & 0 & 0 \\ \hline + \col{t} & 0 & \greenOne & 0 & 0 \\ + \col{t} & 0 & \greenOne & 0 & 0 \\ + \col{t} & 0 & \greenDots & 0 & 0 \\ + \col{t} & 0 & \greenOne & 0 & 0 \\ \hline + \col{t} & 0 & 0 & \yellowOne & 0 \\ + \col{t} & 0 & 0 & \yellowOne & 0 \\ + \col{t} & 0 & 0 & \yellowDots & 0 \\ + \col{t} & 0 & 0 & \yellowOne & 0 \\ \hline + \col{t} & 0 & 0 & 0 & \orangeOne \\ + \col{t} & 0 & 0 & 0 & \orangeOne \\ + \col{t} & 0 & 0 & 0 & \orangeDots \\ + \col{t} & 0 & 0 & 0 & \orangeOne \\ \hline\hline + \col{t} + 1 & \greenQuestionmark & \greenQuestionmark & 0 & 0 \\ + \vdots & \vdots & \vdots & \vdots & \vdots \\ +\end{array} +\qquad +\qquad +\begin{array}{|c||c|c|c|c|} \hline + \absTxNum & ~ \col{tw} ~ & ~ \col{ti} ~ & ~ \col{te} ~ & ~ \col{tf} ~ \\ \hline\hline + \vdots & \vdots & \vdots & \vdots & \vdots \\ + \col{t} - 1 & 0 & 0 & 0 & \orangeOne \\ \hline\hline + \col{t} & 0 & \greenOne & 0 & 0 \\ + \col{t} & 0 & \greenOne & 0 & 0 \\ + \col{t} & 0 & \greenDots & 0 & 0 \\ + \col{t} & 0 & \greenOne & 0 & 0 \\ \hline + \col{t} & 0 & 0 & \yellowOne & 0 \\ + \col{t} & 0 & 0 & \yellowOne & 0 \\ + \col{t} & 0 & 0 & \yellowDots & 0 \\ + \col{t} & 0 & 0 & \yellowOne & 0 \\ \hline + \col{t} & 0 & 0 & 0 & \orangeOne \\ + \col{t} & 0 & 0 & 0 & \orangeOne \\ + \col{t} & 0 & 0 & 0 & \orangeDots \\ + \col{t} & 0 & 0 & 0 & \orangeOne \\ \hline\hline + \col{t} + 1 & \greenQuestionmark & \greenQuestionmark & 0 & 0 \\ + \vdots & \vdots & \vdots & \vdots & \vdots \\ +\end{array} +\] +\label{fig: typical progression of the [b,t] pair} +\caption{The numbers of rows occupied by a \emph{nonzero} absolute transaction number $\col{t}$ appears is always $\geq 3$ according to constraints on the +$\txWarm$, +$\txInit$, +$\txExec$ and +$\txFinl$ (which we have abbreviated to +\col{tw}, +\col{ti}, +\col{te} and +\col{tf} respectively for succinctness.) \\ +The table on the left represents the transaction phase cycle of a transaction that contains some addresses to prewarm. The table on the left represents the transaction phase cycle of a transaction that contains none. +} +\end{figure} + diff --git a/hub/heartbeat/hub_stamp.tex b/hub/heartbeat/hub_stamp.tex new file mode 100644 index 0000000..02806fd --- /dev/null +++ b/hub/heartbeat/hub_stamp.tex @@ -0,0 +1,147 @@ +\def\st{\col{st}} +\def\ts{\col{ts}} +\def\tw{\col{tw}} +\def\ti{\col{ti}} +\def\te{\col{te}} +\def\tf{\col{tf}} +%%%%%%%%%%%%%%%%% +The present section constrains the hub stamp column $\hubStamp$. +The main expectations we place upon the hub stamp are as follows: +(\emph{a}) every time a new transaction starts processing $\hubStamp$ should jump by $1$; +(\emph{b}) every time there is a change in processing phase $\hubStamp$ should jump by $1$; +(\emph{c}) the $\hubStamp$ should remain constant during the processing of a transaction which requires no \textsc{evm}-execution; +(\emph{d}) the $\hubStamp$ should remain constant during the initialization and finalization phases; +(\emph{e}) the $\hubStamp$ should jump by $1$ with every row in the prewarming phase; +(\emph{f}) during the execution phase $\hubStamp$ should jump by $1$ every time an instruction has been dealt with and a new instruction is executed (or transaction processing enters the finalization phase); +(\emph{g}) other than that $\hubStamp$ should remain constant. + +For more concise equations we shall use the following shorthands: +\[ + \left\{ \qquad \begin{array}{rcl} + \ts & \define & \txSkip{} \\ + \tw & \define & \txWarm{} \\ + \ti & \define & \txInit{} \\ + \te & \define & \txExec{} \\ + \tf & \define & \txFinl{} \\ + \end{array} \qquad \right\} +\] +respectively. + +\noindent Here are the constraints for $\hubStamp$ : +\begin{enumerate} + \item \If $\absTxNum_{i} = 0$ \Then $\hubStamp_{i} = 0$; + \item $\hubStamp_{i + 1} \in \{ \hubStamp_{i}, 1 + \hubStamp_{i} \}$ + \item we impose + \[ + \If + \left\{ \begin{array}{rrcl} + + & (1 - \ts_{i}) & \!\!\! \cdot \!\!\! & \ts_{i + 1} \\ + + & (1 - \tw_{i}) & \!\!\! \cdot \!\!\! & \tw_{i + 1} \\ + + & (1 - \ti_{i}) & \!\!\! \cdot \!\!\! & \ti_{i + 1} \\ + + & (1 - \te_{i}) & \!\!\! \cdot \!\!\! & \te_{i + 1} \\ + + & (1 - \tf_{i}) & \!\!\! \cdot \!\!\! & \tf_{i + 1} \\ + + & \tw_{i} & & \\ + \end{array} \right\} + \neq 0 + ~ + \Then \hubStamp_{i + 1} = 1 + \hubStamp_{i}. + \] +\end{enumerate} +\saNote{} In other words $\hubStamp$ jumps by $1$ every time there is a \textbf{noticeable} change in transaction processing phase. +It furthermore increments with every prewarming row. +Note that the term in braces is itself binary so that ``$\neq 0$'' really means ``$=1$''. + +\saNote{} Given constraint~(\ref{hub: heartbeat: acceptable tx phases at first row of new transaction}) the above is triggered in particular the first time $\absTxNum$ turns nonzero and more generally every time a transaction which requires \textsc{evm}-execution ends and processing of the next transaction starts. Note that this condition won't be triggered at the end of the processing of a transaction that requires no \textsc{evm}-execution if the next transaction \emph{also} requires no \textsc{evm}-execution. +We nonetheless want to impose a jump under those circumstances. +The associated jump in $\hubStamp$ is enforced in the constraint below. +\begin{enumerate}[resume] + \item + \[ + \If + \left[ \begin{array}{cccc} + + & \ts_{i} \\ + + & \ti_{i} \\ + + & \tf_{i} \\ + \end{array} \right] + \neq 0 + ~ \Then \hubStamp_{i + 1} = \hubStamp_{i} + \peekTransaction_{i}. + \] +\end{enumerate} +\saNote{} +The above enforces that $\hubStamp$ remains constant throughout the processing of any transaction which requires no \textsc{evm}-execution as well as during the initialization and finalization phases of transactions that require \evm{} execution. The \hubStamp{} furthermore will jump by one (on any one of those phases) whenever the current row peeks into the transaction. +We remind the reader that for these three phases (\txSkip, \txInit{} and \txFinl{}) the $\peekTransaction{}$ flag already played a special role in the previous section, see constraints +(\ref{hub: heartbeat: skipping phase finishes on a transaction row}), +(\ref{hub: heartbeat: initialization phase finishes on a transaction row}) and +(\ref{hub: heartbeat: finalization phase finishes on a transaction row}). +This column also served a special purpose with respect to the \absTxNum, see constraint (\ref{hub: heartbeat: abs tx num increments}). + +The above has as a consequence that +\begin{enumerate}[resume] + \item \If $\absTxNum_{i + 1} \neq \absTxNum_{i}$ \Then $\hubStamp_{i + 1} = 1 + \hubStamp_{i}$; \quad (\trash) +\end{enumerate} +\saNote{} Thus $\hubStamp$ increments every time processing of a new transaction starts. +This follows from the above given constraint (\ref{hub: heartbeat: abs tx num increments}). + +We now deal with the remaining case, that of the execution phase of transaction processing. +\begin{enumerate}[resume] + \item \If $\te_{i} = 1$ \Then + \begin{enumerate} + \item \If $\hubStamp_{i} \neq \hubStamp_{i - 1}$ \Then + \[ + \left\{ \begin{array}{lcl} + \ct_{i} & = & 0 \\ + \nonStackRowsCounter_{i} & = & 0 \\ + \end{array} \right. + \] + \item \If $\nonStackRowsCounter_{i} = 0$ \Then $\peekStack_{i} = 1$ + \item \If $\nonStackRowsCounter_{i} \neq 0$ \Then $\peekStack_{i} = 0$ + \item \If $\ct_{i} \neq \tli_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \hubStamp_{i + 1} & = & \hubStamp_{i} \\ + \ct_{i + 1} & = & 1 + \ct_{i} \\ + \nonStackRowsCounter_{i + 1} & = & 0 \\ + \end{array} \right. + \] + \item \If $\ct_{i} = \tli_{i}$ \Then + \begin{enumerate} + \item \If $\nonStackRowsCounter_{i} \neq \nonStackRows_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \hubStamp_{i + 1} & = & \hubStamp_{i} \\ + \ct_{i + 1} & = & \ct_{i} \\ + \nonStackRowsCounter_{i + 1} & = & 1 + \nonStackRowsCounter_{i} \\ + \end{array} \right. + \] + \item \If $\nonStackRowsCounter_{i} = \nonStackRows_{i}$ \Then $\hubStamp_{i + 1} = 1 + \hubStamp_{i}$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +\saNote{} It follows that every collection of execution-rows ($\txExec \equiv 1$) that share the same \hubStamp{} starts out with either one or two stack-rows ($\peekStack \equiv 1$.) + +Below we represent typical evolutions of the \hubStamp{} during the execution phase: +\begin{figure}[h!] + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|c|c||c|c|c|c||c|} \hline + \te & \hubStamp & \tli & \ct & \nonStackRows & \nonStackRowsCounter & \peekStack \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + 1 & \st - 1 & \vdots & \vdots & \vdots & \vdots & ? \\ \hline \hline + 1 & {\cellcolor{\romCol}\st} & 1 & 0 & 0 & 0 & 1 \\ \hline + 1 & {\cellcolor{\romCol}\st} & 1 & 1 & 0 & 0 & 1 \\ \hline \hline + 1 & {\cellcolor{\stackCol}\st + 1} & 0 & 0 & 3 & 0 & 1 \\ \hline + 1 & {\cellcolor{\stackCol}\st + 1} & 0 & 0 & 3 & 1 & 0 \\ \hline + 1 & {\cellcolor{\stackCol}\st + 1} & 0 & 0 & 3 & 2 & 0 \\ \hline + 1 & {\cellcolor{\stackCol}\st + 1} & 0 & 0 & 3 & 3 & 0 \\ \hline \hline + 1 & {\cellcolor{\logCol}\st + 2} & 0 & 0 & 0 & 0 & 1 \\ \hline \hline + 1 & {\cellcolor{\ramCol}\st + 3} & 1 & 0 & 4 & 0 & 1 \\ \hline + 1 & {\cellcolor{\ramCol}\st + 3} & 1 & 1 & 4 & 0 & 1 \\ \hline + 1 & {\cellcolor{\ramCol}\st + 3} & 1 & 1 & 4 & 1 & 0 \\ \hline + 1 & {\cellcolor{\ramCol}\st + 3} & 1 & 1 & 4 & 2 & 0 \\ \hline + 1 & {\cellcolor{\ramCol}\st + 3} & 1 & 1 & 4 & 3 & 0 \\ \hline + 1 & {\cellcolor{\ramCol}\st + 3} & 1 & 1 & 4 & 4 & 0 \\ \hline \hline + 1 & \st + 4 & \vdots & \vdots & \vdots & \vdots & 1 \\ + \end{array} + \] + \caption{We use the shorthand $\st = \hubStamp$. Recall that according to section~\ref{hub: constancy conditions} the column $\nonStackRows$ is stamp-constant.} +\end{figure} diff --git a/hub/heartbeat/intro.tex b/hub/heartbeat/intro.tex new file mode 100644 index 0000000..0b5f80e --- /dev/null +++ b/hub/heartbeat/intro.tex @@ -0,0 +1,5 @@ +We present the heartbeat of the \hubMod{} module. +We introduce the various processing phases that a transaction goes through and explain the \hubStamp{} which is used to timestamp certain operations in the \hubMod{} module. +We draw the reader's attention to the fact that our arithmetization of the \textsc{evm} makes a \textbf{fundamental distinction} between transactions. +There are those transactions that require code execution (characterized by $\txSkip \equiv 0$) and those that don't (characterized by $\txSkip \equiv 1$.) +Transactions are uniquely identified by an absolute transaction number $\absTxNum$, see section~\ref{hub: heartbeat: absTxNum and batchNum}, which grows linearly from transaction to transaction. diff --git a/hub/heartbeat/peeking_flags.tex b/hub/heartbeat/peeking_flags.tex new file mode 100644 index 0000000..437841c --- /dev/null +++ b/hub/heartbeat/peeking_flags.tex @@ -0,0 +1,48 @@ +\def\locPeekingFlagSum {\col{peeking\_sum}} +In this section we provide basic constraints for the following binary flags +$\peekStack$, +$\peekContext$, +$\peekAccount$, +$\peekStorage$, +$\peekTransaction$ +which specify which data store the present peeks into as well as +$\peekMisc$ which highlights rows that are used to trigger certain lookups and +$\peekScenario$ which is used to simplify the control flow of complex instructions. +\begin{enumerate} + \item + $\peekAccount$, + $\peekContext$, + $\peekMisc$, + $\peekScenario$ + $\peekStack$, + $\peekStorage$ and + $\peekTransaction$ + are binary; +\end{enumerate} +We define the following shorthand: +\[ + \locPeekingFlagSum_{i} + \define + \left[ \begin{array}{cl} + + & \peekAccount _{i} \\ + + & \peekContext _{i} \\ + + & \peekMisc _{i} \\ + + & \peekScenario _{i} \\ + + & \peekStack _{i} \\ + + & \peekStorage _{i} \\ + + & \peekTransaction _{i} \\ + \end{array} \right] +\] +and we impose +\begin{enumerate}[resume] + \item $\locPeekingFlagSum_{i} = \locTransactionPhaseSum_{i}$ +\end{enumerate} +In other words: every non-padding row peeks into precisely one data store. +The precise constraints which apply to these flags depend on the transaction processing phase. + +\saNote{} The above is equivalent to imposing the analogous constraints for \locPeekingFlagSum{} to those imposed on those \locPeekingFlagSum{} in (\ref{hub:heartbeat: tx phase sum constraints}): +\begin{enumerate}[resume] + \item $\locPeekingFlagSum$ is binary \quad (\trash) + \item \If $\absTxNum_{i} = 0$ \Then $\locPeekingFlagSum_{i} = 0$ \quad (\trash) + \item \If $\absTxNum_{i} \neq 0$ \Then $\locPeekingFlagSum_{i} = 1$ \quad (\trash) +\end{enumerate} diff --git a/hub/heartbeat/phase_flags.tex b/hub/heartbeat/phase_flags.tex new file mode 100644 index 0000000..b9fe681 --- /dev/null +++ b/hub/heartbeat/phase_flags.tex @@ -0,0 +1,77 @@ +\def\locTransactionPhaseSum {\col{tx\_phase\_sum}} +\def\locAcceptableTransactionPhaseFlagsAtFirstRowOfNewTransaction {\txSkip_{i} + \txWarm_{i} + \txInit_{i} = 1} +In this section we constrain the binary flags $\txSkip$, $\txWarm$, $\txInit$, $\txExec$, $\txFinl$ which indicate the transaction processing phase. We enforce a phase-rotation i.e. when which bits $\txWarm$, $\txInit$, $\txExec$, $\txFinl$ get turned on and off in non-padding rows. +These phases are expected to transition as shown in figure~\ref{fig: processing phase transition graph}. + +\input{figures/processing_phase_transition_graph} + +\noindent We now list the corresponding constraints: +\begin{enumerate} + \item $\txSkip$, $\txWarm$, $\txInit$, $\txExec$ and $\txFinl$ are binary; +\end{enumerate} +We define the following shorthand: +\[ + \locTransactionPhaseSum_{i} + \define + \left[ \begin{array}{cl} + + & \txSkip_{i} \\ + + & \txWarm_{i} \\ + + & \txInit_{i} \\ + + & \txExec_{i} \\ + + & \txFinl_{i} \\ + \end{array} \right] +\] +\begin{enumerate}[resume] \label{hub:heartbeat: tx phase sum constraints} + \item \If $\absTxNum_{i} = 0$ \Then $\locTransactionPhaseSum_{i} = 0$; + \item\label{hub: heartbeat: tx phase flag exclusivity} + \If $\absTxNum_{i} \neq 0$ \Then $\locTransactionPhaseSum_{i} = 1$; + \item\label{hub: heartbeat: acceptable tx phases at first row of new transaction} + \If $\absTxNum_{i} \neq \absTxNum_{i - 1}$ \Then $\locAcceptableTransactionPhaseFlagsAtFirstRowOfNewTransaction$; +\end{enumerate} +The above says that on padding rows all processing flags are off while on non-padding rows \emph{precisely} one of the processing flags flags is set. Furthermore when a new transaction starts processing it either +requires no \textsc{evm}-execution ($\txSkip_{i} = 1$) +or does and starts in either the pre-warming phase ($\txWarm_{i} = 1$) +or the initialization phase ($\txInit_{i} = 1$.) +Phases follow a cyclical pattern where the order is set (the prewarming phase being optional.) +\begin{enumerate}[resume] + \item\label{hub: heartbeat: abs tx num increments} + \If $\absTxNum_{i} \neq 0$ \Then + \[ \absTxNum_{i + 1} = \absTxNum_{i} + (\txFinl_{i} + \txSkip_{i}) \cdot \peekTransaction_{i} \] +\end{enumerate} +\saNote{} The expression $(\txFinl + \txSkip) \cdot \peekTransaction$ which we use above is \textbf{binary}. + +The above specifies precisely, for non padding rows $i$, when $\absTxNum$ is required to change from row $i$ to row $i + 1$. It remains unchanged in all cases \emph{except} if the transaction requires no \textsc{evm}-execution and the present row peeks into transaction data \emph{or} the transaction requires \textsc{evm}-execution, is in the finalization phase and and the present row peeks into transaction data. In this case the next row thus marks the beginning of the processing of a new transaction. + +We now deal with the cyclical nature of the process. +\paragraph{Transactions whose processing requires no \textsc{evm} execution.} +\begin{enumerate}[resume] + \item + \label{hub: heartbeat: skipping phase finishes on a transaction row} + \If \Big($\txSkip_{i} = 1$ \et $\peekTransaction_{i} = 0$\Big) \Then $\txSkip_{i + 1} = 1$; +\end{enumerate} +\saNote{} The case $\txSkip_{i} = 1$ \et $\peekTransaction_{i} = 1$ is already known: the $\absTxNum$ changes at the following row and so by the above $\locAcceptableTransactionPhaseFlagsAtFirstRowOfNewTransaction$. + +\paragraph{Transactions whose processing \emph{does} require \textsc{evm} execution.} +\begin{enumerate}[resume] + \item \If $\txWarm_{i} = 1$ \Then $\txWarm_{i + 1} + \txInit_{i + 1} = 1$ + \item + \label{hub: heartbeat: initialization phase finishes on a transaction row} + \If $\txInit_{i} = 1$ \Then + \[ + \begin{cases} + \If \peekTransaction_{i} = 0 ~ \Then \txInit_{i + 1} = 1 \\ + \If \peekTransaction_{i} = 1 ~ \Then \txExec_{i + 1} = 1 \\ + \end{cases} + \] + \item \If $\txExec_{i} = 1$ \Then $\txExec_{i + 1} + \txFinl_{i + 1} = 1$ + \item + \label{hub: heartbeat: finalization phase finishes on a transaction row} + \If $\txFinl_{i} = 1$ \Then $\txFinl_{i + 1} = 1 - \peekTransaction_{i}$ +\end{enumerate} +\saNote{} +Just as above we note that the case $\txFinl_{i} = 1$ \et $\peekTransaction_{i} = 1$ was already known. +Indeed, in that case the absolute transaction number must change at the next row due to constraint~(\ref{hub: heartbeat: abs tx num increments}). +It follows from constraint~(\ref{hub: heartbeat: acceptable tx phases at first row of new transaction}) that $\locAcceptableTransactionPhaseFlagsAtFirstRowOfNewTransaction$. +By flag exclusivity~(\ref{hub: heartbeat: tx phase flag exclusivity}) it follows in particular that $\txFinl_{i + 1} = 0$. + +The above enforces the basic cycling behaviour as depicted in figure~\ref{fig: processing phase transition graph}. Prewarming rows (if any) lead to initialization rows which lead to execution rows which lead to finalization rows. Furthermore, the finalization phase may only end on a row that peeks into transaction data. The number of rows of each phase will be specified later. diff --git a/hub/inputs/_require_evm_execution.tex b/hub/inputs/_require_evm_execution.tex new file mode 100644 index 0000000..8f5ba10 --- /dev/null +++ b/hub/inputs/_require_evm_execution.tex @@ -0,0 +1,3 @@ +\section{Transactions which require EVM execution} +\subsection{Introduction} \label{hub: tx w/ evm execution introduction} \input{tx_warm/intro} +\section{Prewarming phase \lispTodo{}} \label{hub: prewarming} \input{tx_warm/_all} diff --git a/hub/inputs/_tx_execution_phase.tex b/hub/inputs/_tx_execution_phase.tex new file mode 100644 index 0000000..40e94df --- /dev/null +++ b/hub/inputs/_tx_execution_phase.tex @@ -0,0 +1,2 @@ +\subsection{Execution phase} \label{subsec: (hub / exec phase) execution} \input{tx_exec/_all} \input{tx_exec/_inputs} +% \subsection{Finalization phase} \label{subsec: (hub / finalization phase) finalization} \input{tx_finl/_all} % that's its own section now ... as it ought to be anyway. diff --git a/hub/instruction_handling/_inputs.tex b/hub/instruction_handling/_inputs.tex new file mode 100644 index 0000000..c9af1d0 --- /dev/null +++ b/hub/instruction_handling/_inputs.tex @@ -0,0 +1,32 @@ +\input{instruction_handling/_local} + +\section{Instruction handling} \label{hub: instruction handling} + +\subsection{Introduction} \label{hub: instruction handling: intro} \input{instruction_handling/intro} +\subsection{Instructions raising \suxSH's or \soxSH's \lispDone{}} \label{hub: instruction handling: sux or sox} \input{instruction_handling/stack_exceptions} +\subsection{Instructions raising the $\stackDecAddFlag$ \lispDone{}} \label{hub: instruction handling: add} \input{instruction_handling/add} +\subsection{Instructions raising the $\stackDecBinFlag$ \lispDone{}} \label{hub: instruction handling: bin} \input{instruction_handling/bin} +\subsection{Instructions raising the $\stackDecExtFlag$ \lispDone{}} \label{hub: instruction handling: ext} \input{instruction_handling/ext} +\subsection{Instructions raising the $\stackDecModFlag$ \lispDone{}} \label{hub: instruction handling: mod} \input{instruction_handling/mod} +\subsection{Instructions raising the $\stackDecMulFlag$ \lispDone{}} \label{hub: instruction handling: mul} \input{instruction_handling/mul} +\subsection{Instructions raising the $\stackDecShfFlag$ \lispDone{}} \label{hub: instruction handling: shf} \input{instruction_handling/shf} +\subsection{Instructions raising the $\stackDecWcpFlag$ \lispDone{}} \label{hub: instruction handling: wcp} \input{instruction_handling/wcp} +\subsection{Constraints for the preceding instruction families \lispDone{}} \label{hub: instruction handling: stateless constraints} \input{instruction_handling/stateless_constraints} +\subsection{Instructions raising the $\stackDecKecFlag$ \lispDone{}} \label{hub: instruction handling: kec} \input{instruction_handling/kec} +\subsection{Instructions raising the $\stackDecConFlag$ \lispDone{}} \label{hub: instruction handling: con} \input{instruction_handling/con} +\subsection{Instructions raising the $\stackDecAccFlag$ \lispDone{}} \label{hub: instruction handling: acc} \input{instruction_handling/account/_inputs} +\subsection{Instructions raising the $\stackDecCopyFlag$ \lispDone{}} \label{hub: instruction handling: copy} \input{instruction_handling/copy/_inputs} +\subsection{Instructions raising the $\stackDecTxnFlag$ \lispDone{}} \label{hub: instruction handling: txn} \input{instruction_handling/txn} +\subsection{Instructions raising the $\stackDecBtcFlag$ \lispDone{}} \label{hub: instruction handling: btc} \input{instruction_handling/btc} +\subsection{Instructions raising the $\stackDecStackRamFlag$ \lispDone{}} \label{hub: instruction handling: stackRam} \input{instruction_handling/stack_ram/_inputs} +\subsection{Instructions raising the $\stackDecStoFlag$ \lispDone{}} \label{hub: instruction handling: sto} \input{instruction_handling/storage/_inputs} +\subsection{Instructions raising the $\stackDecJumpFlag$ \lispDone{}} \label{hub: instruction handling: jump} \input{instruction_handling/jump} +\subsection{Instructions raising the $\stackDecMachineStateFlag$ \lispDone{}} \label{hub: instruction handling: machineState} \input{instruction_handling/machinestate} +\subsection{Instructions raising the $\stackDecPushPopFlag$ \lispDone{}} \label{hub: instruction handling: pushPop} \input{instruction_handling/pushpop} +\subsection{Instructions raising the $\stackDecDupFlag$ \lispDone{}} \label{hub: instruction handling: dup} \input{instruction_handling/dup} +\subsection{Instructions raising the $\stackDecSwapFlag$ \lispDone{}} \label{hub: instruction handling: swap} \input{instruction_handling/swap} +\subsection{Instructions raising the $\stackDecLogFlag$ \lispDone{}} \label{hub: instruction handling: log} \input{instruction_handling/logs/_inputs} +\subsection{Instructions raising the $\stackDecCreateFlag$ \lispDone{}} \label{hub: instruction handling: create} \input{instruction_handling/create/_inputs} +\subsection{Instructions raising the $\stackDecCallFlag$ \lispTodo{}} \label{hub: instruction handling: call} \input{instruction_handling/call/_inputs} +\subsection{Instructions raising the $\stackDecHaltFlag$ \lispDone{}} \label{hub: instruction handling: halt} \input{instruction_handling/halt/_inputs} +\subsection{Instructions raising the $\stackDecInvalidFlag$ \lispDone{}} \label{hub: instruction handling: invalid} \input{instruction_handling/invalid} diff --git a/hub/instruction_handling/_local.tex b/hub/instruction_handling/_local.tex new file mode 100644 index 0000000..481dd45 --- /dev/null +++ b/hub/instruction_handling/_local.tex @@ -0,0 +1,23 @@ +\def\oneCell{\cellcolor{\romCol}\bm{1}} +\def\zero{\bm{0}} + +% Stateless +\def\isStatelessInst {\col{is\_stateless\_inst}} +\def\instIsExp {\col{inst\_is\_exp}} +\def\instIsntExp {\col{inst\_isnt\_exp}} +\def\oneArgInst {\col{one\_arg\_inst}} +\def\twoArgInst {\col{two\_arg\_inst}} +\def\treArgInst {\col{three\_arg\_inst}} +% jump +\def\locNewPcHi {\col{new\_pc\_hi}} +\def\locNewPcLo {\col{new\_pc\_lo}} +\def\locJumpConditionHi {\col{jump\_cond\_hi}} +\def\locJumpConditionLo {\col{jump\_cond\_lo}} +\def\locIsJump {\col{is\_jump}} +\def\locIsJumpi {\col{is\_jumpi}} +\def\locOobInst {\col{oob\_inst}} +\def\locByteCodeAddressHi {\col{code\_address\_hi}} +\def\locByteCodeAddressLo {\col{code\_address\_lo}} + +% machine state +\def\locMachineStateMiscRow {\redm{1}} diff --git a/hub/instruction_handling/_old.tex b/hub/instruction_handling/_old.tex new file mode 100644 index 0000000..f25c00b --- /dev/null +++ b/hub/instruction_handling/_old.tex @@ -0,0 +1,347 @@ +\iffalse +%%%%%%%% + +\subsection{Instructions raising the $\stackDecAddFlag$} +\label{hub: instruction handling: Add} + +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecAddFlag \\ \hline\hline + \inst{ADD} & \zero & \one \\ \hline + \inst{SUB} & \zero & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecModFlag$} +\label{hub: instruction handling: Mod} + +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecModFlag \\ \hline\hline + \inst{DIV} & \zero & \one \\ \hline + \inst{SDIV} & \zero & \one \\ \hline + \inst{MOD} & \zero & \one \\ \hline + \inst{SMOD} & \zero & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecMulFlag$} +\label{hub: instruction handling: Mul} + +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecMulFlag \\ \hline\hline + \inst{ADDMOD} & \zero & \one \\ \hline + \inst{MULMOD} & \zero & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecExtFlag$} +\label{hub: instruction handling: Ext} + +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecExtFlag \\ \hline\hline + \inst{MUL} & \zero & \one \\ \hline + \inst{EXP} & \zero & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecWcpFlag$} +\label{hub: instruction handling: Wcp} + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecWcpFlag & \decFlag{1} \\ \hline\hline + \inst{LT} & \zero & \one & \zero \\ \hline + \inst{GT} & \zero & \one & \zero \\ \hline + \inst{SLT} & \zero & \one & \zero \\ \hline + \inst{SGT} & \zero & \one & \zero \\ \hline + \inst{EQ} & \zero & \one & \zero \\ \hline + \inst{ISZERO} & \zero & \one & \one \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ singles out the only \wcpMod{}-instructions following the \oneZeroSP{}. + +\subsection{Instructions raising the $\stackDecBinFlag$} +\label{hub: instruction handling: Bin} + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecBinFlag & \decFlag{1} \\ \hline\hline + \inst{AND} & \zero & \one & \zero \\ \hline + \inst{OR} & \zero & \one & \zero \\ \hline + \inst{XOR} & \zero & \one & \zero \\ \hline + \inst{BYTE} & \zero & \one & \zero \\ \hline + \inst{SIGNEXTEND} & \zero & \one & \zero \\ \hline + \inst{NOT} & \zero & \one & \one \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ singles out the only \binMod{}-instructions following the \oneZeroSP{} + +\subsection{Instructions raising the $\stackDecShfFlag$} +\label{hub: instruction handling: Shf} + +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecShfFlag \\ \hline\hline + \inst{SHL} & \zero & \one \\ \hline + \inst{SHR} & \zero & \one \\ \hline + \inst{SAR} & \zero & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecKecFlag$} +\label{hub: instruction handling: Kec} + +\[ +\begin{array}{|l||c||c||c|} + \hline + \INST & \tli & \stackDecKecFlag & \stackDecMxpFlag \\ \hline\hline + \inst{SHA3} & \zero & \one & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecConFlag$} +\label{hub: instruction handling: Con} + +\[ +\begin{array}{|l||c||c|c|c|c|} + \hline + \INST & \tli & \stackDecConFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} \\ \hline\hline + \inst{ADDRESS} & \zero & \one & \zero & \zero & \nothing \\ \hline + \inst{CALLER} & \zero & \one & \zero & \one & \nothing \\ \hline + \inst{CALLVALUE} & \zero & \one & \one & \zero & \zero \\ \hline + \inst{CALLDATASIZE} & \zero & \one & \one & \zero & \one \\ \hline + \inst{RETURNDATASIZE} & \zero & \one & \one & \one & \zero \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecAccFlag$} +\label{hub: instruction handling: Acc} + +\[ +\begin{array}{|l||c||c|c|c|c||c|} + \hline + \INST & \tli & \stackDecAccFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \trmFlag \\ \hline\hline + \inst{BALANCE} & \zero & \one & \zero & \zero & \zero & \one \\ \hline + \inst{EXTCODESIZE} & \zero & \one & \zero & \zero & \one & \one \\ \hline + \inst{EXTCODEHASH} & \zero & \one & \zero & \one & \zero & \one \\ \hline + \inst{CODESIZE} & \zero & \one & \one & \zero & \nothing & \zero \\ \hline + \inst{SELFBALANCE} & \zero & \one & \one & \one & \nothing & \zero \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecCopyFlag$} +\label{hub: instruction handling: Copy} + +\[ +\begin{array}{|l||c||c|c|c||c|c|} + \hline + \INST & \tli & \stackDecCopyFlag & \decFlag{1} & \decFlag{2} & \stackDecTrmFlag & \mxpFlag \\ \hline\hline + \inst{CALLDATACOPY} & \zero & \one & \zero & \zero & \zero & \one \\ \hline + \inst{RETURNDATACOPY} & \zero & \one & \zero & \one & \zero & \one \\ \hline + \inst{CODECOPY} & \zero & \one & \one & \zero & \zero & \one \\ \hline + \inst{EXTCODECOPY} & \zero & \one & \one & \one & \one & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecTxnFlag$} +\label{hub: instruction handling: Txn} + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecTxnFlag & \decFlag{1} \\ \hline\hline + \inst{ORIGIN} & \zero & \one & \zero \\ \hline + \inst{GASPRICE} & \zero & \one & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecBtcFlag$} +\label{hub: instruction handling: Btc} + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecBtcFlag & \decFlag{1} \\ \hline\hline + \inst{COINBASE} & \zero & \one & \zero \\ \hline + \inst{TIMESTAMP} & \zero & \one & \zero \\ \hline + \inst{NUMBER} & \zero & \one & \zero \\ \hline + \inst{PREVRANDAO} & \zero & \one & \zero \\ \hline + \inst{GASLIMIT} & \zero & \one & \zero \\ \hline + \inst{CHAINID} & \zero & \one & \zero \\ \hline + \inst{BASEFEE} & \zero & \one & \zero \\ \hline + \inst{BLOCKHASH} & \zero & \one & \one \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ singles out the only \oneOneSP{} instruction. + +\subsection{Instructions raising the $\stackDecStackRamFlag$} +\label{hub: instruction handling: StackRam} + +\[ +\begin{array}{|l||c||c|c||c|c|} + \hline + \INST & \tli & \stackDecStackRamFlag & \decFlag{1} & \stackDecOobFlag & \mxpFlag \\ \hline\hline + \inst{CALLDATALOAD} & \zero & \one & \zero & \one & \zero \\ \hline + \inst{MLOAD} & \zero & \one & \zero & \zero & \one \\ \hline + \inst{MSTORE} & \zero & \one & \one & \zero & \one \\ \hline + \inst{MSTORE8} & \zero & \one & \one & \zero & \one \\ \hline +\end{array} +\] +\saNote{} The $\stackDecStackRamFlag$-instructions which raise the $\decFlag{1}$ are those that pop two items off the stack. + +\subsection{Instructions raising the $\stackDecStoFlag$} +\label{hub: instruction handling: Sto} + +\[ +\begin{array}{|l||c||c|c||c|} + \hline + \INST & \tli & \stackDecStoFlag & \decFlag{1} & \decStaticInst \\ \hline\hline + \inst{SLOAD} & \zero & \one & \zero & \zero \\ \hline + \inst{SSTORE} & \zero & \one & \one & \one \\ \hline +\end{array} +\] +\saNote{} Just as in section~\ref{hub: instruction handling: StackRam} the $\stackDecStoFlag$-instructions which raise the $\decFlag{1}$ are those that pop two items off the stack. + +\subsection{Instructions raising the $\stackDecJumpFlag$} +\label{hub: instruction handling: Jump} + +\[ +\begin{array}{|l||c||c|c||c|} + \hline + \INST & \tli & \stackDecJumpFlag & \decFlag{1} & \stackDecOobFlag \\ \hline\hline + \inst{JUMP} & \zero & \one & \zero & \one \\ \hline + \inst{JUMPI} & \zero & \one & \one & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecMachineStateFlag$} +\label{hub: instruction handling: MachineState} + +\[ +\begin{array}{|l||c||c|c|c||c|} + \hline + \INST & \tli & \stackDecMachineStateFlag & \decFlag{1} & \decFlag{2} & \stackDecMxpFlag \\ \hline\hline + \inst{PC} & \zero & \one & \zero & \zero & \zero \\ \hline + \inst{MSIZE} & \zero & \one & \zero & \one & \one \\ \hline + \inst{GAS} & \zero & \one & \one & \zero & \zero \\ \hline + \inst{JUMPDEST} & \zero & \one & \one & \one & \zero \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecPushPopFlag$} +\label{hub: instruction handling: PushPop} + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecPushPopFlag & \decFlag{1} \\ \hline\hline + \inst{POP} & \zero & \one & \zero \\ \hline + \inst{PUSH1-32} & \zero & \one & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecDupFlag$} +\label{hub: instruction handling: Dup} + +The \inst{DUP\_X}-instructions are all one line instructions (i.e. $\tli = 0$.) For instructions that conform to the \dupSP{} the value of $\inst{X}$ can be derived from the instruction via $\inst{X} = \INST - \inst{DUP1} + 1$. Locally within section~\ref{hub: stack patterns: dup} we use the shorthand $\param := \INST - \inst{DUP1} = \inst{X} - 1$. +\[ +\begin{array}{|l||c||c|r|} + \hline + \INST & \tli & \stackDecDupFlag & \param \\ \hline\hline + \inst{DUP1-16} & \zero & \one & \inst{X} - 1 \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecSwapFlag$} +\label{hub: instruction handling: Swap} + +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecSwapFlag \\ \hline\hline + \inst{SWAP1-16} & \zero & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecLogFlag$} +\label{hub: instruction handling: Log} + +\[ +\begin{array}{|l||c||c|c|c|c||c|c|} + \hline + \INST & \tli & \stackDecLogFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decStaticInst & \stackDecMxpFlag \\ \hline\hline + \inst{LOG0} & \one & \one & \zero & \zero & \zero & \one & \one \\ \hline + \inst{LOG1} & \one & \one & \one & \zero & \zero & \one & \one \\ \hline + \inst{LOG2} & \one & \one & \one & \zero & \one & \one & \one \\ \hline + \inst{LOG3} & \one & \one & \one & \one & \zero & \one & \one \\ \hline + \inst{LOG4} & \one & \one & \one & \one & \one & \one & \one \\ \hline +\end{array} +\] +We treat \inst{LOG}-type instructions as $\TLI$ regardless of the fact that (strictly speaking) only \inst{LOG3} and \inst{LOG4} require 2 stack rows. The $\decFlag{1}$, $\decFlag{2}$, $\decFlag{3}$ flags distinguish between the five \inst{LOG}-type instructions. + +\subsection{Instructions raising the $\stackDecCreateFlag$} +\label{hub: instruction handling: Create} + +\[ +\begin{array}{|l||c||c|c||c|c|} + \hline + \INST & \tli & \stackDecCreateFlag & \decFlag{1} & \decStaticInst & \stackDecMxpFlag \\ \hline\hline + \inst{CREATE} & \one & \one & \zero & \one & \one \\ \hline + \inst{CREATE2} & \one & \one & \one & \one & \one \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecCallFlag$} +\label{hub: instruction handling: Call} + +\[ +\begin{array}{|l||c||c|c|c||c|c|} + \hline + \INST & \tli & \stackDecCallFlag & \decFlag{1} & \decFlag{2} & \stackDecMxpFlag & \decStaticInst \\ \hline\hline + \inst{DELEGATECALL} & \one & \one & \zero & \zero & \one & \zero \\ \hline + \inst{STATICCALL} & \one & \one & \zero & \one & \one & \zero \\ \hline + \inst{CALL} & \one & \one & \one & \zero & \one & \one \\ \hline + \inst{CALLCODE} & \one & \one & \one & \one & \one & \zero \\ \hline +\end{array} +\] +\saNote{} Within the instructions which raise the $\stackDecCallFlag$, \inst{CALL} and \inst{CALLCODE} (which transfer value and thus require 7 stack arguments) are distinguished by $\decFlag{1} = 1$. + +\subsection{Instructions raising the $\stackDecHaltFlag$} +\label{hub: instruction handling: Halt} + +\[ +\begin{array}{|l||c||c|c|c||c|} + \hline + \INST & \tli & \stackDecHaltFlag & \decFlag{1} & \decFlag{2} & \stackDecMxpFlag \\ \hline\hline + \inst{RETURN} & \zero & \one & \zero & \zero & \one \\ \hline + \inst{REVERT} & \zero & \one & \zero & \one & \one \\ \hline + \inst{STOP} & \zero & \one & \one & \zero & \zero \\ \hline + \inst{SELFDESTRUCT} & \zero & \one & \one & \one & \zero \\ \hline +\end{array} +\] + +\subsection{Instructions raising the $\stackDecInvalidFlag$} +\label{hub: instruction handling: Invalid} + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecInvalidFlag & \decFlag{1} \\ \hline\hline + \inst{INVALID} & \zero & \one & \zero \\ \hline + \inst{notOpCode} & \zero & \one & \one \\ \hline +\end{array} +\] +\dots{} where \inst{notOpCode} stands for any byte that isn't an opcode. + +\fi +%%% diff --git a/hub/instruction_handling/account/_inputs.tex b/hub/instruction_handling/account/_inputs.tex new file mode 100644 index 0000000..11f9599 --- /dev/null +++ b/hub/instruction_handling/account/_inputs.tex @@ -0,0 +1,4 @@ +\input{instruction_handling/account/_local} +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: account: instructions} \input{instruction_handling/account/instructions} +\subsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: account: shorthands} \input{instruction_handling/account/shorthands} +\subsubsection{Constraints \lispDone{}} \label{hub: instruction handling: account: constraints} \input{instruction_handling/account/constraints} diff --git a/hub/instruction_handling/account/_local.tex b/hub/instruction_handling/account/_local.tex new file mode 100644 index 0000000..04ada59 --- /dev/null +++ b/hub/instruction_handling/account/_local.tex @@ -0,0 +1,12 @@ +\def\locRawAddressHi {\col{raw\_address\_hi}} +\def\locRawAddressLo {\col{raw\_address\_lo}} +\def\locAccountAddressHi {\col{account\_address\_hi}} +\def\locAccountAddressLo {\col{account\_address\_lo}} +\def\locCodeAddressHi {\col{byte\_code\_address\_hi}} +\def\locCodeAddressLo {\col{byte\_code\_address\_lo}} + +\def\locRequiresTrimming {\col{requires\_trimming}} +\def\locCurrentAccount {\col{current\_account}} +\def\locWarmth {\col{address\_warmth}} + +\def\locDecFlagSumAccount {\col{decoded\_flag\_sum}} diff --git a/hub/instruction_handling/account/_old.tex b/hub/instruction_handling/account/_old.tex new file mode 100644 index 0000000..f015a9e --- /dev/null +++ b/hub/instruction_handling/account/_old.tex @@ -0,0 +1,27 @@ +\subsubsection{Address trimming lookup $\hubMod \hookrightarrow \trmMod$} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{description} + \item[Row selector.] $\col{sel}_{i} := \peekStack_{i} \cdot \stackDecAccFlag_{i} \cdot \stackDecTrmFlag_{i}$ + + I.e. we select stack rows whose instructions raise the \accFlag{} and peek into foreign accounts. + \item[Source columns.] --- + \begin{multicols}{4} + \begin{enumerate} + \item $\cnAccountAddress\high_{i + 1}$ + \item $\stackItemValHi{4}_{i}$ + \item $\stackItemValLo{4}_{i}$ + \item $\accTrmIsPrecompile_{i + 1}$ + \end{enumerate} + \end{multicols} + \item[Target columns.] --- + \begin{multicols}{4} + \begin{enumerate} + \item $\trmAddrHi_{j}$ + \item $\addr\high_{j}$ + \item $\addr\low_{j}$ + \item $\isPrecompile_{j}$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} The present collection of instructions does not care about the $\accTrmIsPrecompile$ flag. Others will, though, and we include it in the lookup for greater uniformity and mergeability with other lookups into the \trmMod{} module. diff --git a/hub/instruction_handling/account/constraints.tex b/hub/instruction_handling/account/constraints.tex new file mode 100644 index 0000000..b75be56 --- /dev/null +++ b/hub/instruction_handling/account/constraints.tex @@ -0,0 +1,263 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecAccFlag_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \end{array} \right. } +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose that + \begin{enumerate} + \item \If $\locRequiresTrimming = 1$ \Then $\oneOneSP _{i}$ + \item \If $\locCurrentAccount = 1$ \Then $\zeroOneSP _{i}$ + \end{enumerate} + \item[\underline{Setting allowable exceptions:}] + we impose $\xAhoy_{i} = \stackOogx_{i}$ \quad (\trash) + \item[\underline{Setting $\nonStackRows$:}] + we impose that + \begin{enumerate} + \item \If $\locRequiresTrimming = 1$ \Then $\nonStackRows_{i} = 1 + \cnWillRev_{i} + \cmc_{i}$ + \item \If $\locCurrentAccount = 1$ \Then $\nonStackRows_{i} = 1 + (1 - \cmc_{i})$ + \end{enumerate} + \saNote{} For instructions raising the $\stackDecAccFlag$ one has $\cmc \equiv \xAhoy$. + \item[\underline{Setting the peeking flags:}] + we impose that + \begin{enumerate} + \item \If $\locRequiresTrimming = 1$ \Then + \begin{enumerate} + \item \If $\cnWillRev_{i} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekAccount_{i + 1} \\ + + & \cmc_{i} \cdot \peekContext_{i + 2} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\cnWillRev_{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekAccount_{i + 1} \\ + + & \peekAccount_{i + 2} \\ + + & \cmc_{i} \cdot \peekContext_{i + 3} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \item \If $\locCurrentAccount = 1$ \Then + \begin{enumerate} + \item \If $\xAhoy_{i} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekContext_{i + 1} \\ + + & \peekAccount_{i + 2} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\xAhoy_{i} = 1$ \Then $\peekContext_{i + 1} = \nonStackRows_{i}$ + \end{enumerate} + \end{enumerate} + \item[\underline{Setting the gas cost:}] + we impose that + \begin{enumerate} + \item \If $\locRequiresTrimming = 1$ \Then + \[ + \gasCost_{i} + = + \left[ \begin{array}{crcl} + + & \locWarmth & \cdot & G_{\text{warmaccess}} \\ + + & (1 - \locWarmth) & \cdot & G_{\text{coldaccountaccess}} \\ + \end{array} \right] + \] + \saNote{} Recall that + $G_{\text{coldaccountaccess}} = 2600$ and + $G_{\text{warmaccess}} = 100$. + \item \If $\locCurrentAccount = 1$ \Then + \[ + \gasCost_{i} = \stackStaticGas_{i} + % = G_{\text{low}} + \decFlag {4} _{i} \cdot ( G_{\text{base}} - G_{\text{low}} ) + \] + \saNote{} In other words for + \inst{CODESIZE} one has $\gasCost \equiv G_{\text{base}} \equiv 2$ while for + \inst{SELFBALANCE} one has $\gasCost \equiv G_{\text{low}} \equiv 5$. + \end{enumerate} + \item[\underline{Garnishing the non stack rows:}] + we impose that + \begin{enumerate} + \item \If $\locRequiresTrimming = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + 1} & = & \nothing \\ + \multicolumn{3}{l}{\accTrimAddress + {i}{1} + {\stackItemValHi {1} _{i}} + {\stackItemValLo {1} _{i}}} \\ + % \accTrmFlag _{i + 1} & = & \rOne \\ + % \accTrmRawAddrHi _{i + 1} & = & \stackItemValHi {1} _{i} \\ + % \accAddressLo _{i + 1} & = & \stackItemValLo {1} _{i} \\ + \multicolumn{3}{l}{\accSameBalance {i}{1}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{1}} \\ + \multicolumn{3}{l}{\accSameCode {i}{1}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{1}} \\ + \multicolumn{3}{l}{\accTurnOnWarmth {i}{1}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{1}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = 1, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{1}{0}} \\ + \end{array} \right. + \] + \begin{enumerate} + \item \If $\cnWillRev_{i} = 0$ \Then we don't need to impose anything else; + \item \If $\cnWillRev_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + 2} & = & \nothing \\ + \accTrmFlag _{i + 2} & = & \nothing \\ + \accSameAddr {i}{2}{1} \\ + \accUndoBalanceUpdate {i}{2}{1} \\ + \accUndoNonceUpdate {i}{2}{1} \\ + \accUndoCodeUpdate {i}{2}{1} \\ + \accUndoDeploymentStatusAndNumberUpdate {i}{2}{1} \\ + \accUndoWarmthUpdate {i}{2}{1} \\ + \accSameMarkedForSelfdestructFlag {i}{2} \\ + \revertDomSubStamps { + anchorRow = i, + relOffset = 2, + subOffset = 1, + } \\ + % \revertDomSubStamps {i}{2}{1} \\ + \end{array} \right. + \] + \end{enumerate} + \item \If $\locCurrentAccount = 1$ \Then + \begin{enumerate} + \item \If $\xAhoy_{i} = 0$ \Then we impose + \begin{description} + \item[\underline{Context row:}] + we impose + $\readContextData {i}{1}{\cn_{i}}$ + \item[\underline{Account row:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \accTrmFlag _{i + 2} & = & \nothing \\ + \accRomLexFlag _{i + 2} & = & \nothing \\ + \accAddressHi _{i + 2} & = & \valueToBeSet \\ + \accAddressLo _{i + 2} & = & \valueToBeSet \\ + \multicolumn{3}{l}{\accSameBalance {i}{2}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{2}} \\ + \multicolumn{3}{l}{\accSameCode {i}{2}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{2}} \\ + \multicolumn{3}{l}{\accTurnOnWarmth {i}{2}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{2}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = 2, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{2}{0}} \\ + \end{array} \right. + \] + furthermore + \begin{enumerate} + \item \If $\decFlag{4}_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accAddressHi _{i + 2} & = & \locAccountAddressHi \\ + \accAddressLo _{i + 2} & = & \locAccountAddressLo \\ + \end{array} \right. + \] + \saNote{} This is the \inst{SELFBALANCE} case. + \item \If $\decFlag{4}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \accAddressHi _{i + 2} & = & \locCodeAddressHi \\ + \accAddressLo _{i + 2} & = & \locCodeAddressLo \\ + \end{array} \right. + \] + \saNote{} This is the \inst{CODESIZE} case. + \end{enumerate} + \end{description} + \item \If $\xAhoy_{i} = 1$ \Then we don't need to impose anything; + \end{enumerate} + \end{enumerate} + \item[\underline{Value constraints:}] + \If $\xAhoy_{i} = 0$ \Then + we impose the following + \begin{description} + \item[\underline{The \inst{BALANCE} case:}] + \If $\decFlag{1}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \accBalance_{i + 1} \\ + \end{array} \right. + \] + \item[\underline{The \inst{EXTCODESIZE} case:}] + \If $\decFlag{2}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \accCodesize_{i + 1} \\ + \end{array} \right. + \] + \item[\underline{The \inst{EXTCODEHASH} case:}] + \If $\decFlag{3}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & \accCodehash_{i + 1}\high \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \accCodehash_{i + 1}\low \\ + \end{array} \right. + \] + \item[\underline{The \inst{CODESIZE} case:}] + \If $\decFlag{4}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \accCodesize_{i + 2} \\ + \end{array} \right. + \] + \item[\underline{The \inst{SELFBALANCE} case:}] + \If $\locDecFlagSumAccount = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \accBalance_{i + 2} \\ + \end{array} \right. + \] + where + \[ + \locDecFlagSumAccount + \define + \left[ \begin{array}{cr} + + & \decFlag{1}_{i} \\ + + & \decFlag{2}_{i} \\ + + & \decFlag{3}_{i} \\ + + & \decFlag{4}_{i} \\ + \end{array} \right] + \] + \end{description} +\end{description} + +% \begin{enumerate} +% \item \If $\locRequiresTrimming = 1$ \Then +% \begin{enumerate} +% \item \If $\cnWillRev_{i} = 0$ \Then +% \item \If $\cnWillRev_{i} = 1$ \Then +% \end{enumerate} +% \item \If $\locCurrentAccount = 1$ \Then +% \begin{enumerate} +% \item \If $\xAhoy_{i} = 0$ \Then +% \item \If $\xAhoy_{i} = 1$ \Then +% \end{enumerate} +% \end{enumerate} diff --git a/hub/instruction_handling/account/instructions.tex b/hub/instruction_handling/account/instructions.tex new file mode 100644 index 0000000..39f1649 --- /dev/null +++ b/hub/instruction_handling/account/instructions.tex @@ -0,0 +1,27 @@ +% \[ +% \begin{array}{|l||c||c|c|c|c||c|} +% \hline +% \INST & \tli & \stackDecAccFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \stackDecTrmFlag \\ \hline\hline +% \inst{BALANCE} & \zero & \oneCell & \zero & \zero & \zero & \oneCell \\ \hline +% \inst{EXTCODESIZE} & \zero & \oneCell & \zero & \zero & \oneCell & \oneCell \\ \hline +% \inst{EXTCODEHASH} & \zero & \oneCell & \zero & \oneCell & \zero & \oneCell \\ \hline +% \inst{CODESIZE} & \zero & \oneCell & \oneCell & \zero & \nothing & \zero \\ \hline +% \inst{SELFBALANCE} & \zero & \oneCell & \oneCell & \oneCell & \nothing & \zero \\ \hline +% \end{array} +% \] +% \saNote{} +% $\decFlag{1} = 0$ for instructions that peek into a foreign account; +% $\decFlag{1} = 1$ for instructions that peek into the current account. +% Furthermore $\decFlag{1}$ distinguishes instructions following the \zeroOneSP{} from those following the \oneOneSP{}. + +\[ +\begin{array}{|l||c||c|c|c|c|c|} + \hline + \INST & \tli & \stackDecAccFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} \\ \hline\hline % & \stackDecTrmFlag + \inst{BALANCE} & \gZero & \oneCell & \oneCell & \gZero & \gZero & \gZero \\ \hline % & \oneCell + \inst{EXTCODESIZE} & \gZero & \oneCell & \gZero & \oneCell & \gZero & \gZero \\ \hline % & \oneCell + \inst{EXTCODEHASH} & \gZero & \oneCell & \gZero & \gZero & \oneCell & \gZero \\ \hline % & \oneCell + \inst{CODESIZE} & \gZero & \oneCell & \gZero & \gZero & \gZero & \oneCell \\ \hline % & \gZero + \inst{SELFBALANCE} & \gZero & \oneCell & \gZero & \gZero & \gZero & \gZero \\ \hline % & \gZero +\end{array} +\] diff --git a/hub/instruction_handling/account/shorthands.tex b/hub/instruction_handling/account/shorthands.tex new file mode 100644 index 0000000..846be0c --- /dev/null +++ b/hub/instruction_handling/account/shorthands.tex @@ -0,0 +1,25 @@ +We define some shorthands +\[ + \left\{ \begin{array}{lcl} + \locRequiresTrimming & \define & \left[ \begin{array}{cr} + & \decFlag{1}_{i} \\ + & \decFlag{2}_{i} \\ + & \decFlag{3}_{i} \\ \end{array} \right] \\ + \locCurrentAccount & \define & \stackDecAccFlag _{i} - \locRequiresTrimming \\ + \locRawAddressHi & \define & \stackItemValHi {1} _{i} \\ + \locRawAddressLo & \define & \stackItemValLo {1} _{i} \\ + \locAccountAddressHi & \define & \cnAccountAddress\high _{i + 1} \\ + \locAccountAddressLo & \define & \cnAccountAddress\low _{i + 1} \\ + \locCodeAddressHi & \define & \cnCodeAddress\high _{i + 1} \\ + \locCodeAddressLo & \define & \cnCodeAddress\low _{i + 1} \\ + \locWarmth & \define & \accWarmth _{i + 1} \\ + \end{array} \right. +\] +Thus by construction +\[ + \begin{array}{|l||c||c|c|c|c|c|} \hline + \INST & \locRequiresTrimming & \locCurrentAccount \\ \hline\hline % & \stackDecTrmFlag + \inst{BALANCE} & \oneCell & \gZero \\ \hline % & \oneCell + \inst{EXTCODESIZE} & \oneCell & \gZero \\ \hline % & \oneCell + \inst{EXTCODEHASH} & \oneCell & \gZero \\ \hline % & \oneCell + \inst{CODESIZE} & \gZero & \oneCell \\ \hline % & \gZero + \inst{SELFBALANCE} & \gZero & \oneCell \\ \hline % & \gZero + \end{array} +\] diff --git a/hub/instruction_handling/add.tex b/hub/instruction_handling/add.tex new file mode 100644 index 0000000..28a8071 --- /dev/null +++ b/hub/instruction_handling/add.tex @@ -0,0 +1,8 @@ +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecAddFlag \\ \hline\hline + \inst{ADD} & \zero & \oneCell \\ \hline + \inst{SUB} & \zero & \oneCell \\ \hline +\end{array} +\] diff --git a/hub/instruction_handling/bin.tex b/hub/instruction_handling/bin.tex new file mode 100644 index 0000000..7da611c --- /dev/null +++ b/hub/instruction_handling/bin.tex @@ -0,0 +1,13 @@ +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecBinFlag & \decFlag{1} \\ \hline\hline + \inst{AND} & \zero & \oneCell & \zero \\ \hline + \inst{OR} & \zero & \oneCell & \zero \\ \hline + \inst{XOR} & \zero & \oneCell & \zero \\ \hline + \inst{BYTE} & \zero & \oneCell & \zero \\ \hline + \inst{SIGNEXTEND} & \zero & \oneCell & \zero \\ \hline + \inst{NOT} & \zero & \oneCell & \oneCell \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ singles out the only \binMod{}-instructions following the \oneOneSP{}. diff --git a/hub/instruction_handling/btc.tex b/hub/instruction_handling/btc.tex new file mode 100644 index 0000000..559bd79 --- /dev/null +++ b/hub/instruction_handling/btc.tex @@ -0,0 +1,55 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\[ + \begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecBtcFlag & \decFlag{1} \\ \hline\hline + \inst{COINBASE} & \zero & \oneCell & \zero \\ \hline + \inst{TIMESTAMP} & \zero & \oneCell & \zero \\ \hline + \inst{NUMBER} & \zero & \oneCell & \zero \\ \hline + \inst{PREVRANDAO} & \zero & \oneCell & \zero \\ \hline + \inst{GASLIMIT} & \zero & \oneCell & \zero \\ \hline + \inst{CHAINID} & \zero & \oneCell & \zero \\ \hline + \inst{BASEFEE} & \zero & \oneCell & \zero \\ \hline + \inst{BLOCKHASH} & \zero & \oneCell & \oneCell \\ \hline + \end{array} +\] +\saNote{} $\decFlag{1}$ singles out the only \oneOneSP{} instruction. + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecBtcFlag_{i} = 1 \\ + \stackSux_{i} + \stackSox_{i} = 0 \\ + \end{cases}} +\end{center} +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose that + \begin{enumerate} + \item \If $\decFlag{1}_{i} = 0$ \Then $\zeroOneSP_{i}$ + \item \If $\decFlag{1}_{i} = 1$ \Then $\oneOneSP_{i}$ + \end{enumerate} + \item[\underline{Setting $\nonStackRows$:}] + we impose $\nonStackRows_{i} = \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] + we don't need to set any; + + \saNote{} Implicitly of course $\cmc_{i} \cdot \peekContext_{i + 1} = \cmc_{i}$ (\trash); + \item[\underline{Setting the gas cost:}] + we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] + the relevant values are obtained by means of a lookup to either the \btcMod{} module or the \blockHashMod{} module, + see sections + (\ref{hub: lookups: into block data}) and + (\ref{hub: lookups: into block hash}) respectively. +\end{description} +\saNote{} For instructions raising the $\stackDecBtcFlag$ one has $\cmc \equiv \xAhoy$. diff --git a/hub/instruction_handling/call/_inputs.tex b/hub/instruction_handling/call/_inputs.tex new file mode 100644 index 0000000..d01511b --- /dev/null +++ b/hub/instruction_handling/call/_inputs.tex @@ -0,0 +1,16 @@ +\input{instruction_handling/call/_local} +\subsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: intro} \input{instruction_handling/call/intro} +\subsubsection{Description of the general approach \lispNone{}} \label{hub: instruction handling: call: general approach} \input{instruction_handling/call/approach} +\subsubsection{Supported instruction and flags \lispNone{}} \label{hub: instruction handling: call: instruction flags} \input{instruction_handling/call/flags} +\subsubsection{High level flowchart for \inst{CALL}-type instructions \lispNone{}} \label{hub: instruction handling: call: high level flowchart} \input{instruction_handling/call/highlevel} +\subsubsection{Forward and backward setting of scenario row \lispDone{}} \label{hub: instruction handling: call: scenario bedrock} \input{instruction_handling/call/bedrock} +\subsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: call: shorthands} \input{instruction_handling/call/shorthands} +\subsubsection{Module triggers \lispDone{}} \label{hub: instruction handling: call: module triggers} \input{instruction_handling/call/triggers/_inputs} +\subsubsection{Peeking flag sums for non precompile scenarios \lispDone{}} \label{hub: instruction handling: call: peeking flag sums for nonn precompiles} \input{instruction_handling/call/flag_sums_no_precompiles} +\subsubsection{Non stack rows for non precompile scenarios \lispDone{}} \label{hub: instruction handling: call: non stack rows for non precompiles} \input{instruction_handling/call/nsr_no_precompiles} +\subsubsection{\emph{Partial} peeking flag sums for precompiles \lispDone{}} \label{hub: instruction handling: call: partial peeking flag sums for precompiles} \input{instruction_handling/call/flag_sums_for_precompiles_partial} +\subsubsection{\emph{Partial} non stack rows for precompile scenarios \lispDone{}} \label{hub: instruction handling: call: partial non stack rows for precompiles} \input{instruction_handling/call/nsr_for_precompiles_partial} +\subsubsection{Generalities \lispDone{}} \label{hub: instruction handling: call: generalities} \input{instruction_handling/call/generalities/_inputs} +\subsubsection{Finishing touches \lispDone{}} \label{hub: instruction handling: call: finishing touches} \input{instruction_handling/call/finishing/_inputs} +\subsubsection{Some specialized constraints \lispDone{}} \label{hub: instruction handling: call: specialized constraints} \input{instruction_handling/call/specialized/_inputs} +\subsubsection{Dealing with precompiles \lispDone{}} \label{hub: instruction handling: call: precompile memory operations} \input{instruction_handling/call/precompiles/_inputs} diff --git a/hub/instruction_handling/call/_local.tex b/hub/instruction_handling/call/_local.tex new file mode 100644 index 0000000..9090646 --- /dev/null +++ b/hub/instruction_handling/call/_local.tex @@ -0,0 +1,136 @@ +\def\exampleOffset {\bluem{\omega}} +\def\one {\redm{1}} +\def\locCallTriggersMxp {\col{trigger\_MXP}} +\def\locCallTriggersTrm {\col{trigger\_TRM}} +\def\locCallTriggersStp {\col{trigger\_STP}} +\def\locCallTriggersOob {\col{trigger\_OOB}} +\def\locCallTriggersRomLex {\col{trigger\_ROMLEX}} +\def\locCallTriggersStaticx {\col{could\_trigger\_STATICX}} +\def\locCallRequiresCalleeAccount {\col{call\_requires\_callee\_account}} +\def\locCallRequiresCallerAccount {\col{call\_requires\_caller\_account}} +\def\locCallRequiresBothAccountsTwice {\col{call\_requires\_both\_accounts\_twice}} +\def\locCallRequiresCalleeAccountThrice {\col{call\_requires\_callee\_account\_thrice}} +% +\def\locIsCall {\col{is\_CALL}} +\def\locIsCallcode {\col{is\_CALLCODE}} +\def\locIsDelegatecall {\col{is\_DELEGATECALL}} +\def\locIsStaticcall {\col{is\_STATICCALL}} +\def\locInst {\col{STACK\_instruction}} +\def\locStaticx {\col{STACK\_staticx}} +\def\locMxpx {\col{STACK\_mxpx}} +\def\locOogx {\col{STACK\_oogx}} +\def\locCdoHi {\col{STACK\_cdo\_hi}} +\def\locCdoLo {\col{STACK\_cdo\_lo}} +\def\locCdsHi {\col{STACK\_cds\_hi}} +\def\locCdsLo {\col{STACK\_cds\_lo}} +\def\locRaoHi {\col{STACK\_r@o\_hi}} +\def\locRaoLo {\col{STACK\_r@o\_lo}} +\def\locRacHi {\col{STACK\_r@c\_hi}} +\def\locRacLo {\col{STACK\_r@c\_lo}} +\def\locGasHi {\col{STACK\_gas\_hi}} +\def\locGasLo {\col{STACK\_gas\_lo}} +\def\locSuccessBitHi {\col{STACK\_success\_bit\_hi}} +\def\locSuccessBitLo {\col{STACK\_success\_bit\_lo}} +\def\locRawAddressHi {\col{STACK\_raw\_callee\_address\_hi}} +\def\locRawAddressLo {\col{STACK\_raw\_callee\_address\_lo}} +\def\locCalleeAddressHi {\col{callee\_address\_hi}} +\def\locCalleeAddressLo {\col{callee\_address\_lo}} +\def\locValue {\col{STACK\_value}} +\def\locValueHi {\locValue\col{\_hi}} +\def\locValueLo {\locValue\col{\_lo}} +\def\locNonzeroValue {\col{\oobMod\_nonzero\_value}} +\def\locOobAbortingCondition {\col{\oobMod\_aborting\_condition}} +\def\locMxpMemoryExpansionException {\col{\mxpMod\_memory\_expansion\_exception}} +\def\locMxpMemoryExpansionGas {\col{\mxpMod\_memory\_expansion\_gas}} +\def\locCallTransfersNonZeroValue {\colm{[\locValue \neq 0]}} +\def\locIsStatic {\col{current\_context\_is\_static}} +\def\locCurrentAddressHi {\col{current\_address\_hi}} +\def\locCurrentAddressLo {\col{current\_address\_lo}} +\def\locCurrentCallerAddressHi {\col{current\_caller\_address\_hi}} +\def\locCurrentCallerAddressLo {\col{current\_caller\_address\_lo}} +\def\locCurrentCallValue {\col{current\_call\_value}} +\def\locCsd {\col{current\_call\_stack\_depth}} +\def\locGasActual {\col{gas\_actual}} +% +\def\relevantValue {\texttt{}} +\def\locPrecompileNames {\mathscr{P}\textit{rec}} +% +% +% MXP +% +% +% +% +% ROMLEX +% +% +\def\locCalleeCfi {\col{callee\_code\_fragment\_index}} +\def\locRomLexFlag {\col{rom\_lex\_flag}} +\def\locCalleeWarmth {\col{callee\_warmth}} +\def\locCalleeExists {\col{callee\_exists}} +% +% +% STP +% +% +\def\locStpGasUpfront {\col{\stpMod\_gas\_upfront}} +\def\locStpGasPoop {\col{\stpMod\_gas\_paid\_out\_of\_pocket}} +\def\locStpGasStipend {\col{\stpMod\_call\_stipend}} +\def\locStpOogx {\col{\stpMod\_out\_of\_gas\_exception}} +% +\def\locCnWillRevert {\col{caller\_will\_revert}} +\def\locCnRevertStamp {\col{caller\_revert\_stamp}} +\def\locCallerBalance {\col{caller\_balance}} +% +\def\locCalleeWillRevert {\col{callee\_self\_reverts}} +\def\locCalleeRevertStamp {\col{callee\_revert\_stamp}} +\def\locCalleeHasCode {\col{callee\_has\_code}} + +\def\callFirstStackRowOffset {\greenm{2}} % are always preceded by minus sign (i.e. point to the past) +\def\callSecondStackRowOffset {\greenm{1}} % are always preceded by minus sign (i.e. point to the past) +\def\callCurrentContextRowOffset {\yellowm{1}} +\def\callMiscRowOffset {\yellowm{2}} +\def\callFirstCallerAccountRowOffset {\yellowm{3}} +\def\callFirstCalleeAccountRowOffset {\yellowm{4}} +\def\callSecondCalleeAccountRowOffsetAbortWillRevert {\yellowm{5}} +\def\callSecondCallerAccountRowOffset {\yellowm{5}} +\def\callSecondCalleeAccountRowOffset {\yellowm{6}} +\def\callThirdCalleeAccountRowOffset {\yellowm{7}} + +\def\callStaticxUpdateParentContextRowOffset {\orangem{3}} +\def\callMxpxUpdateParentContextRowOffset {\orangem{3}} +\def\callOogxUpdateParentContextRowOffset {\orangem{5}} +\def\callAbortWillRevertUpdateCurrentContextRowOffset {\orangem{6}} +\def\callAbortWontRevertUpdateCurrentContextRowOffset {\orangem{5}} +\def\callEoaWillRevertCallerContextRowOffset {\orangem{7}} +\def\callEoaWontRevertCallerContextRowOffset {\orangem{5}} +\def\callSmcFailureWillRevertInitializeCalleeContextRowOffset {\orangem{8}} +\def\callSmcFailureWontRevertInitializeCalleeContextRowOffset {\orangem{7}} +\def\callSmcSuccessWillRevertInitializeCalleeContextRowOffset {\orangem{7}} +\def\callSmcSuccessWontRevertInitializeCalleeContextRowOffset {\orangem{5}} +% +\def\callFirstScenarioRowOffset {\bluem{0}} +\def\callPrcFailureSecondScenarioRowOffset {\bluem{5}} +\def\callPrcSuccessWillRevertSecondScenarioRowOffset {\bluem{7}} +\def\callPrcSuccessWontRevertSecondScenarioRowOffset {\bluem{5}} +% +\def\peekingSumPrcFailureFH {\col{flag\_sum\_prc\_failure\_first\_half}} +\def\peekingSumPrcSuccessWillRevertFH {\col{flag\_sum\_prc\_success\_will\_revert\_first\_half}} +\def\peekingSumPrcSuccessWontRevertFH {\col{flag\_sum\_prc\_success\_wont\_revert\_first\_half}} +\def\nsrPrecompilesFH {\col{nsr\_first\_half}} + +\def\standardPeekingSumForCalls {\col{standard\_call\_prefix}} +\def\extendedPeekingSumForCalls {\col{extended\_call\_prefix}} +\def\peekingSumStaticx {\col{flag\_sum\_staticx}} +\def\peekingSumMxpx {\col{flag\_sum\_mxpx}} +\def\peekingSumOogx {\col{flag\_sum\_oogx}} +\def\peekingSumAbortWillRevert {\col {flag\_sum\_abort\_will\_revert}} +\def\peekingSumAbortWontRevert {\col {flag\_sum\_abort\_wont\_revert}} +\def\peekingSumEoaWillRevert {\col{flag\_sum\_eoa\_will\_revert}} +\def\peekingSumEoaWontRevert {\col{flag\_sum\_eoa\_wont\_revert}} +\def\peekingSumSmcFailureWillRevert {\col{flag\_sum\_smc\_failure\_will\_revert}} +\def\peekingSumSmcFailureWontRevert {\col{flag\_sum\_smc\_failure\_wont\_revert}} +\def\peekingSumSmcSuccessWillRevert {\col{flag\_sum\_smc\_success\_will\_revert}} +\def\peekingSumSmcSuccessWontRevert {\col{flag\_sum\_smc\_success\_wont\_revert}} + +\def\calleeContextInitializationParameters {\col{callee\_context\_params}} diff --git a/hub/instruction_handling/call/approach.tex b/hub/instruction_handling/call/approach.tex new file mode 100644 index 0000000..9d43689 --- /dev/null +++ b/hub/instruction_handling/call/approach.tex @@ -0,0 +1,66 @@ +We explain our general appproach for the instruction processing of \inst{CALL}'s. +The first step in instruction processing is detecting exceptions / proving their absence. +Recall that \inst{CALL}-type instructions can trigger the following exceptions: +\begin{itemize} + \item \suxSH{} + \item \staticxSH{} (may only be triggered by \inst{CALL}) + \item \mxpxSH{} + \item \oogxSH{} +\end{itemize} +The processing we present below, like any instruction processing, applies \emph{if and only if} no \suxSH{} was triggered (as witnessed by the $\stackSux + \stackSox \equiv 0$ precondition.) +The second step in instruction processing (of \emph{unexceptional} \inst{CALL}-type instructions) is detecting aborting conditions / proving their absence. +Recall that a \inst{CALL}-type instruction will be aborted for any of the following reasons +\begin{itemize} + \item \balAbortSH{} + \item \csdAbortSH{} +\end{itemize} +\inst{CALL}-type instructions that make it past these hurdles then undergo specialized processing depending on whether the \inst{CALL} targets an \textbf{externally owned account}, a \textbf{smart contract} or a \textbf{precompile}. +In our arithmetization +\begin{description} + \item[\textsc{Externally owned accounts}] + are characterized by having empty code ($\accHasCode \equiv 0$) and not being a precompile ($\accTrmIsPrecompile \equiv 0$); + \item[\textsc{Smart contracts}] + are characterized by having nonempty code ($\accHasCode \equiv 1$); + \item[\textsc{Precompiles}] + are characterized by raising the a precompile flag (i.e. $\accTrmIsPrecompile \equiv 1$). +\end{description} +Instruction processing beyond that point is either done in a single phase or subdivided two phases. +In more detail: +\begin{itemize} + \item + For \inst{CALL}'s to \textsc{externally owned accounts}' processing happens in one go (i.e. \textbf{one phase}) and culminates in the update of the present execution context's return data (which is reset to being empty $(\,)$). + + The final processing row is a \textbf{context-row}. + \item For \inst{CALL}'s to \textsc{smart contracts}' processing, too, happens in one go (i.e. \textbf{one phase}) and culminates with: + \begin{itemize} + \item Backpropagating certain values pertaining to the success / failure of the child context; + \item Initializating the execution context spawned by the \inst{CALL}; + \item Setting up the first row of the execution of the newly spawned execution environment; + \end{itemize} + See section~(\ref{hub: instruction handling: call: finishing: cases: smc}) for more details. + The final processing row is a \textbf{context-row}. + \item For \inst{CALL}'s to \textsc{precompiles}' processing is subdivided into \textbf{two phases}: + \begin{enumerate} + \item + The first phase is similar to the processing of \inst{CALL}'s to \textsc{eoa}'s and to \textsc{smc}'s and their processing is shared. + However, rather than finishing on a context-row the final row of this phase is a \textbf{scenario-row}, where, among other things, we determine the relevant precompile scenario + + This first phase culminates with a (second) scenario-row where we set, for some positive (scenario-dependent) row offset $\exampleOffset$, + \[ + \left\{ \begin{array}{lcl} + \peekScenario_{i + \exampleOffset} & = & 1 \\ + \scenSomePrecompile _{i + \exampleOffset} & = & 1 \\ + \multicolumn{3}{l}{\!\!\!\! \left. \begin{array}{lcl} + \scenPrcSuccessWillRevert _{i + \exampleOffset} & = & \varepsilon \\ + \scenPrcSuccessWontRevert _{i + \exampleOffset} & = & \varepsilon' \\ + \scenPrcFailureKnownToHub _{i + \exampleOffset} & = & \varepsilon'' \\ + \scenPrcFailureKnownToRam _{i + \exampleOffset} & = & \varepsilon''' \\ + \end{array} \right \} \text{ precisely one is set to $1$.}} + \end{array} \right. + \] + \item + The second phase is entirely determined by the precompile address and the success/failure prediction made on the final row of the first phase. + \end{enumerate} +\end{itemize} +In all cases the first phase deals with detecting exceptions, aborting conditions and updates to accounts (as well as undoing said upates in case of future rollbacks.) +the first phase The precise precompile address being called, as well as the success or failure of the relevant precompile, have diff --git a/hub/instruction_handling/call/bedrock.tex b/hub/instruction_handling/call/bedrock.tex new file mode 100644 index 0000000..5d20e0e --- /dev/null +++ b/hub/instruction_handling/call/bedrock.tex @@ -0,0 +1,44 @@ +We impose the following constraints. +\begin{description} + \item[\underline{Forward setting of \emph{some} \inst{CALL}-scenario:}] + we impose that + \[ + \If + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecCallFlag _{i} & = & 1 \\ + \ct _{i} & = & 0 \\ + \stackSux _{i} + + \stackSux _{i} & = & 0 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \peekScenario _{i + 2} & = & 1 \\ + \scenCallSum _{i + 2} & = & 1 \\ + \end{array} \right. + \] +\end{description} +\saNote{} Recall that \inst{CALL}-type instructions are $\TLI$'s. The above thus sets the first non stack row of such an instruction. + +Conversely we \emph{may} want to impose +\begin{description} + \item[\underline{Backwards setting of the \inst{CALL}-type instruction:}] + we impose that + \[ + \underbrace{\If + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \scenCallSum _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \peekStack _{i - \callFirstStackRowOffset} & = & 1 \\ + \stackDecCallFlag _{i - \callFirstStackRowOffset} & = & 1 \\ + \ct _{i - \callFirstStackRowOffset} & = & 0 \\ + \stackSux _{i - \callFirstStackRowOffset} + + \stackSox _{i - \callFirstStackRowOffset} & = & 0 \\ + \end{array} \right.}_{\displaystyle (\trash)} + \] +\end{description} +\saNote{} +In the upcoming sections the vantage point for dealing with \inst{CALL} instructions will be a row $i$ with $\peekScenario _{i + \callFirstScenarioRowOffset} = 1$ \et $\scenCallSum _{i + \callFirstScenarioRowOffset} = 1$, i.e. a row $i$ representing the first non stack row of a \inst{CALL}-type instruction (which raises no \suxSH{}.) diff --git a/hub/instruction_handling/call/finishing/_inputs.tex b/hub/instruction_handling/call/finishing/_inputs.tex new file mode 100644 index 0000000..3fb9143 --- /dev/null +++ b/hub/instruction_handling/call/finishing/_inputs.tex @@ -0,0 +1,7 @@ +\subsubsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: finishing: cases: intro} \input{instruction_handling/call/finishing/intro} +\subsubsubsection{Finishing touches for exceptional \inst{CALL}'s \lispDone{}} \label{hub: instruction handling: call: finishing: cases: exception} \input{instruction_handling/call/finishing/exception} +\subsubsubsection{Finishing touches for unexceptional, aborted \inst{CALL}'s \lispDone{}} \label{hub: instruction handling: call: finishing: cases: abort} \input{instruction_handling/call/finishing/abort} +\subsubsubsection{Finishing touches for \inst{CALL}'s to externally owned accounts \lispDone{}} \label{hub: instruction handling: call: finishing: cases: eoa} \input{instruction_handling/call/finishing/eoa} +\subsubsubsection{Finishing touches for \inst{CALL}'s to smart contracts \lispDone{}} \label{hub: instruction handling: call: finishing: cases: smc} \input{instruction_handling/call/finishing/smc} +\subsubsubsection{Setting up the second phase of \inst{CALL}'s to precompiles \lispDone{}} \label{hub: instruction handling: call: finishing: cases: prc} \input{instruction_handling/call/finishing/prc} +\subsubsubsection{Loose ends \lispDone{}} \label{hub: instruction handling: call: finishing: cases: prc} \input{instruction_handling/call/finishing/loose_ends} diff --git a/hub/instruction_handling/call/finishing/abort.tex b/hub/instruction_handling/call/finishing/abort.tex new file mode 100644 index 0000000..ffbe22b --- /dev/null +++ b/hub/instruction_handling/call/finishing/abort.tex @@ -0,0 +1,57 @@ +\begin{center} + \boxed{% + \text{The constraints below apply whenever } + \left\{ \begin{array}{lclr} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & \one \\ + \scenCallAbort _{i + \callFirstScenarioRowOffset} & = & \one & (\trash) \\ + \end{array} \right.} +\end{center} +We update the current execution context's return data. +The current execution context receives empty return data. +\begin{description} + \item[\underline{The \textsc{revert}ed case:}] + \If $\scenCallAbortWillRevert _{i + \callFirstScenarioRowOffset} = 1$ \Then we undo the warmth udpate and reset the \callerr's return data: + \begin{description} + \item[\underline{Account-row $n^°(i + \callSecondCalleeAccountRowOffsetAbortWillRevert)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameBalance {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}} \\ + %%%% + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\callSecondCalleeAccountRowOffsetAbortWillRevert}} \\ + \accRomLexFlag _{i + \callSecondCalleeAccountRowOffsetAbortWillRevert} & = & 0 \\ + \accTrmFlag _{i + \callSecondCalleeAccountRowOffsetAbortWillRevert} & = & 0 \\ + \accRlpAddrFlag _{i + \callSecondCalleeAccountRowOffsetAbortWillRevert} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \callSecondCalleeAccountRowOffsetAbortWillRevert, + subOffset = 2, + } + } \\ + \end{array} \right. + \] + \item[\underline{Context-row $n^°(i + \callAbortWillRevertUpdateCurrentContextRowOffset)$:}] + we impose that + \[ + \nonContextProvidesEmptyReturnData + {i}{\callAbortWillRevertUpdateCurrentContextRowOffset} + \] + \end{description} + \item[\underline{The un\textsc{revert}ed case:}] + \If $\scenCallAbortWontRevert _{i + \callFirstScenarioRowOffset} = 1$ \Then we reset the \callerr's return data: + \begin{description} + \item[\underline{Context-row $n^°(i + \callAbortWontRevertUpdateCurrentContextRowOffset)$:}] + we impose that + \[ + \nonContextProvidesEmptyReturnData + {i}{\callAbortWontRevertUpdateCurrentContextRowOffset} + \] + \end{description} +\end{description} diff --git a/hub/instruction_handling/call/finishing/eoa.tex b/hub/instruction_handling/call/finishing/eoa.tex new file mode 100644 index 0000000..5315b37 --- /dev/null +++ b/hub/instruction_handling/call/finishing/eoa.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{% + \text{The constraints below apply whenever } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & \one \\ + \scenCallEoa _{i + \callFirstScenarioRowOffset} & = & \one \quad (\trash) \\ + \end{array} \right.} +\end{center} +We indicate $\scenCallEoa \equiv 1$ only for greater clarity but it should be omitted from implementations. +Indeed, all constraints below are guarded by a more stringent precondition. +We update the current execution context's return data. +The current execution context receives empty return data. +We must differentiate between reverted \inst{CALL}'s and unreverted ones. +\begin{description} + \item[\underline{The reverted case: account-row $n^°(i + \callEoaWillRevertCallerContextRowOffset)$:}] + \If $\scenCallEoaSuccessWillRevert_{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \nonContextProvidesEmptyReturnData + {i}{\callEoaWillRevertCallerContextRowOffset} + \] + \item[\underline{The unreverted case: account-row $n^°(i + \callEoaWontRevertCallerContextRowOffset)$:}] + \If $\scenCallEoaSuccessWontRevert_{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \nonContextProvidesEmptyReturnData + {i}{\callEoaWontRevertCallerContextRowOffset} + \] +\end{description} diff --git a/hub/instruction_handling/call/finishing/exception.tex b/hub/instruction_handling/call/finishing/exception.tex new file mode 100644 index 0000000..7b61abf --- /dev/null +++ b/hub/instruction_handling/call/finishing/exception.tex @@ -0,0 +1,36 @@ +\begin{center} + \boxed{% + \text{The constraints below apply whenever } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & \one \\ + \scenCallException _{i + \callFirstScenarioRowOffset} & = & \one \\ + \end{array} \right.} +\end{center} +We update the current execution context's parent context's return data. +We must differentiate between the \oogxSH{} case and others. +\begin{description} + \item[\underline{The ``no \staticxSH{}'' case:}] + \If $\locStaticx = 1$ \Then + we impose that + \[ + \executionProvidesEmptyReturnData + {i}{\callStaticxUpdateParentContextRowOffset} + \quad (\trash) + \] + \item[\underline{The ``no \oogxSH{}'' case:}] + \If $\locMxpx = 1$ \Then + we impose that + \[ + \executionProvidesEmptyReturnData + {i}{\callMxpxUpdateParentContextRowOffset} + \quad (\trash) + \] + \item[\underline{The ``\oogxSH{}'' case:}] + \If $\locOogx = 1$ \Then + we impose that + \[ + \executionProvidesEmptyReturnData + {i}{\callOogxUpdateParentContextRowOffset} + \quad (\trash) + \] +\end{description} diff --git a/hub/instruction_handling/call/finishing/intro.tex b/hub/instruction_handling/call/finishing/intro.tex new file mode 100644 index 0000000..ed6c95c --- /dev/null +++ b/hub/instruction_handling/call/finishing/intro.tex @@ -0,0 +1,3 @@ +The present section describes +(\emph{a}) the last row of all of the \textbf{non precompile} \inst{CALL}-scenarios (a \textbf{context-row}, always) +(\emph{b}) the last row of the first phase of \textbf{precompile} \inst{CALL}-scenarios (a \textbf{scenario-row}, always). diff --git a/hub/instruction_handling/call/finishing/loose_ends.tex b/hub/instruction_handling/call/finishing/loose_ends.tex new file mode 100644 index 0000000..6c686c7 --- /dev/null +++ b/hub/instruction_handling/call/finishing/loose_ends.tex @@ -0,0 +1,10 @@ +The above leaves several constraint systems and parameters undefined. Definitions will follow, in particular +\begin{itemize} + \item $\justifyCalleeRevertData {i}{\relof}$ is defined in section~(\ref{hub: instruction handling: call: specialized: callee revert data}) + \item $\initializeCalleeContextName _{i} \big[ \relof \big]$ is defined in section~(\ref{hub: instruction handling: call: specialized: initializing callee}) + \item $\firstRowOfCallee {i}{\relof}$ is defined in section~(\ref{hub: instruction handling: call: specialized: first row of callee}) + \item $\precompileScenarioRow {i}{\relof}$ is defined in section~(\ref{hub: instruction handling: call: specialized: specialized precompile scenario row}) + \item the parameter set $\calleeContextInitializationParameters$ is defined in section~(\ref{hub: instruction handling: call: specialized: callee context parameters definition}) +\end{itemize} +Furthermore a gaping hole remains for the treatment of precompiles. +We begin our treatment of (unexceptional, unaborted) \inst{CALL}'s to \textbf{precompiles} in section~(\ref{hub: instruction handling: call: precompile memory operations}). diff --git a/hub/instruction_handling/call/finishing/prc.tex b/hub/instruction_handling/call/finishing/prc.tex new file mode 100644 index 0000000..0cdbdcc --- /dev/null +++ b/hub/instruction_handling/call/finishing/prc.tex @@ -0,0 +1,17 @@ +\begin{center} + \boxed{% + \text{The constraints below apply whenever } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & \one \\ + \scenCallPrc _{i + \callFirstScenarioRowOffset} & = & \one \quad (\trash) \\ + \end{array} \right.} +\end{center} +We indicate $\scenCallPrc \equiv 1$ only for greater clarity but it should be omitted from implementations. +Indeed, the constraints below are guarded by a more stringent precondition (the relevant \inst{CALL}-scenario.) +The purpose of this section is to set the second scenario row associated with a \inst{CALL} to a precompile. +We impose that +\begin{enumerate} + \item \If $\scenCallPrcFailure _{i + \callFirstScenarioRowOffset} = \one$ \Then \[ \precompileScenarioRow {i}{\callPrcFailureSecondScenarioRowOffset } \] + \item \If $\scenCallPrcSuccessWillRevert_{i + \callFirstScenarioRowOffset} = \one$ \Then \[ \precompileScenarioRow {i}{\callPrcSuccessWillRevertSecondScenarioRowOffset} \] + \item \If $\scenCallPrcSuccessWontRevert_{i + \callFirstScenarioRowOffset} = \one$ \Then \[ \precompileScenarioRow {i}{\callPrcSuccessWontRevertSecondScenarioRowOffset} \] +\end{enumerate} diff --git a/hub/instruction_handling/call/finishing/smc.tex b/hub/instruction_handling/call/finishing/smc.tex new file mode 100644 index 0000000..20ec1fd --- /dev/null +++ b/hub/instruction_handling/call/finishing/smc.tex @@ -0,0 +1,68 @@ +\begin{center} + \boxed{% + \text{The constraints below apply whenever } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & \one \\ + \scenCallSmc _{i + \callFirstScenarioRowOffset} & = & \one \quad (\trash) \\ + \end{array} \right.} +\end{center} +We indicate $\scenCallSmc \equiv 1$ only for greater clarity but it should be omitted from implementations. +Indeed, all constraints below are guarded by a more stringent precondition. + +The purpose of this section is to +\begin{itemize} + \item funnel some ``callee context revert data (i.e. justifying $\miscChildSelfReverts$ and $\miscChildRevertStamp$)'' \emph{back} to the current set of rows through some $\initializeContextName$ constraint; + \item initialize the callee context through some $\initializeContextName$ constraint; + \item set up some parameters on the first row of the new execution context through some $\firstRowOfCallee {i}{\relof}$ constraint; +\end{itemize} +We thus impose the following constraints: +\begin{enumerate} + \item \If $\scenCallSmcFailureWillRevert_{i + \callFirstScenarioRowOffset} = \one$ \Then + \[ + \left\{ \begin{array}{lcl} + \justifyCalleeRevertData {i}{\callSmcFailureWillRevertInitializeCalleeContextRowOffset} \\ + \initializeCalleeContext { + anchorRow = i, + relOffset = \callSmcFailureWillRevertInitializeCalleeContextRowOffset, + initializationParameters = \calleeContextInitializationParameters, + } \\ + \firstRowOfCallee {i}{\callSmcFailureWillRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right. + \] + \item \If $\scenCallSmcFailureWontRevert_{i + \callFirstScenarioRowOffset} = \one$ \Then + \[ + \left\{ \begin{array}{lcl} + \justifyCalleeRevertData {i}{\callSmcFailureWontRevertInitializeCalleeContextRowOffset} \\ + \initializeCalleeContext { + anchorRow = i, + relOffset = \callSmcFailureWontRevertInitializeCalleeContextRowOffset, + initializationParameters = \calleeContextInitializationParameters, + } \\ + \firstRowOfCallee {i}{\callSmcFailureWontRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right. + \] + \item \If $\scenCallSmcSuccessWillRevert_{i + \callFirstScenarioRowOffset} = \one$ \Then + \[ + \left\{ \begin{array}{lcl} + \justifyCalleeRevertData {i}{\callSmcSuccessWillRevertInitializeCalleeContextRowOffset} \\ + \initializeCalleeContext { + anchorRow = i, + relOffset = \callSmcSuccessWillRevertInitializeCalleeContextRowOffset, + initializationParameters = \calleeContextInitializationParameters, + } \\ + \firstRowOfCallee {i}{\callSmcSuccessWillRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right. + \] + \item \If $\scenCallSmcSuccessWontRevert_{i + \callFirstScenarioRowOffset} = \one$ \Then + \[ + \left\{ \begin{array}{l} + \justifyCalleeRevertData {i}{\callSmcSuccessWontRevertInitializeCalleeContextRowOffset} \\ + \initializeCalleeContext { + anchorRow = i, + relOffset = \callSmcSuccessWontRevertInitializeCalleeContextRowOffset, + initializationParameters = \calleeContextInitializationParameters, + } \\ + \firstRowOfCallee {i}{\callSmcSuccessWontRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/hub/instruction_handling/call/flag_sums_for_precompiles_partial.tex b/hub/instruction_handling/call/flag_sums_for_precompiles_partial.tex new file mode 100644 index 0000000..c69e8a1 --- /dev/null +++ b/hub/instruction_handling/call/flag_sums_for_precompiles_partial.tex @@ -0,0 +1,37 @@ +We provide some \textbf{partial peeking flag sums for precompiles} below. +We can't precisely predict the number of required rows at this point in time. +We will be setting \nonStackRows{} and associated peeking flag sums on the scenario row that marks the end of the first half of peeking flags for \inst{CALL}'s to precompiles. +This will be achieved in +section~(\ref{hub: instruction handling: call: precompiles: generalities}) and +section~(\ref{hub: instruction handling: call: precompiles: flag sums and nsr}). +\begin{description} + \item[\underline{Precompile failure:}] + \[ + \peekingSumPrcFailureFH + \define + \left[ \begin{array}{lcl} + + & \extendedPeekingSumForCalls \\ + + & \peekScenario _{i + \callPrcFailureSecondScenarioRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Precompile success, current context will revert:}] + \[ + \peekingSumPrcSuccessWillRevertFH + \define + \left[ \begin{array}{lcl} + + & \extendedPeekingSumForCalls \\ + + & \peekAccount _{i + \callSecondCallerAccountRowOffset} \\ + + & \peekAccount _{i + \callSecondCalleeAccountRowOffset} \\ + + & \peekScenario _{i + \callPrcSuccessWillRevertSecondScenarioRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Precompile success, current context won't revert:}] + \[ + \peekingSumPrcSuccessWontRevertFH + \define + \left[ \begin{array}{lcl} + + & \extendedPeekingSumForCalls \\ + + & \peekScenario _{i + \callPrcSuccessWontRevertSecondScenarioRowOffset} \\ + \end{array} \right] + \] +\end{description} diff --git a/hub/instruction_handling/call/flag_sums_no_precompiles.tex b/hub/instruction_handling/call/flag_sums_no_precompiles.tex new file mode 100644 index 0000000..44f803a --- /dev/null +++ b/hub/instruction_handling/call/flag_sums_no_precompiles.tex @@ -0,0 +1,153 @@ +We centralize in this section \textbf{most} computations relative to the number of non-stack-rows and the associated peeking flags. +We exclude the case of (unexceptional, unaborted) \inst{CALL}'s to \textbf{precompiles}. +Those scenarios take more care and depend on various factors, including which precompile is being executed. + +We start by defining a series of peeking flag shorthands: +\begin{description} + \item[\underline{Standard and extended \inst{CALL} flag prefixes:}] + we define + \[ + \left\{ \begin{array}{lcl} + \standardPeekingSumForCalls & \define & + \left[ \begin{array}{cr} + + & \peekScenario _{i + \callFirstScenarioRowOffset} \\ + + & \peekContext _{i + \callCurrentContextRowOffset} \\ + + & \peekMisc _{i + \callMiscRowOffset} \\ + \end{array} \right] + \vspace{2mm} \\ + \extendedPeekingSumForCalls & \define & + \left[ \begin{array}{cr} + + & \standardPeekingSumForCalls \\ + + & \peekAccount _{i + \callFirstCallerAccountRowOffset} \\ + + & \peekAccount _{i + \callFirstCalleeAccountRowOffset} \\ + \end{array} \right] + \\ + \end{array} \right. + \] + \item[\underline{Exception: \staticxSH{}:}] + we define + \[ + \peekingSumStaticx + \define + \left[ \begin{array}{cr} + + & \standardPeekingSumForCalls \\ + + & \peekContext _{i + \callStaticxUpdateParentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Exception: \mxpxSH{}:}] + we define + \[ + \peekingSumMxpx + \define + \left[ \begin{array}{cr} + + & \standardPeekingSumForCalls \\ + + & \peekContext _{i + \callMxpxUpdateParentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Exception: \oogxSH{}:}] + we define + \[ + \peekingSumOogx + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekContext _{i + \callOogxUpdateParentContextRowOffset} \\ + \end{array} \right] + \] + \saNote{} + There is, \emph{a priori}, no necessity to load two account-rows to justify an \oogxSH{}. + Loading the callee account is sufficient. + From that single account we are able to determine whether the callee \textbf{exists} and whether it is \textbf{warm} or not. + Yet we load both the caller and callee accounts as this makes our treatment of account rows more uniform. + The cost is an extraeneous account row for the rare \inst{CALL}-instruction which raises an \oogxSH{} (and no other exception.) + \item[\underline{Aborted call, caller context will revert:}] + we define + \[ + \peekingSumAbortWillRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekAccount _{i + \callSecondCalleeAccountRowOffsetAbortWillRevert} \\ + + & \peekContext _{i + \callAbortWillRevertUpdateCurrentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Aborted call, caller context won't revert:}] + we define + \[ + \peekingSumAbortWontRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekContext _{i + \callAbortWontRevertUpdateCurrentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{(Successful) call to Externally Owned Account, caller context will revert:}] + we define + \[ + \peekingSumEoaWillRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekAccount _{i + \callSecondCallerAccountRowOffset} \\ + + & \peekAccount _{i + \callSecondCalleeAccountRowOffset} \\ + + & \peekContext _{i + \callEoaWillRevertCallerContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{(Successful) call to Externally Owned Account, caller context won't revert:}] + we define + \[ + \peekingSumEoaWontRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekContext _{i + \callEoaWontRevertCallerContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Smart contract call failure, caller context will revert:}] + we define + \[ + \peekingSumSmcFailureWillRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekAccount _{i + \callSecondCallerAccountRowOffset} \\ + + & \peekAccount _{i + \callSecondCalleeAccountRowOffset} \\ + + & \peekAccount _{i + \callThirdCalleeAccountRowOffset} \\ + + & \peekContext _{i + \callSmcFailureWillRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Smart contract call failure, caller context won't revert:}] + we define + \[ + \peekingSumSmcFailureWontRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekAccount _{i + \callSecondCallerAccountRowOffset} \\ + + & \peekAccount _{i + \callSecondCalleeAccountRowOffset} \\ + + & \peekContext _{i + \callSmcFailureWontRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Smart contract call success, caller context will revert:}] + we define + \[ + \peekingSumSmcSuccessWillRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekAccount _{i + \callSecondCallerAccountRowOffset} \\ + + & \peekAccount _{i + \callSecondCalleeAccountRowOffset} \\ + + & \peekContext _{i + \callSmcSuccessWillRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Smart contract call success, caller context won't revert:}] + we define + \[ + \peekingSumSmcSuccessWontRevert + \define + \left[ \begin{array}{cr} + + & \extendedPeekingSumForCalls \\ + + & \peekContext _{i + \callSmcSuccessWontRevertInitializeCalleeContextRowOffset} \\ + \end{array} \right] + \] +\end{description} diff --git a/hub/instruction_handling/call/flags.tex b/hub/instruction_handling/call/flags.tex new file mode 100644 index 0000000..8872acf --- /dev/null +++ b/hub/instruction_handling/call/flags.tex @@ -0,0 +1,20 @@ +\[ + \begin{array}{|l||c||c|c|c|c|c|} \hline + \INST & \tli & \stackDecCallFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} \\ \hline\hline + \inst{CALL} & \oneCell & \oneCell & \oneCell & \zero & \zero & \zero \\ \hline + \inst{CALLCODE} & \oneCell & \oneCell & \zero & \oneCell & \zero & \zero \\ \hline + \inst{DELEGATECALL} & \oneCell & \oneCell & \zero & \zero & \oneCell & \zero \\ \hline + \inst{STATICCALL} & \oneCell & \oneCell & \zero & \zero & \zero & \oneCell \\ \hline + \end{array} +\] + +\[ + \begin{array}{|l||c|c|} \hline + \INST & \decStaticInst & \stackDecMxpFlag \\ \hline\hline + \inst{CALL} & \oneCell & \oneCell \\ \hline + \inst{CALLCODE} & \zero & \oneCell \\ \hline + \inst{DELEGATECALL} & \zero & \oneCell \\ \hline + \inst{STATICCALL} & \zero & \oneCell \\ \hline + \end{array} +\] +\saNote{} Within the instructions which raise the $\stackDecCallFlag$ the decoded flags $\decFlag{k}$, $k = 1, 2, 3, 4$, uniquely identify all different instructions. diff --git a/hub/instruction_handling/call/generalities/_inputs.tex b/hub/instruction_handling/call/generalities/_inputs.tex new file mode 100644 index 0000000..02e6830 --- /dev/null +++ b/hub/instruction_handling/call/generalities/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsubsection{Graphical representation \lispNone{}} \label{hub: instruction handling: call: generalities} \input{instruction_handling/call/generalities/lua/_inputs} +\subsubsubsection{Universal constraints for \inst{CALL}'s \lispDone{}} \label{hub: instruction handling: call: generalities} \input{instruction_handling/call/generalities/universal} +\subsubsubsection{First set of account-rows \lispDone{}} \label{hub: instruction handling: call: first set of account rows} \input{instruction_handling/call/generalities/account_rows_first_set} +\subsubsubsection{Second set of account-rows \lispDone{}} \label{hub: instruction handling: call: second set of account rows} \input{instruction_handling/call/generalities/account_rows_second_set} +\subsubsubsection{Third set of account-rows \lispDone{}} \label{hub: instruction handling: call: third set of account rows} \input{instruction_handling/call/generalities/account_rows_third_set} diff --git a/hub/instruction_handling/call/generalities/account_rows_first_set.tex b/hub/instruction_handling/call/generalities/account_rows_first_set.tex new file mode 100644 index 0000000..1ce076e --- /dev/null +++ b/hub/instruction_handling/call/generalities/account_rows_first_set.tex @@ -0,0 +1,92 @@ +\begin{center} + \boxed{% + \text{The constraints presented below require that } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \scenCallSum _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \locOogx + \scenCallUnexceptional _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \end{array} \right. + } +\end{center} +In the present section we describe the various account operations that are required a \inst{CALL}-type instruction depending on the scenario. +\begin{description} + \item[\underline{First \callerr{} account-row $n^°(i + \callFirstCallerAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \accAddressHi _{i + \callFirstCallerAccountRowOffset} & = & \locCurrentAddressHi \\ + \accAddressLo _{i + \callFirstCallerAccountRowOffset} & = & \locCurrentAddressLo \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\callFirstCallerAccountRowOffset}} \\ + %%%% + \accRomLexFlag _{i + \callFirstCallerAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \callFirstCallerAccountRowOffset} & = & 0 \\ + \accRlpAddrFlag _{i + \callFirstCallerAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \callFirstCallerAccountRowOffset, + domOffset = 0, + } + } \\ + \end{array} \right. + \] + \item[\underline{Setting the \callerr{} balance operation on account-row $n^°(i + \callFirstCallerAccountRowOffset)$:}] + we impose that + \begin{enumerate} + \item \If $\scenCallBalanceUpdateNotRequired _{i} = 1$ \Then + \[ + \accSameBalance + {i}{\callFirstCallerAccountRowOffset} + \] + \item \If $\scenCallBalanceUpdateRequired _{i} = 1$ \Then + \[ + \accDecrementBalance + {i}{\callFirstCallerAccountRowOffset}{\locValueLo} + \] + \end{enumerate} + \item[\underline{First \calleee{} account-row $n^°(i + \callFirstCalleeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \accAddressHi _{i + \callFirstCalleeAccountRowOffset} & = & \relevantValue \\ + \accAddressLo _{i + \callFirstCalleeAccountRowOffset} & = & \locRawAddressLo \\ + \accTrmRawAddrHi _{i + \callFirstCalleeAccountRowOffset} & = & \locRawAddressLo \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\callFirstCalleeAccountRowOffset}} \\ + %%%% + \accRomLexFlag _{i + \callFirstCalleeAccountRowOffset} & = & \scenCallSmc _{i} \\ + \accTrmFlag _{i + \callFirstCalleeAccountRowOffset} & = & \rOne \\ + \accRlpAddrFlag _{i + \callFirstCalleeAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \callFirstCalleeAccountRowOffset, + domOffset = 1, + } + } \\ + \end{array} \right. + \] + \item[\underline{Setting the \calleee{} balance operation on account-row $n^°(i + \callFirstCalleeAccountRowOffset)$:}] + we impose that + \begin{enumerate} + \item \If $\scenCallBalanceUpdateNotRequired _{i} = 1$ \Then $\accSameBalance {i}{\callFirstCalleeAccountRowOffset}$ + \item \If $\scenCallBalanceUpdateRequired _{i} = 1$ \Then $\accIncrementBalance {i}{\callFirstCalleeAccountRowOffset}{\locValueLo}$ + \end{enumerate} + \item[\underline{Setting the \calleee{} warmth update on account-row $n^°(i + \callFirstCalleeAccountRowOffset)$:}] + we impose that + \begin{enumerate} + \item \If $\scenCallCalleeWarmthUpdateNotRequired _{i} = 1$ \Then $\accSameWarmth {i}{\callFirstCalleeAccountRowOffset}$ + \item \If $\scenCallCalleeWarmthUpdateRequired _{i} = 1$ \Then $\accTurnOnWarmth {i}{\callFirstCalleeAccountRowOffset}$ + \end{enumerate} +\end{description} diff --git a/hub/instruction_handling/call/generalities/account_rows_second_set.tex b/hub/instruction_handling/call/generalities/account_rows_second_set.tex new file mode 100644 index 0000000..048a229 --- /dev/null +++ b/hub/instruction_handling/call/generalities/account_rows_second_set.tex @@ -0,0 +1,148 @@ +\begin{center} + \boxed{% + \text{The constraints presented below require that } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \scenCallRequiresBothAccountsTwice _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \end{array} \right. + } +\end{center} +When a to +a (successful) \inst{CALL} to precompile is (eventually) reverted, +a pure transfer to an externally owned account is eventually reverted, +a \inst{CALL} to a smartcontract is (eventually) unsuccessful or +a \inst{CALL} to a smartcontract is successful but later on execution is reverted +certain account operations must be undone. +This undoing operation pertains to +(\emph{a}) the value transfer, both for the caller and callee, +(\emph{b}) the warmth update of the callee. +\begin{description} + \item[\underline{Account-row $n^°(i + \callSecondCallerAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\callSecondCallerAccountRowOffset}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\callSecondCallerAccountRowOffset}{\callFirstCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\callSecondCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\callSecondCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\callSecondCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\callSecondCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\callSecondCallerAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\callSecondCallerAccountRowOffset}} \\ + %%%% + \accRomLexFlag _{i + \callSecondCallerAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \callSecondCallerAccountRowOffset} & = & 0 \\ + \accRlpAddrFlag _{i + \callSecondCallerAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + % \multicolumn{3}{l}{ + % \standardDomSubStamps { + % anchorRow = i, + % relOffset = \callSecondCallerAccountRowOffset, + % domOffset = 2, + % } + % } \\ + \end{array} \right. + \] + \item[] + we impose that + \begin{enumerate} + \item \If $\scenCallBalanceUpdateUndoneWithCalleeFailure _{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \revertWithChildFailureDomSubStamps { + anchorRow = i, + relOffset = \callSecondCallerAccountRowOffset, + childRevertStamp = \locCalleeRevertStamp, + subOffset = 2, + } + \] + \item \If $\scenCallBalanceUpdateUndoneWithCallerRevert _{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \revertDomSubStamps { + anchorRow = i, + relOffset = \callSecondCallerAccountRowOffset, + subOffset = 2, + } + % \revertDomSubStamps {i}{\callSecondCallerAccountRowOffset} + \] + \end{enumerate} + \item[\underline{Account-row $n^°(i + \callSecondCalleeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\callSecondCalleeAccountRowOffset}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\callSecondCalleeAccountRowOffset}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\callSecondCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\callSecondCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\callSecondCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\callSecondCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\callSecondCalleeAccountRowOffset}} \\ + %%%% + \accRomLexFlag _{i + \callSecondCalleeAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \callSecondCalleeAccountRowOffset} & = & 0 \\ + \accRlpAddrFlag _{i + \callSecondCalleeAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + % \multicolumn{3}{l}{ + % \standardDomSubStamps { + % anchorRow = i, + % relOffset = \callSecondCalleeAccountRowOffset, + % domOffset = 3, + % } + % } \\ + \end{array} \right. + \] + \item[\underline{Setting the balance and warmth operation on account-row $n^°(i + \callSecondCalleeAccountRowOffset)$:}] + we impose that + \begin{enumerate} + \item \If $\scenCallBalanceUpdateUndoneWithCalleeFailure _{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \revertWithChildFailureDomSubStamps { + anchorRow = i , + relOffset = \callSecondCalleeAccountRowOffset , + childRevertStamp = \locCalleeRevertStamp , + subOffset = 3 , + } \\ + \accSameWarmth {i}{\callSecondCalleeAccountRowOffset} \\ + \end{array} \right. + % \revertWithChildFailureDomSubStamps {i}{\callSecondCallerAccountRowOffset} + \] + \saNote{} + For \scenCallSmcFailureWillRevert{} (which is one of the two subcases of the above) warmth \textbf{will} be reverted but with the caller reverting (not with failure of the child context, see section~(\ref{hub: instruction handling: call: third set of account rows}). + \item \If $\scenCallBalanceUpdateUndoneWithCallerRevert _{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \revertDomSubStamps { + anchorRow = i , + relOffset = \callSecondCalleeAccountRowOffset , + subOffset = 3 , + } \\ + \accUndoWarmthUpdate {i}{\callSecondCalleeAccountRowOffset}{\callFirstCalleeAccountRowOffset} \\ + \end{array} \right. + \] + \end{enumerate} +\end{description} + +\noindent Table~(\ref{hub: instruction handling: call: generalities: fig: when to revert warmth and balance}) below subsumes when these operations must be undone: +\begin{figure} + \begin{center} + % \hspace*{-2cm} + \renewcommand{\arraystretch}{1.5} + \begin{tabular}{|l|l|} + \hline + \inst{CALL}-scenario & Callee account actions \\ \hline \hline + \scenCallEoaSuccessWillRevert & \undoSignifier{} balance update with \textcolor{draculapurple}{caller revert} \\ + & \undoSignifier{} warmth update with \textcolor{draculapurple}{caller revert} \\ \hline \hline + \scenCallSmcFailureWillRevert & \undoSignifier{} balance update with \textcolor{draculaorange}{child failure} \\ + & \undoSignifier{} warmth update with \textcolor{draculapurple}{caller revert} \\ \hline + \scenCallSmcFailureWontRevert & \undoSignifier{} balance update with \textcolor{draculaorange}{child failure} \\ + & \sameSignifier{} warmth as after initial update \\ \hline + \scenCallSmcSuccessWillRevert & \undoSignifier{} balance update with \textcolor{draculapurple}{caller revert} \\ + & \undoSignifier{} warmth update with \textcolor{draculapurple}{caller revert} \\ \hline \hline + \scenCallPrcSuccessWillRevert & \undoSignifier{} balance update with \textcolor{draculapurple}{caller revert} \\ \hline + \end{tabular} + \caption{Observe that there is \textbf{no undoing of the warmth update} in the \scenCallPrcSuccessWillRevert{} case. Precompiles are (constrained to be) perpetually warm in our arithmetization, see section~(\ref{hub: consistencies: account}).} + \label{hub: instruction handling: call: generalities: fig: when to revert warmth and balance} + \end{center} +\end{figure} + diff --git a/hub/instruction_handling/call/generalities/account_rows_third_set.tex b/hub/instruction_handling/call/generalities/account_rows_third_set.tex new file mode 100644 index 0000000..4ce1874 --- /dev/null +++ b/hub/instruction_handling/call/generalities/account_rows_third_set.tex @@ -0,0 +1,41 @@ +\begin{center} + \boxed{% + \text{The constraints presented below require that } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \scenCallSmcFailureWillRevert _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \end{array} \right. + } +\end{center} +The present section finishes the ``reverting/undoing'' of \textbf{callee} account operations in the +\[ + \scenCallSmcFailureWillRevert +\] +case. What remains to be done is to undo the warmth update induced by the underlying \inst{CALL}-instruction. +\begin{description} + \item[\underline{Account-row $n^°(i + \callThirdCalleeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\callThirdCalleeAccountRowOffset}{\callSecondCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameBalance {i}{\callThirdCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\callThirdCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\callThirdCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\callThirdCalleeAccountRowOffset}{\callFirstCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\callThirdCalleeAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\callThirdCalleeAccountRowOffset}} \\ + %%%% + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\callThirdCalleeAccountRowOffset}} \\ + \accRomLexFlag _{i + \callThirdCalleeAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \callThirdCalleeAccountRowOffset} & = & 0 \\ + \accRlpAddrFlag _{i + \callThirdCalleeAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \callThirdCalleeAccountRowOffset, + subOffset = 4, + } + } \\ + \end{array} \right. + \] +\end{description} diff --git a/hub/instruction_handling/call/generalities/lua/_inputs.tex b/hub/instruction_handling/call/generalities/lua/_inputs.tex new file mode 100644 index 0000000..b4d73b3 --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/_inputs.tex @@ -0,0 +1,6 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/generalities/lua/exceptions/staticx.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/generalities/lua/exceptions/mxpx.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/generalities/lua/exceptions/oogx.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/generalities/lua/abort/will_revert.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/generalities/lua/abort/wont_revert.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/generalities/lua/entry.pdf} diff --git a/hub/instruction_handling/call/generalities/lua/abort/will_revert.lua.tex b/hub/instruction_handling/call/generalities/lua/abort/will_revert.lua.tex new file mode 100644 index 0000000..a91faca --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/abort/will_revert.lua.tex @@ -0,0 +1,153 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ██████\ ██\ ██\ ██\ + ██ __██\ ██ __██\ ██ | ██ | ██ | + ██ / \__|██ / ██ |██ | ██ | ██████\ ██\ ██\ ██████\ ██████\ + ██ | ████████ |██ | ██ |██████\\_██ _| ██ | ██ |██ __██\ ██ __██\ + ██ | ██ __██ |██ | ██ |\______| ██ | ██ | ██ |██ / ██ |████████ | + ██ | ██\ ██ | ██ |██ | ██ | ██ |██\ ██ | ██ |██ | ██ |██ ____| + \██████ |██ | ██ |████████\ ████████\ \████ |\███████ |███████ |\███████\ + \______/ \__| \__|\________|\________| \____/ \____██ |██ ____/ \_______| + ██\ ██ |██ | + \██████ |██ | + \______/ \__| + + + | | + _` | __ \ _ \ __| __| + ( | | | ( | | | + \__,_| _.__/ \___/ _| \__| + + _) | | | + \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + \ \ \ / | | | | __/ \ \ / __/ | | + \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+---------------+-----------| +| Row index | Persp. | Actions | | | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+---------------+-----------| +| i - 2 | STACK | | | | required: | +| i - 1 | STACK | | | | * stack/STATICX ≡ 0 | +|   | | | | | * stack/MXPX ≡ 0 | +|   | | | | | * stack/OOGX ≡ 0 | +|   | | | | | . => XAHOY ≡ 0 | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i  | SCEN |  CALL/unexceptional ≡ 1 👋 | | | | +|   | | ^^^^^^^^^^^^^^^^^^^^^^^^ | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | .  CALL/EXCEPTION ≡ XAHOY | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | . context/IS_STATIC | +|   | | | | | . context/CALL_STACK_DEPTH | +|   | | | | | . context/ACCOUNT_ADDRESS | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 2 | MISC | misc/OOB🚩 ≡ is_CALL | | | | +|   | | misc/OOB_INST ≡ OOB_INST_call 👋 | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * OOB_nonzero_value | +|   | | | | | * OOB_aborting_condition | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | | +|   | | | | | . stack/STATICX ≡ is_CALL | +|   | | | | | . ∧ OOB_nonzero_value | +|   | | | | | . ∧ context/IS_STATIC | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | | .  CALL/abort ≡ OOB_aborting_condition | +|   | | | | | . ≡ 1 👋 | +|   | | | | | | +|   | | | | | .  CALL/ABORT_WILL_REVERT | +|   | | | | | . ≡ CONTEXT_WILL_REVERT | +|   | | | | | . ≡ 1 👋 | +|   | | | | | | +|   | | | misc/MXP🚩 ≡ 1 | | | +|   | | | misc/MXP_INST ≡ MXP_INST_TYPE_5 | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/MXP_MXPX <== MXPX_memory_expansion_exception | +|   | | | | | * misc/MXP_GAS <== MXPX_memory_expansion_gas | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/MXPX ≡ MXPX_memory_expansion_exception | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | misc/STP🚩 ≡ 1 | | +|   | | | | misc/STP_INST ≡ stack/INSTRUCTION | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/STP_UPFRONT_GAS_COST | +|   | | | | | * misc/STP_OOGX | +|   | | | | | * misc/STP_GAS_POOP | +|   | | | | | * misc/STP_GAS_STPD | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/OOGX ≡ misc/STP_OOGX | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+---------------+-----------| +| i + 3 | ACC | read( context/ACCOUNT_ADDRESS ) | | | | τ ∙ h + 0 | 0 | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/BALANCE | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+---------------+-----------| +| i + 4 | ACC | acc/TRM🚩 ≡ 1 | | | | τ ∙ h + 1 | 0 | +|   | | ecc/ROM_LEX🚩 ≡ 0 | | | | | | +|   | | read( trimmed_target_address ) 👋 | | | | | | +|   | | [4]turnOnWarmth (i.e. warmth ↑) 👋 | | | | | | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/ADDRESS_HI (<== trimmed high part) | | | +|   | | | | | * acc/HAS_CODE | | | +|   | | | | | * acc/EXISTS | | | +|   | | | | | * acc/IS_PRECOMPILE | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+---------------+-----------| +| i + 5 | ACC | acc/TRM🚩 ≡ 1 | | | | τ ∙ ρ + ε_rev | τ ∙ h + 0 | +|   | | ecc/ROM_LEX🚩 ≡ 0 | | | | | | +|   | | [5,4]sameAddress 👋 | | | | | | +|   | | [5,4]undoWarmthUpdate 👋 | | | | | | +|   | | | | | | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+---------------+-----------| +| i + 6 | CON | nonExecutionProvidesEmptyReturnData() | +|-----------+--------+---------------------------------------| + +NOTE. We use the following shorthands + + * ρ ≡ CONTEXT_REVERT_STAMP + * h ≡ HUB_STAMP + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/generalities/lua/abort/wont_revert.lua.tex b/hub/instruction_handling/call/generalities/lua/abort/wont_revert.lua.tex new file mode 100644 index 0000000..cd8d578 --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/abort/wont_revert.lua.tex @@ -0,0 +1,146 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ██████\ ██\ ██\ ██\ + ██ __██\ ██ __██\ ██ | ██ | ██ | + ██ / \__|██ / ██ |██ | ██ | ██████\ ██\ ██\ ██████\ ██████\ + ██ | ████████ |██ | ██ |██████\\_██ _| ██ | ██ |██ __██\ ██ __██\ + ██ | ██ __██ |██ | ██ |\______| ██ | ██ | ██ |██ / ██ |████████ | + ██ | ██\ ██ | ██ |██ | ██ | ██ |██\ ██ | ██ |██ | ██ |██ ____| + \██████ |██ | ██ |████████\ ████████\ \████ |\███████ |███████ |\███████\ + \______/ \__| \__|\________|\________| \____/ \____██ |██ ____/ \_______| + ██\ ██ |██ | + \██████ |██ | + \______/ \__| + + + | | + _` | __ \ _ \ __| __| + ( | | | ( | | | + \__,_| _.__/ \___/ _| \__| + + ) | | + \ \ \ / _ \ __ \ / __| __| _ \ \ \ / _ \ __| __| + \ \ \ / ( | | | | | __/ \ \ / __/ | | + \_/\_/ \___/ _| _| \__| _| \___| \_/ \___| _| \__| + + +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | | | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | | | required: | +| i - 1 | STACK | | | | * stack/STATICX ≡ 0 | +|   | | | | | * stack/MXPX ≡ 0 | +|   | | | | | * stack/OOGX ≡ 0 | +|   | | | | | . => XAHOY ≡ 0 | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i  | SCEN |  CALL/unexceptional ≡ 1 👋 | | | | +|   | | ^^^^^^^^^^^^^^^^^^^^^^^^ | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | .  CALL/EXCEPTION ≡ XAHOY | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | . context/IS_STATIC | +|   | | | | | . context/CALL_STACK_DEPTH | +|   | | | | | . context/ACCOUNT_ADDRESS | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 2 | MISC | misc/OOB🚩 ≡ is_CALL | | | | +|   | | misc/OOB_INST ≡ OOB_INST_call 👋 | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * OOB_nonzero_value | +|   | | | | | * OOB_aborting_condition | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | | +|   | | | | | . stack/STATICX ≡ is_CALL | +|   | | | | | . ∧ OOB_nonzero_value | +|   | | | | | . ∧ context/IS_STATIC | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | | .  CALL/abort ≡ OOB_aborting_condition | +|   | | | | | . ≡ 1 👋 | +|   | | | | | | +|   | | | | | .  CALL/ABORT_WILL_REVERT | +|   | | | | | . ≡ CONTEXT_WILL_REVERT | +|   | | | | | . ≡ 0 👋 | +|   | | | | | | +|   | | | misc/MXP🚩 ≡ 1 | | | +|   | | | misc/MXP_INST ≡ MXP_INST_TYPE_5 | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/MXP_MXPX <== MXPX_memory_expansion_exception | +|   | | | | | * misc/MXP_GAS <== MXPX_memory_expansion_gas | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/MXPX ≡ MXPX_memory_expansion_exception | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | misc/STP🚩 ≡ 1 | | +|   | | | | misc/STP_INST ≡ stack/INSTRUCTION | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/STP_UPFRONT_GAS_COST | +|   | | | | | * misc/STP_OOGX | +|   | | | | | * misc/STP_GAS_POOP | +|   | | | | | * misc/STP_GAS_STPD | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/OOGX ≡ misc/STP_OOGX | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 3 | ACC | read( context/ACCOUNT_ADDRESS ) | | | | τ ∙ h + 0 | 0 | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/BALANCE | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 4 | ACC | acc/TRM🚩 ≡ 1 | | | | τ ∙ h + 1 | 0 | +|   | | ecc/ROM_LEX🚩 ≡ 0 | | | | | | +|   | | read( trimmed_target_address ) 👋 | | | | | | +|   | | [4]turnOnWarmth (i.e. warmth ↑) | | | | | | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/ADDRESS_HI (<== trimmed high part) | | | +|   | | | | | * acc/HAS_CODE | | | +|   | | | | | * acc/EXISTS | | | +|   | | | | | * acc/IS_PRECOMPILE | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 5 | CON | nonExecutionProvidesEmptyReturnData() | +|-----------+--------+---------------------------------------| + +NOTE. We use the following shorthands + + * h ≡ HUB_STAMP + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/generalities/lua/entry.lua.tex b/hub/instruction_handling/call/generalities/lua/entry.lua.tex new file mode 100644 index 0000000..6375a20 --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/entry.lua.tex @@ -0,0 +1,180 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ██████\ ██\ ██\ ██\ + ██ __██\ ██ __██\ ██ | ██ | ██ | + ██ / \__|██ / ██ |██ | ██ | ██████\ ██\ ██\ ██████\ ██████\ + ██ | ████████ |██ | ██ |██████\\_██ _| ██ | ██ |██ __██\ ██ __██\ + ██ | ██ __██ |██ | ██ |\______| ██ | ██ | ██ |██ / ██ |████████ | + ██ | ██\ ██ | ██ |██ | ██ | ██ |██\ ██ | ██ |██ | ██ |██ ____| + \██████ |██ | ██ |████████\ ████████\ \████ |\███████ |███████ |\███████\ + \______/ \__| \__|\________|\________| \____/ \____██ |██ ____/ \_______| + ██\ ██ |██ | + \██████ |██ | + \______/ \__| + + + | _) | + | | __ \ _ \ \ \ / __| _ \ __ \ __| | _ \ __ \ _` | | + | | | | __/ ` < ( __/ | | | | ( | | | ( | | + \__,_| _| _| \___| _/\_\ \___| \___| .__/ \__| _| \___/ _| _| \__,_| _| ) + _| / + + | | | + | | __ \ _` | __ \ _ \ __| __| _ \ _` | + | | | | ( | | | ( | | | __/ ( | + \__,_| _| _| \__,_| _.__/ \___/ _| \__| \___| \__,_| + + +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | | | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | | | required: | +| i - 1 | STACK | | | | * stack/STATICX ≡ 0 | +|   | | | | | * stack/MXPX ≡ 0 | +|   | | | | | * stack/OOGX ≡ 0 | +|   | | | | | . => XAHOY ≡ 0 | +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i  | SCEN |  CALL/entry ≡ 1 👋 | | | | +|   | | ^^^^^^^^^^^^^^^^ | | | | +|   | | | | | | +|   | |  CALL/precompile <== callee_is_precompile 👋 | | | | +|   | |  CALL/externally_owned_account <== ¬ callee_is_precompile | | | | +|   | | . ∧ ¬ callee_has_code 👋 | | | | +|   | |  CALL/smart_contract <== callee_has_code 👋 | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | .  CALL/EXCEPTION ≡ XAHOY | +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | . context/IS_STATIC | +|   | | | | | . context/CALL_STACK_DEPTH | +|   | | | | | . context/ACCOUNT_ADDRESS | +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 2 | MISC | misc/OOB🚩 ≡ is_CALL | | | | +|   | | misc/OOB_INST ≡ OOB_INST_call ✅ | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * OOB_nonzero_value | +|   | | | | | * OOB_aborting_condition | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | | +|   | | | | | . stack/STATICX ≡ is_CALL | +|   | | | | | . ∧ OOB_nonzero_value | +|   | | | | | . ∧ context/IS_STATIC | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | | .  CALL/ABORT ≡ OOB_aborting_condition | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | misc/MXP🚩 ≡ 1 | | | +|   | | | misc/MXP_INST ≡ MXP_INST_TYPE_5 | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/MXP_MXPX <== MXPX_memory_expansion_exception | +|   | | | | | * misc/MXP_GAS <== MXPX_memory_expansion_gas | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/MXPX ≡ MXPX_memory_expansion_exception | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | misc/STP🚩 ≡ 1 | | +|   | | | | misc/STP_INST ≡ stack/INSTRUCTION | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/STP_UPFRONT_GAS_COST | +|   | | | | | * misc/STP_OOGX | +|   | | | | | * misc/STP_GAS_POOP | +|   | | | | | * misc/STP_GAS_STPD | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/OOGX ≡ misc/STP_OOGX | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 3 | ACC | load( context/ACCOUNT_ADDRESS ) | | | | τ ∙ h + 0 | 0 | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/BALANCE | | | +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 4 | ACC | acc/TRM🚩 ≡ 1 👋 | | | | τ ∙ h + 1 | 0 | +|   | | acc/ROM_LEX🚩 ≡  CALL/smart_contract 👋 | | | | | | +|   | | load( trimmed_target_address ) 👋 | | | | | | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/ADDRESS_HI (<== trimmed high part) | | | +|   | | | | | * acc/HAS_CODE <== callee_has_code | | | +|   | | | | | * acc/EXISTS <== callee_exists | | | +|   | | | | | * acc/IS_PRECOMPILE <== callee_is_precompile | | | +|   | | | | | * If acc/ROM_LEX🚩 ≡ 1: acc/CODE_FRAGMENT_INDEX | | | +|   | | | | | . <== callee_cfi | | | +|-----------+--------+---------------------------------------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| + + +NOTE. We use the following shorthands + + * h ≡ HUB_STAMP + +NOTE. The above depicts the layout of the first 3 NON_STACK_ROWS of ANY unexceptional, unaborted CALL-type instruction. +The above also depitcts the first set of 2 account-rows (which is present in ALL unexceptional, unaborted CALL-type instruction handlings.) + +NOTE. The account-rows that are required to deal with (unexceptional, unaborted) CALL-type instructions are: + + *  CALL/externally_owned_account ≡ 1: + - 2 or 4 extra account-rows followed by a context-row + - the context-row updates (i.e. resets) the current context's return data + + *  CALL/smart_contract ≡ 1: + - 2, 4 or 5 account-rows followed by a context-row + - the context row INITIALIZES the execution context where execution of the callee will take place; + + *  CALL/precompile ≡ 1: + - 2 or 4 account-rows followed by a scenario-row + - the scenario-row remembers which precompile processing is required: + ∙  PRC/ECRECOVER + ∙  PRC/SHA2-256 + ∙  PRC/RIPEMD-160 + ∙  PRC/IDENTITY + ∙  PRC/MODEXP + ∙  PRC/ECADD + ∙  PRC/ECMUL + ∙  PRC/ECPAIRING + ∙  PRC/BLAKE2f + - the scenario-row carries a PREDICTION of which precompile scenario will play out + ∙  PRC/FAILURE_KNOWN_TO_HUB + ∙  PRC/FAILURE_KNOWN_TO_RAM + ∙  PRC/SUCCESS_WILL_REVERT + ∙  PRC/SUCCESS_WONT_REVERT + - beyond that point the 'second phase of precompile processing' sets in + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/generalities/lua/exceptions/mxpx.lua.tex b/hub/instruction_handling/call/generalities/lua/exceptions/mxpx.lua.tex new file mode 100644 index 0000000..4cc56e2 --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/exceptions/mxpx.lua.tex @@ -0,0 +1,92 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ██████\ ██\ ██\ ██\ + ██ __██\ ██ __██\ ██ | ██ | ██ | + ██ / \__|██ / ██ |██ | ██ | ██████\ ██\ ██\ ██████\ ██████\ + ██ | ████████ |██ | ██ |██████\\_██ _| ██ | ██ |██ __██\ ██ __██\ + ██ | ██ __██ |██ | ██ |\______| ██ | ██ | ██ |██ / ██ |████████ | + ██ | ██\ ██ | ██ |██ | ██ | ██ |██\ ██ | ██ |██ | ██ |██ ____| + \██████ |██ | ██ |████████\ ████████\ \████ |\███████ |███████ |\███████\ + \______/ \__| \__|\________|\________| \____/ \____██ |██ ____/ \_______| + ██\ ██ |██ | + \██████ |██ | + \______/ \__| + + + __ `__ \ \ \ / __ \ \ \ / + | | | ` < | | ` < + _| _| _| _/\_\ .__/ _/\_\ + _| + + +|-----------+--------+------------------------------------+---------------------------------+--------------------------------------------------| +| Row index | Persp. | Actions | | Notes | +|:---------:+--------+------------------------------------+---------------------------------+--------------------------------------------------| +| i - 2 | STACK | | | required: | +| i - 1 | STACK | | | * stack/STATICX ≡ 0 | +|   | | | | * stack/MXPX ≡ 1 | +|   | | | | * stack/OOGX ≡ 0 | +|   | | | | . => XAHOY ≡ 1 | +|-----------+--------+------------------------------------+---------------------------------+--------------------------------------------------| +| i  | SCEN |  CALL/EXCEPTION ≡ 1 👋 | | | +|   | | ^^^^^^^^^^^^^^^^^^^^ | | | +|   | | | | Impose that: | +|   | | | | ============ | +|   | | | | .  CALL/EXCEPTION ≡ XAHOY | +|-----------+--------+------------------------------------+---------------------------------+--------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | | +|   | | | | | +|   | | | | Provides: | +|   | | | | ========= | +|   | | | | . context/IS_STATIC | +|-----------+--------+------------------------------------+---------------------------------+--------------------------------------------------| +| i + 2 | MISC | misc/OOB🚩 ≡ is_CALL | | | +|   | | misc/OOB_INST ≡ OOB_INST_xcall | | | +|   | | | | | +|   | | | | Provides: | +|   | | | | ========= | +|   | | | | * OOB_nonzero_value | +|   | | | | | +|   | | | | Impose that: | +|   | | | | ============ | +|   | | | | . stack/STATICX ≡ is_CALL | +|   | | | | . ∧ OOB_nonzero_value | +|   | | | | . ∧ context/IS_STATIC | +|   | | | | . ≡ 0 ✅ | +|   | | | | | +|   | | | misc/MXP🚩 ≡ 1 | | +|   | | | misc/MXP_INST ≡ MXP_INST_TYPE_5 | | +|   | | | | | +|   | | | | Provides: | +|   | | | | ========= | +|   | | | | * MXPX_memory_expansion_exception | +|   | | | | | +|   | | | | Impose that: | +|   | | | | ============ | +|   | | | | . stack/MXPX ≡ MXPX_memory_expansion_exception | +|   | | | | . ≡ 1 👋 | +|-----------+--------+------------------------------------+---------------------------------+--------------------------------------------------| +| i + 3 | CON | executionProvidesEmptyReturnData() | | +|-----------+--------+------------------------------------+---------------------------------| + + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/generalities/lua/exceptions/oogx.lua.tex b/hub/instruction_handling/call/generalities/lua/exceptions/oogx.lua.tex new file mode 100644 index 0000000..7f6e8a8 --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/exceptions/oogx.lua.tex @@ -0,0 +1,127 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ██████\ ██\ ██\ ██\ + ██ __██\ ██ __██\ ██ | ██ | ██ | + ██ / \__|██ / ██ |██ | ██ | ██████\ ██\ ██\ ██████\ ██████\ + ██ | ████████ |██ | ██ |██████\\_██ _| ██ | ██ |██ __██\ ██ __██\ + ██ | ██ __██ |██ | ██ |\______| ██ | ██ | ██ |██ / ██ |████████ | + ██ | ██\ ██ | ██ |██ | ██ | ██ |██\ ██ | ██ |██ | ██ |██ ____| + \██████ |██ | ██ |████████\ ████████\ \████ |\███████ |███████ |\███████\ + \______/ \__| \__|\________|\________| \____/ \____██ |██ ____/ \_______| + ██\ ██ |██ | + \██████ |██ | + \______/ \__| + + + _ \ _ \ _` | \ \ / + ( | ( | ( | ` < + \___/ \___/ \__, | _/\_\ + |___/ + + +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | | | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | | | required: | +| i - 1 | STACK | | | | * stack/STATICX ≡ 0 | +|   | | | | | * stack/MXPX ≡ 0 | +|   | | | | | * stack/OOGX ≡ 1 | +|   | | | | | . => XAHOY ≡ 1 | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i  | SCEN |  CALL/EXCEPTION ≡ 1 👋 | | | | +|   | | ^^^^^^^^^^^^^^^^^^^^ | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | .  CALL/EXCEPTION ≡ XAHOY | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | . context/IS_STATIC | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------| +| i + 2 | MISC | misc/OOB🚩 ≡ is_CALL | | | | +|   | | misc/OOB_INST ≡ OOB_INST_xcall | | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * OOB_nonzero_value | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/STATICX ≡ is_CALL | +|   | | | | | . ∧ OOB_nonzero_value | +|   | | | | | . ∧ context/IS_STATIC | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | misc/MXP🚩 ≡ 1 | | | +|   | | | misc/MXP_INST ≡ MXP_INST_TYPE_5 | | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/MXP_MXPX <== MXPX_memory_expansion_exception | +|   | | | | | * misc/MXP_GAS <== MXPX_memory_expansion_gas | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/MXPX ≡ MXPX_memory_expansion_exception | +|   | | | | | . ≡ 0 ✅ | +|   | | | | | | +|   | | | | misc/STP🚩 ≡ 1 | | +|   | | | | misc/STP_INST ≡ stack/INSTRUCTION | | +|   | | | | | | +|   | | | | | Provides: | +|   | | | | | ========= | +|   | | | | | * misc/STP_UPFRONT_GAS_COST | +|   | | | | | * misc/STP_OOGX | +|   | | | | | | +|   | | | | | Impose that: | +|   | | | | | ============ | +|   | | | | | . stack/OOGX ≡ misc/STP_OOGX | +|   | | | | | . ≡ 1 👋 | +|   | | | | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 3 | ACC | read( context/ACCOUNT_ADDRESS ) | | | | τ ∙ h + 0 | 0 | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/BALANCE | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 4 | ACC | acc/TRM🚩 ≡ 1 | | | | τ ∙ h + 1 | 0 | +|   | | read( trimmed_target_address ) 👋 | | | | | | +|   | | acc/ROM_LEX🚩 ≡ 0 | | | | | | +|   | | | | | | | | +|   | | | | | Provides: | | | +|   | | | | | ========= | | | +|   | | | | | * acc/ADDRESS_HI (<== trimmed high part) | | | +|   | | | | | * acc/HAS_CODE | | | +|   | | | | | * acc/EXISTS | | | +|   | | | | | * acc/IS_PRECOMPILE | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------+-----------------------------------------------------+-----------+-----------| +| i + 5 | CON | executionProvidesEmptyReturnData() | | | +|-----------+--------+---------------------------------------+---------------------------------+-----------------------------------| + +NOTE. We use the following shorthands + + * h ≡ HUB_STAMP + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/generalities/lua/exceptions/staticx.lua.tex b/hub/instruction_handling/call/generalities/lua/exceptions/staticx.lua.tex new file mode 100644 index 0000000..c0f05df --- /dev/null +++ b/hub/instruction_handling/call/generalities/lua/exceptions/staticx.lua.tex @@ -0,0 +1,77 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ██████\ ██\ ██\ ██\ + ██ __██\ ██ __██\ ██ | ██ | ██ | + ██ / \__|██ / ██ |██ | ██ | ██████\ ██\ ██\ ██████\ ██████\ + ██ | ████████ |██ | ██ |██████\\_██ _| ██ | ██ |██ __██\ ██ __██\ + ██ | ██ __██ |██ | ██ |\______| ██ | ██ | ██ |██ / ██ |████████ | + ██ | ██\ ██ | ██ |██ | ██ | ██ |██\ ██ | ██ |██ | ██ |██ ____| + \██████ |██ | ██ |████████\ ████████\ \████ |\███████ |███████ |\███████\ + \______/ \__| \__|\________|\________| \____/ \____██ |██ ____/ \_______| + ██\ ██ |██ | + \██████ |██ | + \______/ \__| + + | | _) + __| __| _` | __| | __| \ \ / + \__ \ | ( | | | ( ` < + ____/ \__| \__,_| \__| _| \___| _/\_\ + + +|-----------+--------+---------------------------------------+------------------------------------------| +| Row index | Persp. | Actions | Notes | +|:---------:+--------+---------------------------------------+------------------------------------------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 1 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 1 | +|-----------+--------+---------------------------------------+------------------------------------------| +| i  | SCEN |  CALL/EXCEPTION ≡ 1 👋 | | +|   | | ^^^^^^^^^^^^^^^^^^^^ | | +|   | | | Impose that: | +|   | | | ============ | +|   | | | .  CALL/EXCEPTION ≡ XAHOY | +|-----------+--------+---------------------------------------+------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | | Provides: | +|   | | | ========= | +|   | | | . context/IS_STATIC | +|-----------+--------+---------------------------------------+------------------------------------------| +| i + 2 | MISC | misc/OOB🚩 ≡ is_CALL | | +|   | | misc/OOB_INST ≡ OOB_INST_xcall 👋 | | +|   | | | Provides: | +|   | | | ========= | +|   | | | * OOB_nonzero_value | +|   | | | | +|   | | | Impose that: | +|   | | | ============ | +|   | | | . stack/STATICX ≡ is_CALL | +|   | | | . ∧ OOB_nonzero_value | +|   | | | . ∧ context/IS_STATIC | +|   | | | . ≡ 1 👋 | +|-----------+--------+---------------------------------------+------------------------------------------| +| i + 3 | CON | executionProvidesEmptyReturnData() | +|-----------+--------+---------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/generalities/universal.tex b/hub/instruction_handling/call/generalities/universal.tex new file mode 100644 index 0000000..0f8b392 --- /dev/null +++ b/hub/instruction_handling/call/generalities/universal.tex @@ -0,0 +1,309 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \scenCallSum _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \end{array} \right. + } +\end{center} +In other words we are in the most general case of a \inst{CALL}-type instruction that (at the very least) raises no \suxSH{}. +Recall from +section~(\ref{hub: instruction handling: call: peeking flags and nRows no precompiles}) and +section~(\ref{hub: instruction handling: call: peeking flags and nRows for precompiles first half}) +that row +$(i + \callCurrentContextRowOffset)$ is \textbf{always} a context-row and +$(i + \callMiscRowOffset)$ is \textbf{always} a miscellaneous-row. +We impose the following constraints: +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\callSP _{i - \callFirstStackRowOffset} \big[ \locIsCall + \locIsCallcode \big]$; + \item[\underline{Setting the success bit:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \locSuccessBitHi & = & 0 \\ + \locSuccessBitLo & = & \scenCallSuccess_{i + \callFirstScenarioRowOffset} \\ + \end{array} \right. + \] + \item[\underline{Setting allowable exceptions:}] + we impose that + \begin{enumerate} + \item \If $\locIsCall = 1$ \Then + \[ + \xAhoy _{i} + = + \left[ \begin{array}{lr} + + & \locStaticx \\ + + & \locMxpx \\ + + & \locOogx \\ + \end{array} \right] + \] + \item \If $\locIsCallcode + \locIsDelegatecall + \locIsStaticcall = 1$ \Then + \[ + \xAhoy _{i} + = + \left[ \begin{array}{lr} + + & \locMxpx \\ + + & \locOogx \\ + \end{array} \right] + \] + \end{enumerate} + \saNote{} The above reflects the fact that among all \inst{CALL}-type instructions only \inst{CALL} may trigger a \staticxSH{}. + \item[\underline{The first context-row $n^°(i + \callCurrentContextRowOffset)$:}] + we impose $\readContextData {i}{\callCurrentContextRowOffset}{\cn_{i}}$; + \item[\underline{Setting miscellaneous flags on row $n^°(i + \callMiscRowOffset)$:}] + we impose that + \[ + \weightedMiscFlagSum + {i}{\callMiscRowOffset} + = + \left[ \begin{array}{lrcl} + + & \miscMxpWeight & \cdot & \locCallTriggersMxp \\ + + & \miscOobWeight & \cdot & \locCallTriggersOob \\ + + & \miscStpWeight & \cdot & \locCallTriggersStp \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag_{i + \callMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag_{i + \callMiscRowOffset} & = & \rZero & (\trash) \\ + \miscMxpFlag_{i + \callMiscRowOffset} & = & \locCallTriggersMxp & (\trash) \\ + \miscOobFlag_{i + \callMiscRowOffset} & = & \locCallTriggersOob & (\trash) \\ + \miscStpFlag_{i + \callMiscRowOffset} & = & \locCallTriggersStp & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \oobMod{} instruction parameters:}] + \If $\miscOobFlag_{i + \callMiscRowOffset} = 1$ \Then + we impose that + \begin{enumerate} + \item \If $\scenCallException _{i} = 1$ \Then + \[ + \setOobInstructionXcall { + anchorRow = i, + relOffset = \callMiscRowOffset, + valueHi = \locValueHi, + valueLo = \locValueLo, + } + \] + \item \If $\scenCallUnexceptional _{i + \callFirstScenarioRowOffset} = 1$ \Then + \[ + \setOobInstructionCall { + anchorRow = i, + relOffset = \callMiscRowOffset, + valueHi = \locValueHi, + valueLo = \locValueLo, + balance = \locCallerBalance, + callStackDepth = \locCsd, + } + \] + \end{enumerate} + \saNote{} + \inst{CALL} instructions \textbf{always} trigger the \oobMod{} module. + \item[\underline{Justifying \staticxSH's:}] + we unconditionally impose that + \[ + \locStaticx + = + \left[ \begin{array}{cl} + \cdot & \locIsCall \\ + \cdot & \locNonzeroValue \\ + \cdot & \locIsStatic \\ + \end{array} \right] + \] + \saNote{} + The interpretation of the cell pointed to by the shorthand \locNonzeroValue{} is the same for both \oobMod{} instructions, see + section~(\ref{hub: misc: oob: call}) and + section~(\ref{hub: misc: oob: xcall}). + + \saNote{} + The above, seeing as it applies to \textbf{each and every \inst{CALL} instruction}, implies that among (non stack over/underflow) exceptions, \staticxSH{} is dominant and always the primary focus of verification. + \item[\underline{Setting \mxpMod{} instruction parameters:}] + \If $\miscMxpFlag_{i + \callMiscRowOffset} = 1$ \Then we impose that + \[ + \setMxpInstructionTypeFive { + anchorRow = i, + relOffset = \callMiscRowOffset, + instruction = \locInst, + callDataOffsetHi = \locCdoHi, + callDataOffsetLo = \locCdoLo, + callDataSizeHi = \locCdsHi, + callDataSizeLo = \locCdsLo, + returnAtOffsetHi = \locRaoHi, + returnAtOffsetLo = \locRaoLo, + returnAtCapacityHi = \locRacHi, + returnAtCapacityLo = \locRacLo, + } + \] + \item[\underline{Justifying \mxpxSH's:}] + \If $\miscMxpFlag_{i + \callMiscRowOffset} = 1$ \Then we impose that + \[ + \locMxpx = + \locMxpMemoryExpansionException + \] + \item[\underline{Setting \stpMod{} instruction parameters:}] + \If $\miscStpFlag_{i + \callMiscRowOffset} = 1$ \Then we impose that + \[ + \setStpInstructionCall{ + anchorRow = i , + relOffset = \callMiscRowOffset , + instruction = \locInst , + gasHi = \locGasHi , + gasLo = \locGasLo , + valueHi = \locValueHi , + valueLo = \locValueHi , + warmth = \locCalleeExists , + exists = \locCalleeWarmth , + mxpGas = \locMxpMemoryExpansionGas , + } + % \left\{ \begin{array}{lcl} + % \miscStpInst _{i + \callMiscRowOffset} & = & \locInst_{i} \\ + % \miscStpGasHi _{i + \callMiscRowOffset} & = & \locGasHi \\ + % \miscStpGasLo _{i + \callMiscRowOffset} & = & \locGasLo \\ + % \miscStpValueHi _{i + \callMiscRowOffset} & = & \locValueHi \\ + % \miscStpValueLo _{i + \callMiscRowOffset} & = & \locValueHi \\ + % \miscStpAccExists _{i + \callMiscRowOffset} & = & \locCalleeExists \\ + % \miscStpAccWarmth _{i + \callMiscRowOffset} & = & \locCalleeWarmth \\ + % \miscStpOogx _{i + \callMiscRowOffset} & = & \locOogx \\ + % \miscStpGasUpfront _{i + \callMiscRowOffset} & = & \relevantValue \\ + % \miscStpGasPoop _{i + \callMiscRowOffset} & = & \relevantValue \\ + % \miscStpGasStipend _{i + \callMiscRowOffset} & = & \relevantValue \\ + % \end{array} \right. + \] + \item[\underline{Justifying \oogxSH's:}] + \If $\miscStpFlag_{i + \callMiscRowOffset} = 1$ \Then we impose that + \[ + \locOogx = + \locStpOogx + \] + \item[\underline{Setting the \inst{CALL}-scenario flag:}] + we constrain the \inst{CALL}-scenario: + \begin{enumerate} + \item we unconditionally impose $\scenCallException_{i + \callFirstScenarioRowOffset} = \xAhoy_{i}$; + \item + \If $\scenCallUnexceptional _{i + \callFirstScenarioRowOffset} = 1$ + \Then we impose that + \[ \scenCallAbort _{i + \callFirstScenarioRowOffset} = \locOobAbortingCondition \] + \item + \If $\scenCallAbort _{i + \callFirstScenarioRowOffset} = 1$ + \Then we impose that + \[ + \left\{ \begin{array}{lclr} + \scenCallAbortWillRevert _{i + \callFirstScenarioRowOffset} & = & \locCallerWillRevert \\ + \scenCallAbortWontRevert _{i + \callFirstScenarioRowOffset} & = & 1 - \locCallerWillRevert & (\trash) \\ + \end{array} \right. + \] + \item + \If $\scenCallEntry _{i + \callFirstScenarioRowOffset} = 1$ + \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \scenCallPrc _{i + \callFirstScenarioRowOffset} & = & \locCalleeIsPrecompile \\ + \scenCallEoa _{i + \callFirstScenarioRowOffset} & = & (1 - \locCalleeIsPrecompile) \cdot (1 - \locCalleeHasCode) \\ + \scenCallSmc _{i + \callFirstScenarioRowOffset} & = & \locCalleeHasCode \\ + \end{array} \right. + \] + \item \If + $\left[ \begin{array}{cl} + + & \scenCallPrcSuccessWillRevert _{i + \callFirstScenarioRowOffset} \\ + + & \scenCallPrcSuccessWontRevert _{i + \callFirstScenarioRowOffset} \\ + \end{array} \right] = 1$ + \Then we impose that + % \item \If $\scenCallPrc _{i + \callFirstScenarioRowOffset} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lclr} + \scenCallPrcSuccessWillRevert _{i + \callFirstScenarioRowOffset} & = & \locCallerWillRevert \\ + \scenCallPrcSuccessWontRevert _{i + \callFirstScenarioRowOffset} & = & 1 - \locCallerWillRevert & (\trash) \\ + \end{array} \right. + \] + \item \If $\scenCallEoa _{i + \callFirstScenarioRowOffset} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lclr} + \scenCallEoaSuccessWillRevert _{i + \callFirstScenarioRowOffset} & = & \locCallerWillRevert \\ + \scenCallEoaSuccessWontRevert _{i + \callFirstScenarioRowOffset} & = & 1 - \locCallerWillRevert & (\trash) \\ + \end{array} \right. + \] + \item \If $\scenCallSmc _{i + \callFirstScenarioRowOffset} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lclr} + \left[ \begin{array}{ll} + + & \scenCallSmcSuccessWillRevert _{i + \callFirstScenarioRowOffset} \\ + + & \scenCallSmcFailureWillRevert _{i + \callFirstScenarioRowOffset} \\ + \end{array} \right] & = & \locCallerWillRevert \vspace{2mm} \\ + \left[ \begin{array}{ll} + + & \scenCallSmcSuccessWontRevert _{i + \callFirstScenarioRowOffset} \\ + + & \scenCallSmcFailureWontRevert _{i + \callFirstScenarioRowOffset} \\ + \end{array} \right] & = & 1 - \locCallerWillRevert & (\trash) \\ + \end{array} \right. + \] + we further impose + \[ + \left\{ \begin{array}{lclr} + \scenCallSmcFailure _{i + \callFirstScenarioRowOffset} & = & \locCalleeSelfReverts \\ + \scenCallSmcSuccess _{i + \callFirstScenarioRowOffset} & = & 1 - \locCalleeSelfReverts \\ + \end{array} \right. + \] + \end{enumerate} + \saNote{} + There is no connection between scenario flags and reverting behaviour of the present or child context in the \scenCallPrcFailure{} case. + Indeed if the \hubMod{} module predicts the \scenCallPrcFailure{} scenario no state change will be enacted. + \item[\underline{Setting the next context number:}] + we impose + \[ + \left\{ \begin{array}{lclr} + \If \scenCallException _{i + \callFirstScenarioRowOffset} = 1 & \Then & \cn\new _{i - \callFirstStackRowOffset} = \caller _{i - \callFirstStackRowOffset} & (\trash) \\ + \If \scenCallNoContextChange _{i + \callFirstScenarioRowOffset} = 1 & \Then & \cn\new _{i - \callFirstStackRowOffset} = \cn _{i - \callFirstStackRowOffset} \\ + \If \scenCallSmc _{i + \callFirstScenarioRowOffset} = 1 & \Then & \cn\new _{i - \callFirstStackRowOffset} = 1 + \hubStamp _{i - \callFirstStackRowOffset} \\ + \end{array} \right. + \] + \item[\underline{Setting \gasCost{}:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \If \locStaticx = 1 & \Then \!\!\! & \gasCost_{i} = 0 \\ + \If \locMxpx = 1 & \Then \!\!\! & \gasCost_{i} = 0 \\ + \If \locOogx = 1 & \Then \!\!\! & \gasCost_{i} = \locStpGasUpfront \\ + \If \scenCallAbort _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasCost_{i} = \locStpGasUpfront \\ + \If \scenCallSmc _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasCost_{i} = \locStpGasUpfront \\ + \If \scenCallEoa _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasCost_{i} = \locStpGasUpfront \\ + \If \scenCallPrc _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasCost_{i} = \locStpGasUpfront \\ + \end{array} \right. + \] + \saNote{} + The implementation may choose to compress the above constraints into the following two constraints: + \[ + \left\{ \begin{array}{lclr} + \If + \left[ \begin{array}{cl} + + & \locStaticx \\ + + & \locMxpx \\ + \end{array} \right] + = 1 & \Then \!\!\! & \gasCost_{i} = 0 & (\trash) \vspace{2mm} \\ + \If + \left[ \begin{array}{cl} + + & \locOogx \\ + + & \scenCallAbort _{i + \callFirstScenarioRowOffset} \\ + + & \scenCallSmc _{i + \callFirstScenarioRowOffset} \\ + + & \scenCallEoa _{i + \callFirstScenarioRowOffset} \\ + + & \scenCallPrc _{i + \callFirstScenarioRowOffset} \\ + \end{array} \right] + = 1 & \Then \!\!\! & \gasCost_{i} = \locStpGasUpfront & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \gasNext{}:}] + we impose + \[ + \hspace*{-2cm} + \left\{ \begin{array}{lclr} + \If \locStaticx = 1 & \Then \!\!\! & \gasNext_{i} = 0 & (\trash) \\ + \If \locMxpx = 1 & \Then \!\!\! & \gasNext_{i} = 0 & (\trash) \\ + \If \locOogx = 1 & \Then \!\!\! & \gasNext_{i} = 0 & (\trash) \\ + \If \scenCallAbort _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasNext_{i} = \gasActual_{i} - \locStpGasUpfront + \locStpGasStipend \\ + \If \scenCallEoa _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasNext_{i} = \gasActual_{i} - \locStpGasUpfront + \locStpGasStipend \\ + \If \scenCallSmc _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasNext_{i} = \gasActual_{i} - \locStpGasUpfront - \locStpGasPoop \\ + \If \scenCallPrc _{i + \callFirstScenarioRowOffset} = 1 & \Then \!\!\! & \gasNext_{i} = \ob{TODO!} \\ + \end{array} \right. + \] + \saNote{} We will complete the specification of \gasNext{} in case $\scenCallPrc \equiv 1$ in section~(\ref{hub: instruction handling: call: precompile memory operations}). +\end{description} diff --git a/hub/instruction_handling/call/highlevel.tex b/hub/instruction_handling/call/highlevel.tex new file mode 100644 index 0000000..bcd5044 --- /dev/null +++ b/hub/instruction_handling/call/highlevel.tex @@ -0,0 +1,2 @@ +\includepdf[fitpaper=true]{instruction_handling/call/lua/highlevel.pdf} +\label{hub: call: fig: highlevel processing} diff --git a/hub/instruction_handling/call/intro.tex b/hub/instruction_handling/call/intro.tex new file mode 100644 index 0000000..4112fcb --- /dev/null +++ b/hub/instruction_handling/call/intro.tex @@ -0,0 +1,25 @@ +The present section deals with the \inst{CALL} instruction family processing i.e. the processing of +\inst{CALL}, \inst{CALLCODE}, \inst{DELEGATECALL} and \inst{STATICCALL} instructions. +These are among the most complex instructions in the \evm{} and certainly in the present arithmetization. +Their complexity stems from the following main reasons: +(\emph{a}) the manifold ways in which \inst{CALL}-type instructions may raise an exception +(\emph{b}) the possibility for unexceptional instrutions to be aborted yet +(\emph{c}) the possibility for unexceptional, unaborted \inst{CALL}-type instructions to be reverted later. +Furthermore +(\emph{d}) instruction-processing must differentiate the case where the target is an \textbf{externally owned account} (which leads to no code execution), a \textbf{smart contract} or a \textbf{precompile}. + +\textbf{Precompile} calls in particular lead to further complications still and \inst{CALL}'s to them require a second processing-phase. +Indeed +(\emph{e.1})) precompiles each follow their own gas schedule +(\emph{e.2})) the pricing of certain precompiles (\inst{MODEXP} and \inst{BLAKE2f}) requires interacting with \textsc{ram} +(\emph{e.3})) precompiles may fail in complex ways beyond being provided with insufficient gas (in particular \textsc{Elliptic Curve} operations) and detecting those failures may require interacting with \textsc{ram} +(\emph{e.4})) when successful they require up to three distinct memory operations (and far more in the case of \inst{MODEXP}). + +We will provide more ample details as to what these memory operations entail in section~(\ref{hub: instruction handling: call: precompiles: intro}). +The general principle is that +the first operation is used to extract the call data and serve it to the relevant ``data module'' (e.g. \shakiraMod{}, \ecDataMod{}, \blkMdxMod{}), +the second operation is used to copy the return data \textbf{in full} to a dedicated \textsc{ram} segment (associated with a unique, unclaimed context number) and +the third (optional) operation copies parts of the return data to the caller's own \textsc{ram}. +Further (preliminary) memory operations are required for the precompile call processing of both \inst{MODEXP} and \inst{BLAKE2f}. + +At this point let us just remark that the pricing of most precompiles will be handled in the \oobMod{} module. Let us also remark that the second phase of processing require by \inst{CALL}'s to precompiles will be dealt with almost separately. diff --git a/hub/instruction_handling/call/lua/highlevel.lua.tex b/hub/instruction_handling/call/lua/highlevel.lua.tex new file mode 100644 index 0000000..eff773b --- /dev/null +++ b/hub/instruction_handling/call/lua/highlevel.lua.tex @@ -0,0 +1,102 @@ +\documentclass[tikz, border = 1cm]{standalone} +\usepackage{xcolor} +\usepackage{fontawesome} +\usepackage{amsmath} +\usepackage{../../../../pkg/draculatheme} +\usepackage{../../../../pkg/common} +\usepackage{../../../../pkg/env} +\usepackage{../../../../pkg/exceptions} +\usepackage{../../../../pkg/flags_stamps_selectors} +\usetikzlibrary{arrows.meta} +\begin{document} +\input{hub/instruction_handling/create/_local} +\begin{tikzpicture} +\def\BASSS {-6.5} +\def\BASS {-4} +\def\BAS {-3} +\def\Bas {-2.5} +\def\bas {-2} +\def\droite {3} +\def\Droite {6.5} +\def\gauche {-3} +\def\Gauche {-6.5} + +\begin{scope}[every node/.style={rectangle, thick, draw, rounded corners = 3pt, inner sep = 6pt, outer sep = 4pt}] + \node [draw=draculapurple] (sux) at (0,0) {\suxSH}; + \path (sux) ++ (0,\Bas) node[draw=red] (exception) {\begin{tabular}{c} exception\\ $\xAhoy \equiv 1$\end{tabular}}; + \path (exception) ++ (0,\BASSS) node[draw=yellow] (abort) {\begin{tabular}{c} aborting condition\\ $\locOobAbortingCondition \equiv 1$\end{tabular}}; + \path (abort) ++ (0,\BASS) node[draw=draculagreen] (entry) {entry}; + \path (entry) ++ (\Gauche, \bas) node[draw=draculagreen] (prc call) {\textsc{prc} - call}; + \path (entry) ++ (0, \bas) node[draw=draculagreen] (eoa call) {\textsc{eoa} - call}; + \path (entry) ++ (\Droite, \bas) node[draw=draculagreen] (smc call) {\textsc{smc} - call}; +\end{scope} + +\begin{scope}[every node/.style={rectangle, thick, draw, rounded corners = 3pt, inner sep=6pt, outer sep = 4pt}] + \path (exception) ++ (\Droite,0) node [draw = draculacomment] (staticx) {\staticxSH}; + \path (staticx) ++ (0,\bas) node [draw = draculacomment] (mxpx) {\mxpxSH}; + \path (mxpx) ++ (0,\bas) node [draw = draculacomment] (oogx) {\oogxSH}; + \path (abort) ++ (\Droite,0) node [draw = draculacomment] (abort will revert) {will revert}; + \path (abort will revert) ++ (0,\bas) node [draw = draculacomment] (abort wont revert) {won't revert}; + \path (prc call) ++ (0,\Bas) node [draw = draculacomment] (prc call failure) {failure}; + \path (prc call failure) ++ (0,\Bas) ++ (0,\bas) node [draw = draculacomment] (prc call success) {success}; + \path (prc call success) ++ (\droite,0) node [draw = draculacomment] (prc call success will revert) {will revert}; + \path (prc call success will revert) ++ (0,\bas) node [draw = draculacomment] (prc call success wont revert) {won't revert}; + \path (eoa call) ++ (0,\Bas) ++ (0,\Bas) ++ (0,\bas) node [draw = draculacomment] (eoa call success) {success}; + \path (eoa call success) ++ (\droite,0) node [draw = draculacomment] (eoa call success will revert) {will revert}; + \path (eoa call success will revert) ++ (0,\bas) node [draw = draculacomment] (eoa call success wont revert) {won't revert}; + \path (smc call) ++ (0,\Bas) node [draw = draculacomment] (smc call failure) {failure}; + \path (smc call failure) ++ (\droite,0) node [draw = draculacomment] (smc call failure will revert) {will revert}; + \path (smc call failure will revert) ++ (0,\bas) node [draw = draculacomment] (smc call failure wont revert) {won't revert}; + \path (smc call failure) ++ (0,\Bas) ++ (0,\bas) node [draw = draculacomment] (smc call success) {success}; + \path (smc call success) ++ (\droite,0) node [draw = draculacomment] (smc call success will revert) {will revert}; + \path (smc call success will revert) ++ (0,\bas) node [draw = draculacomment] (smc call success wont revert) {won't revert}; +\end{scope} + +\begin{scope}[>={latex[draculacomment]}, + every node/.style={}, + every edge/.style={draw=draculacomment, very thick}] + \path (sux) ++ (\Gauche, 1) node (call type inst) [color=draculacomment] {\Large{\inst{CALL}-type instruction}}; + \path [->] (call type inst.357) edge (sux.north west); + \path [->] (sux) edge (exception); + \path [->] (exception) edge (staticx); + \path [->] (exception) edge (abort); + \path [->] (staticx) edge (mxpx); + \path [->] (mxpx) edge (oogx); + \path [->] (abort) edge (abort will revert); + \path [->] (abort) edge (entry); + \path [->] (abort will revert) edge (abort wont revert); + \path [->] (entry) edge (prc call); + \path [->] (entry) edge (eoa call); + \path [->] (entry) edge (smc call); + \path [->] (prc call) edge (prc call failure); + \path [->] (prc call failure) edge (prc call success); + \path [->] (eoa call) edge (eoa call success); + \path [->] (smc call) edge (smc call failure); + \path [->] (smc call failure) edge (smc call success); + % + % \path [->] (prc call failure) edge (prc call failure will revert); + % \path [->] (prc call failure will revert) edge (prc call failure wont revert); + \path [->] (prc call success) edge (prc call success will revert); + \path [->] (prc call success will revert) edge (prc call success wont revert); + % + \path [->] (eoa call success) edge (eoa call success will revert); + \path [->] (eoa call success will revert) edge (eoa call success wont revert); + % + \path [->] (smc call failure) edge (smc call failure will revert); + \path [->] (smc call failure will revert) edge (smc call failure wont revert); + \path [->] (smc call success) edge (smc call success will revert); + \path [->] (smc call success will revert) edge (smc call success wont revert); + % \path [->] (empty success) edge (empty success will revert); + % \path [->] (empty success will revert) edge (empty success wont revert); + % \path [->] (entry) edge (nonempty); + % \path [->] (nonempty) edge (nonempty failure); + % \path [->] (nonempty failure) edge (nonempty failure will revert); + % \path [->] (nonempty failure will revert) edge (nonempty failure wont revert); + % \path [->] (nonempty failure) edge (nonempty success); + % \path [->] (nonempty success) edge (nonempty success will revert); + % \path [->] (nonempty success will revert) edge (nonempty success wont revert); +\end{scope} + +\end{tikzpicture} +\end{document} + diff --git a/hub/instruction_handling/call/nsr_for_precompiles_partial.tex b/hub/instruction_handling/call/nsr_for_precompiles_partial.tex new file mode 100644 index 0000000..50390cc --- /dev/null +++ b/hub/instruction_handling/call/nsr_for_precompiles_partial.tex @@ -0,0 +1,43 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCallPrc _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +\begin{description} + \item[\underline{Setting the first half of peeking flags:}] + we use the following shorthand + \[ + \nsrPrecompilesFH + \define + \left[ \begin{array}{lrcl} + + & (\callPrcFailureSecondScenarioRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallPrcFailure _{i} \\ + + & (\callPrcSuccessWillRevertSecondScenarioRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallPrcSuccessWillRevert _{i} \\ + + & (\callPrcSuccessWontRevertSecondScenarioRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] + \] + and use it to set the first few non stack-rows of \inst{CALL}'s to precompiles: + \[ + \hspace*{-2cm} + \left[ \begin{array}{lrcl} + + \!\!\! & \peekingSumPrcFailureFH & \!\!\! \cdot \!\!\! & \scenCallPrcFailure _{i} \\ + + \!\!\! & \peekingSumPrcSuccessWillRevertFH & \!\!\! \cdot \!\!\! & \scenCallPrcSuccessWillRevert _{i} \\ + + \!\!\! & \peekingSumPrcSuccessWontRevertFH & \!\!\! \cdot \!\!\! & \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] + = + \nsrPrecompilesFH + \] + \item[\underline{Propagating the current \hubStamp:}] + we impose that the current \hubStamp{} remain valid at least for a while: + \[ + \left[ \begin{array}{lrcl} + + \!\!\! & \Big[ \hubStamp_{i + \callPrcFailureSecondScenarioRowOffset } - \hubStamp_{i - \callFirstStackRowOffset} \Big] & \!\!\! \cdot \!\!\! & \scenCallPrcFailure _{i} \vspace{2mm} \\ + + \!\!\! & \Big[ \hubStamp_{i + \callPrcSuccessWillRevertSecondScenarioRowOffset} - \hubStamp_{i - \callFirstStackRowOffset} \Big] & \!\!\! \cdot \!\!\! & \scenCallPrcSuccessWillRevert _{i} \vspace{2mm} \\ + + \!\!\! & \Big[ \hubStamp_{i + \callPrcSuccessWontRevertSecondScenarioRowOffset} - \hubStamp_{i - \callFirstStackRowOffset} \Big] & \!\!\! \cdot \!\!\! & \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] = 0 + \] +\end{description} + diff --git a/hub/instruction_handling/call/nsr_no_precompiles.tex b/hub/instruction_handling/call/nsr_no_precompiles.tex new file mode 100644 index 0000000..99e8389 --- /dev/null +++ b/hub/instruction_handling/call/nsr_no_precompiles.tex @@ -0,0 +1,77 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that } + \left\{ \begin{array}{lcl} + \peekScenario _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \scenCallNoPrc _{i + \callFirstScenarioRowOffset} & = & 1 \\ + \end{array} \right. + } +\end{center} +In other words we consider all \inst{CALL}-type instructions that are either +(\emph{a}) exceptional, +(\emph{b}) unexceptional and aborted, +(\emph{c}) unexceptional, unaborted targeting an externally owned account or a smart contract. +The only case we \textbf{don't} deal with here is that of +(\emph{d}) unexceptional, unaborted \inst{CALL}-type instructions targeting a precompile. +This task will be taken up in \emph{in part} in +section~(\ref{hub: instruction handling: call: peeking flags and nRows for precompiles first half}). +\begin{description} + \item[\underline{Setting \nonStackRows{} for non precompiles:}] + we can set \nonStackRows{} once and for all (as long as we are not entering a precompile, that is): + \[ + \nonStackRows_{i - \callFirstStackRowOffset} + = + \left[ \begin{array}{lrcl} + + & (\callStaticxUpdateParentContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \locStaticx \\ + + & (\callMxpxUpdateParentContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \locMxpx \\ + + & (\callOogxUpdateParentContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \locOogx \\ + + & (\callAbortWillRevertUpdateCurrentContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallAbortWillRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callAbortWontRevertUpdateCurrentContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallAbortWontRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callEoaWillRevertCallerContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallEoaSuccessWillRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callEoaWontRevertCallerContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallEoaSuccessWontRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callSmcFailureWillRevertInitializeCalleeContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallSmcFailureWillRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callSmcFailureWontRevertInitializeCalleeContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallSmcSuccessWillRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callSmcSuccessWillRevertInitializeCalleeContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallSmcFailureWontRevert _{i + \callFirstScenarioRowOffset} \\ + + & (\callSmcSuccessWontRevertInitializeCalleeContextRowOffset + 1) & \!\!\! \cdot \!\!\! & \scenCallSmcSuccessWontRevert _{i + \callFirstScenarioRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Setting the peeking flags:}] + we set the peeking flags once and for all (as long as we are not entering a precompile, that is): + \[ + \hspace*{-3.8cm} + \left[ \begin{array}{lrcl} + + \!\!\! & \peekingSumStaticx & \!\!\! \cdot \!\!\! & \locStaticx \\ + + \!\!\! & \peekingSumMxpx & \!\!\! \cdot \!\!\! & \locMxpx \\ + + \!\!\! & \peekingSumOogx & \!\!\! \cdot \!\!\! & \locOogx \\ + + \!\!\! & \peekingSumAbortWillRevert & \!\!\! \cdot \!\!\! & \scenCallAbortWillRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumAbortWontRevert & \!\!\! \cdot \!\!\! & \scenCallAbortWontRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumEoaWillRevert & \!\!\! \cdot \!\!\! & \scenCallEoaSuccessWillRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumEoaWontRevert & \!\!\! \cdot \!\!\! & \scenCallEoaSuccessWontRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumSmcFailureWillRevert & \!\!\! \cdot \!\!\! & \scenCallSmcFailureWillRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumSmcFailureWontRevert & \!\!\! \cdot \!\!\! & \scenCallSmcSuccessWillRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumSmcSuccessWillRevert & \!\!\! \cdot \!\!\! & \scenCallSmcFailureWontRevert _{i + \callFirstScenarioRowOffset} \\ + + \!\!\! & \peekingSumSmcSuccessWontRevert & \!\!\! \cdot \!\!\! & \scenCallSmcSuccessWontRevert _{i + \callFirstScenarioRowOffset} \\ + \end{array} \right] + = + \nonStackRows_{i - \callFirstStackRowOffset} + \] +\end{description} +Below are the concrete values of \nonStackRows{} depending on the \inst{CREATE}-type instruction scenario: +\[ + \begin{array}{|l|l|c|} \hline + \multicolumn{2}{|l|}{\textsc{Scenario}} & \nonStackRows{} \\ \hline \hline + \scenCallException{} & \suxSH{} & 1 \\ \hline + \scenCallException{} & \staticxSH{} & (\callStaticxUpdateParentContextRowOffset + 1) \\ \hline + \scenCallException{} & \mxpxSH{} & (\callMxpxUpdateParentContextRowOffset + 1) \\ \hline + \scenCallException{} & \oogxSH{} & (\callOogxUpdateParentContextRowOffset + 1) \\ \hline \hline + \multicolumn{2}{|l|}{\scenCallAbortWillRevert} & (\callAbortWillRevertUpdateCurrentContextRowOffset + 1) \\ \hline \hline + \multicolumn{2}{|l|}{\scenCallAbortWontRevert} & (\callAbortWontRevertUpdateCurrentContextRowOffset + 1) \\ \hline \hline + \multicolumn{2}{|l|}{\scenCallEoaSuccessWillRevert} & (\callEoaWillRevertCallerContextRowOffset + 1) \\ \hline + \multicolumn{2}{|l|}{\scenCallEoaSuccessWontRevert} & (\callEoaWontRevertCallerContextRowOffset + 1) \\ \hline \hline + \multicolumn{2}{|l|}{\scenCallSmcFailureWillRevert} & (\callSmcFailureWillRevertInitializeCalleeContextRowOffset + 1) \\ \hline + \multicolumn{2}{|l|}{\scenCallSmcFailureWontRevert} & (\callSmcFailureWontRevertInitializeCalleeContextRowOffset + 1) \\ \hline + \multicolumn{2}{|l|}{\scenCallSmcSuccessWillRevert} & (\callSmcSuccessWillRevertInitializeCalleeContextRowOffset + 1) \\ \hline + \multicolumn{2}{|l|}{\scenCallSmcSuccessWontRevert} & (\callSmcSuccessWontRevertInitializeCalleeContextRowOffset + 1) \\ \hline + \end{array} +\] +\saNote{} The ubiquitous ``$+1$'' accounts for the fact that the \nonStackRows{} count must include the scenario row with index $i + \callFirstScenarioRowOffset$. diff --git a/hub/instruction_handling/call/precompiles/TODO.md b/hub/instruction_handling/call/precompiles/TODO.md new file mode 100644 index 0000000..c42ce02 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/TODO.md @@ -0,0 +1,9 @@ +We need to finish +- nonStackRows and peeking flags, i.e. finishing section~(\ref{hub: instruction handling: call: peeking flags and nRows for precompiles first half}) +- setting GAS_NEXT, see section~(\ref{hub: instruction handling: call: generalities}) +- pricing in OOB +- probing ram + - extracting + - transferring + - copying +- update the caller's return data diff --git a/hub/instruction_handling/call/precompiles/_inputs.tex b/hub/instruction_handling/call/precompiles/_inputs.tex new file mode 100644 index 0000000..289fda1 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/_inputs.tex @@ -0,0 +1,16 @@ +\subsubsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: precompiles: intro} \input{instruction_handling/call/precompiles/intro} +\subsubsubsection{Precompile failure vs. success \lispNone{}} \label{hub: instruction handling: call: precompiles: failures vs. successes} \input{instruction_handling/call/precompiles/failures_vs_successes} +\subsubsubsection{Precompile failure classification \lispNone{}} \label{hub: instruction handling: call: precompiles: failure classification} \input{instruction_handling/call/precompiles/classification} +\subsubsubsection{Global shorthands \lispDone{}} \label{hub: instruction handling: call: precompiles: globally valid shorthands} \input{instruction_handling/call/precompiles/shorthands} +\subsubsubsection{Peeking flags \lispNone{}} \label{hub: instruction handling: call: precompiles: flags} \input{instruction_handling/call/precompiles/flags} +\subsubsubsection{Generalities \lispDone{}} \label{hub: instruction handling: call: precompiles: generalities} \input{instruction_handling/call/precompiles/generalities} +\subsubsubsection{Flag sums and \col{nsr}'s \lispDone{}} \label{hub: instruction handling: call: precompiles: flag sums and nsr} \input{instruction_handling/call/precompiles/nsr_and_flagsum} \newpage +\subsubsubsection{Explicit values for \nonStackRows{} \lispNone{}} \label{hub: instruction handling: call: precompiles: explicit values of nsr} \input{instruction_handling/call/precompiles/explicit_nsr} + +\subsubsection{Common setup for all precompiles except for \inst{MODEXP} and \inst{BLAKE2f} \lispDone{}} \label{hub: instruction handling: call: precompiles: most precompiles} \input{instruction_handling/call/precompiles/common/_inputs} +\subsubsection{\inst{ECRECOVER} \lispDone{}} \label{hub: instruction handling: call: precompiles: ecrecover} \input{instruction_handling/call/precompiles/ecrecover/_inputs} +\subsubsection{\inst{SHA2-256} and \inst{RIPEMD-160} \lispDone{}} \label{hub: instruction handling: call: precompiles: sha2 and ripemd} \input{instruction_handling/call/precompiles/sha2_ripemd/_inputs} +\subsubsection{\inst{IDENTITY} \lispDone{}} \label{hub: instruction handling: call: precompiles: identity} \input{instruction_handling/call/precompiles/identity/_inputs} +\subsubsection{\inst{MODEXP} \lispDone{}} \label{hub: instruction handling: call: precompiles: modexp} \input{instruction_handling/call/precompiles/modexp/_inputs} +\subsubsection{\inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} \lispTodo{}} \label{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing} \input{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/_inputs} +\subsubsection{\inst{BLAKE2f} \lispTodo{}} \label{hub: instruction handling: call: precompiles: blake} \input{instruction_handling/call/precompiles/blake/_inputs} diff --git a/hub/instruction_handling/call/precompiles/_local.tex b/hub/instruction_handling/call/precompiles/_local.tex new file mode 100644 index 0000000..e48d1f1 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/_local.tex @@ -0,0 +1,223 @@ +\def\locPrcCallerGas {\col{dup\_caller\_gas}} +\def\locPrcCallGas {\col{dup\_call\_gas}} +\def\locPrcCdo {\col{dup\_cdo}} +\def\locPrcCds {\col{dup\_cds}} +\def\locPrcRao {\col{dup\_r@o}} +\def\locPrcRac {\col{dup\_r@c}} +\def\locPrcReturnGas {\col{prd\_return\_gas}} +\def\locNsr {\col{nsr}} +\def\secondHalf {\col{\_second\_half}} +\def\locSecondPhaseNsr {\locNsr\secondHalf} +\def\locFirstPhaseNsr {\locNsr\col{\_first\_half}} +\def\locStandardFailure {\col{\_std\_fail}} +\def\locStandardSuccess {\col{\_std\_succ}} +\def\locStandardFailureFlagSum {\flagSum\locStandardFailure} +\def\locStandardSuccessFlagSum {\flagSum\locStandardSuccess} +\def\locIdentitySuccessFlagSum {\flagSum\col{\_identity\_succ}} +\def\locModexpFailureFlagSum {\flagSum\col{\_modexp\_fail}} +\def\locModexpSuccessFlagSum {\flagSum\col{\_modexp\_succ}} +\def\locStandardFailureNsr {\locNsr\locStandardFailure} +\def\locStandardSuccessNsr {\locNsr\locStandardSuccess} +\def\locIdentitySuccessNsr {\locNsr\col{\_identity\_succ}} +\def\locModexpFailureNsr {\locNsr\col{\_modexp\_fail}} +\def\locModexpSuccessNsr {\locNsr\col{\_modexp\_succ}} +\def\locFlagSumPrecompilesSH {\flagSum\secondHalf} +\def\locNsrPrecompilesSH {\locNsr\secondHalf} +\def\locOobInst {\col{oob\_inst}} +\def\locTriggerMmu {\col{trigger\_\mmuMod}} +\def\locMmuInst {\col{mmu\_inst}} +\def\locMmuSrcId {\col{mmu\_src\_id}} +\def\locMmuTgtId {\col{mmu\_tgt\_id}} +\def\locMmuSize {\col{mmu\_size}} +\def\locMmuPhase {\col{mmu\_phase}} +\def\locMmuExoSum {\col{mmu\_exo\_sum}} +\def\locMmuRefSize {\col{mmu\_ref\_size}} +\def\locLimbOne {\col{mmu\_limb\_one}} +\def\locLimbTwo {\col{mmu\_limb\_two}} +\def\locMmuRecoverSuccess {\col{recovery\_success}} +\def\locMmuWellFormedData {\col{wellformed\_data}} +\def\locMmuMalFormedData {\col{malformed\_data}} +% +\def\locAddressRecoveryFailure {\col{address\_recovery\_failure}} +\def\locAddressRecoverySuccess {\col{address\_recovery\_success}} +\def\locMalFormedData {\col{mal\_formed\_data}} +\def\locWellFormedData {\col{well\_formed\_data}} +% +\def\locOobResultReturnGas {\col{\oobMod\_return\_gas}} +\def\locOobResultExtractCallData {\col{\oobMod\_extract\_call\_data}} +\def\locOobResultEmptyCallData {\col{\oobMod\_empty\_call\_data}} +\def\locOobResultNonzeroRac {\col{\oobMod\_r@c\_nonzero}} +\def\locOobResultHubSuccess {\col{\oobMod\_hub\_success}} +\def\locOobResultRamSuccess {\col{\oobMod\_ram\_success}} +% +\def\locNontrivialAdd {\col{nontrivial\_ecadd}} +\def\locNontrivialMul {\col{nontrivial\_ecmul}} +\def\locNontrivialPairing {\col{nontrivial\_ecpairing}} +\def\locTrivialPairing {\phantom{\col{non}}\col{trivial\_ecpairing}} + +% generic +%%%%%%%%% +\def\locFlagSumXxx { \flagSum\col{\_xxx}\secondHalf} +\def\locFlagSumXxxSuccess { \flagSum\col{\_xxx\_success}} +\def\locFlagSumXxxFKTH { \flagSum\col{\_xxx\_FKTH}} +\def\locFlagSumXxxFKTR { \flagSum\col{\_xxx\_FKTR}} +\def\locNsrXxx { \locNsr\col{\_xxx}\secondHalf} +\def\locNsrXxxSuccess { \locNsr\col{\_xxx\_success}} +\def\locNsrXxxFKTH { \locNsr\col{\_xxx\_FKTH}} +\def\locNsrXxxFKTR { \locNsr\col{\_xxx\_FKTR}} +% ECRECOVER +%%%%%%%%%%% +\def\locFlagSumEcrecover { \flagSum\col{\_ecrecover}\secondHalf} +\def\locFlagSumEcrecoverSuccess { \flagSum\col{\_ecrecover\_success}} +\def\locFlagSumEcrecoverFKTH { \flagSum\col{\_ecrecover\_FKTH}} +\def\locFlagSumEcrecoverFKTR { \flagSum\col{\_ecrecover\_FKTR}} +\def\locNsrEcrecover { \locNsr\col{\_ecrecover}\secondHalf} +\def\locNsrEcrecoverSuccess { \locNsr\col{\_ecrecover\_success}} +\def\locNsrEcrecoverFKTH { \locNsr\col{\_ecrecover\_FKTH}} +\def\locNsrEcrecoverFKTR { \locNsr\col{\_ecrecover\_FKTR}} +% SAH2-256 +%%%%%%%%%% +\def\locFlagSumShaTwo { \flagSum\col{\_sha2}\secondHalf} +\def\locFlagSumShaTwoSuccess { \flagSum\col{\_sha2\_success}} +\def\locFlagSumShaTwoFKTH { \flagSum\col{\_sha2\_FKTH}} +\def\locFlagSumShaTwoFKTR { \flagSum\col{\_sha2\_FKTR}} +\def\locNsrShaTwo { \locNsr\col{\_sha2}\secondHalf} +\def\locNsrShaTwoSuccess { \locNsr\col{\_sha2\_success}} +\def\locNsrShaTwoFKTH { \locNsr\col{\_sha2\_FKTH}} +\def\locNsrShaTwoFKTR { \locNsr\col{\_sha2\_FKTR}} +% RIPEMD-160 +%%%%%%%%%%%% +\def\locFlagSumRipemd { \flagSum\col{\_ripemd}\secondHalf} +\def\locFlagSumRipemdSuccess { \flagSum\col{\_ripemd\_success}} +\def\locFlagSumRipemdFKTH { \flagSum\col{\_ripemd\_FKTH}} +\def\locFlagSumRipemdFKTR { \flagSum\col{\_ripemd\_FKTR}} +\def\locNsrRipemd { \locNsr\col{\_ripemd}\secondHalf} +\def\locNsrRipemdSuccess { \locNsr\col{\_ripemd\_success}} +\def\locNsrRipemdFKTH { \locNsr\col{\_ripemd\_FKTH}} +\def\locNsrRipemdFKTR { \locNsr\col{\_ripemd\_FKTR}} +% IDENTITY +%%%%%%%%%% +\def\locFlagSumIdentity { \flagSum\col{\_identity}\secondHalf} +\def\locFlagSumIdentitySuccess { \flagSum\col{\_identity\_success}} +\def\locFlagSumIdentityFKTH { \flagSum\col{\_identity\_FKTH}} +\def\locFlagSumIdentityFKTR { \flagSum\col{\_identity\_FKTR}} +\def\locNsrIdentity { \locNsr\col{\_identity}\secondHalf} +\def\locNsrIdentitySuccess { \locNsr\col{\_identity\_success}} +\def\locNsrIdentityFKTH { \locNsr\col{\_identity\_FKTH}} +\def\locNsrIdentityFKTR { \locNsr\col{\_identity\_FKTR}} +% MODEXP +%%%%%%%% +\def\locFlagSumModexp { \flagSum\col{\_modexp}\secondHalf} +\def\locFlagSumModexpSuccess { \flagSum\col{\_modexp\_success}} +\def\locFlagSumModexpFKTH { \flagSum\col{\_modexp\_FKTH}} +\def\locFlagSumModexpFKTR { \flagSum\col{\_modexp\_FKTR}} +\def\locNsrModexp { \locNsr\col{\_modexp}\secondHalf} +\def\locNsrModexpSuccess { \locNsr\col{\_modexp\_success}} +\def\locNsrModexpFKTH { \locNsr\col{\_modexp\_FKTH}} +\def\locNsrModexpFKTR { \locNsr\col{\_modexp\_FKTR}} +% ECADD +%%%%%%% +\def\locFlagSumEcadd { \flagSum\col{\_ecadd}\secondHalf} +\def\locFlagSumEcaddSuccess { \flagSum\col{\_ecadd\_success}} +\def\locFlagSumEcaddFKTH { \flagSum\col{\_ecadd\_FKTH}} +\def\locFlagSumEcaddFKTR { \flagSum\col{\_ecadd\_FKTR}} +\def\locNsrEcadd { \locNsr\col{\_ecadd}\secondHalf} +\def\locNsrEcaddSuccess { \locNsr\col{\_ecadd\_success}} +\def\locNsrEcaddFKTH { \locNsr\col{\_ecadd\_FKTH}} +\def\locNsrEcaddFKTR { \locNsr\col{\_ecadd\_FKTR}} +% ECMUL +%%%%%%% +\def\locFlagSumEcmul { \flagSum\col{\_ecmul}\secondHalf} +\def\locFlagSumEcmulSuccess { \flagSum\col{\_ecmul\_success}} +\def\locFlagSumEcmulFKTH { \flagSum\col{\_ecmul\_FKTH}} +\def\locFlagSumEcmulFKTR { \flagSum\col{\_ecmul\_FKTR}} +\def\locNsrEcmul { \locNsr\col{\_ecmul}\secondHalf} +\def\locNsrEcmulSuccess { \locNsr\col{\_ecmul\_success}} +\def\locNsrEcmulFKTH { \locNsr\col{\_ecmul\_FKTH}} +\def\locNsrEcmulFKTR { \locNsr\col{\_ecmul\_FKTR}} +% ECPAIRING +%%%%%%%%%%% +\def\locFlagSumEcpairing { \flagSum\col{\_ecpairing}\secondHalf} +\def\locFlagSumEcpairingSuccess { \flagSum\col{\_ecpairing\_success}} +\def\locFlagSumEcpairingFKTH { \flagSum\col{\_ecpairing\_FKTH}} +\def\locFlagSumEcpairingFKTR { \flagSum\col{\_ecpairing\_FKTR}} +\def\locNsrEcpairing { \locNsr\col{\_ecpairing}\secondHalf} +\def\locNsrEcpairingSuccess { \locNsr\col{\_ecpairing\_success}} +\def\locNsrEcpairingFKTH { \locNsr\col{\_ecpairing\_FKTH}} +\def\locNsrEcpairingFKTR { \locNsr\col{\_ecpairing\_FKTR}} + +% BLAKE +%%%%%%% +\def\locFlagSumBlake { \flagSum\col{\_blake}\secondHalf} +\def\locFlagSumBlakeSuccess { \flagSum\col{\_blake\_success}} +\def\locFlagSumBlakeFKTH { \flagSum\col{\_blake\_FKTH}} +\def\locFlagSumBlakeFKTR { \flagSum\col{\_blake\_FKTR}} +\def\locNsrBlake { \locNsr\col{\_blake}\secondHalf} +\def\locNsrBlakeSuccess { \locNsr\col{\_blake\_success}} +\def\locNsrBlakeFKTH { \locNsr\col{\_blake\_FKTH}} +\def\locNsrBlakeFKTR { \locNsr\col{\_blake\_FKTR}} +\def\locBlakeHmtDataSize {\redm{208}} +\def\locBlakeCallDataSize {\redm{213}} +\def\locBlakeRparamSize {\redm{4}} +\def\locBlakeFparamSize {\redm{1}} + +\def\nsrPrcFailureKnownToTheHub {\redm{\colm{nsr\_failure}}} +\def\nsrPrcSuccessWillRevertStandard {\redm{\colm{nsr\_success\_will\_revert}}} +\def\nsrPrcSuccessWontRevertStandard {\redm{\colm{nsr\_success\_wont\_revert}}} +\def\nsrPrcSuccessWillRevertIdentity {\redm{\colm{nsr\_identity\_success\_will\_revert}}} +\def\nsrPrcSuccessWontRevertIdentity {\redm{\colm{nsr\_identity\_success\_wont\_revert}}} +\def\nsrPrcFailureKnownToTheHubConst {\textcolor{draculaorange}{\bm{8 }}} +\def\nsrPrcSuccessWillRevertStandardConst {\textcolor{draculaorange}{\bm{12}}} +\def\nsrPrcSuccessWontRevertStandardConst {\textcolor{draculaorange}{\bm{10}}} +\def\nsrPrcSuccessWillRevertIdentityConst {\textcolor{draculaorange}{\bm{11}}} +\def\nsrPrcSuccessWontRevertIdentityConst {\textcolor{draculaorange}{\bm{9 }}} + + +\def\locFkth {\col{FAIL\_HUB}} +\def\locFktr {\col{FAIL\_RAM}} +\def\locSwill {\col{SUCC\_WILL}} +\def\locSwont {\col{SUCC\_WONT}} +\def\johnSnow {$\graym{\varnothing}$} +\def\locStandardFail {$\nsrPrcFailureKnownToTheHubConst \quad ( = \callPrcFailureSecondScenarioRowOffset + 3 )$} +\def\locStandardSuccWill {$\nsrPrcSuccessWillRevertStandardConst \quad ( = \callPrcSuccessWillRevertSecondScenarioRowOffset + 5 )$} +\def\locStandardSuccWont {$\nsrPrcSuccessWontRevertStandardConst \quad ( = \callPrcSuccessWontRevertSecondScenarioRowOffset + 5 )$} +\def\locIdentitySuccWill {$\nsrPrcSuccessWillRevertIdentityConst \quad ( = \callPrcSuccessWillRevertSecondScenarioRowOffset + 4 )$} +\def\locIdentitySuccWont {$\nsrPrcSuccessWontRevertIdentityConst \quad ( = \callPrcSuccessWontRevertSecondScenarioRowOffset + 4 )$} +\def\locModexpFKTR {$\textcolor{draculaorange}{\bm{13}} \quad ( = \callPrcFailureSecondScenarioRowOffset + 8 )$} +\def\locModexpSuccWill {$\textcolor{draculaorange}{\bm{20}} \quad ( = \callPrcSuccessWillRevertSecondScenarioRowOffset + 13 )$} +\def\locModexpSuccWont {$\textcolor{draculaorange}{\bm{18}} \quad ( = \callPrcSuccessWontRevertSecondScenarioRowOffset + 13 )$} +\def\locBlakeFKTH {$\textcolor{draculaorange}{\bm{8} } \quad ( = \callPrcFailureSecondScenarioRowOffset + 3 )$} +\def\locBlakeFKTR {$\textcolor{draculaorange}{\bm{9} } \quad ( = \callPrcFailureSecondScenarioRowOffset + 4 )$} +\def\locBlakeSuccWill {$\textcolor{draculaorange}{\bm{13}} \quad ( = \callPrcSuccessWillRevertSecondScenarioRowOffset + 6 )$} +\def\locBlakeSuccWont {$\textcolor{draculaorange}{\bm{11}} \quad ( = \callPrcSuccessWontRevertSecondScenarioRowOffset + 6 )$} + +\def\prcCommonMiscRowOffset {\yellowm{1}} +\def\prcCommonFKTRContextRowOffset {\yellowm{2}} +\def\prcStandardSuccessSecondMiscRowOffset {\yellowm{2}} +\def\prcStandardSuccessThirdMiscRowOffset {\yellowm{3}} +\def\prcStandardSuccessCallerContextRowRowOffset {\yellowm{4}} +\def\prcIdentitySuccessCallerContextRowRowOffset {\yellowm{3}} + +\def\prcBlakeFirstMiscRowOffset {\yellowm{1}} +\def\prcBlakeSecondMiscRowOffset {\yellowm{2}} +\def\prcBlakeThirdMiscRowOffset {\yellowm{3}} +\def\prcBlakeFourthMiscRowOffset {\yellowm{4}} +\def\prcBlakeFKTHCallerContextRowOffset {\yellowm{2}} +\def\prcBlakeFKTRCallerContextRowOffset {\yellowm{3}} +\def\prcBlakeSuccessCallerContextRowOffset {\yellowm{5}} + +\def\prcModexpCdsMiscRowOffset {\yellowm{1}} +\def\prcModexpFirstXbsRowOffset {\yellowm{2}} +\def\prcModexpSecondXbsRowOffset {\yellowm{3}} +\def\prcModexpThirdXbsRowOffset {\yellowm{4}} +\def\prcModexpLeadRowOffset {\yellowm{5}} +\def\prcModexpPricingRowOffset {\yellowm{6}} + +\def\prcModexpFKTRcallerContextRowOffset {\yellowm{7}} + +\def\prcModexpSuccessExtractBaseRowOffset {\yellowm{7}} +\def\prcModexpSuccessExtractExponentRowOffset {\yellowm{8}} +\def\prcModexpSuccessExtractModulusRowOffset {\yellowm{9}} +\def\prcModexpSuccessTransferResultRowOffset {\yellowm{10}} +\def\prcModexpSuccessPartialCopyOfResultsRowOffset {\yellowm{11}} +\def\prcModexpSuccessUpdatingCallerReturnData {\yellowm{12}} diff --git a/hub/instruction_handling/call/precompiles/blake/_inputs.tex b/hub/instruction_handling/call/precompiles/blake/_inputs.tex new file mode 100644 index 0000000..866e657 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/_inputs.tex @@ -0,0 +1,7 @@ +\subsubsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: precompiles: blake: introduction} \input{instruction_handling/call/precompiles/blake/intro} +\subsubsubsection{\inst{BLAKE2f} representation \lispNone{}} \label{hub: instruction handling: call: precompiles: blake: representation} \input{instruction_handling/call/precompiles/blake/representation} +\subsubsubsection{\inst{BLAKE2f} generalities \lispTodo{}} \label{hub: instruction handling: call: precompiles: blake: generalities} \input{instruction_handling/call/precompiles/blake/generalities} +\subsubsubsection{\inst{BLAKE2f} the \scenPrcFailureKnownToHub{} case \lispTodo{}} \label{hub: instruction handling: call: precompiles: blake: failure KTH} \input{instruction_handling/call/precompiles/blake/failure_KTH} +\subsubsubsection{\inst{BLAKE2f} surviving the \hubMod{} \lispTodo{}} \label{hub: instruction handling: call: precompiles: blake: surviving} \input{instruction_handling/call/precompiles/blake/surviving} +\subsubsubsection{\inst{BLAKE2f} the \scenPrcFailureKnownToRam{} case \lispTodo{}} \label{hub: instruction handling: call: precompiles: blake: failure KTR} \input{instruction_handling/call/precompiles/blake/failure_KTR} +\subsubsubsection{\inst{BLAKE2f} the \scenPrcSuccess{} case \lispTodo{}} \label{hub: instruction handling: call: precompiles: blake: success} \input{instruction_handling/call/precompiles/blake/success} diff --git a/hub/instruction_handling/call/precompiles/blake/failure_KTH.tex b/hub/instruction_handling/call/precompiles/blake/failure_KTH.tex new file mode 100644 index 0000000..596f126 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/failure_KTH.tex @@ -0,0 +1,19 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenBlake _{i} & = & 1 \\ + \scenPrcFailureKnownToHub _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus considering the first row of the second phase of the \hubMod{}'s processing of a \inst{CALL} to the \inst{BLAKE2f} precompile. +\begin{description} + \item[\underline{Context-row $n^°(i + \prcBlakeFKTHCallerContextRowOffset)$:}] + we impose that + \[ + \nonContextProvidesEmptyReturnData + {i}{\prcBlakeFKTHCallerContextRowOffset} + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/blake/failure_KTR.tex b/hub/instruction_handling/call/precompiles/blake/failure_KTR.tex new file mode 100644 index 0000000..b9e00d4 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/failure_KTR.tex @@ -0,0 +1,22 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenBlake _{i} & = & 1 \\ + \scenPrcFailureKnownToRam _{i} & = & 0 \\ + \end{array} \right. + } +\end{center} +We are thus considering the first row of the second phase of the \hubMod{}'s processing of a \inst{CALL} to the \inst{BLAKE2f} precompile. +We are further assuming that the \hubMod{} module didn't detect an exceptional \inst{CALL} to the \inst{BLAKE2f} precompile (i.e. $\cds = \locBlakeCallDataSize$.) +The only thing that remains to do is for us to set the return data of the caller context to being empty. +\begin{description} + \item[\underline{Context-row $n^°(i + \prcBlakeFKTRCallerContextRowOffset)$:}] + we impose + \[ + \nonContextProvidesEmptyReturnData + {i}{\prcBlakeFKTRCallerContextRowOffset} + \] +\end{description} + diff --git a/hub/instruction_handling/call/precompiles/blake/generalities.tex b/hub/instruction_handling/call/precompiles/blake/generalities.tex new file mode 100644 index 0000000..77d03b2 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/generalities.tex @@ -0,0 +1,113 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenBlake _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus considering the first row of the second phase of the \hubMod{}'s processing of a \inst{CALL} to the \inst{BLAKE2f} precompile. +The first row is always a miscellaneous-row. +\begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcBlakeFirstMiscRowOffset)$:}}] + we impose that + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum {i}{\prcBlakeFirstMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \!\!\! \cdot \!\!\! & \locOobResultHubSuccess \\ + + & \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcBlakeFirstMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcBlakeFirstMiscRowOffset} & = & \undefinedStar \quad \locOobResultHubSuccess & (\trash) \\ + \miscMxpFlag _{i + \prcBlakeFirstMiscRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcBlakeFirstMiscRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcBlakeFirstMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + We are thus always calling the \oobMod{} and only calling the \mmuMod{} if the call to the \oobMod{} + + \saNote{} The shorthand \locOobResultHubSuccess{} which we label with $\undefinedStar$ will be set below. + \item[\underline{Setting \oobMod{} values and shorthands:}] + we impose the following constraints + \[ + \setOobInstructionBlakeCds { + anchorRow = i , + relOffset = \prcBlakeFirstMiscRowOffset , + callDataSize = \locPrcCds , + returnAtCapacity = \locPrcRac , + } + \label{hub: instruction handling: call: precompiles: blake: hub success call} + % \left\{ \begin{array}{lcl} \label{hub: instruction handling: call: precompiles: blake: hub success call} + % \miscOobInst _{i + \prcBlakeFirstMiscRowOffset} & = & \oobInstBlakeCds \vspace{2mm} \\ + % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \miscOobDataCol{1} _{i + \prcBlakeFirstMiscRowOffset} & = & \nothing \\ + % \miscOobDataCol{2} _{i + \prcBlakeFirstMiscRowOffset} & = & \locPrcCds \\ + % \miscOobDataCol{3} _{i + \prcBlakeFirstMiscRowOffset} & = & \locPrcRac \\ + % \miscOobDataCol{4} _{i + \prcBlakeFirstMiscRowOffset} & = & \relevantValue \\ + % \miscOobDataCol{5} _{i + \prcBlakeFirstMiscRowOffset} & = & \nothing \\ + % \miscOobDataCol{6} _{i + \prcBlakeFirstMiscRowOffset} & = & \nothing \\ + % \miscOobDataCol{7} _{i + \prcBlakeFirstMiscRowOffset} & = & \nothing \\ + % \miscOobDataCol{8} _{i + \prcBlakeFirstMiscRowOffset} & = & \relevantValue \\ + % \end{array} \right. + \] + We also define the following shorthands + \[ + \left\{ \begin{array}{lcl} \label{hub: instruction handling: call: precompiles: blake: shorthands} + % & \define & \miscOobDataCol{1}_{i + \prcBlakeFirstMiscRowOffset} \\ + % & \define & \miscOobDataCol{2}_{i + \prcBlakeFirstMiscRowOffset} \\ + % & \define & \miscOobDataCol{3}_{i + \prcBlakeFirstMiscRowOffset} \\ + \locOobResultHubSuccess & \define & \miscOobDataCol{4}_{i + \prcBlakeFirstMiscRowOffset} \\ + % & \define & \miscOobDataCol{5}_{i + \prcBlakeFirstMiscRowOffset} \\ + % & \define & \miscOobDataCol{6}_{i + \prcBlakeFirstMiscRowOffset} \\ + % & \define & \miscOobDataCol{7}_{i + \prcBlakeFirstMiscRowOffset} \\ + \locOobResultNonzeroRac & \define & \miscOobDataCol{8}_{i + \prcBlakeFirstMiscRowOffset} \\ + \end{array} \right. + \] + \saNote{} We have, by construction and by the computation in the \oobMod{} module, the following relations: + \[ + \locOobResultHubSuccess \equiv \text{binary} + \] + \item[\underline{Setting \scenPrcFailureKnownToHub{}:}] + we impose + \[ + \scenPrcFailureKnownToHub_{i} = 1 - \locOobResultHubSuccess. + \] + \item[\underline{Setting \mmuMod{} values:}] + \If $\miscMmuFlag_{i + \prcBlakeFirstMiscRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersBlake { + anchorRow = i , + relOffset = \prcBlakeFirstMiscRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + sourceOffsetLo = \locPrcCdo , + successBit = \scenPrcSuccess_{i} , + limbOne = \relevantValue , + limbTwo = \relevantValue , + } + \] + We also define the following shorthands + \[ + \left\{ \begin{array}{lcl} \label{hub: instruction handling: call: precompiles: blake: shorthands} + \locBlakeR & \define & \miscMmuLimbOne _{i + \prcBlakeFirstMiscRowOffset} \\ + \locBlakeF & \define & \miscMmuLimbTwo _{i + \prcBlakeFirstMiscRowOffset} \\ + \end{array} \right. + \] + \saNote{} + The purpose of the setting $\miscMmuSuccessBit _{i + \prcBlakeFirstMiscRowOffset} = \scenPrcSuccess _{i}$ is for the \mmuMod{} / \mmioMod{} to decide, depending on the success bit, whether or not to send data to the \blakeDataMod{} module. + The data in question being the ``rounds'' parameter $\locBlakeR \equiv I_\textbf{d}[0..4]$ and the ``f'' parameter $\locBlakeF \equiv I_\textbf{d}[212]$, using notations from the \cite{EYP}. + + \saNote{} + At this point only $\scenPrcFailureKnownToHub$ was set. + The distinction between the two remaing cases ($\scenPrcFailureKnownToRam$ nor $\scenPrcSuccess$) has been set. + \end{description} + \end{description} diff --git a/hub/instruction_handling/call/precompiles/blake/intro.tex b/hub/instruction_handling/call/precompiles/blake/intro.tex new file mode 100644 index 0000000..3afc38b --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/intro.tex @@ -0,0 +1,13 @@ +The \inst{BLAKE2f} precompile can fail ``in the \hubMod{}'' or ``in \textsc{ram}.'' +It fails ``in the \hubMod{}'' \emph{if and only if} $\CDS \neq 213$. +It fails ``in \textsc{ram}'' \emph{if and only if} (it didn't fail in the \hubMod{} and) upon excavating the +``rounds'' parameter \locBlakeR{} and the +``final block indicator flag'' parameter \locBlakeF{} +from \textsc{ram}, sending these parameters to the \oobMod{} module with the appropriate \oobMod{}-instruction, either +(\emph{a}) the precompile was provided with insufficient gas to pay for \locBlakeR{} many rounds of \inst{BLAKE2f} +(\emph{b}) the ``\locBlakeF{}'' parameter fails to be a bit. + +If the call is successful the remaining steps are essentially the same as for other precompiles: +(\emph{a}) extract the data +(\emph{a}) transfer the full result (which occupies $\blakeReturnDataSize$ bytes of return data) +(\emph{a}) potentially copy parts of the result over to the current execution context's \textsc{ram}. diff --git a/hub/instruction_handling/call/precompiles/blake/lua/common.lua.tex b/hub/instruction_handling/call/precompiles/blake/lua/common.lua.tex new file mode 100644 index 0000000..28aaf07 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/lua/common.lua.tex @@ -0,0 +1,70 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +███████\ ██\ ██████\ ██\ ██\ ████████\ ██████\ ██████\ +██ __██\ ██ | ██ __██\ ██ | ██ |██ _____|██ __██\ ██ __██\ +██ | ██ |██ | ██ / ██ |██ |██ / ██ | \__/ ██ |██ / \__| +███████\ |██ | ████████ |█████ / █████\ ██████ |████\ +██ __██\ ██ | ██ __██ |██ ██< ██ __| ██ ____/ ██ _| +██ | ██ |██ | ██ | ██ |██ |\██\ ██ | ██ | ██ | +███████ |████████\ ██ | ██ |██ | \██\ ████████\ ████████\ ██ | +\_______/ \________|\__| \__|\__| \__|\________|\________|\__| + + + __| _ \ __ `__ \ __ `__ \ _ \ __ \ + ( ( | | | | | | | ( | | | +\___| \___/ _| _| _| _| _| _| \___/ _| _| + + +|-------+--------+-------------------------------+---------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------+---------------------------------------------------------| +| i | SCEN | SCEN/BLAKE2f | SCEN/SUCCESS + SCEN/PRC_FKTR + SCEN/PRC_FKTH = 1 | +|-------+--------+-------------------------------+---------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_blake_cds⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [cds = 213] | +| | | | | +| | | | WE IMPOSE: | +| | | | ========== | +| | | | SCEN/PRC_FKTH + hub_success = 1 | +| | | | if hub_success = 1 then: SCEN/PRC_SUCCESS = SUCCESS_BIT | +| | | | | +| | | MMU🏴 = hub_success | | +| | | MMU_INST = | | +| | | ID_SRC = cn | | +| | | SRC_OFF = cdo | | +| | | val_hi = r, val_lo = f | | +| | | SUCCESS_BIT = 0 / 1 | | +| | | | | +| | | ID_TGT = 1 + HUB_ | | +| | | | | +| | | Recall: we have to transfer | | +| | | r and f to BLAKE_DATA in case | | +| | | the call is successful | | +|-------+--------+-------------------------------+---------------------------------------------------------| +| ... | ... | ... | ... | +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/blake/lua/failure_KTH.lua.tex b/hub/instruction_handling/call/precompiles/blake/lua/failure_KTH.lua.tex new file mode 100644 index 0000000..ae1d67a --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/lua/failure_KTH.lua.tex @@ -0,0 +1,57 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +███████\ ██\ ██████\ ██\ ██\ ████████\ ██████\ ██████\ +██ __██\ ██ | ██ __██\ ██ | ██ |██ _____|██ __██\ ██ __██\ +██ | ██ |██ | ██ / ██ |██ |██ / ██ | \__/ ██ |██ / \__| +███████\ |██ | ████████ |█████ / █████\ ██████ |████\ +██ __██\ ██ | ██ __██ |██ ██< ██ __| ██ ____/ ██ _| +██ | ██ |██ | ██ | ██ |██ |\██\ ██ | ██ | ██ | +███████ |████████\ ██ | ██ |██ | \██\ ████████\ ████████\ ██ | +\_______/ \________|\__| \__|\__| \__|\________|\________|\__| + + + | | | | __ ) _| _) | + | | | | __ \ | _` | | | | | __| _ \ + ___ | | | | | __| ( | | | | | | __/ +_| _| \___/ ____/ _| \__,_| _| _| \__,_| _| \___| + + +|-------+--------+-------------------------------------+---------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+---------------------------------| +| i | SCEN | SCEN/BLAKE2f | SCEN/PRC_FKTH = 1 ⛔ | +|-------+--------+-------------------------------------+---------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_blake_cds⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [cds = 213] | +| | | | | +| | | | here: hub_success = 0 | +| | | | | +| | | MMU🏴 = 0 (= hub_success) | | +|-------+--------+-------------------------------------+---------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/blake/lua/failure_KTR.lua.tex b/hub/instruction_handling/call/precompiles/blake/lua/failure_KTR.lua.tex new file mode 100644 index 0000000..fa3d979 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/lua/failure_KTR.lua.tex @@ -0,0 +1,92 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +███████\ ██\ ██████\ ██\ ██\ ████████\ ██████\ ██████\ +██ __██\ ██ | ██ __██\ ██ | ██ |██ _____|██ __██\ ██ __██\ +██ | ██ |██ | ██ / ██ |██ |██ / ██ | \__/ ██ |██ / \__| +███████\ |██ | ████████ |█████ / █████\ ██████ |████\ +██ __██\ ██ | ██ __██ |██ ██< ██ __| ██ ____/ ██ _| +██ | ██ |██ | ██ | ██ |██ |\██\ ██ | ██ | ██ | +███████ |████████\ ██ | ██ |██ | \██\ ████████\ ████████\ ██ | +\_______/ \________|\__| \__|\__| \__|\________|\________|\__| + + + _ \ \ \ | _| _) | + | | _ \ |\/ | | _` | | | | | __| _ \ + __ < ___ \ | | __| ( | | | | | | __/ +_| \_\ _/ _\ _| _| _| \__,_| _| _| \__,_| _| \___| + + +|-------+--------+---------------------------------------------+----------------------------------------------| +| Row | Persp. | | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i | SCEN | SCEN/BLAKE2f | SCEN/PRC_FKTR = 1 ⛔ | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_blake_cds⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [cds = 213] | +| | | | | +| | | | here: hub_success = 1 | +| | | | | +| | | MMU🏴 = hub_success (here: 1) | | +| | | MMU_INST = | | +| | | ⟦MMU_INST_blakeParameterExtraction⟧ | | +| | | * SUCCESS_BIT = SCEN/PRC_SUCCESS (here: 0) | | +| | | * extract r (don't send to BLAKE_DATA) | | +| | | * extract f (don't send to BLAKE_DATA) | | +| | | | | +| | | SRC_ID = cn | | +| | | SRC_OFF = cdo | | +| | | TGT_ID = 1 + HUB_ | | +| | | PHASE = Φ_blake_prams | | +| | | EXO_SUM = ⟦1 << blake⟧ | | +| | | | | +| | | RECALL: we don't transfer r and f to | | +| | | BLAKE_DATA in case the call is unsuccessful | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 2 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_blake_params⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * call_gas | +| | | | * r | +| | | | * f | +| | | | * r@c | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * ram_success := [r ≤ call_gas] ∧ [f ≡ bit] | +| | | | * return_gas := 0 ∨ [call_gas - r] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | | WE IMPOSE: | +| | | | ========== | +| | | | SUCCESS_BIT = ram_success | +| | | | here: ram_success = 0 | +| | | | | +| | | MMU🏴 = ram_success (here: 0) | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 3 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+---------------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/blake/lua/success.lua.tex b/hub/instruction_handling/call/precompiles/blake/lua/success.lua.tex new file mode 100644 index 0000000..c1f5417 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/lua/success.lua.tex @@ -0,0 +1,122 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +███████\ ██\ ██████\ ██\ ██\ ████████\ ██████\ ██████\ +██ __██\ ██ | ██ __██\ ██ | ██ |██ _____|██ __██\ ██ __██\ +██ | ██ |██ | ██ / ██ |██ |██ / ██ | \__/ ██ |██ / \__| +███████\ |██ | ████████ |█████ / █████\ ██████ |████\ +██ __██\ ██ | ██ __██ |██ ██< ██ __| ██ ____/ ██ _| +██ | ██ |██ | ██ | ██ |██ |\██\ ██ | ██ | ██ | +███████ |████████\ ██ | ██ |██ | \██\ ████████\ ████████\ ██ | +\_______/ \________|\__| \__|\__| \__|\________|\________|\__| + + + __| | | __| __| _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ + ____/ \__,_| \___| \___| \___| ____/ ____/ + + +|-------+--------+---------------------------------------------+----------------------------------------------| +| Row | Persp. | | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i | SCEN | SCEN/BLAKE2f | SCEN/PRC_SUCCESS = 1 ✅ | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_blake_cds⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [cds = 213] | +| | | | | +| | | | here: hub_success = 1 | +| | | | | +| | | MMU🏴 = hub_success (here: 1) | | +| | | MMU_INST = | | +| | | ⟦MMU_INST_blake⟧ | | +| | | * SUCCESS_BIT = SCEN/PRC_SUCCESS (here: 1) | | +| | | * extract r (and send to BLAKE_DATA) | | +| | | * extract f (and send to BLAKE_DATA) | | +| | | * send r, f to BLAKE_DATA if SUCCESS | | +| | | | | +| | | SRC_ID = cn | | +| | | SRC_OFF = cdo | | +| | | TGT_ID = 1 + HUB_ | | +| | | PHASE = Φ_blake_prams | | +| | | EXO_SUM = ⟦⟦1 << blake⟧⟧ | | +| | | | | +| | | RECALL: we do transfer r and f to | | +| | | BLAKE_DATA in case the call is successful | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 2 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_blake_params⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * call_gas | +| | | | * r | +| | | | * f | +| | | | * r@c | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * ram_success := [r ≤ call_gas] ∧ [f ≡ bit] | +| | | | * return_gas := 0 ∨ [call_gas - r] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | | here: ram_success = 1 | +| | | | | +| | | MMU🏴 = ram_success (here: 1) | | +| | | MMU_INST = | | +| | | 13 MMIO limb extractions | | +| | | | | +| | | ID_SRC = cn | | +| | | SRC_OFF = cdo | | +| | | | | +| | | SUCCESS_BIT = SCEN/PRC_SUCCESS | | +| | | 1 + HUB_ | | +| | | exo_sum = ⟦1 << blake⟧ | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 3 | MISC | MMU🏴 = 1 | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | 4 MMIO limb extractions | | +| | | | | +| | | ID_SRC = 1 + HUB_ | | +| | | SRC_OFF = ??? | | +| | | | | +| | | ID_TGT = 1 + HUB_ | | +| | | exo_sum = ⟦1 << blake⟧ | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 4 | MISC | MMU🏴 = r@c_nonzero | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | | | +| | | ID_SRC = 1 + HUB_ | | +| | | SRC_OFF = 0 | | +| | | | | +| | | ID_TGT = cn | | +| | | TGT_OFF = r@o | | +| | | SIZE = r@c | | +|-------+--------+---------------------------------------------+----------------------------------------------| +| i + 5 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = CDS | +|-------+--------+---------------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/blake/representation.tex b/hub/instruction_handling/call/precompiles/blake/representation.tex new file mode 100644 index 0000000..2ba5b92 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/representation.tex @@ -0,0 +1,4 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/blake/lua/common.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/blake/lua/failure_KTH.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/blake/lua/failure_KTR.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/blake/lua/success.pdf} diff --git a/hub/instruction_handling/call/precompiles/blake/success.tex b/hub/instruction_handling/call/precompiles/blake/success.tex new file mode 100644 index 0000000..973e155 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/success.tex @@ -0,0 +1,142 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenBlake _{i} & = & 1 \\ + \scenPrcSuccess _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus considering the first row of the second phase of the \hubMod{}'s processing of a \inst{CALL} to the \inst{BLAKE2f} precompile. +We are in the success case. +We still need to copy the result of the precompile over to a designated \textsc{ram} slot and to potentially do a partial transfer of that result to the current execution context's \textsc{ram}. +\begin{description} + \item[\underline{\underline{Miscellaneous-row $n^°(i + \prcBlakeThirdMiscRowOffset)$:}}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcBlakeThirdMiscRowOffset} + = + \miscMmuWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + 3} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + 3} & = & \one & (\trash) \\ + \miscMxpFlag _{i + 3} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + 3} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + 3} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{\mmuMod{} data:}] + we impose + \[ + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = 3 , + sourceId = 1 + \hubStamp_{i} , + targetId = 1 + \hubStamp_{i} , + size = \blakeReturnDataSize , + exoSum = \exoWeightBlakeModexp , + phase = \phaseBlakeResult , + } + % \left\{ \begin{array}{lcl} + % \miscMmuInst _{i + 3} & = & \mmuInstExoToRamTransplants \\ + % \miscMmuSrcId _{i + 3} & = & 1 + \hubStamp_{i} \\ + % \miscMmuTgtId _{i + 3} & = & 1 + \hubStamp_{i} \\ + % \miscMmuAuxId _{i + 3} & = & \nothing \\ + % \miscMmuSrcOffsetHi _{i + 3} & = & \nothing \\ + % \miscMmuSrcOffsetLo _{i + 3} & = & \nothing \\ + % \miscMmuTgtOffsetLo _{i + 3} & = & 0 \\ + % \miscMmuSize _{i + 3} & = & \redm{64} \\ + % \miscMmuRefOffset _{i + 3} & = & \nothing \\ + % \miscMmuRefSize _{i + 3} & = & \nothing \\ + % \miscMmuSuccessBit _{i + 3} & = & \nothing \\ + % \miscMmuLimbOne _{i + 3} & = & \nothing \\ + % \miscMmuLimbTwo _{i + 3} & = & \nothing \\ + % \miscMmuExoSum _{i + 3} & = & \exoWeightBlakeModexp \\ + % \miscMmuPhase _{i + 3} & = & \phaseBlakeResult \\ + % \end{array} \right. + \] + \saNote{} The output of a successful call to the \inst{BLAKE2f} precompile has length $\blakeReturnDataSize$. + \end{description} + \item[\underline{\underline{Miscellaneous-row $n^°(i + \prcBlakeFourthMiscRowOffset)$:}}] + the next step is to proceed (when relevant) to a (partial) transfer of return data to the caller context: + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcBlakeFourthMiscRowOffset} + = + \miscMmuWeight + \cdot + \locOobResultNonzeroRac + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcBlakeFourthMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcBlakeFourthMiscRowOffset} & = & \locOobResultNonzeroRac & (\trash) \\ + \miscMxpFlag _{i + \prcBlakeFourthMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcBlakeFourthMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcBlakeFourthMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{\mmuMod{} data:}] + \If $\miscMmuFlag_{i + \prcBlakeFourthMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcBlakeFourthMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = \cn_{i} , + sourceOffsetLo = 0 , + size = \blakeReturnDataSize , + referenceOffset = \locPrcRao , + referenceSize = \locPrcRac , + } + \] + % \[ + % \left\{ \begin{array}{lcl} + % \miscMmuInst _{i + \prcBlakeFourthMiscRowOffset} & = & \mmuInstRamToRamSansPadding \\ + % \miscMmuSrcId _{i + \prcBlakeFourthMiscRowOffset} & = & 1 + \hubStamp_{i} \\ + % \miscMmuTgtId _{i + \prcBlakeFourthMiscRowOffset} & = & \cn_{i} \\ + % \miscMmuAuxId _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuSrcOffsetHi _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuSrcOffsetLo _{i + \prcBlakeFourthMiscRowOffset} & = & 0 \\ + % \miscMmuTgtOffsetLo _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuSize _{i + \prcBlakeFourthMiscRowOffset} & = & \blakeReturnDataSize \\ + % \miscMmuRefOffset _{i + \prcBlakeFourthMiscRowOffset} & = & \locPrcRao \\ + % \miscMmuRefSize _{i + \prcBlakeFourthMiscRowOffset} & = & \locPrcRac \\ + % \miscMmuSuccessBit _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbOne _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbTwo _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuExoSum _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \miscMmuPhase _{i + \prcBlakeFourthMiscRowOffset} & = & \nothing \\ + % \end{array} \right. + % \] + \end{description} + \item[\underline{\underline{Context-row $n^°(i + \prcBlakeSuccessCallerContextRowOffset)$:}}] + we impose \ + \[ + \provideReturnData { + anchorRow = i , + relOffset = \prcBlakeSuccessCallerContextRowOffset , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = 0 , + returnDataSize = \blakeReturnDataSize , + } + % \provideReturnData + % {i}{4} + % {\cn_{i} } % Return data receiver + % {1 + \hubStamp_{i}} % Return data provider + % {0 } % Return data offset + % {\redm{64} } % Return data size + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/blake/surviving.tex b/hub/instruction_handling/call/precompiles/blake/surviving.tex new file mode 100644 index 0000000..c2149ab --- /dev/null +++ b/hub/instruction_handling/call/precompiles/blake/surviving.tex @@ -0,0 +1,120 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenBlake _{i} & = & 1 \\ + \scenPrcFailureKnownToHub _{i} & = & 0 \\ + \end{array} \right. + } +\end{center} +We are thus considering the first row of the second phase of the \hubMod{}'s processing of a \inst{CALL} to the \inst{BLAKE2f} precompile. +We are further assuming that the \hubMod{} module didn't detect an exceptional \inst{CALL} to the \inst{BLAKE2f} precompile (i.e. $\cds = \locBlakeCallDataSize$.) +The call may still fail in \textsc{ram} (or succeed.) +We fix the behaviour of the next row, i.e. row $n^°(i + \prcBlakeSecondMiscRowOffset)$: +\begin{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcBlakeSecondMiscRowOffset)$:}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcBlakeSecondMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \!\!\! \cdot \!\!\! & \locOobResultRamSuccess \\ + + & \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcBlakeSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcBlakeSecondMiscRowOffset} & = & \undefinedStar \quad \locOobResultRamSuccess & (\trash) \\ + \miscMxpFlag _{i + \prcBlakeSecondMiscRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcBlakeSecondMiscRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcBlakeSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + We are thus always calling the \oobMod{} and only calling the \mmuMod{} if the call to the \oobMod{} + + \saNote{} The shorthand \locOobResultRamSuccess{} which we label with $\undefinedStar$ will be set below. + \item[\underline{Setting \oobMod{} values and shorthands:}] + we impose the following constraints + \[ + \setOobInstructionBlakeParams { + anchorRow = i , + relOffset = \prcBlakeSecondMiscRowOffset , + callGas = \locPrcCallGas , + blakeR = \locBlakeR , + blakeF = \locBlakeF , + } + \label{hub: instruction handling: call: precompiles: blake: hub success call} + \] + We also define the following shorthands + \[ + \left\{ \begin{array}{lcl} \label{hub: instruction handling: call: precompiles: blake: shorthands} + % & \define & \miscOobDataCol{1}_{i + \prcBlakeSecondMiscRowOffset} \\ + % & \define & \miscOobDataCol{2}_{i + \prcBlakeSecondMiscRowOffset} \\ + % & \define & \miscOobDataCol{3}_{i + \prcBlakeSecondMiscRowOffset} \\ + \locOobResultRamSuccess & \define & \miscOobDataCol{4}_{i + \prcBlakeSecondMiscRowOffset} \\ + \locOobResultReturnGas & \define & \miscOobDataCol{5}_{i + \prcBlakeSecondMiscRowOffset} \\ + % \locOobResultExtractCallData & \define & \miscOobDataCol{6}_{i + \prcBlakeSecondMiscRowOffset} \\ + % \locOobResultEmptyCallData & \define & \miscOobDataCol{7}_{i + \prcBlakeSecondMiscRowOffset} \\ + % \locOobResultNonzeroRac & \define & \miscOobDataCol{8}_{i + \prcBlakeSecondMiscRowOffset} \\ + \end{array} \right. + \] + \saNote{} We have, by construction and by the computation in the \oobMod{} module, the following relations: + \[ + \locOobResultRamSuccess \equiv \text{binary} + \] + \item[\underline{Setting \mmuMod{} values:}] + \If $\miscMmuFlag_{i + \prcBlakeSecondMiscRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i , + relOffset = \prcBlakeSecondMiscRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + auxiliaryId = \nothing , + sourceOffsetLo = \locPrcCdo + \locBlakeRparamSize , + size = \locBlakeHmtDataSize , + referenceSize = \locBlakeHmtDataSize , + successBit = \nothing , + exoSum = \exoWeightBlakeModexp , + phase = \phaseBlakeData , + } + \] + \saNote{} Recall that the \inst{BLAKE2f} precompile fails unless $\cds \equiv \locBlakeCallDataSize$. + Also $\locBlakeCallDataSize = \locBlakeRparamSize + \locBlakeHmtDataSize + \locBlakeFparamSize$, with + the ``rounds'' parameter occupying the first $\locBlakeRparamSize$ bytes and + the ``f'' parameter occupying the last $\locBlakeFparamSize$ bytes, i.e. the final byte. + The above step thus extracts the $\locBlakeHmtDataSize = 13 \cdot \llarge$ bytes in between contains + ``\texttt{h}'', + ``\texttt{m}'', + ``\texttt{t\_max}'' and + ``\texttt{t\_min}''. + \end{description} + \item[\underline{Setting \scenPrcFailureKnownToHub{}:}] + we impose + \[ + \left\{ \begin{array}{lclr} + \scenPrcSuccess _{i} & = & \locOobResultRamSuccess \\ + \scenPrcFailureKnownToRam _{i} & = & 1 - \locOobResultRamSuccess & (\trash) \\ + \end{array} \right. + \] + \saNote{} + With this we have set all success / failure flags. + + \saNote{} + It is enough to impose \textbf{one} of the preceding constraints. + \item[\underline{Justifying return gas prediction:}] + we impose + \[ + \locPrcReturnGas + = + \scenPrcSuccess_{i} + \cdot + \locOobResultReturnGas. + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/classification.tex b/hub/instruction_handling/call/precompiles/classification.tex new file mode 100644 index 0000000..2e7beb5 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/classification.tex @@ -0,0 +1,88 @@ +\def\toOob {$\rightsquigarrow$ \oobMod{}} +In the present section we go over the various precompiles and the failures they can provoke. +We distinguish between two failure modes: $\scenPrcFailureKnownToHub$ and $\scenPrcFailureKnownToRam$. +The general idea is that all failure scenarios that are detectable without interacting with \textsc{ram} trigger the $\scenPrcFailureKnownToHub$ flag, while those that require reading or even extracting data from \textsc{ram} fall into the $\scenPrcFailureKnownToRam$ category. +In particular we explain which precompiles may raise the $\scenPrcFailureKnownToRam$ flag. +\begin{figure}[!h] + \centering + \begin{tabular}{|l||l|c|l|} \hline + \textsc{Precompile} & \multicolumn{2}{c|}{\scenPrcFailureKnownToHub} & \scenPrcFailureKnownToRam \\ \hline \hline + \inst{ECRECOVER} & insufficient gas & \toOob & $\nothing$ \\ \hline + \inst{SHA2-256} & insufficient gas & \toOob & $\nothing$ \\ \hline + \inst{RIPEMD-160} & insufficient gas & \toOob & $\nothing$ \\ \hline + \inst{IDENTITY} & insufficient gas & \toOob & $\nothing$ \\ \hline + \multirow{2}{*}{\inst{MODEXP}} & \multirow{2}{*}{$\nothing$} & & insufficient gas \\ + \iffalse\fi & & & extracting $\ell_B,\ell_E,\ell_M,\ell_E'$ \\ \hline + \multirow{2}{*}{\inst{ECADD}} & \multirow{2}{*}{insufficient gas} & \multirow{2}{*}{\toOob} & malformed data: \\ + \iffalse\fi & & & $x = \varnothing \vee y = \varnothing$ \\ \hline + \multirow{2}{*}{\inst{ECMUL}} & \multirow{2}{*}{insufficient gas} & \multirow{2}{*}{\toOob} & malformed data: \\ + \iffalse\fi & & & $x = \varnothing$ \\ \hline + \multirow{2}{*}{\inst{ECPAIRING}} & insufficient gas & \multirow{2}{*}{\toOob} & malformed data: \\ + \iffalse\fi & $\cds\not\equiv0\mod192$ & & $\exists j$ such that $a_j = \varnothing \vee b_j = \varnothing$ \\ \hline + \multirow{2}{*}{\inst{BLAKE2f}} & \multirow{2}{*}{$\cds\neq213$} & \multirow{2}{*}{\toOob} & $r$ (gas cost) too high \\ + \iffalse\fi & & & $f$ is not a bit \\ \hline + \end{tabular} + \label{hub: instruction handling: call: precompiles: table classifying failures known to the HUB vs. to RAM} + \caption{All justifications for \scenPrcFailureKnownToHub{}'s are done through the \oobMod{} module. Notations such as ``$x = \varnothing''$ are from the \cite{EYP}.} +\end{figure} + +\noindent We now give full details. +\begin{description} + \item[\inst{ECRECOVER}:] + failure is entirely detectable using \hubMod{} data; + failure can only be due to insufficient gas; + gas cost is fixed; + the precompile may however return either $()$ if data is malformed or no public address is recoverable; + otherwise it returns $\textbf{o} \in \mathbb{B}_{32}$ a $32$ byte slice containing a $20$ byte address. + \item[\inst{SHA2-256}, \inst{RIPEMD-160} and \inst{IDENTITY}:] + failure is entirely detectable using \hubMod{} data; + failure can only be due to insufficient gas; + computing the gas cost can be done entirely in terms of the underlying \inst{CALL}-type instruction's \CDS{} which is a stack argument (and is available in the scenario row by virtue of the constraints in section~(\ref{hub: instruction handling: call: finishing: cases: prc})); + \item[\inst{MODEXP}:] + this is by far the most complex precompile from the point of view of the arithmetization of \inst{CALL}-type instructions in the \hubMod{} module; + this holds true on all levels: \hubMod{} general workflow, \oobMod{}, \expMod{}, \mmuMod{} and \textsc{ram} interaction; + failure can only be due to insufficient gas; + but computing the gas cost requires interacting with \textsc{ram} in order to extract certain parameters + ($\locBase$, $\locExponent$, $\locModulus$ and $\locExponentLogEYP$ using notations from the \cite{EYP}); + data extraction is complicated by the fact that $\cds$, the $\CDS$, may be arbitrary long / short; + shortness may lead to the extraction of fewer parameters according to the result of the following comparisons $\cds > 0 $, $\cds > 32$, $\cds > 64$; + on the other hand the result of comparisons such as $0 < \cds < 32$, $32 <\cds < 64$, $64 < \cds < 96$ impacts whether or not data must be trimmed before use; + if trimming is necessary the \expMod{} module is tasked with carrying it out; + furthermore extracting some of these parameters (e.g. $\locExponentLogEYP$) requires previously having extrated other parameters (namely $\locBase$ and $\locModulus$); + one must carry out some potentially complex ``$\lfloor \log_2(\cdots) \rfloor$-style'' computation; + one half of this computation (i.e. computing the $\lfloor \log_2(\cdots) \rfloor$ of the leading bytes of the exponent $\text{E}$) is done by the \expMod{} module; + return data is also a complex matter as it is \textbf{variable size}; + indeed return data is a slice $\textbf{o} \in \mathbb{B}^*$ of length $\locModulus$; + \item[\inst{ECADD} and \inst{ECMUL}:] + these can fail for several independent reasons, some known to the \hubMod{}, others known to the \mmuMod{}: + (\emph{a}) insufficient gas (which triggers the \scenPrcFailureKnownToHub{}) + (\emph{b}) sufficient gas but malformed call data (which triggers the \scenPrcFailureKnownToRam{}); + if none of these conditions are triggered the output is a 32 byte integer slice $\textbf{o} \in \mathbb{B}_{32}$; + \item[\inst{ECPARIRING}:] + this can fail both for reasons known to the \hubMod{} module and for reasons known to \textsc{ram}; + (\emph{a}) whenever $\CDS \not\equiv 0 \mod 192$ + (\emph{b}) insufficient gas + (\emph{c}) malformed data; + conditions (\emph{a}) and (\emph{b}) are detected by the \scenPrcFailureKnownToHub{} flag; + only (\emph{c}) requires touching \textsc{ram} in order to detect; + it is detected by \scenPrcFailureKnownToRam{}; + if none of these conditions are triggered the output is a 32 byte integer slice $\textbf{o} \in \mathbb{B}_{32}$; + the output slice is either + $ + \utt{00}\, + \utt{00} \cdots + \utt{00} \in \mathbb{B}_{32}$ + or + $ + \utt{00}\, + \utt{00} \cdots + \utt{01} \in \mathbb{B}_{32}$. + \item[\inst{BLAKE2f}:] + this can fail for several independent reasons; + (\emph{a}) whenever $\CDS \neq 213$ + (\emph{b}) insufficient gas + (\emph{c}) the ``$f$'' parameter isn't a bit; + the first point (\emph{a}) is detectable without touching \textsc{ram} and is detected by \scenPrcFailureKnownToHub{} + in order to address points (\emph{b}) and (\emph{c}) the arithmetization has to extract certain parameters from \textsc{ram} ($r$ and $f$ in \cite{EYP} notation); + these conditions are thus detected by \scenPrcFailureKnownToRam{}; +\end{description} diff --git a/hub/instruction_handling/call/precompiles/common/_inputs.tex b/hub/instruction_handling/call/precompiles/common/_inputs.tex new file mode 100644 index 0000000..f12d62e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: precompiles: common: intro} \input{instruction_handling/call/precompiles/common/intro} +\subsubsubsection{Representation \lispNone{}} \label{hub: instruction handling: call: precompiles: common: representation} \input{instruction_handling/call/precompiles/common/representation} +\subsubsubsection{Generalities \lispDone{}} \label{hub: instruction handling: call: precompiles: common: generalities} \input{instruction_handling/call/precompiles/common/generalities} +\subsubsubsection{The \scenPrcFailureKnownToHub{} case \lispDone{}} \label{hub: instruction handling: call: precompiles: common: failure known to hub} \input{instruction_handling/call/precompiles/common/failure_KTH} diff --git a/hub/instruction_handling/call/precompiles/common/failure_KTH.tex b/hub/instruction_handling/call/precompiles/common/failure_KTH.tex new file mode 100644 index 0000000..49c2e93 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/failure_KTH.tex @@ -0,0 +1,28 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenPrecompileCommon _{i} & = & 1 \\ + \scenPrcFailureKnownToHub _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus (again) assuming that the present row is the first of the second phase of dealing with the +\inst{ECRECOVER}, +\inst{SHA2-256}, +\inst{RIPEMD-160}, +\inst{IDENTITY}, +\inst{ECADD}, +\inst{ECMUL} or +\inst{ECPAIRING} precompiles. +However, this time we are also assuming that $\scenPrcFailureKnownToHub \equiv 1$. + +\saNote{} For all of these precompiles this information ``$\scenPrcFailureKnownToHub \equiv 1$'' can be gleamed off of the first miscellaneous-row of the second phase of the \hubMod{} module's processing. +Actually the same applies to \inst{BLAKE2f}, but we will keep it separate as filling of the first \oobMod{} data rows is different. + +The only task left for us at this point is to provide the caller context with empty return data: +\begin{description} + \item[\underline{Context-row $n^°(i + \prcCommonFKTRContextRowOffset)$:}] + we impose $\nonContextProvidesEmptyReturnData {i}{\prcCommonFKTRContextRowOffset} $ +\end{description} diff --git a/hub/instruction_handling/call/precompiles/common/generalities.tex b/hub/instruction_handling/call/precompiles/common/generalities.tex new file mode 100644 index 0000000..448e7f2 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/generalities.tex @@ -0,0 +1,355 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenPrecompileCommon _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus assuming that the present row is the first of the second phase of dealing with the +\inst{ECRECOVER}, +\inst{SHA2-256}, +\inst{RIPEMD-160}, +\inst{ECADD}, +\inst{ECMUL} or +\inst{ECPAIRING} +precompiles. +We know that the current scenario-row $i$ will be followed by a miscellaneous-row $(i + \prcCommonMiscRowOffset)$. +\begin{description} + \item[\underline{Miscellaneous row $n^°(i + \prcCommonMiscRowOffset)$:}] we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose that + \[ + \weightedMiscFlagSum + {i}{\prcCommonMiscRowOffset} + = + \left[ \begin{array}{clcl} + + & \miscMmuWeight & \cdot & \locOobResultExtractCallData \\ + + & \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcCommonMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcCommonMiscRowOffset} & = & \locOobResultExtractCallData & (\trash) \\ + \miscMxpFlag _{i + \prcCommonMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcCommonMiscRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcCommonMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} + The shorthand \locOobResultExtractCallData{} will be defined shortly. + It is gleaned from one of the outputs of the call to the \oobMod{} module (which is systematically triggered given the above.) + \item[\underline{Setting \oobMod{} instruction:}] + we populate the \oobMod{} columns: + \[ + \setOobInstructionCommon { + anchorRow = i, + relOffset = \prcCommonMiscRowOffset, + oobInstruction = \locOobInst, + callGas = \locPrcCallGas, + callDataSize = \locPrcCds, + returnAtCapacity = \locPrcRac, + } + \] + where + \[ + \locOobInst \define + \left[ \begin{array}{crcl} + + & \oobInstEcrecover & \cdot & \scenEcrecover _{i} \\ + + & \oobInstShaTwo & \cdot & \scenShaTwo _{i} \\ + + & \oobInstRipemd & \cdot & \scenRipemd _{i} \\ + + & \oobInstIdentity & \cdot & \scenIdentity _{i} \\ + + & \oobInstEcadd & \cdot & \scenEcadd _{i} \\ + + & \oobInstEcmul & \cdot & \scenEcmul _{i} \\ + + & \oobInstEcpairing & \cdot & \scenEcpairing _{i} \\ + \end{array} \right] + \] + \item[\underline{Defining \oobMod{} shorthands:}] + We also define the following shorthands + \[ + \left\{ \begin{array}{lcl} \label{hub: instruction handling: call: precompiles: common: shorthands} + % & \define & \miscOobDataCol{1}_{i + \prcCommonMiscRowOffset} \\ + % & \define & \miscOobDataCol{2}_{i + \prcCommonMiscRowOffset} \\ + % & \define & \miscOobDataCol{3}_{i + \prcCommonMiscRowOffset} \\ + \locOobResultHubSuccess & \define & \miscOobDataCol{4}_{i + \prcCommonMiscRowOffset} \\ + \locOobResultReturnGas & \define & \miscOobDataCol{5}_{i + \prcCommonMiscRowOffset} \\ + \locOobResultExtractCallData & \define & \miscOobDataCol{6}_{i + \prcCommonMiscRowOffset} \\ + \locOobResultEmptyCallData & \define & \miscOobDataCol{7}_{i + \prcCommonMiscRowOffset} \\ + \locOobResultNonzeroRac & \define & \miscOobDataCol{8}_{i + \prcCommonMiscRowOffset} \\ + \end{array} \right. + \] + \saNote{} + We refer the reader to the relevant section in the \oobMod{} module, in particular section~(\ref{oob: populating: common precompiles}). + + \saNote{} We have, by construction and by the computation in the \oobMod{} module, the following relations: + \[ + \left\{ \begin{array}{lclr} + \locOobResultHubSuccess & \equiv & \text{binary} & \quad (\trash) \\ + \locOobResultExtractCallData & \equiv & \text{binary} & \quad (\trash) \\ + \locOobResultEmptyCallData & \equiv & \text{binary} & \quad (\trash) \vspace{2mm} \\ + \multicolumn{3}{l}{\locOobResultExtractCallData + \locOobResultEmptyCallData = \locOobResultHubSuccess} & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \mmuMod{} instruction:}] + \If $\miscMmuFlag_{i + \prcCommonMiscRowOffset} = 1$ \Then we impose that + \begin{enumerate} + \item \If $\scenIdentity _{i} = 1$ \Then + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcCommonMiscRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + sourceOffsetLo = \locPrcCdo , + size = \locPrcCds , + referenceOffset = 0 , + referenceSize = \locPrcCds , + } + \] + \item \If $\scenPrecompileCommonNotIdentity _{i} = 1$ \Then + \[ + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i , + relOffset = \prcCommonMiscRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + auxiliaryId = \nothing , + sourceOffsetLo = \locPrcCdo , + size = \locPrcCds , + referenceSize = \undefinedStar \quad \locMmuRefSize , + successBit = \relevantValue , + exoSum = \undefinedStar \quad \locMmuExoSum , + phase = \undefinedStar \quad \locMmuPhase , + } + \] + \end{enumerate} + where the shorthands marked with $\undefinedStar$ are as of yet undefined. We define them as follows: + \[ + \locMmuRefSize \define + \left[ \begin{array}{crcl} + + & \redm{128} & \cdot & \scenEcrecover _{i} \\ + + & \locPrcCds & \cdot & \scenShaTwo _{i} \\ + + & \locPrcCds & \cdot & \scenRipemd _{i} \\ + + & \redm{128} & \cdot & \scenEcadd _{i} \\ + + & \redm{96} & \cdot & \scenEcmul _{i} \\ + + & \locPrcCds & \cdot & \scenEcpairing _{i} \\ + \end{array} \right] + \] + and + \[ + \locMmuExoSum \define + \left[ \begin{array}{crcl} + + & \exoWeightEcdata & \cdot & \scenEcrecover _{i} \\ + + & \exoWeightRipSha & \cdot & \scenShaTwo _{i} \\ + + & \exoWeightRipSha & \cdot & \scenRipemd _{i} \\ + % + & \gZero & \cdot & \scenIdentity _{i} \\ + + & \exoWeightEcdata & \cdot & \scenEcadd _{i} \\ + + & \exoWeightEcdata & \cdot & \scenEcmul _{i} \\ + + & \exoWeightEcdata & \cdot & \scenEcpairing _{i} \\ + \end{array} \right] + \] + and + \[ + \locMmuPhase \define + \left[ \begin{array}{crcl} + + & \phaseEcrecoverData & \cdot & \scenEcrecover _{i} \\ + + & \phaseShaTwoData & \cdot & \scenShaTwo _{i} \\ + + & \phaseRipemdData & \cdot & \scenRipemd _{i} \\ + % + & \gZero & \cdot & \scenIdentity _{i} \\ + + & \phaseEcaddData & \cdot & \scenEcadd _{i} \\ + + & \phaseEcmulData & \cdot & \scenEcmul _{i} \\ + + & \phaseEcpairingData & \cdot & \scenEcpairing _{i} \\ + \end{array} \right] + \] + \saNote{} + In the implementation of the above \mmuMod{}-instruction setting one may drop the global precondition ``$\scenPrecompileCommon \equiv 1$.'' + Indeed both constraints impose more stringent preconditions. + \item[\underline{Some shorthands for elliptic curve precompiles:}] + we will use the following shorthands + \begin{description} + \item[\underline{\inst{ECRECOVER} specific:}] + we set + \[ + \left\{ \begin{array}{lcl} + \locAddressRecoveryFailure & \define & + \left[ \begin{array}{clcl} + + & \locOobResultEmptyCallData \\ + + & \locOobResultExtractCallData & \cdot & (1 - \miscMmuSuccessBit_{i + \prcCommonMiscRowOffset}) \\ + \end{array} \right] \\ + \locAddressRecoverySuccess & \define & \locOobResultExtractCallData \cdot \miscMmuSuccessBit_{i + \prcCommonMiscRowOffset} \\ + \end{array} \right. + \] + \saNote{} These bits will be used in the processing of \inst{ECRECOVER}. + In that context (and given the precompile succedes) + \begin{itemize} + \item $\locAddressRecoveryFailure \equiv 1$ precisely when return data is empty ($\textbf{o} = ()$) + \item $\locAddressRecoverySuccess \equiv 1$ precisely when recovery is successful and return data is nonempty ($\textbf{o} \in \mathbb{B}_{32}$.) + \end{itemize} + + \saNote{} We have, by construction, and given that the precompile at hand is \inst{ECRECOVER}, the following relations: + \[ + \left\{ \begin{array}{lclr} + \locAddressRecoveryFailure & \equiv & \text{binary} & \quad (\trash) \\ + \locAddressRecoverySuccess & \equiv & \text{binary} & \quad (\trash) \vspace{2mm} \\ + \multicolumn{3}{l}{\locAddressRecoveryFailure + \locAddressRecoverySuccess = \locOobResultHubSuccess} & \quad (\trash) \\ + \end{array} \right. + \] + + \saNote{} We finish by reminding that from the point of view of the \hubMod{} the bit $\miscMmuSuccessBit_{i + \prcCommonMiscRowOffset}$ is a \textbf{prediction}. + This prediction will be borne out in the \ecDataMod{} module. + \item[\underline{\inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} specific:}] we set + \[ + \left\{ \begin{array}{lcl} + \locMalFormedData & \define & \locOobResultExtractCallData \cdot (1 - \miscMmuSuccessBit_{i + \prcCommonMiscRowOffset}) \\ + \locWellFormedData & \define & + \left[ \begin{array}{clcl} + + & \locOobResultEmptyCallData \\ + + & \locOobResultExtractCallData & \cdot & \miscMmuSuccessBit_{i + \prcCommonMiscRowOffset} \\ + \end{array} \right] \\ + \end{array} \right. + \] + \saNote{} These bits will be used in the processing of \inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING}. + These precompiles have the property that \textbf{empty call data} is acceptable and produces the following outputs: + \begin{center} + \begin{tabular}{|ll|} + \hline + \underline{\inst{ECADD} case:} + & $\textbf{o} = + \utt{00}\, + \utt{00}\, \cdots \, + \utt{00} \in \mathbb{B}_{64}$ \\ + & representing the point at infinity; \\ + \underline{\inst{ECMUL} case:} + & $\textbf{o} = + \utt{00}\, + \utt{00}\, \cdots \, + \utt{00} \in \mathbb{B}_{64}$ \\ + & representing the point at infinity; \\ + \underline{\inst{ECPAIRING} case:} + & $\textbf{o} = + \utt{00}\, + \utt{00}\, \cdots \, + \utt{01} \in \mathbb{B}_{32}$ \\ + & representing $\rOne$. \\ \hline + \end{tabular} + \end{center} + \saNote{} We have, by construction, the following relations: + \[ + \left\{ \begin{array}{lclr} + \locMalFormedData & \equiv & \text{binary} & \quad (\trash) \\ + \locWellFormedData & \equiv & \text{binary} & \quad (\trash) \vspace{2mm} \\ + \multicolumn{3}{l}{\locMalFormedData + \locWellFormedData = \locOobResultHubSuccess} & \quad (\trash) \\ + \end{array} \right. + \] + \end{description} + \item[\underline{Some constraints involving the success bit:}] + we may want to impose the following + \[ + \miscMmuSuccessBit_{i + \prcCommonMiscRowOffset} \cdot + \left[ \begin{array}{cl} + + & \scenShaTwo _{i} \\ + + & \scenRipemd _{i} \\ + \end{array} \right] + = 0 \qquad (\trash) + \] + The above simply means that $\miscMmuSuccessBit_{i + \prcCommonMiscRowOffset}$ must vanish for the following precompiles: + \inst{SHA2-256}, + \inst{RIPEMD-160}. + + \saNote{} We will come back to the interpretation of both + \locMmuRecoverSuccess{} and + \locMmuWellFormedData{}. + As the names suggest \locMmuRecoverSuccess{} lets the \hubMod{} module know whether recovery of a public address was successful in case of a \inst{CALL} to \inst{ECRECOVER}. + As the names suggest \locMmuWellFormedData{} lets the \hubMod{} module know whether the input data to \inst{ECADD}, \inst{ECMUL} or \inst{ECPAIRING} is well formed. + \item[\underline{Justifying scenario success / failure predictions:}] + \scenPrcSuccess{}, \scenPrcFailureKnownToHub{} and \scenPrcFailureKnownToRam{} are, by construction, exclusive binary columns; + furthermore we previously imposed that + \[ + \left[ \begin{array}{cr} + + & \scenPrcSuccess _{i} \\ + + & \scenPrcFailureKnownToHub _{i} \\ + + & \scenPrcFailureKnownToRam _{i} \\ + \end{array} \right] + = 1 \qquad (\trash) + \] + recall further that several precompiles have $\scenPrcFailureKnownToRam_{i} \equiv 0$ automatically; + we impose the following: + \[ + \scenPrcSuccess_{i} = + \left[ \begin{array}{crcl} + + & \locOobResultHubSuccess & \cdot & + \left[ \begin{array}{cl} + + & \scenEcrecover _{i} \\ + + & \scenShaTwo _{i} \\ + + & \scenRipemd _{i} \\ + + & \scenIdentity _{i} \\ + \end{array} \right] \vspace{2mm} \\ + + & \locWellFormedData & \cdot & + \left[ \begin{array}{cl} + + & \scenEcadd _{i} \\ + + & \scenEcmul _{i} \\ + + & \scenEcpairing _{i} \\ + \end{array} \right] \\ + \end{array} \right] + \] + and + \[ + \scenPrcFailureKnownToHub_{i} = + \left[ \begin{array}{crcl} + + & (1 - \locOobResultHubSuccess) & \cdot & + \left[ \begin{array}{cl} + + & \scenEcrecover _{i} \\ + + & \scenShaTwo _{i} \\ + + & \scenRipemd _{i} \\ + + & \scenIdentity _{i} \\ + + & \scenEcadd _{i} \\ + + & \scenEcmul _{i} \\ + + & \scenEcpairing _{i} \\ + \end{array} \right] \\ + \end{array} \right] + \] + and + \[ + \hspace*{-1.5cm} + \scenPrcFailureKnownToRam_{i} = + \left[ \begin{array}{crcl} + + & \gZero & \cdot & + \left[ \begin{array}{cl} + + & \scenEcrecover _{i} \\ + + & \scenShaTwo _{i} \\ + + & \scenRipemd _{i} \\ + + & \scenIdentity _{i} \\ + \end{array} \right] \vspace{2mm} \\ + + & \locMalFormedData & \cdot & + \left[ \begin{array}{cl} + + & \scenEcadd _{i} \\ + + & \scenEcmul _{i} \\ + + & \scenEcpairing _{i} \\ + \end{array} \right] \\ + \end{array} \right] + \] + \saNote{} The above is somewhat redundant. We include the full characterizations of + \scenPrcSuccess{}, + \scenPrcFailureKnownToRam{} and + \scenPrcFailureKnownToRam{} for greater clarity. + \item[\underline{Justifying return gas prediction:}] + we impose + \begin{enumerate} + \item \If $\scenPrcFailure_{i} = 1$ \Then $\locPrcReturnGas = 0$ + \item \If $\scenPrcSuccess_{i} = 1$ \Then $\locPrcReturnGas = \locOobResultReturnGas$ + \end{enumerate} + \saNote{} The above may be subsumed under + \[ + \locPrcReturnGas + = + \scenPrcSuccess_{i} + \cdot + \locOobResultReturnGas + \quad (\trash) + \] + \end{description} + \end{description} diff --git a/hub/instruction_handling/call/precompiles/common/intro.tex b/hub/instruction_handling/call/precompiles/common/intro.tex new file mode 100644 index 0000000..4dea0d2 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/intro.tex @@ -0,0 +1,16 @@ +The present section deals with the \hubMod{} processing of \emph{most} precompiles. We are able to have a rather uniform setup for the following precompiles: +\begin{multicols}{3} +\begin{enumerate} + \item \inst{ECRECOVER} + \item \inst{SHA2-256} + \item \inst{RIPEMD-160} + \item \inst{IDENTITY} + \item \inst{ECADD} + \item \inst{ECMUL} + \item \inst{ECPAIRING} +\end{enumerate} +\end{multicols} +Despite the fact that these precompiles are rather different along several dimensions of analysis: +(\emph{a}) what constitutes success / failure +(\emph{b}) how and when to interact with \text{ram}. +These differences will re-emerge beyond the common setup phase. diff --git a/hub/instruction_handling/call/precompiles/common/lua/setup.lua.tex b/hub/instruction_handling/call/precompiles/common/lua/setup.lua.tex new file mode 100644 index 0000000..8c97b73 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/lua/setup.lua.tex @@ -0,0 +1,86 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ███████\ ██████\ ██████\████\ ██████\████\ ██████\ ███████\ +██ _____|██ __██\ ██ _██ _██\ ██ _██ _██\ ██ __██\ ██ __██\ +██ / ██ / ██ |██ / ██ / ██ |██ / ██ / ██ |██ / ██ |██ | ██ | +██ | ██ | ██ |██ | ██ | ██ |██ | ██ | ██ |██ | ██ |██ | ██ | +\███████\ \██████ |██ | ██ | ██ |██ | ██ | ██ |\██████ |██ | ██ | + \_______| \______/ \__| \__| \__|\__| \__| \__| \______/ \__| \__| + + ██\ ██\ + \__|██ | + ██████\ ██████\ ██████\ ███████\ ██████\ ██████\████\ ██████\ ██\ ██ | ██████\ ███████\ +██ __██\ ██ __██\ ██ __██\ ██ _____|██ __██\ ██ _██ _██\ ██ __██\ ██ |██ |██ __██\ ██ _____| +██ / ██ |██ | \__|████████ |██ / ██ / ██ |██ / ██ / ██ |██ / ██ |██ |██ |████████ |\██████\ +██ | ██ |██ | ██ ____|██ | ██ | ██ |██ | ██ | ██ |██ | ██ |██ |██ |██ ____| \____██\ +███████ |██ | \███████\ \███████\ \██████ |██ | ██ | ██ |███████ |██ |██ |\███████\ ███████ | +██ ____/ \__| \_______| \_______| \______/ \__| \__| \__|██ ____/ \__|\__| \_______|\_______/ +██ | ██ | +██ | ██ | +\__| \__| + +|-------+--------+---------------------------+------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+---------------------------+------------------------------------------------------| +| i | SCEN | one of: | SCEN/PRC_FKTH + SCEN/PRC_FKTR + SCEN/PRC_SUCCESS = 1 | +| | | | | +| | | * SCEN/ECRECOVER = 1 | . <== SCEN/PREC_FKTR ≡ 0 (always!) | +| | | * SCEN/SHA2-256 = 1 | . <== SCEN/PREC_FKTR ≡ 0 (always!) | +| | | * SCEN/RIPEMD-160 = 1 | . <== SCEN/PREC_FKTR ≡ 0 (always!) | +| | | * SCEN/IDENTITY = 1 | . <== SCEN/PREC_FKTR ≡ 0 (always!) | +| | | * SCEN/ECADD = 1 | | +| | | * SCEN/ECMUL = 1 | | +|-------+--------+---------------------------+------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST (case dependent) | +| | | | * ⟦OOB_INST_ecrecover⟧ | +| | | | * ⟦OOB_INST_sha2-256⟧ | +| | | | * ⟦OOB_INST_ripemd-160⟧ | +| | | | * ⟦OOB_INST_identity⟧ | +| | | | * ⟦OOB_INST_ecadd⟧ | +| | | | * ⟦OOB_INST_ecmul⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success ≡ [gas_cost ≤ call_gas] | +| | | | * return_gas ≡ 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data ≡ hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data ≡ hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero ≡ [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data | | +|-------+--------+---------------------------+------------------------------------------------------| +| ... | ... | ... | ... | + +We have used the following abbreviations: + FKTH ≡ FAILURE_KNONWN_TO_HUB + FKTR ≡ FAILURE_KNONWN_TO_RAM + +NOTE. depending on the case we use the notation " ∨ " either as logical OR or as the maximum; +similarly we use the notation " ∧ " as either logical AND or as the minimum. +\end{verbatim} +\end{document} + diff --git a/hub/instruction_handling/call/precompiles/common/lua/setup_ecpairing.lua.tex b/hub/instruction_handling/call/precompiles/common/lua/setup_ecpairing.lua.tex new file mode 100644 index 0000000..fad5ebc --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/lua/setup_ecpairing.lua.tex @@ -0,0 +1,62 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ███████\ ██████\ ██████\ ███████\ ██████\ ██\ ██\ ██████\ +██ _____|██ __██\ ██ __██\ ██ __██\ \_██ _|██ __██\ \_██ _|███\ ██ |██ __██\ +██ | ██ / \__|██ | ██ |██ / ██ | ██ | ██ | ██ | ██ | ████\ ██ |██ / \__| +█████\ ██ | ███████ |████████ | ██ | ███████ | ██ | ██ ██\██ |██ |████\ +██ __| ██ | ██ ____/ ██ __██ | ██ | ██ __██< ██ | ██ \████ |██ |\_██ | +██ | ██ | ██\ ██ | ██ | ██ | ██ | ██ | ██ | ██ | ██ |\███ |██ | ██ | +████████\ \██████ |██ | ██ | ██ |██████\ ██ | ██ |██████\ ██ | \██ |\██████ | +\________| \______/ \__| \__| \__|\______|\__| \__|\______|\__| \__| \______/ + +|-------+--------+---------------------------+------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+---------------------------+------------------------------------------------------| +| i | SCEN | * SCEN/ECPAIRING = 1 | SCEN/PRC_FKTH + SCEN/PRC_FKTR + SCEN/PRC_SUCCESS = 1 | +|-------+--------+---------------------------+------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST: | +| | | | * ⟦OOB_INST_ecpairing⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success ≡ [gas_cost ≤ call_gas] | +| | | | . ∧ [cds ≡ 0 mod 192] | +| | | | * return_gas ≡ 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data ≡ hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data ≡ hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero ≡ [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data | | +|-------+--------+---------------------------+------------------------------------------------------| +| ... | ... | ... | ... | +\end{verbatim} +\end{document} + + + + + diff --git a/hub/instruction_handling/call/precompiles/common/representation.tex b/hub/instruction_handling/call/precompiles/common/representation.tex new file mode 100644 index 0000000..513db62 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/common/representation.tex @@ -0,0 +1,2 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/common/lua/setup.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/common/lua/setup_ecpairing.pdf} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/_inputs.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/_inputs.tex new file mode 100644 index 0000000..ceb5db8 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsubsection{Dealing with empty call data} \label{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing: empty} \input{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/empty} +\subsubsubsection{\inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} shorthands \lispTodo{}} \label{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing: shorthands} \input{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/shorthands} +\subsubsubsection{\inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} representation} \label{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing: representation} \input{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/representation} +\subsubsubsection{\inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} the \scenPrcFailureKnownToRam{} case \lispTodo{}} \label{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing: failure KTR} \input{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/failure_KTR} +\subsubsubsection{\inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} the \scenPrcSuccess{} case \lispTodo{}} \label{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing: success} \input{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/success} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/empty.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/empty.tex new file mode 100644 index 0000000..6378fab --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/empty.tex @@ -0,0 +1,81 @@ +In this section we describe the desired behaviour of \inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} which \textbf{don't fail in the \hubMod{} but are provided with empty call data}. +In the \hubMod{} this is measured \emph{exactly} by +\[ + \locOobResultEmptyCallData \equiv 1 +\] +see +section~(\ref{oob: precompiles: common precompiles: generalities}) and +section~(\ref{oob: precompiles: common precompiles: one row precompiles}) +in the \oobMod{} chapter. +Recall that in case of a call with \textbf{zero call data size} the callee's call data is the ``infinite\footnote{Or nearly so: it remains addressable with offsets and sizes that are in the range $\mathbb{N}_{256}$.} slice of 0 bytes'' $I_\textbf{d} \equiv [\utt{00}, +\utt{00}, +\utt{00}, \dots]$; + +We claim that such calls are necessarily successful (and thus don't fail in \textsc{ram}.) +Indeed +\begin{description} + \item[The \inst{ECADD} case:] + the precompile extracts from $I_\textbf{d}$ two inputs + \begin{enumerate} + \item $ + \utt{00} \; + \utt{00} \; \cdots \; + \utt{00} \in \mathbb{B}_{\smallCurvePointSize}$ + \item $ + \utt{00} \; + \utt{00} \; \cdots \; + \utt{00} \in \mathbb{B}_{\smallCurvePointSize}$ + \end{enumerate} + by \evm{} convention, both are considered valid curve points and are both understood to represent the \textbf{point at infinity} on the \texttt{altbn} curve; + this input data is therefore well-formed and cannot trigger $\scenPrcFailureKnownToRam$; + furthermore, the return data is (the \evm{} encoding of) the point at infinity + $ + \utt{00} \; + \utt{00} \; + \utt{00} \; \cdots \; + \utt{00} \in \mathbb{B}_{\smallCurvePointSize}$; + \item[The \inst{ECMUL} case:] + the precompile extracts from $I_\textbf{d}$ two inputs + \begin{enumerate} + \item $ + \utt{00} \; + \utt{00} \; \cdots \; + \utt{00} \in \mathbb{B}_{\evmWordSize}$ + \item $ + \utt{00} \; + \utt{00} \; \cdots \; + \utt{00} \in \mathbb{B}_{\smallCurvePointSize}$ + \end{enumerate} + the first one is interpreted as the zero integer $\in \mathbb{N}_{256}$; + the second one is interpreted, by \evm{} convention and as already explained, as the \textbf{point at infinity} on the \texttt{altbn} curve; + this input data is therfore well-formed and cannot trigger $\scenPrcFailureKnownToRam$; + furthermore, the return data is (the \evm{} encoding of) the point at infinity + $ + \utt{00} \; + \utt{00} \; + \utt{00} \; \cdots \; + \utt{00} \in \mathbb{B}_{\smallCurvePointSize}$; + \item[The \inst{ECPAIRING} case:] + empty call data leads to the ``empty pairing'' which, in accordance with \evm{} specification and standard mathematical practice, evaluates to ``\texttt{true}''; + as such the return data is + $ + \utt{00} \; + \utt{00} \; \cdots \; + \utt{01} \in \mathbb{B}_{\evmWordSize}$; +\end{description} +\saNote{} +For both \inst{ECADD} and \inst{ECMUL} return data in the empty call data case is +$\utt{00} \; +\utt{00} \; \cdots \; +\utt{00} \in \mathbb{B}_{\smallCurvePointSize}$. +Since \textsc{ram} is initialized as empty in the \mmuMod{} module there is no requirement for us to transfer this return data to its dedicated execution context. +That execution context already contains it by default. +For \inst{ECPAIRING} things are different. +Since return data is nontrivial +$\utt{00} \; +\utt{00} \; \cdots \; +\utt{01} \in \mathbb{B}_{\evmWordSize}$; +and in particular \textbf{nonzero} it must be transferred to its dedicated \textsc{ram} context. +The arithmetization sets this value ``by hand'' i.e. without interacting with the \ecDataMod{} module. +This the \zkEvm{} does through a dedicated \mmuInstMstore{} instruction, see section~(\ref{hub: instruction handling: call: precompiles: ecadd, ecmul and ecpairing: success}). + diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/failure_KTR.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/failure_KTR.tex new file mode 100644 index 0000000..5f65fc1 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/failure_KTR.tex @@ -0,0 +1,24 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \left[ \begin{array}{cr} + + & \scenEcadd _{i} \\ + + & \scenEcmul _{i} \\ + + & \scenEcpairing _{i} \\ + \end{array} \right] + & = & 1 \\ + \scenPrcFailureKnownToRam _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus assuming that the present row is the first of the second phase of dealing with one of the following precompiles: \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING}. +We are furthermore assuming that $\scenPrcFailureKnownToRam \equiv 1$. +The only constraint we are missing at this point is imposing that \textbf{call data be nonempty} and updating the caller's call data\footnote{though this already happens implicitly}: +\begin{description} + \item[\underline{Call data must be nonempty:}] + we impose \( \locExtractCallData = 1. \) + \item[\underline{\underline{Context-row $n^°(i + \prcCommonFKTRContextRowOffset)$:}}] + we impose $\nonContextProvidesEmptyReturnData {i}{\prcCommonFKTRContextRowOffset}$ \quad $(\trash)$ +\end{description} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_common.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_common.lua.tex new file mode 100644 index 0000000..65c9ac5 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_common.lua.tex @@ -0,0 +1,73 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ██████\ ███████\ ███████\ ██\ ████████\ ██████\ ██\ ██\ ██\ ██\ ██\ +██ _____|██ __██\ ██ __██\ ██ __██\ ██ __██\ ██ | ██ _____|██ __██\ ███\ ███ |██ | ██ |██ | +██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ / ██ | ██ / \__|████\ ████ |██ | ██ |██ | +█████\ ██ | ████████ |██ | ██ |██ | ██ | ██ / █████\ ██ | ██\██\██ ██ |██ | ██ |██ | +██ __| ██ | ██ __██ |██ | ██ |██ | ██ | ██ / ██ __| ██ | ██ \███ ██ |██ | ██ |██ | +██ | ██ | ██\ ██ | ██ |██ | ██ |██ | ██ | ██ / ██ | ██ | ██\ ██ |\█ /██ |██ | ██ |██ | +████████\ \██████ |██ | ██ |███████ |███████ | ██ / ████████\ \██████ |██ | \_/ ██ |\██████ |████████\ +\________| \______/ \__| \__|\_______/ \_______/ \__/ \________| \______/ \__| \__| \______/ \________| + + + __| _ \ __ `__ \ __ `__ \ _ \ __ \ + ( ( | | | | | | | ( | | | + \___| \___/ _| _| _| _| _| _| \___/ _| _| + + +|-------+--------+-----------------------------------+------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-----------------------------------+------------------------------------------------------| +| i | SCEN | SCEN/ECADD or SCEN/ECMUL | SCEN/PRC_SUCCESS + SCEN/PRC_FKTH + SCEN/PRC_FKTR = 1 | +|-------+--------+-----------------------------------+------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECADD⟧ / ⟦OOB_ECMUL⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data | | +| | | MMU_INST = | | +| | | | | +| | | ID_SCR := CN | | +| | | SRC_OFF := CDO | | +| | | SIZE := CDS | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | | | +| | | ram_success := 0 / 1 (prediction) | | +|-------+--------+-----------------------------------+------------------------------------------------------| +\end{verbatim} +\end{document} + + + diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTH.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTH.lua.tex new file mode 100644 index 0000000..bfebd78 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTH.lua.tex @@ -0,0 +1,62 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ██████\ ███████\ ███████\ ██\ ████████\ ██████\ ██\ ██\ ██\ ██\ ██\ +██ _____|██ __██\ ██ __██\ ██ __██\ ██ __██\ ██ | ██ _____|██ __██\ ███\ ███ |██ | ██ |██ | +██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ / ██ | ██ / \__|████\ ████ |██ | ██ |██ | +█████\ ██ | ████████ |██ | ██ |██ | ██ | ██ / █████\ ██ | ██\██\██ ██ |██ | ██ |██ | +██ __| ██ | ██ __██ |██ | ██ |██ | ██ | ██ / ██ __| ██ | ██ \███ ██ |██ | ██ |██ | +██ | ██ | ██\ ██ | ██ |██ | ██ |██ | ██ | ██ / ██ | ██ | ██\ ██ |\█ /██ |██ | ██ |██ | +████████\ \██████ |██ | ██ |███████ |███████ | ██ / ████████\ \██████ |██ | \_/ ██ |\██████ |████████\ +\________| \______/ \__| \__|\_______/ \_______/ \__/ \________| \______/ \__| \__| \______/ \________| + + + | | | | __ ) _| _) | + | | | | __ \ | _` | | | | | __| _ \ + ___ | | | | | __| ( | | | | | | __/ +_| _| \___/ ____/ _| \__,_| _| _| \__,_| _| \___| + + +|-------+--------+-------------------------------------+----------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+----------------------------------------------| +| i | SCEN | SCEN/ECADD or SCEN/ECMUL | SCEN/PRC_FKTH = 1 ⛔ | +|-------+--------+-------------------------------------+----------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST: | +| | | | * ⟦OOB_ECADD⟧ | +| | | | * ⟦OOB_ECMUL⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := hub_success ∧ [cds = 0] | +| | | | * extract_cd := hub_success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +|-------+--------+-------------------------------------+----------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTR.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTR.lua.tex new file mode 100644 index 0000000..a7fe721 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTR.lua.tex @@ -0,0 +1,73 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ██████\ ███████\ ███████\ ██\ ████████\ ██████\ ██\ ██\ ██\ ██\ ██\ +██ _____|██ __██\ ██ __██\ ██ __██\ ██ __██\ ██ | ██ _____|██ __██\ ███\ ███ |██ | ██ |██ | +██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ / ██ | ██ / \__|████\ ████ |██ | ██ |██ | +█████\ ██ | ████████ |██ | ██ |██ | ██ | ██ / █████\ ██ | ██\██\██ ██ |██ | ██ |██ | +██ __| ██ | ██ __██ |██ | ██ |██ | ██ | ██ / ██ __| ██ | ██ \███ ██ |██ | ██ |██ | +██ | ██ | ██\ ██ | ██ |██ | ██ |██ | ██ | ██ / ██ | ██ | ██\ ██ |\█ /██ |██ | ██ |██ | +████████\ \██████ |██ | ██ |███████ |███████ | ██ / ████████\ \██████ |██ | \_/ ██ |\██████ |████████\ +\________| \______/ \__| \__|\_______/ \_______/ \__/ \________| \______/ \__| \__| \______/ \________| + + + _ \ \ \ | _| _) | + | | _ \ |\/ | | _` | | | | | __| _ \ + __ < ___ \ | | __| ( | | | | | | __/ + _| \_\ _/ _\ _| _| _| \__,_| _| _| \__,_| _| \___| + + +|-------+--------+--------------------------------------+---------------------------------------------------| +| Row | Persp. | | | +|-------+--------+--------------------------------------+---------------------------------------------------| +| i | SCEN | SCEN/ECADD or SCEN/ECMUL | SCEN/PRC_FKTR = 1 ⛔ | +|-------+--------+--------------------------------------+---------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECADD⟧ / ⟦OOB_ECMUL⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data (here: 1) | | +| | | MMU_INST = | | +| | | | | +| | | ID_SCR := CN | | +| | | SRC_OFF := CDO | | +| | | SIZE := CDS | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | | | +| | | ram_success := 0 / 1 (here: 0) | | +|-------+--------+--------------------------------------+---------------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+--------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_success.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_success.lua.tex new file mode 100644 index 0000000..ef6a123 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_success.lua.tex @@ -0,0 +1,123 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ██████\ ███████\ ███████\ ██\ ████████\ ██████\ ██\ ██\ ██\ ██\ ██\ +██ _____|██ __██\ ██ __██\ ██ __██\ ██ __██\ ██ | ██ _____|██ __██\ ███\ ███ |██ | ██ |██ | +██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ / ██ | ██ / \__|████\ ████ |██ | ██ |██ | +█████\ ██ | ████████ |██ | ██ |██ | ██ | ██ / █████\ ██ | ██\██\██ ██ |██ | ██ |██ | +██ __| ██ | ██ __██ |██ | ██ |██ | ██ | ██ / ██ __| ██ | ██ \███ ██ |██ | ██ |██ | +██ | ██ | ██\ ██ | ██ |██ | ██ |██ | ██ | ██ / ██ | ██ | ██\ ██ |\█ /██ |██ | ██ |██ | +████████\ \██████ |██ | ██ |███████ |███████ | ██ / ████████\ \██████ |██ | \_/ ██ |\██████ |████████\ +\________| \______/ \__| \__|\_______/ \_______/ \__/ \________| \______/ \__| \__| \______/ \________| + + + __| | | __| __| _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ + ____/ \__,_| \___| \___| \___| ____/ ____/ + + +|-------+--------+-----------------------------------+---------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-----------------------------------+---------------------------------------------------| +| i | SCEN | SCEN/ECADD or SCEN/ECMUL | SCEN/PRC_SUCCESS ✅ | +|-------+--------+-----------------------------------+---------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECADD⟧ / ⟦OOB_ECMUL⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data | | +| | | | | +| | | CASE: MMU🏴 = 0: | | +| | | ================ | | +| | | do nothing | | +| | | | | +| | | CASE: MMU🏴 = 1: | | +| | | ================ | | +| | | MMU_INST = | | +| | | | | +| | | ID_SCR := CN | | +| | | SRC_OFF := CDO | | +| | | SIZE := CDS | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | | | +| | | REF_SIZE = 128 / 96 | | +| | | | | +| | | ram_success := 0 / 1 (prediction) | | +| | | (here: 1) | | +|-------+--------+-----------------------------------+---------------------------------------------------| +| i + 2 | MISC | MMU🏴 = extract_cd | OOB🏴 = 0 | +| | | | | +| | | CASE: MMU🏴 = 0: | | +| | | ================ | | +| | | do nothing | | +| | | | | +| | | CASE: MMU🏴 = 1: | | +| | | ================ | | +| | | | | +| | | MMU🏴 = full_transfer | | +| | | MMU_INST = 2 x | | +| | | | | +| | | SRC_ID := 1 + HUB_ | | +| | | CN_T := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +|-------+--------+-----------------------------------+---------------------------------------------------| +| i + 3 | MISC | MMU🏴 = transfer_rd | OOB🏴 = 0 | +| | | | | +| | | CASE: MMU🏴 = 0: | | +| | | ================ | | +| | | do nothing | | +| | | | | +| | | CASE: MMU🏴 = 1: | | +| | | ================ | | +| | | MMU_INST = | | +| | | | | +| | | ID_SRC := 1 + HUB_ | | +| | | REF_OFF := 0 | | +| | | REF_SIZE := 32 | | +| | | ID_TGT := cn | | +| | | TGT_OFF := r@o | | +| | | SIZE := r@c | | +|-------+--------+-----------------------------------+---------------------------------------------------| +| i + 4 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = 64 | +|-------+--------+-----------------------------------| + +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_common.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_common.lua.tex new file mode 100644 index 0000000..1cf7e46 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_common.lua.tex @@ -0,0 +1,79 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ███████\ ██████\ ██████\ ███████\ ██████\ ██\ ██\ ██████\ +██ _____|██ __██\ ██ __██\ ██ __██\ \_██ _|██ __██\ \_██ _|███\ ██ |██ __██\ +██ | ██ / \__|██ | ██ |██ / ██ | ██ | ██ | ██ | ██ | ████\ ██ |██ / \__| +█████\ ██ | ███████ |████████ | ██ | ███████ | ██ | ██ ██\██ |██ |████\ +██ __| ██ | ██ ____/ ██ __██ | ██ | ██ __██< ██ | ██ \████ |██ |\_██ | +██ | ██ | ██\ ██ | ██ | ██ | ██ | ██ | ██ | ██ | ██ |\███ |██ | ██ | +████████\ \██████ |██ | ██ | ██ |██████\ ██ | ██ |██████\ ██ | \██ |\██████ | +\________| \______/ \__| \__| \__|\______|\__| \__|\______|\__| \__| \______/ + + + __| _ \ __ `__ \ __ `__ \ _ \ __ \ + ( ( | | | | | | | ( | | | + \___| \___/ _| _| _| _| _| _| \___/ _| _| + + +|-------+--------+-----------------------------------+--------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-----------------------------------+--------------------------------------------------------| +| i | SCEN | SCEN/ECPAIRING | SCEN/PRC_SUCCESS + SCEN/PRC_FKTH + SCEN/PRC_FKTR = 1 | +|-------+--------+-----------------------------------+--------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST: | +| | | | * ⟦OOB_INST_ecpairing⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | . ∧ [cds ≡ 0 mod 192] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | | WE IMPOSE: | +| | | | ========== | +| | | | * SCEN/PRC_SUCCESS + SCEN/PRC_FKTH + SCEN/PRC_FKTR = 1 | +| | | | * hub_success + SCEN/PRC_FKTH = 1 | +| | | | * If no_call_data = 1 Then: SCEN/SUCCESS = 1 | +| | | | * If extract_cd = 1 Then: SCEN/SUCCESS = ram_success | +| | | | | +| | | MMU🏴 = extract_call_data | | +| | | MMU_INST = | | +| | | | | +| | | ID_SCR := CN | | +| | | SRC_OFF := CDO | | +| | | SIZE := CDS = 192 * k | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | | | +| | | ram_success := 0 / 1 (prediction) | | +|-------+--------+-----------------------------------+--------------------------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTH.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTH.lua.tex new file mode 100644 index 0000000..0f2c91b --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTH.lua.tex @@ -0,0 +1,64 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ███████\ ██████\ ██████\ ███████\ ██████\ ██\ ██\ ██████\ +██ _____|██ __██\ ██ __██\ ██ __██\ \_██ _|██ __██\ \_██ _|███\ ██ |██ __██\ +██ | ██ / \__|██ | ██ |██ / ██ | ██ | ██ | ██ | ██ | ████\ ██ |██ / \__| +█████\ ██ | ███████ |████████ | ██ | ███████ | ██ | ██ ██\██ |██ |████\ +██ __| ██ | ██ ____/ ██ __██ | ██ | ██ __██< ██ | ██ \████ |██ |\_██ | +██ | ██ | ██\ ██ | ██ | ██ | ██ | ██ | ██ | ██ | ██ |\███ |██ | ██ | +████████\ \██████ |██ | ██ | ██ |██████\ ██ | ██ |██████\ ██ | \██ |\██████ | +\________| \______/ \__| \__| \__|\______|\__| \__|\______|\__| \__| \______/ + + + | | | | __ ) _| _) | + | | | | __ \ | _` | | | | | __| _ \ + ___ | | | | | __| ( | | | | | | __/ +_| _| \___/ ____/ _| \__,_| _| _| \__,_| _| \___| + + +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| i | SCEN | SCEN/ECPAIRING | SCEN/PRC_FKTH = 1 ⛔ | +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECPAIRING⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [gas_cost ≤ call_gas] ∧ [size ≡ 0 mod 192] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := hub_success ∧ [cds = 0] | +| | | | * extract_cd := hub_success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +| | | | | +| | | | WE IMPOSE: | +| | | | ========== | +| | | | * hub_success = 0 | +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTR.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTR.lua.tex new file mode 100644 index 0000000..5a7e260 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTR.lua.tex @@ -0,0 +1,80 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ███████\ ██████\ ██████\ ███████\ ██████\ ██\ ██\ ██████\ +██ _____|██ __██\ ██ __██\ ██ __██\ \_██ _|██ __██\ \_██ _|███\ ██ |██ __██\ +██ | ██ / \__|██ | ██ |██ / ██ | ██ | ██ | ██ | ██ | ████\ ██ |██ / \__| +█████\ ██ | ███████ |████████ | ██ | ███████ | ██ | ██ ██\██ |██ |████\ +██ __| ██ | ██ ____/ ██ __██ | ██ | ██ __██< ██ | ██ \████ |██ |\_██ | +██ | ██ | ██\ ██ | ██ | ██ | ██ | ██ | ██ | ██ | ██ |\███ |██ | ██ | +████████\ \██████ |██ | ██ | ██ |██████\ ██ | ██ |██████\ ██ | \██ |\██████ | +\________| \______/ \__| \__| \__|\______|\__| \__|\______|\__| \__| \______/ + + + _ \ \ \ | _| _) | + | | _ \ |\/ | | _` | | | | | __| _ \ + __ < ___ \ | | __| ( | | | | | | __/ +_| \_\ _/ _\ _| _| _| \__,_| _| _| \__,_| _| \___| + + +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| i | SCEN | SCEN/ECPAIRING | SCEN/PRC_FKTR = 1 ⛔ | +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECPAIRING⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [gas_cost ≤ call_gas] ∧ [size ≡ 0 mod 192] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := hub_success ∧ [cds = 0] | +| | | | * extract_cd := hub_success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +| | | | | +| | | | WE HAVE: | +| | | | ======== | +| | | | * hub_success = 1 | +| | | | * no_call_data = 0 | +| | | | * extract_cd = 1 | +| | | | | +| | | MMU🏴 = extract_cd | | +| | | MMU_INST = | | +| | | | | +| | | ID_SCR := CN | | +| | | SRC_OFF := CDO | | +| | | SIZE := CDS = 192 * k | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | | | +| | | WE HAVE: | | +| | | ======== | | +| | | ram_success := 0 (HUB prediction) | | +|-------+--------+-------------------------------------+---------------------------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_success.lua.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_success.lua.tex new file mode 100644 index 0000000..d1794f0 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_success.lua.tex @@ -0,0 +1,121 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +████████\ ██████\ ███████\ ██████\ ██████\ ███████\ ██████\ ██\ ██\ ██████\ +██ _____|██ __██\ ██ __██\ ██ __██\ \_██ _|██ __██\ \_██ _|███\ ██ |██ __██\ +██ | ██ / \__|██ | ██ |██ / ██ | ██ | ██ | ██ | ██ | ████\ ██ |██ / \__| +█████\ ██ | ███████ |████████ | ██ | ███████ | ██ | ██ ██\██ |██ |████\ +██ __| ██ | ██ ____/ ██ __██ | ██ | ██ __██< ██ | ██ \████ |██ |\_██ | +██ | ██ | ██\ ██ | ██ | ██ | ██ | ██ | ██ | ██ | ██ |\███ |██ | ██ | +████████\ \██████ |██ | ██ | ██ |██████\ ██ | ██ |██████\ ██ | \██ |\██████ | +\________| \______/ \__| \__| \__|\______|\__| \__|\______|\__| \__| \______/ + + + __| | | __| __| _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ + ____/ \__,_| \___| \___| \___| ____/ ____/ + + +|-------+--------+-----------------------------------+---------------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-----------------------------------+---------------------------------------------------------------| +| i | SCEN | SCEN/ECPAIRING | SCEN/PRC_SUCCESS ✅ | +|-------+--------+-----------------------------------+---------------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECPAIRING⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * hub_success := [gas_cost ≤ call_gas] ∧ [size ≡ 0 mod 192] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := hub_success ∧ [cds = 0] | +| | | | * extract_cd := hub_success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +| | | | | +| | | | WE HAVE: | +| | | | * hub_success = 1 | +| | | | * hub_success = 1 | +| | | | | +| | | MMU🏴 = has_call_data | | +| | | MMU_INST = | | +| | | | | +| | | ID_SCR := CN | | +| | | SRC_OFF := CDO | | +| | | SIZE := CDS = 192 * k | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | | | +| | | ram_success := 0 / 1 (prediction) | | +| | | | | +| | | WE IMPOSE: | | +| | | ========== | | +| | | ram_success = 1 - SCEN/PRC_FKTR | | +| | | | | +| | | (here: 1) | | +|-------+--------+-----------------------------------+---------------------------------------------------------------| +| i + 2 | MISC | MMU🏴 = 1 | OOB🏴 = 0 | +| | | | | +| | | CASE: has_call_data = 0: | | +| | | ======================== | | +| | | MMU_INST = | | +| | | | | +| | | val_hi/lo := 0x 00 ... 01 (32B) | | +| | | CN_T := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +| | | | | +| | | CASE: has_call_data = 1: | | +| | | ======================== | | +| | | | | +| | | MMU🏴 = full_transfer | | +| | | MMU_INST = 2 x | | +| | | | | +| | | SRC_ID := 1 + HUB_ | | +| | | CN_T := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +|-------+--------+-----------------------------------+---------------------------------------------------------------| +| i + 3 | MISC | MMU🏴 = transfer_rd | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | | | +| | | CN_S := 1 + HUB_ | | +| | | REF_OFF := 0 | | +| | | REF_SIZE := 32 | | +| | | CN_T := CN | | +| | | TGT_OFF := R@O | | +| | | SIZE := R@C | | +|-------+--------+-----------------------------------+---------------------------------------------------------------| +| i + 4 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = 32 | +|-------+--------+-----------------------------------| + +Above HASH is shorthand for SHA2-256 or RIPEMD-160 depending on the case. + +SHA2-256(( )) = 0x e3b0c44298fc1c149afbf4c8996fb924 27ae41e4649b934ca495991b7852b855 +RIPEMD-160(( )) = 0x 0000000000000000000000009c1185a5 c5e9fc54612808977ee8f548b2258d31 +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/representation.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/representation.tex new file mode 100644 index 0000000..8309d99 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/representation.tex @@ -0,0 +1,7 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_common.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTH.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_failure_KTR.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecaddmul_success.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTH.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_failure_KTR.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/lua/ecpairing_success.pdf} diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/shorthands.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/shorthands.tex new file mode 100644 index 0000000..0994500 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/shorthands.tex @@ -0,0 +1,2 @@ +We will make use of the shorthands introduced in +section~(\ref{hub: instruction handling: call: precompiles: common: shorthands}). diff --git a/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/success.tex b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/success.tex new file mode 100644 index 0000000..04e0646 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecadd_ecmul_ecpairing/success.tex @@ -0,0 +1,331 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \left[ \begin{array}{cr} + + & \scenEcadd _{i} \\ + + & \scenEcmul _{i} \\ + + & \scenEcpairing _{i} \\ + \end{array} \right] + & = & 1 \\ + \scenPrcSuccess _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus assuming that the present row is the first of the second phase of dealing with one of the following precompiles: \inst{ECADD}, \inst{ECMUL} or \inst{ECPAIRING}. +We are also assuming that $\scenPrcSuccess \equiv 1$. +We remind the reader that success of any of the \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING} precompiles means that the precompile was +(\emph{a}) provided with sufficient gas +(\emph{b}) in the case of \inst{ECPAIRING} was provided with call data satisfying $\cds \equiv 0 \mod 192$ +(\emph{c}) the call data is well formed in the sense that it represents point(s) on the right curve (or sugroup of a curve in the case of \inst{ECPAIRING}.) +\begin{description} + \item[\underline{\underline{Shorthands:}}] + to streamline the upcoming constraints we introduce some shorthands + \[ + \left\{ \begin{array}{lclcl} + \locNontrivialAdd & \define & \locOobResultExtractCallData & \cdot & \scenEcadd _{i} \\ + \locNontrivialMul & \define & \locOobResultExtractCallData & \cdot & \scenEcmul _{i} \\ + \locNontrivialPairing & \define & \locOobResultExtractCallData & \cdot & \scenEcpairing _{i} \\ + \locTrivialPairing & \define & \locOobResultEmptyCallData & \cdot & \scenEcpairing _{i} \\ + \end{array} \right. + \] + \item[\underline{\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessSecondMiscRowOffset)$:}}] + this row serves to move the output of the precompile at hand to the designated \textsc{ram} segment which will house return data; + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessSecondMiscRowOffset} + = + \miscMmuWeight \cdot \locTriggerMmu + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \end{description} + where we define the \locTriggerMmu{} shorthand as follows: + \[ + \locTriggerMmu \define + \left[ \begin{array}{cl} + + & \locNontrivialAdd \\ + + & \locNontrivialMul \\ + + & \locNontrivialPairing \\ + + & \locTrivialPairing \\ + % + & \locOobResultExtractCallData & \cdot & \scenEcadd _{i} \\ + % + & \locOobResultExtractCallData & \cdot & \scenEcmul _{i} \\ + % + & & & \scenEcpairing _{i} \\ + \end{array} \right] + \] +\end{description} +\saNote{} In other words we trigger the \mmuMod{} module \emph{iff} +\begin{center} + \begin{tabular}{|ll|} + \hline + \underline{\inst{ECADD} case:} & the precompile was provided with nonempty call data \\ + \underline{\inst{ECMUL} case:} & the precompile was provided with nonempty call data \\ + \underline{\inst{ECPAIRING} case:} & in \textbf{all} cases \\ \hline + \end{tabular} +\end{center} +We remind the reader that calling \inst{ECPAIRING} with empty call data is a success case for that precompile. +In particular return data is $\textbf{o} = +\utt{00}\, +\utt{00}\, \cdots \, +\utt{01} +\in \mathbb{B}_{\evmWordSize}$ as already pointed out in +section~(\ref{hub: instruction handling: call: precompiles: common: empty}). +\begin{description} + \item[\underline{\underline{Setting \mmuMod{} data:}}] + we begin with the description of the ``trivial pairing'' case and then move onto the remaining case; + \begin{description} + \item[\underline{``Trivial pairing'' result writing:}] + \If $\locTrivialPairing = 1$ \Then we impose that + % \[ + % \scenEcpairing _{i} = 1$ \et $\locOobResultEmptyCallData = 1 + % \] + % \Then + \[ + \setMmuInstructionParametersMstore { + anchorRow = i , + relOffset = \prcStandardSuccessSecondMiscRowOffset , + targetId = 1 + \hubStamp_{i} , + targetOffsetLo = 0 , + limbOne = 0 , + limbTwo = 1 , + } + \] + \item[\underline{``Nontrivial case'' result writing:}] + we impose that + \If + \[ + \left[ \begin{array}{cl} + + & \locNontrivialAdd \\ + + & \locNontrivialMul \\ + + & \locNontrivialPairing \\ + % + & \scenEcadd _{i} \\ + % + & \scenEcmul _{i} \\ + % + & \locNontrivialPairing \\ + % + & \scenEcpairing _{i} & \cdot & \locOobResultExtractCallData \\ + \end{array} \right] + = 1 + \] + \Then + % $\miscMmuFlag_{i + \prcStandardSuccessSecondMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = \prcStandardSuccessSecondMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = 1 + \hubStamp_{i} , + size = \undefinedStar \quad \locMmuSize , + exoSum = \exoWeightEcdata , + phase = \undefinedStar \quad \locMmuPhase , + } + % \left\{ \begin{array}{lcl} + % \miscMmuInst _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locMmuInst \\ + % \miscMmuSrcId _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locMmuSrcId \\ + % \miscMmuTgtId _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locMmuTgtId \\ + % \miscMmuAuxId _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \nothing \\ + % \miscMmuSrcOffsetHi _{i + \prcStandardSuccessSecondMiscRowOffset} & = & 0 \\ + % \miscMmuSrcOffsetLo _{i + \prcStandardSuccessSecondMiscRowOffset} & = & 0 \\ + % \miscMmuTgtOffsetLo _{i + \prcStandardSuccessSecondMiscRowOffset} & = & 0 \\ + % \miscMmuSize _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locMmuSize \\ + % \miscMmuRefOffset _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \nothing \\ + % \miscMmuRefSize _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \nothing \\ + % \miscMmuSuccessBit _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbOne _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locLimbOne \\ + % \miscMmuLimbTwo _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locLimbTwo \\ + % \miscMmuExoSum _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locMmuExoSum \\ + % \miscMmuPhase _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locMmuPhase \\ + % \end{array} \right. + \] + where the shorthands marked with $\undefinedStar$ are as of yet undefined shorthands which we define as follows: + % where + % \[ + % % \hspace*{-4cm} + % \locMmuInst \define + % \left[ \begin{array}{crclcl} + % + & \mmuInstExoToRamTransplants & \!\!\!\cdot\!\!\! & \scenEcadd _{i} \\ + % + & \mmuInstExoToRamTransplants & \!\!\!\cdot\!\!\! & \scenEcmul _{i} \\ + % + & \mmuInstExoToRamTransplants & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\!\! & \locOobResultExtractCallData \\ + % + & \mmuInstMstore & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\!\! & \locOobResultEmptyCallData \\ + % \end{array} \right] + % \] + % and + % \[ + % \left\{ \begin{array}{lcl} + % \locMmuSrcId & \define & (1 + \hubStamp_{i}) \cdot + % \left[ \begin{array}{crcl} + % + & \scenEcadd _{i} \\ + % + & \scenEcmul _{i} \\ + % + & \scenEcpairing _{i} & \!\!\!\cdot\!\!\!\! & \locOobResultExtractCallData \\ + % \end{array} \right] \\ + % \locMmuTgtId & \define & (1 + \hubStamp_{i}) \\ + % \end{array} \right. + % \] + and + \[ + % \hspace*{-4cm} + \locMmuSize \define + \left[ \begin{array}{crcl} + + & \smallCurvePointSize & \!\!\!\cdot\!\!\! & \locNontrivialAdd \\ + + & \smallCurvePointSize & \!\!\!\cdot\!\!\! & \locNontrivialMul \\ + + & \evmWordSize & \!\!\!\cdot\!\!\! & \locNontrivialPairing \\ + % + & \redm{64} & \!\!\!\cdot\!\!\! & \scenEcadd _{i} \\ + % + & \redm{64} & \!\!\!\cdot\!\!\! & \scenEcmul _{i} \\ + % + & \redm{32} & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\!\! & \locOobResultExtractCallData \\ + % + & \gZero & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\!\! & \locOobResultEmptyCallData \\ + \end{array} \right] + \] + % and + % \[ + % \left\{ \begin{array}{lcl} + % \locLimbOne & \define & 0 \\ + % \locLimbTwo & \define & \scenEcpairing _{i} \cdot \locOobResultEmptyCallData \\ + % \end{array} \right. + % \] + % and + % \[ + % % \hspace*{-4cm} + % \locMmuExoSum \define + % \left[ \begin{array}{crclcl} + % + & \exoWeightEcdata & \!\!\!\cdot\!\!\! & \scenEcadd _{i} \\ + % + & \exoWeightEcdata & \!\!\!\cdot\!\!\! & \scenEcmul _{i} \\ + % + & \exoWeightEcdata & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\! & \locOobResultExtractCallData \\ + % + & \gZero & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\! & \locOobResultEmptyCallData \\ + % \end{array} \right] + % \] + and + \[ + % \hspace*{-4cm} + \locMmuPhase \define + \left[ \begin{array}{crclcl} + + & \phaseEcaddResult & \!\!\!\cdot\!\!\! & \locNontrivialAdd \\ + + & \phaseEcmulResult & \!\!\!\cdot\!\!\! & \locNontrivialMul \\ + + & \phaseEcpairingResult & \!\!\!\cdot\!\!\! & \locNontrivialPairing \\ + % + & \gZero & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} & \!\!\!\cdot\!\!\! & \locOobResultEmptyCallData \\ + \end{array} \right] + \] + \saNote{} Observe that we \textbf{don't} use + $\locOobResultExtractCallData \cdot \scenEcadd _{i}$ or + $\locOobResultExtractCallData \cdot \scenEcmul _{i}$ + when defining the shorthands + \locMmuInst{}, + \locMmuSize{}, + \locMmuExoSum{} and + \locMmuPhase{} while we \textbf{do} in order to define the \locTriggerMmu{} shorthand. + This is due to the fact that the above constraints won't trigger for \inst{ECADD} / \inst{ECMUL} unless $\locOobResultExtractCallData \equiv 1$ by virtue of the precondition + ``\If $\miscMmuFlag_{i + \prcStandardSuccessSecondMiscRowOffset} = 1$.'' + + \saNote{} The shorthands we provide are very granular and more ``precise'' than what is actually needed. + For instance we could simply have defined ``$\locMmuSrcId \define 1 + \hubStamp_{i}$'' rather than do a case analysis. + Indeed the case that our case analysis sets to $0$ (i.e. \inst{ECPAIRING}'s with empty call data) uses a \mmuMod{}-instruction, \mmuInstMstore{}, that simply ``ignores'' the \miscMmuSrcId{} altogether. Similar remarks apply to other shorthands. + + \saNote{} Recall that the return data \textbf{o} of a successful call to the \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING} precompile which successfully recovers an address is a $\redm{32}$ byte string $\textbf{o} \in \mathbb{B}_{32}$ is a string of composed of 12 (leading) zero bytes followed by 20 bytes making up the recovered Ethereum public address. + + \saNote{} We remind the reader that \textsc{ram} segments (associated to a nonzero context number) are intialized as \textbf{empty}. + Since the case of \textbf{empty call data} yields the zero string in + $\mathbb{B}_{64}$ and + $\mathbb{B}_{32}$ + for + \inst{ECADD} and + \inst{ECMUL} respectively, + there is no reason for us to set the result in either of those cases. + \end{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessThirdMiscRowOffset)$:}] + row $n^°(i + \prcStandardSuccessThirdMiscRowOffset)$ serves to copy over a portion of the return data to the current execution context's \textsc{ram}. + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessThirdMiscRowOffset} + = + \miscMmuWeight \cdot \locOobResultNonzeroRac + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locOobResultNonzeroRac & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \end{description} + \saNote{} In other words the ``result transfer'' step of a call to the \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING} is only required if the \inst{CALL} is provided with nonzero \RAC{}. + \begin{description} + \item[\underline{\mmuMod{} data:}] + \If $\miscMmuFlag_{i + \prcStandardSuccessThirdMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcStandardSuccessThirdMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = \cn_{i} , + sourceOffsetLo = \locPrcRao , + size = \locPrcRac , + referenceOffset = 0 , + referenceSize = \undefinedStar \quad \locMmuRefSize , + } + % \left\{ \begin{array}{lcl} + % \miscMmuInst _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \mmuInstRamToRamSansPadding \\ + % \miscMmuSrcId _{i + \prcStandardSuccessThirdMiscRowOffset} & = & 1 + \hubStamp_{i} \\ + % \miscMmuTgtId _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \cn_{i} \\ + % \miscMmuAuxId _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuSrcOffsetHi _{i + \prcStandardSuccessThirdMiscRowOffset} & = & 0 \\ + % \miscMmuSrcOffsetLo _{i + \prcStandardSuccessThirdMiscRowOffset} & = & 0 \\ + % \miscMmuTgtOffsetLo _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locPrcRao \\ + % \miscMmuSize _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locPrcRac \\ + % \miscMmuRefOffset _{i + \prcStandardSuccessThirdMiscRowOffset} & = & 0 \\ + % \miscMmuRefSize _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locMmuRefSize \\ + % \miscMmuSuccessBit _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbOne _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbTwo _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuExoSum _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuPhase _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \end{array} \right. + \] + where + \[ + \locMmuRefSize \define + \left[ \begin{array}{crclcl} + + & \smallCurvePointSize & \!\!\!\cdot\!\!\! & \scenEcadd _{i} \\ + + & \smallCurvePointSize & \!\!\!\cdot\!\!\! & \scenEcmul _{i} \\ + + & \evmWordSize & \!\!\!\cdot\!\!\! & \scenEcpairing _{i} \\ + \end{array} \right] + \] + \saNote{} + The above holds for all successful calls to of a successful call to either of \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING}. + That is: as long as the precompile is successful \textbf{o} is a byte string of size + precompile which successfully recovers an address is a $\redm{32}$ byte string $\textbf{o} \in \mathbb{B}_{32}$ is a string of composed of 12 (leading) zero bytes followed by 20 bytes making up the recovered Ethereum public address. + \end{description} + \item[\underline{Context-row $n^°(i + \prcStandardSuccessCallerContextRowRowOffset)$:}] + we impose + \[ + \provideReturnData { + anchorRow = i , + relOffset = \prcStandardSuccessCallerContextRowRowOffset , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = 0 , + returnDataSize = \locMmuRefSize , + } + % \provideReturnData + % {i}{4} + % {\cn_{i} } % Return data receiver + % {1 + \hubStamp_{i}} % Return data provider + % {0 } % Return data offset + % {\locMmuRefSize } % Return data size + \] + \end{description} + diff --git a/hub/instruction_handling/call/precompiles/ecrecover/_inputs.tex b/hub/instruction_handling/call/precompiles/ecrecover/_inputs.tex new file mode 100644 index 0000000..841a856 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsubsection{\inst{ECRECOVER} shorthands \lispNone{}} \label{hub: instruction handling: call: precompiles: ecrecover: shorthands} \input{instruction_handling/call/precompiles/ecrecover/shorthands} +\subsubsubsection{\inst{ECRECOVER} representation \lispNone{}} \label{hub: instruction handling: call: precompiles: ecrecover: representation} \input{instruction_handling/call/precompiles/ecrecover/representation} +\subsubsubsection{\inst{ECRECOVER} success case \lispDone{}} \label{hub: instruction handling: call: precompiles: ecrecover: success} \input{instruction_handling/call/precompiles/ecrecover/success} diff --git a/hub/instruction_handling/call/precompiles/ecrecover/lua/common.lua.tex b/hub/instruction_handling/call/precompiles/ecrecover/lua/common.lua.tex new file mode 100644 index 0000000..956ea1e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/lua/common.lua.tex @@ -0,0 +1,122 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ████████\ ██████\ ███████\ ████████\ ██████\ ██████\ ██\ ██\ ████████\ ███████\ + ██ _____|██ __██\ ██ __██\ ██ _____|██ __██\ ██ __██\ ██ | ██ |██ _____|██ __██\ + ██ | ██ / \__|██ | ██ |██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ | + █████\ ██ | ███████ |█████\ ██ | ██ | ██ |\██\ ██ |█████\ ███████ | + ██ __| ██ | ██ __██< ██ __| ██ | ██ | ██ | \██\██ / ██ __| ██ __██< + ██ | ██ | ██\ ██ | ██ |██ | ██ | ██\ ██ | ██ | \███ / ██ | ██ | ██ | + ████████\ \██████ |██ | ██ |████████\ \██████ | ██████ | \█ / ████████\ ██ | ██ | + \________| \______/ \__| \__|\________| \______/ \______/ \_/ \________|\__| \__| + + + __| _ \ __ `__ \ __ `__ \ _ \ __ \ + ( ( | | | | | | | ( | | | + \___| \___/ _| _| _| _| _| _| \___/ _| _| + + + +|-------+--------+----------------------------------------+--------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+----------------------------------------+--------------------------------------------------------| +| i | SCEN | SCEN/ECRECOVER | SCEN/PRC_SUCCESS ✅ | +|-------+--------+----------------------------------------+--------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_ecrecover⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | =============== | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | ================== | +| | | | * (implicit) compute gas_cost | +| | | | * success := [gas_cost ≤ call_gas] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := success ∧ [cds = 0] | +| | | | * extract_cd := success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +| | | | | +| | | | WE IMPOSE: | +| | | | ========== | +| | | | * SCEN/PRC_SUCCESS + SCEN/PRC_FKTR + SCEN/PRC_FKTH = 1 | +| | | | * SCEN/PRC_FKTR = 0 | +| | | | * success = SCEN/PRC_SUCCESS | +| | | | | +| | | | WE PREDICT: | +| | | | =========== | +| | | | * recovery_success = 0 / 1 (prediction!) | +| | | | | +| | | MMU🏴 = extract_cd | | +| | | if extract_padded = 1: | | +| | | MMU_INST = | | +| | | | | +| | | if extract_unpadded = 1: | | +| | | MMU_INST = | | +| | | | | +| | | ID_S := CN | | +| | | ID_T := 1 + HUB_ | | +| | | SRC_OFF := CDO | | +| | | TGT_OFF := 0 | | +| | | SIZE := CDS | | +| | | SUCCESS := recovery_success | | +| | | exo_sum:= 1 << ec_data | | +|-------+--------+----------------------------------------+--------------------------------------------------------| +| i + 2 | MISC | MMU🏴 = recovery_success | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | 2 x limb transplant | | +| | | | | +| | | ID_S := 1 + HUB_ | | +| | | ID_T := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +| | | SIZE := 32 | | +| | | REF_SIZE := 32 | | +| | | exo_sum := 1 << ec_data | | +|-------+--------+----------------------------------------+--------------------------------------------------------| +| i + 2 | MISC | MMU🏴 = recovery_success ∧ transfer_rd | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | | | +| | | ID_S := 1 + HUB_ | | +| | | ID_T := CN | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := r@o | | +| | | SIZE := r@c | | +| | | REF_SIZE := 32 | | +| | | exo_sum := 1 << ec_data | | +|-------+--------+----------------------------------------+--------------------------------------------------------| +| i + 3 | CON | if recovery_success = 0: | +| | | nonContextProvidesEmptyReturnData() | +| | | | +| | | if recovery_success = 1: | +| | | updateReturnData() | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = 32 | +|-------+--------+----------------------------------------| +\end{verbatim} +\end{document} + + + + + diff --git a/hub/instruction_handling/call/precompiles/ecrecover/lua/failure_KTH.lua.tex b/hub/instruction_handling/call/precompiles/ecrecover/lua/failure_KTH.lua.tex new file mode 100644 index 0000000..9214533 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/lua/failure_KTH.lua.tex @@ -0,0 +1,78 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ████████\ ██████\ ███████\ ████████\ ██████\ ██████\ ██\ ██\ ████████\ ███████\ + ██ _____|██ __██\ ██ __██\ ██ _____|██ __██\ ██ __██\ ██ | ██ |██ _____|██ __██\ + ██ | ██ / \__|██ | ██ |██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ | + █████\ ██ | ███████ |█████\ ██ | ██ | ██ |\██\ ██ |█████\ ███████ | + ██ __| ██ | ██ __██< ██ __| ██ | ██ | ██ | \██\██ / ██ __| ██ __██< + ██ | ██ | ██\ ██ | ██ |██ | ██ | ██\ ██ | ██ | \███ / ██ | ██ | ██ | + ████████\ \██████ |██ | ██ |████████\ \██████ | ██████ | \█ / ████████\ ██ | ██ | + \________| \______/ \__| \__|\________| \______/ \______/ \_/ \________|\__| \__| + + + _| _) | | + | _` | | | | | __| _ \ | / __ \ _ \ \ \ \ / __ \ + __| ( | | | | | | __/ < | | ( | \ \ \ / | | + _| \__,_| _| _| \__,_| _| \___| _|\_\ _| _| \___/ \_/\_/ _| _| + + | | | | | __ ) + __| _ \ | | | | __ \ + | ( | ___ | | | | | + \__| \___/ _| _| \___/ ____/ + + + +|-------+--------+-------------------------------------+----------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+----------------------------------------------| +| i | SCEN | SCEN/ECRECOVER | SCEN/PRC_FAILURE_KNOWN_TO_HUB ⛔ | +|-------+--------+-------------------------------------+----------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECRECOVER⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | =============== | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | ================== | +| | | | * (implicit) compute gas_cost | +| | | | * success := [gas_cost ≤ call_gas] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := success ∧ [cds = 0] | +| | | | * extract_cd := success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +| | | | | +| | | | IMPOSE: | +| | | | ======= | +| | | | sufficient_gas = SCEN/PRC_SUCCESS (here: 0) | +| | | | | +| | | MMU🏴 = extract_cd (here: 0) | | +| | | do nothing: | | +|-------+--------+-------------------------------------+----------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} + + + diff --git a/hub/instruction_handling/call/precompiles/ecrecover/lua/success.lua.tex b/hub/instruction_handling/call/precompiles/ecrecover/lua/success.lua.tex new file mode 100644 index 0000000..28a6d69 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/lua/success.lua.tex @@ -0,0 +1,115 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ████████\ ██████\ ███████\ ████████\ ██████\ ██████\ ██\ ██\ ████████\ ███████\ + ██ _____|██ __██\ ██ __██\ ██ _____|██ __██\ ██ __██\ ██ | ██ |██ _____|██ __██\ + ██ | ██ / \__|██ | ██ |██ | ██ / \__|██ / ██ |██ | ██ |██ | ██ | ██ | + █████\ ██ | ███████ |█████\ ██ | ██ | ██ |\██\ ██ |█████\ ███████ | + ██ __| ██ | ██ __██< ██ __| ██ | ██ | ██ | \██\██ / ██ __| ██ __██< + ██ | ██ | ██\ ██ | ██ |██ | ██ | ██\ ██ | ██ | \███ / ██ | ██ | ██ | + ████████\ \██████ |██ | ██ |████████\ \██████ | ██████ | \█ / ████████\ ██ | ██ | + \________| \______/ \__| \__|\________| \______/ \______/ \_/ \________|\__| \__| + + + __| | | __| __| _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ + ____/ \__,_| \___| \___| \___| ____/ ____/ + + + +|-------+--------+----------------------------------------+---------------------------------------------------| +| Row | Persp. | | | +|-------+--------+----------------------------------------+---------------------------------------------------| +| i | SCEN | SCEN/ECRECOVER | SCEN/PRC_SUCCESS ✅ | +|-------+--------+----------------------------------------+---------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_ECRECOVER⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | =============== | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | ================== | +| | | | * (implicit) compute gas_cost | +| | | | * success := [gas_cost ≤ call_gas] | +| | | | * remaining_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * no_call_data := success ∧ [cds = 0] | +| | | | * extract_cd := success ∧ [cds ≠ 0] | +| | | | * transfer_rd := [r@c ≠ 0] | +| | | | | +| | | | WE IMPOSE: | +| | | | ========== | +| | | | * success = SCEN/PRC_SUCCESS (here: 1) | +| | | | | +| | | | WE PREDICT: | +| | | | =========== | +| | | | * recovery_success = 0 / 1 | +| | | | if SCEN/PRC_FAILURE = 1 then recovery_success = 0 | +| | | | | +| | | MMU🏴 = extract_cd | | +| | | if extract_padded = 1: | | +| | | MMU_INST = | | +| | | | | +| | | if extract_unpadded = 1: | | +| | | MMU_INST = | | +| | | | | +| | | ID_S := CN | | +| | | ID_T := 1 + HUB_ | | +| | | SRC_OFF := CDO | | +| | | TGT_OFF := 0 | | +| | | SIZE := CDS ∧ 128 | | +| | | SUCCESS := recovery_success | | +| | | exo_sum:= 1 << ec_data | | +|-------+--------+----------------------------------------+---------------------------------------------------| +| i + 2 | MISC | MMU🏴 = recovery_success | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | | | +| | | ID_S := 1 + HUB_ | | +| | | ID_T := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +| | | SIZE := 32 | | +| | | REF_SIZE := 32 | | +| | | exo_sum := 1 << ec_data | | +|-------+--------+----------------------------------------+---------------------------------------------------| +| i + 2 | MISC | MMU🏴 = recovery_success ∧ transfer_rd | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | | | +| | | ID_S := 1 + HUB_ | | +| | | ID_T := CN | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := R@O | | +| | | SIZE := R@C | | +| | | REF_SIZE := 32 | | +| | | exo_sum := 1 << ec_data | | +|-------+--------+----------------------------------------+---------------------------------------------------| +| i + 3 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = CDS | +|-------+--------+----------------------------------------| +\end{verbatim} +\end{document} + + + diff --git a/hub/instruction_handling/call/precompiles/ecrecover/representation.tex b/hub/instruction_handling/call/precompiles/ecrecover/representation.tex new file mode 100644 index 0000000..88c9f81 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/representation.tex @@ -0,0 +1,4 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecrecover/lua/common.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecrecover/lua/failure_KTH.pdf} +% \includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecrecover/lua/failure_KTR.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/ecrecover/lua/success.pdf} diff --git a/hub/instruction_handling/call/precompiles/ecrecover/shorthands.tex b/hub/instruction_handling/call/precompiles/ecrecover/shorthands.tex new file mode 100644 index 0000000..b7f9c83 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/shorthands.tex @@ -0,0 +1,9 @@ +We will make use of the shorthands introduced in +section~(\ref{hub: instruction handling: call: precompiles: shorthands}). +We will also use the ``\inst{ECRECOVER}-specific'' shorthands from +section~(\ref{hub: instruction handling: call: precompiles: common: generalities}), +in particular +\begin{itemize} + \item \locAddressRecoveryFailure{} + \item \locAddressRecoverySuccess{} +\end{itemize} diff --git a/hub/instruction_handling/call/precompiles/ecrecover/success.tex b/hub/instruction_handling/call/precompiles/ecrecover/success.tex new file mode 100644 index 0000000..4fc45fc --- /dev/null +++ b/hub/instruction_handling/call/precompiles/ecrecover/success.tex @@ -0,0 +1,119 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenEcrecover _{i} & = & 1 \\ + \scenPrcSuccess _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus assuming that the present row is the first of the second phase of dealing with the \inst{ECRECOVER} precompile. +We are also assuming that $\scenPrcSuccess \equiv 1$. +We remind the reader that success of the \inst{ECRECOVER} precompile only means that it was provided with sufficient gas, not that an address was effectively recovered. +\begin{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessSecondMiscRowOffset)$:}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessSecondMiscRowOffset} + = + \miscMmuWeight \cdot \locAddressRecoverySuccess + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locAddressRecoverySuccess & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \end{description} + \saNote{} In other words the ``result transfer'' step of a call to the \inst{ECRECOVER} only required if the call is + (\emph{a}) is successful (i.e. is given sufficient gas) and + (\emph{b}) is successful in recovering an address (as measured by $\locAddressRecoverySuccess \equiv 1$.) + \begin{description} + \item[\underline{\mmuMod{} data:}] + \If $\miscMmuFlag_{i + \prcStandardSuccessSecondMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = \prcStandardSuccessSecondMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = 1 + \hubStamp_{i} , + size = \evmWordSize , + exoSum = \exoWeightEcdata , + phase = \phaseEcrecoverResult , + } + \] + \saNote{} Recall that the return data \textbf{o} of a successful call to the \inst{ECRECOVER} precompile which successfully recovers an address is a $\evmWordSize$ byte string $\textbf{o} \in \mathbb{B}_{\evmWordSize}$ is a string of composed of 12 (leading) zero bytes followed by 20 bytes making up the recovered Ethereum public address. + \end{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessThirdMiscRowOffset)$:}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessThirdMiscRowOffset} + = + \miscMmuWeight + \cdot + \left[ \begin{array}{l} + \cdot \; \locAddressRecoverySuccess   \\ + \cdot \; \locOobResultNonzeroRac  \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclc} + \miscExpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locAddressRecoverySuccess \cdot \locOobResultNonzeroRac & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \end{description} + \saNote{} In other words the ``result transfer'' step of a call to the \inst{ECRECOVER} only required if the call is + (\emph{a}) is successful (i.e. is given sufficient gas) and + (\emph{b}) is successful in recovering an address (as measured by $\locAddressRecoverySuccess \equiv 1$.) + \begin{description} + \item[\underline{\mmuMod{} data:}] + \If $\miscMmuFlag_{i + \prcStandardSuccessThirdMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcStandardSuccessThirdMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = \cn_{i} , + sourceOffsetLo = 0 , + size = \evmWordSize , + referenceOffset = \locPrcRao , + referenceSize = \locPrcRac , + } + \] + \saNote{} Recall that the return data \textbf{o} of a successful call to the \inst{ECRECOVER} precompile which successfully recovers an address is a $\redm{\evmWordSize}$ byte string $\textbf{o} \in \mathbb{B}_{\evmWordSize}$ composed of 12 (leading) zero bytes followed by 20 bytes making up the recovered Ethereum public address. + \end{description} + \item[\underline{Context-row $n^°(i + \prcStandardSuccessCallerContextRowRowOffset)$:}] + we impose + \[ + \provideReturnData { + anchorRow = i , + relOffset = \prcStandardSuccessCallerContextRowRowOffset , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = 0 , + returnDataSize = \evmWordSize \cdot \locAddressRecoverySuccess , + } + % \provideReturnData + % {i}{4} + % {\cn_{i} } % Return data receiver + % {1 + \hubStamp_{i} } % Return data provider + % {0 } % Return data offset + % {\evmWordSize \cdot \locAddressRecoverySuccess} % Return data size + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/explicit_nsr.tex b/hub/instruction_handling/call/precompiles/explicit_nsr.tex new file mode 100644 index 0000000..c7f175a --- /dev/null +++ b/hub/instruction_handling/call/precompiles/explicit_nsr.tex @@ -0,0 +1,36 @@ +The table below contains the summary of what will be imposed by means of the previous constraint. +The numerical values that are found in that table are the values of \nonStackRows{} associated with the various execution scenarios of the various precompiled contracts. +It is a concretization of +the setting of \nonStackRows{} in section~(\ref{hub: instruction handling: call: precompiles: generalities}), +the definition of \locFirstPhaseNsr{} in the section~(\ref{hub: instruction handling: call: precompiles: flag sums and nsr}) +as well as the definitions of the various \locNsrXxx{} in section~(\ref{hub: instruction handling: call: precompiles: flag sums and nsr}). +\begin{figure}[!h] + \centering + + \begin{tabular}{|l||c|c|c|c|} \hline + \textsc{Precompile} & \locFkth & \locFktr & \locSwill & \locSwont \\ \hline \hline + \inst{ECRECOVER} & \locStandardFail & \johnSnow & \locStandardSuccWill & \locStandardSuccWont \\ \hline + \inst{SHA2-256} & \locStandardFail & \johnSnow & \locStandardSuccWill & \locStandardSuccWont \\ \hline + \inst{RIPEMD-160} & \locStandardFail & \johnSnow & \locStandardSuccWill & \locStandardSuccWont \\ \hline + \inst{IDENTITY} & \locStandardFail & \johnSnow & \locIdentitySuccWill & \locIdentitySuccWont \\ \hline + \inst{MODEXP} & \johnSnow & \locModexpFKTR & \locModexpSuccWill & \locModexpSuccWont \\ \hline + \inst{ECADD} & \locStandardFail & \locStandardFail & \locStandardSuccWill & \locStandardSuccWont \\ \hline + \inst{ECMUL} & \locStandardFail & \locStandardFail & \locStandardSuccWill & \locStandardSuccWont \\ \hline + \inst{ECPAIRING} & \locStandardFail & \locStandardFail & \locStandardSuccWill & \locStandardSuccWont \\ \hline + \inst{BLAKE2f} & \locBlakeFKTH & \locBlakeFKTR & \locBlakeSuccWill & \locBlakeSuccWont \\ \hline + \end{tabular} + + \label{hub: instruction handling: call: precompiles: table of non stack-rows classifying failures known to the HUB vs. to RAM} + \caption{The numerical values in the table above represent the value of \nonStackRows{} for each precompile depending on the execution scenario. + To save space we have used the following abbreviations \\ + \centering + \begin{tabular}{lcl} + \locFkth & $ \longleftrightarrow $ & \scenPrcFailureKnownToHub \\ + \locFktr & $ \longleftrightarrow $ & \scenPrcFailureKnownToRam \\ + \locSwill & $ \longleftrightarrow $ & \scenPrcSuccessWillRevert \\ + \locSwont & $ \longleftrightarrow $ & \scenPrcSuccessWontRevert \\ + \end{tabular} + } +\end{figure} + + diff --git a/hub/instruction_handling/call/precompiles/failures_vs_successes.tex b/hub/instruction_handling/call/precompiles/failures_vs_successes.tex new file mode 100644 index 0000000..9d87c9e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/failures_vs_successes.tex @@ -0,0 +1,24 @@ +The reader should note that what we dub +\textbf{precompile failures}\label{def: precompile failure} +are all those execution scenarios which lead to the current precompile \texttt{PRC} returning +\[ + \Xi_\texttt{PRC} + (\bm{\sigma}, g, A, I) + \equiv + (\varnothing, 0, A, ()) +\] +while +\textbf{precompile successes}\label{def: precompile success} +are all those execution scenarios which lead to the current precompile \texttt{PRC} returning +\[ + \Xi_\texttt{PRC} + (\bm{\sigma}, g, A, I) + \equiv + (\bm{\sigma}, g - g_\text{r}, A, \textbf{o}) +\] +Notations are those of the \cite{EYP}. + +\saNote{} +Thus an \inst{ECRECOVER} which is provided with (sufficient gas but) malformed data, preventing it from recovering an address, constitutes a ``precompile success'' (with $\textbf{o} = ()$), +while an \inst{ECADD} / \inst{ECMUL} / \inst{ECPAIRING} which is provided with (sufficient gas but) malformed data is considered a ``precompile failure'' (with $\textbf{o} = ()$.) +More details will be given in section~(\ref{hub: instruction handling: call: precompiles: failure classification}) diff --git a/hub/instruction_handling/call/precompiles/flags.tex b/hub/instruction_handling/call/precompiles/flags.tex new file mode 100644 index 0000000..0e999ef --- /dev/null +++ b/hub/instruction_handling/call/precompiles/flags.tex @@ -0,0 +1,11 @@ +In this section we finish what was started in +section~(\ref{hub: instruction handling: call: partial peeking flag sums for precompiles}) and +section~(\ref{hub: instruction handling: call: partial non stack rows for precompiles}). +\begin{enumerate} + \item set the value of $\nonStackRows$ for all precompiles and all execution paths; + \item set the associate peeking flags; + \item specify the contents of the associated rows; + \item update the caller context's return data; +\end{enumerate} +In terms of peeking rows, beyond the chosen vantage point which will be a scenario-row pertaining to some precompile scenario, what follows will be a sequence of miscellaneous-rows and one context-row where there may be a call to the \oobMod{} module (e.g. for pricing of most precompiles) and zero, one or more calls to the \mmuMod{} to +We shall define a number of shorthands: diff --git a/hub/instruction_handling/call/precompiles/flowcharts/0x01_ECRECOVER.dot b/hub/instruction_handling/call/precompiles/flowcharts/0x01_ECRECOVER.dot new file mode 100644 index 0000000..d55a224 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/flowcharts/0x01_ECRECOVER.dot @@ -0,0 +1,172 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + precompiles [label=< + + + + +
ECRECOVER
ECADD
ECMUL
ECPAIRING
>]; + insufficient_gas [ + label = "\nInsufficient\ngas exception\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + malformed_data [ + label = "\nMalformed\ndata\n "; + shape = diamond; + style = filled; + fillcolor = "yellow"; + color = "ORANGE"; + ]; + success [ + label = "\nSuccess\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "GREEN"; + ]; + + { + rank=same; + insufficient_gas; insufficient_gas_rows; + } + { + rank=same; + malformed_data; malformed_data_rows; + } + { + rank=same; + success; success_rows; + } + + precompiles -> insufficient_gas; + insufficient_gas -> insufficient_gas_rows; + insufficient_gas -> malformed_data; + malformed_data -> malformed_data_rows; + malformed_data -> success; + success -> success_rows; + +insufficient_gas_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
jSCNCREATE/EXCEPTION
j + 1MISC OOB🏴 = 1, OOB_EVENT = 1
j + 2ConparentCaller: update return data   μo ­  ← ∅
>]; + +malformed_data_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
jSCNCREATE/EXCEPTION
j + 1MISC + OOB🏴 = 1, OOB_EVENT = 0
+ MMU🏴 = 1, extractXxxData; INFO = 1; +
j + 2ConparentCaller: update return data   μo ­  ← ∅
>]; + +success_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
jSCNCREATE/EXCEPTION
j + 1MISC + OOB🏴 = 1, OOB_EVENT = 0
+ MMU🏴 = 1, extractXxxData; INFO = 0; +
j + 2MISC MMU🏴 = 1, copyXxxResult
j + 3MISC MMU🏴 = [R@C ≠ 0], transferXxxResult; iff ;
j + 4ConparentCaller: update return data   μo ­  ← RDO, RDS
>]; + +} + diff --git a/hub/instruction_handling/call/precompiles/flowcharts/0x01_ECRECOVER.svg b/hub/instruction_handling/call/precompiles/flowcharts/0x01_ECRECOVER.svg new file mode 100644 index 0000000..4cab0b2 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/flowcharts/0x01_ECRECOVER.svg @@ -0,0 +1,259 @@ + + + + + + +G + + + +precompiles + + ECRECOVER + ECADD + ECMUL + ECPAIRING + + + +insufficient_gas + +Insufficient +gas exception + + + + +precompiles->insufficient_gas + + + + + +malformed_data + +Malformed +data + + + + +insufficient_gas->malformed_data + + + + + +insufficient_gas_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +j + + +SCN + + +CREATE/EXCEPTION + +j + 1 + +MISC + + + OOB🏴 = +1 +, OOB_EVENT = +1 + + +j + 2 + +Con + +parent + +Caller: update return data   +μ +o + ­  ← ∅ + + + +insufficient_gas->insufficient_gas_rows + + + + + +success + +Success + + + + +malformed_data->success + + + + + +malformed_data_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +j + + +SCN + + +CREATE/EXCEPTION + +j + 1 + +MISC + + +    OOB🏴 = +1 +, OOB_EVENT = +0 + +MMU🏴 = +1 +, extractXxxData; INFO = +1 +;     + +j + 2 + +Con + +parent + +Caller: update return data   +μ +o + ­  ← ∅ + + + +malformed_data->malformed_data_rows + + + + + +success_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +j + + +SCN + + +CREATE/EXCEPTION + +j + 1 + +MISC + + +    OOB🏴 = +1 +, OOB_EVENT = +0 + +MMU🏴 = +1 +, extractXxxData; INFO = +0 +;     + +j + 2 + +MISC + + + MMU🏴 = +1 +, copyXxxResult + +j + 3 + +MISC + + + MMU🏴 = +[R@C ≠ 0] +, transferXxxResult; +iff + ; + +j + 4 + +Con + +parent + +Caller: update return data   +μ +o + ­  ← +RDO +,   +RDS + + + + +success->success_rows + + + + + diff --git a/hub/instruction_handling/call/precompiles/flowcharts/0x05_modexp.dot b/hub/instruction_handling/call/precompiles/flowcharts/0x05_modexp.dot new file mode 100644 index 0000000..e822daf --- /dev/null +++ b/hub/instruction_handling/call/precompiles/flowcharts/0x05_modexp.dot @@ -0,0 +1,168 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + +failure [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveActions
iSCENSCEN/PRC = 1, SCEN/MODEXP = 1
i + 1MISC MMU🏴 = 0 EXP🏴 = 0 OOB🏴 = 1 +
OOB_INST = MODEXP_cds +
cds +
extract_raw_bbs = [ cds > 0 ] +
extract_raw_ebs = [ cds > 32 ] +
extract_raw_mbs = [ cds > 64 ] +
trim_raw_bbs = [ cds > 0 ] ∧ [ cds < 32 ] +
trim_raw_ebs = [ cds > 32 ] ∧ [ cds < 64 ] +
trim_raw_mbs = [ cds > 64 ] ∧ [ cds < 96 ] +
i + 1MISC MMU🏴 = extract_raw_bbs
MMU_INST = MLOAD
offset = cdo
EXP🏴 = trim_raw_bbs
EXP_INST = trimBytesBeyond
OOB🏴 = extract_raw_bbs +
bbs +
(implicit check) bbs ≤ 512 +
OOB_INST = MODEXP_base +
i + 2MISC MMU🏴 = extract_raw_ebs
MMU_INST = MLOAD
offset = cdo + 32
EXP🏴 = trim_raw_ebs
EXP_INST = trimBytesBeyond
OOB🏴 = extract_raw_ebs +
ebs +
(implicit check) ebs ≤ 512 +
OOB_INST = MODEXP_exponent +
diff := 0 ∨ [ebs - 32] +
n_ebs_bytes := 32 ∧ ebs +
i + 3MISC MMU🏴 = extract_raw_mbs
MMU_INST = MLOAD
offset = cdo + 64
EXP🏴 = trim_raw_mbs
EXP_INST = trimBytesBeyond
OOB🏴 = extract_raw_mbs +
mbs, bbs +
(implicit check) mbs ≤ 512 +
OOB_INST = MODEXP_modulus +
max_bbs_mbs := bbs mbs +
i + 4MISC MMU🏴 = extract_raw_leading_word
MMU_INST = MLOAD
offset = cdo + 96
EXP🏴 = extract_raw_leading_word
EXP_INST = exponentLeadingWordLog
OOB🏴 = 1 +
cds, ebs, bbs +
OOB_INST = MODEXP_leading +
n_cds_bytes := 32 ∧ [ 0 ∨ [cds - (96 + bbs)]] +
extract_raw_leading_word := [cds > 96 + bbs] ∧ [ebs ≠ 0] +
i + 5MISC MMU🏴 = 0 EXP🏴 = 0 OOB🏴 = 1 +
call_gas, rem_gas, log(E)_approx, max_bbs_mbs, r@c +
(implicit check) mbs ≤ 512 +
OOB_INST = MODEXP_pricing +
insufficient_gas = 1 +
[r@c ≠ 0] +
extract_raw_leading_word := [cds > 96 + bbs] ∧ [ebs ≠ 0] +
i + 1MISC MMU🏴 = 1 EXP🏴 = 1 OOB🏴 = 1
i - 1STACKCT = 1excavate stack items
success bit = 1
iSCNCALL SCEN/CALL/smc_success_will_revert
i + 1CONcurrentread context; STATIC🏴 = 0
i + 2MISC MXP🏴 = 1, MXPX = 0
STP🏴 = 1, OOGX = 0
OOB🏴 = 1, OOB_EVENT_1 = 0
CCSR🏴 = 0, CCRS = 0
i + 3ACCcallee bal' += val, warmth' ↗
TRM🏴 = 1, ROMLEX🏴 = 1
HAS_CODE = 1, IS_PREC = 0
τ · h + 10
i + 4ACCcallerbal -= val, same warmthτ · h + 00
i + 5ACCcalleebal' ↶, warmth' ↶ τ · ρ + ετ · h + 1
i + 6ACCcallerbal ↶, warmth ↶ τ · ρ + ετ · h + 0
i + 7CONcalleeinitialize callee
>]; + + +} diff --git a/hub/instruction_handling/call/precompiles/flowcharts/0x05_modexp.svg b/hub/instruction_handling/call/precompiles/flowcharts/0x05_modexp.svg new file mode 100644 index 0000000..3c113a1 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/flowcharts/0x05_modexp.svg @@ -0,0 +1,459 @@ + + + + + + +G + + + +failure + +Row index + +Perspective + +Actions + +i + + +SCEN + + +SCEN/PRC = 1, SCEN/MODEXP = 1 + +i + 1 + +MISC + + +MMU🏴 + = 0 + + +EXP🏴 + = 0 + + +OOB🏴 + = +1 +     + OOB_INST = MODEXP_cds      + +cds +     + +extract_raw_bbs + + = [ +cds + > 0 ]     + +extract_raw_ebs + + = [ +cds + > 32 ]     + +extract_raw_mbs + + = [ +cds + > 64 ]     + +trim_raw_bbs + + = [ +cds + > 0  ] ∧ [ +cds + < 32  ]     + +trim_raw_ebs + + = [ +cds + > 32 ] ∧ [ +cds + < 64 ]     + +trim_raw_mbs + + = [ +cds + > 64 ] ∧ [ +cds + < 96 ]     + +i + 1 + +MISC + + +MMU🏴 + = +extract_raw_bbs + + MMU_INST = MLOAD + offset = +cdo + + + +EXP🏴 + = +trim_raw_bbs + + EXP_INST = trimBytesBeyond + + +OOB🏴 + = +extract_raw_bbs +     + +bbs +     + (implicit check) +bbs + ≤ 512     + OOB_INST = MODEXP_base      + +i + 2 + +MISC + + +MMU🏴 + = +extract_raw_ebs + + MMU_INST = MLOAD + offset = +cdo + 32 + + + +EXP🏴 + = +trim_raw_ebs + + EXP_INST = trimBytesBeyond + + +OOB🏴 + = +extract_raw_ebs +     +ebs +     +(implicit check) +ebs + ≤ 512     +OOB_INST = MODEXP_exponent      +diff + := 0 ∨ [ebs - 32]     +n_ebs_bytes   + := 32 ∧ ebs     + +i + 3 + +MISC + + +MMU🏴 + = +extract_raw_mbs + + MMU_INST = MLOAD + offset = +cdo + 64 + + + +EXP🏴 + = +trim_raw_mbs + + EXP_INST = trimBytesBeyond + + +OOB🏴 + = +extract_raw_mbs +     +mbs, bbs +     +(implicit check) +mbs + ≤ 512     +OOB_INST = MODEXP_modulus      +max_bbs_mbs + := +bbs + +mbs +     + +i + 4 + +MISC + + +MMU🏴 + = +extract_raw_leading_word + + MMU_INST = MLOAD + offset = +cdo + 96 + + + +EXP🏴 + = +extract_raw_leading_word + + EXP_INST = exponentLeadingWordLog + + +OOB🏴 + = +1 +     +cds, ebs, bbs +     +OOB_INST = MODEXP_leading     +n_cds_bytes + := 32 ∧ [ 0 ∨ [ +cds + - (96 + +bbs +)]]     +extract_raw_leading_word + := [ +cds + > 96 + +bbs +] ∧ [ +ebs + ≠ 0]     + +i + 5 + +MISC + + +MMU🏴 + = +0 + + + +EXP🏴 + = +0 + + + +OOB🏴 + = +1 +     +call_gas, rem_gas, log(E)_approx, max_bbs_mbs, r@c +     +(implicit check) +mbs + ≤ 512     +OOB_INST = MODEXP_pricing      +insufficient_gas + = +1 +     +[r@c ≠ 0] +     +extract_raw_leading_word + := [ +cds + > 96 + +bbs +] ∧ [ +ebs + ≠ 0]     + +i + 1 + +MISC + + +MMU🏴 + = +1 + + + +EXP🏴 + = +1 + + + +OOB🏴 + = +1 + + +i - 1 + +STACK + +CT = 1 + +excavate stack items + success bit = +1 + +i + + +SCN + + +CALL + + + SCEN/CALL/smc_success_will_revert + +i + 1 + +CON + +current + +read context; +STATIC🏴 + = +0 + + +i + 2 + +MISC + + + +MXP🏴 + = +1 +, +MXPX + = +0 + + +STP🏴 + = +1 +, +OOGX + = +0 + + +OOB🏴 + = +1 +, +OOB_EVENT_1 + = +0 + + CCSR🏴 = +0 +, CCRS = +0 + +i + 3 + +ACC + + +callee + + bal' += val, warmth' ↗   + +TRM🏴 + = +1 +, +ROMLEX🏴 + = +1 + + HAS_CODE = +1 +, IS_PREC = +0 + + +τ · h + 1 + +0 + +i + 4 + +ACC + + +caller + +bal -= val, same warmth + +τ · h + 0 + +0 + +i + 5 + +ACC + + +callee + +bal' ↶, warmth' ↶ + +τ · ρ + ε + +τ · h + 1 + +i + 6 + +ACC + + +caller + +bal ↶, warmth ↶ + +τ · ρ + ε + +τ · h + 0 + +i + 7 + +CON + + +callee + + +initialize callee + + + diff --git a/hub/instruction_handling/call/precompiles/flowcharts/modexp b/hub/instruction_handling/call/precompiles/flowcharts/modexp new file mode 100644 index 0000000..a68264e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/flowcharts/modexp @@ -0,0 +1,42 @@ +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| Row index | Perspective | | | | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i | SCEN | SCEN/MODEXP | FAILURE_KNOWN_TO_RAM | | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 1 | MISC | MMU🏴 = 0 | EXP🏴 = 0 | OOB🏴 = 1 | +| | | | | OOB_INST = MODEXP_cds | +| | | | | extract_raw_bbs := [cds > 0] | +| | | | | extract_raw_ebs := [cds > 32] | +| | | | | extract_raw_mbs := [cds > 64] | +| | | | | trim_raw_bbs := [cds > 0] ∧ [cds < 32] | +| | | | | trim_raw_ebs := [cds > 32] ∧ [cds < 64] | +| | | | | trim_raw_mbs := [cds > 64] ∧ [cds < 96] | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 2 | MISC | MMU🏴 = extract_raw_bbs | EXP🏴 = trim_raw_bbs | OOB🏴 = extract_raw_bbs | +| | | MMU_INST = MLOAD, offset = cdo | EXP_INST = trimBytesBeyond | (implicit check) bbs ≤ 512 | +| | | | | OOB_INST = MODEXP_base | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 3 | MISC | MMU🏴 = extract_raw_ebs | EXP🏴 = trim_raw_ebs | OOB🏴 = extract_raw_ebs | +| | | MMU_INST = MLOAD, offset = cdo + 32 | EXP_INST = trimBytesBeyond | (implicit check) ebs ≤ 512 | +| | | | | OOB_INST = MODEXP_exponent | +| | | | | diff := 0 ∨ [ebs - 32] | +| | | | | n_ebs_bytes := 32 ∧ ebs | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 4 | MISC | MMU🏴 = extract_raw_mbs | EXP🏴 = trim_raw_mbs | OOB🏴 = extract_raw_mbs | +| | | MMU_INST = MLOAD, offset = cdo + 64 | EXP_INST = trimBytesBeyond | (implicit check) mbs ≤ 512 | +| | | | | OOB_INST = MODEXP_modulus | +| | | | | max_bbs_mbs := bbs ∨ mbs | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 5 | MISC | MMU🏴 = extract_raw_leading_word | EXP🏴 = extract_raw_leading_word | OOB🏴 = 1 | +| | | MMU_INST = MLOAD, offset = cdo + 96 | EXP_INST = exponentLeadingWordLog | cds, ebs, bbs | +| | | | | OOB_INST = MODEXP_leading | +| | | | | n_cds_bytes := 32 ∧ [0 ∨ [cds - (96 + bbs)]] | +| | | | | extract_raw_leading_word := [cds > 96 + bbs] ∧ [ebs ≠ 0] | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 6 | MISC | MMU🏴 = 0 | EXP🏴 = 0 | OOB🏴 = 1 | +| | | | | call_gas, rem_gas, log(E)_approx, max_bbs_mbs, r@c | +| | | | | OOB_INST = MODEXP_pricing | +| | | | | insufficient_gas := 1 | +| | | | | r@c_nonzero := [r@c != 0] | +|-----------+-------------+-------------------------------------+-----------------------------------+----------------------------------------------------------| +| i + 7 | CON | nonContextProvidesEmptyReturnData() | diff --git a/hub/instruction_handling/call/precompiles/generalities.tex b/hub/instruction_handling/call/precompiles/generalities.tex new file mode 100644 index 0000000..e9ec929 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/generalities.tex @@ -0,0 +1,40 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenPrecompileSum _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We list some high level generalities for the second phase of precompile processing. +\begin{description} + \item[\underline{Admissible failure scenarios:}] + we impose thath + \begin{enumerate} + \item \If $\scenPrecompileMayOnlyFailInHub _{i} = 1$ \Then $\scenPrcFailureKnownToRam _{i} = 0$ + \item \If $\scenPrecompileMayOnlyFailInRam _{i} = 1$ \Then $\scenPrcFailureKnownToHub _{i} = 0$ + \end{enumerate} + \saNote{} + In the implementation we may omit the ``$\scenPrecompileSum _{i} = 1$'' precondition when imposing the above + as this condition is weaker than any of the preconditions we provide in the preceding. + \item[\underline{Setting \gasNext{}:}] we settle the value of \gasNext{}: + \begin{enumerate} + \item $\gasNext_{i} = \locPrcCallerGas + \locPrcReturnGas$ + \item \If $\scenPrcFailure_{i} = 1$ \Then $\locPrcReturnGas = 0$. + \item \If $\scenPrcSuccess_{i} = 1$ \Then we must work on a precompile per precompile basis; + \end{enumerate} + \item[\underline{Setting \nonStackRows{}:}] + we impose + \[ \nonStackRows_{i} = \locFirstPhaseNsr + \locNsrPrecompilesSH \] +\end{description} +\saNote{} This fulfils a promise we made in +section~(\ref{hub: instruction handling: call: peeking flags and nRows no precompiles}) and more to the point in +section~(\ref{hub: instruction handling: call: peeking flags and nRows for precompiles first half}). +\begin{description} + \item[\underline{Setting the peeking flags for the second processing phase:}] + we impose + \[ \locFlagSumPrecompilesSH = \locNsrPrecompilesSH \] +\end{description} +\saNote{} +Neither of these shorthands have been defined at this point. This is done in section~(\ref{hub: instruction handling: call: precompiles: flag sums and nsr}). diff --git a/hub/instruction_handling/call/precompiles/identity/_inputs.tex b/hub/instruction_handling/call/precompiles/identity/_inputs.tex new file mode 100644 index 0000000..5fabc0c --- /dev/null +++ b/hub/instruction_handling/call/precompiles/identity/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsubsection{\inst{IDENTITY} shorthands \lispNone{}} \label{hub: instruction handling: call: precompiles: identity: shorthands} \input{instruction_handling/call/precompiles/identity/shorthands} +\subsubsubsection{\inst{IDENTITY} representation \lispNone{}} \label{hub: instruction handling: call: precompiles: identity: representation} \input{instruction_handling/call/precompiles/identity/representation} +\subsubsubsection{\inst{IDENTITY} success case \lispDone{}} \label{hub: instruction handling: call: precompiles: identity: success} \input{instruction_handling/call/precompiles/identity/success} diff --git a/hub/instruction_handling/call/precompiles/identity/lua/failure_KTH.lua.tex b/hub/instruction_handling/call/precompiles/identity/lua/failure_KTH.lua.tex new file mode 100644 index 0000000..929779e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/identity/lua/failure_KTH.lua.tex @@ -0,0 +1,69 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██████\ ███████\ ████████\ ██\ ██\ ████████\ ██████\ ████████\ ██\ ██\ + \_██ _|██ __██\ ██ _____|███\ ██ |\__██ __|\_██ _|\__██ __|\██\ ██ | + ██ | ██ | ██ |██ | ████\ ██ | ██ | ██ | ██ | \██\ ██ / + ██ | ██ | ██ |█████\ ██ ██\██ | ██ | ██ | ██ | \████ / + ██ | ██ | ██ |██ __| ██ \████ | ██ | ██ | ██ | \██ / + ██ | ██ | ██ |██ | ██ |\███ | ██ | ██ | ██ | ██ | + ██████\ ███████ |████████\ ██ | \██ | ██ | ██████\ ██ | ██ | + \______|\_______/ \________|\__| \__| \__| \______| \__| \__| + + + _| _) | | + | _` | | | | | __| _ \ | / __ \ _ \ \ \ \ / __ \ + __| ( | | | | | | __/ < | | ( | \ \ \ / | | + _| \__,_| _| _| \__,_| _| \___| _|\_\ _| _| \___/ \_/\_/ _| _| + + | | | | | __ ) + __| _ \ | | | | __ \ + | ( | ___ | | | | | + \__| \___/ _| _| \___/ ____/ + + +|-------+--------+-------------------------------------+---------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+---------------------------------------------------| +| i | SCEN | SCEN/IDENTITY | SCEN/PRC_FAILURE_KNOWN_TO_HUB ⛔ | +|-------+--------+-------------------------------------+---------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_identity⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data (here 0) | | +|-------+--------+-------------------------------------+---------------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/call/precompiles/identity/lua/success.lua.tex b/hub/instruction_handling/call/precompiles/identity/lua/success.lua.tex new file mode 100644 index 0000000..46a534b --- /dev/null +++ b/hub/instruction_handling/call/precompiles/identity/lua/success.lua.tex @@ -0,0 +1,87 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██████\ ███████\ ████████\ ██\ ██\ ████████\ ██████\ ████████\ ██\ ██\ + \_██ _|██ __██\ ██ _____|███\ ██ |\__██ __|\_██ _|\__██ __|\██\ ██ | + ██ | ██ | ██ |██ | ████\ ██ | ██ | ██ | ██ | \██\ ██ / + ██ | ██ | ██ |█████\ ██ ██\██ | ██ | ██ | ██ | \████ / + ██ | ██ | ██ |██ __| ██ \████ | ██ | ██ | ██ | \██ / + ██ | ██ | ██ |██ | ██ |\███ | ██ | ██ | ██ | ██ | + ██████\ ███████ |████████\ ██ | \██ | ██ | ██████\ ██ | ██ | + \______|\_______/ \________|\__| \__| \__| \______| \__| \__| + + + __| | | __| __| _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ + ____/ \__,_| \___| \___| \___| ____/ ____/ + + + +|-------+--------+-----------------------------+---------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-----------------------------+---------------------------------------------------| +| i | SCEN | SCEN/IDENTITY | SCEN/PRC_SUCCESS ✅ | +|-------+--------+-----------------------------+---------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_identity⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | MMU🏴 = extract_call_data | | +| | | MMU_INST = | | +| | | | | +| | | CN_S := CN | | +| | | CN_T := 1 + HUB_ | | +| | | SRC_OFF := CDO | | +| | | TGT_OFF := 0 | | +| | | SIZE := CDS | | +|-------+--------+-----------------------------+---------------------------------------------------| +| i + 2 | MISC | MMU🏴 = r@c_nonzero | OOB🏴 = 0 | +| | | . ∧ extract_call_data | | +| | | | | +| | | MMU_INST = | | +| | | | | +| | | CN_S := 1 + HUB_ | | +| | | CN_T := CN | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := R@O | | +| | | SIZE := R@C | | +| | | REF_SIZE := R@C | | +|-------+--------+-----------------------------+---------------------------------------------------| +| i + 3 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = CDS | +|-------+--------+-----------------------------| +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/call/precompiles/identity/representation.tex b/hub/instruction_handling/call/precompiles/identity/representation.tex new file mode 100644 index 0000000..bda52aa --- /dev/null +++ b/hub/instruction_handling/call/precompiles/identity/representation.tex @@ -0,0 +1,5 @@ +% \includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/identity/lua/common.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/identity/lua/failure_KTH.pdf} +% \includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/identity/lua/failure_KTR.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/identity/lua/success.pdf} + diff --git a/hub/instruction_handling/call/precompiles/identity/shorthands.tex b/hub/instruction_handling/call/precompiles/identity/shorthands.tex new file mode 100644 index 0000000..27cb743 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/identity/shorthands.tex @@ -0,0 +1 @@ +We will make use of the shorthands introduced in section~(\ref{hub: instruction handling: call: precompiles: common: shorthands}). diff --git a/hub/instruction_handling/call/precompiles/identity/success.tex b/hub/instruction_handling/call/precompiles/identity/success.tex new file mode 100644 index 0000000..ef22983 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/identity/success.tex @@ -0,0 +1,72 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenIdentity _{i} & = & 1 \\ + \scenPrcSuccess _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus (again) assuming that the present row is the first of the second phase of dealing with the +\inst{IDENTITY} precompile. +However, this time we are also assuming that $\scenPrcSuccess \equiv 1$. +\begin{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessSecondMiscRowOffset)$:}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessSecondMiscRowOffset} + = + \miscMmuWeight + \cdot + \left[ \begin{array}{cl} + \cdot & \locOobResultExtractCallData \\ + \cdot & \locOobResultNonzeroRac \\ + \end{array} \right] + \] + in other words: + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \locOobResultExtractCallData \cdot \locOobResultNonzeroRac & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} In other words the ``partial data copy'' step of a call to the \inst{IDENTITY} is only required if the call is + (\emph{a}) successful (i.e. is given sufficient gas) + (\emph{b}) provided with nonempty call data + (\emph{c}) provided with nonzero \rac{}. + Recall that the first two points are equivalent to $\locOobResultExtractCallData \equiv 1$. + \item[\underline{\mmuMod{} data:}] + \If $\miscMmuFlag_{i + \prcStandardSuccessSecondMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcStandardSuccessSecondMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = \cn_{i} , + sourceOffsetLo = 0 , + size = \locPrcCds , + referenceOffset = \locPrcRao , + referenceSize = \locPrcRac , + } + \] + \end{description} + \item[\underline{Context-row $n^°(i + \prcStandardSuccessThirdMiscRowOffset)$:}] + we impose \ + \[ + \provideReturnData { + anchorRow = i , + relOffset = \prcIdentitySuccessCallerContextRowRowOffset , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = 0 , + returnDataSize = \locPrcCds , + } + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/intro.tex b/hub/instruction_handling/call/precompiles/intro.tex new file mode 100644 index 0000000..75706b8 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/intro.tex @@ -0,0 +1,20 @@ +The present section deals with precompiles from the point of view of the \hubMod{} module. +For the purposes of the \hubMod{} ``dealing with precompiles'' means dealing with \textbf{pricing}, \textbf{control flow} and triggering certain \textsc{ram} instructions \textbf{extracting input data} and \textbf{writing output data} to the caller's \textsc{ram}. +Concretely this \emph{may} involve any the following: +\begin{enumerate} + \item extracting pricing parameters from \textsc{ram}; + \item extracting input data from \textsc{ram} to detect either malformed / wellformed call data; + \item extracting input data from \textsc{ram} to provide as input to relevant modules; + \item transferring output data (i.e. return data) from the relevant exogenous data module to a special execution context's \textsc{ram}; + \item copying the relevant section of return data from said special execution context's \textsc{ram} to the current execution context's \textsc{ram}; +\end{enumerate} +\saNote{} The first point applies only to \inst{MODEXP} and \inst{BLAKE2f} for which one must extract, respectively, +the relevant \textbf{base byte size}, \textbf{exponent byte size}, \textbf{modulus byte size} and the leading word of the exponent i.e. +$\locBase$, $\locExponent$, $\locModulus$ and $\locExponentLogEYP$ using notations from the \cite{EYP}, +the \textbf{rounds} parameter $\col{r}$ and the \textbf{final block indicator flag} $\col{f}$. + +\saNote{} +The exogenous data modules in question, i.e. \shakiraMod{}, \ecDataMod{} and \blkMdxMod{}, may perform some preliminary data vetting before serving the requests to the relevant precompile circuits. + +\saNote{} Precompile processing \textbf{does not} mean that we provide a constraint system / circuit for these operations. +This is not the perview of our arithmetization and is the responsability of a different component of the system. diff --git a/hub/instruction_handling/call/precompiles/modexp/_inputs.tex b/hub/instruction_handling/call/precompiles/modexp/_inputs.tex new file mode 100644 index 0000000..5ec9ea7 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/_inputs.tex @@ -0,0 +1,6 @@ +\input{instruction_handling/call/precompiles/modexp/_local} +\subsubsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: precompiles: modexp: introduction} \input{instruction_handling/call/precompiles/modexp/intro} +\subsubsubsection{Representation \lispNone{}} \label{hub: instruction handling: call: precompiles: modexp: representation} \input{instruction_handling/call/precompiles/modexp/representation} +\subsubsubsection{\inst{MODEXP} common processing \lispDone{}} \label{hub: instruction handling: call: precompiles: modexp: common constraints} \input{instruction_handling/call/precompiles/modexp/common} +\subsubsubsection{\inst{MODEXP} failure case \lispDone{}} \label{hub: instruction handling: call: precompiles: modexp: failure} \input{instruction_handling/call/precompiles/modexp/failure_KTR} +\subsubsubsection{\inst{MODEXP} success case \lispDone{}} \label{hub: instruction handling: call: precompiles: modexp: success} \input{instruction_handling/call/precompiles/modexp/success} diff --git a/hub/instruction_handling/call/precompiles/modexp/_local.tex b/hub/instruction_handling/call/precompiles/modexp/_local.tex new file mode 100644 index 0000000..7040161 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/_local.tex @@ -0,0 +1,18 @@ +\def\gZero{\bm{\gray{0}}} +\def\one{\red{1}} + +\def\locTransferModulusZeros {\col{trsf\_M\_zeros}} +\def\locTransferModulusTrim {\col{trsf\_M\_trim}} +\def\locTransferModulusFull {\col{trsf\_M\_full}} +\def\locMbsIsNonzero {\col{mbs\_nonzero}} +\def\locNonTrivial {\col{non\_trivial}} +\def\locTransferExponentZeros {\col{trsf\_E\_zeros}} +\def\locTransferExponentTrim {\col{trsf\_E\_trim}} +\def\locTransferExponentFull {\col{trsf\_E\_full}} +\def\locTransferBaseZeros {\col{trsf\_B\_zeros}} +\def\locTransferBaseTrim {\col{trsf\_B\_trim}} +\def\locTransferBaseFull {\col{trsf\_B\_full}} + +\def\locModexpBaseExtractionInst {\col{base\_extraction\_inst}} +\def\locModexpExponentExtractionInst {\col{exponent\_extraction\_inst}} +\def\locModexpModulusExtractionInst {\col{modulus\_extraction\_inst}} diff --git a/hub/instruction_handling/call/precompiles/modexp/common.tex b/hub/instruction_handling/call/precompiles/modexp/common.tex new file mode 100644 index 0000000..010d7bc --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/common.tex @@ -0,0 +1,419 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenModexp _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +In other words we will be specifying the common prefix for all \inst{MODEXP} handling, regardless of success or failure. +We know, see section~(\ref{hub: instruction handling: call: precompiles: modexp: representation}), that the current scenario row will be followed by a miscellaneous-row. +\begin{description} + \item[\underline{\underline{Excluding execution scenarios:}}] + we impose that $\scenPrcFailureKnownToHub_{i} = 0$ \qquad (\trash); + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpCdsMiscRowOffset)$:}}] we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpCdsMiscRowOffset} + = + \miscOobWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpCdsMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpCdsMiscRowOffset} & = & \rZero & (\trash) \\ + \miscMxpFlag _{i + \prcModexpCdsMiscRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpCdsMiscRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpCdsMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \oobMod{} values and defining shorthands:}] + we populate the \oobMod{} columns: + \[ + \setOobInstructionModexpCds { + anchorRow = i , + relOffset = \prcModexpCdsMiscRowOffset , + callDataSize = \locPrcCds , + } + \] + and define the following shorthands + \[ + \left\{ \begin{array}{lclc} + \locExtractBbs & \define & \miscOobDataCol {3} _{i + \prcModexpCdsMiscRowOffset} \\ + \locExtractEbs & \define & \miscOobDataCol {4} _{i + \prcModexpCdsMiscRowOffset} \\ + \locExtractMbs & \define & \miscOobDataCol {5} _{i + \prcModexpCdsMiscRowOffset} \\ + \end{array} \right. + \] + \end{description} +\end{description} +We refer the reader to section~(\ref{oob: precompiles: modexp: cds}) for the interpretation of these fields and the interface of the \oobInstModexpCds{} instruction. + +The following three rows serve to extract the three byte size parameters of the \inst{MODEXP} precompile. +In order of appearance they extract the following parameters: +the base byte size $\locBbs~(\equiv\locBase)$, +the exponent byte size $\locEbs~(\equiv\locExponent)$ and +the modulus byte size $\locMbs~(\equiv\locModulus)$. +These rows follow the same pattern, with the third row also computing \locMaxMbsBbs{}. +\begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpFirstXbsRowOffset)$:}}] + we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpFirstXbsRowOffset} + = + \left[ \begin{array}{crcl} + \miscMmuWeight & \cdot & \locExtractBbs \\ + \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpFirstXbsRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpFirstXbsRowOffset} & = & \locExtractBbs & (\trash) \\ + \miscMxpFlag _{i + \prcModexpFirstXbsRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpFirstXbsRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpFirstXbsRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \mmuMod{} values:}] + \If $\miscMmuFlag_{i + \prcModexpFirstXbsRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRightPaddedWordExtraction { + anchorRow = i , + relOffset = \prcModexpFirstXbsRowOffset , + sourceId = \cn_{i} , + sourceOffsetLo = 0 , + referenceOffset = \locPrcCdo , + referenceSize = \locPrcCds , + limbOne = \relevantValue , + limbTwo = \relevantValue , + } + \] + \item[\underline{Setting some \locBbs{} related shorthands:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locBbsHi & \define & \locExtractBbs \cdot \miscMmuLimbOne _{i + \prcModexpFirstXbsRowOffset} \\ + \locBbsLo & \define & \locExtractBbs \cdot \miscMmuLimbTwo _{i + \prcModexpFirstXbsRowOffset} \\ + \end{array} \right. + \] + \saNote{} This imposes vanishing conditions in case call data is empty. + \item[\underline{Setting \oobMod{} values and defining shorthands:}] + \[ + \setOobInstructionModexpXbs { + anchorRow = i , + relOffset = \prcModexpFirstXbsRowOffset , + xbsHi = \locBbsHi , + xbsLo = \locBbsLo , + ybsLo = \nothing , + computeMax = \nothing , + } + \] + \end{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpSecondXbsRowOffset)$:}}] we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpSecondXbsRowOffset} + = + \left[ \begin{array}{crcl} + \miscMmuWeight & \cdot & \locExtractEbs \\ + \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpSecondXbsRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpSecondXbsRowOffset} & = & \locExtractEbs & (\trash) \\ + \miscMxpFlag _{i + \prcModexpSecondXbsRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpSecondXbsRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpSecondXbsRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \mmuMod{} values:}] + \If $\miscMmuFlag_{i + \prcModexpSecondXbsRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRightPaddedWordExtraction { + anchorRow = i , + relOffset = \prcModexpSecondXbsRowOffset , + sourceId = \cn_{i} , + sourceOffsetLo = 32 , + referenceOffset = \locPrcCdo , + referenceSize = \locPrcCds , + limbOne = \relevantValue , + limbTwo = \relevantValue , + } + \] + \item[\underline{Setting some \locEbs{} related shorthands:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locEbsHi & \define & \locExtractEbs \cdot \miscMmuLimbOne _{i + \prcModexpSecondXbsRowOffset} \\ + \locEbsLo & \define & \locExtractEbs \cdot \miscMmuLimbTwo _{i + \prcModexpSecondXbsRowOffset} \\ + \end{array} \right. + \] + \saNote{} This imposes vanishing conditions in case call data is empty. + \item[\underline{Setting \oobMod{} values and defining shorthands:}] + \[ + \setOobInstructionModexpXbs { + anchorRow = i , + relOffset = \prcModexpSecondXbsRowOffset , + xbsHi = \locEbsHi , + xbsLo = \locEbsLo , + ybsLo = \nothing , + computeMax = \nothing , + } + \] + \end{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpThirdXbsRowOffset)$:}}] we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpThirdXbsRowOffset} + = + \left[ \begin{array}{crcl} + \miscMmuWeight & \cdot & \locExtractMbs \\ + \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpThirdXbsRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpThirdXbsRowOffset} & = & \locExtractMbs & (\trash) \\ + \miscMxpFlag _{i + \prcModexpThirdXbsRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpThirdXbsRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpThirdXbsRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \mmuMod{} values:}] + \If $\miscMmuFlag_{i + \prcModexpThirdXbsRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRightPaddedWordExtraction { + anchorRow = i , + relOffset = \prcModexpThirdXbsRowOffset , + sourceId = \cn_{i} , + sourceOffsetLo = 64 , + referenceOffset = \locPrcCdo , + referenceSize = \locPrcCds , + limbOne = \relevantValue , + limbTwo = \relevantValue , + } + \] + \item[\underline{Setting some \locMbs{} related shorthands:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locMbsHi & \define & \locExtractMbs \cdot \miscMmuLimbOne _{i + \prcModexpThirdXbsRowOffset} \\ + \locMbsLo & \define & \locExtractMbs \cdot \miscMmuLimbTwo _{i + \prcModexpThirdXbsRowOffset} \\ + \end{array} \right. + \] + \saNote{} This imposes vanishing conditions in case call data is empty. + \item[\underline{Setting \oobMod{} values and defining shorthands:}] + \[ + \setOobInstructionModexpXbs { + anchorRow = i , + relOffset = \prcModexpThirdXbsRowOffset , + xbsHi = \locMbsHi , + xbsLo = \locMbsLo , + ybsLo = \locBbsLo , + computeMax = \one , + } + \] + we further define the following shorthand + \[ + \left\{ \begin{array}{lcl} + \locMaxMbsBbs & \define & \miscOobDataCol{7} _ {i + \prcModexpThirdXbsRowOffset} \\ + \locMbsIsNonzero & \define & \miscOobDataCol{8} _ {i + \prcModexpThirdXbsRowOffset} \\ + \end{array} \right. + \] + \saNote{} By definition \locMaxMbsBbs{} computes the maximum $\max \Big \{ \locMbs, \locBbs \Big \} $. + \end{description} + \end{description} + We refer the reader to section~(\ref{oob: precompiles: modexp: xbs check and max}) for the interpretation of these fields and the interface of the \oobInstModexpXbs{} instruction. + + The three byte sizes have been extracted. + For the pricing we still require the $\lfloor\log_{2}(\cdot)\rfloor$ of the leading word of the exponent. + Extracting this log is quite challenging. + The first step is deciding \emph{whether or not} the extraction from \textsc{ram} is even required. + Indeed call data may have already run out. + This decision is deferred to the \oobMod{} module. + \begin{description} + \def\rowNum{\yellowm{5}} \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpLeadRowOffset)$:}}] we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpLeadRowOffset} + = + \left[ \begin{array}{crcl} + \miscExpWeight & \cdot & \locLoadLeadingWord \\ + \miscMmuWeight & \cdot & \locLoadLeadingWord \\ + \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpLeadRowOffset} & = & \undefinedStar \quad \locLoadLeadingWord & (\trash) \\ + \miscMmuFlag _{i + \prcModexpLeadRowOffset} & = & \undefinedStar \quad \locLoadLeadingWord & (\trash) \\ + \miscMxpFlag _{i + \prcModexpLeadRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpLeadRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpLeadRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} The shorthand \locLoadLeadingWord{} labeled with $\undefinedStar$ is defined below. + \item[\underline{Setting \oobMod{} values:}] + \[ + \setOobInstructionModexpLead { + anchorRow = i , + relOffset = \prcModexpLeadRowOffset , + bbsLo = \locBbsLo , + callDataSize = \locPrcCds , + ebsLo = \locEbsLo , + } + \] + \item[\underline{Setting some shorthands:}] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locLoadLeadingWord & \define & \locExtractBbs \cdot \miscOobDataCol{4} _{i + \prcModexpLeadRowOffset} \\ + \locCdsCutoff & \define & \locExtractBbs \cdot \miscOobDataCol{6} _{i + \prcModexpLeadRowOffset} \\ + \locEbsCutoff & \define & \locExtractBbs \cdot \miscOobDataCol{7} _{i + \prcModexpLeadRowOffset} \\ + \locEbsSubThirtyTwo & \define & \locExtractBbs \cdot \miscOobDataCol{8} _{i + \prcModexpLeadRowOffset} \\ + \end{array} \right. + \] + \item[\underline{Setting \mmuMod{} values:}] + \If $\miscMmuFlag_{i + \prcModexpLeadRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersMload { + anchorRow = i , + relOffset = \prcModexpLeadRowOffset , + sourceId = \cn_{i} , + sourceOffsetLo = \locPrcCdo + 96 + \locBbsLo , + limbOne = \relevantValue , + limbTwo = \relevantValue , + } + \] + \item[\underline{Setting some shorthands:}] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locRawLeadingWordHi & \define & \locLoadLeadingWord \cdot \miscMmuLimbOne _{i + \prcModexpLeadRowOffset} \\ + \locRawLeadingWordLo & \define & \locLoadLeadingWord \cdot \miscMmuLimbTwo _{i + \prcModexpLeadRowOffset} \\ + \end{array} \right. + \] + \saNote{} Again this imposes vanishing conditions in case the \mmuMod{} module isn't called. + \item[\underline{Setting \expMod{} values:}] + \If $\miscExpFlag_{i + \prcModexpLeadRowOffset} = 1$ \Then + \[ + \setExpInstructionParametersModexpLog {i}{\prcModexpLeadRowOffset} + \left[ \begin{array}{ll} + \utt{Raw leading word high:} & \locRawLeadingWordHi \\ + \utt{Raw leading word low:} & \locRawLeadingWordLo \\ + \utt{Call data offset cutoff:} & \locCdsCutoff \\ + \utt{Exponent byte size cutoff:} & \locEbsCutoff \\ + \end{array} \right] + % \left\{ \begin{array}{lcl} + % \miscExpInstruction _{i + \prcModexpLeadRowOffset} & = & \expInstModexpLog \vspace{2mm} \\ + % \miscExpDataCol{1} _{i + \prcModexpLeadRowOffset} & = & \locRawLeadingWordHi \\ + % \miscExpDataCol{2} _{i + \prcModexpLeadRowOffset} & = & \locRawLeadingWordLo \\ + % \miscExpDataCol{3} _{i + \prcModexpLeadRowOffset} & = & \locCdsCutoff \\ + % \miscExpDataCol{4} _{i + \prcModexpLeadRowOffset} & = & \locEbsCutoff \\ + % \miscExpDataCol{5} _{i + \prcModexpLeadRowOffset} & = & \relevantValue \\ + % \end{array} \right. + \] + \item[\underline{Setting some shorthands:}] + we define + \[ + \left\{ \begin{array}{lcl} + \locLeadingWordLog & \define & \locLoadLeadingWord \cdot \miscExpDataCol{5}_{i + \prcModexpLeadRowOffset} \\ + \locModexpExponentLog & \define & + \left[ \begin{array}{cr} + + & \locLeadingWordLog \\ + + & 8 \cdot \locEbsSubThirtyTwo \\ + \end{array} \right] \\ + \end{array} \right. + \] + \saNote{} Again this imposes vanishing conditions in case the \expMod{} module isn't called. + \end{description} + \end{description} + \saNote{} We refer the reader to + section~(\ref{exp: intro}) for the description of the \expInstModexpLog{} instruction and to + section~(\ref{exp: modexp log base 2}) for a description of the interface of this instruction and further details. + + The \zkEvm{} is, at long last, in a position to compute the gas cost of the \inst{MODEXP} call, and thereby justify + \scenPrcSuccess{} and \scenPrcFailureKnownToRam{}. + \begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpPricingRowOffset)$:}}] we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpPricingRowOffset} + = + \miscOobWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpPricingRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpPricingRowOffset} & = & \rZero & (\trash) \\ + \miscMxpFlag _{i + \prcModexpPricingRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpPricingRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpPricingRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting \oobMod{} values:}] + we impose + \[ + \setOobInstructionModexpPricing { + anchorRow = i , + relOffset = \prcModexpPricingRowOffset , + callGas = \locPrcCallGas , + returnAtCapacity = \locPrcRac , + exponentLog = \locModexpExponentLog , + maxMbsBbs = \locMaxMbsBbs , + } + \] + \item[\underline{Setting some shorthands:}] + we define + \[ + \left\{ \begin{array}{lcl} + \locRamSuccess & \define & \miscOobDataCol{4} _{i + \prcModexpPricingRowOffset} \\ + \locReturnGas & \define & \miscOobDataCol{5} _{i + \prcModexpPricingRowOffset} \\ + \locRacIsNonzero & \define & \miscOobDataCol{8} _{i + \prcModexpPricingRowOffset} \\ + \end{array} \right. + \] + \end{description} + \item[\underline{\underline{Justifying precompile success / failure scenarios:}}] + we impose + \[ + \left\{ \begin{array}{lcl} + \scenPrcSuccess _{i} & = & \locRamSuccess \\ + \locPrcReturnGas _{i} & = & \locReturnGas \\ + \end{array} \right. + \] + \end{description} + \saNote{} The above equation involving \scenPrcFailure{} and \locPrcReturnGas{} is how we justify the presence/absence of failure due to insufficient gas and the amount of returned gas. + + This marks the end of the ``common'' part of constraints. + The next two sections tackle the remaining constraints for both the + \textbf{failure} case ($\scenPrcFailureKnownToRam \equiv 1$) and the + \textbf{success} case ($\scenPrcSuccess \equiv 1$). diff --git a/hub/instruction_handling/call/precompiles/modexp/failure_KTR.tex b/hub/instruction_handling/call/precompiles/modexp/failure_KTR.tex new file mode 100644 index 0000000..ac19ab2 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/failure_KTR.tex @@ -0,0 +1,16 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/modexp/lua/failure_KTR.pdf} + +\begin{center} + \boxed{% + \text{The constraints apply whenever } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenModexp _{i} & = & 1 \\ + \scenPrcFailure _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +\begin{description} + \item[\underline{Context row $n^°(i + \prcModexpFKTRcallerContextRowOffset)$:}] we impose + \[ \nonContextProvidesEmptyReturnData {i}{\prcModexpFKTRcallerContextRowOffset} \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/modexp/intro.tex b/hub/instruction_handling/call/precompiles/modexp/intro.tex new file mode 100644 index 0000000..d6d07fa --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/intro.tex @@ -0,0 +1,43 @@ +The present section describes the processing of \inst{CALL}'s to the \inst{MODEXP} precompile. +The \inst{MODEXP} precompile is by far the most complex in terms of its \hubMod{}-processing. +The complexity stems from the fact that +\textbf{pricing} is a multi-step process requiring the extraction and complex processing of various byte size arguments from \textsc{ram} (as well as the leading word of the exponent), +\textbf{the actual computation} requires the extraction of the functional parameters (base, exponent and modulus) in distcinct interactions with \textsc{ram}. +Only then does processing start aligning with standard precompile processing. +The \zkEvm{} performs a \textbf{full copy the results} to a dedicated \textsc{ram} segment +and, potentially, a \textbf{(partial) transfer of the result} to the current context's \textsc{ram}. + +More precisely the pricing alone (which is the only dimension along which this particular precompile may fail) requires +\begin{itemize} + \item performing various comparisons of \locPrcCds{} against $0$, $32$, $64$, in order to decide which byte size parameters to extract; +\end{itemize} +This first step requires a call to the \oobMod{} module. +This allows us to decide which (byte size) parameters are to be extracted. +Byte sizes (see below) are to be extracted in all cases except for the trivial cases (when the underlying \inst{CALL} is provided with a small ``call data size'' parameter.) +The next step requires, \textbf{when appropriate}, the extraction of various byte size parameters: +\begin{itemize} + \item \textbf{extracting the base byte size}, $\locBase$; + \item \textbf{extracting the exponent byte size}, $\locExponent$; + \item \textbf{extracting the modulus byte size}, $\locModulus$; + \item \textbf{extracting the leading word of the exponent}; +\end{itemize} +The above steps are done by triggering, \textbf{when appropriate}, a ``\inst{CALLDATALOAD}''-like instruction which extracts a right zero padded \evm{} word from memory. +In order to price the instruction the next step is computing the base two logarithm of the leading word previously extracted +\begin{itemize} + \item compute $\locExponentLogEYP$; +\end{itemize} +This step is performed by the \expMod{} module. +At this point the processing is in position to compute the gas cost of the \inst{MODEXP} precompile and thus deciding whether the precompile succeeds or fails. +This step is carried out by the \oobMod{} module. + +If the precompile is provided with insufficient gas the next and final step updates the caller context's return data. +If, on the other hand, the precompile is provided with sufficient gas processing continues. +The next step is to extract \textbf{base}, \textbf{exponent} and \textbf{modulus} from \textsc{ram} and provide to the appropriate exo data module. +This, again, is done in three separate steps. +Special care must be taken to deal with the case where one of the byte size parameters is zero. +The final steps are more or less the same as for the common precompiles, perform \textbf{when appropriate}: +\begin{itemize} + \item a \textbf{full transfer} of the result to a dedicated execution context's \textsc{ram}; + \item a \textbf{partial transfer} of the result to the current excecution context's \textsc{ram}; +\end{itemize} +The first of these steps is necessary if and only if the modulus byte size is nonzero. diff --git a/hub/instruction_handling/call/precompiles/modexp/lua/common.lua.tex b/hub/instruction_handling/call/precompiles/modexp/lua/common.lua.tex new file mode 100644 index 0000000..cca1e5d --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/lua/common.lua.tex @@ -0,0 +1,191 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██\ ██\ ██████\ ███████\ ████████\ ██\ ██\ ███████\ + ███\ ███ |██ __██\ ██ __██\ ██ _____|██ | ██ |██ __██\ + ████\ ████ |██ / ██ |██ | ██ |██ | \██\ ██ |██ | ██ | ███████\ ██████\ ██████\████\ ██████\████\ ██████\ ███████\ + ██\██\██ ██ |██ | ██ |██ | ██ |█████\ \████ / ███████ | ██ _____|██ __██\ ██ _██ _██\ ██ _██ _██\ ██ __██\ ██ __██\ + ██ \███ ██ |██ | ██ |██ | ██ |██ __| ██ ██< ██ ____/ ██ / ██ / ██ |██ / ██ / ██ |██ / ██ / ██ |██ / ██ |██ | ██ | + ██ |\█ /██ |██ | ██ |██ | ██ |██ | ██ /\██\ ██ | ██ | ██ | ██ |██ | ██ | ██ |██ | ██ | ██ |██ | ██ |██ | ██ | + ██ | \_/ ██ | ██████ |███████ |████████\ ██ / ██ |██ | \███████\ \██████ |██ | ██ | ██ |██ | ██ | ██ |\██████ |██ | ██ | + \__| \__| \______/ \_______/ \________|\__| \__|\__| \_______| \______/ \__| \__| \__|\__| \__| \__| \______/ \__| \__| + + + + +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| Row | Persp. | | | | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i | SCEN | here: | | | +| | | * SCEN/MODEXP | | | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i + 1 | MISC | MMU🏴 = 0 | EXP🏴 = 0 | OOB🏴 = 1 | +| | | | | OOB_INST = ⟦OOB_INST_modexp_cds⟧ | +| | | | | | +| | | | | TRUSTED INPUTS: | +| | | | | * cds | +| | | | | | +| | | | | JUSTIFICATION FOR: | +| | | | | * extract_bbs ≡ [cds > 0] | +| | | | | * extract_ebs ≡ [cds > 32] | +| | | | | * extract_mbs ≡ [cds > 64] | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i + 2 | MISC | MMU🏴 = extract_bbs | EXP🏴 = 0 | | +| | | MMU_INST = ⟦MMU_INST_rightPaddedWordExtraction⟧ | | | +| | | | | | +| | | TRUSTED INPUTS: | | | +| | | * SRC_ID = cn | | | +| | | * SRC_OFFSET_LO = 0 | | | +| | | * REF_OFFSET = cdo | | | +| | | * REF_SIZE = cds | | | +| | | | | | +| | | JUSTIFICATION FOR: | | | +| | | * bbs_hi | | | +| | | * bbs_lo | | | +| | | | | | +| | | | | OOB🏴 = 1 | +| | | | | OOB_INST = ⟦OOB_INST_modexp_xbs⟧ | +| | | | | | +| | | | | TRUSTED INPUTS: | +| | | | | * bbs_hi | +| | | | | * bbs_lo | +| | | | | * 0 | +| | | | | * do_compute_max = 0 | +| | | | | | +| | | | | JUSTIFICATION FOR: | +| | | | | * (implicit check) bbs ≤ 512 | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i + 3 | MISC | MMU🏴 = extract_ebs | EXP🏴 = 0 | | +| | | MMU_INST = ⟦MMU_INST_rightPaddedWordExtraction⟧ | | | +| | | | | | +| | | TRUSTED INPUTS: | | | +| | | * SRC_ID = cn | | | +| | | * SRC_OFFSET_LO = 32 | | | +| | | * REF_OFFSET = cdo | | | +| | | * REF_SIZE = cds | | | +| | | | | | +| | | JUSTIFICATION FOR: | | | +| | | * ebs_hi | | | +| | | * ebs_lo | | | +| | | | | | +| | | | | OOB🏴 = 1 | +| | | | | OOB_INST = ⟦OOB_INST_modexp_xbs⟧ | +| | | | | | +| | | | | TRUSTED INPUTS: | +| | | | | * ebs_hi | +| | | | | * ebs_lo | +| | | | | * 0 | +| | | | | * do_compute_max = 0 | +| | | | | | +| | | | | JUSTIFICATION FOR: | +| | | | | * (implicit check) ebs ≤ 512 | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i + 4 | MISC | MMU🏴 = extract_mbs | EXP🏴 = 0 | | +| | | MMU_INST ≡ ⟦MMU_INST_rightPaddedWordExtraction⟧ | | | +| | | | | | +| | | TRUSTED INPUTS: | | | +| | | * SRC_ID = cn | | | +| | | * SRC_OFFSET_LO = 64 | | | +| | | * REF_OFFSET = cdo | | | +| | | * REF_SIZE = cds | | | +| | | | | | +| | | JUSTIFICATION FOR: | | | +| | | * ebs_hi | | | +| | | * ebs_lo | | | +| | | | | | +| | | | | OOB🏴 = 1 | +| | | | | OOB_INST = ⟦OOB_INST_modexp_xbs⟧ | +| | | | | | +| | | | | TRUSTED INPUTS: | +| | | | | * mbs_hi | +| | | | | * mbs_lo | +| | | | | * bbs_lo | +| | | | | * do_compute_max = 1 | +| | | | | | +| | | | | JUSTIFICATION FOR: | +| | | | | * max_bbs_mbs ≡ bbs ∨ mbs | +| | | | | * mbs_nonzero ≡ [mbs ≠ 0] | +| | | | | * (implicit check) mbs ≤ 512 | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i + 5 | MISC | | | OOB🏴 = 1 | +| | | | | OOB_INST = ⟦OOB_INST_modexp_lead⟧ | +| | | | | | +| | | | | TRUSTED INPUTS: | +| | | | | * bbs_lo | +| | | | | * cds | +| | | | | * ebs_lo | +| | | | | | +| | | | | | +| | | | | JUSTIFICATION FOR: | +| | | | | * load_lead ≡ [cds > 96 + bbs] ∧ [ebs ≠ 0] | +| | | | | * lead_calldata_bytes ≡ 32 ∧ [0 ∨ [cds - (96 + bbs)]] | +| | | | | * lead_exponent_bytes ≡ 32 ∧ ebs | +| | | | | * ebs_sub_32 ≡ 0 ∨ [ebs - 32] | +| | | | | | +| | | MMU🏴 = load_lead | | | +| | | MMU_INST = MLOAD | | | +| | | | | | +| | | TRUSTED INPUTS: | | | +| | | * SRC_ID = cn | | | +| | | * SRC_OFFSET_LO = cdo + 96 + bbs | | | +| | | | | | +| | | JUSTIFICATION FOR: | | | +| | | * raw_leading_word_of_exponent_hi | | | +| | | * raw_leading_word_of_exponent_lo | | | +| | | | | | +| | | | EXP🏴 = load_lead | | +| | | | EXP_INST = ⟦EXP_INST_modexpLog⟧ | | +| | | | | | +| | | | TRUSTED INPUTS: | | +| | | | * raw_leading_word_of_exponent_hi | | +| | | | * raw_leading_word_of_exponent_lo | | +| | | | * lead_exponent_bytes | | +| | | | * lead_calldata_bytes | | +| | | | | | +| | | | JUSTIFICATION FOR: | | +| | | | * lead_log ≡ | | +| | | | . ⌊ log_2(leading_word_of_exponent) ⌋ | | +| | | | | | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +| i + 6 | MISC | MMU🏴 = 0 | EXP🏴 = 0 | OOB🏴 = 1 | +| | | | | OOB_INST = ⟦OOB_INST_modexp_pricing⟧ | +| | | | | | +| | | | | TRUSTED INPUTS: | +| | | | | * call_gas | +| | | | | * r@c | +| | | | | * lead_log | +| | | | | * max_bbs_mbs | +| | | | | | +| | | | | JUSTIFICATION FOR: | +| | | | | * ram_success | +| | | | | * return_gas | +| | | | | * r@c_nonzero ≡ [r@c ≠ 0] | +| | | | | | +| | | | | WE IMPOSE: | +| | | | | * SCEN/SUCCESS = ram_success | +| | | | | | +| | | | | Thus | +| | | | | * ram_success = 0 (⛔ ⟵ FAILURE) | +| | | | | * ram_success = 1 (✅ ⟵ SUCCESS) | +|-------+--------+-------------------------------------------------+------------------------------------------+-------------------------------------------------------| +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/call/precompiles/modexp/lua/failure_KTR.lua.tex b/hub/instruction_handling/call/precompiles/modexp/lua/failure_KTR.lua.tex new file mode 100644 index 0000000..1e6778e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/lua/failure_KTR.lua.tex @@ -0,0 +1,49 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██\ ██\ ██████\ ███████\ ████████\ ██\ ██\ ███████\ + ███\ ███ |██ __██\ ██ __██\ ██ _____|██ | ██ |██ __██\ + ████\ ████ |██ / ██ |██ | ██ |██ | \██\ ██ |██ | ██ | + ██\██\██ ██ |██ | ██ |██ | ██ |█████\ \████ / ███████ | + ██ \███ ██ |██ | ██ |██ | ██ |██ __| ██ ██< ██ ____/ + ██ |\█ /██ |██ | ██ |██ | ██ |██ | ██ /\██\ ██ | + ██ | \_/ ██ | ██████ |███████ |████████\ ██ / ██ |██ | + \__| \__| \______/ \_______/ \________|\__| \__|\__| + + + + ████████\ ██\ ██\ ████████\ ███████\ + ██ _____|██ | ██ |\__██ __|██ __██\ + ██ | ██ |██ / ██ | ██ | ██ | + █████\ █████ / ██ | ███████ | + ██ __| ██ ██< ██ | ██ __██< + ██ | ██ |\██\ ██ | ██ | ██ | + ██ | ██ | \██\ ██ | ██ | ██ | + \__| \__| \__| \__| \__| \__| + +|-------+--------+-------------------------------------+-------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+-------------------------| +| i | SCEN | SCEN/MODEXP | FAILURE_KNOWN_TO_RAM ⛔ | +|-------+--------+-------------------------------------+-------------------------| +| | | common constraints | | +|-------+--------+-------------------------------------+-------------------------| +| i + 7 | CON | nonContextProvidesEmptyReturnData() | +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/modexp/lua/success.lua.tex b/hub/instruction_handling/call/precompiles/modexp/lua/success.lua.tex new file mode 100644 index 0000000..14cf8b3 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/lua/success.lua.tex @@ -0,0 +1,145 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + + ██\ ██\ ██████\ ███████\ ████████\ ██\ ██\ ███████\ + ███\ ███ |██ __██\ ██ __██\ ██ _____|██ | ██ |██ __██\ + ████\ ████ |██ / ██ |██ | ██ |██ | \██\ ██ |██ | ██ | + ██\██\██ ██ |██ | ██ |██ | ██ |█████\ \████ / ███████ | + ██ \███ ██ |██ | ██ |██ | ██ |██ __| ██ ██< ██ ____/ + ██ |\█ /██ |██ | ██ |██ | ██ |██ | ██ /\██\ ██ | + ██ | \_/ ██ | ██████ |███████ |████████\ ██ / ██ |██ | + \__| \__| \______/ \_______/ \________|\__| \__|\__| + + + + + + ███████\ ██\ ██\ ███████\ ███████\ ██████\ ███████\ ███████\ + ██ _____|██ | ██ |██ _____|██ _____|██ __██\ ██ _____|██ _____| + \██████\ ██ | ██ |██ / ██ / ████████ |\██████\ \██████\ + \____██\ ██ | ██ |██ | ██ | ██ ____| \____██\ \____██\ + ███████ |\██████ |\███████\ \███████\ \███████\ ███████ |███████ | + \_______/ \______/ \_______| \_______| \_______|\_______/ \_______/ + + +|--------+--------+-------------------------------------------+--------------------------------------| +| Row | Persp. | | | +|--------+--------+-------------------------------------------+--------------------------------------| +| i | SCEN | SCEN/MODEXP | SUCCESS ✅ | +|--------+--------+-------------------------------------------+--------------------------------------| +| | | common constraints | | +|--------+--------+-------------------------------------------+--------------------------------------| +|--------+--------+-------------------------------------------+--------------------------------------| +| i + 7 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_modexp_extract⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * bbs_lo | +| | | | * ebs_lo | +| | | | * mbs_lo | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * extract_base | +| | | | * extract_exponent | +| | | | * extract_modulus | +| | | | | +| | | MMU🏴 = extract_modulus | | +| | | | | +| | | If extract_base = 1: | | +| | | MMU_INST = ⟦MMU_INST_modexpData⟧ | | +| | | | | +| | | If extract_base = 0: | | +| | | MMU_INST = ⟦MMU_INST_modexpZero⟧ | | +| | | | | +| | | SRC_ID = cn | | +| | | SRC_OFFSET_LO = 96 | | +| | | SIZE = bbs_lo | | +| | | TGT_ID = 1 + HUB_ | | +| | | TGT_OFFSET_LO = 0 | | +| | | EXO_SUM = ⟦1 << modexpdata⟧ | | +| | | PHASE = Φ_base | | +|--------+--------+-------------------------------------------+--------------------------------------| +| i + 8 | MISC | MMU🏴 = extract_modulus | OOB🏴 = 0 | +| | | | | +| | | If extract_exponent = 1: | | +| | | MMU_INST = ⟦MMU_INST_modexpData⟧ | | +| | | | | +| | | If extract_exponent = 0: | | +| | | MMU_INST = ⟦MMU_INST_modexpZero⟧ | | +| | | | | +| | | SRC_ID = cn | | +| | | SRC_OFFSET_LO = 96 + bbs_lo | | +| | | SIZE = ebs_lo | | +| | | TGT_ID = 1 + HUB_ | | +| | | TGT_OFFSET_LO = 0 | | +| | | EXO_SUM = ⟦1 << modexpdata⟧ | | +| | | PHASE = Φ_exponent | | +|--------+--------+-------------------------------------------+--------------------------------------| +| i + 9 | MISC | MMU🏴 = extract_modulus | OOB🏴 = 0 | +| | | | | +| | | If extract_modulus = 1: | | +| | | MMU_INST = ⟦MMU_INST_modexpData⟧ | | +| | | | | +| | | If extract_modulus = 0: | | +| | | MMU_INST = ⟦MMU_INST_modexpZero⟧ | | +| | | | | +| | | SRC_ID = cn | | +| | | SRC_OFFSET_LO = 96 + bbs_lo + ebs_lo | | +| | | SIZE = mbs_lo | | +| | | TGT_ID = 1 + HUB_ | | +| | | TGT_OFFSET_LO = 0 | | +| | | EXO_SUM = ⟦1 << modexpdata⟧ | | +| | | PHASE = Φ_modulus | | +|--------+--------+-------------------------------------------+--------------------------------------| +| i + 10 | MISC | MMU🏴 = extract_modulus | OOB🏴 = 0 | +| | | MMU_INST = ⟦MMU_INST_exoToRamTransplants⟧ | | +| | | | | +| | | SRC_ID = 1 + HUB_ | | +| | | TGT_ID = 1 + HUB_ | | +| | | SIZE = 512 | | +| | | PHASE = Φ_modexp_res | | +| | | EXO_SUM = ⟦1 << modexpdata⟧ | | +|--------+--------+-------------------------------------------+--------------------------------------| +| i + 11 | MISC | MMU🏴 = mbs_nonzero ∧ r@c_nonzero | OOB🏴 = 0 | +| | | MMU_INST = MODEXP_copy_partial_result | | +| | | | | +| | | SRC_ID = 1 + HUB_ | | +| | | TGT_ID = CN | | +| | | | | +| | | OFFSET_1 = r@o | | +| | | SIZE_1 = r@c | | +| | | REF_OFFSET = 512 - mbs | | +| | | REF_SIZE = mbs | | +|--------+--------+-------------------------------------------+--------------------------------------| +| i + 12 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RETURN_DATA_OFFSET = 512 - mbs | +| | | RETURN_DATA_SIZE = mbs | +| | | | +| | | Note: this works ALWAYS. | +|--------+--------+-------------------------------------------| +\end{verbatim} +\end{document} +Φ_base +Φ_exponent +Φ_modulus diff --git a/hub/instruction_handling/call/precompiles/modexp/representation.tex b/hub/instruction_handling/call/precompiles/modexp/representation.tex new file mode 100644 index 0000000..031801d --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/representation.tex @@ -0,0 +1 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/modexp/lua/common.pdf} diff --git a/hub/instruction_handling/call/precompiles/modexp/success.tex b/hub/instruction_handling/call/precompiles/modexp/success.tex new file mode 100644 index 0000000..be1d4fe --- /dev/null +++ b/hub/instruction_handling/call/precompiles/modexp/success.tex @@ -0,0 +1,292 @@ +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/modexp/lua/success.pdf} + +\begin{center} + \boxed{% + \text{The constraints apply whenever } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenModexp _{i} & = & 1 \\ + \scenPrcSuccess _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +At this point the \inst{MODEXP} call is known to be successful and it remains to +(\emph{a}) potentially extract the base +(\emph{b}) potentially extract the exponent +(\emph{c}) potentially extract the modulus +(\emph{d}) potentially transfer the output of the precompile to a dedicated execution context's \textsc{ram} +(\emph{e}) potentially copy part of the ouput to the current exeuction context's \textsc{ram}. +\begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpSuccessExtractBaseRowOffset)$:}}] + the \zkEvm{} triggers the \oobMod{} instruction \oobInstModexpExtract{}; + this instruction determines whether or not to extract the base, exponent and modulus; + this information finds itself in the (as of yet undefined) shorthands + \locExtractBase{}, \locExtractExponent{} and \locExtractModulus{}; + furthermore it either extracts the base from \textsc{ram} or sets it to zero if the base byte size is zero; + + \saNote{} There is no need to extract \textbf{anything} if the modulus doesn't get extracted (i.e. $\locExtractModulus \equiv 0$). + In this case the modulus value used in the \inst{MODEXP} computation is $0$ and the result is $0$, too, or + $\utt{0x} \, + \utt{00} \, + \utt{00} \, \cdots \, + \utt{00} \in \mathbb{B}_{\locMbs}$ + to be precise + The \textbf{type} of extraction of the base being performed depends on \locExtractBase{}. + The same remarks apply to the following miscellaneous row with \locExtractExponent{}. + + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpSuccessExtractBaseRowOffset} + = + \left[ \begin{array}{crcl} + \miscMmuWeight & \cdot & \locExtractModulus \\ + \miscOobWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpSuccessExtractBaseRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpSuccessExtractBaseRowOffset} & = & \undefinedStar \quad \locExtractModulus & (\trash) \\ + \miscMxpFlag _{i + \prcModexpSuccessExtractBaseRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpSuccessExtractBaseRowOffset} & = & \one & (\trash) \\ + \miscStpFlag _{i + \prcModexpSuccessExtractBaseRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} The $\locExtractModulus$ shorthand marked with $\undefinedStar$ will be defined below. + \item[\underline{Setting the \oobMod{} instruction:}] + we impose + \[ + \setOobInstructionModexpExtract { + anchorRow = i , + relOffset = \prcModexpSuccessExtractBaseRowOffset , + callDataSize = \locPrcCds , + bbsLo = \locBbsLo , + ebsLo = \locEbsLo , + mbsLo = \locMbsLo , + } + \] + \item[\underline{Setting some shorthands:}] + we define + \[ + \left\{ \begin{array}{lcl} + \locExtractBase & \define & \miscOobDataCol{6} _{i + \prcModexpSuccessExtractBaseRowOffset} \\ + \locExtractExponent & \define & \miscOobDataCol{7} _{i + \prcModexpSuccessExtractBaseRowOffset} \\ + \locExtractModulus & \define & \miscOobDataCol{8} _{i + \prcModexpSuccessExtractBaseRowOffset} \\ + \end{array} \right. + \] + \item[\underline{Setting the \mmuMod{} instruction:}] + \If $\miscMmuFlag_{i + \prcModexpSuccessExtractBaseRowOffset} = 1$ \Then we impose + \begin{enumerate} + \item \If $\locExtractBase = 0$ \Then + \[ + \setMmuInstructionParametersModexpZero { + anchorRow = i , + relOffset = \prcModexpSuccessExtractBaseRowOffset , + targetId = 1 + \hubStamp_{i} , + phase = \phaseModexpBase , + } + \] + \item \If $\locExtractBase = 1$ \Then + \[ + \setMmuInstructionParametersModexpData { + anchorRow = i , + relOffset = \prcModexpSuccessExtractBaseRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + sourceOffsetLo = 96 , + size = \locBbsLo , + referenceOffset = \locPrcCdo , + referenceSize = \locPrcCds , + phase = \phaseModexpBase , + } + \] + \end{enumerate} + \saNote{} Some of the above constraints are independent of the value of $\locExtractBase$ and may be ``merged into one'' in the implementation. + \end{description} + \end{description} + The above thus either extracts some data from \textsc{ram} and serves it to the \modexpMod{} module as the``base'' argument or sets its ``base'' to zero. + \begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpSuccessExtractExponentRowOffset)$:}}] + we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpSuccessExtractExponentRowOffset} + = + \miscMmuWeight \cdot \locExtractModulus + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpSuccessExtractExponentRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpSuccessExtractExponentRowOffset} & = & \locExtractModulus & (\trash) \\ + \miscMxpFlag _{i + \prcModexpSuccessExtractExponentRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpSuccessExtractExponentRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcModexpSuccessExtractExponentRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the \mmuMod{} instruction:}] + \If $\miscMmuFlag_{i + \prcModexpSuccessExtractExponentRowOffset} = 1$ \Then we impose + \begin{enumerate} + \item \If $\locExtractExponent = 0$ \Then + \[ + \setMmuInstructionParametersModexpZero { + anchorRow = i , + relOffset = \prcModexpSuccessExtractExponentRowOffset , + targetId = 1 + \hubStamp_{i} , + phase = \phaseModexpExponent , + } + \] + \item \If $\locExtractExponent = 1$ \Then + \[ + \setMmuInstructionParametersModexpData { + anchorRow = i , + relOffset = \prcModexpSuccessExtractExponentRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + sourceOffsetLo = 96 + \locBbsLo , + size = \locEbsLo , + referenceOffset = \locPrcCdo , + referenceSize = \locPrcCds , + phase = \phaseModexpExponent , + } + \] + \end{enumerate} + \saNote{} Some of the above constraints are independent of the value of $\locExtractExponent$ and may be ``merged into one'' in the implementation. + \end{description} +\end{description} +The above thus either extracts some data from \textsc{ram} and serves it to the \modexpMod{} module as the``exponent'' argument or sets its ``exponent'' to zero. +\begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpSuccessExtractModulusRowOffset)$:}}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpSuccessExtractModulusRowOffset} + = + \miscMmuWeight \cdot \locExtractModulus + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpSuccessExtractModulusRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpSuccessExtractModulusRowOffset} & = & \locExtractModulus & (\trash) \\ + \miscMxpFlag _{i + \prcModexpSuccessExtractModulusRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpSuccessExtractModulusRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcModexpSuccessExtractModulusRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the \mmuMod{} instruction:}] + \If $\miscMmuFlag_{i + \prcModexpSuccessExtractModulusRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersModexpData { + anchorRow = i , + relOffset = \prcModexpSuccessExtractModulusRowOffset , + sourceId = \cn_{i} , + targetId = 1 + \hubStamp_{i} , + sourceOffsetLo = 96 + \locBbsLo + \locEbsLo , + size = \locMbsLo , + referenceOffset = \locPrcCdo , + referenceSize = \locPrcCds , + phase = \phaseModexpModulus , + } + \] + \end{description} +\end{description} +The above thus either extracts some data from \textsc{ram} and serves it to the \modexpMod{} module as the``modulus'' argument. There is no ``zeroing out the modulus'' case. +\begin{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpSuccessTransferResultRowOffset)$:}}] + we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpSuccessTransferResultRowOffset} + = + \miscMmuWeight \cdot \locExtractModulus + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpSuccessTransferResultRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpSuccessTransferResultRowOffset} & = & \locExtractModulus & (\trash) \\ + \miscMxpFlag _{i + \prcModexpSuccessTransferResultRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpSuccessTransferResultRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcModexpSuccessTransferResultRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the \mmuMod{} instruction:}] + \If $\miscMmuFlag_{i + \prcModexpSuccessTransferResultRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = \prcModexpSuccessTransferResultRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = 1 + \hubStamp_{i} , + size = 512 , + exoSum = \exoWeightBlakeModexp , + phase = \phaseModexpResult , + } + \] + \end{description} + \item[\underline{\underline{Miscellaneous row $n^°(i + \prcModexpSuccessPartialCopyOfResultsRowOffset)$:}}] + we impose + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcModexpSuccessPartialCopyOfResultsRowOffset} + = + \miscMmuWeight \cdot + \left[ \begin{array}{l} + \cdot \, \locMbsIsNonzero \\ + \cdot \, \locRacIsNonzero \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcModexpSuccessPartialCopyOfResultsRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcModexpSuccessPartialCopyOfResultsRowOffset} & = & \locMbsIsNonzero \cdot \locRacIsNonzero & (\trash) \\ + \miscMxpFlag _{i + \prcModexpSuccessPartialCopyOfResultsRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \prcModexpSuccessPartialCopyOfResultsRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcModexpSuccessPartialCopyOfResultsRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the \mmuMod{} instruction:}] + \If $\miscMmuFlag_{i + \prcModexpSuccessPartialCopyOfResultsRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcModexpSuccessPartialCopyOfResultsRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = \cn_{i} , + sourceOffsetLo = 512 - \locMbs , + size = \locMbs , + referenceOffset = \locPrcRao , + referenceSize = \locPrcRac , + } + \] + \end{description} + \item[\underline{\underline{Context row $n^°(i + \prcModexpSuccessUpdatingCallerReturnData)$:}}] + we impose that + \[ + \provideReturnData { + anchorRow = i , + relOffset = \prcModexpSuccessUpdatingCallerReturnData , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = 512 - \locMbs , + returnDataSize = \locMbs , + } + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/nsr_and_flagsum.tex b/hub/instruction_handling/call/precompiles/nsr_and_flagsum.tex new file mode 100644 index 0000000..45e7607 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/nsr_and_flagsum.tex @@ -0,0 +1,322 @@ +The purpose of this section is to define the shorthands that were used in section~(\ref{hub: instruction handling: call: precompiles: generalities}), that is: +\begin{multicols}{3} + \begin{enumerate} + \item \locFirstPhaseNsr{} + \item \locFlagSumPrecompilesSH{} + \item \locNsrPrecompilesSH{} + \end{enumerate} +\end{multicols} +\noindent We provide an explicit definition for \locFirstPhaseNsr{} first: +\[ + \locFirstPhaseNsr + \define + \left[ \begin{array}{lrcl} + + & \callPrcFailureSecondScenarioRowOffset & \cdot & \scenPrcFailure_{i} \\ + + & \callPrcSuccessWillRevertSecondScenarioRowOffset & \cdot & \scenPrcSuccessWillRevert_{i} \\ + + & \callPrcSuccessWontRevertSecondScenarioRowOffset & \cdot & \scenPrcSuccessWontRevert_{i} \\ + \end{array} \right] +\] +The definitions of \locFlagSumPrecompilesSH{} and \locNsrPrecompilesSH{} are more involved. +The are precompile specific and depend on precompile \scenPrcSuccess{} / failure as well as the type of failure i.e. +\scenPrcFailureKnownToHub{} vs. +\scenPrcFailureKnownToRam{}. +The following will be made explicit shortly: +\[ + \left\{ \begin{array}{lcr} + \locNsrPrecompilesSH & \define & + \left[ \begin{array}{rcl} + \locNsrEcrecover & \cdot & \scenEcrecover _{i} \\ + \locNsrShaTwo & \cdot & \scenShaTwo _{i} \\ + \locNsrRipemd & \cdot & \scenRipemd _{i} \\ + \locNsrIdentity & \cdot & \scenIdentity _{i} \\ + \locNsrModexp & \cdot & \scenModexp _{i} \\ + \locNsrEcadd & \cdot & \scenEcadd _{i} \\ + \locNsrEcmul & \cdot & \scenEcmul _{i} \\ + \locNsrEcpairing & \cdot & \scenEcpairing _{i} \\ + \locNsrBlake & \cdot & \scenBlake _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \locFlagSumPrecompilesSH & \define & + \left[ \begin{array}{rcl} + \locFlagSumEcrecover & \cdot & \scenEcrecover _{i} \\ + \locFlagSumShaTwo & \cdot & \scenShaTwo _{i} \\ + \locFlagSumRipemd & \cdot & \scenRipemd _{i} \\ + \locFlagSumIdentity & \cdot & \scenIdentity _{i} \\ + \locFlagSumModexp & \cdot & \scenModexp _{i} \\ + \locFlagSumEcadd & \cdot & \scenEcadd _{i} \\ + \locFlagSumEcmul & \cdot & \scenEcmul _{i} \\ + \locFlagSumEcpairing & \cdot & \scenEcpairing _{i} \\ + \locFlagSumBlake & \cdot & \scenBlake _{i} \\ + \end{array} \right] + \\ + \end{array} \right. +\] +The above is incomplete as we didn't specify the various +\locFlagSumXxx{} and \locNsrXxx{}, +where +\[ + \col{xxx} \in \locPrecompileNames \define + \left\{ \begin{array}{r} + \col{ecrecover}, + \col{sha2}, + \col{ripemd}, + \col{identity}, \\ + \col{modexp}, + \col{ecadd}, + \col{ecmul}, + \col{ecpairing}, + \col{blake} \\ + \end{array} \right\} +\] +These quantities will all be defined according to the following recipe: +\[ + \left\{ \begin{array}{lcl} + \locNsrXxx & \define & + \left[ \begin{array}{lcl} + \locNsrXxxFKTH & \cdot & \scenPrcFailureKnownToHub _{i} \\ + \locNsrXxxFKTR & \cdot & \scenPrcFailureKnownToRam _{i} \\ + \locNsrXxxSuccess & \cdot & \scenPrcSuccess _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \locFlagSumXxx & \define & + \left[ \begin{array}{lcl} + \locFlagSumXxxFKTH & \cdot & \scenPrcFailureKnownToHub _{i} \\ + \locFlagSumXxxFKTR & \cdot & \scenPrcFailureKnownToRam _{i} \\ + \locFlagSumXxxSuccess & \cdot & \scenPrcSuccess _{i} \\ + \end{array} \right] + \\ + \end{array} \right. +\] +To finish what we have set out to do we only require defining all the various +``\col{flag sums}'' and ``\col{nsr's}'' i.e. the various +\locFlagSumXxxFKTH{}, +\locFlagSumXxxFKTR{}, +\locFlagSumXxxSuccess{}, +\locNsrXxxFKTH{}, +\locNsrXxxFKTR{}, +\locNsrXxxSuccess{} +where $\col{xxx} \in \locPrecompileNames$. +This we do now. + +We settle for every precompile the relevant ``\col{flag sums}'' and ``\col{nsr's}''. +A lot of them are the same. We thus introduce some high level shorthands first +\[ + \left\{ \begin{array}{lclcr} + \locStandardFailureFlagSum & \define & + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekContext _{i + 2} \\ + \end{array} \right] & \text{and} & \locStandardFailureNsr = 3 + \vspace{2mm} \\ + \locStandardSuccessFlagSum & \define & + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} \\ + + & \peekMisc _{i + 3} \\ + + & \peekContext _{i + 4} \\ + \end{array} \right] & \text{and} & \locStandardSuccessNsr = 5 \\ + \end{array} \right. +\] +We now tackle the case of interest: +\begin{description} + \item[\inst{ECRECOVER}:] the \inst{ECRECOVER} precompile requires special care: + \[ + \left\{ \begin{array}{lcl} + \locFlagSumEcrecoverFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcrecoverFKTR & \equiv & \leftUndefined \\ + \locFlagSumEcrecoverSuccess & \define & \locStandardSuccessFlagSum \\ + % \left[ \begin{array}{rcl} + % (1 - \locMmuRecoverSuccess) & \cdot & \locStandardFailureFlagSum \\ + % \locMmuRecoverSuccess & \cdot & \locStandardSuccessFlagSum \\ + % \end{array} \right] \vspace{2mm} \\ + \locNsrEcrecoverFKTH & \define & \locStandardFailureNsr \\ + \locNsrEcrecoverFKTR & \equiv & \leftUndefined \\ + \locNsrEcrecoverSuccess & \define & \locStandardSuccessNsr \\ + % \left[ \begin{array}{rcl} + % (1 - \locMmuRecoverSuccess) & \cdot & \locStandardFailureNsr \\ + % \locMmuRecoverSuccess & \cdot & \locStandardSuccessNsr \\ + % \end{array} \right] \\ + \end{array} \right. + \] +\end{description} +\saNote{} There are actually two fundamentally distinct ``success'' scenarios for \inst{ECRECOVER}. +Recall that ``success'' (i.e. $\scenPrcSuccess \equiv 1$) for \inst{ECRECOVER} simply means that the precompile is provided with sufficient gas. +A successfull call to the \inst{ECRECOVER} precompile may yet lead to two very distinct scenarios: +\begin{itemize} + \item $\locMmuRecoverSuccess \equiv 0$ i.e. \textbf{address recovery fails} and $\textbf{o} = ()$; + \item $\locMmuRecoverSuccess \equiv 1$ i.e. \textbf{address recovery succeeds} and $\textbf{o} \in \mathbb{B}_{32}$; +\end{itemize} +In the first case we \emph{could} get away with fewer rows. +Indeed, the output of the precompile is known to be empty and we \emph{could} skip the two miscellaneous-rows that are responsible for +(\emph{a}) fully moving the return data from a \ecDataMod{} module to a fictitious execution context's \textsc{ram} +(\emph{b}) doing a (partial) copy of the (freshly transferred) return data to the part of memory in the current execution context made available by the underlying \inst{CALL}-type instruction for that purpose. +We have chosen \textbf{not} to go for this optimization as it would complexify the computation of \nonStackRows{}. +The above definitions for flag sums and \col{nsr}'s are therefore somewhat wasteful. +\begin{description} + \item[\inst{SHA2-256}:] we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locFlagSumShaTwoFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumShaTwoFKTR & \equiv & \leftUndefined \\ + \locFlagSumShaTwoSuccess & \define & \locStandardSuccessFlagSum \vspace{2mm} \\ + \locNsrShaTwoFKTH & \define & \locStandardFailureNsr \\ + \locNsrShaTwoFKTR & \equiv & \leftUndefined \\ + \locNsrShaTwoSuccess & \define & \locStandardSuccessNsr \\ + \end{array} \right. + \] + \item[\inst{RIPEMD}:] we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locFlagSumRipemdFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumRipemdFKTR & \equiv & \leftUndefined \\ + \locFlagSumRipemdSuccess & \define & \locStandardSuccessFlagSum \vspace{2mm} \\ + \locNsrRipemdFKTH & \define & \locStandardFailureNsr \\ + \locNsrRipemdFKTR & \equiv & \leftUndefined \\ + \locNsrRipemdSuccess & \define & \locStandardSuccessNsr \\ + \end{array} \right. + \] + \item[\inst{IDENTITY}:] the \inst{IDENTITY} precompile requires special care: + \[ + \left\{ \begin{array}{lcl} + \locFlagSumIdentityFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumIdentityFKTR & \equiv & \leftUndefined \\ + \locFlagSumIdentitySuccess & \define & + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} \\ + + & \peekContext _{i + 3} \\ + \end{array} \right] \vspace{2mm} \\ + \locNsrIdentityFKTH & \define & \locStandardFailureNsr \\ + \locNsrIdentityFKTR & \equiv & \leftUndefined \\ + \locNsrIdentitySuccess & \define & 4 \\ + \end{array} \right. + \] +\end{description} +\saNote{} +Several precompiles (elliptic curve precompiles \inst{ECRECOVER}, \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING} +and some hashing precompiles \inst{SHA2-256} and \inst{RIPEMD-160}) +are dealt with as follows: +\begin{enumerate} + \item copying call data to the relevant exogenous data module; + \item copying (if appropriate) the full return data from said exo data module to a dedicated execution context's \textsc{ram}; + \item (potentially) transferring parts of that return data to the current execution context's \textsc{ram}; +\end{enumerate} +The above chain of events requires up to \textbf{three} accesses to \textsc{ram} and as such \textbf{three} individual miscellaneous rows. +The \inst{IDENTITY} precompile, on the other hand, happens in \textbf{two stages}: +\begin{enumerate} + \item copying call data to a dedicated execution context's \textsc{ram} where it will serve as source of return data; + \item (potentially) transferring parts of that call data to the current execution context's \textsc{ram}; +\end{enumerate} +In order to achieve the above \textbf{two} miscellaneous-rows are sufficient. +The above explains the special value attributed to \locFlagSumIdentitySuccess{} compared to other similar flag sums. +\begin{description} + \item[\inst{MODEXP}:] the \inst{MODEXP} precompile requires special care: + \[ + \left\{ \begin{array}{lcl} + \locFlagSumModexpFKTH & \equiv & \leftUndefined \\ + \locFlagSumModexpFKTR & \define & + \left[ \begin{array}{cr} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} + + \peekMisc _{i + 3} + + \peekMisc _{i + 4} \\ + + & \peekMisc _{i + 5} \\ + + & \peekMisc _{i + 6} \\ + + & \peekContext _{i + 7} \\ + \end{array} \right] \\ + \locFlagSumModexpSuccess & \define & + \left[ \begin{array}{cr} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} + + \peekMisc _{i + 3} + + \peekMisc _{i + 4} \\ + + & \peekMisc _{i + 5} \\ + + & \peekMisc _{i + 6} \\ + + & \peekMisc _{i + 7} + + \peekMisc _{i + 8} + + \peekMisc _{i + 9} \\ + + & \peekMisc _{i + 10} \\ + + & \peekMisc _{i + 11} \\ + + & \peekContext _{i + 12} \\ + \end{array} \right] \\ + \locNsrModexpFKTH & \equiv & \leftUndefined \\ + \locNsrModexpFKTR & \define & 8 \\ + \locNsrModexpSuccess & \define & 13 \\ + \end{array} \right. + \] + In the above we have regrouped "like-minded" miscellaneous rows. + The first batch corresponds to the extraction of + $\locBase$, + $\locExponent$ + and $\locModulus$ (i.e. in the notations of the \oobMod{} module, + \locBbs{}, + \locEbs{} + and \locMbs{}.) + \item[\inst{ECADD}:] + \[ + \left\{ \begin{array}{lcl} + \locFlagSumEcaddFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcaddFKTR & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcaddSuccess & \define & \locStandardSuccessFlagSum \\ + \locNsrEcaddFKTH & \define & \locStandardFailureNsr \\ + \locNsrEcaddFKTR & \define & \locStandardFailureNsr \\ + \locNsrEcaddSuccess & \define & \locStandardSuccessNsr \\ + \end{array} \right. + \] + \item[\inst{ECMUL}:] + \[ + \left\{ \begin{array}{lcl} + \locFlagSumEcmulFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcmulFKTR & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcmulSuccess & \define & \locStandardSuccessFlagSum \\ + \locNsrEcmulFKTH & \define & \locStandardFailureNsr \\ + \locNsrEcmulFKTR & \define & \locStandardFailureNsr \\ + \locNsrEcmulSuccess & \define & \locStandardSuccessNsr \\ + \end{array} \right. + \] + \item[\inst{ECPAIRING}:] + \[ + \left\{ \begin{array}{lcl} + \locFlagSumEcpairingFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcpairingFKTR & \define & \locStandardFailureFlagSum \\ + \locFlagSumEcpairingSuccess & \define & \locStandardSuccessFlagSum \\ + \locNsrEcpairingFKTH & \define & \locStandardFailureNsr \\ + \locNsrEcpairingFKTR & \define & \locStandardFailureNsr \\ + \locNsrEcpairingSuccess & \define & \locStandardSuccessNsr \\ + \end{array} \right. + \] + \item[\inst{BLAKE2f}:] the \inst{BLAKE2f} precompile requires special care: + \[ + \left\{ \begin{array}{lcl} + \locFlagSumBlakeFKTH & \define & \locStandardFailureFlagSum \\ + \locFlagSumBlakeFKTR & \define & + \left[ \begin{array}{cr} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} \\ + + & \peekContext _{i + 3} \\ + \end{array} \right] \\ + \locFlagSumBlakeSuccess & \define & + \left[ \begin{array}{cr} + + & \peekScenario _{i } \\ + + & \peekMisc _{i + 1} \\ + + & \peekMisc _{i + 2} \\ + + & \peekMisc _{i + 3} \\ + + & \peekMisc _{i + 4} \\ + + & \peekContext _{i + 5} \\ + \end{array} \right] \\ + \locNsrBlakeFKTH & \define & \locStandardFailureNsr \\ + \locNsrBlakeFKTR & \define & 4 \\ + \locNsrBlakeSuccess & \define & 6 \\ + \end{array} \right. + \] +\end{description} +\saNote{} +\textbf{In all cases the first row after the scenario row $i$ is a miscellaneous-row.} +In fact there are either (depending on the precompile and the scenario) +1, 2, 3, 4, 6 or 11 consecutive miscellaneous-rows following the initial precompile scenario-row. diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/_inputs.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/_inputs.tex new file mode 100644 index 0000000..75a736e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/_inputs.tex @@ -0,0 +1,4 @@ +\input{instruction_handling/call/precompiles/sha2_ripemd/_local} +\subsubsubsection{\inst{SHA2-256} and \inst{RIPEMD-160} shorthands \lispNone{}} \label{hub: instruction handling: call: precompiles: sha2 and ripe: shorthands} \input{instruction_handling/call/precompiles/sha2_ripemd/shorthands} +\subsubsubsection{\inst{SHA2-256} and \inst{RIPEMD-160} representation \lispNone{}} \label{hub: instruction handling: call: precompiles: sha2 and ripe: representation} \input{instruction_handling/call/precompiles/sha2_ripemd/representation} +\subsubsubsection{\inst{SHA2-256} and \inst{RIPEMD-160} success case \lispDone{}} \label{hub: instruction handling: call: precompiles: sha2 and ripe: success} \input{instruction_handling/call/precompiles/sha2_ripemd/success} diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/_local.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/_local.tex new file mode 100644 index 0000000..b58ac8d --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/_local.tex @@ -0,0 +1,4 @@ +\def\locShaTwoRipemdResultTransferMmuInst {\col{mmu\_inst\_result\_transfer\_sha2\_ripemd}} +\def\locShaTwoRipemdResultPhase {\col{phase\_result}} +\def\locEmptyHashHi {\col{relevant\_empty\_hash\_hi}} +\def\locEmptyHashLo {\col{relevant\_empty\_hash\_lo}} diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/lua/failure_KTH.lua.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/lua/failure_KTH.lua.tex new file mode 100644 index 0000000..e514dac --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/lua/failure_KTH.lua.tex @@ -0,0 +1,91 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██████\ ██\ ██\ ██████\ ██████\ ██████\ ███████\ ██████\ + ██ __██\ ██ | ██ |██ __██\ ██ __██\ ██ __██\ ██ ____| ██ __██\ + ██ / \__|██ | ██ |██ / ██ |\__/ ██ | \__/ ██ |██ | ██ / \__| + \██████\ ████████ |████████ | ██████ | ██████\ ██████ |███████\ ███████\ + \____██\ ██ __██ |██ __██ |██ ____/ \______| ██ ____/ \_____██\ ██ __██\ + ██\ ██ |██ | ██ |██ | ██ |██ | ██ | ██\ ██ |██ / ██ | + \██████ |██ | ██ |██ | ██ |████████\ ████████\ \██████ | ██████ | + \______/ \__| \__|\__| \__|\________| \________| \______/ \______/ + + + ██\ + ██ | + ██████\ ███████\ ███████ | + \____██\ ██ __██\ ██ __██ | + ███████ |██ | ██ |██ / ██ | + ██ __██ |██ | ██ |██ | ██ | + \███████ |██ | ██ |\███████ | + \_______|\__| \__| \_______| + + + ███████\ ██████\ ███████\ ████████\ ██\ ██\ ███████\ ██\ ██████\ ██████\ + ██ __██\ \_██ _|██ __██\ ██ _____|███\ ███ |██ __██\ ████ | ██ __██\ ███ __██\ + ██ | ██ | ██ | ██ | ██ |██ | ████\ ████ |██ | ██ | \_██ | ██ / \__|████\ ██ | + ███████ | ██ | ███████ |█████\ ██\██\██ ██ |██ | ██ | ██████\ ██ | ███████\ ██\██\██ | + ██ __██< ██ | ██ ____/ ██ __| ██ \███ ██ |██ | ██ | \______| ██ | ██ __██\ ██ \████ | + ██ | ██ | ██ | ██ | ██ | ██ |\█ /██ |██ | ██ | ██ | ██ / ██ |██ |\███ | + ██ | ██ |██████\ ██ | ████████\ ██ | \_/ ██ |███████ | ██████\ ██████ |\██████ / + \__| \__|\______|\__| \________|\__| \__|\_______/ \______|\______/ \______/ + + + _| _) | | + | _` | | | | | __| _ \ | / __ \ _ \ \ \ \ / __ \ + __| ( | | | | | | __/ < | | ( | \ \ \ / | | + _| \__,_| _| _| \__,_| _| \___| _|\_\ _| _| \___/ \_/\_/ _| _| + + | | | | | __ ) + __| _ \ | | | | __ \ + | ( | ___ | | | | | + \__| \___/ _| _| \___/ ____/ + + + +|-------+--------+-------------------------------------+--------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------+--------------------------------------------------------| +| i | SCEN | one of: | SCEN/PRC_FKTH ⛔ | +| | | * SCEN/SHA2-256 = 1 | | +| | | * SCEN/RIPEMD-160 = 1 | | +|-------+--------+-------------------------------------+--------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_SHA2-256⟧ / ⟦OOB_INST_RIPEMD-160⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * call_gas | +| | | | * cds | +| | | | * r@c | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | | here: hub_success ≡ 0 | +| | | MMU🏴 = extract_cd (= 0) | | +|-------+--------+-------------------------------------+--------------------------------------------------------| +| i + 2 | CON | nonContextProvidesEmptyReturnData() | +|-------+--------+-------------------------------------| +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/lua/success.lua.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/lua/success.lua.tex new file mode 100644 index 0000000..fa7ad9d --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/lua/success.lua.tex @@ -0,0 +1,146 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██████\ ██\ ██\ ██████\ ██████\ ██████\ ███████\ ██████\ + ██ __██\ ██ | ██ |██ __██\ ██ __██\ ██ __██\ ██ ____| ██ __██\ + ██ / \__|██ | ██ |██ / ██ |\__/ ██ | \__/ ██ |██ | ██ / \__| + \██████\ ████████ |████████ | ██████ | ██████\ ██████ |███████\ ███████\ + \____██\ ██ __██ |██ __██ |██ ____/ \______| ██ ____/ \_____██\ ██ __██\ + ██\ ██ |██ | ██ |██ | ██ |██ | ██ | ██\ ██ |██ / ██ | + \██████ |██ | ██ |██ | ██ |████████\ ████████\ \██████ | ██████ | + \______/ \__| \__|\__| \__|\________| \________| \______/ \______/ + + + ██\ + ██ | + ██████\ ███████\ ███████ | + \____██\ ██ __██\ ██ __██ | + ███████ |██ | ██ |██ / ██ | + ██ __██ |██ | ██ |██ | ██ | + \███████ |██ | ██ |\███████ | + \_______|\__| \__| \_______| + + + ███████\ ██████\ ███████\ ████████\ ██\ ██\ ███████\ ██\ ██████\ ██████\ + ██ __██\ \_██ _|██ __██\ ██ _____|███\ ███ |██ __██\ ████ | ██ __██\ ███ __██\ + ██ | ██ | ██ | ██ | ██ |██ | ████\ ████ |██ | ██ | \_██ | ██ / \__|████\ ██ | + ███████ | ██ | ███████ |█████\ ██\██\██ ██ |██ | ██ | ██████\ ██ | ███████\ ██\██\██ | + ██ __██< ██ | ██ ____/ ██ __| ██ \███ ██ |██ | ██ | \______| ██ | ██ __██\ ██ \████ | + ██ | ██ | ██ | ██ | ██ | ██ |\█ /██ |██ | ██ | ██ | ██ / ██ |██ |\███ | + ██ | ██ |██████\ ██ | ████████\ ██ | \_/ ██ |███████ | ██████\ ██████ |\██████ / + \__| \__|\______|\__| \________|\__| \__|\_______/ \______|\______/ \______/ + + + __| | | __| __| _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ + ____/ \__,_| \___| \___| \___| ____/ ____/ + + + +|-------+--------+-------------------------------------------------------+--------------------------------------------------------| +| Row | Persp. | | | +|-------+--------+-------------------------------------------------------+--------------------------------------------------------| +| i | SCEN | one of: | SCEN/PRC_SUCCESS ✅ | +| | | * SCEN/SHA2-256 = 1 | | +| | | * SCEN/RIPEMD-160 = 1 | | +|-------+--------+-------------------------------------------------------+--------------------------------------------------------| +| i + 1 | MISC | | OOB🏴 = 1 | +| | | | OOB_INST = ⟦OOB_INST_SHA2-256⟧ / ⟦OOB_INST_RIPEMD-160⟧ | +| | | | | +| | | | TRUSTED INPUTS: | +| | | | * cds | +| | | | * r@c | +| | | | * call_gas | +| | | | | +| | | | JUSTIFICATION FOR: | +| | | | * (implicit) compute gas_cost | +| | | | * hub_success := [gas_cost ≤ call_gas] | +| | | | * return_gas := 0 ∨ [call_gas - gas_cost] | +| | | | * extract_call_data := hub_success ∧ [cds ≠ 0] | +| | | | * empty_call_data := hub_success ∧ [cds = 0] | +| | | | * r@c_nonzero := [r@c ≠ 0] | +| | | | | +| | | | here: hub_success ≡ 1 | +| | | | | +| | | MMU🏴 = extract_call_data | | +| | | MMU_INST = MMU_INST_dataTransferRamToExoSansPadding | | +| | | | | +| | | ID_SRC := cn | | +| | | SRC_OFF := cdo | | +| | | SIZE := cds | | +| | | | | +| | | ID_TGT := 1 + HUB_ | | +| | | TGT_OFF := 0 | | +| | | EXO_SUM := ⟦1 << ripsha⟧ | | +| | | PHASE := ⟦Φ_sha2_data⟧ or ⟦Φ_ripemd_data⟧ | | +|-------+--------+-------------------------------------------------------+--------------------------------------------------------| +| i + 2 | MISC | MMU🏴 = 1 | OOB🏴 = 0 | +| | | | | +| | | Case: empty_call_data = 1: | | +| | | ========================== | | +| | | | | +| | | MMU_INST = ⟦MMU_INST_mstore⟧ | | +| | | | | +| | | LIMB_1 / LIMB_2 := HASH(( ))_hi / lo (see below) | | +| | | ID_TGT := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +| | | | | +| | | Case: extract_call_data = 1: | | +| | | ============================ | | +| | | | | +| | | MMU_INST = ⟦MMU_INST_alignedExoToRamLimbTransplants⟧ | | +| | | | | +| | | ID_SRC := 1 + HUB_ | | +| | | ID_TGT := 1 + HUB_ | | +| | | SRC_OFF := 0 | | +| | | TGT_OFF := 0 | | +| | | EXO_SUM := exo_sum (see below) | | +| | | PHASE := ⟦Φ_sha2_res⟧ or ⟦Φ_ripemd_res⟧ | | +|-------+--------+-------------------------------------------------------+--------------------------------------------------------| +| i + 3 | MISC | MMU🏴 = r@c_nonzero | OOB🏴 = 0 | +| | | MMU_INST = | | +| | | | | +| | | CN_S := 1 + HUB_ | | +| | | REF_OFF := 0 | | +| | | REF_SIZE := 32 | | +| | | CN_T := cn | | +| | | TGT_OFF := r@o | | +| | | SIZE := r@c | | +|-------+--------+-------------------------------------------------------+--------------------------------------------------------| +| i + 4 | CON | updateReturnData() | +| | | | +| | | RETURNER = 1 + HUB_ | +| | | RDO = 0 | +| | | RDS = 32 | +|-------+--------+-------------------------------------------------------| + +We use the folowing shorthands: + +CASE SCEN/SHA2-256: +=================== +exo_sum = 1 << sha2 +HASH(( )) = 0x e3b0c44298fc1c149afbf4c8996fb924 27ae41e4649b934ca495991b7852b855 + +CASE SCEN/RIPEMD-160: +===================== +exo_sum = 1 << ripemd +HASH(( )) = 0x 0000000000000000000000009c1185a5 c5e9fc54612808977ee8f548b2258d31 +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/representation.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/representation.tex new file mode 100644 index 0000000..2ad2499 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/representation.tex @@ -0,0 +1,4 @@ +% \includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/sha2_ripemd/lua/common.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/sha2_ripemd/lua/failure_KTH.pdf} +% \includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/sha2_ripemd/lua/failure_KTR.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/call/precompiles/sha2_ripemd/lua/success.pdf} diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/shorthands.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/shorthands.tex new file mode 100644 index 0000000..27cb743 --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/shorthands.tex @@ -0,0 +1 @@ +We will make use of the shorthands introduced in section~(\ref{hub: instruction handling: call: precompiles: common: shorthands}). diff --git a/hub/instruction_handling/call/precompiles/sha2_ripemd/success.tex b/hub/instruction_handling/call/precompiles/sha2_ripemd/success.tex new file mode 100644 index 0000000..bbd4fcc --- /dev/null +++ b/hub/instruction_handling/call/precompiles/sha2_ripemd/success.tex @@ -0,0 +1,170 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume that } + \left\{ \begin{array}{lcl} + \peekScenario_{i} & = & 1 \\ + \left[ \begin{array}{cr} + + & \scenShaTwo _{i} \\ + + & \scenRipemd _{i} \\ + \end{array} \right] & = & 1 \\ + \scenPrcSuccess_{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We are thus (again) assuming that the present row is the first of the second phase of dealing with the +\inst{SHA2-256} and +\inst{RIPEMD-160} precompiles. +However, this time we are also assuming that $\scenPrcSuccess \equiv 1$. +\begin{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessSecondMiscRowOffset)$:}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessSecondMiscRowOffset} + = + \miscMmuWeight + \] + in other words: + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \one & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessSecondMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{\mmuMod{} data:}] + for simplicity we distinguish the empty call data case from the nonempty call data case: + \begin{description} + \item[\underline{The empty call data case:}] + \If $\locOobResultEmptyCallData{} = 1$ \Then we impose + \[ + \setMmuInstructionParametersMstore { + anchorRow = i , + relOffset = \prcStandardSuccessSecondMiscRowOffset , + targetId = 1 + \hubStamp_{i} , + targetOffsetLo = 0 , + limbOne = \locEmptyHashHi , + limbTwo = \locEmptyHashLo , + } + \] + where we have set + \[ + \left\{ \begin{array}{lcl} + \locEmptyHashHi & \define & + \left[ \begin{array}{rcl} + \scenShaTwo_{i} & \cdot & \emptyShaTwoHi \\ + \scenRipemd_{i} & \cdot & \emptyRipemdHi \\ + \end{array} \right] \\ + \locEmptyHashLo & \define & + \left[ \begin{array}{rcl} + \scenShaTwo_{i} & \cdot & \emptyShaTwoLo \\ + \scenRipemd_{i} & \cdot & \emptyRipemdLo \\ + \end{array} \right] \\ + \end{array} \right. + \] + where we set + \[ + \left\{ \begin{array}{lcl} + \emptyShaTwoHi & \define & \texttt{0x\,e3b0c44298fc1c149afbf4c8996fb924} \\ + \emptyShaTwoLo & \define & \texttt{0x\,27ae41e4649b934ca495991b7852b855} \vspace{2mm} \\ + \emptyRipemdHi & \define & \texttt{0x\,0000000000000000000000009c1185a5} \\ + \emptyRipemdLo & \define & \texttt{0x\,c5e9fc54612808977ee8f548b2258d31} \\ + \end{array} \right. \\ + \] + \saNote{} The reader will recognize the high and low parts of + the \inst{SHA2-256} hash of the empty string and + % e3b0c44298fc1c149afbf4c8996fb924 27ae41e4649b934ca495991b7852b855 + the \inst{RIPEMD-160} hash of the empty string respectively. + % 0000000000000000000000009c1185a5 c5e9fc54612808977ee8f548b2258d31 + \item[\underline{The nonempty call data case:}] + \If $\locOobResultExtractCallData{} = 1$ \Then we impose + \[ + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = \prcStandardSuccessSecondMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = 1 + \hubStamp_{i} , + size = \evmWordSize , + exoSum = \exoWeightRipSha , + phase = \locShaTwoRipemdResultPhase , + } + \] + where + \[ + \locShaTwoRipemdResultPhase \define + \left[ \begin{array}{crcl} + + & \phaseShaTwoResult & \cdot & \scenShaTwo _{i} \\ + + & \phaseRipemdResult & \cdot & \scenRipemd _{i} \\ + \end{array} \right] + \] + \end{description} + \end{description} + \item[\underline{Miscellaneous-row $n^°(i + \prcStandardSuccessThirdMiscRowOffset)$:}] + \begin{description} + \item[\underline{Setting lookup flags:}] + we impose + \[ + \weightedMiscFlagSum + {i}{\prcStandardSuccessThirdMiscRowOffset} + = + \miscMmuWeight \cdot \locOobResultNonzeroRac + \] + in other words: + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locOobResultNonzeroRac & (\trash) \\ + \miscMxpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscOobFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{\mmuMod{} data:}] + \If $\miscMmuFlag_{i + \prcStandardSuccessThirdMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \prcStandardSuccessThirdMiscRowOffset , + sourceId = 1 + \hubStamp_{i} , + targetId = \cn_{i} , + sourceOffsetLo = 0 , + size = \evmWordSize , + referenceOffset = \locPrcRao , + referenceSize = \locPrcRac , + } + % \left\{ \begin{array}{lcl} + % \miscMmuInst _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \mmuInstRamToRamSansPadding \\ + % \miscMmuSrcId _{i + \prcStandardSuccessThirdMiscRowOffset} & = & 1 + \hubStamp_{i} \\ + % \miscMmuTgtId _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \cn_{i} \\ + % \miscMmuAuxId _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuSrcOffsetHi _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuSrcOffsetLo _{i + \prcStandardSuccessThirdMiscRowOffset} & = & 0 \\ + % \miscMmuTgtOffsetLo _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuSize _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \evmWordSize \\ + % \miscMmuRefOffset _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locPrcRao \\ + % \miscMmuRefSize _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \locPrcRac \\ + % \miscMmuSuccessBit _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbOne _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuLimbTwo _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuExoSum _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \miscMmuPhase _{i + \prcStandardSuccessThirdMiscRowOffset} & = & \nothing \\ + % \end{array} \right. + \] + \end{description} + \item[\underline{Context-row $n^°(i + \prcStandardSuccessCallerContextRowRowOffset)$:}] + we impose \ + \[ + \provideReturnData { + anchorRow = i , + relOffset = \prcStandardSuccessCallerContextRowRowOffset , + returnDataReceiver = \cn_{i} , + returnDataProvider = 1 + \hubStamp_{i} , + returnDataOffset = 0 , + returnDataSize = \evmWordSize , + } + \] +\end{description} diff --git a/hub/instruction_handling/call/precompiles/shorthands.tex b/hub/instruction_handling/call/precompiles/shorthands.tex new file mode 100644 index 0000000..b61f58e --- /dev/null +++ b/hub/instruction_handling/call/precompiles/shorthands.tex @@ -0,0 +1,31 @@ +The present section introduces some shorthands relevant to the second phase of the arithmetization of \inst{CALL}-type instructions targeting a precompiled contract. +The justification for these notations is +section~(\ref{hub: instruction handling: call: specialized: specialized precompile scenario row}) and +section~(\ref{hub: instruction handling: call: finishing: cases: prc}). +\[ + \left\{ \begin{array}{lclr} + \locPrcCallerGas & \define & \scenPrcCurrentlyValidCallerGas _{i} \\ + \locPrcCallGas & \define & \scenPrcGasAllowance _{i} \\ + \locPrcReturnGas & \define & \scenPrcGasOwedToCaller _{i} & \prediction \\ + \locPrcCdo & \define & \scenPrcCdo _{i} \\ + \locPrcCds & \define & \scenPrcCds _{i} \\ + \locPrcRao & \define & \scenPrcRao _{i} \\ + \locPrcRac & \define & \scenPrcRac _{i} \\ + \end{array} \right. +\] +\saNote{} +We preface some shorthands with the prefix \col{dup\_} to remind the reader that these are values that were \col{duplicated} in the scenario-row $i$ from previous values extracted from the stack (or elsewhere.) +We preface other shorthands with the prefix \col{prd\_} to let the reader know that these are \col{predicted} values. +We also remind the reader that \locPrcReturnGas{} is meant to contain +\[ + \locPrcReturnGas \equiv + \begin{cases} + \text{precompile failure:} & 0 \\ + \text{precompile success:} & \locPrcCallGas - \col{prc\_gas\_cost} \\ + \end{cases} +\] +The precise meaning of ``precompile failure'' and ``precompile success'' is that of +section~(\ref{hub: instruction handling: call: precompiles: failures vs. successes}) and +section~(\ref{hub: instruction handling: call: precompiles: failure classification}). +Also computing determining failure conditions for precompiles (which in particular involves, but is generally not limited to, computing \col{prc\_gas\_cost} and comparing it to \locPrcCallGas{}) is complex, as is determining the associated cost. +Realizing the above requires some preparation. diff --git a/hub/instruction_handling/call/shorthands.tex b/hub/instruction_handling/call/shorthands.tex new file mode 100644 index 0000000..fa170a7 --- /dev/null +++ b/hub/instruction_handling/call/shorthands.tex @@ -0,0 +1,68 @@ +We shall use the following shorthands +\[ + \hspace*{-2.7cm} + \left\{ \begin{array}{lcl} + \locIsCall & \define & \decFlag {1} _{i - \callFirstStackRowOffset} \\ + \locIsCallcode & \define & \decFlag {2} _{i - \callFirstStackRowOffset} \\ + \locIsDelegatecall & \define & \decFlag {3} _{i - \callFirstStackRowOffset} \\ + \locIsStaticcall & \define & \decFlag {4} _{i - \callFirstStackRowOffset} \\ + \locStaticx & \define & \stackStaticx _{i - \callFirstStackRowOffset} \\ + \locMxpx & \define & \stackMxpx _{i - \callFirstStackRowOffset} \\ + \locOogx & \define & \stackOogx _{i - \callFirstStackRowOffset} \\ + \locInst & \define & \stackInst _{i - \callFirstStackRowOffset} \\ + \locCdoHi & \define & \stackItemValHi {1} _{i - \callFirstStackRowOffset} \\ + \locCdoLo & \define & \stackItemValLo {1} _{i - \callFirstStackRowOffset} \\ + \locCdsHi & \define & \stackItemValHi {2} _{i - \callFirstStackRowOffset} \\ + \locCdsLo & \define & \stackItemValLo {2} _{i - \callFirstStackRowOffset} \\ + \locRaoHi & \define & \stackItemValHi {3} _{i - \callFirstStackRowOffset} \\ + \locRaoLo & \define & \stackItemValLo {3} _{i - \callFirstStackRowOffset} \\ + \locRacHi & \define & \stackItemValHi {4} _{i - \callFirstStackRowOffset} \\ + \locRacLo & \define & \stackItemValLo {4} _{i - \callFirstStackRowOffset} \\ + \locGasHi & \define & \stackItemValHi {1} _{i - \callSecondStackRowOffset} \\ + \locGasLo & \define & \stackItemValLo {1} _{i - \callSecondStackRowOffset} \\ + \locRawAddressHi & \define & \stackItemValHi {2} _{i - \callSecondStackRowOffset} \\ + \locRawAddressLo & \define & \stackItemValLo {2} _{i - \callSecondStackRowOffset} \\ + \locValueHi & \define & \stackItemValHi {3} _{i - \callSecondStackRowOffset} \\ + \locValueLo & \define & \stackItemValLo {3} _{i - \callSecondStackRowOffset} \\ + \locSuccessBitHi & \define & \stackItemValHi {4} _{i - \callSecondStackRowOffset} \\ + \locSuccessBitLo & \define & \stackItemValLo {4} _{i - \callSecondStackRowOffset} \\ + \end{array} \right. + \left\{ \begin{array}{lcl} + \locGasActual & \define & \gasActual _{i - \callFirstStackRowOffset} \\ + \locCurrentAddressHi & \define & \cnAccountAddress\high _{i + \callCurrentContextRowOffset} \\ + \locCurrentAddressLo & \define & \cnAccountAddress\low _{i + \callCurrentContextRowOffset} \\ + \locIsStatic & \define & \cnStatic _{i + \callCurrentContextRowOffset} \\ + \locCurrentCallerAddressHi & \define & \cnCallerAddress\high _{i + \callCurrentContextRowOffset} \\ + \locCurrentCallerAddressLo & \define & \cnCallerAddress\low _{i + \callCurrentContextRowOffset} \\ + \locCurrentCallValue & \define & \cnCallValue _{i + \callCurrentContextRowOffset} \\ + \locCsd & \define & \cnCsd _{i + \callCurrentContextRowOffset} \\ + \locMxpMemoryExpansionException & \define & \miscMxpMxpx _{i + \callMiscRowOffset} \\ + \locMxpMemoryExpansionGas & \define & \miscMxpGasMxp _{i + \callMiscRowOffset} \\ + \locStpGasUpfront & \define & \miscStpGasUpfront _{i + \callMiscRowOffset} \\ + \locStpGasPoop & \define & \miscStpGasPoop _{i + \callMiscRowOffset} \\ + \locStpGasStipend & \define & \miscStpGasStipend _{i + \callMiscRowOffset} \\ + \locStpOogx & \define & \miscStpOogx _{i + \callMiscRowOffset} \\ + \locNonzeroValue & \define & \miscOobDataCol {7} _{i + \callMiscRowOffset} \\ + \locOobAbortingCondition & \define & \miscOobDataCol {8} _{i + \callMiscRowOffset} \\ + \locCallerBalance & \define & \accBalance _{i + \callFirstCallerAccountRowOffset} \\ + \locCalleeAddressHi & \define & \accAddressHi _{i + \callFirstCalleeAccountRowOffset} \\ + \locCalleeAddressLo & \define & \accAddressLo _{i + \callFirstCalleeAccountRowOffset} \\ + \locCalleeCfi & \define & \accCfi _{i + \callFirstCalleeAccountRowOffset} \\ + \locCalleeHasCode & \define & \accHasCode _{i + \callFirstCalleeAccountRowOffset} \\ + \locCalleeWarmth & \define & \accWarmth _{i + \callFirstCalleeAccountRowOffset} \\ + \locCalleeExists & \define & \accExists _{i + \callFirstCalleeAccountRowOffset} \\ + \multicolumn{3}{l}{\locCalleeIsPrecompile \define \accTrmIsPrecompile _{i + \callFirstCalleeAccountRowOffset}} \\ + \end{array} \right. +\] +We further introduce some shorthands for ``revert data'': +\[ + \left\{ \begin{array}{lcl} + \locCnWillRevert & \define & \cnWillRev _{i - \callFirstStackRowOffset} \\ + \locCnRevertStamp & \define & \cnRevStamp _{i - \callFirstStackRowOffset} \\ + \locCalleeWillRevert & \define & \miscChildSelfReverts _{i + \callMiscRowOffset} \\ + \locCalleeRevertStamp & \define & \miscChildRevertStamp _{i + \callMiscRowOffset} \\ + \end{array} \right. +\] +\saNote{} +These shorthands only make sense given that both $\peekScenario_{i} = 1$ and $\scenCreateSum_{i} = 1$. +These constraints will be imposed starting with section~(\ref{hub: instruction handling: create: generalities}) diff --git a/hub/instruction_handling/call/specialized/_inputs.tex b/hub/instruction_handling/call/specialized/_inputs.tex new file mode 100644 index 0000000..a164a6d --- /dev/null +++ b/hub/instruction_handling/call/specialized/_inputs.tex @@ -0,0 +1,6 @@ +\subsubsubsection{$\justifyCalleeRevertData {i}{\relof}$ constraints \lispDone{}} \label{hub: instruction handling: call: specialized: callee revert data} \input{instruction_handling/call/specialized/child_data} +\subsubsubsection{$\initializeCalleeContextName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: instruction handling: call: specialized: initializing callee} \input{instruction_handling/call/specialized/initialize} +\subsubsubsection{$\firstRowOfCallee {i}{\relof}$ constraints \lispDone{}} \label{hub: instruction handling: call: specialized: first row of callee} \input{instruction_handling/call/specialized/first_row_callee} +\subsubsubsection{Distinctions between the various \inst{CALL}-type instructions \lispNone{}} \label{hub: instruction handling: call: specialized: callee context parameters definition} \input{instruction_handling/call/specialized/differences} +\subsubsubsection{Defining the missing context parameters \lispDone{}} \label{hub: instruction handling: call: specialized: callee context parameters definition} \input{instruction_handling/call/specialized/parameters} +\subsubsubsection{$\precompileScenarioRow {i}{\relof}$ constraints \lispDone{}} \label{hub: instruction handling: call: specialized: specialized precompile scenario row} \input{instruction_handling/call/specialized/precompile} diff --git a/hub/instruction_handling/call/specialized/child_data.tex b/hub/instruction_handling/call/specialized/child_data.tex new file mode 100644 index 0000000..0873506 --- /dev/null +++ b/hub/instruction_handling/call/specialized/child_data.tex @@ -0,0 +1,9 @@ +We define a parametrized collection of constraints. Below $\relof$ is a \textbf{positive integer}. In applications this positive integer will be set by the \inst{CALL}-scenario. +\[ + \justifyCalleeRevertData {i}{\relof} + \iff + \left\{ \begin{array}{lcl} + \locCalleeSelfReverts & = & \cnSelfRev _{i + \relof + 1} \\ + \locCalleeRevertStamp & = & \cnRevStamp _{i + \relof + 1} \\ + \end{array} \right. +\] diff --git a/hub/instruction_handling/call/specialized/differences.tex b/hub/instruction_handling/call/specialized/differences.tex new file mode 100644 index 0000000..0a02d79 --- /dev/null +++ b/hub/instruction_handling/call/specialized/differences.tex @@ -0,0 +1,75 @@ +Before defining the values for the missing shorthands from section~(\ref{hub: instruction handling: call: specialized: initializing callee}) +we take the time to remind the reader how the various \inst{CALL}-type instructions set the parameters for the message call function $\Theta$: +\[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|l|c|l|} \cline{3-3} + \multicolumn{2}{c|} & \text{Caller context} \\ + \multicolumn{2}{c|} & \text{environment} \\ + \multicolumn{2}{c|} & \text{variables} \\ \hline + \text{Definition of }\Theta & \Theta(\bm{\sigma}, A , \yellowm{s} , o , \yellowm{r} , c, g , p , v , \yellowm{\tilde{v}} , \textbf{d}, e , \yellowm{w} ) & \begin{cases} I_\text{s}' & \leftarrow \yellowm{s} \\ I_\text{a}' & \leftarrow \yellowm{r } \\ I_\text{v}' & \leftarrow \yellowm{\tilde{v}} \\ I_\text{w}' & \leftarrow \yellowm{w} \\ \end{cases} \\ \hline \hline + \inst{CALL} & \Theta(\bm{\sigma}, A^*, \redm{I_\text{a}}, I_\text{o}, \redm{t } , t, C_\textsc{callgas}, I_\text{p}, \bm{\mu}_\textbf{s}[2], \redm{\bm{\mu}_\textbf{s}[2]}, \textbf{i}, I_\text{e} + 1, \redm{I_{\text{w}}} ) & \begin{cases} I_\text{s}' & \leftarrow \redm{I_\text{a}} \\ I_\text{a}' & \leftarrow \redm{t } \\ I_\text{v}' & \leftarrow \redm{\bm{\mu}_\textbf{s}[2]} \\ I_\text{w}' & \leftarrow \redm{I_\text{w}} \\ \end{cases} \\ \hline + \inst{CALLCODE} & \Theta(\bm{\sigma}, A^*, \redm{I_\text{a}}, I_\text{o}, \redm{I_\text{a}} , t, C_\textsc{callgas}, I_\text{p}, \bm{\mu}_\textbf{s}[2], \redm{\bm{\mu}_\textbf{s}[2]}, \textbf{i}, I_\text{e} + 1, \redm{I_{\text{w}}} ) & \begin{cases} I_\text{s}' & \leftarrow \redm{I_\text{a}} \\ I_\text{a}' & \leftarrow \redm{I_\text{a} } \\ I_\text{v}' & \leftarrow \redm{\bm{\mu}_\textbf{s}[2]} \\ I_\text{w}' & \leftarrow \redm{I_\text{w}} \\ \end{cases} \\ \hline + \inst{DELEGATECALL} & \Theta(\bm{\sigma}, A^*, \redm{I_\text{s}}, I_\text{o}, \redm{I_\text{a}} , t, C_\textsc{callgas}, I_\text{p}, 0 , \redm{I_\text{v} }, \textbf{i}, I_\text{e} + 1, \redm{I_{\text{w}}} ) & \begin{cases} I_\text{s}' & \leftarrow \redm{I_\text{s}} \\ I_\text{a}' & \leftarrow \redm{I_\text{a} } \\ I_\text{v}' & \leftarrow \redm{I_\text{v}} \\ I_\text{w}' & \leftarrow \redm{I_\text{w}} \\ \end{cases} \\ \hline + \inst{STATICCALL} & \Theta(\bm{\sigma}, A^*, \redm{I_\text{a}}, I_\text{o}, \redm{t } , t, C_\textsc{callgas}, I_\text{p}, 0 , \redm{0 }, \textbf{i}, I_\text{e} + 1, \redm{\bot } ) & \begin{cases} I_\text{s}' & \leftarrow \redm{I_\text{a}} \\ I_\text{a}' & \leftarrow \redm{t } \\ I_\text{v}' & \leftarrow \redm{0} \\ I_\text{w}' & \leftarrow \redm{\bot } \\ \end{cases} \\ \hline + \end{array} +\] +from which it follows that +\begin{description} + \item[\underline{Caller address $I_\text{s}'$ of the callee context:}] + $I_\text{s}'$ is accessible through the \inst{CALLER} opcode + \begin{itemize} + \item + \inst{CALL}, + \inst{CALLCODE} and + \inst{STATICCALL} + set the callee context's ``caller address $I_\text{s}$'' + to the caller context's ``account address $I_\text{a}$'' + \item + \inst{DELEGATECALL} + perpetuates the caller context's ``caller address $I_\text{s}$'' + to the callee context's ``caller address $I_\text{s}$'' + \end{itemize} + % \inst{CALL}, + % \inst{CALLCODE} + % \inst{DELEGATECALL} + % \inst{STATICCALL} + \item[\underline{Account address $I_\text{a}'$ of the callee context:}] + $I_\text{a}'$ is accessible through the \inst{ADDRESS} opcode + \begin{itemize} + \item + \inst{CALLCODE} + \inst{DELEGATECALL} + perpetuate the current account address (as accessible through the \inst{ADDRESS} opcode) to the callee context; + \item + \inst{CALL}, + \inst{STATICCALL} + the underlying account address is that of the target address of the \inst{CALL}-type instruction; + \end{itemize} + \item[\underline{Value $I_\text{v}'$ passed to the callee context:}] + $I_\text{a}'$ is accessible through the \inst{CALLVALUE} opcode + \begin{itemize} + \item + \inst{CALL}, + \inst{CALLCODE} + provide the callee context with the ``value'' stack argument as its ``call value''; + \item + \inst{DELEGATECALL} + transfers the current ``call value'' $I_\text{v}$ to the callee context; + \item + \inst{STATICCALL} + provides the callee context with zero ``call value''; + \end{itemize} + \item[\underline{Write permission $I_\text{w}'$ of the callee context:}] + responsible for raising \staticxSH{}'s + \begin{itemize} + \item + \inst{CALL}, + \inst{CALLCODE} and + \inst{DELEGATECALL} + tranfer the current write permission ($I_\text{w} \equiv \neg ~ \locIsStatic$) to the callee context; + \item + \inst{STATICCALL} + sets the write permission of the callee context to false, $I_\text{w} \equiv \perp$, i.e. sets it $\cnStatic \equiv \rOne$; + \end{itemize} +\end{description} + diff --git a/hub/instruction_handling/call/specialized/first_row_callee.tex b/hub/instruction_handling/call/specialized/first_row_callee.tex new file mode 100644 index 0000000..7a77060 --- /dev/null +++ b/hub/instruction_handling/call/specialized/first_row_callee.tex @@ -0,0 +1,14 @@ +We define a parametrized collection of constraints. Below $\relof$ is a \textbf{positive integer}. \ob{TODO} +\[ + \firstRowOfCallee {i}{\relof} + \iff + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\caller _{i + \relof + 1} = \cn _{i + \relof}} \\ + \cn _{i + \relof + 1} & \!\!\! = \!\!\! & \cnCn_{i + \relof} \\ + \cfi _{i + \relof + 1} & \!\!\! = \!\!\! & \locCalleeCfi \\ + \pc _{i + \relof + 1} & \!\!\! = \!\!\! & 0 \\ + \gasExpected _{i + \relof + 1} & \!\!\! = \!\!\! & \locStpGasPoop + \locStpGasStipend \\ + \gasActual _{i + \relof + 1} & \!\!\! = \!\!\! & \gasExpected _{i + \relof + 1} \\ + \end{array} \right. +\] + diff --git a/hub/instruction_handling/call/specialized/initialize.tex b/hub/instruction_handling/call/specialized/initialize.tex new file mode 100644 index 0000000..5fa7778 --- /dev/null +++ b/hub/instruction_handling/call/specialized/initialize.tex @@ -0,0 +1,56 @@ +We define the \initializeCalleeContextName{} constraint system as follows, using the \initializeContextName{} constraints from section~(\ref{hub: consistencies: context: constraints}), +\[ + \left\{ \begin{array}{l} + \initializeCalleeContext { + anchorRow = i, + relOffset = \relof, + initializationParameters = \calleeContextInitializationParameters, + } \vspace {4mm} \\ + \qquad \define + \initializeContext{ + anchorRow = i , + relOffset = \relof , + contextNumber = \cn\new_{i} , + callStackDepth = 1 + \locCsd , + isRoot = 0 , + isStatic = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_context\_is\_static} , + accountAddressHigh = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_account\_address\_hi} , + accountAddressLow = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_account\_address\_lo} , + accountDeploymentNumber = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_account\_deployment\_number} , + byteCodeAddressHi = \locCalleeAddressHi , + byteCodeAddressLo = \locCalleeAddressLo , + byteCodeDeploymentNumber = \accDepNumber_{i + \callFirstCalleeAccountRowOffset} , + byteCodeDeploymentStatus = \accDepStatus_{i + \callFirstCalleeAccountRowOffset} , + byteCodeCodeFragmentIndex = \locCalleeCfi , + callerAddressHi = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_caller\_address\_hi} , + callerAddressLo = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_caller\_address\_lo} , + callValue = (\textcolor{draculaorange}{\bigstar}) \quad \col{new\_call\_value} , + callDataContextNumber = \cn_{i} , + callDataOffset = \locCdoLo , + callDataSize = \locCdsLo , + returnAtOffset = \locRaoLo , + returnAtCapacity = \locRacLo , + } + \end{array} \right. +\] +All shorthands above were previously defined with the exception of those marked with $(\textcolor{draculaorange}{\bigstar})$ +\begin{multicols}{2} + \begin{itemize} + \item \col{new\_account\_address\_hi} + \item \col{new\_account\_address\_lo} + \item \col{new\_caller\_address\_hi} + \item \col{new\_caller\_address\_lo} + \item \col{new\_account\_deployment\_number} + \item \col{new\_context\_is\_static} + \item \col{new\_call\_value} + \item[\vspace{\fill}] + \end{itemize} +\end{multicols} +\noindent These shorthands will be defined in section~(\ref{hub: instruction handling: call: specialized: callee context parameters definition}). +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_context\_is\_static}}, +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_account\_address\_hi}}, +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_account\_address\_lo}}, +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_account\_deployment\_number}}, +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_caller\_address\_hi}}, +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_caller\_address\_lo}}, +% (\textcolor{draculaorange}{\bigstar}) \quad \textcolor{draculagreen}{\col{new\_call\_value}}, diff --git a/hub/instruction_handling/call/specialized/parameters.tex b/hub/instruction_handling/call/specialized/parameters.tex new file mode 100644 index 0000000..b7a91e2 --- /dev/null +++ b/hub/instruction_handling/call/specialized/parameters.tex @@ -0,0 +1,71 @@ +We define the remaining context initialization parameterns, +i.e. those marked with $(\textcolor{draculaorange}{\bigstar})$ in section~(\ref{hub: instruction handling: call: specialized: initializing callee}), +as follows: +\[ + \col{new\_context\_is\_static} + \define + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \locIsStatic \\ + + & \locIsCallcode & \cdot & \locIsStatic \\ + + & \locIsDelegatecall & \cdot & \locIsStatic \\ + + & \locIsStaticcall & \cdot & \one \\ + \end{array} \right] +\] +and +\[ + \left\{ \begin{array}{lcl} + \col{new\_account\_address\_hi} & \define & + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \locCalleeAddressHi \\ + + & \locIsCallcode & \cdot & \locCurrentAddressHi \\ + + & \locIsDelegatecall & \cdot & \locCurrentAddressHi \\ + + & \locIsStaticcall & \cdot & \locCalleeAddressHi \\ + \end{array} \right] \vspace{2mm} \\ + \col{new\_account\_address\_lo} & \define & + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \locCalleeAddressLo \\ + + & \locIsCallcode & \cdot & \locCurrentAddressLo \\ + + & \locIsDelegatecall & \cdot & \locCurrentAddressLo \\ + + & \locIsStaticcall & \cdot & \locCalleeAddressLo \\ + \end{array} \right] \vspace{2mm} \\ + % + \col{new\_account\_deployment\_number} & \define & + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \accDepNumber_{i + \callFirstCalleeAccountRowOffset} \\ + + & \locIsCallcode & \cdot & \accDepNumber_{i + \callFirstCallerAccountRowOffset} \\ + + & \locIsDelegatecall & \cdot & \accDepNumber_{i + \callFirstCallerAccountRowOffset} \\ + + & \locIsStaticcall & \cdot & \accDepNumber_{i + \callFirstCalleeAccountRowOffset} \\ + \end{array} \right] \\ + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \col{new\_caller\_address\_hi} & \define & + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \locCurrentAddressHi \\ + + & \locIsCallcode & \cdot & \locCurrentAddressHi \\ + + & \locIsDelegatecall & \cdot & \locCurrentCallerAddressHi \\ + + & \locIsStaticcall & \cdot & \locCurrentAddressHi \\ + \end{array} \right] \vspace{2mm} \\ + \col{new\_caller\_address\_lo} & \define & + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \locCurrentAddressLo \\ + + & \locIsCallcode & \cdot & \locCurrentAddressLo \\ + + & \locIsDelegatecall & \cdot & \locCurrentCallerAddressLo \\ + + & \locIsStaticcall & \cdot & \locCurrentAddressLo \\ + \end{array} \right] \vspace{2mm} \\ + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \col{new\_call\_value} & \define & + \left[ \begin{array}{rrrr} + + & \locIsCall & \cdot & \locValueLo \\ + + & \locIsCallcode & \cdot & \locValueLo \\ + + & \locIsDelegatecall & \cdot & \locCurrentCallValue \\ + + & \locIsStaticcall & \cdot & 0 \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/instruction_handling/call/specialized/precompile.tex b/hub/instruction_handling/call/specialized/precompile.tex new file mode 100644 index 0000000..7c09c09 --- /dev/null +++ b/hub/instruction_handling/call/specialized/precompile.tex @@ -0,0 +1,34 @@ +We define constraints that impose basic behaviour of the second scenario-row of a \inst{CALL}-type instruction (unexceptional, unaborted i.e. entered) targeting a precompile. +\[ + \hspace*{-2cm} + \precompileScenarioRow {i}{\relof} + \iff + \left\{ \begin{array}{lcl} + \begin{array}{lcl} + \peekScenario _{i + \relof} & = & \one \\ + \scenPrecompileSum _{i + \relof} & = & \one \\ + \scenPrecompileWeightedSum _{i + \relof} & = & \locCalleeAddressLo \\ + \end{array} \vspace{4mm} \\ + \begin{array}{lcl} + \scenPrcFailure _{i + \relof} & = & \scenCallPrcFailure_{i} \\ + \scenPrcSuccessWillRevert _{i + \relof} & = & \scenCallPrcSuccessWillRevert_{i} \\ + \scenPrcSuccessWontRevert _{i + \relof} & = & \scenCallPrcSuccessWontRevert_{i} \\ + \end{array} \vspace{4mm} \\ + \begin{array}{lcl} + \scenPrcCurrentlyValidCallerGas _{i + \relof} & = & \locGasActual - \locStpGasUpfront - \locStpGasPoop \\ + \scenPrcGasAllowance _{i + \relof} & = & \locStpGasPoop + \locStpGasStipend \\ + \scenPrcGasOwedToCaller _{i + \relof} & = & \toBeSet \\ + \end{array} \vspace{4mm} \\ + \begin{array}{lcl} + \scenPrcCdo _{i + \relof} & = & \locCdoLo \\ + \scenPrcCds _{i + \relof} & = & \locCdsLo \\ + \scenPrcRao _{i + \relof} & = & \locRaoLo \\ + \scenPrcRac _{i + \relof} & = & \locRacLo \\ + % \scenPrcFailureGas _{i + \relof} & = & \\ + % \scenPrcFailureData _{i + \relof} & = & \\ + \end{array} \\ + \end{array} \right. +\] +\saNote{} The contents of column \scenPrcGasOwedToCaller{} will be set from the vantage point of a precompile row. + +\saNote{} Every time this constraint is invoked the first condition $\peekScenario \equiv \one$ will already hold by virtue of section~(\ref{hub: instruction handling: call: peeking flags and nRows for precompiles first half}). diff --git a/hub/instruction_handling/call/triggers/_inputs.tex b/hub/instruction_handling/call/triggers/_inputs.tex new file mode 100644 index 0000000..d93cf62 --- /dev/null +++ b/hub/instruction_handling/call/triggers/_inputs.tex @@ -0,0 +1,7 @@ +\subsubsubsection{Introduction \lispNone{}} \label{hub: instruction handling: call: trigger: intro} \input{instruction_handling/call/triggers/intro} +\subsubsubsection{Setting \locCallTriggersOob{} \lispDone{}} \label{hub: instruction handling: call: trigger: oob} \input{instruction_handling/call/triggers/oob} +\subsubsubsection{Setting \locCallTriggersMxp{} \lispDone{}} \label{hub: instruction handling: call: trigger: mxp} \input{instruction_handling/call/triggers/mxp} +\subsubsubsection{Setting \locCallTriggersTrm{} \lispDone{}} \label{hub: instruction handling: call: trigger: trm} \input{instruction_handling/call/triggers/trm} +\subsubsubsection{Setting \locCallTriggersStp{} \lispDone{}} \label{hub: instruction handling: call: trigger: stp} \input{instruction_handling/call/triggers/stp} +\subsubsubsection{Setting \locCallTriggersRomLex{} \lispDone{}} \label{hub: instruction handling: call: trigger: rom lex} \input{instruction_handling/call/triggers/romLex} +\subsubsubsection{Setting \locCallRequiresCalleeAccount{} etc\dots{} \lispDone{}} \label{hub: instruction handling: call: trigger: callee account} \input{instruction_handling/call/triggers/accounts} diff --git a/hub/instruction_handling/call/triggers/accounts.tex b/hub/instruction_handling/call/triggers/accounts.tex new file mode 100644 index 0000000..be374ec --- /dev/null +++ b/hub/instruction_handling/call/triggers/accounts.tex @@ -0,0 +1,11 @@ +The following shorthand is used to determine when to load the contents of the \callerr{} account. +This happens precisely when the \inst{CALL}-type instruction is unexceptional. +As such we impose +\[ + \left\{ \begin{array}{lcl} + \locCallRequiresCalleeAccount & \define & \miscStpFlag _{i + 2} \\ + \locCallRequiresCallerAccount & \define & \scenCallUnexceptional _{i} \\ + \locCallRequiresBothAccountsTwice & \define & \scenCallRequiresBothAccountsTwice _{i} \\ + \locCallRequiresCalleeAccountThrice & \define & \scenCallSmcFailureWillRevert _{i} \\ + \end{array} \right. +\] diff --git a/hub/instruction_handling/call/triggers/intro.tex b/hub/instruction_handling/call/triggers/intro.tex new file mode 100644 index 0000000..7f7d37e --- /dev/null +++ b/hub/instruction_handling/call/triggers/intro.tex @@ -0,0 +1,16 @@ +In this section we specify the following ``module trigger shorthands.'' +\begin{multicols}{2} +\begin{itemize} + \item \locCallTriggersMxp{} + \item \locCallTriggersTrm{} + \item \locCallTriggersStp{} + \item \locCallTriggersOob{} + \item \locCallTriggersRomLex{} + \item[\vspace{\fill}] +\end{itemize} +\end{multicols} +\noindent These are binary (by construction) flags which will be used to set certain columns in the processing of \inst{CALL}-type instructions. + +\saNote{} We draw attention to the fact that all \col{trigger\_XXX} expressions which we define are \emph{de facto} binary and that binariness need not be imposed by constraint. + +\saNote{} These shorthands (as defined in the next few sections) only make sense (and will only ever be used) for row indices $i$ which satisfy both $\peekScenario_{i} = 1$ and $\scenCreateSum_{i} = 1$. These constraints will be imposed starting with section~(\ref{hub: instruction handling: call: generalities}). diff --git a/hub/instruction_handling/call/triggers/mxp.tex b/hub/instruction_handling/call/triggers/mxp.tex new file mode 100644 index 0000000..93b06e7 --- /dev/null +++ b/hub/instruction_handling/call/triggers/mxp.tex @@ -0,0 +1,10 @@ +We must trigger the \mxpMod{} in every case except for that of a \staticxSH{}. As such we impose +\[ + \locCallTriggersMxp + \define + \left[ \begin{array}{ll} + + & \locMxpx + \locOogx \\ + + & \scenCallUnexceptional _{i} \\ + \end{array} \right] +\] +In other words the \mxpMod{} will be triggered in all cases \emph{except for} that of a \staticxSH{}. diff --git a/hub/instruction_handling/call/triggers/oob.tex b/hub/instruction_handling/call/triggers/oob.tex new file mode 100644 index 0000000..7c5ac22 --- /dev/null +++ b/hub/instruction_handling/call/triggers/oob.tex @@ -0,0 +1,19 @@ +We trigger the \oobMod{} whenever the \zkEvm{} predicts an exception for a \inst{CALL} instruction and for all unexceptional \inst{CALL}-type instructions. +As such we set +\[ + \locCallTriggersOob + \define + \left[ \begin{array}{cr} + + & \locIsCall \cdot \scenCallException \\ + + & \scenCallUnexceptional \\ + \end{array} \right] +\] +\saNote{} +There are two distinct \oobMod{} instructions that may be triggered: \oobInstXcall{} and \oobInstCall{}. +The former is used to detect \staticxSH{}'s, the latter is used to justify the absence of any \staticxSH{} and to detect the presence or absence of aborting conditions. +We refer the reader to section~(\ref{hub: instruction handling: call: generalities}) for more ample details, to +section~(\ref{hub: misc: oob: call}) and +section~(\ref{hub: misc: oob: xcall}) for a description of these instructions from the \hubMod{} point of view and to +section~(\ref{oob: populating: opcodes: exceptional calls}) and +section~(\ref{oob: populating: opcodes: call}) +for details about the implementations of these constraint systems in the \oobMod{} module. diff --git a/hub/instruction_handling/call/triggers/romLex.tex b/hub/instruction_handling/call/triggers/romLex.tex new file mode 100644 index 0000000..a956424 --- /dev/null +++ b/hub/instruction_handling/call/triggers/romLex.tex @@ -0,0 +1,7 @@ +We must trigger the \romLexMod{} in every case which requires the execution of actual bytecode. +That is whenever the \inst{CALL}-type instruction actually gets executed and its target is an account which has nonempty bytecode. As such we set +\[ + \locCallTriggersRomLex + \define + \scenCallToSmartContract_{i} +\] diff --git a/hub/instruction_handling/call/triggers/stp.tex b/hub/instruction_handling/call/triggers/stp.tex new file mode 100644 index 0000000..0eb4ce5 --- /dev/null +++ b/hub/instruction_handling/call/triggers/stp.tex @@ -0,0 +1,10 @@ +We must trigger the \stpMod{} in every case which requires us to compute the gas cost of the \inst{CALL}-type instruction. That is in case of an \oogxSH{} and in case no exception has occurred. As such we set +\[ + \locCallTriggersStp + \define + \left[ \begin{array}{cl} + + & \locOogx \\ + + & \scenCallUnexceptional _{i} \\ + \end{array} \right] +\] +\saNote{} For \inst{CALL}-type instructions $\locCallTriggersTrm \equiv \locCallTriggersStp$. diff --git a/hub/instruction_handling/call/triggers/trm.tex b/hub/instruction_handling/call/triggers/trm.tex new file mode 100644 index 0000000..3992e65 --- /dev/null +++ b/hub/instruction_handling/call/triggers/trm.tex @@ -0,0 +1,9 @@ +We must trigger the \trmMod{} in every case which requires us to compute the gas cost of the \inst{CALL}-type instruction. That is in case of an \oogxSH{} and in case no exception has occurred. As such we set +\[ + \locCallTriggersTrm + \define + \left[ \begin{array}{cl} + + & \locOogx \\ + + & \scenCallUnexceptional _{i} \\ + \end{array} \right] +\] diff --git a/hub/instruction_handling/con.tex b/hub/instruction_handling/con.tex new file mode 100644 index 0000000..431431f --- /dev/null +++ b/hub/instruction_handling/con.tex @@ -0,0 +1,103 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\[ + \begin{array}{|l||c||c|c|c|c|c|} + \hline + \INST & \tli & \stackDecConFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} \\ \hline\hline + \inst{ADDRESS} & \zero & \oneCell & \oneCell & \zero & \zero & \zero \\ \hline + \inst{CALLER} & \zero & \oneCell & \zero & \oneCell & \zero & \zero \\ \hline + \inst{CALLVALUE} & \zero & \oneCell & \zero & \zero & \oneCell & \zero \\ \hline + \inst{CALLDATASIZE} & \zero & \oneCell & \zero & \zero & \zero & \oneCell \\ \hline + \inst{RETURNDATASIZE} & \zero & \oneCell & \zero & \zero & \zero & \zero \\ \hline + \end{array} +\] + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecConFlag_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \end{array} \right. + } +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\zeroOneSP_{i}$ + \item[\underline{Setting the gas cost:}] + we impose $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Setting $\nonStackRows$:}] + we impose $\nonStackRows_{i} = 1 + \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] + we impose that + \[ + \left[ \begin{array}{cr} + + & \peekContext_{i + 1} \\ + + & \cmc_{i} \cdot \peekContext_{i + 2} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + we further unconditionally set $\readContextData {i}{1}{\cn_{i}} = 1$ + \item[\underline{Value constraints:}] + \If $\cmc_{i} = 0$ \Then + \begin{enumerate} + \item \If $\decFlag{1}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & \cnAccountAddress\high_{i + 1} \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \cnAccountAddress\low_{i + 1} \\ + \end{array} \right. + \] + \item \If $\decFlag{2}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & \cnCallerAddress\high_{i + 1} \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \cnCallerAddress\low_{i + 1} \\ + \end{array} \right. + \] + \item \If $\decFlag{3}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \cnCallValue_{i + 1} \\ + \end{array} \right. + \] + \item \If $\decFlag{4}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \cnCds_{i + 1} \\ + \end{array} \right. + \] + \def\locDecFlagSum{\col{id\_flag\_sum}} + \item \If $\locDecFlagSum_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \cnRds_{i + 1} \\ + \end{array} \right. + \] + where we use the following shorthand + \[ + \locDecFlagSum_{i} + \define + \left[ \begin{array}{cr} + + & \decFlag{1}_{i} \\ + + & \decFlag{2}_{i} \\ + + & \decFlag{3}_{i} \\ + + & \decFlag{4}_{i} \\ + \end{array} \right] + \] + \saNote{} Given the flag table presented above \locDecFlagSum{} is binary. + \end{enumerate} +\end{description} +\saNote{} For instructions raising the $\stackDecConFlag$ one has $\cmc \equiv \xAhoy$. diff --git a/hub/instruction_handling/copy/_inputs.tex b/hub/instruction_handling/copy/_inputs.tex new file mode 100644 index 0000000..a536606 --- /dev/null +++ b/hub/instruction_handling/copy/_inputs.tex @@ -0,0 +1,8 @@ +\input{instruction_handling/copy/_local} +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: logs: instruction flags} \input{instruction_handling/copy/flags} +\subsubsection{Global precondition and shorthands \lispDone{}} \label{hub: instruction handling: logs: shorthands} \input{instruction_handling/copy/shorthands} +\subsubsection{General constraints \lispDone{}} \label{hub: instruction handling: logs: constraints} \input{instruction_handling/copy/generalities} +\subsubsection{Specifics for \inst{CALLDATACOPY} \lispDone{}} \label{hub: instruction handling: logs: calldatadopy} \input{instruction_handling/copy/specifics/calldatacopy} +\subsubsection{Specifics for \inst{RETURNDATACOPY} \lispDone{}} \label{hub: instruction handling: logs: returndatacopy} \input{instruction_handling/copy/specifics/returndatacopy} +\subsubsection{Specifics for \inst{CODECOPY} \lispDone{}} \label{hub: instruction handling: logs: codecopy} \input{instruction_handling/copy/specifics/codecopy} +\subsubsection{Specifics for \inst{EXTCODECOPY} \lispDone{}} \label{hub: instruction handling: logs: extcodecopy} \input{instruction_handling/copy/specifics/extcodecopy} diff --git a/hub/instruction_handling/copy/_local.tex b/hub/instruction_handling/copy/_local.tex new file mode 100644 index 0000000..669a97f --- /dev/null +++ b/hub/instruction_handling/copy/_local.tex @@ -0,0 +1,57 @@ +\def\locInst {\col{instruction}} +\def\locTargetOffsetHi {\col{target\_offset\_hi}} +\def\locTargetOffsetLo {\col{target\_offset\_lo}} +\def\locSourceOffsetHi {\col{source\_offset\_hi}} +\def\locSourceOffsetLo {\col{source\_offset\_lo}} +\def\locSizeHi {\col{size\_hi}} +\def\locSizeLo {\col{size\_lo}} +\def\locAddressParamHi {\col{raw\_address\_hi}} +\def\locAddressParamLo {\col{raw\_address\_lo}} +\def\locAddressCfi {\col{target\_address\_cfi}} +% \def\locCurrentCfi {\col{current\_cfi}} +\def\locAddressIsWarm {\col{address\_is\_warm}} +\def\relevantValue {\texttt{}} +\def\locException {\col{raises\_exception}} +\def\locMxpx {\col{raises\_mxpx}} +\def\locOogx {\col{raises\_oogx}} +\def\locRdcx {\col{raises\_rdcx}} +\def\locOobRdcx {\oobMod\col{\_raises\_rdcx}} +\def\locMxpMxpx {\mxpMod\col{\_raises\_mxpx}} +\def\locMxpGas {\mxpMod\col{\_mxp\_gas}} +\def\locCallDataContext {\col{call\_data\_context}} +\def\locCdo {\col{call\_data\_offset}} +\def\locCds {\col{call\_data\_size}} +\def\locReturnDataContext {\col{return\_data\_context}} +\def\locRdo {\col{return\_data\_offset}} +\def\locRds {\col{return\_data\_size}} +\def\locCodeSize {\col{code\_size}} +\def\locHasCode {\col{has\_code}} +\def\locIsCdc {\col{is\_CDC}} +\def\locIsRdc {\col{is\_RDC}} +\def\locIsCc {\col{is\_CC}} +\def\locIsExtcc {\col{is\_EXTCC}} +\def\locTriggerMxp {\col{trigger\_MXP}} +\def\locTriggerMmu {\col{trigger\_MMU}} +\def\locTriggerOob {\col{trigger\_OOB}} +\def\locTriggerTrm {\col{trigger\_TRM}} +\def\locTriggerCfi {\col{trigger\_CFI}} +\def\locTriggerStp {\col{trigger\_STP}} +\def\locReturner {\col{returner}} +\def\locRefOffset {\col{ref\_offset}} +\def\locRefSize {\col{ref\_size}} +\def\locParamOne {\col{param\_one}} +\def\locInfo {\col{info}} + +% row offset colors +\def\locCopyMiscRowOffset {\yellowm{1}} +\def\locCopyCurrentContextRow {\yellowm{2}} +\def\locCopyCallerContextRowSmall {\orangem{2}} +\def\locCopyCallerContextRowLarge {\orangem{3}} +\def\locCopyCurrentAccountRow {\yellowm{3}} +\def\locCopyOutsideAccountRowFirst {\yellowm{2}} +\def\locCopyOutsideAccountRowSecond {\yellowm{3}} + +\def\locExoSum {\col{exo\_sum}} +\def\locReferenceSize {\col{reference\_size}} +\def\locReferenceOffset {\col{reference\_offset}} +\def\locSourceId {\col{source\_id}} diff --git a/hub/instruction_handling/copy/flags.tex b/hub/instruction_handling/copy/flags.tex new file mode 100644 index 0000000..e2117e4 --- /dev/null +++ b/hub/instruction_handling/copy/flags.tex @@ -0,0 +1,38 @@ +\[ + \hspace*{-1.5cm} + \begin{array}{|l||c||c|c|c|c|c||c|c|} \hline + \INST & \tli & \stackDecCopyFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} & \mxpFlag \\ \hline\hline + \inst{CALLDATACOPY} & \zero & \oneCell & \oneCell & \zero & \zero & \zero & \oneCell \\ \hline + \inst{RETURNDATACOPY} & \zero & \oneCell & \zero & \oneCell & \zero & \zero & \oneCell \\ \hline + \inst{CODECOPY} & \zero & \oneCell & \zero & \zero & \oneCell & \zero & \oneCell \\ \hline + \inst{EXTCODECOPY} & \zero & \oneCell & \zero & \zero & \zero & \oneCell & \oneCell \\ \hline + \end{array} +\] + +The family of \inst{COPY}-type instructions presents a certain amount of diversity. What follows are some of the peculiarities of the individual instructions. +\begin{description} + \item[\underline{\inst{CALLDATACOPY}:}] + is rather straightforward; + in all cases the data is located in a \textsc{ram} segment, namely the $\cnCallDataContextNumber$; + \item[\underline{\inst{RETURNDATACOPY}:}] + is unique among all instructions in that it can raise the \rdcxSH{}; + this exception is triggered \emph{iff} + \[ \col{source\_offset} + \col{size} \geq \col{return\_data\_size} \] + (with \col{source\_offset} being the offset with return data from where to start reading.) + The first two parameters are apparent on the stack. + The return data size (along with the return data offset) is available in the current execution context. + \item[\underline{\inst{CODECOPY}:}] + requires copying bytes from the currently executing bytecode; + this bytecode fragment is (uniquely) identifiable by means of the currently valid \cfi{}; + if the \mmuMod{} is to be triggered we also require the associated \col{code\_size}, for which we require peeking into the underlying account. + \item[\underline{\inst{EXTCODECOPY}:}] + requires trimming the (target) address argument from the stack; + may require loading the target bytecode into the \romMod{} module and requesting the associated \accCfi{}; + its pricing schedule is complicated by the fact that the target account's warmth has to be taken into account and switched if the instruction raises no exception; + its overall handling is further complicated by the fact that this ``switching on the warmth'' may have to be undone at a later point if the current execution context will be reverted. +\end{description} +\saNote{} The \rdcxSH{} is triggered \textbf{even if} the \col{size} parameter is zero. See chapter~(\ref{chap: oob}) for more details. + +\hypertarget{note: EXT instruction precautions}{\saNote{} +One has to be cautious of the fact that \inst{EXTCODECOPY} behaves differently depending on whether or not the (trimmed) address whose code is to be copied is currently undergoing deployment or not. +If it is then, from the point of view of all ``\inst{EXT}'' instructions (i.e. \inst{EXTCODESIZE}, \inst{EXTCODECOPY} and \inst{EXTCODEHASH}) the account is understood to have empty code.} diff --git a/hub/instruction_handling/copy/flowcharts/cc.dot b/hub/instruction_handling/copy/flowcharts/cc.dot new file mode 100644 index 0000000..f77f6d6 --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/cc.dot @@ -0,0 +1,212 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
CODECOPY
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + execution [ + label = "\nExecution\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + execution; execution_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> mxpx; + mxpx -> mxpx_rows; + mxpx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> execution; + execution -> execution_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1CONparentupdate return data:   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1MISCMXP🏴 = 1, MXPX = 1
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1MISCMXP🏴 = 1, MXPX = 0
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +execution_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexCFIPerspectiveWhoActionsWhen
DomSub
icfiSTACKCT = 0offset and size
i + 1cfiMISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = [size ≠ 0];
i + 2cfiACCcode accountACC_CFI = cfi, code size; read accountτ · h + 00
>]; + +} diff --git a/hub/instruction_handling/copy/flowcharts/cc.png b/hub/instruction_handling/copy/flowcharts/cc.png new file mode 100644 index 0000000..a504ddb Binary files /dev/null and b/hub/instruction_handling/copy/flowcharts/cc.png differ diff --git a/hub/instruction_handling/copy/flowcharts/cc.svg b/hub/instruction_handling/copy/flowcharts/cc.svg new file mode 100644 index 0000000..6a7d6f3 --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/cc.svg @@ -0,0 +1,297 @@ + + + + + + +G + + + +inst + +CODECOPY + + + +sux + +SUX + + + + +inst->sux + + + + + +mxpx + +MXPX + + + + +sux->mxpx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +1 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +execution + +Execution + + + + +unexceptional->execution + + + + + +execution_rows + +Row index + +CFI + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +cfi + +STACK + +CT = 0 + +offset and size + +i + 1 + +cfi + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = [size ≠ 0]; + +i + 2 + +cfi + +ACC + +code account + +ACC_CFI = +cfi +, code size; read account + +τ · h + 0 + +0 + + + +execution->execution_rows + + + + + diff --git a/hub/instruction_handling/copy/flowcharts/cdc.dot b/hub/instruction_handling/copy/flowcharts/cdc.dot new file mode 100644 index 0000000..5b7c25d --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/cdc.dot @@ -0,0 +1,207 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
CALLDATACOPY
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + execution [ + label = "\nExecution\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + execution; execution_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> mxpx; + mxpx -> mxpx_rows; + mxpx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> execution; + execution -> execution_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1Conparentupdate return data:   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 1
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +execution_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = [size ≠ 0];
i + 2CONcurrentCDO, CDS, IS_ROOT;
>]; + +} diff --git a/hub/instruction_handling/copy/flowcharts/cdc.png b/hub/instruction_handling/copy/flowcharts/cdc.png new file mode 100644 index 0000000..429c1ad Binary files /dev/null and b/hub/instruction_handling/copy/flowcharts/cdc.png differ diff --git a/hub/instruction_handling/copy/flowcharts/cdc.svg b/hub/instruction_handling/copy/flowcharts/cdc.svg new file mode 100644 index 0000000..3c595f3 --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/cdc.svg @@ -0,0 +1,284 @@ + + + + + + +G + + + +inst + +CALLDATACOPY + + + +sux + +SUX + + + + +inst->sux + + + + + +mxpx + +MXPX + + + + +sux->mxpx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +Con + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +1 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +execution + +Execution + + + + +unexceptional->execution + + + + + +execution_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = [size ≠ 0]; + +i + 2 + +CON + + +current + +CDO, CDS, IS_ROOT; + + + +execution->execution_rows + + + + + diff --git a/hub/instruction_handling/copy/flowcharts/extcc.dot b/hub/instruction_handling/copy/flowcharts/extcc.dot new file mode 100644 index 0000000..f7f72b1 --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/extcc.dot @@ -0,0 +1,281 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
EXTCODECOPY
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + wont_revert [ + label = "\nWon't revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + will_revert [ + label = "\nWill revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + will_revert; will_revert_rows; + } + { + rank=same; + wont_revert; wont_revert_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> mxpx; + mxpx -> mxpx_rows; + mxpx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> will_revert; + will_revert -> will_revert_rows; + will_revert -> wont_revert; + wont_revert -> wont_revert_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 2Conparentupdate return data:   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 1
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0
i + 2ACCtargetTRM🏴 = 1; same warmth; read account;τ · h + 00
i + 3CONparentupdate return data:   μo ­  ← ∅
>]; + +wont_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = [size ≠ 0];
i + 2ACCtargetTRM🏴 = 1; warmth ↗;τ · h + 00
CFI_REQUIRED = HAS_CODE * [SIZE != 0];
>]; + +will_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 2MISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = 0;
i + 2ACCtargetTRM🏴 = 1; warmth ↗;τ · h + 00
CFI_REQUIRED = HAS_CODE * [SIZE != 0];
i + 3ACCtargetTRM🏴 = 1; warmth ↶; read account;τ · ρ + ετ · h + 0
>]; + +} + diff --git a/hub/instruction_handling/copy/flowcharts/extcc.png b/hub/instruction_handling/copy/flowcharts/extcc.png new file mode 100644 index 0000000..089991d Binary files /dev/null and b/hub/instruction_handling/copy/flowcharts/extcc.png differ diff --git a/hub/instruction_handling/copy/flowcharts/extcc.svg b/hub/instruction_handling/copy/flowcharts/extcc.svg new file mode 100644 index 0000000..51778f6 --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/extcc.svg @@ -0,0 +1,387 @@ + + + + + + +G + + + +inst + +EXTCODECOPY + + + +sux + +SUX + + + + +inst->sux + + + + + +mxpx + +MXPX + + + + +sux->mxpx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 2 + +Con + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +1 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 + +i + 2 + +ACC + + +target + +TRM🏴 = 1; same warmth; read account; + +τ · h + 0 + +0 + +i + 3 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +will_revert + +Will revert + + + + +unexceptional->will_revert + + + + + +wont_revert + +Won't revert + + + + +wont_revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = [size ≠ 0]; + +i + 2 + +ACC + + +target + +TRM🏴 = 1; warmth ↗; + +τ · h + 0 + +0 + +CFI_REQUIRED = HAS_CODE * [SIZE != 0]; + + + +wont_revert->wont_revert_rows + + + + + +will_revert->wont_revert + + + + + +will_revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 2 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = 0; + +i + 2 + +ACC + + +target + +TRM🏴 = 1; warmth ↗; + +τ · h + 0 + +0 + +CFI_REQUIRED = HAS_CODE * [SIZE != 0]; + +i + 3 + +ACC + + +target + +TRM🏴 = 1; warmth ↶; read account; + +τ · ρ + ε + +τ · h + 0 + + + +will_revert->will_revert_rows + + + + + diff --git a/hub/instruction_handling/copy/flowcharts/rdc.dot b/hub/instruction_handling/copy/flowcharts/rdc.dot new file mode 100644 index 0000000..be2fceb --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/rdc.dot @@ -0,0 +1,265 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
RETURNDATACOPY
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + rdcx [ + label = "\nRDCX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + execution [ + label = "\nExecution\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + rdcx; rdcx_rows; + } + { + rank=same; + execution; execution_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> rdcx; + rdcx -> rdcx_rows; + rdcx -> mxpx; + mxpx -> mxpx_rows; + mxpx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> execution; + execution -> execution_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1Conparentupdate return data:   μo ­  ← ∅
>]; + +rdcx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 0
OOB🏴 = 1, EVENT = 1
i + 2CONcallerread context; RDS
i + 3CONparentupdate return data:   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 1
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +execution_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0;
OOB🏴 = 1, EVENT = 0;
MMU🏴 = [size ≠ 0];
i + 2CONcurrentRDO, RDS, RETURNER_CN;
>]; + +} diff --git a/hub/instruction_handling/copy/flowcharts/rdc.png b/hub/instruction_handling/copy/flowcharts/rdc.png new file mode 100644 index 0000000..dfbe7cd Binary files /dev/null and b/hub/instruction_handling/copy/flowcharts/rdc.png differ diff --git a/hub/instruction_handling/copy/flowcharts/rdc.svg b/hub/instruction_handling/copy/flowcharts/rdc.svg new file mode 100644 index 0000000..1f2a5bc --- /dev/null +++ b/hub/instruction_handling/copy/flowcharts/rdc.svg @@ -0,0 +1,362 @@ + + + + + + +G + + + +inst + +RETURNDATACOPY + + + +sux + +SUX + + + + +inst->sux + + + + + +rdcx + +RDCX + + + + +sux->rdcx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +Con + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +mxpx + +MXPX + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +1 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +rdcx->mxpx + + + + + +rdcx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +OOB🏴 = 1, EVENT = +1 + +i + 2 + +CON + + +caller + +read context; RDS + +i + 3 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +rdcx->rdcx_rows + + + + + +execution + +Execution + + + + +unexceptional->execution + + + + + +execution_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +OOB🏴 = 1, EVENT = +0 +; + +MMU🏴 = [size ≠ 0]; + +i + 2 + +CON + + +current + +RDO, RDS, RETURNER_CN; + + + +execution->execution_rows + + + + + diff --git a/hub/instruction_handling/copy/generalities.tex b/hub/instruction_handling/copy/generalities.tex new file mode 100644 index 0000000..6aeca83 --- /dev/null +++ b/hub/instruction_handling/copy/generalities.tex @@ -0,0 +1,301 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecCopyFlag_{i} = 1 \\ + \stackSux_{i} + \stackSox_{i} = 0 \\ + \end{cases}} +\end{center} +The constraints are as follows: +\begin{description} + \item[\underline{\underline{Setting the stack pattern:}}] + we impose $\copySP_{i} \big[ \locIsExtcc \big]$; + \item[\underline{\underline{Allowable exceptions:}}] + we impose + \[ \xAhoy _{i} = \locIsRdc \cdot \stackRdcx _{i} + \stackMxpx _{i} + \stackOogx _{i} \quad (\trash) \] + \item[\underline{\underline{Setting $\nonStackRows$ and peeking flags:}}] we impose the following + \begin{description} + \item[\underline{The \inst{CALLDATACOPY} case:}] + \If $\locIsCdc = 1$ \Then $\nonStackRows_{i} = 2$ furthermore + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekContext _{i + \locCopyCurrentContextRow } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item[\underline{The \inst{RETURNDATACOPY} case:}] + \If $\locIsRdc = 1$ \Then $\nonStackRows_{i} = 2 + \stackRdcx_{i}$ furthermore + \begin{enumerate} + \item \If $\stackRdcx_{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekContext _{i + \locCopyCurrentContextRow } \\ + + & \peekContext _{i + \locCopyCallerContextRowLarge } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\stackRdcx_{i} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekContext _{i + \locCopyCurrentContextRow } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \saNote{} \rdcxSH{} induce an extra row of instruction processing of \inst{RETURNDATACOPY}, + \item[\underline{The \inst{CODECOPY} case:}] + \If $\locIsCc = 1$ \Then $\nonStackRows_{i} = 2 + (1 - \xAhoy_{i})$ furthermore + \begin{enumerate} + \item \If $\xAhoy_{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekContext _{i + \locCopyCallerContextRowSmall } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\xAhoy_{i} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekContext _{i + \locCopyCurrentContextRow } \\ + + & \peekAccount _{i + \locCopyCurrentAccountRow } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \item[\underline{The \inst{EXTCODECOPY} case:}] + \If $\locIsExtcc = 1$ \Then $\nonStackRows_{i} = 2 + \stackOogx_{i} + (1 - \xAhoy_{i}) \cdot \cnWillRev$ furthermore + \begin{enumerate} + \item \If $\stackMxpx_{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekContext _{i + \locCopyCallerContextRowSmall } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\stackOogx_{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekAccount _{i + \locCopyOutsideAccountRowFirst } \\ + + & \peekContext _{i + \locCopyCallerContextRowLarge } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\xAhoy_{i} = 0$ \et $\cnWillRev_{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekAccount _{i + \locCopyOutsideAccountRowFirst } \\ + + & \peekAccount _{i + \locCopyOutsideAccountRowSecond } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\xAhoy_{i} = 0$ \et $\cnWillRev_{i} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekMisc _{i + \locCopyMiscRowOffset } \\ + + & \peekAccount _{i + \locCopyOutsideAccountRowFirst } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \saNote{} \oogxSH{}'s and unexceptional but later on reverted \inst{EXTCODECOPY} induce an extra instruction processing row. + \end{description} + \item[\underline{\underline{Setting the miscellaneous-row $n^°(i + \locCopyMiscRowOffset)$:}}] + observe that every processing path bigstarts with a \textbf{miscellaneous-row} + \begin{description} + \item[\underline{Setting module flags:}] + \[ + \weightedMiscFlagSum {i}{\locCopyMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \!\!\! \cdot \!\!\! & \locTriggerMmu \\ + + & \miscMxpWeight & \!\!\! \cdot \!\!\! & \locTriggerMxp \\ + + & \miscOobWeight & \!\!\! \cdot \!\!\! & \locTriggerOob \\ + \end{array} \right] + \] + i.e. + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag_{i + \locCopyMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag_{i + \locCopyMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag_{i + \locCopyMiscRowOffset} & = & \locTriggerMxp & (\trash) \\ + \miscOobFlag_{i + \locCopyMiscRowOffset} & = & \locTriggerOob & (\trash) \\ + \miscStpFlag_{i + \locCopyMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} We will specify \locTriggerMmu{}, \locTriggerMxp{} and \locTriggerOob{} shortly. + \item[\underline{Specifying \locTriggerOob{}:}] + \inst{RETURNDATACOPY} is the only instruction in the \inst{COPY}-family that requires the \oobMod{} module; + indeed the \oobMod{} detects \rdcxSH{}'s; + we thus impose + \[ + \locTriggerOob = \locIsRdc + \] + \item[\underline{Specifying \locTriggerMxp{}:}] + we technically don't have to call the \mxpMod{} module in case of \inst{RETURNDATACOPY} instructions raising the \rdcxSH{}; + this exception is enough to justify the exceptional halting condition; this behaviour is reflected in the assignment of the \miscMxpFlag{} since we impose + \[ \locTriggerMxp = \one - \stackRdcx_{i} \] + \item[\underline{Specifying \locTriggerMmu{}:}] + \label{locTriggerMmu for the copy family} + for a \inst{COPY}-type instruction to trigger the \mmuMod{} is is necessary and sufficient that the instruction raise no exception and be provided with a nonzero size parameter; + as such we set + \begin{enumerate} + \item \If $\xAhoy _{i} = 1$ \Then $\locTriggerMmu = 0$ + \item \If $\xAhoy _{i} = 0$ \Then $\locTriggerMmu = \miscMxpTypeFourInstMayTriggerMmu _{i + \locCopyMiscRowOffset}$ + \end{enumerate} + \saNote{} + Recall the specification of \miscMxpTypeFourInstMayTriggerMmu{} in the \mxpMod{}, section~(\ref{mxp: may trigger non trivial operation}). + This flag vanishes for instructions that aren't ``\textbf{type 4}'' as well as whenever the \mxpx{} flag is raised. + In all other cases this flag is $0$ \textbf{iff} the size parameter \locSizeLo{} is zero. + \item[\underline{Setting \oobMod{} data:}] + \If $\miscOobFlag _{i + \locCopyMiscRowOffset} = 1$ \Then we impose + \[ + \setOobInstructionRdc {i}{\locCopyMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Reference offset high:} & \locSourceOffsetHi \\ + \utt{Reference offset low:} & \locSourceOffsetLo \\ + \utt{Size high:} & \locSizeHi \\ + \utt{Size low:} & \locSizeLo \\ + \utt{Return data size:} & \locRds \\ + \end{array} \right] \vspace{2mm} \\ + \] + \item[\underline{Setting $\stackRdcx_{i}$:}] + we impose + \begin{enumerate} + \item $\miscOobFlag _{i + \locCopyMiscRowOffset} = 0$ \Then $\stackRdcx_{i} = 0$ \quad (\trash) + \item $\miscOobFlag _{i + \locCopyMiscRowOffset} = 1$ \Then $\stackRdcx_{i} = \locOobRdcx$ + \end{enumerate} + \item[\underline{Setting \mxpMod{} data:}] + \If $\miscMxpFlag _{i + \locCopyMiscRowOffset} = 1$ \Then we impose + \[ + \setMxpInstructionTypeFour {i}{\locCopyMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \locInst \\ + \utt{Deploys byte code:} & 0 \\ + \utt{Offset high part:} & \locTargetOffsetHi \\ + \utt{Offset low part:} & \locTargetOffsetLo \\ + \utt{Size high part:} & \locSizeHi \\ + \utt{Size low part:} & \locSizeLo \\ + \end{array} \right] + \] + \item[\underline{Setting $\stackMxpx_{i}$:}] + we impose + \begin{enumerate} + \item \If $\miscMxpFlag _{i + \locCopyMiscRowOffset} = 0$ \Then we impose $\stackMxpx_{i} = 0$ \quad (\trash) + \item \If $\miscMxpFlag _{i + \locCopyMiscRowOffset} = 1$ \Then we impose $\stackMxpx_{i} = \locMxpMxpx$ + \end{enumerate} + \item[\underline{Setting \mmuMod{} data:}] + \If $\miscMmuFlag _{i + \locCopyMiscRowOffset} = 1$ \Then we impose + \[ + \setMmuInstructionParametersAnyToRamWithPadding { + anchorRow = i , + relOffset = \locCopyMiscRowOffset , + sourceId = \locSourceId , + targetId = \cn_{i} , + sourceOffsetHi = \locSourceOffsetHi , + sourceOffsetLo = \locSourceOffsetLo , + targetOffsetLo = \locTargetOffsetLo , + size = \locSizeLo , + referenceOffset = \locReferenceOffset , + referenceSize = \locReferenceSize , + exoSum = \locExoSum , + } + % \setMmuInstructionParametersAnyToRamWithPadding {i}{\locCopyMiscRowOffset} + % \left[ \begin{array}{llr} + % \utt{Source ID:} & \locSourceId & (\bigstar) \\ + % \utt{Target ID:} & \cn_{i} \\ + % % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % \utt{Source offset high:} & \locSourceOffsetHi \\ + % \utt{Source offset low:} & \locSourceOffsetLo \\ + % \utt{Target offset low:} & \locTargetOffsetLo \\ + % \utt{Size:} & \locSizeLo \\ + % \utt{Reference offset:} & \locReferenceOffset & (\bigstar) \\ + % \utt{Reference size:} & \locReferenceSize & (\bigstar) \\ + % % \utt{Success bit:} & \col{success\_bit} \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \locExoSum & (\bigstar) \\ + % % \utt{Phase:} & \col{phase} \\ + % \end{array} \right] + \] + where the fields labeled with $(\bigstar)$ are (currently undefined) shorthands for which we now produce definitions + \begin{description} + \item[The \inst{CALLDATACOPY} case:] + \If $\locIsCdc = 1$ \Then + we impose + % \[ + % \left\{ \begin{array}{lcl} + % \locSourceId & \define & \cnCallDataContextNumber _{i + \locCopyCurrentContextRow} \\ + % \locReferenceOffset & \define & \cnCdo _{i + \locCopyCurrentContextRow} \\ + % \locReferenceSize & \define & \cnCds _{i + \locCopyCurrentContextRow} \\ + % \locExoSum & \define & 0 \\ + % \end{array} \right. + % \] + \[ + \left\{ \begin{array}{lcl} + \locSourceId & \define & \locCallDataContext \\ + \locReferenceOffset & \define & \locCdo \\ + \locReferenceSize & \define & \locCds \\ + \locExoSum & \define & 0 \\ + \end{array} \right. + \] + \item[The \inst{RETURNDATACOPY} case:] + \If $\locIsRdc = 1$ \Then + we impose + % \[ + % \left\{ \begin{array}{lcl} + % \locSourceId & \define & \cnReturner _{i + \locCopyCurrentContextRow} \\ + % \locReferenceOffset & \define & \cnRdo _{i + \locCopyCurrentContextRow} \\ + % \locReferenceSize & \define & \cnRds _{i + \locCopyCurrentContextRow} \\ + % \locExoSum & \define & 0 \\ + % \end{array} \right. + % \] + \[ + \left\{ \begin{array}{lcl} + \locSourceId & \define & \locReturnDataContext \\ + \locReferenceOffset & \define & \locRdo \\ + \locReferenceSize & \define & \locRds \\ + \locExoSum & \define & 0 \\ + \end{array} \right. + \] + \item[The \inst{CODECOPY} case:] + \If $\locIsCc = 1$ \Then + we impose + \[ + \left\{ \begin{array}{lcl} + \locSourceId & \define & \accCfi _{i + \locCopyCurrentAccountRow} \\ + \locReferenceOffset & \define & 0 \\ + \locReferenceSize & \define & \accCodesize _{i + \locCopyCurrentAccountRow} \\ + \locExoSum & \define & \exoWeightRom \\ + \end{array} \right. + \] + \item[The \inst{EXTCODECOPY} case:] + \If $\locIsExtcc = 1$ \Then + we impose + \[ + \left\{ \begin{array}{lcl} + \locSourceId & \define & \accCfi _{i + \locCopyOutsideAccountRowFirst} \\ + \locReferenceOffset & \define & 0 \\ + \locReferenceSize & \define & \accCodesize _{i + \locCopyOutsideAccountRowFirst} \cdot \accHasCode _{i + \locCopyOutsideAccountRowFirst} \\ + \locExoSum & \define & \exoWeightRom \\ + \end{array} \right. + \] + \end{description} + \end{description} + \end{description} + \saNote{} + We provide some explanations concerning the \locReferenceSize{} in the \inst{EXTCODECOPY} case. + The above addresses a subtlety concerning the interplay between \inst{EXTCODECOPY} (and \inst{EXTCODEHASH}) and \textbf{deployments}. + If the (trimmed) address parameter of an \inst{EXTCODECOPY} invocation points to an address currently undergoing deployment its code is considered to be empty (and indeed \inst{EXTCODEHASH} would return $\emptyKeccak$). + From the point of view of the arithmetization said address will have nonzero code size but we will have set its code hash to $\emptyKeccak$. + As a consequence will have $\accHasCode \equiv 0$ and the above makes it appear as though the target address' code is empty. + + \saNote{} For instructions raising the $\stackDecCopyFlag$ one has $\cmc = \xAhoy$. diff --git a/hub/instruction_handling/copy/shorthands.tex b/hub/instruction_handling/copy/shorthands.tex new file mode 100644 index 0000000..12706e4 --- /dev/null +++ b/hub/instruction_handling/copy/shorthands.tex @@ -0,0 +1,53 @@ +\begin{center} + \boxed{% + \text{The shorthands presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecCopyFlag_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \end{array} \right. + } +\end{center} + +We will use the following shorthands +\[ + \hspace*{-1.5cm} + \left\{ \begin{array}{lcl} + \locInst & \!\!\!\define\!\!\! & \stackInst _{i} \vspace{2mm} \\ + \locIsCdc & \!\!\!\define\!\!\! & \decFlag {1}_{i} \\ + \locIsRdc & \!\!\!\define\!\!\! & \decFlag {2}_{i} \\ + \locIsCc & \!\!\!\define\!\!\! & \decFlag {3}_{i} \\ + \locIsExtcc & \!\!\!\define\!\!\! & \decFlag {4}_{i} \vspace{2mm} \\ + \locTargetOffsetHi & \!\!\!\define\!\!\! & \stackItemValHi {1}_{i} \\ + \locTargetOffsetLo & \!\!\!\define\!\!\! & \stackItemValLo {1}_{i} \\ + \locSourceOffsetHi & \!\!\!\define\!\!\! & \stackItemValHi {2}_{i} \\ + \locSourceOffsetLo & \!\!\!\define\!\!\! & \stackItemValLo {2}_{i} \\ + \locSizeHi & \!\!\!\define\!\!\! & \stackItemValHi {3}_{i} \\ + \locSizeLo & \!\!\!\define\!\!\! & \stackItemValLo {3}_{i} \\ + \locAddressParamHi & \!\!\!\define\!\!\! & \stackItemValHi {4}_{i} \\ + \locAddressParamLo & \!\!\!\define\!\!\! & \stackItemValLo {4}_{i} \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcl} + \locOobRdcx & \!\!\!\define\!\!\! & \miscOobDataCol {7} _{i + \locCopyMiscRowOffset} \\ + \locMxpMxpx & \!\!\!\define\!\!\! & \miscMxpMxpx _{i + \locCopyMiscRowOffset} \\ + \locMxpGas & \!\!\!\define\!\!\! & \miscMxpGasMxp _{i + \locCopyMiscRowOffset} \vspace{2mm} \\ + \locCallDataContext & \!\!\!\define\!\!\! & \cnCallDataContextNumber _{i + \locCopyCurrentContextRow} \\ + \locCdo & \!\!\!\define\!\!\! & \cnCdo _{i + \locCopyCurrentContextRow} \\ + \locCds & \!\!\!\define\!\!\! & \cnCds _{i + \locCopyCurrentContextRow} \\ + \locReturnDataContext & \!\!\!\define\!\!\! & \cnReturner _{i + \locCopyCurrentContextRow} \\ + \locRdo & \!\!\!\define\!\!\! & \cnRdo _{i + \locCopyCurrentContextRow} \\ + \locRds & \!\!\!\define\!\!\! & \cnRds _{i + \locCopyCurrentContextRow} \vspace{2mm} \\ + \locAddressIsWarm & \!\!\!\define\!\!\! & \accWarmth _{i + \locCopyOutsideAccountRowFirst} \\ + \locHasCode & \!\!\!\define\!\!\! & \accHasCode _{i + \locCopyOutsideAccountRowFirst} \\ + \locCodeSize & \!\!\!\define\!\!\! & \accCodesize _{i + \locCopyOutsideAccountRowFirst} \\ + \locAddressCfi & \!\!\!\define\!\!\! & \accCfi _{i + \locCopyOutsideAccountRowFirst} \\ + \end{array} \right. +\] +\saNote{} In the above we use the following abbreviations: +\col{CDC}, \col{RDC}, \col{CC}, \col{EXTCC} stand for +\inst{CALLDATACOPY}, \inst{RETURNDATACOPY}, \inst{CODECOPY}, \inst{EXTCODECOPY} respectively. + + + + diff --git a/hub/instruction_handling/copy/specifics/calldatacopy.tex b/hub/instruction_handling/copy/specifics/calldatacopy.tex new file mode 100644 index 0000000..e1fd701 --- /dev/null +++ b/hub/instruction_handling/copy/specifics/calldatacopy.tex @@ -0,0 +1,45 @@ +% \begin{figure}[!ht] +% \centering +% \includegraphics[width=\textwidth]{instruction_handling/copy/flowcharts/cdc.png} +% \caption{General workflow for \inst{CALLDATACOPY}-type instructions.} +% \label{hub: call: fig: general processing} +% \end{figure} + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecCopyFlag _{i} & = & 1 \\ + \locIsCdc & = & 1 \\ + \stackSux _{i} + \stackSox _{i} & = & 0 \\ + \end{array} \right.} +\end{center} +In other words we are dealing with a \inst{CALLDATACOPY} instruction that doesn't raise a \suxSH{}. +The specialized constraints are as follows: +\begin{description} + % - [x] context stuff, + % - [x] gas cost stuff, + % - [∅] account stuff, + % - [∅] trimming stuff, + % - [∅] setting and unsetting warmth, + % - [∅] account remain unchanged otherwise, + % - [∅] etc ... + \item[\underline{\underline{Setting the gas cost:}}] + we only set the gas cost to the actual gas cost if no \mxpxSH{} has occurred (given no stack exception, that is): + \begin{enumerate} + \item \If $\stackMxpx _{i} = 1$ \Then $\gasCost_{i} = 0$ + \item \If $\stackOogx _{i} = 1$ \Then $\gasCost_{i} = \stackStaticGas_{i} + \locMxpGas$ + \item \If $\xAhoy _{i} = 0$ \Then $\gasCost_{i} = \stackStaticGas_{i} + \locMxpGas$ + \end{enumerate} + \saNote{} The above \emph{could} be subsumed under the single constraint + \[ + \gasCost _{i} = (\stackOogx _{i} + (1 - \xAhoy _{i})) \cdot (\stackStaticGas_{i} + \locMxpGas) \quad (\trash) + \] + \item[\underline{\underline{Setting the context-row $n^°(i + \locCopyCurrentContextRow)$:}}] + depending on whether the instruction produces an exception or not we either peek into the caller context (and provide it with empty return data) or inspect the current execution frame; we extract from it the following: call data offset, call data size and the datum of whether or not it is the root context; as such we impose + \begin{enumerate} + \item \If $\xAhoy _{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{\locCopyCallerContextRowSmall} $ (\trash) + \item \If $\xAhoy _{i} = 0$ \Then $\readContextData {i}{\locCopyCurrentContextRow}{\cn_{i}} $ + \end{enumerate} +\end{description} diff --git a/hub/instruction_handling/copy/specifics/codecopy.tex b/hub/instruction_handling/copy/specifics/codecopy.tex new file mode 100644 index 0000000..b2e7383 --- /dev/null +++ b/hub/instruction_handling/copy/specifics/codecopy.tex @@ -0,0 +1,79 @@ +% \begin{figure}[!ht] +% \centering +% \includegraphics[width=\textwidth]{instruction_handling/copy/flowcharts/cc.png} +% \caption{General workflow for \inst{CODECOPY} instructions.} +% \label{fig: hub: instruction handling: copy: codecopy: general processing} +% \end{figure} + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecCopyFlag _{i} & = & 1 \\ + \locIsCc & = & 1 \\ + \stackSux _{i} + \stackSox _{i} & = & 0 \\ + \end{array} \right.} +\end{center} +In other words we are dealing with a \inst{CODECOPY} instruction that doesn't raise a \suxSH{}. +Recall that this instruction either requires a context-row (if an exception occurs) or an account-row (otherwise.) +The specialized constraints are as follows: +\begin{description} + % - [x] context stuff, + % - [x] gas cost stuff, + % - [∅] account stuff, + % - [∅] trimming stuff, + % - [∅] setting and unsetting warmth, + % - [∅] account remain unchanged otherwise, + % - [∅] etc ... + \item[\underline{\underline{Setting the gas cost:}}] + we only set the gas cost to the actual gas cost if no \mxpxSH{} has occurred (given no stack exception, that is): + \begin{enumerate} + \item \If $\stackMxpx _{i} = 1$ \Then $\gasCost_{i} = 0$ + \item \If $\stackOogx _{i} = 1$ \Then $\gasCost_{i} = \stackStaticGas_{i} + \locMxpGas$ + \item \If $\xAhoy _{i} = 0$ \Then $\gasCost_{i} = \stackStaticGas_{i} + \locMxpGas$ + \end{enumerate} + \saNote{} The above \emph{could} be subsumed under the single constraint + \[ + \gasCost _{i} = (\stackOogx _{i} + (1 - \xAhoy _{i})) \cdot (\stackStaticGas_{i} + \locMxpGas) \quad (\trash) + \] + \item[\underline{\underline{Exceptional \inst{CODECOPY} case:}}] + we impose that + \begin{enumerate} + \item \If $\xAhoy _{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{\locCopyCallerContextRowSmall} $ (\trash) + \end{enumerate} + \saNote{} Depending on whether the instruction produces an exception or not we either peek into the caller context (and provide it with empty return data) or inspect the current execution frame; we extract from it the following: call data offset, call data size and the datum of whether or not it is the root context. + \item[\underline{\underline{Unexceptional \inst{CODECOPY} case:}}] + \If $\xAhoy _{i} = 0$ \Then we impose + \begin{description} + \item[\underline{Setting the context row $n^°(i + \locCopyCurrentContextRow)$:}] + we impose $\readContextData {i}{\locCopyCurrentContextRow}{\cn_{i}}$ + \item[\underline{Setting the account row $n^°(i + \locCopyCurrentAccountRow)$:}] + we impose + \[ + \left\{ \begin{array}{lclr} + \accAddressHi _{i + \locCopyCurrentAccountRow} & = & \cnCodeAddress\high _{i + \locCopyCurrentContextRow} \\ + \accAddressLo _{i + \locCopyCurrentAccountRow} & = & \cnCodeAddress\low _{i + \locCopyCurrentContextRow} \\ + \accDepNumber _{i + \locCopyCurrentAccountRow} & = & \cnAccDepNum _{i + \locCopyCurrentContextRow} & (\trash) \\ + \accCfi _{i + \locCopyCurrentAccountRow} & = & \cfi_{i} & (\trash) \\ + \accRomLexFlag _{i + \locCopyCurrentAccountRow} & = & \rOne & (\trash) \\ + \multicolumn{4}{l}{\accSameBalance {i}{\locCopyCurrentAccountRow}} \\ + \multicolumn{4}{l}{\accSameNonce {i}{\locCopyCurrentAccountRow}} \\ + \multicolumn{4}{l}{\accSameCode {i}{\locCopyCurrentAccountRow}} \\ + \multicolumn{4}{l}{\accSameDeployment {i}{\locCopyCurrentAccountRow}} \\ + \multicolumn{4}{l}{\accSameWarmth {i}{\locCopyCurrentAccountRow}} \\ + \multicolumn{4}{l}{\accSameMarkedForSelfdestructFlag {i}{\locCopyCurrentAccountRow}} \\ + \multicolumn{4}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locCopyCurrentAccountRow, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locCopyCurrentAccountRow}{0}} \\ + \end{array} \right. + \] + \end{description} + % % I don't do this anymore ... even though it's valid; this avoids useless complications; + % \saNote{} We provide some explanation. There is no need to specify the address nor the deployment number or status as these are deduced in the \romLexMod{} module from the \accCfi{}. Observe furthermore that the lookup to the \romLexMod{} module \textbf{is active} as we impose $\accRomLexFlag \equiv \one$. +\end{description} diff --git a/hub/instruction_handling/copy/specifics/extcodecopy.tex b/hub/instruction_handling/copy/specifics/extcodecopy.tex new file mode 100644 index 0000000..3d563fa --- /dev/null +++ b/hub/instruction_handling/copy/specifics/extcodecopy.tex @@ -0,0 +1,175 @@ +% \begin{figure}[!ht] +% \centering +% \includegraphics[width=\textwidth]{instruction_handling/copy/flowcharts/extcc.png} +% \caption{General workflow for \inst{EXTCODECOPY} instructions. We use the abbreviation $\rho := \cnRevStamp_{i}$.} +% \label{fig: hub: instruction handling: copy: extcodecopy: general processing} +% \end{figure} + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecCopyFlag _{i} & = & 1 \\ + \locIsExtcc & = & 1 \\ + \stackSux _{i} + \stackSox _{i} & = & 0 \\ + \end{array} \right.} +\end{center} +The \inst{EXTCODECOPY} instruction is the most complex of all instructions in the \inst{COPY} instruction family. +Indeed it \emph{may} require any of the following +(\emph{a}) trimming of the address argument +(\emph{b}) loading bytecode into the \romMod{} +(\emph{c}) considering whether the target address is undoing deployment or not +(\emph{d}) turning on the target account's warmth +(\emph{e}) and, in case of an upcoming revert, undoing the previous turning on of the target account's warmth. +Recall that depending on whether the instruction produces an \mxpxSH{} or not we either peek into the caller context (and provide it with empty return data) +or inspect the called account. The specialized constraints are as follows. +\begin{description} + % - [x] context stuff, + % - [x] gas cost stuff, + % - [ ] account stuff, + % - [x] trimming stuff, + % - [x] cfi stuff, + % - [ ] setting and unsetting warmth, + % - [ ] account remain unchanged otherwise, + % - [∅] etc ... + \item[\underline{\underline{Setting the gas cost:}}] + we only set the gas cost to the actual gas cost if no \mxpxSH{} has occurred (given no stack exception, that is): + \begin{enumerate} + \item \If $\stackMxpx _{i} = 1$ \Then $\gasCost_{i} = 0$ + \item \If $\stackMxpx _{i} = 0$ \Then + \[ + \gasCost_{i} + = + \left[ \begin{array}{cl} + + & \stackStaticGas_{i} \\ + + & \locMxpGas \\ + + & \left[\begin{array}{crcl} + + & \locAddressIsWarm & \cdot & G_\text{warmaccess} \\ + + & (1 - \locAddressIsWarm) & \cdot & G_\text{coldaccountaccess} \\ + \end{array} \right] \\ + \end{array} \right] + \] + \end{enumerate} + \item[\underline{\underline{The \mxpxSH{} case:}}] + \If $\stackMxpx_{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{\locCopyCallerContextRowSmall} $ + \item[\underline{\underline{The \oogxSH{} case:}}] + \If $\stackOogx _{i} = 1$ \Then + we impose the following: + \begin{description} + \item[\underline{Setting the account row $n^°(i + \locCopyOutsideAccountRowFirst)$:}] + we impose that + \[ + \left\{ \begin{array}{lclr} + \multicolumn{4}{l}{\accTrimAddress + {i}{\locCopyOutsideAccountRowFirst} + {\locAddressParamHi} + {\locAddressParamLo}} \\ + \accRomLexFlag _{i + \locCopyOutsideAccountRowFirst} & = & \rZero \\ + \multicolumn{4}{l}{\accSameBalance {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameNonce {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameCode {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameDeployment {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameWarmth {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameMarkedForSelfdestructFlag {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locCopyOutsideAccountRowFirst, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locCopyOutsideAccountRowFirst}{0}} \\ + \end{array} \right. + \] + \item[\underline{Setting the context row $n^°(i + \locCopyCallerContextRowLarge )$:}] + we impose that + $\executionProvidesEmptyReturnData {i}{\locCopyCallerContextRowLarge} $ + \end{description} + \item[\underline{\underline{Specifying \locTriggerCfi{}:}}] + \inst{EXTCODECOPY} is the only instruction in the \inst{COPY}-family that \textbf{may} require loading (new) bytecode into the \romMod{} module; + this is required precisely for \textbf{unexceptional} executions that copy a \textbf{nonzero} number of bytes from an address with \textbf{nonempty bytecode}; + as such we impose: + \[ + \locTriggerCfi = \locIsExtcc \cdot \locTriggerMmu \cdot \locHasCode + \] + \saNote{} By construction the \locTriggerMmu{} flag, see section~(\ref{locTriggerMmu for the copy family}), \locTriggerMmu{} is off whenever an exception occurs or the instruction is unexceptional but has zero size. + \item[\underline{\underline{The unexceptional, reverted case:}}] + \If $\xAhoy_{i} = 0$ \et $\cnWillRev_{i} = 1$ \Then + \begin{description} + \item[\underline{The ``doing'' account-row $n^°(i + \locCopyOutsideAccountRowFirst )$:}] + we impose that + \[ + \left\{ \begin{array}{lclr} + \multicolumn{4}{l}{\accTrimAddress + {i}{\locCopyOutsideAccountRowFirst} + {\locAddressParamHi} + {\locAddressParamLo}} \\ + \accRomLexFlag _{i + 2} & = & \locTriggerCfi \vspace{2mm} \\ + \multicolumn{4}{l}{\accSameBalance {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameNonce {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameCode {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameDeployment {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accTurnOnWarmth {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameMarkedForSelfdestructFlag {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locCopyOutsideAccountRowFirst, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locCopyOutsideAccountRowFirst}{0}} \\ + \end{array} \right. + \] + \item[\underline{The ``undoing'' account-row $n^°(i + \locCopyOutsideAccountRowSecond )$:}] + we impose that + \[ + \left\{ \begin{array}{lclr} + \multicolumn{4}{l}{\accSameAddr {i}{\locCopyOutsideAccountRowSecond}{\locCopyOutsideAccountRowFirst}} \\ + \accRomLexFlag _{i + \locCopyOutsideAccountRowSecond} & = & 0 & (\trash) \vspace{2mm} \\ + \multicolumn{4}{l}{\accUndoBalanceUpdate {i}{\locCopyOutsideAccountRowSecond}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accUndoNonceUpdate {i}{\locCopyOutsideAccountRowSecond}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accUndoCodeUpdate {i}{\locCopyOutsideAccountRowSecond}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\locCopyOutsideAccountRowSecond}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accUndoWarmthUpdate {i}{\locCopyOutsideAccountRowSecond}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameMarkedForSelfdestructFlag {i}{\locCopyOutsideAccountRowSecond}} \\ + \multicolumn{4}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locCopyOutsideAccountRowSecond, + subOffset = 1, + } + } \\ + % {i}{\locCopyOutsideAccountRowSecond}{1}} + \end{array} \right. + \] + \end{description} + \saNote{} With the the first constraints we impose a lookup to the \trmMod{} module (and hence the correction of the ``address parameter'' of \inst{EXTCODECOPY}.) + With the second constraints we impose a lookup to the \romLexMod{} (and hence get access to the relevant \CFI{}.) + \item[\underline{\underline{The unexceptional, unreverted case:}}] + \If $\xAhoy_{i} = 0$ \et $\cnWillRev_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \multicolumn{4}{l}{\accTrimAddress + {i}{\locCopyOutsideAccountRowFirst} + {\locAddressParamHi} + {\locAddressParamLo}} \\ + \accRomLexFlag _{i + \locCopyOutsideAccountRowFirst} & = & \locTriggerCfi \vspace{2mm} \\ + \multicolumn{4}{l}{\accSameBalance {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameNonce {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameCode {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameDeployment {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accTurnOnWarmth {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{\accSameMarkedForSelfdestructFlag {i}{\locCopyOutsideAccountRowFirst}} \\ + \multicolumn{4}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locCopyOutsideAccountRowFirst, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locCopyOutsideAccountRowFirst}{0}} \\ + \end{array} \right. + \] +\end{description} diff --git a/hub/instruction_handling/copy/specifics/returndatacopy.tex b/hub/instruction_handling/copy/specifics/returndatacopy.tex new file mode 100644 index 0000000..660a260 --- /dev/null +++ b/hub/instruction_handling/copy/specifics/returndatacopy.tex @@ -0,0 +1,55 @@ +% \begin{figure}[!ht] +% \centering +% \includegraphics[width=\textwidth]{instruction_handling/copy/flowcharts/rdc.png} +% \caption{General workflow for \inst{RETURNDATACOPY} instructions.} +% \label{fig: hub: instruction handling: copy: returndatacopy: general processing} +% \end{figure} + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecCopyFlag _{i} & = & 1 \\ + \locIsRdc & = & 1 \\ + \stackSux _{i} + \stackSox _{i} & = & 0 \\ + \end{array} \right.} +\end{center} +In other words we are dealing with a \inst{RETURNDATACOPY} instruction that doesn't raise a \suxSH{}. +The specialized constraints are as follows: +\begin{description} + % - [x] context stuff, + % - [x] gas cost stuff, + % - [∅] account stuff, + % - [∅] trimming stuff, + % - [∅] setting and unsetting warmth, + % - [∅] account remain unchanged otherwise, + % - [∅] etc ... + \item[\underline{\underline{Setting the gas cost:}}] + we only set the gas cost to the actual gas cost if no \mxpxSH{} has occurred (given no stack exception, that is): + \begin{enumerate} + \item \If $\stackRdcx _{i} = 1$ \Then $\gasCost_{i} = 0$ + \item \If $\stackMxpx _{i} = 1$ \Then $\gasCost_{i} = 0$ + \item \If $\stackOogx _{i} = 1$ \Then $\gasCost_{i} = \stackStaticGas_{i} + \locMxpGas$ + \item \If $\xAhoy _{i} = 0$ \Then $\gasCost_{i} = \stackStaticGas_{i} + \locMxpGas$ + \end{enumerate} + \saNote{} The above \emph{could} be subsumed under the single constraint + \[ + \gasCost _{i} = (\stackOogx _{i} + (1 - \xAhoy _{i})) \cdot (\stackStaticGas_{i} + \locMxpGas) \quad (\trash) + \] + \item[\underline{\underline{Setting the context-row $n^°(i + \locCopyCurrentContextRow)$:}}] + depending on whether the instruction produces an exception or not we either peek into the caller context (and provide it with empty return data) or inspect the current execution frame and extract from it the following: call data offset, call data size and whether or not it is the root context; as such we impose + \begin{enumerate} + \item \If $\stackRdcx _{i} = 1$ \Then + \[ + \left\{ \begin{array}{l} + \readContextData {i}{\locCopyCurrentContextRow}{\cn_{i}} \\ + \executionProvidesEmptyReturnData {i}{\locCopyCallerContextRowLarge} (\trash) \\ + \end{array} \right. + \] + \item \If $\stackMxpx _{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{\locCopyCurrentContextRow} $ (\trash) + \item \If $\stackOogx _{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{\locCopyCurrentContextRow} $ (\trash) + \item \If $\xAhoy _{i} = 0$ \Then $\readContextData {i}{\locCopyCurrentContextRow}{\cn_{i}}$ + \end{enumerate} + \saNote{} We remind the reader that raising the \rdcxSH{} requires \emph{two} context rows. +\end{description} diff --git a/hub/instruction_handling/create/_inputs.tex b/hub/instruction_handling/create/_inputs.tex new file mode 100644 index 0000000..76ed8b2 --- /dev/null +++ b/hub/instruction_handling/create/_inputs.tex @@ -0,0 +1,10 @@ +\input{instruction_handling/create/_local} +\subsubsection{Introduction} \label{hub: instruction handling: create: intro} \input{instruction_handling/create/intro} +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: create: instruction flags} \input{instruction_handling/create/flags} +\subsubsection{Highlevel \inst{CREATE} processing diagrams} \label{hub: instruction handling: create: high level diagram} \input{instruction_handling/create/lua/_inputs} +\subsubsection{Forward and backward setting of scenario row \lispDone{}} \label{hub: instruction handling: create: scenario bedrock} \input{instruction_handling/create/bedrock} +\subsubsection{Peeking flag shorthands \lispDone{}} \label{hub: instruction handling: create: peeking flags shorthands} \input{instruction_handling/create/peeking_flag_shorthands} +\subsubsection{Non-stack-rows and peeking flags \lispDone{}} \label{hub: instruction handling: create: non stack rows} \input{instruction_handling/create/non_stack_rows} +\subsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: create: shorthands} \input{instruction_handling/create/shorthands} +\subsubsection{Module triggers \lispDone{}} \label{hub: instruction handling: create: module triggers} \input{instruction_handling/create/triggers/_inputs} +\subsubsection{Constraints \lispDone{}} \label{hub: instruction handling: create: generalities} \input{instruction_handling/create/generalities/_inputs} diff --git a/hub/instruction_handling/create/_local.tex b/hub/instruction_handling/create/_local.tex new file mode 100644 index 0000000..6b044ca --- /dev/null +++ b/hub/instruction_handling/create/_local.tex @@ -0,0 +1,139 @@ +\def\locInst {\col{instruction}} +\def\locIsCreate {\col{is\_CREATE}} +\def\locIsCreateTwo {\col{is\_CREATE2}} +\def\locSizeHi {\col{STACK\_size\_hi}} +\def\locSizeLo {\col{STACK\_size\_lo}} +\def\locOffsetHi {\col{STACK\_offset\_hi}} +\def\locOffsetLo {\col{STACK\_offset\_lo}} +\def\locOutputHi {\col{STACK\_output\_hi}} +\def\locOutputLo {\col{STACK\_output\_lo}} +\def\locSaltHi {\col{STACK\_salt\_hi}} +\def\locSaltLo {\col{STACK\_salt\_lo}} +\def\locValueHi {\col{STACK\_value\_hi}} +\def\locValueLo {\col{STACK\_value\_lo}} +\def\locIsStatic {\col{current\_context\_is\_static}} +\def\locStaticx {\col{STACK\_staticx}} +\def\locMxpx {\col{STACK\_mxpx}} +\def\locOogx {\col{STACK\_oogx}} +% +\def\relevantValue {\texttt{}} +% +\def\locTriggerHashInfo {\col{trigger\_\hashInfoMod}} +\def\locHashInfoStamp {\col{hash\_info\_stamp}} +\def\locInitCodeHashHi {\col{init\_code\_hash\_hi}} +\def\locInitCodeHashLo {\col{init\_code\_hash\_lo}} +\def\locInitCodeSize {\col{init\_code\_size}} +%} +\def\locTriggerMmu {\col{trigger\_\mmuMod}} +\def\locHashInitCode {\col{hash\_init\_code}} +\def\locHashInitCodeAndSendToRom {\col{hash\_init\_code\_and\_send\_to\_\romMod}} +\def\locSendInitCodeToRom {\col{send\_init\_code\_to\_\romMod}} +\def\locMmuInst {\col{mmu\_inst}} +%} +\def\locTriggerMxp {\col{trigger\_\mxpMod}} +\def\locMxpMxpx {\col{\mxpMod\_mxpx}} +\def\locMxpGas {\col{\mxpMod\_gas}} +\def\locMxpMtntop {\col{\mxpMod\_mtntop}} +% +\def\locTriggerOob {\col{trigger\_\oobMod}} +\def\locOobAbortingCondition {\col{\oobMod\_aborting\_condition}} +\def\locOobFailureCondition {\col{\oobMod\_failure\_condition}} +%} +\def\locTriggerRlpAddr {\col{trigger\_\rlpAddrMod}} +\def\locRlpAddrRecipe {\col{address\_computation\_recipe}} +\def\locCreateeAddressHi {\col{createe\_address\_hi}} +\def\locCreateeAddressLo {\col{createe\_address\_lo}} +%} +\def\locTriggerRomLex {\col{trigger\_\romLexMod}} +\def\locDepCfi {\col{deployment\_cfi} } +\def\locRomLexFlag {\col{\romLexMod\_flag}} +% +\def\locTriggerStp {\col{trigger\_\stpMod}} +\def\locStpGasPoop {\col{\stpMod\_(63/64)ths\_gas}} +\def\locStpOogx {\col{\stpMod\_oogx}} +% +\def\locCnWillRevert {\col{creator\_will\_revert}} +\def\locCnRevertStamp {\col{creator\_revert\_stamp}} +\def\locComputeAddress {\col{compute\_address}} +\def\locCreatorAddressHi {\col{creator\_address\_hi}} +\def\locCreatorAddressLo {\col{creator\_address\_lo}} +\def\locCsd {\col{current\_context\_csd}} +\def\locCreatorNonce {\col{creator\_nonce}} +\def\locCreatorBalance {\col{creator\_balance}} +%} +\def\locCreateeSelfReverts {\col{createe\_self\_reverts}} +\def\locCreateeRevertStamp {\col{createe\_revert\_stamp}} +\def\locCreateeNonce {\col{createe\_nonce}} +\def\locCreateeHasCode {\col{createe\_has\_code}} +\def\locCreateAborts {\col{aborts}} +\def\locCreateFCond {\col{failure\_condition}} +\def\locMmuInst {\col{mmu\_inst}} +\def\locMmuParamOne {\col{mmu\_param\_one}} +\def\locMmuParamTwo {\col{mmu\_param\_two}} + +\def\relofCreateException {\relof\texttt{\_exception}} +\def\relofCreateAbort {\relof\texttt{\_aborting\_condition}} +\def\relofCreateFailureConditionWillRevert {\relof\texttt{\_F\_condition\_will\_revert}} +\def\relofCreateFailureConditionWontRevert {\relof\texttt{\_F\_condition\_wont\_revert}} +\def\relofCreateEmptyCodeWontRevert {\relof\texttt{\_empty\_init\_code\_failure\_will\_revert}} +\def\relofCreateEmptyCodeWillRevert {\relof\texttt{\_empty\_init\_code\_failure\_wont\_revert}} +\def\relofCreateNonEmptyFailureWillRevert {\relof\texttt{\_failure\_will\_revert}} +\def\relofCreateNonEmptyFailureWontRevert {\relof\texttt{\_failure\_wont\_revert}} +\def\relofCreateNonEmptySuccessWillRevert {\relof\texttt{\_success\_will\_revert}} +\def\relofCreateNonEmptySuccessWontRevert {\relof\texttt{\_success\_wont\_revert}} + +\def\peekingSumStandardPrefix {\col {std\_prefix}} +\def\peekingSumStaticx {\col {flag\_sum\_staticx}} +\def\peekingSumMxpx {\col {flag\_sum\_mxpx}} +\def\peekingSumOogx {\col {flag\_sum\_oogx}} +\def\peekingSumAbort {\col {flag\_sum\_abort}} +\def\peekingSumFCondWillRevert {\col {flag\_sum\_fcond\_will\_revert}} +\def\peekingSumFCondWontRevert {\col {flag\_sum\_fcond\_wont\_revert}} +\def\peekingSumSanctionedCreatePrefix {\col {sanctioned\_prefix}} +\def\peekingSumEmptyInitCodeWillRevert {\colm{flag\_sum\_empty\_init\_will\_revert}} +\def\peekingSumEmptyInitCodeWontRevert {\colm{flag\_sum\_empty\_init\_wont\_revert}} +\def\peekingSumNonEmptyInitCodeFailureWillRevert {\colm{flag\_sum\_nonempty\_init\_failure\_will\_revert}} +\def\peekingSumNonEmptyInitCodeFailureWontRevert {\colm{flag\_sum\_nonempty\_init\_failure\_wont\_revert}} +\def\peekingSumNonEmptyInitCodeSuccessWillRevert {\colm{flag\_sum\_nonempty\_init\_success\_will\_revert}} +\def\peekingSumNonEmptyInitCodeSuccessWontRevert {\colm{flag\_sum\_nonempty\_init\_success\_wont\_revert}} + +\def\locTgtId {\col{tgt\_id}} +\def\locAuxId {\col{aux\_id}} +\def\locExoSum {\col{exo\_sum}} + + + +% CALL specific row offset constants +\def\createFirstStackRowOffset {\greenm{2}} +\def\createSecondStackRowOffset {\greenm{1}} +\def\createCurrentContextRowOffset {\yellowm{1}} +\def\createMiscRowOffset {\yellowm{2}} +\def\createFirstCreatorAccountRowOffset {\yellowm{3}} +\def\createFirstCreateeAccountRowOffset {\yellowm{4}} +\def\createSecondCreatorAccountRowOffset {\yellowm{5}} +\def\createSecondCreateeAccountRowOffset {\yellowm{6}} +\def\createThirdCreatorAccountRowOffset {\yellowm{7}} +\def\createThirdCreateeAccountRowOffset {\yellowm{8}} + +% Exception +\def\createExceptionCallerContextRowOffset {\orangem{3}} + +% Abort +\def\createAbortCurrentAccountRowOffset {\yellowm{3}} +\def\createAbortCurrentContextRowOffset {\orangem{4}} + +% Failure condition (will or won't revert) +\def\createFCondWillRevertCurrentContextRowOffset {\orangem{7}} +\def\createFCondWontRevertCurrentContextRowOffset {\orangem{5}} + +% Empty initialization code (will or won't revert) +\def\createEmptyInitCodeWillRevertCurrentContextRowOffset {\orangem{7}} +\def\createEmptyInitCodeWontRevertCurrentContextRowOffset {\orangem{5}} + +% Nonmpty initialization code failure (will or won't revert) +\def\createNonemptyInitCodeFailureWillRevertNewContextRowOffset {\orangem{9}} +\def\createNonemptyInitCodeFailureWontRevertNewContextRowOffset {\orangem{7}} + +% Nonmpty initialization code success (will or won't revert) +\def\createNonemptyInitCodeSuccessWillRevertNewContextRowOffset {\orangem{7}} +\def\createNonemptyInitCodeSuccessWontRevertNewContextRowOffset {\orangem{5}} diff --git a/hub/instruction_handling/create/bedrock.tex b/hub/instruction_handling/create/bedrock.tex new file mode 100644 index 0000000..81856b0 --- /dev/null +++ b/hub/instruction_handling/create/bedrock.tex @@ -0,0 +1,37 @@ +We impose the following constraints. +\begin{description} + \item[\underline{Forward setting of \emph{some} \inst{CREATE}-scenario:}] we enforce that + \[ + \If + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecCreateFlag_{i} & = & 1 \\ + \ct_{i} & = & 0 \\ + \stackSux_{i} & = & 0 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \peekScenario_{i + 2} & = & 1 \\ + \scenCreateSum_{i + 2} & = & 1 \\ + \end{array} \right. + \] +\end{description} +\saNote{} In the upcoming sections row $n^°(i + 2)$ will become the new vantage point for dealing with \inst{CREATE} instructions. +\begin{description} + \item[\underline{Backwards setting of the \inst{CREATE}-type instruction:}] we \emph{may} want to enforce that + \[ + \underbrace{\If + \left\{ \begin{array}{lcl} + \peekScenario_{i} & = & 1 \\ + \scenCreateSum_{i} & = & 1 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \peekStack _{i - \createFirstStackRowOffset} & = & 1 \\ + \stackDecCreateFlag _{i - \createFirstStackRowOffset} & = & 1 \\ + \ct _{i - \createFirstStackRowOffset} & = & 0 \\ + \stackSux _{i - \createFirstStackRowOffset} & = & 0 \\ + \end{array} \right.}_{\displaystyle (\trash)} + \] +\end{description} +\saNote{} Recall that \inst{CREATE}-type instructions are $\TLI$. The above thus sets the first non stack row of such an instruction. diff --git a/hub/instruction_handling/create/flags.tex b/hub/instruction_handling/create/flags.tex new file mode 100644 index 0000000..7595c95 --- /dev/null +++ b/hub/instruction_handling/create/flags.tex @@ -0,0 +1,8 @@ +\[ + \begin{array}{|l||c|c||c|c||c|c|} \hline + \INST & \tli & \stackDecCreateFlag & \decFlag{1} & \decFlag{2} & \decStaticInst & \stackDecMxpFlag \\ \hline\hline + \inst{CREATE} & \oneCell & \oneCell & \oneCell & \zero & \oneCell & \oneCell \\ \hline + \inst{CREATE2} & \oneCell & \oneCell & \zero & \oneCell & \oneCell & \oneCell \\ \hline + \end{array} +\] +\saNote{} The $\decFlag{1}$ differentiates between the two \inst{CREATE}-type instructions. diff --git a/hub/instruction_handling/create/generalities/_inputs.tex b/hub/instruction_handling/create/generalities/_inputs.tex new file mode 100644 index 0000000..33fdf3e --- /dev/null +++ b/hub/instruction_handling/create/generalities/_inputs.tex @@ -0,0 +1,8 @@ +\subsubsection{Generalities for all \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: all} \input{instruction_handling/create/generalities/all} +\subsubsection{Exceptional \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: exceptional} \input{instruction_handling/create/generalities/exceptional} +\subsubsection{Unexceptional \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: unexceptional} \input{instruction_handling/create/generalities/unexceptional} +\subsubsection{Unexceptional, unaborted \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: unexceptional, unaborted} \input{instruction_handling/create/generalities/unaborted} +\subsubsection{One step reverting \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: simply reverting} \input{instruction_handling/create/generalities/revert_in_one_step} +\subsubsection{Deployment failures \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: deployment failures} \input{instruction_handling/create/generalities/failure} +\subsubsection{Two step reverting \inst{CREATE}'s \lispDone{}} \label{hub: instruction handling: create: generalities: reverted deployment failure} \input{instruction_handling/create/generalities/revert_in_two_steps} +\subsubsection{Final context row \lispDone{}} \label{hub: instruction handling: create: generalities: final context row} \input{instruction_handling/create/generalities/final_context_row} diff --git a/hub/instruction_handling/create/generalities/all.tex b/hub/instruction_handling/create/generalities/all.tex new file mode 100644 index 0000000..232e9fc --- /dev/null +++ b/hub/instruction_handling/create/generalities/all.tex @@ -0,0 +1,301 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateSum _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +The present section deals with generalities pertaining to \inst{CREATE}-type instructions. These constraints hold regardless of anything else. +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\createSP_{i - 2}\big[ \locIsCreateTwo \big]$; + \item[\underline{Setting the ``deployment address'' stack output:}] + we impose + \begin{enumerate} + \item \If $\scenCreateSuccess_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \locOutputHi & = & 0 \\ + \locOutputLo & = & 0 \\ + \end{array} \right. + \] + \item \If $\scenCreateSuccess_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locOutputHi & = & \locCreateeAddressHi \\ + \locOutputLo & = & \locCreateeAddressLo \\ + \end{array} \right. + \] + \end{enumerate} + \item[\underline{Triggering the \hashInfoMod{} module and settings:}] + we impose + \[ + \maybeRequestHash { + anchorRow = i, + relOffset = - \createFirstStackRowOffset, + requestBit = \locTriggerHashInfo, + } + \] + \item[\underline{Setting the context-row $n^°(i + \createCurrentContextRowOffset)$:}] + we unconditionally impose + \[ + \readContextData {i}{\createCurrentContextRowOffset} {\cn_{i}} + \] + \item[\underline{Setting the \staticxSH{}:}] + we unconditionally impose + \[ + \locStaticx = \locIsStatic + \] + \item[\underline{Setting the module flags of miscellaneous-row $n^°(i + \createMiscRowOffset)$::}] + every processing path for \inst{CREATE}-type instructions contains a single \textbf{miscellaneous-row} + \[ + \weightedMiscFlagSum + {i}{\createMiscRowOffset} + = + \left[ \begin{array}{lcl} + \miscMmuWeight & \cdot & \locTriggerMmu \\ + \miscMxpWeight & \cdot & \locTriggerMxp \\ + \miscOobWeight & \cdot & \locTriggerOob \\ + \miscStpWeight & \cdot & \locTriggerStp \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \createMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \createMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag _{i + \createMiscRowOffset} & = & \locTriggerMxp & (\trash) \\ + \miscOobFlag _{i + \createMiscRowOffset} & = & \locTriggerOob & (\trash) \\ + \miscStpFlag _{i + \createMiscRowOffset} & = & \locTriggerStp & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the \mxpMod{} instruction:}] + we impose \If $\miscMxpFlag_{i + \createMiscRowOffset} = 1$ \Then + \[ + \setMxpInstructionTypeFour + {i}{\createMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \locInst \\ + \utt{Deploys byte code:} & 0 \\ + \utt{Offset high part:} & \locOffsetHi \\ + \utt{Offset low part:} & \locOffsetLo \\ + \utt{Size high part:} & \locSizeHi \\ + \utt{Size low part:} & \locSizeLo \\ + \end{array} \right] + \] + \item[\underline{Setting the \mxpxSH{}:}] + we impose + \begin{enumerate} + \item \If $\miscMxpFlag_{i + \createMiscRowOffset} = 0$ \Then $\locMxpx = 0$ \quad (\trash) + \item \If $\miscMxpFlag_{i + \createMiscRowOffset} = 1$ \Then $\locMxpx = \locMxpMxpx$ + \end{enumerate} + \item[\underline{Setting the \stpMod{} instruction:}] + we impose \If $\miscStpFlag_{i + \createMiscRowOffset} = 1$ \Then + \[ + \setStpInstructionCreate{ + anchorRow = i, + relOffset = \createMiscRowOffset, + instruction = \locInst, + valueHi = \locValueHi, + valueLo = \locValueLo, + mxpGas = \locMxpGas, + } + % \left\{ \begin{array}{lcl} + % % \miscStpFlag _{i + \createMiscRowOffset} & = & \one \vspace{2mm} \\ + % \miscStpInst _{i + \createMiscRowOffset} & = & \locInst \\ + % \miscStpGasHi _{i + \createMiscRowOffset} & = & \gZero \\ + % \miscStpGasLo _{i + \createMiscRowOffset} & = & \gZero \\ + % \miscStpValueHi _{i + \createMiscRowOffset} & = & \locValueHi \\ + % \miscStpValueLo _{i + \createMiscRowOffset} & = & \locValueLo \\ + % \miscStpAccExists _{i + \createMiscRowOffset} & = & 0 \\ + % \miscStpAccWarmth _{i + \createMiscRowOffset} & = & 0 \\ + % \miscStpOogx _{i + \createMiscRowOffset} & = & \locOogx \\ + % % \gasActual _{i + \createMiscRowOffset} & = & \\ % shared column + % % \gasCost _{i + \createMiscRowOffset} & = & \\ % shared column + % % \miscMxpGasMxp _{i + \createMiscRowOffset} & = & \\ % mxp gas (available on the same row) + % \miscStpGasUpfront _{i + \createMiscRowOffset} & = & \relevantValue \\ + % \miscStpGasPoop _{i + \createMiscRowOffset} & = & \relevantValue \\ + % \miscStpGasStipend _{i + \createMiscRowOffset} & = & \relevantValue \\ + % \end{array} \right. + \] + \saNote{} The \stpMod{} computes the gas cost $\gasCost_{i}$ of \inst{CREATE}-type instructions; it also, verifies \locOogx{}. + \item[\underline{Setting the \oogxSH{}:}] + we impose + \begin{enumerate} + \item \If $\miscStpFlag_{i + \createMiscRowOffset} = 0$ \Then $\locOogx = 0$ \quad (\trash) + \item \If $\miscStpFlag_{i + \createMiscRowOffset} = 1$ \Then $\locOogx = \locStpOogx$ + \end{enumerate} + \item[\underline{Setting the \oobMod{} instruction:}] + we impose \If $\miscOobFlag_{i + \createMiscRowOffset} = 1$ \Then + \[ + \setOobInstructionCreate { + anchorRow = i, + relOffset = \createMiscRowOffset, + valueHi = \locValueHi, + valueLo = \locValueLo, + balance = \locCreatorBalance, + nonce = \locCreateeNonce, + hasCode = \locCreateeHasCode, + callStackDepth = \locCsd, + } + % \vspace{2mm} \\ + % \left\{ \begin{array}{lclc} + % \miscOobDataCol{1} _{i + 1} & = & \locValueHi \\ + % \miscOobDataCol{2} _{i + 1} & = & \locValueLo \\ + % \miscOobDataCol{3} _{i + 1} & = & \locCreatorBalance \\ + % \miscOobDataCol{4} _{i + 1} & = & \locCreateeNonce \\ + % \miscOobDataCol{5} _{i + 1} & = & \locCreateeHasCode \\ + % \miscOobDataCol{6} _{i + 1} & = & \locCsd \\ + % \miscOobInst _{i + 1} & = & \oobInstCreate \\ + % \miscOobDataCol{7} _{i + 1} & = & \scenCreateAbort_{i} \\ + % \miscOobDataCol{8} _{i + 1} & = & \scenCreateFCond_{i} \\ + % \end{array} \right. + \] + where we define the following shorthands: + \[ + \left\{ \begin{array}{lclc} + \If \locTriggerRlpAddr = 0 ~ \Then + \left\{ \begin{array}{lclc} + \locCreateeNonce & = & 0 \\ + \locCreateeHasCode & = & 0 \\ + \end{array} \right. \\ + \If \locTriggerRlpAddr = 1 ~ \Then + \left\{ \begin{array}{lclc} + \locCreateeNonce & = & \accNonce _{i + \createFirstCreateeAccountRowOffset} \\ + \locCreateeHasCode & = & \accHasCode _{i + \createFirstCreateeAccountRowOffset} \\ + \end{array} \right. \\ + \end{array} \right. + \] + \saNote{} We explain the conditional definitions of \locCreateeNonce{} and \locCreateeHasCode{} by the fact that the \zkEvm{} is granted access to the account of the deployment address \emph{iff} it computes that address. + \item[\underline{Setting the \inst{CREATE}-scenario:}] + we impose the following + \begin{enumerate} + \item we unconditionally impose $\scenCreateException_{i} = \xAhoy_{i}$ \label{create: setting exceptional scenario} + \item \If $\scenCreateUnexceptional_{i} = 1$\footnote{i.e. ``\If $\miscOobFlag_{i + \createMiscRowOffset} = 1$.''} \Then + \[ + \left\{ \begin{array}{lclr} + \scenCreateAbort _{i} & = & \locOobAbortingCondition \\ + \scenCreateFCond _{i} & = & \locOobFailureCondition \\ + \scenCreateNotRebuffed _{i} & = & 1 - \locOobAbortingCondition - \locOobFailureCondition & (\trash) \\ + \end{array} \right. + \] + \item \If $\scenCreateCreatorStateChange_{i} = 1$ \Then + \[ + \scenCreateCreatorStateChangeWillRevert_{i} + = + \cnWillRev_{i} + \] + \item \If $\scenCreateNotRebuffed _{i} = 1$ \Then + \[ + \scenCreateExecutionNonEmptyInitCode _{i} + = + \locMxpMtntop + \] + \item \If $\scenCreateExecutionNonEmptyInitCode _{i} = 1$ \Then + \[ + \scenCreateFailure _{i} + = + \miscChildSelfReverts _{i + \createMiscRowOffset} + \] + \saNote{} + The value of $\miscChildSelfReverts _{i + \createMiscRowOffset}$ is justified in section~(\ref{hub: instruction handling: create: generalities: final context row}). + \end{enumerate} + \item[\underline{Setting the \mmuMod{} data:}] + we impose \If $\miscMmuFlag_{i + \createMiscRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i , + relOffset = \createMiscRowOffset , + sourceId = \cn_{i} , + targetId = \undefinedStar \quad \locTgtId , + auxiliaryId = \undefinedStar \quad \locAuxId , + % sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \locOffsetLo , + % targetOffsetLo = \col{tgt\_offset\_lo} , + size = \locSizeLo , + % referenceOffset = \col{ref\_offset} , + referenceSize = \locSizeLo , + successBit = \nothing , + % limbOne = \col{limb\_1} , + % limbTwo = \col{limb\_2} , + exoSum = \undefinedStar \quad \locExoSum , + phase = \rZero , + } + % \setMmuInstructionParametersRamToExoWithPadding + % {i}{\createMiscRowOffset} + % \left[ \begin{array}{llr} + % \utt{Source ID:} & \cn_{i} \\ + % \utt{Target ID:} & \locTgtId & (\bigstar) \\ + % \utt{Auxiliary ID:} & \locAuxId & (\bigstar) \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \locOffsetLo \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \locSizeLo \\ + % % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \locSizeLo \\ + % \utt{Success bit:} & \nothing \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \locExoSum & (\bigstar) \\ + % \utt{Phase:} & \rZero \\ + % \end{array} \right] + \] + where we have used the following (as of yet undefined) shorthands \locTgtId{}, \locAuxId{} and \locExoSum{} which we define as follows: + \begin{enumerate} + \item \If $\locHashInitCode = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locTgtId & \define & \nothing \\ + \locAuxId & \define & 1 + \hubStamp_{i} \\ + \locExoSum & \define & \exoWeightKec \\ + \end{array} \right. + \] + \item \If $\locHashInitCodeAndSendToRom = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locTgtId & \define & \locDepCfi \\ + \locAuxId & \define & 1 + \hubStamp_{i} \\ + \locExoSum & \define & \exoWeightRom + \exoWeightKec \\ + \end{array} \right. + \] + \item \If $\locSendInitCodeToRom = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locTgtId & \define & \locDepCfi \\ + \locAuxId & \define & \nothing \\ + \locExoSum & \define & \exoWeightRom \\ + \end{array} \right. + \] + \end{enumerate} + \saNote{} Recall that the lookup serving the \mmuMod{} module its instructions provides the current context number \cn{} and caller context number \caller{} (so that there is no need to specify those in the above.) + \item[\underline{Setting the next context number:}] + we impose + \[ + \left\{ \begin{array}{lclr} + \If \scenCreateException _{i} = 1 & \Then & \nextContextIsCaller _{i} & (\trash) \\ + \If \scenCreateNoContextChange _{i} = 1 & \Then & \nextContextIsCurrent _{i} \\ + \If \scenCreateExecutionNonEmptyInitCode _{i} = 1 & \Then & \nextContextIsNew _{i} \\ + \end{array} \right. + \] + \item[\underline{Setting the \gasCost{}:}] + we impose + \begin{enumerate} + \item \If $\locStaticx + \locMxpx = 1$ \Then $\gasCost _{i} = 0$ + \item \If $\locOogx + \scenCreateUnexceptional = 1$ \Then $\gasCost _{i} = G_\text{create} + \locMxpGas$ + \end{enumerate} + \item[\underline{Setting the \gasNext{}:}] + we impose + \begin{enumerate} + \item \If $\scenCreateException _{i} = 1$ \Then $\gasNext_{i} = 0$ (\trash) + \item \If $\scenCreateNoContextChange _{i} = 1$ \Then $\gasNext_{i} = \gasActual_{i} - \gasCost_{i}$ + \item \If $\scenCreateExecutionNonEmptyInitCode _{i} = 1$ \Then + \[ + \gasNext_{i} = \gasActual_{i} - + \left[ \begin{array}{cl} + + & \gasCost_{i} \\ + + & \locStpGasPoop \\ + \end{array} \right] + \] + \end{enumerate} +\end{description} diff --git a/hub/instruction_handling/create/generalities/exceptional.tex b/hub/instruction_handling/create/generalities/exceptional.tex new file mode 100644 index 0000000..acab832 --- /dev/null +++ b/hub/instruction_handling/create/generalities/exceptional.tex @@ -0,0 +1,20 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateException _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +The present section deals with exceptional \inst{CREATE}-type instructions. +Recall that a \inst{CREATE}-type instruction can throw the following exceptions: +(\emph{a}) \staticxSH{} +(\emph{b}) \mxpxSH{} or +(\emph{c}) \oogxSH{}. +All the work has already been accomplished except for updating, if necessary, the caller context data. +The update wipes any existing return data in the caller context. +\begin{description} + \item[\underline{Updating the caller context $n^°(i + \createExceptionCallerContextRowOffset)$:}] + we impose + \[ \executionProvidesEmptyReturnData {i}{\createExceptionCallerContextRowOffset} \] +\end{description} diff --git a/hub/instruction_handling/create/generalities/failure.tex b/hub/instruction_handling/create/generalities/failure.tex new file mode 100644 index 0000000..905f8ea --- /dev/null +++ b/hub/instruction_handling/create/generalities/failure.tex @@ -0,0 +1,74 @@ +\begin{center} + \boxed{% + \text{The next constraints are written assuming that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateFailure _{i} & = & 1 \\ + \end{array} \right. } +\end{center} +We deal with the ``deployment failure'' case. Recall that, by definition of $\scenCreateFailure$, this encompasses the following cases: +\begin{itemize} + \item $\scenCreateNonEmptyInitCodeFailureWillRevert$ + \item $\scenCreateNonEmptyInitCodeFailureWontRevert$ +\end{itemize} +we impose the following constraints: +\begin{description} + \item[\underline{Undoing creator account operations on row $n^°(i + \createSecondCreatorAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accSameAddr {i}{\createSecondCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % address + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\createSecondCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % balance + \multicolumn{3}{l}{\accSameNonce {i}{\createSecondCreatorAccountRowOffset}} \\ % nonce + \multicolumn{3}{l}{\accSameCode {i}{\createSecondCreatorAccountRowOffset}} \\ % code + \multicolumn{3}{l}{\accSameWarmth {i}{\createSecondCreatorAccountRowOffset}} \\ % warmth + \multicolumn{3}{l}{\accSameDeployment {i}{\createSecondCreatorAccountRowOffset}} \\ % deployment number and status + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createSecondCreatorAccountRowOffset}} \vspace{2mm} \\ + \accTrmFlag _{i + \createSecondCreatorAccountRowOffset} & = & 0 \\ % TRM + \accRomLexFlag _{i + \createSecondCreatorAccountRowOffset} & = & 0 \\ % ROM_LEX + \accRlpAddrFlag _{i + \createSecondCreatorAccountRowOffset} & = & 0 \vspace{2mm} \\ % RLP_ADDR + \multicolumn{3}{l}{ + \revertWithChildFailureDomSubStamps { + anchorRow = i, + relOffset = \createSecondCreatorAccountRowOffset, + subOffset = 0, + childRevertStamp = \locCreateeRevertStamp, + } + } \\ + % \multicolumn{3}{l}{ + % \revertWithChildFailureDomSubStamps {i}{\relof} {\col{s}} {\locCreateeRevertStamp} + % } \\ + % \multicolumn{3}{l}{\revertDomSubStamps {i}{\createSecondCreatorAccountRowOffset}{0}} \\ % Dom / Sub stamps + \end{array} \right. + \] + \saNote{} The balance is refunded to the creator, but the nonce remains at ``$n + 1$.'' + \item[\underline{Undoing createe account operations on row $n^°(i + \createSecondCreateeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % address + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % balance + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % nonce + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % code + \multicolumn{3}{l}{\accSameWarmth {i}{\createSecondCreateeAccountRowOffset}} \\ % warmth + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % deployment number and status + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createSecondCreateeAccountRowOffset}} \vspace{4mm} \\ + \accTrmFlag _{i + \createSecondCreateeAccountRowOffset} & = & 0 \\ % TRM + \accRomLexFlag _{i + \createSecondCreateeAccountRowOffset} & = & 0 \\ % ROM_LEX + \accRlpAddrFlag _{i + \createSecondCreateeAccountRowOffset} & = & 0 \vspace{4mm} \\ % RLP_ADDR + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \createSecondCreatorAccountRowOffset, + subOffset = 1, + } + } \\ + % {i}{\createSecondCreatorAccountRowOffset}{1}} \\ % Dom / Sub stamps + \end{array} \right. + \] + \saNote{} The only nontrivial operations which the above ``undoes'' are + the nonce update, + the warmth update and + the \accDepStatus{} udpate (\accDepNumber{} updates are \emph{never} undone, see the definition of \accUndoDeploymentStatusAndNumberUpdateName{} in section~(\ref{hub: account: specialized constraints: deployment}).) +\end{description} + diff --git a/hub/instruction_handling/create/generalities/final_context_row.tex b/hub/instruction_handling/create/generalities/final_context_row.tex new file mode 100644 index 0000000..fa44a57 --- /dev/null +++ b/hub/instruction_handling/create/generalities/final_context_row.tex @@ -0,0 +1,149 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that} + \left\{ \begin{array}{lclr} + \peekScenario _{i} & = & 1 \\ + \scenCreateSum _{i} & = & 1 & (\trash) \\ + \end{array} \right.} +\end{center} +The present section deals with the final row of \inst{CREATE}-type instructions. +Given that such instructions trigger the $\CONTEXTMAYCHANGE$ flag, see section~(\ref{hub: generalities: context: cmc flag}), the final row of the instruction must be a context row, see section~(\ref{}). +We now specify the contents of said row. +We will now (at last) deal with ``proper'' deployments i.e. deployments whose processing requires spawning a new execution environment wherein to execute the (from here on out) nonempty intialization code. We remind the reader that in the present case (characterized by $\scenCreateExecutionNonEmptyInitCode \equiv 1$) the initialization code is necessarily nonempty, see section~(\ref{hub: instruction handling: create: intro}). We need to do the following in the current section: +\begin{itemize} + \item justify the failure / success of the upcoming deployment context; + \item justify the associated revert time; + \item perform the relevant account updates and rollbacks; + \item initialize the deployment execution context; + \item provide the new deployment context with its initial balance, code fragment index, program counter; +\end{itemize} + +We impose the following +\begin{enumerate} + \item \If $\scenCreateException _{i} = 1$ \Then \[ \executionProvidesEmptyReturnData {i} {\createExceptionCallerContextRowOffset} \] + \item \If $\scenCreateAbort _{i} = 1$ \Then \[ \nonContextProvidesEmptyReturnData {i} {\createAbortCurrentContextRowOffset } \] + \item \If $\scenCreateFCondWillRevert _{i} = 1$ \Then \[ \nonContextProvidesEmptyReturnData {i} {\createFCondWillRevertCurrentContextRowOffset } \] + \item \If $\scenCreateFCondWontRevert _{i} = 1$ \Then \[ \nonContextProvidesEmptyReturnData {i} {\createFCondWontRevertCurrentContextRowOffset } \] + \item \If $\scenCreateEmptyInitCodeWillRevert _{i} = 1$ \Then \[ \nonContextProvidesEmptyReturnData {i} {\createEmptyInitCodeWillRevertCurrentContextRowOffset} \] + \item \If $\scenCreateEmptyInitCodeWontRevert _{i} = 1$ \Then \[ \nonContextProvidesEmptyReturnData {i} {\createEmptyInitCodeWontRevertCurrentContextRowOffset} \] +\end{enumerate} +The remaining cases (characterized by $\scenCreateExecutionNonEmptyInitCode \equiv 1$) require setting up the upcoming execution context. +We introduce a number of numerical constants to that end: +\[ + \left\{ \begin{array}{lcl} + % \relofCreateException & \define & \createExceptionCallerContextRowOffset \\ + % \relofCreateAbort & \define & \createAbortCurrentContextRowOffset \\ + % \relofCreateFailureConditionWillRevert & \define & \createFCondWillRevertCurrentContextRowOffset \\ + % \relofCreateFailureConditionWontRevert & \define & \createFCondWontRevertCurrentContextRowOffset \\ + % \relofCreateEmptyCodeWontRevert & \define & \createEmptyInitCodeWillRevertCurrentContextRowOffset \\ + % \relofCreateEmptyCodeWillRevert & \define & \createEmptyInitCodeWontRevertCurrentContextRowOffset \\ + \relofCreateNonEmptyFailureWillRevert & \define & \createNonemptyInitCodeFailureWillRevertNewContextRowOffset \\ + \relofCreateNonEmptyFailureWontRevert & \define & \createNonemptyInitCodeFailureWontRevertNewContextRowOffset \\ + \relofCreateNonEmptySuccessWillRevert & \define & \createNonemptyInitCodeSuccessWillRevertNewContextRowOffset \\ + \relofCreateNonEmptySuccessWontRevert & \define & \createNonemptyInitCodeSuccessWontRevertNewContextRowOffset \\ + \end{array} \right. +\] +These will serve for the final phase of the above, i.e. initialzing the upcoming (deployment) context. + + % \item \If $\scenCreateNonEmptyInitCodeFailureWillRevert _{i} = 1$ \Then \[ \] + % \item \If $\scenCreateNonEmptyInitCodeSuccessWillRevert _{i} = 1$ \Then \[ \] + % \item \If $\scenCreateNonEmptyInitCodeFailureWontRevert _{i} = 1$ \Then \[ \] + % \item \If $\scenCreateNonEmptyInitCodeSuccessWontRevert _{i} = 1$ \Then \[ \] +The final steps in dealing with \inst{CREATE}-type instructions satisfying $\scenCreateExecutionNonEmptyInitCode \equiv 1$ are as follows: +\begin{enumerate} + \item initialize the upcoming execution context; + \item justify earlier predictions pertaining to the (temporary) success / self-induced failure of the child frame; + \item set some shared environment variables of the child context; +\end{enumerate} +This is what we do below by invoking certain parametrized constraint systems that achieve the desired goals: +\begin{enumerate} + \item \If $\scenCreateNonEmptyInitCodeFailureWillRevert_{i} = 1$ \Then + \[ + \begin{cases} + \initializeDeploymentContext {i}{\relofCreateNonEmptyFailureWillRevert} \\ + \firstRowOfDeployment {i}{\relofCreateNonEmptyFailureWillRevert} \\ + \justifyCreateeRevertData {i}{\relofCreateNonEmptyFailureWillRevert} \\ + \end{cases} + \] + \item \If $\scenCreateNonEmptyInitCodeFailureWontRevert_{i} = 1$ \Then + \[ + \begin{cases} + \initializeDeploymentContext {i}{\relofCreateNonEmptyFailureWontRevert} \\ + \firstRowOfDeployment {i}{\relofCreateNonEmptyFailureWontRevert} \\ + \justifyCreateeRevertData {i}{\relofCreateNonEmptyFailureWontRevert} \\ + \end{cases} + \] + \item \If $\scenCreateNonEmptyInitCodeSuccessWillRevert_{i} = 1$ \Then + \[ + \begin{cases} + \initializeDeploymentContext {i}{\relofCreateNonEmptySuccessWillRevert} \\ + \firstRowOfDeployment {i}{\relofCreateNonEmptySuccessWillRevert} \\ + \justifyCreateeRevertData {i}{\relofCreateNonEmptySuccessWillRevert} \\ + \end{cases} + \] + \item \If $\scenCreateNonEmptyInitCodeSuccessWontRevert_{i} = 1$ \Then + \[ + \begin{cases} + \initializeDeploymentContext {i}{\relofCreateNonEmptySuccessWontRevert} \\ + \firstRowOfDeployment {i}{\relofCreateNonEmptySuccessWontRevert} \\ + \justifyCreateeRevertData {i}{\relofCreateNonEmptySuccessWontRevert} \\ + \end{cases} + \] +\end{enumerate} + +It remains for us to define the parametrized constraint systems used above. +We define a family of constraints (parametrized by a positive integer $\relof$) +\[ + \underbrace{% + \begin{array}{l} + \initializeContext{ + anchorRow = i , + relOffset = \relof , + contextNumber = 1 + \hubStamp_{i} , + callStackDepth = \locCsd + 1 , + isRoot = 0 , + isStatic = 0 , + accountAddressHigh = \locCreateeAddressHi , + accountAddressLow = \locCreateeAddressLo , + accountDeploymentNumber = \accDepNumber\new_{i + \createFirstCreateeAccountRowOffset} , + byteCodeAddressHi = \locCreateeAddressHi , + byteCodeAddressLo = \locCreateeAddressLo , + byteCodeDeploymentNumber = \accDepNumber\new_{i + \createFirstCreateeAccountRowOffset} , + byteCodeDeploymentStatus = 1 , + byteCodeCodeFragmentIndex = \locDepCfi , + callerAddressHi = \locCreatorAddressHi , + callerAddressLo = \locCreatorAddressLo , + callValue = \locValueLo , + callDataContextNumber = \cn_{i} , + callDataOffset = 0 , + callDataSize = 0 , + returnAtOffset = 0 , + returnAtCapacity = 0 , + } + \vspace{2mm} \\ + \end{array} + }_{\displaystyle \define \initializeDeploymentContext {i}{\relof}} + \] + We further set + \[ + \firstRowOfDeployment {i}{\relof} + \iff + \left\{ \begin{array}{lclr} + % \cn\new_{i} & \!\!\! = \!\!\! & \cnCn_{i + \relof} \\ + \cn _{i + \relof + 1} & \!\!\! = \!\!\! & \cnCn _{i + \relof} & (\trash) \\ + \caller _{i + \relof + 1} & \!\!\! = \!\!\! & \cn _{i + \relof} \\ + \cfi _{i + \relof + 1} & \!\!\! = \!\!\! & \cnCodeCfi _{i + \relof} \\ + \pc _{i + \relof + 1} & \!\!\! = \!\!\! & 0 \\ + \gasExpected _{i + \relof + 1} & \!\!\! = \!\!\! & \locStpGasPoop \\ + \end{array} \right. + \] + and + \[ + \justifyCreateeRevertData {i}{\relof} + \iff + \left\{ \begin{array}{lcl} + \locCreateeSelfReverts & = & \cnSelfRev _{i + \relof + 1} \\ + \locCreateeRevertStamp & = & \cnRevStamp _{i + \relof + 1} \\ + \end{array} \right. + \] + With this definition in hand we proceed to initializing the upcoming execution context: diff --git a/hub/instruction_handling/create/generalities/revert_in_one_step.tex b/hub/instruction_handling/create/generalities/revert_in_one_step.tex new file mode 100644 index 0000000..94fb00d --- /dev/null +++ b/hub/instruction_handling/create/generalities/revert_in_one_step.tex @@ -0,0 +1,67 @@ +\begin{center} + \boxed{% + \text{The next constraints are written assuming that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateSimpleRevert _{i} & = & 1 \\ + \end{array} \right. } +\end{center} +We deal with the ``simple revert'' case first. Recall that, by definition of $\scenCreateSimpleRevert$, this encompasses the following cases: +\begin{itemize} + \item $\scenCreateFCondWillRevert$ + \item $\scenCreateNonEmptyInitCodeSuccessWillRevert$ + \item $\scenCreateEmptyInitCodeWillRevert$ +\end{itemize} +we impose the following constraints: +\begin{description} + \item[\underline{Undoing creator account operations on row $n^°(i + \createSecondCreatorAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accSameAddr {i}{\createSecondCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % address + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\createSecondCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % balance + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\createSecondCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % nonce + \multicolumn{3}{l}{\accSameCode {i}{\createSecondCreatorAccountRowOffset}} \\ % code + \multicolumn{3}{l}{\accSameWarmth {i}{\createSecondCreatorAccountRowOffset}} \\ % warmth + \multicolumn{3}{l}{\accSameDeployment {i}{\createSecondCreatorAccountRowOffset}} \\ % deployment number and status + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createSecondCreatorAccountRowOffset}} \vspace{4mm} \\ + \accTrmFlag _{i + \createSecondCreatorAccountRowOffset} & = & 0 \\ % TRM + \accRomLexFlag _{i + \createSecondCreatorAccountRowOffset} & = & 0 \\ % ROM_LEX + \accRlpAddrFlag _{i + \createSecondCreatorAccountRowOffset} & = & 0 \vspace{4mm} \\ % RLP_ADDR + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \createSecondCreatorAccountRowOffset, + subOffset = 0, + } + } \\ + \end{array} \right. + \] + \item[\underline{Undoing createe account operations on row $n^°(i + \createSecondCreateeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % address + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % balance + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % nonce + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % code + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % warmth + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\createSecondCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % deployment number and status + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createSecondCreateeAccountRowOffset}} \vspace{4mm} \\ + \accTrmFlag _{i + \createSecondCreateeAccountRowOffset} & = & 0 \\ % TRM + \accRomLexFlag _{i + \createSecondCreateeAccountRowOffset} & = & 0 \\ % ROM_LEX + \accRlpAddrFlag _{i + \createSecondCreateeAccountRowOffset} & = & 0 \vspace{4mm} \\ % RLP_ADDR + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i , + relOffset = \createSecondCreateeAccountRowOffset, + subOffset = 1 , + } + } \\ + \end{array} \right. + \] + \saNote{} The only nontrivial operations which the above ``undoes'' are + the nonce update, + the warmth update and + the \accDepStatus{} udpate (\accDepNumber{} updates are \emph{never} undone.) +\end{description} diff --git a/hub/instruction_handling/create/generalities/revert_in_two_steps.tex b/hub/instruction_handling/create/generalities/revert_in_two_steps.tex new file mode 100644 index 0000000..0d1948e --- /dev/null +++ b/hub/instruction_handling/create/generalities/revert_in_two_steps.tex @@ -0,0 +1,71 @@ +\begin{center} + \boxed{% + \text{The next constraints are written assuming that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} & = & 1 \\ + \end{array} \right. } +\end{center} +We deal with the extra complication that arises when a deployment fails and the context which launched it is later on reverted. +We impose the following constraints: +\begin{description} + \item[\underline{Undoing creator account operations on row $n^°(i + \createThirdCreatorAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accSameAddr {i}{\createThirdCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % address + \multicolumn{3}{l}{\accSameBalance {i}{\createThirdCreatorAccountRowOffset}} \\ % balance + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\createThirdCreatorAccountRowOffset}{\createFirstCreatorAccountRowOffset}} \\ % nonce + \multicolumn{3}{l}{\accSameCode {i}{\createThirdCreatorAccountRowOffset}} \\ % code + \multicolumn{3}{l}{\accSameWarmth {i}{\createThirdCreatorAccountRowOffset}} \\ % warmth + \multicolumn{3}{l}{\accSameDeployment {i}{\createThirdCreatorAccountRowOffset}} \\ % deployment number and status + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createThirdCreatorAccountRowOffset}} \vspace{2mm} \\ + \accTrmFlag _{i + \createThirdCreatorAccountRowOffset} & = & 0 \\ % TRM + \accRomLexFlag _{i + \createThirdCreatorAccountRowOffset} & = & 0 \\ % ROM_LEX + \accRlpAddrFlag _{i + \createThirdCreatorAccountRowOffset} & = & 0 \vspace{2mm} \\ % RLP_ADDR + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \createThirdCreatorAccountRowOffset, + subOffset = 2, + } + } \\ + % \revertDomSubStamps {i}{\createThirdCreatorAccountRowOffset}{2} } \\ + % \multicolumn{3}{l}{ + % \revertWithChildFailureDomSubStamps {i}{\relof} {\col{s}} {\locCreateeRevertStamp} + % } \\ + % \multicolumn{3}{l}{\revertDomSubStamps {i}{\createThirdCreatorAccountRowOffset}{0}} \\ % Dom / Sub stamps + \end{array} \right. + \] + \saNote{} The balance is refunded to the creator, but the nonce remains at ``$n + 1$.'' + \item[\underline{Undoing createe account operations on row $n^°(i + \createThirdCreateeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameAddr {i}{\createThirdCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % address + \multicolumn{3}{l}{\accSameBalance {i}{\createThirdCreateeAccountRowOffset}} \\ % balance + \multicolumn{3}{l}{\accSameNonce {i}{\createThirdCreateeAccountRowOffset}} \\ % nonce + \multicolumn{3}{l}{\accSameCode {i}{\createThirdCreateeAccountRowOffset}} \\ % code + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\createThirdCreateeAccountRowOffset}{\createFirstCreateeAccountRowOffset}} \\ % warmth + \multicolumn{3}{l}{\accSameDeployment {i}{\createThirdCreateeAccountRowOffset}} \\ % deployment number and status + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createThirdCreateeAccountRowOffset}} \vspace{4mm} \\ + \accTrmFlag _{i + \createThirdCreateeAccountRowOffset} & = & 0 \\ % TRM + \accRomLexFlag _{i + \createThirdCreateeAccountRowOffset} & = & 0 \\ % ROM_LEX + \accRlpAddrFlag _{i + \createThirdCreateeAccountRowOffset} & = & 0 \vspace{4mm} \\ % RLP_ADDR + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \createThirdCreateeAccountRowOffset, + subOffset = 3, + } + } \\ + % \revertDomSubStamps {i}{\createThirdCreateeAccountRowOffset}{3}} \\ % Dom / Sub stamps + \end{array} \right. + \] + \saNote{} The only nontrivial operations which the above ``undoes'' are + the nonce update, + the warmth update and + the \accDepStatus{} udpate (\accDepNumber{} updates are \emph{never} undone, see the definition of \accUndoDeploymentStatusAndNumberUpdateName{} in section~(\ref{hub: account: specialized constraints: deployment}).) +\end{description} + + diff --git a/hub/instruction_handling/create/generalities/unaborted.tex b/hub/instruction_handling/create/generalities/unaborted.tex new file mode 100644 index 0000000..39864f1 --- /dev/null +++ b/hub/instruction_handling/create/generalities/unaborted.tex @@ -0,0 +1,102 @@ +\saNote{} Nonce and balance may change for the ``creator'' account. Everything else remains unchanged. +\begin{center} + \boxed{% + \text{The next constraints are written assuming that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateComputeAddress _{i} & = & 1 \\ + \end{array} \right. } +\end{center} +The present section contains details pertaining to the first appearance of the createe account. +The \zkEvm{} loads this account \textbf{iff} the \inst{CREATE}-type instruction neither provokes an exception nor is aborted. +Note that these innstructions may still produce a failure condition. +In order to detect the triggering of the failure condition $\yellowPaperFailureCondition$. +\begin{description} + \item[\underline{Account-row $n^°(i + \createFirstCreateeAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \accAddressHi _{i + \createFirstCreateeAccountRowOffset} & = & \locCreateeAddressHi \\ + \accAddressLo _{i + \createFirstCreateeAccountRowOffset} & = & \locCreateeAddressLo \\ + % balance: missing + % nonce : not yet set + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + % \multicolumn{3}{l}{\accSameCode {i}{\createFirstCreateeAccountRowOffset}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + % \multicolumn{3}{l}{\accSameWarmth {i}{\createFirstCreateeAccountRowOffset}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + % \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\createFirstCreateeAccountRowOffset}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + % \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\createFirstCreateeAccountRowOffset}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createFirstCreateeAccountRowOffset}} \\ + \accRomLexFlag _{i + \createFirstCreateeAccountRowOffset} & = & \locTriggerRomLex \\ + \accTrmFlag _{i + \createFirstCreateeAccountRowOffset} & = & \valueUnknown \\ + \accRlpAddrFlag _{i + \createFirstCreateeAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \createFirstCreateeAccountRowOffset, + domOffset = 1, + } + } \\ + % \standardDomSubStamps {i}{\createFirstCreateeAccountRowOffset}{1}} \\ + \end{array} \right. + \] + \saNote{} + Given the premise of this section ($\scenCreateUnexceptional \equiv 1$) one will have $\accRlpAddrFlag \equiv 1$ unless $\scenCreateAbort \equiv 1$. +\end{description} +\saNote{} +For the upcoming set of constraints it suffices to impose the weaker precondition that $\peekScenario _{i} = 1$ i.e. one may drop the assumption that $\scenCreateComputeAddress _{i} = 1$. +Indeedd this precondition follows from each and every precondition we will be imposing below. +\begin{description} + \item[\underline{Setting the balance operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateRebuffed _{i} = 1$ \Then $\accSameBalance {i}{\createFirstCreatorAccountRowOffset}$ + \item \If $\scenCreateNotRebuffed _{i} = 1$ \Then $\accIncrementBalance {i}{\createFirstCreatorAccountRowOffset}{\locValueLo}$ + \end{enumerate} + \item[\underline{Setting the nonce operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateRebuffed _{i} = 1$ \Then $\accSameNonce {i}{\createFirstCreateeAccountRowOffset}$ + \item \If $\scenCreateNotRebuffed _{i} = 1$ \Then $\accIncrementNonce {i}{\createFirstCreateeAccountRowOffset}$ + \end{enumerate} + \item[\underline{Setting the code operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateRebuffed _{i} = 1$ \Then $\accSameCode {i}{\createFirstCreateeAccountRowOffset}$ + \item \If $\scenCreateNotRebuffed _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accSameCodeHash {i}{\createFirstCreateeAccountRowOffset}} \\ + \accCodesize\new _{i + \createFirstCreateeAccountRowOffset} & = & \locSizeLo  \vspace{2mm} \\ + \accCodehashHi\new _{i + \createFirstCreateeAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo\new _{i + \createFirstCreateeAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \end{array} \right. + \] + \saNote{} + The above is valid both for \inst{CREATE}-type instructions with empty initialization code and those with nonempty initialization code. + \end{enumerate} + \item[\underline{Setting the warmth operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateNoCreatorStateChange _{i} = 1$ \Then $\accSameWarmth {i}{\createFirstCreateeAccountRowOffset}$ + \item \If $\scenCreateCreatorStateChange _{i} = 1$ \Then $\accTurnOnWarmth {i}{\createFirstCreateeAccountRowOffset}$ + \end{enumerate} + \item[\underline{Setting the deployment number operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateRebuffed _{i} = 1$ \Then $\accSameDeploymentNumber {i}{\createFirstCreateeAccountRowOffset}$ + \item \If $\scenCreateNotRebuffed _{i} = 1$ \Then $\accIncrementDeploymentNumber {i}{\createFirstCreateeAccountRowOffset}$ + \end{enumerate} + \item[\underline{Setting the deployment status operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateRebuffed _{i} = 1$ \Then $\accSameDeploymentStatus {i}{\createFirstCreateeAccountRowOffset}$ + \item \If $\scenCreateExecutionNonEmptyInitCode _{i} = 1$ \Then $\accTurnOnDepStatus {i}{\createFirstCreateeAccountRowOffset}$ + \item \If $\scenCreateExecutionEmptyInitCode _{i} = 1$ \Then $\accSameDeploymentStatus {i}{\createFirstCreateeAccountRowOffset}$ + \end{enumerate} +\end{description} + diff --git a/hub/instruction_handling/create/generalities/unexceptional.tex b/hub/instruction_handling/create/generalities/unexceptional.tex new file mode 100644 index 0000000..007be8f --- /dev/null +++ b/hub/instruction_handling/create/generalities/unexceptional.tex @@ -0,0 +1,82 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenCreateUnexceptional _{i} & = & 1 \\ + \end{array} \right. } +\end{center} +The present section deals with generalities pertaining to \textbf{unexceptional} \inst{CREATE}-type instructions. +Whil unexceptional these may still be aborted. +We must differentiate between (potentially) aborted \inst{CREATE}-type instructions those that aren't aborted. +We impose the following constraints: +\begin{description} + \item[\underline{Account-row $n^°(i + \createFirstCreatorAccountRowOffset)$:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \accAddressHi _{i + \createFirstCreatorAccountRowOffset} & = & \locCreatorAddressHi \\ + \accAddressLo _{i + \createFirstCreatorAccountRowOffset} & = & \locCreatorAddressLo \\ + % balance: missing + % nonce : not yet set + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\textcolor{solarized-green}{\texttt{}}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\createFirstCreatorAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\createFirstCreatorAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\createFirstCreatorAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeploymentStatus {i}{\createFirstCreatorAccountRowOffset}} \\ + %%%%% + %%%%% + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\createFirstCreatorAccountRowOffset}} \\ + \accRomLexFlag _{i + \createFirstCreatorAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \createFirstCreatorAccountRowOffset} & = & 0 \\ + \accRlpAddrFlag _{i + \createFirstCreatorAccountRowOffset} & = & \locTriggerRlpAddr \vspace{2mm} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \createFirstCreatorAccountRowOffset, + domOffset = 0, + } + } \\ + \end{array} \right. + \] + \saNote{} + Given the premise of this section ($\scenCreateUnexceptional \equiv 1$) one will have $\accRlpAddrFlag \equiv 1$ unless $\scenCreateAbort \equiv 1$. + \item[\underline{Setting the balance operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateRebuffed _{i} = 1$ \Then $\accSameBalance {i}{\createFirstCreatorAccountRowOffset}$ + \item \If $\scenCreateNotRebuffed _{i} = 1$ \Then $\accDecrementBalance {i}{\createFirstCreatorAccountRowOffset}{\locValueLo}$ + \end{enumerate} + \item[\underline{Setting the nonce operation:}] + we impose that + \begin{enumerate} + \item \If $\scenCreateNoCreatorStateChange _{i} = 1$ \Then $\accSameNonce {i}{\createFirstCreatorAccountRowOffset}$ + \item \If $\scenCreateCreatorStateChange _{i} = 1$ \Then $\accIncrementNonce {i}{\createFirstCreatorAccountRowOffset}$ + \end{enumerate} + \item[\underline{Setting the \rlpAddrMod{} module parameters:}] + \If $\accRlpAddrFlag _{i + \createFirstCreatorAccountRowOffset} = 1$ \Then we impose + % \If $\accRlpAddrFlag _{i + \createFirstCreatorAccountRowOffset} = 1$ \Then we impose + \[ + \left\{ \begin{array}{lcl} + % \accRlpAddrFlag _{i + \createFirstCreatorAccountRowOffset} & = & \rOne \\ + \accRlpAddrRecipe _{i + \createFirstCreatorAccountRowOffset} & = & \locRlpAddrRecipe \\ + \accRlpAddrDepAddrHi _{i + \createFirstCreatorAccountRowOffset} & = & \relevantValue \\ + \accRlpAddrDepAddrLo _{i + \createFirstCreatorAccountRowOffset} & = & \relevantValue \\ + \accRlpAddrSaltHi _{i + \createFirstCreatorAccountRowOffset} & = & \locSaltHi \\ + \accRlpAddrSaltLo _{i + \createFirstCreatorAccountRowOffset} & = & \locSaltLo \\ + \accRlpAddrKecHi _{i + \createFirstCreatorAccountRowOffset} & = & \locInitCodeHashHi \\ + \accRlpAddrKecLo _{i + \createFirstCreatorAccountRowOffset} & = & \locInitCodeHashLo \\ + \end{array} \right. + \] + where we set + \[ + \locRlpAddrRecipe := + \left[ \begin{array}{lrcl} + + & \locIsCreate & \!\!\! \cdot \!\!\! & \addressCreationRecipeConstantStd \\ + + & \locIsCreateTwo & \!\!\! \cdot \!\!\! & \addressCreationRecipeConstantTwo \\ + \end{array} \right] + \] + \saNote{} We remind the reader that section~(\ref{rlpAddr: create computation constants}) defines two nonzero constants $\addressCreationRecipeConstantStd$ and $\addressCreationRecipeConstantTwo$. +\end{description} +\saNote{} The \zkEvm{} thus loads the account whose address corresponds to $I_\text{a}$ in the \cite{EYP}. diff --git a/hub/instruction_handling/create/intro.tex b/hub/instruction_handling/create/intro.tex new file mode 100644 index 0000000..9a6ab11 --- /dev/null +++ b/hub/instruction_handling/create/intro.tex @@ -0,0 +1,5 @@ +The present section deals with the instruction handling of both \inst{CREATE} and \inst{CREATE2} instructions. These are rather complex instructions in several ways: +(\emph{a}) they can several different exceptions (see section~(\ref{hub: instruction handling: create: intro}) +(\emph{b}) unexceptional \inst{CREATE}-type instructions may raise an aborting condition and not be executed +(\emph{c}) unexceptional and unaborted \inst{CREATE}-type instructions may raise a failure condition if the deployment address has nonzero nonce or nonempty code +(\emph{d}) \inst{CREATE}-type instructions that make it past these initial hurdles may lead to (temporary) deployments which may need to be reverted later on. diff --git a/hub/instruction_handling/create/lua/_inputs.tex b/hub/instruction_handling/create/lua/_inputs.tex new file mode 100644 index 0000000..4e478da --- /dev/null +++ b/hub/instruction_handling/create/lua/_inputs.tex @@ -0,0 +1,15 @@ +\includepdf[fitpaper = true]{instruction_handling/create/lua/highlevel.pdf} \label{hub: create: fig: highlevel processing} +% +\includepdf[fitpaper = true]{instruction_handling/create/lua/exceptions/staticx.pdf} \label{hub: instruction handling: create: lua: staticx} +\includepdf[fitpaper = true]{instruction_handling/create/lua/exceptions/mxpx.pdf} \label{hub: instruction handling: create: lua: mxpx} +\includepdf[fitpaper = true]{instruction_handling/create/lua/exceptions/oogx.pdf} \label{hub: instruction handling: create: lua: oogx} +\includepdf[fitpaper = true]{instruction_handling/create/lua/unexceptional.pdf} \label{hub: instruction handling: create: lua: unexceptional} +\includepdf[fitpaper = true]{instruction_handling/create/lua/abort.pdf} \label{hub: instruction handling: create: lua: abort} +\includepdf[fitpaper = true]{instruction_handling/create/lua/failure_condition/will_revert.pdf} \label{hub: instruction handling: create: lua: will revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/failure_condition/wont_revert.pdf} \label{hub: instruction handling: create: lua: wont revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/empty/will_revert.pdf} \label{hub: instruction handling: create: lua: will revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/empty/wont_revert.pdf} \label{hub: instruction handling: create: lua: wont revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/nonempty/failure_will_revert.pdf} \label{hub: instruction handling: create: lua: failure will revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/nonempty/failure_wont_revert.pdf} \label{hub: instruction handling: create: lua: failure wont revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/nonempty/success_will_revert.pdf} \label{hub: instruction handling: create: lua: success will revert} +\includepdf[fitpaper = true]{instruction_handling/create/lua/nonempty/success_wont_revert.pdf} \label{hub: instruction handling: create: lua: success wont revert} diff --git a/hub/instruction_handling/create/lua/abort.lua.tex b/hub/instruction_handling/create/lua/abort.lua.tex new file mode 100644 index 0000000..f028061 --- /dev/null +++ b/hub/instruction_handling/create/lua/abort.lua.tex @@ -0,0 +1,104 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | | + _` | __ \ _ \ __| __| + ( | | | ( | | | + \__,_| _.__/ \___/ _| \__| + + +|-----------+--------+--------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+--------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+--------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+--------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . con/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . con/IS_STATIC = 0 | +|-----------+--------+--------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 1 | +|   | | | . OOB_failure_condition = 0 | +|-----------+--------+--------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 3 | ACC | read account data of current account (I_a) | | τ ∙ h + 0 | 0 | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH = 1024] ∨ [acc/BALANCE < value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 1) | | | +|-----------+--------+--------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 4 | CON | nonContextProvidesEmptyReturnData() | +|-----------+--------+--------------------------------------------| + +NOTE. We use the following shorthands + + * h ≡ HUB_STAMP + + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/empty/will_revert.lua.tex b/hub/instruction_handling/create/lua/empty/will_revert.lua.tex new file mode 100644 index 0000000..144dc81 --- /dev/null +++ b/hub/instruction_handling/create/lua/empty/will_revert.lua.tex @@ -0,0 +1,139 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) _) | | + _ \ __ `__ \ __ \ __| | | | __ \ | __| __| _ \ _` | _ \ + __/ | | | | | | | | | | | | | ( ( | ( | __/ + \___| _| _| _| .__/ \__| \__, | _| _| _| _| \__| \___| \___/ \__,_| \___| + _| ____/ + + _) | | | + \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + \ \ \ / | | | | __/ \ \ / __/ | | + \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ 0 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 0 | +|   | | | . mxp/MXP_MTNTOP = 0 (i.e. size == 0) | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | ⤴️decrementBalance (i.e. balance -= value) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️incrementNonce (i.e. nonce: 0 → 1) | | | | +|   | | ⤴️incrementBalance (i.e. balance += value) | | | | +|   | | ⤴️incrementDeploymentNumber (i.e. depNum += 1) | | | | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . acc/NONCE = 0 | | | +|   | | | . acc/HAS_CODE = 0 | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 5 | ACC | Load account with address I_a | | τ ∙ ρ_curr + ε_rev | τ ∙ h + 2 | +|   | | ♻️sameAddress[5,3] | | | | +|   | | ⏪undoNonceUpdate[5,3] | | | | +|   | | ⏪undoBalanceUpdate[5,3] | | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 6 | ACC | Read account with address δ | | τ ∙ ρ_curr + ε_rev | τ ∙ h + 3 | +|   | | ♻️sameAddress[6,4] | | | | +|   | | ⏪undoNonceUpdate[6,4] | | | | +|   | | ⏪undoBalanceUpdate[6,4] | | | | +|   | | ♻️sameDeploymentNumber[6,4] | | | | +|   | | ⏪undoWarmthUpdate[6,4] | | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 7 | CON | nonContextProvidesEmptyReturnData( current context ) | +|-----------+--------+------------------------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/empty/wont_revert.lua.tex b/hub/instruction_handling/create/lua/empty/wont_revert.lua.tex new file mode 100644 index 0000000..6496e73 --- /dev/null +++ b/hub/instruction_handling/create/lua/empty/wont_revert.lua.tex @@ -0,0 +1,128 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) _) | | + _ \ __ `__ \ __ \ __| | | | __ \ | __| __| _ \ _` | _ \ + __/ | | | | | | | | | | | | | ( ( | ( | __/ + \___| _| _| _| .__/ \__| \__, | _| _| _| _| \__| \___| \___/ \__,_| \___| + _| ____/ + + ) | | + \ \ \ / _ \ __ \ / __| __| _ \ \ \ / _ \ __| __| + \ \ \ / ( | | | | | __/ \ \ / __/ | | + \_/\_/ \___/ _| _| \__| _| \___| \_/ \___| _| \__| + + +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+------------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ 0 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 0 | +|   | | | . mxp/MXP_MTNTOP = 0 (i.e. size == 0) | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | ⤴️decrementBalance (i.e. balance -= value) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️incrementNonce (i.e. nonce: 0 → 1) | | | | +|   | | ⤴️incrementBalance (i.e. balance += value) | | | | +|   | | ⤴️incrementDeploymentNumber (i.e. depNumber += 1) | | | | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . acc/NONCE = 0 | | | +|   | | | . acc/HAS_CODE = 0 | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 7 | CON | nonContextProvidesEmptyReturnData( current context ) | +|-----------+--------+------------------------------------------------------| + +\end{verbatim} +\end{document} + diff --git a/hub/instruction_handling/create/lua/exceptions/mxpx.lua.tex b/hub/instruction_handling/create/lua/exceptions/mxpx.lua.tex new file mode 100644 index 0000000..b586828 --- /dev/null +++ b/hub/instruction_handling/create/lua/exceptions/mxpx.lua.tex @@ -0,0 +1,73 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + + __ `__ \ \ \ / __ \ \ \ / + | | | ` < | | ` < + _| _| _| _/\_\ .__/ _/\_\ + _| + +|-----------+--------+----------------------------------------+--------------------------------| +| Row index | Persp. | Actions | Notes | +|:---------:+--------+----------------------------------------+--------------------------------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 1 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 1 | +|-----------+--------+----------------------------------------+--------------------------------| +| i  | SCEN |  CREATE/EXCEPTION ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY | +|-----------+--------+----------------------------------------+--------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+----------------------------------------+--------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 1 | +|-----------+--------+----------------------------------------+--------------------------------| +| i + 3 | CON | executionProvidesEmptyReturnData() | +|-----------+--------+----------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/exceptions/oogx.lua.tex b/hub/instruction_handling/create/lua/exceptions/oogx.lua.tex new file mode 100644 index 0000000..d4fa4c5 --- /dev/null +++ b/hub/instruction_handling/create/lua/exceptions/oogx.lua.tex @@ -0,0 +1,81 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + + _ \ _ \ _` | \ \ / + ( | ( | ( | ` < + \___/ \___/ \__, | _/\_\ + |___/ + +|-----------+--------+----------------------------------------+--------------------------------| +| Row index | Persp. | Actions | Notes | +|:---------:+--------+----------------------------------------+--------------------------------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 1 | +|   | | | . => XAHOY ≡ 1 | +|-----------+--------+----------------------------------------+--------------------------------| +| i  | SCEN |  CREATE/EXCEPTION ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY | +|-----------+--------+----------------------------------------+--------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+----------------------------------------+--------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/mxp/OOGX = 1 | +|-----------+--------+----------------------------------------+--------------------------------| +| i + 3 | CON | executionProvidesEmptyReturnData() | +|-----------+--------+----------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/exceptions/staticx.lua.tex b/hub/instruction_handling/create/lua/exceptions/staticx.lua.tex new file mode 100644 index 0000000..09eeb18 --- /dev/null +++ b/hub/instruction_handling/create/lua/exceptions/staticx.lua.tex @@ -0,0 +1,63 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | | _) + __| __| _` | __| | __| \ \ / + \__ \ | ( | | | ( ` < + ____/ \__| \__,_| \__| _| \___| _/\_\ + + +|-----------+--------+------------------------------------+---------------------------------------| +| Row index | Persp. | Actions | Notes | +|:---------:+--------+------------------------------------+---------------------------------------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 1 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 1 | +|-----------+--------+------------------------------------+---------------------------------------| +| i  | SCEN |  CREATE/EXCEPTION ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY | +|-----------+--------+------------------------------------+---------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | | Impose that: | +|   | | | . context/IS_STATIC = stack/STATICX | +|   | | | . context/IS_STATIC = 1 | +|-----------+--------+------------------------------------+---------------------------------------| +| i + 2 | MISC | | do nothing ... 😊 | +|-----------+--------+------------------------------------+---------------------------------------| +| i + 3 | CON | executionProvidesEmptyReturnData() | +|-----------+--------+------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/failure_condition/generic.lua.tex b/hub/instruction_handling/create/lua/failure_condition/generic.lua.tex new file mode 100644 index 0000000..3f1028f --- /dev/null +++ b/hub/instruction_handling/create/lua/failure_condition/generic.lua.tex @@ -0,0 +1,139 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + _| _) | | _) | _) + | _` | | | | | __| _ \ __| _ \ __ \ _` | | __| | _ \ __ \ + __| ( | | | | | | __/ ( ( | | | ( | | | | ( | | | + _| \__,_| _| _| \__,_| _| \___| \___| \___/ _| _| \__,_| _| \__| _| \___/ _| _| + + _) | | | + \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + \ \ \ / | | | | __/ \ \ / __/ | | + \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +|-----------+--------+------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|   | | stack/HASHINFO🚩 ≡ trigger_HASHINFO | | +|   | | | | +|   | | trigger_HASHINFO ≡ [size ≠ 0] | | +|   | | . ∧ is_CREATE2 | | +|   | | | Provides: | +|   | | | * init_code_hash | +|-----------+--------+------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/failure_condition ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|   | | | .  CREATE/creator_context_will_revert ≡ CN_WILL_REVERT | +|-----------+--------+------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ trigger_MMU | | +|   | | | | +|   | | trigger_MMU ≡ hash_init_code | | +|   | | . + hash_init_code_and_send_to_ROM | | +|   | | . + send_init_code_to_ROM | | +|   | | | | +|   | | hash_init_code ≡ [size ≠ 0] | | +|   | | . ∧ is_CREATE2 | | +|   | | hash_init_code_and_send_to_ROM ≡ 0 | | +|   | | send_init_code_to_ROM ≡ 0 | | +|   | | | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 1 | +|-----------+--------+------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | nonce += 1 | | | | +|   | | | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | warmth ↑ | | | | +|   | | | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|-----------+--------+------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 5 | TBD | +|-----------+--------| + +NOTE. We use the following shorthands + + * h ≡ HUB_STAMP + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/failure_condition/will_revert.lua.tex b/hub/instruction_handling/create/lua/failure_condition/will_revert.lua.tex new file mode 100644 index 0000000..7128af7 --- /dev/null +++ b/hub/instruction_handling/create/lua/failure_condition/will_revert.lua.tex @@ -0,0 +1,137 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + _| _) | | _) | _) + | _` | | | | | __| _ \ __| _ \ __ \ _` | | __| | _ \ __ \ + __| ( | | | | | | __/ ( ( | | | ( | | | | ( | | | + _| \__,_| _| _| \__,_| _| \___| \___| \___/ _| _| \__,_| _| \__| _| \___/ _| _| + + _) | | | + \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + \ \ \ / | | | | __/ \ \ / __/ | | + \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/FAILURE_CONDITION_WILL_REVERT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ trigger_MMU | | +|   | | | | +|   | | trigger_MMU ≡ hash_init_code | | +|   | | hash_init_code ≡ [size ≠ 0] | | +|   | | . ∧ is_CREATE2 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 1 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [acc/NONCE ≠ 0] ∨ [acc/HAS_CODE = 1] | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 1) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| i + 5 | ACC | Load account with address I_a | | τ ∙ ρ + ε_rev | τ ∙ h + 2 | +|   | | ♻️sameAddress[5,3] | | | | +|   | | ⏪undoNonceUpdate[5,3] | | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| i + 6 | ACC | Read account with address δ | | τ ∙ ρ + ε_rev | τ ∙ h + 3 | +|   | | ♻️sameAddress[6,4] | | | | +|   | | ⏪undoWarmthUpdate[6,4] | | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+---------------+-----------| +| i + 7 | CON | nonContextProvidesEmptyReturnData( current context ) | +|-----------+--------+------------------------------------------------------| + + +NOTE. We use the following shorthands + + * ρ ≡ CONTEXT_REVERT_STAMP + * h ≡ HUB_STAMP + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/failure_condition/wont_revert.lua.tex b/hub/instruction_handling/create/lua/failure_condition/wont_revert.lua.tex new file mode 100644 index 0000000..4b540b8 --- /dev/null +++ b/hub/instruction_handling/create/lua/failure_condition/wont_revert.lua.tex @@ -0,0 +1,128 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + _| _) | | _) | _) + | _` | | | | | __| _ \ __| _ \ __ \ _` | | __| | _ \ __ \ + __| ( | | | | | | __/ ( ( | | | ( | | | | ( | | | + _| \__,_| _| _| \__,_| _| \___| \___| \___/ _| _| \__,_| _| \__| _| \___/ _| _| + + ) | | + \ \ \ / _ \ __ \ / __| __| _ \ \ \ / _ \ __| __| + \ \ \ / ( | | | | | __/ \ \ / __/ | | + \_/\_/ \___/ _| _| \__| _| \___| \_/ \___| _| \__| + + +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+------------------------------------------------------+---------------------------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------| +| i  | SCEN |  CREATE/FAILURE_CONDITION_WONT_REVERT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|   | | | .  CREATE/FAILURE_CONDITION_WILL_REVERT ≡ CN_WILL_REVERT | +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ trigger_MMU | | +|   | | | | +|   | | trigger_MMU ≡ hash_init_code | | +|   | | hash_init_code ≡ [size ≠ 0] | | +|   | | . ∧ is_CREATE2 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 1 | +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------+-----------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------+-----------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [acc/NONCE ≠ 0] ∨ [acc/HAS_CODE = 1] | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 1) | | | +|-----------+--------+------------------------------------------------------+---------------------------------------------------------------------+-----------+-----------| +| i + 5 | CON | nonContextProvidesEmptyReturnData( current context ) | +|-----------+--------+------------------------------------------------------| + +NOTE. We use the following shorthands + + * h ≡ HUB_STAMP + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/highlevel.lua.tex b/hub/instruction_handling/create/lua/highlevel.lua.tex new file mode 100644 index 0000000..d3a24b3 --- /dev/null +++ b/hub/instruction_handling/create/lua/highlevel.lua.tex @@ -0,0 +1,93 @@ +\documentclass[tikz, border = 1cm]{standalone} +\usepackage{xcolor} +\usepackage{fontawesome} +\usepackage{amsmath} +\usepackage{../../../../pkg/draculatheme} +\usepackage{../../../../pkg/common} +\usepackage{../../../../pkg/env} +\usepackage{../../../../pkg/exceptions} +\usepackage{../../../../pkg/flags_stamps_selectors} +\usetikzlibrary{arrows.meta} +\begin{document} +\input{hub/instruction_handling/create/_local} +\begin{tikzpicture} +\def\BAS {-3} +\def\Bas {-2.5} +\def\bas {-2} +\def\droite{ 3.5} +\def\Droite{ 6.5} +\def\gauche{-3.5} +\def\Gauche{-6.5} + + \begin{scope}[every node/.style={rectangle, thick, draw, rounded corners = 3pt, inner sep = 6pt, outer sep = 4pt}] + \node [draw=draculapurple] (sux) at (0,0) {\suxSH}; + \path (sux) ++ (0,\Bas) node[draw=red] (exception) {\begin{tabular}{c} exception\\ $\xAhoy \equiv 1$\end{tabular}}; + \path (exception) ++ (0,\Bas) node[draw=orange] (abort) {\begin{tabular}{c} aborting condition\\ $\locOobAbortingCondition \equiv 1$\end{tabular}}; + \path (abort) ++ (0,\Bas) node[draw=yellow] (failure condition) {\begin{tabular}{c} failure condition $F$\\ $\locOobFailureCondition \equiv 1$\end{tabular}}; + \path (failure condition) ++ (0,\Bas) node[draw=draculagreen] (entry) {entry}; + \path (entry) ++ (\gauche, \bas) node[draw=draculagreen] (empty) {\begin{tabular}{c} empty\\init code\end{tabular}}; + \path (entry) ++ (\droite, \bas) node[draw=draculagreen] (nonempty) {\begin{tabular}{c} nonempty\\init code\end{tabular}}; + \end{scope} + + \begin{scope}[every node/.style={rectangle, thick, draw, rounded corners = 3pt, inner sep=6pt, outer sep = 4pt}] + \path (exception) ++ (\Droite,0) node [draw = draculacomment] (staticx) {\staticxSH}; + \path (staticx) ++ (0,\bas) node [draw = draculacomment] (mxpx) {\mxpxSH}; + \path (mxpx) ++ (0,\bas) node [draw = draculacomment] (oogx) {\oogxSH}; + \path (failure condition) ++ (\Gauche,0) node [draw = draculacomment] (failure condition will revert) {will revert}; + \path (failure condition will revert) ++ (0,\bas) node [draw = draculacomment] (failure condition wont revert) {won't revert}; + \path (empty) ++ (0,\Bas) ++ (0,\Bas) ++ (0,\bas) node [draw = draculacomment] (empty success) {success}; + \path (empty success) ++ (\gauche,0) node [draw = draculacomment] (empty success will revert) {will revert}; + \path (empty success will revert) ++ (0,\bas) node [draw = draculacomment] (empty success wont revert) {won't revert}; + \path (nonempty) ++ (0,\Bas) node [draw = draculacomment] (nonempty failure) {failure}; + \path (nonempty failure) ++ (\droite,0) node [draw = draculacomment] (nonempty failure will revert) {will revert}; + \path (nonempty failure will revert) ++ (0,\bas) node [draw = draculacomment] (nonempty failure wont revert) {won't revert}; + \path (nonempty failure) ++ (0,\Bas) ++ (0,\bas) node [draw = draculacomment] (nonempty success) {success}; + \path (nonempty success) ++ (\droite,0) node [draw = draculacomment] (nonempty success will revert) {will revert}; + \path (nonempty success will revert) ++ (0,\bas) node [draw = draculacomment] (nonempty success wont revert) {won't revert}; +\end{scope} + +\iffalse +\ref{hub: instruction handling: create: lua: staticx} +\ref{hub: instruction handling: create: lua: mxpx} +\ref{hub: instruction handling: create: lua: oogx} +\ref{hub: instruction handling: create: lua: unexceptional} +\ref{hub: instruction handling: create: lua: abort} +\ref{hub: instruction handling: create: lua: will revert} +\ref{hub: instruction handling: create: lua: wont revert} +\ref{hub: instruction handling: create: lua: will revert} +\ref{hub: instruction handling: create: lua: wont revert} +\ref{hub: instruction handling: create: lua: failure will revert} +\ref{hub: instruction handling: create: lua: failure wont revert} +\ref{hub: instruction handling: create: lua: success will revert} +\ref{hub: instruction handling: create: lua: success wont revert} +\fi + +\begin{scope}[>={latex[draculacomment]}, + every node/.style={}, + every edge/.style={draw=draculacomment,very thick}] + \path (sux) ++ (\Gauche, 1) node (create type inst) [color=draculacomment] {\Large{\inst{CREATE}-type instruction}}; + \path [->] (create type inst.357) edge (sux.north west); + \path [->] (sux) edge (exception); + \path [->] (exception) edge (staticx); + \path [->] (exception) edge (abort); + \path [->] (staticx) edge (mxpx); + \path [->] (mxpx) edge (oogx); + \path [->] (abort) edge (failure condition); + \path [->] (failure condition) edge (failure condition will revert); + \path [->] (failure condition will revert) edge (failure condition wont revert); + \path [->] (failure condition) edge (entry); + \path [->] (entry) edge (empty); + \path [->] (empty) edge (empty success); + \path [->] (empty success) edge (empty success will revert); + \path [->] (empty success will revert) edge (empty success wont revert); + \path [->] (entry) edge (nonempty); + \path [->] (nonempty) edge (nonempty failure); + \path [->] (nonempty failure) edge (nonempty failure will revert); + \path [->] (nonempty failure will revert) edge (nonempty failure wont revert); + \path [->] (nonempty failure) edge (nonempty success); + \path [->] (nonempty success) edge (nonempty success will revert); + \path [->] (nonempty success will revert) edge (nonempty success wont revert); +\end{scope} + +\end{tikzpicture} +\end{document} diff --git a/hub/instruction_handling/create/lua/nonempty/failure_will_revert.lua.tex b/hub/instruction_handling/create/lua/nonempty/failure_will_revert.lua.tex new file mode 100644 index 0000000..789690b --- /dev/null +++ b/hub/instruction_handling/create/lua/nonempty/failure_will_revert.lua.tex @@ -0,0 +1,168 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) _) | | + __ \ _ \ __ \ _ \ __ `__ \ __ \ __| | | | __ \ | __| __| _ \ _` | _ \ + | | ( | | | __/ | | | | | | | | | | | | | ( ( | ( | __/ + _| _| \___/ _| _| \___| _| _| _| .__/ \__| \__, | _| _| _| _| \__| \___| \___/ \__,_| \___| + _| ____/ + + + _| _) | / _) | | | + | _` | | | | | __| _ \ / \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + __| ( | | | | | | __/ / \ \ \ / | | | | __/ \ \ / __/ | | + _| \__,_| _| _| \__,_| _| \___| _/ \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ 1 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 0 | +|   | | | . mxp/MXP_MTNTOP = 0 (i.e. size == 0) | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | ⤴️decrementBalance (i.e. balance -= value) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️incrementNonce (i.e. nonce: 0 → 1) | | | | +|   | | ⤴️incrementBalance (i.e. balance += value) | | | | +|   | | ⤴️incrementDeploymentNumber (i.e. depNumber += 1) | | | | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . acc/NONCE = 0 | | | +|   | | | . acc/HAS_CODE = 0 | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 0) | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 5 | ACC | Load account with address I_a | | τ ∙ ρ_chld + ε_rev | 2 | +|   | | ♻️sameAddress[5,3] | | | | +|   | | ♻️sameNonce[5] | | | | +|   | | ⏪undoBalanceUpdate[5,3] | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 6 | ACC | Read account with address δ | | τ ∙ ρ_chld + ε_rev | 3 | +|   | | ♻️sameAddress[6,4] | | | | +|   | | ⏪undoNonceUpdate[6,4] | | | | +|   | | ⏪undoBalanceUpdate[6,4] | | | | +|   | | ⏪undoDeploymentNumberAndStatus[6,4] | | | | +|   | | ♻️sameWarmth[6] | | | | +|   | | ⏪undoCodeUpdate[6,4] | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 7 | ACC | Load account with address I_a | | τ ∙ ρ_curr + ε_rev | 4 | +|   | | ♻️sameAddress[7,5] | | | | +|   | | ⏪undoNonceUpdate[7,5] | | | | +|   | | ♻️sameBalance[7] | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 8 | ACC | Read account with address δ | | τ ∙ ρ_curr + ε_rev | 5 | +|   | | ♻️sameAddress[8,6] | | | | +|   | | ♻️sameNonce[8] | | | | +|   | | ♻️sameBalance[8] | | | | +|   | | ♻️sameDeploymentNumberAndStatus[8] | | | | +|   | | ⏪undoWarmthUpdate[8,6] | | | | +|   | | ♻️sameCode[8] | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|-----------+--------+------------------------------------------------------+-------------------------------------------------------------+----------------------+-----------| +| i + 9 | CON | initializeDeploymentContext( next context ) | +| | | firstRowOfDeploymentContext( next context ) | +| | | justifyCreateeRevertData( next context ) | +|-----------+--------+------------------------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/nonempty/failure_wont_revert.lua.tex b/hub/instruction_handling/create/lua/nonempty/failure_wont_revert.lua.tex new file mode 100644 index 0000000..00b2d72 --- /dev/null +++ b/hub/instruction_handling/create/lua/nonempty/failure_wont_revert.lua.tex @@ -0,0 +1,148 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) _) | | + __ \ _ \ __ \ _ \ __ `__ \ __ \ __| | | | __ \ | __| __| _ \ _` | _ \ + | | ( | | | __/ | | | | | | | | | | | | | ( ( | ( | __/ + _| _| \___/ _| _| \___| _| _| _| .__/ \__| \__, | _| _| _| _| \__| \___| \___/ \__,_| \___| + _| ____/ + + + _| _) | / ) | | + | _` | | | | | __| _ \ / \ \ \ / _ \ __ \ / __| __| _ \ \ \ / _ \ __| __| + __| ( | | | | | | __/ / \ \ \ / ( | | | | | __/ \ \ / __/ | | + _| \__,_| _| _| \__,_| _| \___| _/ \_/\_/ \___/ _| _| \__| _| \___| \_/ \___| _| \__| + + +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ 1 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 0 | +|   | | | . mxp/MXP_MTNTOP = 0 (i.e. size == 0) | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | ⤴️decrementBalance (i.e. balance -= value) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️incrementNonce (i.e. nonce: 0 → 1) | | | | +|   | | ⤴️incrementBalance (i.e. balance += value)| | | | +|   | | ⤴️incrementDeploymentNumber (i.e. depNumber += 1) | | | | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . acc/NONCE = 0 | | | +|   | | | . acc/HAS_CODE = 0 | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 0) | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 5 | ACC | Load account with address I_a | | τ ∙ ρ_chld + ε_rev | 2 | +|   | | ♻️sameAddress[5,3] | | | | +|   | | ⏪sameNonce[5] | | | | +|   | | ⏪undoBalanceUpdate[5,3] | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 6 | ACC | Read account with address δ | | τ ∙ ρ_chld + ε_rev | 3 | +|   | | ♻️sameAddress[6,4] | | | | +|   | | ⏪undoNonceUpdate[6,4] | | | | +|   | | ⏪undoBalanceUpdate[6,4] | | | | +|   | | ⏪undoDeploymentNumberAndStatus[6,4] | | | | +|   | | ♻️sameWarmth[6] | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 7 | CON | initializeDeploymentContext( next context ) | +| | | firstRowOfDeploymentContext( next context ) | +| | | justifyCreateeRevertData( next context ) | +|-----------+--------+----------------------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/nonempty/success_will_revert.lua.tex b/hub/instruction_handling/create/lua/nonempty/success_will_revert.lua.tex new file mode 100644 index 0000000..79ea9ec --- /dev/null +++ b/hub/instruction_handling/create/lua/nonempty/success_will_revert.lua.tex @@ -0,0 +1,152 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) _) | | + __ \ _ \ __ \ _ \ __ `__ \ __ \ __| | | | __ \ | __| __| _ \ _` | _ \ + | | ( | | | __/ | | | | | | | | | | | | | ( ( | ( | __/ + _| _| \___/ _| _| \___| _| _| _| .__/ \__| \__, | _| _| _| _| \__| \___| \___/ \__,_| \___| + _| ____/ + + + / _) | | | + __| | | __| __| _ \ __| __| / \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ / \ \ \ / | | | | __/ \ \ / __/ | | + ____/ \__,_| \___| \___| \___| ____/ ____/ _/ \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ 1 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 0 | +|   | | | . mxp/MXP_MTNTOP = 0 (i.e. size == 0) | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | Compute deployment address | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | ⤴️decrementBalance (i.e. balance -= value) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | computeDeploymentAddress() | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️incrementNonce (i.e. nonce: 0 → 1) | | | | +|   | | ⤴️incrementBalance (i.e. balance += value)| | | | +|   | | ⤴️incrementDeploymentNumber (i.e. depNumber += 1) | | | | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | updateCodeSize( size_lo ) | | | | +|   | | updateCodeHash( KECCAK( ∅ ) ) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | requestCodeFragmentIndex() | * acc/CODE_FRAGMENT_INDEX | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . acc/NONCE = 0 | | | +|   | | | . acc/HAS_CODE = 0 | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 0) | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 5 | ACC | Load account with address I_a | | τ ∙ ρ_curr + ε_rev | 2 | +|   | | ♻️sameAddress[5,3] | | | | +|   | | ⏪undoNonceUpdate | | | | +|   | | ⏪undoBalanceUpdate | | | | +|   | | ⏪undoCodeUpdate | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 6 | ACC | Read account with address δ | | τ ∙ ρ_curr + ε_rev | 3 | +|   | | ♻️sameAddress[6,4] | | | | +|   | | ⏪undoNonceUpdate | | | | +|   | | ⏪undoBalanceUpdate | | | | +|   | | ⏪undoDeploymentNumberAndStatus | | | | +|   | | ⏪undoWarmthUpdate | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+--------------------+-----------| +| i + 7 | CON | initializeDeploymentContext( next context ) | +| | | firstRowOfDeploymentContext( next context ) | +| | | justifyCreateeRevertData( next context ) | +|-----------+--------+----------------------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/nonempty/success_wont_revert.lua.tex b/hub/instruction_handling/create/lua/nonempty/success_wont_revert.lua.tex new file mode 100644 index 0000000..290f3ba --- /dev/null +++ b/hub/instruction_handling/create/lua/nonempty/success_wont_revert.lua.tex @@ -0,0 +1,133 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) _) | | + __ \ _ \ __ \ _ \ __ `__ \ __ \ __| | | | __ \ | __| __| _ \ _` | _ \ + | | ( | | | __/ | | | | | | | | | | | | | ( ( | ( | __/ + _| _| \___/ _| _| \___| _| _| _| .__/ \__| \__, | _| _| _| _| \__| \___| \___/ \__,_| \___| + _| ____/ + + + / ) | | + __| | | __| __| _ \ __| __| / \ \ \ / _ \ __ \ / __| __| _ \ \ \ / _ \ __| __| + \__ \ | | ( ( __/ \__ \ \__ \ / \ \ \ / ( | | | | | __/ \ \ / __/ | | + ____/ \__,_| \___| \___| \___| ____/ ____/ _/ \_/\_/ \___/ _| _| \__| _| \___| \_/ \___| _| \__| + + +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+----------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i  | SCEN |  CREATE/ABORT ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Provides: | +|   | | | * con/CALL_STACK_DEPTH | +|   | | | * con/ACCOUNT_ADDRESS (I_a) | +|   | | | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +|   | | | * mxp/MXP_MTNTOP | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +| | | misc/MMU🚩 ≡ 1 | | +|   | | | | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|   | | | . OOB_aborting_condition = 0 | +|   | | | . OOB_failure_condition = 0 | +|   | | | . mxp/MXP_MTNTOP = 0 (i.e. size == 0) | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 3 | ACC | Load account with address I_a | | τ ∙ h + 0 | 0 | +|   | | ♻️sameAddress[6,4] | | | | +|   | | ⤴️incrementNonce (i.e. nonce += 1) | | | | +|   | | ⤴️decrementBalance (i.e. balance -= value) | | | | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|   | | computeDeploymentAddress() | * acc/DEPLOYMENT_ADDRESS ≡ δ | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . [con/CALL_STACK_DEPTH ≠ 1024] ∧ [acc/BALANCE ≥ value] | | | +|   | | | . (<== this triggers OOB_aborting_condition ≡ 0) | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 4 | ACC | Read account with address δ | | τ ∙ h + 1 | 0 | +|   | | ⤴️incrementNonce (i.e. nonce: 0 → 1) | | | | +|   | | ⤴️incrementBalance (i.e. balance += value)| | | | +|   | | ⤴️incrementDeploymentNumber (i.e. depNumber += 1) | | | | +|   | | ⤴️turnOnWarmth (i.e. warmth ↑) | | | | +|   | | | | | | +|   | | updateCodeSize( size_lo ) | | | | +|   | | updateCodeHash( KECCAK( ∅ ) ) | | | | +|   | | | Provides: | | | +|   | | | * acc/NONCE | | | +|   | | | * acc/HAS_CODE | | | +|   | | | | | | +|   | | | Implicitly: | | | +|   | | | . acc/NONCE = 0 | | | +|   | | | . acc/HAS_CODE = 0 | | | +|   | | | . (<== this triggers OOB_failure_condition ≡ 0) | | | +|-----------+--------+----------------------------------------------------+-------------------------------------------------------------+-----------+-----------| +| i + 5 | CON | initializeDeploymentContext( next context ) | +| | | firstRowOfDeploymentContext( next context ) | +| | | justifyCreateeRevertData( next context ) | +|-----------+--------+----------------------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/create/lua/unexceptional.lua.tex b/hub/instruction_handling/create/lua/unexceptional.lua.tex new file mode 100644 index 0000000..f92d061 --- /dev/null +++ b/hub/instruction_handling/create/lua/unexceptional.lua.tex @@ -0,0 +1,93 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + + ██████\ ███████\ ████████\ ██████\ ████████\ ████████\ ███\ ██████\ ███\ + ██ __██\ ██ __██\ ██ _____|██ __██\\__██ __|██ _____| ██ _|██ __██\ \██\ + ██ / \__|██ | ██ |██ | ██ / ██ | ██ | ██ | ██ / \__/ ██ | \██\ + ██ | ███████ |█████\ ████████ | ██ | █████\ ██ | ██████ | ██ | + ██ | ██ __██< ██ __| ██ __██ | ██ | ██ __| ██ | ██ ____/ ██ | + ██ | ██\ ██ | ██ |██ | ██ | ██ | ██ | ██ | \██\ ██ | ██ | + \██████ |██ | ██ |████████\ ██ | ██ | ██ | ████████\ \███\ ████████\ ███ / + \______/ \__| \__|\________|\__| \__| \__| \________| \___|\________|\___/ + + + | _) | + | | __ \ _ \ \ \ / __| _ \ __ \ __| | _ \ __ \ _` | | + | | | | __/ ` < ( __/ | | | | ( | | | ( | | + \__,_| _| _| \___| _/\_\ \___| \___| .__/ \__| _| \___/ _| _| \__,_| _| + _| + + +|-----------+--------+----------------------------------------+---------------------------------------------------------+-----------+-----------| +| Row index | Persp. | Actions | Notes | DOM_STAMP | SUB_STAMP | +|:---------:+--------+----------------------------------------+---------------------------------------------------------+-----------+-----------| +| i - 2 | STACK | | required: | +| i - 1 | STACK | | * stack/STATICX ≡ 0 | +|   | | | * stack/MXPX ≡ 0 | +|   | | | * stack/OOGX ≡ 0 | +|   | | | . => XAHOY ≡ 0 | +|-----------+--------+----------------------------------------+---------------------------------------------------------| +| i  | SCEN |  CREATE/unexceptional ≡ 1 | | +|   | | | | +|   | | | Impose that: | +|   | | | .  CREATE/EXCEPTION ≡ XAHOY ≡ 0 | +|   | | | .  CREATE/ABORT ≡ OOB_aborting_condition | +|   | | | .  CREATE/failure_condition ≡ OOB_failure_condition | +|-----------+--------+----------------------------------------+---------------------------------------------------------| +| i + 1 | CON | readContextData( current context ) | | +|   | | | | +|   | | Impose that: | | +|   | | . context/IS_STATIC = stack/STATICX | | +|   | | | Implicitly: | +|   | | | . context/IS_STATIC = 0 | +|   | | | | +|   | | | * provides con/CALL_STACK_DEPTH | +|-----------+--------+----------------------------------------+---------------------------------------------------------| +| i + 2 | MISC | misc/MXP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * mxp/MXPX | +|   | | | * mxp/MXP_GAS | +| | | misc/STP🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * stp/OOGX | +|   | | | * stp/UPFRONT_GAS_COST | +|   | | | * stp/63_64_ths | +| | | misc/OOB🚩 ≡ 1 | | +|   | | | Provides: | +|   | | | * OOB_aborting_condition | +|   | | | * OOB_failure_condition | +|   | | Impose that: | | +|   | | . misc/mxp/MXPX = stack/MXPX | | +|   | | . misc/stp/OOGX = stack/OOGX | | +|   | | | | +|   | | | Implicitly: | +|   | | | . misc/mxp/MXPX = 0 | +|   | | | . misc/stp/OOGX = 0 | +|-----------+--------+----------------------------------------+---------------------------------------------------------+-----------+-----------| +| i + 3 | ACC | ... depends ... | | τ ∙ h + 0 | 0 | +|   | | | Provides: | | | +|   | | | * acc/BALANCE | | | +|-----------+--------+----------------------------------------+---------------------------------------------------------+-----------+-----------| +| i + 4 | ??? | +|-----------+--------| + +\end{verbatim} +\end{document} + diff --git a/hub/instruction_handling/create/non_stack_rows.tex b/hub/instruction_handling/create/non_stack_rows.tex new file mode 100644 index 0000000..e5b6b87 --- /dev/null +++ b/hub/instruction_handling/create/non_stack_rows.tex @@ -0,0 +1,72 @@ +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that} + \left\{ \begin{array}{lclr} + \peekScenario _{i} & = & 1 \\ + \scenCreateSum _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +With the shorthands defined in section~(\ref{hub: instruction handling: create: peeking flags shorthands}) we impose the following constraints: +\begin{description} + \item[\underline{Setting \nonStackRows{}:}] + we set \nonStackRows{} once and for all, though we will set it again at later points to clarify: + \[ + \nonStackRows_{i - \createFirstStackRowOffset} + = + \left[ \begin{array}{lrcl} + + & (1 + \createExceptionCallerContextRowOffset ) & \!\!\! \cdot \!\!\! & \scenCreateException _{i} \\ + + & (1 + \createAbortCurrentContextRowOffset ) & \!\!\! \cdot \!\!\! & \scenCreateAbort _{i} \\ + + & (1 + \createFCondWillRevertCurrentContextRowOffset ) & \!\!\! \cdot \!\!\! & \scenCreateFCondWillRevert _{i} \\ + + & (1 + \createFCondWontRevertCurrentContextRowOffset ) & \!\!\! \cdot \!\!\! & \scenCreateFCondWontRevert _{i} \\ + + & (1 + \createEmptyInitCodeWillRevertCurrentContextRowOffset ) & \!\!\! \cdot \!\!\! & \scenCreateEmptyInitCodeWillRevert _{i} \\ + + & (1 + \createEmptyInitCodeWontRevertCurrentContextRowOffset ) & \!\!\! \cdot \!\!\! & \scenCreateEmptyInitCodeWontRevert _{i} \\ + + & (1 + \createNonemptyInitCodeFailureWillRevertNewContextRowOffset) & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + + & (1 + \createNonemptyInitCodeFailureWontRevertNewContextRowOffset) & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + + & (1 + \createNonemptyInitCodeSuccessWillRevertNewContextRowOffset) & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + + & (1 + \createNonemptyInitCodeSuccessWontRevertNewContextRowOffset) & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + \end{array} \right] + \] + \item[\underline{Setting the peeking flags:}] + we set \nonStackRows{} once and for all, though we will set it again at later points to clarify: + \[ + \hspace*{-2.8cm} + \nonStackRows_{i - \createFirstStackRowOffset} + = + \left[ \begin{array}{lrcl} + + \!\!\! & \peekingSumStaticx & \!\!\! \cdot \!\!\! & \locStaticx \\ + + \!\!\! & \peekingSumMxpx & \!\!\! \cdot \!\!\! & \locMxpx \\ + + \!\!\! & \peekingSumOogx & \!\!\! \cdot \!\!\! & \locOogx \\ + + \!\!\! & \peekingSumAbort & \!\!\! \cdot \!\!\! & \scenCreateAbort _{i}\\ + + \!\!\! & \peekingSumFCondWillRevert & \!\!\! \cdot \!\!\! & \scenCreateFCondWillRevert _{i}\\ + + \!\!\! & \peekingSumFCondWontRevert & \!\!\! \cdot \!\!\! & \scenCreateFCondWontRevert _{i}\\ + + \!\!\! & \peekingSumEmptyInitCodeWillRevert & \!\!\! \cdot \!\!\! & \scenCreateEmptyInitCodeWillRevert _{i}\\ + + \!\!\! & \peekingSumEmptyInitCodeWontRevert & \!\!\! \cdot \!\!\! & \scenCreateEmptyInitCodeWontRevert _{i}\\ + + \!\!\! & \peekingSumNonEmptyInitCodeFailureWillRevert & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeFailureWillRevert _{i}\\ + + \!\!\! & \peekingSumNonEmptyInitCodeFailureWontRevert & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeSuccessWillRevert _{i}\\ + + \!\!\! & \peekingSumNonEmptyInitCodeSuccessWillRevert & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeFailureWontRevert _{i}\\ + + \!\!\! & \peekingSumNonEmptyInitCodeSuccessWontRevert & \!\!\! \cdot \!\!\! & \scenCreateNonEmptyInitCodeSuccessWontRevert _{i}\\ + \end{array} \right] + \] +\end{description} +\saNote{} +We set the value of $\nonStackRows$ on the \textbf{previous row} (i.e. we constrain $\nonStackRows_{i - 1}$) so as to connect back to the stack rows, thus preventing an attacker to set the previous value to \nonStackRows{} to $0$, say. Note that this isn't strictly speaking necessary since every new \hubStamp{} of the execution phase starts with one or two stack rows and the present row is a scenario row. + +Below are the concreate values of \nonStackRows{} depending on the \inst{CREATE}-type instruction scenario: +\begin{center} + \begin{tabular}{|l|l|c|} \hline + \multicolumn{2}{|l|}{\textsc{Scenario}} & \nonStackRows{} \\ \hline \hline + \scenCreateException{} & \suxSH{} & $1$ \\ \hline + \scenCreateException{} & \staticxSH{} & $1 + \createExceptionCallerContextRowOffset $ \\ \hline + \scenCreateException{} & \mxpxSH{} & $1 + \createExceptionCallerContextRowOffset $ \\ \hline + \scenCreateException{} & \oogxSH{} & $1 + \createExceptionCallerContextRowOffset $ \\ \hline \hline + \multicolumn{2}{|l|}{\scenCreateAbort} & $1 + \createAbortCurrentContextRowOffset $ \\ \hline \hline + \multicolumn{2}{|l|}{\scenCreateFCondWillRevert} & $1 + \createFCondWillRevertCurrentContextRowOffset $ \\ \hline + \multicolumn{2}{|l|}{\scenCreateFCondWontRevert} & $1 + \createFCondWontRevertCurrentContextRowOffset $ \\ \hline \hline + \multicolumn{2}{|l|}{\scenCreateEmptyInitCodeWillRevert} & $1 + \createEmptyInitCodeWillRevertCurrentContextRowOffset $ \\ \hline + \multicolumn{2}{|l|}{\scenCreateEmptyInitCodeWontRevert} & $1 + \createEmptyInitCodeWontRevertCurrentContextRowOffset $ \\ \hline \hline + \multicolumn{2}{|l|}{\scenCreateNonEmptyInitCodeFailureWillRevert} & $1 + \createNonemptyInitCodeFailureWillRevertNewContextRowOffset $ \\ \hline + \multicolumn{2}{|l|}{\scenCreateNonEmptyInitCodeSuccessWillRevert} & $1 + \createNonemptyInitCodeFailureWontRevertNewContextRowOffset $ \\ \hline + \multicolumn{2}{|l|}{\scenCreateNonEmptyInitCodeFailureWontRevert} & $1 + \createNonemptyInitCodeSuccessWillRevertNewContextRowOffset $ \\ \hline + \multicolumn{2}{|l|}{\scenCreateNonEmptyInitCodeSuccessWontRevert} & $1 + \createNonemptyInitCodeSuccessWontRevertNewContextRowOffset $ \\ \hline + \end{tabular} +\end{center} diff --git a/hub/instruction_handling/create/peeking_flag_shorthands.tex b/hub/instruction_handling/create/peeking_flag_shorthands.tex new file mode 100644 index 0000000..3c21d6c --- /dev/null +++ b/hub/instruction_handling/create/peeking_flag_shorthands.tex @@ -0,0 +1,166 @@ +We centralize in this section all computations relative to the number of non-stack-rows and the associated peeking flags. +We start by defining a series of peeking flag shorthands: +\begin{description} + \item[\underline{Standard flag sum prefix:}] + we define + \[ + \peekingSumStandardPrefix + \define + \left[ \begin{array}{ll} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \createCurrentContextRowOffset} \\ + + & \peekMisc _{i + \createMiscRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Exception: \staticxSH{}:}] + we define + \[ + \peekingSumStaticx + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekContext _{i + \createExceptionCallerContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Exception: \mxpxSH{}:}] + we define + \[ + \peekingSumMxpx + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekContext _{i + \createExceptionCallerContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Exception: \oogxSH{}:}] + we define + \[ + \peekingSumOogx + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekContext _{i + \createExceptionCallerContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Aborted:}] + we define + \[ + \peekingSumAbort + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekAccount _{i + \createFirstCreatorAccountRowOffset} \\ + + & \peekContext _{i + \createAbortCurrentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Failure condition \& execution will revert:}] + we define + \[ + \peekingSumFCondWillRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekAccount _{i + \createFirstCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createFirstCreateeAccountRowOffset} \\ + + & \peekAccount _{i + \createSecondCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createSecondCreateeAccountRowOffset} \\ + + & \peekContext _{i + \createFCondWillRevertCurrentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Failure condition \& execution won't revert:}] + we define + \[ + \peekingSumFCondWontRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekAccount _{i + \createFirstCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createFirstCreateeAccountRowOffset} \\ + + & \peekContext _{i + \createFCondWontRevertCurrentContextRowOffset} \\ + \end{array} \right] + \] +\end{description} +We shall label a \inst{CREATE}-type instruction that neither provokes an exception, nor is aborted, nor raises a failure condition as \textbf{sanctioned}. We may alternatively say that this instruction \textbf{gets executed}. +\begin{description} + \item[\underline{Sanctioned \inst{CREATE} flag sum prefix:}] + we define + \[ + \peekingSumSanctionedCreatePrefix + \define + \left[ \begin{array}{ll} + + & \peekingSumStandardPrefix \\ + + & \peekAccount _{i + \createFirstCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createFirstCreateeAccountRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Empty init code \& execution will revert:}] + we define + \[ + \peekingSumEmptyInitCodeWillRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumSanctionedCreatePrefix \\ + + & \peekAccount _{i + \createSecondCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createSecondCreateeAccountRowOffset} \\ + + & \peekContext _{i + \createEmptyInitCodeWillRevertCurrentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Empty init code \& execution won't revert:}] + we define + \[ + \peekingSumEmptyInitCodeWontRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumSanctionedCreatePrefix \\ + + & \peekContext _{i + \createEmptyInitCodeWontRevertCurrentContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Nonempty init code \& deployment failure \& execution will revert:}] + we define + \[ + \peekingSumNonEmptyInitCodeFailureWillRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumSanctionedCreatePrefix \\ + + & \peekAccount _{i + \createSecondCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createSecondCreateeAccountRowOffset} \\ + + & \peekAccount _{i + \createThirdCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createThirdCreateeAccountRowOffset} \\ + + & \peekContext _{i + \createNonemptyInitCodeFailureWillRevertNewContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Nonempty init code \& deployment failure \& execution won't revert:}] + we define + \[ + \peekingSumNonEmptyInitCodeFailureWontRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumSanctionedCreatePrefix \\ + + & \peekAccount _{i + \createSecondCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createSecondCreateeAccountRowOffset} \\ + + & \peekContext _{i + \createNonemptyInitCodeFailureWontRevertNewContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Nonempty init code \& deployment success \& execution will revert:}] + we define + \[ + \peekingSumNonEmptyInitCodeSuccessWillRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumSanctionedCreatePrefix \\ + + & \peekAccount _{i + \createSecondCreatorAccountRowOffset} \\ + + & \peekAccount _{i + \createSecondCreateeAccountRowOffset} \\ + + & \peekContext _{i + \createNonemptyInitCodeSuccessWillRevertNewContextRowOffset} \\ + \end{array} \right] + \] + \item[\underline{Nonempty init code \& deployment success \& execution won't revert:}] + we define + \[ + \peekingSumNonEmptyInitCodeSuccessWontRevert + \define + \left[ \begin{array}{ll} + + & \peekingSumSanctionedCreatePrefix \\ + + & \peekContext _{i + \createNonemptyInitCodeSuccessWontRevertNewContextRowOffset} \\ + \end{array} \right] + \] +\end{description} diff --git a/hub/instruction_handling/create/shorthands.tex b/hub/instruction_handling/create/shorthands.tex new file mode 100644 index 0000000..606c3f0 --- /dev/null +++ b/hub/instruction_handling/create/shorthands.tex @@ -0,0 +1,64 @@ +We shall use the following shorthands +\[ + \hspace*{-2.3cm} + \left\{ \begin{array}{lcl} + \locInst & \define & \stackInst _{i - \createFirstStackRowOffset} \\ + \locIsCreate & \define & \decFlag{1} _{i - \createFirstStackRowOffset} \\ + \locIsCreateTwo & \define & \decFlag{2} _{i - \createFirstStackRowOffset} \\ + \locStaticx & \define & \stackStaticx _{i - \createFirstStackRowOffset} \\ + \locMxpx & \define & \stackMxpx _{i - \createFirstStackRowOffset} \\ + \locOogx & \define & \stackOogx _{i - \createFirstStackRowOffset} \\ + \locOffsetHi & \define & \stackItemValHi{1} _{i - \createFirstStackRowOffset} \\ + \locOffsetLo & \define & \stackItemValLo{1} _{i - \createFirstStackRowOffset} \\ + \locSizeHi & \define & \stackItemValHi{2} _{i - \createFirstStackRowOffset} \\ + \locSizeLo & \define & \stackItemValLo{2} _{i - \createFirstStackRowOffset} \\ + \locCnWillRevert & \define & \cnWillRev _{i - \createFirstStackRowOffset} \\ + \locCnRevertStamp & \define & \cnRevStamp _{i - \createFirstStackRowOffset} \\ + \locInitCodeHashHi & \define & \stackHashInfoValHi _{i - \createFirstStackRowOffset} \\ + \locInitCodeHashLo & \define & \stackHashInfoValLo _{i - \createFirstStackRowOffset} \\ + \locInitCodeSize & \define & \stackItemValLo{2} _{i - \createFirstStackRowOffset} \\ % TODO: make sure this is doesn't fuck things up + % + \locSaltHi & \define & \stackItemValHi{2} _{i - \createSecondStackRowOffset} \\ + \locSaltLo & \define & \stackItemValLo{2} _{i - \createSecondStackRowOffset} \\ + \locValueHi & \define & \stackItemValHi{3} _{i - \createSecondStackRowOffset} \\ + \locValueLo & \define & \stackItemValLo{3} _{i - \createSecondStackRowOffset} \\ + \locOutputHi & \define & \stackItemValHi{4} _{i - \createSecondStackRowOffset} \\ + \locOutputLo & \define & \stackItemValLo{4} _{i - \createSecondStackRowOffset} \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcl} + \locCreatorAddressHi & \define & \cnAccountAddress\high _{i + \createCurrentContextRowOffset} \\ + \locCreatorAddressLo & \define & \cnAccountAddress\low _{i + \createCurrentContextRowOffset} \\ + \locIsStatic & \define & \cnStatic _{i + \createCurrentContextRowOffset} \\ + \locCsd & \define & \cnCsd _{i + \createCurrentContextRowOffset} \\ + % + \locCreateeSelfReverts & \define & \miscChildSelfReverts _{i + \createMiscRowOffset} \\ + \locCreateeRevertStamp & \define & \miscChildRevertStamp _{i + \createMiscRowOffset} \\ + \locOobAbortingCondition & \define & \miscOobDataCol{7} _{i + \createMiscRowOffset} \\ + \locOobFailureCondition & \define & \miscOobDataCol{8} _{i + \createMiscRowOffset} \\ + \locMxpMxpx & \define & \miscMxpMxpx _{i + \createMiscRowOffset} \\ + \locMxpGas & \define & \miscMxpGasMxp _{i + \createMiscRowOffset} \\ + \locMxpMtntop & \define & \miscMxpTypeFourInstMayTriggerMmu _{i + \createMiscRowOffset} \\ + \locStpGasPoop & \define & \miscStpGasPoop _{i + \createMiscRowOffset} \\ + \locStpOogx & \define & \miscStpOogx _{i + \createMiscRowOffset} \\ + % + \locComputeAddress & \define & \accRlpAddrFlag _{i + \createFirstCreatorAccountRowOffset} \\ + \locCreateeAddressHi & \define & \accRlpAddrDepAddrHi _{i + \createFirstCreatorAccountRowOffset} \\ + \locCreateeAddressLo & \define & \accRlpAddrDepAddrLo _{i + \createFirstCreatorAccountRowOffset} \\ + \locCreatorNonce & \define & \accNonce _{i + \createFirstCreatorAccountRowOffset} \\ + \locCreatorBalance & \define & \accBalance _{i + \createFirstCreatorAccountRowOffset} \\ + % + \locDepCfi & \define & \accCfi _{i + \createFirstCreateeAccountRowOffset} \\ + \locRomLexFlag & \define & \accRomLexFlag _{i + \createFirstCreateeAccountRowOffset} \\ + \end{array} \right. +\] +\saNote{} These shorthands only make sense given that both $\peekScenario_{i} = 1$ and $\scenCreateSum_{i} = 1$. These constraints will be imposed starting with section~(\ref{hub: instruction handling: create: generalities}) + +% \accRlpAddrFlag +% \accRlpAddrRecipe +% \accRlpAddrDepAddrHi +% \accRlpAddrDepAddrLo +% \accRlpAddrSaltHi +% \accRlpAddrSaltLo +% \accRlpAddrKecHi +% \accRlpAddrKecLo diff --git a/hub/instruction_handling/create/triggers/_inputs.tex b/hub/instruction_handling/create/triggers/_inputs.tex new file mode 100644 index 0000000..1b3f303 --- /dev/null +++ b/hub/instruction_handling/create/triggers/_inputs.tex @@ -0,0 +1,10 @@ +\input{instruction_handling/create/triggers/_local} +\subsubsubsection{Introduction} \label{hub: instruction handling: create: trigger: intro} \input{instruction_handling/create/triggers/intro} +\subsubsubsection{Setting \locTriggerMxp{} \lispDone{}} \label{hub: instruction handling: create: trigger: mxp} \input{instruction_handling/create/triggers/mxp} +\subsubsubsection{Setting \locTriggerStp{} \lispDone{}} \label{hub: instruction handling: create: trigger: stp} \input{instruction_handling/create/triggers/stp} +\subsubsubsection{Setting \locTriggerOob{} \lispDone{}} \label{hub: instruction handling: create: trigger: oob} \input{instruction_handling/create/triggers/oob} +\subsubsubsection{Setting \locTriggerMmu{} \lispDone{}} \label{hub: instruction handling: create: trigger: mmu} \input{instruction_handling/create/triggers/mmu} +\subsubsubsection{Setting \locTriggerHashInfo{} \lispDone{}} \label{hub: instruction handling: create: trigger: hash info} \input{instruction_handling/create/triggers/hashInfo} +\subsubsubsection{Setting \locTriggerRlpAddr{} \lispDone{}} \label{hub: instruction handling: create: trigger: rlp addr} \input{instruction_handling/create/triggers/rlpAddr} +\subsubsubsection{Setting \locTriggerRomLex{} \lispDone{}} \label{hub: instruction handling: create: trigger: rom lex} \input{instruction_handling/create/triggers/romLex} +\subsubsubsection{Table representation} \label{hub: instruction handling: create: trigger: graphical representation} \input{instruction_handling/create/triggers/table} diff --git a/hub/instruction_handling/create/triggers/_local.tex b/hub/instruction_handling/create/triggers/_local.tex new file mode 100644 index 0000000..fcb1af1 --- /dev/null +++ b/hub/instruction_handling/create/triggers/_local.tex @@ -0,0 +1,6 @@ +\def\createVertColStaticx {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\stackStaticx}}} +\def\createVertColMxpx {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\stackMxpx}}} +\def\createVertColOogx {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\stackOogx}}} +\def\nonemptyCreateTwo {{\textcolor{solarized-yellow}{\bm{\mathtt{NEC2}}}}} +\def\createOne {{\textcolor{solarized-yellow}{\bm{\mathtt{C1}}}}} +\def\createTwo {{\textcolor{solarized-yellow}{\bm{\mathtt{C2}}}}} diff --git a/hub/instruction_handling/create/triggers/hashInfo.tex b/hub/instruction_handling/create/triggers/hashInfo.tex new file mode 100644 index 0000000..deb3893 --- /dev/null +++ b/hub/instruction_handling/create/triggers/hashInfo.tex @@ -0,0 +1,44 @@ +We impose the following: +\begin{enumerate} + \item \If + \( + \left[ \begin{array}{ll} + + & \scenCreateException _{i} \\ + + & \scenCreateAbort _{i} \\ + + & \scenCreateExecutionEmptyInitCode _{i} \\ + \end{array} \right] = 1 + \) + \Then + \( \locTriggerHashInfo \define \gZero \) + \item \If $\scenCreateFCond = 1$ \Then $\locTriggerHashInfo \define \locMxpMtntop \cdot \locIsCreateTwo$ + + \saNote{} In other words + \begin{enumerate} + \item \If $\locSizeLo \neq 0$ \Then $\locTriggerHashInfo \define \locIsCreateTwo$ (\trash) + \item \If $\locSizeLo = 0$ \Then $\locTriggerHashInfo \define \gZero$ (\trash) + \end{enumerate} + \item \If $\scenCreateExecutionNonEmptyInitCode = 1$ \Then $\locTriggerHashInfo \define \locIsCreateTwo$ +\end{enumerate} +\saNote{} +One \emph{may} subsume the above into a single constraint +\[ + \locTriggerHashInfo + \define + \locIsCreateTwo + \cdot + \left[ \begin{array}{cr} + + & \scenCreateFCond \cdot \locMxpMtntop \\ + + & \scenCreateExecutionNonEmptyInitCode \\ + \end{array} \right] +\] +\saNote{} The \hashInfoMod{} is called by \inst{CREATE2} instructions to compute the \textbf{initialization code hash}; +this is required to compute the \textbf{deployment address}; +this is necessary \emph{iff} the following conditions are met: +(\emph{a}) the instruction is a \inst{CREATE2} +(\emph{b}) the instruction doesn't raise an exception +(\emph{c}) the instruction isn't aborted +(\emph{d}) the initialization code is nonempty; + +\saNote{} Hashing the initialization code \textbf{is required} in case of a failure condition (as it requires us computing the deployment address to confirm that it has either a nonzero nonce or nonempty code). + +\saNote{} The only difference between the \locTriggerMmu{} and \locTriggerHashInfo{} flags is that the \mmuMod{} module is \emph{always} triggered in case of a deployment of nonempty bytecode, while in similar circumstances the \hashInfoMod{} module is only triggered if the instruction is a \inst{CREATE2}. diff --git a/hub/instruction_handling/create/triggers/intro.tex b/hub/instruction_handling/create/triggers/intro.tex new file mode 100644 index 0000000..d669b20 --- /dev/null +++ b/hub/instruction_handling/create/triggers/intro.tex @@ -0,0 +1,15 @@ +In this section we specify the following ``module trigger shorthands.'' +\begin{multicols}{2} +\begin{itemize} + \item \locTriggerMxp{} + \item \locTriggerStp{} + \item \locTriggerOob{} + \item \locTriggerMmu{} + \item \locTriggerHashInfo{} + \item \locTriggerRlpAddr{} + \item \locTriggerRomLex{} + \item[\vspace{\fill}] +\end{itemize} +\end{multicols} +\noindent These are binary (by construction) flags which will be used to set certain columns in the processing of \inst{CREATE}-type instructions. +\saNote{} These shorthands only make sense given that both $\peekScenario_{i} = 1$ and $\scenCreateSum_{i} = 1$. These constraints will be imposed starting with section~(\ref{hub: instruction handling: create: generalities}) diff --git a/hub/instruction_handling/create/triggers/mmu.tex b/hub/instruction_handling/create/triggers/mmu.tex new file mode 100644 index 0000000..9e667cb --- /dev/null +++ b/hub/instruction_handling/create/triggers/mmu.tex @@ -0,0 +1,65 @@ +Consider the case of an \textbf{unexceptional}, \textbf{unaborted} \inst{CREATE}-type instruction which is provided with \textbf{nonempty initialization code}. +Given this premise the \mmuMod{} module may get invoked for several disctint reasons and serves different purposes each time. +These purposes are as follows: +\begin{description} + \item[\underline{The $\locHashInitCode \equiv \rOne \phantom{\big|}\!\!$ case:}] + to compute the initialization code hash for \inst{CREATE2} instructions that raise the failure condition $\yellowPaperFailureCondition$ + \item[\underline{The $\locHashInitCodeAndSendToRom \equiv \rOne \phantom{\big|}\!\!$ case:}] + to compute the initialization code hash for \inst{CREATE2} instructions that don't raise the failure condition $\yellowPaperFailureCondition$ and also send this initialization code to the \romMod{} module + \item[\underline{The $\locSendInitCodeToRom \equiv \rOne \phantom{\big|}\!\!$ case:}] + to send the initialization code to the \romMod{} module for unexceptional, unaborted \inst{CREATE} instructions that don't raise the failure condition $\yellowPaperFailureCondition$ +\end{description} +We refer the reader to \cite{EYP} for the definition of the failure condition $\yellowPaperFailureCondition$. + +We provide below the specification of the \locTriggerMmu{} flag which determines whether or not the \mmuMod{} gets triggered or not. +In light of the previous discussion we split this flag into \emph{de facto} exclusive binary flags which light up precisely for one of the previously described cases (and are zero in all other cases.) +\begin{enumerate} + \item we impose a threefold decomposition + \[ + \locTriggerMmu \define + \left[ \begin{array}{ll} + + \!\!\! & \locHashInitCode \\ + + \!\!\! & \locHashInitCodeAndSendToRom \\ + + \!\!\! & \locSendInitCodeToRom \\ + \end{array} \right] + \] + \item \If + \( + \left[ \begin{array}{ll} + + \!\!\! & \scenCreateException _{i} \\ + + \!\!\! & \scenCreateAbort _{i} \\ + + \!\!\! & \scenCreateExecutionEmptyInitCode _{i} \\ + \end{array} \right] = 1 + \) + \Then + \[ + \left\{ \begin{array}{lclr} + \locTriggerMmu & \define & \gZero & (\trash) \\ + \locHashInitCode & \define & \gZero \\ + \locHashInitCodeAndSendToRom & \define & \gZero \\ + \locSendInitCodeToRom & \define & \gZero \\ + \end{array} \right. + \] + \item \If $\scenCreateFCond = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \locTriggerMmu & \define & \locMxpMtntop \cdot \locIsCreateTwo & (\trash) \\ + \locHashInitCode & \define & \locMxpMtntop \cdot \locIsCreateTwo \\ + \locHashInitCodeAndSendToRom & \define & \gZero \\ + \locSendInitCodeToRom & \define & \gZero \\ + \end{array} \right. + \] + % \begin{enumerate} + % \item \If $\locSizeLo \neq 0$ \Then $\locTriggerMmu = \locIsCreateTwo$ + % \item \If $\locSizeLo = 0$ \Then $\locTriggerMmu = 0$ + % \end{enumerate} + \item \If $\scenCreateExecutionNonEmptyInitCode = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \locTriggerMmu & \define & \rOne & (\trash) \\ + \locHashInitCode & \define & \gZero \\ + \locHashInitCodeAndSendToRom & \define & \locIsCreateTwo \\ + \locSendInitCodeToRom & \define & \locIsCreate \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/hub/instruction_handling/create/triggers/mxp.tex b/hub/instruction_handling/create/triggers/mxp.tex new file mode 100644 index 0000000..fe02b69 --- /dev/null +++ b/hub/instruction_handling/create/triggers/mxp.tex @@ -0,0 +1,10 @@ +We trigger the \mxpMod{} in every case except for that of a \staticxSH{}. As such we impose +\[ + \locTriggerMxp \define + \left[ \begin{array}{ll} + % + & \scenCreateException _{i} \cdot (1 - \locStaticx) \\ + + & \locMxpx \\ + + & \locOogx \\ + + & \scenCreateUnexceptional _{i} \\ + \end{array} \right] +\] diff --git a/hub/instruction_handling/create/triggers/oob.tex b/hub/instruction_handling/create/triggers/oob.tex new file mode 100644 index 0000000..e1b4695 --- /dev/null +++ b/hub/instruction_handling/create/triggers/oob.tex @@ -0,0 +1,5 @@ +We trigger the \oobMod{} whenever no exception occurs; as such +\[ + \locTriggerOob \define \scenCreateUnexceptional _{i} +\] +\saNote{} Recall that the the \oobMod{} module detects aborting conditions and failure conditions for \inst{CREATE}-type instrutions. diff --git a/hub/instruction_handling/create/triggers/rlpAddr.tex b/hub/instruction_handling/create/triggers/rlpAddr.tex new file mode 100644 index 0000000..1023d9a --- /dev/null +++ b/hub/instruction_handling/create/triggers/rlpAddr.tex @@ -0,0 +1,8 @@ +We define +\[ + \locTriggerRlpAddr \define \scenCreateComputeAddress _{i} +\] +\saNote{} In other words: we systematically invoke the \rlpAddrMod{} module unless the \inst{CREATE}-type instruction either +(\emph{a}) raises an exception or +(\emph{b}) is aborted. + diff --git a/hub/instruction_handling/create/triggers/romLex.tex b/hub/instruction_handling/create/triggers/romLex.tex new file mode 100644 index 0000000..7512e12 --- /dev/null +++ b/hub/instruction_handling/create/triggers/romLex.tex @@ -0,0 +1,5 @@ +We define the following shorthand +\[ + \locTriggerRomLex \define \scenCreateExecutionNonEmptyInitCode_{i} +\] +Indeed the only time a \inst{CREATE}-type instruction induces communication with the \hubMod{} is when actual (initialization) code is deployed. In all other scenarios (ranging from exceptions, abortgs, failures and (temporary) deployments with empty initialization code) the \romMod{} remains unaffected. diff --git a/hub/instruction_handling/create/triggers/stp.tex b/hub/instruction_handling/create/triggers/stp.tex new file mode 100644 index 0000000..d3904bf --- /dev/null +++ b/hub/instruction_handling/create/triggers/stp.tex @@ -0,0 +1,9 @@ +We trigger the \stpMod{} when an \oogxSH{} occurs and whenever no exception occurs; as such +\[ + \locTriggerStp \define + \left[ \begin{array}{ll} + % + & \scenCreateException _{i} \cdot \locOogx \\ + + & \locOogx \\ + + & \scenCreateUnexceptional _{i} \\ + \end{array} \right] +\] diff --git a/hub/instruction_handling/create/triggers/table.tex b/hub/instruction_handling/create/triggers/table.tex new file mode 100644 index 0000000..adcd795 --- /dev/null +++ b/hub/instruction_handling/create/triggers/table.tex @@ -0,0 +1,37 @@ +\begin{figure} + \centering + \[ + \hspace*{-2.5cm} + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|l|c|c|c|c|c|c|c|c|c|c|c|c|} + \cline{3-14} + \multicolumn{2}{c|}{} & + \createVertColStaticx & + \createVertColMxpx & + \createVertColOogx & + \columnCreateB & + \columnCreateD & + \columnCreateC & + \columnCreateF & + \columnCreateE & + \columnCreateH & + \columnCreateG & + \columnCreateJ & + \columnCreateI \\ \cline{2-14} + \multicolumn{1}{c|}{} &  \locTriggerMxp & \rCross & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark \\ \cline{2-14} + \multicolumn{1}{c|}{} &  \locTriggerStp & \rCross & \rCross & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark \\ \cline{2-14} + \multicolumn{1}{c|}{} &  \locTriggerOob & \rCross & \rCross & \rCross & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark \\ \hline + \multirow{4}{*}{\locTriggerMmu} &  \locHashInitCode & \rCross & \rCross & \rCross & \rCross & \nonemptyCreateTwo & \nonemptyCreateTwo & \rCross & \rCross & \rCross & \rCross & \rCross & \rCross \\ \cline{2-14} + &  \locHashInitCodeAndSendToRom & \rCross & \rCross & \rCross & \rCross & \rCross & \rCross & \createTwo & \createTwo & \createTwo & \createTwo & \rCross & \rCross \\ \cline{2-14} + &  \locSendInitCodeToRom & \rCross & \rCross & \rCross & \rCross & \rCross & \rCross & \createOne & \createOne & \createOne & \createOne & \rCross & \rCross \\ \cline{2-14} + &  \locTriggerMmu & \rCross & \rCross & \rCross & \rCross & \nonemptyCreateTwo & \nonemptyCreateTwo & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \rCross & \rCross \\ \hline + \multicolumn{1}{c|}{} &  \locTriggerRlpAddr & \rCross & \rCross & \rCross & \rCross & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark \\ \cline{2-14} + \multicolumn{1}{c|}{} &  \locTriggerHashInfo & \rCross & \rCross & \rCross & \rCross & \nonemptyCreateTwo & \nonemptyCreateTwo & \createTwo & \createTwo & \createTwo & \createTwo & \rCross & \rCross \\ \cline{2-14} + \multicolumn{1}{c|}{} &  \locTriggerRomLex & \rCross & \rCross & \rCross & \rCross & \rCross & \rCross & \gCheckMark & \gCheckMark & \gCheckMark & \gCheckMark & \rCross & \rCross \\ \cline{2-14} + \end{array} + \] + \caption{We use the following shorthands: + $\createOne \define \locIsCreate$, + $\createTwo \define \locIsCreateTwo$ and + $\nonemptyCreateTwo \define \locMxpMtntop \cdot \locIsCreateTwo$ (the acronym stands for \textbf{nonempty \inst{CREATE2}}.)} +\end{figure} diff --git a/hub/instruction_handling/dup.tex b/hub/instruction_handling/dup.tex new file mode 100644 index 0000000..4518126 --- /dev/null +++ b/hub/instruction_handling/dup.tex @@ -0,0 +1,40 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +The \inst{DUPX}-instructions are all one line instructions (i.e. $\tli = 0$.) For instructions that conform to the \dupSP{} the value of $\inst{X}$ can be derived from the instruction via $\inst{X} = \INST - \inst{DUP1} + 1$. Locally within section~\ref{hub: stack patterns: dup} we use the shorthand $\param := \INST - \inst{DUP1} = \inst{X} - 1$. +\[ +\begin{array}{|l||c||c|r|} + \hline + \INST & \tli & \stackDecDupFlag & \param \\ \hline\hline + \inst{DUP1-16} & \zero & \oneCell & \inst{X} - 1 \\ \hline +\end{array} +\] + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +\begin{center} +\boxed{% +\text{The stack constraints presented below assume } +\begin{cases} +\peekStack_{i} = 1 \\ +\stackDecDupFlag_{i} = 1 \\ +\stackSux_{i} + \stackSox_{i} = 0 \\ +\end{cases}} +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose $\dupSP\big[ \INST_{i} - \inst{DUP1} \big]_{i}$ + \item[\underline{Setting $\nonStackRows$:}] we impose $\nonStackRows_{i} = \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] we impose + \[ + \cmc_{i} \cdot \peekContext_{i + 1} = \nonStackRows_{i} \quad (\trash) + \] + \item[\underline{Setting the gas cost:}] we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] implicit in the stack pattern; %\If $\cmc_{i} = 0$ \Then +\end{description} +\saNote{} For instructions raising the $\stackDecDupFlag$ one has $\cmc \equiv \xAhoy$. diff --git a/hub/instruction_handling/ext.tex b/hub/instruction_handling/ext.tex new file mode 100644 index 0000000..44ccfba --- /dev/null +++ b/hub/instruction_handling/ext.tex @@ -0,0 +1,8 @@ +\[ + \begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecExtFlag \\ \hline\hline + \inst{ADDMOD} & \zero & \oneCell \\ \hline + \inst{MULMOD} & \zero & \oneCell \\ \hline + \end{array} +\] diff --git a/hub/instruction_handling/halt.tex b/hub/instruction_handling/halt.tex new file mode 100644 index 0000000..5907a85 --- /dev/null +++ b/hub/instruction_handling/halt.tex @@ -0,0 +1,409 @@ +% \subsubsection{Supported instructions and flags} +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% \subsubsection{The \inst{SELFDESTRUCT} case} +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% \begin{center} +% \boxed{% +% \text{The stack constraints presented below assume } +% \left\{ +% \begin{array}{lcl} +% \peekStack_{i} & \!\!\! = \!\!\! & 1 \\ +% \stackDecHaltFlag_{i} & \!\!\! = \!\!\! & 1 \\ +% \decFlag{4}_{i} & \!\!\! = \!\!\! & 1 \\ +% \stackSux_{i} + \stackSox_{i} & \!\!\! = \!\!\! & 0 \\ +% \end{array} +% \right.} +% \end{center} +% \begin{description} +% \item[\underline{Setting the stack pattern:}] we impose $\oneZeroSP_{i}$ +% \item[\underline{Setting $\nonStackRows$:}] --- +% \begin{enumerate} +% \item +% \label{case: SELFDESTRUCT: non stack rows: no roll back} +% \If $\cnWillRev_{i} = 0$ +% \Then \( \nonStackRows_{i} = 5 \) +% \item +% \label{case: SELFDESTRUCT: non stack rows: will be rolled back} +% \If \Big[$\cnWillRev_{i} = 1$ \et $\cnSelfRev_{i} = 0$\Big] +% \Then \( \nonStackRows_{i} = 6 \) +% \item +% \label{case: SELFDESTRUCT: non stack rows: self roll back} +% \If $\cnSelfRev_{i} = 1$ +% \Then \( \nonStackRows_{i} = 3 \) +% \end{enumerate} +% \saNote{} +% Case~(\ref{case: SELFDESTRUCT: non stack rows: no roll back}) +% corresponds to a \inst{SELFDESTRUCT} that raises no exception and is enacted at the end of the transaction. +% Case~(\ref{case: SELFDESTRUCT: non stack rows: will be rolled back}) +% corresponds to a \inst{SELFDESTRUCT} that raises no exception but is rolled back later through a reverting parent context. +% Case~(\ref{case: SELFDESTRUCT: non stack rows: self roll back}) +% corresponds to a \inst{SELFDESTRUCT} that raises an exception (other than a stack exception.) +% \item[\underline{Setting the peeking flags:}] --- +% \begin{enumerate} +% \item +% \label{case: SELFDESTRUCT: peeking flags: no roll back} +% \If $\cnWillRev_{i} = 0$ +% \Then +% \[ +% \left[ +% \begin{array}{lr} +% & \peekContext_{i + 1} \\ +% & + \peekAccount_{i + 2} +% + \peekAccount_{i + 3} +% + \peekAccount_{i + 4} \\ +% (\trash) +% & + \peekContext_{i + 5} \\ +% \end{array} +% \right] +% = 5 +% \] +% \item +% \label{case: SELFDESTRUCT: peeking flags: will be rolled back} +% \If \Big[$\cnWillRev_{i} = 1$ \et $\cnSelfRev_{i} = 0$\Big] +% \Then +% \[ +% \left[ +% \begin{array}{lr} +% & \peekContext_{i + 1} \\ +% & + \peekAccount_{i + 2} +% + \peekAccount_{i + 3} +% + \peekAccount_{i + 4} +% + \peekAccount_{i + 5} \\ +% (\trash) +% & + \peekContext_{i + 6} \\ +% \end{array} +% \right] +% = 6 +% \] +% \item +% \label{case: SELFDESTRUCT: peeking flags: self roll back} +% \If $\cnSelfRev_{i} = 1$ +% \Then +% \[ +% \left[ +% \begin{array}{lr} +% & \peekContext_{i + 1} \\ +% & + \peekAccount_{i + 2} +% + \peekAccount_{i + 3} \\ +% (\trash) +% & + \peekContext_{i + 4} \\ +% \end{array} +% \right] +% = 3 +% \] +% \end{enumerate} +% \saNote{} There is some regularity to this: the first non stack-row is always a context-row. This row will always peek into the current execution context. +% The final row is also always a context-row. It always peeks into the parent context and provides empty return data. \saNote{} Constraining the last row to be a context-row is redundant given that any halting instruction raises the \cmc{}. +% \item[\underline{Setting the first context-row $n°(i + 1)$:}] we impose +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\readContextData {1}{\cn_{i + 1}} _{i}} \\ +% \stackStaticx_{i} & \!\!\! = \!\!\! & \cnStatic_{i + 1} \\ +% \end{array} +% \right. +% \] +% The above fully justifies the $\stackStaticx$ exception flag. +% \saNote{} $\cn_{i + 1} = \cn_{i}$. +% \end{description} +% What follows (value constraints, gas, \dots{}) is heavily dependent on whether the present scenario reverts or not, and if it does, whether it causes its own rollback or is forcefully rolled back by a parent context rolling back. +% \begin{description} +% \item[\underline{Setting the following account-rows:}] --- +% \begin{enumerate} +% \item \label{case: SELFDESTRUCT: value constraints: no roll back} +% \If $\cnWillRev_{i} = 0$ \Then +% \begin{description} +% \item[\underline{Row $n°(i + 2)$:}] the first account-row peeks into the account which \inst{SELFDESTRUCT}'s and depletes its balance: +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accOpening_{i + 2}} \\ +% \accAddress\high_{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\high_{i + 1} \\ +% \accAddress\low _{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\low _{i + 1} \\ +% \accBalance\new_{i + 2} & \!\!\! = \!\!\! & 0 \\ +% \multicolumn{3}{l}{\standardDomSubStamps\big[0\big]_{i + 2}} \\ +% \end{array} +% \right. +% \] +% \item[\underline{Row $n°(i + 3)$:}] the second account-row (again) peeks into the account which \inst{SELFDESTRUCT}'s and deletes it at transaction end: +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accSameAddrDepNumAndDepStage_{i + 3}} \\ +% \accDeletion_{i + 3} \\ +% \multicolumn{3}{l}{\selfdestructDomSubStamps_{i + 3}} \\ +% \end{array} +% \right. +% \] +% \item[\underline{Row $n°(i + 4)$:}] the third account-row peeks into the recipient account and adds to its balance (unless the recipient coincides with the account \inst{SELFDESTRUCT}'ing, in which case its balance was already depleted and it should remain so for now): +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accOpening_{i + 4}} \\ +% \multicolumn{3}{l}{\accAddress\low _{i + 4} = \stackItemValLo{1}_{i}} \\ +% \If \accAddress\high_{i + 4} \neq \accAddress\high_{i + 2} & \!\!\! \Then \!\!\! & \accBalance_{i + 4}\new = \accBalance_{i + 4} + \accBalance_{i + 2} \\ +% \If \accAddress\low _{i + 4} \neq \accAddress\low _{i + 2} & \!\!\! \Then \!\!\! & \accBalance_{i + 4}\new = \accBalance_{i + 4} + \accBalance_{i + 2} \\ +% \If +% \left\{ +% \begin{array}{c} +% \accAddress\low _{i + 4} = \accAddress\low _{i + 2} \\ +% \accAddress\low _{i + 4} = \accAddress\low _{i + 2} \\ +% \end{array} +% \right\} +% & \!\!\! \Then \!\!\! & +% \begin{cases} +% \accBalance_{i + 4}\new = \accBalance_{i + 4} & \\ +% \accBalance_{i + 4} = 0 & (\trash) \\ +% \end{cases} +% \\ +% \multicolumn{3}{l}{\accTurnOnWarmth_{i + 4}} \\ +% \multicolumn{3}{l}{\standardDomSubStamps\big[1\big]_{i + 4}} \\ +% \end{array} +% \right. +% \] +% \saNote{} \inst{SELFDESTRUCT} raises the \trmFlag{}; the high part of the recipient address (i.e. $\accAddress\high_{i + 4}$) will be filled in by the \trmMod{} module. \ob{TODO: plookup into \trmMod{}} +% \item[\underline{Row $n°(i + 5)$:}] a successful \inst{SELFDESTRUCT} returns empty return data; in this row we update the caller context's return data: +% \[ \executionProvidesEmptyReturnData {5} _{i}\] +% % \[ +% % \left\{ +% % \begin{array}{lcl} +% % \multicolumn{3}{l}{\accOpening_{i + 2}} \\ +% % \accAddress\high_{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\high_{i + 1} \\ +% % \accAddress\low _{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\low _{i + 1} \\ +% % \accBalance\new_{i + 2} & \!\!\! = \!\!\! & 0 \\ +% % \multicolumn{3}{l}{\standardDomSubStamps {2}{0} _{i} } \\ +% % \end{array} +% % \right. +% % \] +% \end{description} +% \item \label{case: SELFDESTRUCT: value constraints: will be rolled back} +% \If \Big[$\cnWillRev_{i} = 1$ \et $\cnSelfRev_{i} = 0$\Big] +% \Then +% \begin{description} +% \item[\underline{Row $n°(i + 2)$:}] the first account-row peeks into the account which seems on track to \inst{SELFDESTRUCT} and (temporarily) depletes its balance: +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accOpening_{i + 2}} \\ +% \accAddress\high_{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\high_{i + 1} \\ +% \accAddress\low _{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\low _{i + 1} \\ +% \accBalance\new_{i + 2} & \!\!\! = \!\!\! & 0 \\ +% \multicolumn{3}{l}{\standardDomSubStamps\big[0\big]_{i + 2}} \\ +% \end{array} +% \right. +% \] +% \item[\underline{Row $n°(i + 3)$:}] the second account-row (again) peeks into the account which seemed on track to \inst{SELFDESTRUCT} (yet will not) and restores it to its previous state: +% \[ +% \left\{ +% \begin{array}{lcl} +% \accSameAddrDepNumAndDepStage_{i + 3} \\ +% \accOpening_{i + 3} \\ +% \accUndoBalanceUpdate_{i + 3} \\ +% \revertDomSubStamps\big[0\big]_{i + 3} \\ +% \end{array} +% \right. +% \] +% $\selfdestructDomSubStamps$ +% \item[\underline{Row $n°(i + 4)$:}] the third account-row peeks into the recipient account and adds to its balance (unless the recipient coincides with the account \inst{SELFDESTRUCT}'ing, in which case its balance was already depleted and it should remain so for now): +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accOpening_{i + 4}} \\ +% \multicolumn{3}{l}{\accAddress\low _{i + 4} = \stackItemValLo{1}_{i}} \\ +% \If \accAddress\high_{i + 4} \neq \accAddress\high_{i + 2} & \!\!\! \Then \!\!\! & \accBalance_{i + 4}\new = \accBalance_{i + 4} + \accBalance_{i + 2} \\ +% \If \accAddress\low _{i + 4} \neq \accAddress\low _{i + 2} & \!\!\! \Then \!\!\! & \accBalance_{i + 4}\new = \accBalance_{i + 4} + \accBalance_{i + 2} \\ +% \If +% \left\{ +% \begin{array}{c} +% \accAddress\low _{i + 4} = \accAddress\low _{i + 2} \\ +% ~ \et{} \\ +% \accAddress\low _{i + 4} = \accAddress\low _{i + 2} \\ +% \end{array} +% \right\} +% & \!\!\! \Then \!\!\! & +% \begin{cases} +% \accBalance_{i + 4}\new = \accBalance_{i + 4} & \\ +% \accBalance_{i + 4} = 0 & (\trash) \\ +% \end{cases} +% \\ +% \multicolumn{3}{l}{\accTurnOnWarmth_{i + 4}} \\ +% \multicolumn{3}{l}{\standardDomSubStamps\big[1\big]_{i + 4}} \\ +% \end{array} +% \right. +% \] +% \saNote{} \inst{SELFDESTRUCT} raises the \trmFlag{}; the high part of the recipient address (i.e. $\accAddress\high_{i + 4}$) will be filled in by the \trmMod{} module. \ob{TODO: plookup into \trmMod{}} +% \item[\underline{Row $n°(i + 5)$:}] the fourth account-row (again) peeks into the account was posed to be the recipient of the value tranfer of the \inst{SELFDESTRUCT} and restores it to its previous state: +% \[ +% \left\{ +% \begin{array}{lcl} +% \accSameAddrDepNumAndDepStage_{i + 5} \\ +% \accOpening_{i + 5} \\ +% \accUndoWarmthUpdate_{i + 5} \\ +% \accUndoBalanceUpdate_{i + 5} \\ +% \revertDomSubStamps\big[1\big]_{i + 5} \\ +% \end{array} +% \right. +% \] +% \item[\underline{Row $n°(i + 6)$:}] in this row we update the caller context's return data: +% \[ \executionProvidesEmptyReturnData {6} _{i}\] +% \end{description} +% % \[ +% % \left\{ +% % \begin{array}{lcl} +% % \accAddress\high_{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\high_{i + 1} \\ +% % \accAddress\low _{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\low _{i + 1} \\ +% % \multicolumn{3}{l}{\accSameAddrDepNumAndDepStage_{i + 3}} \\ +% % \accAddress\low _{i + 4} & \!\!\! = \!\!\! & \stackItemValLo{1}_{i} \\ +% % \multicolumn{3}{l}{\accSameAddrDepNumAndDepStage_{i + 5}} \\ +% % \end{array} +% % \right. +% % \] +% \item \label{case: SELFDESTRUCT: value constraints: self roll back} +% \If $\cnSelfRev_{i} = 1$ +% \Then +% \begin{description} +% \item[\underline{Row $n°(i + 2)$:}] the first account-row views the account trying to \inst{SELFDESTRUCT} but only to gather its balance: +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accViewing {2} _{i}} \\ +% \multicolumn{3}{l}{\accSameWarmth {2} _{i}} \\ +% \accAddress\high_{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\high_{i + 1} \\ +% \accAddress\low _{i + 2} & \!\!\! = \!\!\! & \cnAccountAddress\low _{i + 1} \\ +% \multicolumn{3}{l}{\standardDomSubStamps {2}{0} _{i}} \\ +% \end{array} +% \right. +% \] +% \item[\underline{Row $n°(i + 3)$:}] the second account-row views the recipient account but only to gather its warmth and existence: +% \[ +% \left\{ +% \begin{array}{lcl} +% \multicolumn{3}{l}{\accViewing {3} _{i}} \\ +% \multicolumn{3}{l}{\accSameWarmth {3} _{i}} \\ +% \multicolumn{3}{l}{\accAddress\low _{i + 3} = \stackItemValLo{1}_{i}} \\ +% \multicolumn{3}{l}{\standardDomSubStamps {3}{1} _{i}} \\ +% \end{array} +% \right. +% \] +% \end{description} +% \saNote{} The recipient account warmth \accWarmth{} and existence $\accExists$ are required to correctly price the instruction. +% \saNote{} There is no reason to switch on its warmth (only to undo it later.) +% \saNote{} As previously mentioned: the \inst{SELFDESTRUCT} raises the \trmFlag{}; the high part of the recipient address (i.e. $\accAddress\high_{i + 3}$) will be filled in by the \trmMod{} module. \ob{TODO: plookup into \trmMod{}} +% \begin{description} +% \item[\underline{Row $n°(i + 4)$:}] we update the caller context's return data: +% \[ \executionProvidesEmptyReturnData {4} _{i}\] +% \end{description} +% \saNote{} The only way a \inst{SELFDESTRUCT} can produce an exception is through a +% \suxSH{}, +% \staticxSH{} or an +% \oogxSH{}. +% Given that in the current paragraph we are assuming +% (\emph{a}) +% $\stackSux + \stackSox \equiv 0$ and +% (\emph{b}) +% $\cnSelfRev_{i} = 1$ +% we know that the present \inst{SELFDESTRUCT} \textbf{must} trigger either +% a \staticxSH{} or a \oogxSH{}. +% The information contained in row $n°(i + 1)$ suffices to justify a \staticxSH{}, +% while that contained in row $n°(i + 2)$ suffices to jusify the \oogxSH{}. +% % \[ +% % \left\{ +% % \begin{array}{lcl} +% % \accAddress\low_{i + 2} & \!\!\! = \!\!\! & \stackItemValLo{1}_{i} \\ +% % \end{array} +% % \right. +% % \] +% \end{enumerate} +% \item[\underline{Setting the gas cost:}] the gas cost of a \inst{SELFDESTRUCT} instruction depends on two factors +% (\emph{}) +% whether the recipient account is warm or not +% (\emph{}) +% whether the account on path to \inst{SELFDESTRUCT}'ing has positive or zero balance. +% \begin{enumerate} +% \item \If $\cnSelfRev_{i} = 0$ \Then +% \begin{enumerate} +% \item \If $\accBalance_{i + 2} \neq 0$ \Then (setting $\col{W} := \accWarmth_{i + 4}$ and $\col{E} := \accExists_{i + 4}$) +% \[ +% \gasCost_{i} = +% \left[ +% \begin{array}{r} +% G_\text{selfdestruct} \\ +% + \col{W} \cdot G_\text{coldaccountaccess} \\ +% + \col{E} \cdot G_\text{newaccount} \\ +% \end{array} +% \right] +% \] +% \item \If $\accBalance_{i + 2} = 0$ \Then +% \[ +% \gasCost_{i} = +% \left[ +% \begin{array}{r} +% G_\text{selfdestruct} \\ +% + \col{W} \cdot G_\text{coldaccountaccess} \\ +% \end{array} +% \right] +% \] +% \end{enumerate} +% \item \If $\cnSelfRev_{i} = 1$ \Then +% \begin{enumerate} +% \item \If $\accBalance_{i + 2} \neq 0$ \Then (setting $\col{W} := \accWarmth_{i + 3}$ and $\col{E} := \accExists_{i + 3}$) +% \[ +% \gasCost_{i} = +% \left[ +% \begin{array}{r} +% G_\text{selfdestruct} \\ +% + \col{W} \cdot G_\text{coldaccountaccess} \\ +% + \col{E} \cdot G_\text{newaccount} \\ +% \end{array} +% \right] +% \] +% \item \If $\accBalance_{i + 2} = 0$ \Then +% \[ +% \gasCost_{i} = +% \left[ +% \begin{array}{r} +% G_\text{selfdestruct} \\ +% + \col{W} \cdot G_\text{coldaccountaccess} \\ +% \end{array} +% \right] +% \] +% \end{enumerate} +% \ob{TODO: should we introduce an \texttt{\textbackslash{}accHasBalance} or so ?} +% \end{enumerate} +% \end{description} + + +% \subsubsection{Address trimming lookup $\hubMod \hookrightarrow \trmMod$} +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% As previously mentioned the address argument of the \inst{SELFDESTRUCT} must be trimmed down before being provided to the account rows. This is the purpose of the \trmMod{} and the present is a description of the lookup. The selector is more complex than otherwise because of the dichotomy between +% (\emph{a}) +% \inst{SELFDESTRUCT}'s that fail at the instruction level (i.e. $\cnSelfRev_{i} = 1$) +% (\emph{b}) +% \inst{SELFDESTRUCT}'s that don't (i.e. $\cnSelfRev_{i} = 0$.) +% In particular a single selector won't do, this dichotomy bleeds over into the source column definitions. +% \saNote{} For simplicity we write $\sigma := \cnSelfRev_{i}$. + +% \begin{description} +% \item[Row selector.] $\col{sel}_{i} := \peekStack_{i} \cdot \stackDecHaltFlag_{i} \cdot \stackDecTrmFlag_{i}$: this selects for the \inst{SELFDESTRUCT} instruction; +% \item[Source columns.] --- +% \begin{enumerate} +% \item $(1 - \sigma) \cdot \cnAccountAddress\high_{i + 4} + \sigma \cdot \cnAccountAddress\high_{i + 3}$ +% \item $\stackItemValHi{1}_{i}$ +% \item $\stackItemValLo{1}_{i}$ +% \item $(1 - \sigma) \cdot \accTrmIsPrecompile_{i + 4} + \sigma \cdot \accTrmIsPrecompile_{i + 3}$ +% \end{enumerate} +% \item[Target columns.] --- +% \begin{enumerate} +% \item $\trmAddrHi_{j}$ +% \item $\addr\high_{j}$ +% \item $\addr\low_{j}$ +% \item $\isPrecompile_{j}$ +% \end{enumerate} +% \end{description} +% \saNote{} The present collection of instructions does not care about the $\accTrmIsPrecompile$ flag. Others will, though, and we include it in the lookup for greater uniformity and mergeability with other lookups into the \trmMod{} module. diff --git a/hub/instruction_handling/halt/_inputs.tex b/hub/instruction_handling/halt/_inputs.tex new file mode 100644 index 0000000..5c3fa2c --- /dev/null +++ b/hub/instruction_handling/halt/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: halt: instruction flags} \input{instruction_handling/halt/flags} +\subsubsection{The \inst{RETURN} case \lispDone{}} \label{hub: instruction handling: halt: revert} \input{instruction_handling/halt/return/_inputs} +\subsubsection{The \inst{REVERT} case \lispDone{}} \label{hub: instruction handling: halt: return} \input{instruction_handling/halt/revert/_inputs} +\subsubsection{The \inst{STOP} case \lispDone{}} \label{hub: instruction handling: halt: stop} \input{instruction_handling/halt/stop/_inputs} +\subsubsection{The \inst{SELFDESTRUCT} case \lispDone{}} \label{hub: instruction handling: halt: selfdestruct} \input{instruction_handling/halt/selfdestruct/_inputs} diff --git a/hub/instruction_handling/halt/flags.tex b/hub/instruction_handling/halt/flags.tex new file mode 100644 index 0000000..2778fc4 --- /dev/null +++ b/hub/instruction_handling/halt/flags.tex @@ -0,0 +1,22 @@ +\[ + \begin{array}{|l||c||c|c|c|c|c|} \hline + \INST & \tli & \stackDecHaltFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} \\ \hline\hline + \inst{RETURN} & \gZero & \oneCell & \oneCell & \gZero & \gZero & \gZero \\ \hline + \inst{REVERT} & \gZero & \oneCell & \gZero & \oneCell & \gZero & \gZero \\ \hline + \inst{STOP} & \gZero & \oneCell & \gZero & \gZero & \oneCell & \gZero \\ \hline + \inst{SELFDESTRUCT} & \gZero & \oneCell & \gZero & \gZero & \gZero & \oneCell \\ \hline + \end{array} +\] + +\[ + \begin{array}{|l||c|c|c|} \hline + \INST & \stackDecMxpFlag & \staticInst \\ \hline\hline + \inst{RETURN} & \oneCell & \gZero \\ \hline + \inst{REVERT} & \oneCell & \gZero \\ \hline + \inst{STOP} & \gZero & \gZero \\ \hline + \inst{SELFDESTRUCT} & \gZero & \oneCell \\ \hline + \end{array} +\] +\saNote{} +Halting instructions (i.e. instructions raising the \haltFlag{}) are fully characterized by the flags $\decFlag{1}$, $\decFlag{2}$, $\decFlag{3}$ and $\decFlag{4}$. +Observe that only \inst{RETURN} and \inst{REVERT} set $\stackDecMxpFlag \equiv 1$ and only \inst{SELFDESTRUCT} may raise the $\trmFlag \equiv 1$. diff --git a/hub/instruction_handling/halt/flowcharts/retDep.dot b/hub/instruction_handling/halt/flowcharts/retDep.dot new file mode 100644 index 0000000..3a38dc6 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/retDep.dot @@ -0,0 +1,379 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + deploy [label=< + + + + +
Bytecode deployment
>]; + + triggerMMU [ + label = < + + + + + + + +
DEPLOYS = 1
trigger_MMU = [ size_lo ≠ 0 ]
>; + shape = rect; + style = filled; + fillcolor = "YELLOW"; + color = "BLUE"; + ] + deploy_empty_bytecode_will_revert [ + label = "\nDeploy empty code\ni.e. trigger_MMU = 0\n WILL revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "BLUE"; + ]; + deploy_empty_bytecode_wont_revert [ + label = "\nDeploy empty code\ni.e. trigger_MMU = 0\n WON'T revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "BLUE"; + ]; + deploy_nonempty_bytecode_will_revert [ + label = "\nDeploy nonempty code\ni.e. trigger_MMU = 1\n WILL revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "BLUE"; + ]; + deploy_nonempty_bytecode_wont_revert [ + label = "\nDeploy nonempty code\ni.e. trigger_MMU = 1\n WON'T revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "BLUE"; + ]; + + { + rank=same; + deploy_empty_bytecode_will_revert; deploy_empty_bytecode_will_revert_rows; + } + { + rank=same; + deploy_empty_bytecode_wont_revert; deploy_empty_bytecode_wont_revert_rows; + } + { + rank=same; + deploy_nonempty_bytecode_will_revert; deploy_nonempty_bytecode_will_revert_rows; + } + { + rank=same; + deploy_nonempty_bytecode_wont_revert; deploy_nonempty_bytecode_wont_revert_rows; + } + + deploy -> deploy_empty_bytecode_will_revert ; + deploy_empty_bytecode_will_revert -> deploy_empty_bytecode_will_revert_rows; + deploy_empty_bytecode_will_revert -> deploy_empty_bytecode_wont_revert ; + deploy_empty_bytecode_wont_revert -> deploy_empty_bytecode_wont_revert_rows; + + deploy_empty_bytecode_wont_revert -> deploy_nonempty_bytecode_will_revert ; + deploy_nonempty_bytecode_will_revert -> deploy_nonempty_bytecode_will_revert_rows; + deploy_nonempty_bytecode_will_revert -> deploy_nonempty_bytecode_wont_revert ; + deploy_nonempty_bytecode_wont_revert -> deploy_nonempty_bytecode_wont_revert_rows; + + +deploy_empty_bytecode_will_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
HASH_INFO🏴 = 0
iSCNRETURN/DEPLOY_EMPTY_BYTECODE_WILL_REVERT  
i + 1CONcurrentread: Ia , DEPLOYS = 1,
i + 2MISCMXP🏴 = 1, MXPX = 0
MMU🏴 = trigger_MMU (= 0)
OOB🏴 = DEPLOYS, EVENT = 0
i + 3ACCIadepStatus: 1 ↘ 0, CODESIZEν ← size_lo (=0), CODEHASHν ← KEC(∅) τ · h + 00
i + 4ACCIa↶ undo everything ↶ τ · ρ + ετ · h + 0
i + 5CONparentupdate return data:   μo ­  ← ∅
>]; + +deploy_empty_bytecode_wont_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
HASH_INFO🏴 = 0
iSCNRETURN/DEPLOY_EMPTY_BYTECODE_WONT_REVERT  
i + 1CONcurrentread: Ia , DEPLOYS = 1,
i + 2MISCMXP🏴 = 1, MXPX = 0
MMU🏴 = trigger_MMU (=0)
OOB🏴 = DEPLOYS, EVENT = 0
i + 3ACCIadepStatus: 1 ↘ 0, CODESIZEν ← size_lo (=0), CODEHASHν ← KEC(∅) τ · h + 00
i + 4CONparentupdate return data:   μo ­  ← ∅
>]; + + +deploy_nonempty_bytecode_will_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
HASH_INFO🏴 = 1, KEC(code) (hi/lo), HASH_STAMP
iSCNRETURN/DEPLOY_NONEMPTY_BYTECODE_WILL_REVERT  
i + 1CONcurrentread: Ia , DEPLOYS = 1,
i + 2MISCMXP🏴 = 1, MXPX = 0
MMU🏴 = trigger_MMU (= 1)
MMU_INST = confirmInvalidCodePrefix, INFO = 0
OOB🏴 = DEPLOYS, EVENT = 0
i + 3ACCIadepStatus: 1 ↘ 0, CODESIZEν ← size_lo, CODEHASHν ← KEC(code) τ · h + 00
CFI_REQ = 1, CFIROM_LEX
i + 4ACCIa↶ undo everything ↶ τ · ρ + ετ · h + 0
i + 5MISCMMU🏴 = 1; MMU_INST = deployAndHash;
CFI and HASH_STAMP
i + 6CONparentupdate return data:   μo ­  ← ∅
>]; + +deploy_nonempty_bytecode_wont_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
HASH_INFO🏴 = 1, KEC(code) (hi/lo), HASH_STAMP
iSCNRETURN/DEPLOY_NONEMPTY_BYTECODE_WONT_REVERT  
i + 1CONcurrentread: Ia , DEPLOYS = 1,
i + 2MISCMXP🏴 = 1, MXPX = 0
MMU🏴 = trigger_MMU (=1)
MMU_INST = confirmInvalidCodePrefix, INFO = 0
OOB🏴 = DEPLOYS, EVENT = 0
i + 3ACCIadepStatus: 1 ↘ 0, CODESIZEν ← size_lo, CODEHASHν ← KEC(code) τ · h + 00
CFI_REQ = 1, CFIROM_LEX
i + 4MISCMMU🏴 = 1; MMU_INST = deployAndHash;
CFI and HASH_STAMP
i + 5CONparentupdate return data:   μo ­  ← ∅
>]; + +} diff --git a/hub/instruction_handling/halt/flowcharts/retDep.png b/hub/instruction_handling/halt/flowcharts/retDep.png new file mode 100644 index 0000000..155901c Binary files /dev/null and b/hub/instruction_handling/halt/flowcharts/retDep.png differ diff --git a/hub/instruction_handling/halt/flowcharts/retDep.svg b/hub/instruction_handling/halt/flowcharts/retDep.svg new file mode 100644 index 0000000..60d09ab --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/retDep.svg @@ -0,0 +1,738 @@ + + + + + + +G + + + +deploy + + +Bytecode deployment + + + +deploy_empty_bytecode_will_revert + +Deploy empty code +i.e. trigger_MMU = 0 + WILL revert + + + + +deploy->deploy_empty_bytecode_will_revert + + + + + +triggerMMU + +DEPLOYS + = +1 +trigger_MMU + = [ size_lo ≠ 0 ] + + + +deploy_empty_bytecode_wont_revert + +Deploy empty code +i.e. trigger_MMU = 0 + WON'T revert + + + + +deploy_empty_bytecode_will_revert->deploy_empty_bytecode_wont_revert + + + + + +deploy_empty_bytecode_will_revert_rows + + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + + + +HASH_INFO🏴 + = +0 + + +i + + +SCN + + +RETURN/DEPLOY_EMPTY_BYTECODE_WILL_REVERT   + +i + 1 + +CON + +current + +read: +I +a + , +DEPLOYS + = +1 +, + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXPX = +0 + + + +MMU🏴 = +trigger_MMU (= 0) + + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + +i + 3 + + +ACC + + +I +a + + +depStatus: +1 ↘ 0 +, +CODESIZE +ν + ← size_lo (=0) +, +CODEHASH +ν + ← KEC(∅) + + + +τ · h + 0 + + +0 + + +i + 4 + + +ACC + + +I +a + + +↶  undo everything ↶ + + +τ · ρ + ε + + +τ · h + 0 + + +i + 5 + + +CON + + +parent + + +update return data:   +μ +o + ­  ← ∅ + + + +deploy_empty_bytecode_will_revert->deploy_empty_bytecode_will_revert_rows + + + + + +deploy_nonempty_bytecode_will_revert + +Deploy nonempty code +i.e. trigger_MMU = 1 + WILL revert + + + + +deploy_empty_bytecode_wont_revert->deploy_nonempty_bytecode_will_revert + + + + + +deploy_empty_bytecode_wont_revert_rows + + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + + + +HASH_INFO🏴 + = +0 + + +i + + +SCN + + +RETURN/DEPLOY_EMPTY_BYTECODE_WONT_REVERT   + +i + 1 + +CON + +current + +read: +I +a + , +DEPLOYS + = +1 +, + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXPX = +0 + + + +MMU🏴 = +trigger_MMU (=0) + + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + +i + 3 + + +ACC + + +I +a + + +depStatus: +1 ↘ 0 +, +CODESIZE +ν + ← size_lo (=0) +, +CODEHASH +ν + ← KEC(∅) + + + +τ · h + 0 + + +0 + + +i + 4 + + +CON + + +parent + + +update return data:   +μ +o + ­  ← ∅ + + + +deploy_empty_bytecode_wont_revert->deploy_empty_bytecode_wont_revert_rows + + + + + +deploy_nonempty_bytecode_wont_revert + +Deploy nonempty code +i.e. trigger_MMU = 1 + WON'T revert + + + + +deploy_nonempty_bytecode_will_revert->deploy_nonempty_bytecode_wont_revert + + + + + +deploy_nonempty_bytecode_will_revert_rows + + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + + + +HASH_INFO🏴 + = +1 +, +KEC(code) + (hi/lo), +HASH_STAMP + + +i + + +SCN + + +RETURN/DEPLOY_NONEMPTY_BYTECODE_WILL_REVERT   + +i + 1 + +CON + +current + +read: +I +a + , +DEPLOYS + = +1 +, + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXPX = +0 + + + +MMU🏴 = +trigger_MMU (= 1) + + + +MMU_INST = confirmInvalidCodePrefix, +INFO + = +0 + + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + +i + 3 + + +ACC + + +I +a + + +depStatus: +1 ↘ 0 +, +CODESIZE +ν + ← size_lo +, +CODEHASH +ν + ← KEC(code) + + + +τ · h + 0 + + +0 + + +CFI_REQ + = +1 +, +CFI + +ROM_LEX + + + +i + 4 + + +ACC + + +I +a + + +↶  undo everything ↶ + + +τ · ρ + ε + + +τ · h + 0 + + +i + 5 + + +MISC + + + + +MMU🏴 = +1 +; MMU_INST = deployAndHash; + + + +CFI + and +HASH_STAMP + + + +i + 6 + + +CON + + +parent + + +update return data:   +μ +o + ­  ← ∅ + + + +deploy_nonempty_bytecode_will_revert->deploy_nonempty_bytecode_will_revert_rows + + + + + +deploy_nonempty_bytecode_wont_revert_rows + + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + + + +HASH_INFO🏴 + = +1 +, +KEC(code) + (hi/lo), +HASH_STAMP + + +i + + +SCN + + +RETURN/DEPLOY_NONEMPTY_BYTECODE_WONT_REVERT   + +i + 1 + +CON + +current + +read: +I +a + , +DEPLOYS + = +1 +, + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXPX = +0 + + + +MMU🏴 = +trigger_MMU (=1) + + + +MMU_INST = confirmInvalidCodePrefix, +INFO + = +0 + + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + +i + 3 + + +ACC + + +I +a + + +depStatus: +1 ↘ 0 +, +CODESIZE +ν + ← size_lo +, +CODEHASH +ν + ← KEC(code) + + + +τ · h + 0 + + +0 + + +CFI_REQ + = +1 +, +CFI + +ROM_LEX + + + +i + 4 + + +MISC + + + + +MMU🏴 = +1 +; MMU_INST = deployAndHash; + + + +CFI + and +HASH_STAMP + + + +i + 5 + + +CON + + +parent + + +update return data:   +μ +o + ­  ← ∅ + + + +deploy_nonempty_bytecode_wont_revert->deploy_nonempty_bytecode_wont_revert_rows + + + + + diff --git a/hub/instruction_handling/halt/flowcharts/retMsg.dot b/hub/instruction_handling/halt/flowcharts/retMsg.dot new file mode 100644 index 0000000..a232cf1 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/retMsg.dot @@ -0,0 +1,164 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + return_from_message_call [label=< + + + + +
RETURN from message call
>]; + + triggerMMU [ + label = < + + + + + + + +
DEPLOYS = 0
trigger_MMU = [ R@C · size_lo ≠ 0 ]
>; + shape = rect; + style = filled; + fillcolor = "YELLOW"; + color = "BLUE"; + ] + will_write_to_ram [ + label = "\nWill write to RAM\ni.e. trigger_MMU = 1\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "BLUE"; + ]; + wont_write_to_ram [ + label = "\nWon't write to RAM\ni.e. trigger_MMU = 0\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "BLUE"; + ]; + + { + rank=same; + will_write_to_ram; will_write_to_ram_rows; + } + { + rank=same; + wont_write_to_ram; wont_write_to_ram_rows; + } + + return_from_message_call -> will_write_to_ram ; + will_write_to_ram -> will_write_to_ram_rows; + will_write_to_ram -> wont_write_to_ram ; + wont_write_to_ram -> wont_write_to_ram_rows; + + +wont_write_to_ram_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNRETURN/MESSAGE_CALL_WONT_WRITE_TO_RAM
i + 1CONcurrentread: Ia , DEPLOYS = 0, R@O, R@C,
i + 2MISCMXP🏴 = 1, MXPX = 0
MMU🏴 = trigger_MMU (=0)
OOB🏴 = DEPLOYS, EVENT = 0
i + 3CONparentRD: RDO = offset, RDS = size
>]; + +will_write_to_ram_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNRETURN/MESSAGE_CALL_WILL_WRITE_TO_RAM
i + 1CONcurrentread: Ia , DEPLOYS = 0, R@O, R@C,
i + 2MISCMXP🏴 = 1, MXPX = 0
MMU🏴 = trigger_MMU (= 1)
MMU_INST = writeReturnDataSlice
OOB🏴 = DEPLOYS, EVENT = 0
i + 3CONparentRD: RDO = offset, RDS = size
>]; + +} diff --git a/hub/instruction_handling/halt/flowcharts/retMsg.png b/hub/instruction_handling/halt/flowcharts/retMsg.png new file mode 100644 index 0000000..23c7b3c Binary files /dev/null and b/hub/instruction_handling/halt/flowcharts/retMsg.png differ diff --git a/hub/instruction_handling/halt/flowcharts/retMsg.svg b/hub/instruction_handling/halt/flowcharts/retMsg.svg new file mode 100644 index 0000000..039adea --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/retMsg.svg @@ -0,0 +1,269 @@ + + + + + + +G + + + +return_from_message_call + + +RETURN from message call + + + +will_write_to_ram + +Will write to RAM +i.e. trigger_MMU = 1 + + + + +return_from_message_call->will_write_to_ram + + + + + +triggerMMU + +DEPLOYS + = +0 +trigger_MMU + = [ R@C · size_lo ≠ 0 ] + + + +wont_write_to_ram + +Won't write to RAM +i.e. trigger_MMU = 0 + + + + +will_write_to_ram->wont_write_to_ram + + + + + +will_write_to_ram_rows + + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +RETURN/MESSAGE_CALL_WILL_WRITE_TO_RAM + +i + 1 + +CON + +current + +read: +I +a + , +DEPLOYS + = +0 +, +R@O +, +R@C +, + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXPX = +0 + + + +MMU🏴 = +trigger_MMU (= 1) + + + +MMU_INST = writeReturnDataSlice + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + +i + 3 + + +CON + + +parent + + +RD: +RDO + = +offset +, +RDS + = +size + + + +will_write_to_ram->will_write_to_ram_rows + + + + + +wont_write_to_ram_rows + + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +RETURN/MESSAGE_CALL_WONT_WRITE_TO_RAM + +i + 1 + +CON + +current + +read: +I +a + , +DEPLOYS + = +0 +, +R@O +, +R@C +, + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXPX = +0 + + + +MMU🏴 = +trigger_MMU (=0) + + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + +i + 3 + + +CON + + +parent + + +RD: +RDO + = +offset +, +RDS + = +size + + + +wont_write_to_ram->wont_write_to_ram_rows + + + + + diff --git a/hub/instruction_handling/halt/flowcharts/retXxx.dot b/hub/instruction_handling/halt/flowcharts/retXxx.dot new file mode 100644 index 0000000..1076b7e --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/retXxx.dot @@ -0,0 +1,359 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
RETURN
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + maxcsx [ + label = "\nMAXCSX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + invcpx [ + label = "\nINVCPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "skyblue"; + color = "green"; + ]; + deployment [ + label = "Bytecode\ndeployment"; + fontsize = 30; + shape = rect; + ]; + message_call [ + label = "Return from\nmessage call"; + fontsize = 30; + shape = rect; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + maxcsx; maxcsx_rows; + } + { + rank=same; + invcpx; invcpx_rows; + } + { + rank=same; + unexceptional; unexceptional_rows; + } + + inst -> sux ; + sux -> sux_rows ; + sux -> mxpx ; + mxpx -> mxpx_rows ; + mxpx -> oogx ; + oogx -> oogx_rows ; + oogx -> maxcsx ; + maxcsx -> maxcsx_rows ; + maxcsx -> invcpx ; + invcpx -> invcpx_rows ; + invcpx -> unexceptional ; + unexceptional -> unexceptional_rows ; + unexceptional -> message_call ; + unexceptional -> deployment ; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0empty stack items00
iCONparentParent: update return data   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNexceptional RETURN scenario
i + 1CONcurrentread: Ia , DEPLOYS = 0/1
i + 2MISCMXP🏴 = 1, MXP/DEPLOYS = DEPLOYS, MXPX = 1
i + 3CONparentupdate return data   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNexceptional RETURN scenario
i + 1CONcurrentread: Ia , DEPLOYS = 0/1
i + 2MISCMXP🏴 = 1, MXP/DEPLOYS = DEPLOYS, MXPX = 0
i + 3CONparentupdate return data   μo ­  ← ∅
>]; + +maxcsx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNexceptional RETURN scenario
i + 1CONcurrentread: Ia , DEPLOYS = 1
i + 2MISCOOB🏴 = 1, EVENT = 1
i + 3CONparentupdate return data   μo ­  ← ∅
>]; + +invcpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNexceptional RETURN scenario
i + 1CONcurrentread: Ia , DEPLOYS = 1
i + 2MISC☢️ MXP🏴 = 1 ☢️, MXP/DEPLOYS = DEPLOYS, MXPX = 0
MMU🏴 = 1, MMU_INST = confirmInvalidCodePrefix, INFO = 1
i + 3CONparentupdate return data   μo ­  ← ∅
>]; + +unexceptional_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
i - 1STACKCT = 0excavate stack items: offset, size
iSCNunexceptional RETURN scenario
i + 1CONcurrentread: Ia , DEPLOYS
i + 2MISCMXP🏴 = 1, MXP/DEPLOYS = DEPLOYS, MXPX = 0
MMU🏴 = ??? TBD ???
OOB🏴 = DEPLOYS, EVENT = 0
>]; +} + diff --git a/hub/instruction_handling/halt/flowcharts/retXxx.png b/hub/instruction_handling/halt/flowcharts/retXxx.png new file mode 100644 index 0000000..8408869 Binary files /dev/null and b/hub/instruction_handling/halt/flowcharts/retXxx.png differ diff --git a/hub/instruction_handling/halt/flowcharts/retXxx.svg b/hub/instruction_handling/halt/flowcharts/retXxx.svg new file mode 100644 index 0000000..a2adab4 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/retXxx.svg @@ -0,0 +1,593 @@ + + + + + + +G + + + +inst + + +RETURN + + + +sux + +SUX + + + + +inst->sux + + + + + +mxpx + +MXPX + + + + +sux->mxpx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +empty stack items + +0 + +0 + +i + +CON + + +parent + +Parent: update return data   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +exceptional RETURN scenario + +i + 1 + +CON + + +current + +read: +I +a + , +DEPLOYS + = +0/1 + + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXP/DEPLOYS = +DEPLOYS +, MXPX = +1 + + +i + 3 + +CON + + +parent + +update return data   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +maxcsx + +MAXCSX + + + + +oogx->maxcsx + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +exceptional RETURN scenario + +i + 1 + +CON + + +current + +read: +I +a + , +DEPLOYS + = +0/1 + + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXP/DEPLOYS = +DEPLOYS +, MXPX = +0 + + +i + 3 + +CON + + +parent + +update return data   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +invcpx + +INVCPX + + + + +maxcsx->invcpx + + + + + +maxcsx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +exceptional RETURN scenario + +i + 1 + +CON + + +current + +read: +I +a + , +DEPLOYS + = +1 + + +i + 2 + +MISC + + +OOB🏴 = +1 +, EVENT = +1 + + +i + 3 + +CON + + +parent + +update return data   +μ +o + ­  ← ∅ + + + +maxcsx->maxcsx_rows + + + + + +unexceptional + +No Exception + + + + +invcpx->unexceptional + + + + + +invcpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +exceptional RETURN scenario + +i + 1 + +CON + + +current + +read: +I +a + , +DEPLOYS + = +1 + + +i + 2 + +MISC + + +☢️ MXP🏴 = +1 + ☢️, MXP/DEPLOYS = +DEPLOYS +, MXPX = +0 + + +MMU🏴 = +1 +, MMU_INST = confirmInvalidCodePrefix, +INFO + = +1 + + +i + 3 + +CON + + +parent + +update return data   +μ +o + ­  ← ∅ + + + +invcpx->invcpx_rows + + + + + +deployment + +Bytecode +deployment + + + +unexceptional->deployment + + + + + +message_call + +Return from +message call + + + +unexceptional->message_call + + + + + +unexceptional_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i - 1 + +STACK + +CT = 0 + +excavate stack items: +offset +, +size + +i + + +SCN + + +unexceptional RETURN scenario + +i + 1 + +CON + + +current + +read: +I +a + , +DEPLOYS + +i + 2 + +MISC + + +MXP🏴 = +1 +, MXP/DEPLOYS = +DEPLOYS +, MXPX = +0 + + +MMU🏴 = +??? TBD ??? + + +OOB🏴 = +DEPLOYS +, EVENT = +0 + + + + +unexceptional->unexceptional_rows + + + + + diff --git a/hub/instruction_handling/halt/flowcharts/revert.dot b/hub/instruction_handling/halt/flowcharts/revert.dot new file mode 100644 index 0000000..f85082f --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/revert.dot @@ -0,0 +1,216 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
REVERT
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + revert [ + label = "\nunexceptional\nREVERT\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "RED"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + revert; revert_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> mxpx; + mxpx -> mxpx_rows; + mxpx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> revert; + revert -> revert_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 2Conparentupdate return data:   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 1
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 1MISCMXP🏴 = 1, MXPX = 0
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offsets and size
i + 2MISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = [size ≠ 0] · [R@C ≠ 0];
i + 2Concurrentread context; observe R@C and R@O;
i + 3Conparentupdate return data:   μo ­  ← μm ­ [offset, ..., offset + size - 1]
>]; + + +} + + diff --git a/hub/instruction_handling/halt/flowcharts/revert.png b/hub/instruction_handling/halt/flowcharts/revert.png new file mode 100644 index 0000000..38ce416 Binary files /dev/null and b/hub/instruction_handling/halt/flowcharts/revert.png differ diff --git a/hub/instruction_handling/halt/flowcharts/revert.svg b/hub/instruction_handling/halt/flowcharts/revert.svg new file mode 100644 index 0000000..d975b02 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/revert.svg @@ -0,0 +1,306 @@ + + + + + + +G + + + +inst + +REVERT + + + +sux + +SUX + + + + +inst->sux + + + + + +mxpx + +MXPX + + + + +sux->mxpx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 2 + +Con + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +1 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 1 + +MISC + + +MXP🏴 = 1, MXPX = +0 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +revert + +unexceptional +REVERT + + + + +unexceptional->revert + + + + + +revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offsets and size + +i + 2 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = [size ≠ 0] · [ +R@C + ≠ 0]; + +i + 2 + +Con + + +current + +read context; observe +R@C + and +R@O +; + +i + 3 + +Con + + +parent + +update return data:   +μ +o + ­  ← +μ +m + ­ [offset, ..., offset + size - 1] + + + +revert->revert_rows + + + + + diff --git a/hub/instruction_handling/halt/flowcharts/selfdestruct.dot b/hub/instruction_handling/halt/flowcharts/selfdestruct.dot new file mode 100644 index 0000000..e8e2a88 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/selfdestruct.dot @@ -0,0 +1,472 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + bgcolor = "lightgray" + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
SELFDESTRUCT
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + staticx [ + label = "\nSTATICX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + sd_will_be_reverted [ + label = "\nSELFDESTRUCT\nWILL revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "RED"; + ]; + sd_wont_be_reverted_marked [ + label = "\nSELFDESTRUCT\nWON'T revert\nmarked for SD\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "RED"; + ]; + sd_wont_be_reverted_nomark [ + label = "\nSELFDESTRUCT\nWON'T revert\nnot marked for SD\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "RED"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + staticx; staticx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + revert; revert_rows; + } + { + rank=same; + sd_will_be_reverted; sd_will_be_reverted_rows; + } + { + rank=same; + sd_wont_be_reverted_marked; sd_wont_be_reverted_marked_rows; + } + { + rank=same; + sd_wont_be_reverted_nomark; sd_wont_be_reverted_nomark_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> staticx; + staticx -> staticx_rows; + staticx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> sd_will_be_reverted; + sd_will_be_reverted -> sd_will_be_reverted_rows; + sd_will_be_reverted -> sd_wont_be_reverted_marked; + sd_wont_be_reverted_marked -> sd_wont_be_reverted_marked_rows; + sd_wont_be_reverted_marked -> sd_wont_be_reverted_nomark; + sd_wont_be_reverted_nomark -> sd_wont_be_reverted_nomark_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + +
REFUNDREFUNDνRow indexPerspectiveWhoActionsWhen
DomSub
sameiSTACKCT = 0empty stack items
i + 1CONparentupdate return data:   μo ­  ← ∅
>]; + +staticx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
REFUNDREFUNDνRow indexPerspectiveWhoActionsWhen
DomSub
sameiSTACKCT = 0rawAddr
i + 1CONcurrentobserve STATIC🏴 = 1;
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
REFUNDREFUNDνRow indexPerspectiveWhoActionsWhen
DomSub
sameiSTACKCT = 0rawAddr
i + 1CONcurrentobserve STATIC🏴 = 0 and Ia;
i + 2ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · h + 00
[BAL ≠ 0] ?
i + 3ACCtrimmed recipient addressTRM🏴 = 1; same everything;τ · h + 10
Warmth ? ∃ ?
i + 1CONparentupdate return data:   μo ­  ← ∅
>]; + +sd_will_be_reverted_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
REFUNDREFUNDνRow indexPerspectiveWhoActionsWhen
DomSub
sameiSTACKCT = 0rawAddr
i + 1SCNSELFDESTRUCT: reverted; [trmAddr ≠  Ia]
i + 2CONcurrentobserve STATIC🏴 = 0 and Ia;
i + 3ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · h + 00
BAL = b; [b ≠ 0] ? BALν = 0
MARKED = 0 unchanged
i + 4ACCtrmAddrTRM🏴 = 1; W ; BAL += b; [trmAddr ≠ Ia] τ · h + 10
Warmth ? ∃ ?
i + 5ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · ρ + ετ · h + 2
BAL
i + 6ACCtrmAddrTRM🏴 = 0; W ;τ · ρ + ετ · h + 3
BAL
i + 7CONparentupdate return data:   μo ­  ← ∅
>]; + +sd_wont_be_reverted_marked_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
REFUNDREFUNDνRow indexPerspectiveWhoActionsWhen
DomSub
sameiSTACKCT = 0rawAddr
i + 1SCNSELFDESTRUCT: no rollback, already marked; [trmAddr ≠  Ia]
i + 2CONcurrentobserve STATIC🏴 = 0 and Ia;
i + 3ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · h + 00
BAL = b; [b ≠ 0] ? BALν = 0
i + 4ACCtrmAddrTRM🏴 = 1; W ; BAL += b; [trmAddr ≠ Ia] τ · h + 10
Warmth ? ∃ ?
i + 5ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · ρ + ετ · h + 2
BAL
i + 6ACCtrmAddrTRM🏴 = 0; W ;τ · ρ + ετ · h + 3
BAL
i + 7CONparentupdate return data:   μo ­  ← ∅
>]; + +sd_wont_be_reverted_nomark_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
REFUNDREFUNDνRow indexPerspectiveWhoActionsWhen
DomSub
+= 25_000iSTACKCT = 0rawAddr
i + 1SCNSELFDESTRUCT: no rollback, unmarked; [trmAddr ≠  Ia]
i + 2CONcurrentobserve STATIC🏴 = 0 and Ia;
i + 3ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · h + 00
BAL = b; [b ≠ 0] ? BALν = 0
i + 4ACCtrmAddrTRM🏴 = 1; W ; BAL += b; [trmAddr ≠ Ia] τ · h + 10
Warmth ? ∃ ?
i + 5ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · TX_END + εsdτ · h + 2
DESTROY ACCOUNT
i + 6CONparentupdate return data:   μo ­  ← ∅
>]; + + + +} + + diff --git a/hub/instruction_handling/halt/flowcharts/selfdestruct.png b/hub/instruction_handling/halt/flowcharts/selfdestruct.png new file mode 100644 index 0000000..e83f5a5 Binary files /dev/null and b/hub/instruction_handling/halt/flowcharts/selfdestruct.png differ diff --git a/hub/instruction_handling/halt/flowcharts/selfdestruct.svg b/hub/instruction_handling/halt/flowcharts/selfdestruct.svg new file mode 100644 index 0000000..fdfdf1c --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/selfdestruct.svg @@ -0,0 +1,824 @@ + + + + + + +G + + + +inst + +SELFDESTRUCT + + + +sux + +SUX + + + + +inst->sux + + + + + +staticx + +STATICX + + + + +sux->staticx + + + + + +sux_rows + +REFUND + +REFUND +ν + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +same + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +oogx + +OOGX + + + + +staticx->oogx + + + + + +staticx_rows + +REFUND + +REFUND +ν + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +same + +i + +STACK + +CT = 0 + +rawAddr + +i + 1 + +CON + + +current + +observe STATIC🏴 = +1 +; + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +staticx->staticx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +REFUND + +REFUND +ν + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +same + +i + +STACK + +CT = 0 + +rawAddr + +i + 1 + +CON + + +current + +observe STATIC🏴 = +0 + and +I +a +; + +i + 2 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · h + 0 + +0 + +[BAL ≠ 0] ? + +i + 3 + +ACC + + +trimmed recipient address + +TRM🏴 = +1 +; same everything; + +τ · h + 1 + +0 + +Warmth ? ∃ ? + +i + 1 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +sd_will_be_reverted + +SELFDESTRUCT +WILL revert + + + + +unexceptional->sd_will_be_reverted + + + + + +sd_wont_be_reverted_marked + +SELFDESTRUCT +WON'T revert +marked for SD + + + + +sd_will_be_reverted->sd_wont_be_reverted_marked + + + + + +sd_will_be_reverted_rows + +REFUND + +REFUND +ν + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +same + +i + +STACK + +CT = 0 + +rawAddr + +i + 1 + +SCN + + +SELFDESTRUCT: reverted; [trmAddr ≠  +I +a +] + +i + 2 + +CON + + +current + +observe STATIC🏴 = +0 + and +I +a +; + +i + 3 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · h + 0 + +0 + +BAL = +b +; [ +b + ≠ 0] ? BAL +ν + = 0 + +MARKED = 0 unchanged + +i + 4 + +ACC + + +trmAddr + +TRM🏴 = +1 +; W + + ; BAL += +b +; [trmAddr ≠ +I +a +] + +τ · h + 1 + +0 + +Warmth ? ∃ ? + +i + 5 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · ρ + ε + +τ · h + 2 + +BAL + + + +i + 6 + +ACC + + +trmAddr + +TRM🏴 = +0 +; W + +; + +τ · ρ + ε + +τ · h + 3 + +BAL + + + +i + 7 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sd_will_be_reverted->sd_will_be_reverted_rows + + + + + +sd_wont_be_reverted_nomark + +SELFDESTRUCT +WON'T revert +not marked for SD + + + + +sd_wont_be_reverted_marked->sd_wont_be_reverted_nomark + + + + + +sd_wont_be_reverted_marked_rows + +REFUND + +REFUND +ν + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +same + +i + +STACK + +CT = 0 + +rawAddr + +i + 1 + +SCN + + +SELFDESTRUCT: no rollback, already marked; [trmAddr ≠  +I +a +] + +i + 2 + +CON + + +current + +observe STATIC🏴 = +0 + and +I +a +; + +i + 3 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · h + 0 + +0 + +BAL = +b +; [ +b + ≠ 0] ? BAL +ν + = 0 + +i + 4 + +ACC + + +trmAddr + +TRM🏴 = +1 +; W + + ; BAL += +b +; [trmAddr ≠ +I +a +] + +τ · h + 1 + +0 + +Warmth ? ∃ ? + +i + 5 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · ρ + ε + +τ · h + 2 + +BAL + + + +i + 6 + +ACC + + +trmAddr + +TRM🏴 = +0 +; W + +; + +τ · ρ + ε + +τ · h + 3 + +BAL + + + +i + 7 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sd_wont_be_reverted_marked->sd_wont_be_reverted_marked_rows + + + + + +sd_wont_be_reverted_nomark_rows + +REFUND + +REFUND +ν + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + ++= 25_000 + +i + +STACK + +CT = 0 + +rawAddr + +i + 1 + +SCN + + +SELFDESTRUCT: no rollback, unmarked; [trmAddr ≠  +I +a +] + +i + 2 + +CON + + +current + +observe STATIC🏴 = +0 + and +I +a +; + +i + 3 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · h + 0 + +0 + +BAL = +b +; [ +b + ≠ 0] ? BAL +ν + = 0 + +i + 4 + +ACC + + +trmAddr + +TRM🏴 = +1 +; W + + ; BAL += +b +; [trmAddr ≠ +I +a +] + +τ · h + 1 + +0 + +Warmth ? ∃ ? + +i + 5 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · TX_END + ε +sd + +τ · h + 2 + +DESTROY ACCOUNT + +i + 6 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sd_wont_be_reverted_nomark->sd_wont_be_reverted_nomark_rows + + + + + +revert +revert + + + +revert_rows +revert_rows + + + diff --git a/hub/instruction_handling/halt/flowcharts/stop.dot b/hub/instruction_handling/halt/flowcharts/stop.dot new file mode 100644 index 0000000..d167180 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/stop.dot @@ -0,0 +1,196 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
STOP
>]; + message_call [ + label = "\nMessage Call\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + deployment_will_revert [ + label = "\nDeployment\nWILL revert\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + deployment_wont_revert [ + label = "\nDeployment\nWON'T revert\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + + { + rank=same; + message_call; message_call_rows; + } + { + rank=same; + deployment_will_revert; deployment_will_revert_rows; + } + { + rank=same; + deployment_wont_revert; deployment_wont_revert_rows; + } + + inst -> message_call; + message_call -> message_call_rows; + message_call -> deployment_will_revert; + deployment_will_revert -> deployment_will_revert_rows; + deployment_will_revert -> deployment_wont_revert; + deployment_wont_revert -> deployment_wont_revert_rows; + +message_call_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1CONcurrentobserve cnDepStatus = 0
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + + +deployment_will_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1CONcurrentobserve cnDepStatus = 1; read Ia
i + 2ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · h + 0 0
WARM ; accDepStatus: 1 ↘ 0;
code ← ∅ (size, hash, ...)
i + 3ACCIaTRM🏴 = 0; CFI_REQ = 0;τ · ρ + ε τ · h + 1
WARM ; accDepStatus ;
code
i + 3CONparentupdate return data:   μo ­  ← ∅
>]; + +deployment_wont_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1CONcurrentobserve cnDepStatus = 1; read Ia
i + 2ACCIaTRM🏴 = 0; CFI_REQ = 0; CFI = cfiτ · h + 00
WARM ; accDepStatus: 1 ↘ 0;
code ← ∅ (size, hash, ...)
i + 2CONparentupdate return data:   μo ­  ← ∅
>]; + +} diff --git a/hub/instruction_handling/halt/flowcharts/stop.png b/hub/instruction_handling/halt/flowcharts/stop.png new file mode 100644 index 0000000..80fa949 Binary files /dev/null and b/hub/instruction_handling/halt/flowcharts/stop.png differ diff --git a/hub/instruction_handling/halt/flowcharts/stop.svg b/hub/instruction_handling/halt/flowcharts/stop.svg new file mode 100644 index 0000000..0d57254 --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/stop.svg @@ -0,0 +1,304 @@ + + + + + + +G + + + +inst + + +STOP + + + +message_call + +Message Call + + + + +inst->message_call + + + + + +deployment_will_revert + +Deployment +WILL revert + + + + +message_call->deployment_will_revert + + + + + +message_call_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +CON + + +current + +observe cnDepStatus = +0 + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +message_call->message_call_rows + + + + + +deployment_wont_revert + +Deployment +WON'T revert + + + + +deployment_will_revert->deployment_wont_revert + + + + + +deployment_will_revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +CON + + +current + +observe cnDepStatus = +1 +; read +I +a + +i + 2 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · h + 0 + +0 + +WARM + +; accDepStatus: +1 ↘ 0 +; + +code ← ∅ (size, hash, ...) + +i + 3 + +ACC + + +I +a + +TRM🏴 = +0 +; CFI_REQ = +0 +; + +τ · ρ + ε + +τ · h + 1 + +WARM + +; accDepStatus + +; + +code + + +i + 3 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +deployment_will_revert->deployment_will_revert_rows + + + + + +deployment_wont_revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +CON + + +current + +observe cnDepStatus = +1 +; read +I +a + +i + 2 + +ACC + + +I +a + +TRM🏴 = 0; CFI_REQ = 0; CFI = cfi + +τ · h + 0 + +0 + +WARM + +; accDepStatus: +1 ↘ 0 +; + +code ← ∅ (size, hash, ...) + +i + 2 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +deployment_wont_revert->deployment_wont_revert_rows + + + + + diff --git a/hub/instruction_handling/halt/flowcharts/symbols b/hub/instruction_handling/halt/flowcharts/symbols new file mode 100644 index 0000000..6a0e85e --- /dev/null +++ b/hub/instruction_handling/halt/flowcharts/symbols @@ -0,0 +1 @@ +← ↶ ↘ diff --git a/hub/instruction_handling/halt/return/_inputs.tex b/hub/instruction_handling/halt/return/_inputs.tex new file mode 100644 index 0000000..bbf2c59 --- /dev/null +++ b/hub/instruction_handling/halt/return/_inputs.tex @@ -0,0 +1,6 @@ +\input{instruction_handling/halt/return/_local} +\subsubsubsection{Introduction} \label{hub: instruction handling: halt: return: intro} \input{instruction_handling/halt/return/intro} +\subsubsubsection{Scenario-row setting \lispDone{}} \label{hub: instruction handling: halt: return: scenario row insertion} \input{instruction_handling/halt/return/scenario_setting} +\subsubsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: halt: return: shorthands} \input{instruction_handling/halt/return/shorthands} +\subsubsubsection{Generalities \lispDone{}} \label{hub: instruction handling: halt: return: generalities} \input{instruction_handling/halt/return/generalities} +\subsubsubsection{Scenario by scenario constraints \lispDone{}} \label{hub: instruction handling: halt: return: scenario by scenario} \input{instruction_handling/halt/return/specialized/_inputs} diff --git a/hub/instruction_handling/halt/return/_local.tex b/hub/instruction_handling/halt/return/_local.tex new file mode 100644 index 0000000..cdfb4b4 --- /dev/null +++ b/hub/instruction_handling/halt/return/_local.tex @@ -0,0 +1,60 @@ +\def\locInst {\col{instruction}} +\def\locFirstMmuInst {\col{first\_mmu\_instruction}} +\def\locFirstMmuInfo {\col{first\_mmu\_info}} +\def\locSecondMmuInst {\col{second\_mmu\_instruction}} +\def\locSeconcMmuInfo {\col{second\_mmu\_info}} +\def\locRefOffset {\col{mmu\_ref\_offset}} +\def\locRefSize {\col{mmu\_ref\_size}} +\def\locMxpx {\col{STACK\_mxpx}} +\def\locOogx {\col{STACK\_oogx}} +\def\locMaxcsx {\col{STACK\_maxcsx}} +\def\locIcpx {\col{STACK\_icpx}} +\def\locTriggerMxp {\col{trigger\_MXP}} +\def\locTriggerOob {\col{trigger\_OOB}} +\def\locTriggerHashInfo {\col{trigger\_HASHINFO}} +\def\locTriggerMmu {\col{trigger\_MMU}} +\def\locTriggerMmuCodePrefixCheck {\col{trigger\_MMU\_for\_invalid\_code\_prefix\_check}} +\def\locTriggerMmuWriteReturnDataToRam {\col{trigger\_MMU\_to\_write\_return\_data\_to\_RAM}} +\def\locDeploymentAddressHi {\col{deployment\_address\_hi}} +\def\locDeploymentAddressLo {\col{deployment\_address\_lo}} +\def\locNewCodeHashHi {\col{new\_code\_hash\_hi}} +\def\locNewCodeHashLo {\col{new\_code\_hash\_lo}} +\def\locHashInfoCodeHashHi {\col{code\_hash\_hi}} +\def\locHashInfoCodeHashLo {\col{code\_hash\_lo}} +\def\locHashInfoCodeSize {\col{code\_size}} +\def\locIsRoot {\col{is\_root}} +\def\locDeploys {\col{is\_deployment}} +\def\locRao {\col{r@o}} +\def\locRac {\col{r@c}} +\def\locOffset {\col{offset}} +\def\locOffsetHi {\locOffset\col{\_hi}} +\def\locOffsetLo {\locOffset\col{\_lo}} +\def\locSize {\col{size}} +\def\locSizeHi {\locSize\col{\_hi}} +\def\locSizeLo {\locSize\col{\_lo}} +\def\locMxpMtntop {\mxpMod\col{\_mtntop}} +\def\locMxpMxpGas {\mxpMod\col{\_gas}} +\def\relevantValue {\texttt{}} +\def\locOobMaxcsx {\oobMod\col{\_maxcsx}} +\def\locGasCostRequired {\col{gas\_cost\_required}} +\def\locDeploymentCfi {\col{deployment\_cfi}} + +\def\locCurrentContextIsRoot {\col{current\_context\_is\_root}} + +\def\locCheckFirstByte {\col{check\_first\_byte}} +\def\locWriteSomeReturnData {\col{write\_return\_data\_to\_caller\_ram}} +\def\locTouchRamAfterMessageCallExpression {\col{touch\_ram\_expression}} + +\def\locCurrentContextRowOffset {\yellowm{1}} +\def\locFirstMiscRowOffset {\yellowm{2}} +\def\locSecondMiscRowOffsetDeployAndHash {\yellowm{3}} +\def\locEmptyDeploymentFirstAccountRowOffset {\yellowm{3}} +\def\locEmptyDeploymentSecondAccountRowOffset {\yellowm{4}} +\def\locNonemptyDeploymentFirstAccountRowOffset {\yellowm{4}} +\def\locNonemptyDeploymentSecondAccountRowOffset {\yellowm{5}} +\def\locCallerContextRowOffsetException {\orangem{3}} +\def\locCallerContextRowOffsetMessageCall {\orangem{3}} +\def\locCallerContextRowOffsetEmptyDeploymentWillRevert {\orangem{5}} +\def\locCallerContextRowOffsetEmptyDeploymentWontRevert {\orangem{4}} +\def\locCallerContextRowOffsetNonemptyDeploymentWillRevert {\orangem{6}} +\def\locCallerContextRowOffsetNonemptyDeploymentWontRevert {\orangem{5}} diff --git a/hub/instruction_handling/halt/return/generalities.tex b/hub/instruction_handling/halt/return/generalities.tex new file mode 100644 index 0000000..fde43da --- /dev/null +++ b/hub/instruction_handling/halt/return/generalities.tex @@ -0,0 +1,427 @@ +The present section deals with generalities pertaining to \inst{RETURN} instructions. +We begin by constraining the acceptable exception flags: +\begin{description} + \item[\underline{Acceptable exception flags:}] + \inst{RETURN} instructions that deploy byte code may trigger specific exceptions, as such + \If $\peekScenario_{i} = 1$ \Then we impose that + \begin{enumerate} + \item \If $\scenReturnFromMessageCall _{i} = 1$ \Then + \[ + \xAhoy_{i} + = + \left[ \begin{array}{cl} + + & \stackMxpx _{i - 1} \\ + + & \stackOogx _{i - 1} \\ + \end{array} \right] + \] + \item \If $\scenReturnFromDeployment _{i} = 1$ \Then + \[ + \xAhoy_{i} + = + \left[ \begin{array}{cl} + + & \stackMxpx _{i - 1} \\ + + & \stackOogx _{i - 1} \\ + + & \stackMaxcsx _{i - 1} \\ + + & \stackIcpx _{i - 1} \\ + \end{array} \right] + \] + \end{enumerate} + \saNote{} \inst{RETURN} instructions can trigger a variety of exceptions: + (\emph{a}) \suxSH{}'s + (\emph{b}) \mxpxSH{}'s + (\emph{c}) \oogxSH{}'s + as well as, \textbf{and in deployment contexts only}, + (\emph{d}) \maxcsxSH{}'s + (\emph{e}) \icpxSH{}'s. + As always stack exceptions are handled through general constraints, and so we directly dive into the remaining exceptions. + For a \inst{RETURN} instruction to raise either a \maxcsxSH{} or a \icpxSH{} it is necesssary that it be executed in a deployment context, whence the above dichotomy. +\end{description} +From now on we will systematically work under the assuption that the underlying instruction is a \inst{RETURN} instruction. +As such: +\begin{center} + \boxed{% + \text{The constraints presented below are written under the assumption that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnSum _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +We impose the following: +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\twoZeroSP_{i - 1}$; + \item[\underline{Setting \nonStackRows{}:}] + we impose that + % \begin{enumerate} + % \item \If $\scenReturnException _{i} = 1$ \Then $\nonStackRows_{i} = 4$ + % \item \If $\scenReturnFromMessageCallWillTouchRam _{i} = 1$ \Then $\nonStackRows_{i} = 4$ + % \item \If $\scenReturnFromMessageCallWontTouchRam _{i} = 1$ \Then $\nonStackRows_{i} = 4$ + % \item \If $\scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} = 1$ \Then $\nonStackRows_{i} = 6$ + % \item \If $\scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} = 1$ \Then $\nonStackRows_{i} = 5$ + % \item \If $\scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} = 1$ \Then $\nonStackRows_{i} = 7$ + % \item \If $\scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} = 1$ \Then $\nonStackRows_{i} = 6$ + % \end{enumerate} + % \saNote{} We may impose the above with a single constraint as follows: + \[ + \nonStackRows_{i} + = + \left[ \begin{array}{rcl} + 4 & \cdot & \scenReturnException _{i} \\ + 4 & \cdot & \scenReturnFromMessageCallWillTouchRam _{i} \\ + 4 & \cdot & \scenReturnFromMessageCallWontTouchRam _{i} \\ + 6 & \cdot & \scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} \\ + 5 & \cdot & \scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} \\ + 7 & \cdot & \scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} \\ + 6 & \cdot & \scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} \\ + \end{array} \right] + \] + \item[\underline{Setting peeking flags:}] + we impose that + \begin{enumerate} + \item \If $\scenReturnException _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetException} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \item \If $\scenReturnFromMessageCallWillTouchRam _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetMessageCall} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \item \If $\scenReturnFromMessageCallWontTouchRam _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetMessageCall} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \item \If $\scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekAccount _{i + \locEmptyDeploymentFirstAccountRowOffset } \\ + + & \peekAccount _{i + \locEmptyDeploymentSecondAccountRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetEmptyDeploymentWillRevert} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \item \If $\scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekAccount _{i + \locEmptyDeploymentFirstAccountRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetEmptyDeploymentWontRevert} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \item \If $\scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekMisc _{i + \locSecondMiscRowOffsetDeployAndHash} \\ + + & \peekAccount _{i + \locNonemptyDeploymentFirstAccountRowOffset } \\ + + & \peekAccount _{i + \locNonemptyDeploymentSecondAccountRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetNonemptyDeploymentWillRevert} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \item \If $\scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekScenario _{i} \\ + + & \peekContext _{i + \locCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locFirstMiscRowOffset} \\ + + & \peekMisc _{i + \locSecondMiscRowOffsetDeployAndHash} \\ + + & \peekAccount _{i + \locNonemptyDeploymentFirstAccountRowOffset} \\ + + & \peekContext _{i + \locCallerContextRowOffsetNonemptyDeploymentWontRevert} \\ + \end{array} \right] + = \nonStackRows_{i} \] + \end{enumerate} + \saNote{} In all cases + $\peekContext _{i + \locCurrentContextRowOffset} = 1$ and + $\peekMisc _{i + \locFirstMiscRowOffset} = 1$. + \item[\underline{First context row:}] + we impose $\readContextData{i}{\locCurrentContextRowOffset}{\cn_{i}}$ + \item[\underline{Refining the \inst{RETURN} scenario:}] + we impose that: + \begin{enumerate} + \item $\scenReturnException_{i} = \xAhoy_{i - 1}$ + \item \If $\scenReturnRaisesNoException _{i} = 1$ \Then $\scenReturnFromDeployment = \locDeploys$ + \item \If $\scenReturnFromDeployment _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \scenReturnDeploymentWillRevert _{i} & = & \cnWillRev _{i} \\ + \scenReturnNonemptyDeployment _{i} & = & \locMxpMtntop \\ + \end{array} \right. + \] + \saNote{} + This uniquely determines one of the \inst{RETURN} scenarios for deployments. + \item \If $\scenReturnFromMessageCall _{i} = 1$ \Then + \begin{enumerate} + \item \If $\locTouchRamAfterMessageCallExpression = 0$ \Then \[ \scenReturnFromMessageCallWontTouchRam _{i} = 1 \] + \item \If $\locTouchRamAfterMessageCallExpression \neq 0$ \Then \[ \scenReturnFromMessageCallWillTouchRam _{i} = 1 \] + \end{enumerate} + where we use the following shorthand (which is a product of terms) + \[ + \locTouchRamAfterMessageCallExpression + \define + \left[ \begin{array}{cr} + \cdot & (1 - \locIsRoot) \\ + \cdot & \locMxpMtntop \\ + \cdot & \locRac \\ + \end{array} \right] + \] + \saNote{} + This completely determines the \inst{RETURN} scenario for message calls. + The intent is that for (unexceptional) \inst{RETURN} instructions executed in a message call (internal) transaction + the \zkEvm{} will touch \textsc{ram} if and only if + (\emph{a}) the current execution context isn't at the root of the call stack + (\emph{b}) the \inst{RETURN} instruction provides nonempty return data + (\emph{c}) the caller context provided nonempty space wherein to copy (a portion of) the return data. + \end{enumerate} + \item[\underline{Setting the miscellaneous-row $n^°(i + \locFirstMiscRowOffset)$:}] + we impose that + \[ + \weightedMiscFlagSum + {i}{\locFirstMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \!\!\!\cdot\!\!\! & \locTriggerMmu \\ + + & \miscMxpWeight & \!\!\!\cdot\!\!\! & \locTriggerMxp \\ + + & \miscOobWeight & \!\!\!\cdot\!\!\! & \locTriggerOob \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \locFirstMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \locFirstMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag _{i + \locFirstMiscRowOffset} & = & \locTriggerMxp & (\trash) \\ + \miscOobFlag _{i + \locFirstMiscRowOffset} & = & \locTriggerOob & (\trash) \\ + \miscStpFlag _{i + \locFirstMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} We will specify \locTriggerMmu{}, \locTriggerMxp{} and \locTriggerOob{} shortly. + \item[\underline{Setting \locTriggerMxp:}] + we impose that + \[ + \locTriggerMxp \define \rOne + \] + \saNote{} In other words the \mxpMod{} must be triggered in all circumstances. + \item[\underline{Setting \locTriggerOob:}] + we impose that + \[ + \locTriggerOob \define \stackMaxcsx _{i - 1} + \scenReturnNonemptyDeployment _{i} + \] + \item[\underline{Setting \locTriggerMmu:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \locTriggerMmu & \define & \locCheckFirstByte + \locWriteSomeReturnData \\ + \locCheckFirstByte & \define & \stackIcpx _{i - 1} + \scenReturnNonemptyDeployment _{i} \\ + \locWriteSomeReturnData & \define & \scenReturnFromMessageCallWillTouchRam _{i} \\ + \end{array} \right. + \] + \item[\underline{Setting \locTriggerHashInfo{}:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \stackHashInfoFlag_{i - 1} & = & \locTriggerHashInfo \\ + % \stackHashInfoSize_{i - 1} & = & \locTriggerHashInfo \cdot \locSizeLo \\ + \end{array} \right. + \] + where we use the shorthand + \[ + \locTriggerHashInfo \define \scenReturnNonemptyDeployment_{i} + \] + \saNote{} In other words we trigger the \hashInfoMod{} module \emph{iff} \textbf{nonempty} bytecode is being (temporarily, at least) successfully deployed. When \textbf{empty} bytecode is being (\emph{idem}) deployed the associated code hash is $\emptyKeccak$ and requires no computation. + + \saNote{} As we will impose below, for a deployment to trigger the \hashInfoMod{} certain conditions must be met. One of them being that its size parameter be small (in fact: $\leq 24576$.) The above \emph{truncated} size parameter therefore accurately represents the actual size parameter of the instruction (when it matters.) +\end{description} +For concreteness we include a table representing the desired behavior of these flags: +\begin{figure}[!h] + \[ + \hspace*{-2.9cm} + \begin{array}{|l|lc||c|c|c|c|c|c|} \hline + \textsc{Scenario} & \textsc{Exception} & & \locTriggerMxp & \locTriggerOob & \locTriggerMmu & \locTriggerHashInfo \\ \hline \hline + \scenReturnException & \mxpxSH & (\stackMxpx _{i - 1} \equiv 1) & \oneCell & \gZero & \gZero & \gZero \\ \hline + \scenReturnException & \oogxSH & (\stackOogx _{i - 1} \equiv 1) & \oneCell & \gZero & \gZero & \gZero \\ \hline + \scenReturnException & \maxcsxSH & (\stackMaxcsx _{i - 1} \equiv 1) & \oneCell & \oneCell & \gZero & \gZero \\ \hline + \scenReturnException & \icpxSH & (\stackIcpx _{i - 1} \equiv 1) & \oneCell & \gZero & \oneCell & \gZero \\ \hline \hline + \multicolumn{3}{|l||}{\scenReturnFromMessageCallWillTouchRam } & \oneCell & \gZero & \oneCell & \gZero \\ \hline + \multicolumn{3}{|l||}{\scenReturnFromMessageCallWontTouchRam } & \oneCell & \gZero & \gZero & \gZero \\ \hline + \multicolumn{3}{|l||}{\scenReturnFromDeploymentEmptyByteCodeWillRevert } & \oneCell & \gZero & \gZero & \gZero \\ \hline + \multicolumn{3}{|l||}{\scenReturnFromDeploymentEmptyByteCodeWontRevert } & \oneCell & \gZero & \gZero & \gZero \\ \hline + \multicolumn{3}{|l||}{\scenReturnFromDeploymentNonemptyByteCodeWillRevert } & \oneCell & \oneCell & \oneCell & \oneCell \\ \hline + \multicolumn{3}{|l||}{\scenReturnFromDeploymentNonemptyByteCodeWontRevert } & \oneCell & \oneCell & \oneCell & \oneCell \\ \hline + \end{array} + \] + \label{hub: instruction handling: halting: return: desired trigger flags} + \caption{When to trigger different module functionalities.} +\end{figure} + +\saNote{} \label{hub: instruction handling: halting: return: desired trigger flags} +We emphasize that there are \textbf{two distinct reasons for triggering the \mmuMod{} module at this point in instruction processing}. +The first reasibt is to check for the presence or absence of the invalid code prefix exception. +This is what is done in the following scenarios: +\begin{enumerate} + \item when $\stackIcpx _{i - 1} \equiv 1$ (a subcase of $\scenReturnException \equiv 1$) we trigger a \textsc{ram} instruction \textbf{expecting to detect} an \icpxSH{}; + \item when $\scenReturnNonemptyDeployment _{i} \equiv 1$ we trigger a \textsc{ram} instruction \textbf{expecting not to detect} an \icpxSH{}. +\end{enumerate} +The other use case is for writing to the caller context's \textsc{ram}. +This is the usecase for \scenReturnFromMessageCallWillTouchRam{}. + +\saNote{} \label{hub: instruction handling: halting: return: why icpx requires an mxp instruction} +When verifying the presence of a \icpxSH{} there is \emph{a priori} no reason to \emph{also} check for \mxpxSH{}'s, yet the above indicates that the \zkEvm{} does just that. +The reason for this surprising choice is to ensure that the offset and size parameters with which we provide the \mmuMod{} are \emph{small}. +Indeed, \textbf{the \mmuMod{} module expects small parameters}, see chapter~(\ref{chap: mmu}) + +\begin{description} + \item[\underline{Setting the \mxpMod{} data:}] + \If $\miscMxpFlag _{i + \locFirstMiscRowOffset} = 1$ \Then we impose + \[ + \setMxpInstructionTypeFour {i}{\locFirstMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \locInst \\ + \utt{Deploys byte code:} & \locDeploys \\ + \utt{Offset high part:} & \locOffsetHi \\ + \utt{Offset low part:} & \locOffsetLo \\ + \utt{Size high part:} & \locSizeHi \\ + \utt{Size low part:} & \locSizeLo \\ + \end{array} \right] + \] + \saNote{} Recall that by definition $\locInst = \inst{RETURN}$. + + \saNote{} The precondition pertaining to $\miscMxpFlag$ is unncessary given that this flag is \textbf{always} set by the above. + \item[\underline{Setting the \oobMod{} data:}] + \If $\miscOobFlag _{i + \locFirstMiscRowOffset} = 1$ \Then we impose that + \[ + \setOobInstructionDeployment + {i}{\locFirstMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Code size high:} & \locSizeHi \\ + \utt{Code size low:} & \locSizeLo \\ + \end{array} \right] + \] + \saNote{} Recall (again) that by construction $\locInst = \inst{RETURN}$. + % \item[\underline{Setting the \locTriggerMmu{} flag:}] + % we impose + % \[ + % \locTriggerMmu = + % \left[ \begin{array}{lr} + % + & \locTriggerMmuCodePrefixCheck \\ + % + & \locTriggerMmuWriteReturnDataToRam \\ + % \end{array} \right] + % \] + % where we set + % \[ + % \left\{\begin{array}{lcl} + % \locTriggerMmuCodePrefixCheck & = & + % \left[ \begin{array}{lr} + % + & \locIcpx \\ + % + & \scenReturnNonemptyDeployment _{i} \\ + % \end{array} \right] \\ + % \locTriggerMmuWriteReturnDataToRam & = & \scenReturnFromMessageCallWillTouchRam_{i} \\ + % \end{array} \right. + % \] + % \saNote{} We need to trigger the \mmuMod{} in the following circumstances: + % (\emph{a}) an \icpxSH{} (is predicted to) take place + % (\emph{b}) the \zkEvm{} returns from a message call and requires modifying its caller context's \textsc{ram} + % (\emph{c}) the \zkEvm{} returns from a deployment and will (temporarily or permanently) deploy nonempty byte code, in which case we need to ensure that the leading byte of said (nonempty) byte code isn't \texttt{0xEF}. + \item[\underline{Setting \mmuMod{} data --- first call:}] + we impose the following + \begin{enumerate} + \item \If $\locCheckFirstByte = 1$ + \[ + \setMmuInstructionParametersInvalidCodePrefix { + anchorRow = i , + relOffset = \locFirstMiscRowOffset , + sourceId = \cn _{i} , + sourceOffsetLo = \locOffsetLo , + successBit = \stackIcpx _{i - 1} , + } + % \setMmuInstructionParametersInvalidCodePrefix + % {i}{\locFirstMiscRowOffset} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \cn _{i} \\ + % \utt{Source offset low:} & \locSizeLo \\ + % \utt{Success bit:} & \stackIcpx _{i - 1} \\ + % \end{array} \right] + \] + \item \If $\locWriteSomeReturnData = 1$ + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \locFirstMiscRowOffset , + sourceId = \cn _{i} , + targetId = \caller _{i} , + sourceOffsetLo = \locOffsetLo , + size = \locSizeLo , + referenceOffset = \locRao , + referenceSize = \locRac , + } + % \setMmuInstructionParametersRamToRamSansPadding + % {i}{\locFirstMiscRowOffset} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \cn _{i} \\ + % \utt{Target ID:} & \caller _{i} \\ + % \utt{Source offset low:} & \locOffsetLo \\ + % \utt{Size:} & \locSizeLo \\ + % \utt{Reference offset:} & \locRao \\ + % \utt{Reference size:} & \locRac \\ + % \end{array} \right] + \] + \end{enumerate} + \saNote{} Recall that the lookup serving the \mmuMod{} module its instructions provides the current context number \cn{} and caller context number \caller{} (so that there is no need to specify those in the above.) + \item[\underline{Justifying the \stackMxpx{}:}] + we unconditionally impose that + \[ + \stackMxpx _{i - 1} = \miscMxpMxpx _{i + \locFirstMiscRowOffset} + \] + \item[\underline{Justifying the \stackIcpx{}:}] + we impose that + \begin{enumerate} + \item \If $\locCheckFirstByte = 0$ \Then we impose $\stackIcpx _{i - 1} = 0$ + \item \If $\locCheckFirstByte = 1$ \Then we impose that + \[ + \stackIcpx _{i - 1} = \miscMmuSuccessBit _{i + \locFirstMiscRowOffset} \quad (\trash) + \] + \end{enumerate} + \saNote{} We already (implicitly) constrained \stackIcpx{} when we set the \mmuMod{} instruction checking the first byte of the byte code to deploy. + \item[\underline{Justifying the \stackMaxcsx{}:}] + and we impose + \begin{enumerate} + \item \If $\miscOobFlag _{i + \locFirstMiscRowOffset} = 0$ \Then $\stackMaxcsx _{i - 1} = 0$ + \item \If $\miscOobFlag _{i + \locFirstMiscRowOffset} = 1$ \Then $\stackMaxcsx _{i - 1} = \locOobMaxcsx$ + \end{enumerate} + where we define the following shorthand + \[ + \locOobMaxcsx + \define + \miscOobDataCol{7} _{i + \locFirstMiscRowOffset} + \] + \item[\underline{Setting gas cost:}] + we impose that + \begin{enumerate} + \item \If $\locGasCostRequired = 0$ \Then $\gasCost_{i} = 0$ + \item \If $\locGasCostRequired = 1$ \Then $\gasCost_{i} = \stackStaticGas _{i - 1} + \miscMxpGasMxp _{i + \locFirstMiscRowOffset}$ + \end{enumerate} + where we made use of the following shorthand + \[ + \locGasCostRequired \define \stackOogx _{i - 1} + \scenReturnRaisesNoException _{i} + \] + \saNote{} By construction $\locGasCostRequired \equiv \stackOogx _{i - 1} + \scenReturnRaisesNoException _{i}$ is \textbf{binary}. +\end{description} diff --git a/hub/instruction_handling/halt/return/intro.tex b/hub/instruction_handling/halt/return/intro.tex new file mode 100644 index 0000000..57847ba --- /dev/null +++ b/hub/instruction_handling/halt/return/intro.tex @@ -0,0 +1,11 @@ +We deal in this section with the instruction handling of the \inst{RETURN} instruction. +This instruction is the most complex of all instructions in the \textbf{halting instruction family}. +Like \inst{STOP} and \inst{SELFDESTRUCT} it is rollback sensitive. +It can fail in complex ways. +Furthermore there are two exceptions that can \textbf{only} be triggered by \inst{RETURN} instructions (in a deployment context): +\begin{description} + \item[\maxcsxSH{}:] + triggered whenever attempting to deploy byte code with $ \col{code\_size} >24576 $ + \item[\icpxSH{}:] + triggered whenever attempting to deploy (nonempty) code starting with $\texttt{0xEF}$; +\end{description} diff --git a/hub/instruction_handling/halt/return/scenario_setting.tex b/hub/instruction_handling/halt/return/scenario_setting.tex new file mode 100644 index 0000000..11cfe3c --- /dev/null +++ b/hub/instruction_handling/halt/return/scenario_setting.tex @@ -0,0 +1,42 @@ +We impose the following constraint. +\begin{description} + \item[\underline{Imposing a \inst{RETURN}-scenario:}] + we enforce that + \[ + \If + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecHaltFlag _{i} & = & 1 \\ + \decFlag {1}_{i} & = & 1 \\ + \stackSux _{i} + \stackSox _{i} & = & 0 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \peekScenario _{i + 1} & = & 1 \\ + \scenReturnSum _{i + 1} & = & 1 \\ + \end{array} \right. + \] + \item[\underline{\dots{} and imposing the converse:}] + conversely we may want to impose + \[ + \underbrace{\If + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnSum _{i} & = & 1 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \peekStack _{i - 1} & = & 1 \\ + \stackDecHaltFlag _{i - 1} & = & 1 \\ + \decFlag {1}_{i - 1} & = & 1 \\ + \stackSux _{i - 1} + \stackSox _{i - 1} & = & 0 \\ + \end{array} \right.}_{\displaystyle (\trash)} + \] +\end{description} +\saNote{} +Given a \inst{RETURN} instruction on row $n^°i$ the above requires the insertion of a scenario-row on row $n^°(i + 1)$ with a \inst{RETURN} scenario prediction (i.e. $\scenReturnSum \equiv 1$.) +This row is the new vantage point for dealing with \inst{RETURN} instructions. +By the above a scenario-row with a \inst{RETURN} scenario prediction may only appear following a \inst{RETURN} instruction raising no stack exception. + +\saNote{} +The above enforces that \emph{some} \inst{RETURN} scenario be active, but not which one. diff --git a/hub/instruction_handling/halt/return/shorthands.tex b/hub/instruction_handling/halt/return/shorthands.tex new file mode 100644 index 0000000..fd8b2a5 --- /dev/null +++ b/hub/instruction_handling/halt/return/shorthands.tex @@ -0,0 +1,43 @@ +\begin{center} + \boxed{% + \text{The shorthands introduced below should only be used given that } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnSum _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +We introduce some shorthands that will be used within the instruction processing of \inst{RETURN}'s. +\[ + \left\{ \begin{array}{lcl} + \locInst & \define & \stackInst _{i - 1} \\ + % \locMxpx & \define & \stackMxpx _{i - 1} \\ + % \locOogx & \define & \stackOogx _{i - 1} \\ + % \locMaxcsx & \define & \stackMaxcsx _{i - 1} \\ + % \locIcpx & \define & \stackIcpx _{i - 1} \\ + \locOffsetHi & \define & \stackItemValHi{1} _{i - 1} \\ + \locOffsetLo & \define & \stackItemValLo{1} _{i - 1} \\ + \locSizeHi & \define & \stackItemValHi{2} _{i - 1} \\ + \locSizeLo & \define & \stackItemValLo{2} _{i - 1} \\ + % \locTriggerHashInfo & \define & _{i} \ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\locHashInfoCodeHashHi ~ \define ~ \stackHashInfoValHi _{i - 1}} \\ + \multicolumn{3}{l}{\locHashInfoCodeHashLo ~ \define ~ \stackHashInfoValLo _{i - 1}} \\ + \multicolumn{3}{l}{\locDeploymentAddressHi ~ \define ~ \cnCodeAddress\high_{i + \locCurrentContextRowOffset}} \\ + \multicolumn{3}{l}{\locDeploymentAddressLo ~ \define ~ \cnCodeAddress\low _{i + \locCurrentContextRowOffset}} \\ + \locIsRoot & \define & \cnIsRootContext _{i + \locCurrentContextRowOffset } \\ + \locDeploys & \define & \cnCodeDepStatus _{i + \locCurrentContextRowOffset } \\ + \locRao & \define & \cnRao _{i + \locCurrentContextRowOffset } \\ + \locRac & \define & \cnRac _{i + \locCurrentContextRowOffset } \\ + \locMxpMtntop & \define & \miscMxpTypeFourInstMayTriggerMmu _{i + \locFirstMiscRowOffset } \\ + \locDeploymentCfi & \define & \accCfi _{i + \locNonemptyDeploymentFirstAccountRowOffset}  \\ + \end{array} \right. +\] +\saNote{} +We remind the reader of the interpretation of the \miscMxpTypeFourInstMayTriggerMmu{} acronym: +\[ + \YNMO +\] +and that the \mxpMod{} module is responsible for computing this (binary) value, see chapter~(\ref{chap: mxp}). +We further remind the reader that $\miscMxpTypeFourInstMayTriggerMmu \equiv 1$ if and only if no \mxpxSH{} has occurred and the size parameter of the \mxpMod{} call is nonzero. diff --git a/hub/instruction_handling/halt/return/specialized/_inputs.tex b/hub/instruction_handling/halt/return/specialized/_inputs.tex new file mode 100644 index 0000000..6fdc11e --- /dev/null +++ b/hub/instruction_handling/halt/return/specialized/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsubsection{The \scenReturnException{} case \lispDone{}} \label{hub: instruction handling: halt: return: exceptional} \input{instruction_handling/halt/return/specialized/exceptional} +\subsubsubsection{The \scenReturnFromMessageCall{} case \lispDone{}} \label{hub: instruction handling: halt: return: unexceptional message call} \input{instruction_handling/halt/return/specialized/message_call} +\subsubsubsection{The \scenReturnEmptyDeployment{} case \lispDone{}} \label{hub: instruction handling: halt: return: trivial deployment} \input{instruction_handling/halt/return/specialized/deployment_trivial} +\subsubsubsection{The \scenReturnNonemptyDeployment{} case \lispDone{}} \label{hub: instruction handling: halt: return: nontrivial deployment} \input{instruction_handling/halt/return/specialized/deployment_nontrivial} + diff --git a/hub/instruction_handling/halt/return/specialized/deployment_nontrivial.tex b/hub/instruction_handling/halt/return/specialized/deployment_nontrivial.tex new file mode 100644 index 0000000..98b03d2 --- /dev/null +++ b/hub/instruction_handling/halt/return/specialized/deployment_nontrivial.tex @@ -0,0 +1,171 @@ +% \locSecondMiscRowOffsetDeployAndHash +% \locNonemptyDeploymentFirstAccountRowOffset +% \locNonemptyDeploymentSecondAccountRowOffset +% \locCallerContextRowOffsetNonemptyDeploymentWillRevert +% \locCallerContextRowOffsetNonemptyDeploymentWontRevert +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnNonemptyDeployment _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +As per the above this section deals with recognizing and handling \textbf{unexceptional and nontrivial} \inst{RETURN} instructions executed in a deployment context. +\begin{description} + \item[\underline{The second miscellaneous row $n^°(i + \locSecondMiscRowOffsetDeployAndHash)$:}] + we impose the following (wherein we deploy bytecode and hash it at the same time) + \[ + \weightedMiscFlagSum + {i}{\locSecondMiscRowOffsetDeployAndHash} + = + \miscMmuWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \locSecondMiscRowOffsetDeployAndHash} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \locSecondMiscRowOffsetDeployAndHash} & = & \rOne & (\trash) \\ + \miscMxpFlag _{i + \locSecondMiscRowOffsetDeployAndHash} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \locSecondMiscRowOffsetDeployAndHash} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \locSecondMiscRowOffsetDeployAndHash} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the (second) \mmuMod{} instruction:}] + we impose that + \[ + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i , + relOffset = \locSecondMiscRowOffsetDeployAndHash , + sourceId = \cn_{i} , + targetId = \locDeploymentCfi , + auxiliaryId = 1 + \hubStamp_{i} , + % sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \locOffsetLo , + % targetOffsetLo = \col{tgt\_offset\_lo} , + size = \locSizeLo , + % referenceOffset = \col{ref\_offset} , + referenceSize = \locSizeLo , + successBit = \nothing , + % limbOne = \col{limb\_1} , + % limbTwo = \col{limb\_2} , + exoSum = \exoWeightRom + \exoWeightKec , + phase = \nothing , + } + % \setMmuInstructionParametersRamToExoWithPadding {i}{\locSecondMiscRowOffsetDeployAndHash} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \cn_{i} \\ + % \utt{Target ID:} & \accCfi _{i + \locNonemptyDeploymentFirstAccountRowOffset} \\ + % \utt{Auxiliary ID:} & 1 + \hubStamp_{i} \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \locOffsetLo \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \locSizeLo \\ + % % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \locSizeLo \\ + % \utt{Success bit:} & \nothing \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \exoWeightRom + \exoWeightKec \\ + % \utt{Phase:} & \nothing \\ + % \end{array} \right] + \] + \saNote{} + The above performs both + (\emph{a}) the transfer of bytecode to the \romMod{} module for deployment + (\emph{b}) the transfer of bytecode to the \shakiraMod{} module for hashing. + \item[\underline{The first account row $n^°(i + \locNonemptyDeploymentFirstAccountRowOffset)$:}] + we impose the following + \[ + \left\{ \begin{array}{lclr} + \accAddressHi _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \locDeploymentAddressHi \\ + \accAddressLo _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \locDeploymentAddressLo \\ + \multicolumn{3}{l}{\accSameBalance {i} {\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameNonce {i} {\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \accCodesize\new _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \locSizeLo \\ + \accCodehashHi\new _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \locHashInfoCodeHashHi \\ + \accCodehashLo\new _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \locHashInfoCodeHashLo \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i} {\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \accDepStatus\new _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & 0 \vspace{2mm} \\ + \multicolumn{3}{l}{\accSameWarmth {i} {\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i} {\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \accRomLexFlag _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \rOne \\ + \accTrmFlag _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \gZero \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i , + relOffset = \locNonemptyDeploymentFirstAccountRowOffset, + domOffset = 0 , + } + } \\ + \end{array} \right. + \] + \saNote{} + Again the following constraints do not need to be enforced (they hold implictly) and we add them for reference: + \[ + \left\{ \begin{array}{lclr} + \accCodehashHi _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \accDepStatus _{i + \locNonemptyDeploymentFirstAccountRowOffset} & = & \rOne & (\trash) \\ + \multicolumn{3}{l}{\accIsntPrecompile {i}{\locNonemptyDeploymentFirstAccountRowOffset}} & (\trash) \\ + \end{array} \right. + \] + \item[\underline{The second account row $n^°(i + \locNonemptyDeploymentSecondAccountRowOffset)$:}] + \If $\scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accSameAddr {i}{\locNonemptyDeploymentSecondAccountRowOffset}{\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\locNonemptyDeploymentSecondAccountRowOffset}{\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\locNonemptyDeploymentSecondAccountRowOffset}{\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\locNonemptyDeploymentSecondAccountRowOffset}{\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\locNonemptyDeploymentSecondAccountRowOffset}{\locNonemptyDeploymentFirstAccountRowOffset}} \vspace{2mm} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\locNonemptyDeploymentSecondAccountRowOffset}{\locNonemptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locNonemptyDeploymentSecondAccountRowOffset}} \\ + \accRomLexFlag _{i + \locNonemptyDeploymentSecondAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \locNonemptyDeploymentSecondAccountRowOffset} & = & 0 \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locNonemptyDeploymentSecondAccountRowOffset, + subOffset = 1, + } + } \\ + % \ob{TODO: The second argument \dots{} just a typo ?} + % {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \end{array} \right. + \] + \item[\underline{Setting the caller's new return data:}] + we impose that + \begin{description} + \item[\underline{The ``will revert'' case:}] + \If $\scenReturnFromDeploymentNonemptyByteCodeWillRevert_{i} = 1$ \Then + \begin{enumerate} + \item \If $\locIsRoot = 1$ \Then we impose + \[ + \readContextData + {i}{\locCallerContextRowOffsetNonemptyDeploymentWillRevert} + {\cn_{i}} + \] + \item \If $\locIsRoot = 0$ \Then we impose + \[ + \executionProvidesEmptyReturnData + {i}{\locCallerContextRowOffsetNonemptyDeploymentWillRevert} + \] + \end{enumerate} + \item[\underline{The ``won't revert'' case:}] + \If $\scenReturnFromDeploymentNonemptyByteCodeWontRevert_{i} = 1$ \Then + \begin{enumerate} + \item \If $\locIsRoot = 1$ \Then we impose + \[ + \readContextData + {i}{\locCallerContextRowOffsetNonemptyDeploymentWontRevert} + {\cn_{i}} + \] + \item \If $\locIsRoot = 0$ \Then we impose + \[ + \executionProvidesEmptyReturnData + {i}{\locCallerContextRowOffsetNonemptyDeploymentWontRevert} + \] + \end{enumerate} + \end{description} +\end{description} diff --git a/hub/instruction_handling/halt/return/specialized/deployment_trivial.tex b/hub/instruction_handling/halt/return/specialized/deployment_trivial.tex new file mode 100644 index 0000000..dc86b23 --- /dev/null +++ b/hub/instruction_handling/halt/return/specialized/deployment_trivial.tex @@ -0,0 +1,110 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnEmptyDeployment _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +As per the above this section deals with recognizing and handling \textbf{unexceptional and trivial} \inst{RETURN} instructions executed in a deployment context. +\begin{description} + \item[\underline{The first account row $n^°(i + \locEmptyDeploymentFirstAccountRowOffset)$:}] + we impose the following + \[ + \left\{ \begin{array}{lclr} + \accAddressHi _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \locDeploymentAddressHi \\ + \accAddressLo _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \locDeploymentAddressLo \\ + \multicolumn{3}{l}{\accSameBalance {i}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \accCodesize\new _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \locSizeLo \\ + \accCodehashHi\new _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \emptyKeccakHi \\ + \accCodehashLo\new _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \emptyKeccakLo \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \accDepStatus\new _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & 0 \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \accRomLexFlag _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & 0 \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locEmptyDeploymentFirstAccountRowOffset, + domOffset = 0, + } + } \\ + \end{array} \right. + \] + \saNote{} + Given the scenario ($\scenReturnEmptyDeployment \equiv 1$) we of course have $\locSizeLo = 0$. + + \saNote{} + The following constraints aren't required \emph{per se} as they hold implicitly: + \[ + \left\{ \begin{array}{lclr} + \accCodehashHi _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \accDepStatus _{i + \locEmptyDeploymentFirstAccountRowOffset} & = & 1 & (\trash) \\ + \multicolumn{3}{l}{\accIsntPrecompile {i}{\locEmptyDeploymentFirstAccountRowOffset}} & (\trash) \\ + \end{array} \right. + \] + \item[\underline{The second account row $n^°(i + \locEmptyDeploymentSecondAccountRowOffset)$:}] + \If $\scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accSameAddr {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \vspace{2mm} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locEmptyDeploymentSecondAccountRowOffset}} \\ + \accRomLexFlag _{i + \locEmptyDeploymentSecondAccountRowOffset} & = & 0 \\ + \accTrmFlag _{i + \locEmptyDeploymentSecondAccountRowOffset} & = & 0 \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locEmptyDeploymentSecondAccountRowOffset, + subOffset = 1, + } + } \\ + % \ob{TODO: The second argument \dots{} just a typo ?} + % {i}{\locEmptyDeploymentSecondAccountRowOffset}{\locEmptyDeploymentFirstAccountRowOffset}} \\ + \end{array} \right. + \] + \item[\underline{Setting the caller's new return data:}] + we impose that + \begin{description} + \item[\underline{The ``will revert'' case:}] + \If $\scenReturnFromDeploymentEmptyByteCodeWillRevert_{i}~=~1$ \Then + we impose that + \begin{enumerate} + \item \If $\locIsRoot = 1$ \Then we impose + \[ + \readContextData + {i}{\locCallerContextRowOffsetEmptyDeploymentWillRevert} + {\cn_{i}} + \] + \item \If $\locIsRoot = 0$ \Then we impose + \[ + \executionProvidesEmptyReturnData + {i}{\locCallerContextRowOffsetEmptyDeploymentWillRevert} + \] + \end{enumerate} + \item[\underline{The ``won't revert'' case:}] + \If $\scenReturnFromDeploymentEmptyByteCodeWontRevert_{i}~=~1$ \Then + we impose that + \begin{enumerate} + \item \If $\locIsRoot = 1$ \Then we impose + \[ + \readContextData + {i}{\locCallerContextRowOffsetEmptyDeploymentWontRevert} + {\cn_{i}} + \] + \item \If $\locIsRoot = 0$ \Then we impose + \[ + \executionProvidesEmptyReturnData + {i}{\locCallerContextRowOffsetEmptyDeploymentWontRevert} + \] + \end{enumerate} + \end{description} +\end{description} diff --git a/hub/instruction_handling/halt/return/specialized/exceptional.tex b/hub/instruction_handling/halt/return/specialized/exceptional.tex new file mode 100644 index 0000000..fcff8a9 --- /dev/null +++ b/hub/instruction_handling/halt/return/specialized/exceptional.tex @@ -0,0 +1,29 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnException _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +We impose the following +\begin{description} + \item[\underline{Setting the caller's new return data:}] + we impose that + \begin{enumerate} + \item \If $\locIsRoot = 1$ \Then we impose + \[ + \executionProvidesEmptyReturnData + {i}{\locCallerContextRowOffsetException} + \quad (\trash) + \] + \item \If $\locIsRoot = 0$ \Then we impose + \[ + \executionProvidesEmptyReturnData + {i}{\locCallerContextRowOffsetException} + \quad (\trash) + \] + \end{enumerate} +\end{description} +\saNote{} +Both cases follow from general context update constraints that apply whenever an exception occurs. diff --git a/hub/instruction_handling/halt/return/specialized/message_call.tex b/hub/instruction_handling/halt/return/specialized/message_call.tex new file mode 100644 index 0000000..9d08b93 --- /dev/null +++ b/hub/instruction_handling/halt/return/specialized/message_call.tex @@ -0,0 +1,35 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenReturnFromMessageCall _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +As per the above this section deals with recognizing and handling unexceptional \inst{RETURN} instructions executed in a message call context. +\begin{description} + \item[\underline{Setting the caller's new return data:}] + we impose that + \begin{enumerate} + \item \If $\locIsRoot = 1$ \Then we impose + \[ + \readContextData + {i}{\locCallerContextRowOffsetMessageCall} + {\cn_{i}} + \] + \item \If $\locIsRoot = 0$ \Then we impose + \[ + \provideReturnData { + anchorRow = i , + relOffset = \locCallerContextRowOffsetMessageCall , + returnDataReceiver = \caller_{i} , + returnDataProvider = \cn_{i} , + returnDataOffset = \locOffsetLo , + returnDataSize = \locSizeLo , + } + \] + \end{enumerate} +\end{description} +\saNote{} +There is no \textbf{intrinsic} reason for the \zkEvm{} to read the current execution context data in case the current context is the root. +We impose this solely in order to prevent stealth updates to another execution context's data. diff --git a/hub/instruction_handling/halt/revert/_inputs.tex b/hub/instruction_handling/halt/revert/_inputs.tex new file mode 100644 index 0000000..6bfe653 --- /dev/null +++ b/hub/instruction_handling/halt/revert/_inputs.tex @@ -0,0 +1,5 @@ +\input{instruction_handling/halt/revert/_local} +\subsubsubsection{Introduction} \label{hub: instruction handling: halt: revert: intro} \input{instruction_handling/halt/revert/intro} +\subsubsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: halt: revert: shorthands} \input{instruction_handling/halt/revert/shorthands} +\subsubsubsection{Constraints \lispDone{}} \label{hub: instruction handling: halt: revert: constraints} \input{instruction_handling/halt/revert/constraints} +\subsubsubsection{Graphical representation} \label{hub: instruction handling: halt: revert: representation} \input{instruction_handling/halt/revert/representation} diff --git a/hub/instruction_handling/halt/revert/_local.tex b/hub/instruction_handling/halt/revert/_local.tex new file mode 100644 index 0000000..e6db71a --- /dev/null +++ b/hub/instruction_handling/halt/revert/_local.tex @@ -0,0 +1,21 @@ +\def\locInst {\col{instruction}} +\def\locMxpx {\col{mxpx}} +\def\locOogx {\col{oogx}} +\def\locTriggerMmu {\col{trigger\_MMU}} +\def\locRao {\col{r@o}} +\def\locRac {\col{r@c}} +\def\locOffset {\col{offset}} +\def\locOffsetHi {\locOffset\col{\_hi}} +\def\locOffsetLo {\locOffset\col{\_lo}} +\def\locSize {\col{size}} +\def\locSizeHi {\locSize\col{\_hi}} +\def\locSizeLo {\locSize\col{\_lo}} +\def\locMxpGas {\col{mxp\_gas}} +\def\locCurrentContext {\col{current\_context}} +\def\locCallerContext {\col{caller\_context}} +\def\locCurrentContextIsRoot {\col{caller\_is\_root}} + + +\def\locRevertMiscRowOffset {\yellowm{1}} +\def\locRevertCurrentContextRowOffset {\yellowm{2}} +\def\locRevertParentContextRowOffset {\yellowm{3}} diff --git a/hub/instruction_handling/halt/revert/constraints.tex b/hub/instruction_handling/halt/revert/constraints.tex new file mode 100644 index 0000000..5b6f04d --- /dev/null +++ b/hub/instruction_handling/halt/revert/constraints.tex @@ -0,0 +1,170 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & \!\!\! = \!\!\! & 1 \\ + \stackDecHaltFlag _{i} & \!\!\! = \!\!\! & 1 \\ + \decFlag {2}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackSux _{i} + \stackSox _{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right.} +\end{center} +The present section deals with handling \inst{REVERT} instructions. +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\twoZeroSP_{i}$; + \item[\underline{Allowable exceptions:}] + we impose + \[ + \xAhoy _{i} + = + \left[ \begin{array}{cl} + + & \stackMxpx _{i} \\ + + & \stackOogx _{i} \\ + \end{array} \right] + \quad (\trash) + \] + \item[\underline{Setting $\nonStackRows$:}] + we impose $\nonStackRows_{i} = 2 + (1-\xAhoy_{i})$ + \item[\underline{Setting the peeking flags:}] + we impose the following + \begin{enumerate} + \item \If $\xAhoy_{i} = 1$ \Then we impose + \[ + \left[ \begin{array}{r} + + \peekMisc _{i + \locRevertMiscRowOffset } \\ + + \peekContext _{i + \locRevertCurrentContextRowOffset} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\xAhoy_{i} = 0$ \Then we impose + \[ + \left[ \begin{array}{r} + + \peekMisc _{i + \locRevertMiscRowOffset } \\ + + \peekContext _{i + \locRevertCurrentContextRowOffset} \\ + + \peekContext _{i + \locRevertParentContextRowOffset } \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \item[\underline{Setting the context rows:}] + we impose the following + \begin{enumerate} + \item \If $\xAhoy_{i} = 1$ \Then we impose + \[ \executionProvidesEmptyReturnData {i}{\locRevertCurrentContextRowOffset} \quad (\trash) \] + \item \If $\xAhoy_{i} = 0$ \Then we impose + \begin{enumerate} + \item $\readContextData {i}{\locRevertCurrentContextRowOffset}{\locCurrentContext}$ + \item \If $\locCurrentContextIsRoot = 1$ \Then $\readContextData {i}{\locRevertParentContextRowOffset}{\locCallerContext}$ + \item \If $\locCurrentContextIsRoot = 0$ \Then + \[ + \provideReturnData { + anchorRow = i , + relOffset = \locRevertParentContextRowOffset , + returnDataReceiver = \locCallerContext , + returnDataProvider = \locCurrentContext , + returnDataOffset = \locOffsetLo , + returnDataSize = \locSizeLo , + } + % \provideReturnData + % {i}{\locRevertParentContextRowOffset} + % {\locCallerContext } % Return data receiver + % {\locCurrentContext} % Return data provider + % {\locOffsetLo } % Return data offset + % {\locSizeLo } % Return data size + \] + In other words: execution provides return data to its caller context provided that it isn't the root context. + \end{enumerate} + \end{enumerate} + \item[\underline{Setting \locTriggerMmu{}:}] + we impose the following: + \begin{enumerate} + \item \If $\xAhoy _{i} = 1$ \Then $\locTriggerMmu = 0$ + \item \If $\locCurrentContextIsRoot = 1$ \Then $\locTriggerMmu = 0$ + \item \If \Big($\xAhoy _{i} = 0$ \et $\cnIsRootContext _{i} = 0$\Big) \Then + \begin{enumerate} + \item \If $\locSizeLo \cdot \locRac = 0$ \Then $\locTriggerMmu = 0$ + \item \If $\locSizeLo \cdot \locRac \neq 0$ \Then $\locTriggerMmu = 1$ + \end{enumerate} + \end{enumerate} + \saNote{} \label{hub: instruction handling: halting: revert: trigger_MMU definition} + In order to trigger the \mmuMod{} module a \inst{REVERT} instruction must trigger no exception, have nonzero size parameter and arise in a context with nonzero \cnRac{}. In particular this cannot happen + (\emph{a}) in the root context of a transaction nor + (\emph{b}) in a context that was spawned through a \inst{CREATE}-type instruction. Indeed in both cases it holds that $\cnRac \equiv 0$. + \item[\underline{The miscellaneous-row $n^°(i + \locRevertMiscRowOffset)$:}] + we impose + \[ + \weightedMiscFlagSum {i}{\locRevertMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \!\!\!\cdot\!\!\! & \locTriggerMmu \\ + + & \miscMxpWeight \\ + \end{array} \right] + \] + i.e. + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \locRevertMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \locRevertMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag _{i + \locRevertMiscRowOffset} & = & \rOne & (\trash) \\ + \miscOobFlag _{i + \locRevertMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \locRevertMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the \mxpMod{} data:}] + we impose + \[ + \setMxpInstructionTypeFour {i}{\locRevertMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \locInst \\ + \utt{Deploys byte code:} & 0 \\ + \utt{Offset high part:} & \locOffsetHi \\ + \utt{Offset low part:} & \locOffsetLo \\ + \utt{Size high part:} & \locSizeHi \\ + \utt{Size low part:} & \locSizeLo \\ + \end{array} \right] + \] + \item[\underline{Setting $\stackMxpx _{i}$:}] + we impose that + \[ + \stackMxpx _{i} + = + \miscMxpMxpx _{i + \locRevertMiscRowOffset} + \] + \item[\underline{Setting the \mmuMod{} data:}] + we impose \If $\miscMmuFlag_{i + \locRevertMiscRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \locRevertMiscRowOffset , + sourceId = \locCurrentContext , + targetId = \locCallerContext , + sourceOffsetLo = \locOffsetLo , + size = \locSizeLo , + referenceOffset = \locRao , + referenceSize = \locRac , + } + % \setMmuInstructionParametersRamToRamSansPadding {i}{\locRevertMiscRowOffset} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \locCurrentContext \\ + % \utt{Target ID:} & \locCallerContext \\ + % % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \locOffsetLo \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \locSizeLo \\ + % \utt{Reference offset:} & \locRao \\ + % \utt{Reference size:} & \locRac \\ + % % \utt{Success bit:} & \col{success\_bit} \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % % \utt{Exo sum:} & \col{exo\_sum} \\ + % % \utt{Phase:} & \col{phase} \\ + % \end{array} \right] + \] + \item[\underline{Setting the gas cost:}] + we impose that + \begin{enumerate} + \item \If $\stackMxpx _{i} = 1$ \Then $\gasCost_{i} = 0$ + \item \If $\stackMxpx _{i} = 0$ \Then $\gasCost_{i} = \staticGas_{i} + \locMxpGas$ + \end{enumerate} +\end{description} diff --git a/hub/instruction_handling/halt/revert/intro.tex b/hub/instruction_handling/halt/revert/intro.tex new file mode 100644 index 0000000..686a4cf --- /dev/null +++ b/hub/instruction_handling/halt/revert/intro.tex @@ -0,0 +1,9 @@ +We deal in this section with the handling of the \inst{REVERT} instruction. +This instruction bears some superficial resemblance with the \inst{RETURN} instruction, but its handling is \textbf{much} simpler. +In particular its behaviour does not depend on whether or not the current execution context is a deployment context. \vspace{1mm} + +\saNote{} In message call context a \inst{REVERT} instruction may write a portion of return data to the caller context's \textsc{ram} (on top of providing said data as return data.) In a deployment context, no return data will be written to the caller context's \textsc{ram} and the \mmuMod{} won't be triggered (but return data will be provided, regardless.) The present arithmetization deals with these disparate behaviours uniformly. +Whether or not the caller context's \textsc{ram} is touched or not is controlled by the +\locTriggerMmu{} flag, see~(\ref{hub: instruction handling: halt: revert: representation}), which is computed in terms of +the current context's \RAC{}, i.e. \locRac{}, see section~(\ref{hub: instruction handling: halt: revert: shorthands}), and the instruction's size parameter \locSize{}, see~(\ref{hub: instruction handling: halt: revert: shorthands}). To be precise, it is absence of an exception and the vanishing of either parameters (i.e. of their product) that dictates \locTriggerMmu, see~(\ref{hub: instruction handling: halting: revert: trigger_MMU definition}). +For deployment contexts and root contexts $\locRac \equiv 0$, so that our arithmetization works in both deployment and message call contexts. diff --git a/hub/instruction_handling/halt/revert/lua/exceptional.lua.tex b/hub/instruction_handling/halt/revert/lua/exceptional.lua.tex new file mode 100644 index 0000000..b01dd51 --- /dev/null +++ b/hub/instruction_handling/halt/revert/lua/exceptional.lua.tex @@ -0,0 +1,57 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ███████\ ████████\ ██\ ██\ ████████\ ███████\ ████████\ + ██ __██\ ██ _____|██ | ██ |██ _____|██ __██\\__██ __| + ██ | ██ |██ | ██ | ██ |██ | ██ | ██ | ██ | + ███████ |█████\ \██\ ██ |█████\ ███████ | ██ | + ██ __██< ██ __| \██\██ / ██ __| ██ __██< ██ | + ██ | ██ |██ | \███ / ██ | ██ | ██ | ██ | + ██ | ██ |████████\ \█ / ████████\ ██ | ██ | ██ | + \__| \__|\________| \_/ \________|\__| \__| \__| + + + + | _) | + _ \ \ \ / __| _ \ __ \ __| | _ \ __ \ _` | | + __/ ` < ( __/ | | | | ( | | | ( | | + \___| _/\_\ \___| \___| .__/ \__| _| \___/ _| _| \__,_| _| + _| + + +|-------+---------+------------------------------------+--------------------------------| +| Row | Persp. | Action | Comments | +|-------+---------+------------------------------------+--------------------------------| +| i | STACK | ⇒ offset, size | by assumption AHOY = 0 | +|-------+---------+------------------------------------+--------------------------------| +| i + 1 | MISC | | | +| | | MXP module: | MXP module is always triggered | +| | | =========== | | +| | | | | +| | | . ⇒ MXP/MXPX | either | +| | | . ⇒ MXP/MXP_GAS | . MXPX ≡ 1 | +| | | | . OOGX ≡ 1 | +| | | trigger_MMU ≡ 0 | MMU module not triggered | +| | | | | +|-------+---------+------------------------------------+--------------------------------| +| i + 2 | CONTEXT | executionProvidesEmptyReturnData() | +|-------+---------+------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/halt/revert/lua/unexceptional.lua.tex b/hub/instruction_handling/halt/revert/lua/unexceptional.lua.tex new file mode 100644 index 0000000..2a55c2d --- /dev/null +++ b/hub/instruction_handling/halt/revert/lua/unexceptional.lua.tex @@ -0,0 +1,73 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ RawFeature={fallback=emojifallback} ] + +\begin{document} +\begin{verbatim} + + ███████\ ████████\ ██\ ██\ ████████\ ███████\ ████████\ + ██ __██\ ██ _____|██ | ██ |██ _____|██ __██\\__██ __| + ██ | ██ |██ | ██ | ██ |██ | ██ | ██ | ██ | + ███████ |█████\ \██\ ██ |█████\ ███████ | ██ | + ██ __██< ██ __| \██\██ / ██ __| ██ __██< ██ | + ██ | ██ |██ | \███ / ██ | ██ | ██ | ██ | + ██ | ██ |████████\ \█ / ████████\ ██ | ██ | ██ | + \__| \__|\________| \_/ \________|\__| \__| \__| + + + + | _) | + | | __ \ _ \ \ \ / __| _ \ __ \ __| | _ \ __ \ _` | | + | | | | __/ ` < ( __/ | | | | ( | | | ( | | + \__,_| _| _| \___| _/\_\ \___| \___| .__/ \__| _| \___/ _| _| \__,_| _| + _| + + +|-------+---------+--------------------------------------------+---------------------------------------------| +| Row | Persp. | Action | Comments | +|-------+---------+--------------------------------------------+---------------------------------------------| +| i | STACK | ⇒ offset, size | | +|-------+---------+--------------------------------------------+---------------------------------------------| +| i + 1 | MISC | | | +| | | MXP module: | MXP module is always triggered | +| | | =========== | | +| | | | | +| | | . ⇒ MXP/MXPX | | +| | | . ⇒ MXP/MXP_GAS | | +| | | | | +| | | MMU module: | MMU module triggered ⇔ trigger_MMU = true | +| | | =========== | | +| | | | | +| | | trigger_MMU ≡ [XAHOY ≡ false] | | +| | | . ∧ [context/IS_ROOT ≡ false] | | +| | | . ∧ [context/r@c ≠ 0] | | +| | | . ∧ [size ≠ 0] | | +| | | | | +|-------+---------+--------------------------------------------+---------------------------------------------| +| i + 2 | CONTEXT | readContextData( current_context ) | +| | | | +| | | ⇒ context/IS_ROOT | +| | | ⇒ context/r@o | +| | | ⇒ context/r@c | +|-------+---------+--------------------------------------------| +| i + 3 | CONTEXT | | +| | | If [context/IS_ROOT ≡ true] | +| | | . readContextData() | +| | | | +| | | If [context/IS_ROOT ≡ false] | +| | | . executionProvidesReturnData() | +| | | . (caller context ⇐ return data) | +|-------+---------+--------------------------------------------| + +\end{verbatim} +\end{document} diff --git a/hub/instruction_handling/halt/revert/representation.tex b/hub/instruction_handling/halt/revert/representation.tex new file mode 100644 index 0000000..83df1a4 --- /dev/null +++ b/hub/instruction_handling/halt/revert/representation.tex @@ -0,0 +1,9 @@ +% \begin{figure}[!ht] +% \centering +% \includegraphics[width=\textwidth]{instruction_handling/halt/flowcharts/revert.png} +% \caption{General workflow for \inst{REVERT} instructions.} +% \label{fig: hub: halt: revert processing} +% \end{figure} + +\includepdf[fitpaper=true, pages={1}]{instruction_handling/halt/revert/lua/unexceptional.pdf} +\includepdf[fitpaper=true, pages={1}]{instruction_handling/halt/revert/lua/exceptional.pdf} diff --git a/hub/instruction_handling/halt/revert/shorthands.tex b/hub/instruction_handling/halt/revert/shorthands.tex new file mode 100644 index 0000000..8669a0a --- /dev/null +++ b/hub/instruction_handling/halt/revert/shorthands.tex @@ -0,0 +1,19 @@ +We introduce some shorthands that will be used within the instruction processing of \inst{REVERT}'s. +\[ + \left\{ \begin{array}{lcl} + \locInst & \define & \stackInst_{i} \\ + \locOffsetHi & \define & \stackItemValHi{1}_{i} \\ + \locOffsetLo & \define & \stackItemValLo{1}_{i} \\ + \locSizeHi & \define & \stackItemValHi{2}_{i} \\ + \locSizeLo & \define & \stackItemValLo{2}_{i} \\ + \end{array} \right. + \text{ and } + \left\{ \begin{array}{lcl} + \locCurrentContext & \define & \cn _{i} \\ + \locCallerContext & \define & \caller _{i} \\ + \locMxpGas & \define & \miscMxpGasMxp _{i + \locRevertMiscRowOffset} \\ + \locRao & \define & \cnRao _{i + \locRevertCurrentContextRowOffset} \\ + \locRac & \define & \cnRac _{i + \locRevertCurrentContextRowOffset} \\ + \locCurrentContextIsRoot & \define & \cnIsRootContext _{i + \locRevertCurrentContextRowOffset} \\ + \end{array} \right. +\] diff --git a/hub/instruction_handling/halt/selfdestruct/_inputs.tex b/hub/instruction_handling/halt/selfdestruct/_inputs.tex new file mode 100644 index 0000000..6520dee --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/_inputs.tex @@ -0,0 +1,8 @@ +\input{instruction_handling/halt/selfdestruct/_local} +\subsubsubsection{Introduction} \label{hub: instruction handling: halt: selfdestruct: intro} \input{instruction_handling/halt/selfdestruct/intro} +\subsubsubsection{Representation} \label{hub: instruction handling: halt: selfdestruct: representation} \input{instruction_handling/halt/selfdestruct/representation} +\subsubsubsection{Scenario \lispDone{}} \label{hub: instruction handling: halt: selfdestruct: scenario} \input{instruction_handling/halt/selfdestruct/scenario} +\subsubsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: halt: selfdestruct: shorthands} \input{instruction_handling/halt/selfdestruct/shorthands} +\subsubsubsection{Constraints \lispDone{}} \label{hub: instruction handling: halt: selfdestruct: constraints} \input{instruction_handling/halt/selfdestruct/constraints} +\subsubsubsection{Undoing rows for \scenSelfdestructWillRevert{} \lispDone{}} \label{hub: instruction handling: halt: selfdestruct: will revert} \input{instruction_handling/halt/selfdestruct/will_revert} +\subsubsubsection{Account deletion rows for \scenSelfdestructWontRevertNotYetMarked{} \lispDone{}} \label{hub: instruction handling: halt: selfdestruct: not yet marked} \input{instruction_handling/halt/selfdestruct/wont_revert_not_yet_marked} diff --git a/hub/instruction_handling/halt/selfdestruct/_local.tex b/hub/instruction_handling/halt/selfdestruct/_local.tex new file mode 100644 index 0000000..d5dd3e4 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/_local.tex @@ -0,0 +1,22 @@ +\def\locRawRecipientAddressHi {\col{raw\_recipient\_addr\_hi}} +\def\locRawRecipientAddressLo {\col{raw\_recipient\_addr\_lo}} +\def\locIsStatic {\col{is\_static}} +\def\locIsDeployment {\col{is\_deployment}} +\def\locAccountAddressHi {\col{account\_addr\_hi}} +\def\locAccountAddressLo {\col{account\_addr\_lo}} +\def\locAccountAddress {\col{account\_addr}} +\def\locAccountBalance {\col{account\_balance}} +\def\locAccountIsMarked {\col{account\_is\_marked}} +\def\locRecipientAddressHi {\col{recipient\_addr\_hi}} +\def\locRecipientAddressLo {\col{recipient\_addr\_lo}} +\def\locRecipientAddress {\col{recipient\_addr}} +\def\locRecipientTrimFlag {\col{recipient\_trm\_flag}} +\def\locFirstContextRow {\yellowm{1}} +\def\locFirstAccountRow {\yellowm{2}} +\def\locSecondAccountRow {\yellowm{3}} +\def\locFirstAccountUndoingRow {\orangem{4}} +\def\locSecondAccountUndoingRow {\orangem{5}} +\def\locSelfdestructAccountRow {\redm{4}} +\def\locRecipientWarmth {\col{recipient\_warmth}} +\def\locRecipientExists {\col{recipient\_exists}} + diff --git a/hub/instruction_handling/halt/selfdestruct/constraints.tex b/hub/instruction_handling/halt/selfdestruct/constraints.tex new file mode 100644 index 0000000..3041030 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/constraints.tex @@ -0,0 +1,324 @@ +\begin{center} + \boxed{% + \text{The constraints below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenSelfdestructSum _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +The present section deals with handling \inst{SELFDESTRUCT} instructions. +Note that by definition, see section~(\ref{hub: scenarios: shorthands: selfdestruct}), precisely one of the following scenarios is active: +\begin{multicols}{2} + \begin{enumerate} + \item \scenSelfdestructException + \item \scenSelfdestructWillRevert + \item \scenSelfdestructWontRevertAlreadyMarked + \item \scenSelfdestructWontRevertNotYetMarked + \end{enumerate} +\end{multicols} +\noindent We now proceed with the constraints +\begin{description} + \item[\underline{Looking back:}] + we impose the following + \[ + \left\{ \begin{array}{lclr} + \peekStack _{i - 1} & = & 1 \\ + \stackInst _{i - 1} & = & \inst{SELFDESTRUCT} \\ + \xAhoy _{i} & = & \stackStaticx_{i - 1} + \stackOogx_{i - 1} & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting the stack pattern:}] + we impose $\oneZeroSP_{i - 1}$; + \item[\underline{Setting the refund:}] we impose that + \[ + \refund\new_{i} = \refund_{i} + R_\text{selfdestruct} \cdot \scenSelfdestructWontRevertNotYetMarked_{i} + \] + \saNote{} Recall that $R_\text{selfdestruct} = 24,000$. + \item[\underline{Setting the \inst{SELFDESTRUCT} scenario:}] + we impose that + \begin{enumerate} + \item $\scenSelfdestructException _{i} = \xAhoy_{i}$ + \item \If $\xAhoy_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \scenSelfdestructWillRevert_{i} & = & \cnWillRev_{i} \\ + \scenSelfdestructWontRevert_{i} & = & 1 - \cnWillRev_{i} \\ + \end{array} \right. + \] + \item \If $\cnWillRev_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \scenSelfdestructWontRevert _{i} & = & \rOne \\ + \scenSelfdestructWontRevertAlreadyMarked _{i} & = & \locAccountIsMarked \\ + \scenSelfdestructWontRevertNotYetMarked _{i} & = & 1 - \locAccountIsMarked \\ + \end{array} \right. + \] + \saNote{} We will later impose that $\stackStaticx_{i - 1} = 0$ \Then $\peekAccount_{i + \locFirstAccountRow} \equiv 1$. + As a consequence the definition of \locAccountIsMarked{} makes sense since + $\cnWillRev_{i} \equiv 0$ implies $\xAhoy_{i} \equiv 0$ and thus $\stackStaticx_{i - 1} = 0$. + \end{enumerate} + \item[\underline{Setting $\nonStackRows$ and peeking flags:}] we impose that + \begin{enumerate} + \item \If $\stackStaticx_{i - 1} = 1$ \Then + \[ + \nonStackRows_{i - 1} = 3 + \quad\text{and}\quad + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekContext _{i + \locFirstContextRow} \\ + + & \peekContext _{i + 2} \\ + \end{array} \right] + = \nonStackRows_{i - 1} + \] + \item \If $\stackOogx_{i - 1} = 1$ \Then + \[ + \nonStackRows_{i - 1} = 5 + \quad\text{and}\quad + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekContext _{i + \locFirstContextRow} \\ + + & \peekAccount _{i + \locFirstAccountRow} + \peekAccount _{i + \locSecondAccountRow} \\ + + & \peekContext _{i + 4} \\ + \end{array} \right] + = \nonStackRows_{i - 1} + \] + \item \If $\scenSelfdestructWillRevert_{i} = 1$ \Then + \[ + \nonStackRows_{i - 1} = 7 + \quad\text{and}\quad + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekContext _{i + \locFirstContextRow} \\ + + & \peekAccount _{i + \locFirstAccountRow} + \peekAccount _{i + \locSecondAccountRow} \\ + + & \peekAccount _{i + \locFirstAccountUndoingRow} + \peekAccount _{i + \locSecondAccountUndoingRow} \\ + + & \peekContext _{i + 6} \\ + \end{array} \right] + = \nonStackRows_{i - 1} + \] + \item \If $\scenSelfdestructWontRevertAlreadyMarked_{i} = 1$ \Then + \[ + \nonStackRows_{i - 1} = 5 + \quad\text{and}\quad + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekContext _{i + \locFirstContextRow} \\ + + & \peekAccount _{i + \locFirstAccountRow} + \peekAccount _{i + \locSecondAccountRow} \\ + + & \peekContext _{i + 4} \\ + \end{array} \right] + = \nonStackRows_{i - 1} + \] + \item \If $\scenSelfdestructWontRevertNotYetMarked_{i} = 1$ \Then + \[ + \nonStackRows_{i - 1} = 6 + \quad\text{and}\quad + \left[ \begin{array}{cl} + + & \peekScenario _{i } \\ + + & \peekContext _{i + \locFirstContextRow} \\ + + & \peekAccount _{i + \locFirstAccountRow} + \peekAccount _{i + \locSecondAccountRow} \\ + + & \peekAccount _{i + \locSelfdestructAccountRow} \\ + + & \peekContext _{i + 5} \\ + \end{array} \right] + = \nonStackRows_{i - 1} + \] + \end{enumerate} + \saNote{} For instructions raising the \haltFlag{} it holds that $\cmc \equiv 1$, see section~\ref{hub: generalities: execution context may change flag}. + + \saNote{} In all cases $\peekContext _{i + \locFirstContextRow} = 1$. + \item[\underline{Reading context data:}] + we impose $\readContextData {i}{\locFirstContextRow}{\cn_{i}}$. + \item[\underline{Returning empty return data:}] + we impose + \begin{enumerate} + \item \If $\stackStaticx_{i - 1} = 1$ \Then \[ \executionProvidesEmptyReturnData {i}{2} \] + \item \If $\stackOogx_{i - 1} = 1$ \Then \[ \executionProvidesEmptyReturnData {i}{4} \] + \item \If $\scenSelfdestructWillRevert_{i} = 1$ \Then \[ \executionProvidesEmptyReturnData {i}{6} \] + \item \If $\scenSelfdestructWontRevertAlreadyMarked_{i} = 1$ \Then \[ \executionProvidesEmptyReturnData {i}{4} \] + \item \If $\scenSelfdestructWontRevertNotYetMarked_{i} = 1$ \Then \[ \executionProvidesEmptyReturnData {i}{5} \] + \end{enumerate} + \item[\underline{Justifying the static exception:}] + we impose $\stackStaticx_{i - 1} = \locIsStatic$ + \item[\underline{Justifying the gas cost:}] + \If $\stackStaticx_{i - 1} = 0$ \Then we impose + \begin{enumerate} + \item \If $\locBalance = 0$ \Then + \[ + \gasCost_{i} = + \left[ \begin{array}{crcl} + + & & \!\!\! \!\!\! & G_\text{selfdestruct} \\ + + & (1 - \locRecipientWarmth) & \!\!\! \cdot \!\!\! & G_\text{coldaccountaccess} \\ + \end{array} \right] + \] + \item \If $\locBalance \neq 0$ \Then + \[ + \gasCost_{i} = + \left[ \begin{array}{crcl} + + & & \!\!\! \!\!\! & G_\text{selfdestruct} \\ + + & (1 - \locRecipientWarmth) & \!\!\! \cdot \!\!\! & G_\text{coldaccountaccess} \\ + + & (1 - \locRecipientExists) & \!\!\! \cdot \!\!\! & G_\text{newaccount} \\ + \end{array} \right] + \] + \end{enumerate} + \item[\underline{Generalities about the first acount row:}] + the first account row peeks into the account which is currently accessible i.e. with address $I_\text{a}$, using \cite{EYP} notations i.e. the account which stands to \inst{SELFDESTRUCT}; + this account will be accessed in all cases except for that of a \staticxSH{}. + + \If $\stackStaticx_{i - 1} = 0$ \Then we impose + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + \locFirstAccountRow} & = & \nothing \\ + \accTrmFlag _{i + \locFirstAccountRow} & = & \nothing \\ + \accAddressHi _{i + \locFirstAccountRow} & = & \locAccountAddressHi \\ + \accAddressLo _{i + \locFirstAccountRow} & = & \locAccountAddressLo \\ + \multicolumn{3}{l}{\texttt{Balance: } \valueToBeSet} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\texttt{Code: } \valueToBeSet} \\ + \multicolumn{3}{l}{\texttt{Deployment: } \valueToBeSet} \\ + % \multicolumn{3}{l}{\accSameCode {i}{\locFirstAccountRow}} \\ + % \multicolumn{3}{l}{\accSameDeployment {i}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\texttt{Marked for selfdestruct: } \valueToBeSet} \vspace {2mm} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locFirstAccountRow, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locFirstAccountRow}{0} } \\ + \end{array} \right. + \] + \saNote{} We must still specify the intende updates to balance, code, deployment and selfdestruct marking. + \item[\underline{Setting code and deployment of the first account row:}] + \If $\stackStaticx_{i - 1} = 0$ \Then + we impose the following for code and deployment: + \begin{enumerate} + \item \If $\xAhoy_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \accSameCode {i}{\locFirstAccountRow} \\ + \accSameDeployment {i}{\locFirstAccountRow} \\ + \end{array} \right. + \] + \saNote{} The update to the code and deployment status is done by the \inst{CREATE}-type instruction; + \item \If $\xAhoy_{i} = 0$ \et $\locIsDeployment = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accSameCode {i}{\locFirstAccountRow} \\ + \accSameDeployment {i}{\locFirstAccountRow} \\ + \end{array} \right. + \] + \item \If $\xAhoy_{i} = 0$ \et $\locIsDeployment = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \accCodesize \new _{i + \locFirstAccountRow} & = & 0 \\ + \accCodehashHi \new _{i + \locFirstAccountRow} & = & \emptyKeccakHi \\ + \accCodehashLo \new _{i + \locFirstAccountRow} & = & \emptyKeccakLo \\ + \accDepStatus _{i + \locFirstAccountRow} & = & 1 & (\trash) \\ + \accDepStatus \new _{i + \locFirstAccountRow} & = & 0 \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\locFirstAccountRow}} \\ + \end{array} \right. + \] + \end{enumerate} + \saNote{} An unexceptional \inst{SELFDESTRUCT} carried out in a deployment context leads to the deployment of empty byte code at the current address (i.e. at $I_\text{a}$.) + \item[\underline{Setting balance and selfdestruct marking of the first account row:}] + \If $\stackStaticx_{i - 1} = 0$ \Then + we impose the following for code and deployment: + \begin{enumerate} + \item \If $\stackOogx_{i - 1} = 1$ \Then we impose + \[ + \left\{ \begin{array}{l} + \accSameBalance {i}{\locFirstAccountRow} \\ + \accSameMarkedForSelfdestructFlag {i}{\locFirstAccountRow} \\ + \end{array} \right. + \] + \item \If $\scenSelfdestructUnexceptional_{i} = 1$ \Then we impose + \[ + \accDecrementBalance {i}{\locFirstAccountRow}{\locBalance} + \] + \item \If $\scenSelfdestructWillRevert _{i} = 1$ \Then we impose + \[ + \left\{ \begin{array}{lr} + \accDecrementBalance {i}{\locFirstAccountRow}{\locBalance} & (\trash) \\ + \accSameMarkedForSelfdestructFlag {i}{\locFirstAccountRow} \\ + \end{array} \right. + \] + \item \If $\scenSelfdestructWontRevertAlreadyMarked _{i} = 1$ \Then we impose + \[ + \left\{ \begin{array}{lr} + \accDecrementBalance {i}{\locFirstAccountRow}{\locBalance} & (\trash) \\ + \accSameMarkedForSelfdestructFlag {i}{\locFirstAccountRow} \\ + \end{array} \right. + \] + \item \If $\scenSelfdestructWontRevertNotYetMarked _{i} = 1$ \Then we impose + \[ + \left\{ \begin{array}{lr} + \accDecrementBalance {i}{\locFirstAccountRow}{\locBalance} & (\trash) \\ + \accTurnOnMarkedForSelfdestructFlag {i}{\locFirstAccountRow} \\ + \end{array} \right. + \] + \end{enumerate} + \item[\underline{Generalities about the second account row:}] + the second account row peeks into the recipient account; + the reference provided to said account is a stack argument and must thus be trimmed of its leading bytes; + again, this account will be accessed in all cases except for that of a \staticxSH{}. + + \If $\stackStaticx_{i - 1} = 0$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + \locSecondAccountRow} & = & \nothing \\ + \multicolumn{3}{l}{\accTrimAddress + {i}{\locSecondAccountRow} + {\locRawRecipientAddressHi} + {\locRawRecipientAddressLo}} \\ + \multicolumn{3}{l}{\texttt{Balance: }\valueToBeSet} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\texttt{Warmth: }\valueToBeSet} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locSecondAccountRow}} \vspace{2mm} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locSecondAccountRow, + domOffset = 1, + } + } \\ + % \standardDomSubStamps {i}{\locSecondAccountRow}{1}} \\ + \end{array} \right. + \] + \item[\underline{Balance and warmth constraints for the second account row:}] + the previous constraints left balance and warmth updates unconstrained; + we impose that + \begin{enumerate} + \item \If $\stackOogx_{i - 1} = 1$ \Then we impose + \[ + \left\{ \begin{array}{l} + \accSameBalance {i}{\locSecondAccountRow} \\ + \accSameWarmth {i}{\locSecondAccountRow} \\ + \end{array} \right. + \] + \item \If $\scenSelfdestructUnexceptional_{i} = 1$ \Then we impose + \[ + \accTurnOnWarmth {i}{\locSecondAccountRow} + \] + \begin{enumerate} + \item \If $\locAccountAddress = \locRecipientAddress$ \Then + \[ + \left\{ \begin{array}{lclr} + \accBalance _{i + \locSecondAccountRow} & = & 0 & (\trash) \\ + \multicolumn{3}{l}{ \accSameBalance {i}{\locSecondAccountRow}} \\ + \end{array} \right. + \] + \item \If $\locAccountAddress \neq \locRecipientAddress$ \Then + \[ + \accIncrementBalance {i}{\locSecondAccountRow}{\locBalance} \\ + \] + \end{enumerate} + \end{enumerate} + \saNote{} Both conditions ``$\stackOogx_{i - 1} = 1$'' and ``$\scenSelfdestructUnexceptional_{i} = 1$'' imply that ``$\stackStaticx_{i - 1} = 0$''. +\end{description} +At this stage what remains to be done is deal with the remaining account rows in the following cases +\begin{itemize} + \item \scenSelfdestructWillRevert{} + \item \scenSelfdestructWontRevertNotYetMarked{} +\end{itemize} diff --git a/hub/instruction_handling/halt/selfdestruct/intro.tex b/hub/instruction_handling/halt/selfdestruct/intro.tex new file mode 100644 index 0000000..ce30266 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/intro.tex @@ -0,0 +1,13 @@ +We deal in this section with the instruction handling of the \inst{SELFDESTRUCT} instruction. +This instruction is relatively complex, in particular when it comes to pricing, refunds and rollbacks. +Thus there are three scenarios for \inst{SELFDESTRUCT} instructions: +\begin{enumerate} + \item the instruction \textbf{raises an exception}\footnote{either a \suxSH{}, a \staticxSH{} or an \oogxSH{}} + \item the instruction is \textbf{unexceptional} but the current execution context \textbf{will be reverted} + \item the instruction is \textbf{unexceptional}, the current execution context \textbf{won't be reverted} and + \begin{enumerate} + \item the current account is already marked for selfdestruct\footnote{i.e. $\accMarkedForSelfdestruct \equiv 1$} + \item the current account isn't yet marked for selfdestruct\footnote{i.e. $\accMarkedForSelfdestruct \equiv 0$} + \end{enumerate} +\end{enumerate} +Thus when processing a \inst{SELFDESTRUCT} instruction we require access to the account address, the datum of whether or not it is currently under deployment or not, and if it is under deployment, we require access to the account \emph{proper}. diff --git a/hub/instruction_handling/halt/selfdestruct/lua/oogx.lua.tex b/hub/instruction_handling/halt/selfdestruct/lua/oogx.lua.tex new file mode 100644 index 0000000..90b4094 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/lua/oogx.lua.tex @@ -0,0 +1,86 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██████\ ████████\ ██\ ████████\ ███████\ ████████\ ██████\ ████████\ ███████\ ██\ ██\ ██████\ ████████\ + ██ __██\ ██ _____|██ | ██ _____|██ __██\ ██ _____|██ __██\\__██ __|██ __██\ ██ | ██ |██ __██\\__██ __| + ██ / \__|██ | ██ | ██ | ██ | ██ |██ | ██ / \__| ██ | ██ | ██ |██ | ██ |██ / \__| ██ | + \██████\ █████\ ██ | █████\ ██ | ██ |█████\ \██████\ ██ | ███████ |██ | ██ |██ | ██ | + \____██\ ██ __| ██ | ██ __| ██ | ██ |██ __| \____██\ ██ | ██ __██< ██ | ██ |██ | ██ | + ██\ ██ |██ | ██ | ██ | ██ | ██ |██ | ██\ ██ | ██ | ██ | ██ |██ | ██ |██ | ██\ ██ | + \██████ |████████\ ████████\ ██ | ███████ |████████\ \██████ | ██ | ██ | ██ |\██████ |\██████ | ██ | + \______/ \________|\________|\__| \_______/ \________| \______/ \__| \__| \__| \______/ \______/ \__| + + + | _| + _ \ | | __| _ \ | _` | _` | __| + ( | | | | ( | __| ( | ( | \__ \ + \___/ \__,_| \__| \___/ _| \__, | \__,_| ____/ + |___/ + +| HUB_STAMP | REFUND | REFUND_NEW | row | persp. | actions | DOM_STAMP | SUB_STAMP | +|:---------:+:------:+:----------:+:-----:+:------:+:-------------------------------------------------+:----------:+:---------:| +| h - 1 | | | | | | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| h | r | r' ← r | i - 1 | STACK | | ∅ | ∅ | +| | | | | | ⇒ raw_recipient_address | | | +| | | | | | • stack/STATICX = 0 ⟦ π ⟧ | | | +| | | | | | • stack/OOGX = 1 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| " | " | " | i | SCN | | ∅ | ∅ | +| | | | | | • scen/SELFDESTRUCT_EXCEPTION = 1 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| " | " | " | i + 1 | CON | | ∅ | ∅ | +| | | | | | • readContextData() | | | +| | | | | | . • account_address ← context/ACCOUNT_ADDRESS | | | +| | | | | | . • is_static ← context/IS_STATIC | | | +| | | | | | . ∴ is_static = 0 | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| " | " | " | i + 2 | ACC | | τ • h + 0 | 0 | +| | | | | | • account/ADDRESS = account_address | | | +| | | | | | • [2]accSameNonce | | | +| | | | | | • [2]accSameBalance | | | +| | | | | | • [2]sameWarmth | | | +| | | | | | • [2]sameNonce | | | +| | | | | | • [2]sameCode | | | +| | | | | | • [2]accSameDeployment | | | +| | | | | | • [2]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| " | " | " | i + 3 | ACC | | τ • h + 1 | 0 | +| | | | | | • account/TRIM_FLAG = 1 | | | +| | | | | | • account/ADDRESS = recipient_address | | | +| | | | | | • [3]accSameNonce | | | +| | | | | | • [3]accSameBalance | | | +| | | | | | • [3]sameWarmth | | | +| | | | | | • [3]sameNonce | | | +| | | | | | • [3]sameCode | | | +| | | | | | • [3]accSameDeployment | | | +| | | | | | • [3]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| " | " | " | i + 4 | CON | | ∅ | ∅ | +| | | | | | ∙ executionProvidesEmptyReturnData() | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +|-----------+--------+------------+-------+--------+--------------------------------------------------+------------+-----------| +| h + 1 | | | | | | | | +| | | | | | | | | +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/halt/selfdestruct/lua/staticx.lua.tex b/hub/instruction_handling/halt/selfdestruct/lua/staticx.lua.tex new file mode 100644 index 0000000..bbe79fc --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/lua/staticx.lua.tex @@ -0,0 +1,62 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██████\ ████████\ ██\ ████████\ ███████\ ████████\ ██████\ ████████\ ███████\ ██\ ██\ ██████\ ████████\ + ██ __██\ ██ _____|██ | ██ _____|██ __██\ ██ _____|██ __██\\__██ __|██ __██\ ██ | ██ |██ __██\\__██ __| + ██ / \__|██ | ██ | ██ | ██ | ██ |██ | ██ / \__| ██ | ██ | ██ |██ | ██ |██ / \__| ██ | + \██████\ █████\ ██ | █████\ ██ | ██ |█████\ \██████\ ██ | ███████ |██ | ██ |██ | ██ | + \____██\ ██ __| ██ | ██ __| ██ | ██ |██ __| \____██\ ██ | ██ __██< ██ | ██ |██ | ██ | + ██\ ██ |██ | ██ | ██ | ██ | ██ |██ | ██\ ██ | ██ | ██ | ██ |██ | ██ |██ | ██\ ██ | + \██████ |████████\ ████████\ ██ | ███████ |████████\ \██████ | ██ | ██ | ██ |\██████ |\██████ | ██ | + \______/ \________|\________|\__| \_______/ \________| \______/ \__| \__| \__| \______/ \______/ \__| + + | | _) + __| __| _` | __| | __| \ \ / + \__ \ | ( | | | ( ` < + ____/ \__| \__,_| \__| _| \___| _/\_\ + + +| HUB_STAMP | REFUND | REFUND_NEW | row | persp. | actions | DOM_STAMP | SUB_STAMP | +|:---------:+:------:+:----------:+:-----:+:------:+:-------------------------------------------------+:---------:+:---------:| +| h - 1 | | | | | | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +| h | r | r' ← r | i - 1 | STACK | | ∅ | ∅ | +| | | | | | → raw_recipient_address | | | +| | | | | | • stack/STATICX = 1 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +| " | " | " | i | SCN | | ∅ | ∅ | +| | | | | | • scen/SELFDESTRUCT_EXCEPTION = 1 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +| " | " | " | i + 1 | CON | | ∅ | ∅ | +| | | | | | • readContextData() | | | +| | | | | | . • account_address ← context/ACCOUNT_ADDRESS | | | +| | | | | | . • is_static ← context/IS_STATIC | | | +| | | | | | . ∴ is_static = 1 | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +| " | " | " | i + 2 | CON | | ∅ | ∅ | +| | | | | | ∙ executionProvidesEmptyReturnData() | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +|-----------+--------+------------+-------+--------+--------------------------------------------------+-----------+-----------| +| h + 1 | | | | | | | | +| | | | | | | | | +\end{verbatim} +\end{document} + diff --git a/hub/instruction_handling/halt/selfdestruct/lua/will_revert.lua.tex b/hub/instruction_handling/halt/selfdestruct/lua/will_revert.lua.tex new file mode 100644 index 0000000..d7f2be2 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/lua/will_revert.lua.tex @@ -0,0 +1,108 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██████\ ████████\ ██\ ████████\ ███████\ ████████\ ██████\ ████████\ ███████\ ██\ ██\ ██████\ ████████\ + ██ __██\ ██ _____|██ | ██ _____|██ __██\ ██ _____|██ __██\\__██ __|██ __██\ ██ | ██ |██ __██\\__██ __| + ██ / \__|██ | ██ | ██ | ██ | ██ |██ | ██ / \__| ██ | ██ | ██ |██ | ██ |██ / \__| ██ | + \██████\ █████\ ██ | █████\ ██ | ██ |█████\ \██████\ ██ | ███████ |██ | ██ |██ | ██ | + \____██\ ██ __| ██ | ██ __| ██ | ██ |██ __| \____██\ ██ | ██ __██< ██ | ██ |██ | ██ | + ██\ ██ |██ | ██ | ██ | ██ | ██ |██ | ██\ ██ | ██ | ██ | ██ |██ | ██ |██ | ██\ ██ | + \██████ |████████\ ████████\ ██ | ███████ |████████\ \██████ | ██ | ██ | ██ |\██████ |\██████ | ██ | + \______/ \________|\________|\__| \_______/ \________| \______/ \__| \__| \__| \______/ \______/ \__| + + _) | | | + \ \ \ / | | | __| _ \ \ \ / _ \ __| __| + \ \ \ / | | | | __/ \ \ / __/ | | + \_/\_/ _| _| _| _| \___| \_/ \___| _| \__| + + +| HUB_STAMP | REFUND | REFUND_NEW | row | persp. | actions | DOM_STAMP | SUB_STAMP | +|:---------:+:------:+:----------:+:-----:+:------:+:-------------------------------------------------+:-------------:+:----------:| +| h - 1 | | | | | | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| h | r | r' ← r | i - 1 | STACK | | ∅ | ∅ | +| | | | | | ⇒ raw_recipient_address | | | +| | | | | | • stack/STATICX = 0 ⟦ π ⟧ | | | +| | | | | | • stack/OOGX = 0 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i | SCN | | ∅ | ∅ | +| | | | | | • scen/SELFDESTRUCT_WILL_REVERT = 1 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i + 1 | CON | | ∅ | ∅ | +| | | | | | • readContextData() | | | +| | | | | | . • account_address ← context/ACCOUNT_ADDRESS | | | +| | | | | | . • is_static ← context/IS_STATIC | | | +| | | | | | . ∴ is_static = 0 | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i + 2 | ACC | | τ • h + 0 | 0 | +| | | | | | • acc/ADDRESS = account_address | | | +| | | | | | • bal ← acc/BALANCE | | | +| | | | | | • [2]decrementBalance(bal) | | | +| | | | | | • [2]accSameWarmth | | | +| | | | | | • [2]accSameNonce | | | +| | | | | | • [2]accSameCode (or empty deployment) | | | +| | | | | | • [2]accSameDeployment (or empty deployment) | | | +| | | | | | • [2]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i + 3 | ACC | | τ • h + 1 | 0 | +| | | | | | • acc/TRM_FLAG = 1 | | | +| | | | | | • acc/ADDRESS = trm_recipient_address | | | +| | | | | | • recipient_address ← acc/ADDRESS | | | +| | | | | | • recipient_address == account_address ? | | | +| | | | | | . • true: [3]accSameBalance() | | | +| | | | | | . • false: [3]accIncrementBalance(bal) | | | +| | | | | | • [3]accTurnOnWarmth | | | +| | | | | | • [3]accSameNonce | | | +| | | | | | • [3]accSameCode | | | +| | | | | | • [3]accSameDeployment | | | +| | | | | | • [3]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i + 4 | ACC | | τ • ρ + ε_rev | τ • h + 2 | +| | | | | | • acc/ADDRESS = account_address | | | +| | | | | | • [4,2]accUndoBalanceUpdate | | | +| | | | | | • [4,2]accUndoWarmthUpdate | | | +| | | | | | • [4,2]accUndoNonceUpdate | | | +| | | | | | • [4,2]accUndoCodeUpdate | | | +| | | | | | • [4,2]accUndoDeploymentUpdate | | | +| | | | | | • [4]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i + 5 | ACC | | τ • ρ + ε_rev | τ • h + 3 | +| | | | | | • acc/TRM_FLAG = 0 | | | +| | | | | | • acc/ADDRESS = trm_recipient_address | | | +| | | | | | • [5,3]accUndoBalanceUpdate | | | +| | | | | | • [5,3]accUndoWarmthUpdate | | | +| | | | | | • [5,3]accUndoNonceUpdate | | | +| | | | | | • [5,3]accUndoCodeUpdate | | | +| | | | | | • [5,3]accUndoDeploymentUpdate | | | +| | | | | | • [5]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| " | " | " | i + 6 | CON | | ∅ | ∅ | +| | | | | | ∙ executionProvidesEmptyReturnData() | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +|-----------+--------+------------+-------+--------+--------------------------------------------------+---------------+------------| +| h + 1 | | | | | | | | +| | | | | | | | | + +NOTE. In the above ρ = CON_REV_STAMP +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/halt/selfdestruct/lua/wont_revert_already_marked.lua.tex b/hub/instruction_handling/halt/selfdestruct/lua/wont_revert_already_marked.lua.tex new file mode 100644 index 0000000..2aef2a2 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/lua/wont_revert_already_marked.lua.tex @@ -0,0 +1,86 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██████\ ████████\ ██\ ████████\ ███████\ ████████\ ██████\ ████████\ ███████\ ██\ ██\ ██████\ ████████\ + ██ __██\ ██ _____|██ | ██ _____|██ __██\ ██ _____|██ __██\\__██ __|██ __██\ ██ | ██ |██ __██\\__██ __| + ██ / \__|██ | ██ | ██ | ██ | ██ |██ | ██ / \__| ██ | ██ | ██ |██ | ██ |██ / \__| ██ | + \██████\ █████\ ██ | █████\ ██ | ██ |█████\ \██████\ ██ | ███████ |██ | ██ |██ | ██ | + \____██\ ██ __| ██ | ██ __| ██ | ██ |██ __| \____██\ ██ | ██ __██< ██ | ██ |██ | ██ | + ██\ ██ |██ | ██ | ██ | ██ | ██ |██ | ██\ ██ | ██ | ██ | ██ |██ | ██ |██ | ██\ ██ | + \██████ |████████\ ████████\ ██ | ███████ |████████\ \██████ | ██ | ██ | ██ |\██████ |\██████ | ██ | + \______/ \________|\________|\__| \_______/ \________| \______/ \__| \__| \__| \______/ \______/ \__| + + | | | | + _` | | __| _ \ _` | _` | | | __ `__ \ _` | __| | / _ \ _` | + ( | | | __/ ( | ( | | | | | | ( | | < __/ ( | + \__,_| _| _| \___| \__,_| \__,_| \__, | _| _| _| \__,_| _| _|\_\ \___| \__,_| + ____/ + + +| HUB_STAMP | REFUND | REFUND_NEW | row | persp. | actions | DOM_STAMP | SUB_STAMP | +|:---------:+:------:+:----------:+:-----:+:------:+:-------------------------------------------------------------+:----------:+:---------:| +| h - 1 | | | | | | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| h | r | r' ← r | i - 1 | STACK | | ∅ | ∅ | +| | | | | | ⇒ raw_recipient_address | | | +| | | | | | • stack/STATICX = 0 ⟦ π ⟧ | | | +| | | | | | • stack/OOGX = 0 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| " | " | " | i | SCN | | ∅ | ∅ | +| | | | | | • scen/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED = 1 ⟦ π ⟧ | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| " | " | " | i + 1 | CON | | ∅ | ∅ | +| | | | | | • readContextData() | | | +| | | | | | . • account_address ← context/ACCOUNT_ADDRESS | | | +| | | | | | . • is_static ← context/IS_STATIC | | | +| | | | | | . ∴ is_static = 0 | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| " | " | " | i + 2 | ACC | | τ • h + 0 | 0 | +| | | | | | • account/ADDRESS = account_address | | | +| | | | | | • account/MARKED_FOR_SELFDESTRUCT = 1 | | | +| | | | | | • bal ← acc/BALANCE | | | +| | | | | | • [2]decrementBalance(bal) | | | +| | | | | | • [2]accSameWarmth | | | +| | | | | | • [2]accSameNonce | | | +| | | | | | • [2]accSameCode (or empty deployment) | | | +| | | | | | • [2]accSameDeployment (or empty deployment) | | | +| | | | | | • [2]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| " | " | " | i + 3 | ACC | | τ • h + 1 | 0 | +| | | | | | • recipient_address ← acc/ADDRESS | | | +| | | | | | • recipient_address == account_address ? | | | +| | | | | | . • true: [3]accSameBalance() | | | +| | | | | | . • false: [3]accIncrementBalance(bal) | | | +| | | | | | • [3]accTurnOnWarmth | | | +| | | | | | • [3]accSameNonce | | | +| | | | | | • [3]accSameCode | | | +| | | | | | • [3]accSameDeployment | | | +| | | | | | • [3]accSameMarkForSelfdestruct | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| " | " | " | i + 4 | CON | | ∅ | ∅ | +| | | | | | ∙ executionProvidesEmptyReturnData() | | | +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +|-----------+--------+------------+-------+--------+--------------------------------------------------------------+------------+-----------| +| h + 1 | | | | | | | | +| | | | | | | | | +\end{verbatim} +\end{document} + diff --git a/hub/instruction_handling/halt/selfdestruct/lua/wont_revert_not_yet_marked.lua.tex b/hub/instruction_handling/halt/selfdestruct/lua/wont_revert_not_yet_marked.lua.tex new file mode 100644 index 0000000..df27afa --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/lua/wont_revert_not_yet_marked.lua.tex @@ -0,0 +1,101 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██████\ ████████\ ██\ ████████\ ███████\ ████████\ ██████\ ████████\ ███████\ ██\ ██\ ██████\ ████████\ + ██ __██\ ██ _____|██ | ██ _____|██ __██\ ██ _____|██ __██\\__██ __|██ __██\ ██ | ██ |██ __██\\__██ __| + ██ / \__|██ | ██ | ██ | ██ | ██ |██ | ██ / \__| ██ | ██ | ██ |██ | ██ |██ / \__| ██ | + \██████\ █████\ ██ | █████\ ██ | ██ |█████\ \██████\ ██ | ███████ |██ | ██ |██ | ██ | + \____██\ ██ __| ██ | ██ __| ██ | ██ |██ __| \____██\ ██ | ██ __██< ██ | ██ |██ | ██ | + ██\ ██ |██ | ██ | ██ | ██ | ██ |██ | ██\ ██ | ██ | ██ | ██ |██ | ██ |██ | ██\ ██ | + \██████ |████████\ ████████\ ██ | ███████ |████████\ \██████ | ██ | ██ | ██ |\██████ |\██████ | ██ | + \______/ \________|\________|\__| \_______/ \________| \______/ \__| \__| \__| \______/ \______/ \__| + + | | | | + __ \ _ \ __| | | _ \ __| __ `__ \ _` | __| | / _ \ _` | + | | ( | | | | __/ | | | | ( | | < __/ ( | + _| _| \___/ \__| \__, | \___| \__| _| _| _| \__,_| _| _|\_\ \___| \__,_| + ____/ + + +| HUB_STAMP | REFUND | REFUND_NEW | row | persp. | actions | DOM_STAMP | SUB_STAMP | +|:---------:+:------:+:------------------------:+:-----:+:------:+:--------------------------------------------------------------+:------------:+:---------:| +| h - 1 | | | | | | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| h | r | r' ← r + R_selfdestruct | i - 1 | STACK | | ∅ | ∅ | +| | | | | | → raw_recipient_address | | | +| | | | | | • stack/STATICX = 0 ⟦ π ⟧ | | | +| | | | | | • stack/OOGX = 0 ⟦ π ⟧ | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| " | " | " | i | SCN | | ∅ | ∅ | +| | | | | | • scen/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED = 1 ⟦ π ⟧ | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| " | " | " | i + 1 | CON | | ∅ | ∅ | +| | | | | | • readContextData() | | | +| | | | | | . • account_address ← context/ACCOUNT_ADDRESS | | | +| | | | | | . • is_static ← context/IS_STATIC | | | +| | | | | | . ∴ is_static = 0 | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| " | " | " | i + 2 | ACC | | τ • h + 0 | 0 | +| | | | | | • account/ADDRESS = account_address | | | +| | | | | | • account/MARKED_FOR_SELFDESTRUCT = 0 | | | +| | | | | | • bal ← acc/BALANCE | | | +| | | | | | • [2]decrementBalance(bal) | | | +| | | | | | • [2]accSameWarmth | | | +| | | | | | • [2]accSameNonce | | | +| | | | | | • [2]accSameCode (or empty deployment) | | | +| | | | | | • [2]accSameDeployment (or empty deployment) | | | +| | | | | | • [2]accMarkForSelfdestruct | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| " | " | " | i + 3 | ACC | | τ • h + 1 | 0 | +| | | | | | • recipient_address ← acc/ADDRESS | | | +| | | | | | • recipient_address == account_address ? | | | +| | | | | | . • true: [3]accSameBalance() | | | +| | | | | | . • false: [3]accIncrementBalance(bal) | | | +| | | | | | • [3]accTurnOnWarmth | | | +| | | | | | • [3]accSameNonce | | | +| | | | | | • [3]accSameCode | | | +| | | | | | • [3]accSameDeployment | | | +| | | | | | • [3]accSameMarkForSelfdestruct | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| " | " | " | i + 4 | ACC | | τ • ζ + ε_sd | τ • h | +| | | | | | • account/ADDRESS = account_address | | | +| | | | | | | | | +| | | | | | Delete account from state: | | | +| | | | | | . + account/BALANCE_NEW = 0 | | | +| | | | | | . + account/NONCE_NEW = 0 | | | +| | | | | | . + account/CODE_SIZE_NEW = 0 | | | +| | | | | | . + account/CODE_HASH_NEW = KECCAK(∅) | | | +| | | | | | . + account/DEPLOYMENT_NUMBER += 1 | | | +| | | | | | . + account/DEPLOYMENT_STATUS = 0 | | | +| | | | | | • [4]accSameMarkForSelfdestruct | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| " | " | " | i + 5 | CON | | ∅ | ∅ | +| | | | | | ∙ executionProvidesEmptyReturnData() | | | +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +|-----------+--------+--------------------------+-------+--------+---------------------------------------------------------------+--------------+-----------| +| h + 1 | | | | | | | | +| | | | | | | | | + +NOTE. In the above ζ = TX_END_STAMP. +\end{verbatim} +\end{document} + + diff --git a/hub/instruction_handling/halt/selfdestruct/representation.tex b/hub/instruction_handling/halt/selfdestruct/representation.tex new file mode 100644 index 0000000..df63252 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/representation.tex @@ -0,0 +1,9 @@ +% \begin{figure} +% \includegraphics[width = \textwidth]{instruction_handling/halt/flowcharts/selfdestruct.png} +% \caption{Flowcharts for the \inst{SELFDESTRUCT} opcode.} +% \end{figure} +\includepdf[fitpaper=true]{instruction_handling/halt/selfdestruct/lua/staticx.pdf} +\includepdf[fitpaper=true]{instruction_handling/halt/selfdestruct/lua/oogx.pdf} +\includepdf[fitpaper=true]{instruction_handling/halt/selfdestruct/lua/will_revert.pdf} +\includepdf[fitpaper=true]{instruction_handling/halt/selfdestruct/lua/wont_revert_already_marked.pdf} +\includepdf[fitpaper=true]{instruction_handling/halt/selfdestruct/lua/wont_revert_not_yet_marked.pdf} diff --git a/hub/instruction_handling/halt/selfdestruct/scenario.tex b/hub/instruction_handling/halt/selfdestruct/scenario.tex new file mode 100644 index 0000000..e2527ba --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/scenario.tex @@ -0,0 +1,21 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & \!\!\! = \!\!\! & 1 \\ + \stackDecHaltFlag _{i} & \!\!\! = \!\!\! & 1 \\ + \decFlag {4} _{i} & \!\!\! = \!\!\! & 1 \\ + \stackSux_{i} + \stackSox_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right.} +\end{center} +We set the scenario row: +\begin{description} + \item[\underline{Setting the \inst{SELFDESTRUCT} scenario:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \peekScenario _{i + 1} & = & 1 \\ + \scenSelfdestructSum _{i + 1} & = & 1 \\ + \end{array} \right. + \] +\end{description} diff --git a/hub/instruction_handling/halt/selfdestruct/shorthands.tex b/hub/instruction_handling/halt/selfdestruct/shorthands.tex new file mode 100644 index 0000000..3c346dd --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/shorthands.tex @@ -0,0 +1,36 @@ +\begin{center} + \boxed{% + \text{The index $i$ used in the shorthands below is one such that} + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenSelfdestructSum _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +We define several shorthands: +\[ + \left\{ \begin{array}{lcl} + \locRawRecipientAddressHi & \define & \stackItemValHi {1} _{i - 1} \\ + \locRawRecipientAddressLo & \define & \stackItemValLo {1} _{i - 1} \vspace{2mm} \\ + \locIsStatic & \define & \cnStatic _{i + \locFirstContextRow} \\ + \locIsDeployment & \define & \cnCodeDepStatus _{i + \locFirstContextRow} \\ + \locAccountAddressHi & \define & \cnAccountAddress\high _{i + \locFirstContextRow} \\ + \locAccountAddressLo & \define & \cnAccountAddress\low _{i + \locFirstContextRow} \\ + \locAccountAddress & \define & 256^\llarge \cdot \locAccountAddressHi + \locAccountAddressLo \vspace{2mm} \\ + \locAccountBalance & \define & \accBalance _{i + \locFirstAccountRow} \\ + \locAccountIsMarked & \define & \accMarkedForSelfdestruct _{i + \locFirstAccountRow} \vspace{2mm} \\ + \locRecipientAddressHi & \define & \accAddressHi _{i + \locSecondAccountRow} \\ + \locRecipientAddressLo & \define & \accAddressLo _{i + \locSecondAccountRow} \\ + \locRecipientAddress & \define & 256^\llarge \cdot \locRecipientAddressHi + \locRecipientAddressLo \\ + \locRecipientTrimFlag & \define & \accTrmFlag _{i + \locSecondAccountRow} \\ + \locRecipientExists & \define & \accExists _{i + \locSecondAccountRow} \\ + \locRecipientWarmth & \define & \accWarmth _{i + \locSecondAccountRow} \\ + % \loc & \define & \\ + % \loc & \define & \\ + % \locFirstContextRow + % \locFirstAccountRow + % \locSecondAccountRow + % \locSelfdestructAccountRow + % \locFirstAccountUndoingRow + % \locSecondAccountUndoingRow + \end{array} \right. +\] diff --git a/hub/instruction_handling/halt/selfdestruct/will_revert.tex b/hub/instruction_handling/halt/selfdestruct/will_revert.tex new file mode 100644 index 0000000..60f59a1 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/will_revert.tex @@ -0,0 +1,55 @@ +\begin{center} + \boxed{% + \text{The constraints below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenSelfdestructWillRevert _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +We impose the following +\begin{description} + \item[\underline{Undoing account updates:}] + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + \locFirstAccountUndoingRow} & = & \nothing \\ + \accTrmFlag _{i + \locFirstAccountUndoingRow} & = & \nothing \\ + \multicolumn{3}{l}{\accSameAddr {i}{\locFirstAccountUndoingRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\locFirstAccountUndoingRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\locFirstAccountUndoingRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\locFirstAccountUndoingRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\locFirstAccountUndoingRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\locFirstAccountUndoingRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locFirstAccountUndoingRow}} \vspace{2mm} \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locFirstAccountUndoingRow, + subOffset = 2, + } + } \\ + % \revertDomSubStamps {i}{\locFirstAccountUndoingRow}{2}} \\ + \end{array} \right. + \] + \item[\underline{Undoing account updates:}] + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + \locSecondAccountUndoingRow} & = & \nothing \\ + \accTrmFlag _{i + \locSecondAccountUndoingRow} & = & \nothing \\ + \multicolumn{3}{l}{\accSameAddr {i}{\locSecondAccountUndoingRow}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\locSecondAccountUndoingRow}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\locSecondAccountUndoingRow}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\locSecondAccountUndoingRow}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\locSecondAccountUndoingRow}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\locSecondAccountUndoingRow}{\locSecondAccountRow}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locSecondAccountUndoingRow}} \vspace{2mm} \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locSecondAccountUndoingRow, + subOffset = 3, + } + } \\ + % \revertDomSubStamps {i}{\locSecondAccountUndoingRow}{3}} \\ + \end{array} \right. + \] +\end{description} diff --git a/hub/instruction_handling/halt/selfdestruct/wont_revert_not_yet_marked.tex b/hub/instruction_handling/halt/selfdestruct/wont_revert_not_yet_marked.tex new file mode 100644 index 0000000..8967b45 --- /dev/null +++ b/hub/instruction_handling/halt/selfdestruct/wont_revert_not_yet_marked.tex @@ -0,0 +1,30 @@ +\begin{center} + \boxed{% + \text{The constraints below assume } + \left\{ \begin{array}{lcl} + \peekScenario _{i} & = & 1 \\ + \scenSelfdestructWontRevertNotYetMarked _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +We impose the following where the current accout (with address $I_\text{a}$) is destroyed: +\begin{description} + \item[\underline{Account destruction:}] + we impose that + \[ + \left\{ \begin{array}{lcl} + \accRomLexFlag _{i + \locSelfdestructAccountRow} & = & \nothing \\ + \accTrmFlag _{i + \locSelfdestructAccountRow} & = & \nothing \\ + \multicolumn{3}{l}{\accSameAddr {i}{\locSelfdestructAccountRow}{\locFirstAccountRow}} \\ + \accBalance \new _{i + \locSelfdestructAccountRow} & = & 0 \\ + \accNonce \new _{i + \locSelfdestructAccountRow} & = & 0 \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locSelfdestructAccountRow}} \\ + \accCodesize\new _{i + \locSelfdestructAccountRow} & = & 0 \\ + \accCodehashHi \new _{i + \locSelfdestructAccountRow} & = & \emptyKeccakHi \\ + \accCodehashLo \new _{i + \locSelfdestructAccountRow} & = & \emptyKeccakLo \\ + \accDepNumber \new _{i + \locSelfdestructAccountRow} & = & 1 + \accDepNumber _{i + \locSelfdestructAccountRow} \\ + \accDepStatus \new _{i + \locSelfdestructAccountRow} & = & 0 \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locSelfdestructAccountRow}} \vspace{2mm} \\ + \multicolumn{3}{l}{\selfdestructDomSubStamps {i}{\locSelfdestructAccountRow}} \\ + \end{array} \right. + \] +\end{description} diff --git a/hub/instruction_handling/halt/stop/_inputs.tex b/hub/instruction_handling/halt/stop/_inputs.tex new file mode 100644 index 0000000..14cc27f --- /dev/null +++ b/hub/instruction_handling/halt/stop/_inputs.tex @@ -0,0 +1,5 @@ +\input{instruction_handling/halt/stop/_local} +\subsubsubsection{Introduction} \label{hub: instruction handling: halt: stop: intro} \input{instruction_handling/halt/stop/intro} +\subsubsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: halt: stop: shorthands} \input{instruction_handling/halt/stop/shorthands} \newpage +\subsubsubsection{Representation} \label{hub: instruction handling: halt: stop: representation} \input{instruction_handling/halt/stop/representation} \newpage +\subsubsubsection{Constraints \lispDone{}} \label{hub: instruction handling: halt: stop: constraints} \input{instruction_handling/halt/stop/constraints} \newpage diff --git a/hub/instruction_handling/halt/stop/_local.tex b/hub/instruction_handling/halt/stop/_local.tex new file mode 100644 index 0000000..45a15a0 --- /dev/null +++ b/hub/instruction_handling/halt/stop/_local.tex @@ -0,0 +1,6 @@ +\def\locDeploys {\col{deploys}} +\def\locWillRevert {\col{will\_revert}} +\def\locAddressHi {\col{address\_hi}} +\def\locAddressLo {\col{address\_lo}} +\def\locFirstAccountRow {\yellowm{2}} +\def\locSecondAccountRow {\yellowm{3}} diff --git a/hub/instruction_handling/halt/stop/constraints.tex b/hub/instruction_handling/halt/stop/constraints.tex new file mode 100644 index 0000000..afd5ada --- /dev/null +++ b/hub/instruction_handling/halt/stop/constraints.tex @@ -0,0 +1,118 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & \!\!\! = \!\!\! & 1 \\ + \stackDecHaltFlag_{i} & \!\!\! = \!\!\! & 1 \\ + \decFlag{3}_{i} & \!\!\! = \!\!\! & 1 \\ + \end{array} \right.} +\end{center} +\saNote{} \inst{STOP} can provoke neither \suxSH{}'s nor \soxSH{}'s. +There is therefore no point in filtering out by the usual precondition +$\stackSux_{i} + \stackSox_{i} \neq 1$. + +The present section deals with handling \inst{STOP} instructions. +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose $\zeroZeroSP_{i}$; + \item[\underline{Setting the gas cost:}] we impose $\gasCost_{i} = \staticGas_{i} ~ (=0)$; + \inst{STOP} instructions don't consume any gas; + \item[\underline{Setting \xAhoy:}] we impose $\xAhoy_{i} = 0$; +\end{description} +\saNote{} Echoing the previous point, \inst{STOP} instructions can't produce \textbf{any exception at all}. +\begin{description} + \item[\underline{The first non stack row:}] we impose + \[ + \begin{cases} + \peekContext _{i + 1} = 1 \\ + \readContextData {i}{1}{\cn_{i}} \\ + \end{cases} + \] + \saNote{} We isolate this constraint for readability. It justifies several of the shorthands introduced in section~(\ref{hub: instruction handling: halt: stop: shorthands}). + \item[\underline{Setting $\nonStackRows$ and peeking flags:}] we impose the following + \begin{enumerate} + \item \If $\locDeploys = 0$ \Then $\nonStackRows_{i} = 2$ and + \[ + \left[ \begin{array}{r} + + \peekContext_{i + 1} \\ + + \peekContext_{i + 2} \\ + \end{array} \right] + = \nonStackRows_{i} + \quad\text{and}\quad + \executionProvidesEmptyReturnData {i}{2} \quad(\trash) + \] + \item \If $\locDeploys = 1$ \Then + \begin{enumerate} + \item \If $\locWillRevert = 0$ \Then $\nonStackRows_{i} = 3$; + \[ + \left[ \begin{array}{r} + + \peekContext_{i + 1} \\ + + \peekAccount_{i + \locFirstAccountRow} \\ + + \peekContext_{i + 3} \\ + \end{array} \right] + = \nonStackRows_{i} + \quad\text{and}\quad + \executionProvidesEmptyReturnData {i}{3} \quad(\trash) + \] + \item \If $\locWillRevert = 1$ \Then $\nonStackRows_{i} = 4$; + \[ + \left[ \begin{array}{r} + + \peekContext_{i + 1} \\ + + \peekAccount_{i + \locFirstAccountRow} \\ + + \peekAccount_{i + \locSecondAccountRow} \\ + + \peekContext_{i + 4} \\ + \end{array} \right] + = \nonStackRows_{i} + \quad\text{and}\quad + \executionProvidesEmptyReturnData {i}{4} \quad(\trash) + \] + \end{enumerate} + \end{enumerate} + \saNote{} The above boils down to $\nonStackRows_{i} = 2 + \locDeploys \cdot (1 + \locWillRevert)$. + \item[\underline{Account row $n^°(i + \locFirstAccountRow)$:}] we impose \If $\locDeploys = 1$ \Then we impose + \[ + \left\{ \begin{array}{lcl} + \accTrmFlag _{i + \locFirstAccountRow} & = & \gZero \\ + \accRomLexFlag _{i + \locFirstAccountRow} & = & \gZero \vspace{2mm} \\ + \accAddressHi _{i + \locFirstAccountRow} & = & \locAddressHi \\ + \accAddressLo _{i + \locFirstAccountRow} & = & \locAddressLo \vspace{2mm} \\ + \multicolumn{3}{l}{\accSameBalance {i}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locFirstAccountRow}} \\ + \accCodesize \new _{i + \locFirstAccountRow} & = & 0 \\ + \accCodehashHi \new _{i + \locFirstAccountRow} & = & \emptyKeccakHi \\ + \accCodehashLo \new _{i + \locFirstAccountRow} & = & \emptyKeccakLo \\ + \multicolumn{3}{l}{\accSameDeploymentNumber {i}{\locFirstAccountRow} } \\ + \accDepStatus _{i + \locFirstAccountRow} & = & 1 \\ + \accDepStatus\new _{i + \locFirstAccountRow} & = & 0 \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locFirstAccountRow, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locFirstAccountRow}{0} } \\ + \end{array} \right. + \] + \item[\underline{Account row $n^°(i + \locFirstAccountRow)$:}] we impose \If $\locDeploys = 1$ \et $\locWillRevert = 1$ \Then we impose + \[ + \left\{ \begin{array}{lcl} + \accTrmFlag _{i + \locSecondAccountRow} & = & \gZero \\ + \accRomLexFlag _{i + \locSecondAccountRow} & = & \gZero \vspace{2mm} \\ + \multicolumn{3}{l}{\accSameAddr {i}{\locSecondAccountRow}{\locFirstAccountRow}} \vspace{2mm} \\ + \multicolumn{3}{l}{\accUndoBalanceUpdate {i}{\locSecondAccountRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoNonceUpdate {i}{\locSecondAccountRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoWarmthUpdate {i}{\locSecondAccountRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoCodeUpdate {i}{\locSecondAccountRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{\accUndoDeploymentStatusAndNumberUpdate {i}{\locSecondAccountRow}{\locFirstAccountRow}} \\ + \multicolumn{3}{l}{ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locSecondAccountRow, + subOffset = 1, + } + } \\ + % {i}{\locSecondAccountRow}{1}} \\ + \end{array} \right. + \] +\end{description} diff --git a/hub/instruction_handling/halt/stop/intro.tex b/hub/instruction_handling/halt/stop/intro.tex new file mode 100644 index 0000000..0b5245d --- /dev/null +++ b/hub/instruction_handling/halt/stop/intro.tex @@ -0,0 +1,10 @@ +We deal in this section with the instruction handling of the \inst{STOP} instruction. This instruction is in many ways straightforward: no exceptions are possible, it has constant gas cost (equal to 0.) The complexity that this instruction exhibits is fully concentrated in its interaction with deployments and rollbacks. Thus there are three scenarios for \inst{STOP} instructions: +\begin{enumerate} + \item the current execution context \textbf{isn't} a deployment context; + \item the current execution context \textbf{is} a deployment context and + \begin{enumerate} + \item \inst{STOP} triggers a deployment (with empty bytecode) which \textbf{will} be reverted by a parent context reverting + \item \inst{STOP} triggers a deployment (with empty bytecode) which \textbf{won't} be reverted by a parent context reverting. + \end{enumerate} +\end{enumerate} +Thus when processing a \inst{STOP} instruction we require access to the account address, the datum of whether or not it is currently under deployment or not, and if it is under deployment, we require access to the account \emph{proper}. diff --git a/hub/instruction_handling/halt/stop/representation.tex b/hub/instruction_handling/halt/stop/representation.tex new file mode 100644 index 0000000..442e47d --- /dev/null +++ b/hub/instruction_handling/halt/stop/representation.tex @@ -0,0 +1,6 @@ +\begin{figure}[!ht] +\centering +\includegraphics[width=\textwidth]{instruction_handling/halt/flowcharts/stop.png} + \caption{General workflow for \inst{STOP} instructions.} +\label{fig: hub: halt: stop processing} +\end{figure} diff --git a/hub/instruction_handling/halt/stop/shorthands.tex b/hub/instruction_handling/halt/stop/shorthands.tex new file mode 100644 index 0000000..d5c7ff0 --- /dev/null +++ b/hub/instruction_handling/halt/stop/shorthands.tex @@ -0,0 +1,9 @@ +We introduce some shorthands that will be used within the instruction processing of \inst{STOP}'s. +\[ + \left\{ \begin{array}{lcl} + \locWillRevert & \longleftrightarrow & \cnWillRev _{i } \\ + \locDeploys & \longleftrightarrow & \cnCodeDepStatus _{i + 1} \\ + \locAddressHi & \longleftrightarrow & \cnCodeAddress\high _{i + 1} \\ + \locAddressLo & \longleftrightarrow & \cnCodeAddress\low _{i + 1} \\ + \end{array} \right. +\] diff --git a/hub/instruction_handling/intro.tex b/hub/instruction_handling/intro.tex new file mode 100644 index 0000000..cf5837e --- /dev/null +++ b/hub/instruction_handling/intro.tex @@ -0,0 +1 @@ +The present section introduces many instruction decoded flags and presents the general classification of instructions into collections of instructions. Tables are incomplete: this is by design: flags that aren't accounted for in a table (group of instructions) must contain only zeros (for all instructions in that group of instructions.) \ No newline at end of file diff --git a/hub/instruction_handling/invalid.tex b/hub/instruction_handling/invalid.tex new file mode 100644 index 0000000..998c70b --- /dev/null +++ b/hub/instruction_handling/invalid.tex @@ -0,0 +1,46 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecInvalidFlag & \decFlag{1} \\ \hline\hline + \inst{notOpCode} & \zero & \oneCell & \zero \\ \hline + \inst{INVALID} & \zero & \oneCell & \oneCell \\ \hline +\end{array} +\] +\dots{} where \inst{notOpCode} stands for any byte that isn't an opcode. + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecInvalidFlag_{i} = 1 \\ + \end{cases}} +\end{center} +\saNote{} +The \inst{INVALID} opcode (and any byte that raises the \invalidFlag{}) can raise neither \suxSH{} nor \soxSH{} exceptions. +Excluding stack exceptions as we do for most other instruction families by filtering agains ``$\stackSux + \stackSox \equiv 0$'' is terefore redundant. +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose $\zeroZeroSP_{i}$ + \item[\underline{Setting $\stackOpcx$:}] we impose $\stackOpcx_{i} = \stackDecInvalidFlag_{i}$; + \item[\underline{Setting $\nonStackRows$:}] we impose $\nonStackRows_{i} = \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] we don't need to set any; + + \saNote{} Implicitly of course $\cmc_{i} \cdot \peekContext_{i + 1} = \cmc_{i}$ (\trash); + \item[\underline{Setting the gas cost:}] we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] implicit in the stack pattern, see section~\ref{hub: stack patterns: 0_0}; %\If $\cmc_{i} = 0$ \Then +\end{description} +\saNote{} For instructions raising the $\invalidFlag$ one has $\cmc \equiv \xAhoy \equiv \stackOpcx \equiv 1$ thus +(\emph{a}) +$\cmc_{i} = \xAhoy_{i} = 1$ +(\emph{b}) +$\nonStackRows_{i} = 1$ +(\emph{c}) +$\peekContext_{i + 1} = 1$. diff --git a/hub/instruction_handling/jump.tex b/hub/instruction_handling/jump.tex new file mode 100644 index 0000000..470ff01 --- /dev/null +++ b/hub/instruction_handling/jump.tex @@ -0,0 +1,252 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\[ +\begin{array}{|l||c||c|c|c|} \hline + \INST & \tli & \stackDecJumpFlag & \decFlag{1} & \decFlag{2} \\ \hline\hline + \inst{JUMP} & \zero & \oneCell & \oneCell & \zero \\ \hline + \inst{JUMPI} & \zero & \oneCell & \zero & \oneCell \\ \hline +\end{array} +\] + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack _{i} = 1 \\ + \stackDecJumpFlag _{i} = 1 \\ + \stackSux _{i} + \stackSox _{i} = 0 \\ + \end{cases}} +\end{center} + +We use the following (more expressive) shorthands: +\[ + \left\{ \begin{array}{lcl} + \locNewPcHi & \define & \stackItemValHi {1} _{i} \\ + \locNewPcLo & \define & \stackItemValLo {1} _{i} \\ + \locJumpConditionHi & \define & \stackItemValHi {2} _{i} \\ + \locJumpConditionLo & \define & \stackItemValLo {2} _{i} \\ + \locIsJump & \define & \decFlag {1} _{i} \\ + \locIsJumpi & \define & \decFlag {2} _{i} \\ + \locByteCodeAddressHi & \define & \cnCodeAddress\high _{i + 1} \\ + \locByteCodeAddressLo & \define & \cnCodeAddress\low _{i + 1} \\ + \locCodeSize & \define & \accCodesize _{i + 2} \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcl} + \locJumpGuaranteedException & \define & \miscOobDataCol {7} _{i + 3} \\ + \locJumpMustBeAttempted & \define & \miscOobDataCol {8} _{i + 3} \vspace{2mm} \\ + \locJumpiNotAttempted & \define & \miscOobDataCol {6} _{i + 3} \\ + \locJumpiGuaranteedException & \define & \miscOobDataCol {7} _{i + 3} \\ + \locJumpiMustBeAttempted & \define & \miscOobDataCol {8} _{i + 3} \\ + \end{array} \right. +\] +\saNote{} +We refer the reader to section~(\ref{fig: oob: jump case interpretation of oob events}) for the interpretation of +$\miscOobDataCol{6}$, +$\miscOobDataCol{7}$ and $\miscOobDataCol{8}$ in the case of \inst{JUMP}-type \oobMod{} module instructions. + +\saNote{} +There is deliberate redundancy in the shorthands pertaining to ``\miscOobDataCol{X}'' columns. + +We now proceed to write down relevant constraints: +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose that + \begin{enumerate} + \item \If $\locIsJump = 1$ \Then $\oneZeroSP_{i}$ + \item \If $\locIsJumpi = 1$ \Then $\twoZeroSP_{i}$ + \end{enumerate} + \item[\underline{Setting allowable exceptions:}] + we impose that $\xAhoy_{i} = \stackOogx_{i} + \stackJumpx_{i}$ ~ (\trash); + \item[\underline{Setting the gas cost:}] + we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Setting $\nonStackRows$:}] + we impose + \begin{enumerate} + \item \If $\stackOogx_{i} = 1$ \Then $\nonStackRows_{i} = \cmc_{i}~(=1)$ + \item \If $\stackOogx_{i} = 0$ \Then $\nonStackRows_{i} = 3 + \cmc_{i}$; + \end{enumerate} + \saNote{} For instructions raising the $\stackDecJumpFlag$ one has $\cmc \equiv \xAhoy$. + \item[\underline{Setting the peeking flags:}] + we impose + \begin{enumerate} + \item \If $\stackOogx_{i} = 1$ \Then $ \peekContext_{i + 1} = \nonStackRows_{i} $ + \item \If $\stackOogx_{i} = 0$ \Then + \[ + \left[ \begin{array}{r} + + \peekContext_{i + 1} \\ + + \peekAccount_{i + 2} \\ + + \peekMisc_{i + 3} \\ + + \cmc_{i} \cdot \peekContext_{i + 4} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \item[\underline{Context-row n$^°(i + 1)$:}] + we impose + \begin{enumerate} + \item \If $\stackOogx_{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{1} $ \quad (\trash); + \item \If $\stackOogx_{i} = 0$ \Then $\readContextData {i}{1}{\cn_{i}}$; + \end{enumerate} +\end{description} +The constraints that follow are written under the following further stronger hypothesis: +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack _{i} & = & 1 \\ + \stackDecJumpFlag _{i} & = & 1 \\ + \stackSux _{i} + \stackSox _{i} & = & 0 \\ + \stackOogx_{i} & = & 0 \\ + \end{array} \right.} +\end{center} +\begin{description} + \item[\underline{Account-row n$^°(i + 2)$:}] + we peek into the account owning the byte code currently executing: + \[ + \left\{ \begin{array}{lcl} + \accAddressHi_{i + 2} = \locByteCodeAddressHi \\ + \accAddressLo_{i + 2} = \locByteCodeAddressLo \\ + \end{array} \right. + \] + we don't impose any modifications: + \[ + \left\{ \begin{array}{lcl} + \accSameBalance {i}{2} \\ + \accSameNonce {i}{2} \\ + \accSameCode {i}{2} \\ + \accSameDeployment {i}{2} \\ + \accSameWarmth {i}{2} \\ + \accSameMarkedForSelfdestructFlag {i}{2} \\ + \standardDomSubStamps { + anchorRow = i, + relOffset = 2, + domOffset = 0, + } + % \standardDomSubStamps {i}{2}{0} \\ + \end{array} \right. + \] + \item[\underline{Miscellaneous-row n$^°(i + 3)$:}] + we make a call to the \oobMod{} module + \[ + \weightedMiscFlagSum {i}{3} + = + \miscOobWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + 3} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + 3} & = & \rZero & (\trash) \\ + \miscMxpFlag _{i + 3} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + 3} & = & \rOne & (\trash) \\ + \miscStpFlag _{i + 3} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Miscellaneous-row n$^°(i + 3)$:}] + we populate the \oobMod{} columns: + \begin{enumerate} + \item \If $\locIsJump = 1$ \Then + \[ + \setOobInstructionJump {i}{3} + \left[ \begin{array}{llr} + \utt{New program counter (high part):} & \locNewPcHi \\ + \utt{New program counter (low part):} & \locNewPcLo \\ + \utt{Code size:} & \locCodeSize \\ + \end{array} \right] \vspace{2mm} \\ + \] + \item \If $\locIsJumpi = 1$ \Then + \[ + \setOobInstructionJumpI {i}{3} + \left[ \begin{array}{llr} + \utt{New program counter (high part):} & \locNewPcHi \\ + \utt{New program counter (low part):} & \locNewPcLo \\ + \utt{Jump condition (high part):} & \locJumpConditionHi \\ + \utt{Jump condition (low part):} & \locJumpConditionLo \\ + \utt{Code size:} & \locCodeSize \\ + \end{array} \right] + \] + \end{enumerate} + % \issue{Make sure the logic is still the same with recent \oobMod{} updates.} + \item[\underline{Setting $\pc\new$ and \stackJumpDestinationVetting{}:}] setting the new program counter depends on the instruction and the presence of a \jumpxSH{}: + \begin{enumerate} + \item \If $\locIsJump = 1$ \Then + \begin{enumerate} + \item \If $\locJumpGuaranteedException = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackJumpDestinationVetting_{i} & = & 0 \\ + \stackJumpx_{i} & = & 1 \\ + \pc\new_{i} & = & \nothing \\ + \end{array} \right. + \] + \item \If $\locJumpMustBeAttempted = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackJumpDestinationVetting_{i} & = & \rOne \\ + \stackJumpx_{i} & = & \relevantValue \\ + \multicolumn{3}{l}{\If \xAhoy_{i} = 0 ~ \Then \pc\new_{i} = \locNewPcLo} \\ + \end{array} \right. + \] + The above implicitly justifies $\stackJumpx_{i}$ through the ``jump destination vetting'' lookup to the \romMod{} module, see section~(\ref{hub: lookups: into rom: jump destination vetting}). + \end{enumerate} + \item \If $\locIsJumpi = 1$ \Then + \begin{enumerate} + \item \If $\locJumpiNotAttempted = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackJumpDestinationVetting_{i} & = & 0 \\ + \stackJumpx_{i} & = & 0 \\ + \pc\new_{i} & = & 1 + \pc_{i} \\ + \end{array} \right. + \] + \item \If $\locJumpiGuaranteedException = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackJumpDestinationVetting_{i} & = & 0 \\ + \stackJumpx_{i} & = & 1 \\ + \pc\new_{i} & = & \nothing \\ + \end{array} \right. + \] + \item \If $\locJumpiMustBeAttempted = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stackJumpDestinationVetting_{i} & = & \rOne \\ + \stackJumpx_{i} & = & \relevantValue \\ + \multicolumn{3}{l}{\If \xAhoy_{i} = 0 ~ \Then \pc\new_{i} = \locNewPcLo} \\ + \end{array} \right. + \] + \saNote{} + Again, the above implicitly justifies $\stackJumpx_{i}$ through the ``jump destination vetting'' lookup to the \romMod{} module, see section~(\ref{hub: lookups: into rom: jump destination vetting}). + % \item \If $\oobDataCol{8}_{i + 3} = 0$ \Then + % \[ + % \left\{ \begin{array}{lcl} + % \stackJumpDestinationVetting_{i} & = & 0 \\ + % \stackJumpx_{i} & = & 0 \\ + % \pc\new_{i} & = & 1 + \pc_{i} \\ + % \end{array} \right. + % \] + % \item \If \Big($\oobDataCol{2}_{i + 3} = 0$ \et $\oobDataCol{7}{1}_{i + 3} = 0$\Big) \Then + % \[ + % \left\{ \begin{array}{lcl} + % \stackJumpDestinationVetting_{i} & = & 1 \\ + % \multicolumn{3}{l}{\If \xAhoy_{i} = 0 ~ \Then \pc\new_{i} = \locNewPcLo} \\ + % \end{array} \right. + % \] + % \item \If $\oobDataCol{7}_{i + 3} = 1$ \Then + % \[ + % \left\{ \begin{array}{lcl} + % \stackJumpx_{i} & = & 1 \\ + % \stackJumpDestinationVetting_{i} & = & 0 \\ + % \end{array} \right. + % \] + \end{enumerate} + \end{enumerate} +\end{description} diff --git a/hub/instruction_handling/kec.tex b/hub/instruction_handling/kec.tex new file mode 100644 index 0000000..7ebe8bf --- /dev/null +++ b/hub/instruction_handling/kec.tex @@ -0,0 +1,222 @@ +\def\locInt {\col{instruction}} +\def\locCallMmu {\col{trigger\_MMU}} +\def\locOffsetHi {\col{offset\_hi}} +\def\locOffsetLo {\col{offset\_lo}} +\def\locSizeHi {\col{size\_hi}} +\def\locSizeLo {\col{size\_lo}} +\def\locKeccakHi {\col{keccak\_hi}} +\def\locKeccakLo {\col{keccak\_lo}} +\def\locMxpx {\col{mxp\_mxpx}} +\def\locMxpGas {\col{mxp\_gas}} +\def\miscRowOffset {\yellowm{1}} +\def\conRowOffset {\orangem{2}} +\subsubsection{Supported instructions and flags} + +\[ +\begin{array}{|l||c||c||c|} + \hline + \INST & \tli & \stackDecKecFlag & \stackDecMxpFlag \\ \hline\hline + \inst{SHA3} & \zero & \oneCell & \oneCell \\ \hline +\end{array} +\] + +\subsubsection{Constraints} + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecKecFlag_{i} = 1 \\ + \stackSux_{i} + \stackSox_{i} = 0 \\ + \end{cases}} +\end{center} +We will use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locOffsetHi & \define & \stackItemValHi {1} _{i} \\ + \locOffsetLo & \define & \stackItemValLo {1} _{i} \\ + \locSizeHi & \define & \stackItemValHi {2} _{i} \\ + \locSizeLo & \define & \stackItemValLo {2} _{i} \\ + \locKeccakHi & \define & \stackItemValHi {4} _{i} \\ + \locKeccakLo & \define & \stackItemValLo {4} _{i} \\ + \locMxpx & \define & \miscMxpMxpx _{i + \miscRowOffset} \\ + \locMxpGas & \define & \miscMxpGasMxp _{i + \miscRowOffset} \\ + \end{array} \right. +\] +The constraints are as follows: +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\twoOneSP_{i}$; + \item[\underline{Setting $\nonStackRows$ and peeking flags:}] + we impose $\nonStackRows_{i} = 1 + \cmc_{i}$. + \item[\underline{Setting the peeking flags:}] + one miscellaneous row is sufficient to deal with \inst{SHA3} instructions: + \[ + \left[ \begin{array}{r} + + \peekMisc _{i + \miscRowOffset} \\ + + \cmc_{i} \cdot \peekContext _{i + \conRowOffset} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item[\underline{Miscellaneous-row $n^°(i + \miscRowOffset)$: flags:}] we impose + \[ + \weightedMiscFlagSum {i}{\miscRowOffset} + = + \left[ \begin{array}{llcl} + + & \miscMmuWeight & \!\!\!\cdot\!\!\! & \locCallMmu \\ + + & \miscMxpWeight \\ + \end{array} \right] + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \miscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \miscRowOffset} & = & \locCallMmu & (\trash) \\ + \miscMxpFlag _{i + \miscRowOffset} & = & \one & (\trash) \\ + \miscOobFlag _{i + \miscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \miscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} The binary flag \locCallMmu{} will be defined below. + \item[\underline{Miscellaneous-row $n^°(i + \miscRowOffset)$: \mxpMod{} data:}] + we deal with the memory expansion cost: + \[ + \setMxpInstructionTypeFour {i}{\miscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \inst{SHA3} \\ + \utt{Deploys byte code:} & 0 \\ + \utt{Offset high part:} & \locOffsetHi \\ + \utt{Offset low part:} & \locOffsetLo \\ + \utt{Size high part:} & \locSizeHi \\ + \utt{Size low part:} & \locSizeLo \\ + \end{array} \right] + \] + % \[ + % \left\{ \begin{array}{lclr} + % \miscMxpFlag _{i + \miscRowOffset} & = & \one & (\trash) \vspace{2mm} \\ + % \miscMxpMxpx _{i + \miscRowOffset} & = & \locMxpx \\ + % \miscMxpInst _{i + \miscRowOffset} & = & \locInst \\ + % \miscMxpCodeDeployment _{i + \miscRowOffset} & = & 0 \\ + % \miscMxpOffsetOneHi _{i + \miscRowOffset} & = & \locOffsetHi \\ + % \miscMxpOffsetOneLo _{i + \miscRowOffset} & = & \locOffsetLo \\ + % \miscMxpSizeOneHi _{i + \miscRowOffset} & = & \locSizeHi \\ + % \miscMxpSizeOneLo _{i + \miscRowOffset} & = & \locSizeLo \\ + % \miscMxpOffsetTwoHi _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMxpOffsetTwoLo _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMxpSizeTwoHi _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMxpSizeTwoLo _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMxpWords _{i + \miscRowOffset} & = & \relevantValue & (\trash) \\ + % \miscMxpGasMxp _{i + \miscRowOffset} & = & \relevantValue \\ + % \end{array} \right. + % \] + \item[\underline{Defining \locCallMmu{}:}] we define it as follows + \[ + \locCallMmu \define + (1 - \xAhoy_{i}) \cdot \miscMxpTypeFourInstMayTriggerMmu_{i + \miscRowOffset} + \] + in other words + \begin{enumerate} + \item \If $\xAhoy_{i} = 1$ \Then $\locCallMmu = 0$ \quad (\trash) + \item \If $\xAhoy_{i} = 0$ \Then + \begin{enumerate} + \item \If $\locSizeLo = 0$ \Then $\locCallMmu = 0$ \quad (\trash) + \item \If $\locSizeLo \neq 0$ \Then $\locCallMmu = 1$ \quad (\trash) + \end{enumerate} + \end{enumerate} + \item[\underline{Miscellaneous-row $n^°(i + \miscRowOffset)$: \mmuMod{} data:}] + \If $\miscMmuFlag_{i + \miscRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i , + relOffset = \miscRowOffset, + sourceId = \cn_{i} , + targetId = \nothing , + auxiliaryId = 1 + \hubStamp_{i} , + % sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \locOffsetLo , + % targetOffsetLo = \col{tgt\_offset\_lo} , + size = \locSizeLo , + % referenceOffset = \col{ref\_offset} , + referenceSize = \locSizeLo , + successBit = \nothing , + % limbOne = \col{limb\_1} , + % limbTwo = \col{limb\_2} , + exoSum = \exoWeightKec , + phase = \nothing , + } + % \setMmuInstructionParametersRamToExoWithPadding {i}{\miscRowOffset} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \cn_{i} \\ + % \utt{Target ID:} & \nothing \\ + % \utt{Auxiliary ID:} & 1 + \hubStamp_{i} \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \locOffsetLo \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \locSizeLo \\ + % % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \locSizeLo \\ + % \utt{Success bit:} & \nothing \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \exoWeightKec \\ + % \utt{Phase:} & \nothing \\ + % \end{array} \right] + \] + % \[ + % \left\{ \begin{array}{lclr} + % \miscMmuFlag _{i + \miscRowOffset} & = & \one & (\trash) \vspace{2mm} \\ + % \miscMmuInst _{i + \miscRowOffset} & = & \locInst \\ + % \miscMmuInstParamOne _{i + \miscRowOffset} & = & \hashInfoStamp_{i} \\ + % \miscMmuInstParamTwo _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % % \miscMmuReturner _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMmuInfo _{i + \miscRowOffset} & = & 0 \\ + % \miscMmuRefOffset _{i + \miscRowOffset} & = & 0 \\ + % \miscMmuRefSize _{i + \miscRowOffset} & = & 0 \\ + % \miscMmuOffsetOneLo _{i + \miscRowOffset} & = & \locOffsetLo \\ + % \miscMmuOffsetTwoHi _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMmuOffsetTwoLo _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMmuSize _{i + \miscRowOffset} & = & \locSizeLo \\ + % \miscMmuStackValHi _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMmuStackValLo _{i + \miscRowOffset} & = & 0 & (\trash) \\ + % \miscMmuExoSum _{i + \miscRowOffset} & = & \ob{TODO!} \\ + % \end{array} \right. + % \] + \saNote{} The current context and caller context (which may own the call data) are provided by the lookup. + + \saNote{} We are providing extra information to the \mmuMod{} in case of a \inst{CALLDATALOAD}: + (\emph{a}) + the knowledge whether the current execution context is the root context + (\emph{b}) + the absolute transaction number. + The purpose of the former is to be able to retrieve the \textbf{transaction call data} whenever we are executing a \inst{CALLDATALOAD} in the root context of a transaction. + \item[\underline{Justifying the \mxpxSH{}:}] + we impose that $\stackMxpx_{i} = \locMxpx$ + \item[\underline{Setting the gas cost:}] + we impose that + \begin{enumerate} + \item \If $\locMxpx = 0$ \Then \( \gasCost_{i} = \decStaticGas_{i} + \locMxpGas \) + \item \If $\locMxpx = 1$ \Then \( \gasCost_{i} = 0 \) + \end{enumerate} + \item[\underline{Constraining \stackHashInfoFlag{}:}] we impose $\stackHashInfoFlag_{i} = \locCallMmu$; + \item[\underline{Value constraints:}] + \If $\xAhoy_{i} = 0$ \et \Then + \begin{enumerate} + \item \If $\locCallMmu = 0$ \Then + \[ + \begin{cases} + \locKeccakHi = \emptyKeccakHi \\ + \locKeccakLo = \emptyKeccakLo \\ + \end{cases} + \] + \item \If $\locCallMmu = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \locKeccakHi & = & \stackHashInfoValHi_{i} \\ + \locKeccakLo & = & \stackHashInfoValLo_{i} \\ + % \locSizeLo & = & \stackHashInfoSize_{i} \\ + \end{array} \right. + \] + \end{enumerate} +\end{description} +\saNote{} For instructions raising the $\stackDecKecFlag$ one has $\cmc \equiv \xAhoy$. diff --git a/hub/instruction_handling/logs/_inputs.tex b/hub/instruction_handling/logs/_inputs.tex new file mode 100644 index 0000000..241039e --- /dev/null +++ b/hub/instruction_handling/logs/_inputs.tex @@ -0,0 +1,5 @@ +\input{instruction_handling/logs/_local} +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: logs: instruction flags} \input{instruction_handling/logs/flags} +\subsubsection{Shorthands \lispDone} \label{hub: instruction handling: logs: shorthands} \input{instruction_handling/logs/shorthands} +\subsubsection{Constraints \lispDone} \label{hub: instruction handling: logs: constraints} \input{instruction_handling/logs/constraints} +% \subsubsection{Graphical representation} \label{hub: instruction handling: logs: representation} \input{instruction_handling/logs/representation} % TODO: representations are out of date diff --git a/hub/instruction_handling/logs/_local.tex b/hub/instruction_handling/logs/_local.tex new file mode 100644 index 0000000..5be772a --- /dev/null +++ b/hub/instruction_handling/logs/_local.tex @@ -0,0 +1,17 @@ +\def\locInst {\col{instruction}} +\def\locTriggerMmu {\col{trigger\_MMU}} +\def\locLogDataSize {\col{log\_data\_size}} +\def\locOffsetHi {\col{offset\_hi}} +\def\locOffsetLo {\col{offset\_lo}} +\def\locSizeHi {\col{size\_hi}} +\def\locSizeLo {\col{size\_lo}} +\def\relevantValue {\texttt{}} +\def\locException {\col{log\_raises\_exception}} +\def\locStaticx {\col{log\_raises\_staticx}} +\def\locMxpx {\col{log\_raises\_mxpx}} +\def\locOogx {\col{log\_raises\_oogx}} +\def\locMxpGas {\col{mxp\_gas}} +\def\locMxpMxpx {\col{mxp\_mxpx}} + +\def\locLogCurrentContextRowOffset {\yellowm{2}} +\def\locLogMiscRowOffset {\yellowm{3}} diff --git a/hub/instruction_handling/logs/constraints.tex b/hub/instruction_handling/logs/constraints.tex new file mode 100644 index 0000000..1703b67 --- /dev/null +++ b/hub/instruction_handling/logs/constraints.tex @@ -0,0 +1,185 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecLogFlag_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \ct_{i} & = & 0 \\ + \end{array} \right. } +\end{center} +\saNote{} \inst{LOG}-type instructions are $\TLI$. We are working relative to the first (instruction processing) row. + +We impose the following constraints: +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose that + \[ + \logSP_{i} + \big[ \INST_{i} - \inst{LOG0}; + \decFlag{1}_{i}, \decFlag{2}_{i}, \decFlag{3}_{i}, \decFlag{4}_{i} \big] + \] + \item[\underline{Allowable exceptions:}] + we impose that + \[ + \xAhoy_{i} = + \left[ \begin{array}{cr} + + & \stackStaticx_{i} \\ + + & \stackMxpx_{i} \\ + + & \stackOogx_{i} \\ + \end{array} \right] + \quad (\trash) + \] + \item[\underline{Setting \nonStackRows:}] + we impose that + \begin{enumerate} + \item \If $\stackStaticx_{i} = 0$ \Then $\nonStackRows _{i} = 2 + \cmc_{i}$ + \item \If $\stackStaticx_{i} = 1$ \Then $\nonStackRows _{i} = 2$ + \end{enumerate} + \item[\underline{Setting the peeking flags:}] + we impose + \begin{enumerate} + \item \If $\stackStaticx_{i} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekContext _{i + \locLogCurrentContextRowOffset} \\ + + & \peekMisc _{i + \locLogMiscRowOffset} \\ + + & \cmc_{i} \cdot \peekContext _{i + 4} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \item \If $\stackStaticx_{i} = 1$ \Then + \[ + \left[ \begin{array}{r} + + \peekContext_{i + \locLogCurrentContextRowOffset} \\ + + \peekContext_{i + 3} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + \saNote{} + In all cases $\peekContext _{i + \locLogCurrentContextRowOffset} \equiv 1$. + This context row will systematically be made to contain the current execution context data. + + \saNote{} + For instructions raising the $\stackDecLogFlag$ one has $\cmc \equiv \xAhoy$. + \item[\underline{Reading the current context data and justifying \staticxSH{}:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\readContextData {i}{\locLogCurrentContextRowOffset}{\cn_{i}}} \\ + \stackStaticx _{i} & = & \cnStatic _{i + \locLogCurrentContextRowOffset} \\ + \end{array} \right. + \] + \item[\underline{The \mxpxSH{} case:}] + \If $\stackStaticx_{i} = 0$ \Then we impose + \[ + \stackMxpx_{i} = \miscMxpMxpx_{i + \locLogMiscRowOffset} + \] + \item[\underline{Setting the gas cost:}] + we impose + \begin{enumerate} + \item \If $\stackStaticx_{i} + \stackMxpx_{i} = 0$ \Then we impose + \[ + \gasCost _{i} = \miscMxpGasMxp_{i + \locLogMiscRowOffset} + \stackStaticGas_{i} + \] + \item \If $\stackStaticx_{i} + \stackMxpx_{i} = 1$ \Then we impose $\gasCost _{i} = 0$ + \end{enumerate} + \saNote{} By construction the sum $\stackStaticx + \stackMxpx$ is binary. + + \saNote{} For \inst{LOG}-type instructions $\stackStaticGas \equiv G_{\text{log}} + (\stackInst - \inst{LOG0}) \cdot G_{\text{logtopic}}$ + where $G_\text{log} = 375$ and $G_\text{logtopic} = 375$. + \item[\underline{The final context-row:}] + we impose + \begin{enumerate} + \item \If $\stackStaticx _{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{3} $ \quad(\trash) + \item \If $\stackMxpx _{i} + \stackOogx _{i} = 1$ \Then $\executionProvidesEmptyReturnData {i}{4} $ \quad(\trash) + \end{enumerate} + \item[\underline{Setting miscellaneous module flags:}] + \If $\stackStaticx_{i} = 0$ \Then + \[ + \weightedMiscFlagSum {i}{\locLogMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \cdot & \locTriggerMmu \\ + + & \miscMxpWeight \\ + \end{array} \right] + \] + In other words we impose + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag_{i + \locLogMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag_{i + \locLogMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag_{i + \locLogMiscRowOffset} & = & \rOne & (\trash) \\ + \miscOobFlag_{i + \locLogMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag_{i + \locLogMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + We further impose the contents of the lookup to the \mxpMod{} module: + + \saNote{} \locTriggerMmu{} will be constrained below. + \item[\underline{Miscellaneous-row $n^°(i + \locLogMiscRowOffset)$: \mxpMod{} data:}] + \If $\stackStaticx_{i} = 0$ \Then + \[ + \setMxpInstructionTypeFour {i}{\locLogMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \locInst \\ + \utt{Deploys byte code:} & \nothing \\ + \utt{Offset high part:} & \locOffsetHi \\ + \utt{Offset low part:} & \locOffsetLo \\ + \utt{Size high part:} & \locSizeHi \\ + \utt{Size low part:} & \locSizeLo \\ + \end{array} \right] + \] + \saNote{} We deal with the memory expansion cost only if \staticxSH{} does not occur. + \item[\underline{Constraining \locTriggerMmu{}:}] + in order to trigger the \mmuMod{} the \inst{LOG}-intruction should + (\emph{a}) raise no exception + (\emph{b}) be executed in a non-reverting context + (\emph{c}) have nonzero size parameter; + since raising an exception prompts the current execution to be rolled-back we only need to care about the context reverting or not; + as such we impose + \begin{enumerate} + \item \If $\cnWillRev_{i} = 1$ \Then $\locTriggerMmu = 0$ + \item \If $\cnWillRev_{i} = 0$ \Then $\locTriggerMmu = \miscMxpTypeFourInstMayTriggerMmu _{i + \locLogMiscRowOffset}$ + \end{enumerate} + \item[\underline{Miscellaneous-row $n^°(i + \locLogMiscRowOffset)$: \mmuMod{} data:}] + \If \Big($\stackStaticx_{i} = 0$ + \et $\miscMmuFlag_{i + \locLogMiscRowOffset} = 1$\Big) \Then + \[ + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i , + relOffset = \locLogMiscRowOffset , + sourceId = \cn_{i} , + targetId = \logStamp_{i} , + auxiliaryId = \nothing , + % sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \locOffsetLo , + % targetOffsetLo = \col{tgt\_offset\_lo} , + size = \locSizeLo , + % referenceOffset = \col{ref\_offset} , + referenceSize = \locSizeLo , + successBit = \nothing , + % limbOne = \col{limb\_1} , + % limbTwo = \col{limb\_2} , + exoSum = \exoWeightLog , + phase = \nothing , + } + % \setMmuInstructionParametersRamToExoWithPadding {i}{\locLogMiscRowOffset} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \cn_{i} \\ + % \utt{Target ID:} & \logStamp_{i} \\ + % \utt{Auxiliary ID:} & \nothing \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \locOffsetLo \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \locSizeLo \\ + % % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \locSizeLo \\ + % \utt{Success bit:} & \nothing \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \exoWeightLog \\ + % \utt{Phase:} & \nothing \\ + % \end{array} \right] + \] +\end{description} diff --git a/hub/instruction_handling/logs/flags.tex b/hub/instruction_handling/logs/flags.tex new file mode 100644 index 0000000..c70d4b6 --- /dev/null +++ b/hub/instruction_handling/logs/flags.tex @@ -0,0 +1,13 @@ +\[ + \hspace*{-2cm} + \begin{array}{|l||c||c|c|c|c|c||c|c|} \hline + \INST & \tli & \stackDecLogFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} & \decStaticInst & \stackDecMxpFlag \\ \hline\hline + \inst{LOG0} & \one & \oneCell & \zero & \zero & \zero & \zero & \oneCell & \oneCell \\ \hline + \inst{LOG1} & \one & \oneCell & \oneCell & \zero & \zero & \zero & \oneCell & \oneCell \\ \hline + \inst{LOG2} & \one & \oneCell & \zero & \oneCell & \zero & \zero & \oneCell & \oneCell \\ \hline + \inst{LOG3} & \one & \oneCell & \zero & \zero & \oneCell & \zero & \oneCell & \oneCell \\ \hline + \inst{LOG4} & \one & \oneCell & \zero & \zero & \zero & \oneCell & \oneCell & \oneCell \\ \hline + \end{array} +\] +We treat \inst{LOG}-type instructions as $\TLI$ regardless of the fact that (strictly speaking) only \inst{LOG3} and \inst{LOG4} require 2 stack rows. +The $\decFlag{1}$, $\decFlag{2}$, $\decFlag{3}$ and $\decFlag{4}$ flags distinguish between the five \inst{LOG}-type instructions. diff --git a/hub/instruction_handling/logs/flowcharts/logs.dot b/hub/instruction_handling/logs/flowcharts/logs.dot new file mode 100644 index 0000000..54d19a7 --- /dev/null +++ b/hub/instruction_handling/logs/flowcharts/logs.dot @@ -0,0 +1,339 @@ +# http://www.graphviz.org/content/cluster + +digraph G { + + node [fontname = "Handlee"]; + node [shape=plaintext]; + edge [fontname = "Handlee"]; + + inst [label=< + + + + +
LOG instructions
>]; + sux [ + label = "\nSUX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + staticx [ + label = "\nSTATICX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + mxpx [ + label = "\nMXPX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + oogx [ + label = "\nOOGX\n "; + shape = diamond; + style = filled; + fillcolor = "ORANGE"; + color = "RED"; + ]; + unexceptional [ + label = "\nNo Exception\n "; + shape = rect; + style = filled; + fillcolor = "LIGHTBLUE"; + color = "green"; + ]; + wont_revert [ + label = "\nWon't revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + will_revert [ + label = "\nWill revert\n "; + shape = diamond; + style = filled; + fillcolor = "LIGHTGREEN"; + color = "green"; + ]; + + { + rank=same; + sux; sux_rows; + } + { + rank=same; + staticx; staticx_rows; + } + { + rank=same; + mxpx; mxpx_rows; + } + { + rank=same; + oogx; oogx_rows; + } + { + rank=same; + will_revert; will_revert_rows; + } + { + rank=same; + wont_revert; wont_revert_rows; + } + + inst -> sux; + sux -> sux_rows; + sux -> staticx; + staticx -> staticx_rows; + staticx -> mxpx; + mxpx -> mxpx_rows; + mxpx -> oogx + oogx -> oogx_rows; + oogx -> unexceptional; + unexceptional -> will_revert; + will_revert -> will_revert_rows; + will_revert -> wont_revert; + wont_revert -> wont_revert_rows; + +sux_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0empty stack items
i + 1STACKCT = 1empty stack items
i + 2Conparentupdate return data:   μo ­  ← ∅
>]; + +staticx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1STACKCT = 1topics
i + 2Concurrentobserve: STATIC🏴 = 1
i + 3Conparentupdate return data:   μo ­  ← ∅
>]; + +mxpx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1STACKCT = 1topics
i + 2MISCMXP🏴 = 1, MXPX = 1
i + 3CONparentupdate return data:   μo ­  ← ∅
>]; + +oogx_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1STACKCT = 1topics
i + 2MISCMXP🏴 = 1, MXPX = 0
i + 3CONparentupdate return data:   μo ­  ← ∅
>]; + +wont_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1STACKCT = 1topics
i + 2MISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = [size ≠ 0];
i + 3CONcurrentobserve: STATIC🏴 = 0, address Ia
>]; + +will_revert_rows [label=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Row indexPerspectiveWhoActionsWhen
DomSub
iSTACKCT = 0offset and size
i + 1STACKCT = 1topics
i + 2MISCMXP🏴 = 1, MXPX = 0;
MMU🏴 = 0;
i + 3CONcurrentobserve: STATIC🏴 = 0, address Ia
>]; + +} + diff --git a/hub/instruction_handling/logs/flowcharts/logs.png b/hub/instruction_handling/logs/flowcharts/logs.png new file mode 100644 index 0000000..d79709d Binary files /dev/null and b/hub/instruction_handling/logs/flowcharts/logs.png differ diff --git a/hub/instruction_handling/logs/flowcharts/logs.svg b/hub/instruction_handling/logs/flowcharts/logs.svg new file mode 100644 index 0000000..ded7449 --- /dev/null +++ b/hub/instruction_handling/logs/flowcharts/logs.svg @@ -0,0 +1,465 @@ + + + + + + +G + + + +inst + +LOG instructions + + + +sux + +SUX + + + + +inst->sux + + + + + +staticx + +STATICX + + + + +sux->staticx + + + + + +sux_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +empty stack items + +i + 1 + +STACK + +CT = 1 + +empty stack items + +i + 2 + +Con + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +sux->sux_rows + + + + + +mxpx + +MXPX + + + + +staticx->mxpx + + + + + +staticx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +STACK + +CT = 1 + +topics + +i + 2 + +Con + + +current + +observe: STATIC🏴 = 1 + +i + 3 + +Con + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +staticx->staticx_rows + + + + + +oogx + +OOGX + + + + +mxpx->oogx + + + + + +mxpx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +STACK + +CT = 1 + +topics + +i + 2 + +MISC + + +MXP🏴 = 1, MXPX = 1 + +i + 3 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +mxpx->mxpx_rows + + + + + +unexceptional + +No Exception + + + + +oogx->unexceptional + + + + + +oogx_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +STACK + +CT = 1 + +topics + +i + 2 + +MISC + + +MXP🏴 = 1, MXPX = 0 + +i + 3 + +CON + + +parent + +update return data:   +μ +o + ­  ← ∅ + + + +oogx->oogx_rows + + + + + +will_revert + +Will revert + + + + +unexceptional->will_revert + + + + + +wont_revert + +Won't revert + + + + +wont_revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +STACK + +CT = 1 + +topics + +i + 2 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = [size ≠ 0]; + +i + 3 + +CON + + +current + +observe: STATIC🏴 = 0, address +I +a + + + +wont_revert->wont_revert_rows + + + + + +will_revert->wont_revert + + + + + +will_revert_rows + +Row index + +Perspective + +Who + +Actions + +When + +Dom + +Sub + +i + +STACK + +CT = 0 + +offset and size + +i + 1 + +STACK + +CT = 1 + +topics + +i + 2 + +MISC + + +MXP🏴 = 1, MXPX = +0 +; + +MMU🏴 = 0; + +i + 3 + +CON + + +current + +observe: STATIC🏴 = 0, address +I +a + + + +will_revert->will_revert_rows + + + + + diff --git a/hub/instruction_handling/logs/representation.tex b/hub/instruction_handling/logs/representation.tex new file mode 100644 index 0000000..0d3c649 --- /dev/null +++ b/hub/instruction_handling/logs/representation.tex @@ -0,0 +1,9 @@ +The following diagram represents the general processing of \inst{LOG}-type instructions. + +\begin{figure}[!h] +\centering +\includegraphics[width=\textwidth]{instruction_handling/logs/flowcharts/logs.png} + \caption{General workflow for \inst{LOG}-type instructions.} +\label{hub: call: fig: general processing} +\end{figure} + diff --git a/hub/instruction_handling/logs/shorthands.tex b/hub/instruction_handling/logs/shorthands.tex new file mode 100644 index 0000000..7018cd6 --- /dev/null +++ b/hub/instruction_handling/logs/shorthands.tex @@ -0,0 +1,15 @@ +We will use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locInst & \define & \stackInst _{i} \\ + \locOffsetHi & \define & \stackItemValHi {1} _{i} \\ + \locOffsetLo & \define & \stackItemValLo {1} _{i} \\ + \locSizeHi & \define & \stackItemValHi {2} _{i} \\ + \locSizeLo & \define & \stackItemValLo {2} _{i} \\ + % \locLogDataSize & \define & \stackItemValLo {2} _{i} \\ + % \locMxpGas & \define & \miscMxpGasMxp _{i + \locLogMiscRowOffset} \\ + % \locMxpMxpx & \define & \miscMxpMxpx _{i + \locLogMiscRowOffset} \\ + % \locTriggerMmu & \define & \miscMmuFlag _{i + 1} \\ + \end{array} \right. +\] +\saNote{} We have two distinct shorthands for $\stackItemValLo{2}_{i}$: this is done on purpose. Semantically we shall not use them equivalently, though they refer to the same underlying data. diff --git a/hub/instruction_handling/machinestate.tex b/hub/instruction_handling/machinestate.tex new file mode 100644 index 0000000..dc8d890 --- /dev/null +++ b/hub/instruction_handling/machinestate.tex @@ -0,0 +1,126 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\[ + \hspace*{-2cm} + \begin{array}{|l||c||c|c|c|c|c||c|} + \hline + \INST & \tli & \stackDecMachineStateFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} & \stackDecMxpFlag \\ \hline\hline + \inst{PC} & \zero & \oneCell & \oneCell & \zero & \zero & \zero & \zero \\ \hline + \inst{MSIZE} & \zero & \oneCell & \zero & \oneCell & \zero & \zero & \oneCell \\ \hline + \inst{GAS} & \zero & \oneCell & \zero & \zero & \oneCell & \zero & \zero \\ \hline + \inst{JUMPDEST} & \zero & \oneCell & \zero & \zero & \zero & \oneCell & \zero \\ \hline + \end{array} +\] + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecMachineStateFlag_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \end{array} \right. } +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose that + \begin{enumerate} + \item \If $\decFlag{4}_{i} = 0$ \Then $\zeroOneSP_{i}$ + \item \If $\decFlag{4}_{i} = 1$ \Then $\zeroZeroSP_{i}$ + \end{enumerate} + Indeed all instructions raising the \machineStateFlag{} are \zeroOneSP{} instructions except for \inst{JUMPDEST} which is a \zeroZeroSP{} instruction. + \item[\underline{Excluding certain exceptions:}] + we impose that $\xAhoy_{i} = \stackOogx_{i}$. + + \saNote{} Without this restriction the \inst{MSIZE} opcode could \emph{a priori} throw a \mxpxSH{}. + Also recall that given the preconditions prefacing this section stack exceptions (that is \soxSH{}'s) have been ruled out. + \item[\underline{Setting $\nonStackRows$:}] we impose $\nonStackRows_{i} = \stackDecMxpFlag_{i} + \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] + we impose + \begin{enumerate} + \item \If $\stackDecMxpFlag_{i} = 0$ \Then $\cmc_{i} \cdot \peekContext_{i + 1} = \nonStackRows_{i}$ + \item \If $\stackDecMxpFlag_{i} = 1$ \Then $\peekMisc_{i + \locMachineStateMiscRow} + \cmc_{i} \cdot \peekContext_{i + 2} = \nonStackRows_{i}$ + \end{enumerate} + \item[\underline{Setting the miscellaneous row for \inst{MSIZE}:}] + \If $\stackDecMxpFlag_{i} = 1$ \Then + \[ + \weightedMiscFlagSum {i}{\locMachineStateMiscRow} + = + \miscMxpWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag_{i + 1} & = & \gZero & (\trash) \\ + \miscMmuFlag_{i + 1} & = & \rZero & (\trash) \\ + \miscMxpFlag_{i + 1} & = & \rOne & (\trash) \\ + \miscOobFlag_{i + 1} & = & \gZero & (\trash) \\ + \miscStpFlag_{i + 1} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + Furthermore + \[ + \setMxpInstructionTypeOne {i}{\locMachineStateMiscRow} + \] + \item[\underline{Setting the gas cost:}] we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] + \If $\xAhoy_{i} = 0$ \Then we impose the following + \begin{enumerate} + \item $\stackItemValHi{4}_{i} = 0$ holds universally; + \item \If $\decFlag{1}_{i} = 1$ \Then $\stackItemValLo{4}_{i} = \pc_{i}$ + + \saNote{} This is the \inst{PC} case; + \item \If $\decFlag{2}_{i} = 1$ \Then $\stackItemValLo{4}_{i} = \miscMxpWords_{i + \locMachineStateMiscRow}$; + + \saNote{} This is the \inst{MSIZE} case; + \item \If $\decFlag{3}_{i} = 1$ \Then $\stackItemValLo{4}_{i} = \gasNext_{i}$; + + \saNote{} This is the \inst{GAS} case; + \end{enumerate} +\end{description} +\saNote{} For instructions raising the $\stackDecPushPopFlag$ one has $\cmc \equiv \xAhoy$. + +% \subsubsection{\inst{MSIZE}-related lookup $\hubMod \hookrightarrow \mxpMod$} +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% +% \begin{description} +% \item[Row selector.] $\col{sel}_{i} := \peekStack_{i} \cdot \stackDecPushPopFlag_{i} \cdot \stackDecMxpFlag_{i}$ +% +% I.e. we select stack rows containing \inst{PUSH} instructions (i.e. $\pushPopFlag = 1$ and $\decFlag{1} = 1$.) +% \item[Source columns.] --- +% \begin{multicols}{4} +% \begin{enumerate} +% \item $\codeAddress\high_{i}$ +% \item $\codeAddress\low_{i}$ +% \item $\codeDepNum_{i}$ +% \item $\codeDepStatus_{i}$ +% \item $\stackItemValHi{4}_{i}$ +% \item $\stackItemValLo{4}_{i}$ +% \item $\pc_{i}$ +% \item[\vspace{\fill}] +% \end{enumerate} +% \end{multicols} +% +% \item[Target columns.] --- +% \begin{multicols}{4} +% \begin{enumerate} +% \item $\addr\high_{j}$ +% \item $\addr\low_{j}$ +% \item $\depNumber_{j}$ +% \item $\depStatus_{j}$ +% \item $\PV\high_{j}$ +% \item $\PV\low_{j}$ +% \item $\pc_{j}$ +% \item[\vspace{\fill}] +% \end{enumerate} +% \end{multicols} +% \end{description} diff --git a/hub/instruction_handling/mod.tex b/hub/instruction_handling/mod.tex new file mode 100644 index 0000000..c731770 --- /dev/null +++ b/hub/instruction_handling/mod.tex @@ -0,0 +1,10 @@ +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecModFlag \\ \hline\hline + \inst{DIV} & \zero & \oneCell \\ \hline + \inst{SDIV} & \zero & \oneCell \\ \hline + \inst{MOD} & \zero & \oneCell \\ \hline + \inst{SMOD} & \zero & \oneCell \\ \hline +\end{array} +\] diff --git a/hub/instruction_handling/mul.tex b/hub/instruction_handling/mul.tex new file mode 100644 index 0000000..477b1bd --- /dev/null +++ b/hub/instruction_handling/mul.tex @@ -0,0 +1,7 @@ +\[ + \begin{array}{|l||c||c||c|c|} \hline + \INST & \tli & \stackDecMulFlag & \decFlag{1} & \decFlag{2} \\ \hline\hline + \inst{MUL} & \zero & \oneCell & \oneCell & \zero \\ \hline + \inst{EXP} & \zero & \oneCell & \zero & \oneCell \\ \hline + \end{array} +\] diff --git a/hub/instruction_handling/pushpop.tex b/hub/instruction_handling/pushpop.tex new file mode 100644 index 0000000..de7b358 --- /dev/null +++ b/hub/instruction_handling/pushpop.tex @@ -0,0 +1,59 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecPushPopFlag & \decFlag{1} \\ \hline\hline + \inst{POP} & \zero & \oneCell & \zero \\ \hline + \inst{PUSH1-32} & \zero & \oneCell & \oneCell \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ distinguishes between the ``push'' and ``pop'' instructions. + + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecPushPopFlag_{i} = 1 \\ + \stackSux_{i} + \stackSox_{i} = 0 \\ + \end{cases}} +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] --- + \begin{enumerate} + \item \If $\decFlag{1}_{i} = 0$ \Then $\oneZeroSP_{i}$ + \item \If $\decFlag{1}_{i} = 1$ \Then $\zeroOneSP_{i}$ + \end{enumerate} + \item[\underline{Setting $\nonStackRows$:}] we impose $\nonStackRows_{i} = \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] we don't need to set any; + + \saNote{} Implicitly of course $\cmc_{i} \cdot \peekContext_{i + 1} = \cmc_{i}$ (\trash); + \item[\underline{Setting the gas cost:}] we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] % \ob{TODO: write down the plookup into the \romMod{} module.} + \If $\decFlag{1}_{i} = 1$ \Then + \[ + \begin{cases} + \stackItemValHi{4}_{i} = \stackPushParamHi_{i} \\ + \stackItemValLo{4}_{i} = \stackPushParamLo_{i} \\ + \end{cases} + \] + \item[\underline{Setting $\pc\new$:}] + we impose that + \begin{enumerate} + \item \If $\decFlag{1}_{i} = 0$ \Then $\pc\new_{i} = 1 + \pc_{i}$ + \item \If $\decFlag{1}_{i} = 1$ \Then $\pc\new_{i} = 1 + \pc_{i} + (\stackInst_{i} - \inst{PUSH1} + 1)$ + \end{enumerate} +\end{description} +\saNote{} We only require setting values in the case of \inst{PUSH}-type instructions. + +\saNote{} For instructions raising the $\stackDecPushPopFlag$ one has $\cmc \equiv \xAhoy$. diff --git a/hub/instruction_handling/shf.tex b/hub/instruction_handling/shf.tex new file mode 100644 index 0000000..bacf0b9 --- /dev/null +++ b/hub/instruction_handling/shf.tex @@ -0,0 +1,9 @@ +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecShfFlag \\ \hline\hline + \inst{SHL} & \zero & \oneCell \\ \hline + \inst{SHR} & \zero & \oneCell \\ \hline + \inst{SAR} & \zero & \oneCell \\ \hline +\end{array} +\] diff --git a/hub/instruction_handling/stack_exceptions.tex b/hub/instruction_handling/stack_exceptions.tex new file mode 100644 index 0000000..578c0c0 --- /dev/null +++ b/hub/instruction_handling/stack_exceptions.tex @@ -0,0 +1,34 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekStack_{i} = 1.} +\end{center} + +Before instruction processing leads to any items being either excavated from (or placed onto) some execution context's stack, the \zkEvm{} must first check whether doing so would cause a \textbf{stack exception}, that is: either a \suxSH{} or a \soxSH{}. +The main ingredients that go into this check are as follows: +\begin{enumerate} + \item the currently valid stack height $\height$; + \item two instruction decoded parameters $\stackDelta$ and $\stackAlpha$; + \item two exclusive exception flags $\stackSux$ and $\stackSox{}$; +\end{enumerate} +\saNote{} For a given instruction $w$ the \idMod{} module provides the pair $(\stackDelta, \stackAlpha)$ representing $(\delta_{w},\alpha_{w})$ respectively, using notations from the \cite{EYP}. +\begin{enumerate}[resume] + \item a lookup to the \wcpMod{} to check for \suxSH{}'s, see section~(\ref{hub: lookups: into wcp for stack underflow}); + \item a lookup to the \wcpMod{} to check for \soxSH{}'s, see section~(\ref{hub: lookups: into wcp for stack overflow}); +\end{enumerate} +\saNote{} The above lookups justify $\stackSux_{i}$ and $\stackSox_{i}$ respectively. + +In case of a stack exception only one (non stack-)peeking row is required, the row which updates the parent context's context data. +We thus impose the following: +\begin{enumerate} + \item \If \Big($\peekStack_{i} = 1$ \et $\stackSux_{i} + \stackSox_{i} = 1$\Big) \Then + \[ + \left\{ \begin{array}{lcl} + \nonStackRows_{i} & = & 1 \\ + \multicolumn{3}{l}{\emptyStackItem{k}_{i}, ~ k\in\{1,2,3,4\}} \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{} The above applies automatically to both rows in case of a $\TLI{}$. + +\saNote{} In case of a stack exception the above and constraints from section~\ref{hub: generalities: context: context numbers} impose that the \textbf{one} non-stack row coming after the stack rows\footnote{one or two depending on $\tli{}$} be a context-row providing empty return data to the caller context. Recall that there is one such row by virtue of the above constraint $\nonStackRows_{i} = 1$. + +\saNote{} The \inst{DUP\_X}, $1 \leq \inst{X} \leq 16$, instructions are the only instructions which may raise both underflow and overflow exceptions. diff --git a/hub/instruction_handling/stack_ram/_inputs.tex b/hub/instruction_handling/stack_ram/_inputs.tex new file mode 100644 index 0000000..35818de --- /dev/null +++ b/hub/instruction_handling/stack_ram/_inputs.tex @@ -0,0 +1,4 @@ +\input{instruction_handling/stack_ram/_local} +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: stack ram: instructions} \input{instruction_handling/stack_ram/instructions} +\subsubsection{Shorthands \lispDone{}} \label{hub: instruction handling: stack ram: shorthands} \input{instruction_handling/stack_ram/shorthands} +\subsubsection{Constraints \lispDone{}} \label{hub: instruction handling: stack ram: constraints} \input{instruction_handling/stack_ram/constraints} diff --git a/hub/instruction_handling/stack_ram/_local.tex b/hub/instruction_handling/stack_ram/_local.tex new file mode 100644 index 0000000..85fbe40 --- /dev/null +++ b/hub/instruction_handling/stack_ram/_local.tex @@ -0,0 +1,21 @@ +\def\locTriggerMmu {\col{trigger\_MMU}} +\def\locInst {\col{inst}} +\def\locHi {\col{\_hi}} +\def\locLo {\col{\_lo}} +\def\locOffset {\col{offset}} +\def\locOffsetHi {\locOffset\locHi} +\def\locOffsetLo {\locOffset\locLo} +\def\locValue {\col{value}} +\def\locValueHi {\locValue\locHi} +\def\locValueLo {\locValue\locLo} +\def\locCallDataSize {\col{call\_data\_size}} +\def\locCallDataOffset {\col{call\_data\_offset}} +\def\locCallDataLoadIsOob {\col{CDL\_is\_oob}} +\def\locMxpx {\col{memory\_expansion\_exception}} +\def\locMxpGas {\col{mxp\_gas}} +\def\locIsCallDataLoad {\col{is\_CDL}} +\def\locIsMSomething {\col{is\_MXX}} +\def\locIsStoreInst {\col{store\_inst}} + +\def\stackramMiscRowOffset {\yellowm{1}} +\def\stackramContextRowOffset {\orangem{2}} diff --git a/hub/instruction_handling/stack_ram/constraints.tex b/hub/instruction_handling/stack_ram/constraints.tex new file mode 100644 index 0000000..b124fe8 --- /dev/null +++ b/hub/instruction_handling/stack_ram/constraints.tex @@ -0,0 +1,197 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lcl} + \peekStack_{i} & = & 1 \\ + \stackDecStackRamFlag_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \end{array} \right. } +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] + we impose $\loadStoreSP\big[ \locIsStoreInst \big]_{i}$; + + \saNote{} + The sum $\locIsStoreInst \equiv \decFlag{3} + \decFlag{4}$ is binary. + It is equal to $1$ \emph{iff} the underlying instruction stores data in memory. + \item[\underline{Setting $\nonStackRows$ and peeking flags:}] + \inst{MLOAD}, \inst{}, \inst{} require computing memory expansion costs and possibly calling for a memory instruction; + \inst{CALLDATALOAD} requires retrieving the call data size from the execution context and possibly calling for a memory instruction; + we thus impose $\nonStackRows_{i} = 1 + \decFlag{1}_{i} + \cmc_{i}$. + \item[\underline{Setting the peeking flags:}] + the analysis depends on whether the instruction is \inst{CALLDATALOAD} (i.e. $\locIsCallDataLoad = 1$) or not (i.e. $\locIsMSomething = 1$): + \begin{enumerate} + \item \If $\locIsCallDataLoad = 1$ \Then + \[ + \left[ \begin{array}{r} + + \peekMisc _{i + \stackramMiscRowOffset} \\ + + \peekContext _{i + \stackramContextRowOffset} \\ + + \cmc_{i} \cdot \peekContext _{i + 3} \\ + \end{array} \right] = + \nonStackRows_{i} + \] + \item \If $\locIsMSomething = 1$ \Then + \[ + \left[ \begin{array}{r} + + \peekMisc _{i + \stackramMiscRowOffset} \\ + + \cmc_{i} \cdot \peekContext _{i + 2} \\ + \end{array} \right] + = \nonStackRows_{i} + \] + \end{enumerate} + + \saNote{} For instructions raising the $\stackDecStackRamFlag$ one has $\cmc \equiv \xAhoy$. + \item[\underline{Setting the \mxpxSH{}:}] + we impose the following + \begin{enumerate} + \item \If $\locIsCallDataLoad = 1$ \Then we impose $\stackMxpx_{i} = 0$ (\trash) + \item \If $\locIsMSomething = 1$ \Then we impose $\stackMxpx_{i} = \locMxpx$ + \end{enumerate} + \saNote{} Setting $\stackMxpx \equiv 0$ for \inst{CALLDATALOAD} is redundant given that $\mxpFlag \equiv 0$ and section~(\ref{hub: generalities: exceptions: automatic vanishing}). + \item[\underline{Setting the gas cost:}] + we impose that + \begin{enumerate} + \item \If $\locIsCallDataLoad = 1$ \Then \( \gasCost_{i} = \decStaticGas_{i} \). + \item \If $\locIsMSomething = 1$ \Then + \begin{enumerate} + \item \If $\locMxpx = 0$ \Then \( \gasCost_{i} = \decStaticGas_{i} + \locMxpGas \) + \item \If $\locMxpx = 1$ \Then \( \gasCost_{i} = 0 \) + \end{enumerate} + \end{enumerate} + \item[\underline{Miscellaneous-row $n^°(i + \stackramMiscRowOffset)$: flags:}] we impose + \[ + \weightedMiscFlagSum {i}{\stackramMiscRowOffset} + = + \left[ \begin{array}{crcl} + + & \miscMmuWeight & \!\!\! \cdot \!\!\! & \locTriggerMmu \\ + + & \miscMxpWeight & \!\!\! \cdot \!\!\! & \locIsMSomething \\ + + & \miscOobWeight & \!\!\! \cdot \!\!\! & \locIsCallDataLoad \\ + \end{array} \right] + \] + in other words we impose + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \stackramMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \stackramMiscRowOffset} & = & \locTriggerMmu & (\trash) \\ + \miscMxpFlag _{i + \stackramMiscRowOffset} & = & \locIsMSomething & (\trash) \\ + \miscOobFlag _{i + \stackramMiscRowOffset} & = & \locIsCallDataLoad & (\trash) \\ + \miscStpFlag _{i + \stackramMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} The binary flag \locTriggerMmu{} will be defined below. + \item[\underline{Defining \locTriggerMmu{}:}] we define it as follows: + \begin{enumerate} + \item \If $\locIsCallDataLoad = 1$ \Then + \( + \locTriggerMmu \define + \big( 1 - \xAhoy_{i} \big) + \cdot + \big( 1 - \locCallDataLoadIsOob \big) + \) + \item \If $\locIsMSomething = 1$ \Then + \( + \locTriggerMmu \define + 1 - \xAhoy_{i} + \) + \end{enumerate} + \item[\underline{Miscellaneous-row $n°(i + \stackramMiscRowOffset)$: \oobMod{} data:}] + \If $\locIsCallDataLoad = 1$ \Then we impose + \[ + \setOobInstructionCdl {i}{\stackramMiscRowOffset} + \left[ \begin{array}{ll} + \utt{offset high:} & \locOffsetHi \\ + \utt{offset low:} & \locOffsetLo \\ + \utt{call data size:} & \locCallDataSize \\ + \end{array} \right] \vspace{2mm} \\ + \] + \saNote{} + Only \inst{CALLDATALOAD} requires a lookup to the \oobMod{}. + + \saNote{} + The purpose of the \oobMod{} module call is to decide whether the offset parameter exceeds the call data size, in which case \textsc{ram} need not be touched by the instruction. + Recall that we set $ \locCallDataLoadIsOob \define \miscOobDataCol{7}_{i + \stackramMiscRowOffset} $ + To be precise + \[ + \left\{ \begin{array}{l} + \locCallDataLoadIsOob \equiv \text{ binary} \\ + \locCallDataLoadIsOob = 1 \iff \locOffset \geq \locCds \\ + \end{array} \right. + \] + \item[\underline{Value for trivial \inst{CALLDATALOAD}'s:}] + \If $\locIsCallDataLoad = 1$ \et $\locCallDataLoadIsOob = 1$ \Then we impose + \[ + \left\{ \begin{array}{lcl} + \locValueHi & = & 0 \\ + \locValueLo & = & 0 \\ + \end{array} \right. + \] + \item[\underline{Context-row $n^°(i + \stackramContextRowOffset)$:}] + we impose that \If $\locIsCallDataLoad = 1$ \Then $\readContextData {i}{\stackramContextRowOffset}{\cn_{i}}$ + \item[\underline{Miscellaneous-row $n^°(i + \stackramMiscRowOffset)$: \mxpMod{} data:}] + \If $\miscMxpFlag_{i + \stackramMiscRowOffset} = 1$ \Then + we compute memory expansion cost: + \[ + \setMxpInstructionTypeTwo {i}{\stackramMiscRowOffset} + \left[ \begin{array}{ll} + \utt{Instruction:} & \locInst \\ + \utt{Offset high part:} & \locOffsetHi \\ + \utt{Offset low part:} & \locOffsetLo \\ + \end{array} \right] + \] + \item[\underline{Miscellaneous-row $n^°(i + \stackramMiscRowOffset)$: \mmuMod{} data:}] + \If $\miscMmuFlag_{i + \stackramMiscRowOffset} = 1$ \Then + we impose + \begin{description} + \item[\underline{The \inst{CALLDATALOAD} case:}] + \If $\decFlag{1}_{i} = 1$ \Then we impose + \[ + \setMmuInstructionParametersRightPaddedWordExtraction { + anchorRow = i , + relOffset = \stackramMiscRowOffset , + sourceId = \cnCallDataContextNumber _{i + \stackramContextRowOffset} , + sourceOffsetLo = \locOffsetLo , + referenceOffset = \locCallDataOffset , + referenceSize = \locCallDataSize , + limbOne = \locValueHi , + limbTwo = \locValueLo , + } + \] + \item[\underline{The \inst{MLOAD} case:}] + \If $\decFlag{2}_{i} = 1$ \Then we impose + \[ + \setMmuInstructionParametersMload { + anchorRow = i, + relOffset = \stackramMiscRowOffset, + sourceId = \cn_{i}, + sourceOffsetLo = \locOffsetLo, + limbOne = \locValueHi, + limbTwo = \locValueLo, + } + \] + \item[\underline{The \inst{MSTORE} case:}] + \If $\decFlag{3}_{i} = 1$ \Then we impose + \[ + \setMmuInstructionParametersMstore { + anchorRow = i , + relOffset = \stackramMiscRowOffset , + targetId = \cn_{i} , + targetOffsetLo = \locOffsetLo , + limbOne = \locValueHi , + limbTwo = \locValueLo , + } + \] + \item[\underline{The \inst{MSTORE8} case:}] + \If $\decFlag{4}_{i} = 1$ \Then we impose + \[ + \setMmuInstructionParametersMstoreEight { + anchorRow = i , + relOffset = \stackramMiscRowOffset , + targetId = \cn_{i} , + targetOffsetLo = \locOffsetLo , + limbOne = \locValueHi , + limbTwo = \locValueLo , + } + \] + \end{description} +\end{description} diff --git a/hub/instruction_handling/stack_ram/instructions.tex b/hub/instruction_handling/stack_ram/instructions.tex new file mode 100644 index 0000000..44b5a3a --- /dev/null +++ b/hub/instruction_handling/stack_ram/instructions.tex @@ -0,0 +1,10 @@ +\[ + \hspace*{-1.5cm} + \begin{array}{|l||c||c|c|c|c|c||c|} \hline + \INST & \tli & \stackDecStackRamFlag & \decFlag{1} & \decFlag{2} & \decFlag{3} & \decFlag{4} & \mxpFlag \\ \hline\hline + \inst{CALLDATALOAD} & \zero & \oneCell & \oneCell & \zero & \zero & \zero & \zero \\ \hline + \inst{MLOAD} & \zero & \oneCell & \zero & \oneCell & \zero & \zero & \oneCell \\ \hline + \inst{MSTORE} & \zero & \oneCell & \zero & \zero & \oneCell & \zero & \oneCell \\ \hline + \inst{MSTORE8} & \zero & \oneCell & \zero & \zero & \zero & \oneCell & \oneCell \\ \hline + \end{array} +\] diff --git a/hub/instruction_handling/stack_ram/shorthands.tex b/hub/instruction_handling/stack_ram/shorthands.tex new file mode 100644 index 0000000..26d1d7c --- /dev/null +++ b/hub/instruction_handling/stack_ram/shorthands.tex @@ -0,0 +1,30 @@ +We will use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locInst & \define & \stackInst _{i} \\ + \locIsCallDataLoad & \define & \decFlag {1} _{i} \\ + \locIsStoreInst & \define & \left[ \begin{array}{cr} + & \decFlag{3}_{i} \\ + & \decFlag{4}_{i} \\ \end{array} \right] \vspace{1mm} \\ + \locIsMSomething & \define & \left[ \begin{array}{cr} + & \decFlag{2}_{i} \\ + & \decFlag{3}_{i} \\ + & \decFlag{4}_{i} \\ \end{array} \right] \\ + \locOffsetHi & \define & \stackItemValHi {1} _{i} \\ + \locOffsetLo & \define & \stackItemValLo {1} _{i} \\ + \locValueHi & \define & \stackItemValHi {4} _{i} \\ + \locValueLo & \define & \stackItemValLo {4} _{i} \\ + \locCallDataLoadIsOob & \define & \miscOobDataCol {7} _{i + \stackramMiscRowOffset} \\ + \locMxpGas & \define & \miscMxpGasMxp _{i + \stackramMiscRowOffset} \\ + \locCallDataSize & \define & \cnCds _{i + \stackramContextRowOffset} \\ + \locCallDataOffset & \define & \cnCdo _{i + \stackramContextRowOffset} \vspace{2mm} \\ + \multicolumn{3}{l}{\locMxpx \define \miscMxpMxpx _{i + \stackramMiscRowOffset}} \\ + \end{array} \right. +\] +\saNote{} In the above ``\col{CDL}'' is short for \inst{CALLDATALOAD}. + +\noindent By definition we have the following +\[ + \begin{array}{|l|c|c|c|} \hline + \INST & \locIsCallDataLoad & \locIsStoreInst & \locIsMSomething \\ \hline \hline + \inst{CALLDATALOAD} & \oneCell & \gZero & \gZero \\ \hline + \inst{MLOAD} & \gZero & \gZero & \oneCell \\ \hline + \inst{MSTORE} & \gZero & \oneCell & \oneCell \\ \hline + \inst{MSTORE8} & \gZero & \oneCell & \oneCell \\ \hline + \end{array} +\] diff --git a/hub/instruction_handling/stateless_constraints.tex b/hub/instruction_handling/stateless_constraints.tex new file mode 100644 index 0000000..376bc8c --- /dev/null +++ b/hub/instruction_handling/stateless_constraints.tex @@ -0,0 +1,127 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \left\{ \begin{array}{lclr} + \peekStack_{i} & = & 1 \\ + \stackSux_{i} + \stackSox_{i} & = & 0 \\ + \isStatelessInst_{i} & = & 1 & (\trash) \\ + \end{array} \right. + } +\end{center} +\saNote{} +We have used the shorthand +\[ + \isStatelessInst_{i} + \define + \left[ \begin{array}{r} + + \stackDecAddFlag_{i} + \stackDecBinFlag_{i} + \stackDecExtFlag_{i} \\ + + \stackDecModFlag_{i} + \stackDecMulFlag_{i} + \stackDecShfFlag_{i} \\ + + \stackDecWcpFlag_{i} \\ + \end{array} \right] = 1 +\] +\saNote{} +The present section deals with \emph{all} instruction raising any of the following flags +\begin{multicols}{4} + \begin{enumerate} + \item $\stackDecAddFlag$ + \item $\stackDecBinFlag$ + \item $\stackDecExtFlag$ + \item $\stackDecModFlag$ + \item $\stackDecMulFlag$ + \item $\stackDecShfFlag$ + \item $\stackDecWcpFlag$ + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +Yet the precondition ``$\isStatelessInst_{i} = 1$ isn't required: this condition will always follow from stronger preconditions imposed using the shorthands we define below. + +We shall use the following shorthands: +\[ + \left\{ \begin{array}{lcl} + \instIsExp & \define & \stackDecMulFlag_{i} \cdot \decFlag{2}_{i} \\ + \instIsntExp & \define & + \left[ \begin{array}{r} + + \stackDecAddFlag_{i} + \stackDecBinFlag_{i} + \stackDecExtFlag_{i} \\ + + \stackDecModFlag_{i} + \stackDecShfFlag_{i} + \stackDecWcpFlag_{i} \\ + + \stackDecMulFlag_{i} \cdot \decFlag{1}_{i} \\ + \end{array} \right] \\ + \oneArgInst & \define & (\stackDecBinFlag_{i} + \stackDecWcpFlag_{i}) \cdot \decFlag{1}_{i} \\ + \twoArgInst & \define & + \left[ \begin{array}{r} + + \stackDecAddFlag_{i} + \stackDecModFlag_{i} + \stackDecMulFlag_{i} + \stackDecShfFlag_{i} \\ + + (\stackDecBinFlag_{i} + \stackDecWcpFlag_{i}) \cdot (1 - \decFlag{1}_{i}) \\ + \end{array} \right] \\ + \treArgInst & \define & \stackDecExtFlag_{i} \\ + \end{array} \right. +\] +\saNote{} By construction +\begin{IEEEeqnarray*}{LCL} + \isStatelessInst & \equiv & \oneArgInst + \twoArgInst + \treArgInst \\ + & \equiv & \instIsExp + \instIsntExp \\ +\end{IEEEeqnarray*} + +In other words we are assuming that the \zkEvm{} is currently dealing with an arithmetic, binary, shifting or word comparison instruction. +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose that + \begin{enumerate} + \item \If $\oneArgInst = 1$ \Then $\oneOneSP_{i}$, see section~(\ref{hub: stack patterns: 1_1}); + \item \If $\twoArgInst = 1$ \Then $\twoOneSP_{i}$, see section~(\ref{hub: stack patterns: 2_1}); + \item \If $\treArgInst = 1$ \Then $\threeOneSP_{i}$, see section~(\ref{hub: stack patterns: 3_1}); + \end{enumerate} + \item[\underline{Zero high part for \wcpMod{}:}]\label{hub: instruction handling: stateless: wcp high part is zero} + \If $\stackDecWcpFlag_{i} = 1$ \Then we impose that + \begin{enumerate} + \item $\stackItemValHi{4}_{i} = 0$ + \item $\stackItemValLo{4}_{i} \cdot (1 - \stackItemValLo{4}_{i}) = 0$ \quad (\trash) + \end{enumerate} + \item[\underline{Setting $\nonStackRows$:}] \If $\isStatelessInst_{i} = 1$ \Then we impose that + \[ + \nonStackRows_{i} = \instIsExp_{i} + \cmc_{i} + \] + i.e. we impose that + \begin{enumerate} + \item \If $\instIsntExp = 1$ \Then $\nonStackRows_{i} = \cmc_{i}$; \quad (\trash) + \item \If $\instIsExp = 1$ \Then $\nonStackRows_{i} = 1 + \cmc_{i}$; \quad (\trash) + \end{enumerate} + \item[\underline{Setting the peeking flags:}] we impose that + \begin{enumerate} + \item \If $\instIsntExp = 1$ \Then $\cmc_{i} \cdot \peekContext_{i + 1} = \nonStackRows_{i}$ (\trash); + \item \If $\instIsExp = 1$ \Then $ \peekMisc_{i + 1} + \cmc_{i} \cdot \peekContext_{i + 2} = \nonStackRows_{i} $ + \end{enumerate} + \item[\underline{Setting miscellaneous flags:}] \If $\instIsExp = 1$ \Then + \[ + \weightedMiscFlagSum {i}{1} + = + \miscExpWeight + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag_{i + 1} & = & \rOne & (\trash) \\ + \miscMmuFlag_{i + 1} & = & \rZero & (\trash) \\ + \miscMxpFlag_{i + 1} & = & \rZero & (\trash) \\ + \miscOobFlag_{i + 1} & = & \gZero & (\trash) \\ + \miscStpFlag_{i + 1} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \item[\underline{Setting $\miscExpFlag$ arguments of:}] \If $\instIsExp = 1$ \Then + \[ + \setExpInstructionParametersExpLog {i}{1} + \left[ \begin{array}{ll} + \utt{Exponent high:} & \stackItemValHi{2}_{i} \\ + \utt{Exponent low:} & \stackItemValLo{2}_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \] + % \[ + % \left\{ \begin{array}{lcl} + % \miscExpDataCol{1}_{i + 1} & = & \stackItemValHi{2}_{i} \\ + % \miscExpDataCol{2}_{i + 1} & = & \stackItemValLo{2}_{i} \\ + % \end{array} \right. + % \] + \saNote{} The second stack item of an \inst{EXP} instruction contains the exponent. + \item[\underline{Setting the gas cost:}] we impose that + \begin{enumerate} + \item \If $\instIsntExp = 1$ \Then $\gasCost_{i} = \decStaticGas_{i}$; + \item \If $\instIsExp = 1$ \Then $\gasCost_{i} = \decStaticGas_{i} + \miscExpDataCol{5}_{i + 1}$ + \end{enumerate} +\end{description} diff --git a/hub/instruction_handling/storage/_inputs.tex b/hub/instruction_handling/storage/_inputs.tex new file mode 100644 index 0000000..e4cd23d --- /dev/null +++ b/hub/instruction_handling/storage/_inputs.tex @@ -0,0 +1,3 @@ +\input{instruction_handling/storage/_local} +\subsubsection{Supported instructions and flags} \label{hub: instruction handling: storage: flags} \input{instruction_handling/storage/flags} +\subsubsection{Constraints} \label{hub: instruction handling: storage: constraints} \input{instruction_handling/storage/constraints} diff --git a/hub/instruction_handling/storage/_local.tex b/hub/instruction_handling/storage/_local.tex new file mode 100644 index 0000000..f2e53e6 --- /dev/null +++ b/hub/instruction_handling/storage/_local.tex @@ -0,0 +1,18 @@ +\def\locOrigIsZero {\col{orig\_is\_zero}} +\def\locCurrIsZero {\col{curr\_is\_zero}} +\def\locNextIsZero {\col{next\_is\_zero}} +\def\locCurrIsOrig {\col{curr\_is\_orig}} +\def\locNextIsOrig {\col{next\_is\_orig}} +\def\locNextIsCurr {\col{next\_is\_curr}} +\def\locFirstCon {\yellowm{1}} +\def\locStaticxSecondCon {\yellowm{2}} +\def\locSstorexMisc {\yellowm{2}} +\def\locSstorexSecondCon {\yellowm{3}} +\def\locOogxMisc {\yellowm{2}} +\def\locOogxDoStorage {\yellowm{3}} +\def\locOogxUndoStorage {\yellowm{4}} +\def\locOogxSecondCon {\yellowm{5}} +\def\locMiscRowOffset {\yellowm{2}} +\def\locFirstStoRowOffset {\yellowm{3}} +\def\locSecondStoRowOffset {\yellowm{4}} +\def\locColdStorageSlot {\col{cold\_slot}} diff --git a/hub/instruction_handling/storage/constraints.tex b/hub/instruction_handling/storage/constraints.tex new file mode 100644 index 0000000..1ca26e7 --- /dev/null +++ b/hub/instruction_handling/storage/constraints.tex @@ -0,0 +1,250 @@ +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecStoFlag_{i} = 1 \\ + \stackSux_{i} + \stackSox_{i} = 0 \\ + \end{cases}} +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose $\loadStoreSP\big[\decFlag{1}_{i}\big]_{i}$ + \item[\underline{Valid exceptions:}] + the constraints below don't need to be imposed in the implementation: + \begin{enumerate} + \item \If $\decFlag{1}_{i} = 0$ \Then $\xAhoy_{i} = \stackOogx_{i}$ \quad (\trash) + \item \If $\decFlag{1}_{i} = 1$ \Then $\xAhoy_{i} = \stackStaticx_{i} + \stackSstorex_{i} + \stackOogx_{i}$ \quad (\trash) + \end{enumerate} + \saNote{} Given section~(\ref{hub: generalities: exceptions: automatic vanishing}) + \inst{SSLOAD} may only raise stack exceptions or \oogxSH{} + while \inst{SSTORE} may raise stack exceptions, \staticxSH{}, \sstorexSH{} or \oogxSH{}. + \item[\underline{Setting $\nonStackRows$ and peeking flags:}] + storage operations can provoke exceptions in multiple ways and are rollback sensitive; + they thus have some inherent complexity; + we impose the following: + \begin{enumerate} + \item \If $\stackStaticx_{i} = 1$ \Then $\nonStackRows_{i} = 2$ and furthermore + \[ + \left[ \begin{array}{cr} + + & \peekContext _{i + \locFirstCon} \\ + + & \peekContext _{i + \locStaticxSecondCon} \\ + \end{array} \right] + = + \nonStackRows_{i} + \] + \item \If $\stackSstorex_{i} = 1$ \Then $\nonStackRows_{i} = 3$ and furthermore + \[ + \left[ \begin{array}{cr} + + & \peekContext _{i + \locFirstCon } \\ + + & \peekMisc _{i + \locSstorexMisc } \\ + + & \peekContext _{i + \locSstorexSecondCon} \\ + \end{array} \right] + = + \nonStackRows_{i} + \] + \item \If $\stackOogx_{i} = 1$ \Then $\nonStackRows_{i} = 5$ and furthermore + \[ + \left[ \begin{array}{cr} + + & \peekContext _{i + \locFirstCon } \\ + + & \peekMisc _{i + \locOogxMisc } \\ + + & \peekStorage _{i + \locOogxDoStorage } \\ + + & \peekStorage _{i + \locOogxUndoStorage } \\ + + & \peekContext _{i + \locOogxSecondCon } \\ + \end{array} \right] + = + \nonStackRows_{i} + \] + \item \If $\xAhoy_{i} = 0$ \Then $\nonStackRows_{i} = 3 + \cnWillRev_{i}$ and furthermore + \[ + \left[ \begin{array}{crcl} + + & & & \peekContext _{i + \locFirstCon } \\ + + & & & \peekMisc _{i + \locMiscRowOffset } \\ + + & & & \peekStorage _{i + \locFirstStoRowOffset } \\ + + & \cnWillRev _{i} & \!\!\!\cdot\!\!\! & \peekStorage _{i + \locSecondStoRowOffset } \\ + \end{array} \right] + = + \nonStackRows_{i} + \] + \end{enumerate} + \item[\underline{The first context row:}] + we \textbf{unconditionally} impose that $\readContextData {i}{\locFirstCon}{\cn_{i}}$ + \item[\underline{Setting \stackStaticx{} flag:}] + we impose that $\stackStaticx_{i} = \decFlag{1}_{i} \cdot \cnStatic_{i + \locFirstCon}$; + + \saNote{} Recall that (among instructions raising the $\stackDecStoFlag$ flag) only \inst{SSTORE} may raise a \staticxSH{}. + \item[\underline{Setting the miscellaneous-row:}] + \If $\peekMisc_{i + \locMiscRowOffset} = 1$ \Then + \begin{enumerate} + \item we impose that \inst{SSTORE} instructions trigger the \oobMod{} + \[ + \weightedMiscFlagSum {i}{\locMiscRowOffset} + = + \miscOobWeight \cdot \decFlag{1}_{i} + \] + in other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \locMiscRowOffset} & \!\!\!=\!\!\! & \gZero & (\trash) \\ + \miscMmuFlag _{i + \locMiscRowOffset} & \!\!\!=\!\!\! & \rZero & (\trash) \\ + \miscMxpFlag _{i + \locMiscRowOffset} & \!\!\!=\!\!\! & \rZero & (\trash) \\ + \miscOobFlag _{i + \locMiscRowOffset} & \!\!\!=\!\!\! & \decFlag{1}_{i} & (\trash) \\ + \miscStpFlag _{i + \locMiscRowOffset} & \!\!\!=\!\!\! & \gZero & (\trash) \\ + \end{array} \right. + \] + \item \If $\decFlag{1}_{i} = 1$ \Then we further impose that + \[ + \setOobInstructionSstore {i}{\locMiscRowOffset} + \Big[ \begin{array}{ll} + \utt{Actual gas:} & \gasActual_{i} \\ + \end{array} \Big] + \] + \end{enumerate} + \item[\underline{Justifying the \stackSstorex{} flag:}] + \begin{enumerate} + \If $\peekMisc_{i + \locMiscRowOffset} = 1$ \Then + \item \If $\decFlag{1}_{i} = 1$ \Then we impose that $\stackSstorex_{i} = \miscOobDataCol{7}_{i + \locMiscRowOffset}$ + \end{enumerate} +\end{description} +\saNote{} +Recall that the purpose of the \oobMod{}-instruction $\oobInstSstore$ is to justify the presence or absence of a \sstorexSH{}. +Recall further that this exception may only be triggered by the \inst{SSTORE} instruction and +\[ + \begin{cases} + \stackSstorex \equiv 0 \iff \gasActual > G_{\text{callstipend}} \\ + \stackSstorex \equiv 1 \iff \gasActual \leq G_{\text{callstipend}} \\ + \end{cases} +\] +where $G_{\text{callstipend}} = 2300$. + +\saNote{} +The gas cost of a storage instruction need only be computed in case of a \oogxSH{} or in the absence of any exception. +In order to compute the gas cost accurately (in particular for \inst{SSTORE}) we let the \zkEvm{} perform the requeste storage update even in case of an exception. +Note however that in case of an exception triggered by the present instruction or the context being rolled back at a later point this update is undone in the present instruction handling. +\begin{description} + \item[\underline{Setting storage slot parameters:}] + \If $\stackOogx_{i} + (1 - \xAhoy_{i}) = 1$ \Then\footnote{Observe that $\stackOogx_{i} + (1 - \xAhoy_{i})$ is binary since by construction $\stackOogx_{i} \cdot (1 - \xAhoy_{i}) = 0$} + \[ + \left\{ \begin{array}{lclr} + \peekContext _{i + \locFirstCon} + \peekStorage_{i + \locFirstStoRowOffset} & = & 2 & (\trash) \\ + \stoAddressHi _{i + \locFirstStoRowOffset} & = & \cnAccountAddress\high _{i + \locFirstCon} \\ + \stoAddressLo _{i + \locFirstStoRowOffset} & = & \cnAccountAddress\low _{i + \locFirstCon} \\ + \stoDeploymentNumber _{i + \locFirstStoRowOffset} & = & \cnAccDepNum _{i + \locFirstCon} \\ + \stoKeyHi _{i + \locFirstStoRowOffset} & = & \stackItemValHi {1} _{i} \\ + \stoKeyLo _{i + \locFirstStoRowOffset} & = & \stackItemValLo {1} _{i} \\ + \multicolumn{3}{l}{\stoTurnOnWarmth {i}{\locFirstStoRowOffset} } \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locFirstStoRowOffset, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locFirstStoRowOffset}{0} } \\ + \end{array} \right. + \] + \item[\underline{Defining storage value operations:}] + \If $\stackOogx_{i} + (1 - \xAhoy_{i}) = 1$ \Then + \begin{description} + \item[\underline{The \inst{SLOAD} case:}] + \If $\decFlag{1}_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\storageReading{i}{\locFirstStoRowOffset}} \\ + \stackItemValHi {4} _{i} & \!\!\! = \!\!\! & \stoCurrValueHi_{i + \locFirstStoRowOffset} \\ + \stackItemValLo {4} _{i} & \!\!\! = \!\!\! & \stoCurrValueLo_{i + \locFirstStoRowOffset} \\ + \end{array} \right. + \] + \item[\underline{The \inst{SSTORE} case:}] + \If $\decFlag{1}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stoNextValueHi _{i + \locFirstStoRowOffset} & \!\!\! = \!\!\! & \stackItemValHi{4}_{i} \\ + \stoNextValueLo _{i + \locFirstStoRowOffset} & \!\!\! = \!\!\! & \stackItemValLo{4}_{i} \\ + \end{array} \right. + \] + \item[\underline{The inverse, undoing operation:}] + \If $\cnWillRev_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stoSameStorageSlot {i}{\locSecondStoRowOffset}{\locFirstStoRowOffset} \\ + \stoUndoWarmthAndValueUpdate {i}{\locSecondStoRowOffset}{\locFirstStoRowOffset} \\ + \revertDomSubStamps { + anchorRow = i, + relOffset = \locSecondStoRowOffset, + subOffset = 0, + } \\ + % {i}{\locSecondStoRowOffset}{0} \\ + \end{array} \right. + \] + \end{description} +\end{description} +What is missing from our analysis so far is the opcode pricing (in both the \oogxSH{} and unexceptional cases) as well as the management of refunds (in the unreverted case.) +We will use the following shorthands: +\[ + \left\{ \begin{array}{lcl} + \locOrigIsZero & \!\!\! \define \!\!\! & \stoOrigValueIsZero_{i + \locFirstStoRowOffset} \\ + \locCurrIsZero & \!\!\! \define \!\!\! & \stoCurrValueIsZero_{i + \locFirstStoRowOffset} \\ + \locNextIsZero & \!\!\! \define \!\!\! & \stoNextValueIsZero_{i + \locFirstStoRowOffset} \\ + \locCurrIsOrig & \!\!\! \define \!\!\! & \stoCurrValueIsOrig_{i + \locFirstStoRowOffset} \\ + \locNextIsOrig & \!\!\! \define \!\!\! & \stoNextValueIsOrig_{i + \locFirstStoRowOffset} \\ + \locNextIsCurr & \!\!\! \define \!\!\! & \stoNextValueIsCurr_{i + \locFirstStoRowOffset} \\ + \end{array} \right. +\] +\begin{description} + \item[\underline{Setting the gas cost:}] + \If $\stackOogx_{i} + (1 - \xAhoy_{i}) = 1$ \Then + \begin{description} + \item[\underline{The \inst{SLOAD} case:}] + \If $\decFlag{1}_{i} = 0$ \Then + \[ + \begin{cases} + \If \stoWarmth_{i + \locFirstStoRowOffset} = 0 ~ \Then \gasCost_{i} = G_{\text{coldsload}}\\ + \If \stoWarmth_{i + \locFirstStoRowOffset} = 1 ~ \Then \gasCost_{i} = G_{\text{warmaccess}}\\ + \end{cases} + \] + \item[\underline{The \inst{SSTORE} case:}] + \If $\decFlag{1}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\locNextIsCurr = 1$ \Then $ \gasCost_{i} = \locColdStorageSlot \cdot G_\text{coldsload} + G_\text{warmaccess} $ + \item \If $\locCurrIsOrig = 0$ \Then $ \gasCost_{i} = \locColdStorageSlot \cdot G_\text{coldsload} + G_\text{warmaccess} $ + \item \If \Big($\locNextIsCurr = 0$ \et $\locCurrIsOrig = 1$\Big) + \begin{enumerate} + \item \If $\locOrigIsZero = 1$ \Then $ \gasCost_{i} = \locColdStorageSlot \cdot G_\text{coldsload} + G_\text{sset} $ + \item \If $\locOrigIsZero = 0$ \Then $ \gasCost_{i} = \locColdStorageSlot \cdot G_\text{coldsload} + G_\text{sreset} $ + \end{enumerate} + \end{enumerate} + where in the above we have used the following shorthand + \[ + \locColdStorageSlot \define (1 - \stoWarmth_{i + \locFirstStoRowOffset}) + \] + \end{description} + \item[\underline{Setting the refund:}] + recall that among instructions raising the $\stackDecStoFlag$ only the \inst{SSTORE} instruction may grand refunds. + Futhermore refunds may only be granted in non reverting contexts. + See section~(\ref{hub: generalities: refunds: refunds}) for more details. + + \If \Big($\cnWillRev_{i} = 0$ \et $\decFlag{1}_{i} = 1$\Big) \Then we thus impose that + \begin{enumerate} + \item \If $\locNextIsCurr = 1$ \Then $\refund\new_{i} = \refund_{i}$ + \item \If $\locNextIsCurr = 0$ \Then + \begin{enumerate} + \item \If $\locCurrIsOrig = 0$ \Then + \[ + \refund\new_{i} = \refund_{i} + + + \left[ \begin{array}{crcccl} + + & (1 - \locOrigIsZero) & \cdot & (\locNextIsZero - \locCurrIsZero) & \cdot & R_\text{sclear} \\ + + & \locNextIsOrig & \cdot & \locOrigIsZero & \cdot & \big(G_\text{sset} - G_\text{warmaccess}\big) \\ + + & \locNextIsOrig & \cdot & (1 -\locOrigIsZero) & \cdot & \big(G_\text{sreset} - G_\text{warmaccess}\big) \\ + \end{array} \right] + \] + \item \If $\locCurrIsOrig = 1$ \Then + \begin{enumerate} + \item \If $\locNextIsZero = 0$ \Then $\refund\new_{i} = \refund_{i}$ + \item \If $\locNextIsZero = 1$ \Then $\refund\new_{i} = \refund_{i} + R_\text{sclear}$ + \end{enumerate} + \end{enumerate} + \end{enumerate} +\end{description} + diff --git a/hub/instruction_handling/storage/flags.tex b/hub/instruction_handling/storage/flags.tex new file mode 100644 index 0000000..e982c61 --- /dev/null +++ b/hub/instruction_handling/storage/flags.tex @@ -0,0 +1,9 @@ +\[ +\begin{array}{|l||c||c|c||c|} + \hline + \INST & \tli & \stackDecStoFlag & \decFlag{1} & \decStaticInst \\ \hline\hline + \inst{SLOAD} & \zero & \oneCell & \zero & \zero \\ \hline + \inst{SSTORE} & \zero & \oneCell & \oneCell & \oneCell \\ \hline +\end{array} +\] +\saNote{} Just as in section~\ref{hub: instruction handling: StackRam} the $\stackDecStoFlag$-instructions which raise the $\decFlag{1}$ are those that pop two items off the stack. diff --git a/hub/instruction_handling/swap.tex b/hub/instruction_handling/swap.tex new file mode 100644 index 0000000..30a4886 --- /dev/null +++ b/hub/instruction_handling/swap.tex @@ -0,0 +1,39 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +The \inst{SWAPX}-instructions are all one line instructions (i.e. $\tli = 0$.) For instructions that conform to the \swapSP{} the value of $\inst{X}$ can be derived from the instruction via $\inst{X} = \INST - \inst{SWAP1} + 1$. Locally within section~\ref{hub: stack patterns: dup} we use the shorthand $\param := \INST - \inst{SWAP1} = \inst{X} - 1$. +\[ +\begin{array}{|l||c||c|} + \hline + \INST & \tli & \stackDecSwapFlag \\ \hline\hline + \inst{SWAP1-16} & \zero & \oneCell \\ \hline +\end{array} +\] + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{center} +\boxed{% +\text{The stack constraints presented below assume } +\begin{cases} +\peekStack_{i} = 1 \\ +\stackDecSwapFlag_{i} = 1 \\ +\stackSux_{i} + \stackSox_{i} = 0 \\ +\end{cases}} +\end{center} + +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose $\swapSP\big[ \INST_{i} - \inst{SWAP1} + 1\big]_{i}$ + \item[\underline{Setting $\nonStackRows$:}] we impose $\nonStackRows_{i} = \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] we impose + \[ + \cmc_{i} \cdot \peekContext_{i + 1} = \nonStackRows_{i} \quad (\trash) + \] + \item[\underline{Setting the gas cost:}] we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] implicit in the stack pattern; %\If $\cmc_{i} = 0$ \Then +\end{description} +\saNote{} For instructions raising the $\stackDecSwapFlag$ one has $\cmc \equiv \xAhoy$. diff --git a/hub/instruction_handling/txn.tex b/hub/instruction_handling/txn.tex new file mode 100644 index 0000000..f902520 --- /dev/null +++ b/hub/instruction_handling/txn.tex @@ -0,0 +1,62 @@ +\subsubsection{Supported instructions and flags} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecTxnFlag & \decFlag{1} \\ \hline\hline + \inst{ORIGIN} & \zero & \oneCell & \zero \\ \hline + \inst{GASPRICE} & \zero & \oneCell & \oneCell \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ distinguishes between the two instructions raising the $\stackDecTxnFlag$ flag. + + + +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% +\def\locTxnRow{\yellowm{1}} +\def\locConRow{\orangem{2}} +\begin{center} + \boxed{% + \text{The stack constraints presented below assume } + \begin{cases} + \peekStack_{i} = 1 \\ + \stackDecTxnFlag_{i} = 1 \\ + \stackSux_{i} + \stackSox_{i} = 0 \\ + \end{cases}} +\end{center} +We impose the following constraints: +\begin{description} + \item[\underline{Setting the stack pattern:}] we impose $\zeroOneSP_{i}$; + \item[\underline{Setting $\nonStackRows$:}] we impose $\nonStackRows_{i} = 1 + \cmc_{i}$; + \item[\underline{Setting the peeking flags:}] we impose + \[ + \left[ \begin{array}{lrcl} + + & \peekTransaction _{i + \locTxnRow} \\ + + & \peekContext _{i + \locConRow} & \!\!\!\cdot\!\!\! & \cmc_{i} \\ + \end{array} \right] + = + \nonStackRows_{i} + \] + \item[\underline{Setting the gas cost:}] we impose that $\gasCost_{i} = \decStaticGas_{i}$; + \item[\underline{Value constraints:}] --- %\If $\cmc_{i} = 0$ \Then + \begin{enumerate} + \item \If $\decFlag{1}_{i} = 0$\footnote{i.e. $\INST_{i} = \inst{ORIGIN}$} \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & \txFrom\high_{i + \locTxnRow} \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \txFrom\low_{i + \locTxnRow} \\ + \end{array} \right. + \] + \item \If $\decFlag{1}_{i} = 1$\footnote{i.e. $\INST_{i} = \inst{GASPRICE}$} \Then + \[ + \left\{ \begin{array}{lcl} + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \txGasPrice_{i + \locTxnRow} \\ + \end{array} \right. + \] + \end{enumerate} +\end{description} +\saNote{} For instructions raising the $\stackDecTxnFlag$ one has $\cmc = \xAhoy$. diff --git a/hub/instruction_handling/wcp.tex b/hub/instruction_handling/wcp.tex new file mode 100644 index 0000000..059a47f --- /dev/null +++ b/hub/instruction_handling/wcp.tex @@ -0,0 +1,13 @@ +\[ +\begin{array}{|l||c||c|c|} + \hline + \INST & \tli & \stackDecWcpFlag & \decFlag{1} \\ \hline\hline + \inst{LT} & \zero & \oneCell & \zero \\ \hline + \inst{GT} & \zero & \oneCell & \zero \\ \hline + \inst{SLT} & \zero & \oneCell & \zero \\ \hline + \inst{SGT} & \zero & \oneCell & \zero \\ \hline + \inst{EQ} & \zero & \oneCell & \zero \\ \hline + \inst{ISZERO} & \zero & \oneCell & \oneCell \\ \hline +\end{array} +\] +\saNote{} $\decFlag{1}$ singles out the only \wcpMod{}-instructions following the \oneOneSP{}. diff --git a/hub/intro.tex b/hub/intro.tex new file mode 100644 index 0000000..b2796b5 --- /dev/null +++ b/hub/intro.tex @@ -0,0 +1,12 @@ +The \textsc{hub} module is the centerpiece of our \zkEvm{} design. +It manages just about everything, in particular +(1) it sets transaction execution in motion and handles the various stages\footnote{or phases} of transaction processing; +(2) it initializes execution context data\footnote{parts of what the Ethereum Yellow Paper \cite{EYP} calls the \textbf{execution environment}; account address, code address, caller address, call value, call stack depth, whether the context is static, a deployment context, \dots{}} when a new transaction starts executing or a new context is spawned through a \inst{CALL}-type instruction or \inst{CREATE}-type instruction; +(3) it updates said context data whenever there is a change in execution contexts\footnote{e.g. when execution resumes in a parent context after either exceptional halting or when executing on a halting instruction}; +(4) it handles instruction fetching from the \textsc{rom}; +(5) it updates the world state as it pertains to account data\footnote{nonces, balances, code hashes, code sizes, \dots{}} and storage; +(6) it has access to transaction data and batch data; +(7) it detects exceptions and more generally decides control flow; +(8) it dispatches instructions for specialized modules to carry out; +(9) it manages the stack \dots{} +If furthermore is manages certain \zkEvm{}-specific environment variables (context numbers, deployment numbers and deployment statuses. diff --git a/hub/lookups/_inputs.tex b/hub/lookups/_inputs.tex new file mode 100644 index 0000000..6e1f5b3 --- /dev/null +++ b/hub/lookups/_inputs.tex @@ -0,0 +1,27 @@ +\input{lookups/_local} + +\section{Lookups \lispWip{}} +\subsection{Introduction} \label{hub: lookups: intro} \input{lookups/_intro} +\subsection{\hubMod{} $\hookrightarrow$ \txnDataMod{} \lispDone {}} \label{hub: lookups: into txnData} \input{lookups/txn_into_txn_data} +\subsection{\hubMod{} $\hookrightarrow$ \rlpTxnMod{} \lispDone {}} \label{hub: lookups: into rlpTxn} \input{lookups/into_rlp_txn} +\subsection{\hubMod{} $\hookrightarrow$ \romMod{} for instruction fetching \lispDone {}} \label{hub: lookups: into rom: instruction fetching} \input{lookups/into_rom_instruction_fetching} +\subsection{\hubMod{} $\hookrightarrow$ \romMod{} for jump destination vetting \lispDone {}} \label{hub: lookups: into rom: jump destination vetting} \input{lookups/into_rom_jump_destination_vetting} +\subsection{\hubMod{} $\hookrightarrow$ \romLexMod{} \lispDone {}} \label{hub: lookups: into romLex} \input{lookups/acc_into_rom_lex} +\subsection{\hubMod{} $\hookrightarrow$ \idMod{} \lispDone {}} \label{hub: lookups: into instruction decoder} \input{lookups/into_instruction_decoder} +\subsection{\hubMod{} $\hookrightarrow$ \wcpMod{} for \suxSH{} detection \lispDone {}} \label{hub: lookups: into wcp for stack underflow} \input{lookups/into_wcp_for_stack_underflow} +\subsection{\hubMod{} $\hookrightarrow$ \wcpMod{} for \soxSH{} detection \lispDone {}} \label{hub: lookups: into wcp for stack overflow} \input{lookups/into_wcp_for_stack_overflow} +\subsection{\hubMod{} $\hookrightarrow$ \addMod{}, \binMod{}, \modMod{}, \mulMod{}, \shfMod{} and \wcpMod{} \lispDone {}} \label{hub: lookups: into the 2 argument stateless modules} \input{lookups/into_add_bin_mod_mul_shf_wcp} +\subsection{\hubMod{} $\hookrightarrow$ \extMod{} \lispDone {}} \label{hub: lookups: into ext} \input{lookups/into_ext} +\subsection{\hubMod{} $\hookrightarrow$ \btcMod{} \lispCommented {}} \label{hub: lookups: into block data} \input{lookups/into_block_data} +\subsection{\hubMod{} $\hookrightarrow$ \blockHashMod{} \lispCommented {}} \label{hub: lookups: into block hash} \input{lookups/into_block_hash} +\subsection{\hubMod{} $\hookrightarrow$ \trmMod{} \lispDone {}} \label{hub: lookups: into trm} \input{lookups/acc_into_trm} +\subsection{\hubMod{} $\hookrightarrow$ \expMod{} \lispDone {}} \label{hub: lookups: into exp} \input{lookups/misc_into_exp} +\subsection{\hubMod{} $\hookrightarrow$ \mmuMod{} \lispDone {}} \label{hub: lookups: into mmu} \input{lookups/misc_into_mmu} +\subsection{\hubMod{} $\hookrightarrow$ \mxpMod{} \lispDone {}} \label{hub: lookups: into mxp} \input{lookups/misc_into_mxp} +\subsection{\hubMod{} $\hookrightarrow$ \oobMod{} \lispCommented {}} \label{hub: lookups: into oob} \input{lookups/misc_into_oob} +\subsection{\hubMod{} $\hookrightarrow$ \stpMod{} \lispDone {}} \label{hub: lookups: into stp} \input{lookups/misc_into_stp} +\subsection{\hubMod{} $\hookrightarrow$ \gasMod{} \lispDone {}} \label{hub: lookups: into gas} \input{lookups/into_gas} +\subsection{\hubMod{} $\hookrightarrow$ \shakiraMod{} \lispDone {}} \label{hub: lookups: into shakira} \input{lookups/into_shakira} +\subsection{\hubMod{} $\hookrightarrow$ \rlpAddrMod{} \lispDone {}} \label{hub: lookups: into rlpAddr} \input{lookups/acc_into_rlp_addr} +\subsection{\hubMod{} $\hookrightarrow$ \logInfoMod{} \lispDone {}} \label{hub: lookups: into log info} \input{lookups/into_log_info} +\subsection{\hubMod{} $\hookrightarrow$ \hubMod{} \lispDone {}} \label{hub: lookups: hub into hub} \input{lookups/acc_into_sto} diff --git a/hub/lookups/_intro.tex b/hub/lookups/_intro.tex new file mode 100644 index 0000000..68b9c88 --- /dev/null +++ b/hub/lookups/_intro.tex @@ -0,0 +1,27 @@ +This section collects all the lookup arguments that connect the \hubMod{} module to other modules in the arithmetization. In order to specify a lookup we will typically provide the following data: +\begin{description} + \item[Selector column:] a binary column \col{sel} used to ``filter'' the rows of some (or all) input columns; + \item[Source columns:] a family of columns $(\col{SRC\_COL\_k})_{1 \leq k \leq \col{w}}$ from the source module (here: the \hubMod{} module); + \item[Target columns:] the corresponding family of columns $(\col{TGT\_COL\_k})_{1 \leq k \leq \col{w}}$ the target module; +\end{description} +The lookup will bypically prove the inclusion of the ``row selected'' row vectors +\[ + \Big( + \col{sel}_{i} \cdot \col{SRC\_1}_{i}, ~ + \col{sel}_{i} \cdot \col{SRC\_2}_{i}, ~ + \col{sel}_{i} \cdot \col{SRC\_3}_{i}, ~ + \dots, ~ + \col{sel}_{i} \cdot \col{SRC\_w}_{i} + \Big)_{0 \leq i \leq N} +\] +in the corresponding set of row vectors $(\col{TGT\_COL\_k})_{1 \leq k \leq \col{w}}$. +\[ + \Big( + \col{TGT\_1}_{j}, ~ + \col{TGT\_2}_{j}, ~ + \col{TGT\_3}_{j}, ~ + \dots, ~ + \col{TGT\_w}_{j} + \Big)_{0 \leq j \leq N'} +\] +\saNote{} The number of columns in the lookup \col{w} is the common width of both the (row selected) source matrix and target matrix. $N$ is the index of the last row in the source module (here: the \hubMod{} module) and $N'$ the index of the last row in the relevant target module. diff --git a/hub/lookups/_local.tex b/hub/lookups/_local.tex new file mode 100644 index 0000000..4276850 --- /dev/null +++ b/hub/lookups/_local.tex @@ -0,0 +1,4 @@ +\def\locAddressHi {\col{address\_hi}} +\def\locAddressLo {\col{address\_lo}} +\def\locStorageKeyHi {\col{key\_hi}} +\def\locStorageKeyLo {\col{key\_lo}} diff --git a/hub/lookups/acc_into_rlp_addr.tex b/hub/lookups/acc_into_rlp_addr.tex new file mode 100644 index 0000000..ea4c1f3 --- /dev/null +++ b/hub/lookups/acc_into_rlp_addr.tex @@ -0,0 +1,35 @@ +The present section describes the lookup between the \hubMod{} and the \rlpAddrMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekAccount \cdot \accRlpAddrFlag$ + \item[Source columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\accRlpAddrRecipe$ + \item $\accAddressHi$ + \item $\accAddressLo$ + \item $\accNonce$ + \item $\accRlpAddrDepAddrHi$ + \item $\accRlpAddrDepAddrLo$ + \item $\accRlpAddrSaltHi$ + \item $\accRlpAddrSaltLo$ + \item $\accRlpAddrKecHi$ + \item $\accRlpAddrKecLo$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\rlpAddrInst$ + \item $\addrHi$ + \item $\addrLo$ + \item $\nonce$ + \item $\depAddr\high$ + \item $\depAddr\low$ + \item $\salt\high$ + \item $\salt\low$ + \item $\kec\high$ + \item $\kec\low$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} The lookup provides the \rlpAddrMod{} module with the current nonce (i.e. pre-increment-by-one.) diff --git a/hub/lookups/acc_into_rom_lex.tex b/hub/lookups/acc_into_rom_lex.tex new file mode 100644 index 0000000..d10356d --- /dev/null +++ b/hub/lookups/acc_into_rom_lex.tex @@ -0,0 +1,41 @@ +The present section describes the lookup between the \hubMod{} and the \romLexMod{} module. +The $\accRomLexFlag$ flag turns on opportunistically (e.g. when performing a \inst{CALL}-type or \inst{CREATE}-type instruction. +In more detail: the \zkEvm{} turns on this flag whenever it is about to enter a new execution context and requires the associated \cfi{}. +\begin{description} + \item[Selector column:] we use the following selector: + \begin{enumerate} + \item \If $\peekAccount _{i} = 0$ \Then $\col{sel} _{i} = 0$ + \item \If $\peekAccount _{i} = 1$ \Then + \begin{enumerate} + \item \If $\accCodesize\new _{i} = 0$ \Then $\col{sel} _{i} = 0$ + \item \If $\accCodesize\new _{i} \neq 0$ \Then $\col{sel} _{i} = \accRomLexFlag _{i}$ + \end{enumerate} + \end{enumerate} + \item[Source columns:] --- + \begin{multicols}{4} + \begin{enumerate} + \item $\accCfi$ + \item $\accCodesize\new$ + \item $\accAddressHi$ + \item $\accAddressLo$ + \item $\accDepNum\new$ + \item $\accDepStatus\new$ + \item $\accCodehashHi$ + \item $\accCodehashLo$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{4} + \begin{enumerate} + \item $\cfi$ + \item $\codeSize$ + \item $\addrHi$ + \item $\addrLo$ + \item $\depNumber$ + \item $\depStatus$ + \item $\CH\high$ + \item $\CH\low$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} We use ``$\peekAccount \cdot \accHasCode \cdot \accRomLexFlag$'' as a selctor rather than ``$\peekAccount \cdot \accRomLexFlag$'' to prevent triggering the \romLexMod{} module with accounts that don't contain any code. diff --git a/hub/lookups/acc_into_sto.tex b/hub/lookups/acc_into_sto.tex new file mode 100644 index 0000000..d15a8c8 --- /dev/null +++ b/hub/lookups/acc_into_sto.tex @@ -0,0 +1,23 @@ +The present section describes an internal lookup within the \hubMod{} module. +It is used to establish coherence between two versions of the maximal deployment number associated with an address. +\begin{description} + \item[Selector column:] + there is a source selector and a target selector; + we directly include them into the lookup; + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\peekStorage \cdot \stoAddressHi$ + \item $\peekStorage \cdot \stoAddressLo$ + \item $\peekStorage \cdot \stoDeploymentNumber^\infty$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\peekAccount \cdot \accAddressHi$ + \item $\peekAccount \cdot \accAddressLo$ + \item $\peekAccount \cdot \accDepNumber^\infty$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/lookups/acc_into_trm.tex b/hub/lookups/acc_into_trm.tex new file mode 100644 index 0000000..12c8db6 --- /dev/null +++ b/hub/lookups/acc_into_trm.tex @@ -0,0 +1,23 @@ +The present section describes the lookup between the \hubMod{} and the \trmMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekAccount \cdot \accTrmFlag$ + \item[Source columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\accAddressHi$ + \item $\accAddressLo$ + \item $\accTrmRawAddrHi$ + \item $\accTrmIsPrecompile$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\trmAddrHi$ + \item $\rawAddrLo$ + \item $\rawAddrHi$ + \item $\isPrecompile$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/address_and_storage_key_shorthand_definitions.tex b/hub/lookups/address_and_storage_key_shorthand_definitions.tex new file mode 100644 index 0000000..2a99a4b --- /dev/null +++ b/hub/lookups/address_and_storage_key_shorthand_definitions.tex @@ -0,0 +1,17 @@ +\[ + \left\{ \begin{array}{lcl} + \locAddressHi & \define & + \left[ \begin{array}{lcl} + \peekAccount _{i} & \cdot & \accAddressHi _{i} \\ + \peekStorage _{i} & \cdot & \stoAddressHi _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locAddressLo & \define & + \left[ \begin{array}{lcl} + \peekAccount _{i} & \cdot & \accAddressLo _{i} \\ + \peekStorage _{i} & \cdot & \stoAddressLo _{i} \\ + \end{array} \right] \\ + \locStorageKeyHi & \define & \peekStorage _{i} \cdot \stoKeyHi _{i} \\ + \locStorageKeyLo & \define & \peekStorage _{i} \cdot \stoKeyLo _{i} \\ + \end{array} \right. +\] + diff --git a/hub/lookups/into_add_bin_mod_mul_shf_wcp.tex b/hub/lookups/into_add_bin_mod_mul_shf_wcp.tex new file mode 100644 index 0000000..639c347 --- /dev/null +++ b/hub/lookups/into_add_bin_mod_mul_shf_wcp.tex @@ -0,0 +1,47 @@ +\def\locUnexceptionalStackRow{\col{unexceptional\_stack\_row}} +The present section describes the lookup between the \hubMod{} and the \addMod{} module, the \binMod{} module, the \modMod{} module, the \mulMod{} module, the \shfMod{} module and the \wcpMod{} module. +The structure is the same for all of these, the only difference is the selector. +\begin{description} + \item[Selector column:] we define the following selectors as follows + \begin{center} + \begin{tabular}{lll} + for \textbf{\hubMod{} $\hookrightarrow${} \addMod} & we set & $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecAddFlag$ \\ + for \textbf{\hubMod{} $\hookrightarrow${} \binMod} & we set & $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecBinFlag$ \\ + for \textbf{\hubMod{} $\hookrightarrow${} \modMod} & we set & $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecModFlag$ \\ + for \textbf{\hubMod{} $\hookrightarrow${} \mulMod} & we set & $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecMulFlag$ \\ + for \textbf{\hubMod{} $\hookrightarrow${} \shfMod} & we set & $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecShfFlag$ \\ + for \textbf{\hubMod{} $\hookrightarrow${} \wcpMod} & we set & $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecWcpFlag$ \\ + \end{tabular} + \end{center} + where $\locUnexceptionalStackRow \define \peekStack \cdot (1 - \xAhoy)$ + \item[Source columns:] \hubMod{} columns: + \begin{multicols}{4} + \begin{enumerate} + \item $\stackInst$ + \item[\vspace{\fill}] + \item $\stackItemValHi{1}$ + \item $\stackItemValLo{1}$ + \item $\stackItemValHi{2}$ + \item $\stackItemValLo{2}$ + \item $\stackItemValHi{4}$ + \item $\stackItemValLo{4}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] (relevant module) columns: + \begin{multicols}{4} + \begin{enumerate} + \item $\INST$ + \item[\vspace{\fill}] + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resHi$ + \item $\resLo$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +The \wcpMod{} doesn't have a ``$\resHi$'' column. +For that module we omit $\stackItemValHi{4}$ from the source and ``$\resHi$'' from the target. +Recall from section~(\ref{hub: instruction handling: stateless: wcp high part is zero}) that for \wcpMod{}-instructions we impose the vanishing of the ``result's'' high part. diff --git a/hub/lookups/into_block_data.tex b/hub/lookups/into_block_data.tex new file mode 100644 index 0000000..ccad100 --- /dev/null +++ b/hub/lookups/into_block_data.tex @@ -0,0 +1,33 @@ +The present section describes the lookup between the \hubMod{} and the \btcMod{} module. +\begin{description} + \item[Row selector:] + we set + \[ + \col{sel}_{i} \define + \left[ \begin{array}{cr} + \cdot & \peekStack _{i} \\ + \cdot & (1 - \xAhoy _{i}) \\ + \cdot & \stackDecBtcFlag _{i} \\ + \cdot & (1 - \decFlag {1} _{i}) \\ + \end{array} \right] + \] + \item[Source columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\batchNum _{i}$ + \item $\stackInst _{i}$ + \item $\stackItemValHi {4} _{i}$ + \item $\stackItemValLo {4} _{i}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\relBlock _{j}$ + \item $\INST _{j}$ + \item $\blockDataHi _{j}$ + \item $\blockDataLo _{j}$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/into_block_hash.tex b/hub/lookups/into_block_hash.tex new file mode 100644 index 0000000..ddd482c --- /dev/null +++ b/hub/lookups/into_block_hash.tex @@ -0,0 +1,41 @@ +The present section describes the lookup between the \hubMod{} and the \btcMod{} module. +\begin{description} + \item[Row selector:] + we set + \[ + \col{sel}_{i} \define + \left[ \begin{array}{cr} + \cdot & \peekStack _{i} \\ + \cdot & (1 - \xAhoy _{i}) \\ + \cdot & \stackDecBtcFlag _{i} \\ + \cdot & \decFlag {1} _{i} \\ + \end{array} \right] + \] + \saNote{} + Recall from section~(\ref{hub: instruction handling: btc}) that, + along stack-rows ($\peekStack \equiv 1$), + the conjunction of $\stackDecBtcFlag \equiv 1$ and $\decFlag{1} \equiv 1$ + characterizes the \inst{BLOCKHASH} opcode. + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\batchNum _{i}$ + \item[\vspace{\fill}] + \item $\stackItemValHi{1} _{i}$ + \item $\stackItemValLo{1} _{i}$ + \item $\stackItemValHi{4} _{i}$ + \item $\stackItemValLo{4} _{i}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\relBlock _{j}$ + \item[\vspace{\fill}] + \item $\blockNumber\high _{j}$ + \item $\blockNumber\low _{j}$ + \item $\resHi _{j}$ + \item $\resLo _{j}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/lookups/into_ext.tex b/hub/lookups/into_ext.tex new file mode 100644 index 0000000..e5d7396 --- /dev/null +++ b/hub/lookups/into_ext.tex @@ -0,0 +1,35 @@ +The present section describes the lookup between the \hubMod{} and the \extMod{} module. Instructions dealt with in the \extMod{} module (that is: \inst{ADDMOD} and \inst{MULMOD}) differ from instructions dealt with in the modules from the last subsection in that they require \textbf{three} stack arguments. Otherwise the structure of the lookups is nearly identical. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \locUnexceptionalStackRow \cdot \stackDecAddFlag \stackDecExtFlag$ + \item[Source columns:] --- + \begin{multicols}{5} + \begin{enumerate} + \item $\stackInst$ + \item[\vspace{\fill}] + \item $\stackItemValHi{1}$ + \item $\stackItemValLo{1}$ + \item $\stackItemValHi{2}$ + \item $\stackItemValLo{2}$ + \item $\stackItemValHi{3}$ + \item $\stackItemValLo{3}$ + \item $\stackItemValHi{4}$ + \item $\stackItemValLo{4}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{5} + \begin{enumerate} + \item $\INST$ + \item[\vspace{\fill}] + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\argTreHi$ + \item $\argTreLo$ + \item $\resHi$ + \item $\resLo$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/into_gas.tex b/hub/lookups/into_gas.tex new file mode 100644 index 0000000..52c6753 --- /dev/null +++ b/hub/lookups/into_gas.tex @@ -0,0 +1,33 @@ +The present section details at which points in time we check gas. +We exclude from this analysis +(\emph{a}) the gas check performed at the onset of a transaction +(\emph{b}) the gas check performed with every \inst{SSTORE}-instruction (i.e. checking that the currently available gas is $> G_{\text{callstipend}} = 2300$.) +The first happens in the \txnDataMod{} module. +The second is triggered automatically with every \inst{SSTORE} instruction (that doesn't raise simpler exceptions such as \suxSH{} or \staticxSH{} first.) +It is carried out by the \oobMod{} module which thereby justifes the \sstorexSH{}. + +\saNote{} We don't perform a ``full'' gas check if the \mxpxSH{} is triggered (i.e. $\mxpx = 1$.) +All we check in this case is that the gas is nonnegative. +The point of the \mxpxSH{} (which really is a subcase of the \oogxSH{}) and its associated exception flag $\stackMxpx$ is to avoid comparisons against potentially large integers which may appear because of the quadratic part of memory expansion costs. + +The present section describes the lookup between the \hubMod{} and the \gasMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \cmc \cdot \peekStack$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\gasActual$ + \item $\gasCost$ + \item $\stackOogx$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\gasActual$ + \item $\gasCost$ + \item $\oogx$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} We require the lookup to happen on stack-rows (raising the \cmc{} flag) since stack-rows are where the \zkEvm{} can access the \stackOogx{} flag. diff --git a/hub/lookups/into_instruction_decoder.tex b/hub/lookups/into_instruction_decoder.tex new file mode 100644 index 0000000..1f250e4 --- /dev/null +++ b/hub/lookups/into_instruction_decoder.tex @@ -0,0 +1,88 @@ +The present section describes the lookup between the \hubMod{} and the \addMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekStack$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\stackInst$ + \item $\tli$ + \item $\stackStaticGas$ + \item $\stackAlpha$ + \item $\stackDelta$ + \item $\stackNbRemove$ + \item $\stackNbAdd$ + \item $\stackDecMxpFlag$ + \item $\stackDecStaticFlag$ + \item $\decFlag{1}$ + \item $\decFlag{2}$ + \item $\decFlag{3}$ + \item $\decFlag{4}$ + \item $\stackDecAccFlag$ + \item $\stackDecAddFlag$ + \item $\stackDecBinFlag$ + \item $\stackDecBtcFlag$ + \item $\stackDecConFlag$ + \item $\stackDecCopyFlag$ + \item $\stackDecDupFlag$ + \item $\stackDecExtFlag$ + \item $\stackDecHaltFlag$ + \item $\stackDecInvalidFlag$ + \item $\stackDecJumpFlag$ + \item $\stackDecKecFlag$ + \item $\stackDecLogFlag$ + \item $\stackDecMachineStateFlag$ + \item $\stackDecModFlag$ + \item $\stackDecMulFlag$ + \item $\stackDecPushPopFlag$ + \item $\stackDecShfFlag$ + \item $\stackDecStackRamFlag$ + \item $\stackDecStoFlag$ + \item $\stackDecSwapFlag$ + \item $\stackDecTxnFlag$ + \item $\stackDecWcpFlag$ + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\INST$ + \item $\tli$ + \item $\staticGas$ + \item $\idAlpha$ + \item $\idDelta$ + \item $\idNbRemove$ + \item $\idNbAdd$ + \item $\mxpFlag$ + \item $\staticFlag$ + \item $\flagColumn{1}$ + \item $\flagColumn{2}$ + \item $\flagColumn{3}$ + \item $\flagColumn{4}$ + \item $\accFlag$ + \item $\addFlag$ + \item $\binFlag$ + \item $\btcFlag$ + \item $\conFlag$ + \item $\copyFlag$ + \item $\dupFlag$ + \item $\extFlag$ + \item $\haltFlag$ + \item $\invalidFlag$ + \item $\jumpFlag$ + \item $\kecFlag$ + \item $\logFlag$ + \item $\machineStateFlag$ + \item $\modFlag$ + \item $\mulFlag$ + \item $\pushPopFlag$ + \item $\shfFlag$ + \item $\stackRamFlag$ + \item $\stoFlag$ + \item $\swapFlag$ + \item $\txnFlag$ + \item $\wcpFlag$ + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/lookups/into_log_info.tex b/hub/lookups/into_log_info.tex new file mode 100644 index 0000000..71f4703 --- /dev/null +++ b/hub/lookups/into_log_info.tex @@ -0,0 +1,51 @@ +The present section describes the lookup between the \hubMod{} and the \logInfoMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel}_{i} \define \peekStack_{i} \cdot \stackLogFlag_{i} \cdot (1 - \ct_{i})$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\absTxNum_{i}$ + \item $\logStamp_{i}$ + \item $\stackInst_{i}$ + \item $\cnAccountAddress\high_{i + 2}$ + \item $\cnAccountAddress\low _{i + 2}$ + \item $\stackItemValHi{1}_{i + 1}$ + \item $\stackItemValLo{1}_{i + 1}$ + \item $\stackItemValHi{2}_{i + 1}$ + \item $\stackItemValLo{2}_{i + 1}$ + \item $\stackItemValHi{3}_{i + 1}$ + \item $\stackItemValLo{3}_{i + 1}$ + \item $\stackItemValHi{4}_{i + 1}$ + \item $\stackItemValLo{4}_{i + 1}$ + \item[\vspace{\fill}] + \item $\stackItemValLo{2}_{i}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\absTxNum_{i}$ + \item $\absLogNum_{j}$ + \item $\INST_{j}$ + \item $\addrHi_{j}$ + \item $\addrLo_{j}$ + \item $\topicHi{1}_{j}$ + \item $\topicLo{1}_{j}$ + \item $\topicHi{2}_{j}$ + \item $\topicLo{2}_{j}$ + \item $\topicHi{3}_{j}$ + \item $\topicLo{3}_{j}$ + \item $\topicHi{4}_{j}$ + \item $\topicLo{4}_{j}$ + \item[\vspace{\fill}] + \item $\logDataSize_{j}$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} The chosen selector flag thus selects the first ($\ct \equiv 0$) stack row ($\peekStack \equiv 1$) of an unexceptional, unreverted \inst{LOG}-type instruction ($\stackLogFlag \equiv 1$.) + +\saNote{} \ob{TODO: are we getting the \logDataSize{} from the correct stack item ?} + +\saNote{} \ob{TODO: are we getting the right address ? Yes: it's $I_\text{a}$ in the spec, that is $\cnAccountAddress$ for us.} + +\saNote{} \ob{TODO: the \logInfoMod{} expects more data ! Where should we get \absLogNumMax{} from ? What about $\absTxNumMax$ ? The latter is likely available in the \hubMod{} ?} diff --git a/hub/lookups/into_rlp_txn.tex b/hub/lookups/into_rlp_txn.tex new file mode 100644 index 0000000..682d596 --- /dev/null +++ b/hub/lookups/into_rlp_txn.tex @@ -0,0 +1,38 @@ +The present section describes the lookup between the \hubMod{} and the \rlpTxnMod{} module. +This lookup allows the \hubMod{} to learn about which (account) addresses and storage keys to pre-warm during the \txWarm-phase. +\begin{description} + \item[Source selector column:] + we use the following selector: $\col{sel} \define \txWarm$ + \item[Source columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $1$ + \item $\absTxNum$ + \item $\peekAccount$ + \item $\peekStorage$ + \item $\locAddressHi$ + \item $\locAddressLo$ + \item $\locStorageKeyHi$ + \item $\locStorageKeyLo$ + \end{enumerate} + \end{multicols} + where we used the following shorthands + \input{lookups/address_and_storage_key_shorthand_definitions} + \item[Target selector column:] + we use the following selector: $\col{sel} \define \phaseAccessList \cdot \txRequiresEvmExecution$ + \item[Target columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $1$ + \item $\absTxNum$ + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \item $1 - \Depth{2}$ + \item $\Depth{2}$ + \item $\addr\high$ + \item $\addr\low $ + \item $\Input{1} \cdot \Depth{2}$ + \item $\Input{2} \cdot \Depth{2}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/lookups/into_rom_instruction_fetching.tex b/hub/lookups/into_rom_instruction_fetching.tex new file mode 100644 index 0000000..710e85d --- /dev/null +++ b/hub/lookups/into_rom_instruction_fetching.tex @@ -0,0 +1,27 @@ +The present section describes the lookup between the \hubMod{} and the \romMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekStack$ + \item[Source columns:] \hubMod{} columns: + \begin{multicols}{3} + \begin{enumerate} + \item \cfi{} + \item \pc{} + \item \stackInst{} + \item[\vspace{\fill}] + \item \stackPushParamHi{} + \item \stackPushParamLo{} + \end{enumerate} + \end{multicols} + \item[Target columns:] \romMod{} columns: + \begin{multicols}{3} + \begin{enumerate} + \item \cfi{} + \item \pc{} + \item \INST{} + \item[\vspace{\fill}] + \item \pushParamHi{} + \item \pushParamLo{} + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/into_rom_jump_destination_vetting.tex b/hub/lookups/into_rom_jump_destination_vetting.tex new file mode 100644 index 0000000..96b6d5b --- /dev/null +++ b/hub/lookups/into_rom_jump_destination_vetting.tex @@ -0,0 +1,24 @@ +The present section describes the lookup between the \hubMod{} and the \romMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekStack \cdot \stackJumpDestinationVetting$ + \saNote{} We refer the reader to section~(\ref{hub: generalities: setting the jump destination vetting flag}) for the specification of the $\stackJumpDestinationVetting$ flag. + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item \cfi{} + \item $\stackItemValLo{1}$ + \item $1 - \stackJumpx$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item \cfi{} + \item \pc{} + \item \ISVALIDJUMPDESTINATION{} + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +For \inst{JUMP}-type instructions the (potential) new jump destination is stored in the first stack item. +If its high part is nonzero the \oobMod{} throws an exception and the above isn't triggered. diff --git a/hub/lookups/into_shakira.tex b/hub/lookups/into_shakira.tex new file mode 100644 index 0000000..2757479 --- /dev/null +++ b/hub/lookups/into_shakira.tex @@ -0,0 +1,33 @@ +The present section describes the lookup between the \hubMod{} and the \shakiraMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel}_{i} \define \peekStack_{i} \cdot \stackHashInfoFlag_{i}$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\phaseKeccakResult$ + \item $1 + \hubStamp_{i}$ + \item $1$ + \item[\vspace{\fill}] + % \item $\stackHashInfoSize_{i}$ + \item $\stackHashInfoValHi_{i}$ + \item $\stackHashInfoValLo_{i}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\shakiraPhase_{j}$ + \item $\shakiraId_{j}$ + \item $\index_{j}$ + \item[\vspace{\fill}] + % \item $\shakiraTotalSize_{j}$ + \item $\limb_{j - 1}$ + \item $\limb_{j}$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +The \shakiraMod{}'s ``$\phaseKeccakResult$'' phase occupies two rows where \index{} will take on the values $0$ and $1$ respectively\footnote{This phase is followed by some ``extra-rows''}. +The first of these rows, characterized by $\index \equiv 0$ contains the high part of the result in the \limb{} column. +The second of these rows, characterized by $\index \equiv 1$ contains the low part of the result in the \limb{} column. +The lookup we describe above targets the second row and grabs the high and low parts in the first and second row respectively. diff --git a/hub/lookups/into_wcp_for_stack_overflow.tex b/hub/lookups/into_wcp_for_stack_overflow.tex new file mode 100644 index 0000000..ba179d1 --- /dev/null +++ b/hub/lookups/into_wcp_for_stack_overflow.tex @@ -0,0 +1,41 @@ +\def\locSoxDetectionSelector{\col{sox\_sel}} +\def\locProjectedHeight{\col{projected\_height}} +The present section describes the two lookups between the \hubMod{} and the \wcpMod{} module which are used to detect \suxSH{}'s and \soxSH{}'s. +The lookup below justifies the $\stackSox$ exception flag. +\begin{description} + \item[Selector column:] we define the following selectors as follows + \[ + \locSoxDetectionSelector \define \peekStack \cdot (1 - \stackSux) + \] + \item[Source columns:] \hubMod{} columns: + \begin{multicols}{4} + \begin{enumerate} + \item $\inst{GT}$ + \item[\vspace{\fill}] + \item $0$ + \item $\locProjectedHeight$ + \item $0$ + \item $1024$ + \item $\stackSox$ + \end{enumerate} + \end{multicols} + where we have used the following shorthand + \[ + \locProjectedHeight + \define + \height - \stackDelta + \stackAlpha + \] + \item[Target columns:] \wcpMod{} columns: + \begin{multicols}{4} + \begin{enumerate} + \item $\INST$ + \item[\vspace{\fill}] + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/into_wcp_for_stack_underflow.tex b/hub/lookups/into_wcp_for_stack_underflow.tex new file mode 100644 index 0000000..8b99c0f --- /dev/null +++ b/hub/lookups/into_wcp_for_stack_underflow.tex @@ -0,0 +1,34 @@ +\def\locSuxDetectionSelector{\col{sux\_sel}} +The present section describes the two lookups between the \hubMod{} and the \wcpMod{} module which are used to detect \suxSH{}'s and \soxSH{}'s. +The lookup below justifies the $\stackSux$ exception flag. +\begin{description} + \item[Selector column:] we define the following selectors as follows + \[ + \locSuxDetectionSelector \define \peekStack + \] + \item[Source columns:] \hubMod{} columns: + \begin{multicols}{4} + \begin{enumerate} + \item $\inst{LT}$ + \item[\vspace{\fill}] + \item $0$ + \item $\height$ + \item $0$ + \item $\stackDelta$ + \item $\stackSux$ + \end{enumerate} + \end{multicols} + \item[Target columns:] \wcpMod{} columns: + \begin{multicols}{4} + \begin{enumerate} + \item $\INST$ + \item[\vspace{\fill}] + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/misc_into_exp.tex b/hub/lookups/misc_into_exp.tex new file mode 100644 index 0000000..1d0fd52 --- /dev/null +++ b/hub/lookups/misc_into_exp.tex @@ -0,0 +1,21 @@ +The present section describes the lookup between the \hubMod{} and the \expMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekMisc \cdot \miscExpFlag$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\col{sel}$ + \item $\miscExpInstruction$ + \item $\miscExpDataCol{k}$, $k=1,2,\dots,5$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\isMacro$ + \item $\expMacroInst$ + \item $\expMacroData{k}$, $k=1,2,\dots,5$ + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/misc_into_mmu.tex b/hub/lookups/misc_into_mmu.tex new file mode 100644 index 0000000..87f7434 --- /dev/null +++ b/hub/lookups/misc_into_mmu.tex @@ -0,0 +1,51 @@ +The present section describes the lookup between the \hubMod{} and the \mmuMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekMisc \cdot \miscMmuFlag$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item \col{sel} + \item \mmuStamp{} + \item \miscMmuInst{} + \item \miscMmuSrcId{} + \item \miscMmuTgtId{} + \item \miscMmuAuxId{} + \item \miscMmuSrcOffsetHi{} + \item \miscMmuSrcOffsetLo{} + \item \miscMmuTgtOffsetLo{} + \item \miscMmuSize{} + \item \miscMmuRefOffset{} + \item \miscMmuRefSize{} + \item \miscMmuSuccessBit{} + \item \miscMmuLimbOne{} + \item \miscMmuLimbTwo{} + \item \miscMmuPhase{} + \item \miscMmuExoSum{} + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\isMacro$ + \item \mmuStamp{} + \item \macroInst{} + \item \macroSrcId{} + \item \macroTgtId{} + \item \macroAuxId{} + \item \macroSrcOffsetHi{} + \item \macroSrcOffsetLo{} + \item \macroTgtOffsetLo{} + \item \macroSize{} + \item \macroRefOffset{} + \item \macroRefSize{} + \item \macroSuccessBit{} + \item \macroLimbOne{} + \item \macroLimbTwo{} + \item \macroPhase{} + \item \macroExoSum{} + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/misc_into_mxp.tex b/hub/lookups/misc_into_mxp.tex new file mode 100644 index 0000000..333391c --- /dev/null +++ b/hub/lookups/misc_into_mxp.tex @@ -0,0 +1,50 @@ +The present section describes the lookup between the \hubMod{} and the \mxpMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekMisc \cdot \miscMxpFlag$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item \mxpStamp{} + \item \cn{} + \item \miscMxpMxpx{} + \item \miscMxpInst{} + \item \miscMxpCodeDeployment{} + \item \miscMxpOffsetOneHi{} + \item \miscMxpOffsetOneLo{} + \item \miscMxpOffsetTwoHi{} + \item \miscMxpOffsetTwoLo{} + \item \miscMxpSizeOneHi{} + \item \miscMxpSizeOneLo{} + \item \miscMxpSizeTwoHi{} + \item \miscMxpSizeTwoLo{} + \item \miscMxpTypeFourInstMayTriggerMmu{} + \item \miscMxpWords{} + \item \miscMxpGasMxp{} + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\mxpStamp$ + \item $\cn$ + \item $\mxpx$ + \item $\INST$ + \item $\codeDeployment$ + \item $\offsetHi{1}$ + \item $\offsetLo{1}$ + \item $\offsetHi{2}$ + \item $\offsetLo{2}$ + \item $\sizeHi{1}$ + \item $\sizeLo{1}$ + \item $\sizeHi{2}$ + \item $\sizeLo{2}$ + \item $\mayTriggerNonTrivialOperation$ + \item $\memSize$ + \item $\gasMxp$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/lookups/misc_into_oob.tex b/hub/lookups/misc_into_oob.tex new file mode 100644 index 0000000..8b4be3a --- /dev/null +++ b/hub/lookups/misc_into_oob.tex @@ -0,0 +1,38 @@ +The present section describes the lookup between the \hubMod{} and the \oobMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekMisc \cdot \miscOobFlag$ + \item[Source columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\miscOobInst$ + \item $\miscOobDataCol{1}$ + \item $\miscOobDataCol{2}$ + \item $\miscOobDataCol{3}$ + \item $\miscOobDataCol{4}$ + \item $\miscOobDataCol{5}$ + \item $\miscOobDataCol{6}$ + \item $\miscOobDataCol{7}$ + \item $\miscOobDataCol{8}$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item \oobInstruction{} + \item \oobDataCol{1} + \item \oobDataCol{2} + \item \oobDataCol{3} + \item \oobDataCol{4} + \item \oobDataCol{5} + \item \oobDataCol{6} + \item \oobDataCol{7} + \item \oobDataCol{8} + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/lookups/misc_into_stp.tex b/hub/lookups/misc_into_stp.tex new file mode 100644 index 0000000..81bc774 --- /dev/null +++ b/hub/lookups/misc_into_stp.tex @@ -0,0 +1,47 @@ +The present section describes the lookup between the \hubMod{} and the \stpMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekMisc \cdot \miscStpFlag$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\miscStpInst$ + \item $\miscStpGasHi$ + \item $\miscStpGasLo$ + \item $\miscStpValueHi$ + \item $\miscStpValueLo$ + \item $\miscStpAccExists$ + \item $\miscStpAccWarmth$ + \item $\miscStpOogx$ + \item $\gasActual$ + % \item $\gasCost$ + \item $\miscStpGasMxp$ + \item $\miscStpGasUpfront$ + \item $\miscStpGasPoop$ + \item $\miscStpGasStipend$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\INST$ + \item $\gasHi$ + \item $\gasLo$ + \item $\valueHi$ + \item $\valueLo$ + \item $\existence$ + \item $\warm$ + \item $\oogx$ + \item $\gasActual$ + % \item $\gasCost$ + \item $\gasMxp$ + \item $\gasPoop$ + \item $\gasUpfront$ + \item $\gasStipend$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/hub/lookups/txn_into_txn_data.tex b/hub/lookups/txn_into_txn_data.tex new file mode 100644 index 0000000..0b78b20 --- /dev/null +++ b/hub/lookups/txn_into_txn_data.tex @@ -0,0 +1,76 @@ +The present section describes the lookup between the \hubMod{} and the \txnDataMod{} module. +\begin{description} + \item[Selector column:] we use the following selector: $\col{sel} \define \peekTransaction$ + \item[Source columns:] --- + \begin{multicols}{3} + \begin{enumerate} + % numbers + \item $\absTxNum$ + \item $\batchNum$ + % addresses + \item $\txFrom\high$ + \item $\txFrom\low$ + \item $\txTo\high$ + \item $\txTo\low$ + \item $\txCoinbase\high$ + \item $\txCoinbase\low$ + % tx values + \item $\txNonce$ + \item $\txValue$ + \item $\txIsDeployment$ + \item $\txIsTypeTwo$ + \item $\txGasPrice$ + \item $\txPriorityFeePerGas$ + \item $\txBasefee$ + \item $\txCallDataSize$ + \item $\txInitCodeSize$ + % directly relevant to hub + \item $\txInitialGas$ + \item $\txInitialBalance$ + \item $\txRequiresEvmExecution$ + \item $\txCopyTxcd$ + % end of tx extracted data + \item $\txStatusCode$ + \item $\txLeftoverGas$ + \item $\txFinalRefundCounter$ + \item $\txEffectiveRefund$ + % \item $\cfi$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{3} + \begin{enumerate} + % numbers + \item $\absTxNum$ + \item $\txBatchNum$ + % addresses + \item $\txFrom\high$ + \item $\txFrom\low$ + \item $\txTo\high$ + \item $\txTo\low$ + \item $\txCoinbase\high$ + \item $\txCoinbase\low$ + % tx values + \item $\txNonce$ + \item $\txValue$ + \item $\txIsDeployment$ + \item $\txIsTypeTwo$ + \item $\txGasPrice$ + \item $\txPriorityFeePerGas$ + \item $\txBasefee$ + \item $\txCallDataSize$ + \item $\txInitCodeSize$ + % directly relevant to hub + \item $\txInitialGas$ + \item $\txInitialBalance$ + \item $\txRequiresEvmExecution$ + \item $\txCopyTxcd$ + % end of tx prediction + \item $\txStatusCode$ + \item $\txLeftoverGas$ + \item $\txFinalRefundCounter$ + \item $\txEffectiveRefund$ + % \item $\cfi$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/hub/misc/_inputs.tex b/hub/misc/_inputs.tex new file mode 100644 index 0000000..a511eda --- /dev/null +++ b/hub/misc/_inputs.tex @@ -0,0 +1,7 @@ +\section{Miscellaneous-rows} +\subsection{$\miscSignifier\separator\expMod$ constraints \lispDone{}} \label{hub: miscellaneous constraints: exp} \input{misc/exp/_inputs} +\subsection{$\miscSignifier\separator\mxpMod$ constraints \lispDone{}} \label{hub: miscellaneous constraints: mxp} \input{misc/mxp/_inputs} +\subsection{$\miscSignifier\separator\mmuMod$ constraints \lispDone{}} \label{hub: miscellaneous constraints: mmu} \input{misc/mmu/_inputs} +\subsection{$\miscSignifier\separator\oobMod$ constraints \lispDone{}} \label{hub: miscellaneous constraints: oob} \input{misc/oob/_inputs} +\subsection{$\miscSignifier\separator\stpMod$ constraints \lispDone{}} \label{hub: miscellaneous constraints: stp} \input{misc/stp/_inputs} +\subsection{$\weightedMiscFlagSum {i}{\relof}$ definition \lispDone{}} \label{hub: miscellaneous constraints: weighted flag sum} \input{misc/flag_sum} diff --git a/hub/misc/exp/_general.tex b/hub/misc/exp/_general.tex new file mode 100644 index 0000000..5dcfd89 --- /dev/null +++ b/hub/misc/exp/_general.tex @@ -0,0 +1,25 @@ +We define a family of constraints parametrized by a \textbf{(small) nonnegative integer} $\relof$. +Variations of this one constraint will be presented in the coming subsections. +These constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setExpInstruction {i}{\relof} + \left[ \begin{array}{ll} + \multicolumn{2}{l}{\utt{\expMod{} instruction:} ~ \col{exp\_inst}} \vspace{2mm} \\ + \utt{Data 1:} & \col{data\_1} \\ + \utt{Data 2:} & \col{data\_2} \\ + \utt{Data 3:} & \col{data\_3} \\ + \utt{Data 4:} & \col{data\_4} \\ + \utt{Data 5:} & \col{data\_5} \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \define + \left\{ \begin{array}{lcl} + \miscExpInstruction _{i + \relof} & = & \col{exp\_inst} \vspace{2mm} \\ + \miscExpDataCol {1} _{i + \relof} & = & \col{data\_1} \\ + \miscExpDataCol {2} _{i + \relof} & = & \col{data\_2} \\ + \miscExpDataCol {3} _{i + \relof} & = & \col{data\_3} \\ + \miscExpDataCol {4} _{i + \relof} & = & \col{data\_4} \\ + \miscExpDataCol {5} _{i + \relof} & = & \col{data\_5} \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/hub/misc/exp/_inputs.tex b/hub/misc/exp/_inputs.tex new file mode 100644 index 0000000..62c9520 --- /dev/null +++ b/hub/misc/exp/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsection{The general $\setExpInstruction {i}{\relof}$ template} \label{hub: misc: exp: general} \input{misc/exp/_general} + +\subsubsection{\expMod{} instruction templates} +\subsubsubsection{$\setExpInstructionParametersExpLog {i}{\relof}$ constraints \lispDone{}} \label{hub: misc: exp: exp log} \input{misc/exp/exp_log} +\subsubsubsection{$\setExpInstructionParametersModexpLog {i}{\relof}$ constraints \lispDone{}} \label{hub: misc: exp: modexp log} \input{misc/exp/modexp_log} diff --git a/hub/misc/exp/exp_log.tex b/hub/misc/exp/exp_log.tex new file mode 100644 index 0000000..16dd94d --- /dev/null +++ b/hub/misc/exp/exp_log.tex @@ -0,0 +1,18 @@ +\[ + \left\{ \begin{array}{l} + \setExpInstructionParametersExpLog {i}{\relof} + \left[ \begin{array}{ll} + \utt{Exponent high:} & \col{exponent\_hi} \\ + \utt{Exponent low:} & \col{exponent\_lo} \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \define + \left\{ \begin{array}{lclr} + \miscExpInstruction _{i + \relof} & = & \expInstExpLog \vspace{2mm} \\ + \miscExpDataCol {1} _{i + \relof} & = & \col{exponent\_hi} \\ + \miscExpDataCol {2} _{i + \relof} & = & \col{exponent\_lo} \\ + \miscExpDataCol {3} _{i + \relof} & = & \nothing \\ + \miscExpDataCol {4} _{i + \relof} & = & \nothing \\ + \miscExpDataCol {5} _{i + \relof} & = & \col{dynamic\_gas} & \prediction \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/hub/misc/exp/modexp_log.tex b/hub/misc/exp/modexp_log.tex new file mode 100644 index 0000000..4710cf2 --- /dev/null +++ b/hub/misc/exp/modexp_log.tex @@ -0,0 +1,20 @@ +\[ + \left\{ \begin{array}{l} + \setExpInstructionParametersModexpLog {i}{\relof} + \left[ \begin{array}{ll} + \utt{Raw leading word high:} & \col{raw\_lead\_hi} \\ + \utt{Raw leading word low:} & \col{raw\_lead\_lo} \\ + \utt{Call data offset cutoff:} & \col{cds\_cutoff} \\ + \utt{Exponent byte size cutoff:} & \col{ebs\_cutoff} \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \define + \left\{ \begin{array}{lclr} + \miscExpInstruction _{i + \relof} & = & \expInstModexpLog \vspace{2mm} \\ + \miscExpDataCol {1} _{i + \relof} & = & \col{raw\_lead\_hi} \\ + \miscExpDataCol {2} _{i + \relof} & = & \col{raw\_lead\_lo} \\ + \miscExpDataCol {3} _{i + \relof} & = & \col{cds\_cutoff} \\ + \miscExpDataCol {4} _{i + \relof} & = & \col{ebs\_cutoff} \\ + \miscExpDataCol {5} _{i + \relof} & = & \col{lead\_log} & \prediction \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/hub/misc/flag_sum.tex b/hub/misc/flag_sum.tex new file mode 100644 index 0000000..56ad169 --- /dev/null +++ b/hub/misc/flag_sum.tex @@ -0,0 +1,23 @@ +We introduce some numerical constants and constraints. +\[ + \left\{ \begin{array}{lcl} + \miscExpWeight & \define & 2^{0} \\ + \miscMmuWeight & \define & 2^{1} \\ + \miscMxpWeight & \define & 2^{2} \\ + \miscOobWeight & \define & 2^{3} \\ + \miscStpWeight & \define & 2^{4} \\ + \end{array} \right. +\] +and we define the following shorthand (which assumes that $i$ is the row-index of a miscellaneous-row) +\[ + \weightedMiscFlagSum + {i}{\relof} + \define + \left[ \begin{array}{lcl} + \miscExpWeight & \cdot & \miscExpFlag _{i + \relof} \\ + \miscMmuWeight & \cdot & \miscMmuFlag _{i + \relof} \\ + \miscMxpWeight & \cdot & \miscMxpFlag _{i + \relof} \\ + \miscOobWeight & \cdot & \miscOobFlag _{i + \relof} \\ + \miscStpWeight & \cdot & \miscStpFlag _{i + \relof} \\ + \end{array} \right] +\] diff --git a/hub/misc/mmu/_general.tex b/hub/misc/mmu/_general.tex new file mode 100644 index 0000000..8f9a671 --- /dev/null +++ b/hub/misc/mmu/_general.tex @@ -0,0 +1,49 @@ +Throughout $\relof$ will stand for some \textbf{(small) nonnegative integer}. +We define a family of constraints \setMmuInstructionName{} parametrized by $\relof \in \mathbb{N}$. +Variations of this one constraint will be presented in the coming subsections. + +\saNote{} The \setMmuInstructionName{} constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setMmuInstruction { + anchorRow = i , + relOffset = \relof , + mmuInstruction = \col{\mmuMod\_inst} , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \col{aux\_id} , + sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \col{tgt\_offset\_lo} , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + successBit = \col{success\_bit} , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + exoSum = \col{exo\_sum} , + phase = \col{phase} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \left\{ \begin{array}{lcl} + \miscMmuInst _{i + \relof} & = & \col{\mmuMod\_inst} \vspace{2mm} \\ + \miscMmuSrcId _{i + \relof} & = & \col{src\_id} \\ + \miscMmuTgtId _{i + \relof} & = & \col{tgt\_id} \\ + \miscMmuAuxId _{i + \relof} & = & \col{aux\_id} \\ + \miscMmuSrcOffsetHi _{i + \relof} & = & \col{src\_offset\_hi} \\ + \miscMmuSrcOffsetLo _{i + \relof} & = & \col{src\_offset\_lo} \\ + \miscMmuTgtOffsetLo _{i + \relof} & = & \col{tgt\_offset\_lo} \\ + \miscMmuSize _{i + \relof} & = & \col{size} \\ + \miscMmuRefOffset _{i + \relof} & = & \col{ref\_offset} \\ + \miscMmuRefSize _{i + \relof} & = & \col{ref\_size} \\ + \miscMmuSuccessBit _{i + \relof} & = & \col{success\_bit} \\ + \miscMmuLimbOne _{i + \relof} & = & \col{limb\_1} \\ + \miscMmuLimbTwo _{i + \relof} & = & \col{limb\_2} \\ + \miscMmuPhase _{i + \relof} & = & \col{exo\_sum} \\ + \miscMmuExoSum _{i + \relof} & = & \col{phase} \\ + \end{array} \right. + \end{array} \right. +\] +We will be defining shorthands for particular instances of the above general definition. +See section~(\ref{mmu: mmu / mmio interface}) for the usecases of these so-called ``\mmuMod{}-instructions.'' diff --git a/hub/misc/mmu/_inputs.tex b/hub/misc/mmu/_inputs.tex new file mode 100644 index 0000000..eb7392d --- /dev/null +++ b/hub/misc/mmu/_inputs.tex @@ -0,0 +1,15 @@ +\subsubsection{The general $\setMmuInstructionName$ template} \label{hub: misc: general} \input{misc/mmu/_general} + +\subsubsection{\mmuMod{} instruction templates} +\subsubsubsection{$\setMmuInstructionParametersMloadName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: mload} \input{misc/mmu/mload} +\subsubsubsection{$\setMmuInstructionParametersMstoreName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: mstore} \input{misc/mmu/mstore} +\subsubsubsection{$\setMmuInstructionParametersMstoreEightName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: mstoreEight} \input{misc/mmu/mstore_eight} +\subsubsubsection{$\setMmuInstructionParametersInvalidCodePrefixName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: invalidCodePrefix} \input{misc/mmu/invalid_code_prefix} +\subsubsubsection{$\setMmuInstructionParametersRightPaddedWordExtractionName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: rightPaddedWordExtraction} \input{misc/mmu/right_padded_word_extraction} +\subsubsubsection{$\setMmuInstructionParametersRamToExoWithPaddingName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: ramToExoWithPadding} \input{misc/mmu/ram_to_exo_with_padding} +\subsubsubsection{$\setMmuInstructionParametersExoToRamTransplantsName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: exoToRamTransplants} \input{misc/mmu/exo_to_ram_transplants} +\subsubsubsection{$\setMmuInstructionParametersRamToRamSansPaddingName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: ramToRamSansPadding} \input{misc/mmu/ram_to_ram_sans_padding} +\subsubsubsection{$\setMmuInstructionParametersAnyToRamWithPaddingName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: anyToRamWithPadding} \input{misc/mmu/any_to_ram_with_padding} +\subsubsubsection{$\setMmuInstructionParametersModexpZeroName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: modexpZero} \input{misc/mmu/modexp_zero} +\subsubsubsection{$\setMmuInstructionParametersModexpDataName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: modexpData} \input{misc/mmu/modexp_data} +\subsubsubsection{$\setMmuInstructionParametersBlakeName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: blake} \input{misc/mmu/blake} diff --git a/hub/misc/mmu/any_to_ram_with_padding.tex b/hub/misc/mmu/any_to_ram_with_padding.tex new file mode 100644 index 0000000..3ce2acb --- /dev/null +++ b/hub/misc/mmu/any_to_ram_with_padding.tex @@ -0,0 +1,61 @@ +We define +$\setMmuInstructionParametersAnyToRamWithPaddingName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersAnyToRamWithPadding { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \col{tgt\_offset\_lo} , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + exoSum = \col{exo\_sum} , + } + % \setMmuInstructionParametersAnyToRamWithPadding {i}{\relof} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \col{src\_id} \\ + % \utt{Target ID:} & \col{tgt\_id} \\ + % % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \col{src\_offset\_lo} \\ + % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \col{size} \\ + % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \col{ref\_size} \\ + % % \utt{Success bit:} & \col{success\_bit} \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \col{exo\_sum} \\ + % % \utt{Phase:} & \col{phase} \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + mmuInstruction = \mmuInstAnyToRamWithPadding , + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \col{src\_offset\_hi} , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \col{tgt\_offset\_lo} , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + successBit = \nothing , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \col{exo\_sum} , + phase = \nothing , + } \\ + \end{array} \right. +\] +\saNote{} +It is required that whenever this instruction is used with \textsc{ram} as its data source the \texttt{Exo sum} be set to $\rZero$. +Otherwise, the micro-instruction sequence produced by the \mmuMod{} module may trigger the usage of an exogenous data source instead. diff --git a/hub/misc/mmu/blake.tex b/hub/misc/mmu/blake.tex new file mode 100644 index 0000000..550dcde --- /dev/null +++ b/hub/misc/mmu/blake.tex @@ -0,0 +1,50 @@ +We define +$\setMmuInstructionParametersBlakeName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersBlake { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + sourceOffsetLo = \col{src\_offset\_lo} , + successBit = \col{success\_bit} , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + mmuInstruction = \mmuInstBlake , + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \nothing , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \col{success\_bit} , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + exoSum = \nothing , + phase = \nothing , + } \\ + \end{array} \right. +\] +\saNote{} +The values +``\col{limb\_1}'' and +``\col{limb\_2}'' +are best understood as \textbf{predictions}. +The \mmuMod{} instruction will fill them with +$\col{r} \in \mathbb{B}_{4}$, the number of rounds as extracted from memory, of the \inst{CALL} to \inst{BLAKE2f} and +$\col{f} \in \mathbb{B}_{1}$, the final block indicator (which is expected to be a bit i.e. $\in \{ 0, 1 \}$.) + +\saNote{} +The \texttt{Exo sum} and \texttt{Phase} are set in the \mmuMod{} module, depending on the \texttt{Success bit}, +see section~(\ref{mmu: instructions: blake}). diff --git a/hub/misc/mmu/exo_to_ram_transplants.tex b/hub/misc/mmu/exo_to_ram_transplants.tex new file mode 100644 index 0000000..5632ca2 --- /dev/null +++ b/hub/misc/mmu/exo_to_ram_transplants.tex @@ -0,0 +1,37 @@ +We define +$\setMmuInstructionParametersExoToRamTransplantsName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + size = \col{size} , + exoSum = \col{exo\_sum} , + phase = \col{phase} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + mmuInstruction = \mmuInstExoToRamTransplants, + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \nothing , + targetOffsetLo = \nothing , + size = \col{size} , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \nothing , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \col{exo\_sum} , + phase = \col{phase} , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/invalid_code_prefix.tex b/hub/misc/mmu/invalid_code_prefix.tex new file mode 100644 index 0000000..e97d49c --- /dev/null +++ b/hub/misc/mmu/invalid_code_prefix.tex @@ -0,0 +1,42 @@ +We define +$\setMmuInstructionParametersInvalidCodePrefixName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersInvalidCodePrefix { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + sourceOffsetLo = \col{src\_offset\_lo} , + successBit = \col{success\_bit} , + } + % \setMmuInstructionParametersInvalidCodePrefix + % {i}{\relof} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \col{src\_id} \\ + % \utt{Source offset low:} & \col{src\_offset\_lo} \\ + % \utt{Success bit:} & \col{success\_bit} \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + mmuInstruction = \mmuInstInvalidCodePrefix , + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \nothing , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \nothing , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \col{success\_bit} , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \nothing , + phase = \nothing , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/mload.tex b/hub/misc/mmu/mload.tex new file mode 100644 index 0000000..08993ff --- /dev/null +++ b/hub/misc/mmu/mload.tex @@ -0,0 +1,53 @@ +We define +$\setMmuInstructionParametersMloadName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersMload { + anchorRow = i, + relOffset = \relof, + sourceId = \col{src\_id}, + sourceOffsetLo = \col{src\_offset\_lo}, + limbOne = \col{limb\_1}, + limbTwo = \col{limb\_2}, + } + % \setMmuInstructionParametersMload {i}{\relof} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \col{src\_id} \\ + % % \utt{Target ID:} & \col{tgt\_id} \\ + % % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \col{src\_offset\_lo} \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % % \utt{Size:} & \col{size} \\ + % % \utt{Reference offset:} & \col{ref\_offset} \\ + % % \utt{Reference size:} & \col{ref\_size} \\ + % % \utt{Success bit:} & \col{success\_bit} \\ + % \utt{Limb one:} & \col{limb\_1} \\ + % \utt{Limb two:} & \col{limb\_2} \\ + % % \utt{Exo sum:} & \col{exo\_sum} \\ + % % \utt{Phase:} & \col{phase} \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + anchorRow = i , + relOffset = \relof , + mmuInstruction = \mmuInstMload , + sourceId = \col{src\_id} , + targetId = \nothing , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \nothing , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \nothing , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + exoSum = \nothing , + phase = \nothing , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/modexp_data.tex b/hub/misc/mmu/modexp_data.tex new file mode 100644 index 0000000..ca1660b --- /dev/null +++ b/hub/misc/mmu/modexp_data.tex @@ -0,0 +1,39 @@ +We define +$\setMmuInstructionParametersModexpDataName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersModexpData { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + sourceOffsetLo = \col{src\_offset\_lo} , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + phase = \col{phase} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + anchorRow = i , + relOffset = \relof , + mmuInstruction = \mmuInstModexpData , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + successBit = \nothing , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \exoWeightBlakeModexp , + phase = \col{phase} , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/modexp_zero.tex b/hub/misc/mmu/modexp_zero.tex new file mode 100644 index 0000000..4091553 --- /dev/null +++ b/hub/misc/mmu/modexp_zero.tex @@ -0,0 +1,34 @@ +We define +$\setMmuInstructionParametersModexpZeroName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersModexpZero { + anchorRow = i , + relOffset = \relof , + targetId = \col{tgt\_id} , + phase = \col{phase} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + anchorRow = i , + relOffset = \relof , + mmuInstruction = \mmuInstModexpZero , + sourceId = \nothing , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \nothing , + targetOffsetLo = \nothing , + size = \nothing , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \nothing , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \exoWeightBlakeModexp , + phase = \col{phase} , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/mstore.tex b/hub/misc/mmu/mstore.tex new file mode 100644 index 0000000..0f56ecf --- /dev/null +++ b/hub/misc/mmu/mstore.tex @@ -0,0 +1,36 @@ +We define +$\setMmuInstructionParametersMstoreName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersMstore { + anchorRow = i , + relOffset = \relof , + targetId = \col{tgt\_id} , + targetOffsetLo = \col{tgt\_offset\_lo} , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction{ + mmuInstruction = \mmuInstMstore , + anchorRow = i , + relOffset = \relof , + sourceId = \nothing , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \nothing , + targetOffsetLo = \col{tgt\_offset\_lo} , + size = \nothing , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \nothing , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + exoSum = \nothing , + phase = \nothing , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/mstore_eight.tex b/hub/misc/mmu/mstore_eight.tex new file mode 100644 index 0000000..10b46c4 --- /dev/null +++ b/hub/misc/mmu/mstore_eight.tex @@ -0,0 +1,36 @@ +We define +$\setMmuInstructionParametersMstoreEightName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersMstoreEight { + anchorRow = i , + relOffset = \relof , + targetId = \col{tgt\_id} , + targetOffsetLo = \col{tgt\_offset\_lo} , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + anchorRow = i , + relOffset = \relof , + mmuInstruction = \mmuInstMstoreEight , + sourceId = \nothing , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \nothing , + targetOffsetLo = \col{tgt\_offset\_lo} , + size = \nothing , + referenceOffset = \nothing , + referenceSize = \nothing , + successBit = \nothing , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + exoSum = \nothing , + phase = \nothing , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/ram_to_exo_with_padding.tex b/hub/misc/mmu/ram_to_exo_with_padding.tex new file mode 100644 index 0000000..b3025c8 --- /dev/null +++ b/hub/misc/mmu/ram_to_exo_with_padding.tex @@ -0,0 +1,46 @@ +We define +$\setMmuInstructionParametersRamToExoWithPaddingName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersRamToExoWithPadding { + anchorRow = i, + relOffset = \relof, + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \col{aux\_id} , + % sourceOffsetHi = \col{src\_offset\_hi}, + sourceOffsetLo = \col{src\_offset\_lo}, + % targetOffsetLo = \col{tgt\_offset\_lo}, + size = \col{size} , + % referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + successBit = \col{success\_bit} , + % limbOne = \col{limb\_1} , + % limbTwo = \col{limb\_2} , + exoSum = \col{exo\_sum} , + phase = \col{phase} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + mmuInstruction = \mmuInstRamToExoWithPadding , + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \col{aux\_id} , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \col{size} , + referenceOffset = \nothing , + referenceSize = \col{ref\_size} , + successBit = \col{success\_bit} , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \col{exo\_sum} , + phase = \col{phase} , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mmu/ram_to_ram_sans_padding.tex b/hub/misc/mmu/ram_to_ram_sans_padding.tex new file mode 100644 index 0000000..e2ef35c --- /dev/null +++ b/hub/misc/mmu/ram_to_ram_sans_padding.tex @@ -0,0 +1,55 @@ +We define +$\setMmuInstructionParametersRamToRamSansPaddingName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersRamToRamSansPadding { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + sourceOffsetLo = \col{src\_offset\_lo} , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + } + % \setMmuInstructionParametersRamToRamSansPadding {i}{\relof} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \col{src\_id} \\ + % \utt{Target ID:} & \col{tgt\_id} \\ + % % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % \utt{Source offset low:} & \col{src\_offset\_lo} \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \col{size} \\ + % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \col{ref\_size} \\ + % % \utt{Success bit:} & \col{success\_bit} \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % % \utt{Exo sum:} & \col{exo\_sum} \\ + % % \utt{Phase:} & \col{phase} \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + mmuInstruction = \mmuInstRamToRamSansPadding , + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + targetId = \col{tgt\_id} , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \col{size} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + successBit = \nothing , + limbOne = \nothing , + limbTwo = \nothing , + exoSum = \nothing , + phase = \nothing , + } + \end{array} \right. +\] diff --git a/hub/misc/mmu/right_padded_word_extraction.tex b/hub/misc/mmu/right_padded_word_extraction.tex new file mode 100644 index 0000000..d3d3b89 --- /dev/null +++ b/hub/misc/mmu/right_padded_word_extraction.tex @@ -0,0 +1,38 @@ +We define +$\setMmuInstructionParametersRightPaddedWordExtractionName _{i} \big[ \; \relof \; \big]$ +as follows +\[ + \left\{ \begin{array}{l} + \setMmuInstructionParametersRightPaddedWordExtraction { + anchorRow = i , + relOffset = \relof , + sourceId = \col{src\_id} , + sourceOffsetLo = \col{src\_offset\_lo} , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setMmuInstruction { + anchorRow = i , + relOffset = \relof , + mmuInstruction = \mmuInstRightPaddedWordExtraction , + sourceId = \col{src\_id} , + targetId = \nothing , + auxiliaryId = \nothing , + sourceOffsetHi = \nothing , + sourceOffsetLo = \col{src\_offset\_lo} , + targetOffsetLo = \nothing , + size = \nothing , + referenceOffset = \col{ref\_offset} , + referenceSize = \col{ref\_size} , + successBit = \nothing , + limbOne = \col{limb\_1} , + limbTwo = \col{limb\_2} , + exoSum = \nothing , + phase = \nothing , + } \\ + \end{array} \right. +\] diff --git a/hub/misc/mxp/_inputs.tex b/hub/misc/mxp/_inputs.tex new file mode 100644 index 0000000..5487845 --- /dev/null +++ b/hub/misc/mxp/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsubsection{$\setMxpInstructionTypeOneName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: mxp: type 1} \input{misc/mxp/type_1} +\subsubsubsection{$\setMxpInstructionTypeTwoName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: mxp: type 2} \input{misc/mxp/type_2} +\subsubsubsection{$\setMxpInstructionTypeThreeName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: mxp: type 3} \input{misc/mxp/type_3} +\subsubsubsection{$\setMxpInstructionTypeFourName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: mxp: type 4} \input{misc/mxp/type_4} +\subsubsubsection{$\setMxpInstructionTypeFiveName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: mxp: type 5} \input{misc/mxp/type_5} diff --git a/hub/misc/mxp/type_1.tex b/hub/misc/mxp/type_1.tex new file mode 100644 index 0000000..1696b81 --- /dev/null +++ b/hub/misc/mxp/type_1.tex @@ -0,0 +1,27 @@ +\[ + \begin{array}{l} + \setMxpInstructionTypeOne {i}{\relof} + \define \vspace{2mm} \\ + \qquad + \left\{ \begin{array}{lclr} + % \miscMxpFlag _{i + \relof} & = & automatic \\ + % \miscMxpStamp _{i + \relof} & = & automatic \\ + % \cn _{i + \relof} & = & automatic \\ + \miscMxpInst _{i + \relof} & = & \inst{MSIZE} \\ + \miscMxpCodeDeployment _{i + \relof} & = & \nothing \\ + \miscMxpOffsetOneHi _{i + \relof} & = & \nothing \\ + \miscMxpOffsetOneLo _{i + \relof} & = & \nothing \\ + \miscMxpSizeOneHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeOneLo _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpTypeFourInstMayTriggerMmu _{i + \relof} & = & \nothing \\ + \miscMxpMxpx _{i + \relof} & = & \nothing \\ + \miscMxpWords _{i + \relof} & = & \prediction \\ + \miscMxpGasMxp _{i + \relof} & = & \nothing \\ + \end{array} \right. + \end{array} +\] +\saNote{} The only prediction that is useful is that of \miscMxpWords{} diff --git a/hub/misc/mxp/type_2.tex b/hub/misc/mxp/type_2.tex new file mode 100644 index 0000000..65b88dc --- /dev/null +++ b/hub/misc/mxp/type_2.tex @@ -0,0 +1,33 @@ +\[ + \begin{array}{l} + \setMxpInstructionTypeTwo {i}{\relof} + \left[ \begin{array}{ll} + \utt{Instruction:} & \col{instruction} \\ + \utt{Offset high part:} & \col{offset\_hi} \\ + \utt{Offset low part:} & \col{offset\_lo} \\ + % \utt{:} & \\ + \end{array} \right] + \define \vspace{2mm} \\ + \qquad + \left\{ \begin{array}{lclr} + % \miscMxpFlag _{i + \relof} & = & automatic \\ + % \miscMxpStamp _{i + \relof} & = & automatic \\ + % \cn _{i + \relof} & = & automatic \\ + \miscMxpInst _{i + \relof} & = & \col{instruction} \\ + \miscMxpCodeDeployment _{i + \relof} & = & \nothing \\ + \miscMxpOffsetOneHi _{i + \relof} & = & \col{offset\_hi} \\ + \miscMxpOffsetOneLo _{i + \relof} & = & \col{offset\_lo} \\ + \miscMxpSizeOneHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeOneLo _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpTypeFourInstMayTriggerMmu _{i + \relof} & = & \nothing \\ + \miscMxpMxpx _{i + \relof} & = & \prediction \\ + \miscMxpWords _{i + \relof} & = & \prediction \\ + \miscMxpGasMxp _{i + \relof} & = & \prediction \\ + \end{array} \right. + \end{array} +\] + diff --git a/hub/misc/mxp/type_3.tex b/hub/misc/mxp/type_3.tex new file mode 100644 index 0000000..69057b6 --- /dev/null +++ b/hub/misc/mxp/type_3.tex @@ -0,0 +1,32 @@ +\[ + \begin{array}{l} + \setMxpInstructionTypeThree {i}{\relof} + \left[ \begin{array}{lcl} + \utt{Offset high part:} & \col{offset\_hi} \\ + \utt{Offset low part:} & \col{offset\_lo} \\ + % \utt{:} & \\ + \end{array} \right] + \define \vspace{2mm} \\ + \qquad + \left\{ \begin{array}{lclr} + % \miscMxpFlag _{i + \relof} & = & automatic \\ + % \miscMxpStamp _{i + \relof} & = & automatic \\ + % \cn _{i + \relof} & = & automatic \\ + \miscMxpInst _{i + \relof} & = & \inst{MSTORE8} \\ + \miscMxpCodeDeployment _{i + \relof} & = & \nothing \\ + \miscMxpOffsetOneHi _{i + \relof} & = & \col{offset\_hi} \\ + \miscMxpOffsetOneLo _{i + \relof} & = & \col{offset\_lo} \\ + \miscMxpSizeOneHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeOneLo _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpTypeFourInstMayTriggerMmu _{i + \relof} & = & \nothing \\ + \miscMxpMxpx _{i + \relof} & = & \prediction \\ + \miscMxpWords _{i + \relof} & = & \prediction \\ + \miscMxpGasMxp _{i + \relof} & = & \prediction \\ + \end{array} \right. + \end{array} +\] + diff --git a/hub/misc/mxp/type_4.tex b/hub/misc/mxp/type_4.tex new file mode 100644 index 0000000..db0e989 --- /dev/null +++ b/hub/misc/mxp/type_4.tex @@ -0,0 +1,38 @@ +\[ + \begin{array}{l} + \setMxpInstructionTypeFour + {i}{\relof} + \left[ \begin{array}{lcl} + \utt{Instruction:} & \col{instruction} \\ + \utt{Deploys byte code:} & \col{deploys} \\ + \utt{Offset high part:} & \col{offset\_hi} \\ + \utt{Offset low part:} & \col{offset\_lo} \\ + \utt{Size high part:} & \col{size\_hi} \\ + \utt{Size low part:} & \col{size\_lo} \\ + \end{array} \right] + \define \vspace{2mm} \\ + \qquad + \left\{ \begin{array}{lclr} + % \miscMxpFlag _{i + \relof} & = & automatic \\ + % \miscMxpStamp _{i + \relof} & = & automatic \\ + % \cn _{i + \relof} & = & automatic \\ + \miscMxpInst _{i + \relof} & = & \col{instruction} \\ + \miscMxpCodeDeployment _{i + \relof} & = & \col{deploys} \\ + \miscMxpOffsetOneHi _{i + \relof} & = & \col{offset\_hi} \\ + \miscMxpOffsetOneLo _{i + \relof} & = & \col{offset\_lo} \\ + \miscMxpSizeOneHi _{i + \relof} & = & \col{size\_hi} \\ + \miscMxpSizeOneLo _{i + \relof} & = & \col{size\_lo} \\ + \miscMxpOffsetTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpOffsetTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoHi _{i + \relof} & = & \nothing \\ + \miscMxpSizeTwoLo _{i + \relof} & = & \nothing \\ + \miscMxpTypeFourInstMayTriggerMmu _{i + \relof} & = & \prediction \\ + \miscMxpMxpx _{i + \relof} & = & \prediction \\ + \miscMxpWords _{i + \relof} & = & \prediction \\ + \miscMxpGasMxp _{i + \relof} & = & \prediction \\ + \end{array} \right. + \end{array} +\] +\saNote{} +So-called ``type 4 \mxpMod{} instructions'' are the only ones that require the \mxpMod{} module to check for nonzeroness of the size parameter. +Depending on other factors (such as the absence of certain exceptions) this is a requirement for triggering the \mmuMod{} module with instructions from that instruction family. diff --git a/hub/misc/mxp/type_5.tex b/hub/misc/mxp/type_5.tex new file mode 100644 index 0000000..915abc7 --- /dev/null +++ b/hub/misc/mxp/type_5.tex @@ -0,0 +1,53 @@ +\[ + \begin{array}{l} + \setMxpInstructionTypeFive { + anchorRow = i, + relOffset = \relof, + instruction = \col{instruction}, + callDataOffsetHi = \col{cdo\_hi}, + callDataOffsetLo = \col{cdo\_lo}, + callDataSizeHi = \col{cds\_hi}, + callDataSizeLo = \col{cds\_lo}, + returnAtOffsetHi = \col{r@o\_hi}, + returnAtOffsetLo = \col{r@o\_lo}, + returnAtCapacityHi = \col{r@c\_hi}, + returnAtCapacityLo = \col{r@c\_lo}, + } + % \setMxpInstructionTypeFive {i}{\relof} + % \left[ \begin{array}{lcl} + % \utt{Instruction:} & \col{instruction} \\ + % \utt{Call data offset high part:} & \col{cdo\_hi} \\ + % \utt{Call data offset low part:} & \col{cdo\_lo} \\ + % \utt{Call data size high part:} & \col{cds\_hi} \\ + % \utt{Call data size low part:} & \col{cds\_lo} \\ + % \utt{Return at offset high part:} & \col{rao\_hi} \\ + % \utt{Return at offset low part:} & \col{rao\_lo} \\ + % \utt{Return at capacity high part:} & \col{rac\_hi} \\ + % \utt{Return at capacity low part:} & \col{rac\_lo} \\ + % % \utt{:} & \\ + % \end{array} \right] + \define + \vspace{2mm} \\ + \qquad + \left\{ \begin{array}{lclr} + % \miscMxpFlag _{i + \relof} & = & automatic \\ + % \miscMxpStamp _{i + \relof} & = & automatic \\ + % \cn _{i + \relof} & = & automatic \\ + \miscMxpInst _{i + \relof} & = & \col{instruction} \\ + \miscMxpCodeDeployment _{i + \relof} & = & \nothing \\ + \miscMxpOffsetOneHi _{i + \relof} & = & \col{cdo\_hi} \\ + \miscMxpOffsetOneLo _{i + \relof} & = & \col{cdo\_lo} \\ + \miscMxpSizeOneHi _{i + \relof} & = & \col{cds\_hi} \\ + \miscMxpSizeOneLo _{i + \relof} & = & \col{cds\_lo} \\ + \miscMxpOffsetTwoHi _{i + \relof} & = & \col{r@o\_hi} \\ + \miscMxpOffsetTwoLo _{i + \relof} & = & \col{r@o\_lo} \\ + \miscMxpSizeTwoHi _{i + \relof} & = & \col{r@c\_hi} \\ + \miscMxpSizeTwoLo _{i + \relof} & = & \col{r@c\_lo} \\ + \miscMxpTypeFourInstMayTriggerMmu _{i + \relof} & = & \nothing \\ + \miscMxpMxpx _{i + \relof} & = & \prediction \\ + \miscMxpWords _{i + \relof} & = & \prediction \\ + \miscMxpGasMxp _{i + \relof} & = & \prediction \\ + \end{array} \right. + \end{array} +\] + diff --git a/hub/misc/oob/_general.tex b/hub/misc/oob/_general.tex new file mode 100644 index 0000000..937699c --- /dev/null +++ b/hub/misc/oob/_general.tex @@ -0,0 +1,36 @@ +Throughout $\relof$ represents a \textbf{small integer}. +In all applications $\relof$ will be nonnegative, too, but this isn't required. +We define a family of constraints $\setOobInstruction{\relof}$ parametrized by $\relof$. +Variations of this one constraint will be presented in the coming subsections. + +\saNote{} The $\setOobInstruction {i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstruction{i} + \left[ \begin{array}{ll} + \multicolumn{2}{l}{\utt{\oobMod{} instruction:} \quad \col{oob\_inst}} \\ + \multicolumn{2}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \quad \col{data\_1} \\ + \utt{Data 2:} & \quad \col{data\_2} \\ + \utt{Data 3:} & \quad \col{data\_3} \\ + \utt{Data 4:} & \quad \col{data\_4} \\ + \utt{Data 5:} & \quad \col{data\_5} \\ + \utt{Data 6:} & \quad \col{data\_6} \\ + \utt{Data 7:} & \quad \col{data\_7} \\ + \utt{Data 8:} & \quad \col{data\_8} \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \left\{ \begin{array}{lcl} + \miscOobInst _{i + \relof} & = & \col{oob\_inst} \vspace{2mm} \\ + \miscOobDataCol {1} _{i + \relof} & = & \col{data\_1} \\ + \miscOobDataCol {2} _{i + \relof} & = & \col{data\_2} \\ + \miscOobDataCol {3} _{i + \relof} & = & \col{data\_3} \\ + \miscOobDataCol {4} _{i + \relof} & = & \col{data\_4} \\ + \miscOobDataCol {5} _{i + \relof} & = & \col{data\_5} \\ + \miscOobDataCol {6} _{i + \relof} & = & \col{data\_6} \\ + \miscOobDataCol {7} _{i + \relof} & = & \col{data\_7} \\ + \miscOobDataCol {8} _{i + \relof} & = & \col{data\_8} \\ + \end{array} \right. + \end{array} \right. +\] + diff --git a/hub/misc/oob/_inputs.tex b/hub/misc/oob/_inputs.tex new file mode 100644 index 0000000..b430ac7 --- /dev/null +++ b/hub/misc/oob/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{The general $\setOobInstruction{i}$ template \lispDone{}} \label{hub: misc: oob: general} \input{misc/oob/_general} +\subsubsection{\oobMod{} instruction templates for \textbf{opcodes} \lispDone{}} \label{hub: misc: oob: opcodes} \input{misc/oob/opcodes/_inputs} +\subsubsection{\oobMod{} instruction templates for \textbf{precompiles} \lispDone{}} \label{hub: misc: oob: precompiles} \input{misc/oob/precompiles/_inputs} diff --git a/hub/misc/oob/_template.tex b/hub/misc/oob/_template.tex new file mode 100644 index 0000000..adc9c06 --- /dev/null +++ b/hub/misc/oob/_template.tex @@ -0,0 +1,30 @@ +\saNote{} The $\setOobInstructionXXX{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionXXX {\relof} _{i} + \left[ \begin{array}{ll} + \utt{:} & \\ + \utt{:} & \\ + \utt{:} & \\ + \utt{:} & \\ + \utt{:} & \\ + \utt{:} & \\ + \utt{:} & \\ + \utt{:} & \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstXXX} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \nothing \\ + \utt{Data 2:} & \nothing \\ + \utt{Data 3:} & \nothing \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \nothing \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \nothing \\ + \utt{Data 8:} & \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/_inputs.tex b/hub/misc/oob/opcodes/_inputs.tex new file mode 100644 index 0000000..5b07574 --- /dev/null +++ b/hub/misc/oob/opcodes/_inputs.tex @@ -0,0 +1,9 @@ +\subsubsubsection{$\setOobInstructionJumpName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: jump} \input{misc/oob/opcodes/jump} +\subsubsubsection{$\setOobInstructionJumpIName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: jumpI} \input{misc/oob/opcodes/jumpI} +\subsubsubsection{$\setOobInstructionRdcName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: rdc} \input{misc/oob/opcodes/rdc} +\subsubsubsection{$\setOobInstructionCdlName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: cdl} \input{misc/oob/opcodes/cdl} +\subsubsubsection{$\setOobInstructionSstoreName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: sstore} \input{misc/oob/opcodes/sstore} +\subsubsubsection{$\setOobInstructionDeploymentName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: deployment} \input{misc/oob/opcodes/deployment} +\subsubsubsection{$\setOobInstructionXcallName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: xcall} \input{misc/oob/opcodes/xcall} +\subsubsubsection{$\setOobInstructionCallName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: call} \input{misc/oob/opcodes/call} +\subsubsubsection{$\setOobInstructionCreateName _{i} \big[~\relof~\big] $ constraints \lispDone{}} \label{hub: misc: oob: create} \input{misc/oob/opcodes/create} diff --git a/hub/misc/oob/opcodes/call.tex b/hub/misc/oob/opcodes/call.tex new file mode 100644 index 0000000..806e5c6 --- /dev/null +++ b/hub/misc/oob/opcodes/call.tex @@ -0,0 +1,35 @@ +\saNote{} The $\setOobInstructionCallName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionCall { + anchorRow = i , + relOffset = \relof , + valueHi = \locValueHi , + valueLo = \locValueLo , + balance = \locBalance , + callStackDepth = \locCallStackDepth , + } + % \setOobInstructionCall {i}{\relof} + % \left[ \begin{array}{ll} + % \utt{Value high:} & \locValueHi \\ + % \utt{Value low:} & \locValueLo \\ + % \utt{Balance:} & \locBalance \\ + % \utt{Call stack depth:} & \locCallStackDepth \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstCall} \vspace{2mm} \\ + \utt{Rel. row offset:} & \relof \\ + \utt{Data 1:} & \locValueHi \\ + \utt{Data 2:} & \locValueLo \\ + \utt{Data 3:} & \locBalance \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \nothing \\ + \utt{Data 6:} & \locCallStackDepth \\ + \utt{Data 7:} & \locNonzeroValue & \prediction \\ + \utt{Data 8:} & \locAbortingCondition & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/cdl.tex b/hub/misc/oob/opcodes/cdl.tex new file mode 100644 index 0000000..ab1a400 --- /dev/null +++ b/hub/misc/oob/opcodes/cdl.tex @@ -0,0 +1,25 @@ +\saNote{} The $\setOobInstructionCdl {i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionCdl {i}{\relof} + \left[ \begin{array}{ll} + \utt{Offset high:} & \locOffsetHi \\ + \utt{Offset low:} & \locOffsetLo \\ + \utt{Call data size:} & \locCds \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstCdl} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locOffsetHi \\ + \utt{Data 2:} & \locOffsetLo \\ + \utt{Data 3:} & \nothing \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \locCds \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locCdlOutOfBounds & \prediction \\ + \utt{Data 8:} & \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/create.tex b/hub/misc/oob/opcodes/create.tex new file mode 100644 index 0000000..f15d233 --- /dev/null +++ b/hub/misc/oob/opcodes/create.tex @@ -0,0 +1,30 @@ +\saNote{} The $\setOobInstructionCreateName$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionCreate { + anchorRow = i, + relOffset = \relof, + valueHi = \locValueHi, + valueLo = \locValueLo, + balance = \locBalance, + nonce = \locNonce, + hasCode = \locHasCode, + callStackDepth = \locCallStackDepth, + } + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstCreate} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locValueHi \\ + \utt{Data 2:} & \locValueLo \\ + \utt{Data 3:} & \locBalance \\ + \utt{Data 4:} & \locNonce \\ + \utt{Data 5:} & \locHasCode \\ + \utt{Data 6:} & \locCallStackDepth \\ + \utt{Data 7:} & \locAbortingCondition & \prediction \\ + \utt{Data 8:} & \locFailureCondition & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/deployment.tex b/hub/misc/oob/opcodes/deployment.tex new file mode 100644 index 0000000..04e89bd --- /dev/null +++ b/hub/misc/oob/opcodes/deployment.tex @@ -0,0 +1,25 @@ +\saNote{} The $\setOobInstructionDeployment {i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionDeployment + {i}{\relof} + \left[ \begin{array}{ll} + \utt{Code size high:} & \locCodeSizeHi \\ + \utt{Code size low:} & \locCodeSizeLo \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstDeployment} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locCodeSizeHi \\ + \utt{Data 2:} & \locCodeSizeLo \\ + \utt{Data 3:} & \nothing \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \nothing \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locMaxCodeSizeException & \prediction \\ + \utt{Data 8:} & \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/jump.tex b/hub/misc/oob/opcodes/jump.tex new file mode 100644 index 0000000..9d00aa5 --- /dev/null +++ b/hub/misc/oob/opcodes/jump.tex @@ -0,0 +1,25 @@ +\saNote{} The $\setOobInstructionJump{i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionJump {i}{\relof} + \left[ \begin{array}{llr} + \utt{New program counter (high part):} & \locPcNewHi \\ + \utt{New program counter (low part):} & \locPcNewLo \\ + \utt{Code size:} & \locCodeSize \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \oobInstJump} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locPcNewHi \\ + \utt{Data 2:} & \locPcNewLo \\ + \utt{Data 3:} & \nothing \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \locCodeSize \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locJumpGuaranteedException & \prediction \\ + \utt{Data 8:} & \locJumpMustBeAttempted & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/jumpI.tex b/hub/misc/oob/opcodes/jumpI.tex new file mode 100644 index 0000000..ee207dd --- /dev/null +++ b/hub/misc/oob/opcodes/jumpI.tex @@ -0,0 +1,27 @@ +\saNote{} The $\setOobInstructionJumpI {i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionJumpI {i}{\relof} + \left[ \begin{array}{llr} + \utt{New program counter (high part):} & \locPcNewHi \\ + \utt{New program counter (low part):} & \locPcNewLo \\ + \utt{Jump condition (high part):} & \locJumpConditionHi \\ + \utt{Jump condition (low part):} & \locJumpConditionLo \\ + \utt{Code size:} & \locCodeSize \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstJumpI} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locPcNewHi \\ + \utt{Data 2:} & \locPcNewLo \\ + \utt{Data 3:} & \locJumpConditionHi \\ + \utt{Data 4:} & \locJumpConditionLo \\ + \utt{Data 5:} & \locCodeSize \\ + \utt{Data 6:} & \locJumpNotAttempted & \prediction \\ + \utt{Data 7:} & \locJumpGuaranteedException & \prediction \\ + \utt{Data 8:} & \locJumpMustBeAttempted & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/opcodes/rdc.tex b/hub/misc/oob/opcodes/rdc.tex new file mode 100644 index 0000000..5671ce0 --- /dev/null +++ b/hub/misc/oob/opcodes/rdc.tex @@ -0,0 +1,28 @@ +\saNote{} The $\setOobInstructionRdc {i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionRdc {i}{\relof} + \left[ \begin{array}{ll} + \utt{Reference offset high:} & \locOffsetHi \\ + \utt{Reference offset low:} & \locOffsetLo \\ + \utt{Size high:} & \locSizeHi \\ + \utt{Size low:} & \locSizeLo \\ + \utt{Return data size:} & \locRds \\ + \end{array} \right] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstRdc} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locOffsetHi \\ + \utt{Data 2:} & \locOffsetLo \\ + \utt{Data 3:} & \locSizeHi \\ + \utt{Data 4:} & \locSizeLo \\ + \utt{Data 5:} & \locRds \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locRdcx & \prediction \\ + \utt{Data 8:} & \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] +\saNote{} We remind the reader that ``\rdcx'' is short for \rdcxSH{}. diff --git a/hub/misc/oob/opcodes/sstore.tex b/hub/misc/oob/opcodes/sstore.tex new file mode 100644 index 0000000..0250df5 --- /dev/null +++ b/hub/misc/oob/opcodes/sstore.tex @@ -0,0 +1,24 @@ +\saNote{} The $\setOobInstructionSstore {i}{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionSstore {i}{\relof} + \Big[ \begin{array}{ll} + \utt{Actual gas:} & \locSstoreGas \\ + \end{array} \Big] \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstSstore} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \nothing \\ + \utt{Data 2:} & \nothing \\ + \utt{Data 3:} & \nothing \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \locSstoreGas \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locSstoreException & \prediction \\ + \utt{Data 8:} & \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] +\saNote{} We remind the reader that ``\sstorex'' is short for \sstorexSH{}. diff --git a/hub/misc/oob/opcodes/xcall.tex b/hub/misc/oob/opcodes/xcall.tex new file mode 100644 index 0000000..f1d3a01 --- /dev/null +++ b/hub/misc/oob/opcodes/xcall.tex @@ -0,0 +1,32 @@ +\saNote{} The $\setOobInstructionXcallName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. + +\[ + \left\{ \begin{array}{l} + \setOobInstructionXcall { + anchorRow = i, + relOffset = \relof, + valueHi = \locValueHi, + valueLo = \locValueLo, + } + % \setOobInstructionXcall {i}{\relof} + % \left[ \begin{array}{ll} + % \utt{Value high:} & \locValueHi \\ + % \utt{Value low:} & \locValueLo \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstXcall} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locValueHi \\ + \utt{Data 2:} & \locValueLo \\ + \utt{Data 3:} & \nothing \\ + \utt{Data 4:} & \nothing \\ + \utt{Data 5:} & \nothing \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locNonzeroValue & \prediction \\ + \utt{Data 8:} & \locZeroValue & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/precompiles/_inputs.tex b/hub/misc/oob/precompiles/_inputs.tex new file mode 100644 index 0000000..3682f7c --- /dev/null +++ b/hub/misc/oob/precompiles/_inputs.tex @@ -0,0 +1,8 @@ +\subsubsubsection{$\setOobInstructionCommonName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: common} \input{misc/oob/precompiles/common} +\subsubsubsection{$\setOobInstructionModexpCdsName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: modexp cds} \input{misc/oob/precompiles/modexp_cds} +\subsubsubsection{$\setOobInstructionModexpXbsName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: modexp xbs} \input{misc/oob/precompiles/modexp_xbs} +\subsubsubsection{$\setOobInstructionModexpLeadName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: modexp lead} \input{misc/oob/precompiles/modexp_lead} +\subsubsubsection{$\setOobInstructionModexpPricingName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: modexp pricing} \input{misc/oob/precompiles/modexp_pricing} +\subsubsubsection{$\setOobInstructionModexpExtractName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: modexp extract} \input{misc/oob/precompiles/modexp_extract} +\subsubsubsection{$\setOobInstructionBlakeCdsName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: blake cds} \input{misc/oob/precompiles/blake_cds} +\subsubsubsection{$\setOobInstructionBlakeParamsName _{i} \big[~\relof~\big]$ constraints \lispDone{}} \label{hub: misc: oob: blake params} \input{misc/oob/precompiles/blake_params} diff --git a/hub/misc/oob/precompiles/blake_cds.tex b/hub/misc/oob/precompiles/blake_cds.tex new file mode 100644 index 0000000..97c447a --- /dev/null +++ b/hub/misc/oob/precompiles/blake_cds.tex @@ -0,0 +1,33 @@ +\saNote{} The $\setOobInstructionBlakeCdsName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + % \setOobInstructionBlakeCds {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{Call data size:} & \locCds \\ + % \utt{Return at capacity:} & \locRac \\ + % \end{array} \right] + \setOobInstructionBlakeCds { + anchorRow = i , + relOffset = \relof , + callDataSize = \locCds , + returnAtCapacity = \locRac , + } + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{$\utt{\oobMod{} instruction:} ~ \oobInstBlakeCds$} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \quad \nothing \\ + \utt{Data 2:} & \quad \locCds \\ + \utt{Data 3:} & \quad \locRac \\ + \utt{Data 4:} & \quad \locHubSuccess & \prediction \\ + \utt{Data 5:} & \quad \nothing \\ + \utt{Data 6:} & \quad \nothing \\ + \utt{Data 7:} & \quad \nothing \\ + \utt{Data 8:} & \quad \locRacIsNonzero & \prediction \\ + \end{array} \right] + \\ + \end{array} \right. +\] + diff --git a/hub/misc/oob/precompiles/blake_params.tex b/hub/misc/oob/precompiles/blake_params.tex new file mode 100644 index 0000000..150343b --- /dev/null +++ b/hub/misc/oob/precompiles/blake_params.tex @@ -0,0 +1,33 @@ +\saNote{} The $\setOobInstructionBlakeParamsName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionBlakeParams { + anchorRow = i , + relOffset = \relof , + callGas = \locCallGas , + blakeR = \locBlakeR , + blakeF = \locBlakeF , + } + % \setOobInstructionBlakeParams {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{Call gas:} & \locCallGas \\ + % \utt{Rounds ``r'':} & \locBlakeR \\ + % \utt{Final block indicator ``f'':} & \locBlakeF \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{$\utt{\oobMod{} instruction:} ~ \oobInstBlakeParams$} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \quad \locCallGas \\ + \utt{Data 2:} & \quad \nothing \\ + \utt{Data 3:} & \quad \nothing \\ + \utt{Data 4:} & \quad \locRamSuccess & \prediction \\ + \utt{Data 5:} & \quad \locReturnGas & \prediction \\ + \utt{Data 6:} & \quad \locBlakeR \\ + \utt{Data 7:} & \quad \locBlakeF \\ + \utt{Data 8:} & \quad \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/precompiles/common.tex b/hub/misc/oob/precompiles/common.tex new file mode 100644 index 0000000..cb3e58e --- /dev/null +++ b/hub/misc/oob/precompiles/common.tex @@ -0,0 +1,42 @@ +\saNote{} The $\setOobInstructionCommonName$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionCommon { + anchorRow = i, + relOffset = \relof, + oobInstruction = \locCommonPrecompile, + callGas = \locCallGas, + callDataSize = \locCds, + returnAtCapacity = \locRac, + } + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \locCommonPrecompile } \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locCallGas \\ + \utt{Data 2:} & \locCds \\ + \utt{Data 3:} & \locRac \\ + \utt{Data 4:} & \locHubSuccess & \prediction \\ + \utt{Data 5:} & \locReturnGas & \prediction \\ + \utt{Data 6:} & \locExtractCallData & \prediction \\ + \utt{Data 7:} & \locEmptyCallData & \prediction \\ + \utt{Data 8:} & \locRacIsNonzero & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] +In applications \locCommonPrecompile{} is one of the following +\begin{multicols}{3} + \begin{enumerate} + \item \oobInstEcrecover{} + \item \oobInstEcadd{} + \item \oobInstEcmul{} + \item \oobInstShaTwo{} + \item \oobInstRipemd{} + \item \oobInstIdentity{} + \item \oobInstEcpairing{} + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/hub/misc/oob/precompiles/modexp_cds.tex b/hub/misc/oob/precompiles/modexp_cds.tex new file mode 100644 index 0000000..7675f98 --- /dev/null +++ b/hub/misc/oob/precompiles/modexp_cds.tex @@ -0,0 +1,29 @@ +\saNote{} The $\setOobInstructionModexpCdsName{\relof}$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionModexpCds { + anchorRow = i , + relOffset = \relof , + callDataSize = \locCds , + } + % \setOobInstructionModexpCds {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{Call data size:} & \locCds \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstModexpCds} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \nothing \\ + \utt{Data 2:} & \locCds \\ + \utt{Data 3:} & \locExtractBbs & \prediction \\ + \utt{Data 4:} & \locExtractEbs & \prediction \\ + \utt{Data 5:} & \locExtractMbs & \prediction \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \nothing \\ + \utt{Data 8:} & \nothing \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/precompiles/modexp_extract.tex b/hub/misc/oob/precompiles/modexp_extract.tex new file mode 100644 index 0000000..f9b186d --- /dev/null +++ b/hub/misc/oob/precompiles/modexp_extract.tex @@ -0,0 +1,35 @@ +\saNote{} The $\setOobInstructionModexpExtractName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionModexpExtract { + anchorRow = i , + relOffset = \relof , + callDataSize = \locCds , + bbsLo = \locBbsLo , + ebsLo = \locEbsLo , + mbsLo = \locMbsLo , + } + % \setOobInstructionModexpExtract {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{Call data size:} & \locCds \\ + % \utt{Base byte size:} & \locBbsLo \\ + % \utt{Exponent byte size:} & \locEbsLo \\ + % \utt{Modulus byte size:} & \locMbsLo \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstModexpExtract} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \nothing \\ + \utt{Data 2:} & \locCds \\ + \utt{Data 3:} & \locBbsLo \\ + \utt{Data 4:} & \locEbsLo \\ + \utt{Data 5:} & \locMbsLo \\ + \utt{Data 6:} & \locExtractBase & \prediction \\ + \utt{Data 7:} & \locExtractExponent & \prediction \\ + \utt{Data 8:} & \locExtractModulus & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/precompiles/modexp_lead.tex b/hub/misc/oob/precompiles/modexp_lead.tex new file mode 100644 index 0000000..2b6a2ae --- /dev/null +++ b/hub/misc/oob/precompiles/modexp_lead.tex @@ -0,0 +1,33 @@ +\saNote{} The $\setOobInstructionModexpLeadName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionModexpLead { + anchorRow = i , + relOffset = \relof , + bbsLo = \locBbsLo , + callDataSize = \locCds , + ebsLo = \locEbsLo , + } + % \setOobInstructionModexpLead {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{Base byte size:} & \locBbsLo \\ + % \utt{Call data size:} & \locCds \\ + % \utt{Exponent byte size:} & \locEbsLo \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstModexpLead} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locBbsLo \\ + \utt{Data 2:} & \locCds \\ + \utt{Data 3:} & \locEbsLo \\ + \utt{Data 4:} & \locLoadLeadingWord & \prediction \\ + \utt{Data 5:} & \nothing \\ + \utt{Data 6:} & \locCdsCutoff & \prediction \\ + \utt{Data 7:} & \locEbsCutoff & \prediction \\ + \utt{Data 8:} & \locEbsSubThirtyTwo & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/precompiles/modexp_pricing.tex b/hub/misc/oob/precompiles/modexp_pricing.tex new file mode 100644 index 0000000..a338be6 --- /dev/null +++ b/hub/misc/oob/precompiles/modexp_pricing.tex @@ -0,0 +1,35 @@ +\saNote{} The $\setOobInstructionModexpPricingName _{i} \big[~\relof~\big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionModexpPricing { + anchorRow = i , + relOffset = \relof , + callGas = \locCallGas , + returnAtCapacity = \locRac , + exponentLog = \locExponentLog , + maxMbsBbs = \locMaxMbsBbs , + } + % \setOobInstructionModexpPricing {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{Call gas:} & \locCallGas \\ + % \utt{Return at capacity:} & \locRac \\ + % \utt{Exponent log:} & \locExponentLog \\ + % \utt{Max(mbs, bbs):} & \locMaxMbsBbs \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstModexpPricing} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locCallGas \\ + \utt{Data 2:} & \nothing \\ + \utt{Data 3:} & \locRac \\ + \utt{Data 4:} & \locRamSuccess & \prediction \\ + \utt{Data 5:} & \locReturnGas & \prediction \\ + \utt{Data 6:} & \locExponentLog \\ + \utt{Data 7:} & \locMaxMbsBbs \\ + \utt{Data 8:} & \locRacIsNonzero & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/oob/precompiles/modexp_xbs.tex b/hub/misc/oob/precompiles/modexp_xbs.tex new file mode 100644 index 0000000..f5ce284 --- /dev/null +++ b/hub/misc/oob/precompiles/modexp_xbs.tex @@ -0,0 +1,35 @@ +\saNote{} The $\setOobInstructionModexpXbsName _{i} \big[ \, \relof \, \big]$ constraints may only be used on rows with row index $i + \relof$ that are \textbf{miscellaneous-rows}. +\[ + \left\{ \begin{array}{l} + \setOobInstructionModexpXbs { + anchorRow = i , + relOffset = \relof , + xbsHi = \locXbsHi , + xbsLo = \locXbsLo , + ybsLo = \locYbsLo , + computeMax = \locComputeMax , + } + % \setOobInstructionModexpXbs {\relof} _{i} + % \left[ \begin{array}{ll} + % \utt{``xbs'' high:} & \locXbsHi \\ + % \utt{``xbs'' low:} & \locXbsLo \\ + % \utt{``ybs'' low:} & \locYbsLo \\ + % \utt{Extra computation bit:} & \locComputeMax \\ + % \end{array} \right] + \vspace{2mm} \\ + \qquad \qquad \define + \setOobInstruction{i} + \left[ \begin{array}{llr} + \multicolumn{3}{l}{\utt{\oobMod{} instruction:} \quad \oobInstModexpXbs} \\ + \multicolumn{3}{l}{\utt{Rel. row offset:} \quad \relof} \vspace{2mm} \\ + \utt{Data 1:} & \locXbsHi \\ + \utt{Data 2:} & \locXbsLo \\ + \utt{Data 3:} & \locYbsLo \\ + \utt{Data 4:} & \locComputeMax \\ + \utt{Data 5:} & \nothing \\ + \utt{Data 6:} & \nothing \\ + \utt{Data 7:} & \locMax & \prediction \\ + \utt{Data 8:} & \locXbsNonzero & \prediction \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/hub/misc/stp/_inputs.tex b/hub/misc/stp/_inputs.tex new file mode 100644 index 0000000..92e8840 --- /dev/null +++ b/hub/misc/stp/_inputs.tex @@ -0,0 +1,4 @@ +\input{misc/stp/_local} +\subsubsection{\stpMod{} module connections to the \mxpMod{} module \lispDone{}} \label{hub: misc: stp: connections} \input{misc/stp/connections} +\subsubsection{\stpMod{} instruction template for \inst{CREATE}-type instructions \lispDone{}} \label{hub: misc: stp: create} \input{misc/stp/create} +\subsubsection{\stpMod{} instruction template for \inst{CALL}-type instructions \lispDone{}} \label{hub: misc: stp: call} \input{misc/stp/call} diff --git a/hub/misc/stp/_local.tex b/hub/misc/stp/_local.tex new file mode 100644 index 0000000..db8b9e2 --- /dev/null +++ b/hub/misc/stp/_local.tex @@ -0,0 +1,10 @@ +\def\locAnchorRow {i} +\def\locInstruction {\col{instruction}} +\def\locGasHi {\col{gas\_hi}} +\def\locGasLo {\col{gas\_lo}} +\def\locValueHi {\col{value\_hi}} +\def\locValueLo {\col{value\_lo}} +\def\locTargetExists {\col{target\_exists}} +\def\locTargetWarmth {\col{target\_warmth}} +\def\locMxpGasMxp {\col{mxp\_gas}} + diff --git a/hub/misc/stp/call.tex b/hub/misc/stp/call.tex new file mode 100644 index 0000000..d34e6ff --- /dev/null +++ b/hub/misc/stp/call.tex @@ -0,0 +1,34 @@ +We define the following parametrized constraint system for setting \stpMod{} rows and \inst{CREATE}-instructions in particular: +\[ + \left\{ \begin{array}{l} + \setStpInstructionCall{ + anchorRow = \locAnchorRow, + relOffset = \relof, + instruction = \locInstruction, + gasHi = \locGasHi, + gasLo = \locGasLo, + valueHi = \locValueHi, + valueLo = \locValueLo, + warmth = \locTargetExists, + exists = \locTargetWarmth, + mxpGas = \locMxpGasMxp, + } + \vspace{4mm}\\ + \qquad \iff + \left\{ \begin{array}{lcl} + \miscStpInst _{\locAnchorRow + \relof} & = & \locInstruction \\ + \miscStpGasHi _{\locAnchorRow + \relof} & = & \locGasHi \\ + \miscStpGasLo _{\locAnchorRow + \relof} & = & \locGasLo \\ + \miscStpValueHi _{\locAnchorRow + \relof} & = & \locValueHi \\ + \miscStpValueLo _{\locAnchorRow + \relof} & = & \locValueLo \\ + \miscStpAccExists _{\locAnchorRow + \relof} & = & \locTargetExists \\ + \miscStpAccWarmth _{\locAnchorRow + \relof} & = & \locTargetWarmth \\ + \miscStpGasMxp _{\locAnchorRow + \relof} & = & \locMxpGasMxp \\ + \miscStpOogx _{\locAnchorRow + \relof} & = & \prediction \\ + \miscStpGasUpfront _{\locAnchorRow + \relof} & = & \prediction \\ + \miscStpGasPoop _{\locAnchorRow + \relof} & = & \prediction \\ + \miscStpGasStipend _{\locAnchorRow + \relof} & = & \nothing \\ + \end{array} \right. + \end{array} \right. +\] + diff --git a/hub/misc/stp/connections.tex b/hub/misc/stp/connections.tex new file mode 100644 index 0000000..4bf0343 --- /dev/null +++ b/hub/misc/stp/connections.tex @@ -0,0 +1,16 @@ +The present section imposes several constraints that are optional in the sense that they will be re-enforced on a case by case basis for all instructions which may trigger the \stpMod{} module, that is: \inst{CALL}-type and \inst{CREATE}-type instructions. +These constraints impose that whenever the \stpMod{} module is triggered by the \hubMod{} module, the \mxpMod{} must also have been triggered. +Furthermore it imposes ``copy constraints'' or ``duplication constraints'' transferring the ``memory expansion gas'' from the \mxpMod{} data columns, specifically: \miscMxpGasMxp{}, to the eponymous \stpMod{} data column, specifically \miscStpGasMxp{}. + +We therefore impose that +\begin{enumerate} + \item \If $\peekMisc _{i} = 1$ \et $\miscStpFlag _{i} = 1$ \Then + \begin{enumerate} + \item $\miscMxpFlag _{i} = 1$ + \item $\miscStpGasMxp _{i} = \miscMxpGasMxp _{i}$ + \end{enumerate} +\end{enumerate} +\saNote{} +Previous iterations of the \hubMod{} arithmetization didn't duplicate the \miscMxpGasMxp{} column. +This column was shared between the \mxpMod{} and \stpMod{}. +This approach is valid and slightly more efficient than the above but also a little more finnicky. diff --git a/hub/misc/stp/create.tex b/hub/misc/stp/create.tex new file mode 100644 index 0000000..61d3698 --- /dev/null +++ b/hub/misc/stp/create.tex @@ -0,0 +1,29 @@ +We define the following parametrized constraint system for setting \stpMod{} rows and \inst{CREATE}-instructions in particular: +\[ + \left\{ \begin{array}{l} + \setStpInstructionCreate{ + anchorRow = \locAnchorRow, + relOffset = \relof, + instruction = \locInstruction, + valueHi = \locValueHi, + valueLo = \locValueLo, + mxpGas = \locMxpGasMxp, + } + \vspace{4mm}\\ + \qquad \iff + \left\{ \begin{array}{lcl} + \miscStpInst _{i + \relof} & = & \locInstruction \\ + \miscStpGasHi _{i + \relof} & = & \nothing \\ + \miscStpGasLo _{i + \relof} & = & \nothing \\ + \miscStpValueHi _{i + \relof} & = & \locValueHi \\ + \miscStpValueLo _{i + \relof} & = & \locValueLo \\ + \miscStpAccExists _{i + \relof} & = & \nothing \\ + \miscStpAccWarmth _{i + \relof} & = & \nothing \\ + \miscStpGasMxp _{i + \relof} & = & \locMxpGasMxp \\ + \miscStpOogx _{i + \relof} & = & \prediction \\ + \miscStpGasUpfront _{i + \relof} & = & \prediction \\ + \miscStpGasPoop _{i + \relof} & = & \prediction \\ + \miscStpGasStipend _{i + \relof} & = & \nothing \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/hub/scenario/_inputs.tex b/hub/scenario/_inputs.tex new file mode 100644 index 0000000..6c4ec2d --- /dev/null +++ b/hub/scenario/_inputs.tex @@ -0,0 +1,5 @@ +\section{Scenario-rows \lispTodo{}} +\subsection{Introduction} \label{hub: scenarios: intro} \input{scenario/intro} +\subsection{Shorthands \lispWip{}} \label{hub: scenarios: shorthands} \input{scenario/shorthands/_inputs} +\subsection{Tables} \label{hub: scenarios: tables} \input{scenario/tables/_inputs} +\subsection{General constraints \lispWip{}} \label{hub: scenarios: generalities} \input{scenario/generalities/_inputs} diff --git a/hub/scenario/generalities/_inputs.tex b/hub/scenario/generalities/_inputs.tex new file mode 100644 index 0000000..d63d1b3 --- /dev/null +++ b/hub/scenario/generalities/_inputs.tex @@ -0,0 +1,6 @@ +\subsubsection{\inst{CALL}-instruction related scenario columns \lispDone{}} \label{hub: scenarios: generalities: call} \input{scenario/generalities/call} +\subsubsection{\inst{CREATE}-instruction related scenario columns \lispDone{}} \label{hub: scenarios: generalities: create} \input{scenario/generalities/create} +\subsubsection{\inst{RETURN}-instruction related scenario columns \lispDone{}} \label{hub: scenarios: generalities: return} \input{scenario/generalities/return} +\subsubsection{\inst{SELFDESTRUCT}-instruction related scenario columns \lispDone{}} \label{hub: scenarios: generalities: selfdestruct} \input{scenario/generalities/selfdestruct} +\subsubsection{Precompile related scenario columns \lispDone{}} \label{hub: scenarios: generalities: precompile} \input{scenario/generalities/precompiles} +\subsubsection{Single active scenario constraints \lispDone{}} \label{hub: scenarios: generalities: single scenario} \input{scenario/generalities/single_scenario} diff --git a/hub/scenario/generalities/call.tex b/hub/scenario/generalities/call.tex new file mode 100644 index 0000000..b77442f --- /dev/null +++ b/hub/scenario/generalities/call.tex @@ -0,0 +1,21 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekScenario_{i} = 1.} +\end{center} +In this section we impose general constraints on \textbf{scenario-columns}. We shall impose the following: +\begin{enumerate} + \item The following columns satisfy a binary constraint \lispDone{} + \begin{enumerate} + \item \scenCallException{} + \item \scenCallAbortWillRevert{} + \item \scenCallAbortWontRevert{} + \item \scenCallEoaSuccessWontRevert{} + \item \scenCallEoaSuccessWillRevert{} + \item \scenCallSmcFailureWillRevert{} + \item \scenCallSmcFailureWontRevert{} + \item \scenCallSmcSuccessWillRevert{} + \item \scenCallSmcSuccessWontRevert{} + \item \scenCallPrcFailure{} + \item \scenCallPrcSuccessWillRevert{} + \item \scenCallPrcSuccessWontRevert{} + \end{enumerate} +\end{enumerate} diff --git a/hub/scenario/generalities/create.tex b/hub/scenario/generalities/create.tex new file mode 100644 index 0000000..04934b8 --- /dev/null +++ b/hub/scenario/generalities/create.tex @@ -0,0 +1,19 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekScenario_{i} = 1.} +\end{center} +In this section we impose general constraints on \textbf{scenario-columns}. We shall impose the following: +\begin{enumerate} + \item The following columns satisfy a binary constraint \lispDone{} + \begin{enumerate} + \item \scenCreateException{} + \item \scenCreateAbort{} + \item \scenCreateFCondWillRevert{} + \item \scenCreateFCondWontRevert{} + \item \scenCreateNonEmptyInitCodeFailureWillRevert{} + \item \scenCreateNonEmptyInitCodeFailureWontRevert{} + \item \scenCreateNonEmptyInitCodeSuccessWillRevert{} + \item \scenCreateNonEmptyInitCodeSuccessWontRevert{} + \item \scenCreateEmptyInitCodeWillRevert{} + \item \scenCreateEmptyInitCodeWontRevert{} + \end{enumerate} +\end{enumerate} diff --git a/hub/scenario/generalities/precompiles.tex b/hub/scenario/generalities/precompiles.tex new file mode 100644 index 0000000..bf54343 --- /dev/null +++ b/hub/scenario/generalities/precompiles.tex @@ -0,0 +1,25 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekScenario_{i} = 1.} +\end{center} +In this section we impose general constraints on \textbf{scenario-columns}. We shall impose the following: +\begin{enumerate} + \item The following columns, which define the precompile to process, satisfy a binary constraint \lispDone{} + \begin{enumerate} + \item \scenEcrecover{} + \item \scenShaTwo{} + \item \scenRipemd{} + \item \scenIdentity{} + \item \scenModexp{} + \item \scenEcadd{} + \item \scenEcmul{} + \item \scenEcpairing{} + \item \scenBlake{} + \end{enumerate} + \item The following columns, which carry a prediction as to the execution path of the precompile processing, satisfy a binary constraint \lispDone{} + \begin{enumerate}[resume] + \item \scenPrcFailureKnownToHub{} + \item \scenPrcFailureKnownToRam{} + \item \scenPrcSuccessWillRevert{} + \item \scenPrcSuccessWontRevert{} + \end{enumerate} +\end{enumerate} diff --git a/hub/scenario/generalities/return.tex b/hub/scenario/generalities/return.tex new file mode 100644 index 0000000..7d17cd3 --- /dev/null +++ b/hub/scenario/generalities/return.tex @@ -0,0 +1,52 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekScenario_{i} = 1.} +\end{center} +In this section we impose general constraints on \textbf{scenario-columns}. We shall impose the following: +\begin{enumerate} + \item The following columns satisfy a binary constraint \lispDone{} + \begin{enumerate} + \item \scenReturnFromMessageCallWillTouchRam{} + \item \scenReturnFromMessageCallWontTouchRam{} + \item \scenReturnFromDeploymentEmptyByteCodeWillRevert{} + \item \scenReturnFromDeploymentEmptyByteCodeWontRevert{} + \item \scenReturnFromDeploymentNonemptyByteCodeWillRevert{} + \item \scenReturnFromDeploymentNonemptyByteCodeWontRevert{} + \end{enumerate} +\end{enumerate} +These sums are further subject to the following constraint: +\begin{enumerate}[resume] + \item Precisely one of the scenario flags is on on each scenario-row: + \[ + \left[ \begin{array}{cr} + + & \scenCallSum _{i} \\ + + & \scenCreateSum _{i} \\ + + & \scenReturnSum _{i} \\ + + & \scenPrecompileSum _{i} \\ + + & \scenSelfdestructSum _{i} \\ + \end{array} \right] + = 1 + \] + \item Furthermore only one precompile scenario can be active + \[ + \scenPrcScenarioSum_{i} = \scenPrecompileSum_{i} + \] +\end{enumerate} +\saNote{} These binary constraints, in particular the final one, have implicit consequences. For one, all shorthands below +\begin{multicols}{2} + \begin{itemize} + \item $\scenCallSum_{i}$ + \item $\scenCallEntry_{i}$ + \item $\scenCallEoa_{i}$ + \item $\scenCallPrc_{i}$ + \item $\scenCallSmc_{i}$ + \item $\scenCallerWillRevert_{i}$ + \item $\scenCallSuccess_{i}$ + \item $\scenCreateSum_{i}$ + \item $\scenCreateSuccess_{i}$ + \item $\scenPrecompileSum_{i}$ + \item $\scenReturnSum_{i}$ + \item[\vspace{\fill}] + \end{itemize} +\end{multicols} +are all \emph{automatically} binary. + diff --git a/hub/scenario/generalities/selfdestruct.tex b/hub/scenario/generalities/selfdestruct.tex new file mode 100644 index 0000000..15b1d5e --- /dev/null +++ b/hub/scenario/generalities/selfdestruct.tex @@ -0,0 +1,13 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekScenario_{i} = 1.} +\end{center} +In this section we impose general constraints on \textbf{scenario-columns}. We shall impose the following: +\begin{enumerate} + \item The following columns satisfy a binary constraint \lispDone{} + \begin{enumerate} + \item \scenSelfdestructException{} + \item \scenSelfdestructWillRevert{} + \item \scenSelfdestructWontRevertAlreadyMarked{} + \item \scenSelfdestructWontRevertNotYetMarked{} + \end{enumerate} +\end{enumerate} diff --git a/hub/scenario/generalities/single_scenario.tex b/hub/scenario/generalities/single_scenario.tex new file mode 100644 index 0000000..0bcc7a0 --- /dev/null +++ b/hub/scenario/generalities/single_scenario.tex @@ -0,0 +1,40 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption } \peekScenario_{i} = 1.} +\end{center} +We impose the following: +\begin{enumerate}[resume] + \item Precisely one of the scenario flags is on on each scenario-row: + \[ + \left[ \begin{array}{cr} + + & \scenCallSum _{i} \\ + + & \scenCreateSum _{i} \\ + + & \scenPrecompileSum _{i} \\ + + & \scenReturnSum _{i} \\ + + & \scenSelfdestructSum _{i} \\ + \end{array} \right] + = 1 + \] + \item Furthermore only one precompile scenario can be active + \[ + \scenPrcScenarioSum_{i} = \scenPrecompileSum_{i} + \] +\end{enumerate} +\saNote{} These binary constraints, in particular the final one, have implicit consequences. For one, all shorthands below (and many others \dots)are all \textbf{automatically} binary: +\begin{multicols}{2} + \begin{itemize} + \item $\scenCallSum_{i}$ + \item $\scenCallEntry_{i}$ + \item $\scenCallEoa_{i}$ + \item $\scenCallPrc_{i}$ + \item $\scenCallSmc_{i}$ + \item $\scenCallerWillRevert_{i}$ + \item $\scenCallSuccess_{i}$ + \item $\scenCreateSum_{i}$ + \item $\scenCreateSuccess_{i}$ + \item $\scenPrecompileSum_{i}$ + \item $\scenReturnSum_{i}$ + \item[\vspace{\fill}] + \end{itemize} +\end{multicols} + + diff --git a/hub/scenario/intro.tex b/hub/scenario/intro.tex new file mode 100644 index 0000000..18d6e94 --- /dev/null +++ b/hub/scenario/intro.tex @@ -0,0 +1,2 @@ +The present section introduces a number of notational shorthands relevant for \textbf{scenario-rows}. +As such these shorthands should \textbf{only} be used on row with row-index $i$ where $\peekScenario_{i} = 1$. diff --git a/hub/scenario/shorthands/_inputs.tex b/hub/scenario/shorthands/_inputs.tex new file mode 100644 index 0000000..ccdcb13 --- /dev/null +++ b/hub/scenario/shorthands/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsection{\inst{CALL}-instruction shorthands \lispDone{}} \label{hub: scenarios: shorthands: call} \input{scenario/shorthands/call} +\subsubsection{\inst{CREATE}-instruction shorthands \lispWip {}} \label{hub: scenarios: shorthands: create} \input{scenario/shorthands/create} +\subsubsection{\inst{RETURN} related shorthands \lispDone{}} \label{hub: scenarios: shorthands: return} \input{scenario/shorthands/return} +\subsubsection{\inst{SELFDESTRUCT} related shorthands \lispDone{}} \label{hub: scenarios: shorthands: selfdestruct} \input{scenario/shorthands/selfdestruct} +\subsubsection{Precompile related shorthands \lispDone{}} \label{hub: scenarios: shorthands: precompile} \input{scenario/shorthands/precompile} diff --git a/hub/scenario/shorthands/call.tex b/hub/scenario/shorthands/call.tex new file mode 100644 index 0000000..ec6a7a6 --- /dev/null +++ b/hub/scenario/shorthands/call.tex @@ -0,0 +1,333 @@ +We define several notational shorthands: +\[ + \left\{ \begin{array}{lcl} + \scenCallEoa _{i} & \define & + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + + \scenCallEoaSuccessWontRevert _{i} \\ + + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallSmc _{i} & \define & + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + + \scenCallSmcFailureWillRevert _{i} \\ + + \scenCallSmcFailureWontRevert _{i} \\ + + \scenCallSmcSuccessWillRevert _{i} \\ + + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallPrc _{i} & \define & + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + + \scenCallPrcFailure _{i} \\ + + \scenCallPrcSuccessWillRevert _{i} \\ + + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] + \end{array} \right. +\] +\saNote{} \inst{CALL}'s to \textbf{externally owned accounts} that raise no exception and aren't aborted amount to a simple value transfer. +They are \textbf{always} successful (though may be rolled back.) + +\noindent We introduce further useful shorthands: +\[ + \left\{ \begin{array}{lcl} + \scenCallSum _{i} & \define & + \left[ \begin{array}{l} + + \scenCallException _{i} \\ + + \scenCallUnexceptional _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallUnexceptional _{i} & \define & + \left[ \begin{array}{l} + + \scenCallAbort _{i} \\ + + \scenCallEntry _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallAbort _{i} & \define & + \left[ \begin{array}{l} + + \scenCallAbortWillRevert _{i} \\ + + \scenCallAbortWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallEntry _{i} & \define & + \left[ \begin{array}{l} + + \scenCallEoa _{i} \\ + + \scenCallSmc _{i} \\ + + \scenCallPrc _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallNoPrc _{i} & \define & + \left[ \begin{array}{l} + + \scenCallException _{i} \\ + + \scenCallAbort _{i} \\ + + \scenCallEoa _{i} \\ + + \scenCallSmc _{i} \\ + % + \scenCallPrc _{i} \\ + \end{array} \right] \\ + \end{array} \right. \\ +\] +\saNote{} The following relation holds $\scenCallPrc_{i} + \scenCallNoPrc_{i} = \scenCallSum_{i}$. + +We further define the following shorthands: +\[ + \scenCallToPrecompileSuccess _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + + \scenCallPrcSuccessWillRevert _{i} \\ + + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCallEntryKnownWillRevert _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + + \scenCallEoaSuccessWillRevert _{i} \\ + + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCallEntryKnownWontRevert _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +\saNote{} The following relation holds +\[ + \scenCallEntry_{i} + = + \left[ \begin{array}{l} + + \scenCallPrcFailure _{i} \\ + + \scenCallEntryKnownWillRevert _{i} \\ + + \scenCallEntryKnownWontRevert _{i} \\ + \end{array} \right] +\] +The purpose of the +\scenCallEntryKnownWillRevert{} and +\scenCallEntryKnownWontRevert{} +shorthands is to clearly delineate the ``entry'' scenarios which are known to revert (resp. to not revert.) +The main point is that \scenCallPrcFailure{} is compatible with both the current context reverting and not reverting. + +We continue with the shorthands: +\[ + \scenCallSuccess _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + + \scenCallEoaSuccessWontRevert _{i} \\ + + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + + \scenCallSmcSuccessWillRevert _{i} \\ + + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + + \scenCallPrcSuccessWillRevert _{i} \\ + + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCallSmcSuccess _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + + \scenCallSmcSuccessWillRevert _{i} \\ + + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCallSmcFailure _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + + \scenCallSmcFailureWillRevert _{i} \\ + + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCallFailure _{i} \define + \left[ \begin{array}{l} + + \scenCallSmcFailure _{i} \\ + + \scenCallPrcFailure _{i} \\ + \end{array} \right] +\] +We finally set +\[ + \scenCallNoContextChange _{i} \define + \left[ \begin{array}{l} + + \scenCallAbort _{i} \\ + + \scenCallEoa _{i} \\ + + \scenCallPrc _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCallRequiresBothAccountsTwice _{i} \define + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + + \scenCallEoaSuccessWillRevert _{i} \\ + + \scenCallSmcFailureWillRevert _{i} \\ + + \scenCallSmcFailureWontRevert _{i} \\ + + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] +\] +The following shorthands are useful in deciding when to turn on the callee's warmth: +\[ + \left\{ \begin{array}{lcl} + \scenCallCalleeWarmthUpdateNotRequired _{i} & \define & \scenCallException _{i} \vspace{2mm} \\ + \scenCallCalleeWarmthUpdateRequired _{i} & \define & + \left[ \begin{array}{l} + + \scenCallAbort _{i} \\ + + \scenCallEntry _{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +The following shorthands are useful to decide when a \inst{CALL}-type instruction leads to a update in balances and in case those updates have to be undone at what point in time it happens. +\[ + \left\{ \begin{array}{lcl} + \scenCallBalanceUpdateNotRequired _{i} & \define & + \left[ \begin{array}{l} + + \scenCallException _{i} \\ + + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallBalanceUpdateRequired _{i} & \define & + \left[ \begin{array}{l} + + \scenCallEoa _{i} \\ + + \scenCallSmc _{i} \\ + + \scenCallToPrecompileSuccess _{i} \\ + % % + \scenCallException _{i} \\ + % % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallBalanceUpdateUndoneWithCalleeFailure _{i} & \define & + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + % + \scenCallEoaSuccessWillRevert _{i} \\ + + \scenCallSmcFailureWillRevert _{i} \\ + + \scenCallSmcFailureWontRevert _{i} \\ + % + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + % + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + % + \scenCallBalanceUpdateUndoneWithCallerRevert _{i} & \define & + \left[ \begin{array}{l} + % + \scenCallException _{i} \\ + % + \scenCallAbort _{i} \\ + % + \scenCallEoaSuccessWontRevert _{i} \\ + + \scenCallEoaSuccessWillRevert _{i} \\ + % + \scenCallSmcFailureWillRevert _{i} \\ + % + \scenCallSmcFailureWontRevert _{i} \\ + + \scenCallSmcSuccessWillRevert _{i} \\ + % + \scenCallSmcSuccessWontRevert _{i} \\ + % + \scenCallPrcFailure _{i} \\ + + \scenCallPrcSuccessWillRevert _{i} \\ + % + \scenCallPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \end{array} \right. +\] +\saNote{} \scenCallBalanceUpdateRequired{} is the same as \scenCallSmcFailure{}. + +\saNote{}\label{hub: scenario: note: calls that require both accounts twice partition} The reader should observe that the following relation holds: +\[ + \scenCallRequiresBothAccountsTwice _{i} + = + \left[ \begin{array}{cl} + + & \scenCallBalanceUpdateUndoneWithCalleeFailure _{i} \\ + + & \scenCallBalanceUpdateUndoneWithCallerRevert _{i} \\ + \end{array} \right] +\] diff --git a/hub/scenario/shorthands/create.tex b/hub/scenario/shorthands/create.tex new file mode 100644 index 0000000..9d3aa6f --- /dev/null +++ b/hub/scenario/shorthands/create.tex @@ -0,0 +1,201 @@ +We introduce the following shorthands for the handling of \inst{CREATE}-type instructions. +\[ + \hspace*{-2cm} + \left\{ \begin{array}{lcl} + \scenCreateExecutionEmptyInitCode_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + % + \scenCreateFCondWontRevert _{i} \\ + % + \scenCreateFCondWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + + \scenCreateEmptyInitCodeWontRevert _{i} \\ + + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateExecutionNonEmptyInitCode_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + % + \scenCreateFCondWontRevert _{i} \\ + % + \scenCreateFCondWillRevert _{i} \\ + + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + % + \scenCreateEmptyInitCodeWontRevert _{i} \\ + % + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateExecution_{i} & \!\!\! \define \!\!\! & + \left[ \begin{array}{l} + + \scenCreateExecutionNonEmptyInitCode _{i} \\ + + \scenCreateExecutionEmptyInitCode _{i} \\ + \end{array} \right] + \\ + & \!\!\! \define \!\!\! & + \left[ \begin{array}{l} + + \scenCreateSuccess _{i} \\ + + \scenCreateFailure _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateRebuffed _{i} & \define & + \left[ \begin{array}{l} + + \scenCreateException _{i} \\ + + \scenCreateAbort _{i} \\ + + \scenCreateFCond _{i} \\ + \end{array} \right] + \end{array} \right. +\] +and +\[ + \hspace*{-2cm} + \left\{ \begin{array}{lcl} + \scenCreateFCond_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + + \scenCreateFCondWontRevert _{i} \\ + + \scenCreateFCondWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + % + \scenCreateEmptyInitCodeWontRevert _{i} \\ + % + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateUnexceptional_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + + \scenCreateAbort _{i} \\ + + \scenCreateFCond _{i} \\ + + \scenCreateExecution _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateSum_{i} & \define & + \left[ \begin{array}{l} + + \scenCreateException _{i} \\ + + \scenCreateUnexceptional _{i} \\ + \end{array} \right] + \end{array} \right. +\] +and +\[ + \scenCreateComputeAddress_{i} \define + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + + \scenCreateFCond _{i} \\ + + \scenCreateExecution _{i} \\ + \end{array} \right] +\] +and +\[ + \scenCreateNoContextChange_{i} \define + \left[ \begin{array}{l} + + \scenCreateAbort _{i} \\ + + \scenCreateFCond _{i} \\ + + \scenCreateExecutionEmptyInitCode _{i} \\ + \end{array} \right] +\] +and +\[ + \hspace*{-2cm} + \left\{ \begin{array}{lcl} + \scenCreateSuccess_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + % + \scenCreateFCondWontRevert _{i} \\ + % + \scenCreateFCondWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + + \scenCreateEmptyInitCodeWontRevert _{i} \\ + + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateFailure_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + % + \scenCreateFCondWontRevert _{i} \\ + % + \scenCreateFCondWillRevert _{i} \\ + + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + % + \scenCreateEmptyInitCodeWontRevert _{i} \\ + % + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \end{array} \right. +\] +and +\[ + \hspace*{-2cm} + \left\{ \begin{array}{lcl} + \scenCreateCreatorStateChangeWillRevert_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + % + \scenCreateFCondWontRevert _{i} \\ + + \scenCreateFCondWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + % + \scenCreateEmptyInitCodeWontRevert _{i} \\ + + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateCreatorStateChangeWontRevert_{i} & \define & + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + + \scenCreateFCondWontRevert _{i} \\ + % + \scenCreateFCondWillRevert _{i} \\ + + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + + \scenCreateEmptyInitCodeWontRevert _{i} \\ + % + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateCreatorStateChange_{i} & \define & + \left[ \begin{array}{l} + + \scenCreateFCond _{i} \\ + + \scenCreateExecution _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenCreateNoCreatorStateChange _{i} & \define & + \left[ \begin{array}{l} + + \scenCreateException _{i} \\ + + \scenCreateAbort _{i} \\ + \end{array} \right] + \\ + \end{array} \right. +\] +and +\[ + % I'm not using this one ... + % also I'm confused why this doesn't include \scenCreateFCondWillRevert as one will have to revert warmth (IIRC) + \scenCreateSimpleRevert_{i} \define + \left[ \begin{array}{l} + % + \scenCreateException _{i} \\ + % + \scenCreateAbort _{i} \\ + % + \scenCreateFCondWontRevert _{i} \\ + + \scenCreateFCondWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWontRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeFailureWillRevert _{i} \\ + % + \scenCreateNonEmptyInitCodeSuccessWontRevert _{i} \\ + + \scenCreateNonEmptyInitCodeSuccessWillRevert _{i} \\ + % + \scenCreateEmptyInitCodeWontRevert _{i} \\ + + \scenCreateEmptyInitCodeWillRevert _{i} \\ + \end{array} \right] +\] diff --git a/hub/scenario/shorthands/precompile.tex b/hub/scenario/shorthands/precompile.tex new file mode 100644 index 0000000..99ba736 --- /dev/null +++ b/hub/scenario/shorthands/precompile.tex @@ -0,0 +1,105 @@ +We define some useful shorthands for precompiles. +In our treatment of calls to precompiles we are able to provide a mostly unified treatment for most precompiles with the exception of \inst{MODEXP} and \inst{BLAKE2f}. +We label all other precompiles as ``common'' precompiles. +\[ + \scenPrecompileCommonNotIdentity _{i} + \define + \left[ \begin{array}{l} + + \scenEcrecover _{i} \\ + + \scenShaTwo _{i} \\ + + \scenRipemd _{i} \\ + % + \scenIdentity _{i} \\ + % + \scenModexp _{i} \\ + + \scenEcadd _{i} \\ + + \scenEcmul _{i} \\ + + \scenEcpairing _{i} \\ + % + \scenBlake _{i} \\ + \end{array} \right] +\] +and +\[ + \scenPrecompileCommon _{i} + \define + \left[ \begin{array}{l} + + \scenPrecompileCommonNotIdentity _{i} \\ + + \scenIdentity _{i} \\ + \end{array} \right] +\] +and +\[ + \scenPrecompileSum_{i} + \define + \left[ \begin{array}{l} + + \scenPrecompileCommon _{i} \\ + + \scenModexp _{i} \\ + + \scenBlake _{i} \\ + \end{array} \right] +\] +We further define +\[ + \scenPrecompileMayOnlyFailInHub _{i} + \define + \left[ \begin{array}{l} + + \scenEcrecover _{i} \\ + + \scenShaTwo _{i} \\ + + \scenRipemd _{i} \\ + + \scenIdentity _{i} \\ + % + \scenModexp _{i} \\ + % + \scenEcadd _{i} \\ + % + \scenEcmul _{i} \\ + % + \scenEcpairing _{i} \\ + % + \scenBlake _{i} \\ + \end{array} \right] +\] +and +\[ + \scenPrecompileMayOnlyFailInRam _{i} + \define + \left[ \begin{array}{l} + % + \scenEcrecover _{i} \\ + % + \scenShaTwo _{i} \\ + % + \scenRipemd _{i} \\ + % + \scenIdentity _{i} \\ + + \scenModexp _{i} \\ + % + \scenEcadd _{i} \\ + % + \scenEcmul _{i} \\ + % + \scenEcpairing _{i} \\ + % + \scenBlake _{i} \\ + \end{array} \right] +\] +and +\[ + \scenPrecompileWeightedSum _{i} + \define + \left[ \begin{array}{l} + + \; 1 \cdot \scenEcrecover _{i} \\ + + \; 2 \cdot \scenShaTwo _{i} \\ + + \; 3 \cdot \scenRipemd _{i} \\ + + \; 4 \cdot \scenIdentity _{i} \\ + + \; 5 \cdot \scenModexp _{i} \\ + + \; 6 \cdot \scenEcadd _{i} \\ + + \; 7 \cdot \scenEcmul _{i} \\ + + \; 8 \cdot \scenEcpairing _{i} \\ + + \; 9 \cdot \scenBlake _{i} \\ + \end{array} \right] +\] +We also define the following +\[ + \left\{ \begin{array}{lcl} + \scenPrcFailure _{i} & \define & + \left[ \begin{array}{l} + + \scenPrcFailureKnownToHub _{i} \\ + + \scenPrcFailureKnownToRam _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \scenPrcSuccess _{i} & \define & + \left[ \begin{array}{l} + + \scenPrcSuccessWillRevert _{i} \\ + + \scenPrcSuccessWontRevert _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \scenPrcScenarioSum _{i} & \define & + \left[ \begin{array}{l} + + \scenPrcFailure _{i} \\ + + \scenPrcSuccess _{i} \\ + \end{array} \right] + \end{array} \right. +\] diff --git a/hub/scenario/shorthands/return.tex b/hub/scenario/shorthands/return.tex new file mode 100644 index 0000000..f8284e8 --- /dev/null +++ b/hub/scenario/shorthands/return.tex @@ -0,0 +1,76 @@ +We define several notational shorthands: +\[ + \scenReturnFromMessageCall_{i} \define + \left[ \begin{array}{cl} + % + & \scenReturnException _{i} \\ + + & \scenReturnFromMessageCallWillTouchRam _{i} \\ + + & \scenReturnFromMessageCallWontTouchRam _{i} \\ + % + & \scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} \\ + % + & \scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} \\ + % + & \scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} \\ + % + & \scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenReturnEmptyDeployment _{i} \define + \left[ \begin{array}{cl} + % + & \scenReturnException _{i} \\ + % + & \scenReturnFromMessageCallWillTouchRam _{i} \\ + % + & \scenReturnFromMessageCallWontTouchRam _{i} \\ + % + & \scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} \\ + % + & \scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} \\ + + & \scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} \\ + + & \scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenReturnNonemptyDeployment _{i} \define + \left[ \begin{array}{cl} + % + & \scenReturnException _{i} \\ + % + & \scenReturnFromMessageCallWillTouchRam _{i} \\ + % + & \scenReturnFromMessageCallWontTouchRam _{i} \\ + + & \scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} \\ + + & \scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} \\ + % + & \scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} \\ + % + & \scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenReturnFromDeployment _{i} \define + \left[ \begin{array}{cl} + + & \scenReturnEmptyDeployment_{i} \\ + + & \scenReturnNonemptyDeployment_{i} \\ + \end{array} \right] +\] +and +\[ + \scenReturnDeploymentWillRevert _{i} \define + \left[ \begin{array}{cl} + % + & \scenReturnException _{i} \\ + % + & \scenReturnFromMessageCallWillTouchRam _{i} \\ + % + & \scenReturnFromMessageCallWontTouchRam _{i} \\ + + & \scenReturnFromDeploymentEmptyByteCodeWillRevert _{i} \\ + % + & \scenReturnFromDeploymentEmptyByteCodeWontRevert _{i} \\ + + & \scenReturnFromDeploymentNonemptyByteCodeWillRevert _{i} \\ + % + & \scenReturnFromDeploymentNonemptyByteCodeWontRevert _{i} \\ + \end{array} \right] +\] +and +\[ + \scenReturnRaisesNoException _{i} \define + \left[ \begin{array}{cl} + + & \scenReturnFromMessageCall _{i} \\ + + & \scenReturnFromDeployment _{i} \\ + \end{array} \right] +\] +and +\[ + \scenReturnSum _{i} \define + \left[ \begin{array}{cl} + + & \scenReturnException _{i} \\ + + & \scenReturnRaisesNoException _{i} \\ + \end{array} \right] +\] diff --git a/hub/scenario/shorthands/selfdestruct.tex b/hub/scenario/shorthands/selfdestruct.tex new file mode 100644 index 0000000..d48bff9 --- /dev/null +++ b/hub/scenario/shorthands/selfdestruct.tex @@ -0,0 +1,38 @@ +We define several \inst{SELFDESTRUCT} related shorthands. +\[ + \left\{ \begin{array}{lcl} + \scenSelfdestructWontRevert_{i} + & \define & + \left[ \begin{array}{cl} + % + & \scenSelfdestructException _{i} \\ + % + & \scenSelfdestructUnexceptional _{i} \\ + % + & \scenSelfdestructWillRevert _{i} \\ + + & \scenSelfdestructWontRevertAlreadyMarked _{i} \\ + + & \scenSelfdestructWontRevertNotYetMarked _{i} \\ + % + & \scenSelfdestructWontRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenSelfdestructUnexceptional_{i} + & \define & + \left[ \begin{array}{cl} + % + & \scenSelfdestructException _{i} \\ + % + & \scenSelfdestructUnexceptional _{i} \\ + + & \scenSelfdestructWillRevert _{i} \\ + % + & \scenSelfdestructWontRevertAlreadyMarked _{i} \\ + % + & \scenSelfdestructWontRevertNotYetMarked _{i} \\ + + & \scenSelfdestructWontRevert _{i} \\ + \end{array} \right] + \vspace{2mm} \\ + \scenSelfdestructSum_{i} + & \define & + \left[ \begin{array}{cl} + + & \scenSelfdestructException _{i} \\ + + & \scenSelfdestructUnexceptional _{i} \\ + % + & \scenSelfdestructWillRevert _{i} \\ + % + & \scenSelfdestructWontRevertAlreadyMarked _{i} \\ + % + & \scenSelfdestructWontRevertNotYetMarked _{i} \\ + % + & \scenSelfdestructWontRevert _{i} \\ + \end{array} \right] + \\ + \end{array} \right. +\] diff --git a/hub/scenario/tables/_inputs.tex b/hub/scenario/tables/_inputs.tex new file mode 100644 index 0000000..4eeb142 --- /dev/null +++ b/hub/scenario/tables/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsection{\inst{CALL} table} \label{hub: scenarios: tables: call} \input{scenario/tables/call} +\subsubsection{\inst{CREATE} table} \label{hub: scenarios: tables: create} \input{scenario/tables/create} +\subsubsection{\inst{RETURN} table} \label{hub: scenarios: tables: return} \input{scenario/tables/return} +\subsubsection{Precompile address table} \label{hub: scenarios: tables: precompile address} \input{scenario/tables/precompile_addresses} +\subsubsection{Precompile scenario table} \label{hub: scenarios: tables: precompile scenario} \input{scenario/tables/precompile_scenario} diff --git a/hub/scenario/tables/_local.tex b/hub/scenario/tables/_local.tex new file mode 100644 index 0000000..2428e94 --- /dev/null +++ b/hub/scenario/tables/_local.tex @@ -0,0 +1,63 @@ +\newcommand{\STAB}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}} + + % \def\gCheckMark {\cellcolor{solarized-green}{\rotatebox[origin=c]{45}{$\bm{1}$}}} + % \def\gCheckMark {\rotatebox[origin=c]{45}{\text{~{\color{solarized-green}\faCheck}~}}} + % \def\rCross {\rotatebox[origin=c]{45}{\text{~{\color{gray}\faClose}~}}} + +\def\gCheckMark {\text{~{\color{solarized-green}\faCheck}~}} +\def\rCross {\text{~{\color{gray}\faClose}~}} +\def\gCM {\gCheckMark} +\def\rC {\rCross} +\def\locRotationAngle {90} + + + +\def\vcolCallStaticx {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\stackStaticx}}} +\def\vcolCallMxpx {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\stackMxpx}}} +\def\vcolCallOogx {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\stackOogx}}} +\def\vcolCallException {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallException}}} +\def\vcolCallAbortWill {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallAbortWillRevert}}} +\def\vcolCallAbortWont {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallAbortWontRevert}}} +\def\vcolCallEoaWill {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallEoaSuccessWillRevert}}} +\def\vcolCallEoaWont {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallEoaSuccessWontRevert}}} +\def\vcolCallSmcFailWill {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallSmcFailureWillRevert}}} +\def\vcolCallSmcFailWont {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallSmcFailureWontRevert}}} +\def\vcolCallSmcSuccWill {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallSmcSuccessWillRevert}}} +\def\vcolCallSmcSuccWont {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallSmcSuccessWontRevert}}} +\def\vcolCallPrcFail {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallPrcFailure}}} +\def\vcolCallPrcSuccWont {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallPrcSuccessWontRevert}}} +\def\vcolCallPrcSuccWill {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCallPrcSuccessWillRevert}}} + +\def\columnCreateA {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateException}}} +\def\columnCreateB {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateAbort}}} +\def\columnCreateC {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateFCondWontRevert}}} +\def\columnCreateD {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateFCondWillRevert}}} +\def\columnCreateE {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateNonEmptyInitCodeFailureWontRevert}}} +\def\columnCreateF {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateNonEmptyInitCodeFailureWillRevert}}} +\def\columnCreateG {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateNonEmptyInitCodeSuccessWontRevert}}} +\def\columnCreateH {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateNonEmptyInitCodeSuccessWillRevert}}} +\def\columnCreateI {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateEmptyInitCodeWontRevert}}} +\def\columnCreateJ {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenCreateEmptyInitCodeWillRevert}}} + +\def\columnReturnA {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnException}}} +\def\columnReturnB {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnFromMessageCallWillTouchRam}}} +\def\columnReturnC {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnFromMessageCallWontTouchRam}}} +\def\columnReturnD {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnFromDeploymentEmptyByteCodeWillRevert}}} +\def\columnReturnE {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnFromDeploymentEmptyByteCodeWontRevert}}} +\def\columnReturnF {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnFromDeploymentNonemptyByteCodeWillRevert}}} +\def\columnReturnG {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenReturnFromDeploymentNonemptyByteCodeWontRevert}}} + +\def\columnPrcEcrecover {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenEcrecover}}} +\def\columnPrcShaTwo {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenShaTwo}}} +\def\columnPrcRipemd {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenRipemd}}} +\def\columnPrcIdentity {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenIdentity}}} +\def\columnPrcModexp {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenModexp}}} +\def\columnPrcEcAdd {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenEcadd}}} +\def\columnPrcEcMul {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenEcmul}}} +\def\columnPrcEcPairing {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenEcpairing}}} +\def\columnPrcBlake {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenBlake}}} + +\def\columnPrcFKTH {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenPrcFailureKnownToHub}}} +\def\columnPrcFKTR {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenPrcFailureKnownToRam}}} +\def\columnPrcSuccWill {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenPrcSuccessWillRevert}}} +\def\columnPrcSuccWont {\STAB{\rotatebox[origin=c]{\locRotationAngle}{\scenPrcSuccessWontRevert}}} diff --git a/hub/scenario/tables/call.tex b/hub/scenario/tables/call.tex new file mode 100644 index 0000000..c39ad35 --- /dev/null +++ b/hub/scenario/tables/call.tex @@ -0,0 +1,28 @@ +\[ + \hspace*{-2cm} + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|c|c|c||c|c||c|c|c|c||c|c|c|} \cline{2-13} + \multicolumn{1}{c|}{} & \vcolCallException & \vcolCallAbortWill & \vcolCallAbortWont & \vcolCallEoaWill & \vcolCallEoaWont & \vcolCallSmcFailWill & \vcolCallSmcFailWont & \vcolCallSmcSuccWill & \vcolCallSmcSuccWont & \vcolCallPrcFail & \vcolCallPrcSuccWill & \vcolCallPrcSuccWont \\ \hline + \scenCallSum & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCallUnexceptional & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCallAbort & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC \\ \hline \hline + \scenCallEntry & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline \hline + \scenCallEoa & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC & \rC & \rC \\ \hline + \scenCallSmc & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \rC & \rC & \rC \\ \hline + \scenCallPrc & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \gCM \\ \hline + \scenCallNoPrc & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \rC & \rC & \rC \\ \hline \hline + \scenCallToPrecompileSuccess & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM \\ \hline + \scenCallEntryKnownWillRevert & \rC & \rC & \rC & \gCM & \rC & \gCM & \rC & \rC & \gCM & \rC & \gCM & \rC \\ \hline + \scenCallEntryKnownWontRevert & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC \\ \hline \hline + \scenCallFailure & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \gCM & \rC & \rC \\ \hline + \scenCallSuccess & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \gCM & \gCM & \rC & \gCM & \gCM \\ \hline + \scenCallSmcSuccess & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \rC \\ \hline + \scenCallSmcFailure & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC \\ \hline + \scenCallNoContextChange & \rC & \gCM & \gCM & \gCM & \gCM & \rC & \rC & \rC & \rC & \gCM & \gCM & \gCM \\ \hline \hline + \scenCallBalanceUpdateNotRequired & \gCM & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC & \rC & \gCM & \rC & \rC \\ \hline + \scenCallBalanceUpdateRequired & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \rC & \gCM & \gCM \\ \hline \hline + \scenCallRequiresBothAccountsTwice & \rC & \rC & \rC & \gCM & \rC & \gCM & \gCM & \gCM & \rC & \rC & \gCM & \rC \\ \hline + \scenCallBalanceUpdateUndoneWithCalleeFailure & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC \\ \hline + \scenCallBalanceUpdateUndoneWithCallerRevert & \rC & \rC & \rC & \gCM & \rC & \rC & \rC & \gCM & \rC & \rC & \gCM & \rC \\ \hline + \end{array} +\] diff --git a/hub/scenario/tables/create.tex b/hub/scenario/tables/create.tex new file mode 100644 index 0000000..e4deefb --- /dev/null +++ b/hub/scenario/tables/create.tex @@ -0,0 +1,22 @@ +\[ + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|c|c|c|c|c|c|c|c|c|c|} \cline{2-11} + \multicolumn{1}{c|}{} & \columnCreateA & \columnCreateB & \columnCreateD & \columnCreateC & \columnCreateF & \columnCreateE & \columnCreateH & \columnCreateG & \columnCreateJ & \columnCreateI \\ \hline + \scenCreateSum & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCreateUnexceptional & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCreateFCond & \rC & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC & \rC \\ \hline \hline + \scenCreateRebuffed & \gCM & \gCM & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC & \rC \\ \hline + \scenCreateNotRebuffed & \rC & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCreateExecutionEmptyInitCode & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM \\ \hline + \scenCreateExecutionNonEmptyInitCode & \rC & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \rC & \rC \\ \hline \hline + \scenCreateNoCreatorStateChange & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC & \rC & \rC & \rC \\ \hline + \scenCreateCreatorStateChange & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCreateCreatorStateChangeWillRevert & \rC & \rC & \gCM & \rC & \gCM & \rC & \gCM & \rC & \gCM & \rC \\ \hline + \scenCreateCreatorStateChangeWontRevert & \rC & \rC & \rC & \gCM & \rC & \gCM & \rC & \gCM & \rC & \gCM \\ \hline \hline + \scenCreateSuccess & \rC & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenCreateFailure & \rC & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC \\ \hline \hline + \scenCreateSimpleRevert & \rC & \rC & \gCM & \rC & \rC & \rC & \gCM & \rC & \gCM & \rC \\ \hline + \scenCreateNoContextChange & \rC & \gCM & \gCM & \gCM & \rC & \rC & \rC & \rC & \gCM & \gCM \\ \hline + \scenCreateComputeAddress & \rC & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \end{array} +\] diff --git a/hub/scenario/tables/precompile_addresses.tex b/hub/scenario/tables/precompile_addresses.tex new file mode 100644 index 0000000..fa13076 --- /dev/null +++ b/hub/scenario/tables/precompile_addresses.tex @@ -0,0 +1,11 @@ +\[ + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|c|c|c|c|c|c|c|c|c|} \cline{2-10} + \multicolumn{1}{c|}{} & \columnPrcEcrecover & \columnPrcShaTwo & \columnPrcRipemd & \columnPrcIdentity & \columnPrcModexp & \columnPrcEcAdd & \columnPrcEcMul & \columnPrcEcPairing & \columnPrcBlake \\ \hline + \scenPrecompileCommonNotIdentity & \gCM & \gCM & \gCM & \rC & \rC & \gCM & \gCM & \gCM & \rC \\ \hline + \scenPrecompileCommon & \gCM & \gCM & \gCM & \gCM & \rC & \gCM & \gCM & \gCM & \rC \\ \hline + \scenPrecompileSum & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenPrecompileMayOnlyFailInHub & \gCM & \gCM & \gCM & \gCM & \rC & \rC & \rC & \rC & \rC \\ \hline + \scenPrecompileMayOnlyFailInRam & \rC & \rC & \rC & \rC & \gCM & \rC & \rC & \rC & \rC \\ \hline + \end{array} +\] diff --git a/hub/scenario/tables/precompile_scenario.tex b/hub/scenario/tables/precompile_scenario.tex new file mode 100644 index 0000000..2bb35e6 --- /dev/null +++ b/hub/scenario/tables/precompile_scenario.tex @@ -0,0 +1,9 @@ +\[ + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|c|c|c|c|} \cline{2-5} + \multicolumn{1}{c|}{} & \columnPrcFKTH & \columnPrcFKTR & \columnPrcSuccWill & \columnPrcSuccWont \\ \hline + \scenPrcFailure & \gCM & \gCM & \rC & \rC \\ \hline + \scenPrcSuccess & \rC & \rC & \gCM & \gCM \\ \hline + \scenPrcScenarioSum & \gCM & \gCM & \gCM & \gCM \\ \hline + \end{array} +\] diff --git a/hub/scenario/tables/return.tex b/hub/scenario/tables/return.tex new file mode 100644 index 0000000..690f2cc --- /dev/null +++ b/hub/scenario/tables/return.tex @@ -0,0 +1,13 @@ +\[ + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|c|c|c|c|c|c|c|} \cline{2-8} + \multicolumn{1}{c|}{} & \columnReturnA & \columnReturnB & \columnReturnC & \columnReturnD & \columnReturnE & \columnReturnF & \columnReturnG \\ \hline + \scenReturnFromMessageCall & \rC & \gCM & \gCM & \rC & \rC & \rC & \rC \\ \hline + \scenReturnFromDeployment & \rC & \rC & \rC & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenReturnEmptyDeployment & \rC & \rC & \rC & \gCM & \gCM & \rC & \rC \\ \hline + \scenReturnNonemptyDeployment & \rC & \rC & \rC & \rC & \rC & \gCM & \gCM \\ \hline + \scenReturnDeploymentWillRevert & \rC & \rC & \rC & \gCM & \rC & \gCM & \rC \\ \hline + \scenReturnRaisesNoException & \rC & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \scenReturnSum & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM & \gCM \\ \hline + \end{array} +\] diff --git a/hub/stack/_inputs.tex b/hub/stack/_inputs.tex new file mode 100644 index 0000000..8459b19 --- /dev/null +++ b/hub/stack/_inputs.tex @@ -0,0 +1,5 @@ +\section{Stack-rows} +\subsection{Introduction \lispDone{}} \label{hub: stack: intro} \input{stack/_intro} +\subsection{Ordering stack operations \lispDone{}} \label{hub: stack: order} \input{stack/_order} +\subsection{Stack patterns} \label{hub: stack: patterns} \input{stack/patterns/_inputs} +\subsection{$\requestHashName$ and $\maybeRequestHashName$ constraints \lispDone{}} \label{hub: stack: request hash} \input{stack/request_hash} diff --git a/hub/stack/_intro.tex b/hub/stack/_intro.tex new file mode 100644 index 0000000..af17e7d --- /dev/null +++ b/hub/stack/_intro.tex @@ -0,0 +1,35 @@ +The present section provides various definitions for so-called stack patterns. A \textbf{stack pattern}\label{def: stack pattern} is a collection of constraints which involve the following 22\footnote{$22 = 4 \cdot 5 + 2$} columns (where $k \in \{1, 2, 3, 4 \}$): +\begin{multicols}{3} +\begin{enumerate} + \item $\stackItemHeight{k}$ + \item $\stackItemPop{k}$ + \item $\stackItemValHi{k}$, $\stackItemValLo{k}$ + \item $\stackItemStamp{k}$ + \item $\stackHeight$, $\stackHeight\new$ +\end{enumerate} +\end{multicols} +\noindent Although we don't impose this condition in the present section, in applications stack pattern constraints will \emph{only} apply to stack rows\footnote{i.e. rows $i$ satisfying $\peekStack = 1$; this is implicit in the column names which involve the signifier $\stackSignifier$ of stack-rows}. A stack pattern defines a \textbf{layout for stack items in a stack row}. The \zkEvm{} arithmetization provides 4 \textbf{stack items}\label{def: stack item} per stack row, labeled by $k \in \{1, 2, 3, 4 \}$. Each stack item is either empty (see section~\ref{hub: stack patterns: empty item}) or provides us with a view into the (current execution context's) stack. We provide the desired interpretation of what is on display in the $k$-th stack item (\emph{given that it is nonempty}): +\begin{description} + \item[\underline{$\stackItemHeight{k}$:}] contains the height $\in \{1, 2, \dots, 1024 \}$ within the stack of the stack item on display; + \item[\underline{$\stackItemPop{k}$:}] bit detailing whether a value is to be removed\footnote{\label{footnote: pop at height bla}at height $\stackItemHeight{k}$} from the stack ($\stackItemPop{k} = 1$) or inserted\cref{footnote: pop at height bla} ($\stackItemPop{k} = 0$); + \item[\underline{$\stackItemValHi{k} \, / \, \stackItemValLo{k}$:}] value either removed at $\stackItemHeight{k}$ (if $\stackItemPop{k} = 1$) or inserted at $\stackItemHeight{k}$ (if $\stackItemPop{k} = 0$); + \item[\underline{$\stackItemStamp{k}$:}] a time stamp; the four time stamps (as $k$ ranges over $\{1, 2, 3, 4 \}$) define the order in which the stack operations (removing items, inserting items) are to be executed. +\end{description} +\saNote{} A stack item's height may also take on the value $0$ but only if the item is empty, see section~\ref{hub: stack patterns: empty item}. + +\saNote{}\label{note: touch stack items at any height} Our arithmetization allows us to remove and insert values \emph{at any height of the stack}. This is important for for \inst{DUPX} and \inst{SWAPX} instructions in particular. + +\saNote{} In our arithmetization of the stack there is no such thing as simply ``peeking at'' a value in the stack. +Every inspection of a value on the stack is destructive in the sense that it triggers the relevant $\stackItemPop{k}$ flag. +If an item is simply to be looked at (as is the case for \inst{DUPX} instructions for instance) the item must first be popped then again pushed onto the same slot on the stack. +To be slightly more precise with \inst{DUPX} instructions our arithmetization +(\emph{a}) pops the value to be duplicated (in stack item $n°1$), thus $\stackItemPop{1} = 1$; +(\emph{b}) reinserts it at the same height (in stack item $n°2$), thus $\stackItemPop{2} = 0$; +(\emph{c}) duplicates the value (in stack item $n°4$) i.e. $\stackItemPop{4} = 0$; see section~\ref{hub: stack patterns: dup}. A similar dance happens for \inst{SWAPX} instructions, see section~\ref{hub: stack patterns: swap}. + +Every stack row displays $0$, $1$, $2$, $3$, or $4$ stack items (depending on how many are empty.) +As already mentioned, the stack pattern specifies the layout of the data i.e. which stack items are empty and which aren't, and, for the nonempty ones, whether the value is removed or inserted and at what height. +\textbf{Every instruction follows a particular stack pattern}. Many instructions share the same stack pattern. There are thus fewer stack patterns than there are instructions. For instance all \inst{DUP\_X}-instructions share the same stack pattern (\dupSP.) + +We make a fundamental distinction between instructions in terms of \textbf{whether their stack pattern spans one or two rows}. Instructions therefore come with an instruction decoded binary flag $\tli$ specifying whether it is a $\TLI$. Typically instructions $w$ with $\alpha_{w} + \delta_{w} > 4$ must span two rows. Thus \inst{CALL}'s pop seven items off the stack ($\delta_{\inst{CALL}} = 7$) and push one onto it $(\alpha_\inst{CALL} = 1$) and must therefore span two rows. But our arithmetization also considers \inst{CREATE} to be a $\TLI$ (despite the fact that $\alpha_{\inst{CREATE}} + \delta_{\inst{CREATE}} = 1 + 3 = 4$.) We have made this choice to achieve greater uniformity among the \inst{CREATE}-type instructions given that \inst{CREATE2} is by necessity a $\TLI$. Similar choices have been made elsewhere, e.g. all \inst{LOG}-type instructions are $\TLI$'s. + diff --git a/hub/stack/_order.tex b/hub/stack/_order.tex new file mode 100644 index 0000000..4369efe --- /dev/null +++ b/hub/stack/_order.tex @@ -0,0 +1,32 @@ +The order in which stack items are removed / inserted is important for the stack consistency argument, see section~(\ref{hub: consistencies: stack}). +To simplify things we impose a total order on all times at which a stack item is touched. +Every stack item has its dedicated stamp column $\stackItemStamp{k}$, $k = 1, 2, 3, 4$. +These stamps are pegged against the \hubStamp{}. +Thus one will find many a constraint of the form +\[ + \stackItemStamp{k}_{i} = + \hubTau \cdot \hubStamp_{i} + \texttt{a} +\] +where \texttt{a} is small as we will make precise below. We also describe the constraints that the (as of yet undefined) parameter $\hubTau$ has to obey. + +The only constraints which the $\hubTau$ constant must abide by are +(\emph{a}) for a given instruction and a given \hubStamp{} we may choose sufficiently many distinct \texttt{a}'s so as to be able to provide each and every touched stack item its own unique $\stackItemStamp{k}$ +(\emph{b}) two different instructions may never provide two touched stack items the same $\stackItemStamp{k}$. + +The most stack items any instruction touches is \textbf{eight} (achieved both by \inst{CALL} and \inst{CALLCODE}). +Also the $\hubStamp$ grows by 1 from one instruction to the next, see section\ref{hub: heartbeat: hub stamp}. +As such setting +\[ + \hubTau \define 8 +\] +is enough, and we may always choose \col{a} from $0 \leq \texttt{a} < \hubTau$ (i.e. $\texttt{a} \in \{0, 1, 2, \dots, 7 \}$.) + +The operations performed on \textbf{nonempty} stack items at time $\hubStamp$ are labeled with a $\stackItemStamp{k}$ chosen from the set below: +\[ + \stackItemStamp{k} \in + \left\{ \begin{array}{r} + \hubTau \cdot \hubStamp + 0, \hubTau \cdot \hubStamp + 1, \hubTau \cdot \hubStamp + 2, \hubTau \cdot \hubStamp + 3, \\ + \hubTau \cdot \hubStamp + 4, \hubTau \cdot \hubStamp + 5, \hubTau \cdot \hubStamp + 6, \hubTau \cdot \hubStamp + 7, \\ + \end{array} \right\} +\] +This achieves a total oder on the $\stackItemStamp{k}$ for \textbf{nontrivial} stack item operations. diff --git a/hub/stack/patterns/0_0.tex b/hub/stack/patterns/0_0.tex new file mode 100644 index 0000000..6a6be8d --- /dev/null +++ b/hub/stack/patterns/0_0.tex @@ -0,0 +1,15 @@ +We let $\zeroZeroSP_{i}$ stand for the following collection of constraints whereby all four stack items are empty and the stack height remains unadulterated: +% \begin{description} +% \item[\underline{Stack Item $n^\circ\,1, 2, 3, 4$:}] $\emptySP_{i}$; +% \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i}$, +% \end{description} +\[ + \zeroZeroSP_{i} + \iff + \left\{ + \begin{array}{l} + \emptySP_{i} \\ + \stackHeight{}\new{}_{i} = \stackHeight{}_{i} \\ + \end{array} + \right. +\] \ No newline at end of file diff --git a/hub/stack/patterns/0_1.tex b/hub/stack/patterns/0_1.tex new file mode 100644 index 0000000..a5f64d1 --- /dev/null +++ b/hub/stack/patterns/0_1.tex @@ -0,0 +1,47 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +We let $\zeroOneSP_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] + is empty i.e. $\emptyStackItem{1}_{i}$; + \item[\underline{Stack Item $n^\circ\,2$:}] + is empty i.e. $\emptyStackItem{2}_{i}$; + \item[\underline{Stack Item $n^\circ\,3$:}] + is empty i.e. $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] + an item is pushed on stack: + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight {4} _{i} & \!\!\! = \!\!\! & \stackHeight_{i} + 1 \\ + \stackItemPop {4} _{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemStamp {4} _{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} \\ + \end{array} \right. + \] + \item[\underline{Height update:}] + $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} + 1$; +\end{description} + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|c|c|c|r|} + \cline{2-5} + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight {k} _{i} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} & \col{h} + 1 \\ \hline + \stackItemValHi {k} _{i} / \stackItemValLo {k} _{i} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} & \col{res} \\ \hline + \stackItemPop {k} _{i} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} & 0 \\ \hline + \stackItemStamp {k} _{i} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} & \hubTau \cdot \col{st} \\ \hline + \end{array} +\] +\label{fig: create stack pattern} +\caption{% +Graphical representation of $\zeroOneSP_{i}$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} diff --git a/hub/stack/patterns/1_0.tex b/hub/stack/patterns/1_0.tex new file mode 100644 index 0000000..8a80841 --- /dev/null +++ b/hub/stack/patterns/1_0.tex @@ -0,0 +1,62 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +We let $\oneZeroSP_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] The first stack item is contains a stack item: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} \\ + \stackItemPop{1}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] is empty i.e. $\emptyStackItem{2}_{i}$; + \item[\underline{Stack Item $n^\circ\,3$:}] is empty i.e. $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] is empty i.e. $\emptyStackItem{4}_{i}$; + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - 1$; +\end{description} + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\noindent The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|c|c|c|} + \cline{2-5} + \multicolumn{1}{c}{} & + \multicolumn{1}{|c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c}{} & + \multicolumn{1}{|c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ + \hline + \stackItemHeight{k}_{i} & + \col{h} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \stackItemValHi{k}_{i} / \stackItemValLo{k}_{i} & + \col{arg} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \stackItemPop{k}_{i} & + 1 & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \stackItemStamp{k}_{i} & + \hubTau \cdot \col{st} & \graym{\varnothing} & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \end{array} +\] +\label{fig: create stack pattern} +\caption{% +Graphical representation of +$\oneZeroSP_{i}$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} \ No newline at end of file diff --git a/hub/stack/patterns/1_1.tex b/hub/stack/patterns/1_1.tex new file mode 100644 index 0000000..2961e69 --- /dev/null +++ b/hub/stack/patterns/1_1.tex @@ -0,0 +1,58 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +We let $\oneOneSP_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] --- + % depending on the instruction contains either a \textbf{relative offset}, an \textbf{absolute offset} or a \textbf{storage key}: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight {1} _{i} & \!\!\! = \!\!\! & \stackHeight_{i}, \\ + \stackItemPop {1} _{i} & \!\!\! = \!\!\! & 1, \\ + \stackItemStamp {1} _{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] is empty: $\emptyStackItem{2}_{i}$; + \item[\underline{Stack Item $n^\circ\,3$:}] is empty: $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight {4} _{i} & \!\!\! = \!\!\! & \stackHeight_{i} \\ + \stackItemPop {4} _{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemStamp {4} _{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 1 \\ + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight\new{}_{i} = \stackHeight{}_{i}$; +\end{description} + + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +\noindent The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|c|c|r|} + \cline{2-5} + \multicolumn{1}{c}{} & \multicolumn{1}{|c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c}{} & \multicolumn{1}{|c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} & \graym{\varnothing} & \graym{\varnothing} & \col{h} \\ \hline + \stackItemValHi{k}/\stackItemValLo{k} & \col{arg} & \graym{\varnothing} & \graym{\varnothing} & \col{res} \\ \hline + \stackItemPop{k}_{i} & 1 & \graym{\varnothing} & \graym{\varnothing} & 0 \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} & \graym{\varnothing} & \graym{\varnothing} & \hubTau \cdot \col{st} + 1 \\ \hline + \end{array} +\] +\caption{% +Graphical representation of $\oneOneSP_{i}$. +% On the left hand side is the picture for a $(1,1)$ instruction (i.e. $\decFlag{1}=0$). +% On the right hand side is the picture for a $(2,0)$ instruction (i.e. $\decFlag{1}=1$). +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} diff --git a/hub/stack/patterns/2_0.tex b/hub/stack/patterns/2_0.tex new file mode 100644 index 0000000..a8021ed --- /dev/null +++ b/hub/stack/patterns/2_0.tex @@ -0,0 +1,69 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +We let $\twoZeroSP_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & = & \stackHeight_{i}, \\ + \stackItemPop{1}_{i} & = & 1, \\ + \stackItemStamp{1}_{i} & = & \hubTau \cdot \hubStamp_{i} + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & = & \stackHeight_{i} - 1 \\ + \stackItemPop{2}_{i} & = & 1 \\ + \stackItemStamp{2}_{i} & = & \hubTau \cdot \hubStamp_{i} + 1 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] is empty: $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] is empty: $\emptyStackItem{4}_{i}$; + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - 2$, +\end{description} +% For this set of instructions the interpretation of $\decFlag{1}$ is that it equals $1$ for storing instructions and $0$ for loading instructions. + + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +\noindent The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|r|c|c|} + \cline{2-5} + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ + \hline + \stackItemHeight{k}_{i} & \col{h} & \col{h} - 1 & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \stackItemValHi{k}_{i} / \stackItemValLo{k}_{i} & \col{arg1} & \col{arg2} & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \stackItemPop{k}_{i} & 1 & 1 & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \graym{\varnothing} & \graym{\varnothing} \\ + \hline + \end{array} +\] +\caption{% +Graphical representation of $\twoZeroSP_{i}$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} \ No newline at end of file diff --git a/hub/stack/patterns/2_1.tex b/hub/stack/patterns/2_1.tex new file mode 100644 index 0000000..f667337 --- /dev/null +++ b/hub/stack/patterns/2_1.tex @@ -0,0 +1,78 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +We let $\twoZeroSP_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & = & \stackHeight_{i}, \\ + \stackItemPop{1}_{i} & = & 1, \\ + \stackItemStamp{1}_{i} & = & \hubTau \cdot \hubStamp_{i} + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & = & \stackHeight_{i} - 1 \\ + \stackItemPop{2}_{i} & = & 1 \\ + \stackItemStamp{2}_{i} & = & \hubTau \cdot \hubStamp_{i} + 1 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] is empty: $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i} & = & \stackHeight_{i} - 1 \\ + \stackItemPop{4}_{i} & = & 0 \\ + \stackItemStamp{4}_{i} & = & \hubTau \cdot \hubStamp_{i} + 2 + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - 1$, +\end{description} +% For this set of instructions the interpretation of $\decFlag{1}$ is that it equals $1$ for storing instructions and $0$ for loading instructions. + + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +\noindent The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|r|c|r|} + \cline{2-5} + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ + \hline + \stackItemHeight{k}_{i} & \col{h} & \col{h} - 1 & \graym{\varnothing} & \col{h} - 1 \\ + \hline + \stackItemValHi{k}/\stackItemValLo{k} & \col{arg1} & \col{arg2} & \graym{\varnothing} & \col{res} \\ + \hline + \stackItemPop{k}_{i} & 1 & 1 & \graym{\varnothing} & 0 \\ + \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \graym{\varnothing} & \hubTau \cdot \col{st} + 2 \\ + \hline + \end{array} +\] +\caption{% +Graphical representation of $\twoZeroSP_{i}$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} \ No newline at end of file diff --git a/hub/stack/patterns/3_1.tex b/hub/stack/patterns/3_1.tex new file mode 100644 index 0000000..d327642 --- /dev/null +++ b/hub/stack/patterns/3_1.tex @@ -0,0 +1,81 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +We let $\threeOneSP_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & = & \stackHeight_{i}, \\ + \stackItemPop{1}_{i} & = & 1, \\ + \stackItemStamp{1}_{i} & = & \hubTau \cdot \hubStamp_{i} + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & = & \stackHeight_{i} - 1 \\ + \stackItemPop{2}_{i} & = & 1 \\ + \stackItemStamp{2}_{i} & = & \hubTau \cdot \hubStamp_{i} + 1 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{3}_{i} & = & \stackHeight_{i} - 2 \\ + \stackItemPop{3}_{i} & = & 1 \\ + \stackItemStamp{3}_{i} & = & \hubTau \cdot \hubStamp_{i} + 2 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,4$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i} & = & \stackHeight_{i} - 2 \\ + \stackItemPop{4}_{i} & = & 0 \\ + \stackItemStamp{4}_{i} & = & \hubTau \cdot \hubStamp_{i} + 3 + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - 2$, +\end{description} + + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +\noindent The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|r|c|r|} + \cline{2-5} + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} & \col{h} - 1 & \col{h} - 2 & \col{h} - 2 \\ \hline + \stackItemValHi{k}_{i} / \stackItemValLo{k}_{i} & \col{arg1} & \col{arg2} & \col{arg3} & \col{res} \\ \hline + \stackItemPop{k}_{i} & 1 & 1 & 1 & 0 \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \hubTau \cdot \col{st} + 2 & \hubTau \cdot \col{st} + 3 \\ \hline + \end{array} +\] +\caption{% +Graphical representation of $\threeOneSP_{i}$. +We write $\col{h} := \stackHeight_{i}$ and $\hubStamp_{i} = \col{st}$.} +\end{figure} \ No newline at end of file diff --git a/hub/stack/patterns/_inputs.tex b/hub/stack/patterns/_inputs.tex new file mode 100644 index 0000000..c453304 --- /dev/null +++ b/hub/stack/patterns/_inputs.tex @@ -0,0 +1,17 @@ +\subsubsection{\stackItemPop{k} binary conditions \lispDone{}} \label{hub: stack patterns: pop is binary} \input{stack/patterns/pop_flag} +\subsubsection{\emptyStackItem{k} \lispDone{}} \label{hub: stack patterns: empty item} \input{stack/patterns/empty_item} +\subsubsection{\emptySP \lispDone{}} \label{hub: stack patterns: empty} \input{stack/patterns/empty} +\subsubsection{\zeroZeroSP{} \lispDone{}} \label{hub: stack patterns: 0_0} \input{stack/patterns/0_0} +\subsubsection{\oneZeroSP{} \lispDone{}} \label{hub: stack patterns: 1_0} \input{stack/patterns/1_0} +\subsubsection{\twoZeroSP{} \lispDone{}} \label{hub: stack patterns: 2_0} \input{stack/patterns/2_0} +\subsubsection{\zeroOneSP{} \lispDone{}} \label{hub: stack patterns: 0_1} \input{stack/patterns/0_1} +\subsubsection{\oneOneSP{} \lispDone{}} \label{hub: stack patterns: 1_1} \input{stack/patterns/1_1} +\subsubsection{\twoOneSP{} \lispDone{}} \label{hub: stack patterns: 2_1} \input{stack/patterns/2_1} +\subsubsection{\threeOneSP{} \lispDone{}} \label{hub: stack patterns: 3_1} \input{stack/patterns/3_1} +\subsubsection{$\loadStoreSP\big[\col{b}\big]$ \lispDone{}} \label{hub: stack patterns: load store} \input{stack/patterns/load_store} +\subsubsection{$\dupSP\big[\col{param}\big]$ \lispDone{}} \label{hub: stack patterns: dup} \input{stack/patterns/dup} +\subsubsection{$\swapSP\big[\col{param}\big]$ \lispDone{}} \label{hub: stack patterns: swap} \input{stack/patterns/swap} +\subsubsection{$\logSP\big[\col{param}; \col{b}_{1}, \col{b}_{2}, \col{b}_{3}, \col{b}_{4} \big]$ \lispDone{}} \label{hub: stack patterns: log} \input{stack/patterns/log} +\subsubsection{$\copySP\big[\col{b}\big]$ \lispDone{}} \label{hub: stack patterns: copy} \input{stack/patterns/copy} +\subsubsection{$\callSP\big[\col{b}\big]$ \lispDone{}} \label{hub: stack patterns: call} \input{stack/patterns/call} +\subsubsection{$\createSP\big[\col{b}\big]$ \lispDone{}} \label{hub: stack patterns: create} \input{stack/patterns/create} diff --git a/hub/stack/patterns/call.tex b/hub/stack/patterns/call.tex new file mode 100644 index 0000000..83845a3 --- /dev/null +++ b/hub/stack/patterns/call.tex @@ -0,0 +1,220 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +Suppose we are given a bit $\col{b} \in \{ 0, 1\}$. +We let $\callSP\big[\col{b}\big]_{i}$ stand for the following collection of constraints on rows $i$ and $i+1$. +The first lot of constraints pertains to the first row (i.e. $\ct_{i} = 0$): +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] the first stack item contains what will become the call data offset: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - 2 - \col{b} \\ + \stackItemPop{1}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 3 \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] the second stack item contains what will become the call data size: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - 3 - \col{b} \\ + \stackItemPop{2}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{2}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 4 \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] the third stack item contais what will become the offset at which return data may be written into RAM: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{3}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - 4 - \col{b} \\ + \stackItemPop{3}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{3}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 5 \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,4$:}] the fourth stack item contains what will become the size in bytes allocated by the call for writing return data directly into RAM: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - 5 - \col{b} \\ + \stackItemPop{4}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{4}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 6 \\ + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - 5 - \col{b}$; +\end{description} +The second lot of constraints pertains to the second row (i.e. $\ct_{i + 1} = 1$). +\begin{description} + \item[\underline{Stack Item ``$n^\circ\,5$'':}] contains the gas argument of the \inst{CALL}-type instruction: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i + 1} & \!\!\! = \!\!\! & \stackHeight_{i + 1} \\ + \stackItemPop{1}_{i + 1} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i + 1} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i + 1} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item ``$n^\circ\,6$'':}] contains the address argument of the \inst{CALL}-type instruction: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i + 1} & \!\!\! = \!\!\! & \stackHeight_{i + 1} - 1 \\ + \stackItemPop{2}_{i + 1} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{2}_{i + 1} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i + 1} + 1 \\ + \end{array} + \right. + \] + \item[\underline{Stack Item ``$n^\circ\,7$'':}] \emph{may} contain a value argument (used for both \inst{CALL} and \inst{CALLCODE}) + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{3}_{i + 1} & \!\!\! = \!\!\! & (\stackHeight_{i + 1} - 2) \cdot \col{b} \\ + \stackItemPop{3}_{i + 1} & \!\!\! = \!\!\! & \col{b} \\ + \stackItemStamp{3}_{i + 1} & \!\!\! = \!\!\! & (\hubTau \cdot \hubStamp_{i + 1} + 2)\cdot \col{b} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item ``$n^\circ\,8$'':}] the fourth stack item contains the success bit + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i + 1} & \!\!\! = \!\!\! & \stackHeight_{i + 1} - 5 - \col{b} \\ + \stackItemPop{4}_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \stackItemStamp{4}_{i + 1} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i + 1} + 7 \\ + \stackItemValHi{4}_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \multicolumn{3}{l}{\stackItemValLo{4}_{i + 1} \in \{ 0, 1 \} } \\ + \end{array} + \right. + \] + \saNote{} The last constraints impose a ``bithood'' constraint on the stack item meant to hold the success bit. +\end{description} +Recall that \inst{CALL}-type instructions require either $\bm{6}$ or $\bm{7}$ stack arguments (and always produce a success bit as output.) +Whether a \inst{CALL}-type instructions requires 6 or 7 arguments can be read off of $\decFlag{1}$, see section~\ref{hub: instruction handling: Call} +In applications $\col{b}$ will be replaced with $\decFlag{1}_{i}$. + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +We represent the stack pattern when $\decFlag{1}=0$ is in figure~\ref{fig: call stack pattern flag1 = 0} and similarly for $\decFlag{1}=1$ see figure~\ref{fig: call stack pattern flag1 = 1}. +\begin{figure}[h!] +\[ + \tag{$\col{b} = 0$} + \begin{array}{r} + \begin{array}{|l|r|r|r|r|} + \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i} = 0)} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ + \hline + \stackItemHeight{k}_{i} & + \col{h} - 2 & \col{h} - 3 & \col{h} - 4 & \col{h} - 5 \\ + \hline + \stackItemValHi{k}_{i}/\stackItemValLo{k}_{i} & \cdo{} & \cds & \retAtOff & \retAtCap{} \\ + \hline + \stackItemPop{k}_{i} & 1 & 1 & 1 & 1 \\ + \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} + 3 & \hubTau \cdot \col{st} + 4 & \hubTau \cdot \col{st} + 5 & \hubTau \cdot \col{st} + 6 \\ + \hline + \end{array} \vspace{3mm} \\ + \begin{array}{|l|r|r|c|r|} + \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i + 1} = 1)} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ + \hline + \stackItemHeight{k}_{i + 1} & \col{h} & \col{h} - 1 & \graym{\varnothing} & \col{h} - 5 \\ + \hline + \stackItemValHi{k}_{i + 1}/\stackItemValLo{k}_{i + 1} & \col{gas} & \col{address} & \graym{\varnothing} & \col{success} \\ + \hline + \stackItemPop{k}_{i + 1} & 1 & 1 & \graym{\varnothing} & 0 \\ + \hline + \stackItemStamp{k}_{i + 1} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \graym{\varnothing} & \hubTau \cdot \col{st} + 7 \\ + \hline + \end{array} + \end{array} +\] +\label{fig: call stack pattern flag1 = 0} +\caption{% +Graphical representation of $\callSP\big[\col{b}\big]_{i}$ for $\col{b} = 0$. +In applications $\col{b} = \decFlag{1}_{i}$ so that the above applies to \inst{DELEGATECALL} and \inst{STATICCALL} instructions. +Recall that \cdo{}, \retAtOff{}, \cds{}, \retAtCap{} are short hand for \CDO{}, \RETATOFF{}, \CDS{}, \RETATCAP{} respectively. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} + +\begin{figure}[h!] +\[ + \tag{$\col{b} = 1$} + \begin{array}{r} + \begin{array}{|l|r|r|r|r|} + \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i} = 0)} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} - 3 & \col{h} - 4 & \col{h} - 5 & \col{h} - 6 \\ + \hline + \stackItemValHi{k}_{i}/\stackItemValLo{k}_{i} & \cdo{} & \cds & \retAtOff & \retAtCap{} \\ + \hline + \stackItemPop{k}_{i} & 1 & 1 & 1 & 1 \\ + \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} + 3 & \hubTau \cdot \col{st} + 4 & \hubTau \cdot \col{st} + 5 & \hubTau \cdot \col{st} + 6 \\ + \hline + \end{array} \vspace{3mm} \\ + \begin{array}{|l|r|r|r|r|} + \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i + 1} = 1)} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i + 1} & \col{h} & \col{h} - 1 & \col{h} - 2 & \col{h} - 6 \\ + \hline + \stackItemValHi{k}_{i + 1}/\stackItemValLo{k}_{i + 1} & \col{gas} & \col{address} & \col{value} & \col{success} \\ + \hline + \stackItemPop{k}_{i + 1} & 1 & 1 & 1 & 0 \\ + \hline + \stackItemStamp{k}_{i + 1} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \hubTau \cdot \col{st} + 2 & \hubTau \cdot \col{st} + 7 \\ + \hline + \end{array} + \end{array} +\] +\label{fig: call stack pattern flag1 = 1} +\caption{% +Graphical representation of $\callSP\big[\col{b}\big]_{i}$ for $\col{b} = 1$. +In applications $\col{b} = \decFlag{1}_{i}$ so that the above will apply to \inst{CALL} and \inst{CALLCODE} instructions. +Recall that \cdo{}, \retAtOff{}, \cds{}, \retAtCap{} are short hand for \CDO{}, \RETATOFF{}, \CDS{}, \RETATCAP{} respectively. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} diff --git a/hub/stack/patterns/copy.tex b/hub/stack/patterns/copy.tex new file mode 100644 index 0000000..6b388d7 --- /dev/null +++ b/hub/stack/patterns/copy.tex @@ -0,0 +1,80 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +Suppose we are given a bit $\col{b} \in \{ 0, 1\}$. We let $\copySP\big[\col{b}\big]_{i}$ stand for the following collection of constraints. +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] the first stack item will contain a source offset: + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight{1}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - (0 + \col{b}) \\ + \stackItemPop{1}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 1 \\ + \end{array} \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] the second stack item will contain a size: + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight{2}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - (2 + \col{b}) \\ + \stackItemPop{2}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{2}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 2 \\ + \end{array} \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] the third stack item will contain a target offset: + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight{3}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - (1 + \col{b}) \\ + \stackItemPop{3}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{3}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 3 \\ + \end{array} \right. + \] + \item[\underline{Stack Item $n^\circ\,4$:}] the fourth stack item \emph{may contain} an address + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight{4}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} \cdot \col{b} \\ + \stackItemPop{4}_{i} & \!\!\! = \!\!\! & \col{b} \\ + \stackItemStamp{4}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} \cdot \col{b} \\ + \end{array} \right. + \] + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - (3 + \col{b})$; +\end{description} +In applications $\col{b}$ will $=1$ for \inst{EXTCODECOPY} only among all instructions in the \inst{COPY}-instruction family. +This bit dictates whether or not the copy instruction requires an address argument or not. + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +For this set of instructions the interpretation of $\decFlag{4}$ is that it equals $1$ for \inst{EXTCODECOPY} only. The picture is the following: +\begin{figure}[h!] + \[ + \tag{$\col{b} = 0$} + \begin{array}{|l|r|r|r|c|} \cline{2-5} + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} & \col{h} - 2 & \col{h} - 1 & \nothing \\ \hline + \stackItemValHi{k}_{i}/\stackItemValLo{k}_{i} & \col{destOffset} & \col{size} & \col{(rel)offset} & \nothing \\ \hline + \stackItemPop{k}_{i} & 1 & 1 & 1 & \nothing \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} + 1 & \hubTau \cdot \col{st} + 3 & \hubTau \cdot \col{st} + 2 & \nothing \\ \hline + \end{array} + \] + \[ + \tag{$\col{b} = 1$} %\inst{EXTCODECOPY}} + \begin{array}{|l|r|r|r|r|} \cline{2-5} + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} - 1 & \col{h} - 3 & \col{h} - 2 & \col{h} \\ \hline + \stackItemValHi{k}_{i}/\stackItemValLo{k}_{i} & \col{destOffset} & \col{size} & \col{(rel)offset} & \col{addr} \\ \hline + \stackItemPop{k}_{i} & 1 & 1 & 1 & 1 \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} + 1 & \hubTau \cdot \col{st} + 3 & \hubTau \cdot \col{st} + 2 & \hubTau \cdot \col{st} \\ \hline + \end{array} + \] + \caption{% + The first three items one pops from stack represent the offset where to start writing, the (relative) offset of where to start reading and the size (i.e. number of bytes to read.) This is all there is when $\decFlag{1}=0$. + But for \inst{EXTCODECOPY} (i.e. $\decFlag{1} = \decFlag{2} = 1$) there is an extra stack argument to pop: the address. + For \inst{CODECOPY} (i.e. $\decFlag{1} = 1$ and $\decFlag{2} = 0$) the fourth stack item is \emph{technically} empty but we make it contain the current bytecode address. + This will not perturb consistency constraints as $\stackHeight = 0$. + We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$. + \ob{TODO: do we still need this }$\yellowm{\codeAddress{}}$ ? + \ob{TODO: rewrite this whole paragraph.}} +\end{figure} diff --git a/hub/stack/patterns/create.tex b/hub/stack/patterns/create.tex new file mode 100644 index 0000000..ccf33ac --- /dev/null +++ b/hub/stack/patterns/create.tex @@ -0,0 +1,128 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +Suppose we are given a bit $\col{b} \in \{ 0, 1\}$. We let $\createSP\big[\col{b}\big]_{i}$ stand for the following collection of constraints spanning rows $i$ and $i+1$. +The first lot of constraints pertains to the first row (i.e. $\ct_{i} = 0$): +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & = & \stackHeight_{i} - 1 \\ + \stackItemPop{1}_{i} & = & 1 \\ + \stackItemStamp{1}_{i} & = & \hubTau \cdot \hubStamp_{i} + 1 \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & = & \stackHeight_{i} - 2 \\ + \stackItemPop{2}_{i} & = & 1 \\ + \stackItemStamp{2}_{i} & = & \hubTau \cdot \hubStamp_{i} + 2 \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] is empty i.e. $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] is empty i.e. $\emptyStackItem{4}_{i}$; + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - 2 - \col{b}$; +\end{description} +The second lot of constraints pertains to the second row (i.e. $\ct_{i + 1} = 1$): +\begin{description} + \item[\underline{Stack Item ``$n^\circ\,5$'':}] is empty i.e. $\emptyStackItem{1}_{i + 1}$; + \item[\underline{Stack Item ``$n^\circ\,6$'':}] contains the \emph{salt} in case of a \inst{CREATE2}, empty otherwise: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & = & (\stackHeight_{i} - 3) \cdot \col{b} \\ + \stackItemPop{2}_{i} & = & \col{b} \\ + \stackItemStamp{2}_{i} & = & (\hubTau \cdot \hubStamp_{i} + 3) \cdot \col{b} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item ``$n^\circ\,7$'':}] contains the value: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{3}_{i + 1} & = & \stackHeight_{i} \\ + \stackItemPop{3}_{i + 1} & = & 1 \\ + \stackItemStamp{3}_{i + 1} & = & \hubTau \cdot \hubStamp_{i} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item ``$n^\circ\,8$'':}] contains either $0$ (unsuccessful deployment) or the deployment address: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i + 1} & = & \stackHeight_{i + 1} - 2 - \col{b} \\ + \stackItemPop{4}_{i + 1} & = & 0 \\ + \stackItemStamp{4}_{i + 1} & = & \hubTau \cdot \hubStamp_{i} + 4 \\ + \end{array} + \right. + \] +\end{description} +Recall that for instructions which raise the $\createFlag$ (i.e. \inst{CREATE} and \inst{CREATE2}) $\decFlag{1}$ lights up for \inst{CREATE2}, see section~\ref{hub: instruction handling: Create}. +As such in application $\col{b}$ will be replaced with $\decFlag{1}_{i}$. +\saNote{} Although the \inst{CREATE} instruction has $(\delta_{w}^\zkevm, \alpha_{w}^\zkevm) = (\delta_{w}, \alpha_{w}) = (3,1)$ and would thus fit into a single row of the execution trace ($\delta_{w}^\zkevm + \alpha_{w}^\zkevm = 4$) we have chosen a unified approach to both create instructions. + + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +We represent $\createSP\big[\col{b}\big]_{i}$ for both $\col{b} = 0$ and $\col{b} = 1$. In applications +the ``($\col{b} = 0$)-variant'' (figure~\ref{fig: create stack pattern}) is the stack pattern of \inst{CREATE} instructions and +the ``($\col{b} = 1$)-variant'' (figure~\ref{fig: create2 stack pattern}) is the stack pattern of \inst{CREATE2} instructions. +\begin{figure}[h!] +\[ + \begin{array}{|l|r|r|c|c|} + \cline{2-5} + \multicolumn{1}{c|}{\ct_{i} = 0} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} - 1 & \col{h} - 2 & \nothing & \nothing \\ \hline + \stackItemValHi{k}/\stackItemValLo{k} & \col{offset} & \col{init\_code\_size} & \nothing & \nothing \\ \hline + \stackItemPop{k}_{i} & 1 & 1 & \nothing & \nothing \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} + 1 & \hubTau \cdot \col{st} + 2 & \nothing & \nothing \\ \hline + \end{array} +\] +\caption{% +Representation of the first row of $\createSP\big[\col{b}\big]_{i}$ (valid for both $\col{b} = 0$ and $\col{b} = 1$.) +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\[ + \tag{$\col{b} = 0$} + \begin{array}{|l|c|c|r|r|} + \cline{2-5} + \multicolumn{1}{c|}{\ct_{i + 1} = 1} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i + 1} & \nothing & \nothing & \col{h} & \col{h} - 2 \\ \hline + \stackItemValHi{k}_{i + 1} / \stackItemValLo{k}_{i + 1} & \nothing & \nothing & \col{value} & \col{address (or 0)} \\ \hline + \stackItemPop{k}_{i + 1} & \nothing & \nothing & 1 & 0 \\ \hline + \stackItemStamp{k}_{i + 1} & \nothing & \nothing & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 4 \\ \hline + \end{array} +\] +\label{fig: create stack pattern} +\caption{% +Representation of the second row of $\createSP\big[\col{b}\big]_{i}$ for $\col{b} = 0$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\[ + \tag{$\col{b} = 1$} + \begin{array}{|l|c|r|r|r|} + \cline{2-5} + \multicolumn{1}{c|}{\ct_{i + 1} = 1} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i + 1} & \nothing & \col{h} - 3 & \col{h} & \col{h} - 3 \\ \hline + \stackItemValHi{k}_{i + 1} / \stackItemValLo{k}_{i + 1} & \nothing & \col{salt} & \col{value} & \col{address (or 0)} \\ \hline + \stackItemPop{k}_{i + 1} & \nothing & 1 & 1 & 0 \\ \hline + \stackItemStamp{k}_{i + 1} & \nothing & \hubTau \cdot \col{st} + 3 & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 4 \\ \hline + \end{array} +\] +\label{fig: create2 stack pattern} +\caption{% +Representation of the second row of $\createSP\big[\col{b}\big]_{i}$ for $\col{b} = 1$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} diff --git a/hub/stack/patterns/dup.tex b/hub/stack/patterns/dup.tex new file mode 100644 index 0000000..499297c --- /dev/null +++ b/hub/stack/patterns/dup.tex @@ -0,0 +1,78 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +Let $\col{param} \in \{ 0, 1, \dots, 15 \}$ be given. +We let $\dupSP\big[\col{param}\big]_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] this excavates the value to duplicate (``$v_\text{deep}$''): + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - \col{param} \\ + \stackItemPop{1}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] this re-inserts said value from whence it was taken: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - \col{param} \\ + \stackItemPop{2}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValHi{2}_{i} & \!\!\! = \!\!\! & \stackItemValHi{1}_{i} \\ + \stackItemValLo{2}_{i} & \!\!\! = \!\!\! & \stackItemValLo{1}_{i} \\ + \stackItemStamp{2}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 1 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] is empty: $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] this inserts said value onto the stack: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} + 1 \\ + \stackItemPop{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & \stackItemValHi{1}_{i} \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \stackItemValLo{1}_{i} \\ + \stackItemStamp{4}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 2 + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} + 1$; +\end{description} + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +The figure below represents the $\dupSP\big[\col{param}\big]_{i}$ stack pattern: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|c|r|r|} + \cline{2-5} + \multicolumn{1}{c}{} & + \multicolumn{1}{|c|}{\text{Stack}} & + \multicolumn{1}{c|} {\text{Stack}} & + \multicolumn{1}{c|} {\text{Stack}} & + \multicolumn{1}{c|} {\text{Stack}} \\ + \multicolumn{1}{c}{} & + \multicolumn{1}{|c|}{\text{Item 1}} & + \multicolumn{1}{c|} {\text{Item 2}} & + \multicolumn{1}{c|} {\text{Item 3}} & + \multicolumn{1}{c|} {\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} - \col{param} & \col{h} - \col{param} & \graym{\varnothing} & \col{h} + 1 \\ \hline + \stackItemValHi{k}/\stackItemValLo{k} & v_\text{deep} & v_\text{deep} & \graym{\varnothing} & v_\text{deep} \\ \hline + \stackItemPop{k}_{i} & 1 & 0 & \graym{\varnothing} & 0 \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st}& \hubTau \cdot \col{st} + 1 & \graym{\varnothing} & \hubTau \cdot \col{st} + 2 \\ \hline + \end{array} +\] +\label{fig: dup stack pattern} +\caption{% +Graphical representation of $\dupSP\big[\col{param}\big]_{i}$. +In applications this stack pattern applies to \inst{DUPX} instructions having set $\col{param} := \INST_{i} - \inst{DUP1}$. +Thus for \inst{DUPX} instructions $\col{param} = \inst{X} - 1$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} \ No newline at end of file diff --git a/hub/stack/patterns/empty.tex b/hub/stack/patterns/empty.tex new file mode 100644 index 0000000..2ee7680 --- /dev/null +++ b/hub/stack/patterns/empty.tex @@ -0,0 +1,20 @@ +We let $\emptySP_{i}$ stand for the following collection of constraints whereby all four stack items are empty: +% \begin{description} +% \item[\underline{Stack Item $n^\circ\,1$:}] is empty i.e. $\emptyStackItem{1}_{i}$; +% \item[\underline{Stack Item $n^\circ\,2$:}] is empty i.e. $\emptyStackItem{2}_{i}$; +% \item[\underline{Stack Item $n^\circ\,3$:}] is empty i.e. $\emptyStackItem{3}_{i}$; +% \item[\underline{Stack Item $n^\circ\,4$:}] is empty i.e. $\emptyStackItem{4}_{i}$; +% \end{description} +\[ + \emptySP_{i} + \iff + \left\{ + \begin{array}{lr} + \emptyStackItem{1}_{i} \\ + \emptyStackItem{2}_{i} \\ + \emptyStackItem{3}_{i} \\ + \emptyStackItem{4}_{i} \\ + \end{array} + \right. +\] +The $\emptySP$ is used when there is a \suxSH{} or a \soxSH{}; in such cases no items need to be excavated or pushed onto the stack. \ No newline at end of file diff --git a/hub/stack/patterns/empty_item.tex b/hub/stack/patterns/empty_item.tex new file mode 100644 index 0000000..4edea24 --- /dev/null +++ b/hub/stack/patterns/empty_item.tex @@ -0,0 +1,14 @@ +We define, for any $k\in\{1,2,3,4\}$, the following "empty $k$-th stack item" constraint system: +\[ + \emptyStackItem{k}_{i} + \iff + \left\{ + \begin{array}{lclr} + \stackItemHeight{k}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemPop{k}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValHi{k}_{i} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \stackItemValLo{k}_{i} & \!\!\! = \!\!\! & 0 & (\trash) \\ + \stackItemStamp{k}_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right. +\] diff --git a/hub/stack/patterns/load_store.tex b/hub/stack/patterns/load_store.tex new file mode 100644 index 0000000..3465295 --- /dev/null +++ b/hub/stack/patterns/load_store.tex @@ -0,0 +1,143 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +Suppose we are given a bit $\col{b} \in \{ 0, 1\}$. We let $\loadStoreSP\big[\col{b}\big]_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight {1} _{i} & \!\!\! = \!\!\! & \stackHeight_{i} \\ + \stackItemPop {1} _{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp {1} _{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} \\ + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] is empty: $\emptyStackItem{2}_{i}$; + \item[\underline{Stack Item $n^\circ\,3$:}] is empty: $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] --- + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight {4} _{i} & \!\!\! = \!\!\! & \stackHeight_{i} - \col{b} \\ + \stackItemPop {4} _{i} & \!\!\! = \!\!\! & \col{b} \\ + \stackItemStamp {4} _{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 1 \\ + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight\new{}_{i} = \stackHeight{}_{i} - 2 \cdot \col{b}$; +\end{description} +For $\col{b} = 0$ the above provides the stack pattern for \inst{LOAD}-type instructions (i.e. \inst{MLOAD}, \inst{SLOAD} and \inst{CALLDATALOAD}.) +For $\col{b} = 1$ the above provides the stack pattern for \inst{STORE}-type instructions (i.e. \inst{MSTORE}, \inst{MSTORE8} and \inst{SSTORE}.) + + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +\noindent The following is the associated graphical representation: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|c|c|r|} + \cline{2-5} + \multicolumn{1}{c}{} & + \multicolumn{1}{|c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c}{} & + \multicolumn{1}{|c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_i & \col{h} & \graym{\varnothing} & \graym{\varnothing} & \col{h} \\ \hline + \stackItemValHi{k}_{i} / \stackItemValLo{k}_{i} & \col{src} & \graym{\varnothing} & \graym{\varnothing} & \col{value} \\ \hline + \stackItemPop{k}_i & 1 & \graym{\varnothing} & \graym{\varnothing} & 0 \\ \hline + \stackItemStamp{k}_i & \hubTau \cdot \col{st} & \graym{\varnothing} & \graym{\varnothing} & \hubTau \cdot \col{st} + 1 \\ \hline + \end{array} + % % + % % + % \qquad + % % + % % + % \begin{array}{|l|r|c|c|r|} + % \cline{2-5} + % \multicolumn{1}{c|}{} & + % \multicolumn{1}{c|}{\text{Stack}} & + % \multicolumn{1}{c|}{\text{Stack}} & + % \multicolumn{1}{c|}{\text{Stack}} & + % \multicolumn{1}{c|}{\text{Stack}} \\ + % \multicolumn{1}{c|}{} & + % \multicolumn{1}{c|}{\text{Item 1}} & + % \multicolumn{1}{c|}{\text{Item 2}} & + % \multicolumn{1}{c|}{\text{Item 3}} & + % \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + % \sHeight{k}_i & \col{h} & \graym{\varnothing} & \graym{\varnothing} & \col{h} - 1 \\ \hline + % \sValHi{k}/\sValLo{k} & \col{ARG1} & \graym{\varnothing} & \graym{\varnothing} & \col{ARG2} \\ \hline + % \sPop{k}_i & 1 & \graym{\varnothing} & \graym{\varnothing} & 1 \\ \hline + % \sStamp{k}_i & \col{st} + 1 & \graym{\varnothing} & \graym{\varnothing} & \col{st} + 2 \\ \hline + % \end{array} +\] +\caption{% +$\loadStoreSP\big[\col{b}\big]_{i}$ with $\col{b} = 0$, i.e. the ``\texttt{load}-variant.'' +We write \col{src} to mean a source location. +In applications this will either be +(\emph{a}) an \col{offset} in memory +(\emph{b}) a (relative) \col{offset} in call data +(\emph{c}) a (storage) \col{key}. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} + +\begin{figure}[h!] +\[ + \begin{array}{|l|r|c|c|r|} + \cline{2-5} + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_i & \col{h} & \graym{\varnothing} & \graym{\varnothing} & \col{h} - 1 \\ \hline + \stackItemValHi{k}_{i} / \stackItemValLo{k}_{i} & \col{tgt} & \graym{\varnothing} & \graym{\varnothing} & \col{value} \\ \hline + \stackItemPop{k}_i & 1 & \graym{\varnothing} & \graym{\varnothing} & 1 \\ \hline + \stackItemStamp{k}_i & \hubTau \cdot \col{st} & \graym{\varnothing} & \graym{\varnothing} & \hubTau \cdot \col{st} + 1 \\ \hline + \end{array} + % % + % % + % \qquad + % % + % % + % \begin{array}{|l|r|c|c|r|} + % \cline{2-5} + % \multicolumn{1}{c|}{} & + % \multicolumn{1}{c|}{\text{Stack}} & + % \multicolumn{1}{c|}{\text{Stack}} & + % \multicolumn{1}{c|}{\text{Stack}} & + % \multicolumn{1}{c|}{\text{Stack}} \\ + % \multicolumn{1}{c|}{} & + % \multicolumn{1}{c|}{\text{Item 1}} & + % \multicolumn{1}{c|}{\text{Item 2}} & + % \multicolumn{1}{c|}{\text{Item 3}} & + % \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + % \sHeight{k}_i & \col{h} & \graym{\varnothing} & \graym{\varnothing} & \col{h} - 1 \\ \hline + % \sValHi{k}/\sValLo{k} & \col{ARG1} & \graym{\varnothing} & \graym{\varnothing} & \col{ARG2} \\ \hline + % \sPop{k}_i & 1 & \graym{\varnothing} & \graym{\varnothing} & 1 \\ \hline + % \sStamp{k}_i & \col{st} + 1 & \graym{\varnothing} & \graym{\varnothing} & \col{st} + 2 \\ \hline + % \end{array} +\] +\caption{% +$\loadStoreSP\big[\col{b}\big]_{i}$ with $\col{b} = 1$, i.e. the ``\texttt{store}-variant.'' +We write \col{tgt} to mean a target location. +In applications this will either be +(\emph{a}) an \col{offset} in memory +(\emph{b}) a (storage) \col{key}. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} diff --git a/hub/stack/patterns/log.tex b/hub/stack/patterns/log.tex new file mode 100644 index 0000000..7d1c121 --- /dev/null +++ b/hub/stack/patterns/log.tex @@ -0,0 +1,138 @@ +\def\bSum {\textsf{bSum}} +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +Suppose we are given a parameter $\col{param} \in \{ 0, 1, 2, 3, 4 \}$ and \textbf{exclusive} bits $\col{b}_{1}, \col{b}_{2}, \col{b}_{3}, \col{b}_{4} \in \{ 0, 1 \}$. +We collect under the moniker +\[ + \logSP_{i} + \big[ \col{param}; \col{b}_{1}, \col{b}_{2}, \col{b}_{3}, \col{b}_{4} \big] +\] +the following collection of constraints (which spans two rows.) The first lot of constraints pertains to the first row (i.e. $\ct_{i} = 0$). This row contains offset and size parameters. +\begin{description} + \item[\underline{Bit exclusivity:}] + we expect all $\col{b}_\ell$ to be bits and for their sum $\sum_{\ell = 1}^4\col{b}_{\ell}$ to be binary, too; + these constraints will always hold since the bits this constraint system will be fed are instruction decoded and thus exclusive bits by definition; + \item[\underline{Stack Item $n^\circ\,1$:}] the first stack item of the first row contains the offset: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} \\ + \stackItemPop{1}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] the second stack item of the first row contains the size: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - 1 \\ + \stackItemPop{2}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{2}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 1 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,3$:}] the third stack item of the first row is empty: $\emptyStackItem{3}_{i}$; + \item[\underline{Stack Item $n^\circ\,4$:}] the fourth stack item of the first row is empty: $\emptyStackItem{4}_{i}$; + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i} - (\col{param} + 2)$; \ob{TODO: check validity}; +\end{description} + +The second lot of constraints pertains to the second row (i.e. $\ct_{i + 1} = 1$). This row contains topics. To simplify notations we will use the following shorthands: +\[ + \bSum_{k} := \sum_{\ell = k}^{4} \col{b}_{\ell} +\] +\begin{description} + \item[\underline{Stack Item $n^\circ\,5$:}] the first stack item of the second row \emph{may} contain a first topic: + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight {1} _{i + 1} & \!\!\! = \!\!\! & \bSum_{1} \cdot (\stackHeight_{i + 1} - 2) \\ + \stackItemPop {1} _{i + 1} & \!\!\! = \!\!\! & \bSum_{1} \\ + \stackItemStamp {1} _{i + 1} & \!\!\! = \!\!\! & \bSum_{1} \cdot (\hubTau \cdot \hubStamp_{i + 1} + 2) \\ + \end{array} \right. + \] + \item[\underline{Stack Item $n^\circ\,6$:}] the second stack item of the second row \emph{may} contain a second topic; % let us write $\col{or} := \col{b'} + \col{b''} - \col{b'} \cdot \col{b''} = \col{b'} \vee \col{b''}$ + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight {2} _{i + 1} & \!\!\! = \!\!\! & \bSum_{2} \cdot (\stackHeight_{i + 1} - 3) \\ + \stackItemPop {2} _{i + 1} & \!\!\! = \!\!\! & \bSum_{2} \\ + \stackItemStamp {2} _{i + 1} & \!\!\! = \!\!\! & \bSum_{2} \cdot (\hubTau \cdot \hubStamp_{i + 1} + 3) \\ + \end{array} \right. + \] + \item[\underline{Stack Item $n^\circ\,7$:}] the third stack item of the second row \emph{may} contain a third topic: + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight {3} _{i + 1} & \!\!\! = \!\!\! & \bSum_{3} \cdot (\stackHeight_{i + 1} - 4) \\ + \stackItemPop {3} _{i + 1} & \!\!\! = \!\!\! & \bSum_{3} \\ + \stackItemStamp {3} _{i + 1} & \!\!\! = \!\!\! & \bSum_{3} \cdot (\hubTau \cdot \hubStamp_{i + 1} + 4) \\ + \end{array} \right. + \] + \item[\underline{Stack Item $n^\circ\,8$:}] the fourth stack item of the second row \emph{may} contain a fourth topic; % let us write $\col{and} := \col{b'} \cdot \col{b''} = \col{b'} \wedge \col{b''}$ + \[ + \left\{ \begin{array}{lcl} + \stackItemHeight {4} _{i + 1} & \!\!\! = \!\!\! & \bSum_{4} \cdot (\stackHeight_{i + 1} - 5) \\ + \stackItemPop {4} _{i + 1} & \!\!\! = \!\!\! & \bSum_{4} \\ + \stackItemStamp {4} _{i + 1} & \!\!\! = \!\!\! & \bSum_{4} \cdot (\hubTau \cdot \hubStamp_{i + 1} + 5) \\ + \end{array} \right. + \] +\end{description} +Recall that the \inst{LOG0}-\inst{LOG4} instructions are characterized by the fact that they raise the $\stackDecLogFlag$ and are distinguished from one another by their +$\decFlag{1}$, $\decFlag{2}$, $\decFlag{3}$ and $\decFlag{4}$, see section~\ref{hub: instruction handling: Log}. +In applications we will use $\col{param} = \INST_{i} - \inst{LOG0} \in \{ 0, 1, 2, 3, 4 \}$ and +$\col{b}_{1}$, $\col{b}_{1}$, $\col{b}_{3}$, and $\col{b}_{4}$ will be replaced with +$\decFlag{1}_{i}$, $\decFlag{2}_{i}$, $\decFlag{3}_{i}$ and $\decFlag{4}_{i}$ respectively. + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\begin{figure}[h!] +\[ + \begin{array}{|l|r|r|c|c|} + \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i} = 0)} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} & \col{h} - 1 & \nothing & \nothing \\ \hline + \stackItemValHi{k}_{i} / \stackItemValLo{k}_{i} & \col{offset} & \col{size} & \nothing & \nothing \\ \hline + \stackItemPop{k}_{i} & 1 & 1 & \nothing & \nothing \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \nothing & \nothing \\ \hline + \end{array} +\] +\caption{% +Representation of the first row ($\ct_{i} = 0$) of $\logSP\big[\col{param}; \col{b}, \col{b'}, \col{b''}\big]_{i}$. +The first row is independent of $\col{param}$, $\col{b}$, $\col{b'}$ and $\col{b''}$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} +\begin{figure}[h!] +\[ + \begin{array}{|l|c|c|c|c|} \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i + 1} = 1)} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i + 1} & \nothing & \nothing & \nothing & \nothing \\ \hline + \stackItemValHi{k}_{i + 1} / \stackItemValLo{k}_{i + 1} & \nothing & \nothing & \nothing & \nothing \\ \hline + \stackItemPop{k}_{i + 1} & \nothing & \nothing & \nothing & \nothing \\ \hline + \stackItemStamp{k}_{i + 1} & \nothing & \nothing & \nothing & \nothing \\ \hline + \end{array} +\] +\caption{% +This table represents the stack pattern of the second row ($\ct_{i + 1} = 1$) of a \inst{LOG0} instruction.} +\[ + \begin{array}{|l|r|r|r|c|} \cline{2-5} + \multicolumn{1}{c|}{(\ct_{i + 1} = 1)} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} & \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & \multicolumn{1}{c|}{\text{Item 1}} & \multicolumn{1}{c|}{\text{Item 2}} & \multicolumn{1}{c|}{\text{Item 3}} & \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i + 1} & \col{h} - 2 & \col{h} - 3 & \col{h} - 4 & \nothing \\ \hline + \stackItemValHi{k}_{i + 1} / \stackItemValLo{k}_{i + 1} & \col{topic1} & \col{topic2} & \col{topic3} & \nothing \\ \hline + \stackItemPop{k}_{i + 1} & 1 & 1 & 1 & \nothing \\ \hline + \stackItemStamp{k}_{i + 1} & \hubTau \cdot \col{st} + 2 & \hubTau \cdot \col{st} + 3 & \hubTau \cdot \col{st} + 4 & \nothing \\ \hline + \end{array} +\] +\caption{% +By way of example, representation of the second row ($\ct_{i + 1} = 1$) of $\logSP\big[\col{param}; \col{b}, \col{b'}, \col{b''}\big]_{i}$ with +$\col{b} = 1$, +$\col{b'} = 1$, and +$\col{b''} = 0$ +and $\inst{param} = 3$ for a \inst{LOG3} instruction. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} diff --git a/hub/stack/patterns/pop_flag.tex b/hub/stack/patterns/pop_flag.tex new file mode 100644 index 0000000..c486b3b --- /dev/null +++ b/hub/stack/patterns/pop_flag.tex @@ -0,0 +1,4 @@ +We impose binary conditions on the $\stackItemPop{k}$ flags: +\begin{enumerate} + \item \If $\peekStack_{i} = 1$ \Then $\stackItemPop{k}$, for $k=1,\dots,4$, satisfy a binary relation (i.e. $\col{x} \cdot (1 - \col{x}) = 0$.) +\end{enumerate} \ No newline at end of file diff --git a/hub/stack/patterns/swap.tex b/hub/stack/patterns/swap.tex new file mode 100644 index 0000000..500bd6a --- /dev/null +++ b/hub/stack/patterns/swap.tex @@ -0,0 +1,87 @@ +\subsubsection{Constraints} +%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +Let $\col{param} \in \{ 1, 2, \dots, 16 \}$ be given. +We let $\swapSP\big[ \col{param} \big]_{i}$ stand for the following collection of constraints: +\begin{description} + \item[\underline{Stack Item $n^\circ\,1$:}] this excavates a value (``$v_\text{deep}$'') from within the stack: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{1}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - \col{param} \\ + \stackItemPop{1}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{1}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] this excavates the value (``$v_\text{top}$'') from the top of the stack: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{2}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} \\ + \stackItemPop{2}_{i} & \!\!\! = \!\!\! & 1 \\ + \stackItemStamp{2}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 1 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,2$:}] this inserts ``$v_\text{top}$'' deep within the stack: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{3}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} - \col{param} \\ + \stackItemPop{3}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValHi{3}_{i} & \!\!\! = \!\!\! & \stackItemValHi{2}_{i} \\ + \stackItemValLo{3}_{i} & \!\!\! = \!\!\! & \stackItemValLo{2}_{i} \\ + \stackItemStamp{3}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 2 + \end{array} + \right. + \] + \item[\underline{Stack Item $n^\circ\,4$:}] this inserts ``$v_\text{deep}$'' onto the top of the stack: + \[ + \left\{ + \begin{array}{lcl} + \stackItemHeight{4}_{i} & \!\!\! = \!\!\! & \stackHeight_{i} \\ + \stackItemPop{4}_{i} & \!\!\! = \!\!\! & 0 \\ + \stackItemValHi{4}_{i} & \!\!\! = \!\!\! & \stackItemValHi{1}_{i} \\ + \stackItemValLo{4}_{i} & \!\!\! = \!\!\! & \stackItemValLo{1}_{i} \\ + \stackItemStamp{4}_{i} & \!\!\! = \!\!\! & \hubTau \cdot \hubStamp_{i} + 3 + \end{array} + \right. + \] + \item[\underline{Height update:}] $\stackHeight{}\new{}_{i} = \stackHeight{}_{i}$; +\end{description} + + +\subsubsection{Graphical representation} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +The figure below represents the \swapSP{} stack pattern: +\begin{figure}[h!] +\[ + \begin{array}{|l|r|r|r|r|} + \cline{2-5} + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} & + \multicolumn{1}{c|}{\text{Stack}} \\ + \multicolumn{1}{c|}{} & + \multicolumn{1}{c|}{\text{Item 1}} & + \multicolumn{1}{c|}{\text{Item 2}} & + \multicolumn{1}{c|}{\text{Item 3}} & + \multicolumn{1}{c|}{\text{Item 4}} \\ \hline + \stackItemHeight{k}_{i} & \col{h} - \col{param} & \col{h} & \col{h} - \col{param} & \col{h} \\ \hline + \stackItemValHi{k}/\stackItemValLo{k} & v_\text{deep} & v_\text{top} & v_\text{top} & v_\text{deep} \\ \hline + \stackItemPop{k}_{i} & 1 & 1 & 0 & 0 \\ \hline + \stackItemStamp{k}_{i} & \hubTau \cdot \col{st} & \hubTau \cdot \col{st} + 1 & \hubTau \cdot \col{st} + 2 & \hubTau \cdot \col{st} + 3 \\ \hline + \end{array} +\] +\label{fig: dup stack pattern} +\caption{% +Graphical representation of $\swapSP\big[ \col{param} \big]_{i}$. +In applications this stack pattern applies to \inst{SWAPX} instructions having set $\col{param} := \INST_{i} - \inst{SWAP1} + 1$. +Thus for \inst{SWAPX} instructions $\col{param} = \inst{X}$. +We write $\col{h} := \stackHeight_{i}$ and $\col{st} := \hubStamp_{i}$.} +\end{figure} \ No newline at end of file diff --git a/hub/stack/request_hash.tex b/hub/stack/request_hash.tex new file mode 100644 index 0000000..9494c2a --- /dev/null +++ b/hub/stack/request_hash.tex @@ -0,0 +1,29 @@ +We introduce the following parametrized constraint family +\[ + \left\{ \begin{array}{l} + \maybeRequestHash { + anchorRow = i, + relOffset = \relof, + requestBit = \col{bit}, + } + \\ + \qquad \iff \stackHashInfoFlag _{i + \relof} = \col{bit} \\ + \end{array} \right. +\] +We further set +\[ + \left\{ \begin{array}{l} + \requestHash { + anchorRow = i, + relOffset = \relof, + } + \\ + \qquad \iff + \maybeRequestHash { + anchorRow = i, + relOffset = \relof, + requestBit = \rOne, + } + \\ + \end{array} \right. +\] diff --git a/hub/storage/_inputs.tex b/hub/storage/_inputs.tex new file mode 100644 index 0000000..a83320e --- /dev/null +++ b/hub/storage/_inputs.tex @@ -0,0 +1,3 @@ +\section{Storage-rows} +\subsection{Specialized constraints \lispDone{}} \label{hub: storage: specialized constraints} \input{storage/specialized/_inputs} +\subsection{Binary columns for gas cost \lispDone{}} \label{hub: storage: gas cost binary columns} \input{storage/pricing_bits} diff --git a/hub/storage/pricing_bits.tex b/hub/storage/pricing_bits.tex new file mode 100644 index 0000000..13a9626 --- /dev/null +++ b/hub/storage/pricing_bits.tex @@ -0,0 +1,76 @@ +\begin{center} +\boxed{% +\text{The constraints presented only make sense given that } +\peekStorage_{i} = 1.} +\end{center} + +The present section (partially) constrains the following columns: +$\stoOrigValueIsZero$, +$\stoCurrValueIsZero$, +$\stoCurrValueIsOrig$, +$\stoNextValueIsCurr$, +$\stoNextValueIsZero$. As already mentioned, their purpose is to serve in the gas cost computation of \inst{SSTORE} instructions. +\begin{enumerate} + \item + $\stoOrigValueIsZero$, + $\stoCurrValueIsOrig$, + $\stoCurrValueIsZero$, + $\stoNextValueIsCurr$, + $\stoNextValueIsZero$, + $\stoNextValueIsOrig$ + are binary columns; + \item we constrain $\stoOrigValueIsZero$: + \begin{enumerate} + \item \If $\stoOrigValueHi_{i} \neq 0$ \Then $\stoOrigValueIsZero_{i} = 0$ + \item \If $\stoOrigValueHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\stoOrigValueLo_{i} \neq 0$ \Then $\stoOrigValueIsZero_{i} = 0$ + \item \If $\stoOrigValueLo_{i} = 0$ \Then $\stoOrigValueIsZero_{i} = 1$ + \end{enumerate} + \end{enumerate} + \item we constrain $\stoCurrValueIsZero$: + \begin{enumerate} + \item \If $\stoCurrValueHi_{i} \neq 0$ \Then $\stoCurrValueIsZero_{i} = 0$ + \item \If $\stoCurrValueHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\stoCurrValueLo_{i} \neq 0$ \Then $\stoCurrValueIsZero_{i} = 0$ + \item \If $\stoCurrValueLo_{i} = 0$ \Then $\stoCurrValueIsZero_{i} = 1$ + \end{enumerate} + \end{enumerate} + \item we constrain $\stoNextValueIsZero$: + \begin{enumerate} + \item \If $\stoNextValueHi_{i} \neq 0$ \Then $\stoNextValueIsZero_{i} = 0$ + \item \If $\stoNextValueHi_{i} = 0$ \Then + \begin{enumerate} + \item \If $\stoNextValueLo_{i} \neq 0$ \Then $\stoNextValueIsZero_{i} = 0$ + \item \If $\stoNextValueLo_{i} = 0$ \Then $\stoNextValueIsZero_{i} = 1$ + \end{enumerate} + \end{enumerate} + \item we constrain $\stoCurrValueIsOrig$: + \begin{enumerate} + \item \If $\stoCurrValueHi_{i} \neq \stoOrigValueHi_{i}$ \Then $\stoCurrValueIsOrig_{i} = 0$ + \item \If $\stoCurrValueHi_{i} = \stoOrigValueHi_{i}$ \Then + \begin{enumerate} + \item \If $\stoCurrValueLo_{i} \neq \stoOrigValueLo_{i}$ \Then $\stoCurrValueIsOrig_{i} = 0$ + \item \If $\stoCurrValueLo_{i} = \stoOrigValueLo_{i}$ \Then $\stoCurrValueIsOrig_{i} = 1$ + \end{enumerate} + \end{enumerate} + \item we constrain $\stoNextValueIsCurr$: + \begin{enumerate} + \item \If $\stoCurrValueHi_{i} \neq \stoNextValueHi_{i}$ \Then $\stoNextValueIsCurr_{i} = 0$ + \item \If $\stoCurrValueHi_{i} = \stoNextValueHi_{i}$ \Then + \begin{enumerate} + \item \If $\stoCurrValueLo_{i} \neq \stoNextValueLo_{i}$ \Then $\stoNextValueIsCurr_{i} = 0$ + \item \If $\stoCurrValueLo_{i} = \stoNextValueLo_{i}$ \Then $\stoNextValueIsCurr_{i} = 1$ + \end{enumerate} + \end{enumerate} + \item we constrain $\stoNextValueIsOrig$: + \begin{enumerate} + \item \If $\stoNextValueHi_{i} \neq \stoOrigValueHi_{i}$ \Then $\stoNextValueIsOrig_{i} = 0$ + \item \If $\stoNextValueHi_{i} = \stoOrigValueHi_{i}$ \Then + \begin{enumerate} + \item \If $\stoNextValueLo_{i} \neq \stoOrigValueLo_{i}$ \Then $\stoNextValueIsOrig_{i} = 0$ + \item \If $\stoNextValueLo_{i} = \stoOrigValueLo_{i}$ \Then $\stoNextValueIsOrig_{i} = 1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/hub/storage/specialized/_inputs.tex b/hub/storage/specialized/_inputs.tex new file mode 100644 index 0000000..6cf9e11 --- /dev/null +++ b/hub/storage/specialized/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsection{Storage reading constraints \lispDone{}} \label{hub: storage: specialized: reading} \input{storage/specialized/reading} +\subsubsection{Storage key warmth updates \lispDone{}} \label{hub: storage: specialized: warmth} \input{storage/specialized/warmth} +\subsubsection{Same storage slot \lispDone{}} \label{hub: storage: specialized: same slot} \input{storage/specialized/same_slot} +\subsubsection{Undoing updates \lispDone{}} \label{hub: storage: specialized: undoing} \input{storage/specialized/undoing} diff --git a/hub/storage/specialized/reading.tex b/hub/storage/specialized/reading.tex new file mode 100644 index 0000000..2e341a1 --- /dev/null +++ b/hub/storage/specialized/reading.tex @@ -0,0 +1,10 @@ +The following set of constraints imposes that storage variables are only read but not modified +\[ + \storageReading + {i}{\relof} + \iff + \left\{ \begin{array}{lcl} + \stoCurrValueHi_{i + \relof} & \!\!\! = \!\!\! & \stoNextValueHi_{i + \relof} \\ + \stoCurrValueLo_{i + \relof} & \!\!\! = \!\!\! & \stoNextValueLo_{i + \relof} \\ + \end{array} \right. +\] diff --git a/hub/storage/specialized/same_slot.tex b/hub/storage/specialized/same_slot.tex new file mode 100644 index 0000000..3983d4e --- /dev/null +++ b/hub/storage/specialized/same_slot.tex @@ -0,0 +1,13 @@ +The constraint below forces two consecutive rows to peek into the same storage slot: +\[ + \stoSameStorageSlot {i}{\reluo}{\reldo} + \iff + \left\{ \begin{array}{lcl} + \stoAddressHi _{i + \reluo} & \!\!\! = \!\!\! & \stoAddressHi _{i + \reldo} \\ + \stoAddressLo _{i + \reluo} & \!\!\! = \!\!\! & \stoAddressLo _{i + \reldo} \\ + \stoKeyHi _{i + \reluo} & \!\!\! = \!\!\! & \stoKeyHi _{i + \reldo} \\ + \stoKeyLo _{i + \reluo} & \!\!\! = \!\!\! & \stoKeyLo _{i + \reldo} \\ + \stoDeploymentNumber _{i + \reluo} & \!\!\! = \!\!\! & \stoDeploymentNumber _{i + \reldo} \\ + \end{array} \right. +\] + diff --git a/hub/storage/specialized/undoing.tex b/hub/storage/specialized/undoing.tex new file mode 100644 index 0000000..a6bc13e --- /dev/null +++ b/hub/storage/specialized/undoing.tex @@ -0,0 +1,24 @@ +The following collections of constraints undo changes made to warmth and or value: +\[ + \left\{ \begin{array}{lcl} + \stoUndoWarmthUpdate {i}{\reluo}{\reldo} & \iff & + \left\{ \begin{array}{lclr} + \stoWarmth _{i + \reluo} & \!\!\! = \!\!\! & \stoWarmth\new_{i + \reldo} & \quad (\trash) \\ + \stoWarmth\new_{i + \reluo} & \!\!\! = \!\!\! & \stoWarmth _{i + \reldo} \\ + \end{array} \right. \vspace{2mm} \\ + \stoUndoValueUpdate {i}{\reluo}{\reldo} & \iff & + \left\{ \begin{array}{lclr} + \stoCurrValueHi_{i + \reluo} & \!\!\! = \!\!\! & \stoNextValueHi_{i + \reldo} & \quad (\trash) \\ + \stoCurrValueLo_{i + \reluo} & \!\!\! = \!\!\! & \stoNextValueLo_{i + \reldo} & \quad (\trash)\vspace{2mm} \\ + \stoNextValueHi_{i + \reluo} & \!\!\! = \!\!\! & \stoCurrValueHi_{i + \reldo} \\ + \stoNextValueLo_{i + \reluo} & \!\!\! = \!\!\! & \stoCurrValueLo_{i + \reldo} \\ + \end{array} \right. \vspace{2mm} \\ + \stoUndoWarmthAndValueUpdate {i}{\reluo}{\reldo} & \iff & + \left\{ \begin{array}{lcl} + \stoUndoWarmthUpdate {i}{\reluo}{\reldo} \\ + \stoUndoValueUpdate {i}{\reluo}{\reldo} \\ + \end{array} \right. \\ + \end{array} \right. +\] +\saNote{} This constraint should only be applied when $\peekStorage_{i} = \peekStorage_{i - 1} = 1$. +There are no scenarios where changes made to storage must be undone where the changes in question are further apart than on the previous row. diff --git a/hub/storage/specialized/warmth.tex b/hub/storage/specialized/warmth.tex new file mode 100644 index 0000000..cc878f0 --- /dev/null +++ b/hub/storage/specialized/warmth.tex @@ -0,0 +1,6 @@ +\label{par: storage key warmth updates} These are the storage key equivalent of the account warmth updates from paragraph~\ref{par: account warmth updates} +\[ + \stoTurnOnWarmth + {i}{\relof} + \iff \stoWarmth\new _{i + \relof} = 1 +\] diff --git a/hub/stupid_edge_cases b/hub/stupid_edge_cases new file mode 100644 index 0000000..a8281e2 --- /dev/null +++ b/hub/stupid_edge_cases @@ -0,0 +1,12 @@ +edge cases à la con + +- tx which is a message call to a precompile: WE DON'T DEAL WITH THOSE AT ALL (they would skip and in the skip part we impose that IS_PRECOMPILE = 0) + +- including one's own address in the addresses to prewarm + +- using IS_PRECOMPILE we can make it so that in the reordered version of events precompiles are always warm OR that in computing the gas cost of operations we take this flag into account e.g. + - IF IS_PRECOMPILE = 1 [one gas computation] + - IF IS_PRECOMPILE = 0 [another depending on WARM] +- des gens incluent leur propre adresse dans les trucs à prewarmer; je crois que pour nous sauver de ces conneries il suffit de ne pas imposer la valeur de WARM dans la phase d'initialization et d'imposer au contraire, dans la version ordonnée par [block_num, tx_num, addr_hi, addr_lo, dom->, <-sub] que la première apparition de WARM vale 0; +- il y a des répétitions dans les addresses à prewarmer; ça je ne veux pas vraiment le résoudre; pour moi l'opérateur devrait juste rejeter ces transactions; il est possible de filtrer à la fin grâce à une 2 sided plookup inclusion proof vers un module qui impose des conditions d'ordre lex. strict. +- l'adresse COINBASE fait un SELFDESTRUCT pendant la transaction: qu'est-ce qui se passe ? J'imagine que le SELFDESTRUCT l'emporte et que les fees sont tuées. \ No newline at end of file diff --git a/hub/templates.tex b/hub/templates.tex new file mode 100644 index 0000000..e69de29 diff --git a/hub/tx_finl/_inputs.tex b/hub/tx_finl/_inputs.tex new file mode 100644 index 0000000..df237cc --- /dev/null +++ b/hub/tx_finl/_inputs.tex @@ -0,0 +1,6 @@ +\input{tx_finl/_local} +\section{Finalization phase \lispDone{}} \label{hub: finalization phase} +\subsection{Introduction} \label{hub: finalization phase: intro} \input{tx_finl/intro} +\subsection{Peeking flags \lispDone{}} \label{hub: finalization phase: peeking} \input{tx_finl/peeking} +\subsection{The transaction success case \lispDone{}} \label{hub: finalization phase: success} \input{tx_finl/success} +\subsection{The transaction failure case \lispDone{}} \label{hub: finalization phase: failure} \input{tx_finl/failure} diff --git a/hub/tx_finl/_local.tex b/hub/tx_finl/_local.tex new file mode 100644 index 0000000..a708dfb --- /dev/null +++ b/hub/tx_finl/_local.tex @@ -0,0 +1,17 @@ +\def\locWeiRefund {\col{caller\_refund}} +\def\locWeiReward {\col{coinbase\_reward}} +% no revert +\def\locTxFinlSuccessSenderAccountOffset {\yellowm{0}} +\def\locTxFinlSuccessCoinbaseAccountOffset {\yellowm{1}} +\def\locTxFinlSuccessTransactionRowOffset {\orangem{2}} +% revert +\def\locTxFinlFailureSenderAccountOffset {\yellowm{0}} +\def\locTxFinlFailureRecipientAccountOffset {\yellowm{1}} +\def\locTxFinlFailureCoinbaseAccountOffset {\yellowm{2}} +\def\locTxFinlFailureTransactionRowOffset {\orangem{3}} +% +\def\locFinlSuccessSenderRefund {\col{sender\_refund}} +\def\locFinlSuccessCoinbaseReward {\col{coinbase\_fee}} +% +\def\locFinlFailureSenderRefund {\col{sender\_refund}} +\def\locFinlFailureCoinbaseReward {\col{coinbase\_fee}} diff --git a/hub/tx_finl/failure.tex b/hub/tx_finl/failure.tex new file mode 100644 index 0000000..aa13962 --- /dev/null +++ b/hub/tx_finl/failure.tex @@ -0,0 +1,118 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \txExec _{i - 1} & = & 1 \\ + \txFinl _{i} & = & 1 \\ + \cnWillRev _{i - 1} & = & 1 \\ + \end{array} \right. + } +\end{center} +The constraints that follow pertain to transaction finalization when the underlying transaction exited with status code $0$. +\begin{description} + \item[\underline{\underline{Account row n$^°{(i + \locTxFinlSuccessSenderAccountOffset)}$:}}] + we impose the following to the \textbf{sender account}: + \[ + \left\{\begin{array}{lcl} + \accAddress\high _{i + \locTxFinlFailureSenderAccountOffset} & = & \txFrom\high _{i + \locTxFinlFailureTransactionRowOffset} \\ + \accAddress\low _{i + \locTxFinlFailureSenderAccountOffset} & = & \txFrom\low _{i + \locTxFinlFailureTransactionRowOffset} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxFinlFailureSenderAccountOffset}{\locFinlFailureSenderRefund}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locTxFinlFailureSenderAccountOffset} } \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxFinlFailureSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxFinlFailureSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxFinlFailureSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxFinlFailureSenderAccountOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxFinlFailureSenderAccountOffset, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locTxFinlFailureSenderAccountOffset}{0}} \\ + \end{array}\right. + \] + where + \[ + \locFinlFailureSenderRefund \define + \txGasPrice_{i + \locTxFinlFailureTransactionRowOffset} + \cdot \txEffectiveRefund_{i + \locTxFinlFailureTransactionRowOffset} + + \txValue_{i + \locTxFinlFailureTransactionRowOffset} + \] + \item[\underline{\underline{Account row n$^°{(i + \locTxFinlFailureRecipientAccountOffset)}$:}}] + we impose the following to the \textbf{recipient account}: + \[ + \left\{\begin{array}{lcl} + \accAddress\high _{i + \locTxFinlFailureRecipientAccountOffset} & = & \txTo\high _{i + \locTxFinlFailureTransactionRowOffset} \\ + \accAddress\low _{i + \locTxFinlFailureRecipientAccountOffset} & = & \txTo\low _{i + \locTxFinlFailureTransactionRowOffset} \\ + \multicolumn{3}{l}{\accDecrementBalance {i}{\locTxFinlFailureRecipientAccountOffset}{\txValue_{i + \locTxFinlFailureTransactionRowOffset}}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locTxFinlFailureRecipientAccountOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxFinlFailureRecipientAccountOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxFinlFailureRecipientAccountOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxFinlFailureRecipientAccountOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxFinlFailureRecipientAccountOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxFinlFailureRecipientAccountOffset, + domOffset = 1, + } + } \\ + % \standardDomSubStamps {i}{\locTxFinlFailureRecipientAccountOffset}{1}} \\ + % \multicolumn{3}{l}{\accOpening {\locTxFinlFailureSenderAccountOffset} _{i}} \\ + \end{array}\right. + \] + \item[\underline{\underline{Account row n$^°{(i + \locTxFinlFailureCoinbaseAccountOffset)}$:}}] + we impose the following to the \textbf{coinbase account}: + \[ + \left\{\begin{array}{lcl} + \accAddress\high _{i + \locTxFinlFailureCoinbaseAccountOffset} & = & \txCoinbase\high _{i + \locTxFinlFailureTransactionRowOffset} \\ + \accAddress\low _{i + \locTxFinlFailureCoinbaseAccountOffset} & = & \txCoinbase\low _{i + \locTxFinlFailureTransactionRowOffset} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxFinlFailureCoinbaseAccountOffset}{\locFinlFailureCoinbaseReward}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locTxFinlFailureCoinbaseAccountOffset} } \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxFinlFailureCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxFinlFailureCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxFinlFailureCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxFinlFailureCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxFinlFailureCoinbaseAccountOffset, + domOffset = 2, + } + } \\ + % \standardDomSubStamps {i}{\locTxFinlFailureCoinbaseAccountOffset}{2} } \\ + \end{array}\right. + \] + where \locFinlFailureCoinbaseReward{} is a shorthand defined as follows: + \[ + \locFinlFailureCoinbaseReward \define + \left[ \begin{array}{cl} + \cdot & \txPriorityFeePerGas_{i + \locTxFinlFailureCoinbaseAccountOffset} \\ + \cdot & (\txGasLimit_{i + \locTxFinlFailureCoinbaseAccountOffset} - \txEffectiveRefund_{i + \locTxFinlFailureCoinbaseAccountOffset}) \\ + \end{array} \right] + \] + % \begin{enumerate} + % \item \If $\txIsTypeTwo_{i + \locTxFinlFailureTransactionRowOffset} = 0$ \Then + % \[ + % \locFinlFailureCoinbaseReward \define + % \txGasPrice_{i + \locTxFinlFailureTransactionRowOffset} + % \cdot (\txGasLimit_{i + \locTxFinlFailureTransactionRowOffset} - \txEffectiveRefund_{i + \locTxFinlFailureTransactionRowOffset}) + % \] + % \item \If $\txIsTypeTwo_{i + \locTxFinlFailureTransactionRowOffset} = 1$ \Then + % \[ + % \locFinlFailureCoinbaseReward \define + % (\txGasPrice_{i + \locTxFinlFailureTransactionRowOffset} - \txBasefee_{i + \locTxFinlFailureTransactionRowOffset}) + % \cdot (\txGasLimit_{i + \locTxFinlFailureTransactionRowOffset} - \txEffectiveRefund_{i + \locTxFinlFailureTransactionRowOffset}) + % \] + % \end{enumerate} + \item[\underline{\underline{Transaction row n$^°{(i + \locTxFinlFailureTransactionRowOffset)}$:}}] + we load transaction data to have access to relevant fields but also to confirm data predicted in the \txnDataMod{}: + \[ + \left\{\begin{array}{lcll} + \txStatusCode _{i + \locTxFinlFailureTransactionRowOffset} & = & \rZero \\ + \txFinalRefundCounter _{i + \locTxFinlFailureTransactionRowOffset} & = & \refund _{i - 1} \\ + \txLeftoverGas _{i + \locTxFinlFailureTransactionRowOffset} & = & \gasNext _{i - 1} \\ + \end{array}\right. + \] +\end{description} diff --git a/hub/tx_finl/intro.tex b/hub/tx_finl/intro.tex new file mode 100644 index 0000000..43469da --- /dev/null +++ b/hub/tx_finl/intro.tex @@ -0,0 +1,17 @@ +The present section deals with \textbf{transaction finalization}. +The purpose of this phase is to +\begin{enumerate} + \item pay the gas refund of the transaction sender $S(T)$; + \item pay the \inst{COINBASE} address the gas fee; +\end{enumerate} +Furthermore, if the transaction reverts, the present phase is responsible for +\begin{enumerate}[resume] + \item undoing the initial value transfer from the transaction sender to the recipient; +\end{enumerate} +Finally it is here that the \hubMod{} gets to +\begin{enumerate}[resume] + \item confirm data predicted in the \txnDataMod{} module and made available on transaction-rows e.g. + $\txStatusCode$, + $\txFinalRefundCounter$, + $\txLeftoverGas$; +\end{enumerate} diff --git a/hub/tx_finl/peeking.tex b/hub/tx_finl/peeking.tex new file mode 100644 index 0000000..7e395db --- /dev/null +++ b/hub/tx_finl/peeking.tex @@ -0,0 +1,51 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \txExec _{i - 1} & = & 1 \\ + \txFinl _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +In other words we assume row $i$ is the first row of the transaction finalization phase. +The purpose of this transaction processing phase is to proceed to gas refunds for the sender address and pay the coinbase address. +In case of a transaction with status code $=0$ the sender address is reimbursed the transaction value (and the recipient sees its balance reduced by the same amount.) +As such we shall peek into +(\emph{a}) +the \texttt{from} account to proceed to the gas refund +(\emph{b}) +the \texttt{coinbase} account to proceed to gas payment. +What follows depends on whether the transaction succeeds or fails. If the transaction succeeds the above is sufficient. +The \zkEvm{} finishes by loading a single transaction row to confirm data. If the transaction fails we insert two extra rows: +(\emph{c}) +we again peek into the sender account and proceed to undo the initial value transfer by crediting the account in question with the transaction value; +(\emph{d}) +we peek into the transaction recipient account and decrement its balance by the transaction value. In all cases after peeking into accounts the final row of the current transaction loads the transaction data. The constraints below ensure the desired behaviour: +\begin{enumerate} + \item \If $\cnWillRev_{i - 1} = 0$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekAccount _{i + \locTxFinlSuccessSenderAccountOffset } \\ + + & \peekAccount _{i + \locTxFinlSuccessCoinbaseAccountOffset } \\ + + & \peekTransaction _{i + \locTxFinlSuccessTransactionRowOffset } \\ + \end{array} \right] + = + \nsrTransactionFinalizationPhaseWontRevert + \] + \item \If $\cnWillRev_{i - 1} = 1$ \Then + \[ + \left[ \begin{array}{cr} + + & \peekAccount _{i + \locTxFinlFailureSenderAccountOffset } \\ + + & \peekAccount _{i + \locTxFinlFailureRecipientAccountOffset } \\ + + & \peekAccount _{i + \locTxFinlFailureCoinbaseAccountOffset } \\ + + & \peekTransaction _{i + \locTxFinlFailureTransactionRowOffset } \\ + \end{array} \right] + = + \nsrTransactionFinalizationPhaseWillRevert + \] +\end{enumerate} +\saNote{} Given the heartbeat constraints, the above has several \emph{implicit} consequences\footnote{which the implemenation need \textbf{not} enforce through new constraints}. The following are some of them. +\begin{itemize} + \item $\batchNum$, $\txNum$, $\hubStamp$, $\txSkip$ remain constant during the finalization phase; + \item $\absTxNum$ and $\hubStamp$ will jump by 1 at the end of the phase; +\end{itemize} diff --git a/hub/tx_finl/success.tex b/hub/tx_finl/success.tex new file mode 100644 index 0000000..ce72bba --- /dev/null +++ b/hub/tx_finl/success.tex @@ -0,0 +1,94 @@ +\begin{center} + \boxed{% + \text{The constraints presented below assume } + \left\{ \begin{array}{lcl} + \txExec _{i - 1} & = & 1 \\ + \txFinl _{i} & = & 1 \\ + \cnWillRev _{i - 1} & = & 0 \\ + \end{array} \right. + } +\end{center} +The constraints that follow pertain to transaction finalization when the underlying transaction exited with status code $1$. +\begin{description} + \item[\underline{\underline{Account row n$^°{(i + \locTxFinlSuccessSenderAccountOffset)}$:}}] + we impose the following to the \textbf{sender account}: + \[ + \left\{\begin{array}{lcl} + \accAddress\high _{i + \locTxFinlSuccessSenderAccountOffset} & = & \txFrom\high _{i + \locTxFinlSuccessTransactionRowOffset} \\ + \accAddress\low _{i + \locTxFinlSuccessSenderAccountOffset} & = & \txFrom\low _{i + \locTxFinlSuccessTransactionRowOffset} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxFinlSuccessSenderAccountOffset}{\locFinlSuccessSenderRefund}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locTxFinlSuccessSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxFinlSuccessSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxFinlSuccessSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxFinlSuccessSenderAccountOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxFinlSuccessSenderAccountOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxFinlSuccessSenderAccountOffset, + domOffset = 0, + } + } \\ + % \multicolumn{3}{l}{\accOpening {\locTxFinlSuccessSenderAccountOffset} _{i}} \\ + \end{array}\right. + \] + where + \[ + \locFinlSuccessSenderRefund \define + \txGasPrice_{i + \locTxFinlSuccessTransactionRowOffset} + \cdot \txEffectiveRefund_{i + \locTxFinlSuccessTransactionRowOffset} + \] + \item[\underline{\underline{Account row n$^°{(i + \locTxFinlSuccessCoinbaseAccountOffset)}$:}}] + we impose the following to the \textbf{coinbase account}: + \[ + \left\{\begin{array}{lcl} + \accAddress\high _{i + \locTxFinlSuccessCoinbaseAccountOffset} & = & \txCoinbase\high _{i + \locTxFinlSuccessTransactionRowOffset} \\ + \accAddress\low _{i + \locTxFinlSuccessCoinbaseAccountOffset} & = & \txCoinbase\low _{i + \locTxFinlSuccessTransactionRowOffset} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxFinlSuccessCoinbaseAccountOffset}{\locFinlSuccessCoinbaseReward}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locTxFinlSuccessCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxFinlSuccessCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxFinlSuccessCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxFinlSuccessCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxFinlSuccessCoinbaseAccountOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxFinlSuccessCoinbaseAccountOffset, + domOffset = 1, + } + } \\ + % \standardDomSubStamps {i}{\locTxFinlSuccessCoinbaseAccountOffset}{1}} \\ + \end{array}\right. + \] + where \locFinlSuccessCoinbaseReward{} is a shorthand defined as follows: + \[ + \locFinlSuccessCoinbaseReward \define + \left[ \begin{array}{cl} + \cdot & \txPriorityFeePerGas_{i + \locTxFinlSuccessCoinbaseAccountOffset} \\ + \cdot & (\txGasLimit_{i + \locTxFinlSuccessCoinbaseAccountOffset} - \txEffectiveRefund_{i + \locTxFinlSuccessCoinbaseAccountOffset}) \\ + \end{array} \right] + \] + % \begin{enumerate} + % \item \If $\txIsTypeTwo_{i + \locTxFinlSuccessTransactionRowOffset} = 0$ \Then + % \[ + % \locFinlSuccessCoinbaseReward \define + % \txGasPrice_{i + \locTxFinlSuccessTransactionRowOffset} + % \cdot (\txGasLimit_{i + \locTxFinlSuccessTransactionRowOffset} - \txEffectiveRefund_{i + \locTxFinlSuccessTransactionRowOffset}) + % \] + % \item \If $\txIsTypeTwo_{i + \locTxFinlSuccessTransactionRowOffset} = 1$ \Then + % \[ + % \locFinlSuccessCoinbaseReward \define + % (\txGasPrice_{i + \locTxFinlSuccessTransactionRowOffset} - \txBasefee_{i + \locTxFinlSuccessTransactionRowOffset}) + % \cdot (\txGasLimit_{i + \locTxFinlSuccessTransactionRowOffset} - \txEffectiveRefund_{i + \locTxFinlSuccessTransactionRowOffset}) + % \] + % \end{enumerate} + \item[\underline{\underline{Transaction row n$^°{(i + \locTxFinlSuccessTransactionRowOffset)}$:}}] + we load transaction data to have access to relevant fields but also to confirm data predicted in the \txnDataMod{}: + \[ + \left\{\begin{array}{lcll} + \txStatusCode _{i + \locTxFinlSuccessTransactionRowOffset} & = & \rOne \\ + \txFinalRefundCounter _{i + \locTxFinlSuccessTransactionRowOffset} & = & \refund _{i - 1} \\ + \txLeftoverGas _{i + \locTxFinlSuccessTransactionRowOffset} & = & \gasNext _{i - 1} \\ + \end{array}\right. + \] +\end{description} diff --git a/hub/tx_init/_inputs.tex b/hub/tx_init/_inputs.tex new file mode 100644 index 0000000..1262f8e --- /dev/null +++ b/hub/tx_init/_inputs.tex @@ -0,0 +1,4 @@ +\input{tx_init/_local} +\section{Initialization phase \lispDone{}} +\subsection{Setting the peeking flags \lispDone{}} \label{hub: initialization phase: setting peeking flags} \input{tx_init/peeking} +\subsection{Common constraints \lispDone{}} \label{hub: initialization phase: setting peeking flags} \input{tx_init/common} diff --git a/hub/tx_init/_local.tex b/hub/tx_init/_local.tex new file mode 100644 index 0000000..683ec10 --- /dev/null +++ b/hub/tx_init/_local.tex @@ -0,0 +1,10 @@ +\def\locTxInitWeiCost {\col{wei\_cost}} +\def\locTxInitIsDeployment {\col{deployment}} +\def\locTxInitTriggerMmu {\col{trigger\_MMU}} +\def\locTxInitCallDataContextNumber {\col{call\_data\_context\_number}} + +\def\locTxInitSenderAccountRowOffset {\yellowm{0}} +\def\locTxInitRecipientAccountRowOffset {\yellowm{1}} +\def\locTxInitMiscRowOffset {\yellowm{2}} +\def\locTxInitContextRowOffset {\yellowm{3}} +\def\locTxInitTransactionRowOffset {\orangem{4}} diff --git a/hub/tx_init/common.tex b/hub/tx_init/common.tex new file mode 100644 index 0000000..d187dda --- /dev/null +++ b/hub/tx_init/common.tex @@ -0,0 +1,276 @@ +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\txInit_{i - 1} = 0$ and $\txInit_{i} = 1$.}} +\end{center} +We deal with setting the contents of the various peeking rows. +\begin{description} + \item[\underline{\underline{Sender account-row n$^°~\bm{(i + \locTxInitSenderAccountRowOffset)}$:}}] + the first row peeks into the sender account: + \[ + \left\{ \begin{array}{lclr} + \accAddress \high _{i + \locTxInitSenderAccountRowOffset} & = & \txFrom \high _{i + \locTxInitTransactionRowOffset} \\ + \accAddress \low _{i + \locTxInitSenderAccountRowOffset} & = & \txFrom \low _{i + \locTxInitTransactionRowOffset} \vspace{2mm} \\ + \multicolumn{3}{l}{\accDecrementBalance {i}{\locTxInitSenderAccountRowOffset}{\locTxInitWeiCost}} \\ + \multicolumn{3}{l}{\accIncrementNonce {i}{\locTxInitSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxInitSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxInitSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accTurnOnWarmth {i}{\locTxInitSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxInitSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accIsntPrecompile {i}{\locTxInitSenderAccountRowOffset}} & (\trash) \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxInitSenderAccountRowOffset, + domOffset = 0, + } + } \\ + %\standardDomSubStamps {i}{\locTxInitSenderAccountRowOffset}{0} } \\ + \end{array} \right. + \] + where + \[ + \locTxInitWeiCost \define + \left[ \begin{array}{cr} + + & \txValue_{i + \locTxInitTransactionRowOffset} \\ + + & \txGasPrice_{i + \locTxInitTransactionRowOffset} \cdot \txGasLimit_{i + \locTxInitTransactionRowOffset} \\ + \end{array} \right] + \] + \item[\underline{\underline{Recipient account-row n$^°~\bm{(i + \locTxInitRecipientAccountRowOffset)}$:}}] + the second row peeks into the recipient account: + \[ + \left\{ \begin{array}{lcl} + \accAddress \high _{i + \locTxInitRecipientAccountRowOffset} & = & \txTo \high _{i + \locTxInitTransactionRowOffset} \\ + \accAddress \low _{i + \locTxInitRecipientAccountRowOffset} & = & \txTo \low _{i + \locTxInitTransactionRowOffset} \vspace{2mm} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxInitRecipientAccountRowOffset}{\txValue_{i + \locTxInitTransactionRowOffset}}} \\ + % \multicolumn{3}{l}{\accSameNonce {i}{\locTxInitRecipientAccountRowOffset}} \\ + % \multicolumn{3}{l}{\accSameCode {i}{\locTxInitRecipientAccountRowOffset}} \\ + % \multicolumn{3}{l}{\accSameDeployment {i}{\locTxInitRecipientAccountRowOffset}} \\ + \texttt{Nonce:} & \multicolumn{2}{l}{\valueToBeSet} \\ + \texttt{Code:} & \multicolumn{2}{l}{\valueToBeSet} \\ + \texttt{Deployment:} & \multicolumn{2}{l}{\valueToBeSet} \\ + \multicolumn{3}{l}{\accTurnOnWarmth {i}{\locTxInitRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxInitRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accRetrieveCodeFragmentIndex {i}{\locTxInitRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accIsntPrecompile {i}{\locTxInitRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxInitRecipientAccountRowOffset, + domOffset = 1, + } + } \\ + % \standardDomSubStamps {i}{\locTxInitRecipientAccountRowOffset}{1}} \\ + \end{array} \right. + \] + We must again distinguish between message calls ($\txIsDeployment \equiv 0$) and deployments ($\txIsDeployment \equiv 1$). + We thus define the following shorthand + \[ + \locTxInitIsDeployment \define \txIsDeployment _{i + \locTxInitTransactionRowOffset} + \] + and set + \begin{description} + \item[\underline{Message calls:}] + \If $\locTxInitIsDeployment = 0$ \Then + \begin{description} + \item[Nonce, code and deployment:] + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameNonce {i}{\locTxInitRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxInitRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxInitRecipientAccountRowOffset}} \\ + \end{array} \right. + \] + \item[Address trimming:] + the following is used to justify the fact that the target address isn't that of a precompile: + \[ + \accTrimAddress + {i}{\locTxInitRecipientAccountRowOffset} + {\txTo \high _{i + \locTxInitTransactionRowOffset}} + {\txTo \low _{i + \locTxInitTransactionRowOffset}} + \] + \end{description} + \item[\underline{Nontrivial deployments:}] + \If $\locTxInitIsDeployment = 1$ \Then + \begin{description} + \item[Nonce:] + we impose + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accIncrementNonce {i}{\locTxInitRecipientAccountRowOffset}} \\ + \accNonce_{i + \locTxInitRecipientAccountRowOffset} & = & 0 & (\trash) \vspace{2mm} \\ + \end{array} \right. + \] + \item[Code:] + we impose + \[ + \left\{ \begin{array}{lclr} + \accHasCode _{i + \locTxInitRecipientAccountRowOffset} & = & 0 & (\trash) \\ + \accCodehashHi _{i + \locTxInitRecipientAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo _{i + \locTxInitRecipientAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \accCodesize _{i + \locTxInitRecipientAccountRowOffset} & = & 0 & (\trash) \\ + \end{array} \right. + \;\text{and}\; + \left\{ \begin{array}{lclr} + \accHasCode \new _{i + \locTxInitRecipientAccountRowOffset} & = & 0 \\ + \accCodehashHi \new _{i + \locTxInitRecipientAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo \new _{i + \locTxInitRecipientAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \accCodesize \new _{i + \locTxInitRecipientAccountRowOffset} & = & \txInitCodeSize_{i + \locTxInitTransactionRowOffset} \\ + \end{array} \right. + \] + \item[Deployment:] + we impose + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accIncrementDeploymentNumber {i}{\locTxInitRecipientAccountRowOffset}} \\ + \accDepStatus _{i + \locTxInitRecipientAccountRowOffset} & = & 0 & (\trash) \\ + \accDepStatus\new _{i + \locTxInitRecipientAccountRowOffset} & = & \rOne \\ + \end{array} \right. + \] + \end{description} + % \item[\underline{Retrieving the code fragment index:}] + % we impose + % \[ + % \accRetrieveCodeFragmentIndex {i}{\locTxInitRecipientAccountRowOffset} + % \] + \end{description} + \item[\underline{\underline{Miscellaneous-row n$^°~(\bm{i + \locTxInitMiscRowOffset})$:}}] + we impose the following + \[ + \weightedMiscFlagSum {i}{\locTxInitMiscRowOffset} + = + \miscMmuWeight \cdot \txCopyTxcd _{i + \locTxInitTransactionRowOffset} + \] + Furthermore, \If $\miscMmuFlag _{i + \locTxInitMiscRowOffset} = 1$ \Then + \[ + \setMmuInstructionParametersExoToRamTransplants { + anchorRow = i , + relOffset = \locTxInitMiscRowOffset , + sourceId = \absTxNum_{i} , + targetId = \locTxInitCallDataContextNumber , + size = \txCallDataSize _{i + \locTxInitTransactionRowOffset} , + exoSum = \exoWeightRlpTxn , + phase = \phaseTransactionCallData , + } + % \setMmuInstructionParametersExoToRamTransplants {i}{\locTxInitMiscRowOffset} + % \left[ \begin{array}{ll} + % \utt{Source ID:} & \absTxNum_{i} \\ + % \utt{Target ID:} & \locTxInitCallDataContextNumber \\ + % % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + % % \utt{Source offset low:} & \col{src\_offset\_lo} \\ + % % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \txCallDataSize _{i + \locTxInitTransactionRowOffset} \\ + % % \utt{Reference offset:} & \col{ref\_offset} \\ + % % \utt{Reference size:} & \col{ref\_size} \\ + % % \utt{Success bit:} & \col{success\_bit} \\ + % % \utt{Limb one:} & \col{limb\_1} \\ + % % \utt{Limb two:} & \col{limb\_2} \\ + % \utt{Exo sum:} & \exoWeightRlpTxn \\ + % \utt{Phase:} & \phaseTransactionCallData \\ + % \end{array} \right] \vspace{2mm} \\ + \] + where we have set + \[ + \locTxInitCallDataContextNumber \define \txCopyTxcd _{i + \locTxInitTransactionRowOffset} \cdot \hubStamp_{i} + \] + \saNote{} In other words + \[ + \left\{ \begin{array}{lclr} + \miscExpFlag _{i + \locTxInitMiscRowOffset} & = & \gZero & (\trash) \\ + \miscMmuFlag _{i + \locTxInitMiscRowOffset} & = & \txCopyTxcd _{i + \locTxInitTransactionRowOffset} & (\trash) \\ + \miscMxpFlag _{i + \locTxInitMiscRowOffset} & = & \rZero & (\trash) \\ + \miscOobFlag _{i + \locTxInitMiscRowOffset} & = & \gZero & (\trash) \\ + \miscStpFlag _{i + \locTxInitMiscRowOffset} & = & \gZero & (\trash) \\ + \end{array} \right. + \] + \saNote{} + The $\txCopyTxcd$ flag is set in the \txnDataMod{} module as the conjunction of a transaction requiring \evm{} execution and being provided with nonempty call data, + see section~(\ref{txn_data: constraints: comparisons}). + + \item[\underline{\underline{Context-row n$^°~(\bm{i + \locTxInitContextRowOffset})$:}}] + we initialize the next execution context as follows: + \[ + \initializeContext{ + anchorRow = i , + relOffset = \locTxInitContextRowOffset , + contextNumber = \cn\new _{i} , + callStackDepth = \rZero , + isRoot = \rOne , + isStatic = \rZero , + accountAddressHigh = \txTo \high _{i + \locTxInitTransactionRowOffset} , + accountAddressLow = \txTo \low _{i + \locTxInitTransactionRowOffset} , + accountDeploymentNumber = \accDepNumber \new _{i + \locTxInitRecipientAccountRowOffset} , + byteCodeAddressHi = \txTo \high _{i + \locTxInitTransactionRowOffset} , + byteCodeAddressLo = \txTo \low _{i + \locTxInitTransactionRowOffset} , + byteCodeDeploymentNumber = \accDepNumber \new _{i + \locTxInitRecipientAccountRowOffset} , + byteCodeDeploymentStatus = \accDepStatus \new _{i + \locTxInitRecipientAccountRowOffset} , + byteCodeCodeFragmentIndex = \accCfi _{i + \locTxInitRecipientAccountRowOffset} , + callerAddressHi = \txFrom \high _{i + \locTxInitTransactionRowOffset} , + callerAddressLo = \txFrom \low _{i + \locTxInitTransactionRowOffset} , + callValue = \txValue _{i + \locTxInitTransactionRowOffset} , + callDataContextNumber = \locTxInitCallDataContextNumber , + callDataOffset = 0 , + callDataSize = \txCallDataSize _{i + \locTxInitTransactionRowOffset} , + returnAtOffset = 0 , + returnAtCapacity = 0 , + } + % \initializeContext{\locTxInitContextRowOffset}_{i} + % \left[ \begin{array}{llr} + % \utt{context number:} & \cn\new _{i} \\ + % \utt{call stack depth:} & \rZero \\ + % \utt{is root:} & \rOne \\ + % \utt{is static:} & \rZero \\ + % \utt{account address high:} & \txTo \high _{i + \locTxInitTransactionRowOffset} \\ + % \utt{account address low:} & \txTo \low _{i + \locTxInitTransactionRowOffset} \\ + % \utt{account deployment number:} & \accDepNumber \new _{i + \locTxInitRecipientAccountRowOffset} \\ + % \utt{byte code address high:} & \txTo \high _{i + \locTxInitTransactionRowOffset} \\ + % \utt{byte code address low:} & \txTo \low _{i + \locTxInitTransactionRowOffset} \\ + % \utt{byte code deployment number:} & \accDepNumber \new _{i + \locTxInitRecipientAccountRowOffset} \\ + % \utt{byte code deployment status:} & \accDepStatus \new _{i + \locTxInitRecipientAccountRowOffset} \\ + % \utt{byte code code fragment index:} & \accCfi _{i + \locTxInitRecipientAccountRowOffset} \\ + % \utt{caller address high:} & \txFrom \high _{i + \locTxInitTransactionRowOffset} \\ + % \utt{caller address low:} & \txFrom \low _{i + \locTxInitTransactionRowOffset} \\ + % \utt{call value:} & \txValue _{i + \locTxInitTransactionRowOffset} \\ + % \utt{call data context number:} & \locTxInitCallDataContextNumber \\ + % \utt{call data offset:} & 0 \\ + % \utt{call data size:} & \txCallDataSize _{i + \locTxInitTransactionRowOffset} \\ + % \utt{return at offset:} & 0 \\ + % \utt{return at capacity:} & 0 \\ + % % \utt{returner context:} & \col{returnerCn} \\ + % % \utt{return data offset:} & \col{returnDataOffset} \\ + % % \utt{return data size:} & \col{returnDataSize} \\ + % \end{array} \right] + \] + \saNote{} Recall that $\cn\new _{i} = 1 + \hubStamp _{i}$, see section~(\ref{hub: generalities: context: context numbers}). + \item[\underline{\underline{Transaction-row n$^°~(\bm{i + \locTxInitTransactionRowOffset})$:}}] + we must justify certain predictions made by the \txnDataMod{} module: + \begin{description} + \item[\underline{(Partially) justifying \txRequiresEvmExecution{}:}] + we impose the following + \begin{enumerate} + \item $\txRequiresEvmExecution_{i + \locTxInitTransactionRowOffset} = \rOne$; + \item \If $\txIsDeployment _{i + \locTxInitTransactionRowOffset} = 0$ \Then $\accHasCode _{i + \locTxInitRecipientAccountRowOffset} = 1$ + \item \If $\txIsDeployment _{i + \locTxInitTransactionRowOffset} = 1$ \Then $\txInitCodeSize _{i + \locTxInitTransactionRowOffset} \neq 0$ (\trash) + \end{enumerate} + \item[\underline{Justifying $\txFinalRefundCounter$:}] + cannot be set at the moment; + \item[\underline{Justifying $\txInitialBalance$:}] + we impose that $\txInitialBalance _{i + \locTxInitTransactionRowOffset} = \accBalance _{i + \locTxInitSenderAccountRowOffset}$ + \item[\underline{Justifying \txStatusCode{}:}] + cannot be set at the moment\footnote{We \textbf{could} actually set the status code of the transaction at the present time: + \[ \txStatusCode _{i + \locTxInitTransactionRowOffset} = 1 - \cnWillRev _{i + \locTxInitTransactionRowOffset + 1} ~ (\trash) \]}; + \item[\underline{Justifying \txNonce{}:}] + we impose $\accNonce_{i + \locTxInitSenderAccountRowOffset} = \txNonce_{i + \locTxInitTransactionRowOffset}$; + \item[\underline{Justifying $\txLeftoverGas$:}] + cannot be set at the moment; + \end{description} + \item[\underline{\underline{Initializing some context variables:}}] + we impose + \[ + \firstRowOfNewContext {i}{\locTxInitTransactionRowOffset + 1} + \left[ \begin{array}{llr} + \utt{Next caller context number:} & 0 \\ + \utt{Next code fragment index:} & \accCfi _{i + \locTxInitRecipientAccountRowOffset} \\ + \utt{Available gas in new frame:} & \txInitialGas _{i + \locTxInitTransactionRowOffset} \\ + \end{array} \right] + \] +\end{description} diff --git a/hub/tx_init/peeking.tex b/hub/tx_init/peeking.tex new file mode 100644 index 0000000..5ae0ee2 --- /dev/null +++ b/hub/tx_init/peeking.tex @@ -0,0 +1,26 @@ +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\txInit_{i - 1} = 0$ and $\txInit_{i} = 1$.}} +\end{center} +In other words we assume row $i$ is the first row of the initialization phase. +This phase peeks into +(\emph{a}) the \texttt{from} account +(\emph{b}) the \texttt{to} account +(\emph{c}) it may transfer transaction call data to \textsc{ram} under the context number $\hubStamp_{i}$ +(\emph{d}) it then \emph{defines} context data +(\emph{e}) and then peeks into transaction data. +This is ensured by the following constraint: +\[ + \left[ \begin{array}{l} + + \peekAccount _{i + \locTxInitSenderAccountRowOffset } \\ + + \peekAccount _{i + \locTxInitRecipientAccountRowOffset} \\ + + \peekMisc _{i + \locTxInitMiscRowOffset } \\ + + \peekContext _{i + \locTxInitContextRowOffset } \\ + + \peekTransaction _{i + \locTxInitTransactionRowOffset } \\ + \end{array} \right] = + \nsrTransactionInitializationPhase +\] +\saNote{} Given the heartbeat constraints, the above has several \emph{implicit} consequences\footnote{which the implemenation need \textbf{not} enforce through new constraints}. The following are some of them. +\begin{itemize} + \item $\batchNum_{j}$, $\txNum_{j}$, $\hubStamp_{j}$, $\txSkip_{j}$ remain constant on the rows $i \leq j < i + \nsrTransactionInitializationPhase$; + \item $\txExec_{i + \nsrTransactionInitializationPhase} = 1$ and $\hubStamp_{i + \nsrTransactionInitializationPhase} = 1 + \hubStamp_{i}$; +\end{itemize} diff --git a/hub/tx_prewarm/_inputs.tex b/hub/tx_prewarm/_inputs.tex new file mode 100644 index 0000000..45fa542 --- /dev/null +++ b/hub/tx_prewarm/_inputs.tex @@ -0,0 +1,3 @@ +\section{Prewarming phase \lispDone{}} +\subsection{Introduction \lispDone{}} \label{hub: prewarming phase: intro} \input{tx_prewarm/intro} +\subsection{Constraints \lispDone{}} \label{hub: prewarming phase: constraints} \input{tx_prewarm/constraints} diff --git a/hub/tx_prewarm/constraints.tex b/hub/tx_prewarm/constraints.tex new file mode 100644 index 0000000..e028a85 --- /dev/null +++ b/hub/tx_prewarm/constraints.tex @@ -0,0 +1,85 @@ +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\txWarm_{i} = 1$.}} +\end{center} +We impose the following: +\begin{enumerate} + \item the following constraints hold unconditionally: + \[ + \left\{ \begin{array}{l} + \peekAccount_{i} + \peekStorage_{i} = 1 \\ + \standardDomSubStamps { + anchorRow = i, + relOffset = 0, + domOffset = 0, + } + % \standardDomSubStamps {i}{0}{0} + \end{array} \right. + \] + i.e. pre-warming-rows either peek into accounts or storage and we apply the standard $\domStamp/\subStamp$ pattern; + \item \If $\txWarm _{i - 1} = 0$ \Then $\peekAccount _{i} = 1$ + \item \If \Big($\txWarm _{i - 1} = 1$ \et $\peekStorage _{i} = 1$\Big) \Then + \begin{enumerate} + \item \If $\peekAccount _{i - 1} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stoAddressHi _{i} & \define & \accAddressHi _{i - 1} \\ + \stoAddressHi _{i} & \define & \accAddressLo _{i - 1} \\ + \stoDeploymentNumber _{i} & \define & \accDepNumber _{i - 1} \\ + \end{array} \right. + \] + \item \If $\peekStorage _{i - 1} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \stoAddressHi _{i} & \define & \stoAddressHi _{i - 1} \\ + \stoAddressHi _{i} & \define & \stoAddressHi _{i - 1} \\ + \stoDeploymentNumber _{i} & \define & \stoDeploymentNumber _{i - 1} \\ + \end{array} \right. + \] + \end{enumerate} + \item \If $\peekAccount_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accTrimAddress + {i}{0} + {\accAddressHi_{i}} + {\accAddressLo_{i}}} & \quad (\trash) \\ + \multicolumn{3}{l}{\accSameBalance {i}{0}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{0}} \\ + \multicolumn{3}{l}{\accSameCode {i}{0}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{0}} \\ + \multicolumn{3}{l}{\accTurnOnWarmth {i}{0}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{0}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = 0, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{0}{0} } & \quad (\trash) \\ + \end{array} \right. + \] + \saNote{} + Every first occurrence of an address will be trimmed in order to detect precompiles, see section~(\ref{hub: consistencies: account: constraints}). + Furthermore the \rlpTxnMod{} already produces addresses that are trimmed ($\addr\high \in \mathbb{B}_{4}$) and so one might wonder why the arithmetization enforces trimming. + In the above the purpose isn't the trimming of incoming addresses \emph{per se}. + Rather the above allows us to set \accTrmRawAddrHi{} to the expected value in case the above is the first time the address undergoes trimming. + Strictly speaking this isn't necessary. + \item \If $\peekStorage_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lr} + \storageReading {i}{0} \\ + \stoTurnOnWarmth {i}{0} \\ + \standardDomSubStamps { + anchorRow = i, + relOffset = 0, + domOffset = 0, + } + % \standardDomSubStamps {i}{0}{0} & \quad (\trash) \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{} +The above is compatible with both (pathological) cases where either +an account address is included more than once in the access set or +a storage key of a particular account is included more than once in the access set. diff --git a/hub/tx_prewarm/intro.tex b/hub/tx_prewarm/intro.tex new file mode 100644 index 0000000..45dd6c2 --- /dev/null +++ b/hub/tx_prewarm/intro.tex @@ -0,0 +1,13 @@ +Recall that \textbf{type 1} and \textbf{type 2} transactions provide (potentially empty) \textbf{accessList}'s, see section~(\ref{rlp_txn: phase constraints: access list: intro}). +The purpose of the ``\textbf{pre-warming}'' phase of transaction processing is to perform the associated pre-warming of addresses and storage keys from the access list \textbf{if present} and \textbf{as required}. +That is to say for transactions that +(\emph{a}) come with an \textbf{accessList} and +(\emph{b}) require \evm{} execution, see section~(\ref{txn_data: constraints: specialized computations}). + +The structure of these pre-warming operations is simple. +Every access list item $E \equiv (E_\text{a}, E_\textbf{s})$, see section~(\ref{rlp_txn: phase constraints: access list: intro}), contains an address $E_\text{a}$. +The first operation is thus to pre-warm said address on a dedicated \textbf{address-row}. +At that point in time we are further able to retrieve the currently valid deployment number for said address. +The following field in the access list item is a (possibly empty) list of storage keys $E_\textbf{s}$ of storage keys. +When that list is nonempty the next step is to pre-warm the storage keys from $E_\textbf{s}$ on as many storage rows as. +This requires us to know the currently valid deployment number, which we have access to by the above. diff --git a/hub/tx_prewarm/lua/layout.lua.tex b/hub/tx_prewarm/lua/layout.lua.tex new file mode 100644 index 0000000..b2c2c87 --- /dev/null +++ b/hub/tx_prewarm/lua/layout.lua.tex @@ -0,0 +1,21 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +| HUB_STAMP | +\end{verbatim} +\end{document} diff --git a/hub/tx_skip/_inputs.tex b/hub/tx_skip/_inputs.tex new file mode 100644 index 0000000..87cae81 --- /dev/null +++ b/hub/tx_skip/_inputs.tex @@ -0,0 +1,5 @@ +\input{tx_skip/_local} +\section{Transactions which skip \evm{} execution \lispDone{}} +\subsection{Introduction} \label{hub: tx skip: intro} \input{tx_skip/intro} +\subsection{Setting the peeking flags \lispDone{}} \label{hub: tx skip: setting peeking flags} \input{tx_skip/peek} +\subsection{Common constraints \lispDone{}} \label{hub: tx skip: common} \input{tx_skip/common} diff --git a/hub/tx_skip/_local.tex b/hub/tx_skip/_local.tex new file mode 100644 index 0000000..fc5b430 --- /dev/null +++ b/hub/tx_skip/_local.tex @@ -0,0 +1,8 @@ +\def\locTxSkipSenderAccountRowOffset {\yellowm{0}} +\def\locTxSkipRecipientAccountRowOffset {\yellowm{1}} +\def\locTxSkipCoinbaseAccountRowOffset {\yellowm{2}} +\def\locTxSkipTransactionRowOffset {\orangem{3}} + +\def\locWeiCost {\col{wei\_cost}} +\def\locCoinbaseFee {\col{coinbase\_fee}} +\def\locTxSkipIsTrivialDeployment {\col{deployment}} diff --git a/hub/tx_skip/common.tex b/hub/tx_skip/common.tex new file mode 100644 index 0000000..7c6adf6 --- /dev/null +++ b/hub/tx_skip/common.tex @@ -0,0 +1,216 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption that + \( + \begin{cases} + \hubStamp_{i - 1} \neq \hubStamp_{i} \\ + \txSkip_{i} = 1 \\ + \end{cases} + \)}} +\end{center} +We now populate the rows of the initialization phase. +\begin{description} + \item[\underline{\underline{Sender account-row n$^°~\bm{(i + \locTxSkipSenderAccountRowOffset)}$:}}] + the first row peeks into the sender account: + \[ + \left\{ \begin{array}{lclr} + \accAddress \high _{i + \locTxSkipSenderAccountRowOffset} & = & \txFrom \high _{i + \locTxSkipTransactionRowOffset} \\ + \accAddress \low _{i + \locTxSkipSenderAccountRowOffset} & = & \txFrom \low _{i + \locTxSkipTransactionRowOffset} \vspace{2mm} \\ + \multicolumn{3}{l}{\accDecrementBalance {i}{\locTxSkipSenderAccountRowOffset}{\locWeiCost}} \\ + \multicolumn{3}{l}{\accIncrementNonce {i}{\locTxSkipSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxSkipSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxSkipSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxSkipSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxSkipSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{\accIsntPrecompile {i}{\locTxSkipSenderAccountRowOffset}} & (\trash) \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxSkipSenderAccountRowOffset, + domOffset = 0, + } + } \\ + % \standardDomSubStamps {i}{\locTxSkipSenderAccountRowOffset}{0} } \\ + \end{array} \right. + \] + where + \[ + \locWeiCost \define + \left[ \begin{array}{cr} + + & \txValue_{i + \locTxSkipTransactionRowOffset} \\ + + & \txGasPrice_{i + \locTxSkipTransactionRowOffset} \cdot \big( \txGasLimit_{i + \locTxSkipTransactionRowOffset} - \txInitialGas_{i + \locTxSkipTransactionRowOffset} \big) \\ + \end{array} \right] + \] + \item[\underline{\underline{Recipient account-row n$^°~\bm{(i + \locTxSkipRecipientAccountRowOffset)}$:}}] + The second row peeks into the recipient account: + \[ + \left\{ \begin{array}{lcl} + \accAddress \high _{i + \locTxSkipRecipientAccountRowOffset} & = & \txTo \high _{i + \locTxSkipTransactionRowOffset} \\ + \accAddress \low _{i + \locTxSkipRecipientAccountRowOffset} & = & \txTo \low _{i + \locTxSkipTransactionRowOffset} \vspace{2mm} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxSkipRecipientAccountRowOffset}{\txValue_{i + \locTxSkipTransactionRowOffset}}} \\ + % \multicolumn{3}{l}{\accSameNonce {i}{\locTxSkipRecipientAccountRowOffset}} \\ + % \multicolumn{3}{l}{\accSameCode {i}{\locTxSkipRecipientAccountRowOffset}} \\ + % \multicolumn{3}{l}{\accSameDeployment {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \texttt{Nonce:} & \multicolumn{2}{l}{\valueToBeSet} \\ + \texttt{Code:} & \multicolumn{2}{l}{\valueToBeSet} \\ + \texttt{Deployment:} & \multicolumn{2}{l}{\valueToBeSet} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accIsntPrecompile {i}{\locTxSkipSenderAccountRowOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxSkipRecipientAccountRowOffset, + domOffset = 1, + } + } \\ + % \standardDomSubStamps {i}{\locTxSkipRecipientAccountRowOffset}{1} } \\ + \end{array} \right. + \] + In order to correctly update the recipient account one must distinguish between message call transactions (e.g. pure transfers) and (trivial) deployments. + For that purpose we introduce the following shorthand + \[ + \locTxSkipIsTrivialDeployment \define \txIsDeployment _{i + \locTxSkipTransactionRowOffset} + \] + and set + \begin{description} + \item[\underline{Pure transfers:}] + \If $\locTxSkipIsTrivialDeployment = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\accSameNonce {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \end{array} \right. + \] + \item[\underline{Trivial deployments:}] + \If $\locTxSkipIsTrivialDeployment = 1$ \Then + \begin{description} + \item[Nonce:] + we impose + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accIncrementNonce {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \accNonce_{i + \locTxSkipRecipientAccountRowOffset} & = & 0 & (\trash) \vspace{2mm} \\ + \end{array} \right. + \] + \item[Code:] + we impose + \[ + \left\{ \begin{array}{lclr} + \accHasCode _{i + \locTxSkipRecipientAccountRowOffset} & = & 0 & (\trash) \\ + \accCodehashHi _{i + \locTxSkipRecipientAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo _{i + \locTxSkipRecipientAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \accCodesize _{i + \locTxSkipRecipientAccountRowOffset} & = & 0 & (\trash) \\ + \end{array} \right. + \;\text{and}\; + \left\{ \begin{array}{lclr} + \accHasCode \new _{i + \locTxSkipRecipientAccountRowOffset} & = & 0 \\ + \accCodehashHi \new _{i + \locTxSkipRecipientAccountRowOffset} & = & \emptyKeccakHi & (\trash) \\ + \accCodehashLo \new _{i + \locTxSkipRecipientAccountRowOffset} & = & \emptyKeccakLo & (\trash) \\ + \accCodesize \new _{i + \locTxSkipRecipientAccountRowOffset} & = & \txInitCodeSize _{i + \locTxSkipTransactionRowOffset} \\ + \end{array} \right. + \] + \item[Deployment:] + we impose + \[ + \left\{ \begin{array}{lclr} + \multicolumn{3}{l}{\accIncrementDeploymentNumber {i}{\locTxSkipRecipientAccountRowOffset}} \\ + \accDepStatus _{i + \locTxSkipRecipientAccountRowOffset} & = & 0 & (\trash) \\ + \accDepStatus\new _{i + \locTxSkipRecipientAccountRowOffset} & = & 0 \\ + \end{array} \right. + \] + \saNote{} As no deployment phase (in the sense of: execution of initialization code) will happen given that the transaction provided initialization code is empty we directly skip to the "deployed status" of the account through $\accDepStatus\new \equiv 0$. + \end{description} + \end{description} + we further impose + \begin{description} + \item[\underline{Address trimming:}] + \If $\locTxSkipIsTrivialDeployment = 0$ + \[ + \accTrimAddress + {i}{\locTxSkipRecipientAccountRowOffset} + {\txTo \high _{i + \locTxSkipTransactionRowOffset}} + {\txTo \low _{i + \locTxSkipTransactionRowOffset}} + \] + \end{description} + \saNote{} + Let us provide context for the above: + \begin{itemize} + \item + setting the \accTrmFlag{} enforces the computation (in the \trmMod{} module) of the \accTrmIsPrecompile{} flag; + \item + we already required $\accIsntPrecompile {i}{\locTxSkipRecipientAccountRowOffset}$; + this \textbf{disallows message call transactions to precompiles}\label{warning: no message calls to precompiles}; + \end{itemize} + \item[\underline{\underline{Coinbase account-row n$^°~\bm{(i + \locTxSkipCoinbaseAccountRowOffset)}$:}}] + \[ + \left\{ \begin{array}{lcl} + \accAddress \high _{i + \locTxSkipCoinbaseAccountRowOffset} & = & \txCoinbase \high _{i + \locTxSkipTransactionRowOffset} \\ + \accAddress \low _{i + \locTxSkipCoinbaseAccountRowOffset} & = & \txCoinbase \low _{i + \locTxSkipTransactionRowOffset} \vspace{2mm} \\ + \multicolumn{3}{l}{\accIncrementBalance {i}{\locTxSkipCoinbaseAccountRowOffset}{\locCoinbaseFee}} \\ + \multicolumn{3}{l}{\accSameNonce {i}{\locTxSkipCoinbaseAccountRowOffset} } \\ + \multicolumn{3}{l}{\accSameCode {i}{\locTxSkipCoinbaseAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameDeployment {i}{\locTxSkipCoinbaseAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameWarmth {i}{\locTxSkipCoinbaseAccountRowOffset}} \\ + \multicolumn{3}{l}{\accSameMarkedForSelfdestructFlag {i}{\locTxSkipCoinbaseAccountRowOffset}} \\ + \multicolumn{3}{l}{ + \standardDomSubStamps { + anchorRow = i, + relOffset = \locTxSkipCoinbaseAccountRowOffset, + domOffset = 2, + } + } \\ + % \standardDomSubStamps {i}{\locTxSkipCoinbaseAccountRowOffset}{2}} \\ + \end{array} \right. + \] + where we define the \locCoinbaseFee{} shorthand as follows: + \[ + \locCoinbaseFee \define + \left[ \begin{array}{cl} + \cdot & \txPriorityFeePerGas_{i + \locTxSkipTransactionRowOffset} \\ + \cdot & (\txGasLimit_{i + \locTxSkipTransactionRowOffset} - \txEffectiveRefund_{i + \locTxSkipTransactionRowOffset}) \\ + \end{array} \right] + \] + % \begin{enumerate} + % \item \If $\txIsTypeTwo_{i + \locTxSkipTransactionRowOffset} = 0$ \Then + % \[ + % \locCoinbaseFee \define + % \left[ \begin{array}{cl} + % \cdot & \txGasPrice_{i + \locTxSkipTransactionRowOffset} \\ + % \cdot & (\txGasLimit_{i + \locTxSkipTransactionRowOffset} - \txEffectiveRefund_{i + \locTxSkipTransactionRowOffset}) \\ + % \end{array} \right] + % \] + % \item \If $\txIsTypeTwo_{i + \locTxSkipTransactionRowOffset} = 1$ \Then + % \[ + % \locCoinbaseFee \define + % \left[ \begin{array}{cl} + % \cdot & (\txGasPrice_{i + \locTxSkipTransactionRowOffset} - \txBasefee_{i + \locTxSkipTransactionRowOffset}) \\ + % \cdot & (\txGasLimit_{i + \locTxSkipTransactionRowOffset} - \txEffectiveRefund_{i + \locTxSkipTransactionRowOffset}) \\ + % \end{array} \right] + % \] + % \end{enumerate} + \item[\underline{\underline{Transaction-row n$^°~(\bm{i + \locTxSkipTransactionRowOffset})$:}}] + the fourth row peeks into transaction data and justifies transaction data + \begin{description} + \item[\underline{(Partially) justifying \txRequiresEvmExecution{}:}] + we impose the following + \begin{enumerate} + \item $\txRequiresEvmExecution_{i + \locTxSkipTransactionRowOffset} = \rZero$; + \item \If $\txIsDeployment _{i + \locTxSkipTransactionRowOffset} = 0$ \Then $\accHasCode _{i + \locTxSkipRecipientAccountRowOffset} = 0$ + \item \If $\txIsDeployment _{i + \locTxSkipTransactionRowOffset} = 1$ \Then $\txInitCodeSize _{i + \locTxSkipTransactionRowOffset} = 0$ + \end{enumerate} + \item[\underline{Justifying $\txFinalRefundCounter$:}] + we impose that $\txFinalRefundCounter _{i + \locTxSkipTransactionRowOffset} = 0$ + \item[\underline{Justifying $\txInitialBalance$:}] + we impose that $\txInitialBalance _{i + \locTxSkipTransactionRowOffset} = \accBalance _{i + \locTxSkipSenderAccountRowOffset}$ + \item[\underline{Justifying \txStatusCode{}:}] + we impose that $\txStatusCode _{i + \locTxSkipTransactionRowOffset} = 1$ + \item[\underline{Justifying \txNonce{}:}] + we impose $\accNonce_{i + \locTxSkipSenderAccountRowOffset} = \txNonce_{i + \locTxSkipTransactionRowOffset}$; + \item[\underline{Justifying $\txLeftoverGas$:}] + we impose that $\txLeftoverGas _{i + \locTxSkipTransactionRowOffset} = \txInitialGas _{i + \locTxSkipTransactionRowOffset}$ + \item[\underline{(Optional) justifying $\txEffectiveRefund$:}] + we may optionnally impose + \[ \txEffectiveRefund _{i + \locTxSkipTransactionRowOffset} = \txLeftoverGas _{i + \locTxSkipTransactionRowOffset} \quad (\trash) \] + \end{description} +\end{description} diff --git a/hub/tx_skip/intro.tex b/hub/tx_skip/intro.tex new file mode 100644 index 0000000..9146e30 --- /dev/null +++ b/hub/tx_skip/intro.tex @@ -0,0 +1,6 @@ +In the present section we deal with transactions that don't require \textsc{evm}-execution to process. Recall that these are of two types: +\begin{enumerate} + \item message calls to addresses with empty code; + \item deployment transactions with empty initialization code; +\end{enumerate} +\saNote{} Our \textsc{zk-evm} disallows transactions which are message calls to precompiles (i.e. transactions with $T_\text{t} \in \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$.) See \ref{warning: no message calls to precompiles}. \ No newline at end of file diff --git a/hub/tx_skip/peek.tex b/hub/tx_skip/peek.tex new file mode 100644 index 0000000..5342e24 --- /dev/null +++ b/hub/tx_skip/peek.tex @@ -0,0 +1,29 @@ +\begin{center} + \boxed{\text{All constraints in this section are written under the assumption that + \( + \begin{cases} + \hubStamp_{i-1} \neq \hubStamp_{i} \\ + \txSkip_{i} = 1 \\ + \end{cases} + \)}} +\end{center} +In other words: row $i$ marks the beginning of the processing of a new transaction which (supposedly) requires no \textsc{evm}-execution. We impose the views over the next rows: +\begin{enumerate} + \item The following rows (in which we include the present row with index $i$) peek into account data and finally peek into transaction data: + \[ + \left[ \begin{array}{cl} + + & \peekAccount _{i + \locTxSkipSenderAccountRowOffset } \\ + + & \peekAccount _{i + \locTxSkipRecipientAccountRowOffset } \\ + + & \peekAccount _{i + \locTxSkipCoinbaseAccountRowOffset } \\ + + & \peekTransaction _{i + \locTxSkipTransactionRowOffset } \\ + \end{array} \right] + = + \nsrTransactionSkippingPhase. + \] +\end{enumerate} +% \saNote{} The above enforces (through other constraints) that $\batchNum_{j}$, $\txNum_{j}$, $\hubStamp_{j}$ and $\txSkip_{j}$ (for $i\leq j \leq i+3$) remain constant throughout; furthermore, if the trace contains an $(i+4)$-th row, then at that row the pair $\big[ \batchNum, \txNum \big]$ changes and $\hubStamp$ jumps by $1$. +\saNote{} Given the heartbeat constraints, the above has several \emph{implicit} consequences\footnote{which the implemenation need \textbf{not} enforce through new constraints}. The following are some of them: +\begin{itemize} + \item $\batchNum_{j}$, $\txNum_{j}$, $\hubStamp_{j}$, $\txSkip_{j}$ remain constant on the rows $i \leq j < i + 4$; + \item $\hubStamp_{i + 4} = 1 + \hubStamp_{i}$; +\end{itemize} diff --git a/img/Fichier_000(3).png b/img/Fichier_000(3).png new file mode 100644 index 0000000..13c3e1d Binary files /dev/null and b/img/Fichier_000(3).png differ diff --git a/img/MODEXP_call_data_does_not_run_out.png b/img/MODEXP_call_data_does_not_run_out.png new file mode 100644 index 0000000..cb48916 Binary files /dev/null and b/img/MODEXP_call_data_does_not_run_out.png differ diff --git a/img/MODEXP_call_data_does_run_out.png b/img/MODEXP_call_data_does_run_out.png new file mode 100644 index 0000000..08869bf Binary files /dev/null and b/img/MODEXP_call_data_does_run_out.png differ diff --git a/img/MODEXP_data_transfers.png b/img/MODEXP_data_transfers.png new file mode 100644 index 0000000..9e06f5a Binary files /dev/null and b/img/MODEXP_data_transfers.png differ diff --git a/img/full_exo_from_ram.jpg b/img/full_exo_from_ram.jpg new file mode 100644 index 0000000..9c211ed Binary files /dev/null and b/img/full_exo_from_ram.jpg differ diff --git a/img/full_exo_to_ram.jpg b/img/full_exo_to_ram.jpg new file mode 100644 index 0000000..8a88217 Binary files /dev/null and b/img/full_exo_to_ram.jpg differ diff --git a/img/full_one_to_two.jpg b/img/full_one_to_two.jpg new file mode 100644 index 0000000..4dcb8d1 Binary files /dev/null and b/img/full_one_to_two.jpg differ diff --git a/img/partial_duo.jpg b/img/partial_duo.jpg new file mode 100644 index 0000000..6dbcedb Binary files /dev/null and b/img/partial_duo.jpg differ diff --git a/img/partial_duo_old.jpg b/img/partial_duo_old.jpg new file mode 100644 index 0000000..83df467 Binary files /dev/null and b/img/partial_duo_old.jpg differ diff --git a/img/partial_mono.jpg b/img/partial_mono.jpg new file mode 100644 index 0000000..ba60041 Binary files /dev/null and b/img/partial_mono.jpg differ diff --git a/img/prefix_trailing_zeros_duo.jpg b/img/prefix_trailing_zeros_duo.jpg new file mode 100644 index 0000000..ba8b695 Binary files /dev/null and b/img/prefix_trailing_zeros_duo.jpg differ diff --git a/img/prefix_trailing_zeros_mono.jpg b/img/prefix_trailing_zeros_mono.jpg new file mode 100644 index 0000000..71b5f38 Binary files /dev/null and b/img/prefix_trailing_zeros_mono.jpg differ diff --git a/img/ram_ram.jpg b/img/ram_ram.jpg new file mode 100644 index 0000000..45bb399 Binary files /dev/null and b/img/ram_ram.jpg differ diff --git a/img/read_from_ram.jpg b/img/read_from_ram.jpg new file mode 100644 index 0000000..a72ff12 Binary files /dev/null and b/img/read_from_ram.jpg differ diff --git a/img/surgeries_1.jpg b/img/surgeries_1.jpg new file mode 100644 index 0000000..d86caae Binary files /dev/null and b/img/surgeries_1.jpg differ diff --git a/img/surgeries_2.jpg b/img/surgeries_2.jpg new file mode 100644 index 0000000..b69f196 Binary files /dev/null and b/img/surgeries_2.jpg differ diff --git a/img/surgeries_2_old.jpg b/img/surgeries_2_old.jpg new file mode 100644 index 0000000..c93d3f2 Binary files /dev/null and b/img/surgeries_2_old.jpg differ diff --git a/img/workflow_Maxwell's_equations.jpg b/img/workflow_Maxwell's_equations.jpg new file mode 100644 index 0000000..8c1a814 Binary files /dev/null and b/img/workflow_Maxwell's_equations.jpg differ diff --git a/img/write_to_ram.jpg b/img/write_to_ram.jpg new file mode 100644 index 0000000..1d65514 Binary files /dev/null and b/img/write_to_ram.jpg differ diff --git a/img/zkevm_better_arrow_heads.png b/img/zkevm_better_arrow_heads.png new file mode 100644 index 0000000..8bd6725 Binary files /dev/null and b/img/zkevm_better_arrow_heads.png differ diff --git a/img/zkevm_better_arrows.png b/img/zkevm_better_arrows.png new file mode 100644 index 0000000..60fb1b5 Binary files /dev/null and b/img/zkevm_better_arrows.png differ diff --git a/img/zkevm_better_arrows_3.png b/img/zkevm_better_arrows_3.png new file mode 100644 index 0000000..2ce0367 Binary files /dev/null and b/img/zkevm_better_arrows_3.png differ diff --git a/img/zkevm_better_arrows_color.png b/img/zkevm_better_arrows_color.png new file mode 100644 index 0000000..f06f4c8 Binary files /dev/null and b/img/zkevm_better_arrows_color.png differ diff --git a/img/zkevm_diagram.png b/img/zkevm_diagram.png new file mode 100644 index 0000000..785435a Binary files /dev/null and b/img/zkevm_diagram.png differ diff --git a/lex/_all_lex.tex b/lex/_all_lex.tex new file mode 100644 index 0000000..c1900d0 --- /dev/null +++ b/lex/_all_lex.tex @@ -0,0 +1,44 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/lex} +\usepackage{../pkg/shifting} + +\title{Lexicographic ordering constraints} +\author{Rollup team} +\date{October 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\renewcommand{\arraystretch}{1.3} + +\input{_inputs} + +\end{document} diff --git a/lex/_inputs.tex b/lex/_inputs.tex new file mode 100644 index 0000000..6d2fdef --- /dev/null +++ b/lex/_inputs.tex @@ -0,0 +1,4 @@ +\section{Lexicographic orders and associated constraint systems} +\subsection{Introduction} \input{intro} +\subsection{Lexicographic orders} \input{order} +\subsection{Lexicographic ordering constraints} \input{lex} diff --git a/lex/intro.tex b/lex/intro.tex new file mode 100644 index 0000000..d5843ab --- /dev/null +++ b/lex/intro.tex @@ -0,0 +1,57 @@ +The present section provides an explanation of lexicographic ordering constraints and their necessity. Such constraints are ubiquitous throughout the \zkEvm{} specification: they are fused in consistency constraints involving a permutation argument and at other times to ensure uniqueness of data where the columns being ordered serve as a kind of generalized ``stamp''. we illustrate both use cases below. + +One often considers a row permutation $\col{X}\rightsquigarrow \order{\col{X}} =: \col{Y}$\footnote{Where $\col{X}, \col{Y}$ are column vectors with $n$ rows for some $n$ and there exists a permutation $\sigma\in\mathfrak{S}_n$ such that $\col{Y}_i = \col{X}_{\sigma^{-1}(i)}$ for all $0\leq i < n$.} defined\footnote{typically, non uniquely} in terms of its effect on a fixed set of columns $\lex^{1},\dots,\lex^{q}$. Generally the desired effect is that (after row permutation) the rows of $\order{\lex^{1}},\dots,\order{\lex^{q}}$ are listed according to some pre-specified lexicographic order. Whenever such permutations are applied the set of constraints presented in this section is implicitly applied, generally the weak kind of lexicographic consraints which allows for repetitions. The columns that are required to make the argument function are generally omitted from the columns section of the module specification. + +The other prominent usecase for (strong) lexicographic ordering is to ensure uniqueness of data which is identified by a multi-column label, as opposed to a single stamp column that grows monotonically with increments of $1$. An example thereof appears in the \romMod{} where code fragments (either initialization code or deployed code) are identified by an address (which occupies two columns: high and low part), a deployment number and a deployment status. + +\saNote{} This section will present \emph{strict} and \emph{weak} lexicographic ordering constraints + +\saNote{} In the present module we directly work with supposedly reordered columns. The column names from here on out are therefore $\ord^k$ rather than, say, $\order{\lex^{k}}$. + +\begin{figure} +\centering +\[ +\def\colS{LimeGreen} +\def\colL{RoyalBlue} +\def\lightgray{gray} +\begin{array}{|c|c|c|c|} +\hline +\lex^{1} & \lex^{2} & \cdots & \lex^{q} \\ \hline +\cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} \\ \hline +\cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} \\ \hline +\cellcolor{\colL!16!\colS} & \cellcolor{\colL!16!\colS} & \cellcolor{\colL!16!\colS} \cdots & \cellcolor{\colL!16!\colS} \\ \hline +\cellcolor{\colL!91!\colS} & \cellcolor{\colL!91!\colS} & \cellcolor{\colL!91!\colS} \cdots & \cellcolor{\colL!91!\colS} \\ \hline +\cellcolor{\colL!50!\colS} & \cellcolor{\colL!50!\colS} & \cellcolor{\colL!50!\colS} \cdots & \cellcolor{\colL!50!\colS} \\ \hline +\cellcolor{\colL!83!\colS} & \cellcolor{\colL!83!\colS} & \cellcolor{\colL!83!\colS} \cdots & \cellcolor{\colL!83!\colS} \\ \hline +\cellcolor{\colL!8!\colS} & \cellcolor{\colL!8!\colS} & \cellcolor{\colL!8!\colS} \cdots & \cellcolor{\colL!8!\colS} \\ \hline +\cellcolor{\colL!66!\colS} & \cellcolor{\colL!66!\colS} & \cellcolor{\colL!66!\colS} \cdots & \cellcolor{\colL!66!\colS} \\ \hline +\cellcolor{\colL!41!\colS} & \cellcolor{\colL!41!\colS} & \cellcolor{\colL!41!\colS} \cdots & \cellcolor{\colL!41!\colS} \\ \hline +\cellcolor{\colL!100!\colS} & \cellcolor{\colL!100!\colS} & \cellcolor{\colL!100!\colS} \cdots & \cellcolor{\colL!100!\colS} \\ \hline +\cellcolor{\colL!25!\colS} & \cellcolor{\colL!25!\colS} & \cellcolor{\colL!25!\colS} \cdots & \cellcolor{\colL!25!\colS} \\ \hline +\cellcolor{\colL!75!\colS} & \cellcolor{\colL!75!\colS} & \cellcolor{\colL!75!\colS} \cdots & \cellcolor{\colL!75!\colS} \\ \hline +\cellcolor{\colL!58!\colS} & \cellcolor{\colL!58!\colS} & \cellcolor{\colL!58!\colS} \cdots & \cellcolor{\colL!58!\colS} \\ \hline +\cellcolor{\colL!33!\colS} & \cellcolor{\colL!33!\colS} & \cellcolor{\colL!33!\colS} \cdots & \cellcolor{\colL!33!\colS} \\ \hline +\end{array} +\qquad\rightsquigarrow\qquad +\begin{array}{|c|c|c|c|} +\hline +\order{\lex^{1}} & \order{\lex^{2}} & \cdots & \order{\lex^{q}} \\ \hline +\cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} \\ \hline +\cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} & \cellcolor{\lightgray} \\ \hline +\cellcolor{\colL!8!\colS} & \cellcolor{\colL!8!\colS} & \cellcolor{\colL!8!\colS} \cdots & \cellcolor{\colL!8!\colS} \\ \hline +\cellcolor{\colL!16!\colS} & \cellcolor{\colL!16!\colS} & \cellcolor{\colL!16!\colS} \cdots & \cellcolor{\colL!16!\colS} \\ \hline +\cellcolor{\colL!25!\colS} & \cellcolor{\colL!25!\colS} & \cellcolor{\colL!25!\colS} \cdots & \cellcolor{\colL!25!\colS} \\ \hline +\cellcolor{\colL!33!\colS} & \cellcolor{\colL!33!\colS} & \cellcolor{\colL!33!\colS} \cdots & \cellcolor{\colL!33!\colS} \\ \hline +\cellcolor{\colL!41!\colS} & \cellcolor{\colL!41!\colS} & \cellcolor{\colL!41!\colS} \cdots & \cellcolor{\colL!41!\colS} \\ \hline +\cellcolor{\colL!50!\colS} & \cellcolor{\colL!50!\colS} & \cellcolor{\colL!50!\colS} \cdots & \cellcolor{\colL!50!\colS} \\ \hline +\cellcolor{\colL!58!\colS} & \cellcolor{\colL!58!\colS} & \cellcolor{\colL!58!\colS} \cdots & \cellcolor{\colL!58!\colS} \\ \hline +\cellcolor{\colL!66!\colS} & \cellcolor{\colL!66!\colS} & \cellcolor{\colL!66!\colS} \cdots & \cellcolor{\colL!66!\colS} \\ \hline +\cellcolor{\colL!75!\colS} & \cellcolor{\colL!75!\colS} & \cellcolor{\colL!75!\colS} \cdots & \cellcolor{\colL!75!\colS} \\ \hline +\cellcolor{\colL!83!\colS} & \cellcolor{\colL!83!\colS} & \cellcolor{\colL!83!\colS} \cdots & \cellcolor{\colL!83!\colS} \\ \hline +\cellcolor{\colL!91!\colS} & \cellcolor{\colL!91!\colS} & \cellcolor{\colL!91!\colS} \cdots & \cellcolor{\colL!91!\colS} \\ \hline +\cellcolor{\colL!100!\colS} & \cellcolor{\colL!100!\colS} & \cellcolor{\colL!100!\colS} \cdots & \cellcolor{\colL!100!\colS} \\ \hline +\end{array} +\] + \caption{Row permutation enforcing \emph{some} lexicographic ordering on the rows of $\order{\lex^{1}}$, \dots, $\order{\lex^{q}}$. The gray rows may represent either padding rows to which the constraints may not apply or other rows that are excluded from the constraints by other means (e.g. through row selection.)} +% \label{} +\end{figure} diff --git a/lex/lex.tex b/lex/lex.tex new file mode 100644 index 0000000..7d2f876 --- /dev/null +++ b/lex/lex.tex @@ -0,0 +1,125 @@ +The present section describes two constraint systems: \weakLexConstraint{} and \strictLexConstraint{} which establishe, respectively, weak and strict versions of lexicographic ordering of the rows a collection of columns with respect to some fixed lexicographic order $\underset{\epsilon_\bullet}{\prec}$. We consider a module $\module$ containing the following: +\begin{itemize} + \item $\ord^1, \dots, \ord^p$: a family of $p\geq 2$ columns assumed to contain $\llarge$-byte integers; + \item $[\colm{@}_{1}], \dots, [\colm{@}_{p}], [\colm{Eq}]$: $p + 1$ many bit columns; + \item $\byteCol{$\llargeMO$},\dots,\byteCol{1},\byteCol{0}$: $\llarge$ many byte columns; +\end{itemize} +The constraint system will ensure that for $\ell \in \{1,\dots,p\}$, +\begin{IEEEeqnarray*}{RCL} + [\col{@}_\ell]_{i} = 1 + & \iff & + \begin{cases} + \ord^{k}_{i} = \ord^{k}_{i - 1}, \quad 1\leq k < \ell \\ + \If \epsilon_\ell = + ~ \Then \ord^{\ell}_{i} > \ord^{\ell}_{i - 1} \\ + \If \epsilon_\ell = - ~ \Then \ord^{\ell}_{i} < \ord^{\ell}_{i - 1} \\ + \end{cases} \\ + & \iff & + \begin{cases} + \sum_{0 \leq k < \ell}^{p} [\col{@}_k]_{i} = 0 \\ + \If \epsilon_\ell = + ~ \Then \ord^{\ell}_{i} > \ord^{\ell}_{i - 1} \\ + \If \epsilon_\ell = - ~ \Then \ord^{\ell}_{i} < \ord^{\ell}_{i - 1} \\ + \end{cases} \\ +\end{IEEEeqnarray*} +(where we set, for convenience, $[\col{@}_0] \equiv 0$) and +\begin{IEEEeqnarray*}{RCL} + [\col{Eq}]_{i} = 1 & \iff & \ord^{\ell}_{i} = \ord^{\ell}_{i - 1}, \quad 1\leq \ell \leq p \\ + & \iff & \sum_{\ell = 1}^{p} [\col{@}_\ell]_{i} = 0 \\ +\end{IEEEeqnarray*} +This is arithmetized as follows: +We subsume under the moniker +\[ + \weakLexConstraint + \left( + \begin{array}{c} + \ord^{1}, + \ord^{2}, + \dots, + \ord^{p} \\ + {[\col{@}_{1}]}, [\col{@}_{2}], \dots, [\col{@}_{p}], [\col{Eq}]; \\ + \byteCol{$\llargeMO$}, \dots, \byteCol{1}, \byteCol{0}; \\ + \end{array} + \right) +\] +the following collection of constraints where we write $\Delta \equiv \sum_{k=0}^{\llargeMO} 256^k \cdot \byteCol{k}$. +\begin{enumerate} + \item $[\col{@}_{1}]_{i} + \cdots + [\col{@}_{p}]_{i} + [\col{Eq}]_{i} = 1$ i.e. precisely one of these binary flags is on at any given time; + \item for $\ell = 1, \dots, p$ we ask that + \If $\sum_{k = 0}^{\ell-1} [\col{@}_{k}]_{i} \neq 1$ \Then + \begin{itemize} + \item \If $[\col{@}_{\ell}]_{i} = 1$ \Then $\ord^\ell_{i} \neq \ord^\ell_{i - 1}$, + \item \If $[\col{@}_{\ell}]_{i} = 0$ \Then $\ord^\ell_{i} = \ord^\ell_{i - 1}$; + \end{itemize} + where, for greater uniformity, we define $[\col{@}_0]$ to be the $0$ column. + \item \If $\col{Eq}_i = 0$ \Then + \[ + \begin{array}{lcl} + 1 + \Delta_{i} + & = & + \displaystyle + \phantom{+} \sum_{\substack{1\leq \ell \leq p\\\epsilon_\ell = +}} + [\col{@}_{\ell}]_{i} + \cdot + \Big( + \ord^\ell_{i} - \ord^\ell_{i - 1} + \Big) \\ + & & + \displaystyle + - + \sum_{\substack{1\leq \ell \leq p\\\epsilon_\ell = -}} + [\col{@}_{\ell}]_{i} + \cdot + \Big( + \ord^\ell_{i} - \ord^\ell_{i - 1} + \Big) + \end{array} + \] +\end{enumerate} +We similarly subsume under the moniker +\[ + \strictLexConstraint + \left( + \begin{array}{c} + \ord^{1}, + \ord^{2}, + \dots, + \ord^{p} \\ + {[\col{@}_{1}]}, [\col{@}_{2}], \dots, [\col{@}_{p}]; \\ + \byteCol{$\llargeMO$}, \dots, \byteCol{1}, \byteCol{0}; \\ + \end{array} + \right) +\] +the following collection of constraints: +\begin{enumerate} + \item $[\col{@}_{1}]_{i} + \cdots + [\col{@}_{p}]_{i} = 1$ i.e. precisely one of these binary flags is on at any given time; + \item for $\ell = 1, \dots, p$ we ask that + \If $\sum_{k = 0}^{\ell-1} [\col{@}_{k}]_{i} \neq 1$ \Then + \begin{itemize} + \item \If $[\col{@}_{\ell}]_{i} = 1$ \Then $\ord^\ell_{i} \neq \ord^\ell_{i - 1}$, + \item \If $[\col{@}_{\ell}]_{i} = 0$ \Then $\ord^\ell_{i} = \ord^\ell_{i - 1}$; + \end{itemize} + where, again, we set $[\col{@}_0] \equiv 0$. + \item unconditionally + \[ + \begin{array}{lcl} + 1 + \Delta_{i} + & = & + \displaystyle + \phantom{+} \sum_{\substack{1\leq \ell \leq p\\\epsilon_\ell = +}} + [\col{@}_{\ell}]_{i} + \cdot + \Big( + \ord^\ell_{i} - \ord^\ell_{i - 1} + \Big) \\ + & & + \displaystyle + - + \sum_{\substack{1\leq \ell \leq p\\\epsilon_\ell = -}} + [\col{@}_{\ell}]_{i} + \cdot + \Big( + \ord^\ell_{i} - \ord^\ell_{i - 1} + \Big) + \end{array} + \] +\end{enumerate} +% \ob{Obsolete! Note that the sum = 1 constraint is incompatible with naive padding. There is a way around it which uses the fact that in all scenarios of interest the padding rows can be left at the start of the reordered versions. Thus all conditions beyond the bytehood constraint can, if we prefer, be made conditional to ``\If $\module\stamp_{i} \neq 0$ \Then'' (yes, the \emph{unordered} version of $\module\stamp$); alternatively we can pad with $\col{Eq} \equiv 1$.} diff --git a/lex/order.tex b/lex/order.tex new file mode 100644 index 0000000..0ddc41f --- /dev/null +++ b/lex/order.tex @@ -0,0 +1,37 @@ +We introduce notations for lexicographic orders. Consider an integer $p \geq 2$ and a sign sequence $\epsilon_{\bullet} \in \{-, +\}^p$. Define the associated lexicographic order $\underset{\epsilon_{\bullet}}{\prec}$ on $p$-tuples nonnegative integers as follows. For \( \alpha_{\bullet} = (\alpha^1,\dots,\alpha^p),\, \beta_{\bullet} = (\beta^1,\dots,\beta^p) \in \mathbb{N}^p \) we set +\[ + \alpha_{\bullet} \underset{\epsilon_{\bullet}}{\prec} \beta_{\bullet} + \iff + \exists j \in \{1,\dots,p\}, + \begin{cases} + \forall i \big( 1\leq i < j \implies \alpha_{i} = \beta_{i} \big) \\ + \epsilon_j(\beta_{i} - \alpha_{i}) > 0 \\ + \end{cases} +\] +For instance with $q=3$ and $\epsilon_{\bullet} = (+,+,-)$ the associated lexicographic order $\underset{\epsilon_{\bullet}}{\prec}$ satisfies +\[ + \alpha_{\bullet} \underset{\epsilon_{\bullet}}{\prec} \beta_{\bullet} + \iff + \begin{cases} + & \alpha_{1} < \beta_{1} \\ + \OR & (\alpha_{1} = \beta_{1} \et \alpha_{2} < \beta_{2}) \\ + \OR & (\alpha_{1} = \beta_{1} \et \alpha_{2} = \beta_{2} \et \alpha_{3} > \beta_{3}) \\ + \end{cases} +\] + +\saNote{} In the applications to come $\alpha_{\bullet}$ and $\beta_{\bullet}$ will typically be sampled from two consecutive rows of a pre-specified set of columns, i.e. there will be a set of columns $\ord^1, \ord^2, \dots, \ord^p$ and the relations that the constraints are meant to enforce are either a \textbf{strict ordering}: +\[ + \alpha_{\bullet} \underset{\epsilon_{\bullet}}{\prec} \beta_{\bullet} +\] +or a \textbf{weak ordering} +\[ + \alpha_{\bullet} \underset{\epsilon_{\bullet}}{\prec} \beta_{\bullet} ~\OR + \alpha_{\bullet} = \beta_{\bullet} +\] +according to some pre-specified lexicographic order $\underset{\epsilon_{\bullet}}{\prec}$ where +\[ + \begin{cases} + \alpha_{\bullet} = \big[\ord_{i}^1, \ord_{i}^2, \dots, \ord^p_{i}\big] \vspace{2mm} \\ + \beta_{\bullet} = \big[\ord_{i + 1}^1, \ord_{i + 1}^2, \dots, \ord^p_{i + 1}\big] \\ + \end{cases} +\] diff --git a/log_data/_all_log_data.tex b/log_data/_all_log_data.tex new file mode 100644 index 0000000..f3347fc --- /dev/null +++ b/log_data/_all_log_data.tex @@ -0,0 +1,43 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/log_info} +\usepackage{../pkg/rlp_log} + +\title{Log data module} +\author{Rollup team} +\date{August 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} + + diff --git a/log_data/_inputs.tex b/log_data/_inputs.tex new file mode 100644 index 0000000..f3c260a --- /dev/null +++ b/log_data/_inputs.tex @@ -0,0 +1,13 @@ +\section{Log data module} \label{log data: generalities} +\subsection{Introduction} \label{log data: generalities: intro} \input{intro} +\subsection{Columns} \label{log data: generalities: columns} \input{columns} + +\section{Constraints} \label{log data: constraints} +\subsection{Heartbeat} \label{log data: constraints: heartbeat} \input{heartbeat} +\subsection{Constancies} \label{log data: constraints: constancies} \input{constancies} +\subsection{\logLogsData{} constraints} \label{log data: constraints: log logs data} \input{log_logs_data} +% \subsection{Binary constraints} \label{lodatafo: constraints: binary} \input{binary} +\subsection{Graphical representation} \label{log data: constraints: graphical rep data} \input{representation} + +\section{Lookups} \label{log data: lookups} +\subsection{Into the \rlpTxnRcptMod{} module} \label{log data: lookups: into txn rlp} \input{lookups/log_data_into_rlp_rcpt} diff --git a/log_data/binary.tex b/log_data/binary.tex new file mode 100644 index 0000000..678e686 --- /dev/null +++ b/log_data/binary.tex @@ -0,0 +1,7 @@ +We impose that the following columns be binary: +\begin{multicols}{2} +\begin{enumerate} +\item \dataSizeTotal{} +\item \logLogsData{} +\end{enumerate} +\end{multicols} diff --git a/log_data/columns.tex b/log_data/columns.tex new file mode 100644 index 0000000..492412b --- /dev/null +++ b/log_data/columns.tex @@ -0,0 +1,11 @@ +\begin{enumerate} + \item \absLogNumMax{}: total number of (non reverted) logging operations; + \item \absLogNum{}: absolute log number (i.e. batch wide numbering of (non reverted) logging operations); + \item \logLogsData{}: binary column which equals $1$ \emph{iff} data is being logged; + \item \logDataSize{}: log-constant column; contains the size (in bytes) of the data to log; + \item \cumulSize{}: accumulates successive limb sizes of the limbs making up the log data of a log item; + \item \limbSize{}: number of significative bytes of the limb column; + \item \limb{}: data limb: when $\logLogsData \equiv 1$ contains $k$-byte integers aligned on the $\llarge^{th}$ byte where $0 < k \leq \llarge$; + \item \index{}: monotonically increasing counter column identifying a data limb of logged data; +\end{enumerate} +We will thus impose $\logLogsData = 1 \iff \logDataSize \neq 0$. diff --git a/log_data/constancies.tex b/log_data/constancies.tex new file mode 100644 index 0000000..8d54de4 --- /dev/null +++ b/log_data/constancies.tex @@ -0,0 +1,11 @@ +We say that a column \col{X} is \textbf{log-constant} if it satisfies +\[ + \If \absLogNum_{i} \neq 1 + \absLogNum_{i - 1} ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We require that the following columns be log-constant: +\begin{multicols}{3} + \begin{enumerate} + \item \logDataSize{} + \item \logLogsData{} (\trash) + \end{enumerate} +\end{multicols} diff --git a/log_data/heartbeat.tex b/log_data/heartbeat.tex new file mode 100644 index 0000000..ebb9e77 --- /dev/null +++ b/log_data/heartbeat.tex @@ -0,0 +1,59 @@ +The heartbeat of the present module is simple. +\begin{enumerate} + \item $\absLogNum_{0} = 0$ + \item \If $\absLogNum_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \logLogsData_{i} & = & 0 & (\trash) \\ + \logDataSize_{i} & = & 0 \\ + \cumulSize_{i} & = & 0 \\ + \limbSize_{i} & = & 0 \vspace{2mm} \\ + \limb_{i} & = & 0 \\ + \index_{i} & = & 0 \\ + \end{array} \right. + \] + \item $\absLogNum_{i} \in \{ \absLogNum_{i - 1}, 1 + \absLogNum_{i - 1} \}$ + \item \If $\absLogNum_{i} \neq \absLogNum_{i - 1}$ \Then $\index_{i} = 0$ + \item \If \Big($\absLogNum_{i} \neq 0$ \et $\logLogsData_{i} = 0$\Big) \Then + \[ + \left\{ \begin{array}{lcl} + \logDataSize_{i} & = & 0 \\ + \cumulSize_{i} & = & 0 \\ + \limbSize_{i} & = & 0 \vspace{2mm} \\ + \limb_{i} & = & 0 \\ + \absLogNum_{i} & = & 1 + \absLogNum_{i - 1} \\ + \end{array} \right. + \] + \item \If $\logLogsData_{i} = 1$ \Then + \begin{enumerate} + \item \If $\absLogNum_{i} \neq \absLogNum_{i - 1}$ \Then $\cumulSize_{i} = \limbSize_{i}$ + + \saNote{} The above constrains first row of log data. + \item \If $\absLogNum_{i} \neq 1 + \absLogNum_{i - 1}$ \Then + \[ + \left\{ \begin{array}{lclr} + \cumulSize_{i} & = & \cumulSize_{i - 1} + \limbSize_{i} \\ + \limbSize_{i - 1} & = & \llarge \quad (\trash) \\ + \index_{i} & = & 1 + \index_{i - 1} \\ + \end{array} \right. + \] + \saNote{} The above constrains intermediate rows of log data. + \item \If $\absLogNum_{i} \neq \absLogNum_{i + 1}$ \Then + \[ + \left\{ \begin{array}{lcl} + \cumulSize_{i} & = & \logDataSize_{i} \\ + \index_{i + 1} & = & 0 \\ + \end{array} \right. + \] + \saNote{} The above constrains last row of log data. + \saNote{} The above does not apply to the first log because of the ``$\logLogsData_{i} = 1$'' pre-condition. + \end{enumerate} + \item \If $\absLogNum_{N} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \absLogNum_{N} & = & \absLogNumMax_{N} \\ + \multicolumn{3}{l}{\If \logLogsData_{N} = 1 ~ \Then \cumulSize_{N} = \logDataSize_{N}} \\ + \end{array} \right. + \] + \saNote{} We constrain the final row +\end{enumerate} diff --git a/log_data/intro.tex b/log_data/intro.tex new file mode 100644 index 0000000..9436dc8 --- /dev/null +++ b/log_data/intro.tex @@ -0,0 +1 @@ +The \logDataMod{} module serves a singular purpose: record the data $O_\textbf{d}$ emitted in (non reverted) logging operations as part of a log item $O$. This data is extracted from \textsc{ram}. diff --git a/log_data/log_logs_data.tex b/log_data/log_logs_data.tex new file mode 100644 index 0000000..67642d0 --- /dev/null +++ b/log_data/log_logs_data.tex @@ -0,0 +1,5 @@ +The \logLogsData{} column detects log instructions that actually log data, as such: +\begin{enumerate} + \item \If $\logDataSize_{i} = 0$ \Then $\logLogsData_{i} = 0$ + \item \If $\logDataSize_{i} \neq 0$ \Then $\logLogsData_{i} = 1$ +\end{enumerate} diff --git a/log_data/lookups/log_data_into_rlp_rcpt.tex b/log_data/lookups/log_data_into_rlp_rcpt.tex new file mode 100644 index 0000000..2f67a70 --- /dev/null +++ b/log_data/lookups/log_data_into_rlp_rcpt.tex @@ -0,0 +1,22 @@ +The present lookup relation connects the \logDataMod{} to the \rlpTxnRcptMod{}. +\begin{description} + \item[\underline{Selector:}] $\logLogsData_{i} = 1$ + \item[\underline{Source columns:}] --- + \begin{enumerate} + \item $\absLogNum_{i}$ + \item $\subPhaseIdDataLimb$ + \item $\index_{i}$ + \item $\limb_{i}$ + \item $\limbSize_{i}$ + %\item[\vspace{\fill}] + \end{enumerate} + \item[\underline{Target columns:}] --- + \begin{enumerate} + \item $\absLogNum_{j}$ + \item $\Phase_{j}$ + \item $\indexlocal_{j}$ + \item $\limb_{j}$ + \item $\limbSize_{j}$ + %\item[\vspace{\fill}] + \end{enumerate} +\end{description} diff --git a/log_data/representation.tex b/log_data/representation.tex new file mode 100644 index 0000000..d8069b5 --- /dev/null +++ b/log_data/representation.tex @@ -0,0 +1,37 @@ +We represent a section of the \logDataMod{} module: +\begin{figure}[h!] + \def\zero{\graym{0}} + \def\one {\redm{1}} + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|c|c|c|c|c|c|c|} + \hline + \absLogNum & \logLogsData & \logDataSize & \cumulSize & \limbSize & \limb & \index \\ \hline \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \col{l - 1} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline \hline + \col{l} & \one & 146 & 16 & \llarge & \mathtt{0x\,abbc079a\cdots{}13} & 0 \\ \hline + \col{l} & \one & 146 & 32 & \llarge & \mathtt{0x\,000102dd\cdots{}7f} & 1 \\ \hline + \col{l} & \one & 146 & 48 & \llarge & \mathtt{0x\,9a00ffcf\cdots{}ff} & 2 \\ \hline + \col{l} & \one & 146 & 64 & \llarge & \mathtt{0x\,7ef910cc\cdots{}90} & 3 \\ \hline + \col{l} & \one & 146 & 80 & \llarge & \mathtt{0x\,11a9046d\cdots{}a3} & 4 \\ \hline + \col{l} & \one & 146 & 96 & \llarge & \mathtt{0x\,afff0ae3\cdots{}00} & 5 \\ \hline + \col{l} & \one & 146 & 112 & \llarge & \mathtt{0x\,00000010\cdots{}00} & 6 \\ \hline + \col{l} & \one & 146 & 128 & \llarge & \mathtt{0x\,a9001bbc\cdots{}ba} & 7 \\ \hline + \col{l} & \one & 146 & 144 & \llarge & \mathtt{0x\,85091a80\cdots{}67} & 8 \\ \hline + \col{l} & \one & 146 & 146 & 2 & \mathtt{0x\,ef13}\graym{\mathtt{0000\cdots{}00}} & 9 \\ \hline \hline + \col{l + 1} & \zero & \zero & \zero & \zero & \zero & \zero \\ \hline \hline + \col{l + 2} & \zero & \zero & \zero & \zero & \zero & \zero \\ \hline \hline + \col{l + 3} & \one & 64 & 16 & \llarge & \mathtt{0x\,445a001f\cdots{}91} & 0 \\ \hline + \col{l + 3} & \one & 64 & 32 & \llarge & \mathtt{0x\,00000000\cdots{}a7} & 1 \\ \hline + \col{l + 3} & \one & 64 & 48 & \llarge & \mathtt{0x\,01ffae1c\cdots{}dd} & 2 \\ \hline + \col{l + 3} & \one & 64 & 64 & \llarge & \mathtt{0x\,9abb3792\cdots{}01} & 3 \\ \hline \hline + \col{l + 4} & \zero & \zero & \zero & \zero & \zero & \zero \\ \hline \hline + \col{l + 5} & \one & 32 & 16 & \llarge & \mathtt{0x\,00091ff0\cdots{}0a} & 0 \\ \hline + \col{l + 5} & \one & 32 & 32 & \llarge & \mathtt{0x\,09111fa1\cdots{}9f} & 1 \\ \hline \hline + \col{l + 6} & \one & 45 & 16 & \llarge & \mathtt{0x\,abbc079a\cdots{}13} & 0 \\ \hline + \col{l + 6} & \one & 45 & 32 & \llarge & \mathtt{0x\,000102dd\cdots{}7f} & 1 \\ \hline + \col{l + 6} & \one & 45 & 45 & 13 & \mathtt{0x\,e7\cdots{}ff}\graym{\mathtt{000000}} & 2 \\ \hline \hline + \col{l + 7} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \end{array} + \] +\end{figure} diff --git a/log_info/_all_log_info.tex b/log_info/_all_log_info.tex new file mode 100644 index 0000000..5093a67 --- /dev/null +++ b/log_info/_all_log_info.tex @@ -0,0 +1,43 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/log_info} +\usepackage{../pkg/oob} + +\title{The \logInfoMod{} module} +\author{Rollup team} +\date{March 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} + diff --git a/log_info/_inputs.tex b/log_info/_inputs.tex new file mode 100644 index 0000000..8fb37bf --- /dev/null +++ b/log_info/_inputs.tex @@ -0,0 +1,17 @@ +\section{Log info module} \label{log info: generalities} +\subsection{Introduction} \label{log info: generalities: intro} \input{intro} +\subsection{Columns} \label{log info: generalities: columns} \input{columns} + +\section{Constraints} \label{log info: constraints} +\subsection{Heartbeat} \label{log info: constraints: heartbeat} \input{heartbeat} +\subsection{Constancies} \label{log info: constraints: constancies} \input{constancies} +\subsection{Binary constraints} \label{log info: constraints: binary} \input{binary} +% \subsection{Log numbers} \label{log info: constraints: btc and txn} \input{log_numbers} +\subsection{Instruction and instruction flags} \label{log info: constraints: inst and flags} \input{inst} +\subsection{Graphical representation} \label{log info: constraints: graphical rep data} \input{representation} +\subsection{Verticalization} \label{log info: constraints: verticalization} \input{verticalization} + +\section{Lookups} \label{log info: lookups} +\subsection{Into the \rlpTxnRcptMod{} module} \label{log info: lookups: txn rlp} \input{lookups/log_info_into_rlp_log} +\subsection{Into the \logDataMod{} module} \label{log info: lookups: log data} \input{lookups/log_info_into_log_data} +\subsection{From the \hubMod{} module} \label{log info: lookups: batch data} \input{lookups/hub_into_log_info} diff --git a/log_info/binary.tex b/log_info/binary.tex new file mode 100644 index 0000000..33c9f4c --- /dev/null +++ b/log_info/binary.tex @@ -0,0 +1,7 @@ +We impose binary constraints on the following columns: +\begin{multicols}{2} +\begin{enumerate} +\item \isLog{X}, $0 \leq \col{X} \leq 4$ +\item \txEmitsLogs +\end{enumerate} +\end{multicols} diff --git a/log_info/columns.tex b/log_info/columns.tex new file mode 100644 index 0000000..020e795 --- /dev/null +++ b/log_info/columns.tex @@ -0,0 +1,16 @@ +\begin{enumerate} + \item $\absTxNumMax$: total number of transactions in the conflated batch; + \item \absTxNum{}: absolute transaction number; + \item \txEmitsLogs{}: transaction-constant binary column which turns on for those transactions emitting log; + \item \absLogNumMax{}: total number of logs emitted in the conflated batch; + \item \absLogNum{}: absolute log number; + \item \maxCt{}: counter-constant column containing the maximal value of the counter in the current counter cycle; + \item \ct{}: counter column; + \item \INST: instruction column; vanishes for transactions which don't emit any logs; + \item \isLog{X} for $\col{X} = 0, 1, \dots, 4$: binary columns that turn on for the respective logging operation; + \item \logDataSize{}: data size (in bytes) of the data to log; + \item \topicHi{k} and \topicLo{k}, for $k = 1, 2, 3, 4$: high and low parts of log topics; + \item $\addrHi$ and $\addrLo$: high and low parts of the address of a log item; + \item \phaseNum{}: ``(sub)phase number'' column; used for the lookup to the \rlpTxnRcptMod{} module; + \item $\outgoingDataHi{}$ and $\outgoingDataLo{}$: high and low parts of outgoing data; +\end{enumerate} diff --git a/log_info/constancies.tex b/log_info/constancies.tex new file mode 100644 index 0000000..a32b178 --- /dev/null +++ b/log_info/constancies.tex @@ -0,0 +1,41 @@ +As ususal we say that a column $\col{X}$ is \textbf{counter-constant} if it satisfies the following: +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We require that the following columns be counter-constant: +\begin{multicols}{2} + \begin{enumerate} + \item \absTxNum{} % (\trash) + \item \absLogNum{} % (\trash) + \item \INST{} + \item \maxCt{} (\trash) + \item $\addrHi$ and $\addrLo$ + \item $\topicHi{k}$, $k = 1, 2, 3, 4$ + \item $\topicLo{k}$, $k = 1, 2, 3, 4$ + \item \logDataSize{} + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} The counter-constancy of \maxCt{} follows from that of \INST{} and heartbeat constraints. +% \saNote{} The columns \absTxNum{} and \absLogNum{} were already constrained to counter-constancy in the heartbeat, see bullet point~(\ref{log info: heartbeat: counter constancy of absTxNum and absLogNum}) + +\noindent We say that a column $\col{X}$ is \textbf{transaction-constant} if it satisfies the following: +\[ + \If \absTxNum_{i + 1} \neq 1 + \absTxNum_{i} ~ \Then \col{X}_{i + 1} = \col{X}_{i} +\] +We require that the following columns be transaction-constant: +% \begin{multicols}{2} +\begin{enumerate} + \item $\txEmitsLogs$ +\end{enumerate} +\noindent We say that a column $\col{X}$ is \textbf{batch-constant} if it satisfies the following: +\[ + \If \absTxNum_{i} \neq 0 ~ \Then \col{X}_{i + 1} = \col{X}_{i} +\] +We require that the following columns be batch-constant: +\begin{multicols}{2} +\begin{enumerate} + \item $\absTxNumMax$ + \item $\absLogNumMax$ +\end{enumerate} +\end{multicols} diff --git a/log_info/heartbeat.tex b/log_info/heartbeat.tex new file mode 100644 index 0000000..46431e5 --- /dev/null +++ b/log_info/heartbeat.tex @@ -0,0 +1,100 @@ +The heartbeat of the present module is designed in such a way that \emph{every} transaction is reflected in the \logInfoMod{} module, regardless of whether any (non reverted) logging operations are associated with it (i.e. $\txEmitsLogs \equiv 1$) or not (i.e. $\txEmitsLogs \equiv 0$.) When tracing the data of a logging operation verticalizing (and thus \maxCt{}) the data will require a variable number of rows depending on the underlying logging operation. +\begin{enumerate} + \item We impose $\absTxNum_{0} = 0$; + \item \If $\absTxNum_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \absTxNumMax_{i} & = & 0 \\ + \txEmitsLogs_{i} & = & 0 \\ + \absLogNumMax_{i} & = & 0 \\ + \absLogNum_{i} & = & 0 \\ + \maxCt_{i} & = & 0 \\ + \ct_{i} & = & 0 \\ + \end{array} \right. + \] + \item $\absTxNum_{i + 1} \in \{ \absTxNum_{i}, 1 + \absTxNum_{i} \}$ + \item $\absLogNum_{i + 1} \in \{ \absLogNum_{i}, 1 + \absLogNum_{i} \}$ + \item \If \Big($\absTxNum_{i} \neq 0$ \et $\txEmitsLogs_{i} = 0$\Big) \Then + \[ + \left\{ \begin{array}{lcl} + \absLogNum_{i} & = & \absLogNum_{i - 1} \\ + \absTxNum_{i} & = & 1 + \absTxNum_{i - 1} \\ + \maxCt_{i} & = & 0 \\ + \INST_{i} & = & 0 \\ % \vspace{2mm} \\ + % \multicolumn{3}{l}{\If \absTxNumMax_{i} \neq \absTxNum_{i} ~ \Then \absTxNum_{i + 1} = 1 + \absTxNum_{i}} \\ + \end{array} \right. + \] + \item\label{log info: heartbeat: counter constancy of absTxNum and absLogNum} \If $\ct_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \absTxNum_{i} & = & \absTxNum_{i - 1} & (\trash) \\ + \absLogNum_{i} & = & \absLogNum_{i - 1} & (\trash) \\ + \end{array} \right. + \] + \saNote{} The above means that \absTxNum{} and \absLogNum{} are \textbf{counter-constant}; these constraints are already in section~(\ref{log info: constraints: constancies}). It follows that if either \absTxNum{} and \absLogNum{} changes from row $i$ to row $(i + 1)$ then $\ct_{i + 1} = 0$. + % \item \If $\absTxNum_{i} \neq \absTxNum_{i - 1}$ \Then + % \begin{enumerate} + % \item $\ct_{i} = 0$ + % \end{enumerate} + % \item \If $\absLogNum_{i} \neq \absLogNum_{i - 1}$ \Then + % \begin{enumerate} + % \item $\ct_{i} = 0$ + % \item \If $\txEmitsLogs_{i} = 0$ \Then + % \[ + % \left\{ \begin{array}{lcl} + % \absLogNum_{i} & = & \absLogNum_{i - 1} \\ + % \maxCt_{i} & = & 0 \\ + % \INST_{i} & = & 0 \\ + % \end{array} \right. + % \] + % \saNote{} The above ensures that transactions that don't emit logs are dealt with in one row. + % \item \If $\txEmitsLogs_{i} = 1$ \Then + % \end{enumerate} + \item \If $\txEmitsLogs_{i} = 1$ \Then + \begin{enumerate} + % \item $\absTxNumMax_{i + 1} = \absTxNumMax_{i}$ i.e. $\absTxNumMax$ remains constant outside of padding; + \item \If $\ct_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \absLogNum_{i} & = & 1 + \absLogNum_{i - 1} \\ + \maxCt_{i} & = & 1 + \big(\INST_{i} - \inst{LOG0}\big) \\ + \end{array} \right. + \] + \saNote{} The above means that \inst{LOGX} instructions take up $2 + \col{X}$ rows. + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then + \begin{enumerate} + \item one of $\absTxNum$, $\absLogNum$ must grow, possibly both: + \[ + \left[ \begin{array}{r} + \Big( \absTxNum_{i + 1} - (1 + \absTxNum_{i} ) \Big) \\ + \cdot + \Big( \absLogNum_{i + 1} - (1 + \absLogNum_{i}) \Big) \\ + \end{array} \right] + = 0 + \] + \item $\absLogNum_{i + 1} = \absLogNum_{i} + \txEmitsLogs_{i + 1}$ + \end{enumerate} + % \item \If $\absLogNum_{i} \neq \absLogNumMax_{i}$ \Then + % \[ + % \left\{ \begin{array}{lcl} + % \absTxNum_{i + 1} & = & \absTxNum_{i} \\ + % \absLogNum_{i + 1} & = & 1 + \absLogNum_{i} \\ + % \maxCt_{i + 1} & = & 1 + \big(\INST_{i + 1} - \inst{LOG0}\big) \\ + % \ct_{i + 1} & = & 0 \\ + % \end{array} \right. + % \] + % \item \If $\absLogNum_{i} = \absLogNumMax_{i}$ \Then $\absTxNum_{i + 1} = 1 + \absTxNum_{i}$ + \end{enumerate} +\end{enumerate} +We further impose finalization constraints: +\begin{enumerate}[resume] + \item \If $\absTxNum_{N} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \absTxNum_{N} & = & \absTxNumMax_{N} \\ + \absLogNum_{N} & = & \absLogNumMax_{N} \\ + \ct_{N} & = & \maxCt_{N} \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/log_info/inst.tex b/log_info/inst.tex new file mode 100644 index 0000000..aaafcc6 --- /dev/null +++ b/log_info/inst.tex @@ -0,0 +1,30 @@ +The present section constrains the \INST{} column and associated $\isLog{X}$ columns. +\begin{enumerate} + \item \If $\txEmitsLogs_{i} = 0$ \Then $\displaystyle \sum_{\col{X} = 0} ^ {4} \isLog{X}_{i} = 0$ + \item \If $\txEmitsLogs_{i} = 1$ \Then $\displaystyle \sum_{\col{X} = 0} ^ {4} \isLog{X}_{i} = 1$ + \item In all circumstances we impose + \[ + \sum_{\col{X} = 0}^{4} \inst{LOGX} \cdot \isLog{X} = \INST_{i} + \] +\end{enumerate} + +\saNote{} We may of course subsume the above as ``$\txEmitsLogs_{i} = \sum_{\col{X} = 0} ^ {4} \isLog{X}_{i}$''. +\saNote{} The above imposes that along rows $i$ pertaining to transactions that emit logs, $\INST_{i} \in \{ \inst{LOG0}, \inst{LOG1}, \inst{LOG2}, \inst{LOG3}, \inst{LOG4} \}$. +\saNote{} Given that $\INST$ is in the range $\{ \texttt{0x00} \} \cup \{ \texttt{0x\,A0}, \dots, \texttt{0x\,A4}\}$, the above unambiguously selects for at most one of the five $\isLog{X}$ flags: +\begin{figure}[h!] + \def\zero{\graym{0}} + \def\one{\cellcolor{solarized-green}\bm{1}} + \[ + \begin{array}{|c|c|c|c|c|c|} + \hline + \INST & \isLog{0} & \isLog{1} & \isLog{2} & \isLog{3} & \isLog{4} \\ \hline \hline + \texttt{0x00} & \zero & \zero & \zero & \zero & \zero \\ \hline + \inst{LOG0} & \one & \zero & \zero & \zero & \zero \\ \hline + \inst{LOG1} & \zero & \one & \zero & \zero & \zero \\ \hline + \inst{LOG2} & \zero & \zero & \one & \zero & \zero \\ \hline + \inst{LOG3} & \zero & \zero & \zero & \one & \zero \\ \hline + \inst{LOG4} & \zero & \zero & \zero & \zero & \one \\ \hline + \end{array} + \] + \caption{Unique configuration for the \isLog{X} flags.} +\end{figure} diff --git a/log_info/intro.tex b/log_info/intro.tex new file mode 100644 index 0000000..ceb4111 --- /dev/null +++ b/log_info/intro.tex @@ -0,0 +1,10 @@ +The present (very simple) \logInfoMod{} module serves as a data repository for \emph{non reverted} \inst{LOG}-type instructions. To be precise: it records information relative to (non reverted) logging operations: +(\emph{a}) +logger address, +(\emph{b}) +log type (i.e. log opcode), +(\emph{c}) +data size and, if present, +(\emph{d}) +log topics. +In other words the present module records all the data making up a \textbf{log item} $O = (O_\text{a}, O_\textbf{t}, O_\textbf{d})$ \emph{except} for the data $O_\textbf{d}$\footnote{The data $O_\textbf{d}$, \emph{if nonempty}, is recorded in the \logDataMod{} module.}. These data are extracted from the \hubMod{} where it presents itself in \emph{row} form. But the data contained in the present module must also be passed on to the \rlpTxnRcptMod{} module, which consumes its data in \emph{column} form. As such the present module also takes care of allowing that communication to take place in a process already encountered in the \txnDataMod{} module: by \textbf{verticalization}. diff --git a/log_info/log_numbers.tex b/log_info/log_numbers.tex new file mode 100644 index 0000000..e69de29 diff --git a/log_info/lookups/hub_into_log_info.tex b/log_info/lookups/hub_into_log_info.tex new file mode 100644 index 0000000..e69de29 diff --git a/log_info/lookups/log_info_into_log_data.tex b/log_info/lookups/log_info_into_log_data.tex new file mode 100644 index 0000000..130f816 --- /dev/null +++ b/log_info/lookups/log_info_into_log_data.tex @@ -0,0 +1,20 @@ +The lookup is used only to verify the size of the data to log. +\begin{description} + \item[\underline{Selector:}] $\txEmitsLogs_{i}$ + \item[\underline{Source columns:}] from the \logInfoMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\absLogNumMax{}_{i}$ + \item $\absLogNum{}_{i}$ + \item $\logDataSize{}_{i}$ + \end{enumerate} + \end{multicols} +\item[\underline{Target columns:}] from the \logDataMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\absLogNumMax{}_{j}$ + \item $\absLogNum{}_{j}$ + \item $\logDataSize{}_{j}$ + \end{enumerate} + \end{multicols} +\end{description} \ No newline at end of file diff --git a/log_info/lookups/log_info_into_rlp_log.tex b/log_info/lookups/log_info_into_rlp_log.tex new file mode 100644 index 0000000..06a314a --- /dev/null +++ b/log_info/lookups/log_info_into_rlp_log.tex @@ -0,0 +1,24 @@ +We describe the lookup transfering \emph{verticalized} data from the current module to the \rlpTxnRcptMod{} module. +\begin{description} + \item[\underline{Selector:}] none. + \item[\underline{Source columns:}] from the \logInfoMod{} module: + \begin{enumerate} + \item $\absTxNumMax{}_{i}$ + \item $\absTxNum{}_{i}$ + \item $\absLogNum{}_{i}$ + \item $\absLogNumMax{}_{i}$ + \item $\phaseNum{}_{i}$ + \item $\outgoingDataHi{}_{i}$ + \item $\outgoingDataLo{}_{i}$ + \end{enumerate} +\item[\underline{Target columns:}] from the \rlpTxnRcptMod{} module: + \begin{enumerate} + \item $\absTxNumMax{}_{j}$ + \item $\absTxNum{}_{j}$ + \item $\absLogNum{}_{j}$ + \item $\absLogNumMax{}_{j}$ + \item $\Phase_{j}$ + \item $\Input{1}_{j}$ + \item $\Input{2}_{j}$ + \end{enumerate} +\end{description} diff --git a/log_info/representation.tex b/log_info/representation.tex new file mode 100644 index 0000000..6c858b7 --- /dev/null +++ b/log_info/representation.tex @@ -0,0 +1,59 @@ +\begin{figure} + \def\zero{\graym{0}} + \def\one{\red{1}} + \renewcommand{\arraystretch}{1.3} + \[ + \begin{array}{|c|c|c|c||c|c|c||c|c|c|} + \hline + \col{ABS} & \col{EMITS} & \col{LOGN} & \col{LOGN}^\infty & \INST & \ct^\infty & \ct & \phaseNum & \outgoingDataHi & \outgoingDataLo \\ \hline + \cellcolor{solarized-cyan}\col{a - 2} & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline \hline + % LOG2 \cellcolor{solarized-green} + % \cellcolor{solarized-yellow}\col{a - 1} & \one & 14 & \col{logn}^\infty & \inst{LOG2} & 4 & 0 & \ob{TODO} & \zero & \col{logn}^\infty~(= 3) \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 14 & \col{logn}^\infty & \inst{LOG2} & 3 & 0 & \subPhaseIdDataSize & \col{data\_size} & \col{nTopics}~(= 2) \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 14 & \col{logn}^\infty & \inst{LOG2} & 3 & 1 & \subPhaseIdAddr & \col{addr\_hi} & \col{addrLo} \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 14 & \col{logn}^\infty & \inst{LOG2} & 3 & 2 & \subPhaseIdTopicBase + \subPhaseIdTopicDelta & \col{topic\_1\_hi} & \col{topic\_1\_lo} \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 14 & \col{logn}^\infty & \inst{LOG2} & 3 & 3 & \subPhaseIdTopicBase + 2 \cdot \subPhaseIdTopicDelta & \col{topic\_2\_hi} & \col{topic\_2\_lo} \\ \hline \hline + % LOG0 + % \cellcolor{solarized-yellow}\col{a - 1} & \one & 15 & \col{logn}^\infty & \inst{LOG0} & 2 & 0 & \ob{TODO} & \zero & \col{logn}^\infty~(= 3) \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 15 & \col{logn}^\infty & \inst{LOG0} & 1 & 0 & \subPhaseIdDataSize & \col{dataSize} & \col{nTopics}~(= 0) \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 15 & \col{logn}^\infty & \inst{LOG0} & 1 & 1 & \subPhaseIdAddr & \col{addrHi} & \col{addrLo} \\ \hline \hline + % LOG4 + % \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 6 & 0 & \ob{TODO} & \zero & \col{logn}^\infty~(= 3) \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 5 & 0 & \subPhaseIdDataSize & \col{dataSize} & \col{nTopics}~(= 4) \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 5 & 1 & \subPhaseIdAddr & \col{addrHi} & \col{addrLo} \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 5 & 2 & \subPhaseIdTopicBase + \subPhaseIdTopicDelta & \col{topic\_1\_hi} & \col{topic\_1\_lo} \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 5 & 3 & \subPhaseIdTopicBase + 2 \cdot \subPhaseIdTopicDelta & \col{topic\_2\_hi} & \col{topic\_2\_lo} \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 5 & 4 & \subPhaseIdTopicBase + 3 \cdot \subPhaseIdTopicDelta & \col{topic\_3\_hi} & \col{topic\_3\_lo} \\ \hline + \cellcolor{solarized-yellow}\col{a - 1} & \one & 16 & \col{logn}^\infty & \inst{LOG4} & 5 & 5 & \subPhaseIdTopicBase + 4 \cdot \subPhaseIdTopicDelta & \col{topic\_4\_hi} & \col{topic\_4\_lo} \\ \hline \hline + % no logs + \cellcolor{solarized-orange}\col{a} & \zero & 16 & \col{logn}^\infty & \zero & \zero & \zero & \subPhaseIdNoLogEntry & \zero & \zero \\ \hline \hline + % LOG1 + % \cellcolor{solarized-green}\col{a + 1} & \one & 17 & \col{logn}^\infty & \inst{LOG1} & 3 & 0 & \ob{TODO} & \zero & \col{logn}^\infty~(= 7) \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 17 & \col{logn}^\infty & \inst{LOG1} & 2 & 0 & \subPhaseIdDataSize & \col{dataSize} & \col{nTopics}~(= 1) \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 17 & \col{logn}^\infty & \inst{LOG1} & 2 & 1 & \subPhaseIdAddr & \col{addrHi} & \col{addrLo} \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 17 & \col{logn}^\infty & \inst{LOG1} & 2 & 2 & \subPhaseIdTopicBase + \subPhaseIdTopicDelta & \col{topic\_1\_hi} & \col{topic\_1\_lo} \\ \hline \hline + % LOG3 + % \cellcolor{solarized-green}\col{a + 1} & \one & 18 & \col{logn}^\infty & \inst{LOG3} & 5 & 0 & \ob{TODO} & \zero & \col{logn}^\infty~(= 7) \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 18 & \col{logn}^\infty & \inst{LOG3} & 4 & 0 & \subPhaseIdDataSize & \col{dataSize} & \col{nTopics}~(= 3) \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 18 & \col{logn}^\infty & \inst{LOG3} & 4 & 1 & \subPhaseIdAddr & \col{addrHi} & \col{addrLo} \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 18 & \col{logn}^\infty & \inst{LOG3} & 4 & 2 & \subPhaseIdTopicBase + \subPhaseIdTopicDelta & \col{topic\_1\_hi} & \col{topic\_1\_lo} \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 18 & \col{logn}^\infty & \inst{LOG3} & 4 & 3 & \subPhaseIdTopicBase + 2 \cdot \subPhaseIdTopicDelta & \col{topic\_2\_hi} & \col{topic\_2\_lo} \\ \hline + \cellcolor{solarized-green}\col{a + 1} & \one & 18 & \col{logn}^\infty & \inst{LOG3} & 4 & 4 & \subPhaseIdTopicBase + 3 \cdot \subPhaseIdTopicDelta & \col{topic\_3\_hi} & \col{topic\_3\_lo} \\ \hline \hline + % continued + \cellcolor{solarized-magenta!80}\col{a + 2} & \zero & 18 & \col{logn}^\infty & \zero & \zero & \zero & \subPhaseIdNoLogEntry & \zero & \zero \\ \hline \hline + \cellcolor{solarized-magenta!60}\col{a + 3} & \zero & 18 & \col{logn}^\infty & \zero & \zero & \zero & \subPhaseIdNoLogEntry & \zero & \zero \\ \hline \hline + \cellcolor{solarized-magenta!40}\col{a + 4} & \one & 19 & \col{logn}^\infty & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + \end{array} + \] + \label{log info: verticalization: figure} + \caption{Graphical representation of verticatlization. To save space we used the following short hands: + $\col{ABS} \leftrightarrow \absTxNum$, + $\col{EMITS} \leftrightarrow \txEmitsLogs$, + $\col{LOGN} \leftrightarrow \absLogNum$, + $\col{LOGN}^\infty \leftrightarrow \absLogNumMax$ and + $\ct^\infty \leftrightarrow \maxCt$. + The interpretation is as follows: + the transaction with $\absTxNum = \col{a - 1}$ logs 3 events, + the transaction with $\absTxNum = \col{a }$ logs 0 events, + the transaction with $\absTxNum = \col{a + 1}$ logs 7 events (only 2 of which are accounted for in the diagram above.)} +\end{figure} diff --git a/log_info/verticalization.tex b/log_info/verticalization.tex new file mode 100644 index 0000000..cc522bc --- /dev/null +++ b/log_info/verticalization.tex @@ -0,0 +1,83 @@ +The present section details the way in which logging data, which the \hubMod{} provides in row form, is \textbf{verticatlize} for consumption by the \rlpTxnRcptMod{} module. Verticalization occurs for log items only. In other words, no verticalization happens for transactions that don't lead to (non reverted) logging events. As such +\[ \boxed{\text{All constraints in this subsection assume } \begin{cases} \absTxNum_{i} \neq 0 \\ \ct_{i} = 0 \\ \end{cases}} \] + \saNote{} Given the constraints below the condition ``$\absTxNum_{i} \neq 0$'' is superfluous. + \begin{description} + % \item[\underline{First row:}] The first row is \emph{always} used to record the number of log items of the transaction: + % \[ + % \left\{ \begin{array}{lcl} + % \phaseNum_{i} & = & \ob{TODO!} \\ + % \outgoingDataHi_{i} & = & 0 \\ + % \outgoingDataLo_{i} & = & \absLogNumMax_{i} \\ + % \end{array} \right. + % \] + \item[\underline{First and second row:}] \If $\isLog{0}_{i} + \cdots + \isLog{4}_{i} \neq 0$ \Then + \[ + \iffalse + \sum_{k=1}^{5} k \cdot \phase{k}_{j} + \subPhaseIdWeightIsPrefix \cdot \isprefix_{j} + \subPhaseIdWeightIsOt \cdot \isOt_{j} + \subPhaseIdWeightIsOd \cdot \isOd_{j} + \subPhaseIdWeightDepth \cdot \Depth1_{j} + \subPhaseIdWeightIndexLocal \cdot \isOt_{j} \cdot \indexlocal_{j}$ + \fi + \left\{ \begin{array}{lcl} + \phaseNum_{i} & = & \subPhaseIdDataSize \\ + \outgoingDataHi_{i} & = & \logDataSize_{i} \\ + \outgoingDataLo_{i} & = & \INST_{i} - \inst{LOG0} \vspace{2mm} \\ + \phaseNum_{i + 1} & = & \subPhaseIdAddr \\ + \outgoingDataHi_{i + 1} & = & \addrHi_{i} \\ + \outgoingDataLo_{i + 1} & = & \addrLo_{i} \\ + \end{array} \right. + \] + \item[\underline{Third row:}] \If $\isLog{1}_{i} + \cdots + \isLog{4}_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \phaseNum_{i + 2} & = & \subPhaseIdTopicBase + \subPhaseIdTopicDelta \\ + \outgoingDataHi_{i + 2} & = & \topicHi{1}_{i} \\ + \outgoingDataLo_{i + 2} & = & \topicLo{1}_{i} \\ + \end{array} \right. + \] + \item[\underline{Fourth row:}] \If $\isLog{2}_{i} + \cdots + \isLog{4}_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \phaseNum_{i + 3} & = & \subPhaseIdTopicBase + 2 \cdot \subPhaseIdTopicDelta \\ + \outgoingDataHi_{i + 3} & = & \topicHi{2}_{i} \\ + \outgoingDataLo_{i + 3} & = & \topicLo{2}_{i} \\ + \end{array} \right. + \] + \item[\underline{Fifth row:}] \If $\isLog{3}_{i} + \isLog{4}_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \phaseNum_{i + 4} & = & \subPhaseIdTopicBase + 3 \cdot \subPhaseIdTopicDelta \\ + \outgoingDataHi_{i + 4} & = & \topicHi{3}_{i} \\ + \outgoingDataLo_{i + 4} & = & \topicLo{3}_{i} \\ + \end{array} \right. + \] + \item[\underline{Sixth row:}] \If $\isLog{4}_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \phaseNum_{i + 5} & = & \subPhaseIdTopicBase + 4 \cdot \subPhaseIdTopicDelta \\ + \outgoingDataHi_{i + 5} & = & \topicHi{4}_{i} \\ + \outgoingDataLo_{i + 5} & = & \topicLo{4}_{i} \\ + \end{array} \right. + \] + + \item[\underline{If no Log entry:}] \If $\txEmitsLogs_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \phaseNum_{i} & = & \subPhaseIdNoLogEntry \\ + \outgoingDataHi_{i} & = & 0 \\ + \outgoingDataLo_{i} & = & 0 \\ + \end{array} \right. + \] + \end{description} +\saNote{} +The numeric constants above are obtained as +\[ + \begin{cases} + \subPhaseIdDataSize & = 5 + \subPhaseIdWeightIsPrefix + \subPhaseIdWeightIsOd + \subPhaseIdWeightDepth \\ + \subPhaseIdAddr & = 5 + \subPhaseIdWeightDepth \\ + \subPhaseIdTopicBase & = 5 + \subPhaseIdWeightIsOt + \subPhaseIdWeightDepth \\ + \subPhaseIdNoLogEntry & = 5 + \subPhaseIdWeightIsPrefix \\ + \end{cases} +\] diff --git a/mmio/_all_mmio.tex b/mmio/_all_mmio.tex new file mode 100644 index 0000000..bc79311 --- /dev/null +++ b/mmio/_all_mmio.tex @@ -0,0 +1,37 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/stack} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/mmio_instructions} +\usepackage{../pkg/mmu} +\usepackage{../pkg/mmu_custom_instructions} +\usepackage{../pkg/prc} +\usepackage{../pkg/log_info} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/prc} +\usepackage{../pkg/draculatheme} + +\title{The \mmioMod{} module} +\author{Rollup team} + +\date{February 2024} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/mmio/_inputs.tex b/mmio/_inputs.tex new file mode 100644 index 0000000..90e4cbf --- /dev/null +++ b/mmio/_inputs.tex @@ -0,0 +1,42 @@ +\input{_local} + +\section{Column descriptions} \input{columns} + +\section{Module constraints} +\subsection{Instruction decoding} \label{mmio: instruction decoding} \input{generalities/decoding} +\subsection{Heartbeat} \label{mmio: heartbeat} \input{generalities/heartbeat} +\subsection{Byte decomposition constraints} \input{generalities/byte_decomposition} +\subsection{Binary constraints} \label{mmio: specialized constraints: binary} \input{generalities/binary} +\subsection{Bytehood constraints} \input{generalities/bytehood} +\subsection{Counter constancy} \label{mmio: counter constancy} \input{generalities/constancies} + +\section{Specialized constraints} \label{mmio: specialized constraints} +\subsection{Purpose} \label{mmio: specialized constraints: purpose} \input{specialized/purpose} +\subsection{\byteDec} \label{mmio: specialized constraints: byte decomposition} \input{specialized/byte_decomposition} +\subsection{\plateau{}} \label{mmio: specialized constraints: plateau} \input{specialized/plateau} +\subsection{\power{}} \label{mmio: specialized constraints: power} \input{specialized/power} +\subsection{\antiPower{}} \label{mmio: specialized constraints: antipower} \input{specialized/anti_power} +\subsection{\compSuffix{}} \label{mmio: specialized constraints: extract suffix} \input{specialized/extraction_suffix} +\subsection{\compPrefix{}} \label{mmio: specialized constraints: extract prefix} \input{specialized/extraction_prefix} +\subsection{\compChunk{}} \label{mmio: specialized constraints: extract chunk} \input{specialized/extraction_chunk} + +\section{Surgical patterns} +\subsection{Purpose} \input{patterns/purpose} +%\subsection{\byteSwap{}} \input{patterns/single_byte_replacement} +\subsection{\excision{}} \input{patterns/excision} +\subsection{$\oneToOnePadded$} \input{patterns/prefix_trailing_zeros_mono} +\subsection{$\twoToOnePadded$} \input{patterns/prefix_trailing_zeros_duo} +%\subsection{$\oneFullToTwo{}$} \input{patterns/ram_ram_full} +%\subsection{$\twoToOneFull{}$} \input{patterns/two_to_one_full} +\subsection{$\onePartialToOne$} \input{patterns/partial_mono} +\subsection{$\onePartialToTwo$} \input{patterns/partial_duo} +\subsection{$\twoPartialToOne$} \input{patterns/two_partial_to_one} + + +\section{\mmioMod{} instruction constraints} \input{mmio_instruction/_inputs} + +\section{Consistency constraints} +\subsection{Concatenated columns and order} \input{consistency/concat} +\subsection{Memory consistency constraints} \input{consistency/consistency} + +\section{Lookups} \input{lookups/_inputs} diff --git a/mmio/_local.tex b/mmio/_local.tex new file mode 100644 index 0000000..3ef2f3c --- /dev/null +++ b/mmio/_local.tex @@ -0,0 +1,5 @@ +\def\locSlowOpFlagSum {\col{slow\_op\_flag\_sum}} +\def\locFastOpFlagSum {\col{fast\_op\_flag\_sum}} +\def\locOpFlagSum {\col{op\_flag\_sum}} +\def\locWeightedExoSum {\col{weighted\_exo\_sum}} +\def\locInstructionMayProvideExoSum {\col{instruction\_may\_provide\_exo\_sum}} diff --git a/mmio/columns.tex b/mmio/columns.tex new file mode 100644 index 0000000..cbf8769 --- /dev/null +++ b/mmio/columns.tex @@ -0,0 +1,124 @@ +\noindent Throughout this document we use the word \textbf{limb}\label{def: limb} to designate a $\llarge$-byte integer. + +% \ob{TODO: representation of RAM with \cnA{}, \indexA{}, \valA{}, $\valA{}\new{}$ etc \dots{}} +The RAM data processor has, at all times, access to precisely 3 values (limbs) from RAM. These values can be chosen from distinct execution contexts, including the $0^{\text{th}}$ execution context which plays a special role. To specify a ``value in RAM'' we thus require a tuples consisting of (a) an execution context (b) a limb offset in RAM (c) the limb (i.e. value) stored at that offset. The arithmetization requires us to add to these (d) a \emph{potentially} udpated value of that limb and (e) bytes that \emph{potentially} spell out the byte decomposition of the limb currently in RAM (i.e. before any \emph{potential} update). This is the purpose of the following columns. Since the RAM data processor can access three RAM slots there are three such quintuples. We give more details below. + +Three \emph{counter-constant columns} containing execution context numbers: +\begin{enumerate} + \item \CNA{}; abbreviated to \cnA{}; + \item \CNB{}; abbreviated to \cnB{}; + \item \CNC{}; abbreviated to \cnC{}; +\end{enumerate} +Three \emph{counter-constant columns} containing limb offsets within the corresponding execution context's RAM: +\begin{enumerate}[resume] + \item \indexA{}: limb offset in the RAM of context \cnA{}; + \item \indexB{}: limb offset in the RAM of context \cnB{}; + \item \indexC{}: limb offset in the RAM of context \cnC{}; +\end{enumerate} +Three \emph{counter-constant columns} containing the limbs currently stored at the given offsets inside the corresponding execution context's RAM: +\begin{enumerate}[resume] + \item \VALA{}: (limb) value currently in \cnA{}'s RAM at \indexA{}; abbreviated to \valA{}; + \item \VALB{}: (limb) value currently in \cnB{}'s RAM at \indexB{}; abbreviated to \valB{}; + \item \VALC{}: (limb) value currently in \cnC{}'s RAM at \indexC{}; abbreviated to \valC{}; +\end{enumerate} +Three \emph{counter-constant columns} containing \emph{potentially} updated values of the limbs currently stored at the given offsets inside the corresponding execution context's RAM: +\begin{enumerate}[resume] + \item \VALANEW{}; updated value in \cnA{}'s RAM at \indexA{}; abbreviated to $\valA{}\new$; + \item \VALBNEW{}; updated value in \cnB{}'s RAM at \indexB{}; abbreviated to $\valB{}\new$; + \item \VALCNEW{}; updated value in \cnC{}'s RAM at \indexC{}; abbreviated to $\valC{}\new$; +\end{enumerate} +Three \emph{byte columns} which \emph{may} contain the byte decompositions of \valA{}, \valB{} and/or \valC{} (depending on whether they are required for the present computation): +\begin{enumerate}[resume] + \item \BYTEA{}; byte columns; % abbreviated to \byteA{}; + \item \BYTEB{}; byte columns; % abbreviated to \byteB{}; + \item \BYTEC{}; byte columns; % abbreviated to \byteC{}; +\end{enumerate} +We also require three \emph{accumulator columns} which \emph{may} witness these byte decompositions: +\begin{enumerate}[resume] + \item \acc{A}: if $\slowOp{} = 1$ accumulates the bytes of the \byteA{} column; + \item \acc{B}: if $\slowOp{} = 1$ accumulates the bytes of the \byteB{} column; + \item \acc{C}: if $\slowOp{} = 1$ accumulates the bytes of the \byteC{} column; +\end{enumerate} +\begin{figure} +\centering +\includegraphics[width = 0.7\textwidth]{drawing/bla} +\caption{The diagram above contains all the intuition there is to convey about context numbers, indices, values and updated values. Every execution context (identified by its context number) has its own RAM, the data in RAM is addressed via an index $\in\{0,1,\dots\}$ which for the purposes of the zk-evm always is a $\ssmall{}$-byte integer as larger offsets are rejected before getting this far. The data itself is packaged as ``limbs'': $\llarge{}$-byte integers. Instructions may change 0, 1, 2 or even three of the available RAM limbs at any point in time. In the above only the $\VALC$ is modified.} +\end{figure} + +The RAM pre-processor converts RAM instructions into a sequence of \textbf{RAM micro instructions}\label{def: RAM micro instruction}. The RAM data processor only knows how to deal with micro instructions. Micro instructions can be fast ($\fastOp = 1$) or slow ($\fastOp = 0$). Fast micro instructions take up exactly one row in the RAM data processor's execution trace. Slow micro instructions take up exactly $\llarge$ rows in the RAM data processor's execution trace. RAM micro instructions can modify 1, 2 or even 3 limbs at once through various forms of \textbf{limb surgery}. These limbs may be in RAM, imported from the stack or part of exogenous data. The modification can use as inputs 1, 2 or even 3 limbs taken from RAM, the stack or exogenous data. Limb surgeries (micro instructions that modify limbs on a byte level) are determined by their \emph{(data) source}, \emph{(data) target}, a \emph{surgery pattern} and an \emph{offset} and potentially a \emph{size}. The micro instruction, the source and target, the offsets and the size (if any) are handed down to the RAM data processor from the pre-processor. Offsets are actually given in terms of a \emph{limb offset} and a \emph{byte offset} determined by euclidean division of the underlying offset by 16: +\[ + \textsf{offset} = 16\cdot \textsf{limbOffset} + \textsf{byteOffset}, + \quad + \textsf{byteOffset} \in \{0,1,\dots,\llargeMO\}. +\] + +The following are columns \textbf{imported} from the RAM preprocessor. Colums that are imported from the RAM preprocessor are distinguished by angular brackets as in $\imported{\col{X}}$. \emph{All imported columms are counter-constant}. +\begin{enumerate}[resume] + \item $\mmioStamp{}$: contains the \mmioMod{} stamp; + \item $\mmioInst{}$: contains the \mmioMod{} instruction of the current $\mmioStamp{}$; + \item $\CNS{}$: context number of the context whose RAM \emph{may} be used as a source of limbs; abbreviated to $\cnS{}$; + \item $\CNT{}$: context number of the context whose RAM \emph{may} be used as a target of limbs; abbreviated to $\cnT{}$; + \item $\SLO{}$: this imported column contains the limb offset of the first limb to read from / write to in $\cnS{}$'s RAM; abbreviated to $\slo{}$ + \item $\TLO{}$: this imported column contains the limb offset of the first limb to read from / write to in $\cnT{}$'s RAM; abbreviated to $\tlo{}$ + \item $\SBO{}$: this imported column contains the byte offset within the limb to read from / write to in $\cnS{}$'s RAM; with values in $\{0,1,\dots, \llargeMO\}$; abbreviated to $\sbo{}$; + \item $\TBO{}$: this imported column contains the byte offset within the limb to read from / write to in $\cnT{}$'s RAM; with values in $\{0,1,\dots, \llargeMO\}$; abbreviated to $\tbo{}$; + \item $\size{}$: an imported column containing a ``size'' parameter used by certain limb surgeries; + \item $\limb{}$: an imported column containing a ``limb''; + \item $\totalSize{}$: an imported column containing the total size of the output of the $\mmuInstAnyToRamWithPadding$; + \item $\exoSum{}$: an imported column containing an integer that is understood as a bit field; is decoded into flags to impose in which exo module read or write the limbs; + \item $\idOne{}$ and $\idTwo{}$: contain an identifier (stamp) of the needed exo module; + \item $\Phase{}$: contains the ``phase'' in the exo module to specify, for a given ``stamp'' at which rows the lookup occurs; + \item $\successBit{}$: bit column; contains the success (or failure) of the current evm operation; + % TODO: add new macros and replace them everywhere in the MMIO module spec + % µ/XX MMIO/XX + % \item $\mmioStamp{}$: contains the \mmioMod{} stamp; + % \item $\mmioInst{}$: contains the \mmioMod{} instruction of the current $\mmioStamp{}$; + % \item $\CNS{}$: context number of the context whose RAM \emph{may} be used as a source of limbs; abbreviated to $\mmioCnS{}$; + % \item $\CNT{}$: context number of the context whose RAM \emph{may} be used as a target of limbs; abbreviated to $\mmioCnT{}$; + % \item $\SLO{}$: this column contains the limb offset of the first limb to read from / write to in $\mmioCnS{}$'s RAM; abbreviated to $\mmioSlo{}$ + % \item $\TLO{}$: this column contains the limb offset of the first limb to read from / write to in $\mmioCnT{}$'s RAM; abbreviated to $\mmioTlo{}$ + % \item $\SBO{}$: this column contains the byte offset within the limb to read from / write to in $\mmioCnS{}$'s RAM; with values in $\{0,1,\dots, \llargeMO\}$; abbreviated to $\mmioSbo{}$; + % \item $\TBO{}$: this column contains the byte offset within the limb to read from / write to in $\mmioCnT{}$'s RAM; with values in $\{0,1,\dots, \llargeMO\}$; abbreviated to $\mmioTbo{}$; + % \item $\mmioSize{}$: a column containing a ``size'' parameter used by certain limb surgeries; + % \item $\mmioLimb{}$: a column containing a ``limb''; + % \item $\mmioTotalSize{}$: a column containing the total size of the output of the $\mmuInstAnyToRamWithPadding$; + % \item $\mmioExoSum{}$: a column containing an integer that is understood as a bit field; is decoded into flags to impose in which exo module read or write the limbs; + % \item $\mmioIdOne{}$ and $\idTwo{}$: contain an identifier (stamp) of the needed exo module; + % \item $\mmioPhase{}$: contains the ``phase'' in the exo module to specify, for a given ``stamp'' at which rows the lookup occurs; + % \item $\mmioSuccessBit{}$: bit column; contains the success (or failure) of the current evm operation; +\end{enumerate} + +The following are binary columns \textbf{decoded} from the previous \textbf{imported} columns: +\begin{enumerate}[resume] + \item \isMmioInstLimbVanishes{} + \item \isMmioInstLimbToRamTransplant{} + \item \isMmioInstLimbToRamOneTarget{} + \item \isMmioInstLimbToRamTwoTarget{} + \item \isMmioInstRamToLimbTransplant{} + \item \isMmioInstRamToLimbOneSource{} + \item \isMmioInstRamToLimbTwoSource{} + \item \isMmioInstRamToRamTransplant{} + \item \isMmioInstRamToRamPartial{} + \item \isMmioInstRamToRamTwoTarget{} + \item \isMmioInstRamToRamTwoSource{} + \item \isMmioInstRamExcision{} + \item \isMmioInstRamVanishes{} + \item \fastOp{} and \slowOp{}: binary flag, indicates whether a micro instruction is fast (i.e. occupies a single line in the RAM data processor) or slow (i.e. occupies 16 consecutive lines in the RAM data processor.) + \item \isExoFlagRom {} + \item \isExoFlagKec {} + \item \isExoFlagLog {} + \item \isExoFlagRlpTxn {} + \item \isExoFlagEcdata {} + \item \isExoFlagRipSha {} + \item \isExoFlagBlakeModexp {} + \item \indexX{}: contains the limb offset of exogenous data; + \item \byteLimb{}: byte column; \emph{may} contain the byte decomposition of $\limb{}$; + \item \acc{LIMB}: if $\slowOp{} = 1$ accumulates the bytes of the \byteLimb{} column; +\end{enumerate} +We now introduce some columns that are of use in producing proofs but aren't meaningful outside of that. +\begin{enumerate}[resume] + \item ``binary plateau'' columns $\bit{1}, \bit{2}, \bit{3}, \bit{4}, \bit{5}$; + \item ``accumulator'' columns \acc{1}, \acc{2}, \acc{3}, \acc{4}; + \item ``powers of 256'' columns $\pow{1}$ and $\pow{2}$; + \item \CT{}: a column that either hovers around 0 or counts up from 0 to $\llargeMO$ and resets to 0; used for slow memory operations (i.e. when $\slowOp{}=1$) when byte decompositions are needed; +\end{enumerate} diff --git a/mmio/consistency/concat.tex b/mmio/consistency/concat.tex new file mode 100644 index 0000000..c2dc2b9 --- /dev/null +++ b/mmio/consistency/concat.tex @@ -0,0 +1,22 @@ +We introduce several interleaved columns: +\begin{enumerate} + \item $\cnABC := \cnA\cc\cnB\cc\cnC$, + \item $\indexABC := \indexA\cc\indexB\cc\indexC$ + \item $\mst^{\cc3} := \mst\cc\mst\cc\mst$ + \item $\valABC := \valA\cc\valB\cc\valC$ + \item $\valABC\new := \valA\new\cc\valB\new\cc\valC\new$ +\end{enumerate} +We introduce their reordered variants: +$\order{\cnABC}$, $\order{\indexABC}$, $\order{\mst^{\cc3}}$, $\order{\valABC}$, $\order{\valABC\new}$ where reordering is done according to the lexicographic order on the triple +\[ + (\CN{}, \index, \mst) +\] +in other words, the reordering is such that +\[ + \Big( + \order{\cnABC},~ + \order{\indexABC},~ + \order{\mst^{\cc3}} + \Big) +\] +are lexicographically ordered. \ No newline at end of file diff --git a/mmio/consistency/consistency.tex b/mmio/consistency/consistency.tex new file mode 100644 index 0000000..8589e4e --- /dev/null +++ b/mmio/consistency/consistency.tex @@ -0,0 +1,83 @@ +\begin{enumerate} + \item There are no constraints when $\order{\cnABC}_{i} = 0$ + \item \If $\order{\cnABC}_{i} \neq 0$: + \begin{enumerate} + \item \If + \[ + \begin{cases} + \order{\cnABC}_{i+1}=\order{\cnABC}_{i} \\ + \quad\et\\ + \order{\indexABC}_{i+1}=\order{\indexABC}_{i} \\ + \quad\et\\ + \order{\mst^{\cc3}}_{i+1} \neq \order{\mst^{\cc3}}_{i} + \end{cases} + \] + \Then $\order{\valABC}_{i+1}=\order{\valABC\new_{i}}$ + \item \If + \[ + \begin{cases} + \order{\cnABC}_{i+1}\neq\order{\cnABC}_{i} \\ + \quad\OR\\ + \order{\indexABC}_{i+1}\neq\order{\indexABC}_{i} + \end{cases} + \] + \Then $\order{\valABC}_{i+1} = 0$. + \end{enumerate} +\end{enumerate} + +In other words after reordering $\valABC$ and $\valABC{}\new{}$ as explained above we have, for constant $\order{\cnABC}$ and $\order{\indexABC}$ +\begin{figure} +\[ + \begin{array}{|l|c|c|c|c|c|} + \hline + & \order{\cnABC} & \order{\indexABC} & \order{\mst^{\cc3}} & \phantom{\bigg|}\order{\valABC}\phantom{\bigg|} & \phantom{\bigg|}\order{\valABC\new}\phantom{\bigg|}\\ + \hline + 0\phantom{\Big|} & 0 & ? & 28 & ? & ? \\ + \hline + 1\phantom{\Big|} & 0 & ? & 55 & ? & ? \\ + \hline + 2\phantom{\Big|} & 0 & ? & 117 & ? & ? \\ + \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ + \hline + i \phantom{\Big|} & c & k & 12 & \bm{0} & \bluem{\spadesuit} \\ + \hline + i + 1 \phantom{\Big|} & c & k & 19 & \bluem{\spadesuit} & \bluem{\star} \\ + \hline + i + 2 \phantom{\Big|} & c & k & 20 & \bluem{\star} & \bluem{\Box}\\ + \hline + i + 3 \phantom{\Big|} & c & k & 38 & \bluem{\square} & \bluem{\heartsuit} \\ + \hline + i + 4 \phantom{\Big|} & c' & l & 23 & \bm{0} & \greenm{\dagger} \\ + \hline + i + 5 \phantom{\Big|} & c' & l & {\cellcolor{\romCol}27} & \greenm{\dagger} & \greenm{\Diamond} \\ + \hline + i + 6 \phantom{\Big|} & c' & l + 1 & 24 & \bm{0} & \redm{\bowtie} \\ + \hline + i + 7 \phantom{\Big|} & c' & l + 1 & {\cellcolor{\romCol}27} & \redm{\bowtie} & \redm{\ddagger} \\ + \hline + i + 8 \phantom{\Big|} & c' & l + 1 & {\cellcolor{\stackCol}33} & \redm{\ddagger} & \redm{\ddagger} \\ + \hline + i + 9 \phantom{\Big|} & c' & l + 1 & 36 & \redm{\ddagger} & \redm{\clubsuit} \\ + \hline + i + 10 \phantom{\Big|} & c' & l + 1 & 37 & \redm{\clubsuit} & \redm{\circledcirc} \\ + \hline + i + 11 \phantom{\Big|} & c' & l + 2 & 25 & \bm{0} & \yellowm{\bigstar} \\ + \hline + i + 12 \phantom{\Big|} & c' & l + 2 & 26 & \yellowm{\bigstar} & \yellowm{\blacktriangle} \\ + \hline + i + 13 \phantom{\Big|} & c' & l + 2 & {\cellcolor{\romCol}27} & \yellowm{\blacktriangle} & \yellowm{\sharp} \\ + \hline + i + 14 \phantom{\Big|} & c' & l + 2 & {\cellcolor{\stackCol}33} & \yellowm{\sharp} & \yellowm{\sharp} \\ + \hline + i + 15 \phantom{\Big|} & c' & l + 2 & 43 & \yellowm{\sharp} & \yellowm{\sphericalangle} \\ + \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots + \end{array} +\] +\caption{% +$\MST{} = 27$ appears thrice (as is to be expected) and the three rows in question ($i+5, i+7, i+13$) the values are taken from the same execution context ($c'$) in consecutive limbs ($l$, $l+1$, $l+2$) and the values in RAM are changed% +($\greenm{\dagger} \rightsquigarrow \greenm{\Diamond}$, $\redm{\bowtie} \rightsquigarrow \redm{\ddagger}$ and% +$\yellowm{\blacktriangle} \rightsquigarrow \yellowm{\sharp}$). This is compatible with the 27th micro RAM operation being a non aligned \inst{MSTORE} (in theory it could also be part of a non aligned \inst{(EXT)CODECOPY}.) In a similar vein, note that the 33rd micro RAM operation (i.e. $\MST{} = 33$) touches two consecutive RAM locations ($l+2$ and $l+2$) in that same execution context $c'$ without modifying their values ($\redm{\ddagger} \rightsquigarrow \redm{\ddagger}$ and $\yellowm{\sharp} \rightsquigarrow \yellowm{\sharp}$). This could be part of an aligned or non aligned logging operation, an aligned or non aligned \inst{MLOAD}, a successful \inst{RETURN} in a deployment context ($\cType = 1$) among other options. (If we wanted to more information we would have to find what other context is activated at $\MST{} = 33$, or better yet: consult the non reordered exeuction trace). +} +\end{figure} \ No newline at end of file diff --git a/mmio/drawing/1_full_to_2.png b/mmio/drawing/1_full_to_2.png new file mode 100644 index 0000000..181928d Binary files /dev/null and b/mmio/drawing/1_full_to_2.png differ diff --git a/mmio/drawing/1_partial_to_1.png b/mmio/drawing/1_partial_to_1.png new file mode 100644 index 0000000..80882d3 Binary files /dev/null and b/mmio/drawing/1_partial_to_1.png differ diff --git a/mmio/drawing/1_partial_to_2.png b/mmio/drawing/1_partial_to_2.png new file mode 100644 index 0000000..95f9481 Binary files /dev/null and b/mmio/drawing/1_partial_to_2.png differ diff --git a/mmio/drawing/1_to_1_padded.png b/mmio/drawing/1_to_1_padded.png new file mode 100644 index 0000000..6265a95 Binary files /dev/null and b/mmio/drawing/1_to_1_padded.png differ diff --git a/mmio/drawing/1_to_1_padded_and_zero.png b/mmio/drawing/1_to_1_padded_and_zero.png new file mode 100644 index 0000000..bcbe7a9 Binary files /dev/null and b/mmio/drawing/1_to_1_padded_and_zero.png differ diff --git a/mmio/drawing/2_full_to_3.png b/mmio/drawing/2_full_to_3.png new file mode 100644 index 0000000..93e0f15 Binary files /dev/null and b/mmio/drawing/2_full_to_3.png differ diff --git a/mmio/drawing/2_to_1_and_zero.png b/mmio/drawing/2_to_1_and_zero.png new file mode 100644 index 0000000..3995ede Binary files /dev/null and b/mmio/drawing/2_to_1_and_zero.png differ diff --git a/mmio/drawing/2_to_1_full.png b/mmio/drawing/2_to_1_full.png new file mode 100644 index 0000000..3f72c3c Binary files /dev/null and b/mmio/drawing/2_to_1_full.png differ diff --git a/mmio/drawing/2_to_1_padded.png b/mmio/drawing/2_to_1_padded.png new file mode 100644 index 0000000..de31b45 Binary files /dev/null and b/mmio/drawing/2_to_1_padded.png differ diff --git a/mmio/drawing/2_to_1_padded_and_zero.png b/mmio/drawing/2_to_1_padded_and_zero.png new file mode 100644 index 0000000..3e5799d Binary files /dev/null and b/mmio/drawing/2_to_1_padded_and_zero.png differ diff --git a/mmio/drawing/2_to_1_partial.png b/mmio/drawing/2_to_1_partial.png new file mode 100644 index 0000000..9e057ee Binary files /dev/null and b/mmio/drawing/2_to_1_partial.png differ diff --git a/mmio/drawing/2_to_2_padded.png b/mmio/drawing/2_to_2_padded.png new file mode 100644 index 0000000..1e390da Binary files /dev/null and b/mmio/drawing/2_to_2_padded.png differ diff --git a/mmio/drawing/3_to_2_full.png b/mmio/drawing/3_to_2_full.png new file mode 100644 index 0000000..c271172 Binary files /dev/null and b/mmio/drawing/3_to_2_full.png differ diff --git a/mmio/drawing/3_to_2_padded.png b/mmio/drawing/3_to_2_padded.png new file mode 100644 index 0000000..d54d606 Binary files /dev/null and b/mmio/drawing/3_to_2_padded.png differ diff --git a/mmio/drawing/bla.png b/mmio/drawing/bla.png new file mode 100644 index 0000000..f8e91fd Binary files /dev/null and b/mmio/drawing/bla.png differ diff --git a/mmio/drawing/byte_swap.png b/mmio/drawing/byte_swap.png new file mode 100644 index 0000000..4c9cc8f Binary files /dev/null and b/mmio/drawing/byte_swap.png differ diff --git a/mmio/drawing/excision.png b/mmio/drawing/excision.png new file mode 100644 index 0000000..1171090 Binary files /dev/null and b/mmio/drawing/excision.png differ diff --git a/mmio/drawing/preprocessing/offset_and_size_1.png b/mmio/drawing/preprocessing/offset_and_size_1.png new file mode 100644 index 0000000..3fd9ae6 Binary files /dev/null and b/mmio/drawing/preprocessing/offset_and_size_1.png differ diff --git a/mmio/drawing/preprocessing/offset_and_size_many.png b/mmio/drawing/preprocessing/offset_and_size_many.png new file mode 100644 index 0000000..a1d6c9e Binary files /dev/null and b/mmio/drawing/preprocessing/offset_and_size_many.png differ diff --git a/mmio/drawing/preprocessing/slide_chunk_no_overlap.png b/mmio/drawing/preprocessing/slide_chunk_no_overlap.png new file mode 100644 index 0000000..477b87b Binary files /dev/null and b/mmio/drawing/preprocessing/slide_chunk_no_overlap.png differ diff --git a/mmio/drawing/preprocessing/slide_chunk_with_overlap.png b/mmio/drawing/preprocessing/slide_chunk_with_overlap.png new file mode 100644 index 0000000..77e2120 Binary files /dev/null and b/mmio/drawing/preprocessing/slide_chunk_with_overlap.png differ diff --git a/mmio/drawing/preprocessing/transition_no_overlap.png b/mmio/drawing/preprocessing/transition_no_overlap.png new file mode 100644 index 0000000..ba1564d Binary files /dev/null and b/mmio/drawing/preprocessing/transition_no_overlap.png differ diff --git a/mmio/drawing/preprocessing/transition_with_overlap.png b/mmio/drawing/preprocessing/transition_with_overlap.png new file mode 100644 index 0000000..4b307d3 Binary files /dev/null and b/mmio/drawing/preprocessing/transition_with_overlap.png differ diff --git a/mmio/drawing/zkevm_organization.png b/mmio/drawing/zkevm_organization.png new file mode 100644 index 0000000..f2319d0 Binary files /dev/null and b/mmio/drawing/zkevm_organization.png differ diff --git a/mmio/drawing/zkevm_organization_.png b/mmio/drawing/zkevm_organization_.png new file mode 100644 index 0000000..939137f Binary files /dev/null and b/mmio/drawing/zkevm_organization_.png differ diff --git a/mmio/drawing/zkevm_organization_white_background.png b/mmio/drawing/zkevm_organization_white_background.png new file mode 100644 index 0000000..df1c9ce Binary files /dev/null and b/mmio/drawing/zkevm_organization_white_background.png differ diff --git a/mmio/generalities/binary.tex b/mmio/generalities/binary.tex new file mode 100644 index 0000000..3eeedcc --- /dev/null +++ b/mmio/generalities/binary.tex @@ -0,0 +1,15 @@ +We impose the following columns to be binary columns: +\begin{multicols}{2} + \begin{enumerate} + \item $\successBit{}$ \quad (\trash) + \item \fastOp{} \quad (\trash) + \item \slowOp{} \quad (\trash) + \item \bit{1} \quad (\trash) + \item \bit{2} \quad (\trash) + \item \bit{3} \quad (\trash) + \item \bit{4} \quad (\trash) + \item \bit{5} \quad (\trash) + \end{enumerate} +\end{multicols} + +We remind the reader that all the decoded flag columns are already imposed being binaries, see \ref{mmio: instruction decoding} \ No newline at end of file diff --git a/mmio/generalities/byte_decomposition.tex b/mmio/generalities/byte_decomposition.tex new file mode 100644 index 0000000..dcdf02c --- /dev/null +++ b/mmio/generalities/byte_decomposition.tex @@ -0,0 +1,10 @@ +We enforce the following byte decomposition constraints: +\[ + \begin{cases} + \byteDec(\valA, \byteA, \acc{A}), \\ + \byteDec(\valB, \byteB, \acc{B}), \\ + \byteDec(\valC, \byteC, \acc{C}), \\ + \byteDec(\limb, \byteLimb, \acc{LIMB}), \\ + \end{cases} +\] +\saNote{} Only some of these byte decompositions matter at any one point in time. In particular, they will be irrelevant for ``fast'' operations. diff --git a/mmio/generalities/bytehood.tex b/mmio/generalities/bytehood.tex new file mode 100644 index 0000000..348f90f --- /dev/null +++ b/mmio/generalities/bytehood.tex @@ -0,0 +1,9 @@ +The following columns must contain bytes: +\begin{multicols}{4} +\begin{enumerate} + \item $\byteA{}$, + \item $\byteB{}$, + \item $\byteC{}$, + \item $\byteLimb{}$, +\end{enumerate} +\end{multicols} diff --git a/mmio/generalities/constancies.tex b/mmio/generalities/constancies.tex new file mode 100644 index 0000000..160ebcc --- /dev/null +++ b/mmio/generalities/constancies.tex @@ -0,0 +1,46 @@ +As per usual we say that a column \col{X} is \textbf{counter-constant}\label{def: counter constant column} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We impose counter-constancy on the following columns +\begin{multicols}{5} + \begin{enumerate} + \item \cnA{} + \item \cnB{} + \item \cnC{} + \item \indexA{} + \item \indexB{} + \item \indexC{} + \item \valA{} + \item \valB{} + \item \valC{} + \item $\valA\new$ + \item $\valB\new$ + \item $\valC\new$ + \item \indexX{} + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} The lookup into the \mmuMod{}, see section~(\ref{mmio: lookups: mmu}), implicitly imposes counter-constancy of the following columns: +\begin{multicols}{3} + \begin{enumerate} + \item $\mmioStamp$ + \item $\microInst$ + \item $\size$ + \item $\slo$ + \item $\sbo$ + \item $\tlo$ + \item $\tbo$ + \item $\limb$ + \item $\cnS$ + \item $\cnT$ + \item $\successBit$ + \item $\exoSum$ + \item $\Phase$ + \item $\idOne$ + \item $\idTwo$ + \item $\totalSize$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/mmio/generalities/decoding.tex b/mmio/generalities/decoding.tex new file mode 100644 index 0000000..d936b13 --- /dev/null +++ b/mmio/generalities/decoding.tex @@ -0,0 +1,114 @@ +\begin{enumerate} + \item We impose that the following columns be \textbf{binary}: + \begin{enumerate} + \item \isMmioInstLimbVanishes{} + \item \isMmioInstLimbToRamTransplant{} + \item \isMmioInstLimbToRamOneTarget{} + \item \isMmioInstLimbToRamTwoTarget{} + \item \isMmioInstRamToLimbTransplant{} + \item \isMmioInstRamToLimbOneSource{} + \item \isMmioInstRamToLimbTwoSource{} + \item \isMmioInstRamToRamTransplant{} + \item \isMmioInstRamToRamPartial{} + \item \isMmioInstRamToRamTwoTarget{} + \item \isMmioInstRamToRamTwoSource{} + \item \isMmioInstRamExcision{} + \item \isMmioInstRamVanishes{} + \end{enumerate} + \item $\mmioInst = \col{mmio\_inst\_weight\_sum}_{i}$ where we define: + \[ + \hspace*{-3.5cm} + \col{mmio\_inst\_weight\_sum}_{i} \define + \left[ \begin{array}{crcl} + + & \mmioInstLimbVanishes & \!\!\!\cdot\!\!\! & \isMmioInstLimbVanishes _{i} \\ + + & \mmioInstLimbToRamTransplant & \!\!\!\cdot\!\!\! & \isMmioInstLimbToRamTransplant _{i} \\ + + & \mmioInstLimbToRamOneTarget & \!\!\!\cdot\!\!\! & \isMmioInstLimbToRamOneTarget _{i} \\ + + & \mmioInstLimbToRamTwoTarget & \!\!\!\cdot\!\!\! & \isMmioInstLimbToRamTwoTarget _{i} \\ + + & \mmioInstRamToLimbTransplant & \!\!\!\cdot\!\!\! & \isMmioInstRamToLimbTransplant _{i} \\ + + & \mmioInstRamToLimbOneSource & \!\!\!\cdot\!\!\! & \isMmioInstRamToLimbOneSource _{i} \\ + + & \mmioInstRamToLimbTwoSource & \!\!\!\cdot\!\!\! & \isMmioInstRamToLimbTwoSource _{i} \\ + + & \mmioInstRamToRamTransplant & \!\!\!\cdot\!\!\! & \isMmioInstRamToRamTransplant _{i} \\ + + & \mmioInstRamToRamPartial & \!\!\!\cdot\!\!\! & \isMmioInstRamToRamPartial _{i} \\ + + & \mmioInstRamToRamTwoTarget & \!\!\!\cdot\!\!\! & \isMmioInstRamToRamTwoTarget _{i} \\ + + & \mmioInstRamToRamTwoSource & \!\!\!\cdot\!\!\! & \isMmioInstRamToRamTwoSource _{i} \\ + + & \mmioInstRamExcision & \!\!\!\cdot\!\!\! & \isMmioInstRamExcision _{i} \\ + + & \mmioInstRamVanishes & \!\!\!\cdot\!\!\! & \isMmioInstRamVanishes _{i} \\ + \end{array} \right] + \] + \item $\fastOp_{i} = \locFastOpFlagSum_{i}$ where we define: + \[ + \locFastOpFlagSum_{i} \define + \left[ \begin{array}{rcl} + + & \!\!\! & \isMmioInstLimbVanishes _{i} \\ + + & \!\!\! & \isMmioInstLimbToRamTransplant _{i} \\ + + & \!\!\! & \isMmioInstRamToLimbTransplant _{i} \\ + + & \!\!\! & \isMmioInstRamToRamTransplant _{i} \\ + + & \!\!\! & \isMmioInstRamVanishes _{i} \\ + \end{array} \right] + \] + \item $\slowOp_{i} = \locSlowOpFlagSum_{i}$ where we define: + \[ + \locSlowOpFlagSum_{i} \define + \left[ \begin{array}{rcl} + + & \!\!\! & \isMmioInstLimbToRamOneTarget _{i} \\ + + & \!\!\! & \isMmioInstLimbToRamTwoTarget _{i} \\ + + & \!\!\! & \isMmioInstRamToLimbOneSource _{i} \\ + + & \!\!\! & \isMmioInstRamToLimbTwoSource _{i} \\ + + & \!\!\! & \isMmioInstRamToRamPartial _{i} \\ + + & \!\!\! & \isMmioInstRamToRamTwoTarget _{i} \\ + + & \!\!\! & \isMmioInstRamToRamTwoSource _{i} \\ + + & \!\!\! & \isMmioInstRamExcision _{i} \\ + \end{array} \right] + \] + \item we further impose that $\locOpFlagSum_{i} \define \locSlowOpFlagSum_{i} + \locSlowOpFlagSum_{i}$ satisfy the following standard constraints: + \begin{enumerate} + \item \If $\mmioStamp_{i} = 0$ \Then $\locOpFlagSum_{i} = 0$ + \item \If $\mmioStamp_{i} \neq 0$ \Then $\locOpFlagSum_{i} = 1$ + \end{enumerate} + \item We impose that the following columns be \textbf{binary}: + \begin{multicols}{2} + \begin{enumerate} + \item \isExoFlagRom {} + \item \isExoFlagKec {} + \item \isExoFlagLog {} + \item \isExoFlagRlpTxn {} + \item \isExoFlagEcdata {} + \item \isExoFlagRipSha {} + \item \isExoFlagBlakeModexp {} + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item \If $\locInstructionMayProvideExoSum_{i} = 1$ \Then $\locWeightedExoSum_{i} = \exoSum_{i}$ + \item \If $\locInstructionMayProvideExoSum_{i} = 0$ \Then $\locWeightedExoSum_{i} = 0$ + where we define: + \[ + \locWeightedExoSum_{i} \define + \left[ \begin{array}{crcl} + + & \exoWeightRom & \!\!\!\cdot\!\!\! & \isExoFlagRom _{i} \\ + + & \exoWeightKec & \!\!\!\cdot\!\!\! & \isExoFlagKec _{i} \\ + + & \exoWeightLog & \!\!\!\cdot\!\!\! & \isExoFlagLog _{i} \\ + + & \exoWeightRlpTxn & \!\!\!\cdot\!\!\! & \isExoFlagRlpTxn _{i} \\ + + & \exoWeightEcdata & \!\!\!\cdot\!\!\! & \isExoFlagEcdata _{i} \\ + + & \exoWeightRipSha & \!\!\!\cdot\!\!\! & \isExoFlagRipSha _{i} \\ + + & \exoWeightBlakeModexp & \!\!\!\cdot\!\!\! & \isExoFlagBlakeModexp _{i} \\ + \end{array} \right] + \] + and + \[ + \locInstructionMayProvideExoSum_{i} \define + \left[ \begin{array}{rcl} + + & \!\!\! & \isMmioInstLimbToRamTransplant _{i} \\ + + & \!\!\! & \isMmioInstLimbToRamOneTarget _{i} \\ + + & \!\!\! & \isMmioInstLimbToRamTwoTarget _{i} \\ + + & \!\!\! & \isMmioInstRamToLimbTransplant _{i} \\ + + & \!\!\! & \isMmioInstRamToLimbOneSource _{i} \\ + + & \!\!\! & \isMmioInstRamToLimbTwoSource _{i} \\ + \end{array} \right] + \] + + \saNote{} This constraint imposes in particular the vanishing of all exogenous data flags on padding-rows. + Its primary purpose is to prevent lookups to exo data modules when the underlying instruction can never require it. + Such lookups, in particular if they target the \romMod{}, could have undesirable consequences. + + \saNote{} The \mmioMod{} module triggers lookups whenever the corresponding module flag is nonzero. If we didn't impose the above, the lookup would remain active in the padding phase which may occur for certain instructions. This would lead to failing lookups. +\end{enumerate} diff --git a/mmio/generalities/heartbeat.tex b/mmio/generalities/heartbeat.tex new file mode 100644 index 0000000..df7f161 --- /dev/null +++ b/mmio/generalities/heartbeat.tex @@ -0,0 +1,23 @@ +The columns $\mmioStamp$, \fastOp{}, \slowOp{} and \ct{} impose a heartbeat on the \mmioMod{} module. We ask that they satisfy the following constraints: +\begin{enumerate} + \item $\mmioStamp_{0} = 0$; + \item $\mmioStamp_{i+1}\in\{\mmioStamp_{i}, 1+\mmioStamp_{i}\}$\footnote{i.e. $(\mmioStamp_{i+1}-\mmioStamp_{i})\cdot(\mmioStamp_{i+1}-\mmioStamp_{i}-1)=0$}; + \item \If $\mmioStamp_{i} = 0$ \Then + \begin{enumerate} + \item $\microInst_{i}=0$ \quad (\trash) + \item $\exoSum_{i}=0$ \quad (\trash) + \item $\ct_{i+1} = 0$ \quad (\trash) + \end{enumerate} + \item \If $\mmioStamp_{i} \neq \mmioStamp_{i - 1}$ \Then $\ct_{i}=0$ + \item \If $\fastOp_{i} = 1$ \Then $\mmioStamp_{i+1} = 1 + \mmioStamp_{i}$ + \item \If $\slowOp_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \llargeMO$ \Then $\ct_{i+1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \llargeMO$ \Then $\mmioStamp_{i+1} = 1 + \mmioStamp_{i}$ + \end{enumerate} + \item \If $\mmioStamp_N \neq 0$ \Then + \begin{enumerate} + \item \If $\fastOp_{N} = 1$ no finalization contraint required; + \item \If $\slowOp_{N} = 1$ \Then $\ct_{N} = \llargeMO$ + \end{enumerate} +\end{enumerate} diff --git a/mmio/lookups/_inputs.tex b/mmio/lookups/_inputs.tex new file mode 100644 index 0000000..fdda49e --- /dev/null +++ b/mmio/lookups/_inputs.tex @@ -0,0 +1,9 @@ +\subsection{\mmioMod{} into \mmuMod{}} \label{mmio: lookups: mmu} \input{lookups/mmio_into_mmu} +\subsection{\mmioMod{} into \blkMdxMod{}} \label{mmio: lookups: blakemodexp} \input{lookups/mmio_into_blakemodexp} +\subsection{\mmioMod{} into \ecDataMod{}} \label{mmio: lookups: ecdata} \input{lookups/mmio_into_ecdata} +\subsection{\mmioMod{} into \logDataMod{}} \label{mmio: lookups: log} \input{lookups/mmio_into_log} +\subsection{\mmioMod{} into \shakiraMod{} for \texttt{SHA2-256} and \texttt{RIPEMD-160}} \label{mmio: lookups: shakira for sha2 and ripe} \input{lookups/mmio_into_shakira_for_sha2_and_ripe} +\subsection{\mmioMod{} into \shakiraMod{} for \texttt{KECCAK}} \label{mmio: lookups: shakira for keccak} \input{lookups/mmio_into_shakira_for_keccak} +\subsection{\mmioMod{} into \romMod{}} \label{mmio: lookups: rom} \input{lookups/mmio_into_rom} +\subsection{\mmioMod{} into \rlpTxnMod{}} \label{mmio: lookups: txcd} \input{lookups/mmio_into_txcd} + diff --git a/mmio/lookups/mmio_into_blakemodexp.tex b/mmio/lookups/mmio_into_blakemodexp.tex new file mode 100644 index 0000000..86a6c12 --- /dev/null +++ b/mmio/lookups/mmio_into_blakemodexp.tex @@ -0,0 +1,25 @@ +The lookup to the $\blkMdxMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagBlakeModexp$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{4} + \begin{enumerate} + \item $\idOne_{i}$ + \item $\Phase_{i}$ + \item $\indexX_{i}$ + \item $\limb_{i}$ +% \item $\size_{i}$ +% \item $\totalSize_{i}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \blkMdxMod{} module: + \begin{multicols}{4} + \begin{enumerate} + \item $\modexpBlakeId_{j}$ + \item $\modexpBlakePhase_{j}$ + \item $\index_{j}$ + \item $\limb_{j}$ + \end{enumerate} + \end{multicols} +\end{description} \ No newline at end of file diff --git a/mmio/lookups/mmio_into_ecdata.tex b/mmio/lookups/mmio_into_ecdata.tex new file mode 100644 index 0000000..f6a5bc8 --- /dev/null +++ b/mmio/lookups/mmio_into_ecdata.tex @@ -0,0 +1,20 @@ +The lookup to the $\ecDataMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagEcdata$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\idOne_{i}$ + \item $\Phase_{i}$ + \item $\indexX_{i}$ + \item $\limb_{i}$ + \item $\size_{i}$ + \item $\totalSize_{i}$ + \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \ecDataMod{} module: + \[ + \ob{TODO: update column names} + \] +\end{description} \ No newline at end of file diff --git a/mmio/lookups/mmio_into_log.tex b/mmio/lookups/mmio_into_log.tex new file mode 100644 index 0000000..98a9ecb --- /dev/null +++ b/mmio/lookups/mmio_into_log.tex @@ -0,0 +1,26 @@ +The lookup to the $\logDataMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagLog$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\idOne_{i}$ +% \item $\Phase_{i}$ + \item $\indexX_{i}$ + \item $\limb_{i}$ + \item $\size_{i}$ + \item $\totalSize_{i}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \logDataMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\absLogNum_{j}$ + \item $\index_{j}$ + \item $\limb_{j}$ + \item $\limbSize_{j}$ + \item $\logDataSize_{j}$ + \end{enumerate} + \end{multicols} +\end{description} \ No newline at end of file diff --git a/mmio/lookups/mmio_into_mmu.tex b/mmio/lookups/mmio_into_mmu.tex new file mode 100644 index 0000000..f25c693 --- /dev/null +++ b/mmio/lookups/mmio_into_mmu.tex @@ -0,0 +1,52 @@ +The lookup to the $\mmioMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] none required; + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{2} + \begin{enumerate} + \item $\locOpFlagSum_{i}$ + \item $\mmioStamp_{i}$ + \item $\microInst_{i}$ + \item $\size_{i}$ + \item $\slo_{i}$ + \item $\sbo_{i}$ + \item $\tlo_{i}$ + \item $\tbo_{i}$ + \item $\limb_{i}$ + \item $\cnS_{i}$ + \item $\cnT_{i}$ + \item $\successBit_{i}$ + \item $\exoSum_{i}$ + \item $\Phase_{i}$ + \item $\idOne_{i}$ + \item $\idTwo_{i}$ + \item $\totalSize_{i}$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \mmuMod{} module: + \begin{multicols}{2} + \begin{enumerate} + \item $\isMicro_{j}$ + \item $\microStamp_{j}$ + \item $\microInst_{j}$ + \item $\microSize_{j}$ + \item $\microSlo_{j}$ + \item $\microSbo_{j}$ + \item $\microTlo_{j}$ + \item $\microTbo_{j}$ + \item $\microLimb_{j}$ + \item $\microCns_{j}$ + \item $\microCnt_{j}$ + \item $\microSuccessBit_{j}$ + \item $\microExoSum_{j}$ + \item $\microPhase_{j}$ + \item $\microIdOne_{j}$ + \item $\microIdTwo_{j}$ + \item $\microTotalSize_{j}$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +The above provides the \mmioMod{} with automatic counter-constancies for all source columns. diff --git a/mmio/lookups/mmio_into_rom.tex b/mmio/lookups/mmio_into_rom.tex new file mode 100644 index 0000000..f936709 --- /dev/null +++ b/mmio/lookups/mmio_into_rom.tex @@ -0,0 +1,26 @@ +The lookup to the $\romMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagRom$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\idOne_{i}$ +% \item $\Phase_{i}$ + \item $\indexX_{i}$ + \item $\limb_{i}$ + \item $\size_{i}$ + \item $\totalSize_{i}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \romMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi_{j}$ + \item $\index_{j}$ + \item $\limb_{j}$ + \item $\nBytes_{j}$ + \item $\CS_{j}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/mmio/lookups/mmio_into_shakira_for_keccak.tex b/mmio/lookups/mmio_into_shakira_for_keccak.tex new file mode 100644 index 0000000..8f1866a --- /dev/null +++ b/mmio/lookups/mmio_into_shakira_for_keccak.tex @@ -0,0 +1,37 @@ +The lookup to the \shakiraMod{} is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagKec$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\idTwo_{i}$ + \item $\phaseKeccakData$ + \item $\indexX_{i}$ + \item $\limb_{i}$ + \item $\size_{i}$ + \item $\totalSize_{i}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \saNote{} + We provide the ``phase'' value manually. + \item[\underline{Target columns:}] from the \shakiraMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\shakiraId_{j}$ + \item $\shakiraPhase_{j}$ + \item $\index_{j}$ + \item $\limb_{j}$ + \item $\nBytes_{j}$ + \item $\shakiraTotalSize_{j}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} +\end{description} + +\saNote{} There are three different \hubMod{} instructions triggering the present lookup: +(\emph{a}) \inst{SHA3} when hashing a (nonempty) slice of bytes, +(\emph{b}) \inst{RETURN} when (temporarily) deploying (nonempty) bytecode, +(\emph{c}) \inst{CREATE2} when hashing (nonempty) initialization code. +All three of which enter the \mmuMod{} by means of a \mmuInstRamToExoWithPadding{} instruction. +Inspecting the \hubMod{} / \mmuMod{} interface, see section~(\ref{mmu: hub / mmu interface}), one notices that no \macroPhase{} is provided by said instruction, yet the \shakiraMod{} requires a phase and hence the lookup requires one too. This phase is provided in the above. diff --git a/mmio/lookups/mmio_into_shakira_for_sha2_and_ripe.tex b/mmio/lookups/mmio_into_shakira_for_sha2_and_ripe.tex new file mode 100644 index 0000000..8780653 --- /dev/null +++ b/mmio/lookups/mmio_into_shakira_for_sha2_and_ripe.tex @@ -0,0 +1,28 @@ +The lookup to the $\shakiraMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagRipSha$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\idOne_{i}$ + \item $\Phase_{i}$ + \item $\indexX_{i}$ + \item $\limb_{i}$ + \item $\size_{i}$ + \item $\totalSize_{i}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \shakiraMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\shakiraId_{j}$ + \item $\shakiraPhase_{j}$ + \item $\index_{j}$ + \item $\limb_{j}$ + \item $\nBytes_{j}$ + \item $\shakiraTotalSize_{j}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/mmio/lookups/mmio_into_txcd.tex b/mmio/lookups/mmio_into_txcd.tex new file mode 100644 index 0000000..46bcfef --- /dev/null +++ b/mmio/lookups/mmio_into_txcd.tex @@ -0,0 +1,27 @@ +The lookup to the $\rlpTxnMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isExoFlagRlpTxn$ + \item[\underline{Source columns:}] from the \mmioMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\idOne_{i}$ + \item $1$ + \item $\Phase_{i}$ + \item $\indexX_{i}$ + \item $\limb_{i}$ +% \item $\totalSize_{i}$ +% \item $\successBit_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \rlpTxnMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\absTxNum_{j}$ + \item $\lc_{j}$ + \item $\Phase_{j}$ + \item $\indexData_{j}$ + \item $\limb_{j}$ +% \item $\outgoingDataSymb\low_{j}$ + \end{enumerate} + \end{multicols} +\end{description} \ No newline at end of file diff --git a/mmio/lua/mmu_mmio_interface.lua.tex b/mmio/lua/mmu_mmio_interface.lua.tex new file mode 100644 index 0000000..bc0eb5b --- /dev/null +++ b/mmio/lua/mmu_mmio_interface.lua.tex @@ -0,0 +1,84 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██████\ ██████\ ██\ ██\ ██████\ + ███\ ███ |███\ ███ |██ | ██ | ██ | ███\ ███ |███\ ███ |\_██ _|██ __██\ \__| ██ | ██ __██\ + ████\ ████ |████\ ████ |██ | ██ | ██ / ████\ ████ |████\ ████ | ██ | ██ / ██ | ██\ ███████\ ██████\ ██████\ ██████\ ██ / \__|██████\ ███████\ ██████\ + ██\██\██ ██ |██\██\██ ██ |██ | ██ | ██ / ██\██\██ ██ |██\██\██ ██ | ██ | ██ | ██ | ██ |██ __██\\_██ _| ██ __██\ ██ __██\ ████\ \____██\ ██ _____|██ __██\ + ██ \███ ██ |██ \███ ██ |██ | ██ | ██ / ██ \███ ██ |██ \███ ██ | ██ | ██ | ██ | ██ |██ | ██ | ██ | ████████ |██ | \__|██ _| ███████ |██ / ████████ | + ██ |\█ /██ |██ |\█ /██ |██ | ██ | ██ / ██ |\█ /██ |██ |\█ /██ | ██ | ██ | ██ | ██ |██ | ██ | ██ |██\ ██ ____|██ | ██ | ██ __██ |██ | ██ ____| + ██ | \_/ ██ |██ | \_/ ██ |\██████ | ██ / ██ | \_/ ██ |██ | \_/ ██ |██████\ ██████ | ██ |██ | ██ | \████ |\███████\ ██ | ██ | \███████ |\███████\ \███████\ + \__| \__|\__| \__| \______/ \__/ \__| \__|\__| \__|\______| \______/ \__|\__| \__| \____/ \_______|\__| \__| \_______| \_______| \_______| + + + +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| MMIO instruction | direction | CN_S | SLO | SBO | CN_T | TLO | TBO | SIZE | LIMB | TOTAL_SIZE | EXO_SUM | ID_1 | ID_2 | PHASE | SUCCESS_BIT | MMU users | +|---------------------------------+:---------:+:----:+:---:+:---:+:----:+:---:+:---:+:----:+:----:+:----------:+:-------:+:----:+:----:+:-----:+:-----------:+-------------------------------------:| +| ⟦MMIO_INST_limbToRamTranplant⟧ | R <== L | | (✗) | | ✗ | ✗ | | | ✗ | | ✗ | (✗) | | (✗) | | ⟦MMU_INST_mstore⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_exoToRamTransplants⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_limbToRamOneTarget⟧ | R <== L | | (✗) | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | | ✗ | (✗) | | | | ⟦MMU_INST_mstore8⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_limbToRamTwoTarget⟧ | R <== L | | (✗) | (✗) | ✗ | ✗ | ✗ | ✗ | ✗ | | ✗ | (✗) | | | | ⟦MMU_INST_mstore⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToLimbTransplant⟧ | L <== R | ✗ | ✗ | | | (✗) | | | ✗ | (✗) | ✗ | (✗) | (✗) | (✗) | (✗) | ⟦MMU_INST_ramToExoWithPadding⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_mload⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_rightPaddedWordExtraction⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_modexpData⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToLimbOneSource⟧ | L <== R | ✗ | ✗ | ✗ | | (✗) | ✗ | ✗ | ✗ | (✗) | ✗ | (✗) | (✗) | (✗) | (✗) | ⟦MMU_INST_ramToExoWithPadding⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_rightPaddedWordExtraction⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_blake⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_modexpData⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_invalidCodePrefix⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToLimbTwoSource⟧ | L <== R | ✗ | ✗ | ✗ | | (✗) | ✗ | ✗ | ✗ | (✗) | ✗ | (✗) | (✗) | (✗) | (✗) | ⟦MMU_INST_ramToExoWithPadding⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_mload⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_rightPaddedWordExtraction⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_blake⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_modexpData⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_limbVanishes⟧ | L | | | | | (✗) | | | | | ✗ | (✗) | | (✗) | (✗) | ⟦MMU_INST_ramToExoWithPadding⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_rightPaddedWordExtraction⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_modexpData⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_INST_modexpZero⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToRamTransplant⟧ | R <== R | ✗ | ✗ | | ✗ | ✗ | | | | | | | | | | ⟦MMU_INST_ramToRamSansPadding⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToRamOnePartial⟧ | R <== R | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | | | | | | | | ⟦MMU_INST_ramToRamSansPadding⟧ | +| | | | | | | | | | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToRamTwoSource⟧ | R <== R | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | | | | | | | | ⟦MMU_INST_ramToRamSansPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramToRamTwoTarget⟧ | R <== R | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramExcision⟧ | R | | | | ✗ | ✗ | ✗ | ✗ | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +| ⟦MMIO_INST_ramVanishes⟧ | R | | | | ✗ | ✗ | | | | | | | | | | ⟦MMU_ISNT_anyToRamWithPadding⟧ | +|---------------------------------+-----------+------+-----+-----+------+-----+-----+------+------+------------+---------+------+------+-------+-------------+--------------------------------------| +``(✗)'' means it's only needed when the EXO_SUM is non-zero. + +\end{verbatim} +\end{document} diff --git a/mmio/mmio_instruction/_inputs.tex b/mmio/mmio_instruction/_inputs.tex new file mode 100644 index 0000000..749cdd4 --- /dev/null +++ b/mmio/mmio_instruction/_inputs.tex @@ -0,0 +1,25 @@ +\subsection{\mmuMod{} / \mmioMod{} interface} \label{mmu: mmu / mmio interface} \includepdf[fitpaper=true, pages={1}]{lua/mmu_mmio_interface.pdf} + + +% Exo +\subsection{$\mmioInstLimbVanishes$} \input{mmio_instruction/limbVanishes} + +% Exo/Stack to Ram +\subsection{$\mmioInstLimbToRamTransplant$} \input{mmio_instruction/limbToRamTransplant} +\subsection{$\mmioInstLimbToRamOneTarget$} \input{mmio_instruction/limbToRamOneTarget} +\subsection{$\mmioInstLimbToRamTwoTarget$} \input{mmio_instruction/limbToRamTwoTarget} + +% Ram to Exo/Stack +\subsection{$\mmioInstRamToLimbTransplant$} \input{mmio_instruction/ramToLimbTransplant} +\subsection{$\mmioInstRamToLimbOneSource$} \input{mmio_instruction/ramToLimbOneSource} +\subsection{$\mmioInstRamToLimbTwoSource$} \input{mmio_instruction/ramToLimbTwoSource} + +% RAM to RAM +\subsection{$\mmioInstRamToRamTransplant$} \input{mmio_instruction/ramToRamTransplant} +\subsection{$\mmioInstRamToRamPartial$} \input{mmio_instruction/ramToRamPartial} +\subsection{$\mmioInstRamToRamTwoTarget$} \input{mmio_instruction/ramToRamTwoTarget} +\subsection{$\mmioInstRamToRamTwoSource$} \input{mmio_instruction/ramToRamTwoSource} + +% RAM +\subsection{$\mmioInstRamExcision$} \input{mmio_instruction/ramExcision} +\subsection{$\mmioInstRamVanishes$} \input{mmio_instruction/ramVanishes} diff --git a/mmio/mmio_instruction/limbToRamOneTarget.tex b/mmio/mmio_instruction/limbToRamOneTarget.tex new file mode 100644 index 0000000..d0de705 --- /dev/null +++ b/mmio/mmio_instruction/limbToRamOneTarget.tex @@ -0,0 +1,40 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstLimbToRamOneTarget_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnT_{i} \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \tlo_{i} \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valueToBeSet \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \slo_{i} \\ + \limb _{i} & = & \relevantValue \\ + \end{array} + \right. +\] + \item +\[ + \onePartialToOne + \left( + \begin{array}{c} + \limb{}, \valA{}, \valA\new{}; + \byteLimb{}, \byteA{};\\ + \acc{1}, \acc{2}; \pow{1}; \\ + \sbo{}, \tbo{}; \size{};\\ + \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} + \right) +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/limbToRamTransplant.tex b/mmio/mmio_instruction/limbToRamTransplant.tex new file mode 100644 index 0000000..f71c876 --- /dev/null +++ b/mmio/mmio_instruction/limbToRamTransplant.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstLimbToRamTransplant_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnT_{i} \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \tlo_{i} \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \limb_{i} \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \slo_{i} \\ + \limb _{i} & = & \relevantValue \\ + \end{array} + \right. +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/limbToRamTwoTarget.tex b/mmio/mmio_instruction/limbToRamTwoTarget.tex new file mode 100644 index 0000000..1f8270c --- /dev/null +++ b/mmio/mmio_instruction/limbToRamTwoTarget.tex @@ -0,0 +1,44 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstLimbToRamTwoTarget_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnT_{i} \\ + \cnB _{i} & = & \cnT_{i} \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \tlo_{i} \\ + \indexB _{i} & = & \tlo_{i} + 1 \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valueToBeSet \\ + \valB _{i}\new{} & = & \valueToBeSet \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \slo_{i} \\ + \limb _{i} & = & \relevantValue \\ + \end{array} + \right. +\] + \item +\[ + \onePartialToTwo + \left( + \begin{array}{c} + \limb{}, \valA{}, \valB{}, + \valA{}\new, \valB{}\new; + \byteLimb{}, \BYTEA{}, \BYTEB{}; + \\ + \acc{1}, \acc{2}, \acc{3}, \acc{4}; \pow{1}; + \\ + \slo, \tlo, \size{}; + \\ + \bit{1}, \bit{2}, \bit{3}, \bit{4}, \bit{5}; \ct{}; + \end{array} + \right) +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/limbVanishes.tex b/mmio/mmio_instruction/limbVanishes.tex new file mode 100644 index 0000000..2da89e9 --- /dev/null +++ b/mmio/mmio_instruction/limbVanishes.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstLimbVanishes_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & 0 \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \nothing \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \nothing \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \tlo_{i} \\ + \limb _{i} & = & 0 \\ + \end{array} + \right. +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramExcision.tex b/mmio/mmio_instruction/ramExcision.tex new file mode 100644 index 0000000..8d5afbc --- /dev/null +++ b/mmio/mmio_instruction/ramExcision.tex @@ -0,0 +1,39 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamExcision_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnT_{i} \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \tlo_{i} \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valueToBeSet \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \nothing \\ + \limb _{i} & = & \nothing \\ + \end{array} + \right. +\] + \item +\[ + \excision{} + \left( + \begin{array}{c} + \valA{}, \valA{}\new{}; \BYTEA{}; + \acc{1}, \pow{1}; \\ + \tbo{}, \size{}; + \bit{1}, \bit{2}; \ct{}; + \end{array} + \right) +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramToLimbOneSource.tex b/mmio/mmio_instruction/ramToLimbOneSource.tex new file mode 100644 index 0000000..74c7eae --- /dev/null +++ b/mmio/mmio_instruction/ramToLimbOneSource.tex @@ -0,0 +1,37 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToLimbOneSource_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \tlo_{i} \\ + \limb _{i} & = & \valueToBeSet \\ + \end{array} + \right. +\] + \item +\[ + \oneToOnePadded + \left( + \begin{array}{c} + \valA{}, \limb{}; \BYTEA{}; \acc{1}, \pow{1}; \\ + \sbo{}, \size{}; \bit{1}, \bit{2}, \bit{3}; \ct{}; \\ + \end{array} + \right) +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramToLimbTransplant.tex b/mmio/mmio_instruction/ramToLimbTransplant.tex new file mode 100644 index 0000000..9a7899d --- /dev/null +++ b/mmio/mmio_instruction/ramToLimbTransplant.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToLimbTransplant_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \tlo_{i} \\ + \limb _{i} & = & \valA_{i} \\ + \end{array} + \right. +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramToLimbTwoSource.tex b/mmio/mmio_instruction/ramToLimbTwoSource.tex new file mode 100644 index 0000000..d545262 --- /dev/null +++ b/mmio/mmio_instruction/ramToLimbTwoSource.tex @@ -0,0 +1,44 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToLimbTwoSource_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & \cnS_{i} \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \slo_{i}+1 \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \valB_{i} \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \tlo_{i} \\ + \limb _{i} & = & \valueToBeSet \\ + \end{array} + \right. +\] + \item +\[ + \twoToOnePadded + \left( + \begin{array}{c} + \valA{}, \valB{}, \limb{}; \BYTEA{}, \BYTEB{};\\ + \acc{1}, \acc{2}; \pow{1}, \pow{2};\\ + \sbo{}, \size{}; \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} + \right) +\] +\end{enumerate} + + + + + + diff --git a/mmio/mmio_instruction/ramToRamPartial.tex b/mmio/mmio_instruction/ramToRamPartial.tex new file mode 100644 index 0000000..80a58f3 --- /dev/null +++ b/mmio/mmio_instruction/ramToRamPartial.tex @@ -0,0 +1,36 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToRamPartial_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item + \[ + \left\{ \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & \cnT_{i} \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \tlo_{i} \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \valueToBeSet \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \nothing \\ + \limb _{i} & = & \nothing \\ + \end{array} \right. + \] + \item + \[ + \onePartialToOne + \left( \begin{array}{c} + \valA{}, \valB{}, \valB{}\new{}; + \BYTEA{}, \BYTEB{};\\ + \acc{1}, \acc{2}; \pow{1}; \\ + \sbo{}, \tbo{}; \size{};\\ + \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} \right) + \] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramToRamTransplant.tex b/mmio/mmio_instruction/ramToRamTransplant.tex new file mode 100644 index 0000000..b088e26 --- /dev/null +++ b/mmio/mmio_instruction/ramToRamTransplant.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToRamTransplant_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & \cnT_{i} \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \tlo_{i} \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \valA_{i} \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \nothing \\ + \limb _{i} & = & \nothing \\ + \end{array} + \right. +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramToRamTwoSource.tex b/mmio/mmio_instruction/ramToRamTwoSource.tex new file mode 100644 index 0000000..41c46c4 --- /dev/null +++ b/mmio/mmio_instruction/ramToRamTwoSource.tex @@ -0,0 +1,40 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToRamTwoSource_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & \cnS_{i} \\ + \cnC _{i} & = & \cnT_{i} \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \slo_{i} + 1 \\ + \indexC _{i} & = & \tlo_{i} \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \valB_{i} \\ + \valC _{i}\new{} & = & \valueToBeSet \\ + \indexX _{i} & = & \nothing \\ + \limb _{i} & = & \nothing \\ + \end{array} + \right. +\] + \item +\[ + \twoPartialToOne + \left( + \begin{array}{c} + \valA{}, \valB{}, \valC{}, \valC{}\new{};\\ + \BYTEA{}, \BYTEB{}, \BYTEC{};\\ + \acc{1}, \acc{2}, \acc{3}; \pow{1}, \pow{2}; \\ + \sbo{}, \tbo{}; \size{}; \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} + \right) +\] + +\end{enumerate} diff --git a/mmio/mmio_instruction/ramToRamTwoTarget.tex b/mmio/mmio_instruction/ramToRamTwoTarget.tex new file mode 100644 index 0000000..4fbdbe2 --- /dev/null +++ b/mmio/mmio_instruction/ramToRamTwoTarget.tex @@ -0,0 +1,44 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamToRamTwoTarget_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item +\[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnS_{i} \\ + \cnB _{i} & = & \cnT_{i} \\ + \cnC _{i} & = & \cnT_{i} \\ + \indexA _{i} & = & \slo_{i} \\ + \indexB _{i} & = & \tlo_{i} \\ + \indexC _{i} & = & \tlo_{i} + 1 \\ + \valA _{i}\new{} & = & \valA_{i} \\ + \valB _{i}\new{} & = & \valueToBeSet \\ + \valC _{i}\new{} & = & \valueToBeSet \\ + \indexX _{i} & = & \nothing \\ + \limb _{i} & = & \nothing \\ + \end{array} + \right. +\] + \item +\[ + \onePartialToTwo + \left( + \begin{array}{c} + \valA{}, \valB{}, \valC{}, + \valB{}\new, \valC{}\new; + \BYTEA{}, \BYTEB{}, \BYTEC{}; + \\ + \acc{1}, \acc{2}, \acc{3}, \acc{4}; \pow{1}; + \\ + \sbo{}, \tbo{}, \size{}; + \\ + \bit{1}, \bit{2}, \bit{3}, \bit{4}, \bit{5}; \ct{}; + \end{array} + \right) +\] +\end{enumerate} diff --git a/mmio/mmio_instruction/ramVanishes.tex b/mmio/mmio_instruction/ramVanishes.tex new file mode 100644 index 0000000..ba04d07 --- /dev/null +++ b/mmio/mmio_instruction/ramVanishes.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that: } \isMmioInstRamVanishes_{i} = 1 + } +\end{center} + +We constrain: +\begin{enumerate} + \item + \[ + \left\{ + \begin{array}{lclr} + \cnA _{i} & = & \cnT_{i} \\ + \cnB _{i} & = & 0 \\ + \cnC _{i} & = & 0 \\ + \indexA _{i} & = & \tlo_{i} \\ + \indexB _{i} & = & \nothing \\ + \indexC _{i} & = & \nothing \\ + \valA _{i}\new{} & = & 0 \\ + \valB _{i}\new{} & = & \nothing \\ + \valC _{i}\new{} & = & \nothing \\ + \indexX _{i} & = & \nothing \\ + \limb _{i} & = & \nothing \\ + \end{array} + \right. +\] +\end{enumerate} diff --git a/mmio/patterns/excision.tex b/mmio/patterns/excision.tex new file mode 100644 index 0000000..fbb74a5 --- /dev/null +++ b/mmio/patterns/excision.tex @@ -0,0 +1,59 @@ +Suppose the following are given: +\begin{enumerate} + \item counter-constant columns \target{} and $\target{}\new{}$, + \item binary columns $\bit{1}$ and $\bit{2}$, + \item a byte colunm \target\byte{}, + \item a counter-constant column \target\mark{}, + \item a counter-constant column \size{}, + \item an accumulator column \ACC{}, + \item a ``powers of 256 column'' column \col{P}, + \item a ``counter column'' \ct{}. +\end{enumerate} +The interpretation is as follows: +\target{} is a counter-constant column containing a value from which we wish to remove a chunk of consecutive bytes; +\target\byte{} is \target{}'s byte decomposition; +$\target{}\new{}$ is the counter-constant column that will contain the result of excision; +\target\mark{} is a byte marker in \target{}; +\size{} is the number of bytes to remove from \target{} starting at byte offset \target\mark{}; +we expect $\target\mark{} + (\size{}-1) \leq \llargeMO$; +$\bit{1}$ plateaus at \target\mark{}, $\bit{2}$ plateaus at $\target\mark{} + \size{}$; +the bytes to be excised are accumulated in \ACC{}; +\col{P} is a ``powers of 256 column'' pegged to $\bit{2}$. + +We collect the following constraints under the moniker $\excision{}$: +\begin{enumerate} + \item plateau constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \target{}\mark{}; \ct{})$ + \item $\plateau(\bit{2}, \target{}\mark{} + \size{}; \ct{})$ + \end{enumerate} + \item chunk constraint: $\compChunk(\ACC{}, \target{}\byte{}, \bit{1}, \bit{2}; \ct{})$; + \item power constraint: $\power(\col{P}, \bit{2}; \ct{})$ + \item value enforcement: + \[ + \If + \ct_i = \llargeMO~ + \Then + \target\new_i = + \target_i - \ACC{}_i\cdot\col{P}_i + \] +\end{enumerate} +We subsume this collection of constraints under the moniker +\[ + \excision{} + \left( + \begin{array}{c} + \target{}, \target{}\new{}; \target{}\byte{}; + \acc{1}, \pow{1}; \\ + \tbo{}, \size{}; + \bit{1}, \bit{2}; \ct{}; + \end{array} + \right) +\] + +\begin{figure}[h!] +\centering +\includegraphics[width = 0.4\textwidth]{drawing/excision} +\label{fig: one partial to one padded} +\caption{Representation of the constraints implemented by $\excision$.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/partial_duo.tex b/mmio/patterns/partial_duo.tex new file mode 100644 index 0000000..a2efc20 --- /dev/null +++ b/mmio/patterns/partial_duo.tex @@ -0,0 +1,85 @@ +Suppose we have +%\begin{multicols}{2} +\begin{itemize} + \item binary columns $\bit{1}$, $\bit{2}$, $\bit{3}$, $\bit{4}$, $\bit{5}$ + \item counter constant columns \source{}, \targetOne{}, \targetTwo{}, $\targetOne{}\new{}$, $\targetTwo{}\new{}$ + \item byte columns \source{}\byte{}, \targetOne{}\byte{} and \targetTwo{}\byte{}, + \item counter constant columns \source{}\mark{} and \targetOne{}\mark{}, + \item a counter constant column \size{}, + \item ``accumulator'' columns \acc{1}, \acc{2}, \acc{3}, \acc{4}; + \item a ``power''column \col{P}, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpretation is as follows: +\source{}, \targetOne{} and \targetTwo{} are counter-constant columns containing limbs viewed respectively as a ``source'' and two ``target'' limbs; +\source{}\byte{}, \targetOne{}\byte{} and \targetTwo{}\byte{} are their respective byte decomposition; +$\targetOne{}\new$ and $\targetTwo{}\new$ contain the ``new'' value of \targetOne{} and \targetTwo{} respectively; +\source{}\mark{} and \target{}\mark{} are markers $\in\{0,1,\dots,\llargeMO\}$ for \source{} and \targetOne{} respectively. +We expect both +$\source{}\mark{} + (\size{}-1)\leq \llargeMO$ and +$\target{}\mark{} + (\size{}-1)\geq \llarge$. +Compare with figure~\ref{fig: one partial to two}. + +We collect the following constraints under a collective name: %\ob{TODO} +\begin{enumerate} + \item plateau constraints + \begin{enumerate} + \item $\plateau(\bit{1}, \targetOne{}\mark{}; \ct{})$ + \item $\plateau(\bit{2}, \targetOne{}\mark{} + \size{} - \llarge; \ct{})$ + \item $\plateau(\bit{3}, \source{}\mark{}; \ct{})$ + \item $\plateau(\bit{4}, \source{}\mark{} + \llarge - \targetOne{}\mark{}; \ct{})$ + \item $\plateau(\bit{5}, \source{}\mark{} + \size{}; \ct{})$ + \end{enumerate} + \item prefix, suffix and chunk constraints: + \begin{enumerate} + \item $\compSuffix(\acc{1}, \targetOne{}\byte{}, \bit{1}; \ct{})$, %i.e. $\acc{1}\implies \alpha'$ + \item $\compPrefix(\acc{2}, \targetTwo{}\byte{}, \bit{2}; \ct{})$, %i.e. $\acc{2}\implies \beta$ + \item $\compChunk(\acc{3}, \source{}\byte{}, \bit{3}, \bit{4}; \ct{})$, %i.e. $\acc{3}\implies \gamma$ + \item $\compChunk(\acc{4}, \source{}\byte{}, \bit{4}, \bit{5}; \ct{})$, %i.e. $\acc{4}\implies \gamma'$ + \end{enumerate} + \item power-constraint: $\power(\col{P},\bit{2}; \ct{})$ + \item update constraint: + \[ + \If + \ct_i = \llargeMO~ + \Then + \begin{cases} + \targetOne{}\new{}_i + = + \targetOne{}_i + + + (\acc{3}_i - \acc{1}_i)\\ + \targetTwo{}\new{}_i + = + \targetTwo{}_i + + + (\acc{4}_i - \acc{2}_i)\cdot\col{P}_i. + \end{cases} + \] +\end{enumerate} +We encapsulate all these constraints under a single relation +\[ + \onePartialToTwo + \left( + \begin{array}{c} + \source{}, \targetOne{}, \targetTwo{}, + \targetOne{}\new, \targetTwo{}\new; + \source{}\byte{}, \targetOne{}\byte{}, \targetTwo{}\byte{}; + \\ + \acc{1}, \acc{2}, \acc{3}, \acc{4}; \col{P}; + \\ + \source{}\mark{}, \targetOne{}\mark{}, \size{}; + \\ + \bit{1}, \bit{2}, \bit{3}, \bit{4}, \bit{5}; \ct{}; + \end{array} + \right) +\] + +\begin{figure}[h!] +\centering +\includegraphics[width = 0.5\textwidth]{drawing/1_partial_to_2} +\label{fig: one partial to two} +\caption{Representation of the constraints implemented by $\onePartialToTwo$.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/partial_mono.tex b/mmio/patterns/partial_mono.tex new file mode 100644 index 0000000..448969e --- /dev/null +++ b/mmio/patterns/partial_mono.tex @@ -0,0 +1,72 @@ +Suppose we have +%\begin{multicols}{2} +\begin{itemize} + \item binary columns $\bit{1}$, $\bit{2}$, $\bit{3}$, $\bit{4}$, + \item counter constant columns \source{}, \target{} and $\target{}\new$, + \item byte columns \source{}\byte{} and \target{}\byte{}, + \item counter constant columns \source{}\mark{} and \target{}\mark{}, + \item a counter constant column \size{}, + \item ``accumulator'' columns \acc{1}, \acc{2}, + \item a ``powers'' column $\col{P}$, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpretation is as follows: +\source{} and \target{} are counter-constant columns containing limbs viewed respectively as a ``source'' and a ``target'' limb; +\source{}\byte{} and \target{}\byte{} are their respective byte decomposition; +$\target{}\new$ contains the ``new'' value of \target{}; +\source{}\mark{} and \target{}\mark{} are markers $\in\{0,1,\dots,\llargeMO\}$ for for \source{} and \target{} respectively; +we expect both +$\col{SM} + (\size{}-1)\leq \llargeMO$ and +$\col{TM} + (\size{}-1)\leq \llargeMO$; +\col{P} is pegged to $\bit{2}$ and computes the appropriate power of $256$ so that we may replace a chunk from $\target$ with a chunk from $\source{}$. +Compare with figure~\ref{fig: one partial to one}. + + +We collect the following constraints under a collective name +\begin{enumerate} + \item binary-plateau-constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \target{}\mark{}; \ct{})$ + \item $\plateau(\bit{2}, \target{}\mark{} + \size{}; \ct{})$ + \item $\plateau(\bit{3}, \source{}\mark{}; \ct{})$ + \item $\plateau(\bit{4}, \source{}\mark{} + \size{}; \ct{})$ + \end{enumerate} + \item chunk-constraints + \begin{enumerate} + \item $\compChunk(\acc{1}, \target{}\byte{}, \bit{1}, \bit{2}; \ct{})$ % i.e. $\acc{1}\implies \alpha$ + \item $\compChunk(\acc{2}, \source{}\byte{}, \bit{3}, \bit{4}; \ct{})$ % i.e. $\acc{2}\implies \gamma$ + \end{enumerate} + \item power-constraint: $\power(\col{P},\bit{2}; \ct{})$ + \item update constraint: + \[ + \If + \ct_i = \llargeMO~ + \Then + \target{}\new{}_i + = + \target{}_i + + + (\acc{2}_i - \acc{1}_i)\cdot\col{P}_i. + \] +\end{enumerate} +We encapsulate all these constraints under a single relation +\[ + \onePartialToOne + \left( + \begin{array}{c} + \source{}, \target{}, \target{}\new{}; + \source{}\byte{}, \target{}\byte{};\\ + \acc{1}, \acc{2}; \col{P}; \\ + \source{}\mark{}, \target{}\mark{}; \size{};\\ + \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} + \right) +\] +\begin{figure}[h!] +\centering +\includegraphics[width = 0.4\textwidth]{drawing/1_partial_to_1} +\label{fig: one partial to one} +\caption{Representation of the constraints implemented by $\onePartialToOne$.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/prefix_extraction.tex b/mmio/patterns/prefix_extraction.tex new file mode 100644 index 0000000..39c3203 --- /dev/null +++ b/mmio/patterns/prefix_extraction.tex @@ -0,0 +1,13 @@ +Suppose the following are given: +\begin{enumerate} + \item counter constant columns \source{} and \target{}, + \item byte colunms \source\byte{} and \target\byte{}, + \item a counter constant column \source\mark{}, + \item a counter constant column \size{}, + \item binary columns $\bit{1}$ and $\bit{2}$, + \item an accumulator column \ACC{}; + \item a column \col{P}; +\end{enumerate} +The interpretation is the following + +Actually this is already present in $\onePartialToOne$ \dots{} \ No newline at end of file diff --git a/mmio/patterns/prefix_trailing_zeros_duo.tex b/mmio/patterns/prefix_trailing_zeros_duo.tex new file mode 100644 index 0000000..6cf30ca --- /dev/null +++ b/mmio/patterns/prefix_trailing_zeros_duo.tex @@ -0,0 +1,78 @@ +Supppose we are given +%\begin{multicols}{2} +\begin{itemize} + \item binary columns $\bit{1}$, $\bit{2}$, $\bit{3}$ and $\bit{4}$, + \item counter-constant columns \sourceOne{}, \sourceTwo{}, \target{}, + \item byte columns \sourceOne{}\byte{} and \sourceTwo{}\byte{}, + \item counter-constant columns \sourceOne{}\mark{} and \size{}, + \item accumulator columns \acc{1} and \acc{2}, + \item two columns \col{P1} and \col{P2}, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpreation is as follows: +\sourceOne{} contains a limb from which we extract a suffix; +\acc{1} will accumulate the bytes of said suffix; +\sourceTwo{} contains a limb from which we extract a prefix; +\acc{2} will accumulate the bytes of said prefix; +\sourceOne{}\byte{} and \sourceTwo{}\byte{} are the respective byte decompositions; +\sourceOne{}\mark{} is the offset within \sourceOne{} from where we start harvesting bytes; +\size{} is the total number of bytes to harvest; +\target{} will be made to contain the prefix extracted from \sourceOne{} followed by the prefix extracted from \sourceTwo{} (left aligned); +the assumption is that $\sourceOne{}\mark{} + \size{} > \llarge$ so that two byte sources are required to build \target{}; +$\bit{1}$ plateaus at \sourceOne{}\mark{}; +$\bit{2}$ plateaus at $\sourceOne{}\mark{} + \size{} - \llarge$; +$\bit{3}$ plateaus at $\llarge - \sourceOne{}\mark{}$; +$\bit{4}$ plateaus at $\size{}$; +$\col{P1}$ and $\col{P2}$ are ``powers of 256'' columns with $\col{P1}$ pegged to $\bit{3}$ and $\col{P2}$ pegged to $\bit{4}$; +together they build the correct powers of 256 required for shifting the extracted prefix and suffix and building \target{}. Compare with figure~\ref{fig: two to one padded}. + +The following collection of constraints ensures the desired behaviour: +\begin{enumerate} + \item binary plateau constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \sourceOne{}\mark{}; \ct{})$, + \item $\plateau(\bit{2}, \sourceOne{}\mark{} + \size{} - \llarge; \ct{})$, + \item $\plateau(\bit{3}, \llarge - \sourceOne{}\mark{}; \ct{})$; + \item $\plateau(\bit{4}, \size{}; \ct{})$; + \end{enumerate} + \item prefix and suffix constraints: + \begin{enumerate} + \item $\compSuffix(\acc{1}, \sourceOne{}\byte{}, \bit{1}; \ct{})$; + \item $\compPrefix(\acc{2}, \sourceTwo{}\byte{}, \bit{2}; \ct{})$; + \end{enumerate} + \item power constraints: + \begin{enumerate} + \item $\power(\col{P1}, \bit{3}; \ct{})$; + \item $\power(\col{P2}, \bit{4}; \ct{})$; + \end{enumerate} + \item value enforcement + \[ + \If\ct{}_{i} = \llargeMO~ + \Then + \target{}_{i} + = + \acc{1}_{i}\cdot \col{P1}_{i} + + + \acc{2}_{i}\cdot \col{P2}_{i}. + \] +\end{enumerate} +We use the short hand +\[ + \twoToOnePadded + \left( + \begin{array}{c} + \sourceOne{}, \sourceTwo{}, \target{}; \sourceOne{}\byte{}, \sourceTwo{}\byte{};\\ + \acc{1}, \acc{2}; \col{P1}, \col{P2};\\ + \sourceOne{}\mark{}, \size{}; \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} + \right) +\] + +\begin{figure}[h!] +\centering +\includegraphics[width = 0.5\textwidth]{drawing/2_to_1_padded} +\label{fig: two to one padded} +\caption{Representation of the constraints implemented by $\twoToOnePadded$.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/prefix_trailing_zeros_mono.tex b/mmio/patterns/prefix_trailing_zeros_mono.tex new file mode 100644 index 0000000..44853f7 --- /dev/null +++ b/mmio/patterns/prefix_trailing_zeros_mono.tex @@ -0,0 +1,60 @@ +Supppose we are given +%\begin{multicols}{2} +\begin{itemize} + \item binary columns $\bit{1}$, $\bit{2}$ and $\bit{3}$, + \item counter-constant columns \source{}, \target{}, + \item a byte column \source{}\byte{}, + \item counter-constant columns \source{}\mark{} and \size{}, + \item an ``accumulator column'' \ACC{}, + \item a ``power''column \col{P}, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpretation is as follows: +\source{} is a limb from which we will harvest a chunk of bytes; +\source{}\byte{} is the byte decomposition of \source{}; +\source{}\mark{} is the offset within \source{} from where we start harvesting bytes; +\size{} is the number of bytes to harvest; +the assumption is that $\source{}\mark{} + (\size{}-1) \leq \llargeMO$; +\target{} will be made to contain this chunk of bytes (left aligned); +$\bit{1}$ plateaus at \source{}\mark{}; +$\bit{2}$ plateaus at $\source{}\mark{} + \size{}$; +$\bit{3}$ plateaus at $\size{}$; +$\col{P}$ is pegged to $\bit{3}$ and builds the correct power of $256$ so that we may shift the harvested chunk to build the desired (left-aligned) prefix. +Compare with figure~\ref{fig: one partial to one padded} + +We the following collection of constraints ensures the desired behaviour: +\begin{enumerate} + \item binary plateau constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \source{}\mark{}; \ct{})$, + \item $\plateau(\bit{2}, \source{}\mark{} + \size{}; \ct{})$, + \item $\plateau(\bit{3}, \size{}; \ct{})$; + \end{enumerate} + \item chunk constraint: $\compChunk(\ACC{}, \source{}\byte{}, \bit{1}, \bit{2}; \ct{})$; + \item power constraint: $\power(\col{P}, \bit{3}; \ct{})$; + \item value enforcement + \[ + \If\ct{}_{i} = \llargeMO~ + \Then + \target{}_{i} = \ACC{}_{i}\cdot \col{P}_{i}. + \] +\end{enumerate} +We use the short hand +\[ + \oneToOnePadded + \left( + \begin{array}{c} + \source{}, \target{}; \source{}\byte{}; \ACC{}, \col{P}; \\ + \source{}\mark{}, \size{}; \bit{1}, \bit{2}, \bit{3}; \ct{}; \\ + \end{array} + \right) +\] + +\begin{figure}[h!] +\centering +\includegraphics[width = 0.4\textwidth]{drawing/1_to_1_padded} +\label{fig: one partial to one padded} +\caption{Representation of the constraints implemented by $\oneToOnePadded$.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/purpose.tex b/mmio/patterns/purpose.tex new file mode 100644 index 0000000..82d49fb --- /dev/null +++ b/mmio/patterns/purpose.tex @@ -0,0 +1,12 @@ +The present section compiles all variations on cutting, grafting and padding that the RAM needs and labels them. These \textbf{surgical patterns} are couched in a neutral setting in the sense that we use place holder names such as \source{} to \source{}\byte{}. These will later will be replaced with actual column names such as $\limb{}$ or $\byteA{}$. We also use \textbf{markers} for what will eventually be \textbf{byte offsets} $\in\{1,\dots,\llargeMO\}$. + +We tend to use the same variable names over and over. Here is their general interpretation: +$(1)$ the letter \source{} and \target{} stand, respetively, for \col{source} and \col{target}; +source and target limbs are assumed counter-constant; +source limbs are generally used as a source of bytes with which to modify one or more target limbs; +$(2)$ an exponent $(-)\new$ is meant to signal a ``new'' or ``updated'' value i.e. a value that is computed by the constraints; ``new'' values are always counter-constant; +$(3)$ the letter \byte{} stands for \col{byte}; +$(4)$ the letter \mark{} stands for \col{marker} i.e. a ``byte marker'' or ``byte offset'' within a limb; +$(5)$ the letter \col{P} stands for \col{power}. +Thus the reader should interpret column names such as \sourceOne{}\mark{}, \targetTwo{}\byte{} and $\target\new$ as ``(byte) marker in the first source limb'', ``bytes of the second target limb'' and ``new value of the target limb.'' +Every surgical pattern is given a detailed interpretation before any constraints are written down. A picture accompanies it to make the intent clear. \ No newline at end of file diff --git a/mmio/patterns/ram_ram_full.tex b/mmio/patterns/ram_ram_full.tex new file mode 100644 index 0000000..a0b8c6d --- /dev/null +++ b/mmio/patterns/ram_ram_full.tex @@ -0,0 +1,65 @@ +Supppose we have +%\begin{multicols}{2} +\begin{itemize} + \item binary columns $\bit{1}, \bit{2}$, + \item counter-constant columns \source{}, \targetOne{}, \targetTwo{}, $\targetOne{}\new{}$, $\targetTwo{}\new{}$, + \item a counter-constant column \targetOne{}\mark{}, + \item byte columns \source{}\byte{}, \targetOne{}\byte{}, \targetTwo{}\byte{}, + \item accumulator columns $\acc{1}, \acc{2}, \acc{3}, \acc{4}$, + \item a column \col{P}, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpreation is as follows: +\source{} is a limb from which we will harvest \emph{all} bytes (hence the descriptor \emph{full}); +\targetOne{} and \targetTwo{} are limbs which we will updata using \source{}'s bytes; +$\targetOne{}\new{}$ and $\targetTwo{}\new{}$ are their ``new'' values; +\source{}\byte{}, \targetOne{}\byte{}, \targetTwo{}\byte{} are the respective byte decompositions; +\targetOne{}\mark{} is a marker for bytes in \targetOne{}; +$\bit{1}$ plateaus at \targetOne{}\mark{}; +$\bit{2}$ plateaus at $16 - \targetOne{}\mark{}$; +$\col{P}$ is pegged to $\bit{1}$ and builds the correct power of $256$ so that we may change the relevant prefix of \targetTwo{}. + +The following collection of constraints ensures the desired behaviour. +% The interpreation of the greek letters ($\alpha'$, $\beta$, $\beta'$, $\gamma$) is given in \ob{TODO} figure~\ref{fig: one full to two}. +\begin{description} + \item[Plateau constraints:] + \begin{enumerate} + \item $\plateau(\bit{1}, \targetOne{}\mark{}; \ct{})$ + \item $\plateau(\bit{2}, 16 - \targetOne{}\mark{}; \ct{})$ + \end{enumerate} + \item[Prefix and suffix constraints:] + \begin{enumerate} + \item $\compSuffix(\acc{1}, \targetOne{}\byte{}, \bit{1}; \ct{})$, %i.e. $\acc{1}\implies\alpha'$, + \item $\compPrefix(\acc{2}, \targetTwo{}\byte{}, \bit{1}; \ct{})$, %i.e. $\acc{2}\implies\beta$, + \item $\compPrefix(\acc{3}, \source{}\byte{}, \bit{2}; \ct{})$, %i.e. $\acc{3}\implies\gamma$, + \item $\compSuffix(\acc{4}, \source{}\byte{}, \bit{2}; \ct{})$, %i.e. $\acc{4}\implies\gamma'$, + \end{enumerate} + \item[Power constraint:] $\power(\col{P}, \bit{1}; \ct{})$, + \item[Update constraints:] \If $\ct_{i} = \llargeMO$ \Then + \begin{enumerate} + \item $\targetOne\new_i = \targetOne_i + (\acc{3}_i - \acc{1}_i)$ + \item $\targetTwo\new_i = \targetTwo_i + (\acc{4}_i - \acc{2}_i) \cdot \col{P}_i$ + \end{enumerate} +\end{description} +We encapsulate all these constraints under a single relation +\[ + \oneFullToTwo + \left( + \begin{array}{c} + \source{}, \targetOne{}, \targetTwo{}, \targetOne{}\new{}, \targetTwo{}\new{};\\ + \source{}\byte{}, \targetOne{}\byte{}, \targetTwo{}\byte{};\\ + \acc{1}, \acc{2},\\ + \acc{3}, \acc{4}, \col{P}; \\ + \targetOne{}\mark{}, \bit{1}, \bit{2}; \ct{}; + \end{array} + \right) +\] + +\begin{figure}[h!] +\centering +\includegraphics[width = 0.5\textwidth]{drawing/1_full_to_2} +\label{fig: one full to two} +\caption{This diagram explains the $\oneFullToTwo{}$ constraint and the greek letters mentioned in the constraints.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/single_byte_replacement.tex b/mmio/patterns/single_byte_replacement.tex new file mode 100644 index 0000000..e07e2dc --- /dev/null +++ b/mmio/patterns/single_byte_replacement.tex @@ -0,0 +1,64 @@ +Suppose we are given +\begin{itemize} + \item counter-constant columns + \source{}, + \target{} and + $\target{}\new{}$, + \item byte columns + \source{}\byte{} and + \target{}\byte{}, + \item binary columns + $\bit{1}$ and $\bit{2}$, + \item an ``accumulator'' column \ACC{}, + \item a counter-constant column $\target\mark$, + \item a column \col{P}, + \item a ``counter column'' \ct{}. +\end{itemize} +The interpretation is the following: +\source{} contains a limb from which we will extract the least significant byte; +\target{}\mark{} is a marker that marks a byte in \target{}; +\target{} contains a limb of which we wish to modify the marked byte; +$\bit{1}$ and $\bit{2}$ are binary columns with threshold at \target{} and $\target{}+1$ respectively; +\col{P} is a ``powers of 256'' column that will allow us modify a single byte in \target{}; +the resulting limb is recorded in $\target{}\new{}$. + +We give the set of conditions below under a name: +\begin{enumerate} + \item binary plateau constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \target\mark; \ct{})$ + \item $\plateau(\bit{2}, \target\mark + 1; \ct{})$; + \end{enumerate} + \item chunk constraint: $\compChunk(\ACC{}, \target{}\byte{}, \bit{1}, \bit{2}; \ct{})$; + \item power constraint: $\power(\col{P}, \bit{2}; \ct{})$; + \item update constraint: + \[ + \If\ct_{i} = \llargeMO~ + \Then + \target{}\new{}_{i} = + \target{}_{i} + + (\source{}\byte{}_{i} - \ACC{}_{i}) + \cdot + \col{P}_{i} + \] +\end{enumerate} +We encapsulate these constraints in a relation +\[ + \byteSwap + \left( + \begin{array}{c} + \source{}, \target{}, \target{}\new{}; + \source{}\byte{}, \target{}\byte{}; + \\ + \ACC{}, \col{P}; + \target{}\mark{}, \bit{1}, \bit{2}; \ct{}; + \\ + \end{array} + \right) +\] +\begin{figure}[h!] +\centering +\includegraphics[width = 0.4\textwidth]{drawing/byte_swap} +\label{fig: one partial to one padded} +\caption{Representation of the constraints implemented by $\byteSwap$.} +\end{figure} \ No newline at end of file diff --git a/mmio/patterns/two_partial_to_one.tex b/mmio/patterns/two_partial_to_one.tex new file mode 100644 index 0000000..bdf704e --- /dev/null +++ b/mmio/patterns/two_partial_to_one.tex @@ -0,0 +1,72 @@ +Supppose we have +\begin{itemize} + \item counter-constant columns $\sourceOne{}, \sourceTwo{}, \target{}, \target{}\new$, + \item counter-constant columns $\source{}\mark{}, \target{}\mark{}$, + \item counter-constant column $\size{}$, + \item binary columns $\bit{1}, \bit{2}, \bit{3}, \bit{4}$ + \item byte columns $\sourceOne{}\byte{}, \sourceTwo{}\byte{}, \target{}\byte{}$, + \item ``accumulator columns'' $\acc{1}$, $\acc{2}$, $\acc{3}$ + \item some ``power'' column $\col{P1}, \col{P2}$, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpreation is as follows: +\sourceOne{}, \sourceTwo{} are limbs from which we will harvest a suffix and a prefix respectively; +\sourceOne{}\byte{}, \sourceTwo{}\byte{}, \target{}\byte{} are the respective byte decompositions of \sourceOne{}, \sourceTwo{} and \target{}; +\acc{1} and \acc{2} accumulate the bytes of the desired suffix (of the first source) and prefix (of the second source); +\acc{3} accumulates the bytes of the chunk to isolate (from the target); +$\target{}\new$ is a limb which we will construct the previously extracted suffix and prefix; +\source{}\mark{} is a marker for bytes in \sourceOne{}; +\target{}\mark{} is a marker for bytes in \target{}; +$\bit{1}$ plateaus at \source{}\mark{}; +$\bit{2}$ plateaus at $\source{}\mark{} + \size{} - \llarge$; +$\bit{3}$ plateaus at \target{}\mark{}; +$\bit{4}$ plateaus at $\target{}\mark{} + \size{}$; +$\col{P1}$ is pegged to $\bit{4}$ and builds a power of $256$: it is used to left shift the isolate chunk extracted from \target{} and the concatenation of the suffix (of the first source) and prefix (of the second source); +$\col{P2}$ is used concatenate the suffix from \sourceOne{} and the prefix from \sourceTwo{}. + +The following collection of constraints ensures the desired behaviour. +% The interpreation of the greek letters ($\alpha'$, $\beta$) is given in \ob{TODO: add figure}. +\begin{enumerate} + \item binary plateau constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \source{}\mark{};\ct{})$, + \item $\plateau(\bit{2}, \source{}\mark{} + \size{} - \llarge;\ct{})$, + \item $\plateau(\bit{3}, \target{}\mark{};\ct{})$, + \item $\plateau(\bit{4}, \target{}\mark{} + \size{};\ct{})$; + \end{enumerate} + \item prefix and suffix constraints: + \begin{enumerate} + \item $\compSuffix(\acc{1}, \sourceOne{}\byte{}, \bit{1};\ct{})$, % i.e. $\acc{1}\implies\alpha'$, + \item $\compPrefix(\acc{2}, \sourceTwo{}\byte{}, \bit{2};\ct{})$; % i.e. $\acc{2}\implies\beta$; + \item $\compChunk(\acc{3}, \target{}\byte{}, \bit{3}, \bit{4}; \ct{})$; + \end{enumerate} + \item power constraint: + \begin{enumerate} + \item $\power(\col{P1}, \bit{4};\ct{})$, + \item $\antiPower(\col{P2}, \bit{2}; \ct{})$ + \end{enumerate} + \item value enforcement: \If $\ct_{i} = \llargeMO$ \Then $\target\new_{i} = \target_{i} + ((\acc{1}_{i} \cdot \col{P2} + \acc{2}_{i}) - \acc{3}_{i}) \cdot \col{P1}$. +\end{enumerate} +We encapsulate all these constraints under a single relation +\[ + \twoPartialToOne + \left( + \begin{array}{c} + \sourceOne{}, \sourceTwo{}, \target{}, \target{}\new{};\\ + \sourceOne{}\byte{}, \sourceTwo{}\byte{}, \target{}\byte{};\\ + \acc{1}, \acc{2}, \acc{3}; \col{P1}, \col{P2}; \\ + \source{}\mark{}, \target{}\mark{}; \size{}; \bit{1}, \bit{2}, \bit{3}, \bit{4}; \ct{}; + \end{array} + \right) +\] + +\iffalse +\begin{figure}[h!] +\centering +\includegraphics[width = \textwidth]{drawing/2_to_1_full} +\label{fig: one full to two} +\caption{Representation of the surgical pattern implemented by $\twoToOneFull{}$.} +\end{figure} +\fi diff --git a/mmio/patterns/two_to_one_full.tex b/mmio/patterns/two_to_one_full.tex new file mode 100644 index 0000000..8859f55 --- /dev/null +++ b/mmio/patterns/two_to_one_full.tex @@ -0,0 +1,59 @@ +Supppose we have +\begin{itemize} + \item counter-constant columns \sourceOne{}, \sourceTwo{}, \target{}, + \item a counter-constant column \source{}\mark{}, + \item binary columns $\bit{1}, \bit{2}$, + \item byte columns \sourceOne{}\byte{}, \sourceTwo{}\byte{}, + \item ``accumulator columns'' $\acc{1}$, $\acc{2}$, + \item a ``power'' column \col{P}, + \item a ``counter column'' \ct{}. + %\item[\vspace{\fill}] +\end{itemize} +%\end{multicols} +The interpreation is as follows: +\sourceOne{}, \sourceTwo{} are limbs from which we will harvest a suffix and a prefix respectively; +\sourceOne{}\byte{}, \sourceTwo{}\byte{} are the respective byte decompositions of \sourceOne{} and \sourceTwo{}; +\acc{1} and \acc{2} accumulate the bytes of the desired suffix and prefix; +\target{} is a limb which we will construct the previously extracted suffix and prefix; +\source{}\mark{} is a marker for bytes in \sourceOne{}; +$\bit{1}$ plateaus at \source{}\mark{}; +$\bit{2}$ plateaus at $16 - \source{}\mark{}$; +$\col{P}$ is pegged to $\bit{2}$ and builds a power of $256$: it is used to left shift the suffix extracted from \sourceOne{}. + +The following collection of constraints ensures the desired behaviour. +% The interpreation of the greek letters ($\alpha'$, $\beta$) is given in \ob{TODO: add figure}. +\begin{enumerate} + \item binary plateau constraints: + \begin{enumerate} + \item $\plateau(\bit{1}, \source{}\mark{};\ct{})$, + \item $\plateau(\bit{2}, 16 - \source{}\mark{};\ct{})$; + \end{enumerate} + \item prefix and suffix constraints: + \begin{enumerate} + \item $\compSuffix(\acc{1}, \sourceOne{}\byte{}, \bit{1};\ct{})$, % i.e. $\acc{1}\implies\alpha'$, + \item $\compPrefix(\acc{2}, \sourceTwo{}\byte{}, \bit{1};\ct{})$; % i.e. $\acc{2}\implies\beta$; + \end{enumerate} + \item power constraint: $\power(\col{P}, \bit{2};\ct{})$; + \item value enforcement: \If $\ct_{i} = \llargeMO$ \Then $\target_i = \acc{1}_i \cdot \col{P}_i + \acc{2}_i$. +\end{enumerate} +We encapsulate all these constraints under a single relation +\[ + \twoToOneFull + \left( + \begin{array}{c} + \sourceOne{}, \sourceTwo{}, \target{};\\ + \sourceOne{}\byte{}, \sourceTwo{}\byte{};\\ + \acc{1}, \acc{2}; \col{P}; \\ + \source{}\mark{}; \bit{1}, \bit{2}; \ct{}; + \end{array} + \right) +\] + +\iffalse +\begin{figure}[h!] +\centering +\includegraphics[width = \textwidth]{drawing/2_to_1_full} +\label{fig: one full to two} +\caption{Representation of the surgical pattern implemented by $\twoToOneFull{}$.} +\end{figure} +\fi \ No newline at end of file diff --git a/mmio/specialized/anti_power.tex b/mmio/specialized/anti_power.tex new file mode 100644 index 0000000..e47eea4 --- /dev/null +++ b/mmio/specialized/anti_power.tex @@ -0,0 +1,41 @@ +Suppose we are given: +\begin{itemize} + \item a binary column \col{X}, + \item a ``powers column'' \col{P}, + \item a ``counter column'' \ct{}. +\end{itemize} +We say that the pair $(\col{P}, \col{X})$ satisfies a \textbf{anti-power-constraint}\label{def: anti power constraint} if it satisfies the following constraints: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then: + \begin{enumerate} + \item \If $\col{X}_{i} = 0$ \Then $\col{P}_{i} = 256$ + \item \If $\col{X}_{i} = 1$ \Then $\col{P}_{i} = 1$ + \end{enumerate} + \item \If $\ct_{i} \neq 0$ \Then: + \begin{enumerate} + \item \If $\col{X}_{i} = 0$ \Then $\col{P}_{i} = 256 \cdot \col{P}_{i - 1}$ + \item \If $\col{X}_{i} = 1$ \Then $\col{P}_{i} = \col{P}_{i - 1}$ + \end{enumerate} +\end{enumerate} +Power constraints will be applied in the case where \col{X} satisfies a plateau constraint: +\begin{figure}[h!] +\centering +\[ + \begin{array}{|l|c|c|c|c|c|c|c|c|c|} + \hline + \ct{} & 0 & 1 & 2 & \cdots & c-1 & c & c+1 & \cdots & \llargeMO \\ + \hline + \col{X} & \zero & \zero & \zero & \cdots & \zero & \one & \one & \cdots & \one \\ + \hline + \col{P} & 256 & 256^2 & 256^{3} & \cdots & 256^{d} & 256^{d} & 256^{d} & \cdots & 256^{d} \\ + \hline + \end{array} +\] +\caption{In the picture above $\col{X}$ satisfies the plateau constraint $\plateau(\col{X},c)$, $0= 2 ? <== totnt_at_least_2 + - if totnt_at_least_2 = false + - is the only nontrivial limb single target ? + - if TOTNT ≠ 1: + - what is the frst source limb byte size ? + - what is the last source limb byte size ? + - is the frst nontrivial limb single target ? + - is the last nontrivial limb single target ? + - are we aligned ? + - if not, what is mddl_tbo ? + - what are init_sbo / init_slo ? + - what are frst_tbo / frst_tlo ? + +- if there is some padding: + - what is TOTRZ ? + - if TOTRZ = 1: + - is the only padding excision or killingRam ? + - init_tpo ? size ? + - if TOTRZ ≠ 1: + - is the frst padding excision or killingRam ? + - is the last padding excision or killingRam ? + - tbo ? size ? in both cases + +We need to establish the following: +- pure_padding ? +- mixed ? +- pure_data ? +- TOTNT ? + - ⟦TOTNT ≥ 2⟧ ? + - [P] aligned ? +- TOTRZ ? + - ⟦TOTRZ ≥ 2⟧ ? +- if pure_padd ≡ false: + - frst_slo / frst_sbo + - frst_tlo / frst_tbo + - frst_size + - frst_single_target_limb + - if ⟦TOTNT ≥ 2⟧ = true + - increment_init_tlo: true / false + - mddl_tbo + - [P] last_size + - [P] last_single_target_limb +- if pure_data ≡ false + - frst_plo + - [P] frst_pbo + - [P] frst_padd_size + - [P] increment_tlo_at_transition + - [P] last_padd_size + + +We first impose + + TOTLZ = 0 + +We define the shorthand + + . + +The operations below deal with everything in the source if required i.e. whenever pure_padd ≡ false. + +NOTE: +- SIZE is at most a 4 byte integer (MXPX not triggered) +- REF_SIZE and REF_OFFSET are of the same order of magnitude + + the addition real_src_offset + (trsf_size - 1) is safe. + +We next deal with the over all structure of the macro-instruction: +- is it all data ? +- is it all padding ? +- is it a mix of both ? + +|--------+----------------------------------------------+----------------------------------+--------------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+----------------------------------------------+----------------------------------+--------------------------------------------------------------------+---------------------| +| i + x | LT( SRC_OFF_HI, SRC_OFF_LO; 0, REF_SIZE ) | EUC( maybe_frst_src_offset; 16 ) | | CARRY OUT euc iff | +| | | | | . pure_padd ≡ false | +| | | | | | +| | | | | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * pure_padd ≡ 1 - WCP/RES[i + x] | | +| | | | | | +| | | | * maybe_frst_src_offset ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then REF_OFFSET + SRC_OFFSET_LO | | +| | | | * frst_read_slo ≡ EUC/QUOT[i + x] | | +| | | | * frst_read_sbo ≡ EUC/REMD[i + x] | | +|--------+----------------------------------------------+----------------------------------+--------------------------------------------------------------------+---------------------| +| i + x | LT( 0, max_src_offset_or_zero; 0, REF_SIZE ) | EUC( maybe_last_src_offset; 16 ) | | CARRY OUT iff | +| | | | | . pure_padd ≡ false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * max_src_offset_or_zero ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then SRC_OFF_LO + (SIZE - 1) | | +| | | | * mixed ≡ (1 - pure_padd) • (1 - WCP/RES[i + x]) | | +| | | | * pure_data ≡ (1 - pure_padd) • WCP/RES[i + x] | | +| | | | | | +| | | | * maybe_last_src_offset ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then maybe_frst_src_offset + (trsf_size - 1) | | +| | | | * trsf_size ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then | | +| | | | . If pure_data = 0 Then (REF_SIZE - SRC_OFF_LO) | | +| | | | . If pure_data = 1 Then SIZE | | +| | | | * last_read_slo ≡ EUC/QUOT[i + x] | | +| | | | * last_read_sbo ≡ EUC/REMD[i + x] | | +| | | | | | +| | | | NOTE: pure_padd + mixed + pure_data = 1 | | +|--------+----------------------------------------------+----------------------------------+--------------------------------------------------------------------+---------------------| + +We next deal with all reading operations. Reading refers to extracting data from the source data store. +Such operations are deemed NONTRIVIAL. + +|--------+----------------------+-----+---------------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+----------------------+-----+---------------------------------------------------------------------+---------------------| +| i + x | LT( 0, 1; 0, TOTNT ) | | | CARRY OUT iff | +| | | | | . pure_padd ≡ false | +| | | | IMPOSE: | | +| | | | ======= | | +| | | | | | +| | | | TOTNT = | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then last_read_slo - frst_read_slo + 1 | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * totnt_at_least_2 ≡ WCP/RES[i + x] | | +| | | | * last_read_src_limb_byte_size ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then 1 + last_read_sbo | | +| | | | . If totnt_at_least_2 = 0: last_read_sbo - frst_read_sbo + 1 | | +| | | | . If totnt_at_least_2 = 1: last_read_sbo + 1 | | +| | | | * frst_read_limb_byte_size ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then | | +| | | | . If totnt_at_least_2 = 0: last_read_sbo - frst_read_sbo + 1 | | +| | | | . If totnt_at_least_2 = 1: 16 - frst_read_sbo | | +|--------+----------------------+-----+---------------------------------------------------------------------+---------------------| + +The following deals the extremal offsets of the target range. +TODO: skip equality checks! We won't use the outputs + +|--------+-----+----------------------------+------------------------------------------------+-------| +| PP row | WCP | EUC | shorthands | notes | +|--------+-----+----------------------------+------------------------------------------------+-------| +| i + x | | EUC( frst_tgt_offset; 16 ) | | | +| | | | | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_tgt_offset ≡ TGT_OFFSET_LO | | +| | | | * frst_tlo ≡ EUC/QUOT[i + x] | | +| | | | * frst_tbo ≡ EUC/REMD[i + x] | | +| | | | * frst_tbo_iszero ≡ WCP/RES[i + x] | | +|--------+-----+----------------------------+------------------------------------------------+-------| +| i + x | | EUC( last_tgt_offset; 16 ) | | | +| | | | | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * last_tgt_offset ≡ TGT_OFFSET_LO + (SIZE - 1) | | +| | | | * last_tlo ≡ EUC/QUOT[i + x] | | +| | | | * last_tbo ≡ EUC/REMD[i + x] | | +| | | | * last_tbo_is_15 ≡ WCP/RES[i + x] | | +|--------+-----+----------------------------+------------------------------------------------+-------| + +The following deals with padding. +These computatoins are only required if pure_data = false. + +|--------+----------------------+----------------------------------------+---------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+----------------------+----------------------------------------+---------------------------------------------------------------+---------------------| +| i + x | | EUC( frst_tgt_offset + trsf_size; 16 ) | | CARRY OUT iff | +| | | | | . pure_data = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_plo ≡ EUC/QUOT[i + x] | | +| | | | * frst_pbo ≡ EUC/REMD[i + x] | | +|--------+----------------------+----------------------------------------+---------------------------------------------------------------+---------------------| +| i + x | LT( 0, 1; 0, TOTRZ ) | | | CARRY OUT iff | +| | | | | . pure_data = false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * TOTRZ = | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then last_tlo - frst_plo + 1 | | +| | | | * totrz_at_least_2 ≡ WCP/RES[i + x] | | +| | | | * frst_padd_size ≡ | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then | | +| | | | . If totrz_at_least_2 = 1 Then 16 - frst_pbo | | +| | | | . If totrz_at_least_2 = 0 Then last_pbo - frst_pbo + 1 | | +| | | | * last_padd_size ≡ | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then | | +| | | | . If totrz_at_least_2 = 1 Then last_pbo + 1 | | +| | | | . If totrz_at_least_2 = 0 Then last_pbo - frst_pbo + 1 | | +|--------+----------------------+----------------------------------------+---------------------------------------------------------------+---------------------| + +The next rows deal with the insertion of the extremal source limbs into the target domain. + +|--------+--------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+--------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------+---------------------| +| i + x | EQ( 0, EUC/REM[i + x]; 0, 15 ) | EUC( frst_tbo + (frst_read_src_limb_byte_size - 1); 16 ) | | CARRY OUT iff | +| | | | | . pure_padd = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_trsf_maxes_out_target_limb ≡ WCP/RES[i + x] | | +| | | | * frst_trsf_targets_single_limb ≡ 1 - EUC/QUOT[i + x] | | +| | | | * mddl_tbo ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then | | +| | | | . If frst_trsf_maxes_out_target_limb = 0 Then 1 + EUC/REM[i + x] | | +| | | | . If frst_trsf_maxes_out_target_limb = 1 Then 0 | | +|--------+--------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------+---------------------| +| i + x | EQ( 0, EUC/REMD[i + x]; 15 ) | EUC( mddl_tbo + (last_read_src_limb_byte_size - 1); 16 ) | | CARRY OUT iff | +| | | | | . pure_padd = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * last_trsf_maxes_out_target_limb ≡ WCP/RES[i + x] | | +| | | | * last_trsf_targets_single_limb ≡ 1 - EUC/QUOT[i + x] | | +|--------+--------------------------------+----------------------------------------------------------+-------------------------------------------------------------------------+---------------------| + +We have a final row that allows the MMU module to differentiate between instructions whose +data source is RAM (e.g. CALLDATCOPY / RETURNDATACOPY) and those whose data source is +an EXO data store (e.g. CODECOPY / EXTCODECOPY). + +|--------+-------------------------------------+-----+------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+-------------------------------------+-----+------------------------------------+---------------------| +| i + x | EQ( 0, frst_read_sbo; 0, frst_tbo ) | | | CARRY OUT iff | +| | | | | . pure_padd = false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * aligned ≡ WCP/RES[i + x] | | +|--------+-------------------------------------+-----+------------------------------------+---------------------| +| i + x | ISZERO( 0, MACRO/EXO_SUM ) | | | USEFUL iff | +| | | | | . pure_padd = false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * data_src_is_ram ≡ WCP/RES[i + x] | | +|--------+-------------------------------------+-----+------------------------------------+---------------------| + + +frst_tlo_increment ≡ + +* frst_tbo + frst_data_trsf_size = 16 q + r +* frst_tbo + (frst_data_trsf_size - 1) = 16 q' + r' + +* frst_tlo_increment: + * If pure_padd = 1 Then 0 + * If pure_padd = 0 Then + * If ⟦TOTNT >= 2⟧ ≡ false Then 0 + * If ⟦TOTNT >= 2⟧ ≡ true Then q +. trns_tlo_increment ≡ q +. frst_padd_tbo ≡ r +. frst_data_trsf_single_target ≡ q' +. If ⟦TOTNT ≥ 2⟧ ≡ true Then +. frst_tlo_increment ≡ q +. mddl_tbo ≡ r +. mddl_tbo + last_data_trsf_size ≡ 16 q'' + r'' +. trns_tlo_increment ≡ q'' +. frst_padd_tbo ≡ r'' +\end{verbatim} +\end{document} + diff --git a/mmu/instructions/anyToRamWithPadding/lua/preprocessing_old.lua.tex b/mmu/instructions/anyToRamWithPadding/lua/preprocessing_old.lua.tex new file mode 100644 index 0000000..99e81be --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/lua/preprocessing_old.lua.tex @@ -0,0 +1,320 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +The preprocessing for ⟦MMU_INST_anyToRamWithPadding⟧ has to answer the following questions: + +- is it all padding ? <== all_padd +- is it mixed (data then) padding) ? <== mixed +- is it all data ? <== all_data +- how many bytes are being transferred from the source to the target ? <== trsf_size + +Nontrivial operations: +- if all_padd = true + - TOTNT = 0 +- if all_padd = false + - frst_read_src_offset ≡ REF_OFFSET + SRC_OFFSET_LO + - last_read_src_offset ≡ frst_read_src_offset + (trsf_size - 1) + - what is TOTNT ? + - is TOTNT >= 2 ? <== totnt_at_least_2 + - if totnt_at_least_2 = false + - is the only nontrivial limb single target ? + - if TOTNT ≠ 1: + - what is the frst source limb byte size ? + - what is the last source limb byte size ? + - is the frst nontrivial limb single target ? + - is the last nontrivial limb single target ? + - are we aligned ? + - if not, what is mddl_tbo ? + - what are init_sbo / init_slo ? + - what are min_tbo / min_tlo ? + +- if there is some padding: + - what is TOTRZ ? + - if TOTRZ = 1: + - is the only padding excision or killingRam ? + - init_tpo ? size ? + - if TOTRZ ≠ 1: + - is the frst padding excision or killingRam ? + - is the last padding excision or killingRam ? + - tbo ? size ? in both cases + +We need to establish the following: +- pure_padding ? +- mixed ? +- pure_data ? +- TOTNT ? + - ⟦TOTNT ≥ 2⟧ ? + - [P] aligned ? +- TOTRZ ? + - ⟦TOTRZ ≥ 2⟧ ? +- if pure_padd ≡ false: + - frst_slo / frst_sbo + - frst_tlo / frst_tbo + - frst_size + - frst_single_target_limb + - if ⟦TOTNT ≥ 2⟧ = true + - increment_init_tlo: true / false + - mddl_tbo + - [P] last_size + - [P] last_single_target_limb +- if pure_data ≡ false + - frst_plo + - [P] frst_pbo + - [P] frst_padd_size + - [P] increment_tlo_at_transition + - [P] last_padd_size + + +We first impose + + TOTLZ = 0 + +We define the shorthand + + . + +The operations below deal with everything in the source if required i.e. whenever pure_padd ≡ false. + +NOTE: +- SIZE is at most a 4 byte integer (MXPX not triggered) +- REF_SIZE and REF_OFFSET are of the same order of magnitude + + the addition real_src_offset + (trsf_size - 1) is safe. + +We next deal with the over all structure of the macro-instruction: +- is it all data ? +- is it all padding ? +- is it a mix of both ? + +|--------+----------------------------------------------+-----+--------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+----------------------------------------------+-----+--------------------------------------------------------+---------------------| +| i + 1 | LT( SRC_OFF_HI, SRC_OFF_LO; 0, REF_SIZE ) | | | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * pure_padd ≡ 1 - WCP/RES[i + 1] | | +| | | | * max_src_offset_or_zero ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then SRC_OFF_LO + (SIZE - 1) | | +|--------+----------------------------------------------+-----+--------------------------------------------------------+---------------------| +| i + 2 | LT( 0, max_src_offset_or_zero; 0, REF_SIZE ) | | | CARRY OUT iff | +| | | | | . pure_padd ≡ false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * mixed ≡ (1 - pure_padd) • (1 - WCP/RES[i + 2]) | | +| | | | * pure_data ≡ (1 - pure_padd) • WCP/RES[i + 2] | | +| | | | * trsf_size ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then | | +| | | | . If pure_data = 0 Then (REF_SIZE - SRC_OFF_LO) | | +| | | | . If pure_data = 1 Then SIZE | | +| | | | | | +| | | | NOTE: pure_padd + mixed + pure_data = 1 | | +|--------+----------------------------------------------+-----+--------------------------------------------------------+---------------------| + +We next deal with all reading operations. Reading refers to extracting data from the source data store. +Such operations are deemed NONTRIVIAL. + +|--------+-------------------------------+---------------------------------+---------------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+-------------------------------+---------------------------------+---------------------------------------------------------------------+---------------------| +| i + 3 | EQ( 0, frst_read_sbo; 0, 0 ) | EUC( frst_read_src_offset; 16 ) | | CARRY OUT iff | +| | | | | . pure_padd ≡ false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_read_src_offset ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then REF_OFFSET + SRC_OFFSET_LO | | +| | | | * frst_read_slo ≡ EUC/QUOT[i + 3] | | +| | | | * frst_read_sbo ≡ EUC/REMD[i + 3] | | +| | | | * frst_read_sbo_iszero ≡ WCP/RES[i + 3] | | +|--------+-------------------------------+---------------------------------+---------------------------------------------------------------------+---------------------| +| i + 4 | EQ( 0, last_read_sbo; 0, 15 ) | EUC( last_read_src_offset; 16 ) | | CARRY OUT iff | +| | | | | . pure_padd ≡ false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * last_read_src_offset ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then frst_read_src_offset + (trsf_size - 1) | | +| | | | * last_read_slo ≡ EUC/QUOT[i + 4] | | +| | | | * last_read_sbo ≡ EUC/REMD[i + 4] | | +| | | | * last_read_sbo_is_15 ≡ WCP/RES[i + 4] | | +|--------+-------------------------------+---------------------------------+---------------------------------------------------------------------+---------------------| +| i + 5 | LT( 0, 1; 0, TOTNT ) | | | CARRY OUT iff | +| | | | | . pure_padd ≡ false | +| | | | IMPOSE: | | +| | | | ======= | | +| | | | | | +| | | | TOTNT = | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then last_read_slo - frst_read_slo + 1 | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * totnt_at_least_2 ≡ WCP/RES[i + 5] | | +| | | | * last_read_src_limb_byte_size ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then 1 + last_read_sbo | | +| | | | . If totnt_at_least_2 = 0: last_read_sbo - frst_read_sbo + 1 | | +| | | | . If totnt_at_least_2 = 1: last_read_sbo + 1 | | +| | | | * frst_read_limb_byte_size ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then | | +| | | | . If totnt_at_least_2 = 0: last_read_sbo - frst_read_sbo + 1 | | +| | | | . If totnt_at_least_2 = 1: 16 - frst_read_sbo | | +|--------+-------------------------------+---------------------------------+---------------------------------------------------------------------+---------------------| + +The following deals the extremal offsets of the target range. + +|--------+------------------------+---------------------------+-----------------------------------------------+-------| +| PP row | WCP | EUC | shorthands | notes | +|--------+------------------------+---------------------------+-----------------------------------------------+-------| +| i + 6 | EQ( 0, min_tbo; 0, 0 ) | EUC( min_tgt_offset; 16 ) | | | +| | | | | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * min_tgt_offset ≡ TGT_OFFSET_LO | | +| | | | * min_tlo ≡ EUC/QUOT[i + 6] | | +| | | | * min_tbo ≡ EUC/REMD[i + 6] | | +| | | | * min_tbo_iszero ≡ WCP/RES[i + 6] | | +|--------+------------------------+---------------------------+-----------------------------------------------+-------| +| i + 7 | EQ( 0, max_tbo; 15 ) | EUC( max_tgt_offset; 16 ) | | | +| | | | | | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * max_tgt_offset ≡ TGT_OFFSET_LO + (SIZE - 1) | | +| | | | * max_tlo ≡ EUC/QUOT[i + 7] | | +| | | | * max_tbo ≡ EUC/REMD[i + 7] | | +| | | | * max_tbo_is_15 ≡ WCP/RES[i + 7] | | +|--------+------------------------+---------------------------+-----------------------------------------------+-------| + +The following deals with padding. +These computatoins are only required if pure_data = false. + +|--------+--------------------------------+---------------------------------------+----------------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+--------------------------------+---------------------------------------+----------------------------------------------------------------------+---------------------| +| i + 8 | ISZERO( 0, frst_pbo ) | EUC( min_tgt_offset + trsf_size; 16 ) | | CARRY OUT iff | +| | | | | . pure_data = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_plo ≡ EUC/QUOT[i + 8] | | +| | | | * frst_pbo ≡ EUC/REMD[i + 8] | | +| | | | * frst_pbo_iszero ≡ WCP/RES[i + 8] | | +|--------+--------------------------------+---------------------------------------+----------------------------------------------------------------------+---------------------| +| i + 9 | LT( 0, 1; 0, TOTRZ ) | | | CARRY OUT iff | +| | | | | . pure_data = false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * TOTRZ = | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then max_tlo - frst_plo + 1 | | +| | | | * totrz_at_least_2 ≡ WCP/RES[i + 9] | | +| | | | * frst_padd_size ≡ | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then | | +| | | | . If totrz_at_least_2 = 1 Then 16 - frst_pbo | | +| | | | . If totrz_at_least_2 = 0 Then last_pbo - frst_pbo + 1 | | +| | | | * last_padd_size ≡ | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then | | +| | | | . If totrz_at_least_2 = 1 Then last_pbo + 1 | | +| | | | . If totrz_at_least_2 = 0 Then last_pbo - frst_pbo + 1 | | +|--------+--------------------------------+---------------------------------------+----------------------------------------------------------------------+---------------------| +| i + 10 | EQ( 0, frst_padd_size; 0, 16 ) | EUC( last_padd_size; 16 ) | | CARRY OUT iff | +| | | | | . pure_data = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_padd_full: | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then WCP/RES[i + 10] | | +| | | | * last_padd_full: | | +| | | | . If pure_data = 1 Then 0 | | +| | | | . If pure_data = 0 Then | | +| | | | . If last_padd_size ≠ 16 Then last_padd_full = 0 | | +| | | | . If last_padd_size ≠ EUC/REM[i + 10] Then last_padd_full = 1 | | +|--------+--------------------------------+---------------------------------------+----------------------------------------------------------------------+---------------------| + +The next rows deal with the insertion of the extremal source limbs into the target domain. + +|--------+------------------------------------+----------------------------------------------------------+--------------------------------------------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+------------------------------------+----------------------------------------------------------+--------------------------------------------------------------------------+---------------------| +| i + 11 | EQ( 0, frst_read_sbo; 0, min_tbo ) | | | CARRY OUT iff | +| | | | | . pure_padd = false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * aligned ≡ WCP/RES[i + 11] | | +|--------+------------------------------------+----------------------------------------------------------+--------------------------------------------------------------------------+---------------------| +| i + 12 | EQ( 0, EUC/REM[i + 12]; 0, 15 ) | EUC( min_tbo + (frst_read_src_limb_byte_size - 1); 16 ) | | CARRY OUT iff | +| | | | | . pure_padd = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * frst_trsf_maxes_out_target_limb ≡ WCP/RES[i + 12] | | +| | | | * frst_trsf_targets_single_limb ≡ 1 - EUC/QUOT[i + 12] | | +| | | | * mddl_tbo ≡ | | +| | | | . If pure_padd = 1 Then 0 | | +| | | | . If pure_padd = 0 Then | | +| | | | . If frst_trsf_maxes_out_target_limb = 0 Then 1 + EUC/REM[i + 12] | | +| | | | . If frst_trsf_maxes_out_target_limb = 1 Then 0 | | +|--------+------------------------------------+----------------------------------------------------------+--------------------------------------------------------------------------+---------------------| +| i + 13 | EQ( 0, EUC/REMD[i + 13]; 15 ) | EUC( mddl_tbo + (last_read_src_limb_byte_size - 1); 16 ) | | CARRY OUT iff | +| | | | | . pure_padd = false | +| | | | | | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * last_trsf_maxes_out_target_limb ≡ WCP/RES[i + 13] | | +| | | | * last_trsf_targets_single_limb ≡ 1 - EUC/QUOT[i + 13] | | +|--------+------------------------------------+----------------------------------------------------------+--------------------------------------------------------------------------+---------------------| + +We have a final row that allows the MMU module to differentiate between instructions whose +data source is RAM (e.g. CALLDATCOPY / RETURNDATACOPY) and those whose data source is +an EXO data store (e.g. CODECOPY / EXTCODECOPY). + +|--------+----------------------------+-----+-------------------------------------+---------------------| +| PP row | WCP | EUC | shorthands | notes | +|--------+----------------------------+-----+-------------------------------------+---------------------| +| i + 14 | ISZERO( 0, MACRO/EXO_SUM ) | | | USEFUL iff | +| | | | | . pure_padd = false | +| | | | DEFINE: | | +| | | | ======= | | +| | | | | | +| | | | * data_src_is_ram ≡ WCP/RES[i + 14] | | +|--------+----------------------------+-----+-------------------------------------+---------------------| +\end{verbatim} +\end{document} diff --git a/mmu/instructions/anyToRamWithPadding/pure_padding/_inputs.tex b/mmu/instructions/anyToRamWithPadding/pure_padding/_inputs.tex new file mode 100644 index 0000000..6609ce2 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/pure_padding/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsubsection{Column aliasing } \label{ mmu: instructions: any to ram with padding: pure padding column aliasing} \input{instructions/anyToRamWithPadding/pure_padding/aliasing} +\subsubsubsection{Pre-processing } \label{ mmu: instructions: any to ram with padding: pure padding preprocessing} \input{instructions/anyToRamWithPadding/pure_padding/preprocessing} +\subsubsubsection{Initialization } \label{ mmu: instructions: any to ram with padding: pure padding initialization} \input{instructions/anyToRamWithPadding/pure_padding/initializing} +\subsubsubsection{Micro-instruction-writing } \label{ mmu: instructions: any to ram with padding: pure padding micro instruction writing} \input{instructions/anyToRamWithPadding/pure_padding/micro_instruction_writing} diff --git a/mmu/instructions/anyToRamWithPadding/pure_padding/aliasing.tex b/mmu/instructions/anyToRamWithPadding/pure_padding/aliasing.tex new file mode 100644 index 0000000..97810ff --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/pure_padding/aliasing.tex @@ -0,0 +1,11 @@ +\begin{center} + \boxed{ \text{The shorthands below assume } \mmuInstFlagAnyToRamWithPaddingPurePadding _{i} = 1 } +\end{center} +We alias some column names for the ``pure padding case'': +\[ + \left\{ \begin{array}{lcl} + \locLastPaddingIsFull & \define & \ppOutputColBin {1} \\ + \locLastPaddingSize & \define & \ppOutputCol {1} \\ + \end{array} \right. +\] + diff --git a/mmu/instructions/anyToRamWithPadding/pure_padding/initializing.tex b/mmu/instructions/anyToRamWithPadding/pure_padding/initializing.tex new file mode 100644 index 0000000..5af45c7 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/pure_padding/initializing.tex @@ -0,0 +1,111 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagAnyToRamWithPaddingPurePadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We use the present vantage point to settle some micro-instruction related paramaters, in particular those which remain constant throughout micro-instruction-writing and other pertaining to the first micro-instruction-writing-row. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ + \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroLimbTwo_{i} \\ + \microCns _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microCnt _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroTgtId_{i} \\ + \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microPhase _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \end{array} \right. + \] + \item[First micro-instruction-writing-row:] \label{mmu: instructions: modexpdata: initialize: tlo is initially 0} + we impose + \begin{description} + \item[Generalities:] + we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \valueToBeSet \\ + \microSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \valueToBeSet \\ + \microSlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microSbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \microTlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locMinTlo \\ + \microTbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locMinTbo \\ + \microLimb _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microCns _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \end{array} \right. + \] + \item[The $\locTotrzIsOne \equiv 1$ case:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locOnlyPaddingInst \\ + \microSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locOnlyPaddingSize \\ + % \microSlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locMinTlo \\ + % \microTbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locMinTbo \\ + % \microLimb _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microCns _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \end{array} \right. + \] + where we use the following shorthand + \begin{enumerate} + \item \If $\locOnlyPaddingIsFull = 0$ \Then \( \locOnlyPaddingInst \define \mmioInstRamExcision \) + \item \If $\locOnlyPaddingIsFull = 1$ \Then \( \locOnlyPaddingInst \define \mmioInstRamVanishes \) + \end{enumerate} + \item[The $\locTotrzIsOne \equiv 0$ case:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locFirstPaddingInst \\ + \microSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locFirstPaddingSize \\ + % \microSlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locInitTlo \\ + % \microTbo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \locInitTbo \\ + % \microLimb _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microCns _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstAnyToRamWithPaddingPurePaddingValuePO} & = & \nothing \\ + \end{array} \right. + \] + where we use the following shorthand + \begin{enumerate} + \item \If $\locFirstPaddingIsFull = 0$ \Then \( \locFirstPaddingInst \define \mmioInstRamExcision \) + \item \If $\locFirstPaddingIsFull = 1$ \Then \( \locFirstPaddingInst \define \mmioInstRamVanishes \) + \end{enumerate} + \end{description} +\end{description} + diff --git a/mmu/instructions/anyToRamWithPadding/pure_padding/micro_instruction_writing.tex b/mmu/instructions/anyToRamWithPadding/pure_padding/micro_instruction_writing.tex new file mode 100644 index 0000000..208411e --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/pure_padding/micro_instruction_writing.tex @@ -0,0 +1,73 @@ +\begin{center} + \boxed{ \text{The constraints below assume that } \mmuInstFlagAnyToRamWithPaddingPurePadding _{i} = 1.} +\end{center} +\begin{description} + \item[Paying forward:] + \If $\isMiddleRZ_{i} + \isLastRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \valueToBeSet \\ + \microSize _{i} & = & \valueToBeSet \\ + \microSlo _{i} & = & \nothing \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & 1 + \microTlo_{i - 1} \\ + \microTbo _{i} & = & 0 \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + \saNote{} + The constraint ``$\microTbo_{i} = 0$'' is only required for the last row (which might be an excition instruction.) + We don't draw the distinction and just impose the above. + \item[The ``middle right padding'' rows:] + \If $\isMiddleRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstRamVanishes \\ + \microSize _{i} & = & \nothing \\ + % \microSlo _{i} & = & \nothing \\ + % \microSbo _{i} & = & \nothing \\ + % \microTlo _{i} & = & 1 + \microTlo_{i - 1} \\ + % \microTbo _{i} & = & 0 \\ + % \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + \item[The ``last right padding'' row:] + \If $\isLastRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locLastPaddingInst \\ + \microSize _{i} & = & \locLastPaddingSize_{i} \\ + % \microSlo _{i} & = & \nothing \\ + % \microSbo _{i} & = & \nothing \\ + % \microTlo _{i} & = & 1 + \microTlo_{i - 1} \\ + % \microTbo _{i} & = & 0 \\ + % \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where we define the \locLastPaddingInst{} shorthand as follows: + \begin{enumerate} + \item \If $\locLastPaddingIsFull_{i} = 0$ \Then $\locLastPaddingInst \define \mmioInstRamExcision$ + \item \If $\locLastPaddingIsFull_{i} = 1$ \Then $\locLastPaddingInst \define \mmioInstRamVanishes$ + \end{enumerate} +\end{description} diff --git a/mmu/instructions/anyToRamWithPadding/pure_padding/preprocessing.tex b/mmu/instructions/anyToRamWithPadding/pure_padding/preprocessing.tex new file mode 100644 index 0000000..bf27ceb --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/pure_padding/preprocessing.tex @@ -0,0 +1,61 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagAnyToRamWithPaddingPurePadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +This section deals with the pre-processing of the \mmuInstAnyToRamWithPadding{} in the +``pure padding'' subcase. +We outline the preprocessing rows +\begin{description} + \item[Total number of right padding operations:] + \[ + \left\{ \begin{array}{lclr} + \ppTotLZ _{i} & = & 0 \\ + \ppTotNT _{i} & = & 0 \\ + \ppTotRZ _{i} & = & \locMaxTlo - \locMinTlo + 1 \\ + \end{array} \right. + \] + \def\rowNum{3} \item[Processing row $n^\circ(i + \rowNum)$:] + we impose + \[ + \callToEq + {i}{\rowNum} + {0}{\ppTotRZ_{i}} + {1} + \] + we introduce the following shorthand + \[ + \locTotrzIsOne \define \ppWcpRes_{i + \rowNum} + \] + \def\rowNum{4} \item[Processing row $n^\circ(i + \rowNum)$:] + we impose + \[ + \left\{ \begin{array}{lcl} + \callToIszero + {i}{\rowNum} + {0}{\locMinTbo} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {1 + \locMaxTbo} + {\llarge} + \\ + \end{array} \right. + \] + and we introduce the following shorthands as well as impose constraints: + \[ + \left\{ \begin{array}{lcl} + \locFirstPaddingIsFull & \define & \ppWcpRes _{i + \rowNum} \\ + \locLastPaddingIsFull & ~ = ~ & (1 - \locTotrzIsOne) \cdot \ppEucQuot _{i + \rowNum} \\ + \locOnlyPaddingIsFull & \define & \locFirstPaddingIsFull \cdot \locLastPaddingIsFull \vspace{2mm} \\ + \locFirstPaddingSize & \define & \llarge - \locMinTbo \\ + \locLastPaddingSize & ~ = ~ & (1 - \locTotrzIsOne) \cdot (1 + \locMaxTbo) \\ + \locOnlyPaddingSize & \define & \locPaddingSize \\ + \end{array} \right. + \] + \saNote{} \locLastPaddingIsFull{} and \locLastPaddingSize{} should only contain data when they are needed, i.e. whenever $\ppTotRZ \not \equiv 1$. +\end{description} diff --git a/mmu/instructions/anyToRamWithPadding/shared/_inputs.tex b/mmu/instructions/anyToRamWithPadding/shared/_inputs.tex new file mode 100644 index 0000000..56c513b --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/shared/_inputs.tex @@ -0,0 +1,2 @@ +\subsubsection{Shared pre-processing} \label{mmu: instructions: any to ram with padding: shared preprocessing} \input{instructions/anyToRamWithPadding/shared/preprocessing} +\subsubsection{Conventions} \label{mmu: instructions: any to ram with padding: conventions} \input{instructions/anyToRamWithPadding/shared/conventions} diff --git a/mmu/instructions/anyToRamWithPadding/shared/conventions.tex b/mmu/instructions/anyToRamWithPadding/shared/conventions.tex new file mode 100644 index 0000000..3de6989 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/shared/conventions.tex @@ -0,0 +1 @@ +We will use the following abbreviation at several points: \col{DT} is short for \col{data\_transfer}. diff --git a/mmu/instructions/anyToRamWithPadding/shared/preprocessing.tex b/mmu/instructions/anyToRamWithPadding/shared/preprocessing.tex new file mode 100644 index 0000000..81b614e --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/shared/preprocessing.tex @@ -0,0 +1,117 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagAnyToRamWithPadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +Recall that the \mmuMod{} module's processing of the \mmuInstAnyToRamWithPadding{} is multiplexed into two subcases, see note~(\ref{mmu: decoding: any to ram with padding multiplexing}). +We outline the common preprocessing rows +\begin{description} + \item[Number of preprocessing rows:] + we impose $\ppTotLZ _{i} = 0$ + \item[Some shorthands ``target range'' shorthands:] + we define + \[ + \left\{ \begin{array}{lcl} + \locMinTgtOffset & \define & \macroTgtOffsetLo_{i} \\ + \locMaxTgtOffset & \define & \macroTgtOffsetLo_{i} + (\macroSize_{i} - 1) \\ + \end{array} \right. + \] + \def\rowNum{1} \item[Processing row $n^\circ(i + \rowNum)$:] + we impose + \[ + \left\{ \begin{array}{lcl} + \callToLt + {i}{\rowNum} + {\macroSrcOffsetHi_{i}}{\macroSrcOffsetLo_{i}} + {\macroRefSize_{i}} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {\locMinTgtOffset} + {\llarge} + \\ + \end{array} \right. + \] + and we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locPurePadding & \define & 1 - \ppWcpRes _{i + \rowNum} \\ + \locMinTlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locMinTbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + \begin{enumerate} + \item \If $\locPurePadding = 1$ \Then $\locMaxSrcOffsetOrZero \define 0$ + \item \If $\locPurePadding = 0$ \Then $\locMaxSrcOffsetOrZero \define \macroSrcOffsetLo_{i} + \big( \macroSize_{i} - 1 \big)$ + \end{enumerate} + \def\rowNum{2} \item[Processing row $n^\circ(i + \rowNum)$:] + we impose + \[ + \left\{ \begin{array}{lcl} + \callToLt + {i}{\rowNum} + {0}{\locMaxSrcOffsetOrZero_{i}} + {\macroRefSize_{i}} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {\locMaxTgtOffset} + {\llarge} + \\ + \end{array} \right. + \] + and we \textbf{unconditionally} define the following shorthands + \[ + \left\{ \begin{array}{lclr} + \locMixed & \define & (1 - \locPurePadding) \cdot (1 - \ppWcpRes_{i + \rowNum}) \\ + \locPureData & \define & (1 - \locPurePadding) \cdot \ppWcpRes_{i + \rowNum} \\ + \locMaxTlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locMaxTbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + At this stage it also makes sense to define the \locTransferSize{} and \locPaddingSize{} shorthands that will be used later + \begin{enumerate} + \item \If $\locPurePadding = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locTransferSize & \define & 0 \\ + \locPaddingSize & \define & \macroSize_{i} \\ + \end{array} \right. + \] + \item \If $\locMixed = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locTransferSize & \define & \macroRefSize_{i} - \macroSrcOffsetLo_{i} \\ + \locPaddingSize & \define & \macroSize_{i} - (\macroRefSize_{i} - \macroSrcOffsetLo_{i}) \\ + \end{array} \right. + \] + \item \If $\locPureData = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locTransferSize & \define & \macroSize_{i} \\ + \locPaddingSize & \define & 0 \\ + \end{array} \right. + \] + \end{enumerate} + \saNote{} These values satisfy the following: + \[ + \left\{ \begin{array}{lclcl} + 0 & \leq & \locTransferSize & \leq & \min\Big\{ \macroSize_{i}, \macroRefSize_{i} \Big\} \\ + 0 & \leq & \locPaddingSize & \leq & \macroSize_{i} \\ + \multicolumn{5}{l}{\locTransferSize + \locPaddingSize = \macroSize_{i}} \\ + \end{array} \right. + \] + \item[Justifying the execution path:] + we impose the following constraints: + \[ + \left\{ \begin{array}{lcl} + \mmuInstFlagAnyToRamWithPaddingPurePadding _{i} & = & \locPurePadding \\ + \mmuInstFlagAnyToRamWithPaddingSomeData _{i} & = & \locMixed + \locPureData \\ + \end{array} \right. + \] +\end{description} +From this point on the analysis follows different paths according to the execution path which was justified above. diff --git a/mmu/instructions/anyToRamWithPadding/some_data/_inputs.tex b/mmu/instructions/anyToRamWithPadding/some_data/_inputs.tex new file mode 100644 index 0000000..9126649 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/some_data/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsubsection{Column aliasing } \label{ mmu: instructions: any to ram with padding: some data: column aliasing} \input{instructions/anyToRamWithPadding/some_data/aliasing} +\subsubsubsection{Data pre-processing } \label{ mmu: instructions: any to ram with padding: some data: preprocessing} \input{instructions/anyToRamWithPadding/some_data/preprocessing} +\subsubsubsection{Initialization } \label{ mmu: instructions: any to ram with padding: some data: initializing} \input{instructions/anyToRamWithPadding/some_data/initializing} +\subsubsubsection{Micro-instruction-writing } \label{ mmu: instructions: any to ram with padding: some data: micro instruction writing} \input{instructions/anyToRamWithPadding/some_data/micro_instruction_writing} diff --git a/mmu/instructions/anyToRamWithPadding/some_data/aliasing.tex b/mmu/instructions/anyToRamWithPadding/some_data/aliasing.tex new file mode 100644 index 0000000..f56056d --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/some_data/aliasing.tex @@ -0,0 +1,18 @@ +\begin{center} + \boxed{ \text{The shorthands below assume that } \mmuInstFlagAnyToRamWithPaddingSomeData _{i} = 1 } +\end{center} +We alias some column names for the ``pure data case'': +\[ + \left\{ \begin{array}{lclr} + \locTloIncrementAfterFirst & \define & \ppOutputColBin {1} \\ + \locAligned & \define & \ppOutputColBin {2} \\ + \locMiddleTbo & \define & \ppOutputCol {1} \\ + \locLastDataTransferSingleTarget & \define & \ppOutputColBin {3} \\ + \locLastDataTransferSize & \define & \ppOutputCol {2} \\ + \locTloIncrementAtTransition & \define & \ppOutputColBin {4} & \text{(mixed case only)} \\ + \locFirstPbo & \define & \ppOutputCol {3} & \text{(mixed case only)} \\ + \locFirstPaddingSize & \define & \ppOutputCol {4} & \text{(mixed case only)} \\ + \locLastPaddingSize & \define & \ppOutputCol {5} & \text{(mixed case only)} \\ + \locDataSourceIsRam & \define & \ppOutputColBin {5} \\ + \end{array} \right. +\] diff --git a/mmu/instructions/anyToRamWithPadding/some_data/initializing.tex b/mmu/instructions/anyToRamWithPadding/some_data/initializing.tex new file mode 100644 index 0000000..ffd66a0 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/some_data/initializing.tex @@ -0,0 +1,147 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagAnyToRamWithPaddingSomeData _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +The upcoming constraints facilitate the transition from pre-processing to micro-instruction-writing. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ + \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroLimbTwo_{i} \\ + \microCns _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMicroCns \\ + \microCnt _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroTgtId_{i} \\ + \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroExoSum_{i} \\ + \microPhase _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMicroIdOne \\ + \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroRefSize_{i} \\ + \end{array} \right. + \] + where have used shorthands obeying the following definitions + \begin{enumerate} + \item \If $\locDataSourceIsRam = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locMicroCns & \define & \macroSrcId_{i} \\ + \locMicroIdOne & \define & \nothing \\ + \end{array} \right. + \] + \item \If $\locDataSourceIsRam = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \locMicroCns & \define & \nothing \\ + \locMicroIdOne & \define & \macroSrcId_{i} \\ + \end{array} \right. + \] + \end{enumerate} +\end{description} +\saNote{} +We provide the \macroRefSize{} in the \microTotalSize{} column to satisfy the lookup interface from the \mmioMod{} to the \romMod{}. +This size isn't required by the \mmioMod{} \emph{per se}. +\begin{description} + \item[First or only micro-instruction-writing-row:] \label{mmu: instructions: modexpdata: initialize: tlo is initially 0} + we impose + \begin{description} + \item[Generalities:] + we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \valueToBeSet \\ + \microSize _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \valueToBeSet \\ + \microSlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinSlo \\ + \microSbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinSbo \\ + \microTlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinTlo \\ + \microTbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinTbo \\ + \microLimb _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \relevantValue \\ + % \microCns _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + \end{array} \right. + \] +\saNote{} In the case $\locDataSourceIsRam = 0$, in order to comply with the lookup between \mmuMod{} and \mmioMod{} one has to fill the $\microLimb$ column with the relevant limb, hence the notation ``$\relevantValue$''. + \item[The $\locTotntIsOne \equiv 1$ case:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locOnlyDataTransferInst \\ + \microSize _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locOnlyDataTransferSize \\ + % \microSlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinTlo \\ + % \microTbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinTbo \\ + % \microLimb _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microCns _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + \end{array} \right. + \] + where \locOnlyDataTransferInst{} is given the following definition: + \begin{enumerate} + \item \If $\locDataSourceIsRam = 1$ + \begin{enumerate} + \item \If $\locOnlyDataTransferSingleTarget = 1$ \Then $\locOnlyDataTransferInst = \mmioInstRamToRamPartial$ + \item \If $\locOnlyDataTransferSingleTarget = 0$ \Then $\locOnlyDataTransferInst = \mmioInstRamToRamTwoTarget$ + \end{enumerate} + \item \If $\locDataSourceIsRam = 0$ + \begin{enumerate} + \item \If $\locOnlyDataTransferSingleTarget = 1$ \Then $\locOnlyDataTransferInst = \mmioInstLimbToRamOneTarget$ + \item \If $\locOnlyDataTransferSingleTarget = 0$ \Then $\locOnlyDataTransferInst = \mmioInstLimbToRamTwoTarget$ + \end{enumerate} + \end{enumerate} + \item[The $\locTotntIsOne \equiv 0$ case:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locFirstDataTransferInst \\ + \microSize _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locFirstDataTransferSize \\ + % \microSlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinTlo \\ + % \microTbo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \locMinTbo \\ + % \microLimb _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microCns _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstAnyToRamWithPaddingSomeDataValuePO} & = & \nothing \\ + \end{array} \right. + \] + where \locOnlyDataTransferInst{} is given the following definition: + \begin{enumerate} + \item \If $\locDataSourceIsRam = 1$ + \begin{enumerate} + \item \If $\locFirstDataTransferSingleTarget = 1$ \Then $\locFirstDataTransferInst = \mmioInstRamToRamPartial$ + \item \If $\locFirstDataTransferSingleTarget = 0$ \Then $\locFirstDataTransferInst = \mmioInstRamToRamTwoTarget$ + \end{enumerate} + \item \If $\locDataSourceIsRam = 0$ + \begin{enumerate} + \item \If $\locFirstDataTransferSingleTarget = 1$ \Then $\locFirstDataTransferInst = \mmioInstLimbToRamOneTarget$ + \item \If $\locFirstDataTransferSingleTarget = 0$ \Then $\locFirstDataTransferInst = \mmioInstLimbToRamTwoTarget$ + \end{enumerate} + \end{enumerate} + \end{description} +\end{description} + diff --git a/mmu/instructions/anyToRamWithPadding/some_data/micro_instruction_writing.tex b/mmu/instructions/anyToRamWithPadding/some_data/micro_instruction_writing.tex new file mode 100644 index 0000000..c8b8888 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/some_data/micro_instruction_writing.tex @@ -0,0 +1,193 @@ +\begin{center} \boxed{ \text{The constraints below assume that } \mmuInstFlagAnyToRamWithPaddingSomeData _{i} = 1 } +\end{center} +\begin{description} + \item[First row paying forward:] + \If $\isFirstNT_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + 1} & = & \valueToBeSet \\ + \microSize _{i + 1} & = & \valueToBeSet \\ + \microSlo _{i + 1} & = & \microSlo_{i} + 1 \\ + \microSbo _{i + 1} & = & 0 \\ + \microTlo _{i + 1} & = & \microTlo_{i} + \locTloIncrementAfterFirst_{i} \\ + \microTbo _{i + 1} & = & \locMiddleTbo_{i} \\ + \microLimb _{i + 1} & = & \relevantValue \\ + % \microCns _{i + 1} & = & \macroSrcId_{i} \\ + % \microCnt _{i + 1} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + 1} & = & \nothing \\ + % \microExoSum _{i + 1} & = & \nothing \\ + % \microPhase _{i + 1} & = & \nothing \\ + % \microIdOne _{i + 1} & = & \nothing \\ + % \microIdTwo _{i + 1} & = & \nothing \\ + \end{array} \right. + \] + \item[Middle rows:] + \If $\isMiddleNT_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locMiddleDataTransferInst \\ + \microSize _{i} & = & \llarge \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \alreadySet \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where \locMiddleDataTransferInst{} is given the following definition: + \begin{enumerate} + \item \If $\locDataSourceIsRam_{i} = 1$ + \begin{enumerate} + \item \If $\locAligned_{i} = 1$ \Then $\locFirstDataTransferInst \define \mmioInstRamToRamTransplant$ + \item \If $\locAligned_{i} = 0$ \Then $\locFirstDataTransferInst \define \mmioInstRamToRamTwoTarget$ + \end{enumerate} + \item \If $\locDataSourceIsRam_{i} = 0$ + \begin{enumerate} + \item \If $\locAligned_{i} = 1$ \Then $\locFirstDataTransferInst \define \mmioInstLimbToRamTransplant$ + \item \If $\locAligned_{i} = 0$ \Then $\locFirstDataTransferInst \define \mmioInstLimbToRamTwoTarget$ + \end{enumerate} + \end{enumerate} + \item[Middle rows paying forward:] + \If $\isMiddleNT_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + 1} & = & \valueToBeSet \\ + \microSize _{i + 1} & = & \valueToBeSet \\ + \microSlo _{i + 1} & = & \microSlo_{i} + 1 \\ + \microSbo _{i + 1} & = & 0 \\ + \microTlo _{i + 1} & = & \microTlo_{i} + 1 \\ + \microTbo _{i + 1} & = & \locMiddleTbo_{i} \\ + \microLimb _{i + 1} & = & \relevantValue \\ + % \microCns _{i + 1} & = & \macroSrcId_{i} \\ + % \microCnt _{i + 1} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + 1} & = & \nothing \\ + % \microExoSum _{i + 1} & = & \nothing \\ + % \microPhase _{i + 1} & = & \nothing \\ + % \microIdOne _{i + 1} & = & \nothing \\ + % \microIdTwo _{i + 1} & = & \nothing \\ + \end{array} \right. + \] + \item[Last row:] + \If $\isLastNT_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locLastDataTransferInst \\ + \microSize _{i} & = & \locLastDataTransferSize_{i} \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \alreadySet \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where \locLastDataTransferInst{} is given the following definition: + \begin{enumerate} + \item \If $\locDataSourceIsRam_{i} = 1$ + \begin{enumerate} + \item \If $\locLastDataTransferSingleTarget_{i} = 1$ \Then $\locLastDataTransferInst \define \mmioInstRamToRamPartial$ + \item \If $\locLastDataTransferSingleTarget_{i} = 0$ \Then $\locLastDataTransferInst \define \mmioInstRamToRamTwoTarget$ + \end{enumerate} + \item \If $\locDataSourceIsRam_{i} = 0$ + \begin{enumerate} + \item \If $\locLastDataTransferSingleTarget_{i} = 1$ \Then $\locLastDataTransferInst \define \mmioInstLimbToRamOneTarget$ + \item \If $\locLastDataTransferSingleTarget_{i} = 0$ \Then $\locLastDataTransferInst \define \mmioInstLimbToRamTwoTarget$ + \end{enumerate} + \end{enumerate} + \item[Transition row:] + \If $\isOnlyRZ_{i} + \isFirstRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstRamExcision \\ + \microSize _{i} & = & \locFirstPaddingSize_{i} \\ + \microSlo _{i} & = & \nothing \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & \microTlo_{i - 1} + \locTloIncrementAtTransition_{i} \\ + \microTbo _{i} & = & \locFirstPbo_{i} \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + \item[Paying forward:] + \If $\isFirstRZ_{i} + \isMiddleRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + 1} & = & \valueToBeSet \\ + \microSize _{i + 1} & = & \valueToBeSet \\ + \microSlo _{i + 1} & = & \nothing \\ + \microSbo _{i + 1} & = & \nothing \\ + \microTlo _{i + 1} & = & 1 + \microTlo_{i} \\ + \microTbo _{i + 1} & = & 0 \\ + \microLimb _{i + 1} & = & \nothing \\ + % \microCns _{i + 1} & = & \macroSrcId_{i} \\ + % \microCnt _{i + 1} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + 1} & = & \nothing \\ + % \microExoSum _{i + 1} & = & \nothing \\ + % \microPhase _{i + 1} & = & \nothing \\ + % \microIdOne _{i + 1} & = & \nothing \\ + % \microIdTwo _{i + 1} & = & \nothing \\ + \end{array} \right. + \] + \saNote{} + The constraint ``$\microTbo_{i} = 0$'' is only required for the last row (which might be an excision instruction.) + \item[The ``middle right padding'' rows:] + \If $\isMiddleRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstRamVanishes \\ + \microSize _{i} & = & \nothing \\ + % \microSlo _{i} & = & \nothing \\ + % \microSbo _{i} & = & \nothing \\ + % \microTlo _{i} & = & 1 + \microTlo_{i - 1} \\ + % \microTbo _{i} & = & 0 \\ + % \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + \item[The ``last right padding'' row:] + \If $\isLastRZ_{i} = 1$ \Then we impose that + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstRamExcision \\ + \microSize _{i} & = & \locLastPaddingSize_{i} \\ + % \microSlo _{i} & = & \nothing \\ + % \microSbo _{i} & = & \nothing \\ + % \microTlo _{i} & = & 1 + \microTlo_{i - 1} \\ + % \microTbo _{i} & = & 0 \\ + % \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] +\end{description} + diff --git a/mmu/instructions/anyToRamWithPadding/some_data/preprocessing.tex b/mmu/instructions/anyToRamWithPadding/some_data/preprocessing.tex new file mode 100644 index 0000000..a040e78 --- /dev/null +++ b/mmu/instructions/anyToRamWithPadding/some_data/preprocessing.tex @@ -0,0 +1,256 @@ +\begin{center} + \boxed{% + \text{The constraints below assume that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagAnyToRamWithPaddingSomeData _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +This section deals with \textbf{parts} of the pre-processing of the \mmuInstAnyToRamWithPadding{} +in the two subcases where some ``source data'' is beind copied over. +We outline the common preprocessing rows +\begin{description} + \def\rowNum{3} \item[Processing row $n^\circ(i + \rowNum)$:] + we determine whether to use + ``\texttt{ramToRam}''-type micro-instructions (e.g. for \inst{CALLDATACOPY} and \inst{RETURNDATACOPY}) or + ``\texttt{exoToRam}''-type micro-instructions (e.g. for \inst{CODECOPY} and \inst{EXTCODECOPY}.) + \[ + \callToIszero + {i}{\rowNum} + {0}{\macroExoSum_{i}} + \] + and we impose the following constraint $\locDataSourceIsRam = \ppWcpRes_{i + \rowNum}$. + + We further impose that \If $\locDataSourceIsRam = 0$ \Then $\macroExoSum_{i} = \exoWeightRom$ (\trash). + \item[Total number of nontrivial operations:] + we impose that + \[ + \left\{ \begin{array}{lclr} + \ppTotLZ _{i} & = & 0 \\ + \ppTotNT _{i} & = & \locMaxSlo{} - \locMinSlo{} + 1 \\ + \ppTotRZ _{i} & = & \valueToBeSet \\ + \end{array} \right. + \] + \saNote{} The shorthands \locMaxSlo{} and \locMinSlo{} are defined below. + \def\rowNum{4} \item[Processing row $n^\circ(i + \rowNum)$:] + we impose + \[ + \callToEq + {i}{\rowNum} + {0}{\ppTotNT_{i}} + {1} + \] + we introduce the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locTotntIsOne & \define & \ppWcpRes_{i + \rowNum} \\ + \locOnlyDataTransferSize & \define & \locTransferSize \\ + \locFirstDataTransferSize & \define & \llarge - \locMinSbo \\ + \end{array} \right. + \] + and the following constraint + \[ + \locLastDataTransferSize_{i} = \locMaxSbo + 1 + \] + \def\rowNum{5} \item[Processing row $n^\circ(i + \rowNum)$:] + we perform computations on the minimal source domain offset and determine alignment + \[ + \left\{ \begin{array}{lcl} + \callToEuc + {i}{\rowNum} + {\locMinSrcOffset} + {\llarge} + \vspace{2mm} \\ + \callToEq + {i}{\rowNum} + {0}{\locMinTbo} + {\locMinSbo} + \\ + \end{array} \right. + \] + where we define / have used the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locMinSrcOffset & \define & \macroSrcOffsetLo _{i} + \macroRefOffset_{i} \\ + \locMinSlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locMinSbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + and we impose the following constraint + \[ + \locAligned = \ppWcpRes_{i + \rowNum} + \] + \def\rowNum{6} \item[Processing row $n^\circ(i + \rowNum)$:] + we perform computations on the maximal source domain offset: + \[ + \callToEuc + {i}{\rowNum} + {\locMaxSrcOffset} + {\llarge} + \] + where we define / have used the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locMaxSrcOffset & \define & \locMinSrcOffset _{i} + (\locTransferSize - 1) \\ + \locMaxSlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locMaxSbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + \def\rowNum{7} \item[Processing row $n^\circ(i + \rowNum)$:] + \If $\locTotntIsOne = 1$ \Then + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{\rowNum} + {\locMinTbo + (\locOnlyDataTransferSize - 1)} + {\llarge} + \vspace{2mm} + \\ + \callToEq + {i}{\rowNum} + {0}{\ppEucRem_{i + \rowNum}} + {\llargeMO} + \\ + \end{array} \right. + \] + and we define the following shorthands + \[ + \left\{ \begin{array}{lclr} + \locOnlyDataTransferSingleTarget & \define & 1 - \ppEucQuot _{i + \rowNum} \\ + \locOnlyDataTransferMaxesOutTarget & \define & \ppWcpRes _{i + \rowNum} \\ + \end{array} \right. + \] + \def\rowNum{8} \item[Processing row $n^\circ(i + \rowNum)$:] + \If $\locTotntIsOne = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \callToEuc + {i}{\rowNum} + {\locMinTbo + (\locFirstDataTransferSize - 1)} + {\llarge} + \vspace{2mm} + \\ + \callToEq + {i}{\rowNum} + {0}{\ppEucRem_{i + \rowNum}} + {\llargeMO} + \\ + \end{array} \right. + \] + and we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locFirstDataTransferSingleTarget & \define & 1 - \ppEucQuot _{i + \rowNum} \\ + \locFirstDataTransferMaxesOutTarget & \define & \ppWcpRes _{i + \rowNum} \\ + \end{array} \right. + \] + and we impose the following constraints: + \begin{enumerate} + \item \If $\locFirstDataTransferMaxesOutTarget = 1$ \Then $\locMiddleTbo = 0$ + \item \If $\locFirstDataTransferMaxesOutTarget = 0$ \Then $\locMiddleTbo = 1 + \ppEucRem _{i + \rowNum}$ + \end{enumerate} + \def\rowNum{9} \item[Processing row $n^\circ(i + \rowNum)$:] + \If $\locTotntIsOne = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \callToEuc + {i}{\rowNum} + {\locMiddleTbo + (\locLastDataTransferSize - 1)} + {\llarge} + \vspace{2mm} + \\ + \callToEq + {i}{\rowNum} + {0}{\ppEucRem_{i + \rowNum}} + {\llargeMO} + \\ + \end{array} \right. + \] + and we impose the following constraints + \[ + \left\{ \begin{array}{lcl} + \locLastDataTransferSingleTarget & = & 1 - \ppEucQuot _{i + \rowNum} \\ + \locLastDataTransferMaxesOutTarget & = & \ppWcpRes _{i + \rowNum} \\ + \end{array} \right. + \] + \item[Justifying \locTloIncrementAfterFirst{}:] + and we impose the following constraints: + \begin{enumerate} + \item \If $\locTotntIsOne = 1$ \Then $\locTloIncrementAfterFirst = 0$ + \item \If $\locTotntIsOne = 0$ \Then + \begin{enumerate} + \item \If $\locFirstDataTransferSingleTarget = 0$ \Then $\locTloIncrementAfterFirst = 1$ + \item \If $\locFirstDataTransferSingleTarget = 1$ \Then $\locTloIncrementAfterFirst = \locFirstDataTransferMaxesOutTarget$ + \end{enumerate} + \end{enumerate} + \item[Justifying \locTloIncrementAtTransition{}:] + and we impose the following constraints: + \begin{enumerate} + \item \If $\locTotntIsOne = 1$ \Then + \begin{enumerate} + \item \If $\locOnlyDataTransferSingleTarget = 0$ \Then $\locTloIncrementAtTransition = 1$ + \item \If $\locOnlyDataTransferSingleTarget = 1$ \Then $\locTloIncrementAtTransition = \locOnlyDataTransferMaxesOutTarget$ + \end{enumerate} + \item \If $\locTotntIsOne = 0$ \Then + \begin{enumerate} + \item \If $\locLastDataTransferSingleTarget = 0$ \Then $\locTloIncrementAtTransition = 1$ + \item \If $\locLastDataTransferSingleTarget = 1$ \Then $\locTloIncrementAtTransition = \locLastDataTransferMaxesOutTarget$ + \end{enumerate} + \end{enumerate} + \def\rowNum{10} \item[Processing row $n^\circ(i + \rowNum)$:] + we impose the folloiwng \textbf{unconditionally} + \[ + \left\{ \begin{array}{l} + \callToEq + {i}{\rowNum} + {0}{\ppTotRZ_{i}} + {1} + \vspace{2mm} + \\ + \callToEuc + {i}{\rowNum} + {\locFirstPaddingOffset} + {\llarge} + \\ + \end{array} \right. + \] + where we set \ppTotRZ{}: + \begin{enumerate} + \item \If $\locPureData = 1$ \Then \( \ppTotRZ _{i} = 0 \) + \item \If $\locMixed = 1$ \Then \( \ppTotRZ _{i} = \locLastPlo - \locFirstPlo + 1. \) + \end{enumerate} + and we introduce the following shorthand + \[ + \locTotrzIsOne \define \ppWcpRes_{i + \rowNum} + \] + and we define the following associated shortands + \[ + \left\{ \begin{array}{lcl} + \locFirstPaddingOffset & \define & \locMinTgtOffset + \locTransferSize \\ + \locFirstPlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locFirstPbo & ~ = ~ & \locMixed \cdot \ppEucRem _{i + \rowNum} \\ + \locLastPlo & \define & \locMaxTlo \\ + \locLastPbo & \define & \locMaxTbo \\ + \end{array} \right. + \] + and we impose that + \begin{enumerate} + \item \If $\locTotrzIsOne = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \locFirstPaddingSize & = & \locPaddingSize \\ + \locLastPaddingSize & = & 0 & (\trash) \\ + \end{array} \right. + \] + \item \If $\locTotrzIsOne = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \locFirstPaddingSize & = & \locMixed \cdot ( \llarge - \locFirstPbo ) \\ + \locLastPaddingSize & = & \locMixed \cdot ( 1 + \locLastPbo ) \\ + \end{array} \right. + \] + \end{enumerate} +\end{description} +\saNote{} The shorthand \locFirstPaddingOffset{} and the associated euclidean division above only make sense (semantically and procedurally) when $\locMixed \equiv 1$. +To simplify things we carry it out regardless. diff --git a/mmu/instructions/blake/_inputs.tex b/mmu/instructions/blake/_inputs.tex new file mode 100644 index 0000000..0d6eb32 --- /dev/null +++ b/mmu/instructions/blake/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Pre-processing and micro-instruction-writing} \label{mmu: instructions: blake: preprocessing and micro instruction writing} \input{instructions/blake/preprocessing} +\subsubsection{Initializing the first micro-instruction} \label{mmu: instructions: blake: initialization} \input{instructions/blake/initializing} +\subsubsection{Micro-instruction writing} \label{mmu: instructions: blake: micro instruction writing} \input{instructions/blake/micro_instruction_writing} diff --git a/mmu/instructions/blake/initializing.tex b/mmu/instructions/blake/initializing.tex new file mode 100644 index 0000000..8ac684e --- /dev/null +++ b/mmu/instructions/blake/initializing.tex @@ -0,0 +1,32 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagBlake _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We now do the initialization of the micro-instruction-writing phase. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstBlakeValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstBlakeValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstBlakeValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + \microCns _{i + \nppMmuInstBlakeValuePO} & = & \macroSrcId _{i} \\ + \microCnt _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstBlakeValuePO} & = & \locSuccessBit \\ + \microExoSum _{i + \nppMmuInstBlakeValuePO} & = & \locSuccessBit \cdot \exoWeightBlakeModexp \\ + \microPhase _{i + \nppMmuInstBlakeValuePO} & = & \locSuccessBit \cdot \phaseBlakeParams \\ + \microIdOne _{i + \nppMmuInstBlakeValuePO} & = & \locSuccessBit \cdot \macroTgtId _{i} \\ + \microIdTwo _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstBlakeValuePO} & = & \nothing \\ + \end{array} \right. + \] +\end{description} diff --git a/mmu/instructions/blake/micro_instruction_writing.tex b/mmu/instructions/blake/micro_instruction_writing.tex new file mode 100644 index 0000000..bf973a3 --- /dev/null +++ b/mmu/instructions/blake/micro_instruction_writing.tex @@ -0,0 +1,44 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagBlake _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We now do the initialization of the micro-instruction-writing phase. +\begin{description} + \item[First micro-instruction-writing-row:] \label{mmu: instructions: exoToRamTransplants: initialize: slo and tlo is initially 0} + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstBlakeValuePO} & = & \locFirstMicroInst \\ + \microSize _{i + \nppMmuInstBlakeValuePO} & = & 4 \\ + \microSlo _{i + \nppMmuInstBlakeValuePO} & = & \locSloBlakeR \\ + \microSbo _{i + \nppMmuInstBlakeValuePO} & = & \locSboBlakeR \\ + \microTlo _{i + \nppMmuInstBlakeValuePO} & = & 0 \\ + \microTbo _{i + \nppMmuInstBlakeValuePO} & = & \llarge - 4 \\ + \microLimb _{i + \nppMmuInstBlakeValuePO} & = & \locPredictedBlakeR \\ + \end{array} \right. + \] + where we define the shorthand \locFirstMicroInst{} as follows: + \begin{enumerate} + \item \If $\locSingleSourceBlakeR = 0$ \Then $\mmioInstRamToLimbTwoSource$ + \item \If $\locSingleSourceBlakeR = 1$ \Then $\mmioInstRamToLimbOneSource$ + \end{enumerate} + \item[Second micro-instruction-writing-row:] \label{mmu: instructions: exoToRamTransplants: initialize: slo and tlo is initially 0} + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstBlakeValuePT} & = & \mmioInstRamToLimbOneSource \\ + \microSize _{i + \nppMmuInstBlakeValuePT} & = & 1 \\ + \microSlo _{i + \nppMmuInstBlakeValuePT} & = & \locSloBlakeF \\ + \microSbo _{i + \nppMmuInstBlakeValuePT} & = & \locSboBlakeF \\ + \microTlo _{i + \nppMmuInstBlakeValuePT} & = & 1 \\ + \microTbo _{i + \nppMmuInstBlakeValuePT} & = & \llarge - 1 \\ + \microLimb _{i + \nppMmuInstBlakeValuePT} & = & \locPredictedBlakeF \\ + \end{array} \right. + \] +\end{description} +\saNote{} The target limb offsets are required as they will be set to the exogenous data limb offsets. diff --git a/mmu/instructions/blake/preprocessing.tex b/mmu/instructions/blake/preprocessing.tex new file mode 100644 index 0000000..4834eff --- /dev/null +++ b/mmu/instructions/blake/preprocessing.tex @@ -0,0 +1,72 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagBlake _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We constrain the number of rows of the pre-processing and micro-instruction-writing phase: +\begin{enumerate} + \item $\ppTotNT_{i} = 2$ + \item $\ppTotLZ_{i} = 0$ + \item $\ppTotRZ_{i} = 0$ +\end{enumerate} +We advance to the actual pre-processing and micro-instruction-writing phases. +We deal with \mmuInstBlake{}'s in a fixed number of rows. +This allows us to deal both with pre-processing and micro-instruction-writing from a single vantage point. +\begin{description} + \item[Shorthands] + we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locCdo & \define & \macroSrcOffsetLo _{i} \\ + \locSuccessBit & \define & \macroSuccessBit _{i} \\ + \locPredictedBlakeR & \define & \macroLimbOne _{i} \\ + \locPredictedBlakeF & \define & \macroLimbTwo _{i} \\ + \end{array} \right. + \] + \item[Pre-processing row $\bm{n^\circ 1}$:] + we impose that + \[ + \callToEuc + {i}{1} + {\locCdo} + {\llarge} + \] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locSloBlakeR & \define & \ppEucQuot _{i + 1} \\ + \locSboBlakeR & \define & \ppEucRem _{i + 1} \\ + \end{array} \right. + \] + we further impose that + \[ + \callToLt + {i}{1} + {0}{\locSboBlakeR + (4 - 1)} + {\llarge} + \] + and define the following associated shorthand: + \[ + \locSingleSourceBlakeR \define \ppWcpRes _{i + 1} + \] + \item[Pre-processing row $\bm{n^\circ 2}$:] + we impose that + \[ + \callToEuc + {i}{2} + {\locCdo + (213 - 1)} + {\llarge} + \] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locSloBlakeF & \define & \ppEucQuot _{i + 2} \\ + \locSboBlakeF & \define & \ppEucRem _{i + 2} \\ + \end{array} \right. + \] +\end{description} + diff --git a/mmu/instructions/exoToRamTransplants/_inputs.tex b/mmu/instructions/exoToRamTransplants/_inputs.tex new file mode 100644 index 0000000..ea9ea47 --- /dev/null +++ b/mmu/instructions/exoToRamTransplants/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Pre-processing} \label{mmu: instructions: modexpdata: preprocessing} \input{instructions/exoToRamTransplants/preprocessing}² +\subsubsection{Initializing the first micro-instruction} \label{mmu: instructions: modexpdata: initializing} \input{instructions/exoToRamTransplants/initializing} +\subsubsection{Micro-instruction writing} \label{mmu: instructions: modexpdata: micro instruction writing} \input{instructions/exoToRamTransplants/micro_instruction_writing} diff --git a/mmu/instructions/exoToRamTransplants/initializing.tex b/mmu/instructions/exoToRamTransplants/initializing.tex new file mode 100644 index 0000000..60face3 --- /dev/null +++ b/mmu/instructions/exoToRamTransplants/initializing.tex @@ -0,0 +1,46 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagExoToRamTransplants _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We now do the initialization of the micro-instruction-writing phase. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \macroLimbTwo_{i} \\ + \microCns _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + \microCnt _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \macroTgtId_{i} \\ + \microSuccessBit _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \macroExoSum_{i} \\ + \microPhase _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \macroPhase_{i} \\ + \microIdOne _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \macroSrcId_{i} \\ + \microIdTwo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + \end{array} \right. + \] + %\item[First micro-instruction-writing-row:] \label{mmu: instructions: exoToRamTransplants: initialize: slo and tlo is initially 0} + % we impose + % \[ + % \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \mmioInstLimbToRamTransplant \\ + % \microSize _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \valueToBeSet \\ + % \microSbo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \valueToBeSet \\ + % \microTbo _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \nothing \\ + % \microLimb _{i + \nppMmuInstExoToRamTransplantsValuePO} & = & \relevantValue \\ + % \end{array} \right. + % \] +\end{description} + diff --git a/mmu/instructions/exoToRamTransplants/micro_instruction_writing.tex b/mmu/instructions/exoToRamTransplants/micro_instruction_writing.tex new file mode 100644 index 0000000..68bcade --- /dev/null +++ b/mmu/instructions/exoToRamTransplants/micro_instruction_writing.tex @@ -0,0 +1,27 @@ +\begin{center} + \boxed{\text{The pre-processing presented below assumes that } \mmuInstFlagExoToRamTransplants _{i} = 1 } +\end{center} +The micro-instruction-writing phase is very simple: the same instruction gets repeated over and over again (with incrementing source and target limb offsets, that is.) +\begin{description} + \item[Progression:] \label{mmu: instructions: modexpdata: micro instrution writing: tlo progression} + we impose generally \If $\isMicro_{i} = 1$ \Then + \begin{enumerate} + \item $\stdProgression_{i}\Big[\isMicro, \microSlo \Big]$ + \item $\stdProgression_{i}\Big[\isMicro, \microTlo \Big]$ + \end{enumerate} + \item[Micro instruction writing:] + %\If $\isMiddleNT_{i} + \isLastNT_{i} = 1$ \Then + \If $\isMicro_{i} = 1$ \Then + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstLimbToRamTransplant \\ + \microSize _{i} & = & \nothing \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \nothing \\ + \microLimb _{i} & = & \relevantValue \\ + \end{array} \right. + \] +\end{description} diff --git a/mmu/instructions/exoToRamTransplants/preprocessing.tex b/mmu/instructions/exoToRamTransplants/preprocessing.tex new file mode 100644 index 0000000..9d92823 --- /dev/null +++ b/mmu/instructions/exoToRamTransplants/preprocessing.tex @@ -0,0 +1,28 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagExoToRamTransplants _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We outline the pre-processing rows below. +\begin{description} + \item[Pre-processing row $\bm{n^\circ 1}$:] + we impose + \[ + \callToEuc + {i}{1} + {\macroSize_{i}} + {\llarge} + \] + we further impose + \[ + \left\{ \begin{array}{lcl} + \ppTotLZ _{i} & = & 0 \\ + \ppTotNT _{i} & = & \ppEucCeil_{i + 1} \\ + \ppTotRZ _{i} & = & 0 \\ + \end{array} \right. + \] +\end{description} diff --git a/mmu/instructions/invalidCodePrefix/_inputs.tex b/mmu/instructions/invalidCodePrefix/_inputs.tex new file mode 100644 index 0000000..82bc54f --- /dev/null +++ b/mmu/instructions/invalidCodePrefix/_inputs.tex @@ -0,0 +1 @@ +\subsubsection{Pre-processing and micro-instruction-writing} \label{mmu: instrutions: invalid code prefix: preprocessing and micro instruction writing} \input{instructions/invalidCodePrefix/preprocessing} diff --git a/mmu/instructions/invalidCodePrefix/preprocessing.tex b/mmu/instructions/invalidCodePrefix/preprocessing.tex new file mode 100644 index 0000000..f0dfc6c --- /dev/null +++ b/mmu/instructions/invalidCodePrefix/preprocessing.tex @@ -0,0 +1,70 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagInvalidCodePrefix _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We constrain the number of rows of the pre-processing and micro-instruction-writing phase: +\begin{enumerate} + \item $\ppTotNT_{i} = 1$ + \item $\ppTotLZ_{i} = 0$ + \item $\ppTotRZ_{i} = 0$ +\end{enumerate} +We advance to the actual pre-processing and micro-instruction-writing phases. +We deal with \mmuInstInvalidCodePrefix{}'s in a fixed number of rows. +This allows us to deal both with pre-processing and micro-instruction-writing from a single vantage point. +\begin{description} + \item[Preprocessing row $\bm{n^\circ 1}$:] + we impose that + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{1} + {\macroSrcOffsetLo _{i}} + {\llarge} + \vspace{2mm} + \\ + \callToEq + {i}{1} + {0}{\microLimb_{i + \nppMmuInstInvalidCodePrefixValuePO}} + {\texttt{0x\,EF}} + \end{array} \right. + \] + and we further impose that + \[ + \macroSuccessBit_{i} = 1 - \ppWcpRes_{i + 1} + \] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locSlo & \define & \ppEucQuot _{i + 1} \\ + \locSbo & \define & \ppEucRem _{i + 1} \\ + \end{array} \right. + \] + \item[Micro-instruction writing:] + only one micro-instruction is required: + \[ \left\{ \begin{array}{lclr} + \microInst _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \mmioInstRamToLimbOneSource \\ + \microSize _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & 1 \\ + \microSlo _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \locSlo \\ + \microSbo _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \locSbo \\ + \microTlo _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + \microTbo _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \llarge - 1 \\ + \microLimb _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \relevantValue \\ + \microCns _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \macroSrcId_{i} \\ + \microCnt _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \rZero \\ + \microPhase _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstInvalidCodePrefixValuePO} & = & \nothing \\ + + \end{array} \right. + \] +\end{description} +\saNote{} The value present in $\microLimb_{i + \nppMmuInstInvalidCodePrefixValuePO}$ will be justified in the \mmioMod{} module by the \mmioInstRamToLimbOneSource{} instruction. +It is the byte contained at offset $\macroSrcOffsetLo_{i}$ in the \textsc{ram} of the execution context with context number $\macroSrcId_{i}$. diff --git a/mmu/instructions/mload/_inputs.tex b/mmu/instructions/mload/_inputs.tex new file mode 100644 index 0000000..24d671c --- /dev/null +++ b/mmu/instructions/mload/_inputs.tex @@ -0,0 +1 @@ +\subsubsection{Pre-processing and micro-instruction-writing} \label{mmu: instrutions: mload: preprocessing and micro instruction writing} \input{instructions/mload/preprocessing} diff --git a/mmu/instructions/mload/preprocessing.tex b/mmu/instructions/mload/preprocessing.tex new file mode 100644 index 0000000..06f3508 --- /dev/null +++ b/mmu/instructions/mload/preprocessing.tex @@ -0,0 +1,105 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagMload _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We constrain the number of rows of the pre-processing and micro-instruction-writing phase: +\begin{enumerate} + \item $\ppTotNT_{i} = 2$ + \item $\ppTotLZ_{i} = 0$ + \item $\ppTotRZ_{i} = 0$ +\end{enumerate} +We advance to the actual pre-processing and micro-instruction-writing phases. +We deal with \mmuInstMload{}'s in a fixed number of rows. +This allows us to deal both with pre-processing and micro-instruction-writing from a single vantage point. +\begin{description} + \item[Pre-processing row $\bm{n^\circ 1}$:] + we impose that + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{1} + {\macroSrcOffsetLo_{i}} + {\llarge} + \vspace{2mm} \\ + \callToIszero + {i}{1} + {0}{\locSbo} + \\ + \end{array} \right. + \] + where we define (and have already used) the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locAligned & \define & \ppWcpRes _{i + 1} \\ + \locSlo & \define & \ppEucQuot _{i + 1} \\ + \locSbo & \define & \ppEucRem _{i + 1} \\ + \end{array} \right. + \] + \item[Setting micro-instruction-writing-constant values:] + \[ \left\{ \begin{array}{lclr} + % \microInst _{i + \nppMmuInstMloadValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstMloadValuePO} & = & \locSlo \\ + % \microSbo _{i + \nppMmuInstMloadValuePO} & = & \locSbo \\ + % \microTlo _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microTbo _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microLimb _{i + \nppMmuInstMloadValuePO} & = & \macroLimbOne_{i} \\ + \microCns _{i + \nppMmuInstMloadValuePO} & = & \macroSrcId_{i} \\ + \microCnt _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstMloadValuePO} & = & \rZero \\ + \microPhase _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \end{array} \right. + \] + \item[First micro-instruction writing:] + \[ \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstMloadValuePO} & = & \locMicroInst \\ + \microSize _{i + \nppMmuInstMloadValuePO} & = & \llarge \\ + \microSlo _{i + \nppMmuInstMloadValuePO} & = & \locSlo \\ + \microSbo _{i + \nppMmuInstMloadValuePO} & = & \locSbo \\ + \microTlo _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microTbo _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \microLimb _{i + \nppMmuInstMloadValuePO} & = & \macroLimbOne_{i} \\ + % \microCns _{i + \nppMmuInstMloadValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microSuccessBit _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstMloadValuePO} & = & \nothing \\ + \end{array} \right. + \] + \item[Second micro-instruction writing:] + \[ \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstMloadValuePT} & = & \locMicroInst \\ + \microSize _{i + \nppMmuInstMloadValuePT} & = & \llarge \\ + \microSlo _{i + \nppMmuInstMloadValuePT} & = & \locSlo + 1 \\ + \microSbo _{i + \nppMmuInstMloadValuePT} & = & \locSbo \\ + \microTlo _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + \microTbo _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + \microLimb _{i + \nppMmuInstMloadValuePT} & = & \macroLimbTwo_{i} \\ + % \microCns _{i + \nppMmuInstMloadValuePT} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + % \microSuccessBit _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstMloadValuePT} & = & \nothing \\ + \end{array} \right. + \] + where \locMicroInst{} is a shorthand defined as follows: + \begin{enumerate} + \item \If $\locAligned = 0$ \Then $\locMicroInst \define \mmioInstRamToLimbTwoSource $ + \item \If $\locAligned = 1$ \Then $\locMicroInst \define \mmioInstRamToLimbTransplant $ + \end{enumerate} +\end{description} diff --git a/mmu/instructions/modexpData/_inputs.tex b/mmu/instructions/modexpData/_inputs.tex new file mode 100644 index 0000000..5ccdceb --- /dev/null +++ b/mmu/instructions/modexpData/_inputs.tex @@ -0,0 +1,6 @@ +\subsubsection{Introduction} \label{mmu: instructions: modexp data: intro} \input{instructions/modexpData/intro} +\subsubsection{Global shorthands} \label{mmu: instructions: modexp data: global shorthands} \input{instructions/modexpData/shorthands_global} +\subsubsection{Pre-processing shorthands} \label{mmu: instructions: modexp data: pre processing shorthands} \input{instructions/modexpData/shorthands_preprocessing} +\subsubsection{Preprocessing} \label{mmu: instructions: modexp data: preprocessing} \input{instructions/modexpData/preprocessing} +\subsubsection{Initializing the micro-instruction-writing} \label{mmu: instructions: modexp data: initialize} \input{instructions/modexpData/initialize} +\subsubsection{Micro instruction writing} \label{mmu: instructions: modexp data: micro instruction writing} \input{instructions/modexpData/micro_instruction_writing} diff --git a/mmu/instructions/modexpData/_lua_modexp_parameter_extraction.tex b/mmu/instructions/modexpData/_lua_modexp_parameter_extraction.tex new file mode 100644 index 0000000..544bd83 --- /dev/null +++ b/mmu/instructions/modexpData/_lua_modexp_parameter_extraction.tex @@ -0,0 +1,122 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +Alias: +* b/e/m_byte_size <-- MI/SIZE +* remaining_call_data_size <-- MI/REF_SIZE - MI/SRC_OFFSET_LO +* rdo <-- MI/REF_OFFSET + MI/SRC_OFFSET_LO + +|-------------------+-------------------------------------------------------------------------+--------------------------------------------------------------------+--------------------------------------------------+------------------------------| +| Preprocessing row | EUC | WCP | description | extractables | +|-------------------+-------------------------------------------------------------------------+--------------------------------------------------------------------+--------------------------------------------------+------------------------------| +| i + 1 | PREPRC/EUC = 1 | | | | +| | num_left_padding_bytes := 512 - b/e/m_byte_size | | | | +| | callToEUC(num_left_padding_bytes, 16; TOTLZ = initial_TLO, initial_TBO) | | <== compute initial value of TOTLZ, | | +| | | | . TLO and TBO | | +| | | | | * TOTLZ | +| | | | | * initial_TLO | +| | | | | * initial_TBO | +|-------------------+-------------------------------------------------------------------------+--------------------------------------------------------------------+--------------------------------------------------+------------------------------| +| i + 2 | | PREPRC/WCP = 1 | | | +| | | callToLT(remaining_call_data_size, b/e/m_byte_size; data_runs_out) | <== data_runs_out = 1 iff | | +| | | | . [remaining_call_data_size < b/e/m_byte_size] | | +| | | | . iff there will is some right padding | | +| | | | | | +| | PREPRC/EUC = 1 | | | | +| | num_right_padding_bytes := | | | | +| | . (b/e/m_byte_size - remaining_call_data_size) • data_runs_out | | | | +| | | | | | +| | callToEUC(num_right_padding_bytes, 16; TOTRZ, right_padding_remainder) | | <== compute initial value of TOTRZ | | +| | | | | | +| | | | | * right_padding_remainder | +| | | | | * data_runs_out | +| | | | | * TOTRZ | +| | | | | * TOTNT via the equation | +| | | | | . TOTLZ + TOTNT + TOTRZ = 32 | +|-------------------+-------------------------------------------------------------------------+--------------------------------------------------------------------+--------------------------------------------------+------------------------------| + + 0 ≤ initial_SBO < 16 + ↓ +|••••••••••••••••|••••••xxxxxxxxxx|xxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxx|xxxxxx•••••••••|••••••••••••••••| <== CN_S' RAM + + + <----------------------- b/e/m_byte_size ∧ remaining_call_data_size --------------------------------> + + + + 0 ≤ initial_TBO < 16 + ↓ +|________________|________________|________________|___________xxxxx|xxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxx|xxxxxxxxxxx_____|________________|________________|________________| + + + <----------- b/e/m_byte_size ----------------------------------------------------------------------------------------------> + <----------- b/e/m_byte_size ∧ remaining_call_data_size -----------> + + <--------------- num_left_padding_bytes ---------------------> <------------------ num_right_padding_bytes -----------> + <---> right_padding_remainder + <------------------------------------------------------------------------------------- 512 ----------------------------------------------------------------------------------------------> + + + +|-------------------+----------------------------------------------+----------------------------------------------------------------------------------+-------------------------------------+----------------------------| +| Preprocessing row | EUC | WCP | description | extractables | +|-------------------+----------------------------------------------+----------------------------------------------------------------------------------+-------------------------------------+----------------------------| +| i + 3 | | PREPRC/WCP = 1 | | | +| | | callToEQ(TOTNT, 1; totnt_is_one) | <== single nontrivial limb or more | | +| | | | | | +| | PREPRC/EUC = 1 | | | | +| | callToEUC(rdo, 16; initial_SLO, initial_SBO) | | <== compute initial slo/sbo | | +| | | | | | +| | | | | * totnt_is_one | +| | | | | * initial_SLO | +| | | | | * initial_SBO | +|-------------------+----------------------------------------------+----------------------------------------------------------------------------------+-------------------------------------+----------------------------| +| i + 4 | | PREPRC/WCP = 1 | | | +| | | callToLT(initial_SBO + (first_limb_byte_size - 1), 16; first_limb_single_source) | <== first nontrivial limb requires | | +| | | | | | +| | | | . one or two input limbs to write | | +| | | | | * first_limb_single_source | +|-------------------+----------------------------------------------+----------------------------------------------------------------------------------+-------------------------------------+----------------------------| + +We have not defined "firstLimbByteSize" yet. We do this now (as well as "lastLimbByteSize"): +* If totnt_is_one = 1 (single nontrivial limb case): + * set firstLimbByteSize + * if data_runs_out = 0: b/e/m_byte_size + * if data_runs_out = 1: remaining_call_data_size + * set lastLimbByteSize + * ∅ +* If totnt_is_one = 0 (multiple nontrivial limbs case): + * set firstLimbByteSize = 16 - initial_TBO + * set lastLimbByteSize = 16 - right_padding_remainder + +|-------------------+-----+--------------------------------------------------------------------------------+-------------+---------------------------| +| Preprocessing row | EUC | WCP | description | extractables | +|-------------------+-----+--------------------------------------------------------------------------------+-------------+---------------------------| +| i + 5 | | PREPRC/WCP = 1 | | | +| | | callToEQ(initial_SBO, initial_TBO; aligned) | | | +| | | | | | +| | | | | * aligned | +|-------------------+-----+--------------------------------------------------------------------------------+-------------+---------------------------| +| i + 6 | | PREPRC/WCP = data_runs_out | | | +| | | callToLT(initial_SBO + (last_limb_byte_size - 1), 16; last_limb_single_source) | | | +| | | | | | +| | | | | * last_limb_single_source | +|-------------------+-----+--------------------------------------------------------------------------------+-------------+---------------------------| +\end{verbatim} + +\end{document} diff --git a/mmu/instructions/modexpData/initialize.tex b/mmu/instructions/modexpData/initialize.tex new file mode 100644 index 0000000..9a3e4e1 --- /dev/null +++ b/mmu/instructions/modexpData/initialize.tex @@ -0,0 +1,40 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagModexpData _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We use the present vantage point to settle some micro-instruction related paramaters, in particular those which remain constant throughout micro-instruction-writing and other pertaining to the first micro-instruction-writing-row. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstModexpDataValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstModexpDataValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstModexpDataValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + \microCns _{i + \nppMmuInstModexpDataValuePO} & = & \locSrcId \\ + \microCnt _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstModexpDataValuePO} & = & \exoWeightBlakeModexp \\ + \microPhase _{i + \nppMmuInstModexpDataValuePO} & = & \locPhase \\ + \microIdOne _{i + \nppMmuInstModexpDataValuePO} & = & \locTgtId \\ + \microIdTwo _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstModexpDataValuePO} & = & \nothing \\ + \end{array} \right. + \] + \saNote{} We should have + $\macroExoSum \equiv ?$. + \ob{TODO!} + \item[First micro-instruction-writing-row:] \label{mmu: instructions: modexpdata: initialize: tlo is initially 0} + we impose + \[ + \microTlo_{i + \nppMmuInstModexpDataValuePO} = 0 \qquad(\trash) + \] +\end{description} diff --git a/mmu/instructions/modexpData/intro.tex b/mmu/instructions/modexpData/intro.tex new file mode 100644 index 0000000..a3910dc --- /dev/null +++ b/mmu/instructions/modexpData/intro.tex @@ -0,0 +1,43 @@ +The present instruction is used by the \hubMod{} to extract a \textbf{potentially nontrivial} base, exponent or modulus parameter for the \inst{MODEXP} precompile. +What follows is, depending on the case, the desired interpretation of some of the fields of the macro-instruction: +\begin{description} + \item[General values:] + all cases will have + \[ + \left\{ \begin{array}{lcl} + \macroRefOffset & \equiv & \CDO \\ + \macroRefSize & \equiv & \CDS \\ + \end{array} \right. + \] + \item[Base extraction case:] + we will have + \[ + \left\{ \begin{array}{lcl} + \macroSrcOffsetLo & \equiv & 96 \\ + \macroSize & \equiv & \ell_\text{B} \\ + \end{array} \right. + \] + \item[Exponent extraction case:] + we will have + \[ + \left\{ \begin{array}{lcl} + \macroSrcOffsetLo & \equiv & 96 + \ell_\text{B} \\ + \macroSize & \equiv & \ell_\text{E} \\ + \end{array} \right. + \] + \item[Modulus extraction case:] + we will have + \[ + \left\{ \begin{array}{lcl} + \macroSrcOffsetLo & \equiv & 96 + \ell_\text{B} + \ell_\text{E} \\ + \macroSize & \equiv & \ell_\text{M} \\ + \end{array} \right. + \] +\end{description} +Using shorthands introduced in section~(\ref{mmu: instrutions: modexpdata: shorthands}) we will furthermore be guaranteed that +\[ + \left\{ \begin{array}{l} + 0 < \locModexpParamByteSize \leq 512 \\ + 0 < \locModexpParamOffset \ll 256^4 \\ + \end{array} \right. +\] diff --git a/mmu/instructions/modexpData/micro_instruction_writing.tex b/mmu/instructions/modexpData/micro_instruction_writing.tex new file mode 100644 index 0000000..3955c2a --- /dev/null +++ b/mmu/instructions/modexpData/micro_instruction_writing.tex @@ -0,0 +1,197 @@ +\begin{center} \boxed{ \text{The pre-processing presented below assumes that } \mmuInstFlagModexpData _{i} = 1 } +\end{center} +We impose the following: +\begin{description} + \item[Progression:] \label{mmu: instructions: modexpdata: micro instrution writing: tlo progression} + we impose generally \If $\isMicro_{i} = 1$ \Then $\stdProgression_{i}\Big[\isMicro, \microTlo \Big]$ +\end{description} +\saNote{} \label{mmu: modexData: microTLO explanation} Recall that in the present case (\mmuInstFlagModexpData{} instruction) the we have +initially\footnote{i.e. during the pre-processing phase} $\ppTot \equiv 32$, +see~(\ref{mmu: instructions: modexpdata: preprocessing: tot = 32 initially}), +and intially\footnote{i.e. on the first micro-instruction-writing row}, again, $\microTlo \equiv 0$, +see~(\ref{mmu: instructions: modexpdata: initialize: tlo is initially 0}). +The above therefore enforces that \microTlo{} will count monotonically and without gaps from $0$ to $31$ during the micro-instruction-writing phase. +And indeed the goal of the present \mmuMod{}-instruction is to copy over up to $512 = 32 \times \llarge$ (potentially left and/or right zero padded) bytes of data i.e. $32$ data limbs. +\begin{description} + \item[Zero padding rows:] + \If $\isZero_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstLimbVanishes \\ + \microSize _{i} & = & \nothing \\ + \microSlo _{i} & = & \nothing \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \nothing \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \nothing \\ + % \microCnt _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing or \alreadySet \\ + \end{array} \right. + \] + \item[Only nontrivial row:] + \If $\isOnlyNT_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locOnlyMicroInst \\ + \microSize _{i} & = & \locFirstLimbByteSize \\ + \microSlo _{i} & = & \locInitSlo \\ + \microSbo _{i} & = & \locInitSbo \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \locInitTbo \\ + \microLimb _{i} & = & \relevantValue \\ + % \microCns _{i} & = & \nothing \\ + % \microCnt _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing or \alreadySet \\ + \end{array} \right. + \] + where + \begin{description} + \item[Defining \locOnlyMicroInst:] --- + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 0$ \Then \[ \locOnlyMicroInst = \mmioInstRamToLimbTwoSource \] + \item \If $\locFirstLimbSingleSource = 1$ \Then \[ \locOnlyMicroInst = \mmioInstRamToLimbOneSource \] + \end{enumerate} + \end{description} + \item[First nontrivial row:] + \If $\isFirstNT_{i} = 1$ \Then + \begin{description} + \item[Micro-instruction:] + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locFirstMicroInst \\ + \microSize _{i} & = & \locFirstLimbByteSize \\ + \microSlo _{i} & = & \locInitSlo \\ + \microSbo _{i} & = & \locInitSbo \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \locInitTbo \\ + \microLimb _{i} & = & \relevantValue \\ + % \microCns _{i} & = & \nothing \\ + % \microCnt _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing or \alreadySet \\ + \end{array} \right. + \] + where we have made use of the shorthand \locFirstMicroInst{} defined below: + \begin{description} + \item[Defining \locFirstMicroInst:] --- + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 0$ \Then \[ \locFirstMicroInst = \mmioInstRamToLimbTwoSource \] + \item \If $\locFirstLimbSingleSource = 1$ \Then \[ \locFirstMicroInst = \mmioInstRamToLimbOneSource \] + \end{enumerate} + \end{description} + \item[Paying forward of \microSlo{}:] + we impose that + \begin{enumerate} + \item \If $\locAligned_{i} = 1$ \Then $\microSlo_{i + 1} = 1 + \microSlo_{i}$ + \item \If $\locAligned_{i} = 0$ \Then + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 0$ \Then $\microSlo_{i + 1} = 1 + \microSlo_{i}$ + \item \If $\locFirstLimbSingleSource = 1$ \Then $\microSlo_{i + 1} = \microSlo_{i}$ + \end{enumerate} + \end{enumerate} + \saNote{} The above may be implemented more efficiently as + \[ \microSlo_{i + 1} = \locMicroSloIncrement + \microSlo_{i} \] + where + \[ + \locMicroSloIncrement \define + \left[ \begin{array}{cr} + + & \locAligned_{i} \\ + + & (1 - \locAligned_{i}) \cdot (1 - \locFirstLimbSingleSource) \\ + \end{array} \right] + \] + \item[Paying forward of \microSbo{}:] + we impose that + \begin{enumerate} + \item \If $\locAligned_{i} = 1$ \Then $\microSbo_{i + 1} = 0$ \quad(\trash) + \item \If $\locAligned_{i} = 0$ \Then + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 0$ \Then $\microSbo_{i + 1} = \microSbo_{i} + \microSize_{i} - \llarge$ + \item \If $\locFirstLimbSingleSource = 1$ \Then $\microSbo_{i + 1} = \microSbo_{i} + \microSize_{i}$ + \end{enumerate} + \end{enumerate} + \saNote{} We really only need to specify the \microSbo{} update in the non-aligned case. + \saNote{} We could have used the shorthand \locMiddleSbo, stored in a $\ppOutputCol{6}$, but that would create a sixth column, only for this (almost never) used instruction. + \item[Paying forward of \microTbo{}:] + we impose that $\microTbo_{i + 1} = 0$ + \end{description} + \item[Middle nontrivial row:] + \If $\isMiddleNT_{i} = 1$ \Then + \begin{description} + \item[Micro-instruction:] + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locMiddleMicroInst \\ + \microSize _{i} & = & \llarge \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \alreadySet \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + % \microCns _{i} & = & \nothing \\ + % \microCnt _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing or \alreadySet \\ + \end{array} \right. + \] + where + \begin{description} + \item[Defining \locMiddleMicroInst:] --- + \begin{enumerate} + \item \If $\locAligned = 0$ \Then \( \locMiddleMicroInst = \mmioInstRamToLimbTwoSource \) + \item \If $\locAligned = 1$ \Then \( \locMiddleMicroInst = \mmioInstRamToLimbTransplant \) + \end{enumerate} + \end{description} + \item[Paying forward of \microSlo{}:] + the next source limb is the next limb in the source: $\microSlo_{i + 1} = 1 + \microSlo_{i}$ + \item[Paying forward of \microSbo{}:] + remains unchanged: $\microSbo_{i + 1} = \microSbo_{i}$ + \item[Paying forward of \microTbo{}:] + remains unchanged: $\microTbo_{i + 1} = \microTbo_{i}$ + \end{description} + \item[Last nontrivial row:] + \If $\isLastNT_{i} = 1$ \Then + \begin{description} + \item[Micro-instruction:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locLastMicroInst \\ + \microSize _{i} & = & \locLastLimbByteSize \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \alreadySet \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + % \microCns _{i} & = & \nothing \\ + % \microCnt _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing or \alreadySet \\ + \end{array} \right. + \] + where + \begin{description} + \item[Defining \locLastMicroInst:] --- + \begin{enumerate} + \item \If $\locLastLimbSingleSource = 0$ \Then \( \locLastMicroInst = \mmioInstRamToLimbTwoSource \) + \item \If $\locLastLimbSingleSource = 1$ \Then \( \locLastMicroInst = \mmioInstRamToLimbOneSource \) + \end{enumerate} + \end{description} + \end{description} +\end{description} +\saNote{} Let us say a few words on the ``\textbf{multiple nontrivial rows case}'' and in particular let us address the matter of the +\microSlo, \microSbo, \microTlo{} and \microTbo{} supposedly being already set (except for on the first nontrivial row.) +This results from the fact that the first nontrivial row and all middle rows \textbf{pay forward} in terms of \microSlo, \microSbo, and \microTbo{}. +When it comes to \microTlo{} the behavior of this column was already settled at the start, see here~(\ref{mmu: instructions: modexpdata: micro instrution writing: tlo progression}). diff --git a/mmu/instructions/modexpData/preprocessing.tex b/mmu/instructions/modexpData/preprocessing.tex new file mode 100644 index 0000000..b4bdb01 --- /dev/null +++ b/mmu/instructions/modexpData/preprocessing.tex @@ -0,0 +1,190 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagModexpData _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We outline the preprocessing rows +\begin{description} + \item[Admissible phases:] + we impose that $\locPhase \in \{ \phaseModexpBase, \phaseModexpExponent, \phaseModexpModulus \}$ (\trash). + \item[Number of preprocessing rows:] \label{mmu: instructions: modexpdata: preprocessing: tot = 32 initially} + we impose $\ppTot_{i} = 32$; + \item[Preprocessing row $\bm{n^\circ 1}$:] + we define the following shorthand + \[ + \locNleftPaddingBytes \define 512 - \locModexpParamByteSize + \] + and we impose that + \[ + \callToEuc + {i}{1} + {\locNleftPaddingBytes} + {\llarge} + \] + we impose the following constraint: + \[ + \left\{ \begin{array}{lcl} + \locInitTbo & = & \ppEucRem _{i + 1} \\ + \ppTotLZ _{i} & = & \ppEucQuot _{i + 1} \\ + \end{array} \right. + \] + \item[Preprocessing row $\bm{n^\circ 2}$:] + we impose that + \[ + \callToLt + {i}{2} + {0}{\locLeftoverCallDataSize} + {\locModexpParamByteSize} + \] + and we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locDataRunsOut & \define & \ppWcpRes_{i + 2} \\ + \locNrightPaddingBytes & \define & (\locModexpParamByteSize - \locLeftoverCallDataSize) \cdot \locDataRunsOut \\ + \end{array} \right. + \] + we impose that + \[ + \callToEuc + {i}{2} + {\locNrightPaddingBytes} + {\llarge} + \] + we impose the following constraint: + \[ + \left\{ \begin{array}{lclr} + \ppTotRZ _{i} & = & \ppEucQuot _{i + 2} \\ + \ppTotNT _{i} & = & 32 - \ppTotLZ_{i} - \ppTotRZ_{i} & (\trash) \\ + \end{array} \right. + \] + (the second constraint is an implicit consequence of others and need not be implemented); + and we further define the following shorthands + \[ + \locRt \define \ppEucRem _{i + 2} + \] + \item[Preprocessing row $\bm{n^\circ 3}$:] + we impose that + \[ + \left\{ \begin{array}{l} + \callToEq + {i}{3} + {0}{\ppTotNT_{i}} + {1} + \vspace{2mm} \\ + % \callToEq {i + 3}{0}{$\ppTotNT_{i}$}{1} \vspace{2mm} \\ + \callToEuc + {i}{3} + {\locRdo} + {\llarge} \\ + \end{array} \right. + \] + we define the following shorthand + \[ + \locTotntIsOne \define \ppWcpRes_{i + 3} + \] + and we enforce the following constraints + \[ + \left\{ \begin{array}{lclr} + \locInitSlo & = & \ppEucQuot _{i + 3} \\ + \locInitSbo & = & \ppEucRem _{i + 3} \\ + \end{array} \right. + \] + we impose that + \begin{enumerate} + \item \If $\locTotntIsOne = 0$ \Then $\locFirstLimbByteSize = \llarge - \locInitTbo$ + \item \If $\locTotntIsOne = 1$ \Then + \begin{enumerate} + \item \If $\locDataRunsOut = 0$ \Then $\locFirstLimbByteSize = \locModexpParamByteSize$ + \item \If $\locDataRunsOut = 1$ \Then $\locFirstLimbByteSize = \locLeftoverCallDataSize$ + \end{enumerate} + \end{enumerate} + we also impose that + \begin{enumerate} + \item \If $\locDataRunsOut = 0$ \Then $\locLastLimbByteSize = \llarge$ + \item \If $\locDataRunsOut = 1$ \Then $\locLastLimbByteSize = \llarge - \locRt$ + \end{enumerate} + See note~(\ref{mmu: modexpData: strange definition of last limb byte size}) for an explanation of the above. + \item[Preprocessing row $\bm{n^\circ 4}$:] + we further impose + \[ + \callToLt + {i}{4} + {0}{\locInitSbo + (\locFirstLimbByteSize - 1)} + {\llarge} + \] + we impose the following constraints: + \[ + \locFirstLimbSingleSource = \ppWcpRes_{i + 4} + \] + \item[Preprocessing row $\bm{n^\circ 5}$:] + we impose that + \[ + \callToEq + {i}{5} + {0}{\locInitSbo} + {\locInitTbo} + \] + we impose the following constraints: + \[ + \locAligned = \ppWcpRes _{i + 5} + \] + \item[Preprocessing row $\bm{n^\circ 6}$:] + we impose that + \begin{enumerate} + \item \If $\locAligned = 1$ \Then we impose $\locLastLimbSingleSource = \locAligned$ + \item \If $\locAligned = 0$ \Then + we impose that + \[ + \callToEuc + {i}{6} + {\locInitSbo + \locFirstLimbByteSize} + {\llarge} + \] + and we define the shorthand + \[ + \locMiddleSbo \define \ppEucRem_{i + 6} + \] + we further impose that + \[ + \callToLt + {i}{6} + {0}{\locMiddleSbo + (\locLastLimbByteSize - 1)} + {\llarge} + \] + and we impose the constraint + \[ + \locLastLimbSingleSource = \ppWcpRes_{i + 6} + \] + \saNote{} We draw attention to the fact that we could alternatively have set + \begin{IEEEeqnarray*}{LCL} + \locMiddleSbo + & \define & + \begin{cases} + \If \locFirstLimbSingleSource = 1 ~ \Then & \locInitSbo + \locFirstLimbByteSize \\ + \If \locFirstLimbSingleSource = 0 ~ \Then & \locInitSbo + \locFirstLimbByteSize - \llarge \\ + \end{cases} \\ + \end{IEEEeqnarray*} + to define \locMiddleSbo{}. + \end{enumerate} +\end{description} +\saNote{} \label{mmu: modexpData: strange definition of last limb byte size} +The definition given above of the shorthand \locLastLimbByteSize{} should seem surprising. +Indeed this definition does not always yield the correct number of ``nontrivial'' bytes in the last ``nontrivial'' limb. +The above formula only ``works'' when two or more limbs are affected nontrivially i.e. $\locTotntIsOne = 0$. +Yet the variable is given the suggestive name ``\locLastLimbByteSize.'' +A more natural definition would be: +\begin{enumerate} + \item \If $\locTotntIsOne = 1$ \Then $\locLastLimbByteSize = \locFirstLimbByteSize$ (\trash) + \item \If $\locTotntIsOne = 0$ \Then + \begin{enumerate} + \item \If $\locDataRunsOut = 0$ \Then $\locLastLimbByteSize = \llarge$ (\trash) + \item \If $\locDataRunsOut = 1$ \Then $\locLastLimbByteSize = \llarge - \locRt$ (\trash) + \end{enumerate} +\end{enumerate} +Looking ahead the reader will notice that \locLastLimbByteSize{} is only ever used on rows with $\isLastNT \equiv 1$. +Such rows only exist if $\ppTotNT \geq 2$. +The original definition is therefore sufficient for our needs. diff --git a/mmu/instructions/modexpData/shorthands_global.tex b/mmu/instructions/modexpData/shorthands_global.tex new file mode 100644 index 0000000..6184a3e --- /dev/null +++ b/mmu/instructions/modexpData/shorthands_global.tex @@ -0,0 +1,50 @@ +The first batch of ``\textbf{global shorthands}'' is sourced from the stamp-constant output columns, see section~(\ref{mmu: constancies: stamp constancies of pre processing outputs}). +As such +\begin{center} + \boxed{% + \text{The shorthands presented below should only be used when } + \mmuInstFlagModexpData _{i} = 1. + } +\end{center} +\[ + \left\{ \begin{array}{lcl} + \locInitTbo + & \define & \ppOutputCol{1}_{i} \\ + \locInitSlo + & \define & \ppOutputCol{2}_{i} \\ + \locInitSbo + & \define & \ppOutputCol{3}_{i} \\ + \locFirstLimbByteSize + & \define & \ppOutputCol{4}_{i} \\ + \locLastLimbByteSize + & \define & \ppOutputCol{5}_{i} \\ + % & \define & \ppOutputCol{6}_{i} \\ + % & \define & \ppOutputCol{7}_{i} \\ + % & \define & \ppOutputCol{8}_{i} \\ + % & \define & \ppOutputCol{9}_{i} \\ + % & \define & \ppOutputCol{10}_{i} \\ + % & \define & \ppOutputCol{11}_{i} \\ + % & \define & \ppOutputCol{12}_{i} \\ + % & \define & \ppOutputCol{13}_{i} \\ + % & \define & \ppOutputCol{14}_{i} \\ + % \locTotntIsOne + \locFirstLimbSingleSource + & \define & \ppOutputColBin{1}_{i} \\ + \locAligned + & \define & \ppOutputColBin{2}_{i} \\ + \locLastLimbSingleSource + & \define & \ppOutputColBin{3}_{i} \\ + % & \define & \ppOutputColBin{4}_{i} \\ + % & \define & \ppOutputColBin{5}_{i} \\ + % & \define & \ppOutputColBin{6}_{i} \\ + % & \define & \ppOutputColBin{7}_{i} \\ + % & \define & \ppOutputColBin{8}_{i} \\ + % & \define & \ppOutputColBin{9}_{i} \\ + % & \define & \ppOutputColBin{10}_{i} \\ + % & \define & \ppOutputColBin{11}_{i} \\ + % & \define & \ppOutputColBin{12}_{i} \\ + % & \define & \ppOutputColBin{13}_{i} \\ + % & \define & \ppOutputColBin{14}_{i} \\ + \end{array} \right. +\] + diff --git a/mmu/instructions/modexpData/shorthands_preprocessing.tex b/mmu/instructions/modexpData/shorthands_preprocessing.tex new file mode 100644 index 0000000..6460893 --- /dev/null +++ b/mmu/instructions/modexpData/shorthands_preprocessing.tex @@ -0,0 +1,47 @@ +The second batch is sourced from the macro-instruction-row. +They define ``\textbf{pre-processing shorthands}.'' +As such +\begin{center} + \boxed{% + \text{The shorthands presented below should only when} + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagModexpData _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +Now onto the shorthands: +\[ + \left\{ \begin{array}{lcl} + \locSrcId + & \define & \macroSrcId_{i} \\ + \locTgtId + & \define & \macroTgtId_{i} \\ + % & \define & \macroAuxId_{i} \\ + % & \define & \macroSrcOffsetHi_{i} \\ + \locSrcOffset + & \define & \macroSrcOffsetLo_{i} \\ + % & \define & \macroTgtOffsetLo_{i} \\ + \locSize + & \define & \macroSize_{i} \\ + \locCdo + & \define & \macroRefOffset_{i} \\ + \locCds + & \define & \macroRefSize_{i} \\ + % & \define & \macroSuccessBit_{i} \\ + % & \define & \macroLimbOne_{i} \\ + % & \define & \macroLimbTwo_{i} \\ + \locExoSum + & \define & \macroExoSum_{i} \\ + \locPhase + & \define & \macroPhase_{i} \\ + \end{array} \right. +\] +We also define +\[ + \left\{ \begin{array}{lcl} + \locModexpParamByteSize & \define & \locSize \\ + \locModexpParamOffset & \define & \locCdo + \locSrcOffset \\ + \locLeftoverCallDataSize & \define & \locCds - \locSrcOffset \\ + \end{array} \right. +\] diff --git a/mmu/instructions/modexpZero/_inputs.tex b/mmu/instructions/modexpZero/_inputs.tex new file mode 100644 index 0000000..2913a91 --- /dev/null +++ b/mmu/instructions/modexpZero/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Preprocessing} \label{mmu: instructions: trivial modexp parameter: preprocessing} \input{instructions/modexpZero/preprocessing} +\subsubsection{Initializing the first micro-instruction} \label{mmu: instructions: trivial modexp parameter: initialization} \input{instructions/modexpZero/initializing} +\subsubsection{Micro-instruction writing} \label{mmu: instructions: trivial modexp parameter: micro instruction writing} \input{instructions/modexpZero/micro_instruction_writing} diff --git a/mmu/instructions/modexpZero/initializing.tex b/mmu/instructions/modexpZero/initializing.tex new file mode 100644 index 0000000..01525bd --- /dev/null +++ b/mmu/instructions/modexpZero/initializing.tex @@ -0,0 +1,40 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagModexpZero _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We now do the initialization of the micro-instruction-writing phase. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstModexpZeroValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstModexpZeroValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstModexpZeroValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + \microCns _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + \microCnt _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstModexpZeroValuePO} & = & \exoWeightBlakeModexp \\ + \microPhase _{i + \nppMmuInstModexpZeroValuePO} & = & \macroPhase _{i} \\ + \microIdOne _{i + \nppMmuInstModexpZeroValuePO} & = & \macroTgtId _{i} \\ + \microIdTwo _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstModexpZeroValuePO} & = & \nothing \\ + \end{array} \right. + \] + \saNote{} + The phase depends on the nature of the data that is to be zero-ed out. + It is either the base of the call to \inst{MODEXP} or the exponent. + If the modulus is known to be zero ahead of time (either because $\ell_\text{M} \equiv 0$ or because call data has run out) the \mmuMod{} module won't be activated. + + We further impose that $\macroPhase _{i} \in \{ \phaseModexpBase, \phaseModexpExponent \}$ (\trash). + +\end{description} + diff --git a/mmu/instructions/modexpZero/micro_instruction_writing.tex b/mmu/instructions/modexpZero/micro_instruction_writing.tex new file mode 100644 index 0000000..992ceba --- /dev/null +++ b/mmu/instructions/modexpZero/micro_instruction_writing.tex @@ -0,0 +1,25 @@ +\begin{center} + \boxed{\text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \mmuInstFlagModexpZero _{i} & = & 1 \\ + \isMicro _{i} & = & 1 \\ + \end{array} \right.} +\end{center} +The micro-instruction-writing phase is very simple: the same instruction gets repeated over and over again (with incrementing source and target limb offsets, that is.) +\begin{description} + \item[Progression:] we impose $\stdProgression_{i}\Big[\isMicro, \microTlo \Big]$ + \item[Micro-instruction-writing] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstLimbVanishes \\ + \microSize _{i} & = & \nothing \\ + \microSlo _{i} & = & \nothing \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \nothing \\ + \microLimb _{i} & = & \nothing \\ + \end{array} \right. + \] +\end{description} + diff --git a/mmu/instructions/modexpZero/preprocessing.tex b/mmu/instructions/modexpZero/preprocessing.tex new file mode 100644 index 0000000..2af4727 --- /dev/null +++ b/mmu/instructions/modexpZero/preprocessing.tex @@ -0,0 +1,24 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagModexpZero _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We outline the pre-processing rows below. +There is no pre-processing to speak of, but we require at least one pre-processing-row. +\begin{description} + \item[Number of pre-processing-rows:] + we impose + \[ + \left\{ \begin{array}{lcl} + \ppTotLZ _{i} & = & 0 \\ + \ppTotNT _{i} & = & 32 \\ + \ppTotRZ _{i} & = & 0 \\ + \end{array} \right. + \] + \item[Pre-processing row $\bm{n^\circ 1}$:] + none required, we take the opportunity to kindly ask the Ethereum Foundation to kill the \inst{BLAKE2f} and \inst{RIPEMD-160} precompiles \faSmileO{} (maybe even \inst{MODEXP}.) $\quad(\trash)$ +\end{description} diff --git a/mmu/instructions/mstore/_inputs.tex b/mmu/instructions/mstore/_inputs.tex new file mode 100644 index 0000000..849f2f4 --- /dev/null +++ b/mmu/instructions/mstore/_inputs.tex @@ -0,0 +1 @@ +\subsubsection{Pre-processing and micro-instruction-writing} \label{mmu: instrutions: mstore: preprocessing and micro instruction writing} \input{instructions/mstore/preprocessing} diff --git a/mmu/instructions/mstore/preprocessing.tex b/mmu/instructions/mstore/preprocessing.tex new file mode 100644 index 0000000..2c925b1 --- /dev/null +++ b/mmu/instructions/mstore/preprocessing.tex @@ -0,0 +1,108 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagMstore _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We constrain the number of rows of the pre-processing and micro-instruction-writing phase: +\begin{enumerate} + \item $\ppTotNT_{i} = 2$ + \item $\ppTotLZ_{i} = 0$ + \item $\ppTotRZ_{i} = 0$ +\end{enumerate} +We advance to the actual pre-processing and micro-instruction-writing phases. +We deal with \mmuInstMstore{}'s in a fixed number of rows. +This allows us to deal both with pre-processing and micro-instruction-writing from a single vantage point. +\begin{description} + \item[Preprocessing row $\bm{n^\circ 1}$:] + we impose that + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{1} + {\macroTgtOffsetLo_{i}} + {\llarge} + \vspace{2mm} \\ + \callToIszero + {i}{1} + {0}{\locTbo} + \\ + \end{array} \right. + \] + where we define (and have already used) the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locAligned & \define & \ppWcpRes _{i + 1} \\ + \locTlo & \define & \ppEucQuot _{i + 1} \\ + \locTbo & \define & \ppEucRem _{i + 1} \\ + \end{array} \right. + \] + \item[Setting micro-instruction-writing-constant values:] + \[ + \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstMstoreValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstMstoreValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstMstoreValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstMstoreValuePO} & = & \macroLimbOne_{i} \\ + \microCns _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microCnt _{i + \nppMmuInstMstoreValuePO} & = & \macroTgtId_{i} \\ + \microSuccessBit _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstMstoreValuePO} & = & \rZero \\ + \microPhase _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \end{array} \right. + \] + \item[First micro-instruction writing:] + \[ \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstMstoreValuePO} & = & \locMicroInst \\ + \microSize _{i + \nppMmuInstMstoreValuePO} & = & \llarge \\ + \microSlo _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microSbo _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \microTlo _{i + \nppMmuInstMstoreValuePO} & = & \locTlo \\ + \microTbo _{i + \nppMmuInstMstoreValuePO} & = & \locTbo \\ + \microLimb _{i + \nppMmuInstMstoreValuePO} & = & \macroLimbOne_{i} \\ + % \microCns _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microCnt _{i + \nppMmuInstMstoreValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstMstoreValuePO} & = & \nothing \\ + \end{array} \right. + \] + + \item[Second micro-instruction writing:] + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstMstoreValuePT} & = & \locMicroInst \\ + \microSize _{i + \nppMmuInstMstoreValuePT} & = & \llarge \\ + \microSlo _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + \microSbo _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + \microTlo _{i + \nppMmuInstMstoreValuePT} & = & \locTlo + 1\\ + \microTbo _{i + \nppMmuInstMstoreValuePT} & = & \locTbo \\ + \microLimb _{i + \nppMmuInstMstoreValuePT} & = & \macroLimbTwo_{i} \\ + % \microCns _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + % \microCnt _{i + \nppMmuInstMstoreValuePT} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstMstoreValuePT} & = & \nothing \\ + \end{array} \right. + \] + where we \locMicroInst{} is a shorthand defined as follows: + \begin{enumerate} + \item \If $\locAligned = 1$ \Then $\locMicroInst \define \mmioInstLimbToRamTransplant $ + \item \If $\locAligned = 0$ \Then $\locMicroInst \define \mmioInstLimbToRamTwoTarget$ + \end{enumerate} +\end{description} diff --git a/mmu/instructions/mstore8/_inputs.tex b/mmu/instructions/mstore8/_inputs.tex new file mode 100644 index 0000000..be6d5c4 --- /dev/null +++ b/mmu/instructions/mstore8/_inputs.tex @@ -0,0 +1 @@ +\subsubsection{Pre-processing and micro-instruction-writing} \label{mmu: instrutions: mstore8: preprocessing and micro instruction writing} \input{instructions/mstore8/preprocessing} diff --git a/mmu/instructions/mstore8/preprocessing.tex b/mmu/instructions/mstore8/preprocessing.tex new file mode 100644 index 0000000..7060ee0 --- /dev/null +++ b/mmu/instructions/mstore8/preprocessing.tex @@ -0,0 +1,56 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagMstoreEight _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We constrain the number of rows of the pre-processing and micro-instruction-writing phase: +\begin{enumerate} + \item $\ppTotNT_{i} = 1$ + \item $\ppTotLZ_{i} = 0$ + \item $\ppTotRZ_{i} = 0$ +\end{enumerate} +We advance to the actual pre-processing and micro-instruction-writing phases. +We deal with \mmuInstMstoreEight{}'s in a fixed number of rows. +This allows us to deal both with pre-processing and micro-instruction-writing from a single vantage point. +\begin{description} + \item[Preprocessing row $\bm{n^\circ 1}$:] + we impose that + \[ + \callToEuc + {i}{1} + {\macroTgtOffsetLo_{i}} + {\llarge} + \] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locTlo & \define & \ppEucQuot _{i + 1} \\ + \locTbo & \define & \ppEucRem _{i + 1} \\ + \end{array} \right. + \] + \item[Setting micro-instruction-writing-constant values:] + \[ \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstMstoreEightValuePO} & = & \mmioInstLimbToRamOneTarget \\ + \microSize _{i + \nppMmuInstMstoreEightValuePO} & = & 1 \\ + \microSlo _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + \microSbo _{i + \nppMmuInstMstoreEightValuePO} & = & \llargeMO \\ + \microTlo _{i + \nppMmuInstMstoreEightValuePO} & = & \locTlo \\ + \microTbo _{i + \nppMmuInstMstoreEightValuePO} & = & \locTbo \\ + \microLimb _{i + \nppMmuInstMstoreEightValuePO} & = & \macroLimbTwo_{i} \\ + \microCns _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + \microCnt _{i + \nppMmuInstMstoreEightValuePO} & = & \macroTgtId_{i} \\ + \microSuccessBit _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstMstoreEightValuePO} & = & \rZero \\ + \microPhase _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstMstoreEightValuePO} & = & \nothing \\ + + \end{array} \right. + \] +\end{description} + diff --git a/mmu/instructions/ramToExoWithPadding/_inputs.tex b/mmu/instructions/ramToExoWithPadding/_inputs.tex new file mode 100644 index 0000000..931581b --- /dev/null +++ b/mmu/instructions/ramToExoWithPadding/_inputs.tex @@ -0,0 +1,4 @@ +\subsubsection{Global shorthands} \label{mmu: instructions: RamToExoWithPadding: global shorthands} \input{instructions/ramToExoWithPadding/shorthands_global} +\subsubsection{Preprocessing} \label{mmu: instructions: RamToExoWithPadding: preprocessing} \input{instructions/ramToExoWithPadding/preprocessing} +\subsubsection{Initializing the micro-instruction-writing} \label{mmu: instructions: RamToExoWithPadding: initialization} \input{instructions/ramToExoWithPadding/initializing} +\subsubsection{Micro instruction writing} \label{mmu: instructions: RamToExoWithPadding: micro instruction writing} \input{instructions/ramToExoWithPadding/micro_instruction_writing} diff --git a/mmu/instructions/ramToExoWithPadding/initializing.tex b/mmu/instructions/ramToExoWithPadding/initializing.tex new file mode 100644 index 0000000..023c533 --- /dev/null +++ b/mmu/instructions/ramToExoWithPadding/initializing.tex @@ -0,0 +1,26 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagRamToExoWithPadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We now do the initialization of the micro-instruction-writing phase. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ \left\{ \begin{array}{lcl} + \microCns _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroSrcId_{i} \\ + \microCnt _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroSuccessBit_{i} \\ + \microExoSum _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroExoSum_{i} \\ + \microPhase _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroPhase_{i} \\ + \microIdOne _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroTgtId_{i} \\ + \microIdTwo _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroAuxId_{i} \\ + \microTotalSize _{i + \nppMmuInstRamToExoWithPaddingValuePO} & = & \macroRefSize_{i} \\ + \end{array} \right. + \] +\end{description} + diff --git a/mmu/instructions/ramToExoWithPadding/micro_instruction_writing.tex b/mmu/instructions/ramToExoWithPadding/micro_instruction_writing.tex new file mode 100644 index 0000000..8aa7a10 --- /dev/null +++ b/mmu/instructions/ramToExoWithPadding/micro_instruction_writing.tex @@ -0,0 +1,104 @@ +\begin{center} \boxed{ \text{The pre-processing presented below assumes that } \mmuInstFlagRamToExoWithPadding _{i} = 1 } \end{center} + +We impose the following: +\begin{description} + \item[Progression:] \label{mmu: instructions: modexpdata: micro instrution writing: tlo progression} + we impose generally \If $\isMicro_{i} = 1$ \Then: + \begin{enumerate} + \item $\stdProgression_{i}\Big[\isMicro, \microTlo \Big]$ + \item $\microTbo_{i} = 0$ + \end{enumerate} + \item[First row:] + \If $\isFirstNT_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locFirstMicroInst \\ + \microSize _{i} & = & \llarge \\ + \microSlo _{i} & = & \locInitSlo \\ + \microSbo _{i} & = & \locInitSbo \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + \end{array} \right. + \] + where we define the \locFirstMicroInst{} shorthand as follows: + \begin{enumerate} + \item \If $\locAligned = 0$ \Then \( \locFirstMicroInst \define \mmioInstRamToLimbTwoSource \) + \item \If $\locAligned = 1$ \Then \( \locFirstMicroInst \define \mmioInstRamToLimbTransplant \) + \end{enumerate} + \item[Middle rows:] + \If $\isMiddleNT_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locMiddleMicroInst \\ + \microSize _{i} & = & \llarge \\ + \microSlo _{i} & = & \microSlo_{i - 1} + 1 \\ + \microSbo _{i} & = & \microSbo_{i - 1} \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + \end{array} \right. + \] + where we define the \locMiddleMicroInst{} shorthand as follows: + \begin{enumerate} + \item \If $\locAligned = 0$ \Then \( \locMiddleMicroInst \define \mmioInstRamToLimbTwoSource \) + \item \If $\locAligned = 1$ \Then \( \locMiddleMicroInst \define \mmioInstRamToLimbTransplant \) + \end{enumerate} + \item[Last nontrivial row:] + \If $\isLastNT_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \valueToBeSet \\ + \microSize _{i} & = & \valueToBeSet \\ + \microSlo _{i} & = & \microSlo_{i - 1} + 1 \\ + \microSbo _{i} & = & \microSbo_{i - 1} \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + \end{array} \right. + \] + \item[Only row:] + \If $\isOnlyNT_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \valueToBeSet \\ + \microSize _{i} & = & \valueToBeSet \\ + \microSlo _{i} & = & \locInitSlo \\ + \microSbo _{i} & = & \locInitSbo \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + \end{array} \right. + \] + \item[Final (only or last) row:] + \If $\isOnlyNT_{i} + \isLastNT_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locLastMicroInst \\ + \microSize _{i} & = & \locLastLimbByteSize \\ + \end{array} \right. + \] + where + \begin{enumerate} + \item \If $\locLastLimbSingleSource = 0$ \Then \( \locLastMicroInst \define \mmioInstRamToLimbTwoSource \) + \item \If $\locLastLimbSingleSource = 1$ + \begin{enumerate} + \item \If $\locLastLimbIsFull = 0$ \Then \( \locLastMicroInst \define \mmioInstRamToLimbOneSource \) + \item \If $\locLastLimbIsFull = 1$ \Then \( \locLastMicroInst \define \mmioInstRamToLimbTransplant \) + \end{enumerate} + \end{enumerate} + \item[Padding rows:] + \If $\isRightZero_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \mmioInstLimbVanishes \\ + \microSize _{i} & = & \nothing \\ + \microSlo _{i} & = & \nothing \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \relevantValue \\ + \end{array} \right. + \] + \saNote{} The ``\relevantValue'' in this case will be $\rZero$. +\end{description} diff --git a/mmu/instructions/ramToExoWithPadding/preprocessing.tex b/mmu/instructions/ramToExoWithPadding/preprocessing.tex new file mode 100644 index 0000000..72ea855 --- /dev/null +++ b/mmu/instructions/ramToExoWithPadding/preprocessing.tex @@ -0,0 +1,100 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagRamToExoWithPadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We outline the preprocessing rows +\begin{description} + \item[Number of preprocessing rows:] + we impose $\ppTotLZ_{i} = 0$ + \def\rowNum{1} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{\rowNum} + {\macroSrcOffsetLo_{i}} + {\llarge} + \vspace{2mm} \\ + \callToIszero + {i}{\rowNum} + {0}{\locInitSbo} \\ + \end{array} \right. + \] + we constrain + \[ + \locAligned = \ppWcpRes _{i + \rowNum} + \] + and we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locInitSlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locInitSbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + \def\rowNum{2} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \left\{ \begin{array}{l} + \callToLt + {i}{\rowNum} + {0}{\macroSize_{i}} + {\macroRefSize_{i}} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {\locPaddingSize} + {\llarge} + \\ + \end{array} \right. + \] + where we define (and have already used) the following shorthand: + \begin{enumerate} + \item $\locHasRightPadding \define \ppWcpRes _{i + \rowNum}$ + \item $\locPaddingSize \define \locHasRightPadding \cdot (\macroRefSize_{i} - \macroSize_{i})$ + \item \If $\locHasRightPadding = 0$ \Then $\locExtractionSize \define \macroRefSize_{i}$ + \item \If $\locHasRightPadding = 1$ \Then $\locExtractionSize \define \macroSize_{i}$ + \end{enumerate} + we further impose the following constraint: + \[ + \ppTotRZ_{i} = \ppEucQuot_{i + \rowNum} + \] + \def\rowNum{3} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \left\{ \begin{array}{lcl} + \callToEuc + {i}{\rowNum} + {\locExtractionSize} + {\llarge} + \vspace{2mm} \\ + \callToIszero + {i}{\rowNum} + {0}{\ppEucRem_{i + \rowNum}} + \\ + \end{array} \right. + \] + we constrain: + \begin{enumerate} + \item $\ppTotNT_{i} = \ppEucCeil_{i + \rowNum}$ + \item $\locLastLimbIsFull = \ppWcpRes_{i + \rowNum}$ + \item \If $\locLastLimbIsFull = 1$ \Then $\locLastLimbByteSize = \llarge$ + \item \If $\locLastLimbIsFull = 0$ \Then $\locLastLimbByteSize = \ppEucRem_{i + \rowNum}$ + \end{enumerate} + \def\rowNum{4} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that: + \[ + \callToLt + {i}{\rowNum} + {0}{\locInitSbo + (\locLastLimbByteSize - 1)} + {\llarge} + \] + and impose that + \[ + \locLastLimbSingleSource = \ppWcpRes _{i + \rowNum} + \] +\end{description} diff --git a/mmu/instructions/ramToExoWithPadding/shorthands_global.tex b/mmu/instructions/ramToExoWithPadding/shorthands_global.tex new file mode 100644 index 0000000..44e979d --- /dev/null +++ b/mmu/instructions/ramToExoWithPadding/shorthands_global.tex @@ -0,0 +1,16 @@ +The first batch of ``\textbf{global shorthands}'' is sourced from the stamp-constant output columns, see section~(\ref{mmu: constancies: stamp constancies of pre processing outputs}). +As such +\begin{center} + \boxed{% + \text{The shorthands presented below should only be used when } + \mmuInstFlagRamToExoWithPadding _{i} = 1. + } +\end{center} +\[ + \left\{ \begin{array}{lcl} + \locAligned & \define & \ppOutputColBin{1} _{i} \\ + \locLastLimbByteSize & \define & \ppOutputCol{1} _{i} \\ + \locLastLimbSingleSource & \define & \ppOutputColBin{2} _{i} \\ + \locLastLimbIsFull & \define & \ppOutputColBin{3} _{i} \\ + \end{array} \right. +\] diff --git a/mmu/instructions/ramToRamSansPadding/_inputs.tex b/mmu/instructions/ramToRamSansPadding/_inputs.tex new file mode 100644 index 0000000..4193e41 --- /dev/null +++ b/mmu/instructions/ramToRamSansPadding/_inputs.tex @@ -0,0 +1,5 @@ +\subsubsection{Introduction} \label{mmu: instructions: ram to ram sans padding: intro} \input{instructions/ramToRamSansPadding/intro} +\subsubsection{Global shorthands} \label{mmu: instructions: ram to ram sans padding: global shorthands} \input{instructions/ramToRamSansPadding/shorthands_global} +\subsubsection{Preprocessing} \label{mmu: instructions: ram to ram sans padding: preprocessing} \input{instructions/ramToRamSansPadding/preprocessing} +\subsubsection{Initializing the micro-instruction-writing} \label{mmu: instructions: ram to ram sans padding: initialization} \input{instructions/ramToRamSansPadding/initialize} +\subsubsection{Micro instruction writing} \label{mmu: instructions: ram to ram sans padding: micro instruction writing} \input{instructions/ramToRamSansPadding/micro_instruction_writing} diff --git a/mmu/instructions/ramToRamSansPadding/initialize.tex b/mmu/instructions/ramToRamSansPadding/initialize.tex new file mode 100644 index 0000000..e7dd264 --- /dev/null +++ b/mmu/instructions/ramToRamSansPadding/initialize.tex @@ -0,0 +1,54 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagRamToRamSansPadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We use the present vantage point to settle some micro-instruction related paramaters, in particular those which remain constant throughout micro-instruction-writing and other pertaining to the first micro-instruction-writing-row. +\begin{description} + \item[Setting micro-instruction-writing-constant values:] + we impose + \[ + \left\{ \begin{array}{lcl} + % \microInst _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microSbo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microTlo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locTlo \\ + % \microTbo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locTbo \\ + % \microLimb _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \macroLimbTwo_{i} \\ + \microCns _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \macroSrcId_{i} \\ + \microCnt _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \macroTgtId_{i} \\ + \microSuccessBit _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \microPhase _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \end{array} \right. + \] + \item[First micro-instruction-writing-row:] \label{mmu: instructions: modexpdata: initialize: tlo is initially 0} + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \valueToBeSet \\ + \microSize _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locFirstLimbByteSize \\ + \microSlo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locInitSlo \\ + \microSbo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locInitSbo \\ + \microTlo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locInitTlo \\ + \microTbo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \locInitTbo \\ + \microLimb _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microCns _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \macroSrcId_{i} \\ + % \microCnt _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstRamToRamSansPaddingValuePO} & = & \nothing \\ + \end{array} \right. + \] +\end{description} diff --git a/mmu/instructions/ramToRamSansPadding/intro.tex b/mmu/instructions/ramToRamSansPadding/intro.tex new file mode 100644 index 0000000..1920f61 --- /dev/null +++ b/mmu/instructions/ramToRamSansPadding/intro.tex @@ -0,0 +1,2 @@ +The present \mmuMod{}-instruction allows one to move an arbitrary amount of data from one \textsc{ram} segment to another. +It is used by (message call) \inst{RETURN}'s, \inst{REVERT}'s, it is used for making the original copy of call data in a \inst{CALL} to the \inst{IDENTITY} precompile as well as for all (partial) copies of return data that feature at the end of \inst{CALL}'s to precompiles. diff --git a/mmu/instructions/ramToRamSansPadding/micro_instruction_writing.tex b/mmu/instructions/ramToRamSansPadding/micro_instruction_writing.tex new file mode 100644 index 0000000..f422634 --- /dev/null +++ b/mmu/instructions/ramToRamSansPadding/micro_instruction_writing.tex @@ -0,0 +1,158 @@ +\begin{center} + \boxed{ \text{The constriants presented below assumes that } \mmuInstFlagRamToRamSansPadding _{i} = 1. } +\end{center} +\begin{description} + \item[Progression:] + we impose that + \begin{enumerate} + \item \If $\isFirstNT_{i} + \isMiddleNT_{i} = 1$ \Then $\microTlo_{i + 1} = \microTlo_{i} + 1$ + \item \If $\isFirstNT_{i} = 1$ \Then $\microSlo_{i + 1} = \microSlo_{i} + \locMicroSloIncrement$ + \item \If $\isMiddleNT_{i} = 1$ \Then $\microSlo_{i + 1} = \microSlo_{i} + 1$ + % \[ + % \left\{ \begin{array}{lcl} + % \microSbo_{i + 1} & = & \locMiddleSbo_{i} \vspace{2mm} \\ + % \microTlo_{i + 1} & = & 1 + \microTlo_{i} \\ + % \microTbo_{i + 1} & = & 0 \\ + % \end{array} \right. + % \] + % \item \If $\isFirstNT_{i} + \isMiddleNT_{i} = 1$ \Then $\microSbo_{i + 1} = \locMiddleSbo_{i}$ + % \[ + % \left\{ \begin{array}{lcl} + % \microTlo_{i + 1} & = & 1 + \microTlo_{i} \\ + % \end{array} \right. + % \] + % \item \If $\isMiddleNT_{i} + \isLastNT_{i} = 1$ \Then + % \[ + % \left\{ \begin{array}{lcl} + % \microSbo_{i} & = & \locMiddleSbo_{i} \\ + % \microTbo_{i} & = & 0 \\ + % \microTlo_{i} & = & 1 + \microTlo_{i - 1} \\ + % \end{array} \right. + % \] + \end{enumerate} + \item[Only nontrivial row:] + \If $\isOnlyNT_{i}$ \Then + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locOnlyMicroInst \\ + \microSize _{i} & = & \alreadySet \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \alreadySet \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where we define the \locOnlyMicroInst{} shorthand as follows: + \begin{enumerate} + \item \If $\locFastLastLimb = 1$ \Then $\locOnlyMicroInst \define \mmioInstRamToRamTransplant$ + \item \If $\locFastLastLimb = 0$ \Then + \begin{enumerate} + \item \If $\locLastLimbSingleSource = 1$ \Then \[ \locOnlyMicroInst \define \mmioInstRamToRamPartial \] + \item \If $\locLastLimbSingleSource = 0$ \Then \[ \locOnlyMicroInst \define \mmioInstRamToRamTwoSource \] + \end{enumerate} + \end{enumerate} + \saNote{} We remind the reader about note~(\ref{mmu: instructions: ram to ram sans padding: fast_last_limb is useful for totnt = 1}) which justifies the use of \locFastLastLimb{} in the $\isOnlyNT \equiv 1$ case. + \item[First nontrivial row:] + \If $\isFirstNT_{i} = 1$ \Then + \begin{description} + \item[Micro-instruction:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locFirstMicroInst \\ + \microSize _{i} & = & \alreadySet \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \alreadySet \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & \alreadySet \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where we define the \locFirstMicroInst{} shorthand as follows: + \begin{enumerate} + \item \If $\locFastFirstLimb = 1$ \Then $\locFirstMicroInst \define \mmioInstRamToRamTransplant$ + \item \If $\locFastFirstLimb = 0$ \Then + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 1$ \Then \[ \locFirstMicroInst \define \mmioInstRamToRamPartial \] + \item \If $\locFirstLimbSingleSource = 0$ \Then \[ \locFirstMicroInst \define \mmioInstRamToRamTwoSource \] + \end{enumerate} + \end{enumerate} + \end{description} + \item[Middle nontrivial rows:] + \If $\isMiddleNT_{i} = 1$ \Then + \begin{description} + \item[Micro-instruction:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locMiddleMicroInst \\ + \microSize _{i} & = & \llarge \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \locMiddleSbo_{i} \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & 0 \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where we define the \locMiddleMicroInst{} shorthand as follows: + \begin{enumerate} + \item \If $\locAligned = 1$ \Then $\locMiddleMicroInst \define \mmioInstRamToRamTransplant$ + \item \If $\locAligned = 0$ \Then $\locMiddleMicroInst \define \mmioInstRamToRamTwoSource$ + \end{enumerate} + \end{description} + \item[Last nontrivial row:] + \If $\isLastNT_{i} = 1$ \Then + \begin{description} + \item[Micro-instruction:] + we impose + \[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \locLastMicroInst \\ + \microSize _{i} & = & \locLastLimbByteSize_{i} \\ + \microSlo _{i} & = & \alreadySet \\ + \microSbo _{i} & = & \locMiddleSbo_{i} \\ + \microTlo _{i} & = & \alreadySet \\ + \microTbo _{i} & = & 0 \\ + \microLimb _{i} & = & \nothing \\ + % \microCns _{i} & = & \macroSrcId_{i} \\ + % \microCnt _{i} & = & \macroTgtId_{i} \\ + % \microSuccessBit _{i} & = & \nothing \\ + % \microExoSum _{i} & = & \nothing \\ + % \microPhase _{i} & = & \nothing \\ + % \microIdOne _{i} & = & \nothing \\ + % \microIdTwo _{i} & = & \nothing \\ + \end{array} \right. + \] + where we set + \begin{enumerate} + \item \If $\locFastLastLimb = 1$ \Then $\locLastMicroInst \define \mmioInstRamToRamTransplant$ + \item \If $\locFastLastLimb = 0$ \Then + \begin{enumerate} + \item \If $\locLastLimbSingleSource = 1$ \Then $\locLastMicroInst \define \mmioInstRamToRamPartial$ + \item \If $\locLastLimbSingleSource = 0$ \Then $\locLastMicroInst \define \mmioInstRamToRamTwoSource$ + \end{enumerate} + \end{enumerate} + \end{description} +\end{description} diff --git a/mmu/instructions/ramToRamSansPadding/preprocessing.tex b/mmu/instructions/ramToRamSansPadding/preprocessing.tex new file mode 100644 index 0000000..2b64c71 --- /dev/null +++ b/mmu/instructions/ramToRamSansPadding/preprocessing.tex @@ -0,0 +1,211 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagRamToRamSansPadding _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We do the pre-processing. +\begin{description} + \item[Number of preprocessing rows:] + we impose + \[ + \left\{ \begin{array}{lcl} + \ppTotLZ_{i} & = & 0 \\ + \ppTotRZ_{i} & = & 0 \\ + \end{array} \right. + \] + \item[Shorthands:] + we use the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locRdo & \define & \macroSrcOffsetLo _{i} \\ + \locRds & \define & \macroSize _{i} \\ + \locRao & \define & \macroRefOffset _{i} \\ + \locRac & \define & \macroRefSize _{i} \\ + \end{array} \right. + \] + \def\rowNum{1} \item[Pre-processing row $\bm{n^\circ (i + \rowNum)}$:] + we impose + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{\rowNum} + {\locRdo} + {\llarge} + \\ + \callToLt + {i}{\rowNum} + {0}{\locRac} + {\locRds} \vspace{2mm} \\ + \end{array} \right. + \] + and we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locInitSlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locInitSbo & \define & \ppEucRem _{i + \rowNum} \\ + \locCmp & \define & \ppWcpRes _{i + \rowNum} \\ + \locRealSize & \define & + \begin{cases} + \If \locCmp = 0 ~ \Then \locRds \\ + \If \locCmp = 1 ~ \Then \locRac \\ + \end{cases} \\ + \end{array} \right. + \] + \def\rowNum{2} \item[Pre-processing row $\bm{n^\circ (i + \rowNum)}$:] + we impose + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{\rowNum} + {\locRao} + {\llarge} + \\ + \callToEq + {i}{\rowNum} + {0}{\locInitSbo} + {\locInitTbo} + \\ + % \callToEq {i + \rowNum} {0}{\locInitSbo} {\locInitTbo} \\ + \end{array} \right. + \] + where we have defined the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locInitTlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locInitTbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + we also impose + \[ + \locAligned = \ppWcpRes_{i + \rowNum} + \] + \def\rowNum{3} \item[Pre-processing row $\bm{n^\circ (i + \rowNum)}$:] + we impose + \[ + \left\{ \begin{array}{l} + \callToEuc + {i}{\rowNum} + {\locRao + (\locRealSize - 1)} + {\llarge} + \vspace{2mm} \\ + \callToEq + {i}{\rowNum} + {0}{\ppTotNT_{i}} + {1} \\ + % \callToEq {i + \rowNum} {0}{$\ppTotNT_{i}$} {1} \\ + \end{array} \right. + \] + and we impose + \[ + \ppTotNT_{i} = \Big( \locLastTlo - \locInitTlo \Big) + 1 + \] + we also define the following shorthand: + \[ + \left\{ \begin{array}{lcl} + \locTotntIsOne & \define & \ppWcpRes_{i + \rowNum} \\ + \locLastTlo & \define & \ppEucQuot_{i + \rowNum} \\ + \end{array} \right. + \] + we further impose + \begin{enumerate} + \item \If $\locTotntIsOne = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \locFirstLimbByteSize & \define & \locRealSize \\ + \locLastLimbByteSize & = & \locRealSize \\ + \end{array} \right. + \] + \item \If $\locTotntIsOne = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \locFirstLimbByteSize & \define & \llarge - \locInitTbo \\ + \locLastLimbByteSize & = & 1 + \ppEucRem_{i + \rowNum} \\ + \end{array} \right. + \] + \end{enumerate} + \def\rowNum{4} \item[Pre-processing row $\bm{n^\circ (i + \rowNum)}$:] + we impose + \[ + \left\{ \begin{array}{l} + \callToLt + {i}{\rowNum} + {0}{\locInitSbo + (\locFirstLimbByteSize - 1)} + {\llarge} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {\locMiddleSbo + (\locLastLimbByteSize - 1)} + {\llarge} + \\ + \end{array} \right. + \] + we further impose + \[ + \locFirstLimbSingleSource \define \ppWcpRes_{i + \rowNum} + \] + we also impose + \begin{enumerate} + \item \If $\locAligned = 1$ \Then $\locMiddleSbo = 0$ \qquad (\trash) + \item \If $\locAligned = 0$ \Then + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 1$ \Then \[ \locMiddleSbo = \locInitSbo + \locFirstLimbByteSize \] + \item \If $\locFirstLimbSingleSource = 0$ \Then \[ \locMiddleSbo = \locInitSbo + \locFirstLimbByteSize - \llarge \] + \end{enumerate} + \end{enumerate} + furthermore + \begin{enumerate} + \item \If $\locTotntIsOne = 1$ \Then $\locLastLimbSingleSource = \locFirstLimbSingleSource$ + \item \If $\locTotntIsOne = 0$ \Then $\locLastLimbSingleSource = 1 - \ppEucQuot _{i + \rowNum}$ + \end{enumerate} + we further constrain \locMicroSloIncrement{} as follows: + \begin{enumerate} + \item \If $\locAligned = 1$ \Then $\locMicroSloIncrement = 1$ + \item \If $\locAligned = 0$ \Then $\locMicroSloIncrement = 1 - \locFirstLimbSingleSource$ + \end{enumerate} + \saNote{} + We will only use \locLastLimbSingleSource{} in the $\locTotntIsOne = 0$ case, so we could get away without the case analysis. + We will similarly only use \locMicroSloIncrement{} in case $\locTotntIsOne = 0$. + \def\rowNum{5} \item[Pre-processing row $\bm{n^\circ (i + \rowNum)}$:] + we impose + \[ + \left\{ \begin{array}{l} + \callToIszero + {i}{\rowNum} + {0}{\locInitTbo} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {\locLastLimbByteSize} + {\llarge} + \\ + \end{array} \right. + \] + we further impose that + \[ + \locFastLastLimb = \locAligned \cdot \locLastLimbIsFull + \] + where we define the \locLastLimbIsFull{} shorthand + \begin{enumerate} + \item $\locInitTboIsZero \define \ppWcpRes _{i + \rowNum}$ + \item $\locLastLimbIsFull \define \ppEucQuot _{i + \rowNum}$ + \item \If $\locTotntIsOne = 0$ \Then $\locFastFirstLimb \define \locAligned \cdot \locInitTboIsZero$ + \end{enumerate} +\end{description} +\saNote{} +We provide some explanation for the shorthand definition of \locLastLimbIsFull{}. +The goal is for this shorthand to contain +$0$ if $\locLastLimbByteSize < \llarge$ and +$1$ if $\locLastLimbByteSize = \llarge$. +Fist of all note that by construction $\locLastLimbByteSize \in \{1, 2, \dots, \llarge \}$. +Its quotient under euclidean division by $\llarge$ is therefore $\in \{ 0, 1\}$, and equals $1$ \emph{iff} $\locLastLimbByteSize = \llarge$. +This justifies the shorthand definition in terms of the quotient. + +\saNote{} \label{mmu: instructions: ram to ram sans padding: fast_last_limb is useful for totnt = 1} +We also provide an observation for \locFastLastLimb{}, that observation being: whenever $\ppTotNT \equiv 1$ (i.e. $\locTotntIsOne = 1$) we see that $\locFastLastLimb = 1 \iff$ the one micro-instruction that gets executed is a limb transplant. This explains why we use that flag in the ``\textbf{Only nontrivial row}'' case of micro-instruction-writing. + +\saNote{} We won't use \locFastFirstLimb{} in case $\ppTotNT \equiv 1$. In its stead we will use \locFastLastLimb{}, which is defined in all cases. +One \emph{could} therefore drop the precondition ``\If $\locTotntIsOne = 0$ \Then \dots'' from its definition, though, if dropped, the interpretation of this shorthand fails in case $\ppTotNT \equiv 1$. diff --git a/mmu/instructions/ramToRamSansPadding/shorthands_global.tex b/mmu/instructions/ramToRamSansPadding/shorthands_global.tex new file mode 100644 index 0000000..f85fb5e --- /dev/null +++ b/mmu/instructions/ramToRamSansPadding/shorthands_global.tex @@ -0,0 +1,18 @@ +The first batch of ``\textbf{global shorthands}'' is sourced from the stamp-constant output columns, see section~(\ref{mmu: constancies: stamp constancies of pre processing outputs}). +As such +\begin{center} + \boxed{% + \text{The shorthands presented below should only be used when } + \mmuInstFlagRamToRamSansPadding _{i} = 1. + } +\end{center} +\[ + \left\{ \begin{array}{lcl} + \locLastLimbByteSize & \define & \ppOutputCol {1} _{i} \\ + \locMiddleSbo & \define & \ppOutputCol {2} _{i} \\ + \locAligned & \define & \ppOutputColBin {1} _{i} \\ + \locLastLimbSingleSource & \define & \ppOutputColBin {2} _{i} \\ + \locMicroSloIncrement & \define & \ppOutputColBin {3} _{i} \\ + \locFastLastLimb & \define & \ppOutputColBin {4} _{i} \\ + \end{array} \right. +\] diff --git a/mmu/instructions/rightPaddedWordExtraction/_inputs.tex b/mmu/instructions/rightPaddedWordExtraction/_inputs.tex new file mode 100644 index 0000000..da0cb56 --- /dev/null +++ b/mmu/instructions/rightPaddedWordExtraction/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Introduction} \label{mmu: instructions: right padded word extraction: intro} \input{instructions/rightPaddedWordExtraction/intro} +\subsubsection{Pre-processing and micro-instruction-writing} \label{mmu: instructions: right padded word extraction: preprocessing} \input{instructions/rightPaddedWordExtraction/preprocessing} +\subsubsection{Micro-instruction writing} \label{mmu: instructions: right padded word extraction: micro instruction writing} \input{instructions/rightPaddedWordExtraction/micro_instruction_writing} diff --git a/mmu/instructions/rightPaddedWordExtraction/intro.tex b/mmu/instructions/rightPaddedWordExtraction/intro.tex new file mode 100644 index 0000000..2d263de --- /dev/null +++ b/mmu/instructions/rightPaddedWordExtraction/intro.tex @@ -0,0 +1,5 @@ +The \mmuMod{}-instruction \mmuInstRightPaddedWordExtraction{} instruction will only ever be called with parameters satisfying +\[ + \macroSrcOffsetLo < \macroRefSize. +\] +\ob{TODO ? We could add this as an extra constraint. This preselection is already done in the \hubMod{} but still \dots{}} diff --git a/mmu/instructions/rightPaddedWordExtraction/micro_instruction_writing.tex b/mmu/instructions/rightPaddedWordExtraction/micro_instruction_writing.tex new file mode 100644 index 0000000..b4f8ef4 --- /dev/null +++ b/mmu/instructions/rightPaddedWordExtraction/micro_instruction_writing.tex @@ -0,0 +1,102 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagRightPaddedWordExtraction{} _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +\begin{description} + \def\rowNum{\nppMmuInstRightPaddedWordExtractionValuePO} \item[Setting micro-instruction-writing-constant values:] + we impose + \[ \left\{ \begin{array}{lclr} + % \microInst _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locMicroInst \\ + % \microSize _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microSlo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locSlo \\ + % \microSbo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locSbo \\ + % \microTlo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microTbo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microLimb _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microCns _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \macroSrcId_{i} \\ + \microCnt _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microSuccessBit _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microExoSum _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \rZero \\ + \microPhase _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microIdOne _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microIdTwo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microTotalSize _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \end{array} \right. + \] + \saNote{} It is important to set the \microExoSum{} to $\rZero$ as we will be using an exogenous data instruction in case the second limb is void. + \item[First micro-instruction:] + we impose that + \[ \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locFirstMicroInst \\ + \microSize _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locFirstLimbByteSize \\ + \microSlo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locSlo \\ + \microSbo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \locSbo \\ + \microTlo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \microTbo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & 0 \\ + \microLimb _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \macroLimbOne_{i} \\ + % \microCns _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \macroTgtId_{i} \\ + % \microCnt _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microSuccessBit _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \end{array} \right. + \] + where \locFirstMicroInst is a shorthand defined as follows: + \begin{enumerate} + \item \If $\locFirstLimbSingleSource = 1$ \Then + \begin{enumerate} + \item \If $\locFirstLimbIsFull = 1$ \Then $\locFirstMicroInst = \mmioInstRamToLimbTransplant$ + \item \If $\locFirstLimbIsFull = 0$ \Then $\locFirstMicroInst = \mmioInstRamToLimbOneSource$ + \end{enumerate} + \item \If $\locFirstLimbSingleSource = 0$ \Then $\locFirstMicroInst = \mmioInstRamToLimbTwoSource$ + \end{enumerate} + \def\rowNum{\nppMmuInstRightPaddedWordExtractionValuePT} \item[Second micro-instruction:] + we impose that + \[ \left\{ \begin{array}{lcl} + \microInst _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \locSecondMicroInst \\ + \microSize _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \locSecondLimbByteSize \\ + \microSlo _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \locSlo + 1 \\ + \microSbo _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \locSbo \\ + \microTlo _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + \microTbo _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & 0 \\ + \microLimb _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \macroLimbTwo_{i} \\ + % \microCns _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \macroTgtId_{i} \\ + % \microCnt _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + % \microSuccessBit _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + % \microExoSum _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + % \microPhase _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + % \microIdOne _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + % \microIdTwo _{i + \nppMmuInstRightPaddedWordExtractionValuePT} & = & \nothing \\ + % \microTotalSize _{i + \nppMmuInstRightPaddedWordExtractionValuePO} & = & \nothing \\ + \end{array} \right. + \] + where \locLastMicroInst is a shorthand defined as follows: + \begin{enumerate} + \item \If $\locSecondLimbVoid = 1$ \Then + \begin{enumerate} + \item $\macroLimbTwo_{i} = 0$ + \item $\locSecondMicroInst \define \mmioInstLimbVanishes$ + \end{enumerate} + \item \If $\locSecondLimbVoid = 0$ \Then + \begin{enumerate} + \item \If $\locSecondLimbSingleSource = 1$ \Then + \begin{enumerate} + \item \If $\locSecondLimbPadded = 0$ \Then $\locSecondMicroInst \define \mmioInstRamToLimbTransplant$ + \item \If $\locSecondLimbPadded = 1$ \Then $\locSecondMicroInst \define \mmioInstRamToLimbOneSource$ + \end{enumerate} + \item \If $\locSecondLimbSingleSource = 0$ \Then $\locSecondMicroInst \define \mmioInstRamToLimbTwoSource$ + \end{enumerate} + \end{enumerate} + \saNote{} The \mmioMod{} is going to carry out a second micro-instrution even if the second limb to be extracted is empty i.e. in case $\locSecondLimbVoid \equiv 1$. + We have chosen for that instruction to be \mmioInstLimbVanishes{}. + In order for this instruction to not affect exogenous data modules we impose that no exogneous data be loaded. + This follows from $\microExoSum \equiv 0$. +\end{description} diff --git a/mmu/instructions/rightPaddedWordExtraction/preprocessing.tex b/mmu/instructions/rightPaddedWordExtraction/preprocessing.tex new file mode 100644 index 0000000..7b64cdf --- /dev/null +++ b/mmu/instructions/rightPaddedWordExtraction/preprocessing.tex @@ -0,0 +1,126 @@ +\begin{center} + \boxed{% + \text{The pre-processing presented below assumes that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagRightPaddedWordExtraction{} _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We constrain the number of rows of the pre-processing and micro-instruction-writing phase: +\begin{enumerate} + \item $\ppTotNT_{i} = 2$ + \item $\ppTotLZ_{i} = 0$ + \item $\ppTotRZ_{i} = 0$ +\end{enumerate} +We advance to the actual pre-processing. +We deal with \mmuInstRightPaddedWordExtraction{}'s in a fixed number of rows. +\begin{description} + \def\rowNum{1} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \callToLt + {i}{\rowNum} + {0}{\macroSrcOffsetLo_{i} + \evmWordSize} + {\macroRefSize_{i}} + \] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locSecondLimbPadded & \define & 1 - \ppWcpRes _{i + \rowNum} \\ + \locExtractionSize & \define & + \begin{cases} + \If \locSecondLimbPadded = 1: & \macroRefSize_{i} - \macroSrcOffsetLo_{i} \\ + \If \locSecondLimbPadded = 0: & \evmWordSize \\ + \end{cases} \\ + \end{array} \right. + \] + \def\rowNum{2} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \left\{ \begin{array}{lcl} + \callToLt + {i}{\rowNum} + {0}{\locExtractionSize} + {\llarge} + \vspace{2mm} \\ + \callToEuc + {i}{\rowNum} + {\locFirstLimbByteSize} + {\llarge} + \\ + \end{array} \right. + \] + where we define (and have already used) some shorthands as follows: + \begin{enumerate} + \item $\locFirstLimbPadded \define \ppWcpRes_{i + \rowNum}$ + \item we define $\locSecondLimbByteSize$ as follows: + \begin{enumerate} + \item \If $\locSecondLimbPadded = 0$ \Then $\locSecondLimbByteSize \define \llarge$ + \item \If $\locSecondLimbPadded = 1$ \Then + \begin{enumerate} + \item \If $\locFirstLimbPadded = 0$ \Then $\locSecondLimbByteSize \define \locExtractionSize - \llarge$ + \item \If $\locFirstLimbPadded = 1$ \Then $\locSecondLimbByteSize \define 0$ + \end{enumerate} + \end{enumerate} + \item we define $\locFirstLimbByteSize$ as follows: + \begin{enumerate} + \item \If $\locFirstLimbPadded = 0$ \Then $\locFirstLimbByteSize \define \llarge$ + \item \If $\locFirstLimbPadded = 1$ \Then $\locFirstLimbByteSize \define \locExtractionSize$ + \end{enumerate} + \item $\locFirstLimbIsFull \define \ppEucQuot_{i + \rowNum}$ + \end{enumerate} +\end{description} +\saNote{} By construction we have $1 \leq \locFirstLimbByteSize \leq \llarge$ whence $\locFirstLimbIsFull \in \{ 0, 1 \}$ and furthermore +$\locFirstLimbIsFull = 1 \iff \locFirstLimbByteSize = \llarge$ +\begin{description} + \def\rowNum{3} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \callToEuc + {i}{\rowNum} + {\macroSrcOffsetLo_{i} + \macroRefOffset{}_{i}} + {\llarge} + \] + we define the following shorthands: + \[ + \left\{ \begin{array}{lcl} + \locSlo & \define & \ppEucQuot _{i + \rowNum} \\ + \locSbo & \define & \ppEucRem _{i + \rowNum} \\ + \end{array} \right. + \] + we impose that + \[ + \callToLt + {i}{\rowNum} + {0}{\locSbo + \locFirstLimbByteSize} + {\llarge + 1} + \] + we define the following shorthands: + \[ + \locFirstLimbSingleSource \define \ppWcpRes _{i + \rowNum} + \] + \def\rowNum{4} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \callToLt + {i}{\rowNum} + {0}{\locSbo + \locSecondLimbByteSize} + {\llarge + 1} + \] + we define the following shorthands: + \[ + \locSecondLimbSingleSource \define \ppWcpRes _{i + \rowNum} + \] + \def\rowNum{5} \item[Preprocessing row $\bm{n^\circ \rowNum}$:] + we impose that + \[ + \callToIszero + {i}{\rowNum} + {0}{\locSecondLimbByteSize} + \] + we define the following shorthands: + \[ + \locSecondLimbVoid \define \ppWcpRes _{i + \rowNum} + \] +\end{description} diff --git a/mmu/instructions/templates/micro_instruction.tex b/mmu/instructions/templates/micro_instruction.tex new file mode 100644 index 0000000..a554001 --- /dev/null +++ b/mmu/instructions/templates/micro_instruction.tex @@ -0,0 +1,19 @@ +\[ + \left\{ \begin{array}{lcl} + \microInst _{i} & = & \nothing \\ + \microSize _{i} & = & \nothing \\ + \microSlo _{i} & = & \nothing \\ + \microSbo _{i} & = & \nothing \\ + \microTlo _{i} & = & \nothing \\ + \microTbo _{i} & = & \nothing \\ + \microLimb _{i} & = & \nothing \\ + \microCns _{i} & = & \nothing \\ + \microCnt _{i} & = & \nothing \\ + \microSuccessBit _{i} & = & \nothing \\ + \microExoSum _{i} & = & \nothing \\ + \microPhase _{i} & = & \nothing \\ + \microIdOne _{i} & = & \nothing \\ + \microIdTwo _{i} & = & \nothing \\ + \microTotalSize _{i} & = & \nothing or \alreadySet \\ + \end{array} \right. +\] diff --git a/mmu/instructions/templates/shortands.tex b/mmu/instructions/templates/shortands.tex new file mode 100644 index 0000000..6b9ac3c --- /dev/null +++ b/mmu/instructions/templates/shortands.tex @@ -0,0 +1,49 @@ +\begin{center} + \boxed{% + \text{The shorthand presented below assume that } + \left\{ \begin{array}{lcl} + \isMacro _{i} & = & 1 \\ + \mmuInstFlagXXX _{i} & = & 1 \\ + \end{array} \right. + } +\end{center} +We define the following shorthands. +The first batch is sourced from the macro instruction row: +\[ + \left\{ \begin{array}{lcl} + & \define & \macroSrcId_{i} \\ + & \define & \macroTgtId_{i} \\ + & \define & \macroAuxId_{i} \\ + & \define & \macroSrcOffsetHi_{i} \\ + & \define & \macroSrcOffsetLo_{i} \\ + & \define & \macroTgtOffsetLo_{i} \\ + & \define & \macroSize_{i} \\ + & \define & \macroRefOffset_{i} \\ + & \define & \macroRefSize_{i} \\ + & \define & \macroSuccessBit_{i} \\ + & \define & \macroLimbOne_{i} \\ + & \define & \macroLimbTwo_{i} \\ + & \define & \macroPhase_{i} \\ + & \define & \macroExoSum_{i} \\ + \end{array} \right. +\] +The second batch is sourced from the output columns: +\[ + \left\{ \begin{array}{lcl} + & \define & \ppOutputCol{1}_{i} \\ + & \define & \ppOutputCol{2}_{i} \\ + & \define & \ppOutputCol{3}_{i} \\ + & \define & \ppOutputCol{4}_{i} \\ + & \define & \ppOutputCol{5}_{i} \\ + & \define & \ppOutputCol{6}_{i} \\ + & \define & \ppOutputCol{7}_{i} \\ + & \define & \ppOutputCol{8}_{i} \\ + & \define & \ppOutputCol{9}_{i} \\ + & \define & \ppOutputCol{10}_{i} \\ + & \define & \ppOutputCol{11}_{i} \\ + & \define & \ppOutputCol{12}_{i} \\ + & \define & \ppOutputCol{13}_{i} \\ + & \define & \ppOutputCol{14}_{i} \\ + \end{array} \right. +\] + diff --git a/mmu/intro.tex b/mmu/intro.tex new file mode 100644 index 0000000..9ca4739 --- /dev/null +++ b/mmu/intro.tex @@ -0,0 +1,2 @@ +The \mmuMod{} does not in and of itself perform the memory operations requested by the \hubMod{}. +This task befalls the \mmioMod{} module. diff --git a/mmu/lookups/_inputs.tex b/mmu/lookups/_inputs.tex new file mode 100644 index 0000000..d7aaf63 --- /dev/null +++ b/mmu/lookups/_inputs.tex @@ -0,0 +1,3 @@ +\newpage \subsection{Lookup to the \eucMod{} module} \label{mmu: lookups: euc} \input{lookups/euc} +\newpage \subsection{Lookup to the \wcpMod{} module} \label{mmu: lookups: wcp} \input{lookups/wcp} +\newpage \subsection{Lookup to the \mmioMod{} module} \label{mmu: lookups: mmio} \input{lookups/mmio} diff --git a/mmu/lookups/euc.tex b/mmu/lookups/euc.tex new file mode 100644 index 0000000..ab631b6 --- /dev/null +++ b/mmu/lookups/euc.tex @@ -0,0 +1,26 @@ +The lookup to the $\eucMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isPreprocessing{} \cdot \ppEucFlag{}$ + \item[\underline{Source columns:}] from the \mmuMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item \ppEucA{} + \item \ppEucB{} + \item \ppEucQuot{} + \item \ppEucRem{} + \item \ppEucCeil{} + \item 1 + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \eucMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item \dividend{} + \item \divisor{} + \item \quotient{} + \item \remainder{} + \item \ceiling{} + \item \done{} + \end{enumerate} + \end{multicols} +\end{description} diff --git a/mmu/lookups/mmio.tex b/mmu/lookups/mmio.tex new file mode 100644 index 0000000..428b245 --- /dev/null +++ b/mmu/lookups/mmio.tex @@ -0,0 +1,20 @@ +The lookup to the $\mmioMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] none required; + \item[\underline{Source columns:}] from the \mmuMod{} module: + \begin{multicols}{2} + \begin{enumerate} + \item $\microStamp_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \mmioMod{} module: + \begin{multicols}{2} + \begin{enumerate} + \item $\mmioStamp_{j}$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +The present lookup only makes sure that the \mmioMod{} deals with all instructions required by the \mmuMod{} but doesn't provide the parameters of said instructions. +There is a separate lookup in the opposite direction to recover the details of said \mmioMod{} instructions, see section~(\ref{mmio: lookups: mmu}). +This opposite direction lookup also ensures that the \mmioMod{} doesn't perform \textbf{more} instructions than those requested by the \mmuMod{}. diff --git a/mmu/lookups/wcp.tex b/mmu/lookups/wcp.tex new file mode 100644 index 0000000..d996eb3 --- /dev/null +++ b/mmu/lookups/wcp.tex @@ -0,0 +1,26 @@ +The lookup to the $\wcpMod$ is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\isPreprocessing{} \cdot \ppEucFlag{}$ + \item[\underline{Source columns:}] from the \mmuMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item \ppWcpArgOneHi{} + \item \ppWcpArgOneLo{} + \item 0 + \item \ppWcpArgTwoLo{} + \item \ppWcpRes{} + \item \ppWcpInst{} + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \wcpMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/mmu/lua/blake_r_f_input_transfer.lua.tex b/mmu/lua/blake_r_f_input_transfer.lua.tex new file mode 100644 index 0000000..c6ffeb3 --- /dev/null +++ b/mmu/lua/blake_r_f_input_transfer.lua.tex @@ -0,0 +1,77 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +We descrive the modus operandi of the following instruction: + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; MMU_INST_blakeParameterExtraction ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +What we call ``Blake parameters'' are the rounds parameter +* rounds = I_d[0..4] +* f = I_d[212] +The goal of the present MMU instruction is thus to extract +these parameters from RAM and to send them off to the +BLAKE_DATA module in case the call to the precompile is +successful. + +Its inputs are the following: +- SRC_ID = cn +- TGT_ID = 1 + HUB_ +- SRC_OFF = cdo +- VAL_HI = rounds +- VAL_LO = f +- SUCCESS_BIT = SCEN/PRC_SUCCESS + +NOTE. the above is the reason why we can't rely on the VAL_HI/LO +columns solely to transfer concrete data from HUB to RAM and why +a dedicated SUCCESS_BIT column makes sense in the lookup. + +This single MMU instruction splits into 2 MMIO instructions. +- one to extract rounds; putting EXO_BLAKE🏴 := SUCCESS_BIT; +- one to extract f; putting EXO_BLAKE🏴 := SUCCESS_BIT; + +# For "rounds" + +We need to compute +- cdo = 16 • q + r + +The only subtle point is whether +- r + (4 - 1) > 15 ? + - if yes: then [2 => 1 partial, from ∅] with appropriate params + - if yes: then [1 => 1 partiao, from ∅] with appropriate params + +Set some phase number for the rounds parameter and send the output of the above limb surgery to the EXO module. +Also set this parameter to the value of val_hi of the HUB instruction. + + +# For "f" + +We need to compute +- cdo + (213 - 1) = 16 • Q + R + +The associated MMIO instruction is always the same: +- [1 => 1 partial, from ∅] with appropriate params. + +Set some phase number for the "f" parameter and send the output of the above limb surgery to the EXO module. +Also set this parameter to the value of val_lo of the HUB instruction. +\end{verbatim} +\end{document} diff --git a/mmu/lua/extraction.lua.tex b/mmu/lua/extraction.lua.tex new file mode 100644 index 0000000..132516e --- /dev/null +++ b/mmu/lua/extraction.lua.tex @@ -0,0 +1,64 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +Plateau bit ⟦1⟧ Plateau bit ⟦2⟧ +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛ ⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ + + SRC 1 (UNCHANGED) SRC 2 (UNCHANGED) +🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩 🟦🟦🟦🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 + + +----------------------------------------------------------------------- + + 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 + TGT OLD + 🏽🏽🏽🏽🏽🏽🏽🟩🟩🟩🟩🟩🟦🟦🟦🏽 + TGT NEW + + ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛ Plateau bit ⟦3⟧ + ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛ Plateau bit ⟦4⟧ +\end{verbatim} + +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛ Plateau bit ⟦1⟧ +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛ Plateau bit ⟦2⟧ + + SRC 1 (UNCHANGED) +🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🏻🏻 + + +---------------------------------------------------- + + +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ + TGT (= 0) +⬜🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ + TGT NEW + +⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ Plateau bit ⟦3⟧ +\end{verbatim} + +\end{document} + diff --git a/mmu/lua/interface.lua.tex b/mmu/lua/interface.lua.tex new file mode 100644 index 0000000..78ddd1f --- /dev/null +++ b/mmu/lua/interface.lua.tex @@ -0,0 +1,125 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + ██\ ██\ ██\ ██\ ███████\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██\ ██████\ + ██ | ██ |██ | ██ |██ __██\ ██ | ███\ ███ |███\ ███ |██ | ██ | \__| ██ | ██ __██\ + ██ | ██ |██ | ██ |██ | ██ | ██ / ████\ ████ |████\ ████ |██ | ██ | ██\ ███████\ ██████\ ██████\ ██████\ ██ / \__|██████\ ███████\ ██████\ + ████████ |██ | ██ |███████\ | ██ / ██\██\██ ██ |██\██\██ ██ |██ | ██ | ██ |██ __██\\_██ _| ██ __██\ ██ __██\ ████\ \____██\ ██ _____|██ __██\ + ██ __██ |██ | ██ |██ __██\ ██ / ██ \███ ██ |██ \███ ██ |██ | ██ | ██ |██ | ██ | ██ | ████████ |██ | \__|██ _| ███████ |██ / ████████ | + ██ | ██ |██ | ██ |██ | ██ | ██ / ██ |\█ /██ |██ |\█ /██ |██ | ██ | ██ |██ | ██ | ██ |██\ ██ ____|██ | ██ | ██ __██ |██ | ██ ____| + ██ | ██ |\██████ |███████ | ██ / ██ | \_/ ██ |██ | \_/ ██ |\██████ | ██ |██ | ██ | \████ |\███████\ ██ | ██ | \███████ |\███████\ \███████\ + \__| \__| \______/ \_______/ \__/ \__| \__|\__| \__| \______/ \__|\__| \__| \____/ \_______|\__| \__| \_______| \_______| \_______| + + + +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_xxx⟧ | EVM instruction / use case | SRC_ID | TGT_ID | AUX_ID | SRC_OFF_HI | SCR_OFF_LO | TGT_OFF_LO | SIZE | REF_OFF | REF_SIZE | SUCCESS_BIT | LIMB_1 | LIMB_2 | PHASE | EXO_SUM | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_mload⟧ | MLOAD | CN | | | | µ[0]_lo | | | | | | ⟦ π ⟧ | ⟦ π ⟧ | | | +| | MODEXP_extract_raw_lead | CN | | | | cdo + 96 + bbs | | | | | | ⟦ π ⟧ raw_lead_hi | ⟦ π ⟧ raw_lead_lo | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_mstore⟧ | MSTORE | | CN | | | | µ[0]_lo | | | | | µ[1]_hi | µ[1]_lo | | | +| | SHA2-256_transfer_trivial_res | | 1 + HUB_ | | | | 0 | | | | | SHA2-256(( ))_hi | SHA2-256(( ))_lo | | | +| | RIPEMD-160_transfer_trivial_res | | 1 + HUB_ | | | | 0 | | | | | RIPEMD-160(( ))_hi | RIPEMD-160(( ))_lo | | | +| | ECPAIRING_transfer_trivial_res | | 1 + HUB_ | | | | 0 | | | | | 0x 00 .. 00 00 | 0x 00 ... 00 01 | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_mstore8⟧ | MSTORE8 | | CN | | | | µ[0]_lo | | | | | µ[1]_hi | µ[1]_lo | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_invalidCodePrefix⟧ | (RETURN in dep. cn. w/ size ≠ 0) | CN | | | | µ[0]_lo | | | | | ⟦ π ⟧ lead_is_0xEF | | | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_rightPaddedWordExtraction⟧ | CALLDATALOAD (non root context) | CALLER_CN | | | | µ[0]_lo | | | cdo | cds | | ⟦ π ⟧ | ⟦ π ⟧ | | | +| | MODEXP_extract_byte_size_param | CN | | | | x_off = 0, 32, 64 | | | cdo | cds | | ⟦ π ⟧ xbs_hi | ⟦ π ⟧ xbs_lo | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_ramToExoWithPadding⟧ | | | | | | | | | | | | | | | | +| | SHA3 | CN | | 1 + HUB_ | | µ[0]_lo | | µ[1]_lo | | µ[1]_lo | | | | (set by MMIO) | . ⟦1 << kec⟧ | +| | CREATE2 (failure condition) | CN | | 1 + HUB_ | | µ[0]_lo | | µ[1]_lo | | µ[1]_lo | | | | (set by MMIO) | . ⟦1 << kec⟧ | +| | CREATE2 | CN | CFI | 1 + HUB_ | | µ[1]_lo | | µ[2]_lo | | µ[2]_lo | | | | (set by MMIO) | ⟦1 << rom⟧ + ⟦1 << kec⟧ | +| | CREATE | CN | CFI | | | µ[1]_lo | | µ[2]_lo | | µ[2]_lo | | | | | ⟦1 << rom⟧ | +| | RETURN (from deployment) | CN | CFI | 1 + HUB_ | | µ[0]_lo | | µ[1]_lo | | µ[1]_lo | | | | (set by MMIO) | ⟦1 << rom⟧ + ⟦1 << kec⟧ | +| (don't actually pad !) | LOG0-4 | CN | ABS_LOG_NUM | | | µ[0]_lo | | µ[1]_lo | | µ[1]_lo | | | | | ⟦1 << log⟧ | +| | SHA2-256_extract | CN | 1 + HUB_ | | | cdo | | cds | | cds | | | | Φ_sha2_data | ⟦1 << ripsha⟧ | +| | RIPEMD-160_extract | CN | 1 + HUB_ | | | cdo | | cds | | cds | | | | Φ_ripemd_data | ⟦1 << ripsha⟧ | +| | ECPAIRING_extract | CN | 1 + HUB_ | | | cdo | | cds = 192 • k | | cds = 192 • k | ⟦ π ⟧ well_formed | | | Φ_ecpairing_data | ⟦1 << ecdata⟧ | +| | BLAKE2f_h_m_t_extract | CN | 1 + HUB_ | | | cdo + 4 | | 208 | | 208 | | | | Φ_blake_data | ⟦1 << blake⟧ | +| | | | | | | | | | | | | | | | | +| | ECRECOVER_extract | CN | 1 + HUB_ | | | cdo | | cds | | 128 | ⟦ π ⟧ recovery_success | | | Φ_ecrec_data | ⟦1 << ecdata⟧ | +| (can actually pad !) | ECADD_extract | CN | 1 + HUB_ | | | cdo | | cds | | 128 | ⟦ π ⟧ well_formed | | | Φ_ecadd_data | ⟦1 << ecdata⟧ | +| | ECMUL_extract | CN | 1 + HUB_ | | | cdo | | cds | | 96 | ⟦ π ⟧ well_formed | | | Φ_ecmul_data | ⟦1 << ecdata⟧ | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_exoToRamTransplants⟧ | ECRECOVER_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 32 | | | | | | Φ_ecrec_res | ⟦1 << ecdata⟧ | +| | SHA2-256_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 32 | | | | | | Φ_sha2_res | ⟦1 << ripsha⟧ | +| | RIPEMD-160_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 32 | | | | | | Φ_ripemd_res | ⟦1 << ripsha⟧ | +| | MODEXP_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 512 | | | | | | Φ_modexp_res | ⟦1 << modexp⟧ | +| | ECADD_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 64 | | | | | | Φ_ecadd_res | ⟦1 << ecdata⟧ | +| | ECMUL_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 64 | | | | | | Φ_ecmul_res | ⟦1 << ecdata⟧ | +| | ECPAIRING_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 32 | | | | | | Φ_ecpairing_res | ⟦1 << ecdata⟧ | +| | BLAKE2f_transfer_res | 1 + HUB_ | 1 + HUB_ | | | | | 64 | | | | | | Φ_blake_res | ⟦1 << blake⟧ | +| | | | | | | | | | | | | | | | | +| | TRANSACTION_CALL_DATA_transfer | ABS_TX_NUM | HUB_ | | | | | txcd_size | | | | | | Φ_txcd | ⟦1 << rlp_txn⟧ | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_ramToRamSansPadding⟧ | REVERT | CN | CALLER_CN | | | µ[0]_lo | | µ[1]_lo | r@o | r@c | | | | | | +| | RETURN_fromMessageCall | CN | CALLER_CN | | | µ[0]_lo | | µ[1]_lo | r@o | r@c | | | | | | +| | ECRECOVER_partial_copy | 1 + HUB_ | CN | | | 0 | | 32 | r@o | r@c | | | | | | +| | SHA2-256_partial_copy | 1 + HUB_ | CN | | | 0 | | 32 | r@o | r@c | | | | | | +| | RIPEMD-160_partial_copy | 1 + HUB_ | CN | | | 0 | | 32 | r@o | r@c | | | | | | +| | IDENTITY_extract | CN | 1 + HUB_ | | | cdo | | cds | 0 | cds | | | | | | +| | IDENTITY_partial_copy | 1 + HUB_ | CN | | | 0 | | cds | r@o | r@c | | | | | | +| | MODEXP_partial_copy | 1 + HUB_ | CN | | | 512 - mbs | | mbs | r@o | r@c | | | | | | +| | ECADD_partial_copy | 1 + HUB_ | CN | | | 0 | | 64 | r@o | r@c | | | | | | +| | ECMUL_partial_copy | 1 + HUB_ | CN | | | 0 | | 64 | r@o | r@c | | | | | | +| | ECPAIRING_partial_copy | 1 + HUB_ | CN | | | 0 | | 32 | r@o | r@c | | | | | | +| | BLAKE2f_partial_copy | 1 + HUB_ | CN | | | 0 | | 64 | r@o | r@c | | | | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_ISNT_anyToRamWithPadding⟧ | CALLDATACOPY | CALL_DATA_CN | CN | | µ[1]_hi | µ[1]_lo | µ[0]_lo | µ[2]_lo | cdo | cds | | | | | 0 | +| | RETURNDATACOPY | RETURNER_CN | CN | | µ[1]_hi | µ[1]_lo | µ[0]_lo | µ[2]_lo | rdo | rds | | | | | 0 | +| | CODECOPY | CFI | CN | | µ[1]_hi | µ[1]_lo | µ[0]_lo | µ[2]_lo | 0 | codesize | | | | | ⟦1 << rom⟧ | +| | EXTCODECOPY | CFI | CN | | µ[2]_hi | µ[2]_lo | µ[1]_lo | µ[3]_lo | 0 | codesize | | | | | ⟦1 << rom⟧ | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_modexpZero⟧ | MODEXP_zero_base | | 1 + HUB_ | | | | | | | | | | | Φ_base | ⟦1 << modexp⟧ | +| | MODEXP_zero_exponent | | 1 + HUB_ | | | | | | | | | | | Φ_exponent | ⟦1 << modexp⟧ | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_modexpData⟧ | MODEXP_extract_base | CN | 1 + HUB_ | | | 96 | | bbs | cdo | cds | | | | Φ_base | ⟦1 << modexp⟧ | +| | MODEXP_extract_exponent | CN | 1 + HUB_ | | | 96 + bbs | | ebs | cdo | cds | | | | Φ_exponent | ⟦1 << modexp⟧ | +| | MODEXP_extract_modulus | CN | 1 + HUB_ | | | 96 + bbs + ebs | | mbs | cdo | cds | | | | Φ_modulus | ⟦1 << modexp⟧ | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| +| ⟦MMU_INST_blake⟧ | BLAKE2f_extract_r_and_f | CN | 1 + HUB_ | | | cdo | | | | | ⟦ π ⟧ blake_b_success | ⟦ π ⟧ rounds | ⟦ π ⟧ f | | | +|--------------------------------------+----------------------------------+--------------+-------------+-----------+------------+-------------------+------------+---------------+---------+---------------+------------------------+--------------------+--------------------+------------------+----------------------------| + +COMMENTS: +* for the nontrivial data transfer of + - SHA3 [see comment below] + - RETURN (deployments) + - LOG0-4 [see comment below] + - CREATE + - CREATE2 + - SHA2-256 + - RIPEMD-160 + - ECPAIRING + we must also communicate the SIZE to the target data module; for SHA3 the SIZE is available in the HASH_INFO module; for LOG0-4 the SIZE is available in the LOG_INFO module; yet we may add these values anyways for greater uniformity; + +* for the ⟦MMU_INST_blake⟧ instruction the MMU module sets its own EXO_SUM and PHASE depending on the SUCCESS_BIT. + - if SUCCESS_BIT = 0: + - EXO_SUM ≡ 0 + - PHASE ≡ 0 + - if SUCCESS_BIT = 1: + - EXO_SUM ≡ ⟦1 << blake⟧ + - PHASE ≡ Φ_blake_params + +\end{verbatim} +\end{document} diff --git a/mmu/lua/left_right_padded_extraction.lua.tex b/mmu/lua/left_right_padded_extraction.lua.tex new file mode 100644 index 0000000..41b06dc --- /dev/null +++ b/mmu/lua/left_right_padded_extraction.lua.tex @@ -0,0 +1,62 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +Plateau bit ⟦1⟧ Plateau bit ⟦2⟧ +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛ ⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ + + SRC 1 (UNCHANGED) SRC 2 (UNCHANGED) +🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩 🟦🟦🟦🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 + + +----------------------------------------------------------------------- + + ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ + TGT OLD (= 0) + ⬜⬜⬜⬜⬜⬜⬜🟩🟩🟩🟩🟩🟦🟦🟦⬜ + TGT NEW + + ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛ Plateau bit ⟦3⟧ + ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛ Plateau bit ⟦4⟧ +\end{verbatim} + +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛ Plateau bit ⟦1⟧ +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛ Plateau bit ⟦2⟧ + + SRC 1 (UNCHANGED) +🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🏻🏻 + + +---------------------------------------------------- + + +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ + TGT (= 0) +⬜🟩🟩🟩🟩🟩⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ + TGT NEW + +⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ Plateau bit ⟦3⟧ +\end{verbatim} + +\end{document} diff --git a/mmu/lua/modexp_byte_size_parameter_extraction.lua.tex b/mmu/lua/modexp_byte_size_parameter_extraction.lua.tex new file mode 100644 index 0000000..fc432dd --- /dev/null +++ b/mmu/lua/modexp_byte_size_parameter_extraction.lua.tex @@ -0,0 +1,68 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +We describe the method by which MODEXP byte size paramaeters +will be extracted from RAM. We will use the same workflow as +for a CALLDATALOAD targeting a non root context. + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; MMU_INST_potentiallyRightPaddedEvmWordExtraction ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +This will be the underlying instruction for: +- CALLDATALOAD (in a non root context) +- MODEXP byte size parameter extractions + + +# The CALLDATALOAD_nonRoot case + + +- SRC_ID = caller_cn +- SRC_OFF = offset <== relative pointer µ[0] +- TGT_ID = ∅ +- REF_OFF = cdo (read off of context data) +- REF_SIZE = cds (read off of context data) +- VAL_HI = xbs_hi (HUB prediction) +- VAL_LO = xbs_lo (HUB prediction) + + +# The "MODEXP byte size parameter extraction" case + + +- SRC_ID = cn +- SRC_OFF = x_off <== relative pointer +- TGT_ID = ∅ +- REF_OFF = cdo (from the underlying CALL) +- REF_SIZE = cds (from the underlying CALL) +- VAL_HI = rel. val. (HUB prediction) +- VAL_LO = rel. val. (HUB prediction) + +Above: x = b, e, m (base, exponent, modulus resp.) + + +|--------+---+----+----| +| x | b | e | m | +|--------+---+----+----| +| x_off | 0 | 32 | 64 | +|--------+---+----+----| + +\end{verbatim} +\end{document} + diff --git a/mmu/lua/precompile_ecRecAddMul_padded_data_extraction.lua.tex b/mmu/lua/precompile_ecRecAddMul_padded_data_extraction.lua.tex new file mode 100644 index 0000000..91fbdbd --- /dev/null +++ b/mmu/lua/precompile_ecRecAddMul_padded_data_extraction.lua.tex @@ -0,0 +1,98 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +We describe a MMU instruction called + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; MMU_INST_rightPaddedPrecompileDataExtraction ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + + +This MMU instruction will be used to extract the data for +- ECRECOVER +- ECADD +- ECMUL + +The inputs of this instruction are +- ID_SRC = cn +- ID_TGT = 1 + HUB_ +- REF_SIZE +- SRC_OFFSET = cdo +- SIZE = cds +- PHASE_NUMBER +- Q_0 + +The Q_0 parameter will be set by the HUB and is either 8 or 6 depending on the precompile. + +NOTE. it is sufficient to send either the REFERENCE_SIZE or Q_0 as + + REFERENCE_SIZE = 16 • Q_0 + +NOTE. the reference size REF_SIZE will be set by the HUB in terms of the precompile +according to the table below: + +|------------+----------------+-----| +| precompile | reference size | Q_0 | +|------------+----------------+----:| +| ECRECOVER | 128 | 8 | +| ECADD | 128 | 8 | +| ECmul | 96 | 6 | +|------------+----------------+-----| + +The MMU needs to perform the following: +- cdo = 16 • q + r +- cds = 16 • Q + R +- r = 0 ? + * false (0) case: Q times [Ram to Exo limb transplant] + * true (1) case: Q times [2 => 1 Ram to Exo surgery] +- R = 0 ? + * may determine whether the boundary between data and padding is messy + * if R ≠ 0 then there may be some paddedExoFromXXX (unless Q ≥ 8) +- Q = 0 ? + * if Q = 0 then R ≠ 0 and we will jump straight into the boundary + case separating padding from nonpadding; + * if Q ≠ 0 there will be a full limb transfer initially + * if r ≠ 0 the do Q many [2 => 1 Exo from Ram] + * if r ≠ 0 the do Q many [Ram to Exo Transplant] +- if R ≠ 0: + - r + (R - 1) < 16 ? + * determine whether the bounardy term between data and padding + can be done with + * false (0) case: paddedExoFromTwo + * true (1) case: paddedExoFromOne +- Anser the question whether + - ECRECOVER and ECADD: + - Q = 0: + - r + (cds - 1) > 15: + - no: paddedExoFromOne + - yes: paddedExoFromTwo + - 0 < Q < Q_0 + - Q ≥ Q_0: + - Q_0 times the same instruction + * if R = 0: [Ram to Exo limb transplant] + * if R ≠ 0: [2 => 1 Ram to Exo] + +Full padding: + * sissi [Q < 7] ∨ ([Q = 7] ∧ [R = 0]) + * sissi ([Q ≤ 7] ∧ [R = 0]) ∨ ([Q ≤ 6] ∧ [R ≠ 0]) +\end{verbatim} +\end{document} diff --git a/mmu/lua/precompile_result_transfer.lua.tex b/mmu/lua/precompile_result_transfer.lua.tex new file mode 100644 index 0000000..a50b049 --- /dev/null +++ b/mmu/lua/precompile_result_transfer.lua.tex @@ -0,0 +1,70 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +We will specify a + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; MMU_INST_transferPrecompileResultsToDedicatedRam ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +Precompiles that comes into play for the following precompiles: +- ECRECOVER +- SHA2-256 (nonempty input data case) +- RIPEMD-160 (nonempty input data case) +- MODEXP +- ECADD +- ECMUL +- ECPAIRING (nonempty input data case) +- BLAKE + +In other words: all precompiles other than IDENTITY. + +NOTE. the IDENTITY precompile tansfers its call data to the (ficitious) +used to house it (with context number 1 + HUB_ ) in the same way that +data is transferred from RAM to RAM under a RETURN instruction. + +It will take as inputs the following: + +- ID_SRC = 1 + HUB_ +- ID_TGT = 1 + HUB_ +- NUMBER_OF_LIMBS_TO_TRANSFER +- PHASE_NUMBER (?) + +NUMBER_OF_LIMBS_TO_TRANSFER (stored in one of the size columns) whose value depends purely on the precompile at hand: + +|------------+-----------------------------+----------------------| +| precompile | NUMBER_OF_LIMBS_TO_TRANSFER | output size in bytes | +|------------+-----------------------------+---------------------:| +| ECRECOVER | 2 | 32 | +| SHA2-256 | 2 | 32 | +| RIPEMD-160 | 2 | 32 | +| MODEXP | 32 | 512 | +| ECADD | 4 | 64 | +| ECMUL | 4 | 64 | +| ECPAIRING | 2 | 32 | +| BLAKE | 4 | 64 | +|------------+-----------------------------+----------------------| + +NOTE. For MODEXP we will always transfer 512 bytes where the first 512 - mbs bytes are zero (or should be zero) and the last mbs bytes occupy the actual return data. +The HUB module (and the current context in particular) remember the relevant rdo (512 - mbs) and rds (mbs) + +The phase number could be removed if we make an effort to have all the results stored under the same phase number in all of the precompile modules. +\end{verbatim} +\end{document} diff --git a/mmu/lua/return_invalid_code_prefix_testing.lua.tex b/mmu/lua/return_invalid_code_prefix_testing.lua.tex new file mode 100644 index 0000000..4ddb1bf --- /dev/null +++ b/mmu/lua/return_invalid_code_prefix_testing.lua.tex @@ -0,0 +1,52 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; +;; MMU_INST_extractAndVetLeadingByteOfCodeToDeploy ;; +;; ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +Inputs: +- SRC_ID : cn +- SRC_OFF : µ[0]_lo +- TGT_ID : ∅ +- VAL_HI : ∅ +- VAL_LO : [lead] +- SUCCCESS_BIT : [lead ≠ 0xEF] + + +This single MMU instruction gives rise to a single MMIO instruction which +HUB: +- the HUB predicts the leading byte [lead] and the associated SUCCESS_BIT ≡ [lead ≠ 0xEF] +MMU: +- the MMU then performs a CALL to WCP with the EQ instruction comparing the extracted byte to 0xEF +- the result of the comparison is then confronted with SUCCESS_BIT as predicted by the HUB +- the MMU sends an instruction to the MMIO which extracts the leading byte of the code to deploy +- +MMIO: +- the MMIO extracts said byte and confronts the value to VAL_LO +- remembers the result and sends it back to the MMU + +NOTE. We DO need 3 different columns VAL_HI, VAL_LO, SUCCESS_BIT; reason being the BLAKE_extract_r_and_f +MMU instruction requires these fields +\end{verbatim} +\end{document} diff --git a/mmu/lua/specialized/isolate_chunk.lua.tex b/mmu/lua/specialized/isolate_chunk.lua.tex new file mode 100644 index 0000000..6d8b37d --- /dev/null +++ b/mmu/lua/specialized/isolate_chunk.lua.tex @@ -0,0 +1,50 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +X ≡ ⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), c = 5 +Y ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛ satisfies Plateau(Y, c; CT), c = 13 + +B ≡ 🟦🟦🟦🟦🟦🟨🟩🟩🟩🟩🟩🟩🟩🟦🟦🟦 byte column + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column + +Evolution of ACC over the counter-cycle of isolateChunk: +======================================================== + +CT = 0: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 1: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 2: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 3: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 4: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 5: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨 +CT = 6: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩 +CT = 7: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩 +CT = 8: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩 +CT = 9: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩 +CT = 10: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩 +CT = 11: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 12: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩🟩 +CT = 13: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩🟩 +CT = 14: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩🟩 +CT = 15: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩🟩 ⇐ extracted chunk +\end{verbatim} + +\end{document} diff --git a/mmu/lua/specialized/isolate_prefix.lua.tex b/mmu/lua/specialized/isolate_prefix.lua.tex new file mode 100644 index 0000000..b1cf90b --- /dev/null +++ b/mmu/lua/specialized/isolate_prefix.lua.tex @@ -0,0 +1,49 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), c = 7 + +B ≡ 🟨🟩🟩🟩🟩🟩🟩🟦🟦🟦🟦🟦🟦🟦🟦🟦 byte column + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column + +Evolution of ACC over the counter-cycle of isolatePrefix: +========================================================= + +CT = 0: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨 +CT = 1: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩 +CT = 2: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩 +CT = 3: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩 +CT = 4: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩 +CT = 5: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩 +CT = 6: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 7: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 8: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 9: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 10: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 11: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 12: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 13: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 14: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 +CT = 15: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩🟩🟩🟩 ⇐ extracted prefix +\end{verbatim} + +\end{document} diff --git a/mmu/lua/specialized/isolate_suffix.lua.tex b/mmu/lua/specialized/isolate_suffix.lua.tex new file mode 100644 index 0000000..dd68bde --- /dev/null +++ b/mmu/lua/specialized/isolate_suffix.lua.tex @@ -0,0 +1,50 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛ satisfies Plateau(X, c; CT), c = 12 + +B ≡ 🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟨🟩🟩🟩 byte column + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column + +Evolution of ACC over the counter-cycle of isolateSuffix: +========================================================= + +CT = 0: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 1: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 2: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 3: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 4: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 5: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 6: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 7: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 8: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 9: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 10: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 11: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ +CT = 12: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨 +CT = 13: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩 +CT = 14: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩 +CT = 15: ACC ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🟨🟩🟩🟩 ⇐ extracted suffix +\end{verbatim} + +\end{document} + diff --git a/mmu/lua/specialized/plateau.lua.tex b/mmu/lua/specialized/plateau.lua.tex new file mode 100644 index 0000000..5e382de --- /dev/null +++ b/mmu/lua/specialized/plateau.lua.tex @@ -0,0 +1,29 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +X ≡ ⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), c = 0 +Y ≡ ⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(Y, c; CT), 0 < c = 5 < 16 +Z ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ satisfies Plateau(Z, c; CT), c ≥ 16 + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +White cells ⬜ represent 0. +Black cells ⬛ represent 1. +\end{verbatim} + +\end{document} diff --git a/mmu/lua/specialized/power_generic.lua.tex b/mmu/lua/specialized/power_generic.lua.tex new file mode 100644 index 0000000..b34354f --- /dev/null +++ b/mmu/lua/specialized/power_generic.lua.tex @@ -0,0 +1,33 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +X ≡ ⬜⬜⬛⬜⬛⬜⬜⬛⬜⬜⬜⬜⬛⬜⬜⬛ generic binary column X + +P ≡ 🟦🟦🟩🟩🟨🟨🟨🟧🟧🟧🟧🟧🟥🟥🟥🟪 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +Where: 🟦 ≡ 256 ^ 0 = 1 ; 🟧 ≡ 256 ^ 3 = ... ; + 🟩 ≡ 256 ^ 1 = 256 ; 🟥 ≡ 256 ^ 4 = ... ; + 🟨 ≡ 256 ^ 2 = 65536 ; 🟪 ≡ 256 ^ 5 = ... ; + +and: ⬜ ≡ 0 ; ⬛ ≡ 1. +\end{verbatim} + +\end{document} + diff --git a/mmu/lua/specialized/power_plateau.lua.tex b/mmu/lua/specialized/power_plateau.lua.tex new file mode 100644 index 0000000..a5dd2da --- /dev/null +++ b/mmu/lua/specialized/power_plateau.lua.tex @@ -0,0 +1,34 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT) + (0 < c = 7 < 16) + +P ≡ 🟦🟦🟦🟦🟦🟦🟦🟩🟨🟧🟥🟪🏿🟫🏽🏻 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +Where: 🟦 ≡ 256 ^ 0 = 1 ; 🟪 ≡ 256 ^ 5 = ... ; + 🟩 ≡ 256 ^ 1 = 256 ; 🏿 ≡ 256 ^ 6 = ... ; + 🟨 ≡ 256 ^ 2 = 65536 ; 🟫 ≡ 256 ^ 7 = ... ; + 🟧 ≡ 256 ^ 3 = ... ; 🏽 ≡ 256 ^ 8 = ... ; + 🟥 ≡ 256 ^ 4 = ... ; 🏻 ≡ 256 ^ 9 = ... ; + +and: ⬜ ≡ 0 ; ⬛ ≡ 1. +\end{verbatim} +\end{document} diff --git a/mmu/lua/specialized/power_test b/mmu/lua/specialized/power_test new file mode 100644 index 0000000..4ee0e5f --- /dev/null +++ b/mmu/lua/specialized/power_test @@ -0,0 +1,148 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + +🟩🟦🟪🟥🟧🟨 +🏿🟫🏽🏻 +🏻🏽🟫🏿 +⬛ +⬜ + + +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜🏻🏽🟫🏿⬛ +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛ +🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏽🟫🏿⬛ +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛ +🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟨🟧🟥🟪🟦 + +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛ satisfies Plateau(Y, c; CT), 0 < c = 13 < 16 + +P ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏽🟫🏿 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +🏻 ≡ 256 ^ 0 = 1 +🏽 ≡ 256 ^ 1 = 256 +🟫 ≡ 256 ^ 2 = ... +🏿 ≡ 256 ^ 3 = ... + +⬜ ≡ 0. +⬛ ≡ 1. + +⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛ +🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟧🟥🟪🟦🟩 + + +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), 0 < c = 9 < 16 + +P ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🟨🟧🟥🟪🟦🟩🟫 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +Where: 🏻 ≡ 256 ^ 0 = 1 ; 🟪 ≡ 256 ^ 4 = ... ; + 🟨 ≡ 256 ^ 1 = 256 ; 🟦 ≡ 256 ^ 5 = ... ; + 🟧 ≡ 256 ^ 2 = ... ; 🟩 ≡ 256 ^ 6 = ... ; + 🟥 ≡ 256 ^ 3 = ... ; 🟫 ≡ 256 ^ 7 = ... ; + +and: ⬜ ≡ 0 ; ⬛ ≡ 1. + + + +P ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏽🟫🏿🟪🟥🟧🟨 satisfies Power(P, X; CT) +P ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🟨🟧🟥🟫🏿🟪🟦🟩🟫 satisfies Power(P, X; CT) +P ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏽🟫🏿🟪🟥🟧🟨 satisfies Power(P, X; CT) +P ≡ 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟨🟧🟥🟪🟦 +P ≡ 🟦🟦🟦🟦🟦🟦🟦🟩🟨🟧🟥🟪🏿🟫🏽🏻 +P ≡ 🟦🟦🟦🟦🟦🟦🟦🟦🟩🟨🟧🟥🏿🟫🏽🏻 + + +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), 0 < c = 13 < 16 + +P ≡ 🟦🟦🟦🟦🟦🟦🟦🟩🟨🟧🟥🟪🏿🟫🏽🏻 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +Where: 🟦 ≡ 256 ^ 0 = 1 ; 🟪 ≡ 256 ^ 5 = ... ; + 🟩 ≡ 256 ^ 1 = 256 ; 🏿 ≡ 256 ^ 6 = ... ; + 🟨 ≡ 256 ^ 2 = 65536 ; 🟫 ≡ 256 ^ 7 = ... ; + 🟧 ≡ 256 ^ 3 = ... ; 🏽 ≡ 256 ^ 8 = ... ; + 🟥 ≡ 256 ^ 4 = ... ; 🏻 ≡ 256 ^ 9 = ... ; + +and: ⬜ ≡ 0 ; ⬛ ≡ 1. + +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), 0 < c = 9 < 16 + +P ≡ 🟦🟦🟦🟦🟦🟦🟦🟦🟦🟩🟨🟧🟥🟫🏽🏻 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +Where: 🟦 ≡ 256 ^ 0 = 1 ; 🟥 ≡ 256 ^ 4 = ... + 🟩 ≡ 256 ^ 1 = 256 ; 🟫 ≡ 256 ^ 7 = ... + 🟨 ≡ 256 ^ 2 = ... ; 🏽 ≡ 256 ^ 8 = ... + 🟧 ≡ 256 ^ 3 = ... ; 🏻 ≡ 256 ^ 9 = ... + + + + +🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟦🟪🟥🟧🟨 +🏻🏻🏻🏻🏻🏻🏽🟫🏿⬛ + + + +X ≡ ⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT), c = 0 +Y ≡ ⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(Y, c; CT), 0 < c = 5 < 16 +Z ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ satisfies Plateau(Z, c; CT), c ≥ 16 + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +White cells ⬜ represent 0. +Black cells ⬛ represent 1. +\end{verbatim} + + +\begin{verbatim} +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT) + (0 < c = 7 < 16) + +P ≡ 🟩🟩🟩🟩🟩🟩🟩🟦🟪🟥🟧🟨🏻🏽🟫🏿 satisfies Power(P, X; CT) + +Where: 🟩 ≡ 256 ^ 0 = 1 ; 🟨 ≡ 256 ^ 5 = ... ; + 🟦 ≡ 256 ^ 1 = 256 ; 🏻 ≡ 256 ^ 6 = ... ; + 🟪 ≡ 256 ^ 2 = 65536 ; 🏽 ≡ 256 ^ 7 = ... ; + 🟥 ≡ 256 ^ 3 = ... ; 🟫 ≡ 256 ^ 8 = ... ; + 🟧 ≡ 256 ^ 4 = ... ; 🏿 ≡ 256 ^ 9 = ... ; + +and: ⬜ ≡ 0 ; ⬛ ≡ 1. +\end{verbatim} + +\begin{verbatim} +X ≡ ⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛ satisfies Plateau(X, c; CT) + (0 < c = 7 < 16) + +P ≡ 🏻🏻🏻🏻🏻🏻🏻🏽🟫🏿🟪🟥🟧🟨🟩🟦 satisfies Power(P, X; CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 + +Where: 🏻 ≡ 256 ^ 0 = 1 ; 🟥 ≡ 256 ^ 5 = ... ; + 🏽 ≡ 256 ^ 1 = 256 ; 🟧 ≡ 256 ^ 6 = ... ; + 🟫 ≡ 256 ^ 2 = 65536 ; 🟨 ≡ 256 ^ 7 = ... ; + 🏿 ≡ 256 ^ 3 = ... ; 🟩 ≡ 256 ^ 8 = ... ; + 🟪 ≡ 256 ^ 4 = ... ; 🟦 ≡ 256 ^ 9 = ... ; + +and: ⬜ ≡ 0 ; ⬛ ≡ 1. +\end{verbatim} +\end{document} diff --git a/mmu/lua/surgical_patterns/[1_Full_to_2].lua.tex b/mmu/lua/surgical_patterns/[1_Full_to_2].lua.tex new file mode 100644 index 0000000..193238f --- /dev/null +++ b/mmu/lua/surgical_patterns/[1_Full_to_2].lua.tex @@ -0,0 +1,40 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column +⟦2⟧ ≡ ⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ + +S ≡ 🟩🟩🟩🟩🟩🟩🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦 + + + +T1 ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 ≡ T2 + + ↧ ↧ + +T1_new ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🟩 🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🏻🏻🏻🏻🏻🏻 ≡ T2_new + +⟦1⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛ +\end{verbatim} + +\end{document} + + diff --git a/mmu/lua/surgical_patterns/[1_Partial_to_1].lua.tex b/mmu/lua/surgical_patterns/[1_Partial_to_1].lua.tex new file mode 100644 index 0000000..b90e8b6 --- /dev/null +++ b/mmu/lua/surgical_patterns/[1_Partial_to_1].lua.tex @@ -0,0 +1,40 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column +⟦3⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦3⟧, SM , CT) +⟦4⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛ s.t. Plateau(⟦4⟧, SM + SIZE, CT) + +S ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🏻🏻 + + + +T ≡ 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 + + ↧ + +T_new ≡ 🏽🏽🟩🟩🟩🟩🟩🏽🏽🏽🏽🏽🏽🏽🏽🏽 + +⟦1⟧ ≡ ⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦1⟧, TM , CT) +⟦2⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦2⟧, TM + SIZE, CT) +\end{verbatim} + +\end{document} diff --git a/mmu/lua/surgical_patterns/[1_Partial_to_2].lua.tex b/mmu/lua/surgical_patterns/[1_Partial_to_2].lua.tex new file mode 100644 index 0000000..2ba40e0 --- /dev/null +++ b/mmu/lua/surgical_patterns/[1_Partial_to_2].lua.tex @@ -0,0 +1,42 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column +⟦3⟧ ≡ ⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦3⟧, SM , CT) +⟦4⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛ s.t. Plateau(⟦4⟧, SM + 16 - T1M, CT) +⟦5⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛ s.t. Plateau(⟦5⟧, SM + SIZE , CT) + +S ≡ 🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🟩🟦🟦🟦🏻🏻 + + + +T1 ≡ 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 ≡ T2 + + ↧ ↧ + +T1_new ≡ 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🟩🟩🟩🟩🟩🟩 🟦🟦🟦🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 ≡ T2_new + +⟦1⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛ ⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ ≡ ⟦2⟧ + +⟦1⟧ s.t. Plateau(⟦1⟧, T1M, CT) ⟦2⟧ s.t. Plateau(⟦2⟧, T1M + SIZE - 16, CT) +\end{verbatim} + +\end{document} diff --git a/mmu/lua/surgical_patterns/[1_to_1_Padded].lua.tex b/mmu/lua/surgical_patterns/[1_to_1_Padded].lua.tex new file mode 100644 index 0000000..69213b4 --- /dev/null +++ b/mmu/lua/surgical_patterns/[1_to_1_Padded].lua.tex @@ -0,0 +1,36 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +⟦1⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦1⟧, SM, CT) +⟦2⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛ s.t. Plateau(⟦2⟧, SM + SIZE, CT) + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column + +S ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🏻🏻🏻 + + + +T ≡ 🟩🟩🟩⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜ + +⟦3⟧ ≡ ⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦3⟧, SIZE, CT) +\end{verbatim} + +\end{document} diff --git a/mmu/lua/surgical_patterns/[2_to_1_Padded].lua.tex b/mmu/lua/surgical_patterns/[2_to_1_Padded].lua.tex new file mode 100644 index 0000000..7982a81 --- /dev/null +++ b/mmu/lua/surgical_patterns/[2_to_1_Padded].lua.tex @@ -0,0 +1,35 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column +⟦1⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛ ⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ ≡ ⟦2⟧ + +S1 ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🟩 🟦🟦🟦🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 ≡ S2 + + + +T ≡ 🟩🟩🟩🟩🟩🟩🟦🟦🟦⬜⬜⬜⬜⬜⬜⬜ + +⟦3⟧ ≡ ⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ +⟦4⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛ +\end{verbatim} + +\end{document} diff --git a/mmu/lua/surgical_patterns/byteSwap.lua.tex b/mmu/lua/surgical_patterns/byteSwap.lua.tex new file mode 100644 index 0000000..514af12 --- /dev/null +++ b/mmu/lua/surgical_patterns/byteSwap.lua.tex @@ -0,0 +1,37 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +SB ≡ 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩 byte column + + + +T ≡ 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 + + ↧ + +T_new ≡ 🏽🏽🏽🏽🏽🟩🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column +⟦1⟧ ≡ ⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦1⟧, TM ; CT) +⟦2⟧ ≡ ⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦2⟧, TM + 1; CT) +\end{verbatim} + +\end{document} diff --git a/mmu/lua/surgical_patterns/excision.lua.tex b/mmu/lua/surgical_patterns/excision.lua.tex new file mode 100644 index 0000000..1f9bb17 --- /dev/null +++ b/mmu/lua/surgical_patterns/excision.lua.tex @@ -0,0 +1,33 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +White cells ⬜ represent 0. +Black cells ⬛ represent 1. + +CT ≡ 0 1 2 3 4 5 6 7 ... 15 counter column +⟦1⟧ ≡ ⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛ s.t. Plateau(⟦1⟧, TM, CT) +⟦2⟧ ≡ ⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛⬛⬛⬛ s.t. Plateau(⟦2⟧ TM + SIZE, CT) + +S ≡ 🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩🏻🏻🏻🏻🏻 + + ↧ + +S_new ≡ 🏻🏻🏻🏻🏻🏻⬜⬜⬜⬜⬜🏻🏻🏻🏻🏻 +\end{verbatim} + +\end{document} diff --git a/mmu/lua/symbols b/mmu/lua/symbols new file mode 100644 index 0000000..df892c1 --- /dev/null +++ b/mmu/lua/symbols @@ -0,0 +1,100 @@ + +___________ ̄ +|||||||| +╳ ╳ ╳ ⏐╳ ╳ ╳⏐| +a ___________ +▯ ▯ ▯ ▯|▯|▯▯▯▮▮▮▮▮▮ +a a a a a a a + ̄ + +▧ ▧ ▧ ▧ ▧ ▧ ▧ ▧ ▧ ▧ ▧ ▧ +▨ +▨ +▨ +▨ +▥ ▥ ▥ ▥ ▥ ▥ ▥ ▤ ▤ ▤ ▤ ▤ +□ □ □ □ □ □ □ ◻ ◻ ◻ □ □ □ + +◽◽◽◽◽◽◽◼ ◼ ◼ ◼ ◼ ◼ ◻ ◻ ◻ ◻ ◻ □ □ □ ◼ ◼ ◼ ◼ ◼ ◼ ◼ +░ ░ ░◻ ◻ ◻ ◻ ◻ ░░░ ░ ░ ░ ░ ░ ░ ▯ ▯ ▒ ▒ ▒ ▓ ▓ ▓ + + +░▒▓█ + +🟥 +🟧 +🟨 +🟩 +🟦 +🟪 +🏿🟫🏽🏻 +⬛ +⬜ + + +🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 + + + 🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫 + 🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪 + + + + +🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟩🟩🟩🟩🟩 🟦🟦🟦🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 + + + 🟫🟫🟫🟫🟫🟫🟩🟩🟩🟩🟩🟦🟦🟦🟫🟫 + + SOURCE 1 SOURCE 2 UNCHANGED UNCHANGED +🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟩🟩🟩🟩🟩 🟦🟦🟦🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 + + + 🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪 🟪🟪🟪🟪🟪🟪🟩🟩🟩🟩🟩🟦🟦🟦🟪🟪 + TARGET TARGET NEW + + SOURCE 1 SOURCE 2 +🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 + + + 🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪 + TARGET + + UNCHANGED UNCHANGED +🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟩🟩🟩🟩🟩 🟦🟦🟦🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 + + + 🟪🟪🟪🟪🟪🟪🟩🟩🟩🟩🟩🟦🟦🟦🟪🟪 + TARGET NEW + + + + SOURCE 1 SOURCE 2 +🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 + + + 🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫 + TARGET + + UNCHANGED UNCHANGED +🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🟩🟩🟩🟩🟩 🟦🟦🟦🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻🏻 + + + 🟫🟫🟫🟫🟫🟫🟩🟩🟩🟩🟩🟦🟦🟦🟫🟫 + TARGET NEW + +🏽 + + SOURCE 1 SOURCE 2 +🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 + + + 🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫🟫 + TARGET + + UNCHANGED UNCHANGED +🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🟩🟩🟩🟩🟩 🟦🟦🟦🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽🏽 + + + 🟫🟫🟫🟫🟫🟫🟩🟩🟩🟩🟩🟦🟦🟦🟫🟫 + TARGET NEW diff --git a/mmu/lua/type3.lua.tex b/mmu/lua/type3.lua.tex new file mode 100644 index 0000000..5432ffd --- /dev/null +++ b/mmu/lua/type3.lua.tex @@ -0,0 +1,61 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} +We define an MMU instruction + + MMU_INST_arbitriraryLengthInputRamToExo + +It takes as inputs +- SRC_ID: cn +- SRC_OFF: cdo +- SIZE: cds +- TGT_ID +- EXO_SUM +- AUX_ID + +|-----------------+--------+-------------+----------+---------------------+-----------+------| +| hub instruction | SRC_ID | TGT_ID | AUX_ID | EXO_SUM | PHASE_NUM | SIZE | +|-----------------+--------+-------------+----------+---------------------+-----------+------| +| LOGX | CN | ABS_LOG_NUM | ∅ | 1 << log | ∅ | cds | +| RETURN (dep.) | CN | CFI | HASH_NUM | 1 << rom + 1 << kec | ∅ | cds | +| SHA3 | CN | ∅ | HASH_NUM | 1 << kec | ∅ | cds | +| CREATE | CN | CFI | ∅ | 1 << rom | ∅ | cds | +| CREATE2 | CN | CFI | HASH_NUM | 1 << rom + 1 << kec | ∅ | cds | +|-----------------+--------+-------------+----------+---------------------+-----------+------| +| SHA2-256 | CN | 1 + h | ∅ | 1 << sha2 | rel. val. | cds | +| RIPEMD-160 | CN | 1 + h | ∅ | 1 << ripe | rel. val. | cds | +| ECPAIRING | CN | 1 + h | ∅ | 1 << ecdata | rel. val. | cds | +| BLAKE2f | CN | 1 + h | ∅ | 1 << blake | rel. val. | ∅ | +|-----------------+--------+-------------+----------+---------------------+-----------+------| + +NOTE. we use the following shorthands + + * h ≡ HUB_STAMP + +NOTE. the relevant value is particularly important for the ECPAIRING case and both the +SHA2-256 and RIPEMD cases, as these modules are located in data modules which collect +the inputs and outputs of several different precompiles: + +- ECDATA does ECRECOVER, ECADD, ECMUL, ECPAIRING; +- RIPSHA does SHA2-256, RIPEMD-160; + +NOTE. the PHASE_NUM is produced by the HUB at the moment the MMU instruction is crafted +\end{verbatim} +\end{document} + diff --git a/mmu/nppRows.tex b/mmu/nppRows.tex new file mode 100644 index 0000000..36ea740 --- /dev/null +++ b/mmu/nppRows.tex @@ -0,0 +1,46 @@ +We settle the number of pre-processing rows per macro-instruction. +To this end let us define the following shorthand: +\[ + \hspace*{-1.5cm} + \begin{array}{l} + \locInitialCtSum_{i} \define \vspace{4mm} \\ + \qquad + \left[ \begin{array}{crcl} + + & ( \nppMmuInstMload - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagMload _{i} \vspace{1mm} \\ + + & ( \nppMmuInstMstore - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagMstore _{i} \vspace{1mm} \\ + + & ( \nppMmuInstMstoreEight - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagMstoreEight _{i} \vspace{1mm} \\ + + & ( \nppMmuInstInvalidCodePrefix - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagInvalidCodePrefix _{i} \vspace{1mm} \\ + + & ( \nppMmuInstRightPaddedWordExtraction - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagRightPaddedWordExtraction _{i} \vspace{1mm} \\ + + & ( \nppMmuInstRamToExoWithPadding - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagRamToExoWithPadding _{i} \vspace{1mm} \\ + + & ( \nppMmuInstExoToRamTransplants - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagExoToRamTransplants _{i} \vspace{1mm} \\ + + & ( \nppMmuInstRamToRamSansPadding - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagRamToRamSansPadding _{i} \vspace{1mm} \\ + + & ( \nppMmuInstAnyToRamWithPaddingSomeData - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagAnyToRamWithPaddingSomeData _{i} \vspace{1mm} \\ + + & ( \nppMmuInstAnyToRamWithPaddingPurePadding - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagAnyToRamWithPaddingPurePadding _{i} \vspace{1mm} \\ + + & ( \nppMmuInstModexpZero - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagModexpZero _{i} \vspace{1mm} \\ + + & ( \nppMmuInstModexpData - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagModexpData _{i} \vspace{1mm} \\ + + & ( \nppMmuInstBlake - 1 ) & \!\!\!\cdot\!\!\! & \mmuInstFlagBlake _{i} \\ + \end{array} \right] \\ + \end{array} +\] +where we define the numerical values on the left as follows: +\[ + \left\{ \begin{array}{lcl} + \nppMmuInstMload & \define & \nppMmuInstMloadValue \\ + \nppMmuInstMstore & \define & \nppMmuInstMstoreValue \\ + \nppMmuInstMstoreEight & \define & \nppMmuInstMstoreEightValue \\ + \nppMmuInstInvalidCodePrefix & \define & \nppMmuInstInvalidCodePrefixValue \\ + \nppMmuInstRightPaddedWordExtraction & \define & \nppMmuInstRightPaddedWordExtractionValue \\ + \nppMmuInstRamToExoWithPadding & \define & \nppMmuInstRamToExoWithPaddingValue \\ + \nppMmuInstExoToRamTransplants & \define & \nppMmuInstExoToRamTransplantsValue \\ + \nppMmuInstRamToRamSansPadding & \define & \nppMmuInstRamToRamSansPaddingValue \\ + \nppMmuInstAnyToRamWithPaddingSomeData & \define & \nppMmuInstAnyToRamWithPaddingSomeDataValue \\ + \nppMmuInstAnyToRamWithPaddingPurePadding & \define & \nppMmuInstAnyToRamWithPaddingPurePaddingValue \\ + \nppMmuInstModexpZero & \define & \nppMmuInstModexpZeroValue \\ + \nppMmuInstModexpData & \define & \nppMmuInstModexpDataValue \\ + \nppMmuInstBlake & \define & \nppMmuInstBlakeValue \\ + \end{array} \right. +\] +We further impose the following: +\begin{enumerate} + \item \If $\isMacro_{i} = 1$ \Then \( \ppCt_{i + 1} = \locInitialCtSum_{i} \) +\end{enumerate} diff --git a/mmu/row_types.tex b/mmu/row_types.tex new file mode 100644 index 0000000..d31250f --- /dev/null +++ b/mmu/row_types.tex @@ -0,0 +1,101 @@ +The present section provides the constraints satisfied by +$\isLeftZero$, +$\isOnlyNT$, $\isFirstNT$, $\isMiddleNT$, $\isLastNT$, +$\isOnlyRZ$, $\isFirstRZ$, $\isMiddleRZ$, $\isLastRZ$. +\begin{enumerate} + \item \label{mmu: row types: binarity} + $\isLeftZero$, + $\isOnlyNT$, $\isFirstNT$, $\isMiddleNT$, $\isLastNT$, + $\isOnlyRZ$, $\isFirstRZ$, $\isMiddleRZ$, $\isLastRZ$, + are binary columns; +\end{enumerate} +We introduce the following shorthand: +\[ + \left\{ \begin{array}{lcl} + \isNontrivial _{i} & \define & \isOnlyNT_{i} + \isFirstNT_{i} + \isMiddleNT_{i} + \isLastNT_{i} \\ + \isRightZero _{i} & \define & \isOnlyRZ_{i} + \isFirstRZ_{i} + \isMiddleRZ_{i} + \isLastRZ_{i} \\ + \isZero _{i} & \define & \isLeftZero_{i} + \isRightZero_{i} \\ + \end{array} \right. +\] +\begin{enumerate}[resume] + \item \label{mmu: row types: exclusivity} + $\isLeftZero_{i} + \isNontrivial_{i} + \isRightZero_{i} = \isMicro_{i}$; +\end{enumerate} +\saNote{} Constraints +(\ref{mmu: row types: binarity}) and +(\ref{mmu: row types: exclusivity}) +enforce that +$\isLeftZero$, +$\isOnlyNT$, $\isFirstNT$, $\isMiddleNT$, $\isLastNT$, +$\isOnlyRZ$, $\isFirstRZ$, $\isMiddleRZ$, $\isLastRZ$. +are \textbf{exclusive binary columns} with precisely one of them lighting up on any give micro-instruction-writing-row. + +These shorthands both point to a binary values and $\isNontrivial + \isZero \equiv \isMicro$. +\begin{enumerate}[resume] + \item \If $\isLeftZero _{i} = 1$ \Then $\ppTotLZ_{i} = - 1 + \ppTotLZ_{i - 1}$ + \item \If $\isNontrivial _{i} = 1$ \Then $\ppTotNT_{i} = - 1 + \ppTotNT_{i - 1}$ + \item \If $\isRightZero _{i} = 1$ \Then $\ppTotRZ_{i} = - 1 + \ppTotRZ_{i - 1}$ +\end{enumerate} +\saNote{} The preconditions of the following constraints pertaining to nontrivial rows have as an implicit consequence that $\isNontrivial_{i} \equiv 1$ and therefore, by virtue of the preceding, that $\ppTotNT_{i} = - 1 + \ppTotNT_{i - 1}$. +\begin{enumerate}[resume] + \item \If $\isOnlyNT _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isNontrivial_{i - 1} & = & 0 \\ + \ppTotNT_{i } & = & 0 \\ + \end{array} \right. + \] + \item \If $\isFirstNT _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \isNontrivial_{i - 1} & = & 0 \\ + \ppTotNT_{i } & \neq & 0 \\ + \end{array} \right. + \] + \item \If $\isMiddleNT _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isNontrivial_{i - 1} & = & 1 \\ + \ppTotNT _{i } & \neq & 0 \\ + \end{array} \right. + \] + \item \If $\isLastNT _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isNontrivial_{i - 1} & = & 1 \\ + \ppTotNT_{i } & = & 0 \\ + \end{array} \right. + \] + % +\end{enumerate} +\saNote{} The preconditions of the following constraints pertaining to right-zero-rows have as an implicit consequence that $\isRightZero_{i} \equiv 1$ and therefore, by virtue of the preceding, that $\ppTotRZ_{i} = - 1 + \ppTotRZ_{i - 1}$. +\begin{enumerate}[resume] + \item \If $\isOnlyRZ _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isRightZero_{i - 1} & = & 0 \\ + \ppTotRZ_{i } & = & 0 \\ + \end{array} \right. + \] + \item \If $\isFirstRZ _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lclr} + \isRightZero_{i - 1} & = & 0 \\ + \ppTotRZ_{i } & \neq & 0 \\ + \end{array} \right. + \] + \item \If $\isMiddleRZ _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isRightZero_{i - 1} & = & 1 \\ + \ppTotRZ _{i } & \neq & 0 \\ + \end{array} \right. + \] + \item \If $\isLastRZ _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isRightZero_{i - 1} & = & 1 \\ + \ppTotRZ _{i } & = & 0 \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/mmu/sketch b/mmu/sketch new file mode 100644 index 0000000..1c9ce44 --- /dev/null +++ b/mmu/sketch @@ -0,0 +1,81 @@ +Consider the following: introduce extra columns like so: + +* lz +* first +* middle +* last +* only +* rz + +We maintain the mechanics of TOT, TOTLZ, TOTNT, TOTRZ and we impose +* all are binary + <> 6 degree 2 constraints +* sum = isMicro + <> 1 degree 1 constraints +* nt := first + middle + last + only + <> 1 degree 1 constraints +* If lz[i] = 1 Then TOTLZ[i - 1] = - 1 + TOTLZ[i] + <> 1 degree 1 constraints +* If nz[i] = 1 Then TOTNT[i - 1] = - 1 + TOTNT[i] + <> 1 degree 1 constraints +* If rz[i] = 1 Then TOTRZ[i - 1] = - 1 + TOTRZ[i] + <> 1 degree 1 constraints +* If only[i] = 1 Then + * TOTNT[i - 2] = 1 + * TOTNT[i] = 0 + <> 2 degree 2 constraints +* If first[i] = 1 Then + * TOTNT[i - 2] = TOTNT[i - 1] + * TOTNT[i - 2] ≠ 1 + <> 1 degree 2 constraints + <> 1 degree 3 constraints +* If middle[i] = 1 Then + * nt[i - 1] = 1 + * TOTNT[i] ≠ 0 + <> 1 degree 2 constraints + <> 1 degree 3 constraints +* If last[i] = 1 Then + * TOTNT[i - 2] = 2 + * TOTNT[i] = 0 + <> 2 degree 2 constraints + +We get a one time cost of these constraints but then we get a +benefit for all other constraints that follow. + +With this our constraints become + +If + * isModexpdata🏴 = 1 + * first = 1 + Then ... (degree d constraint) + +as opposed to + +If + * isModexpdata🏴 = 1 + * isMicro = 1 + * NT[i - 1] ≠ NT[i] + * NT[i - 2] = NT[i - 1] (<== degree 2) + Then ... (degree d constraint) + +So we go from degree d + 5 to d + 2. And this reduction will hold +for all families of MMU instructions. +For a total of: + +* 6 columns +* 19 constraints + - 2 of degree 3 + <> 1 degree 3 constraints + <> 1 degree 3 constraints + - 12 of degree 2 + <> 6 degree 2 constraints + <> 2 degree 2 constraints + <> 2 degree 2 constraints + <> 1 degree 2 constraints + <> 1 degree 2 constraints + - 5 of degree 1 + <> 1 degree 1 constraints + <> 1 degree 1 constraints + <> 1 degree 1 constraints + <> 1 degree 1 constraints + <> 1 degree 1 constraints diff --git a/mmu/utilities/_inputs.tex b/mmu/utilities/_inputs.tex new file mode 100644 index 0000000..5661795 --- /dev/null +++ b/mmu/utilities/_inputs.tex @@ -0,0 +1,3 @@ +\subsection{Euclidean divisions} \input{utilities/euc} +\subsection{Word comparisons} \input{utilities/wcp} +\subsection{The \stdProgression{} constraint} \input{utilities/standard_progression} diff --git a/mmu/utilities/euc.tex b/mmu/utilities/euc.tex new file mode 100644 index 0000000..d43833c --- /dev/null +++ b/mmu/utilities/euc.tex @@ -0,0 +1,15 @@ +The present section define constraints for pre-processing rows. +Specifically they provide the facilities to trigger the \eucMod{} module. +We define the following constraint +\[ + \left\{ \begin{array}{l} + \callToEuc {i}{\relof}{\col{a}}{\col{b}} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \ppEucFlag _{i + \relof} & = & \rOne \\ + \ppEucA _{i + \relof} & = & \col{a} \\ + \ppEucB _{i + \relof} & = & \col{b} \\ + \end{array} \right. + \end{array} \right. +\] +The above allows us to compute the euclidean division of \col{a} by \col{b} on row $i + \relof$. diff --git a/mmu/utilities/row_types.tex b/mmu/utilities/row_types.tex new file mode 100644 index 0000000..5377bf3 --- /dev/null +++ b/mmu/utilities/row_types.tex @@ -0,0 +1,58 @@ +The present section introduces some very useful collections of conditions which allow us to characterize and name micro-instruction-writing-rows with greater specificity. +It is understood that the constraints below will only ever apply to micro-instruction-rows i.e. rows $i$ satisfying $\isMicro_{i} = 1$. +Such safeguards will systematically be present when the conditions defined below are in use. + +We say that $i$ is a +\textbf{left-zero-padding-row} if it satisfies +\[ + \leftPaddingRow_{i} \equiv \Big[\ppTotLZ_{i - 1} \neq 0 \Big] +\] +a \textbf{nontrivial-row} if it satisfies +\[ + \nontrivialRow_{i} \equiv \Big[\ppTotNT_{i - 1} \neq \ppTotNT_{i} \Big] +\] +and a \textbf{right-zero-padding-row} if it satisfies +\[ + \rightPaddingRow_{i} \equiv \Big[\ppTotRZ_{i - 1} \neq \ppTotRZ_{i} \Big] +\] + +The following conditions on a row $i$ provide more detail still for nontrivial-rows. +Thus the above conditions should be applied \textbf{on top} of the \nontrivialRow{} condition. +We say that a (nontrivial-row) $i$ is a +\textbf{first-term-row} if it satisfies +\[ + \firstTerm_{i} + \equiv + \Big[ \ppTotNT_{i - 2} = \ppTotNT_{i - 1} \Big] + % \begin{cases} + % \nontrivialRow_{i} & \et \\ + % \ppTotNT_{i - 2} = \ppTotNT_{i - 1} & \\ + % \end{cases} +\] +\textbf{middle-term-row} if it satisfies +\[ + \middleTerm_{i} + \equiv + \begin{cases} + % \nontrivialRow_{i} & \et \\ + \ppTotNT_{i - 2} \neq \ppTotNT_{i - 1} & \et \\ + \ppTotNT_{i} \neq 0 & \\ + \end{cases} +\] +\textbf{last-term-row} if it satisfies +\[ + \lastTerm_{i} + \equiv + \Big[ \ppTotNT_{i} = 0 \Big] + % \begin{cases} + % \nontrivialRow_{i} & \et \\ + % \ppTotNT_{i} = 0 & \\ + % \end{cases} +\] +\saNote{} +If the \textbf{initial value} of \ppTotNT{} is $>1$ then these conditions are disjoint. +The condition \middleTerm{} may only be achieved if \ppTotNT{} is $>2$. + +\saNote{} +If the \textbf{initial value} of \ppTotNT{} is $=1$ then the conditions +\firstTerm{} and \lastTerm{} are identical and \nontrivialRow{} is a void condition. diff --git a/mmu/utilities/row_types_diagram.tex b/mmu/utilities/row_types_diagram.tex new file mode 100644 index 0000000..6e43f3c --- /dev/null +++ b/mmu/utilities/row_types_diagram.tex @@ -0,0 +1,171 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| MMU_ | MACRO | PRPRC | MICRO | TOT | TOTLZ | TOTNT | TOTRZ | LFTZ | ONLY | FRST | MDDL | LAST | RGTZ | +|:-----:+:-----:+:------:+:-----:+----:+:-----:+:-----:+:-----:+:----:+:----:+:----:+:----:+:----:+:----:| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| a | M | | | 15 | 3 | 8 | 4 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| a | | pp | | 15 | 3 | 8 | 4 | | | | | | | +| a | | pp | | 15 | 3 | 8 | 4 | | | | | | | +| a | | pp | | 15 | 3 | 8 | 4 | | | | | | | +| a | | pp | | 15 | 3 | 8 | 4 | | | | | | | +| a | | pp | | 15 | 3 | 8 | 4 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| a | | | µ | 14 | 2 | . 8 . | . 4 . | 1 | | | | | | +| a | | | µ | 13 | 1 | . 8 . | . 4 . | 1 | | | | | | +| a | | | µ | 12 | 0 | . 8 . | . 4 . | 1 | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| a | | | µ | 11 | | 7 | . 4 . | | | 1 | | | | +| a | | | µ | 10 | | 6 | . 4 . | | | | 1 | | | +| a | | | µ | 9 | | 5 | . 4 . | | | | 1 | | | +| a | | | µ | 8 | | 4 | . 4 . | | | | 1 | | | +| a | | | µ | 7 | | 3 | . 4 . | | | | 1 | | | +| a | | | µ | 6 | | 2 | . 4 . | | | | 1 | | | +| a | | | µ | 5 | | 1 | . 4 . | | | | 1 | | | +| a | | | µ | 4 | | 0 | . 4 . | | | | | 1 | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| a | | | µ | 3 | | | 3 | | | | | | 1 | +| a | | | µ | 2 | | | 2 | | | | | | 1 | +| a | | | µ | 1 | | | 1 | | | | | | 1 | +| a | | | µ | 0 | | | 0 | | | | | | 1 | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| MMU_ | MACRO | PREPRC | MICRO | TOT | TOTLZ | TOTNT | TOTRZ | LFTZ | ONLY | FRST | MDDL | LAST | RGTZ | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| b | M | | | 11 | 5 | 2 | 4 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| b | | pp | | 11 | 5 | 2 | 4 | | | | | | | +| b | | pp | | 11 | 5 | 2 | 4 | | | | | | | +| b | | pp | | 11 | 5 | 2 | 4 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| b | | | µ | 10 | 4 | . 2 . | . 4 . | 1 | | | | | | +| b | | | µ | 9 | 3 | . 2 . | . 4 . | 1 | | | | | | +| b | | | µ | 8 | 2 | . 2 . | . 4 . | 1 | | | | | | +| b | | | µ | 7 | 1 | . 2 . | . 4 . | 1 | | | | | | +| b | | | µ | 6 | 0 | . 2 . | . 4 . | 1 | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| b | | | µ | 5 | | 1 | . 4 . | | | 1 | | | | +| b | | | µ | 4 | | 0 | . 4 . | | | | | 1 | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| b | | | µ | 3 | | | 3 | | | | | | 1 | +| b | | | µ | 2 | | | 2 | | | | | | 1 | +| b | | | µ | 1 | | | 1 | | | | | | 1 | +| b | | | µ | 0 | | | 0 | | | | | | 1 | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| MMU_ | MACRO | PREPRC | MICRO | TOT | TOTLZ | TOTNT | TOTRZ | LFTZ | ONLY | FRST | MDDL | LAST | RGTZ | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| c | M | | | 3 | 0 | 1 | 2 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +| c | | pp | | 3 | 0 | 1 | 2 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| c | | | µ | 2 | | 0 | . 2 . | | 1 | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| c | | | µ | 1 | | | 1 | | | | | | 1 | +| c | | | µ | 0 | | | 0 | | | | | | 1 | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| MMU_ | MACRO | PREPRC | MICRO | TOT | TOTLZ | TOTNT | TOTRZ | LFTZ | ONLY | FRST | MDDL | LAST | RGTZ | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| d | M | | | 1 | 0 | 1 | 0 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| d | | pp | | 1 | 0 | 1 | 0 | | | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| d | | | µ | 0 | | | 0 | | 1 | | | | | +|-------+-------+--------+-------+-----+-------+-------+-------+------+------+------+------+------+------| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +\end{verbatim} + +\begin{verbatim} +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| MMU_ | MACRO | PREPRC | MICRO | TOT | TOTLZ | TOTNT | TOTRZ | row type | nontrivial row type | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| a | 1 | | | 15 | 3 | 8 | 4 | | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| a | | 1 | | 15 | 3 | 8 | 4 | | | +| a | | 1 | | 15 | 3 | 8 | 4 | | | +| a | | 1 | | 15 | 3 | 8 | 4 | | | +| a | | 1 | | 15 | 3 | 8 | 4 | | | +| a | | 1 | | 15 | 3 | 8 | 4 | | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| a | | | 1 | 14 | 2 | 8 | 4 | leftPaddingRow | | +| a | | | 1 | 13 | 1 | 8 | 4 | leftPaddingRow | | +| a | | | 1 | 12 | 0 | 8 | 4 | leftPaddingRow | | +| a | | | 1 | 11 | 0 | 7 | 4 | . nontrivialRow | firstTerm | +| a | | | 1 | 10 | 0 | 6 | 4 | . nontrivialRow | . middleTerm | +| a | | | 1 | 9 | 0 | 5 | 4 | . nontrivialRow | . middleTerm | +| a | | | 1 | 8 | 0 | 4 | 4 | . nontrivialRow | . middleTerm | +| a | | | 1 | 7 | 0 | 3 | 4 | . nontrivialRow | . middleTerm | +| a | | | 1 | 6 | 0 | 2 | 4 | . nontrivialRow | . middleTerm | +| a | | | 1 | 5 | 0 | 1 | 4 | . nontrivialRow | . middleTerm | +| a | | | 1 | 4 | 0 | 0 | 4 | . nontrivialRow | . lastTerm | +| a | | | 1 | 3 | 0 | 0 | 3 | . rightPaddingRow | | +| a | | | 1 | 2 | 0 | 0 | 2 | . rightPaddingRow | | +| a | | | 1 | 1 | 0 | 0 | 1 | . rightPaddingRow | | +| a | | | 1 | 0 | 0 | 0 | 0 | . rightPaddingRow | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| b | 1 | | | 11 | 5 | 2 | 4 | | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| b | | 1 | | 11 | 5 | 2 | 4 | | | +| b | | 1 | | 11 | 5 | 2 | 4 | | | +| b | | 1 | | 11 | 5 | 2 | 4 | | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| b | | | 1 | 10 | 4 | 2 | 4 | leftPaddingRow | | +| b | | | 1 | 9 | 3 | 2 | 4 | leftPaddingRow | | +| b | | | 1 | 8 | 2 | 2 | 4 | leftPaddingRow | | +| b | | | 1 | 7 | 1 | 2 | 4 | leftPaddingRow | | +| b | | | 1 | 6 | 0 | 2 | 4 | leftPaddingRow | | +| b | | | 1 | 5 | 0 | 1 | 4 | . nontrivialRow | firstTerm | +| b | | | 1 | 4 | 0 | 0 | 4 | . nontrivialRow | . lastTerm | +| b | | | 1 | 3 | 0 | 0 | 3 | . rightPaddingRow | | +| b | | | 1 | 2 | 0 | 0 | 2 | . rightPaddingRow | | +| b | | | 1 | 1 | 0 | 0 | 1 | . rightPaddingRow | | +| b | | | 1 | 0 | 0 | 0 | 0 | . rightPaddingRow | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| c | 1 | | | 8 | 2 | 1 | 5 | | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| c | | 1 | | 8 | 2 | 1 | 5 | | | +| c | | 1 | | 8 | 2 | 1 | 5 | | | +| c | | 1 | | 8 | 2 | 1 | 5 | | | +| c | | 1 | | 8 | 2 | 1 | 5 | | | +| c | | 1 | | 8 | 2 | 1 | 5 | | | +| c | | 1 | | 8 | 2 | 1 | 5 | | | +| c | | 1 | | 8 | 2 | 1 | 5 | | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +| c | | | 1 | 7 | 1 | 1 | 5 | leftPaddingRow | | +| c | | | 1 | 6 | 0 | 1 | 5 | leftPaddingRow | | +| c | | | 1 | 5 | 0 | 0 | 5 | . nontrivialRow | firstTerm ∧ lastTerm | +| c | | | 1 | 4 | 0 | 0 | 4 | . rightPaddingRow | | +| c | | | 1 | 3 | 0 | 0 | 3 | . rightPaddingRow | | +| c | | | 1 | 2 | 0 | 0 | 2 | . rightPaddingRow | | +| c | | | 1 | 1 | 0 | 0 | 1 | . rightPaddingRow | | +| c | | | 1 | 0 | 0 | 0 | 0 | . rightPaddingRow | | +|-------+-------+--------+-------+-----+-------+-------+-------+-----------------------------+----------------------| +\end{verbatim} +\end{document} diff --git a/mmu/utilities/standard_progression.tex b/mmu/utilities/standard_progression.tex new file mode 100644 index 0000000..e53df80 --- /dev/null +++ b/mmu/utilities/standard_progression.tex @@ -0,0 +1,10 @@ +The following constraint system is recurrent enough to warrant being singled out. +It applies to micro-instruction limb offset columns (typically $\microTlo$ and / or $\microSlo$) that follow a simple and predictable progression during the micro-instruction phase counting monotonically from $0$ upwards. +\[ + \stdProgression_{i} \Big( \isMicro, \col{xlo} \Big) + \iff + \col{xlo}_{i} = + \isMicro_{i - 1} + \cdot (1 + \col{xlo}_{i - 1}) +\] +\saNote{} The above will \textbf{always} be prefaced by a precondition ``\If $\isMicro_{i} = 1$ \Then $\cdots$'' diff --git a/mmu/utilities/wcp.tex b/mmu/utilities/wcp.tex new file mode 100644 index 0000000..9d0654a --- /dev/null +++ b/mmu/utilities/wcp.tex @@ -0,0 +1,56 @@ +The present section define constraints for pre-processing rows. +Specifically they provide the facilities to trigger the \wcpMod{} module. +We define the following constraint +\[ + \left\{ \begin{array}{l} + \callToLt + {i}{\relof} + {\col{a}}{\col{b}} + {\col{c}} + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \ppWcpFlag _{i + \relof} & = & 1 \\ + \ppWcpInst _{i + \relof} & = & \inst{LT} \\ + \ppWcpArgOneHi _{i + \relof} & = & \col{a} \\ + \ppWcpArgOneLo _{i + \relof} & = & \col{b} \\ + \ppWcpArgTwoLo _{i + \relof} & = & \col{c} \\ + \end{array} \right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \callToEq + {i}{\relof} + {\col{a}}{\col{b}} + {\col{c}} + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \ppWcpFlag _{i + \relof} & = & 1 \\ + \ppWcpInst _{i + \relof} & = & \inst{EQ} \\ + \ppWcpArgOneHi _{i + \relof} & = & \col{a} \\ + \ppWcpArgOneLo _{i + \relof} & = & \col{b} \\ + \ppWcpArgTwoLo _{i + \relof} & = & \col{c} \\ + \end{array} \right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \callToIszero + {i}{\relof} + {\col{a}}{\col{b}} + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \ppWcpFlag _{i + \relof} & = & 1 \\ + \ppWcpInst _{i + \relof} & = & \inst{ISZERO} \\ + \ppWcpArgOneHi _{i + \relof} & = & \col{a} \\ + \ppWcpArgOneLo _{i + \relof} & = & \col{b} \\ + \ppWcpArgTwoLo _{i + \relof} & = & 0 \quad (\trash) \\ + \end{array} \right. + \end{array} \right. +\] + diff --git a/module_classification.md b/module_classification.md new file mode 100644 index 0000000..0a33e5d --- /dev/null +++ b/module_classification.md @@ -0,0 +1,52 @@ + + +# Nearly trivial data store modules + +Could be tackled in any order (modulo computational endpoints) + +- SHAKIRA: trivial data storey to send data to some (gnark) circuit; +- BLAKEMODEXP: trivial data store to send data to some (gnark) ciruict; +- LOG_DATA / LOG_INFO: trivial data stores to prepare data to send to RLP_TXN_RCPT (the transaction receipt module); +- ROM_LEX: nearly trivial internal logic; associates every nonempty bytecode with a unique identifier (CODE_FRAGMENT_INDEX); complex relationship with the HUB; +- ROM: somewhat complex internal logic; parses bytecode / initialization code; performs jumpdestination analysis; constructs push values; +- ECDATA: data store for elliptic curve precompiles; somewhat complex internal logic (e.g. ECPAIRING) to send data to the correct external (gnark) circuit; relies heavily on other modules (MOD, WCP); +- BLOCKDATA: trivial data store for block data; +- BLOCKHASH: trivial data stores for coherence of BLOCKHASH outputs; +- GAS: trivial module; complex triggering by the HUB; + +# Computational endpoints + +Could be tackled in any order: + +- ADD: deals with ADD, SUB; trivial; +- BIN: deals with AND, OR, XOR, NOT, BYTE and SIGNEXTEND; trivial except for BYTE and SIGNEXTEND; depends on the "binary reference table"; +- EUC: deals with small euclidean divisions required by RAM operations; can call the WCP module; +- EXP: deals with computing various logarithms required in pricing the EXP opcode and the MODEXP precompile; a little involved; +- EXT: deals with ADDMOD, MULMOD; a little involved; +- MOD: deals with DIV, MOD, SDIV, SMOD; a little involved; +- MUL: deals with MUL and EXP computation; EXP is somewhat complex; +- SHF: deals with SHL, SHR, SAR; somewhat involved; depends on the "shifting reference table"; +- TRM: deals with trimming addresses (e.g. converting Bytes32's from the stack to Bytes20 for BALANCE, EXTCODEXXX, CALL) and recognizing addresses of precompiles; trivial; +- WCP: deals with LT, GT, SLT, SGT, EQ, ISZERO; also deals with instructions not directly present in the EVM (LEQ ≤ and GEQ ≥); essentially trivial; + +# Entry point of transactions + +- RLPTXN: decodes RLP strings of transactions, partially re-encodes them to be hashed for signature verification; +- RLP_TXN_RCPT: transaction receipt module; produces the RLP for transaction receipts; +- RLP_ADDR: essentially trivial; produces the strings to be hashed and trimmed when defining deployment addresses; +- TXN_DATA: extracts relevant transaction data from the above and serves it to the HUB; + +# "Users" of computational endpoints + +- OOB: does all sorts of computations for various opcodes and precompiles; relies heavily on other modules (ADD, MOD, WCP) +- STP: computes upfront gas costs of CALL's and CREATE's, gas stipends for CALL's and gas provided to the child context by the parent context; relies heavily on other modules (MOD, WCP); + +# Memory + +- MXP: detects wildly out of bounds arguments for instructions that may trigger memory expansion; STATEFUL module (it provides e.g. the number of active words in memory for MSIZE); +- MMU: breaks complext memory instructions (MSTORE, MLOAD, MSTORE8, SHA3, RETURN, REVERT, CREATE's, COPY-instructions, ...) down into simpler custom ones; +- MMIO: executes the custom instructions prepared by the MMU; STATEFUL module; + +# Hub + +- HUB: main coordination module; complex; diff --git a/mxp/_all_mxp.tex b/mxp/_all_mxp.tex new file mode 100644 index 0000000..b4544c5 --- /dev/null +++ b/mxp/_all_mxp.tex @@ -0,0 +1,35 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +%\usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/env} +\usepackage{../pkg/ram} +\usepackage{../pkg/stack} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/draculatheme} + +\usepackage{../pkg/draculatheme} + +\title{Memory expansion module} +\author{Rollup team} +\date{August 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/mxp/_inputs.tex b/mxp/_inputs.tex new file mode 100644 index 0000000..f7fdd4f --- /dev/null +++ b/mxp/_inputs.tex @@ -0,0 +1,31 @@ +\section{Memory expansion module} + +% \newpage +% \subsection{Raw columns} \input{columns_raw} +\subsection{Introduction} \input{intro} +\subsection{Instructions} \input{instructions} +\subsection{Columns} \input{columns} +\subsection{Offset bounds} \input{details} \label{mxp: offset bounds} + +\section{General constraints} +\subsection{Binary constraints} \input{binary} \label{mxp: binary} +\subsection{Constancy constraints} \input{constancies} \label{mxp: counter-constancies} +\subsection{The \roob{} flag} \input{roob} \label{mxp: roob} +\subsection{The \noop{} flag} \input{noop} \label{mxp: noop} +\subsection{The \mayTriggerNonTrivialOperation{} flag} \input{mtntop} \label{mxp: may trigger non trivial operation} +\subsection{Heartbeat} \input{heartbeat} \label{mxp: heartbeat} +\subsection{Byte decompositions} \input{bytedec} \label{mxp: byte decompositions} + +\section{Specialized constraints} \label{mxp: specialized constraints} +\subsection{Standing hypothesis} \input{standing_hyp} +\subsection{Max offsets} \input{max_offsets} +\subsection{Offsets are out of bounds} \input{out_of_bounds/intro} +\subsection{Offsets are in bounds} +\subsubsection{Preliminary computations} \input{in_bounds/comp} +\subsubsection{Update --- no expansion event} \input{in_bounds/no_update} +\subsubsection{Update --- expansion event} \input{in_bounds/update} +\subsubsection{Memory expansion gas} \input{in_bounds/gas_cost} \label{mxp: mxp gas cost} + +\section{Consistency constraints} \input{consistency} \label{mxp: consistency} + +\section{Lookup into the \idMod{} module} \input{lookup} \label{mxp: instruction decoding lookup} diff --git a/mxp/binary.tex b/mxp/binary.tex new file mode 100644 index 0000000..a3625f2 --- /dev/null +++ b/mxp/binary.tex @@ -0,0 +1,13 @@ +We impose that the following columns be binary: +\begin{multicols}{3} + \begin{enumerate} + \item \roob{} + \item \noop{} + \item \mxpx{} + \item \codeDeployment{} + \item $\decMxpType{k}$, $k = 1,\dots,5$ (\trash) + \item \comp{} + \item \mexpEvent{} + \item \mayTriggerNonTrivialOperation{} + \end{enumerate} +\end{multicols} diff --git a/mxp/bytedec.tex b/mxp/bytedec.tex new file mode 100644 index 0000000..0f5a0cf --- /dev/null +++ b/mxp/bytedec.tex @@ -0,0 +1,6 @@ +We impose the following constraints, for $k = 1, 2, 3, 4, \col{A}, \col{W}, \col{Q}$: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_{i}$ + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i - 1} + \byteCol{k}_{i}$ +\end{enumerate} +The byte columns $\byteCol{7}$ and $\byteCol{8}$ serve a different purpose: rather than partake in a classical byte decomposition, they are used to store auxiliary bytes. They only play a role in case $\roob = \noop = 0$. We further impose \textbf{bytehood} constraints on all byte columns $\byteCol{k}$, $k = 1, 2, 3, 4, \col{A}, \col{W}, \col{Q}, \col{QQ}, \col{R}$ \ No newline at end of file diff --git a/mxp/columns.tex b/mxp/columns.tex new file mode 100644 index 0000000..3defae0 --- /dev/null +++ b/mxp/columns.tex @@ -0,0 +1,107 @@ +The following columns determine the heartbeat of the module: +\begin{enumerate} + \item \mxpStamp: \godGiven{} + \ccc{} containing the module stamp; stamp increments are $0$ or $1$; + \item \cn: \godGiven{} + \ccc{} containing the relevant context number; + \item \ct: + counter column; grows monotonically and resets to 0 with every new instruction; + \item \roob{}: + \ccbc{} indicating whether an offset or a size is \ROOB; + \item \noop{}: + \ccbc{}; is zero if $\roob \equiv 1$; otherwise lights up if relevant size(s) are zero; +\end{enumerate} +Thus if $\noop \equiv 1$ the underlying instruction is a no-op \emph{from the point of view of memory expansion and that alone}. +\begin{enumerate}[resume] + \item \mxpx: \godGiven{} + \ccbc{}; indicates whether a \mxpX{} has taken place i.e. whenever \emph{both} maximal offsets fit into $\ssmall{}$ bytes or not; +\end{enumerate} +The \ct{} column either hovers around $0$ or counts from 0 to either $\ssmallMO{}$ or $\lllargeMO{}$ depending on other factors. Which of the two is the cut-off point depends on whether the maximal offset fits into $\ssmall{}$ bytes ($\mxpx{} = 0$) or not ($\mxpx{} = 1$). +Maximal offsets are defined as sums of two 16 byte integers and as such may overflow 16 bytes. Computing their byte decomposition may thus require $\lllarge{}$ bytes. This explains \ct's threshold at $\lllargeMO{} = \lllarge - 1$ rather than the customary $\llargeMO = \llarge - 1$ found in most other modules.% Imported columns are surrounded by $\langle\,\cdots\rangle$. +\begin{enumerate}[resume] + \item $\INST$: \godGiven{} + \ccc{} containing an instruction; + \item $\decMxpType{k}$ for $k \in \{ 1, 2, \dots, 5\}$: + instruction decoded binary columns (and thus \ccbc); + \item $\decWordCost$ and $\decByteCost$: + instruction decoded (and thus \ccc{}) containing gas cost parameters; +\end{enumerate} +The $\decMxpType{1}, \decMxpType{2}, \dots, \decMxpType{5}$ partition the instructions into different classes. The present module treats instructions of a same class homogeneously. +\begin{enumerate}[resume] + \item $\codeDeployment$: \godGiven{} + \ccbc{} indicating whether the memory expansion cost pertains to a \inst{RETURN} in a deployment context; + \item $\offsetHi{k}$, $\offsetLo{k}$ for $k = 1, 2$: \godGiven{} + \ccc{} containing the high and low parts of an offset parameter; + \item $\sizeHi{k}$, $\sizeLo{k}$ for $k = 1, 2$: \godGiven{} + \ccc{}'s containing the high and low parts of a size parameter; + \item $\lastOffset{k}$ for $k = 1, 2$: + largest offsets in memory touched by the instruction by the first and second pairs of offsets and sizes respectively; + \item $\maxOffset$: + computes $\max\Big\{\lastOffset{1},\lastOffset{2}\Big\}$ \emph{when both are in bounds}; + \item \comp: + \ccbc{} which equals 1 \emph{iff} $\lastOffset{1}\geq\lastOffset{2}$; +\end{enumerate} +The above ``comparison bit'' column comes into play only for memory expanding instructions involving two offsets, i.e. \inst{CALL}-type instructions. +\begin{enumerate}[resume] + \item $\byteCol{k}$ and $\acc{k}$ for $k \in \{ \col{1}, \col{2}, \col{3}, \col{4}, \col{A}, \col{W}, \col{Q}\}$: + byte columns and associated accumulator columns; + \item $\byteCol{QQ}, \byteCol{R}$: + extra byte columns; +\end{enumerate} +The byte columns $\byteCol{R}$, $\byteCol{QQ}$ provide auxiliary bytes that are used, for instance, to \emph{complete} byte decompositions of \emph{medium-sized} numbers (i.e. $\medium{}$-byte integers) that can appear in calculations. +\begin{enumerate}[resume] + \item $\memSize$: \godGiven{} + \ccc{} containing ``the [currently valid] active number of words in memory (counting continuously from position $0$)'' \emph{before} excuting on the current instruction; + \item $\memSize\new$: + \ccc{} which \emph{may} contain ``the active number of words in memory (counting continuously from position $0$)'' \emph{after} executing the current instruction; + \item \expCost: + \ccc{} containing the currently accrued memory expansion cost; + \item $\expCost\new$: + \ccc{} containing the updated value of $\expCost$: if no memory expansion took place contains the same value as \expCost{} while if memory expansion \emph{did} occur will store the updated value of $\expCost$; + \item $\mxpQuadGas$: + \ccc{} containing the quadratic expansion cost of the instruction; + \item $\mxpLinGas$: + \ccc{} containing the linear cost (if relevant) of the instruction; + \item $\gasMxp$: \godGiven{} + \ccc{} containing the relevant sum of the quadratic and linear gas costs; + \item \mexpEvent{}: + given $\roob = \noop = 0$, indicates a \MEXPEVENT{} takes place, i.e. whether $\maxOffset + 1 \geq \memSize$ and thus whether the current instruction incurs a memory expansion cost; abbreviated to \mexpEvent{}; + \item \YNMO{}: + \godGiven{} column; indicates if type 4 instruction could potentially trigger the \mmuMod{} module; + abbreviated to \mayTriggerNonTrivialOperation{}; +\end{enumerate} + +We provide more details. Using the notation from the Ethereum Yellow Paper \ob{TODO: add reference} the above columns will contain respectively +\[ + \left\{ \begin{array}{lcl} + \memSize & \longleftrightarrow & \bm{\mu}_\text{i} \\ + \memSize\new & \longleftrightarrow & \bm{\mu}_\text{i}' \\ + \expCost & \longleftrightarrow & C_\textrm{mem}(\bm{\mu}_\text{i}) \\ + \expCost\new & \longleftrightarrow & C_\textrm{mem}(\bm{\mu}_\text{i}') \\ + \end{array} \right. +\] +where $C_\textrm{mem}$ is defined as: +\[ + C_\textrm{mem}(a) = + G_\textrm{mem}\cdot a + + + \left\lfloor\frac{a^2}{512}\right\rfloor +\] +$\mxpQuadGas$ will contain the quadratic memory expansion cost: +\[ + \mxpQuadGas = + \expCost\new - \expCost +\] +while any applicable ``linear'' gas costs incurred on top of that is stored in \mxpLinGas{}: +\[ + \mxpLinGas = + \left[ \begin{array}{c} + \texttt{any applicable} \\ + \texttt{linear cost} \\ + \end{array} \right] +\] +\saNote{} The present module exposes the sum of both the linear and quadratic terms to the \hubMod{} module. + +\saNote{} Fixed costs such such as $G_\text{create}$ for \inst{CREATE}-type instructions or $G_\text{log} + \inst{X} \cdot G_\text{logtopic}$ for \inst{LOGX} instructions aren't included in the present module. + +\saNote{} Other gas costs (such as those related to warmth, account existence etc\dots{} for \inst{CALL}-type instructions) are handled elsewhere i.e. either in the \hubMod{} module directly or in the \stpMod{} module. diff --git a/mxp/consistency.tex b/mxp/consistency.tex new file mode 100644 index 0000000..d7d4cc6 --- /dev/null +++ b/mxp/consistency.tex @@ -0,0 +1,31 @@ +We impose consistency constraints. Consider a row permutation $\col{X}\rightsquigarrow\order{\col{X}}$ such that the rows of the following columns are listed in lexicographic order: +\[ + \Big( + \order{\cn}, + \order{\mxpStamp} + \Big) +\] +We write ``\emph{a} row permutation'' since there may be some (inconsequential) ambiguity: the module can start with an arbitrary number of null rows. Otherwise the ordering is unique. This row permutation groups together, in chronological order, all instructions raising the memory expansion flag executed within the same execution context. The constraints below thus impose coherence between values of $\memSize$ and $\expCost$ that may be separated (in the temporal execution trace) by memory expanding instructions in a descendant context. +\begin{enumerate} + \item \If $\order{\cn}_i\neq 0$: + \begin{enumerate} + \item \If $\order{\cn}_{i - 1} = \order{\cn}_{i}$ \et $\order{\mxpStamp}_{i - 1} \neq \order{\mxpStamp}_{i}$\Then + \[ + \left\{ + \begin{array}{lcl} + \order{\memSize}_{i} & \!\!\! = \!\!\! & \order{\memSize\new_{i - 1}} \vspace{2mm} \\ + \order{\expCost}_{i} & \!\!\! = \!\!\! & \order{\expCost\new_{i - 1}} \\ + \end{array} + \right. + \] + \item \If $\order{\cn}_{i - 1} \neq \order{\cn}_{i}$ \Then + \[ + \left\{ + \begin{array}{lcl} + \order{\memSize}_{i} & \!\!\! = \!\!\! & 0 \vspace{2mm} \\ + \order{\expCost}_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right. + \] + \end{enumerate} +\end{enumerate} diff --git a/mxp/constancies.tex b/mxp/constancies.tex new file mode 100644 index 0000000..7ea25a0 --- /dev/null +++ b/mxp/constancies.tex @@ -0,0 +1,28 @@ +We say that a column $\col{X}$ is \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i}\neq 0 ~ \Then \col{X}_{i} = \col{X}_{i-1}. +\] +We require that the following columns be counter-constant: +\begin{multicols}{3} +\begin{enumerate} + \item $\INST$ + \item $\offsetHi{k}$, $k=1, 2$ + \item $\offsetLo{k}$, $k=1, 2$ + \item $\sizeHi{k}$, $k=1, 2$ + \item $\sizeLo{k}$, $k=1, 2$ + \item $\memSize$ + \item $\memSize\new$ + \item $\expCost$ + \item $\expCost\new$ + \item $\comp$ + \item $\mxpx$ + \item $\mexpEvent$ + \item $\mxpQuadGas$ + \item $\mxpLinGas$ + \item $\gasMxp$ + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\noindent \saNote{} This implies that the instruction decoded memory expansion type flags +$\decMxpType{k}$, $1\leq k \leq 5$, are automatically counter-constant. \ob{TODO: does this account for all counter-constant columns?} diff --git a/mxp/details.tex b/mxp/details.tex new file mode 100644 index 0000000..db19d11 --- /dev/null +++ b/mxp/details.tex @@ -0,0 +1,56 @@ +Touching (i.e. reading or writing) the byte at offset $\offset$ in memory may incur a gas cost on top of the intrinsic gas cost of the instruction. This extra \textbf{memory expansion cost} applies whenever the offset is greater than any other offset previously touched, or more precisely: when the byte belongs to slice of 32 consecutive bytes with word offset $a = \lceil (\offset + 1)/32\rceil = 1 + \lfloor \offset/32 \rfloor$ greater than that of any previously accessed byte. +\[ + \begin{array}{|c||c||c|c|c|c||c|c|c|c||c|c|c|c||c} + \hline + \offset & \varnothing & 0 & 1 & \cdots & 31 & 32 & 33 & \cdots & 63 & 64 & 65 & \cdots & 95 & \cdots\\ + \hline + \col{word offset} & 0 & \multicolumn{4}{c||}{a = 1} + & \multicolumn{4}{c||}{a = 2} + & \multicolumn{4}{c||}{a = 3} + \\ + \hline + \end{array} +\] +The memory expansion module has a notion of \textbf{smallness}: small integers are $\ssmall$-byte integers. Whenever an $\col{offset} + \col{size}$ excedes this threshold (given that $\col{size}\neq0$) the memory expansion module ``gives up'' on the instruction and raises the $\imxx$-flag. We further refer the reader to the following paragraph from the Ethereum Yellow Paper \cite{EthYellowpaperBerlin} +\begin{displayquote} +$[\text{The}]$ total fee for memory-usage payable is proportional to smallest multiple of 32 bytes that are required such that all memory indices $[\,\dots{}]$ are included in the range $[\,\dots{}]$ Due to this fee it is highly unlikely addresses will ever go above 32-bit bounds. That said, implementations must be able to manage this eventuality. +\end{displayquote} +The memory expansion cost for a byte offset $\offset\geq 256^{\ssmall}$ is, setting and $G_\text{memory} = 3$ +\[ + \geq G_\text{memory} \cdot a + \lfloor a^2/512 \rfloor \approx 35 ~ \text{TGas} +\] +When a (potentially) memory expanding instruction has its largest offset(s) ``within bounds'' and isn't a \textsf{noop}, the memory expansion module sets the \emph{two} last touched offsets as $\lastOffset{1} = \offset_1 + (\size_1 - 1)$ and $\lastOffset{2} = \offset_2 + (\size_2 - 1)$. If the memory expansion type $\iMemExpType$ requires only one offset the second one is instead set to $0$; if a size parameter is zero then the associated $\lastOffset{k}$ is also set to $0$. With all these parameters in place the first task of the present module is to determine the maximum of the two: +\[ + \maxOffset = \max\Big\{\lastOffset{1}, \lastOffset{2}\Big\} +\] +It then compares $\maxOffset$ to $\memSize$. If $\maxOffset \leq \memSize$ its work is essentially done as no memory expansion is triggered. Otherwise, if $\maxOffset > \memSize$ it computes $\lceil \maxOffset / 32 \rceil$ which it does by establishing the following variation on the euclidean division +\begin{equation} +\label{eq: euclidean division by 32} +\tag{$\clubsuit$} +\maxOffset + 1 = 32 \cdot \mathtt{q} - \mathtt{r} +\end{equation} +with $\mathtt{r}\in\{0,1,\dots31\}$. In the arithmetization, $\mathtt{q} = \acc{A}$. The next step is to compute the quadratic part of the memory expansion cost which requires determining the euclidean division of $\mathtt{q}^2$ by $512$: +\begin{equation} +\label{eq: euclidean division by 512} +\tag{$\spadesuit$} + \left\{ + \begin{array}{rcll} + \mathtt{q}^2 & = & 512 \cdot \mathtt{q'} + \mathtt{r'}, & 0\leq \mathtt{r'} < 512, \\ + \mathtt{r'} & = & 256\cdot\epsilon + \mathtt{b}, & \epsilon \in\{0,1\},~ 0 \leq \mathtt{b} < 256, \\ + \end{array} + \right. +\end{equation} +In the arithmetization $\mathtt{q'} = \acc{6}$. + +Given the smallness bounds on $\maxOffset < 2\cdot 256^{\ssmall} = 2^{32+1}$, we see that +\begin{enumerate} + \item $\mathtt{q}$ can be of the order of magnitude of $\approx 2^{27}$ and defines a $\ssmall$-byte integer + \item $\mathtt{q'}$ can be of the order of magnitude of $\approx 2^{45}$ and defines a $(\ssmall + 2)$-byte integer +\end{enumerate} +The memory expansion cost is therefore, with $G_\textrm{mem} = 3$: +\[ + C_\textrm{mem} = + G_\textrm{memory}\cdot \mathtt{q} + + + \mathtt{q'} +\] \ No newline at end of file diff --git a/mxp/heartbeat.tex b/mxp/heartbeat.tex new file mode 100644 index 0000000..10d01d9 --- /dev/null +++ b/mxp/heartbeat.tex @@ -0,0 +1,72 @@ +The columns $\mxpStamp$, $\roob{}$, $\noop{}$, $\mxpx{}$ and \ct{} define the heartbeat of the memory expansion module. Observe that the counter-constancy constraints from section~\ref{mxp: sec: counter-constancies} as well as those from section~\ref{mxp: sec: roob} and section~\ref{mxp: sec: noop} imply that both \roob{} and \noop{} are counter-constant (binary) columns. +\begin{enumerate} + \item $\mxpx$ is binary; + %\footnote{Further constraints will impose that $\roob + \noop$ is binary, too.} + \item $\mxpStamp_0 = 0$; + \item $\mxpStamp_{i+1}\in\{\mxpStamp_{i}, 1 + \mxpStamp_{i}\}$; + \item \If $\mxpStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \multicolumn{3}{l}{\roob{}_{i} + \noop{}_{i} + \mxpx{}_{i} = 0} \\ + \ct_{i} & \!\!\! = \!\!\! & 0 \\ + \INST_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right. + \] + \item \If $\mxpStamp_{i} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \phantom{+ ~} \decMxpType{1}_{i} \\ + \qquad + ~ \decMxpType{2}_{i} \\ + \qquad\qquad + ~ \decMxpType{3}_{i} \\ + \qquad\qquad\qquad + ~ \decMxpType{4}_{i} \\ + \qquad\qquad\qquad\qquad + ~ \decMxpType{5}_{i} & = & 1 \\ + \end{array} \right. + \] + \item \If $\mxpStamp_{i + 1} \neq \mxpStamp_{i}$ \Then $\ct{}_{i+1} = 0$; + \item \If $\roob{}_{i} + \noop{}_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \mxpStamp_{i+1} & \!\!\! = \!\!\! & 1 + \mxpStamp_{i} \\ + \mxpx{}_{i} & \!\!\! = \!\!\! & \roob_{i} \\ + \end{array} \right. + \] + \saNote{} Given that $\noop + \roob$ is binary (see note~\ref{mxp: noop: roob + noop is binary}) one may replace the precondition + ``$\noop_{i} + \roob_{i} = 1$'' with + ``$\noop_{i} + \roob_{i} \neq 0$'' in the implementation. +\end{enumerate} +Nothing of interest happens if the current instruction is a \col{noop}. +Nothing of interest happens if offset(s) or size(s) are ridiculously out of bounds (except that the $\mxpx$ is triggered.) +%\begin{enumerate}[resume] +% \item \If \Big($\mxpStamp_{i} \neq 0$ \et $\roob_{i} = 0$ \et $\noop_{i} = 1$\Big) \Then +% \[ +% \left\{ +% \begin{array}{l} +% \ct_{i} = 0 \\ +% \mxpx{}_{i} = 0 \\ +% \mxpStamp_{i+1} = 1 + \mxpStamp_{i} \\ +% \end{array} +% \right. +% \] +%\end{enumerate} +The following case is the main case of interest: the \zkEvm{} deals with a real instruction, i.e. $\mxpStamp \neq 0$, offsets aren't ridiculously out of bounds, i.e. $\roob = 0$, and some size is nonzero, i.e. $\noop = 0$. +\begin{enumerate}[resume] + \item \If \Big($\mxpStamp_{i} \neq 0$ \et $\roob_{i} = 0$ \et $\noop_{i} = 0$\Big) \Then + \begin{enumerate} + \item \If $\mxpx{}_{i} = 0$ \Then + \begin{enumerate} + \item \If $\ct{}_{i} \neq \ssmallMO{}$ \Then $\ct_{i + 1} = 1 + \ct{}_{i}$ + \item \If $\ct{}_{i} = \ssmallMO{}$ \Then $\mxpStamp_{i+1} = 1 + \mxpStamp_{i}$ + \end{enumerate} + \item \If $\mxpx{}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct{}_{i} \neq \lllargeMO$ \Then $\ct_{i + 1} = 1 + \ct{}_{i}$ + \item \If $\ct{}_{i} = \lllargeMO$ \Then $\mxpStamp_{i+1} = 1 + \mxpStamp_{i}$ + \end{enumerate} + \end{enumerate} + \item \If \Big($\mxpStamp_{N} \neq 0$ \et $\roob_{N} = 0$ \et $\noop_{N} = 0$\Big) \Then + \begin{enumerate} + \item \If $\mxpx{}_{N} = 0$ \Then $\ct{}_{N} = \ssmallMO$; + \item \If $\mxpx{}_{N} = 1$ \Then $\ct{}_{N} = \lllargeMO$. + \end{enumerate} + In other words the module doesn't terminate mid instruction. +\end{enumerate} diff --git a/mxp/implicit.tex b/mxp/implicit.tex new file mode 100644 index 0000000..c910222 --- /dev/null +++ b/mxp/implicit.tex @@ -0,0 +1 @@ +The previously stated counter constancies \ No newline at end of file diff --git a/mxp/in_bounds/comp.tex b/mxp/in_bounds/comp.tex new file mode 100644 index 0000000..a461a7d --- /dev/null +++ b/mxp/in_bounds/comp.tex @@ -0,0 +1,111 @@ +This section computes memory expansion in case both maximal offsets are in bounds. The first point is to establish this bound assertion. We then compare the two maximal offsets and store the greatest of the two in $\maxOffset$. +\[ + \boxed{\text{All constraints in this subsection further assume that } + \left\{ + \begin{array}{lcl} + \ct_{i} & \!\!\! = \!\!\! & \ssmallMO \\ + \mxpx_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right.} +\] +\begin{enumerate} + \item For instructions that may require it, the \zkEvm{} computes the number of evm-words $\lceil \col{size}/32 \rceil$ the data to hash or copy occupies: + \[ + \If \decMxpType{4}_{i} = 1 ~ \Then + \left\{ \begin{array}{lcrcr} + \sizeLo{1} & \!\!\! = \!\!\! & + 32 \cdot \acc{W}_{i} & \!\!\! - \!\!\! & \byteCol{R}_{i} \\ + \byteCol{R}_{i - 1} & \!\!\! = \!\!\! & + (256 - 32) & \!\!\! + \!\!\! & \byteCol{R}_{i} \\ + \end{array} \right. + \] + Note that the bytehood constraint on $\byteCol{R}$ enforces $\byteCol{R}_{i} \in \{ 0, 1, \dots, 31\}$. + \item The \zkEvm{} confirms smallness of both $\lastOffset{1}$ and $\lastOffset{2}$: + \[ + \left[ \begin{array}{c} + \text{Confirmation} \\ + \text{of }\mxpx \equiv 0 \\ + \end{array} \right] + \iff + \left\{ \begin{array}{lcl} + \acc{1}_{i} & \!\!\! = \!\!\! & \lastOffset{1}_{i} \\ + \acc{2}_{i} & \!\!\! = \!\!\! & \lastOffset{2}_{i} \\ + \end{array} \right. + \] + In other words, $\lastOffset{1}$ and $\lastOffset{2}$ are both $\ssmall$-byte integers; + \item The \zkEvm{} compares $\lastOffset{1}$ and $\lastOffset{2}$: + \[ + \acc{3}_{i} + (1 - \comp_{i}) + = + \big(\lastOffset{1}_{i} - \lastOffset{2}_{i}\big)\cdot(2\cdot\comp_{i} - 1) + \] + In other words: + \[ + \left\{ \begin{array}{lcl} + \comp{} = 1 & \!\!\! \iff \!\!\! & \lastOffset{1} \geq \lastOffset{2} \\ + \comp{} = 0 & \!\!\! \iff \!\!\! & \lastOffset{1} < \lastOffset{2} \\ + \end{array} \right. + \] + \item The \zkEvm{} sets $\maxOffset_{i}$ to be the maximum of the two max offsets: + \[ + \maxOffset_{i} = \comp_{i} \cdot \lastOffset{1}_{i} + (1 - \comp_{i}) \cdot \lastOffset{2}_{i} + \] + In other words, + \[ + \left\{ \begin{array}{lcl} + \If \lastOffset{1} \geq \lastOffset{2} ~ \Then \maxOffset = \lastOffset{1}\\ + \If \lastOffset{1} < \lastOffset{2} ~ \Then \maxOffset = \lastOffset{2}\\ + \end{array} \right. + \] + \item We compute the index of the EVM word in memory containing the byte at offset $\maxOffset$: + \[ + \left\{ \begin{array}{lcrcr} + \maxOffset_{i} + 1 & \!\!\! = \!\!\! & + 32 \cdot \acc{A}_{i} & \!\!\! - \!\!\! & \byteCol{R}_{i - 2} \\ + \byteCol{R}_{i - 3} & \!\!\! = \!\!\! & + (256 - 32) & \!\!\! + \!\!\! & \byteCol{R}_{i - 2} \\ + \end{array} \right. + \] + Again, bytehood constraints for $\byteCol{R}$ and the previous constraint impose $\byteCol{R}_{i - 2} \in \{0, 1, \dots, 31 \}$. This verifies eq.~(\ref{eq: euclidean division by 32}) + \item The \zkEvm{} decides whether a memory expansion event took place + \[ + \acc{4}_{i} + \mexpEvent_{i} + = + \big( \acc{A}_{i} - \memSize_{i} \big) \cdot ( 2 \cdot \mexpEvent_{i} - 1 ). + \] + In other words, + \[ + \left[ \begin{array}{c} + \text{Confirmation} \\ + \text{of }\mxpx \equiv 0 + \end{array} \right] + \iff + \left\{ \begin{array}{lcl} + \mexpEvent{} = 1 & \!\!\! \iff \!\!\! & \acc{A} > \memSize \\ + \mexpEvent{} = 0 & \!\!\! \iff \!\!\! & \acc{A} \leq \memSize \\ + \end{array} \right. + \] + % \item Some parameters are updated + % \begin{enumerate} + % \item \If $\mexpEvent_{i} = 0$ \Then + % \[ + % \left\{ + % \begin{array}{lcl} + % \memSize_{i}\new & \!\!\! = \!\!\! & \memSize_{i}, \\ + % \expCost_{i}\new & \!\!\! = \!\!\! & \expCost_{i}, \\ + % \end{array} + % \right. + % \] + % In other words: if no memory expansion took place then $\memSize$ and $\expCost$ don't change. + % \item \If $\mexpEvent_{i} = 1$ \Then + % \[ + % \left\{ + % \begin{array}{lcl} + % \memSize_{i}\new & \!\!\! = \!\!\! & \acc{A}_{i} \\ + % \expCost_{i}\new & \!\!\! = \!\!\! & \text{\dots{} next section \dots{}} \\ + % \end{array} + % \right. + % \] + % in other words, if memory expansion took place then we update the memory size; the updated expansion cost will be computed in the following section. + % \end{enumerate} +\end{enumerate} diff --git a/mxp/in_bounds/expansion_flag.tex b/mxp/in_bounds/expansion_flag.tex new file mode 100644 index 0000000..d59e44e --- /dev/null +++ b/mxp/in_bounds/expansion_flag.tex @@ -0,0 +1,41 @@ +\begin{enumerate} + \item \mexpEvent{} is a counter-constant binary column; we ask that $\mexpEvent{} = 1$ \emph{iff} $\maxOffset > \memSize$; the following constraints ensure this: + \begin{enumerate} + \item \If $\ct_i = 0$ \Then $\expAcc_i = \expByte_i$ + \item \If $\ct_i \neq 0$ \Then $\expAcc_i = 256 \cdot \expAcc_{i-1} + \expByte_i$ + \item \If $\ct_i = 2$ \Then + \begin{enumerate} + \item \If $\mexpEvent_{i} = 1$: + \[ + \expAcc_{i} = \maxOffset_{i} - \memSize_{i} - 1 + \] + \item \If $\mexpEvent_{i} = 0$: + \[ + \expAcc_{i} = \memSize_{i} - \maxOffset_{i} + \] + \end{enumerate} + In other words when $\ct_i = 2$: + \[ + \expAcc_{i} + = + \big(\maxOffset_{i} - \memSize_{i}\big)\cdot(2\cdot\mexpEvent_i - 1) + - + \mexpEvent_i. + \] + \end{enumerate} + \item \If $\mexpEvent_i = 0$ \Then + \[ + \begin{cases} + \memSize_{i}\new = \memSize_{i}, \\ + \expCost_{i}\new = \expCost_{i}, + \end{cases} + \] + \item \If $\mexpEvent_i = 1$ \Then + \[ + \begin{cases} + \memSize_{i}\new = \memSize_{i}, \\ + \expCost_{i}\new = \text{compute the updated expansion cost in the following section \dots{}} + \end{cases} + \] + $\memSize_{i}\new = \maxOffset_{i}$ +\end{enumerate} diff --git a/mxp/in_bounds/gas_cost.tex b/mxp/in_bounds/gas_cost.tex new file mode 100644 index 0000000..97b1e08 --- /dev/null +++ b/mxp/in_bounds/gas_cost.tex @@ -0,0 +1,23 @@ +\[ + \boxed{\text{All constraints in this subsection further assume that } + \left\{ + \begin{array}{lcl} + \ct_{i} & \!\!\! = \!\!\! & \ssmallMO \\ + \mxpx_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right.} +\] +Having settled $\expCost\new$ we are now in position to settle the gas expansion cost: +\[ + \left\{ \begin{array}{lcl} + %\decMxpType{4}_{i} \cdot + \mxpQuadGas_{i} & = & \Big[ \expCost\new_{i} - \expCost_{i} \Big] \vspace{2mm} \\ + \mxpLinGas_{i} & = & \Big[ \decByteCost_{i} \cdot \sizeLo{1}_{i} + \decWordCost_{i} \cdot \acc{W}_{i} \Big] \\ + \end{array} \right. +\] +We now specify \gasMxp{}: +\begin{enumerate} + \item \If $\INST_{i} \neq \inst{RETURN}$ \Then \( \gasMxp_{i} = \mxpQuadGas_{i} + \mxpLinGas_{i} \) + \item \If $\INST_{i} = \inst{RETURN}$ \Then \( \gasMxp_{i} = \mxpQuadGas_{i} + \codeDeployment_{i} \cdot \mxpLinGas_{i} \) +\end{enumerate} +\saNote{} $\decByteCost$ and $\decWordCost$ are zero for instructions that don't incur linear byte/word costs. diff --git a/mxp/in_bounds/intro.tex b/mxp/in_bounds/intro.tex new file mode 100644 index 0000000..e69de29 diff --git a/mxp/in_bounds/max_offset_prefixes.tex b/mxp/in_bounds/max_offset_prefixes.tex new file mode 100644 index 0000000..e69de29 diff --git a/mxp/in_bounds/no_update.tex b/mxp/in_bounds/no_update.tex new file mode 100644 index 0000000..15039bb --- /dev/null +++ b/mxp/in_bounds/no_update.tex @@ -0,0 +1,20 @@ +\[ + \boxed{\text{All constraints in this subsection further assume that } + \left\{ + \begin{array}{lcl} + \ct_{i} & \!\!\! = \!\!\! & \ssmallMO \\ + \mxpx_{i} & \!\!\! = \!\!\! & 0 \\ + \mexpEvent_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right.} +\] +In this case we impose +\[ +\left\{ +\begin{array}{lcl} + \memSize_{i}\new & \!\!\! = \!\!\! & \memSize_{i}, \\ + \expCost_{i}\new & \!\!\! = \!\!\! & \expCost_{i}, \\ +\end{array} +\right. +\] +In other words: if no memory expansion took place then $\memSize$ and $\expCost$ don't change. \ No newline at end of file diff --git a/mxp/in_bounds/update.tex b/mxp/in_bounds/update.tex new file mode 100644 index 0000000..a3e4619 --- /dev/null +++ b/mxp/in_bounds/update.tex @@ -0,0 +1,81 @@ +\[ + \boxed{\text{All constraints in this subsection further assume that } + \left\{ + \begin{array}{lcl} + \ct_{i} & \!\!\! = \!\!\! & \ssmallMO \\ + \mxpx_{i} & \!\!\! = \!\!\! & 0 \\ + \mexpEvent_{i} & \!\!\! = \!\!\! & 1\\ + \end{array} + \right.} +\] +We compute the updated expansion cost. The following constraints apply \emph{iff} $\mexpEvent = 1$ in the current counter-cycle. +\begin{enumerate} + % \item $\qOffsetOne$ is counter-constant; + % \item $\qOffsetTwo$ is counter-constant; + % \item \If $\mexpEvent_{i} = 1$: +% \item $\acc{A}$ accumulates the bytes of $\lceil \memSize\new_{i} / 32 \rceil$: +% \[ +% \left\{ +% \begin{array}{lclr} +% \memSize\new_{i} & \!\!\! = \!\!\! & 32 \cdot \acc{A}_{i} - \byteCol{7}_{i} \\ +% \byteCol{7}_{i - 1} & \!\!\! = \!\!\! & \byteCol{7}_{i} + (256 - 32) & (1) \\ +% \end{array} +% \right. +% \] +% The bytehood constraint on $\byteCol{7}$ and $(1)$ imply that $\mathtt{r} := \byteCol{7}_{i} \in\{0,1,\dots,31\}$. This verifies eq.~(\ref{eq: euclidean division by 32}). + \item We impose $\memSize_{i}\new = \acc{A}_{i}$ + \item $\acc{Q}$ accumulates the first $\ssmall{}$ bytes of the euclidean division of $\acc{A}_{i}^2$ by $512$: + \[ + \left\{ + \begin{array}{lcl} + \label{eq: euclidean division by 512 in constraints} + \tag{$\bigstar$} + \acc{A}_{i} \cdot \acc{A}_{i} + & \!\!\! = \!\!\! & + 512 \cdot + \Big[ \acc{Q}_{i} + 256^{\ssmall} \cdot \byteCol{QQ}_{i-2} + 256^{\ssmall + 1} \cdot \byteCol{QQ}_{i-3} \Big] \vspace{1mm} \\ + & & ~ + \, 256 \cdot \byteCol{QQ}_{i - 1} + \byteCol{QQ}_{i} \vspace{2mm} \\ + \multicolumn{3}{l}{\byteCol{QQ}_{i - 1} \cdot ( 1 - \byteCol{QQ}_{i - 1} ) = 0} \\ + \end{array} + \right. + \] + \item We settle $\expCost\new$: + \[ + \begin{array}{lcl} + \expCost\new_{i} & = & G_{\text{mem}}\cdot \acc{A}_{i} \vspace{2mm}\\ + & & \quad + \Big[ \acc{Q}_{i} + 256^{\ssmall} \cdot \byteCol{QQ}_{i-2} + 256^{\ssmall + 1} \cdot \byteCol{QQ}_{i-3} \Big] + \end{array} + \] +\end{enumerate} +We provide some explanatory details regarding equations~(\ref{eq: euclidean division by 512 in constraints}). What is being verified is the following +\[ +\left\{ +\begin{array}{lclr} + \acc{A}_{i}^2 & \!\!\! = \!\!\! & 512 \cdot \mathtt{q'} + \mathtt{r'} & (4) \vspace{2mm} \\ + %%%%%%%%%%%%%%%%%%%%%%%% + \mathtt{q'} & \!\!\! := \!\!\! & \acc{Q}_{i} + 256^{\ssmall} \cdot \mathtt{b}_{4} + 256^{\ssmall + 1} \cdot \mathtt{b}_{5} & (3) \\ + \mathtt{r'} & \!\!\! := \!\!\! & 256 \cdot \epsilon + \mathtt{b} & (2) \\ + %\multicolumn{3}{l}{\epsilon^2 = \epsilon} & (1)\vspace{2mm} \\ + \epsilon^2 & \!\!\! = \!\!\! & \epsilon & (1) \vspace{2mm} \\ + %%%%%%%%%%%%%%%%%%%%%%%% + \mathtt{b}_{4} & \!\!\! := \!\!\! & \byteCol{QQ}_{i-2} \\ + %%%%%%%%%%%%%%%%%%%%%%%% + \mathtt{b}_{5} & \!\!\! := \!\!\! & \byteCol{QQ}_{i-3} \\ + %%%%%%%%%%%%%%%%%%%%%%%% + \epsilon & \!\!\! := \!\!\! & \byteCol{QQ}_{i - 1} \\ + %%%%%%%%%%%%%%%%%%%%%%%% + \mathtt{b} & \!\!\! := \!\!\! & \byteCol{QQ}_{i} \\ +\end{array} +\right. +\] +$(1)$ verifies that $\epsilon := \byteCol{QQ}_{i - 1}$ is a bit; +$(2)$ verifies that $0\leq \mathtt{r'} < 512$; +$(3)$ verifies that $\mathtt{q'}$ is a $6$-byte integer; +$(4)$ verifies the euclidean division of $\acc{A}_{i}^2$ by $512$; +\iffalse +the byte $\mathtt{b}_{4} := \byteCol{QQ}_{i-2}$ and $\mathtt{b}_{5} := \byteCol{QQ}_{i-3}$ are the most significant bytes of the 6 byte integer +$\texttt{q'} := \lfloor \acc{A}_{i}^2 / 512 \rfloor$. +$\qOffsetTwo_{i}$\footnote{the other bytes being, in increasing order of significance: $\qOffsetTwoByte_{i-2}$, $\qOffsetTwoByte_{i - 1}$ and $\qOffsetTwoByte_{i}$}; +$(3)$ verifies that $256\cdot\epsilon + \mathtt{b}$ is the remainder of the euclidean division of $(1 + \qOffsetOne_{i})^2$ by $512$, where $\mathtt{b} := \byteCol{QQ}_{i}$; +\fi +together they verify Eq.~(\ref{eq: euclidean division by 512}). \ No newline at end of file diff --git a/mxp/instructions.tex b/mxp/instructions.tex new file mode 100644 index 0000000..3224144 --- /dev/null +++ b/mxp/instructions.tex @@ -0,0 +1,54 @@ +The memory expansion module is triggered by those instructions that raise the (instruction decoded) memory expansion flag (i.e. $\decMxpFlag$). +The Hub keeps a tally of the number of (potentially) memory expanding operations: the $\mxpStamp$ column. +This stamp grows by 1 with every (potentially) memory expanding operation. +The present module imports this stamp along with the instruction and appropriate parameters. Importing the stamp is necessary as the order of operations is important in assessing an instruction's memory expansion cost. + +Memory expanding instructions fall into 5 \textbf{memory expansion types}, each requiring specialized computations. These categories are identified using flags which are instruction decoded in the present module according to the following table: + +\begin{figure}[h!] + \[ + \def\zero{{\color{gray!60}\bm{0}}} + \def\one{{\cellcolor{\romCol} \bm{1}}} + \renewcommand{\arraystretch}{1.5} + \begin{array}{|l|c|c|c|c|c|c|c|} + \hline + \INST & \decMxpType{1} & \decMxpType{2} & \decMxpType{3} & \decMxpType{4} & \decMxpType{5} & \decWordCost & \decByteCost \\ \hline\hline + 0 & \zero & \zero & \zero & \zero & \zero & \zero & \zero \\ \hline + \inst{MSIZE} & \one & \zero & \zero & \zero & \zero & \zero & \zero \\ \hline + \inst{MLOAD} & \zero & \one & \zero & \zero & \zero & \zero & \zero \\ + \inst{MSTORE} & \zero & \one & \zero & \zero & \zero & \zero & \zero \\ \hline + \inst{MSTORE8} & \zero & \zero & \one & \zero & \zero & \zero & \zero \\ \hline + \inst{CREATE} & \zero & \zero & \zero & \one & \zero & \zero & \zero \\ + \inst{CREATE2} & \zero & \zero & \zero & \one & \zero & {\cellcolor{\ramCol} G_{\text{keccak256word}}} & \zero \\ + \inst{RETURN} & \zero & \zero & \zero & \one & \zero & \zero & {\cellcolor{\ramCol} G_{\text{codedeposit}}} \\ + \inst{REVERT} & \zero & \zero & \zero & \one & \zero & \zero & \zero \\ + \inst{LOG}\text{-type} & \zero & \zero & \zero & \one & \zero & \zero & {\cellcolor{\ramCol} G_{\text{logdata}}} \\ + \inst{SHA3} & \zero & \zero & \zero & \one & \zero & {\cellcolor{\ramCol} G_{\text{keccak256word}}} & \zero \\ + \inst{COPY}\text{-type} & \zero & \zero & \zero & \one & \zero & {\cellcolor{\ramCol} G_{\text{copy}}} & \zero \\ \hline + \inst{CALL}\text{-type} & \zero & \zero & \zero & \zero & \one & \zero & \zero \\ \hline + \end{array} + \] + \caption{Where + $G_{\text{keccak256word}} = 6$, + $G_{\text{copy}} = 3$, + $G_{\text{codedeposit}} = 200$, + $G_{\text{logdata}} = 8$; + \inst{LOG0}-\inst{LOG4} are the + \inst{LOG}\text{-type} instructions; + \inst{CODECOPY}, + \inst{EXTCODECOPY}, + \inst{CALLDATACOPY} and + \inst{RETURNDATACOPY} + are the \inst{COPY}\text{-type} instructions; + \inst{CALL}, + \inst{CALLCODE}, + \inst{STATICCALL} and + \inst{DELEGATECALL} + are the \inst{COPY}\text{-type} instructions.} +\end{figure} + +The \zkEvm{} considers \inst{MSIZE} a \textbf{type 1 instruction} (the only of its kind.) It incurs no memory expansion cost and only retrieves the value of the $\memSize$ column. \textbf{Type 2 and 3 instructions} are those instructions whose memory expansion cost depends purely on an \emph{offset} i.e. instructions with an implicit \emph{size} parameter (32 for \textbf{type 2} and 1 for \textbf{type 3} depending on the instruction): +\textbf{Type 4 instructions} compute memory expansion in terms on a a single \emph{offset} and \emph{size} pair. +\textbf{Type 5 instructions} are \inst{CALL}-type instruction. These compute memory expansion in terms on \emph{two} pairs of \emph{offset} and \emph{size} parameters: (\emph{a}) the offset and size defining the call data of the call (\emph{b}) the offset and size defining the memory segment where the callee might write (part of) its return data. The zk-evm needs to determine the maximum value memory expansion cost between the two. The relevant instructions are + +The present module deals with memory expansion uniformly. To that effect it first recognizes trivial cases: either when offsets or sizes are far too large or when no memory expansion \emph{can} happen since relevant sizes are zero ($\noop = 1$). In case offsets and sizes satisfy both requirements it produces the maximal offset(s) that may be written to or read from. If there are two sets of offsets diff --git a/mxp/intro.tex b/mxp/intro.tex new file mode 100644 index 0000000..3ad76f6 --- /dev/null +++ b/mxp/intro.tex @@ -0,0 +1,23 @@ +The \textbf{memory expansion module} serves several different purposes: +(\emph{a}) +it tracks and updates, when appropriate, ``the active number of words in memory (counting continuously from position $0$)'' i.e. $\bm{\mu}_\text{i}$ in the Ethereum Yellow Paper \ob{TODO: add reference to the spec}) +\[ + \memSize\rightsquigarrow\memSize\new +\] +(\emph{b}) +it tracks and updates, when appropriate, the associated memory cost i.e. $C_\text{mem}(\bm{\mu}_\text{i})$ in the Ethereum Yellow Paper \ob{TODO: add reference to the spec}, +\[ + \expCost\rightsquigarrow\expCost\new +\] +(\emph{c}) +it justifies the $\mxpX$ ($\mxpx$ for short) i.e. it recognizes grossly out of bounds memory operations +(\emph{d}) +it computes, when necessary, the quadratic memory expansion cost +(\mxpQuadGas) associated with certain memory expanding instructions as well as any ``linear costs'' that the instruction may incur +(\mxpLinGas). + +\saNote{} We remind the reader that what we have dubbed \mxpxSH{} is a \emph{sub-exception} of the \oogxSH{}. It corresponds to a case where the quadratic cost of memory expansion is large enough as to produce an \oogxSH{} regardless of other extra costs that may stack on top of it. See + +\saNote{} These ``linear costs'' are either proportional to the number of bytes in a certain (input) memory range or to the minimum number of \text{evm} words needed to contain a certain (input) memory range. + +The idea behind the binary $\mxpx$ flag is simple: the hub module uses it to recognize scenarios when an out of gas exception is bound to happen; what we call ``\mxpxSH{}'' can be thought of as a refinement/subcase of the \oogxSH{} in the sense that the former is a sufficient condition to trigger the latter. diff --git a/mxp/lookup.tex b/mxp/lookup.tex new file mode 100644 index 0000000..ef709e3 --- /dev/null +++ b/mxp/lookup.tex @@ -0,0 +1,37 @@ +The present subsection describes the lookup into the \idMod{}. This lookup justifies instruction type and byte / word prices. +\begin{description} + \item[Selector:] none required; + \item[Source columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item \INST{} + \item $\decWordCost$ + \item $\decByteCost$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item $\decMxpType{1}$ + \item $\decMxpType{2}$ + \item $\decMxpType{3}$ + \item $\decMxpType{4}$ + \item $\decMxpType{5}$ + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item \INST{} + \item $\wordCost$ + \item $\byteCost$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item $\mxpType{1}$ + \item $\mxpType{2}$ + \item $\mxpType{3}$ + \item $\mxpType{4}$ + \item $\mxpType{5}$ + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/mxp/max_offsets.tex b/mxp/max_offsets.tex new file mode 100644 index 0000000..217e6a7 --- /dev/null +++ b/mxp/max_offsets.tex @@ -0,0 +1,66 @@ +This section defines maximal offsets. We define a pair of maximal offsets (even in case the instruction requires only one offset, size pair). Definitions depend on the memory expansion type. +\begin{enumerate} + \item \If $\decMxpType{2}_{i} = 1$ + \[ + \left\{ + \begin{array}{l} + \lastOffset{1}_{i} = \offsetLo{1}_{i} + (32 - 1)\\ + \lastOffset{2}_{i} = 0 \\ + \end{array} + \right. + \] + \item \If $\decMxpType{3}_{i} = 1$ + \[ + \left\{ + \begin{array}{l} + \lastOffset{1}_{i} = \offsetLo{1}_{i} + (1 - 1)\\ + \lastOffset{2}_{i} = 0 \\ + \end{array} + \right. + \] + \item \If $\decMxpType{4}_{i} = 1$ + \[ + \left\{ + \begin{array}{l} + \lastOffset{1}_{i} = \offsetLo{1}_{i} + (\sizeLo{1}_{i} - 1) \\ + \lastOffset{2}_{i} = 0 \\ + \end{array} + \right. + \] + \item \If $\decMxpType{5}_{i} = 1$ + \[ + \left\{ + \begin{array}{l} + \begin{cases} + \If \sizeLo{1}_{i} \neq 0 ~ \Then + \lastOffset{1}_{i} = \offsetLo{1}_{i} + (\sizeLo{1}_{i} - 1) \\ + \If \sizeLo{1}_{i} = 0 ~ \Then + \lastOffset{1}_{i} = 0 \\ + \end{cases} \vspace{2mm} \\ + \begin{cases} + \If \sizeLo{1}_{i} \neq 0 ~ \Then + \lastOffset{2}_{i} = \offsetLo{2}_{i} + (\sizeLo{2}_{i} - 1) \\ + \If \sizeLo{1}_{i} = 0 ~ \Then + \lastOffset{2}_{i} = 0 \\ + \end{cases} \\ + \end{array} + \right. + \] +\end{enumerate} +Let us clarify the preceding constraints. +If $\decMxpType{4} = 1$ the standing assumption $\noop = 0$ implies that $\sizeLo{1} \geq 1$. +If $\decMxpType{5} = 1$ it may happen that one of the size parameters is zero i.e. +\[ + \left\{ + \begin{array}{lclr} + 256^{\llarge} \cdot \sizeHi{1} + \sizeLo{1} + & \!\!\! = \!\!\! & \sizeLo{1} = 0 & \text{i.e. }\CDS = 0 \vspace{1mm} \\ + \qquad \OR \vspace{1mm}\\ + 256^{\llarge} \cdot \sizeHi{2} + \sizeLo{2} + & \!\!\! = \!\!\! & \sizeLo{2} = 0 & \text{i.e. }\col{RETURNDATACAPACITY} = 0 \\ + \end{array} + \right. +\] +that the \inst{CALL}-type instruction provides either no call data or no space for return data\footnote{but, given our standing assumption that $\roob = \noop = 0$, at least one or the other}.) In that case the relevant empty memory segment has no impact on the computation and we set the corresponding $\lastOffset{k}$ to $0$. Note furthermore that this prevents the edge case where one of the $\lastOffset{k}$ is accidentally set to $-1$. + +$\lastOffset{1}$ and $\lastOffset{2}$ are thus nonnegative and the sum of two $\llarge$ byte integers. They are thus $\lllarge$ byte integers. \ No newline at end of file diff --git a/mxp/memory_expansion.pdf b/mxp/memory_expansion.pdf new file mode 100644 index 0000000..175676e Binary files /dev/null and b/mxp/memory_expansion.pdf differ diff --git a/mxp/mtntop.tex b/mxp/mtntop.tex new file mode 100644 index 0000000..f86463f --- /dev/null +++ b/mxp/mtntop.tex @@ -0,0 +1,33 @@ +The binary flag $\mayTriggerNonTrivialOperation$ indicates whether a $\decMxpType{4}$ instruction has any chance of triggering the \mmuMod{} module (i.e. of touching \textsc{ram}.) +The main question is that of whether these instructions ``actually require touching \textsc{ram}''. +Note that \textbf{exceptional} instructions almost never require touching \textsc{ram}, the exception being \inst{RETURN}'s attempting to deploy bytecode starting with \texttt{0x\,EF} thus raising the \icpxSH{}\footnote{as well as \inst{CALL}'s to precompiles which cna ``fail in \textsc{ram}''; the analysis below explicitly \textbf{excludes} the memory operations that may be triggered by calls to precompiles; such \inst{CALL}'s follow a completely separate ``biphasic'' or ``first half/second half'' or ``two scenarios'' regime which is of no relevance to the present analysis} +But instructions raising the \mxpxSH{} exception \textbf{never} trigger the \mmuMod{} module. +Below we assume instructions don't raise the \mxpxSH{}. +\begin{description} + \item[$\decMxpType{1}$ operations:]\footnote{that is, \inst{MSIZE}} + \textbf{never} touch \textsc{ram} at all; + \item[$\decMxpType{2}$ operations:] + \textbf{always} touch \textsc{ram} (if \textbf{unexceptional}); + \item[$\decMxpType{3}$ operations:] + \textbf{always} touch \textsc{ram} (if \textbf{unexceptional}); + \item[$\decMxpType{5}$ operations:]\footnote{that is, \inst{CALL}-type opcodes} + \textbf{never} touch \textsc{ram} at all\footnote{}; + \item[$\decMxpType{4}$ operations:] may or may not touch \textsc{ram} depending on whether a relevant ``size paramater'' is zero or not; +\end{description} +For the \hubMod{} module to decide whether an \textbf{unexceptional} $\decMxpType{4}$ operation should trigger the \mmuMod{} it must know whether some size parameter is nonzero or not. +This information is essentially relayed to the \hubMod{} by means of the \mayTriggerNonTrivialOperation{} flag. + +We thus impose the following +\begin{enumerate} + \item \mayTriggerNonTrivialOperation{} is binary \quad (\trash) + \item \If $\decMxpType {4} _{i} = 0$ \Then $\mayTriggerNonTrivialOperation_{i} = 0$ \quad (\trash) + \item \If $\decMxpType {4} _{i} = 1$ \Then + \begin{enumerate} + \item \If $\mxpx = 1$ \Then $\mayTriggerNonTrivialOperation = 0$ + \item \If $\mxpx = 0$ \Then + \begin{enumerate} + \item \If $\sizeLo{1} = 0$ \Then $\mayTriggerNonTrivialOperation = 0$ + \item \If $\sizeLo{1} \neq 0$ \Then $\mayTriggerNonTrivialOperation = 1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/mxp/noop.tex b/mxp/noop.tex new file mode 100644 index 0000000..98a8e51 --- /dev/null +++ b/mxp/noop.tex @@ -0,0 +1,51 @@ +The present section computes the $\noop{}$ flag. Its definition is simple: a \col{noop} \emph{from the point of view of memory expansion} happens precisely when all relevant size parameters are zero. No-op dependent constraints are subordinate to $\roob{} = 0$, in other words: the value of $\noop$ matters only when $\roob{} = 0$. As such the zk-evm focuses on the low part of the size parameter(s). The ``no-operation'' check could be handled in the main execution trace, but for simplicity it is handled in the present module. +\begin{enumerate} + \item $\noop$ is binary; + \item \If $\roob_{i} = 1$ \Then $\noop_{i} = 0$ +\end{enumerate} + \saNote{}\label{mxp: noop: roob + noop is binary} It follows that $\roob + \noop$ is a boolean column. +\begin{enumerate}[resume] + \item \If $\roob_{i} = 0$ \Then + \begin{enumerate} + \item \If $\decMxpType{1}_{i} + \decMxpType{2}_{i} + \decMxpType{3}_{i} \neq 0$ \Then% + \[ + \noop_{i} = \decMxpType{1}_{i} + \] + \item \If $\decMxpType{4}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \If \sizeLo{1}_{i} = 0 ~ \Then \noop_{i} = 1 \\ + \If \sizeLo{1}_{i} \neq 0 ~ \Then \noop_{i} = 0 \\ + \end{array} + \right. + \] + \item \If $\decMxpType{5}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \If \Big( \sizeLo{1}_{i} = 0 ~ \et \sizeLo{2}_{i} = 0 \Big) ~ \Then \noop_{i} = 1 \\ + \If \sizeLo{1}_{i} \neq 0 ~ \Then \noop_{i} = 0 \\ + \If \sizeLo{2}_{i} \neq 0 ~ \Then \noop_{i} = 0 \\ + \end{array} + \right. + \] + \end{enumerate} +\end{enumerate} +\saNote{} The constraints from section~\ref{mxp: sec: noop} and section~\ref{mxp: sec: counter-constancies} imply that \noop{} is counter-constant. + +We further settle the expected behaviour in case of a (from the point of view of the memory expansion module) \col{noop}. No memory expansion happens, memory size remains the same. The associated constraints are thus: +\begin{enumerate} + \item \If $\noop_{i} = 1$ \Then +\[ + \left\{ + \begin{array}{lcl} + \mxpQuadGas_{i} & \!\!\! = \!\!\! & 0 \\ + \mxpLinGas_{i} & \!\!\! = \!\!\! & 0 \\ + \memSize_{i}\new & \!\!\! = \!\!\! & \memSize_{i} \\ + \expCost\new_{i} & \!\!\! = \!\!\! & \expCost_{i} \\ + \end{array} + \right. +\] +\end{enumerate} +Recall that \inst{MSIZE} is the only \textbf{type 0} instruction. The constraints in that case push the memory size onto the stack. diff --git a/mxp/offset_bounds.tex b/mxp/offset_bounds.tex new file mode 100644 index 0000000..56d7c89 --- /dev/null +++ b/mxp/offset_bounds.tex @@ -0,0 +1,37 @@ + +The memory expansion cost is therefore, with $G_\textrm{mem} = 3$: +\[ + C_\textrm{mem} = + G_\textrm{memory}\cdot \mathtt{q} + + + \mathtt{q'} +\] +\iffalse +where $G_\textrm{mem} = 3$ and the byte at byte offset $\offset{}$ is contained in the $a^{th}$ EVM word of RAM. In other words +\[ + a + = + 1 + + + \left\lfloor + \offset{}/32 + \right\rfloor + = + \left\lceil + (\offset{}+1)/32 + \right\rceil +\] +In other words, if we represent the byte array of RAM as below +\[ + \begin{array}{|c||c|c|c|c||c|c|c|c||c|c|c|c||c} + \hline + \offset & 0 & 1 & \cdots & 31 & 32 & 33 & \cdots & 63 & 64 & 65 & \cdots & 95 & \cdots\\ + \hline + \col{EVM WORD}& \multicolumn{4}{c||}{a = 1} + & \multicolumn{4}{c||}{a = 2} + & \multicolumn{4}{c||}{a = 3} + \\ + \hline + \end{array} +\] +\fi \ No newline at end of file diff --git a/mxp/oob.tex b/mxp/oob.tex new file mode 100644 index 0000000..4e91a74 --- /dev/null +++ b/mxp/oob.tex @@ -0,0 +1 @@ +This subsection tackles the behaviour of the module when offsets are out of bounds \ No newline at end of file diff --git a/mxp/out_of_bounds/intro.tex b/mxp/out_of_bounds/intro.tex new file mode 100644 index 0000000..a8f39cf --- /dev/null +++ b/mxp/out_of_bounds/intro.tex @@ -0,0 +1,30 @@ +This subsection is about justifying raising the $\mxpx$ flag if one (at least) of the max offsets isn't a $\ssmall{}$-byte integer. +\[ + \boxed{\text{All constraints in this subsection further assume that } + \left\{ \begin{array}{lcl} + \ct_{i} & \!\!\! = \!\!\! & \lllargeMO \\ + \mxpx_{i} & \!\!\! = \!\!\! & 1 \\ + \end{array} \right.} +\] +We impose +\[ + \Big(\lastOffset{1}_{i} - \big( 256^{\ssmall} + \acc{1}_{i} \big) \Big) + \cdot + \Big(\lastOffset{2}_{i} - \big( 256^{\ssmall} + \acc{2}_{i} \big) \Big) + = + 0. +\] +in other words we impose that one (or both) of the equalities below hold: +\[ + \left[ \begin{array}{c} + \text{Confirmation} \\ + \text{of }\mxpx \equiv 1 \\ + \end{array} \right] + \iff + \left\{ \begin{array}{lcl} + \lastOffset{1} & \!\!\! = \!\!\! & 256^{\ssmall} + \acc{1} \\ + \qquad\Or \\ + \lastOffset{2} & \!\!\! = \!\!\! & 256^{\ssmall} + \acc{2} \\ + \end{array} \right. +\] +In other words that one or both of $\lastOffset{1}$ or $\lastOffset{2}$ are $\geq 256^{\ssmall}$. diff --git a/mxp/out_of_bounds/max_offset_prefixes.tex b/mxp/out_of_bounds/max_offset_prefixes.tex new file mode 100644 index 0000000..e69de29 diff --git a/mxp/roob.tex b/mxp/roob.tex new file mode 100644 index 0000000..120ec26 --- /dev/null +++ b/mxp/roob.tex @@ -0,0 +1,101 @@ +The present section specifies the behaviour of the binary $\roob$. This binary flag should turn on \emph{if and only if} offset(s) and / or size(s) are $\ROOB$. Its behaviour depends on the memory expansion type of the instruction at hand. +\begin{enumerate} + \item $\roob$ is binary (\trash); + \item \If $\decMxpType{1}_{i} = 1$ \Then $\roob_{i} = 0$; + \item \If \Big($\decMxpType{2}_{i} + \decMxpType{3}_{i} \neq 0$\Big) \Then + \[ + \left\{ + \begin{array}{l} + \If \offsetHi{1}_{i} \neq 0 ~ \Then \roob_{i} = 1 \\ + \If \offsetHi{1}_{i} = 0 ~ \Then \roob_{i} = 0 \\ + \end{array} + \right. + \] + \item \If $\decMxpType{4}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \If \sizeHi{1}_{i} \neq 0 ~ \Then \roob_{i} = 1 \vspace{2mm} \\ + \If \offsetHi{1}_{i} \cdot \sizeLo{1}_{i} \neq 0 ~ \Then \roob_{i} = 1 \vspace{2mm} \\ +% \If \roob_{i} = 1 ~ \Then \Big(\isValHi{3}_{i} \neq 0 ~ \OR \isValHi{1}_{i} \cdot \isValLo{3}_{i} \neq 0\Big) \vspace{2mm} \\ + \If + \left\{ + \begin{array}{lr} + \sizeHi{1}_{i} = 0 & \et \\ + \offsetHi{1}_{i} \cdot \sizeLo{1}_{i} = 0 + \end{array} + \right\} + \Then \roob_{i} = 0 +% \If \roob_{i} = 0 ~ \Then +% \begin{cases} +% \isValHi{3}_{i} = 0 & \et \\ +% \isValHi{1}_{i} \cdot \isValLo{3}_{i} = 0 \\ +% \end{cases} \\ + \end{array} + \right. + \] + In other words, the desired behaviour is + \[ + \roob_{i} = 1 \iff + \left\{ + \begin{array}{l} + \sizeHi{1}_{i} \neq 0 \\ + \qquad \OR \\ + \Big( \offsetHi{1}_{i} \neq 0 ~ \et \sizeLo{1}_{i} \neq 0 \Big) \\ + \end{array} + \right. + \] + \item \If $\decMxpType{5}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \If \sizeHi{1}_{i} \neq 0 + ~ \Then \roob_{i} = 1 \vspace{2mm} \\ + \If \sizeHi{2}_{i} \neq 0 + ~ \Then \roob_{i} = 1 \vspace{2mm} \\ + \If \offsetHi{1}_{i} \cdot \sizeLo{1}_{i} \neq 0 + ~ \Then \roob_{i} = 1 \vspace{2mm} \\ + \If \offsetHi{2}_{i} \cdot \sizeLo{2}_{i} \neq 0 + ~ \Then \roob_{i} = 1 \vspace{2mm} \\ +% \If \roob_{i} = 1 ~ \Then +% \left\{ +% \begin{array}{lr} +% \sizeHi{1}_{i} \neq 0 & \OR \\ +% \offsetHi{1}_{i} \cdot \isValLo{3}_{i} \neq 0 & \OR \\ +% \sizeHi{2}_{i} \neq 0 & \OR \\ +% \offsetHi{2}_{i} \cdot \isValLo{4}_{i} \neq 0 \\ +% \end{array} +% \right. +% \vspace{2mm} \\ + \If + \left\{ + \begin{array}{lr} + \sizeHi{1}_{i} = 0 & \et \\ + \sizeHi{2}_{i} = 0 & \et \\ + \offsetHi{1}_{i} \cdot \sizeLo{1}_{i} = 0 & \et \\ + \offsetHi{2}_{i} \cdot \sizeLo{2}_{i} = 0 \\ + \end{array} + \right\} \Then \roob_{i} = 0 \\ + \end{array} + \right. + \] + \ob{TODO: can we replace the first two conditions with $\redm{\sizeHi{1}_{i} + \sizeHi{2}_{i} = 0}$ ? The reason being that these are stack values and those should always be 16B integers.} + In other words, the desired behaviour is + \[ + \roob_{i} = 1 \iff + \left\{ + \begin{array}{lr} + \sizeHi{1}_{i} \neq 0 & \OR \\ + \sizeHi{2}_{i} \neq 0 & \OR \\ + \Big( \offsetHi{1}_{i} \neq 0 ~ \et \sizeLo{1}_{i} \neq 0 \Big) & \OR \\ + \Big( \offsetHi{2}_{i} \neq 0 ~ \et \sizeLo{2}_{i} \neq 0 \Big) & \OR \\ + \end{array} + \right. + \] +\end{enumerate} + +We provide some context. +If $\decMxpType{1}_{i} = 1$ then the instruction is $\inst{MSIZE}$ which takes no size or offset arguments and can't provoke an out of bounds error. Thus $\roob_{i} = 0$ automatically. +If $\decMxpType{2}_{i} = 1$ or $\decMxpType{3}_{i} = 1$ then the instruction is one of \inst{MLOAD}, \inst{MSTORE}, \inst{MSTORE8} and takes a single offset parameter. Offsets that are greater than 4 bytes may never occur because of gas related expenses, let alone offsets that occupy $>\llarge$ bytes (as witnessed by $\isValHi{1} \neq 0$.) +If $\decMxpType{4}_{i} = 1$ the instruction takes \col{offset} and \col{size} arguments. For such an instruction to be ridiculously out of bounds either its size parameter has to be huge (as witnessed by $\sValHi{3}\neq0$) or its offset parameter has to be huge and its size parameter nonzero (as witnessed by $\sValHi{1}\neq0$ and $\sVal{3}\neq0$.) +If $\decMxpType{5}_{i} = 1$ is entirely analoguous to the $\decMxpType{4}$ case except that two $(\col{offset}, \col{size})$ pairs are required. diff --git a/mxp/standing_hyp.tex b/mxp/standing_hyp.tex new file mode 100644 index 0000000..65de65b --- /dev/null +++ b/mxp/standing_hyp.tex @@ -0,0 +1,14 @@ +\[ + \boxed{% + \text{All constraints in section~\ref{mxp: sec: specialized constraints} and all its subsections assume }% + \begin{cases} + \mxpStamp_{i} \neq 0 \\ + \noop_{i} + \roob_{i} = 0 \\ + \end{cases} + } +\] +Different subsections may impose further constraints. These stack onto the standing hypothesis (but not onto one another.) + +\saNote{} Given that $\noop + \roob$ is binary (see note~\ref{mxp: noop: roob + noop is binary}) one may replace the precondition +``$\noop_{i} + \roob_{i} = 0$'' with +``$\noop_{i} + \roob_{i} \neq 1$'' in the implementation. diff --git a/mxp/type0.tex b/mxp/type0.tex new file mode 100644 index 0000000..e69de29 diff --git a/mxp/ynmo.tex b/mxp/ynmo.tex new file mode 100644 index 0000000..85138ab --- /dev/null +++ b/mxp/ynmo.tex @@ -0,0 +1,32 @@ +The binary flag $\ynmo$ indicates whether a $\decMxpType{4}$ instruction has any chance of triggering the \mmuMod{} module (i.e. of touching \textsc{ram}.) +The main question is that of whether these instructions ``actually require touching \textsc{ram}''. +Note that \textbf{exceptional} instructions almost never require touching \textsc{ram}, the exception being \inst{RETURN}'s attempting to deploy bytecode starting with \texttt{0x\,EF} thus raising the \icpxSH{}\footnote{as well as \inst{CALL}'s to precompiles which cna ``fail in \textsc{ram}''; the analysis below explicitly \textbf{excludes} the memory operations that may be triggered by calls to precompiles; such \inst{CALL}'s follow a completely separate ``biphasic'' or ``first half/second half'' or ``two scenarios'' regime which is of no relevance to the present analysis} +But instructions raising the \mxpxSH{} exception \textbf{never} trigger the \mmuMod{} module. +Below we assume instructions don't raise the \mxpxSH{}. +\begin{description} + \item[$\decMxpType{1}$ operations:]\footnote{that is, \inst{MSIZE}} + \textbf{never} touch \textsc{ram} at all; + \item[$\decMxpType{2}$ operations:] + \textbf{always} touch \textsc{ram} (if \textbf{unexceptional}); + \item[$\decMxpType{3}$ operations:] + \textbf{always} touch \textsc{ram} (if \textbf{unexceptional}); + \item[$\decMxpType{5}$ operations:]\footnote{that is, \inst{CALL}-type opcodes} + \textbf{never} touch \textsc{ram} at all\footnote{}; + \item[$\decMxpType{4}$ operations:] may or may not touch \textsc{ram} depending on whether a relevant ``size paramater'' is zero or not; +\end{description} +For the \hubMod{} module to decide whether an \textbf{unexceptional} $\decMxpType{4}$ operation should trigger the \mmuMod{} it must know whether some size parameter is nonzero or not. +This information is essentially relayed to the \hubMod{} by means of the \ynmo{} flag. + +We thus impose the following +\begin{enumerate} + \item \ynmo{} is binary \quad (\trash) + \item \If $\decMxpType{4}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\mxpx = 1$ \Then $\ynmo = 0$ + \item \If $\mxpx = 0$ \Then + \begin{enumerate} + \item \If $\sizeLo{1} = 0$ \Then $\ynmo = 0$ + \item \If $\sizeLo{1} \neq 0$ \Then $\ynmo = 1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/notes/2023.12.22.md b/notes/2023.12.22.md new file mode 100644 index 0000000..fe202bd --- /dev/null +++ b/notes/2023.12.22.md @@ -0,0 +1,20 @@ +# 2023.12.22 + +## Alex Update + +Worked on BIN module and SIGNEXTEND. +No issues found in BIN module. +Version: the latest version of the spec (with IS_AND, ...) +But for SIGNEXTEND there is an issue (SMALL isn't counter-constant) +BYTE done in terms of bug-hunting pov. + +BUG-hunting: +- make sure there are no issues +- bounded model checking with extra assumptions +- it's a kind of "weak proof" +- make assumptions that are "obvious" to people but would actually require a formal proof that is long +- not necessary to verify stuff like "our byte extraction method coincides with a computer's division by the appropriate power of 256 followed by taking modulo" + +SMT solver still has issues reasoning about non linear stuff. + +Would like to start looking at the hub in toy cases (e.g. single instruction bytecode) diff --git a/notes/2023_11_24.md b/notes/2023_11_24.md new file mode 100644 index 0000000..bb18640 --- /dev/null +++ b/notes/2023_11_24.md @@ -0,0 +1,47 @@ +# Friday call + +## Olivier + +Reworked the specifications² + +## Alex + +Started work on several modules +- MOD +- BIN +- SHF +- WCP +Decided to implement inductive style approach with simplified module. First case: ADD module. Checking inductive properties and thus for arbitrary traces. +Cehck some properties for every row and then checking backwards inductive properties when the trace is built. +Constraints that are nonlinear such as STAMP increments taht are the vanishing of a product are hard to check for SMT solver. + +For the induction he can set the number of rows to use in the inductive step. Doing it with $k=1$ atm. $k=17$ should also be doable but would take time. +TRM module has done similar work. + +Issues: shift operations means also propagating bytehood constraints for instance. +So for instance you have to say that binary constraints are held for 16 rows. + +With the ADD module he implements the k=1 inductive approach. +In WCP it's the k=16 approach. + +Questions: +- properties of columns ? + - Why can you not specify that a column should contain only bytes / bits ? + - if you have 2 rows and have the associated constraints, you still have the shifting operations (e.g. in WCP you still have shifts by large amounts) + - we could change the spec to do bit accumulation in those cases (e.g. WCP) but Alex says that it's not a big issue. + +Alex has some extension of Corset to handle comparisons and implications. +Contains essentially the same data as the Corset constraints but is easier. +"Summaries" where for instance we specify that `0 <= CT < 16` or so, and similarly for ranges of byte accumulation +These summaries make it quicker to do the checking (backwards and forwards, didn't get for which) + +One problem: would like to be able to write shifts by stuff like `(- 16 CT)` which can't be done in the polynomial side + +INDUCTIVE APPROACH Is the winner (with summaries i.e. loop invariants and intermediate lemmas). It's so fast for checking, so SPEED. And we can infer these properties automatically in the future. This gives us inductive proofs for arbitrary traces. And it can give you COUNTER-EXAMPLES. Can also generate ISABEL code (which has integration with z3, while Dafny has not) +It may pay off in the future if we use this tool extensively to have a pathway to corset inspect and corset traces. + +BOUNDED MODEL CHECKING is slow (in practice it does not work with larger modules) + +Corset semantics and proving +"Is this approach (Python script) sound ? I.e. what can we deduce from this script succeeding" +ISABEL gives you more confidence in the result and in the semantics ... whatever that means diff --git a/notes/2024 b/notes/2024 new file mode 100644 index 0000000..e69de29 diff --git a/notes/2024.01.12.md b/notes/2024.01.12.md new file mode 100644 index 0000000..02da418 --- /dev/null +++ b/notes/2024.01.12.md @@ -0,0 +1,67 @@ +2024.01.12 notes + +Olivier: +- implemnted some optimizations + * variable length instructions in WCP, ADD and BIN + * new EUC module to offload work from the MMU +- MMU + * reworking so that none of the computations are done _in situ_ +- HUB + * some precompiles are finally done (SHA2, RIPEMD) others are wip (IDENTITY, MODEXP) + * remaining ones will follow + +Alex: +===== + +experimenting with new approach +uninterpreted functions <=> skolemization technique +instead of existential quantifier you introduce new constant +e.g. for binary operations you have bitwise operations +avoids introducing quantifiers (uneasy with SMT) +instantiation requires new axioms +(for the new constants) + +benefits: +uninterpreted functions can help with byte/bit decompositions for e.g. the BIN module + +solution that avoids bit vectors +currently we use unbounded integers for everything +Sometimes we know that a cell is small (<16 or some power of 2) +SMT solvers have native support of such numbers (bit vectors) +different type of variable +bit operations / shifting will be much more efficient like so + + +Is this change for a particular module ? +- will benefit everywhere +- BIN, WCP or SHF: + We want to select a particular byte in there to do work with it + For SMT solver this is a problem (nonlinear) and it can struggle + +we can say we have a byte extraction function that gets byte + index of interest +instead of implementing it with division and remainder we can describe it axiomatically + +Question: +- how do we connect the two ? axiomatic approach vs implementation as constraints ? + +Yes, requires equivalence proof. + +It's basically a black box (opaque) that makes the SMT solving easier. + +We have similar patterns (e.g. extract particular bytes) in many places. + +Joanne: +======= + +variation of structure leading to simplification of structure +Looking at MXP module soon but first wants to look at variable length instructions + + +2023 recap: +=========== + +good few months. +Simpler than testing. +Quick updates for WCP/ADD etc spec updates with existing framework for Alex. +The problem is difficult from the reasoning pov so we need lemmas, but fewer than expected +Better coverage than just tests, too. diff --git a/notes/2024.01.19.md b/notes/2024.01.19.md new file mode 100644 index 0000000..6f318c6 --- /dev/null +++ b/notes/2024.01.19.md @@ -0,0 +1,54 @@ +# Alex + +- Working on EUC and verification of it +- Maybe some constraints wrt CT_MAX are useless ? +- Easy to implement an dinvestigate performance issues +- Bounded Model chencking does run in to perf issues +- E.g. because if you have 8 rows you could have 7 padding rows & one row computation +- Or 1 padding row and 7 computation row or +- 1 padding row and 2 computations (3 rows + 4 rows) +- Etc. + +Conclusion: there was a mistake in the translation of the spec to Lisp. + +# Joanne + +- Model Checking vs Fully verified +- Looking at changes in the WCP module (var. length instruction) +- Working on further automation + +# Planning + +- Alex: + - [[working on an instruction level rather than on a module level]] + - preparation for working on a transaction level + - a single instruction can trigger many modules + - main problem: SMT solver issues + - model checking + backward/forward induction is a good model (e.g. produces counter-examples) + - issue: glueing stuff together in an ``proving instructions'' approach + - Lean auto feature (which attempts to prove stuff on its own) with various SMT backends (e.g. z3) + - Lean may be useful in our context + - replace Python with Lean + - low level modules are simple + - objective is to prove the more important stuff (instructions) + - this can be done incrementally: + - if no exceptions + - if one arg is bla ... + - sampling / testing derived from this approach + - [[fuzz testing of completeness]] + - [[look for optimizations / factorizations]] + - formal methods provide an approach for that + - experiment with different approaches to implement logic + - [equality saturation], [synthesis] <= may help us find equivalent formulations that are cheaper + - choose best implementation according to some metric + - complex project but doable + - also check for redundancies (e.g. de facto boolean columns that are enforced to be boolean) + - Valentin Wüstholz + - completeness could also be tested with his fuzzer + - as could the Corset "compiler" +- Joanne + - scripts that go trhough constraints one by one to remove them and see if redundant + - keep chipping away at modules + - going to something that is stateful soon + - adding lots of automation (it's getting there) + - Q: Corset to Dafny pipeline, how far along ? diff --git a/notes/2024.01.26.md b/notes/2024.01.26.md new file mode 100644 index 0000000..c53c271 --- /dev/null +++ b/notes/2024.01.26.md @@ -0,0 +1,68 @@ +# Notes from 2024.12.26 + +## Alex + +implementing manual approach with uninterpreted functions for BIN functions +e.g. select `select-byte` function that extracts specific byte from an integer +Still some performance issues but improvement over e.g. explicit formula version +Able to write spec for that and model check it +Current spec is successfully verified +Previous spec has issues for some reason +MyPy tool to do static type inference from EVM execution spec +could generate tests + +There are many perf issues: +- non linear computations +- big formulas + +We don't inline the definitinos of the uninterpreted functions +We just constrain its behaviour +When included it's like an opaque term + +These uninterpreted functions could be shared between modules +e.g. +- EXP +- RLP + +Both have a requirement for computing some log_256 (rounded up) +The axiomatics of these fucntiosn can be shared + + +## David + +Agreed upon system for constraint format +- forward / backwards induction +Code can generated Dafny lemmas +e.g. bounds on CT's and CT_MAX's etc + +applied to WCP, looking at BIN + +Uniformize names for constraints +- last-row +- lastRow +- final_row + +Adding assumptions of smallness +Or for the vanishing of the second argument for ISZERO in WCP + + +Want to write properties in the corset file sfor formla verification +Example: in the WCP ''it should be the case taht CT <= CT_MAX < 16" +There are no constraints that do that directly +The constraints should imply this +These are useful for formal verification +"intermediate propterties" make formal verification work faster +Also there is some taggin system where properties are either forward induction or backward induction +Also doesn't impose high burden on SMT solver +These properties are added into the underlying corset file +Could be written in theory by constraints people, but not trivial to know which ones to include nor whether b/f +Typically when we have some property that we don't +E.g. EUC has DONE which is de facto binary + +Constraints (properties) can have no direction either, be "direct". + +Alex: +EUC model checked with latest constraints (dropping DONE[N] = 1 when not all padding) +But we should revert it. +Lookups can be implemented as preconditions / properties on some rows ! +But this applies also to implicit smallness conditions (e.g. if we look up into WCP then the arguments must be small) diff --git a/notes/2024.02.02.md b/notes/2024.02.02.md new file mode 100644 index 0000000..aada74b --- /dev/null +++ b/notes/2024.02.02.md @@ -0,0 +1,56 @@ +# Meeting notes + +## Olivier + +Quick update on implementation: +- HUB implementation is wip (mainly precompile specific stuff) +- thorough review of MMU before implementation +- EXP module implementation + +## Joanne + +- Fully verified the updated WCP +- Signed instructions were harder than others +- Observation: + - You may not need ACC_4/5 + - same for and ACC_2/3 + - We may need to homogenize these accumulators +- Template in place for such modules in place for proof structure +- WRT variable length instructions +- ADD, BIN, SHF +- CT_MAX being nondeterministic has an impact ? + - now verification time of 24s + - new structure for the loops + - not a huge difference from the Tools perspective + +Set up the basics for STP + +## David + +- Adding features to the tool +- Corset advances faster than tool : ) +- Type inference in Corset +- ADD module functional correctness done +- WCP module a lot of time in it +- Signed instructions killed Dafny for David +- Had to revamp parts of it +- BIN pondering how to deal with lookup tables / bitwise operations in Dafny +- Boils down to an assumption that the lookup tables are correct + +Spec questions: +- Consistency questions around the spec / constraints +- THETA and THETA_2 +- Purpose of debug constraints ? + - Olivier: 2 purposes + - signal constraints that are not required per se (e.g. vanishing of counter's and max counters during the padding) + - formal consequence of other things (e.g. they _should_ follow implicitly from other constraints, e.g. columns that are binary by construction don't need to be verified to be so) +- For audit the 2 use cases of debug may be confusing + +## General discussion + +Formal verification: +- will become part of communication of Linea + - talks, blog posts, tweets ... papers ? +- very interesting point (raised by Madeline M. and communicated here by Joanne): + - unusual for FV to be happening in parallel with specification / implementation + - developing tools to deal with evolving specification diff --git a/notes/2024.02.09.md b/notes/2024.02.09.md new file mode 100644 index 0000000..749f093 --- /dev/null +++ b/notes/2024.02.09.md @@ -0,0 +1,74 @@ +# Meeting notes 2024.02.09 + +## Olivier + +- implementation progress: + - HUB: did the Java implemnetation of + - CALL's and CREATE's + - precompiles + - interfacing with other modules (OOB/EXP/MMU/...) for these 'instructions' + - MMU v2 implementation has started + - MMIO spec update will likely start soon, too + - EXP is in the testing phase + +## Alex + +- completing BIN module +- updating proof scripts to work with uninterpreted functions +- works +- performance still an issue +- model checking vs inductive proofs +- adding auxiliary properties adds a lot of work to the prover +- plan to implement inductive proofs for BIN +- BIN not that complicated but inductive proofs require properties + - the more properties you have the harder the proofs become for the prover + - SMT struggles with big formulas +- for ADD there are only 2 operations, for BIN there are at least 5 ... this has an impact on the complexity +- work on transpiler from Python (execution spec) to generate properties (e.g. type annotations) +- doing type inference in Python + +## Joanne + +- adjusting approach: row by row now rather than blocks of rows +- a lot of previous proofs translated easily to the new strategy +- more exploratory with defining properties maybe ? +- some comments on the BTC_DATA module + - §2.3: Note is wrong (wrong i + 2 should be i) + - counter constancy is stated but not specifed +- Will take a look at stateful modules (e.g. MXP) next week +- continue with STP, too. + + +## David + +- spent some time on the Corset -> Dafny tool +- made changes that allow you to be more specific how Dafny instantiates the constraints + - you can now e.g. instantiate only a subset of the constraints at row k and another subset at row k-1 +- this has had an impact + - ADD now verifies in a couple of seconds without user +- `:binary@prove` improves stuff in WCP +- SHF: looking at the BYTE instruction +- prototyped a translation of the constraints into Lean + - doesn't look too bad (no proofs yet, just constraints and properties) + - Lean could give us some advantages (Note: I didn't catch which ones) +- updated the report (FI ≡ forward induction) +- will share updated version of the report next week most likely +- in a FI you want to know all the constraints at point k +- if you are in the inductive case you also want the constraints to be instantiated at k-1 +- the report still has to describe how we do backward induction + +## Discussion + +- **Olivier to Alex**: is the BIN module more difficult? + - modules such as BIN are why uninterpreted functions were introduced + - same issue arises for SHF (but didn't require uninterpreted functions) + - we have functions that work on the byte-level, how it doesn't matter, will work for all NOT, AND, OR, XOR, ... + - uninterpreted functions allow to hide complexity and introduce an axiomatic approach instead + - simplifies complexity and will remain important in the future + - another option would be to translate to bit vectors of fixed length +- Question: there is some interest within the arithmetization team (e.g. Lorenzo) to partake in the formal verification effort. Obviously not before our work is done, e.g. by May 1. How, if at all, will we be able to contribute at some point ? + - David: Tools are still very clunky. Working on some module properties could be a place to start. + - Alex: BMC is rather easy to step in. Performance issues are tricky though, and speeding things up requires understanding how it works (the BMC I take it). Properties for modules that aren't constraints, there additional manpower could make sense. + - Alex: simplified modules (3 or 4 rows rather than 16) would make perf issues simpler. + - [ ] Alex: We can have a session to look at simple modules like ADD / EUC / ... + - Alex: **Model checking could become a part of the module specification process** to verify that properties are enforced by constraints. Especially using the same corset files + properties within the corset files diff --git a/notes/2024.02.16.md b/notes/2024.02.16.md new file mode 100644 index 0000000..e7b5bf2 --- /dev/null +++ b/notes/2024.02.16.md @@ -0,0 +1,18 @@ +# Olivier + +# Alex + +- refactoring of rewriting engine +- support for constants +- new technique (parametrized model checking) +- ``max length'' business +- huge number of properties e.g. in BIN +- we can set constants to smaller values to make model checking faster (e.g. LLARGE <-- 4) +- note that for those instructions the `LLARGE` is hardcoded into the constraints (byte decomposition of the leading byte e.g.) +- even so BYTE and SIGNEXTEND don't work +- for work with variable lenght instructions (currently max length = 4) +- sometimes model checking is quick, other times it doesn't work +- tried applying this to SHF, too, but not working +- reworked BIN module, ok for everything except BYTE and SIGNEXTEND +- those were already the performance bottlenecks +- not working with Python transpilation yet diff --git a/notes/2024.02.23.md b/notes/2024.02.23.md new file mode 100644 index 0000000..f5ff3ac --- /dev/null +++ b/notes/2024.02.23.md @@ -0,0 +1,16 @@ +## Olivier +- implementation (Java & Lisp) +- spec refining +- filling gaps +- call with Nethermind + - they have worked with risc0 on formal verification + - they work with Lean + - + +## Joanne + +- updating the proofs after module redesign +- STP module WIP +- different number of CT_MAX's is challenging +- trying to find key properties and feeding them back to the tool +- This module has a lookup to the diff --git a/notes/2024.03.08.md b/notes/2024.03.08.md new file mode 100644 index 0000000..77ef7cf --- /dev/null +++ b/notes/2024.03.08.md @@ -0,0 +1,26 @@ +# ALEX + +- still working on SIGNEXTEND +- similar to BYTE, but more complicated +- need to formulate properties, slight challenge +- automation would help here (in theory) + - derive intermediate properties / lemmas + - doing it properly is challenging + - also should be resistant to small changes + - simple approach: we have patterns in Croset (plateau, counter-constancy, byte dec) + - can be detected + - provide lemmas to help Z3 to reason about difficult cases + - did Nethermind use model checking or spacer ? +- automation will run into bugs and get stuck ... + + +# Joanne + +- not much work in the last week +- completeness proof of ADD with variable number of rows +- adjusting existing proof +- new constraints are supported & completeness proved +- STP module (soundness) + - CREATE(2) ok + - POOP may be missing counter-constancy ? + - CALL instructions are WIP diff --git a/notes/2024.03.29.md b/notes/2024.03.29.md new file mode 100644 index 0000000..e69de29 diff --git a/notes/2024.04.05.md b/notes/2024.04.05.md new file mode 100644 index 0000000..1f0070c --- /dev/null +++ b/notes/2024.04.05.md @@ -0,0 +1,22 @@ +# 2024.04.05 + +## François + +- François mentions issue with corset interleaving constraints +- unaccounted for values appearing in the interleaving of columns produced during MXP tests +- Interest in the debugging + +## David + +- small amount of work on BIN and related stuff +- most of the time spent on the go corset stuff +- splitting time between FV and Go port and Rust fixes +- some time spent on the Rust tool + - If condition expansion fix + - "expression::void" +- ordering of interleaving is nondeterministic and depends on build (changes from one build to another) +- building define.go had issues (presumably large constant) "exponent very large number" +- debugging the binary constraints and the `:bianry@prove` for binary columns in perspectives + +## Olivier + diff --git a/notes/2024.04.26.md b/notes/2024.04.26.md new file mode 100644 index 0000000..e69de29 diff --git a/notes/PRECOMPILE_INFO.md b/notes/PRECOMPILE_INFO.md new file mode 100644 index 0000000..6d69333 --- /dev/null +++ b/notes/PRECOMPILE_INFO.md @@ -0,0 +1,42 @@ +## Lookup columns + +There is the option to use dedicated columns for the lookups, e.g.: + +| ARG_1_LO | ARG_2_LO | RES_LO | INST | WCP | MOD | +| :---: | :---: | :---: | :---: | :---: | :---: | +| CDS + 31 | 32 | bla | MOD | 0 | 1 | +| 3000 | GAS_STIPEND | 1 | LT | 1 | 0 | +| LM | L_B | 1 | LT | 1 | 0 | + +(N.B.: the high parts, which one must insert into the lookups, will always be 0) + +These columns could be used to (1) simplify the layout of the lookups that are done to WCP and MOD (2) kill many of the EXPMOD related columns. The idea being that in case of a EXPMOD you produce a mosaic of results from lookups to WCP and MOD and use these values to further the compuation in the next rows. + +This should allow you to kill the following columns (at least): +- MODEXP_LM_LESS_THAN_LB +- MODEXP_MAX_LM_LB_BYTES_COUNT +- MODEXP_LE_GREATER_THAN_32 +- MODEXP_BIG_FRACTION (result from a DIV) +- MODEXP_NUMERATOR (remplissage à la mano) + +for other reasons one should probably get rid of: +- MODEXP_E_LEADING_WORD_RELEVANT_HALF (just insert a second If in the If INDEX == 15 Then MOD_EXP_ACC = ...) + +## Making the lookups explicit + +### WCP lookups: + +- GAS_STIPEND < PRECOMPILE_COST (must be done for all precompiles) +- 0 <= STAMP_DELTA < 2**32 (must be done for all precompiles) +- EQ applied to 213 = CDS (BLAKE2f) +- EQ applied to 192 * k = CDS (for ECPAIRING) +- LT applied to l_M and l_B (MODEXP specific) +- LT applied to l_E and 32 (MODEXP specific) +- LT applied to 200 and (big floor) (MODEXP specific) + +### MOD lookups + +- DIV by 32 (after adding 31) of CDS +- DIV by 8 (after adding 7) for f(x) +- DIV by 3 +- DIV by 192 diff --git a/notes/constraints.md b/notes/constraints.md new file mode 100644 index 0000000..d9de614 --- /dev/null +++ b/notes/constraints.md @@ -0,0 +1,70 @@ +# Constraints + +Consider an If-Then-Else constraint: + +(*) If a = 0 Then P = 0 Else Q = 0 + +Define a new column A. A should be a^{-1} +Subject to + +- a * (1 - aA) = 0 +- A * (1 - aA) = 0 + +Equation of pseudo inverse from Algebra +2 constraints of degree 3 + an extra column + + +In equations you will have to enforce (*) like so + +- a * (1 - aA) = 0 +- A * (1 - aA) = 0 +- a * Q + (1 - aA) * P = 0 + +In the end you get something of degree 4. + +IF CT_i = 0 Then bla +If CT_i = 1 Then Bla' +If CT_i = 2 Then Bla'' + +Avoid this !! + +Prefer looking ahead from the vantage point of CT_i = 0 + + +And how do we verify a constraint ? (in the prover) + +Data you want to constrain is commited to as the evaluations of polynomials over a certain FFT friendly subset of a field. Some coset of a multiplicative subgroup of the units of a field. + +We have some fixed size rquirements, e.G. the cosets all have size 2^22. This is realistic for say HUB and RAM. + +What we prove on chain is the satisfaction of a SNARK circuit (of Plonk type) with fixed sizes that verifies a proof of our type (general huge constraint system.) It's a proof of a proof of a proof of a... (maybe 3 or 4 times). With every recursion step reduce size by a factor of sqrt(n). Vortex. + +Not everything is of that circuit size. + +When we verify an equatoin of the form + +A * B + C - D * E * F * G * H + 1 = 0 (must be true on the coset, call it Dom) + +We must verify that the above vanishes on the FFT domain. +It's not that the polynomials are zero, it's that their evaluations vanish on the coset. + +A * B + C - D * E + 1 = Z_Dom * Q + +Z_Dom = \prod_{d\in Dom} (X - d) +and +Q is the quotient of the Euclidean division of the LHS by Z_Dom. + +Note: Q has degree 4 * |Dom| + +FFT is needed for 2 things: + - going from the evaluations to the coefficients + - what we commit to is the polynomial given by its coefficients + - to compute quotients effciently. + - we first do FFTs on a larger domain of size 4 * |Dom| + - we deduce the evaluations of Q on that larger domain + - we do inverse FFT using these evaluations to get the coefficients Q so we can commit to it. + + +N.B. The instruction type (1 for CREATE's, 0 for CALL's) which you inherit from the HUB is obtained not through IF statements (e.g. if ISNT = CREATE Then ...) but through "instruction decoding" i.e. by means of a lookup to a fixed reference table. + +In some sense the cost of a lookup is that of 6 constraints. diff --git a/notes/contexts.md b/notes/contexts.md new file mode 100644 index 0000000..3e47de9 --- /dev/null +++ b/notes/contexts.md @@ -0,0 +1,9 @@ +# Spawning execution contexts at initialization + +- if TX_SKIP ≡ 1: + - no execution context is spawned +- if TX_INIT ≡ 1 and hubStamp = h + - if transaction ≡ contract creation then during the TX_INIT phase there is 1 context row; that row initializes the deployment context; it is given as context number CN = 1 + h; + - if transaction ≡ message call then during the TX_INIT phase: + - if transaction call data = ∅ we do as with creation: there is 1 context row; that row initializes the deployment context ("root"); it is given as context number CN = 1 + h; + - if transaction call data ≠ ∅ then we define a fictitious parent context with CN = h (which will be nonzero) which is used solely to hold the transaction call data; we also initialization as above the execution context that will be the "root context" with CN = 1 + h; diff --git a/notes/devcon todo b/notes/devcon todo new file mode 100644 index 0000000..c5f6d23 --- /dev/null +++ b/notes/devcon todo @@ -0,0 +1,4 @@ +TODOs for devcon presentation: + + - zkGeth + - \ No newline at end of file diff --git a/notes/deviations.md b/notes/deviations.md new file mode 100644 index 0000000..d946028 --- /dev/null +++ b/notes/deviations.md @@ -0,0 +1,8 @@ +# Deviations from the EVM + +This list is likely incomplete and will evolve. This is as it stands currently: +- we don't deal with transactions whose TO address is a precompile +- we don't deal with transactions that violate transaction validity: + - insufficient balance (for cumulative gas cost + transfer value) + - wrong nonce (txNonce != accNonce) +- we don't deal with arbitrary calls to MODEXP: such calls are capped at 4096 bit values of E, B and M; diff --git a/notes/ethresearch post b/notes/ethresearch post new file mode 100644 index 0000000..3696c8f --- /dev/null +++ b/notes/ethresearch post @@ -0,0 +1,15 @@ +Hi all, + +last year we shared with you an draft for an [arithmetization of a zk-evm](https://ethresear.ch/t/a-zk-evm-specification/11549). Our stated goas were + +- to support for all EVM opcodes including internal smart contract calls, error management and gas management, +- to execute bytecode as is, +- have minimal prover time. + +[A few months later at L2Beat](https://youtu.be/jSC5fQZlWYQhttps://ethresear.ch/t/a-zk-evm-specification/11549 we were able to show off an implementation of the spec which was powerful enough to produce valid execution traces for calls to complex smart contracts (e.g. Uniswap) and working on evm bytecode. + +In the mean time a lot of work has gone into the project. The specification has evolved quite substantially, and we provide the latest version of it below. The RAM and the stack have been rebuilt from the ground up: the RAM has been expanded to support all memory instructions and to communicate with exogenous data spaces such as bytecode in the ROM for deployments and code copy instructions. The stack design is much more straightforward than previously: this provides clarity and simplifies instruction dispatching (through plookups). We have added support for dynamic gas costs, out of bounds recognition for instructions/exceptions that need it, exception handling and appropriate instruction dispatching. + +Our implementation is in progress and currently covers the stack, parts of the RAM, opcode executing modules such as binary, word comparison, arithmetic, storage. We have connected our implementation to the [EVM test suite](link). We produce both inner and outer proofs of execution using a tool developped by [AC team] + +The current state of our zk-evm achieves [percentage, 90%+] compliance. [results breakdown from Franklin] \ No newline at end of file diff --git a/notes/exception_profiles.md b/notes/exception_profiles.md new file mode 100644 index 0000000..3b847b5 --- /dev/null +++ b/notes/exception_profiles.md @@ -0,0 +1,161 @@ +# Exception profiles + +The present note is a record of the way exceptions may arise and be dealt with on an opcode per opcode basis. + +## Exceptions + +Our zk-evm knows the following exceptions with associated stack columns: +- OPCX: invalidOpCodeException: +- SUX: stack underflow exception: stack underflow exception +- SOX: stack overflow exception +- MXPX: memory expansion exeption (a subcase of the out of gas exception) +- OOGX: out of gas exception +- RDCX: RETURNDATACOPY exception +- JUMPX: invalid JUMP exception +- STATICX: static context exception +- SSTOREX: SSTORE minimum gas exception +- ICPX: invalid code prefix exception (can only manifest for deployments) +- MAXCSX: max code size exception (can only manifest for deployments) + +## Exception profiles + +### Profile 1 + +The following instructions trigger exceptions in the following order: + +1. SUX +2. OOGX + +These instructions are +```bash +ADD, SUB, +DIV, SDIV, MOD, SMOD, +ADDMOD, MULMOD, +MUL, EXP, +LT, GT, SLT, SGT, EQ, ISZERO, +AND, OR, XOR, NOT, BYTE, SIGNEXTEND, +SHL, SHR, SAR, +BALANCE, EXTCODESIZE, EXTCODEHASH, +CALLDATALOAD, SLOAD, +BLOCKHASH, +POP, +SWAP1-SWAP16, +``` + +### Profile 2 + +1. SOX +2. OOGX + +```bash +ORIGIN, CALLVALUE, GASPRICE, COINBASE, TIMESTAMP, NUMBER, PREVRANDAO, GASLIMIT, CHAINID, BASEFEE, +ADDRESS, CALLDATASIZE, CALLER, RETURNDATASIZE, +PC, MSIZE, GAS, +SELFBALANCE, CODESIZE, +PUSH0-PUSH32, +``` + +### Profile 3 + +1. SUX +2. MXPX +3. OOGX + +These instructions are: +```bash +SHA3, +CALLDATACOPY, CODECOPY, EXTCODECOPY, +MLOAD, MSTORE, MSTORE8, +CALLCODE, DELEGATECALL, STATICCALL, +REVERT +``` + +Add to that +```bash +RETURN // when NOT in a deployment context +``` + +### Special profile: invalid byte + +1. OPCX + +```bash +INVALID and all bytes that aren't opcodes +``` + +### Special profile: STATIC_RAM + +1. SUX +2. STATICX +3. MXPX +4. OOGX + +```bash +LOG0-LOG4, CREATE, CREATE2, CALL +``` + +### Special profile: DUP + +1. SUX +2. SOX +3. OOGX + +These instructions are: +```bash +DUP1-DUP16 +``` + +### Special profile: JUMPs + +1. SUX +2. JUMPX +3. OOGX + +These instructions are: +```bash +JUMP, JUMPI +``` + +### Special profile: RETURNDATACOPY + +1. SUX +2. RDCX +3. MXPX +4. OOGX + +```bash +RETURNDATACOPY +``` + +### Special profile: SSTORE + +1. SUX +2. STATICX +3. SSTOREX +4. OOGX + +```bash +SSTORE +``` + +### Special profile: JUMPDEST + +1. OOGX + +```bash +JUMPDEST +``` + +### Special profile: code deployment + +1. SUX +2. MAXCSX +3. MXPX +4. OOGX +5. ICPX + +```bash +RETURN // in a deployment context +``` + +**Note.** STOP diff --git a/notes/extended_lookps b/notes/extended_lookps new file mode 100644 index 0000000..e69de29 diff --git a/notes/extended_lookps.md b/notes/extended_lookps.md new file mode 100644 index 0000000..077fa21 --- /dev/null +++ b/notes/extended_lookps.md @@ -0,0 +1,27 @@ +# Extended lookup discussion with Alex and Bogdan + +Notes from 2023.12.20 + +Github issue: https://github.com/Consensys/zkevm-monorepo/issues/1615 +Extending the API for lookups: we would have to provide the source and target columns and the source / target boolean filters. +Bogdan: this may allow us to not have to recommit to the "filtered" columns. +As opposed to the pre-filtered stuff. + +In practice we only mask stuff in the source. + +Conditional on the target table. + +Does this mean changes in Corset ? +- translation into constraints: + +Fragmenting lookups: +==================== +- GOAL: getting rid of interleaved columns + - i.e. more efficient way to get the same functionality as interleaving without doing the interleaving. +- HUB: contains little redundancy (mostly CN and HEIGHT) +- HUB: consistency of storage / account +- HUB: possibility to have extra modules (ACC, STO, ...) +- MMIO: contains some redundancy (16 times repetition of VAL_A, ...) + +The need is more on the prover side. +And we can't get improvements on the HUB just by these techniques. diff --git a/notes/friday 2023.11.09.md b/notes/friday 2023.11.09.md new file mode 100644 index 0000000..9138abb --- /dev/null +++ b/notes/friday 2023.11.09.md @@ -0,0 +1,84 @@ +# Meeting notes 2023.11.09 + +## Alex + +Wrote a specification for TRM +BMC found bugs ? +TRM should detect precompiles; seems like 16 is recognized as precompile; not 100% sure +Also: there are binary constraints that are missing + +Olivier: +- spec updated, see [commit 14c26a5d19f4375c6ac05ace010048638fe826b2](https://github.com/Consensys/zkevm-spec/commit/14c26a5d19f4375c6ac05ace010048638fe826b2) on the spec repo +- corset constraints updated, see [TRM: missing binary constraints](https://github.com/Consensys/zkevm-constraints/pull/38) + +**BMC (Branching Model Checking)** implemented as sample code. +It is based on temporal logic. +**Idea** +- have some notion of branching time +- in bounded model checking we fix the number of rows, but + - we could have all padding rows + - we could have padding + non-padding rows +- we can branch on that dichotomy by making distinction between the two cases. + +Partially solves the problem of determining the lengths we want to check. + +We need some sort of **dual notion of reachability** (reachability in the opposite direction ?) +Related to "predictions" +We don't have time in setting, but we can "invent" time notion in our setting. +Adding rows corresponds to doing a computation +Predictions break this (locally non-deterministic) +For constructing rows we can produce whatever we want. But this clashes with future constraints (e.g. target constraints) +Building traces row by row seems natural, but one should be able to **look ahead** to predict the result ahead (e.g. 15 rows in the future.) +To solve this one could add several rows at a time. +One can also see it as knowing both the first and last row of a chunk at the start. +State transition system language is compatible with the forward looking / backwards looking approaches +Dual reachability says: we have a trace that satisfies constraints + +Does that mean that the constraints have to be reinterpreted ? +E.G. STAMP_{i + 1} \in STAMP_{i}, 1 + STAMP_{i} +This can be interpreted in two directions +Having the two interpretations makes checking faster as there is more information available. +This is because e.g. if you have 17 rows in bounded model checking then you don't know whether you are in one scenario or another (e.g. all padding or one padding row followed by an actual instruction.) + +## Joanne + +Finished completeness for ADD module (previously missing SUB instruction) +Completeness is solved for that module. +**Completeness:** +- you can build any trace for any sequence of (ADD/SUB) instructions +- arbitrary ARG1 / ARG2 and arbitrary instructions +- working from the honest prover perspective + +New trace mechanism. More on that later. +This new trace mechanism will be adapted to older modules +Advantage of this tracing mechanism: it's fast to prove: under 60 seconds +E.G. Helper for byte decompositions + +### New trace mechanism + +Still doing induction starting with an empty trace. +Idea remains that adding another set of rows keeps valid trace valid. +The stuff you are adding, the delta, is now so that you only need to check it. +You are being more assertive about the properties of the existing trace. +You can send in the whole trace table or the update to the trace table. + +Olivier: what about the constraints that link one chunk of trace to the next ? E.g. those that live at the threshold of one chunk of rows to another, where one chunk of rows represents a give computation. +Joanne: In ADD module and others Heartbeat constraints are the linking constraints. +Dafny was struggling with them for some reason. +This approach is better for Dafny. +"Assume all constraints hold on the previous trace, prove that the updated trace still satisfies constraints" +In the past "all" was for instance replaced with a subset of the constraints such as the "heartbeat" + +David's focus is on the LISP to Dafny. +The more aggressive part of the verification is generic and can be ported to other modules and can be incorporated in the automation part. +This is based on some python notebooks ... + +Should try something new with next module (e.g. MUL and the EXP opcode.) + +Going back to older modules to apply these modifications to older modules. + +## Olivier + +Recommendation: there are two pathways forward: +- either tackle one of the more complex stateless modules (e.g. MUL which deals with the MUL and EXP opcodes, the latter which can take anywhere from 1 row to (any nonzero module of 8 less than or equal to 2*256*8 =) 4096 rows per EXP opcode) +- or tackle a stateful module (e.g. MXP which tracks WORDS / WORDS_NEW (the number of active words of an execution context) and C_MEM / C_MEM_NEW (the cost of memory expansion up to that point)); it may pay off to deal with only a subset of the covered instructions for such a module (e.g. with MXP one could start with MSTORE / MSTORE8 and MLOAD only) diff --git a/notes/friday_call_2023_10_27.md b/notes/friday_call_2023_10_27.md new file mode 100644 index 0000000..cd1c7c7 --- /dev/null +++ b/notes/friday_call_2023_10_27.md @@ -0,0 +1,69 @@ +Alex: + +- improving ADD proof in Dafny +- arbitrary number of rows +- mostly done with soundness +- relies on some sort of extraction +- need to reason about arbitrary traces +- took some time (Danfy: boogie, ...) +- Question: is this wrt some finie state machine for separating instructions ? +- use Dafny for arbitrary rows in the future, and SMT solver for individual instructions +- work with the desugared instructions (Wizard IOP level) +- Question: expand on this + + +Details +- finite state machine not explicitly mentioned +- lemma for arbitrary trace, use a "find_fragment" to split trace +- it recognizes where the stamp jumps +- it can separate the padding from the other things +- proves that non-padding fragments have size 16 +- proves stuff about the last row +- does current spec allow to insert additions / subtractions into padding ? + - Olivier: yes and it's a bug : ) + - fixed it in the spec during the call, fixing it in the corset after the call + - [ ] TODO: fix it in the corset files + +Next step: +- work on new modules as ADD is more or less complete +- focus on SMT stuff, as Dafny has demonstrated that it can handle arbitrary row numbers + - Question: what does that mean ? + - approach: make the SMT stuff able to handle arbitrary traces + - use the state machine stuff + - go from set of 16 rows to arbitrary traces + - "find inductive principles automatically and from there go to Dafny proofs" + - one option: prove everything in SMT but one can have + - other option: use Dafny as an external proof checker + - Dafny requires multiple lemmas + - SMT allows for better automatization, not write lemmas by hand e.g. + - inferring inductive predicates to handle the arbitrary row traces + - "property directed reachability" + - exploit scaffolding / extractability + - Dave: finding those inductive predicates won't be straightforward + - Olivier can provide regular expressions + - start with those to help + - sometimes can find proofs on its own, sometimes not + - inferring loop invariants etc ... Dave: an SMT solver won't do that + +Joanne: what does the add module soundness look like ? +Alex: work with a fragment; for soundness assume that constraints are satisfied; verify that if inputs are ok then the outputs should comply with the specification; property verified at the 16th row; + +Dave has worked on automation this week +Joanne: refactoring / refactoring, ... +simplify code in preparation for automation +Dave working on the Lisp to Dafny predicate generation +Automatic Lemma Generation in python notebook +hope to get back to the missing constraints next week + + +Dave: automation +parsing Corset constraints +learning Corset semantics +- what happens when you fall off the edge of the matrix in the constraints? +- Also thinking how to translate into Dafny (bool, loob etc how to convert them into Dafny types) + +WRT to using Wizard +- Franklin: you can use the -e (-ee, -eee, etc ...) to display different levels of expansions of the constraints +- until you get to the level of the WIZARD + +Link to issue diff --git a/notes/hub tests.md b/notes/hub tests.md new file mode 100644 index 0000000..ccc518f --- /dev/null +++ b/notes/hub tests.md @@ -0,0 +1,70 @@ +## CN_NEW purpose + +CN_NEW: represents the context number of the context wherein the next instruction of the will be executed. Wether the execution context changes or remains the same ... depends on the CONTEXT_MAY_CHANGE flag i.e. CMC. + +Recall that +Recall that +```rust +XAHOY == true <=> [any exception occurs] +``` +and that +```rust +CMC == true <=> XAHOY == true // 100% sure CN_NEW = CN_CALLER + || opCode.InstructionFamily() == InstructionFamily.HALTING // 100% sure CN_NEW = CN_CALLER + || opCode.InstructionFamily() == InstructionFamily.INVALID // 100% sure CN_NEW = CN_CALLER + || opCode.InstructionFamily() == InstructionFamily.CREATE + || opCode.InstructionFamily() == InstructionFamily.CALL + +// PS: I write XAHOY == true just for more explicit pseudo-code +``` + +The idea is simple +- If `CMC = false` then CN_NEW == CN automatically +- if `CMC = true` then there are three possibilities: + - CN_NEW == CN (context _could have changed_ but ended up _not changing_) + - CN_NEW == HUB_STAMP + 1 (when actually entering a CREATE(2) or a CALL other than to a precompile) + - CN_NEW == CALLER_CN (when the current execution context stops executing) + +## Tests + +### Back to CALLER + +Under any of the following scenarios one shoud have CN_NEW == CALLER_CN: + - [ ] if `InstructionFamily.HALTING` + - [ ] if `InstructionFamily.INVALID` Then CN_NEW == CALLER_CN + - [ ] if $\textsf{XAHOY}_{i} = 1$ Then CN_NEW == CALLER_CN + +### Back to SELF + +Under any of the following scenarios one shoud have CN_NEW == CN: +- [ ] If $\textsf{CMC}_{i} = 0$ Then must equal CN +- [ ] CREATE's + - [ ] no exception but abort + - [ ] no exception, no abort but $\textsf{FCOND}_{i} = 1$ (deployment address already has nonzero nonce or nonempty code) + - [ ] no exception, no abort but empty init code +- [ ] CALL's + - [ ] no exception but abort + - [ ] no exceptoin, no abort but call to precompile + +### Entering new context + +Under any of the following scenarios one shoud have CN_NEW == HUB_STAMP + 1: +- CALL: no exception, no abort, to != precompile +- CREATE: no exception, no abort and non empty init code + +## `EXT`-Address instructions + +These tests pertain to $\texttt{EXTCODECOPY}$, $\texttt{EXTCODEHASH}$, $\texttt{EXTCODESIZE}$ instructions. We must test that +- [ ] `EXT-Address` instruction tests + - [ ] those addresses correctly cut their address stack argument down $\mod 2^{160}$ (purpose of the $\textsf{TRM}$ module) + - [ ] if the target address has its `DEP_STATUS == true` then + - [ ] $\texttt{EXTCODECOPY}$ copies 0's into RAM + - [ ] $\texttt{EXTCODEHASH}$ returns $\color{green}\texttt{KEC}(\varnothing)$ + - [ ] $\texttt{EXTCODESIZE}$ returns 0 + - [ ] if the target address doesn't exist currently then + - [ ] $\texttt{EXTCODECOPY}$ copies 0's into RAM + - [ ] $\texttt{EXTCODEHASH}$ returns $\color{green}0$ + - [ ] $\texttt{EXTCODESIZE}$ returns 0 + - [ ] This must be true even if there are several successive (failed) deployments at a given address. + +**Note.** If an address is \ No newline at end of file diff --git a/notes/logs.md b/notes/logs.md new file mode 100644 index 0000000..1edb744 --- /dev/null +++ b/notes/logs.md @@ -0,0 +1,60 @@ +# LOG_RLP, LOG_DATA, LOG_INFO + +## Main issue + +We currently have 3 modules dealing with LOGs: LOG_INFO, LOG_DATA, LOG_RLP. The LOG_RLP module is a consumer of the data logged in the other two modules and associated lookup arguments are required. + +## Relevant data from LOG_DATA and LOG_INFO + +- LOG_INFO + - LOG_NUMBER + - ADDR_HI / ADDR_LO + - SIZE + - INST (i.e. LOG0 - LOG4) + - TOPIC_1_HI / TOPIC_1_LO, + - TOPIC_2_HI / TOPIC_2_LO, + - TOPIC_3_HI / TOPIC_3_LO, + - TOPIC_4_HI / TOPIC_4_LO, +- LOG_DATA + - LOG_NUMBER + - LIMB: already known to be 16 byte integers, left aligned on the 16 byte + - nBYTES + - INDEX + +## Verticalization for LOG_INFO + +**Note.** As with the TX_DATA module it will likely make sense to duplicate the data in LOG_INFO to make it "vertically available" in the LOG_RLP module. We can do _verticalization_ as follows: we will require a VAL_HI / VAL_LO column that will present as follows: + +| VAL_HI | VAL_LO | LOG_NUMBER | INST | ... | +|------------|------------|------------|------|-----| +| ... | ... | ... | ... | ... | +|------------|------------|------------|------|-----| +| addr_hi | addr_lo | 16 | LOG0 | ... | +| 0 | dataSize | 16 | LOG0 | ... | +|------------|------------|------------|------|-----| +| addr_hi | addr_lo | 17 | LOG3 | ... | +| topic_1_hi | topic_1_lo | 17 | LOG3 | ... | +| topic_2_hi | topic_2_lo | 17 | LOG3 | ... | +| topic_3_hi | topic_3_lo | 17 | LOG3 | ... | +| 0 | dataSize | 17 | LOG3 | ... | +|------------|------------|------------|------|-----| +| addr_hi | addr_lo | 18 | LOG1 | ... | +| topic_1_hi | topic_1_lo | 18 | LOG1 | ... | +| 0 | dataSize | 18 | LOG1 | ... | +|------------|------------|------------|------|-----| +| addr_hi | addr_lo | 19 | LOG4 | ... | +| topic_1_hi | topic_1_lo | 19 | LOG4 | ... | +| topic_2_hi | topic_2_lo | 19 | LOG4 | ... | +| topic_3_hi | topic_3_lo | 19 | LOG4 | ... | +| topic_4_hi | topic_4_lo | 19 | LOG4 | ... | +| 0 | dataSize | 19 | LOG4 | ... | +|------------|------------|------------|------|-----| +| ... | ... | ... | ... | ... | + +## Unjustified data + +The TX_RLP module encode currently unjustified data: $R_x, R_z, R_u, R_b$. Here's a the road map to get these values fully justified: +- $R_x$ is available in TX_DATA (indexed by ABS_TX_NUM) +- $R_z$ can be made available in TX_DATA (indexed by ABS_TX_NUM) +- $R_u$ can be made available in TX_DATA (indexed by ABS_TX_NUM) +- $R_b$ there are currently no plans to justify it ... diff --git a/notes/meaningful_creates_returns_and_calls_for_mxp.md b/notes/meaningful_creates_returns_and_calls_for_mxp.md new file mode 100644 index 0000000..2d4ec34 --- /dev/null +++ b/notes/meaningful_creates_returns_and_calls_for_mxp.md @@ -0,0 +1,42 @@ +- [x] first step: randomized bytecode that triggers the MXP often without producing errors along the way +- [ ] second step: randomized bytecode that contains meaningful CREATE's +- [ ] third step: same thing but CREATE's finish with nontrivial (randomized) RETURNs: this allows us to deploy nontrivial smart contracts +- [ ] fourth step: same thing but after the successful deployment remember the deployment address (SSTORE) and later on CALL that address + +# Meaningful CREATE's + +- produce a function nontrivialCreate() that returns a _slice of bytes_ INIT that will be the initialization code + - use appendOpcodeCall() many times to fill INIT, finishing on a RETURN or REVERT +- produce a function called randomBytecodeWithCreates() that will return a random bytecode + - appending random opcode calls like previously + - from time to time invoke the nontrivialCreate() function to produce a slice of bytes INIT + - choose a random small offset called INITCODEOFFSET + - take that slice of bytes INIT, chop it up into 32B chunks + - PUSH32 a chunk, and MSTORE it starting INITCODEOFFSET + - every new chunk is again PUSH32'd, MSTORE'd at the the previous offset + 32 + - when the code has been stored in memory in its entirety we invoke appendOpcodeCall() with the following instruction: + - OpCode = CREATE (or CREATE2 but add some random 32B salt to it) + - offset1 = INITCODEOFFSET + - size1 = |INIT| (length of the slice of bytes) + - value = some random small number (< 10**18) + - rinse and repeat + - i.e. to this several times within a single global bytecode that you produce + +This will allow you to test for very cheap the coherence conditions + +# Producing meaningful deployments + +You can then: also tests CALL's quite cheaply if you first do something like this: + - the final RETURN instruction that you produced above should, too, have interesting arguments + - you can create, similiarly as above, a function called nontrivialReturn() that: + - produces some interesting DEPLOYMENTCODE (some bytecode produced like INIT earlier) + - sticks this DEPLOYMENTCODE into memory (of the CREATEE) with again some PUSH32's and MSTORE's + - at the end returns that slice of bytecode + - then you can after the CREATE(2) instruction you have the address on the stack + - you can then use that address (maybe SSTORE it) + - and use it in CALL's + +This requires some care: + - the nontrivialReturn must be invoked within the nontrivialCreate funtion + - in otherwords, we should append such a nontrivialReturn to the end of the INIT code we use. + diff --git a/notes/meeting_notes_2023_11_03.md b/notes/meeting_notes_2023_11_03.md new file mode 100644 index 0000000..5ec2bbc --- /dev/null +++ b/notes/meeting_notes_2023_11_03.md @@ -0,0 +1,82 @@ +# Friday 2023.11.03 + +Alex: +Other style of proof checking (~PROPERTY DIRECTED~ REACHABILITY approach) +- written in Dafny +related with "inductive invariants" +Wrote prototype for stripped down module (0-3 for simplification) +- requires defining many states and their transitions + - states that are reachable in 1, 2, ... steps + - check whether certain predicates are inductive + - E.g. a state F4 which is defined by either STAMP = 0 or nonzero and CT = 0, 1, 2, 3. + - this state is inductive (once you are in there, you should remain there + - you have predicates fro"Forward rechability" and "Backward reachability" + - and you prove that when you are a fwd and bwd reachable state you satisfy the spec +- this approach tries to deal with both the scaffolding and the functional correctness + - prove specification based on summaries (B3, F4 predicates) + - these could be rich enough to prove specification + - goal: build these predicates automatically +- what is the upshot of Reachability approach ? + - property directed reachability + - state transition style approach where each row is a state + - initial state, final state + - you have a transfer function from one state to the next +- is that an alternative approach to dafny theorem proving / z3 SMT solving ? + - it is written in Dafny +Could rewrite stuff in that style +ADD module looks into the future mostly but also into the past for OVERFLOW +- makes it difficult to apply state transition approach +- State could be 2 consecutive rows +- real issue ? + - Olivier: we could write all constraints to be forward looking + - Franklin: this would be interesting for the padding business for Corset, but also for Alex for the formal verification +This approach lends itself to +- Looking for "trivial" counter examples using simple predicate calculus +- Then build a symbolic trace which can then be instantiated + + +This vs other approach: +in reachability we extract summary to do actual proof +in the other approach we need more (constraint satisfaction or so up ot this point) + +NEXT STEPS: +- write ADD (real module) proof in this style + +Experiment with PREDICATE ABSTRACTION +So that in ADD module we can just analyze 17 rows or so and abstract the statement and infer inductive stuff from that +Should work for ADD module +Related to state machine stuff +We have basically 16 predicates +- is padding a predicate ? +- every CT value is its own predicate ? +Counterexample finding stuff + +Did BOUNDED MODEL CHECKING Prototype +- Do you need to predict the combinatorics of the module ? What instructions can come up and in what order ? + - requires predicting the combinatorics of the module +- for ADD module use limits of 33 = 1 + 16 + 16 + - write model checker for that "representative" combinatorics +Instantiating module +First and last row must be satisfied. +- what do you get with this approach ? +- E.g. if there are several instructions +Also tried to apply this to TRM module +Going from BMC to arbitrary traces: +- BMC for "useful samples" of a trace +- extract properties that should hold +- prove that these are inductive properties +- predicate abstraction works with arbitrary traces + +Valentin: use Horn encoding stuff for Z3 + +Alex: "directed reachability" + +David: +- EF project focus + +Joanne: +- helper proofs for WCP and ADD module +- one away for ADD module to satisfy completeness +- done progress on WCP module +- automation: pattern extracted from proofs +- forward looking of constraints would help a lot diff --git a/notes/modexp.md b/notes/modexp.md new file mode 100644 index 0000000..a956ca2 --- /dev/null +++ b/notes/modexp.md @@ -0,0 +1,96 @@ +- [MODEXP\_INFO and MODEXP\_DATA](#modexp_info-and-modexp_data) + - [MODEXP\_INFO](#modexp_info) + - [HUB data](#hub-data) + - [MMIO data](#mmio-data) + - [Required checks](#required-checks) + - [Execution flow in the HUB](#execution-flow-in-the-hub) + - [Simplification](#simplification) + - [MODEXP\_DATA](#modexp_data) + - [Representation](#representation) + +# MODEXP_INFO and MODEXP_DATA + +We currently deal with MODEXP stuff in the PREC_INFO module. We will not be doing this in the future. Here is the idea for the workflow + +## MODEXP_INFO + +The MODEXP_INFO module receives data from two sources: + +### HUB data + +(Will likely occupy cells on a scenario row) +- HUB_STAMP +- $\ell_B$ (low part only, HUB module prediction) +- $\ell_E$ (low part only, HUB module prediction) +- $\ell_M$ (low part only, HUB module prediction) +- GAS_STIPEND, GAS_LEFTOVER, MODEXP_OOGX (the last one is a bit; the first one is computed, the other ones are predicted) +- CALL's to MODEXP expect the following + + +### MMIO data + +- $\ell_B$ (high and low part, 32B read from memory) +- $\ell_E$ (high and low part, 32B read from memory) +- $\ell_M$ (high and low part, 32B read from memory) +- $\textsf{LEAD\\_E} \equiv \big( \textsf{LEAD\\_E\\_HI} , \textsf{LEAD\\_E\\_LO} \big)$ + +### Required checks + +We verify the following, at transition points: +- [WCP] show strict increments of the HUB_STAMP +- [WCP] verify that $\ell_B \leq 512$ i.e. $<513$ +- [WCP] verify that $\ell_E \leq 512$ i.e. $<513$ +- [WCP] verify that $\ell_M \leq 512$ i.e. $<513$ +- [WCP] inquire whether $\ell_E \leq 32$ (i.e. $<33$) or not +- [local] compute $\ell_E'$ using the previous comparison to 32 and potentially 2 byte decompositions of length 8 for either the high or low part of $\ell_E$ depending on whether the high part is nonzero or zero; also remember the leading byte and do its byte decomposition; we've done this sort of shit many times; derive $\ell_E'$ from that; +- [WCP] inquire whether $\ell_M < \ell_B$ + - from this we derive $m := \max \lbrace \ell_M , \ell_B \rbrace$ +- [DIV] compute $q := \lceil m / 8 \rceil = \lfloor (m + 7) / 8 \rfloor$ +- [DIV] compute $L := q^2 \cdot \max \lbrace \ell_E' , 1 \rbrace$ and compute $c := \lfloor L/ 3 \rfloor$ +- [WCP] inquire whether $200 < c$ + - we thus have derived $g_r$ +- [WCP] inquire whether $g_r > g_\text{stipend}$ + - this computs MODEXP_OOGX + +![20231105_033041](https://github.com/Consensys/linea-besu-plugin/assets/38285177/b57c36fa-92b9-4ded-b83b-a9db822e4aa4) +![20231105_033049](https://github.com/Consensys/linea-besu-plugin/assets/38285177/0fbe0164-de64-4d82-8139-c532972039f7) + + +### Execution flow in the HUB + +In terms of the HUB flow it goes as follows: +- SCENARIO predicts $\ell_B$, $\ell_E$, $\ell_M$ +- launch a MMU instruction $\texttt{modexpSizeExtraction}$ using the following parameters: + - CN + - HUB_STAMP + - CDS + - CDO +- requires extracint 6 limbs (3 pairs of high and low parts) +- lanch a MMU instruction $\texttt{modexpExtractExponentLeadingBytes}$ to get $\ell_E'$ (which requires the predicted data) + +Now comes the first bifucation: at this point we have enough information to detect MODEXP_OOGX +If it is raised then +- we provide the current execution context with empty return data + +Otherwise we continue with the following: +- launch an MMU instruction $\texttt{extractModexpBase}$ (iff $\ell_B \neq 0$, otherwise sit it out) +- launch an MMU instruction $\texttt{extractModexpExponent}$ (iff $\ell_E \neq 0$, otherwise sit it out) +- launch an MMU instruction $\texttt{extractModexpModulus}$ (iff $\ell_M \neq 0$, otherwise sit it out) +- launch an MMU instruction $\texttt{transferModexpResultToFictitiousContextsRam}$ (iff $\ell_M \neq 0$, otherwise sit it out) +- launch an MMU instruction $\texttt{copyRelevantPortionOfResultToCurrentRam}$ (iff $\ell_M \cdot \textsf{R@C} \neq 0$, otherwise sit it out) +- update current execution context's context dat with new updated return data (returner = 1 + HUB_STAMP, RDO = 0, RAO) + +### Simplification + +I can simplify the transfer of data +- a nonzero RDO :D +- just copy the unadulterated data over, no byte decompositions required :D +- 32 limbs of 16 bytes + +This will be far quicker and less painful than the messy copy :D + +## MODEXP_DATA + +### Representation + +![20231104_033058](https://github.com/Consensys/linea-besu-plugin/assets/38285177/a93006f0-7f23-451d-9b73-9c0c07bd8039) diff --git a/notes/operations.md b/notes/operations.md new file mode 100644 index 0000000..b3371d7 --- /dev/null +++ b/notes/operations.md @@ -0,0 +1,108 @@ +- [RAM instructions revisited](#ram-instructions-revisited) + - [Classification](#classification) + - [Instructions that touch RAM](#instructions-that-touch-ram) + + +# RAM instructions revisited + +There will be a rewrite of the MMU module. This re-write will attempt the following things: +- homogenize instructions: several instructions are separate currently that shouldn't be since they do similar things in effect; +- in particular we can from the start use different instructions than the INST column of the HUB +- in particular all PRECOMPILE instructions will be treated the same way as the others (with CDL in CSD = 1 remaining a pain) +- furthermore, all the logic will be treated in RAM itself, e.g.: + - extracting the EXO flags (see below) + - dealing with CDL in the case where OFFSET >= CDS + - dealing with RDCX (the return data copy exception) +- we will encode EXO sources using a single number, e.g. through an EXO_SOURCES column such that + - EXO_SOURCES = \sum_i 2^bla EXO_IS_BLA[i] with exo sources such as + - EXO_IS_ROM + - EXO_IS_TXCD + - EXO_IS_LOG + - EXO_IS_KEC + - EXO_IS_SHA2 + - EXO_IS_RIPEMD + - EXO_IS_BLAKE2f + - EXO_IS_MODEXP + +Examples: +- for a successful RETURN in a deployment setting we can set (in the HUB) EXO_SOURCES = 2^rom[EXO_IS_ROM] + 2^kec[EXO_IS_KEC] + - the KEC part allows us to retrieve the code hash +- for a successful CREATE2 we can set (in the HUB) EXO_SOURCES = 2^rom[EXO_IS_ROM] + 2^kec[EXO_IS_KEC] + - the KEC part allows us to retrieve the initialization code hash + +## Classification + +### Instructions that touch RAM + +| INST | FLOW | EXO | modifier | PARAMS | STEPS | pad | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| MLOAD | RAM -> HUB | ∅ | ∅ | OFF1, CNS = CN, VAL | XTRCT | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| CDL | EXO -> HUB | TXCD | CSD = 1 | OFF1, CDS, ABSTX#, VAL | WRITEZEROS | y | +| | | | | | GRABTHREE | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| CDL | RAM -> HUB | ∅ | CSD > 1 | OFF1, CDS, ABSTX#, VAL | WRITEZEROS | y | +| | | | | several cases | sev. cases | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| MSTORE | HUB -> RAM | ∅ | ∅ | OFF1, CNT = CN, VAL | INSERT | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| MSTORE8 | HUB -> RAM | ∅ | ∅ | OFF1, CNT = CN, VAL | INSERTBYTE | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| RETURN | RAM -> RAM | ∅ | CTYPE = 0, CSD = 1 | OFF1, SIZE, R@O, R@C, CNS = CN, CNT = CALLER, CSD | ∅ | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| RETURN | RAM -> RAM | ∅ | CTYPE = 0, CSD > 1 | OFF1, SIZE, R@O, R@C, CNS = CN, CNT = CALLER, CSD | COPY | n | +| | | ROM, SHA3 | | | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| REVERT | RAM -> RAM | ∅ | CTYPE = 0 | OFF1, SIZE, R@O, R@C, CNS = CN, CNT = CALLER | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| CDC | EXO -> RAM | TXCD | CSD = 1 | OFF1, SIZE, OFF2, CDO = 0, CDS, CNS = ∅, CNT = CN | COPY | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| CDC | RAM -> RAM | ∅ | CSD > 1 | OFF1, SIZE, OFF2, CDO, CDS, CNS = CALLER, CNT = CN | COPY | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| RDC | RAM -> | ∅ | | OFF1, SIZE, OFF2, RDO, RDS, CNS = RETURNER, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| CC | ROM -> RAM | ROM | | OFF1, SIZE, OFF2, CODESIZE, CNT = CN, ADDR | COPY | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| EXTCC | ROM -> ROM | ROM | depStatus = 0 | OFF1, SIZE, OFF2, CODESIZE, CNT = CN, ADDR | WRITEZEROS | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| EXTCC | ROM -> ROM | ROM | depStatus = 1 | OFF1, SIZE, OFF2, CODESIZE, CNT = CN, ADDR | COPY | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| SHA3 | RAM -> SHA3 | SHA3_DATA | | OFF1, SIZE, CNS = CN, HUBSTAMP | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| LOGX | RAM -> LOG | LOG_DATA | | OFF1, SIZE, CNS = CN, LOGSTAMP | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x01 | RAM -> ECD | EC_DATA | TOUCHES_RAM = 1 | CDO, CDS, REFS = 128, CNS = CN, HUBSTAMP | COPY | y | +| | ECI -> RAM | EC_DATA | PROVIDES_RD = 1 | RDS = 32, CNT = 1 + HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, REFS = 32, CNS = 1 + HUBSTAMP, CNT = CN | COPY | y | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x02 | RAM -> SHA2 | SHA2 | TOUCHES_RAM = 1 | CDO, CDS, REFS = 128, CNS = CN, HUBSTAMP | COPY | y | +| | ECI -> RAM | SHA2 | TOUCHES_RAM = 1 | RDS = 32, CNT = 1 + HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, REFS = 32, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x03 | RAM -> RIPEMD | RIPEMD | TOUCHES_RAM = 1 | CDO, CDS, REFS = 128, CNS = CN, HUBSTAMP | COPY | y | +| | ECI -> RAM | RIPEMD | TOUCHES_RAM = 1 | RDS = 32, CNT = 1 + HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS = 32, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x04 | RAM -> RAM | ∅ | TOUCHES_RAM = 1 | CDO, CDS, CNS = CN, CNT = 1 + HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS = CDS, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x05 | RAM -> MODEXP | MODEXP | TOUCHES_RAM = 1 | CDO, CDS, CNS = CN, HUBSTAMP | COPY | y | +| | MODEXP -> RAM | MODEXP | PROVIDES_RD = 1 | RDS = l_M, CNT = 1 + HUBSTAMP, HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x06 | RAM -> ECD | EC_DATA | TOUCHES_RAM = 1 | CDO, CDS, CNS = CN, HUBSTAMP | COPY | y | +| | ECD -> RAM | EC_DATA | PROVIDES_RD = 1 | RDS = l_M, CNT = 1 + HUBSTAMP, HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x07 | RAM -> ECD | EC_DATA | TOUCHES_RAM = 1 | CDO, CDS, CNS = CN, HUBSTAMP | COPY | y | +| | ECD -> RAM | EC_DATA | PROVIDES_RD = 1 | RDS = l_M, CNT = 1 + HUBSTAMP, HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x08 | RAM -> ECD | EC_DATA | TOUCHES_RAM = 1 | CDO, CDS, CNS = CN, HUBSTAMP | COPY | y | +| | ECD -> RAM | EC_DATA | PROVIDES_RD = 1 | RDS = l_M, CNT = 1 + HUBSTAMP, HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| +| 0x09 | RAM -> BLAKE2f | BLAKE2f | TOUCHES_RAM = 1 | CDO, CDS, CNS = CN, HUBSTAMP | COPY | y | +| | BLAKE2f -> RAM | BLAKE2f | PROVIDES_RD = 1 | RDS = l_M, CNT = 1 + HUBSTAMP, HUBSTAMP | COPY | n | +| | RAM -> RAM | ∅ | and R@C != 0 | R@O, R@C, RDS, CNS = 1 + HUBSTAMP, CNT = CN | COPY | n | +|---------|----------------|-----------|--------------------|------------------------------------------------------|------------|-----| diff --git a/notes/precompiles.md b/notes/precompiles.md new file mode 100644 index 0000000..e6462b8 --- /dev/null +++ b/notes/precompiles.md @@ -0,0 +1,385 @@ +- [Dealing with CALL's to precompiles](#dealing-with-calls-to-precompiles) + - [HUB columns sent to PRECOMPILE\_INFO](#hub-columns-sent-to-precompile_info) + - [🔥 ECRECOVER 🔥](#-ecrecover-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction) + - [Details](#details) + - [🔥 SHA2-256 🔥](#-sha2-256-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-1) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-1) + - [Details](#details-1) + - [🔥 RIPEMD-160 🔥](#-ripemd-160-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-2) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-2) + - [Details](#details-2) + - [🔥 IDENTITY 🔥](#-identity-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-3) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-3) + - [Details](#details-3) + - [🔥 MODEXP 🔥](#-modexp-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-4) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-4) + - [Details](#details-4) + - [🔥 ECADD 🔥](#-ecadd-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-5) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-5) + - [Details](#details-5) + - [🔥 ECMUL 🔥](#-ecmul-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-6) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-6) + - [Details](#details-6) + - [🔥 ECPAIRING 🔥](#-ecpairing-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-7) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-7) + - [Details](#details-7) + - [🔥 BLAKE2f 🔥](#-blake2f-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-8) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-8) + - [Details](#details-8) + + +# Dealing with CALL's to precompiles + +## HUB columns sent to PRECOMPILE_INFO + +- ADDR_LO +- GAS_STIPEND (GS) +- GAS_RETURNED (GR) +- CALLDATASIZE (CDS) +- RETURNDATASIZE (RDS) +- SUCCESS +- TOUCHES_RAM +- PROVIDES_RETURNDATA + +**Note** Below we mention the RETURN_AT_CAPACITY (R@C) value: it is the last argument to any CALL-type instruction. + +## 🔥 ECRECOVER 🔥 + + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ +- **IF** SUCCESS $~=~$ 0 **THEN** + - TOUCHES_RAM $~=~$ 0 + - PROVIDES_RETURNDATA $~=~$ 0 + - RDS $~=~$ 0 +- **IF** SUCCESS $~=~$ 1 **THEN** + - **IF** CDS $~=~$ 0 **THEN** + - TOUCHES_RAM $~=~$ 0 + - PROVIDES_RETURNDATA $~=~$ 0 + - RDS $~=~$ 0 + We don't need to provide data: the data will be all zeros due to padding and ECRECOVER will be unable to recover a public key. + - **IF** CDS $~\neq~$ 0 **THEN** + - TOUCHES_RAM $~=~$ 1 + - **IF** PROVIDES_RETURNDATA $~=~$ 0 **THEN** RDS = 0 + - **IF** PROVIDES_RETURNDATA $~=~$ 1 **THEN** RDS = 32 + + +### HUB ⇆ MMU interaction + +- **IF** SUCCESS $~=~$ 0 **THEN** _RAM noop_ +- **IF** SUCCESS $~=~$ 1 **THEN** + - **IF** CDS $~=~$ 0 **THEN** _RAM noop_ + - **IF** CDS $~\neq~$ 0 **THEN** $\texttt{dataExtractionRamToExo}$ + - **IF** PROVIDES_RETURNDATA $~=~$ 0 **THEN** _that's it_ + - **IF** PROVIDES_RETURNDATA $~=~$ 1 **THEN** + - $\texttt{copyResultsFromExoToRam}$ + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _padded to 128_ bytes $\big]$ from RAM to the EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all 32 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy _up to_ 32 bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 SHA2-256 🔥 + + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ +- TOUCHES_RAM $~=~$ SUCCESS +- PROVIDES_RETURNDATA $~=~$ SUCCESS +- **IF** SUCCESS $~=~$ 0 **THEN** RDS $~=~$ 0 +- **IF** SUCCESS $~=~$ 1 **THEN** RDS $~=~$ 32 + + +### HUB ⇆ MMU interaction + +- **IF** SUCCESS $~=~$ 0 **THEN** _RAM noop_ +- **IF** SUCCESS $~=~$ 1 **THEN** + - **IF** CDS $~=~$ 0 **THEN** $\texttt{writeKnownValueToRam}$ (wherein we write SHA2-256(∅) to fictitious RAM) + - **IF** CDS $~\neq~$ 0 **THEN** + - $\texttt{dataExtractionRamToExo}$ + - $\texttt{copyResultsFromExoToRam}$ + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{writeKnownValueToRam}$ must write SHA2-256(∅) to a fictitious context's RAM +2. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _unpadded_ bytes $\big]$ from RAM to the SHA2-256_DATA module +3. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes from SHA2-256_INFO to a fictitious context's RAM +4. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ from the ficitious context's RAM to the current context's RAM + +## 🔥 RIPEMD-160 🔥 + + +(virtually identitcal with [SHA2-256](#sha2-256)) + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ +- TOUCHES_RAM $~=~$ SUCCESS +- PROVIDES_RETURNDATA $~=~$ SUCCESS +- **IF** SUCCESS $~=~$ 0 **THEN** RDS $~=~$ 0 +- **IF** SUCCESS $~=~$ 1 **THEN** RDS $~=~$ 32 + + +### HUB ⇆ MMU interaction + +- **IF** SUCCESS $~=~$ 0 **THEN** _RAM noop_ +- **IF** SUCCESS $~=~$ 1 **THEN** + - **IF** CDS $~=~$ 0 **THEN** $\texttt{writeKnownValueToRam}$ (wherein we write RIPEMD-160(∅) to fictitious RAM) + - **IF** CDS $~\neq~$ 0 **THEN** + - $\texttt{dataExtractionRamToExo}$ + - $\texttt{copyResultsFromExoToRam}$ + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + +### Details + +1. $\texttt{writeKnownValueToRam}$ must write RIPEMD-160(∅) to a fictitious context's RAM +2. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _unpadded_ bytes $\big]$ from RAM to the RIPEMD-160_DATA module +3. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes to a fictitious context's RAM +4. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 IDENTITY 🔥 + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ +- PROVIDES_RETURNDATA $~=~$ 1 $\iff$ (SUCCESS $~=~$ 1 $~\wedge~$ CDS $~\neq~$ 0) +- TOUCHES_RAM = PROVIDES_RETURNDATA +- RDS = SUCCESS * CDS + + +### HUB ⇆ MMU interaction + +- **IF** TOUCHES_RAM $~=~$ 0 **THEN** _RAM noop_ +- **IF** TOUCHES_RAM $~=~$ 1 **THEN** + - $\texttt{moveRamToRam}$ + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{moveRamToRam}$ must transfer $\big[$ CDS _unpadded_ bytes $\big]$ to a fictitious context's RAM +2. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the fictitious context's RAM to current RAM + + +## 🔥 MODEXP 🔥 + +### HUB ⇆ PRECOMPILE_INFO interaction + +- **IF** CDS $~=~$ 0 **THEN** + - SUCCESS $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ + - $g_r$ $~=~$ 200 + - RDS $~=~$ 0 + - PROVIDES_RETURNDATA $~=~$ 0 + +Some explanation: Given that the extracted data will be 0-padded the first 96 bytes of it are all 0 so that $\ell_B = \ell_E = \ell_M = 0$ and the output is has size 0 (it's the empty byte slice ()). + +- **IF** CDS $~\neq~$ 0 **THEN** + - SUCCESS $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ + - **IF** SUCCESS $~=~$ 0 **THEN** + - RDS $~=~$ 0 + - PROVIDES_RETURNDATA $~=~$ 0 + - **IF** SUCCESS $~=~$ 1 **THEN** + - RDS $~=~$ $\ell_M$ + - **IF** RDS $~=~$ 0 **THEN** PROVIDES_RETURNDATA $~=~$ 0 + - **IF** RDS $~\neq~$ 0 **THEN** PROVIDES_RETURNDATA $~=~$ 1 + - $g_r$ $~\longleftarrow~$ requires access to RAM for $\ell_B$, $\ell_E$, $\ell_M$ and the 32 leading bytes of E + - $\ell_M$ $~\longleftarrow~$ requires access to RAM + + +### HUB ⇆ MMU interaction + +- **IF** CDS $~=~$ 0 **THEN** _RAM noop_ +- **IF** CDS $~\neq~$ 0 **THEN** + - $\texttt{dataExtractionRamToExo}$ + - **IF** PROVIDES_RETURNDATA $~=~$ 0 **THEN** _that's it_ + - **IF** PROVIDES_RETURNDATA $~=~$ 1 **THEN** + - $\texttt{copyResultsFromExoToRam}$ (all $\ell_M$ = RDS bytes) + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 1632 _padded_ bytes $\big]$ from RAM to the MODEXP_DATA module comprising + - (32 + 32 + 32) bytes + (4096 + 4096 + 4096) bits from RAM + - i.e. (2 + 2 + 2) + (32 + 32 + 32) = 102 limbs of 16 byte integers; + - allows access to $\ell_B$, $\ell_E$, $\ell_M$ (these are the first 6 limbs of the data) + - $B$, $E$ and $M$ (contained in the following 96 or less limbs of data) + - the leading 32 bytes of E +2. $\texttt{copyResultsFromExoToRam}$ must copy all $\ell_M$ = RDS result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 ECADD 🔥 + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ +- SUCCESS $~=~$ 1 $\iff$ $\big[$ TOUCHES_RAM $~=~1 \big]$ $~\wedge~ \big[x, ~ y \in C_1\big]$ +- PROVIDES_RETURNDATA $~=~$ SUCCESS +- RDS $~=~$ 64 * SUCCESS + + +### HUB ⇆ MMU interaction + +- **IF** TOUCHES_RAM $~=~$ 0 **THEN** _that's it_ +- **IF** TOUCHES_RAM $~=~$ 1 **THEN** + - **IF** CDS $~=~$ 0 **THEN** + - SUCCESS $~=~$ 1 + - $\texttt{writeKnownValueToRam}$ + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + - **IF** CDS $~\neq~$ 0 **THEN** + - $\texttt{dataExtractionRamToExo}$ (we write to the EC_DATA module) + - **IF** SUCCESS $~=~$ 0 **THEN** _that's it_ + - **IF** SUCCESS $~=~$ 1 **THEN** + - $\texttt{copyResultsFromExoToRam}$ (64 bytes <=> 4 limbs) + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + +**Note.** In the CDS $~=~$ 0 case zero padding of the inputs ensures that the effective inputs to the ECADD precompile are 128 bytes of zeros which represent twice the point at infinity. It follows that the result is known in this case and is the point at infinity which is represented by 64 zero bytes. + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 128 _padded_ bytes $\big]$ from current RAM to EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 64 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 ECMUL 🔥 + + +(virtually the same as [ECADD](#ecadd)) + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $~=~$ 1 $\iff$ GAS_STIPEND $~\geq~$ $g_r$ +- SUCCESS $~=~$ 1 $\iff$ $\big[$ TOUCHES_RAM $~=~1 \big]$ $~\wedge~ \big[ x \in C_1\big]$ +- PROVIDES_RETURNDATA $~=~$ SUCCESS +- RDS $~=~$ 64 * SUCCESS + + +### HUB ⇆ MMU interaction + +- **IF** TOUCHES_RAM $~=~$ 0 **THEN** _that's it_ +- **IF** TOUCHES_RAM $~=~$ 1 **THEN** + - $\texttt{dataExtractionRamToExo}$ (we write to the EC_DATA module) + - **IF** SUCCESS $~=~$ 0 **THEN** _that's it_ + - **IF** SUCCESS $~=~$ 1 **THEN** + - $\texttt{copyResultsFromExoToRam}$ (64 bytes <=> 4 limbs) + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 96 _padded_ bytes $\big]$ from current RAM to EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 64 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 ECPAIRING 🔥 + + +(similar to [ECADD](#ecadd)) + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $~=~$ 1 $\iff$ [ CDS $~ \equiv 0 \mod 192$ ] $~\wedge~$ [ GAS_STIPEND $~\geq~$ $g_r$ ] +- $192\cdot k~=~$ CDS where $k$ is imported from the EC_DATA module +- SUCCESS $~=~$ 1 $\iff$ $\big[$ TOUCHES_RAM $~=~1 \big]$ $~\wedge~ \big[ x_{1}, \dots, x_{k} \in C_1\big]$ $~\wedge~ \big[ y_{1}, \dots, y_{k} \in G_2\big]$ +- PROVIDES_RETURNDATA $~=~$ SUCCESS +- RDS $~=~$ 32 * SUCCESS + +**Note.** TOUCHES_RAM = 1 also when CDS = 0 (and gas is sufficient.) Indeed in that case the pairing succedes and outputs 1. There will thus be some known data to fill out in a fictitious contex's RAM. + + +### HUB ⇆ MMU interaction + +- **IF** TOUCHES_RAM $~=~$ 0 **THEN** _that's it_ +- **IF** TOUCHES_RAM $~=~$ 1 **THEN** + - **IF** CDS $~=~$ 0 **THEN** + - $\texttt{writeKnownValueToRam}$ (wherein we write 0x00...0001 $\in\mathbb{B}_{32}$ to fictitious RAM) + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + - **IF** CDS $~\neq~$ 0 **THEN** + - $\texttt{dataExtractionRamToExo}$ (we write to the EC_DATA module) + - **IF** SUCCESS $~=~$ 0 **THEN** _that's it_ + - **IF** SUCCESS $~=~$ 1 **THEN** + - $\texttt{copyResultsFromExoToRam}$ (32 bytes <=> 2 limbs) + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _unpadded_ bytes $\big]$ from current RAM to EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 BLAKE2f 🔥 + + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $~=~$ 1 $\iff$ [ CDS $~=~$ 213 ] +- SUCCESS $~=~$ 1 $\iff$ [ TOUCHES_RAM $~=~$ 1 ] $~\wedge~$ [ $f \in \{ 0, 1\}$ ] $~\wedge~$ [ STIPEND $~\geq~ r$ ] +- PROVIDES_RETURNDATA = SUCCESS +- **Note.** $f$ and $r$ will be provided in the module that collects the 213 bytes of RAM data. + + +### HUB ⇆ MMU interaction + +- **IF** TOUCHES_RAM $~=~$ 0 **THEN** _RAM noop_ +- **IF** TOUCHES_RAM $~=~$ 1 **THEN** + - $\texttt{dataExtractionRamToExo}$ (we write to some BLAKE2f_DATA module) + - **IF** SUCCESS $~=~$ 0 **THEN** _that's it_ + - **IF** SUCCESS $~=~$ 1 **THEN** + - $\texttt{copyResultsFromExoToRam}$ (64 bytes <=> 4 limbs) + - **IF** R@C $~=~$ 0 **THEN** _that's it_ + - **IF** R@C $~\neq~$ 0 **THEN** $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 213 _unpadded_ bytes $\big]$ from current RAM to BLAKE2f_DATA module (which also contains the result if applicable) +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\{$ RDS, R@C $\}$ bytes from the ficitious context's RAM to the current context's RAM + +| INDEX | LIMB | PARAMS | +|-------|-------|--------| +| 0 | ... | r | +| 1 | ... | f | +| 2 | ... | 0 | +| ... | ... | ... | +| 13 | ... | 0 | + +N.B. 14 * 16 = 213 so there will be 14 data limbs in the BLAKE2f_DATA module per BLAKE2f call + + + + diff --git a/notes/precompiles_color.md b/notes/precompiles_color.md new file mode 100644 index 0000000..91ea8f2 --- /dev/null +++ b/notes/precompiles_color.md @@ -0,0 +1,378 @@ +- [Dealing with CALL's to precompiles](#dealing-with-calls-to-precompiles) + - [HUB columns sent to PRECOMPILE\_INFO](#hub-columns-sent-to-precompile_info) + - [🔥 ECRECOVER 🔥](#-ecrecover-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction) + - [Details](#details) + - [🔥 SHA2-256 🔥](#-sha2-256-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-1) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-1) + - [Details](#details-1) + - [🔥 RIPEMD-160 🔥](#-ripemd-160-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-2) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-2) + - [Details](#details-2) + - [🔥 IDENTITY 🔥](#-identity-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-3) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-3) + - [Details](#details-3) + - [🔥 MODEXP 🔥](#-modexp-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-4) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-4) + - [Details](#details-4) + - [🔥 ECADD 🔥](#-ecadd-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-5) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-5) + - [Details](#details-5) + - [🔥 ECMUL 🔥](#-ecmul-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-6) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-6) + - [Details](#details-6) + - [🔥 ECPAIRING 🔥](#-ecpairing-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-7) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-7) + - [Details](#details-7) + - [🔥 BLAKE2f 🔥](#-blake2f-) + - [HUB ⇆ PRECOMPILE\_INFO interaction](#hub--precompile_info-interaction-8) + - [HUB ⇆ MMU interaction](#hub--mmu-interaction-8) + - [Details](#details-8) + + +# Dealing with CALL's to precompiles + +## HUB columns sent to PRECOMPILE_INFO + +- ADDR_LO +- GAS_STIPEND (GS) +- GAS_RETURNED (GR) +- CALLDATASIZE (CDS) +- RETURNDATASIZE (RDS) +- SUCCESS +- TOUCHES_RAM +- PROVIDES_RETURNDATA + +**Note** Below we mention the RETURN_AT_CAPACITY (R@C) value: it is the last argument to any CALL-type instruction. + +## 🔥 ECRECOVER 🔥 + + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - TOUCHES_RAM $\\,\\,=\\,\\,$ 0 + - PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 + - RDS $\\,\\,=\\,\\,$ 0 +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - TOUCHES_RAM $\\,\\,=\\,\\,$ 0 + - PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 + - RDS $\\,\\,=\\,\\,$ 0 + We don't need to provide data: the data will be all zeros due to padding and ECRECOVER will be unable to recover a public key. + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - TOUCHES_RAM $\\,\\,=\\,\\,$ 1 + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ RDS = 0 + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ RDS = 32 + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{dataExtractionRamToExo}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{copyResultsFromExoToRam}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _padded to 128_ bytes $\big]$ from RAM to the EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all 32 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy _up to_ 32 bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 SHA2-256 🔥 + + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ +- TOUCHES_RAM $\\,\\,=\\,\\,$ SUCCESS +- PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ SUCCESS +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ RDS $\\,\\,=\\,\\,$ 0 +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ RDS $\\,\\,=\\,\\,$ 32 + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{writeKnownValueToRam}$ (wherein we write SHA2-256(∅) to fictitious RAM) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ + - $\texttt{copyResultsFromExoToRam}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{writeKnownValueToRam}$ must write SHA2-256(∅) to a fictitious context's RAM +2. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _unpadded_ bytes $\big]$ from RAM to the SHA2-256_DATA module +3. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes from SHA2-256_INFO to a fictitious context's RAM +4. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ from the ficitious context's RAM to the current context's RAM + +## 🔥 RIPEMD-160 🔥 + + +(virtually identitcal with [SHA2-256](#sha2-256)) + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ +- TOUCHES_RAM $\\,\\,=\\,\\,$ SUCCESS +- PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ SUCCESS +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ RDS $\\,\\,=\\,\\,$ 0 +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ RDS $\\,\\,=\\,\\,$ 32 + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{writeKnownValueToRam}$ (wherein we write RIPEMD-160(∅) to fictitious RAM) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ + - $\texttt{copyResultsFromExoToRam}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + +### Details + +1. $\texttt{writeKnownValueToRam}$ must write RIPEMD-160(∅) to a fictitious context's RAM +2. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _unpadded_ bytes $\big]$ from RAM to the RIPEMD-160_DATA module +3. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes to a fictitious context's RAM +4. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 IDENTITY 🔥 + +### HUB ⇆ PRECOMPILE_INFO interaction + +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ +- PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 1 $\iff$ (SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\wedge\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0) +- TOUCHES_RAM = PROVIDES_RETURNDATA +- RDS = SUCCESS * CDS + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{moveRamToRam}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{moveRamToRam}$ must transfer $\big[$ CDS _unpadded_ bytes $\big]$ to a fictitious context's RAM +2. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the fictitious context's RAM to current RAM + + +## 🔥 MODEXP 🔥 + +### HUB ⇆ PRECOMPILE_INFO interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ + - $g_r$ $\\,\\,=\\,\\,$ 200 + - RDS $\\,\\,=\\,\\,$ 0 + - PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 + +Some explanation: Given that the extracted data will be 0-padded the first 96 bytes of it are all 0 so that $\ell_B = \ell_E = \ell_M = 0$ and the output is has size 0 (it's the empty byte slice ()). + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - RDS $\\,\\,=\\,\\,$ 0 + - PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - RDS $\\,\\,=\\,\\,$ $\ell_M$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ RDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ RDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 1 + - $g_r$ $\\,\\,\longleftarrow\\,\\,$ requires access to RAM for $\ell_B$, $\ell_E$, $\ell_M$ and the 32 leading bytes of E + - $\ell_M$ $\\,\\,\longleftarrow\\,\\,$ requires access to RAM + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{copyResultsFromExoToRam}$ (all $\ell_M$ = RDS bytes) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 1632 _padded_ bytes $\big]$ from RAM to the MODEXP_DATA module comprising + - (32 + 32 + 32) bytes + (4096 + 4096 + 4096) bits from RAM + - i.e. (2 + 2 + 2) + (32 + 32 + 32) = 102 limbs of 16 byte integers; + - allows access to $\ell_B$, $\ell_E$, $\ell_M$ (these are the first 6 limbs of the data) + - $B$, $E$ and $M$ (contained in the following 96 or less limbs of data) + - the leading 32 bytes of E +2. $\texttt{copyResultsFromExoToRam}$ must copy all $\ell_M$ = RDS result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 ECADD 🔥 + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ $\big[$ TOUCHES_RAM $\\,\\,=\\,\\,1 \big]$ $\\,\\,\wedge\\,\\, \big[x, \\,\\, y \in C_1\big]$ +- PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ SUCCESS +- RDS $\\,\\,=\\,\\,$ 64 * SUCCESS + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ (we write to the EC_DATA module) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{copyResultsFromExoToRam}$ (64 bytes <=> 4 limbs) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 128 _padded_ bytes $\big]$ from current RAM to EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 64 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 ECMUL 🔥 + + +(virtually the same as [ECADD](#ecadd)) + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\iff$ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ $\big[$ TOUCHES_RAM $\\,\\,=\\,\\,1 \big]$ $\\,\\,\wedge\\,\\, \big[ x \in C_1\big]$ +- PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ SUCCESS +- RDS $\\,\\,=\\,\\,$ 64 * SUCCESS + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ (we write to the EC_DATA module) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{copyResultsFromExoToRam}$ (64 bytes <=> 4 limbs) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 96 _padded_ bytes $\big]$ from current RAM to EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 64 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 ECPAIRING 🔥 + + +(similar to [ECADD](#ecadd)) + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\iff$ [ CDS $\\,\\, \equiv 0 \mod 192$ ] $\\,\\,\wedge\\,\\,$ [ GAS_STIPEND $\\,\\,\geq\\,\\,$ $g_r$ ] +- $192\cdot k\\,\\,=\\,\\,$ CDS where $k$ is imported from the EC_DATA module +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ $\big[$ TOUCHES_RAM $\\,\\,=\\,\\,1 \big]$ $\\,\\,\wedge\\,\\, \big[ x_{1}, \dots, x_{k} \in C_1\big]$ $\\,\\,\wedge\\,\\, \big[ y_{1}, \dots, y_{k} \in G_2\big]$ +- PROVIDES_RETURNDATA $\\,\\,=\\,\\,$ SUCCESS +- RDS $\\,\\,=\\,\\,$ 32 * SUCCESS + +**Note.** TOUCHES_RAM = 1 also when CDS = 0 (and gas is sufficient.) Indeed in that case the pairing succedes and outputs 1. There will thus be some known data to fill out in a fictitious contex's RAM. + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{writeKnownValueToRam}$ (wherein we write $\texttt{0x00...0001 }\in\mathbb{B}_{32}$ to fictitious RAM) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ CDS $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ (we write to the EC_DATA module) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{copyResultsFromExoToRam}$ (32 bytes <=> 2 limbs) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ CDS _unpadded_ bytes $\big]$ from current RAM to EC_DATA module +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the ficitious context's RAM to the current context's RAM + + +## 🔥 BLAKE2f 🔥 + + +### HUB ⇆ PRECOMPILE_INFO interaction + +- TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\iff$ [ CDS $\\,\\,=\\,\\,$ 213 ] +- SUCCESS $\\,\\,=\\,\\,$ 1 $\iff$ [ TOUCHES_RAM $\\,\\,=\\,\\,$ 1 ] $\\,\\,\wedge\\,\\,$ [ $f \in \\{ 0, 1\\}$ ] $\\,\\,\wedge\\,\\,$ [ STIPEND $\\,\\,\geq\\,\\, r$ ] +- PROVIDES_RETURNDATA = SUCCESS +- **Note.** $f$ and $r$ will be provided in the module that collects the 213 bytes of RAM data. + + +### HUB ⇆ MMU interaction + +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _RAM noop_ +- $\textcolor{GoldenRod}{\text{If}}\\,\\,$ TOUCHES_RAM $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{dataExtractionRamToExo}$ (we write to some BLAKE2f_DATA module) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ SUCCESS $\\,\\,=\\,\\,$ 1 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ + - $\texttt{copyResultsFromExoToRam}$ (64 bytes <=> 4 limbs) + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,=\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ _that's it_ + - $\textcolor{GoldenRod}{\text{If}}\\,\\,$ R@C $\\,\\,\neq\\,\\,$ 0 $\\,\\,\textcolor{ForestGreen}{\text{Then}}\\,\\,$ $\texttt{moveRamToRam}$ + + +### Details + +1. $\texttt{dataExtractionRamToExo}$ must copy $\big[$ 213 _unpadded_ bytes $\big]$ from current RAM to BLAKE2f_DATA module (which also contains the result if applicable) +2. $\texttt{copyResultsFromExoToRam}$ must copy all RDS = 32 result bytes to a fictitious context's RAM +3. $\texttt{moveRamToRam}$ must copy $\min\\{$ RDS, R@C $\\}$ bytes from the ficitious context's RAM to the current context's RAM + +| INDEX | LIMB | PARAMS | +|-------|-------|--------| +| 0 | ... | r | +| 1 | ... | f | +| 2 | ... | 0 | +| ... | ... | ... | +| 13 | ... | 0 | + +N.B. 14 * 16 = 213 so there will be 14 data limbs in the BLAKE2f_DATA module per BLAKE2f call + + + + diff --git a/notes/prover_notes_account.md b/notes/prover_notes_account.md new file mode 100644 index 0000000..dcccc86 --- /dev/null +++ b/notes/prover_notes_account.md @@ -0,0 +1,98 @@ +# Account and storage management in the zkevm from the prover POV + +The zkevm is able to prove internal consistency for account fields and storage values touched / read in a batch of transactions. In so doing it is able to identify when an account (or a storage key/value pair) is touched for the **first time** and when an account (or a storage value/key pair) is touched for the **last time** in the execution of said batch of transactions. Identifying these special "first" and "final" interactions with Linea state allows us extract the required state data and to update it accordingly. This identification happens in the "permuted domain" where access to the same account or storage key are listed contiguously and in chronological order. + +- [Account and storage management in the zkevm from the prover POV](#account-and-storage-management-in-the-zkevm-from-the-prover-pov) +- [Account Data](#account-data) + - [Account consistency permutation](#account-consistency-permutation) + - [(reordered) Account data](#reordered-account-data) + - [Interaction with the state](#interaction-with-the-state) + - [Account existence](#account-existence) + +# Account Data + +## Account consistency permutation + +We use the acronym **acp** for "account consistency permutation" (the names may evolve.) This is a permutation of the row set of the HUB module. If X is a column in the arithmetization then acp_X is the column obtained by applying the `acp` to the rows of X. The `acp` used by the arithmetization is **some** row permutation with the following properties +1. padding-rows, after permutation, appear before non padding-rows +2. account-rows are contiguous +3. within (reordered) account-rows, rows are ordered as follows + - account addresses are listed in "ascending" order + - among (reordered) account-rows with the same address, rows are listed in chronological order + +**Note.** The standard, non permuted trace has **exclusive binary columns** PEEK_AT_ACCOUNT, PEEK_AT_CONTEXT, PEEK_AT_MISCELLANEOUS, PEEK_AT_STACK, PEEK_AT_STORAGE, PEEK_AT_TRANSACTION. Rows where PEEK_AT_XXX ≡ 1 are labelled XXX-rows. This is what we mean by account-rows, storage-rows, etc ... Similarly a **reordered account-row** is one where acp_PEEK_AT_ACCOUNT ≡ 1. + +**Note.** The arithmetization uses multiplexed columns. Thus the same underlying, physical column X (or register), may, on some row i contain a value X[i], which according to whether we are on an account-row, context-row, etc ... will have a different name in the arithmetization (e.g. account/BALANCE[i] or context/CFI[i] or misc/MXP_OOGX[i] or storage/KEY_LO[i] etc ...) and, accordingly, a completely different interpretation. + +## (reordered) Account data + +The Arithmetization will provide the following columns +- binary column acp_PEEK_AT_ACCOUNT + - `true` on (reordered) account rows + - `false` on all other (reordered) rows +- binary columns FIRST_AOC, FINAL_AOC + - The acronym `AOC` stands for "account occurrence." + - both are false on (reordred) rows that aren't (reordered) account-rows + - FIRST_AOC lights up on the first (reordered) account-row featuring some given address + - FINAL_AOC lights up on the final (reordered) account-row featuring some given address + - both may be on the same row if a particular account is only viewed once (e.g. successful simple transfer) +- account field columns: + - acp_account/ADDRESS_HI + - acp_account/ADDRESS_LO + - acp_account/CODE_HASH_HI + - acp_account/CODE_HASH_LO + - acp_account/CODE_HASH_HI_NEW + - acp_account/CODE_HASH_LO_NEW + - acp_account/NONCE + - acp_account/NONCE_NEW + - acp_account/CODE_SIZE + - acp_account/CODE_SIZE_NEW + - acp_account/BALANCE + - acp_account/BALANCE_NEW + +We also mention the two following rows that are of no use to the account side of things but will be important when it comes to storage (and byte code.) +- acp_account/DEPLOYMENT_NUMBER +- acp_account/DEPLOYMENT_NUMBER_INFTY + +## Interaction with the state + +The rows of interest can be filtered out by means of FIRST_AOC[i] + FINAL_AOC[i] ≠ 0 (or FIRST_AOC[i] + FINAL_AOC[i] - FIRST_AOC[i] ∙ FINAL_AOC[i] = 1). + +**Original values** +- rows with original values are characterized by FIRST_AOC ≡ 1; the zkevm needs to trust the coherence of the following values wrt to the initial state + - acp_account/ADDRESS_HI + - acp_account/ADDRESS_LO + - acp_account/CODE_HASH_HI + - acp_account/CODE_HASH_LO + - acp_account/CODE_SIZE + - acp_account/NONCE + - acp_account/BALANCE + +**Updated values** +- rows with updated values are characterized by FINAL_AOC ≡ 1; the state needs to update itself to reflect the following + - acp_account/ADDRESS_HI + - acp_account/ADDRESS_LO + - acp_account/CODE_HASH_HI_NEW + - acp_account/CODE_HASH_LO_NEW + - acp_account/CODE_SIZE_NEW + - acp_account/NONCE_NEW + - acp_account/BALANCE_NEW + +## Account existence + +**Note.** The zkevm already has to compute the following binary value +- account/EXISTS +- account/EXISTS_NEW + +These are bits that equal 1 if the account **exists**. Recall that the account associated with a particular address $a$ is said to not exist in the state $\sigma$ (and $\sigma[a] = \varnothing$) if +- it has zero nonce i.e. $\sigma[a]_\text{n} = 0$ +- it has zero balance i.e. $\sigma[a]_\text{b} = 0$ +- it has empty code i.e. $\sigma[a]_\text{c} = \texttt{KECCAK}\big((\\;)\big)$ + +In all other cases the account is deemed to exist. If desirable we can include these bits in the permutation argument and also send them to the prover. + +We could include them in the permutation argument and provide you with +- acp_account/EXISTS +- acp_account/EXISTS_NEW + +to help the prover distinguish between accounts that the zkevm expects to find in the state of Linea vs. those that are, say, created during a transaction and don't really exist in the state. diff --git a/notes/prover_notes_bytecode.md b/notes/prover_notes_bytecode.md new file mode 100644 index 0000000..ffeffec --- /dev/null +++ b/notes/prover_notes_bytecode.md @@ -0,0 +1,46 @@ +# Smart contract byte code + +- [Smart contract byte code](#smart-contract-byte-code) + - [Accessing byte code from Linea state](#accessing-byte-code-from-linea-state) + - [Committing byte code to the Linea state](#committing-byte-code-to-the-linea-state) + - [Notes on addressing columns from different modules](#notes-on-addressing-columns-from-different-modules) + +## Accessing byte code from Linea state + +The byte code of an account **which exists in the Linea state** may be required to be loded if +- the address pointing to the account can be found among account rows of the HUB +- the underlying account **exists** and has **nonempty bytecode** +- the byte code is actually accessed either through + - execution (target of a message call transaction or (STATIC/DELEGATE)CALL(CODE)'ed during transaction execution) + - code copy (target of a EXTCODECOPY) + +**Note.** If code is being CODECOPY'd the underlying account must already be executing, so the first bullet point was previously true. + +In either of these circumstances the ROMLEX module will have a reference to +- ADDRESS_HI, ADDRESS_LO, DEPLOYMENT_NUMBER = 0, DEPLOYMENT_STATUS = 0 + +## Committing byte code to the Linea state + +Byte code of an account with address _a_ may either +- assuming it existed in Linea state: + - continue to exist if both + - hub.account/DEPLOYMENT_NUMBER_INFTY = 0 + - (final) hub.acp_account/EXISTS_NEW = 1 + - be erased if either + - hub_account/DEPLOYMENT_NUMBER_INFTY ≠ 0 + - (final) hub.acp_account/EXISTS_NEW = 0 +- be introduced + - hub.account/DEPLOYMENT_NUMBER_INFTY ≠ 0 + - (final) hub.acp_account/EXISTS_NEW = 1 + - (final) hub.acp_account/CODE_SIZE_NEW ≠ 0 + - then the code can be copied from ROM using the CFI associated with the ROMLEX values + - rom.CFI ← romlex.CFI + - gives access to the pairs [INDEX, LIMB] of byte code limbs + - romlex.CFI ← [ romlex.ADDRESS_HI, romlex.ADDRESS_LO, romlex.DEPLOYMENT_NUMBER ] + - romlex.ADDRESS_HI ← hub.acp_account/ADDRESS_HI + - romlex.ADDRESS_LO ← hub.acp_account/ADDRESS_LO + - romlex.DEPLOYMENT_NUMBER ← hub.account/DEPLOYMENT_NUMBER_INFTY + +## Notes on addressing columns from different modules + +To disambiguate column names that may occurr in several modules we use the following notation `module.COLUMN` to talk unambiguously about column `COLUMN` in the module called `module`. We remind the reader that we also have special notation for multiplexing columns whereby (e.g. in the HUB) we may speak of a column belonging to the perspective e.g. account with name e.g. BALANCE and address it as `account/BALANCE`. If this column interacts with columns from other modules we may apply both conventions and speak say of column `hub.stack/STACK_ITEM_VALUE_HI_4` to speak of the column `STACK_ITEM_VALUE_HI_4` belonging to the `stack` perspective of the `hub` module. diff --git a/notes/prover_notes_storage.md b/notes/prover_notes_storage.md new file mode 100644 index 0000000..5f49518 --- /dev/null +++ b/notes/prover_notes_storage.md @@ -0,0 +1,80 @@ +# Storage data + +- [Storage data](#storage-data) + - [Storage consistency](#storage-consistency) + - [(reordered) Storage data](#reordered-storage-data) + - [Interaction with the state](#interaction-with-the-state) + +## Storage consistency + +Like for account data we use an acronym **scp** for "storage consistency permutation" (again, names may evolve.) This is a permutation of the row set of the HUB module. If X is a column in the arithmetization then scp_X is the column obtained by applying the `scp` to the rows of X. The `scp` used by the arithmetization is **some** row permutation with the following properties +1. padding-rows, after permutation, appear before non padding-rows +2. storage-rows are contiguous +3. within (reordered) storage-rows, rows are ordered as follows + - account addresses are listed in ascending order + - among (reordered) storage-rows with the same address storage keys are listed in ascending order + - amont (reordered) storage-rows with the same address and storage key, rows are listed in "chronological" order + +**Note.** We refer the reader to the note on account consistency from the prover POV for the explanation of what constitutes a (reordered) storage-row. + +## (reordered) Storage data + +The Arithmetization will provide the following columns +- binary column acp_PEEK_AT_STORAGE + - `true` on (reordered) account rows + - `false` on all other (reordered) rows +- binary columns FIRST_KOC, FINAL_KOC + - The acronym `KOC` stands for "(storage) key occurrence." + - both are false on (reordred) rows that aren't (reordered) storage-rows + - FIRST_AOC lights up on the first (reordered) storage-row featuring some given address and some given storage key + - FINAL_AOC lights up on the final (reordered) storage-row featuring some given address and some given storage key + - both may be on the same row if a particular storage slot is only viewed once (e.g. a single (unreverted) SLOAD or a single (unreverted) SSTORE) +- account field columns: + - scp_storage/ADDRESS_HI + - scp_storage/ADDRESS_LO + - scp_storage/KEY_HI + - scp_storage/KEY_LO + - scp_storage/VALUE_HI_CURR + - scp_storage/VALUE_LO_CURR + - scp_storage/VALUE_HI_NEXT + - scp_storage/VALUE_LO_NEXT + - scp_account/DEPLOYMENT_NUMBER + - scp_account/DEPLOYMENT_NUMBER_INFTY + +## Interaction with the state + +The rows of interest can be filtered out by means of FIRST_KOC[i] + FINAL_KOC[i] ≠ 0 (or FIRST_KOC[i] + FINAL_KOC[i] - FIRST_KOC[i] ∙ FINAL_KOC[i] = 1). + +**Original values** +- rows with original values to be extracted from the Linea state are characterized by + - FIRST_KOC ≡ 1 + - scp_storage/DEPLOYMENT_NUMBER = 0 +- the zkevm needs to trust the coherence of the following values wrt to the initial state + - scp_storage/ADDRESS_HI + - scp_storage/ADDRESS_LO + - scp_storage/KEY_HI + - scp_storage/KEY_LO + - scp_storage/VALUE_HI_CURR + - scp_storage/VALUE_LO_CURR + +**Updated values** +- rows with final values to be committed to the Linea state are characterized by + - FINAL_KOC ≡ 1 + - scp_storage/DEPLOYMENT_NUMBER = scp_storage/DEPLOYMENT_NUMBER_INFTY +- the state needs to update itself to reflect the following + - scp_storage/ADDRESS_HI + - scp_storage/ADDRESS_LO + - scp_storage/KEY_HI + - scp_storage/KEY_LO + - scp_storage/VALUE_HI_NEXT + - scp_storage/VALUE_LO_NEXT + +**Account non existence** +- if an account originally existed in state and ends up, after a batch of transactions, with (final) acp_account/EXISTS_NEW = 0 then all original values in storage must be discarded, regardless of whether any storage values were used in the execution. + +The above can happen with a SELFDESTRUCT (it's the only way.) + +**Account redeployment** +- if an account originally existed in state and ends up after the batch of transaction with acp_account/DEPLOYMENT_NUMBER_INFTY ≠ 0 then all original values in storage must be discarded, regardless of whether any storage values were required during execution. + +The above can happen for instance if an account was SELFDESTRUCT'ed in some transaction T and in a later transction T' (same batch of tx's) redeployed (the original account was created with a CREATE2 so redeployments at the same address are possible. diff --git a/notes/stipend.md b/notes/stipend.md new file mode 100644 index 0000000..f5e24ad --- /dev/null +++ b/notes/stipend.md @@ -0,0 +1,167 @@ +- [The `STI` module](#the-sti-module) + - [Purpose](#purpose) + - [High level specification](#high-level-specification) + - [Input columns](#input-columns) + - [CREATE(2) case](#create2-case) + - [CALL case](#call-case) + - [Column and constraint details](#column-and-constraint-details) + - [CREATE workflow](#create-workflow) + - [CALL workflow](#call-workflow) + + +# The `STI` module + +## Purpose + +The purpose of the present `STI` module is to carry out the computation producing the gas stipend provided to any context spawned through a CALL-type instruction or a CREATE-type instruction. + +**Note.** The stipend itself is already claimed (without proof) in the `hub` (or will be, once the update to the `hub` is implemented.) For justficiation the `hub` will lookup the computaiton in the STI module, thereby justify the associated values which the `hub` merely claims. Note furthermore that the present module is stateless. + +## High level specification + +### Input columns + +The following are columns that will be imported from the HUB. All of them are trustworthy with the exception of GAS_STIPEND, of course, which has to be justified in the present module. + +- INST_TYPE: binary column +- VALUE_TRANSFER: binary column which = 1 only for CALL-type instructions which may transfer value + +**Note.** The `hub` module will prefil these out depending on the instruction. + +- GAS_UPDT: gas amount available to the execution context just prior to dealing with the current CALL-type or CREATE-type instruction +- GAS_COST: sum of all upfront gas costs associated with the instruction (e.g. static cost, memory expansion cost, hashing cost for CREATE2, account creation cost for CALL-type instruction whose recipient account doesn't exist in the state, warmth cost, value transfer cost ...) +- GAS_HI, GAS_LO: required only for CALL-type instructions, 256 bit stack argument containing the 'max gas stipend' parameter $\mu{s}\big[0\big]$ of the instruction +- VALUE_HI, VALUE_LO: required for CALL-type isntructions that take a value parameter (i.e. CALL and CALLCODE) +- GAS_STIPEND: the value which ought to be justified + + + +As far as I understand the stipend computation doesn't depend on the instruction _per se_, only on the instruction type and, in case of CALL-type instructions, on whether the instruction accepts a value parameter. One may thus set, for instance + +1. CALL-type (e.g. INST_TYPE = 0) + 1. CALL (e.g. VALUE_TRANSFER = 1) + 1. CALLCODE (e.g. VALUE_TRANSFER = 1) + 1. DELEGATECALL (e.g. VALUE_TRANSFER = 0) + 1. STATICCALL (e.g. VALUE_TRANSFER = 0) +1. or CREATE-type (e.g. INST_TYPE = 1) + 1. CREATE + 1. CREATE2 + +**Note.** The `hub` should have already justified the inequality + +$$\textsf{GAS\\_UPDT} \geq \textsf{GAS\\_COST} ~ ( \geq 0 )$$ + +by means of a lookup to the WCP module. One may thus assume this inequality true. Alternatively one may set up the constraints for that comparison which would provide a short term guarantee of correctness, won't take up that much space but will be dropped later. + +### CREATE(2) case + +AFAIR one simply has to compute + +$$\lambda := L(\textsf{GAS\\_UPDT} - \textsf{GAS\\_COST})$$ + +Where $L(n) := n - \lfloor n/64 \rfloor$ and impose that + +$$\textsf{GAS\\_STIPEND} == \lambda$$ + +### CALL case + +This case starts with the same computation of + +$$\lambda := L(\textsf{GAS\\_UPDT} - \textsf{GAS\\_COST})$$ + +Next one must compare compare $\lambda$ and the 256-bit integer $\mu{s}\big[0\big]$. This can be done via a lookup to the WCP module. Using the outcome of that comparison one can impose that + +$$\textsf{GAS-STIPEND} == \min \big\lbrace \lambda, \mu_{\textbf{s}} \big[ 0 \big] \big\rbrace + 2300 \cdot \textsf{VALUE-TRANSFER} \cdot \big[ \mu_{\textbf{s}} \big[ 2 \big] \neq 0 \big]$$ + +For more details on the CALL cost computation consult #13 + + +Type = bit (1 or 0 depending on whether it's a CALL type instruction or a CREATE type instruction) +VALUE_LOOKUP_FLAG = bit, only true for CALL and CALLCODE (since they have value parameters) + +## Column and constraint details + +There must be the following: +- STAMP column: counts monotonically from 0 to ... +- COUNTER column: zero while STAMP is zero, and as soon as STAMP nonzero it cycles 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ... +- some instruction specific columns that distinguish between them: + - VALUE_LOOKUP_FLAG binary column (=1 for CALL and CALLCODE only) + - TYPE binary column (for instance `TYPE = 0` for all CALL's and `TYPE = 1` for all CREATE's) + + + + + + + + + + + +| INST | TYPE | VALUE_LOOKUP_FLAG | VALUE_HI | VALUE_LO | TRANSFERS_VALUE | +|--------------+----------+-------------------+----------+----------+-------------------| +| CALL | callType | 1 | v_hi | v_lo | =1 <=> value != 0 | +| CALLCODE | callType | 1 | v_hi | v_lo | =1 <=> value != 0 | +| STATICCALL | callType | 1 | 0 | 0 | 0 | +| DELEGATECALL | callType | 1 | 0 | 0 | 0 | +|--------------+----------+-------------------+----------+----------+-------------------| + + +For COUNTER there are two options: +- either have a very specific behaviour, e.g. COUNTER: 0, 1, 2, 3 or 0, 1, 2 or just 0, 1 depending on CALL transfering value, CALL not transfering value or CREATE +- either have generic behaviour: COUNTER: 0, 1, 2, 3 _always_ <--- likely the best option + +Have some "counter-constancy" constraints on columns imported from the HUB: +- INST +- GAS_UPDT +- GAS_COST +- GAS_STIPEND +- GAS_HI +- GAS_LO +- VAL_HI +- VAL_LO + +We can have some columns that contain the contents of things to look-up else where, e.g. +- LOOKUP_ARG_1_HI +- LOOKUP_ARG_1_LO +- LOOKUP_ARG_2_HI +- LOOKUP_ARG_2_LO +- LOOKUP_RES_HI +- LOOKUP_RES_LO +- LOOKUP_INST +- WCP_SELECTOR: binary column that acts as the selector for data to send to WCP +- MOD_SELECTOR: binary column that acts as the selector for data to send to MOD + +**Note.** The high parts of all inputs are zero except for when comparing GAS = $\mu_\textbf{s}\big[0\big]$ with $L(\cdots)$. The High part of all results will always be zero. We could therefore kill the following: +- LOOKUP_ARG_2_HI +- LOOKUP_RES_HI + +The idea would be that one has +- WCP_SELECTOR * EXT_SELECTOR = 0 +- If STAMP = 0 Then WCP_SELECTOR + MOD_SELECTOR = 0 (i.e. both are zero) +- If WCP_SELECTOR = 1 Then LOOKUP_INST $\in$ { LT, ISZERO } (i.E. we can only request LT and ISZERO instuctions) +- If MOD_SELECTOR = 1 Then LOOKUP_INST = DIV (i.e. we can only request the DIV from MOD) + +### CREATE workflow + +- CT = 0: compare GAS_UPDT with GAS_COST + +_If_ the above comparison worked with the desired comparison bit _Then_ + +- CT = 1: 1/64th computation (with a single CALL to MOD module using the DIV instruction and argument GU - GC and 64 which gives you the floor.) + **Note.** The RES_HI / RES_LO columns for the MOD lookup will contain the \lambda := L(GU - GC) + +You should only require 2 rows so if you have a counter that always counts to 3 you would be idle for the next 2 rows + +### CALL workflow + +- CT = 0: compare GAS_UPDT with GAS_COST (for all instructions) + +_If_ the above comparison worked with the desired comparison bit _Then_ + +- CT = 1: 1/64th computation (with a single CALL to MOD module using the DIV instruction and argument 1 being GU - GC and argument 2 being 64 - this gives you the desired floor.) + +**Note.** The RES_HI / RES_LO columns for the MOD lookup will contain the $\lambda$ := L(GU - GC) + +- CT = 2: compute the minimum (for all CALLs calling to WCP with LT instruction) +- CT = 3: compare GAS_UPDT with GAS_COST (for CALLs that may transfer value calling WCP with the ISZERO instruction) diff --git a/notes/talk_arithmetization.md b/notes/talk_arithmetization.md new file mode 100644 index 0000000..91133e4 --- /dev/null +++ b/notes/talk_arithmetization.md @@ -0,0 +1,32 @@ +# zk-evm + +# Arithmetization + +# Techniques + +- arithmetic mismatch +- size proofs +- comparisons +- dominant / subordinate stamp technique +- reordering arguments +- lex. ordering techniques +- perspectives +- RAM instructions +- sporadic gas checks + +# Intricacies of the EVM + +- padding (zero padding) +- EXTCODECOPY / EXTCODEHASH / EXTCODESIZE +- trimming (ADDRESS) +- deployment number / status + - CREATE2 / CREATE / SELFDESTRUCT / deployment failure + - several pieces of code with a given address + - updating storage (invisible update in case of SELFDESTRUCT) +- warmth, prewarming +- RLP everywhere +- size issues ("type system") + - stack items must be small + - byte decomposition of data flowing into the zkevm + - tx rlp + ROM + storage +- precompiles (magic values appearing in RAM) diff --git a/notes/talk_ethcc b/notes/talk_ethcc new file mode 100644 index 0000000..18d7faf --- /dev/null +++ b/notes/talk_ethcc @@ -0,0 +1,39 @@ +$# arith + - basics on arithmetization and the problem + - Patrick McCorry blog post on Blockchains + - complete arith + - conflation (efficacité, price reduction) + +Slides +- zk-rollup with internal logic = EVM +- zk-rollup => translation of that logic into the language of circuits and polynomials +- life-cycle of transaction: + - RLP + - execution + - transaction receipt + +# prover + - schéma général (Vortex, Arcane, arithmetization + gnark + KEC circuit) + - ECDSA + - KECCAK +# différences api + - opcodes (Number, Basefee, PREVRANDAO) + - seqencer imposed limits (SHA3, ECDSA) + - MODEXP limited to 4096 bit integers + - tx with TO = precompile: not accepted + - tx that are INVALID: not accepted + - calldata limitation (in effect: 150 tx / batch) + - BASEFEE = 0 +# points communts + - codehash +# bridge + - audit de SC + - Julien ? +# state: + - MiMC used internally for proving and internal state representation + - discuter avec Karim ? + +# Questions pour Nicolas: + - sequencer / state manager + - talk about limits ? + - ... décentralization ? diff --git a/notes/tests.md b/notes/tests.md new file mode 100644 index 0000000..d5a93ac --- /dev/null +++ b/notes/tests.md @@ -0,0 +1,108 @@ +# Test scenarios + +The instructions that require most intensive testing are: +- CALL's +- CREATE's +- SELFDESTRUCT +- SSTORE / SLOAD + +Tests should focus on +- exception handling in particular opcode pricing in terms of + - account existence / warmth + - storage values (original, current and next) +- abort condition handling (CALL's / CREATE's) +- failure condition handling (CREATE's and CALL's to precompiles) +- rollback handling (in particular wrt deployments, warmth, refunds, SELFDESTRUCT's) +- refund tallying + - for SSTORE instructions and SELFDESTRUCT's + - wrt rollbacks and the MARKED_FOR_SELFDESTRUCT flag +- storage, in particular wrt + - rollbacks + - successive deployments + - SELFDESTRUCT's + +and their interactions. + +## CALL-type instructions + +**Exception scenarios:** +- stackUnderflowException +- staticContextException (only for CALL's which transfer value in a static environment) +- MXPX +- outOfGasException (but MXPX = false) + - TO is warm ? + - TO exists ? + - CALL / CALLCODE transfers value + +**Abort scenarios:** +- No exception but + - CALLSTACKDEPTH = 1024 + - from.Balance < callValue + +**TO addresses:** +- Non precompile + - has code + - doens't have code + - TO has been deployed several times with same or different code within the block +- Precompile (Emile's PRECOMPILE_INFO module) + - correct gas costs + - correct exception cases +- Address trimming is done correctly + +CALL(address, ...) address µ[0] mod 2^160 + +## CREATE-type instructions + +**Exception scenarios:** +- stackUnderflowException +- staticContextException +- MXPX +- out of gas (but MXPX = false) + +**Abort scenarios:** +- No exception but + - CALLSTACKDEPTH = 1024 + - from.Balance < callValue + +**Failure condition:** +- No exception, no abort but + - deployment address has nonzero nonce + - deployment address has nonempty code + +## SELFDESTRUCT + +Main point: test how SELFDESTRUCT's interact with +- other SELFDESTRUCT's on the same address: +- with ROLLBACK's +- STORAGE instructions (in particular deployment numbers) + +**Note.** During a transaction, an address that has been marked for SELFDESTRUCT remains operational as previously in particular in terms of execution (same bytecode) and storage. It can continue to deploy other contracts, it can be CALL'ed, etc ... + +**Exception scenarios:** +- stackUnderflowException +- staticContextException +- out of gas + - TO is warm ? + - TO exists ? + - SELFDESTRUCT transfers value or not ? + +**Refund counter:** +- Refunds are paid out only once even if a given address triggers several SELFDESTRUCTS's before the end of a transaction (TAGGED_FOR_SELFDESTRUCT) + +TO address parameter: +- Address trimming is done correctly + +## STORAGE + +**Exception scenarios:** +- stackUnderflowException +- staticContextException (for SSTORE's) +- sstoreGasException (for SSTORE's) +- outOfGasException + - complex pricing model depending on current value, original value, next value etc ... + +**Refund counter** +- computed correctly +- discarded correctly in terms of rollbacks + +Interaction with successive deployments and SELFDESTRUCT's. diff --git a/notes/traces determine batch b/notes/traces determine batch new file mode 100644 index 0000000..4c4d140 --- /dev/null +++ b/notes/traces determine batch @@ -0,0 +1,13 @@ +to a set of polynomials such that all the relations hold, it corresponds exactly one correct trace ? + +We don't have such tests and I'm not sure how one would test for this, but looking at the way the traces are constructed I believe this is the case. There are several reasons for saying this. + +First of all the connection with public data and the associated constraints will prove to the verifier that the prover only executed the transactions declared in the batch. There can be no stealth transactions. Stealth transaction would be a disaster as other operators would be incapable of computing the updated state. + +Secondly, with the issues of stealth transactions out of the way, comes the question of the execution itself. Before touching upon execution one must settle the question of what bytecode is being run and whether there can be any ambiguity. Again my point is that there can not and if an ambiguity were to appear that we would be able to patch it with existing methods. The bytecode to be executed is given either (a) as public data (input data of the transaction used as initialization code in the execution) (b) bytecode previously committed to the state or (c) a slice of memory from an execution context which hits a CREATE(2) instruction that it can afford in terms of gas. The first case is covered by my earlier point about connecting the proof to public (block) data. The second case is about retrieving committed bytecode from the state. This will be handled by opening a commitment. The third case will be covered by my next point which is more general. Indeed, it touches upon executing individual instructions (of which RAM related opcodes and CREATEs are particular cases). I'll state my conclusion for that subcase right now: we can expect that the bytecode that's being run as initialization code of a CREATE(2) instruction is the expected one. There are quite a few subtleties that I'm brushing under the carpet about CREATE(2) in the presence of reverts which I won't get into them here + +Thirdly, and lastly, the execution itself. For every relevant opcode its inputs/outputs appear as evaluations on the domain of at least one cell in the trace on the line(s) corresponding to the instruction. These inputs/outputs are funneled through to the relevant modules where outputs are justified. There are operations that are invisible on the stack (e.g. RAM operations such as RETURN that pop items off the stack but all the work happens in the background). In the case of RAM, for instance, the arguments of the various micro-instructions that in conjunction produce the desired effect (copying the relevant slice of bytes from one place to another, say) are checked by coherence conditions. For RAM the coherence conditions are simple: RAM is initially empty, and when a slice of 16 consecutive bytes (a limb) is touched at one point in time (serving either as a source of bytes or as a target in which to modify some bytes) then it produces a new value (e.g. VAL_A and VAL_A_NEW in the MMIO arithmetization) and the next time that slice of bytes is touched we expect to find in VAL_A what was previously written into VAL_A_NEW. Permutation arguments allow us to make this practical by grouping together all accesses to limbs in RAM in such a way that all RAM operations relative to a given execution context are contiguous, and within that all accesses to the limb with given offset are contiguous, and within that all accesses are ordered chronologically. This is the content of the "coherence checks" that was mentioned in one of the slides. + +RAM is by far the most complicated case. Other operations are simpler: modules such as WORD_COMPARISON etc ... just perform standard boring operations whose arithmetization should be uncontroversial. + +In any case, my final point is the following: other than for human mistakes in the arithmetization of certain operations the traces of individual modules are extractable: you can recover the inputs (and outputs if you want) of each and every instruction. \ No newline at end of file diff --git a/notes/transaction_tests_wrt_state.md b/notes/transaction_tests_wrt_state.md new file mode 100644 index 0000000..52c3938 --- /dev/null +++ b/notes/transaction_tests_wrt_state.md @@ -0,0 +1,18 @@ +Assert at the very beginning +- tx.nonce is an 8 byte integer +- tx.nonce == account.Nonce (sender, pre anything) +- initial balance (sender, pre anything) +- tx.nonce's are in order over various transactions emanating from a single sender + - this is about the sequencer +- scenario: + - one transaction deploys some SC + - a later transaction in the block calls it (directly, to == deployed address) + - one tx makes some address SELFDESTRUCT + - a later tx targets directly the SELFDESTRUCT'ed account +- REQUIRES_EVM_EXECUTION: boolean which is only false in the following scenarios + - message call and to address has empty byte code (i.e. pure transfer) + - deployment transaction whose initialization code is empty + +Test that these are as advertized is happening in the hub module. + +Test for type 0, 1, 2 tx's. diff --git a/notes/x.md b/notes/x.md new file mode 100644 index 0000000..bd99469 --- /dev/null +++ b/notes/x.md @@ -0,0 +1,22 @@ +# 01.03.2024 + +i- BIN module BYte operation verificaiton +- several properties required to do so +- automation will take too much time +- SIGNEXTEND will e done soon, too +- similar to BYTE + +- using a technique "finite quantification" +- "for all" over bounded domain can be replaced by explicit formulas +- in BIN (BYTE, SIGNEXTEND) but also SHF +- you want ot establish some intermediate property +- e.g. get the 6th BYTE and make it available through stamp constancy +- establishing in forward & backward direction (since the PIVOT byte appears "along the way fora particular CT row", need to be propagated in both directions) +- Thus for all CT <= 6 and for all CT >= 6 etc ... + +- difficulties with flag_sum's and weight_sum's as used everywhere for instruction decoding +- Z3 can deal with it but it's easiest to rewrite it for Z3 for performance gain +- would make sense to have corset semantics for dealing with binary values (negation, and, or ...) +- more readable binary semantics for corset ? + - would be more easily interpretable by corset => whatever + - would also be more direct for corset writers diff --git a/oob/_all_oob.tex b/oob/_all_oob.tex new file mode 100644 index 0000000..6bbb611 --- /dev/null +++ b/oob/_all_oob.tex @@ -0,0 +1,47 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/oob} +\usepackage{../pkg/stp} +\usepackage{../pkg/stack} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/trm} +\usepackage{../pkg/misc} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/log_info} + +\usepackage{../pkg/draculatheme} + +\title{The \oobMod{} module} +\author{Rollup team} +\date{September 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/oob/_inputs.tex b/oob/_inputs.tex new file mode 100644 index 0000000..34ec526 --- /dev/null +++ b/oob/_inputs.tex @@ -0,0 +1,20 @@ +% local shorthands +\input{_local} + +\section{Out of bounds module} +\subsection{Introduction} \input{intro} \label{oob: intro} +\subsection{Columns} \input{columns} \label{oob: columns} + +\section{Constraints} +\subsection{Shorthands and constants} \input{shorthands} \label{oob: shorthands} +\subsection{Binary constraints} \input{binary} \label{oob: binary} +\subsection{Instruction decoding} \input{decoding} \label{oob: instruction decoding} +\subsection{Constancy constraints} \input{constancies} \label{oob: counter-constancies} +\subsection{Heartbeat} \input{heartbeat} \label{oob: heartbeat} +\subsection{Constraint systems for populating lookups} \input{specialized} \label{oob: specialized constraints} + +\input{opcodes/_inputs} + +\input{precompiles/_inputs} + +\section{Lookups} \input{lookups/_inputs} \label{oob: lookups} diff --git a/oob/_local.tex b/oob/_local.tex new file mode 100644 index 0000000..def20cc --- /dev/null +++ b/oob/_local.tex @@ -0,0 +1,218 @@ +\newcommand{\locInc} [1] {\col{INC\_#1}} +\newcommand{\locOut} [1] {\col{OUT\_#1}} +\newcommand{\x} [1] {\cellcolor{solarized-green!40!yellow}#1} +\def\locIncomingInstruction {\col{INC\_INST}} +\def\locCallGas {\col{call\_gas}} +\def\locCeil {\col{ceil}} +\def\locHi {\col{\_hi}} +\def\locLo {\col{\_lo}} +\def\one {\cellcolor{\romCol}\bm{1}} +\def\rOne {\red{1}} +\def\zero {\bm{0}} +\def\gZero {\graym{0}} +\def\locAdd {\redm{1}} +\def\locMod {\redm{2}} +\def\locWcp {\redm{3}} + +% arguments for specialized constraints +\def\locArgOneHi {\col{arg\_1\_hi}} +\def\locArgOneLo {\col{arg\_1\_lo}} +\def\locArgTwoHi {\col{arg\_2\_hi}} +\def\locArgTwoLo {\col{arg\_2\_lo}} +% +\def\locPrecompileCost {\col{precompile\_cost}} +\def\locRemainingGas {\col{remaining\_gas}} +\def\locCdsIsZero {\col{cds\_is\_zero}} +\def\locCdsIsNonZero {\col{cds\_nonzero}} +\def\locReturnAtCapacity {\col{return\_at\_capacity}} +\def\locRac {\col{r@c}} +\def\locRacIsZero {\col{r@c\_is\_zero}} +\def\locRacIsNonZero {\col{r@c\_nonzero}} +\def\locCeil {\col{ceil}} +\def\locRemainder {\col{remainder}} +\def\locPairingSizeIsMultiple {\col{is\_multiple\_of\_192}} +\def\locSufficientGas {\col{sufficient\_gas}} +\def\locInsufficientGas {\col{insufficient\_gas}} +% JUMP / JUMPI +\def\locPcNew {\col{pc\_new}} +\def\locPcNewHi {\locPcNew\locHi} +\def\locPcNewLo {\locPcNew\locLo} +\def\locJumpCondition {\col{jump\_cond}} +\def\locJumpConditionHi {\locJumpCondition\locHi} +\def\locJumpConditionLo {\locJumpCondition\locLo} +\def\locJumpConditionIsZero {\col{jump\_cond\_is\_zero}} +\def\locCodeSize {\col{code\_size}} +\def\locInvalidPcNew {\col{invalid\_pc\_new}} +\def\locValidPcNew {\col{valid\_pc\_new}} +\def\locJumpNotAttempted {\col{jump\_not\_attempted}} +\def\locJumpGuaranteedException {\col{jump\_guaranteed\_exception}} +\def\locJumpMustBeAttempted {\col{jump\_must\_be\_attempted}} +\def\locJumpiNotAttempted {\col{jumpi\_not\_attempted}} +\def\locJumpiGuaranteedException {\col{jumpi\_guaranteed\_exception}} +\def\locJumpiMustBeAttempted {\col{jumpi\_must\_be\_attempted}} +% CALL +% XCALL +\def\locNzv {\colm{[val \neq 0]}} % nzv <=> non zero value +\def\locNonzeroValue {\col{value\_is\_nonzero}} +\def\locBalanceAbort {\col{insufficient\_balance\_abort}} +\def\locCsdAbort {\col{call\_stack\_depth\_abort}} +\def\locAbortingCondition {\col{aborting\_condition}} +\def\locFailureCondition {\col{failure\_condition}} +\def\locZeroValue {\col{value\_is\_zero}} +% CDL, RDC +\def\locOffset {\col{offset}} +\def\locOffsetHi {\locOffset\locHi} +\def\locOffsetLo {\locOffset\locLo} +\def\locSize {\col{size}} +\def\locSizeHi {\locSize\locHi} +\def\locSizeLo {\locSize\locLo} +\def\locCdlTouchesRam {\col{touches\_ram}} +\def\locCdlOutOfBounds {\col{cdl\_out\_of\_bounds}} +\def\locCds {\col{cds}} +\def\locCallDataSize {\col{call\_data\_size}} +\def\locRds {\col{rds}} +\def\locRdcx {\col{rdcx}} +\def\locReturnDataSize {\col{return\_data\_size}} +\def\locCsd {\col{csd}} +\def\locCallStackDepth {\col{call\_stack\_depth}} +\def\locBalance {\col{balance}} +\def\locBal {\col{bal}} +\def\locValue {\col{value}} +\def\locValueHi {\locValue\locHi} +\def\locValueLo {\locValue\locLo} +\def\locRdcRoob {\col{rdc\_roob}} +\def\locRdcSoob {\col{rdc\_soob}} +% +\def\locCompToFiveTwelve {\col{comp\_to\_512}} +\def\locBase {\ell_\text{B}} +\def\locExponent {\ell_\text{E}} +\def\locModulus {\ell_\text{M}} +\def\locExponentLogEYP {\ell_\text{E}'} +% MODEXP: call data size +\def\locCdsGtZero {\col{cds\_GT\_0}} +\def\locCdsGtTt {\col{cds\_GT\_32}} +\def\locCdsGtSf {\col{cds\_GT\_64}} +\def\locCdsLtTt {\col{cds\_LT\_32}} +\def\locCdsLtSf {\col{cds\_LT\_64}} +\def\locCdsLtNs {\col{cds\_LT\_96}} +\def\locCdsLttt {\col{cds\_LT\_32}} % Lttt = less than thirty two +\def\locCdsLtsf {\col{cds\_LT\_64}} % Ltsf = less than sixty four +\def\locCdsLtns {\col{cds\_LT\_96}} % Ltns = less than ninety six +% MODEXP: extract byte size ? trim it ? +\def\locExtractBbs {\col{extract\_bbs}} +\def\locExtractEbs {\col{extract\_ebs}} +\def\locExtractMbs {\col{extract\_mbs}} +\def\locTrimBbs {\col{trim\_bbs}} +\def\locTrimEbs {\col{trim\_ebs}} +\def\locTrimMbs {\col{trim\_mbs}} +\def\locExtractExponentLead {\col{extract\_exponent\_lead}} +% MODEXP: base +\def\locBbs {\col {bbs}} +\def\locBbsHi {\locBbs\locHi} +\def\locBbsLo {\locBbs\locLo} +\def\locBbsIsZero {\locBbs\col{\_is\_zero}} +\def\locNDataBytesX {\colm{[\locCds - (96 + \locBbs) < 32]}} + +% MODEXP: generic byte size +\def\locXbs {\col {xbs}} +% MODEXP: exponent +\def\locEbs {\col {ebs}} +\def\locEbsHi {\locEbs\locHi} +\def\locEbsLo {\locEbs\locLo} +\def\locEbsIsZero {\locEbs\col{\_is\_zero}} +\def\locEbsLtThirtyTwo {\locEbs\col{\_less\_than\_32}} +\def\locEbsMinThirtyTwo {\col{min\_}\locEbs\col{\_32}} +\def\locEbsSubThirtyTwo {\col{sub\_}\locEbs\col{\_32}} +% MODEXP: modulus +\def\locMbs {\col {mbs}} +\def\locMbsHi {\locMbs\locHi} +\def\locMbsLo {\locMbs\locLo} +\def\locMbsIsZero {\locMbs\col{\_is\_zero}} +\def\locMaxMbsBbs {\col{max\_}\locMbs\col{\_}\locBbs} +\def\locMbsLtBbs {\locMbs\col{\_LT\_}\locBbs} +% MODEXP: leading word +\def\locCdsCutoff {\col{cds\_cutoff}} +\def\locEbsCutoff {\col{ebs\_cutoff}} +\def\locExtractableCdsBytes {\col{cds\_bytes}} +\def\locBeyondBase {\col{call\_data\_extends\_beyond\_base}} +\def\locBeyondBaseByLessThanAnEvmWord {\col{by\_less\_than\_an\_EVM\_word}} +\def\locNDataBytes {\col{up\_to\_32\_call\_data\_bytes}} +\def\locLoadLeadingWord {\col{load\_lead}} +\def\locCallDataContainsExponentBytes {\col{call\_data\_contains\_exponent\_bytes}} +\def\locCallDataExtendsBeyondExponent {\col{call\_data\_extends\_beyond\_exponent}} +% MODEXP: pricing +\def\locExponentLog {\col{exponent\_log}} +\def\locExponentLogIsZero {\col{exponent\_log\_is\_zero}} +\def\locFOfMax {\col{f\_of\_max}} +\def\locBigQuotient {\col{big\_quotient}} +\def\locBigQuotientLtTwoHundred {\col{big\_quotient\_LT\_200}} +\def\locProduct {\col{big\_numerator}} +% MODEXP: predicting RAM instruction for extraction of base, exponent, modulus +\def\locUsedBytes {\col{used}} +\def\locByteSize {\col{size}} +\def\locTransfer {\col{trsf}} +\def\locTransferAllZeros {\locTransfer\col{\_zeros}} +\def\locTransferUntrimmed {\locTransfer\col{\_full}} +\def\locTransferTrimmed {\locTransfer\col{\_trim}} +\def\locZeroByteSize {\col{zero\_size}} +\def\locNonZeroByteSize {\col{nonzero\_size}} +\def\locCallDataWillRunOut {\col{call\_data\_will\_run\_out}} +\def\locCallDataWontRunOut {\col{call\_data\_wont\_run\_out}} +\def\locSomeCallDataRemains {\col{some\_call\_data\_remains}} +\def\locNoCallDataRemains {\col{no\_call\_data\_remains}} +% BLAKE2f +\def\locFNotABit {\col{f\_is\_not\_a\_bit}} +\def\locFisABit {\col{f\_is\_a\_bit}} +\def\locBlakeR {\col{blake\_r}} +\def\locBlakeF {\col{blake\_f}} +% CREATE +\def\locNonce {\col{nonce}} +\def\locHasNonce {\col{has\_nonce}} +\def\locHasCode {\col{has\_code}} +\def\locNonzeroNonce {\col{nonzero\_nonce}} +% SSTORE +\def\locSstoreGas {\col{gas}} +\def\locSstoreSufficientGas {\col{sufficient\_gas}} +\def\locSstoreException {\col{sstorex}} +% RETURN deployment +\def\locExceedsMaxCodeSize {\col{exceeds\_max\_code\_size}} +\def\locCodeSizeHi {\col{code\_size\_hi}} +\def\locCodeSizeLo {\col{code\_size\_lo}} +\def\locMaxCodeSizeException {\col{max\_code\_size\_exception}} +% lookup shorthands +\def\locLookupSum {\col{lookup\_sum}} +\def\locWeightedLookupSum {\col{wght\_lookup\_sum}} +\def\locInstFlagSum {\col{flag\_sum\_inst}} +\def\locPrcFlagSum {\col{flag\_sum\_prc}} +\def\locPrcFlagSumCommon {\locPrcFlagSum\col{\_common}} +\def\locPrcFlagSumBlake {\locPrcFlagSum\col{\_blake}} +\def\locPrcFlagSumModexp {\locPrcFlagSum\col{\_modexp}} + +% common precompile shorthands +% \def\locCallGas {\col{call\_gas}} +% \def\locCds {\col{cds}} +% \def\locRac {\col{r@c}} +\def\locCommonPrecompile {\col{common\_precompile}} + +\def\locHubSuccess {\col{hub\_success}} +\def\locRamSuccess {\col{ram\_success}} +\def\locReturnGas {\col{return\_gas}} +\def\locExtractCallData {\col{extract\_call\_data}} +\def\locEmptyCallData {\col{empty\_call\_data}} +\def\locRacIsNonzero {\col{r@c\_nonzero}} + +\def\locXbsHi {\col{xbs\_hi}} +\def\locXbsLo {\col{xbs\_lo}} +\def\locYbsLo {\col{ybs\_lo}} +\def\locMax {\col{max\_xbs\_ybs}} +\def\locXbsNonzero {\col{xbs\_nonzero}} +\def\locComputeMax {\col{compute\_max}} +\def\locCmp {\col{comp}} + +\def\locExtractBase {\col{extract\_base}} +\def\locExtractExponent {\col{extract\_exponent}} +\def\locExtractModulus {\col{extract\_modulus}} +\def\locExtractXxx {\col{extract\_xxx}} + +% BLAKE2f +\def\locValidCdsBlake {\col{valid\_cds}} diff --git a/oob/binary.tex b/oob/binary.tex new file mode 100644 index 0000000..77070aa --- /dev/null +++ b/oob/binary.tex @@ -0,0 +1,39 @@ +We require that the following columns be \textbf{binary}: +\begin{multicols}{3} + \begin{enumerate} + \item \addFlag{} + \item \modFlag{} + \item \wcpFlag{} + \item \oobInstIsJump{} + \item \oobInstIsJumpI{} + \item \oobInstIsRdc{} + \item \oobInstIsCdl{} + \item \oobInstIsXcall{} + \item \oobInstIsCall{} + \item \oobInstIsCreate{} + \item \oobInstIsSstore{} + \item \oobInstIsDeployment{} + \item \oobInstIsEcrecover{} + \item \oobInstIsShaTwo{} + \item \oobInstIsRipemd{} + \item \oobInstIsIdentity{} + \item \oobInstIsEcadd{} + \item \oobInstIsEcmul{} + \item \oobInstIsEcpairing{} + \item \oobInstIsBlakeCds{} + \item \oobInstIsBlakeParams{} + \item \oobInstIsModexpCds{} + \item \oobInstIsModexpXbs{} + \item \oobInstIsModexpLead{} + \item \oobInstIsModexpPricing{} + \item \oobInstIsModexpExtract{} + \item[\vspace{\fill}] + % \item $\outgoingResLo$ + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\noindent +We further ask that \addFlag{}, \modFlag{} and \wcpFlag{} be \textbf{exclusive} i.e. that +\[ + \locLookupSum_{i} \equiv \text{binary} +\] diff --git a/oob/columns.tex b/oob/columns.tex new file mode 100644 index 0000000..a7e5304 --- /dev/null +++ b/oob/columns.tex @@ -0,0 +1,50 @@ +\begin{enumerate} + \item \oobStamp{}: + stamp colum; + \item \ct{}: + counter column; + \item \maxCt{}: + \ccc{} containing the maximum value of the counter column; + \item \oobDataCol{k}, for $k = 1, 2, \dots, 8$: \godGiven{} + \ccc{}'s containing incoming data from the \hubMod{} module; + \item \oobInstruction{}: \godGiven{} + \ccc{} containing an \emph{\oobMod{} instruction}; + \item + \oobInstIsJump{}, + \oobInstIsJumpI{}, + \oobInstIsRdc{}, + \oobInstIsCdl{}, + \oobInstIsXcall{}, + \oobInstIsCall{}, + \oobInstIsCreate{}, + \oobInstIsSstore{} and + \oobInstIsDeployment{}: + (\emph{de facto}) \ccbc{}; explicitly decoded from \oobInst{}; + \item + \oobInstIsEcrecover{}, + \oobInstIsShaTwo{}, + \oobInstIsRipemd{}, + \oobInstIsIdentity{}, + \oobInstIsEcadd{}, + \oobInstIsEcmul{}, + \oobInstIsEcpairing{}, + \oobInstIsBlakeCds{}, + \oobInstIsBlakeParams{}, + \oobInstIsModexpCds{}, + \oobInstIsModexpXbs{}, + \oobInstIsModexpLead{}, + \oobInstIsModexpPricing{}, + \oobInstIsModexpExtract{}: + (\emph{de facto}) \ccbc{}; explicitly decoded from \oobInstruction{}; +\end{enumerate} +The following columns pertain to lookups into the \wcpMod{} and \addMod{}: +\begin{enumerate}[resume] + \item \wcpFlag{}, \addFlag{} and \modFlag{}: + binary columns which light up depending on which modules are targeted by the lookup; + \item \outgoingInst{}: + outgoing instruction colum; + \item \outgoingDataCol{k}, for $k = 1, 2, 3, 4$: + outgoing data columns; + \item \outgoingResLo{}: + outgoing (low part of the) result column; +\end{enumerate} diff --git a/oob/constancies.tex b/oob/constancies.tex new file mode 100644 index 0000000..cb0fde8 --- /dev/null +++ b/oob/constancies.tex @@ -0,0 +1,21 @@ +As per usual we declare a colum \col{X} to be \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We impose that the following columns be counter-constant: +\begin{multicols}{3} + \begin{enumerate} + \item \oobStamp{} (\trash) + \item \maxCt{} (\trash) + \item \oobDataCol{k} + \item \oobInstruction{} + \end{enumerate} +\end{multicols} +Where in the above $k=1, \dots, 8$. +\saNote{} There is no requirement to impose counter-constancy onto \maxCt{}: it follows from counter-constancy of \oobInstruction{}, which imposes counter constancy on all of +\oobInstIsJump, +\oobInstIsJumpI, +\dots{}, +\oobInstBlakeParams. +This in turn imposes counter-constancy on \maxCt{}. + diff --git a/oob/decoding.tex b/oob/decoding.tex new file mode 100644 index 0000000..496b5bf --- /dev/null +++ b/oob/decoding.tex @@ -0,0 +1,9 @@ +This section describes the simple decoding procedure of the \emph{compressed instruction} contained in \oobInstruction{}. The procedure is simple. +\begin{enumerate} + \item \If $\oobStamp_{i} = 0$ \Then $\flagSum_{i} = 0$ + \item \If $\oobStamp_{i} \neq 0$ \Then $\flagSum_{i} = 1$ + \item We impose the following unique decoding constraint: + \[ + \oobInstruction_{i} = \weightedFlagSum_{i} + \] +\end{enumerate} diff --git a/oob/heartbeat.tex b/oob/heartbeat.tex new file mode 100644 index 0000000..dbc7e34 --- /dev/null +++ b/oob/heartbeat.tex @@ -0,0 +1,20 @@ +The \oobMod{} module has a simple heartbeat: +\begin{enumerate} + \item $\oobStamp_{0} = 0$ + \item \If $\oobStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \ct_{i} & = & 0 \\ + \locLookupSum_{i} + \flagSum_{i} & = & 0 \\ + \end{array} \right. + \] + \item $\oobStamp_{i} \in \{ \oobStamp_{i - 1}, 1 + \oobStamp_{i - 1} \}$ + \item \If $\oobStamp_{i} \neq \oobStamp_{i - 1}$ \Then $\ct_{i} = 0$ + \item $\maxCt_{i} = \maxCtFlagSum_{i}$ + \item \If $\oobStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then $\oobStamp_{i + 1} = 1 + \oobStamp_{i}$ + \end{enumerate} + \item \If $\oobStamp_{N} \neq 0$ \Then $\ct_{N} = \maxCt_{N}$. +\end{enumerate} diff --git a/oob/intro.tex b/oob/intro.tex new file mode 100644 index 0000000..9f6eaa9 --- /dev/null +++ b/oob/intro.tex @@ -0,0 +1,76 @@ +The purpose of the \textbf{out of bounds module} \oobMod{} is to perform certain comparisons and ``out of bounds'' detection for the \hubMod{} module. +It only serves as a stepping stone and data formatting step --- all the \emph{actual} work is done by other modules: \addMod{}, \modMod{} and \wcpMod{} more specifically. + +What follows is the list of tasks in which the present module helps the \hubMod{}\footnote{These are deliberately vague, full details are in section~\ref{oob: populating lookups}}: +\begin{description} + \item[\underline{Jump-destination pre-vetting:}] + (for \inst{JUMP} and \inst{JUMPI} instructions) compare the proposed (program counter) jump destination with the codesize; + and determine if a jump is to take place at all for \inst{JUMPI} instructions; + see section~(\ref{oob: populating: jump}) and section~(\ref{oob: populating: jumpi}); + \item[\underline{\rdcxSH{} detection:}] + (for \inst{RETURNDATACOPY} instructions) perform the following addition and comparison: + \[ + \begin{cases} + \text{is either \col{offset} or \col{size} grossly out of bounds ?} \\ + \col{offset} + \col{size} \\ + \col{offset} + \col{size} > \RDS \\ + \end{cases} + \] + or not; + see section section~(\ref{oob: populating: rdc}); + \item[\underline{Trivial \inst{CALLDATALOAD} detection:}] + (for \inst{CALLDATACOPY} instructions) perform the comparison + \[ + \col{offset} \geq \CDS + \] + (in which case \inst{CALLDATALOAD} must put $0$ on the stack); + see section section~(\ref{oob: populating: cdl}); + \item[\underline{Exceptional \inst{CALL}'s:}] + detect whether $\col{value} \neq 0$; + \item[\underline{\inst{CALL}-type and \inst{CREATE}-type abort detection:}] + detect $\col{value} > \col{balance}$, $\col{callstackdepth} = 1024$ and $\col{value} \neq 0$; + see section~(\ref{oob: populating: call}) and section~(\ref{oob: populating: create}); + \item[\underline{\sstorexSH{} detection:}] + determine if $\col{gas} \leq G_\text{callstipend} = 2300$; + see section section~(\ref{oob: populating: sstore}); + \item[\underline{\maxcsxSH{} detection:}] + determine if a \inst{RETURN} in a deployment context returns code that is too big (i.e. $(\col{codesize} > 24576$); + see section section~(\ref{oob: populating: return}); +\end{description} +We furthermore use the \oobMod{} for the pricing of certain precompiles and the testing of certain conditions pertaining to some of the underlying \inst{CALL}'s parameters +\CDS{} (recall its abbreviation \cds{}) and +\RAC{} (recall its abbreviation \rac{}.) +\saNote{} Below we use the \cite{EYP}'s notation $I_\textbf{d}$ for call data. +\begin{description} + \item[\underline{\inst{ECRECOVER}, \inst{SHA2-256}, \inst{RIPEMD-160}, \inst{IDENTITY}, \inst{ECADD}, \inst{ECMUL}, \inst{ECPAIRING} parameters:}] + detect both $\cds \equiv 0$ and $\rac \equiv 0$; + \item[\underline{\inst{ECRECOVER}, \inst{ECADD} and \inst{ECMUL} pricing:}] + performs the comparison + \[ + \left\{ \begin{array}{llcrcl} + \text{for }\inst{ECRECOVER} : & \locCallGas \leq g_\text{r} & := & 3000 \\ + \text{for }\inst{ECADD} : & \locCallGas \leq g_\text{r} & := & 150 \\ + \text{for }\inst{ECMUL} : & \locCallGas \leq g_\text{r} & := & 6000 \\ + \end{array} \right. + \] + \item[\underline{\inst{SHA2-256}, \inst{RIPEMD-160} and \inst{IDENTITY} pricing:}] + compute the ceiling + \[ \col{ceil} := \left \lceil \frac{\| I_\textbf{d} \|}{32} \right \rceil \] + and respectively perform the comparisons + \[ + \left\{ \begin{array}{llcrcr} + \text{for }\inst{SHA2-256} : & \locCallGas \leq g_\text{r} & := & 60 & + & 12 \cdot \locCeil \\ + \text{for }\inst{RIPEMD-160} : & \locCallGas \leq g_\text{r} & := & 600 & + & 120 \cdot \locCeil \\ + \text{for }\inst{IDENTITY} : & \locCallGas \leq g_\text{r} & := & 15 & + & 3 \cdot \locCeil \\ + \end{array} \right. + \] + \item[\underline{\inst{ECPAIRING} pricing:}] + verifies that $\| I_\textbf{d} \| \equiv 0 \mod 192$ and performs the comparison + \[ \locCallGas \leq g_\text{r} := 34000 \cdot \frac{\| I_\textbf{d} \|}{192} + 45000 \] +\end{description} + +\saNote{} +\inst{ECRECOVER}, \inst{ECADD}, \inst{ECMUL} and \inst{ECPAIRING} can throw other exceptions besides ``insufficient gas''. +The present module is only a preliminary step toward detecting exceptions related to those precompiles. + +\saNote{} The pricing of \inst{MODEXP} and \inst{BLAKE2f} requires excavating values stored in \texttt{ram}. Their pricing is \emph{not} dealt with in the present module. diff --git a/oob/lookups/_inputs.tex b/oob/lookups/_inputs.tex new file mode 100644 index 0000000..2cc5ed7 --- /dev/null +++ b/oob/lookups/_inputs.tex @@ -0,0 +1,3 @@ +\subsection{Into the \addMod{} module} \input{lookups/into_add} \label{oob: lookups: add} +\subsection{Into the \modMod{} module} \input{lookups/into_mod} \label{oob: lookups: mod} +\subsection{Into the \wcpMod{} module} \input{lookups/into_wcp} \label{oob: lookups: wcp} diff --git a/oob/lookups/into_add.tex b/oob/lookups/into_add.tex new file mode 100644 index 0000000..abd7cba --- /dev/null +++ b/oob/lookups/into_add.tex @@ -0,0 +1,32 @@ +The present subsection describes the lookup into the \addMod{}. This lookup is required by the \inst{RETURNDATACOPY} opcode. +\begin{description} + \item[Selector:] we use this module's $\addFlag{}_{i}$; + \item[Source columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item $\outgoingDataCol{1}_{i}$ + \item $\outgoingDataCol{2}_{i}$ + \item $\outgoingDataCol{3}_{i}$ + \item $\outgoingDataCol{4}_{i}$ + \item $\outgoingDataCol{1}_{i + 1}$ + \item $\outgoingDataCol{2}_{i + 1}$ + \item $\outgoingInst_{i}$ + \item[\vspace{\fill}] + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item $\argOneHi_{j}$ + \item $\argOneLo_{j}$ + \item $\argTwoHi_{j}$ + \item $\argTwoLo_{j}$ + \item $\resHi_{j}$ + \item $\resLo_{j}$ + \item $\INST_{j}$ + \item[\vspace{\fill}] + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/oob/lookups/into_mod.tex b/oob/lookups/into_mod.tex new file mode 100644 index 0000000..5eb31a1 --- /dev/null +++ b/oob/lookups/into_mod.tex @@ -0,0 +1,35 @@ +The present subsection describes the lookup into the \modMod{}. +\begin{description} + \item[Selector:] we use this module's $\modFlag{}_{i}$; + \item[Source columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item $\outgoingDataCol{1}_{i}$ + \item $\outgoingDataCol{2}_{i}$ + \item $\outgoingDataCol{3}_{i}$ + \item $\outgoingDataCol{4}_{i}$ + % \item $\outgoingDataCol{5}_{i}$ + \item $0$ + \item $\outgoingResLo_{i}$ + \item $\outgoingInst_{i}$ + \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item $\argOneHi_{j}$ + \item $\argOneLo_{j}$ + \item $\argTwoHi_{j}$ + \item $\argTwoLo_{j}$ + % \item $\resHi_{j}$ + \item $\resHi_{j}$ + \item $\resLo_{j}$ + \item $\INST$ + \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/oob/lookups/into_wcp.tex b/oob/lookups/into_wcp.tex new file mode 100644 index 0000000..2c5d5a5 --- /dev/null +++ b/oob/lookups/into_wcp.tex @@ -0,0 +1,33 @@ +The present subsection describes the lookup into the \wcpMod{}. +\begin{description} + \item[Selector:] we use this module's $\wcpFlag{}_{i}$; + \item[Source columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item $\outgoingDataCol{1}_{i}$ + \item $\outgoingDataCol{2}_{i}$ + \item $\outgoingDataCol{3}_{i}$ + \item $\outgoingDataCol{4}_{i}$ + % \item $\outgoingDataCol{5}_{i}$ + \item $\outgoingResLo_{i}$ + \item $\outgoingInst_{i}$ + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] we use the following: + \begin{multicols}{2} + \begin{enumerate} + \item $\argOneHi_{j}$ + \item $\argOneLo_{j}$ + \item $\argTwoHi_{j}$ + \item $\argTwoLo_{j}$ + % \item $\resHi_{j}$ + \item $\resLo_{j}$ + \item $\INST$ + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/oob/opcodes/_inputs.tex b/oob/opcodes/_inputs.tex new file mode 100644 index 0000000..834100d --- /dev/null +++ b/oob/opcodes/_inputs.tex @@ -0,0 +1,12 @@ +\section{Populating opcodes} \label{oob: populating: opcodes} +\subsection{Graphical representation} \includepdf[fitpaper=true, pages={1}]{opcodes/lua/layout.pdf} \label{oob: populating: opcodes: layout} +\subsection{Disclaimer} \input{opcodes/disclaimer} \label{oob: populating: opcodes: disclaimer} +\subsection{For $\oobInstJump$} \input{opcodes/jump} \label{oob: populating: opcodes: jump} % \newpage +\subsection{For $\oobInstJumpI$} \input{opcodes/jumpi} \label{oob: populating: opcodes: jumpi} % \newpage +\subsection{For $\oobInstRdc$} \input{opcodes/rdc} \label{oob: populating: opcodes: rdc} % \newpage +\subsection{For $\oobInstCdl$} \input{opcodes/cdl} \label{oob: populating: opcodes: cdl} % \newpage +\subsection{For $\oobInstSstore$} \input{opcodes/sstore} \label{oob: populating: opcodes: sstore} % \newpage +\subsection{For $\oobInstDeployment$} \input{opcodes/deployment} \label{oob: populating: opcodes: deployment} % \newpage +\subsection{For $\oobInstXcall$} \input{opcodes/xcall} \label{oob: populating: opcodes: exceptional calls} % \newpage +\subsection{For $\oobInstCall$} \input{opcodes/call} \label{oob: populating: opcodes: call} % \newpage +\subsection{For $\oobInstCreate$} \input{opcodes/create} \label{oob: populating: opcodes: create} % \newpage diff --git a/oob/opcodes/call.tex b/oob/opcodes/call.tex new file mode 100644 index 0000000..b496d0e --- /dev/null +++ b/oob/opcodes/call.tex @@ -0,0 +1,76 @@ +The present section describes the data layout for the \inst{CALL} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsCall_{i} = 1} +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the following tasks +\green{(\emph{a})} compare \col{value} and \col{balance}, where \col{value} represents the transfer value (if any) of the instruction +\green{(\emph{b})} compare \col{callstackdepth} and $1024$ +\green{(\emph{c})} verify the \hubMod{} module prediction as to the vanishing of the \locValue{}. + +We use the following shorthands for the values in the \oobDataCol{k} columns: +\[ + \left\{ \begin{array}{lclr} + \locValueHi & \define & \oobDataCol {1} _{i} \\ + \locValueLo & \define & \oobDataCol {2} _{i} \\ + \locBalance & \define & \oobDataCol {3} _{i} \\ + % \loc & \define & \oobDataCol {4} _{i} \\ + % \loc & \define & \oobDataCol {5} _{i} \\ + \locCallStackDepth & \define & \oobDataCol {6} _{i} \\ + \locNonzeroValue & \define & \oobDataCol {7} _{i} & \prediction \\ + \locAbortingCondition & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Rows n°$(i)$, n°$(i + 1)$ and n°$(i + 2)$:}] + we impose the following: + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{0} + {0}{\locBalance} + {\locValueHi}{\locValueLo} + \vspace{2mm} \\ + \oobCallToLt + {i}{1} + {0}{\locCallStackDepth} + {0}{1024} + \vspace{2mm} \\ + \oobCallToIszero + {i}{2} + {\locValueHi}{\locValueLo} + \\ + \end{array} \right. + \] + we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locBalanceAbort & \define & \outgoingResLo _{i } \\ + \locCsdAbort & \define & 1 - \outgoingResLo _{i + 1} \\ + \locZeroValue & \define & \outgoingResLo _{i + 2} \\ + \end{array} \right. + \] + Thus by construction + $\locBalance < \locValue \iff \locBalanceAbort = 1$, + $\locCallStackDepth \geq \col{1024} \iff \locCsdAbort = 1$ and + $\locValue = 0 \iff \locZeroValue = 1$. + \item[\underline{Justifying \hubMod{} predictions:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locNonzeroValue & = & 1 - \locZeroValue \\ + \locAbortingCondition & = & + \left[ \begin{array}{cl} + + & \locBalanceAbort \\ + + & (1 - \locBalanceAbort) \cdot \locCsdAbort \\ + \end{array} \right] \\ + \end{array} \right. + \] +\end{description} +\saNote{} Thus +\[ + \locAbortingCondition \equiv 1 \iff + \big[ \locValue > \locBalance \big] + \vee + \big[\locCallStackDepth \geq 1024\big] +\] diff --git a/oob/opcodes/cdl.tex b/oob/opcodes/cdl.tex new file mode 100644 index 0000000..b13f039 --- /dev/null +++ b/oob/opcodes/cdl.tex @@ -0,0 +1,41 @@ +The present section describes the data layout for the \inst{CALLDATALOAD} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsCdl_{i} = 1.} +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the comparison +\green{(\emph{a})} justify the result of the comparison $\locOffset < \locCallDataSize$. +\saNote{} The purpose of this comparison isn't to detect an exception; rather it allows the \hubMod{} to bypass a call to the \mmuMod{} as the output of the \inst{CALLDATALOAD} opcode will be to put a $0$ on the stack. + +\noindent We use the following shorthands for the values in the \oobDataCol{k} columns: +\[ + \left\{ \begin{array}{lclr} + \locOffsetHi & \define & \oobDataCol{1} _{i} \\ + \locOffsetLo & \define & \oobDataCol{2} _{i} \\ + % \loc & \define & \oobDataCol{3} _{i} \\ + % \loc & \define & \oobDataCol{4} _{i} \\ + \locCds & \define & \oobDataCol{5} _{i} \\ + % \loc & \define & \oobDataCol{6} _{i} \\ + \locCdlOutOfBounds & \define & \oobDataCol{7} _{i} & \prediction \\ + % \loc & \define & \oobDataCol{8} _{i} \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToLt + {i}{0} + {\locOffsetHi}{\locOffsetLo} + {0}{\locCds} + \] + and we define the following shorthand + \[ + \locCdlTouchesRam \define \outgoingResLo _{i} + \] + It follows that $\locOffset < \locCds \iff \locCdlTouchesRam = 1$ + \item[\underline{Justifying \hubMod{} predictions:}] + we impose + \[ + \locCdlOutOfBounds = 1 - \locCdlTouchesRam + \] +\end{description} diff --git a/oob/opcodes/create.tex b/oob/opcodes/create.tex new file mode 100644 index 0000000..d49440b --- /dev/null +++ b/oob/opcodes/create.tex @@ -0,0 +1,83 @@ +The present section describes the data layout for the \inst{CREATE} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsCreate_{i} = 1} +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the following tasks. +First it detects aborting conditions for \inst{CREATE}-type instructions: +\green{(\emph{a})} compare \col{value} and \col{balance}, where \col{value} represents the transfer value (if any) of the instruction +\green{(\emph{b})} compare \col{callstackdepth} and $1024$. +Next it detects failure conditions for \inst{CREATE}-type instructions: +\green{(\emph{c})} the createe already has nonzero nonce +\green{(\emph{d})} the createe has nonempty byte code. + +\noindent The interpretation of the \oobDataCol{k}'s is the following: +\[ + \left\{ \begin{array}{lclr} + \locValueHi & \define & \oobDataCol {1} _{i} \\ + \locValueLo & \define & \oobDataCol {2} _{i} \\ + \locBalance & \define & \oobDataCol {3} _{i} \\ + \locNonce & \define & \oobDataCol {4} _{i} \\ + \locHasCode & \define & \oobDataCol {5} _{i} \\ + \locCallStackDepth & \define & \oobDataCol {6} _{i} \\ + \locAbortingCondition & \define & \oobDataCol {7} _{i} & \prediction \\ + \locFailureCondition & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Rows n°$(i)$, n°$(i + 1)$ and n°$(i + 2)$:}] + this row compares the balance to the value to transfer: + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{0} + {0}{\locBalance} + {\locValueHi}{\locValueLo} + \vspace{2mm} \\ + \oobCallToLt + {i}{1} + {0}{\locCallStackDepth} + {0}{1024} + \vspace{2mm} \\ + \oobCallToIszero + {i}{2} + {0}{\locNonce} + \\ + \end{array} \right. + \] + and we introduce the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locBalanceAbort & \define & \outgoingResLo _{i } \\ + \locCsdAbort & \define & 1 - \outgoingResLo _{i + 1} \\ + \locNonzeroNonce & \define & 1 - \outgoingResLo _{i + 2} \\ + \end{array} \right. + \] + Thus by construction + $\locBalanceAbort = 1 \iff \locBalance < \locValue $, + $\locCsdAbort = 1 \iff \locCallStackDepth \geq \col{1024}$ and + $\locNonzeroNonce = 1 \iff \locNonce \neq 0$. + \item[\underline{Justifying \hubMod{} predictions:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locAbortingCondition & = & + \left[ \begin{array}{crcl} + + & \locBalanceAbort \\ + + & (1 - \locBalanceAbort) & \cdot & \locCsdAbort \\ + \end{array} \right] \vspace{2mm} \\ + \locFailureCondition & = & + (1 - \locAbortingCondition) \cdot + \left[ \begin{array}{crcl} + + & \locHasCode \\ + + & (1 - \locHasCode) & \cdot & \locNonzeroNonce \\ + \end{array} \right] \\ + \end{array} \right. + \] + \saNote{} In other words + $\locAbortingCondition$ tracks the \textbf{aborting conditions} for \inst{CREATE}'s instructions (which are the same as for \inst{CALL}-type instructions) while + $\locFailureCondition$ tracks the \textbf{failure conditions} for \inst{CREATE}'s. + + \saNote{} By construction $\locAbortingCondition$ and $\locFailureCondition$ are \textbf{mutually exclusive binary flags}. +\end{description} + diff --git a/oob/opcodes/deployment.tex b/oob/opcodes/deployment.tex new file mode 100644 index 0000000..0acfae0 --- /dev/null +++ b/oob/opcodes/deployment.tex @@ -0,0 +1,41 @@ +The present section describes the data layout for the \inst{RETURN} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsDeployment_{i} = 1 } +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is: +\green{(\emph{a})} to perform the comparison \( \col{size} \leq 24576 \). + + +\noindent We use the following shorthands for the values in the \oobDataCol{k} columns: +\[ + \left\{ \begin{array}{lclr} + \locCodeSizeHi & \define & \oobDataCol {1} _{i} \\ + \locCodeSizeLo & \define & \oobDataCol {2} _{i} \\ + % & \define & \oobDataCol {3} _{i} \\ + % & \define & \oobDataCol {4} _{i} \\ + % & \define & \oobDataCol {5} _{i} \\ + % & \define & \oobDataCol {6} _{i} \\ + \locMaxCodeSizeException & \define & \oobDataCol {7} _{i} & \prediction \\ + % & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] + +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToLt + {i}{0} + {0}{24576} + {\locCodeSizeHi}{\locCodeSizeLo} + \] + and we define the following associated shorthand + \[ + \locExceedsMaxCodeSize \define \outgoingResLo _{i} + \] + It follows that $\locExceedsMaxCodeSize = 1 \iff 24576 < \locCodeSize$. + \item[\underline{Justifying \hubMod{} predictions:}] we impose + \[ + \locMaxCodeSizeException = \locExceedsMaxCodeSize + \] +\end{description} diff --git a/oob/opcodes/disclaimer.tex b/oob/opcodes/disclaimer.tex new file mode 100644 index 0000000..84afec4 --- /dev/null +++ b/oob/opcodes/disclaimer.tex @@ -0,0 +1,5 @@ +All constraints written below take as starting point the processing of a new instruction, which coincides with an increment in the \oobStamp{}. As such: +\[ + \boxed{\boxed{\text{All constraints in this section are written under the assumption that } \oobStamp_{i} \neq \oobStamp_{i - 1}}} +\] +In other words: we are assuming that row $i$ is the first row dealing with a particular instruction. diff --git a/oob/opcodes/jump.tex b/oob/opcodes/jump.tex new file mode 100644 index 0000000..bed48ea --- /dev/null +++ b/oob/opcodes/jump.tex @@ -0,0 +1,57 @@ +The present section describes the data layout for the \inst{JUMP} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume }\oobInstIsJump_{i} = 1} +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the following \textbf{preliminary check}: +\green{(\emph{a})} compare \locPcNew{} and \locCodeSize{}. + +\noindent We introduce the following shorthands: +\[ + \left\{ \begin{array}{lclr} + \locPcNewHi & \define & \oobDataCol{1} _{i} \\ + \locPcNewLo & \define & \oobDataCol{2} _{i} \\ + % & \define & \oobDataCol{3} _{i} \\ + % & \define & \oobDataCol{4} _{i} \\ + \locCodeSize & \define & \oobDataCol{5} _{i} \\ + % & \define & \oobDataCol{6} _{i} \\ + \locJumpGuaranteedException & \define & \oobDataCol{7}_{i} & \prediction \\ + \locJumpMustBeAttempted & \define & \oobDataCol{8}_{i} & \prediction \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToLt + {i}{0} + {\col{pc\_new\_hi}}{\col{pc\_new\_lo}} + {0}{\col{codesize}} + \] + we also define the shorthand + \[ + \locValidPcNew \define \outgoingResLo _{i} + \] + It follows that $\locValidPcNew = 1 \iff \locPcNew < \locCodeSize$. + \item[\underline{Justifying \hubMod{} predictions:}] we impose + \[ + \left\{ \begin{array}{lcl} + \locJumpGuaranteedException & = & 1 - \locValidPcNew \\ + \locJumpMustBeAttempted & = & \locValidPcNew \\ + \end{array} \right. + \] + \saNote{} In other words $\locInvalidPcNew \equiv 1 \iff$ the \inst{JUMP} instruction leads to an (attempted) jump that takes the program counter out of bounds relative to the byte code under execution and its code size. Since byte code is zero padded beyond its code size this automatically leads to a \jumpxSH{}. Indeed, the zero byte $\utt{00}$ corresponds to the \inst{STOP} opcode which differs from the \inst{JUMPDEST} opcode where any unexceptional \inst{JUMP}-type instruction must land. +\end{description} +\saNote{} The above has implicit consequences which we list below which don't need to be incorporated into the implementation: +\begin{enumerate} + \item $\locJumpGuaranteedException$ is binary \quad (\trash) + \item $\locJumpMustBeAttempted $ is binary \quad (\trash) + \item furthermore + \[ + \left[ \begin{array}{cr} + + & \locJumpGuaranteedException \\ + + & \locJumpMustBeAttempted \\ + \end{array} \right] + \equiv 1 + \quad (\trash) + \] +\end{enumerate} diff --git a/oob/opcodes/jumpi.tex b/oob/opcodes/jumpi.tex new file mode 100644 index 0000000..ae0f3da --- /dev/null +++ b/oob/opcodes/jumpi.tex @@ -0,0 +1,98 @@ +The present section describes the data layout for the \inst{JUMPI} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume }\oobInstIsJumpI_{i} = 1} +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the following tasks +\green{(\emph{a})} compare \locPcNew{} and \locCodeSize{} +\green{(\emph{b})} compare the jump condition \locJumpCondition{}, the second argument to the \inst{JUMPI} instruction, to zero. + +\noindent We thus introduce the following (local) shorthands: +\[ + \left\{ \begin{array}{lclr} + \locPcNewHi & \define & \oobDataCol {1} _{i} \\ + \locPcNewLo & \define & \oobDataCol {2} _{i} \\ + \locJumpConditionHi & \define & \oobDataCol {3} _{i} \\ + \locJumpConditionLo & \define & \oobDataCol {4} _{i} \\ + \locCodeSize & \define & \oobDataCol {5} _{i} \\ + \locJumpNotAttempted & \define & \oobDataCol {6} _{i} & \prediction \\ + \locJumpGuaranteedException & \define & \oobDataCol {7} _{i} & \prediction \\ + \locJumpMustBeAttempted & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$ and n°$(i + 1)$:}] + we impose the following: + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{0} + {\locPcNewHi}{\locPcNewLo} + {0}{\locCodeSize} + \vspace{2mm} \\ + \oobCallToIszero + {i}{1} + {\locJumpConditionHi}{\locJumpConditionLo} + \\ + \end{array} \right. + \] + we define the following associated shorthands + \[ + \left\{ \begin{array}{lcl} + \locValidPcNew & \define & \outgoingResLo _{i} \\ + \locJumpConditionIsZero & \define & \outgoingResLo _{i + 1} \\ + \end{array} \right. + \] + It follows that + $\locValidPcNew = 1 \iff \locPcNew < \locCodeSize$ and + $\locJumpConditionIsZero = 1 \iff \locJumpCondition = 0$. + \item[\underline{Setting \hubMod{} predictions:}] we impose + \[ + \left\{ \begin{array}{lclcl} + \locJumpNotAttempted & = & \locJumpConditionIsZero \\ + \locJumpGuaranteedException & = & (1 - \locJumpConditionIsZero) & \cdot & (1 - \locValidPcNew) \\ + \locJumpMustBeAttempted & = & (1 - \locJumpConditionIsZero) & \cdot & \locValidPcNew \\ + \end{array} \right. + \] +\end{description} +\saNote{} A \inst{JUMPI} instruction can either +(\emph{a}) not be triggered at all (zero jump condition) +(\emph{b}) be triggered but immediately produce an exception due to jumping out of bounds of the code size or +(\emph{c}) be triggered and not immediately fail for the previous reason. +These cases correspond, in order, to the following possibilities +(\emph{a}) $\locJumpNotAttempted \equiv 1$, +(\emph{b}) $\locJumpGuaranteedException \equiv 1$ and +(\emph{c}) $\locJumpMustBeAttempted \equiv 1$ respectively. +In the third case the \zkEvm{} must retrieve the corresponding byte from the bytecode. +The \inst{JUMPI} may still fail yet due either +(\emph{a}) landing either on a byte which ``belongs'' to some \inst{PUSHX} instruction or +(\emph{b}) landing on a byte not contributing to the argument of a \inst{PUSHX} instruction but not coding for the \inst{JUMPDEST} opcode either. + +\saNote{} The above has implicit consequences which we list below which don't need to be incorporated into the implementation: +\begin{enumerate} + \item $\locJumpNotAttempted $ is binary \quad (\trash) + \item $\locJumpGuaranteedException $ is binary \quad (\trash) + \item $\locJumpMustBeAttempted $ is binary \quad (\trash) + \item furthermore + \[ + \left[ \begin{array}{cr} + + & \locJumpNotAttempted \\ + + & \locJumpGuaranteedException \\ + + & \locJumpMustBeAttempted \\ + \end{array} \right] + \equiv 1 + \quad (\trash) + \] +\end{enumerate} +The table below subsumes the intent behind the $\oobDataCol{6}$ / $\oobDataCol{7}$ / $\oobDataCol{8}$ flags for \inst{JUMP} and \inst{JUMPI} instructions. +\begin{figure}[!h] + \renewcommand{\arraystretch}{1.3} + \[ + \begin{array}{|l|c|c|c|} \hline + & \text{interpretation of } ``\oobDataCol{6} = 1" & \text{interpretation of } ``\oobDataCol{7} = 1" & \text{interpretation of } ``\oobDataCol{8} = 1" \\ \hline \hline + \inst{JUMP} & \nothing & \text{the jump is guaranteed to fail} & \text{the jump must be attempted} \\ \hline + \inst{JUMPI} & \text{the jump won't be attempted} & \text{the jump is guaranteed to fail} & \text{the jump must be attempted} \\ \hline + \end{array} + \] + \label{fig: oob: jump case interpretation of oob events} +\end{figure} diff --git a/oob/opcodes/lua/layout.lua.tex b/oob/opcodes/lua/layout.lua.tex new file mode 100644 index 0000000..8e818d3 --- /dev/null +++ b/oob/opcodes/lua/layout.lua.tex @@ -0,0 +1,79 @@ +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + + ██\ ██\ ██\ ██\ ███████\ ██\ ██████\ ██████\ ███████\ ██\ ██\ ██████\ + ██ | ██ |██ | ██ |██ __██\ ██ | ██ __██\ ██ __██\ ██ __██\ \__| ██ | ██ __██\ + ██ | ██ |██ | ██ |██ | ██ | ██ / ██ / ██ |██ / ██ |██ | ██ | ██\ ███████\ ██████\ ██████\ ██████\ ██ / \__|██████\ ███████\ ██████\ + ████████ |██ | ██ |███████\ | ██ / ██ | ██ |██ | ██ |███████\ | ██ |██ __██\\_██ _| ██ __██\ ██ __██\ ████\ \____██\ ██ _____|██ __██\ + ██ __██ |██ | ██ |██ __██\ ██ / ██ | ██ |██ | ██ |██ __██\ ██ |██ | ██ | ██ | ████████ |██ | \__|██ _| ███████ |██ / ████████ | + ██ | ██ |██ | ██ |██ | ██ | ██ / ██ | ██ |██ | ██ |██ | ██ | ██ |██ | ██ | ██ |██\ ██ ____|██ | ██ | ██ __██ |██ | ██ ____| + ██ | ██ |\██████ |███████ | ██ / ██████ | ██████ |███████ | ██ |██ | ██ | \████ |\███████\ ██ | ██ | \███████ |\███████\ \███████\ + \__| \__| \______/ \_______/ \__/ \______/ \______/ \_______/ \__|\__| \__| \____/ \_______|\__| \__| \_______| \_______| \_______| + + + | + _ \ __ \ __| _ \ _` | _ \ __| + ( | | | ( ( | ( | __/ \__ \ + \___/ .__/ \___| \___/ \__,_| \___| ____/ + _| + + + +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| OOB_INST | OOB_DATA_1 | OOB_DATA_2 | OOB_DATA_3 | OOB_DATA_4 | OOB_DATA_5 | OOB_DATA_6 | OOB_DATA_7 | OOB_DATA_8 | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_jump⟧ | pc_new_hi | pc_new_lo | | | code_size | | jump_guaranteed_exception | jump_must_be_attempted | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | | | ✓ trusted | | ⟦ π ⟧ | ⟦ π ⟧ | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_jumpi⟧ | pc_new_hi | pc_new_lo | jump_condition_hi | jump_condition_lo | code_size | jump_not_attempted | jump_guaranteed_exception | jump_must_be_attempted | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_return_data_copy⟧ | offset_hi | offset_lo | size_hi | size_lo | return_data_size | | return_data_copy_exception | | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | | ⟦ π ⟧ | | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_call_data_load⟧ | offset_hi | offset_lo | | | call_data_size | | call_data_load_out_of_bounds | | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | | | ✓ trusted | | ⟦ π ⟧ | | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_sstore⟧ | | | | | gas | | sstore_exception | | +| | | | | | | | | | +| | | | | | ✓ trusted | | ⟦ π ⟧ | | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_deployment⟧ | size_hi | size_lo | | | | | max_code_size_exception | | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | | | | | ⟦ π ⟧ | | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_exceptional_call⟧ | value_hi | value_lo | | | | | value_is_nonzero | value_is_zero | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | | | | | ⟦ π ⟧ | ⟦ π ⟧ | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_call⟧ | value_hi | value_lo | balance | | | call_stack_depth | value_is_nonzero | aborting_condition | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | | | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| +| ⟦OOB_INST_create⟧ | value_hi | value_lo | balance | createe_nonce | createe_has_code | call_stack_depth | aborting_condition | failure_condition | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | +|-----------------------------+------------+------------+-------------------+-------------------+------------------+--------------------+------------------------------+------------------------| + +\end{verbatim} +\end{document} diff --git a/oob/opcodes/rdc.tex b/oob/opcodes/rdc.tex new file mode 100644 index 0000000..b455db5 --- /dev/null +++ b/oob/opcodes/rdc.tex @@ -0,0 +1,83 @@ +The present section describes the data layout for the \inst{RETURNDATACOPY} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsRdc_{i} = 1} +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the following tasks +\green{(\emph{a})} establish that neither the \col{offset} nor \col{size} (as read off the stack) are grossly out of bounds (i.e. $\geq 2^{128}$); +\green{(\emph{b})} compute the sum \( \col{sum} := \locOffset + \locSize \) +\green{(\emph{c})} compare \col{sum} and the return data size \locRds{}. + +\noindent We use the following shorthands for the values in the \oobDataCol{k} columns: +\[ + \left\{ \begin{array}{lclr} + \locOffsetHi & \define & \oobDataCol {1} _{i} \\ + \locOffsetLo & \define & \oobDataCol {2} _{i} \\ + \locSizeHi & \define & \oobDataCol {3} _{i} \\ + \locSizeLo & \define & \oobDataCol {4} _{i} \\ + \locRds & \define & \oobDataCol {5} _{i} \\ + \locRdcx & \define & \oobDataCol {7} _{i} & \prediction \\ + \end{array} \right. +\] +\saNote{} As done elsewhere the acronym ``\col{roob}'' stands for ``\textbf{r}idiculously \textbf{o}ut \textbf{o}f \textbf{b}ounds.'' +The acronym ``\col{soob}'' stands for ``\textbf{s}um is \textbf{o}ut \textbf{o}f \textbf{b}ounds.'' + +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToIszero + {i}{0} + {\locOffsetHi}{\locSizeHi} + \] + and we define the shorthand + \[ + \locRdcRoob \define 1 - \outgoingResLo _{i} + \] + The above tests simultaneously whether + (\emph{a}) the offset (within return data) is ridiculously large (i.e. $\geq 2^{\oneTwoEight}$) + or + (\emph{b}) the size parameter is ridiculously large (i.e. $\geq 2^{\oneTwoEight}$). + The further constraints below are only triggered if the above returns \texttt{true} i.e. if offsets and sizes aren't + \item[\underline{Row n°$(i + 1)$:}] we impose that + \begin{enumerate} + \item \If $\locRdcRoob = 0$ \Then + \[ + \oobCallToAdd + {i}{1} + {0}{\locOffsetLo} + {0}{\locSizeLo} + \] + The above computes, when the preceding check was successful, the sum of the low parts of the offset and size parameters of the \inst{RETURNDATACOPY} instruction; recall from section~(\ref{oob: lookups: add}) that the result of this \inst{ADD} instruction is stored on the following row (whence the ``\gray{\text{implicitly constrained}}'' below); + \item \If $\locRdcRoob = 1$ \Then $\oobNoCall{1}_{i}$. + \end{enumerate} + \item[\underline{Row n°$(i + 2)$:}] + \begin{enumerate} + \item \If $\locRdcRoob = 0$ \Then we impose the following: + \[ + \left\{ \begin{array}{lcl} + \addFlag_{i + 2} & = & 0 \quad (\trash) \\ + \modFlag_{i + 2} & = & 0 \quad (\trash) \\ + \wcpFlag_{i + 2} & = & 1 \\ + \outgoingInst_{i + 2} & = & \inst{GT} \vspace{2mm} \\ + \outgoingData{1}_{i + 2} & = & \gray{\text{implicitly constrained}} \\ + \outgoingData{2}_{i + 2} & = & \gray{\text{implicitly constrained}} \\ + \outgoingData{3}_{i + 2} & = & 0 \\ + \outgoingData{4}_{i + 2} & = & \locRds \\ + \end{array} \right. + \] + and we define the shorthand + \[ + \locRdcSoob \define \outgoingResLo _{i + 2} + \] + The above thus imposes $\col{offset} + \col{size} > \col{rds} \iff \locRdcSoob = 1$. + \item \If $\locRdcRoob = 1$ \Then we impose $\oobNoCall{2}_{i}$. + \end{enumerate} + \item[\underline{Justifying \hubMod{} predictions:}] we impose + \[ + \locRdcx = + \left[ \begin{array}{cl} + + & \locRdcRoob \\ + + & (1 - \locRdcRoob) \cdot \locRdcSoob + \end{array} \right] + \] +\end{description} diff --git a/oob/opcodes/sstore.tex b/oob/opcodes/sstore.tex new file mode 100644 index 0000000..c1b5e01 --- /dev/null +++ b/oob/opcodes/sstore.tex @@ -0,0 +1,39 @@ +The present section describes the data layout for the \inst{SSTORE} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsSstore_{i} = 1 } +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to perform the comparison +\( \col{gas} \leq G_\text{callstipend} \define 2300 \). + +\noindent We use the following shorthands for the values in the \oobDataCol{k} columns: +\[ + \left\{ \begin{array}{lclr} + % & \define & \oobDataCol {1} _{i} \\ + % & \define & \oobDataCol {2} _{i} \\ + % & \define & \oobDataCol {3} _{i} \\ + % & \define & \oobDataCol {4} _{i} \\ + \locSstoreGas & \define & \oobDataCol {5} _{i} \\ + % & \define & \oobDataCol {6} _{i} \\ + \locSstoreException & \define & \oobDataCol {7} _{i} & \prediction \\ + % & \define & \oobDataCol {8} _{i} \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToLt + {i}{0} + {0}{G_\text{callstipend}} + {0}{\locSstoreGas} + \] + we define the following shorthand + \[ + \locSstoreSufficientGas \define \outgoingResLo _{i} + \] + It follows that $\locSstoreSufficientGas = 1 \iff G_\text{callstipend} < \locSstoreGas$. + \item[\underline{Justifying \hubMod{} predictions:}] we impose + \[ + \locSstoreException = 1 - \locSstoreSufficientGas \\ + \] +\end{description} diff --git a/oob/opcodes/xcall.tex b/oob/opcodes/xcall.tex new file mode 100644 index 0000000..3cfda9d --- /dev/null +++ b/oob/opcodes/xcall.tex @@ -0,0 +1,37 @@ +The present section describes the data layout for the \inst{CALL} case. As such: +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsXcall_{i} = 1} +\] +We remind the reader that purpose of the \oobInstXcall{} instruction is to detect nonzero value transfers for \inst{CALL} instructions. +These are liable to trigger a \staticxSH{}. + +We introduce the following shorthands: +\[ + \left\{ \begin{array}{lclr} + \locValueHi & \define & \oobDataCol{1} _{i} \\ + \locValueLo & \define & \oobDataCol{2} _{i} \\ + % & \define & \oobDataCol{3} _{i} \\ + % & \define & \oobDataCol{4} _{i} \\ + % & \define & \oobDataCol{5} _{i} \\ + % & \define & \oobDataCol{6} _{i} \\ + \locNonzeroValue & \define & \oobDataCol{7} _{i} & \prediction \\ + \locZeroValue & \define & \oobDataCol{8} _{i} & \prediction \\ + \end{array} \right. +\] +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToIszero + {i}{0} + {\locValueHi}{\locValueLo} + \] + \item[\underline{Justifying the \hubMod's prediction:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locNonzeroValue & = & 1 - \outgoingResLo _{i} \\ + \locZeroValue & = & \outgoingResLo _{i} \\ + \end{array} \right. + \] +\end{description} diff --git a/oob/precompiles/_inputs.tex b/oob/precompiles/_inputs.tex new file mode 100644 index 0000000..1ed5487 --- /dev/null +++ b/oob/precompiles/_inputs.tex @@ -0,0 +1,6 @@ +\section{Precompile generalities} \label{oob: populating: precompiles} +\subsection{\hubMod{} / \oobMod{} interface for precompile instructions} \label{oob: hub / oob interface for precompiles} \includepdf[fitpaper=true, pages={1}] {precompiles/lua/layout.pdf} +\subsection{Shorthands} \label{oob: populating: shorthands} \input{precompiles/shorthands} +\section{Populating common precompiles} \label{oob: populating: common precompiles} \input{precompiles/common/_inputs} +\section{Populating \inst{MODEXP}-related \oobMod{} instructions} \label{oob: populating: modexp} \input{precompiles/modexp/_inputs} +\section{Populating \inst{BLAKE2f}-related \oobMod{} instructions} \label{oob: populating: blake2f} \input{precompiles/blake2f/_inputs} diff --git a/oob/precompiles/blake2f/_inputs.tex b/oob/precompiles/blake2f/_inputs.tex new file mode 100644 index 0000000..0e44eeb --- /dev/null +++ b/oob/precompiles/blake2f/_inputs.tex @@ -0,0 +1,2 @@ +\subsection{For \oobInstBlakeCds{}} \input{precompiles/blake2f/cds} \label{oob: precompiles: blake2f cds} \newpage +\subsection{For \oobInstBlakeParams{}} \input{precompiles/blake2f/params} \label{oob: precompiles: blake2f params} \newpage diff --git a/oob/precompiles/blake2f/cds.tex b/oob/precompiles/blake2f/cds.tex new file mode 100644 index 0000000..7af2cb5 --- /dev/null +++ b/oob/precompiles/blake2f/cds.tex @@ -0,0 +1,54 @@ +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsBlakeCds_{i} = 1} +\] +We use the shorthands defined below: +\[ + \left\{ \begin{array}{lclr} + % & \define & \oobDataCol {1} _{i} \\ + \locCds & \define & \oobDataCol {2} _{i} \\ + \locRac & \define & \oobDataCol {3} _{i} \\ + \locHubSuccess & \define & \oobDataCol {4} _{i} & \prediction \\ + % & \define & \oobDataCol {5} _{i} \\ + % & \define & \oobDataCol {6} _{i} \\ + % & \define & \oobDataCol {7} _{i} \\ + \locRacIsNonzero & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] +\saNote{} The decorator `` $\prediction{}$ '' stands for ``\hubMod{} prediction.'' + +We impose the following constraints: +\begin{description} + \item[\underline{Rows n°$(i)$ and n°$(i + 1)$:}] + we impose the following: + \[ + \left\{ \begin{array}{l} + \oobCallToEq + {i}{0} + {0}{\locCds} + {0}{213} + \vspace{2mm} \\ + \oobCallToIszero + {i}{1} + {0}{\locRac} + \\ + \end{array} \right. + \] + we then set the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locValidCdsBlake & \define & \outgoingResLo _{i } \\ + \locRacIsZero & \define & \outgoingResLo _{i + 1} \\ + \end{array} \right. + \] + It follows that $\locValidCdsBlake = 1 \iff \locCds = 213$. + \item[\underline{Justifying \hubMod{} predictions:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \locHubSuccess & = & \locValidCdsBlake \\ + \locRacIsNonzero & = & 1 - \locRacIsZero \\ + \end{array} \right. + \] +\end{description} +In other words, when making ``first contact'' with a \inst{CALL} to the \inst{BLAKE2f} precompile the +\locValidCdsBlake{} flag measures failure of the \cds{} being the expected value of $213$. This will trigger a special failure mode in the \hubMod{} module. diff --git a/oob/precompiles/blake2f/params.tex b/oob/precompiles/blake2f/params.tex new file mode 100644 index 0000000..e8a30f3 --- /dev/null +++ b/oob/precompiles/blake2f/params.tex @@ -0,0 +1,64 @@ +The present section describes the data layout for the first way in which the \oobMod{} module may interact with the \inst{BLAKE2f} precompile. +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsBlakeParams_{i} = 1 } +\] +We remind the reader that the objective of the \oobMod{} module in this particular case is to +\green{(\emph{a})} compare the \locCallGas{} to the number of rounds \locBlakeR{} +\green{(\emph{b})} verify that $\locBlakeF{} \in \{0, 1\}$ +\green{(\emph{c})} verify the \hubMod{}'s prediction as to the (non)vanishing of \locRac{} +\green{(\emph{d})} justify the failure / success of the precompile +\green{(\emph{e})} computed the \locRemainingGas{}. + +We thus introduce the following (local) shorthands: +\[ + \left\{ \begin{array}{lclr} + \locCallGas & \define & \oobDataCol {1} _{i} \\ + % & \define & \oobDataCol {2} _{i} \\ + % & \define & \oobDataCol {3} _{i} \\ + \locRamSuccess & \define & \oobDataCol {4} _{i} & \prediction \\ + \locReturnGas & \define & \oobDataCol {5} _{i} & \prediction \\ + \locBlakeR & \define & \oobDataCol {6} _{i} \\ + \locBlakeF & \define & \oobDataCol {7} _{i} \\ + % & \define & \oobDataCol {8} _{i} \\ + \end{array} \right. +\] + +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$ and n°$(i + 1)$:}] we impose the following: + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{0} + {0}{\locCallGas} + {0}{\locBlakeR} + \vspace{2mm} \\ + \oobCallToEq + {i}{1} + {0}{\locBlakeF} + {0}{\locBlakeF \cdot \locBlakeF} + \vspace{2mm} \\ + \end{array} \right. + \] + we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locSufficientGas & \define & 1 - \outgoingResLo _{i} \\ + \locFisABit & \define & \outgoingResLo _{i + 1} \\ + \end{array} \right. + \] + It follows that $\locInsufficientGas = 1 \iff \locCallGas < \locBlakeR$ i.e. if and only if the \inst{BLAKE2f} precompile was provided with insufficient gas. + It follows that $\locFNotABit = 1 \iff \locBlakeF \notin \{0, 1\}$. + \saNote{} There is no issue with \locBlakeR{} overflowing the \wcpMod{} as that parameter will have been extracted from \textsc{ram} as a 4-Byte integer. + \saNote{} The parameter \locBlakeF{} will have been extracted from \textsc{ram} as a single byte. There is no danger of overflowing the \wcpMod{} by providing it with the square of \locBlakeF{} as one of its inputs. + \item[\underline{Justifying \hubMod{} predictions:}] + we impose + \[ + \locRamSuccess = \locSufficientGas \cdot \locFisABit + \] + we further impose that + \begin{enumerate} + \item \If $\locRamSuccess = 1$ \Then \( \locReturnGas = \locCallGas - \locBlakeR \); + \item \If $\locRamSuccess = 0$ \Then \( \locReturnGas = 0 \). + \end{enumerate} +\end{description} diff --git a/oob/precompiles/common/_inputs.tex b/oob/precompiles/common/_inputs.tex new file mode 100644 index 0000000..dbad1d6 --- /dev/null +++ b/oob/precompiles/common/_inputs.tex @@ -0,0 +1,4 @@ +\subsection{Common constraints for precompiles} \label{oob: precompiles: common precompiles: generalities} \input{precompiles/common/generalities} \newpage +\subsection{For \oobInstEcrecover{}, \oobInstEcadd{} and \oobInstEcmul{}} \label{oob: precompiles: common precompiles: one row precompiles} \input{precompiles/common/one} \newpage +\subsection{For \oobInstShaTwo{}, \oobInstRipemd{} and \oobInstIdentity{}} \label{oob: precompiles: common precompiles: two row precompiles} \input{precompiles/common/two} \newpage +\subsection{For \oobInstEcpairing{}} \label{oob: precompiles: common precompiles: three row precompiles} \input{precompiles/common/tre} \newpage diff --git a/oob/precompiles/common/generalities.tex b/oob/precompiles/common/generalities.tex new file mode 100644 index 0000000..1940a89 --- /dev/null +++ b/oob/precompiles/common/generalities.tex @@ -0,0 +1,58 @@ +\[ + \boxed{\text{All constraints in this subsection further assume that } + \locPrcFlagSumCommon_{i} = 1 + } +\] +The present section describes some common constraints to the processing of all \oobMod{} instructions related to the following precompiles: +\begin{multicols}{3} + \begin{itemize} + \item \inst{ECRECOVER} + \item\inst{ECADD} + \item\inst{ECMUL} + \item\inst{SHA2-256} + \item\inst{RIPEMD-160} + \item\inst{IDENTITY} + \item\inst{ECPAIRING}. + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{itemize} +\end{multicols} +\noindent What these precompiles have in common is +\green{(\emph{a})} establish whether or not $\CDS \equiv 0$ +\green{(\emph{b})} establish whether or not $\RAC \equiv 0$. + +We impose the following constraints: +\begin{description} + \item[\underline{Row n°$(i)$:}] we impose the following: + \[ + \oobCallToIszero + {i}{0} + {0}{\locCds} + \] + and we define the shorthand $\locCdsIsZero \define \outgoingResLo_{i}$ + \item[\underline{Row n°$(i + 1)$:}] we impose the following: + \[ + \oobCallToIszero + {i}{1} + {0}{\locRac} + \] + and we define the shorthand $\locRacIsZero \define \outgoingResLo_{i + 1}$ + \item[\underline{Justifying some \hubMod{} predictions:}] + we impose the following relations + \[ + \left\{ \begin{array}{lcl} + \locExtractCallData & = & \locHubSuccess \cdot (1 - \locCdsIsZero) \\ + \locEmptyCallData & = & \locHubSuccess \cdot \locCdsIsZero \\ + \locRacIsNonzero & = & 1 - \locRacIsZero \\ + \end{array} \right. + \] + \saNote{} We want the binary flags + \locExtractCallData{} and + \locEmptyCallData{} + to light up \textbf{only} if the underlying precompile satisfies $\locHubSuccess \equiv 1$. + Note that at this stage the conditions that trigger $\locHubSuccess \equiv 1$ aren't set. + Neither is it clear that \locHubSuccess{} is binary. +\end{description} +We remind the reader that the remaing objectives of the \oobMod{} module in this particular case are to perform the following tasks +\green{(\emph{a})} compare the call gas to the (constant) cost of these precompiles thus justifying the \locHubSuccess{} (In case of \inst{ECPAIRING} a congruence must also be checked) +\green{(\emph{b})} compute the \locReturnGas{}. diff --git a/oob/precompiles/common/one.tex b/oob/precompiles/common/one.tex new file mode 100644 index 0000000..9f51598 --- /dev/null +++ b/oob/precompiles/common/one.tex @@ -0,0 +1,47 @@ +The present section describes the remaining computations required for dealing with \inst{ECRECOVER}, \inst{ECADD} and \inst{ECMUL}. +As such: +\[ + \boxed{\text{All constraints in this subsection further assume } + \left[ \begin{array}{cr} + + & \oobInstIsEcrecover_{i} \\ + + & \oobInstIsEcadd_{i} \\ + + & \oobInstIsEcmul_{i} \\ + \end{array} \right] + = 1 + } +\] +We impose that +\begin{description} + \item[\underline{Row n°$(i + 2)$:}] we impose the following: + \[ + \oobCallToLt + {i}{2} + {0}{\locCallGas} + {0}{\locPrecompileCost} + \] + where + \[ + \locPrecompileCost + \define + \left[ \begin{array}{crcl} + + & 3000 & \cdot & \oobInstIsEcrecover_{i} \\ + + & 150 & \cdot & \oobInstIsEcadd_{i} \\ + + & 6000 & \cdot & \oobInstIsEcmul_{i} \\ + \end{array} \right] + \] + we further introduce the following shorthand + \[ + \locInsufficientGas \define \outgoingResLo_{i + 2} + \] + it follows that $\locCallGas < \locPrecompileCost \iff \locInsufficientGas = 1$. + \item[\underline{Justifying the remaining \hubMod{} predictions:}] + we impose that + \[ + \locHubSuccess = 1 - \locInsufficientGas. + \] + we further impose that + \begin{enumerate} + \item \If $\locHubSuccess = 0$ \Then $\locReturnGas = 0$ + \item \If $\locHubSuccess = 1$ \Then $\locReturnGas = \locCallGas - \locPrecompileCost$ + \end{enumerate} +\end{description} diff --git a/oob/precompiles/common/tre.tex b/oob/precompiles/common/tre.tex new file mode 100644 index 0000000..4d544a2 --- /dev/null +++ b/oob/precompiles/common/tre.tex @@ -0,0 +1,66 @@ +The present section describes the remaining computations required for \inst{ECPAIRING}. +As such: +\[ + \boxed{\text{All constraints in this subsection further assume } + \oobInstIsEcpairing_{i} = 1 } +\] +Besides verifying whether the precompile was provided with sufficient gas we must also check a congruence condition. +\begin{description} + \item[\underline{Row n°$(i + 2)$:}] + we impose that + \[ + \oobCallToMod + {i}{2} + {0}{\locCds} + {0}{192} + \] + and we define the following shorthand + \[ + \locRemainder \define \outgoingResLo_{i + 2} + \] + \item[\underline{Row n°$(i + 3)$:}] + we impose that + \[ + \oobCallToIszero + {i}{3} + {0}{\locRemainder} + \] + and we define the following shorthand + \[ + \locPairingSizeIsMultiple \define \outgoingResLo_{i + 3} + \] + \item[\underline{Row n°$(i + 4)$:}] + we impose that + \begin{enumerate} + \item \If $\locPairingSizeIsMultiple = 0$ \Then we impose $\oobNoCall{4}_{i}$. + \item \If $\locPairingSizeIsMultiple = 1$ \Then we impose that + \[ + \oobCallToLt + {i}{4} + {0}{\locCallGas} + {0}{\locPrecompileCost} + \] + where we use the following shorthand + \[ + \locPrecompileCost \define \Big[ 45000 + 34000 \cdot \big( \locCds / 192 \big) \Big] + \] + we further introduce the following shorthand + \[ + \locInsufficientGas \define \outgoingResLo_{i + 4} + \] + It follows that $\locCallGas < \locPrecompileCost \iff \locInsufficientGas = 1$. + \end{enumerate} + \item[\underline{Justifying the remaining \hubMod{} predictions:}] + we impose that + \[ + \locHubSuccess = + \locPairingSizeIsMultiple \cdot + (1 - \locInsufficientGas) + \] + we further impose that + \begin{enumerate} + \item \If $\locHubSuccess = 0$ \Then $\locReturnGas = 0$ + \item \If $\locHubSuccess = 1$ \Then $\locReturnGas = \locCallGas - \locPrecompileCost$ + \end{enumerate} +\end{description} +\saNote{} In other words $\locHubSuccess \equiv 1 \iff$ \Big($\cds \equiv 0 \mod 192$ \et{} $\locCallGas \geq \locPrecompileCost$\Big). diff --git a/oob/precompiles/common/two.tex b/oob/precompiles/common/two.tex new file mode 100644 index 0000000..31322d4 --- /dev/null +++ b/oob/precompiles/common/two.tex @@ -0,0 +1,73 @@ +The present section describes the remaining computations required for dealing with +\inst{SHA2-256}, +\inst{RIPEMD-160} and +\inst{IDENTITY}. +As such: +\[ + \boxed{\text{All constraints in this subsection further assume } + \left[ \begin{array}{cr} + + & \oobInstIsShaTwo_{i} \\ + + & \oobInstIsRipemd_{i} \\ + + & \oobInstIsIdentity_{i} \\ + \end{array} \right] = 1} +\] +These precompiles have in common is that in order to compute their \locPrecompileCost{} one must compute +\[ + \locCeil \equiv \bigg \lceil \frac{\locCds}{32} \bigg \rceil, \quad \locCds \equiv \|I_\textbf{d}\|. +\] +\begin{description} + \item[\underline{Row n°$(i + 2)$:}] we impose the following: + \[ + \oobCallToDiv + {i}{2} + {0}{\locCds + 31} + {0}{32} + \] + we further define the shorthand $\locCeil \define \outgoingResLo_{i + 2}$. +\end{description} +\saNote{} Computing the addition $\locCds + 31$ does not require the \addMod{} module. +Indeed, if (a \inst{CALL}-type instruction targeting) a precompile makes it this far its \CDS{} parameter is known to be small by virtue of it not triggering a \mxpxSH{}. +The sum ``$\locCds + 31$'' may therefore be safely computed as above. +\begin{description} + \item[\underline{Row n°$(i + 3)$:}] we impose that + \[ + \oobCallToLt + {i}{3} + {0}{\locCallGas} + {0}{\locPrecompileCost} + \] + where + \[ + \locPrecompileCost \define + \Big[ 5 + \locCeil \Big] + \cdot + \left[ \begin{array}{crcl} + + & 12 & \cdot & \oobInstIsShaTwo _{i} \\ + + & 120 & \cdot & \oobInstIsRipemd _{i} \\ + + & 3 & \cdot & \oobInstIsIdentity _{i} \\ + \end{array} \right] + \] + we further introduce the following shorthand + \[ + \locInsufficientGas \define \outgoingResLo_{i + 3} + \] + it follows that $\locCallGas < \locPrecompileCost \iff \locInsufficientGas = 1$. + \item[\underline{Justifying the remaining \hubMod{} predictions:}] + we impose that + \[ + \locHubSuccess = 1 - \locInsufficientGas. + \] + we further impose that + \begin{enumerate} + \item \If $\locHubSuccess = 0$ \Then $\locReturnGas = 0$ + \item \If $\locHubSuccess = 1$ \Then $\locReturnGas = \locCallGas - \locPrecompileCost$ + \end{enumerate} +\end{description} +% We thus introduce the following (local) shorthands: +% \[ +% \left\{ \begin{array}{lcl} +% \locCeil & \longleftrightarrow & \outgoingResLo _{i + 2} \\ +% \locInsufficientGas & \longleftrightarrow & \outgoingResLo _{i + 3} \\ +% \end{array} \right. +% \] +% \saNote{} Since the above precompiles can fail in more complex ways than being provided with insufficient gas, what we have called ``remaining gas'' should really be called ``potentially refunded gas.'' diff --git a/oob/precompiles/lua/layout.lua.tex b/oob/precompiles/lua/layout.lua.tex new file mode 100644 index 0000000..fd4468c --- /dev/null +++ b/oob/precompiles/lua/layout.lua.tex @@ -0,0 +1,113 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\usepackage{../../../pkg/draculatheme} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██\ ██\ ██\ ██\ ███████\ ██\ ██████\ ██████\ ███████\ ██\ ██\ ██████\ + ██ | ██ |██ | ██ |██ __██\ ██ | ██ __██\ ██ __██\ ██ __██\ \__| ██ | ██ __██\ + ██ | ██ |██ | ██ |██ | ██ | ██ / ██ / ██ |██ / ██ |██ | ██ | ██\ ███████\ ██████\ ██████\ ██████\ ██ / \__|██████\ ███████\ ██████\ + ████████ |██ | ██ |███████\ | ██ / ██ | ██ |██ | ██ |███████\ | ██ |██ __██\\_██ _| ██ __██\ ██ __██\ ████\ \____██\ ██ _____|██ __██\ + ██ __██ |██ | ██ |██ __██\ ██ / ██ | ██ |██ | ██ |██ __██\ ██ |██ | ██ | ██ | ████████ |██ | \__|██ _| ███████ |██ / ████████ | + ██ | ██ |██ | ██ |██ | ██ | ██ / ██ | ██ |██ | ██ |██ | ██ | ██ |██ | ██ | ██ |██\ ██ ____|██ | ██ | ██ __██ |██ | ██ ____| + ██ | ██ |\██████ |███████ | ██ / ██████ | ██████ |███████ | ██ |██ | ██ | \████ |\███████\ ██ | ██ | \███████ |\███████\ \███████\ + \__| \__| \______/ \_______/ \__/ \______/ \______/ \_______/ \__|\__| \__| \____/ \_______|\__| \__| \_______| \_______| \_______| + + + _) | + __ \ __| _ \ __| _ \ __ `__ \ __ \ | | _ \ __| + | | | __/ ( ( | | | | | | | | __/ \__ \ + .__/ _| \___| \___| \___/ _| _| _| .__/ _| _| \___| ____/ + _| _| + +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| OOB_INST | OOB_DATA_1 | OOB_DATA_2 | OOB_DATA_3 | OOB_DATA_4 | OOB_DATA_5 | OOB_DATA_6 | OOB_DATA_7 | OOB_DATA_8 | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_ecrecover⟧ | call_gas | cds | r@c | hub_success ≡ | return_gas ≡ | extract_call_data ≡ | empty_call_data ≡ | r@c_nonzero ≡ | +| ⟦OOB_INST_sha2-256⟧ | | | | . [gas_cost ≤ call_gas] | . 0 ∨ [call_gas - gas_cost] | . hub_success | . hub_success | . [r@c ≠ 0] | +| ⟦OOB_INST_ripemd-160⟧ | | | | | | . ∧ [cds ≠ 0] | . ∧ [cds = 0] | | +| ⟦OOB_INST_identity⟧ | | | | | | | | | +| ⟦OOB_INST_ecadd⟧ | | | | | | | | | +| ⟦OOB_INST_ecmul⟧ | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_ecpairing⟧ | call_gas | cds | r@c | hub_success ≡ | return_gas ≡ | extract_call_data ≡ | empty_call_data ≡ | r@c_nonzero ≡ | +| | | | | . [gas_cost ≤ call_gas] | . 0 ∨ [call_gas - gas_cost] | . hub_success | . hub_success | . [r@c ≠ 0] | +| | | | | . ∧ [cds ≡ 0 mod 192] | . (if hub_success ≡ true) | . ∧ [cds ≠ 0] | . ∧ [cds = 0] | | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_modexp_cds⟧ | | cds | extract_bbs ≡ | extract_ebs ≡ | extract_mbs ≡ | | | | +| | | | . [0 < cds] | . [32 < cds] | . [64 < cds] | | | | +| | | | | | | | | | +| | | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | | | | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_modexp_xbs⟧ | xbs_hi | xbs_lo | ybs_lo | do_compute_max | | | max ≡ | xbs_nonzero ≡ | +| | | | | | | | . xbs ∨ ybs | . [xbs ≠ 0] | +| | | | | | | | (if do_compute_max ≡ true) | (if do_compute_max ≡ true) | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | | | ⟦ π ⟧ | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_modexp_lead⟧ | bbs_lo | cds | ebs_lo | load_lead ≡ | | lead_calldata_bytes ≡ | lead_exponent_bytes ≡ | ebs_sub_32 ≡ | +| | | | | . [cds > 96 + bbs] | | . [0 ∨ [cds - 96 - bbs]] | . ebs ∧ 32 | . 0 ∨ [ebs - 32] | +| | | | | . ∧ [ebs ≠ 0] | | . ∧ 32 | | | +| | | | | | | | | | +| | ✓ trusted | ✓ trusted | ✓ trusted | ⟦ π ⟧ | | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_modexp_pricing⟧ | call_gas | | r@c | ram_success ≡ | return_gas ≡ | exponent_log | max_mbs_bbs | r@c_nonzero ≡ | +| | | | | . [gas_cost ≤ call_gas] | . 0 ∨ [call_gas - gas_cost] | | | . [r@c ≠ 0] | +| | | | | | | | | | +| | ✓ trusted | | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | ✓ trusted | ✓ trusted | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_modexp_extract⟧ | | cds | bbs_lo | ebs_lo | mbs_lo | base_extraction ≡ | exponent_extraction ≡ | modulus_extraction ≡ | +| | | | | | | . modulus_extraction | . modulus_extraction | . [cds > 96 + bbs + ebs] | +| | | | | | | . ∧ [bbs ≠ 0] | . ∧ [ebs ≠ 0] | . ∧ [mbs ≠ 0] | +| | | | | | | | | | +| | | ✓ trusted | ✓ trusted | ✓ trusted | ✓ trusted | ⟦ π ⟧ | ⟦ π ⟧ | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_blake_cds⟧ | | cds | r@c | hub_success ≡ | | | | r@c_nonzero ≡ | +| | | | | . [cds = 213] | | | | . [r@c ≠ 0] | +| | | | | | | | | | +| (we could merge it | | | | | | | | | +| with others) | | ✓ trusted | ✓ trusted | ⟦ π ⟧ | | | | ⟦ π ⟧ | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| +| ⟦OOB_INST_blake_params⟧ | call_gas | | | ram_success ≡ | return_gas ≡ | r | f | | +| | | | | . [r ≤ call_gas] | . 0 ∨ [call_gas - r] | | | | +| | | | | . ∧ [f ≡ bit] | | | | | +| | | | | | | | | | +| | ✓ trusted | | | ⟦ π ⟧ | ⟦ π ⟧ | ✓ trusted | ✓ trusted | | +|---------------------------+------------+------------+---------------+---------------------------+-------------------------------+----------------------------+----------------------------+----------------------------| + +Comments: +- call_gas, cds and r@c always occupy the same columns (when present); +- return_gas, r@c_nonzero and hub_success/ram_success always occupy the same columns (when present); +- the data layout for + * ⟦OOB_ecrecover⟧ * ⟦OOB_sha2-256⟧ * ⟦OOB_ecpairing⟧ + * ⟦OOB_ecadd⟧ * ⟦OOB_ripemd-160⟧ + * ⟦OOB_ecmul⟧ * ⟦OOB_identity⟧ + is precisely the same; +- the ``⟦ π ⟧'' label applies to HUB-module PREDICTIONS which the OOB module is tasked with justifying; + +While the data layout is the same the underlying computations performed by the OOB module are distinct +- the "gas_cost" computation are precompile specific; +- the "hub_success" condition are always just [call_gas ≤ gas_cost] except for ⟦OOB_ecpairing⟧ which also requires a congruence condition. + +NOTE. ECADD, ECMUL and ECPAIRING can have hard failures unrelated to insufficient gas induced by MALFORMED DATA. +Detection of these, however, requires reading input data from RAM. Such failures will be detected by the SCEN/PRC_FAILURE_KNOWN_TO_RAM +\end{verbatim} +\end{document} diff --git a/oob/precompiles/modexp/_inputs.tex b/oob/precompiles/modexp/_inputs.tex new file mode 100644 index 0000000..eeb2590 --- /dev/null +++ b/oob/precompiles/modexp/_inputs.tex @@ -0,0 +1,6 @@ +% \subsection{The \hubMod{} module's point of view} \input{precompiles/modexp/representation/_table} \label{oob: precompiles: modexp: hub pov} \newpage +\subsection{For $\oobInstModexpCds$} \input{precompiles/modexp/cds} \label{oob: precompiles: modexp: cds} \newpage +\subsection{For $\oobInstModexpXbs$} \input{precompiles/modexp/xbs} \label{oob: precompiles: modexp: xbs check and max} \newpage +\subsection{For $\oobInstModexpLead$} \input{precompiles/modexp/lead} \label{oob: precompiles: modexp: leading word} \newpage +\subsection{For $\oobInstModexpPricing$} \input{precompiles/modexp/pricing} \label{oob: precompiles: modexp: pricing} \newpage +\subsection{For $\oobInstModexpExtract$} \input{precompiles/modexp/extract} \label{oob: precompiles: modexp: data extraction} \newpage diff --git a/oob/precompiles/modexp/cds.tex b/oob/precompiles/modexp/cds.tex new file mode 100644 index 0000000..a468d6d --- /dev/null +++ b/oob/precompiles/modexp/cds.tex @@ -0,0 +1,59 @@ +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsModexpCds_{i} = 1} +\] +The present instruction aims to provide the \hubMod{} module with the following information: +\green{(\emph{a})} whether $ 0 < \locCds$, +\green{(\emph{b})} whether $32 < \locCds$, +\green{(\emph{c})} whether $64 < \locCds$. + +Comparisons of the form ``$32\cdot n < \locCds$'' allow the \hubMod{} module to know when extraction of a \textbf{byte size parameter} from \textsc{ram} is necessary. +Recall that the first 96 (padded) bytes of call data of a \inst{CALL} to the \inst{MODEXP} precompiles are to be interpreted as the +the base byte size \locBbs, +the exponent byte size \locEbs, +the modulus byte size \locMbs{} respectively, +alternatively, using notations from the \cite{EYP}, +$\locBase$, $\locExponent$ and $\locModulus$ respectively. + +\noindent We use the shorthands defined below: +\[ + \left\{ \begin{array}{lclr} + \locCds & \define & \oobDataCol {2} _{i} \\ + \locExtractBbs & \define & \oobDataCol {3} _{i} & \prediction \\ + \locExtractEbs & \define & \oobDataCol {4} _{i} & \prediction \\ + \locExtractMbs & \define & \oobDataCol {5} _{i} & \prediction \\ + \end{array} \right. +\] +\saNote{} The decorator `` $\prediction{}$ '' stands for ``\hubMod{} prediction.'' + +We impose the following constraints: +\begin{description} + \item[\underline{Rows n°$(i)$, $n^\circ(i + 1)$ and $n^\circ(i + 2)$:}] we impose + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{0} + {0}{0} + {0}{\locCds} + \\vspace{2mm} \\ + \oobCallToLt + {i}{1} + {0}{32} + {0}{\locCds} + \vspace{2mm} \\ + \oobCallToLt + {i}{2} + {0}{64} + {0}{\locCds} + \\ + \end{array} \right. + \] + \item[\underline{Justifying \hubMod{} predictions:}] we impose + we further impose + \[ + \left\{ \begin{array}{lcl} + \locExtractBbs & = & \outgoingResLo_{i} \\ + \locExtractEbs & = & \outgoingResLo_{i + 1} \\ + \locExtractMbs & = & \outgoingResLo_{i + 2} \\ + \end{array} \right. + \] +\end{description} diff --git a/oob/precompiles/modexp/extract.tex b/oob/precompiles/modexp/extract.tex new file mode 100644 index 0000000..f18a1af --- /dev/null +++ b/oob/precompiles/modexp/extract.tex @@ -0,0 +1,73 @@ +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsModexpExtract_{i} = 1} +\] +We use the shorthands defined below: +\[ + \left\{ \begin{array}{lclr} + % \locCallGas & \define & \oobDataCol{1}_{i} \\ + \locCds & \define & \oobDataCol{2}_{i} \\ + \locBbs & \define & \oobDataCol{3}_{i} \\ + \locEbs & \define & \oobDataCol{4}_{i} \\ + \locMbs & \define & \oobDataCol{5}_{i} \\ + \locExtractBase & \define & \oobDataCol{6}_{i} & \quad \prediction \\ + \locExtractExponent & \define & \oobDataCol{7}_{i} & \quad \prediction \\ + \locExtractModulus & \define & \oobDataCol{8}_{i} & \quad \prediction \\ + \end{array} \right. +\] +\saNote{} The decorator `` $\prediction{}$ '' stands for ``\hubMod{} prediction.'' + +\begin{description} + \item[\underline{Rows $n^\circ(i)$, $n^\circ(i + 1)$, $n^\circ(i + 2)$ and $n^\circ(i + 3)$:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \oobCallToIszero + {i}{0} + {0}{\locBbs} + \vspace{2mm} \\ + \oobCallToIszero + {i}{1} + {0}{\locEbs} + \vspace{2mm} \\ + \oobCallToIszero + {i}{2} + {0}{\locMbs} + \vspace{2mm} \\ + \oobCallToLt + {i}{3} + {0}{96 + \locBbs + \locEbs} + {0}{\locCds} + \\ + \end{array} \right. + \] + and define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locBbsIsZero & \define & \outgoingResLo_{i } \\ + \locEbsIsZero & \define & \outgoingResLo_{i + 1} \\ + \locMbsIsZero & \define & \outgoingResLo_{i + 2} \\ + \locCallDataExtendsBeyondExponent & \define & \outgoingResLo_{i + 3} \\ + \end{array} \right. + \] + \item[\underline{Justifying \hubMod{} predictions:}] + we impose that + \[ + \left\{ \begin{array}{lcrcl} + \locExtractModulus & = & \locCallDataExtendsBeyondExponent & \!\!\!\cdot\!\!\! & (1 - \locMbsIsZero) \\ + \locExtractBase & = & \locExtractModulus & \!\!\!\cdot\!\!\! & (1 - \locBbsIsZero) \\ + \locExtractExponent & = & \locExtractModulus & \!\!\!\cdot\!\!\! & (1 - \locEbsIsZero) \\ + \end{array} \right. + \] +\end{description} +\saNote{} By construction \( 0 \leq \locExtractXxx \leq \locExtractModulus \leq 1)$ for $\col{xxx} = \col{base}, \col{exponent}, \col{modulus}$. + +\saNote{} We provide some explanations. +The condition ``$\locExtractModulus \equiv 0$'' amounts to either $\locMbs \equiv 0$ or $\locCds \leq 96 + \locBbs + \locEbs$. +In either case the \textbf{modulus} of the underlying \inst{MODEXP} call is $\bm{0}$ and so is the \textbf{result} (though, importantly, the \RDS{} \emph{post-call} is \locMbs{} which can be anything in the range $\{ 0, 1, \dots, 512 \}$.) +In this case there is no reason to extract any of the base, exponent or modulus. +On the other hand when $\locExtractModulus \equiv 1$ it is necessary to extract base, exponent and modulus. +It may still happen that $\locBbs \equiv 0$ or $\locEbs \equiv 0$. +In which case the \hubMod{} will order the \textsc{ram} to send zeros to the \modexpMod{} (rather than potentially left and right padded data from \textsc{ram}.) +To account for this possibility the $\oobInstModexpExtract$ instruction provides the bits +\locExtractBase {} and +\locExtractExponent {} for exploitation by the \inst{MODEXP} processing in the \hubMod{} module. diff --git a/oob/precompiles/modexp/lead.tex b/oob/precompiles/modexp/lead.tex new file mode 100644 index 0000000..5fdd4a9 --- /dev/null +++ b/oob/precompiles/modexp/lead.tex @@ -0,0 +1,101 @@ +The present section describes computations required in order to determine whether or not to extract the leading word (potentially zero padded) of the exponent. +The \inst{MODEXP} computes the $\lfloor \log_{2} ( \cdots ) \rfloor$ of this in order to deduce what the \cite{EYP} calls $\locExponentLogEYP$. +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsModexpLead_{i} = 1} +\] +What the present system of constraints aims to verify the following predictions made in the \hubMod{} module: +\green{(\emph{a})} compute the small integer $32\wedge \big[ \locCds - (96 + \locBbs) \big]^+$ +\green{(\emph{b})} compute the bit $[ \locCds > (96 + \locBbs) ] \wedge [ \locEbs \neq 0 ]$. + +\noindent We use the shorthands defined below: +\[ + \left\{ \begin{array}{lclr} + \locBbs & \define & \oobDataCol {1} _{i} \\ + \locCds & \define & \oobDataCol {2} _{i} \\ + \locEbs & \define & \oobDataCol {3} _{i} \\ + \locLoadLeadingWord & \define & \oobDataCol {4} _{i} & \prediction \\ + \locCdsCutoff & \define & \oobDataCol {6} _{i} & \prediction \\ + \locEbsCutoff & \define & \oobDataCol {7} _{i} & \prediction \\ + \locEbsSubThirtyTwo & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] +\saNote{} The decorator `` $\prediction{}$ '' stands for ``\hubMod{} prediction.'' + +We impose the following constraints: +\begin{description} + \item[\underline{Rows $n^\circ(i)$, $n^\circ(i + 1)$ and $n^\circ(i + 2)$:}] + we impose + \[ + \left\{ \begin{array}{lcl} + \oobCallToIszero + {i}{0} + {0}{\locEbs} + \vspace{2mm} \\ + \oobCallToLt + {i}{1} + {0}{\locEbs} + {0}{32} + \vspace{2mm} \\ + \oobCallToLt + {i}{2} + {0}{96 + \locBbs} + {0}{\locCds} + \end{array} \right. + \] + and define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locEbsIsZero & \define & \outgoingResLo_{i } \\ + \locEbsLtThirtyTwo & \define & \outgoingResLo_{i + 1} \\ + \locCallDataContainsExponentBytes & \define & \outgoingResLo_{i + 2} \\ + \end{array} \right. + \] + \item[\underline{Row $n^\circ(i + 3)$:}] + \If $\locCallDataContainsExponentBytes = 1$ \Then + \[ + \oobCallToLt + {i}{3} + {0}{\locCds - \big( 96 + \locBbs \big)} + {0}{32} + \] + we define the following shorthand + \[ + \locCmp \define \outgoingResLo_{i + 3} + \] + \item[\underline{Justifying \hubMod{} predictions:}] --- + \begin{description} + \item[Constraining \locLoadLeadingWord{}:] we impose that + \[ + \locLoadLeadingWord + = + \locCallDataContainsExponentBytes \cdot (1 - \locEbsIsZero) + \] + \item[Constraining \locCdsCutoff{}:] we impose that + \begin{enumerate} + \item \If $\locCallDataContainsExponentBytes = 0$ \Then $\locCdsCutoff = 0$ + \item \If $\locCallDataContainsExponentBytes = 1$ \Then + \begin{enumerate} + \item \If $\locCmp = 0$ \Then $\locCdsCutoff = 32$ + \item \If $\locCmp = 1$ \Then $\locCdsCutoff = \locCds - \big( 96 + \locBbs \big)$ + \end{enumerate} + \end{enumerate} + \item[Constraining \locEbsCutoff {}:] we impose that + \begin{enumerate} + \item \If $\locEbsLtThirtyTwo = 0$ \Then $\locEbsCutoff = 32$ + \item \If $\locEbsLtThirtyTwo = 1$ \Then $\locEbsCutoff = \locEbs$ + \end{enumerate} + \item[Constraining \locEbsSubThirtyTwo {}:] we impose that + \begin{enumerate} + \item \If $\locEbsLtThirtyTwo = 0$ \Then $\locEbsSubThirtyTwo = \locEbs - 32$ + \item \If $\locEbsLtThirtyTwo = 1$ \Then $\locEbsSubThirtyTwo = 0$ + \end{enumerate} + \end{description} +\end{description} +\saNote{} The above thus computes respectively +\[ + \left\{ \begin{array}{lcl} + \locCdsCutoff & \equiv & \Big[ \locCds - \big( 96 + \locBbs \big) \Big] ^ + \wedge \, 32 \\ + \locEbsCutoff & \equiv & \locEbs \wedge 32 \\ + \locEbsSubThirtyTwo & \equiv & \Big[ \locEbs - 32 \Big] ^ + \\ + \end{array} \right. +\] diff --git a/oob/precompiles/modexp/pricing.tex b/oob/precompiles/modexp/pricing.tex new file mode 100644 index 0000000..f77df44 --- /dev/null +++ b/oob/precompiles/modexp/pricing.tex @@ -0,0 +1,124 @@ +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsModexpPricing_{i} = 1} +\] +We use the shorthands defined below: +\[ + \left\{ \begin{array}{lclr} + \locCallGas & \define & \oobDataCol{1}_{i} \\ + % \locCds & \define & \oobDataCol{2}_{i} \\ + \locRac & \define & \oobDataCol{3}_{i} \\ + \locRamSuccess & \define & \oobDataCol{4}_{i} & \quad \prediction \\ + \locReturnGas & \define & \oobDataCol{5}_{i} & \quad \prediction \\ + \locExponentLog & \define & \oobDataCol{6}_{i} \\ + \locMaxMbsBbs & \define & \oobDataCol{7}_{i} \\ + \locRacIsNonzero & \define & \oobDataCol{8}_{i} & \quad \prediction \\ + \end{array} \right. +\] +\saNote{} The decorator `` $\prediction{}$ '' stands for ``\hubMod{} prediction.'' + +\saNote{} +The intended interpretation is that $\locExponentLog$ contain $\locExponentLogEYP$ as defined in the \cite{EYP}. +The value of \locExponentLog{} will be computed in the \expMod{} module using a specialized instruction. + +We impose the following: +\begin{description} + \item[\underline{Rows n°$(i)$, $n^\circ(i + 1)$ and $n^\circ(i + 2)$:}] we impose + we impose that + \[ + \left\{ \begin{array}{l} + \oobCallToIszero + {i}{0} + {0}{\locRac} + \vspace{2mm} \\ + \oobCallToIszero + {i}{1} + {0}{\locExponentLog} + \vspace{2mm} \\ + \oobCallToDiv + {i}{2} + {0}{\locMax \cdot \locMax + 7} + {0}{8} + \\ + \end{array} \right. + \] + we define the following associated shorthands + \[ + \left\{ \begin{array}{lcl} + \locExponentLogIsZero & \define & \outgoingResLo_{i + 1} \\ + \locFOfMax & \define & \outgoingResLo_{i + 2} \\ + \end{array} \right. + \] +\end{description} +\saNote{} $\locFOfMax$ computes $\displaystyle f\big(\max(\locBase, \locModulus)\big) = \left\lceil\frac{\max(\locBase, \locModulus)^2}{8}\right\rceil$. +\begin{description} + \item[\underline{Row $n^°(i + 3)$:}] + we impose that + \[ + \oobCallToDiv + {i}{3} + {0}{\locProduct} + {0}{G_\text{quaddivisor}} + \] + where $G_\text{quaddivisor} = 3$ and we have used the following shorthand + \[ + \left\{ \begin{array}{lcl} + \locProduct & \define & + \begin{cases} + \If \locExponentLogIsZero = 0 ~ \Then : & \locFOfMax \cdot \locExponentLog \\ + \If \locExponentLogIsZero = 1 ~ \Then : & \locFOfMax + \end{cases} \\ + \locBigQuotient & \define & \outgoingResLo_{i + 3} \\ + \end{array} \right. + \] +\end{description} +\saNote{} Thus $\locProduct$ computes, in the notations of the \cite{EYP}, $\displaystyle f\big(\max(\locBase, \locModulus)\big) \cdot \max(\locExponentLogEYP, 1)$. +It follows that $\locBigQuotient$ computes +\[ + \left\lfloor\frac{f\big(\max(\locBase, \locModulus)\big) \cdot \max(\locExponentLogEYP, 1)}{G_\text{quaddivisor}}\right\rfloor. +\] +\begin{description} + \item[\underline{Rows $n^°(i + 4)$ and $n^°(i + 5)$:}] + we impose that + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{4} + {0}{\locBigQuotient} + {0}{200} + \vspace{2mm} \\ + \oobCallToLt + {i}{5} + {0}{\locCallGas} + {0}{\locPrecompileCost} + \\ + \end{array} \right. + \] + we define the \locBigQuotientLtTwoHundred{} shorthand + \[ + \locBigQuotientLtTwoHundred \define \outgoingResLo_{i + 4} + \] + from which we define the \locPrecompileCost{} shorthand used above + \begin{enumerate} + \item \If \locBigQuotientLtTwoHundred = 0 \Then $\locPrecompileCost \define \locBigQuotient$ + \item \If \locBigQuotientLtTwoHundred = 1 \Then $\locPrecompileCost \define 200$ + \end{enumerate} + \item[\underline{Justifying \hubMod{} predictions:}] we impose that + \begin{description} + \item[{Constraining \locRamSuccess:}] + we impose that + \[ + \locRamSuccess = 1 - \outgoingResLo_{i + 5} + \] + \item[{Constraining \locReturnGas:}] + we impose that + \begin{enumerate} + \item \If $\locRamSuccess = 0$ \Then $\locReturnGas = 0$ + \item \If $\locRamSuccess = 1$ \Then $\locReturnGas = \locCallGas - \locPrecompileCost$ + \end{enumerate} + \item[{Constraining \locRacIsNonzero:}] + we impose that + \[ + \locRacIsNonzero = 1 - \outgoingResLo_{i} + \] + \end{description} +\end{description} diff --git a/oob/precompiles/modexp/representation/_end.tex b/oob/precompiles/modexp/representation/_end.tex new file mode 100644 index 0000000..8a5d9d6 --- /dev/null +++ b/oob/precompiles/modexp/representation/_end.tex @@ -0,0 +1 @@ +\end{array} diff --git a/oob/precompiles/modexp/representation/_start.tex b/oob/precompiles/modexp/representation/_start.tex new file mode 100644 index 0000000..bfdf7c2 --- /dev/null +++ b/oob/precompiles/modexp/representation/_start.tex @@ -0,0 +1,3 @@ +\renewcommand\arraystretch{1.3} +\begin{array}{|c|c|c|c|c|c|c||c|} \hline +\locInc {1} & \locInc {2} & \locInc {3} & \locInc {4} & \locInc {5} & \locInc {6} & \oobDataCol{7}{1} & \locIncomingInstruction diff --git a/oob/precompiles/modexp/representation/_table.tex b/oob/precompiles/modexp/representation/_table.tex new file mode 100644 index 0000000..33291dc --- /dev/null +++ b/oob/precompiles/modexp/representation/_table.tex @@ -0,0 +1,24 @@ +Below we represent the sequence of \oobMod{} instructions that are generated by the \hubMod{} module: +\begin{figure}[!h] + \[ + \hspace*{-2.5cm} + \input{precompiles/modexp/representation/_start} \\ \hline \hline + \input{precompiles/modexp/representation/cds} \\ \hline + \input{precompiles/modexp/representation/bbs} \\ \hline + \input{precompiles/modexp/representation/ebs} \\ \hline + \input{precompiles/modexp/representation/mbs} \\ \hline + \input{precompiles/modexp/representation/lead} \\ \hline + \input{precompiles/modexp/representation/pricing} \\ \hline \hline + \input{precompiles/modexp/representation/instruction_modulus} \\ \hline + \input{precompiles/modexp/representation/instruction_exponent} \\ \hline + \input{precompiles/modexp/representation/instruction_base} \\ \hline + \end{array} + \] + \caption{Incoming data of the first means by which \inst{MODEXP} may interact with the \oobMod{} module. + Cells that are colored contain data which is vetted by the \hubMod{}. + All other (nonvacuous) cells contain data which must be confirmed by the \oobMod{} module. + Note that \locMaxMbsBbs{} is initially not highlighted, but is highlighted the second time around. + This is becase when it first appears the \oobMod{} module verifies this particular \hubMod{} module predition, and the second time it appears (pointing to the same underlying value) this value requires not more justification. + } + \label{fig: oob: MODEXP pricing} +\end{figure} diff --git a/oob/precompiles/modexp/representation/bbs.tex b/oob/precompiles/modexp/representation/bbs.tex new file mode 100644 index 0000000..1705355 --- /dev/null +++ b/oob/precompiles/modexp/representation/bbs.tex @@ -0,0 +1 @@ +\x\locBbsHi & \x\locBbsLo & \nothing & \nothing & \nothing & \nothing & \nothing & \oobInstModexpBase diff --git a/oob/precompiles/modexp/representation/cds.tex b/oob/precompiles/modexp/representation/cds.tex new file mode 100644 index 0000000..8a0d2f8 --- /dev/null +++ b/oob/precompiles/modexp/representation/cds.tex @@ -0,0 +1 @@ +\x\locCds & \locExtractBbs & \locExtractEbs & \locExtractMbs & \locTrimBbs & \locTrimEbs & \locTrimMbs & \oobInstModexpCds diff --git a/oob/precompiles/modexp/representation/ebs.tex b/oob/precompiles/modexp/representation/ebs.tex new file mode 100644 index 0000000..8f1041b --- /dev/null +++ b/oob/precompiles/modexp/representation/ebs.tex @@ -0,0 +1 @@ +\x\locEbsHi & \x\locEbsLo & \nothing & \nothing & \locEbsMinThirtyTwo & \locEbsSubThirtyTwo & \nothing & \oobInstModexpExponent diff --git a/oob/precompiles/modexp/representation/instruction.tex b/oob/precompiles/modexp/representation/instruction.tex new file mode 100644 index 0000000..708ffa4 --- /dev/null +++ b/oob/precompiles/modexp/representation/instruction.tex @@ -0,0 +1 @@ +\x\locCds & \x\locUsedBytes & \x\locByteSize & \locTransferAllZeros & \locTransferUntrimmed & \locTransferTrimmed & \locNonZeroByteSize & \oobInstModexpExtract diff --git a/oob/precompiles/modexp/representation/instruction_base.tex b/oob/precompiles/modexp/representation/instruction_base.tex new file mode 100644 index 0000000..08b540f --- /dev/null +++ b/oob/precompiles/modexp/representation/instruction_base.tex @@ -0,0 +1 @@ +\x\locCds & 0 & \x\locBbs & \locTransferAllZeros & \locTransferUntrimmed & \locTransferTrimmed & \col{nonzero\_bbs} & \oobInstModexpExtract diff --git a/oob/precompiles/modexp/representation/instruction_exponent.tex b/oob/precompiles/modexp/representation/instruction_exponent.tex new file mode 100644 index 0000000..c95526d --- /dev/null +++ b/oob/precompiles/modexp/representation/instruction_exponent.tex @@ -0,0 +1 @@ +\x\locCds & \x \locBbs & \x\locEbs & \locTransferAllZeros & \locTransferUntrimmed & \locTransferTrimmed & \col{nonzero\_ebs} & \oobInstModexpExtract diff --git a/oob/precompiles/modexp/representation/instruction_modulus.tex b/oob/precompiles/modexp/representation/instruction_modulus.tex new file mode 100644 index 0000000..c14e281 --- /dev/null +++ b/oob/precompiles/modexp/representation/instruction_modulus.tex @@ -0,0 +1 @@ +\x\locCds & \x \locBbs + \locEbs & \x\locMbs & \locTransferAllZeros & \locTransferUntrimmed & \locTransferTrimmed & \col{nonzero\_mbs} & \oobInstModexpExtract diff --git a/oob/precompiles/modexp/representation/lead.tex b/oob/precompiles/modexp/representation/lead.tex new file mode 100644 index 0000000..d3b35db --- /dev/null +++ b/oob/precompiles/modexp/representation/lead.tex @@ -0,0 +1 @@ +\x\locCds & \x\locBbs & \x\locEbs & \nothing & \nothing & \locExtractableCdsBytes & \locLoadLeadingWord & \oobInstModexpLead diff --git a/oob/precompiles/modexp/representation/mbs.tex b/oob/precompiles/modexp/representation/mbs.tex new file mode 100644 index 0000000..059fd56 --- /dev/null +++ b/oob/precompiles/modexp/representation/mbs.tex @@ -0,0 +1 @@ +\x\locMbsHi & \x\locMbsLo & \x\locBbs & \nothing & \nothing & \locMaxMbsBbs & \nothing & \oobInstModexpModulus diff --git a/oob/precompiles/modexp/representation/pricing.tex b/oob/precompiles/modexp/representation/pricing.tex new file mode 100644 index 0000000..61d776d --- /dev/null +++ b/oob/precompiles/modexp/representation/pricing.tex @@ -0,0 +1 @@ +\x\locCallGas & \locRemainingGas & \x\locExponentLog & \x\locMaxMbsBbs & \x\locRac & \locRacIsZero & \locInsufficientGas & \oobInstModexpPricing diff --git a/oob/precompiles/modexp/xbs.tex b/oob/precompiles/modexp/xbs.tex new file mode 100644 index 0000000..6a4ae23 --- /dev/null +++ b/oob/precompiles/modexp/xbs.tex @@ -0,0 +1,75 @@ +\[ + \boxed{\text{All constraints in this subsection further assume } \oobInstIsModexpXbs_{i} = 1} +\] +The present instruction is used thrice within every single call to the \inst{MODEXP} precompile. +It ensures that the byte size arguments are $\leq 512$. +We use the shorthands defined below: +\[ + \left\{ \begin{array}{lclr} + \locXbsHi & \define & \oobDataCol {1} _{i} \\ + \locXbsLo & \define & \oobDataCol {2} _{i} \\ + \locYbsLo & \define & \oobDataCol {3} _{i} \\ + \locComputeMax & \define & \oobDataCol {4} _{i} \\ + \locMax & \define & \oobDataCol {7} _{i} & \prediction \\ + \locXbsNonzero & \define & \oobDataCol {8} _{i} & \prediction \\ + \end{array} \right. +\] +\saNote{} The decorator `` $\prediction{}$ '' stands for ``\hubMod{} prediction.'' + +For the present instruction the \oobMod{} expects the value of \locComputeMax{} to be binary. +In applications the value of \locXbs{} is either \locBbs{}, \locEbs{} or \locMbs{}. +The first step is to compare \locXbs{} to $512$. +If \locComputeMax{} is set we compute the maximum of \locYbsLo{} and \locXbs{}. +The use case for this comparison is to compute the maxium $\max\{ \locBbs, \locMbs \}$ as required by the pricing of the \inst{MODEXP} precompile. +\begin{description} + \item[\underline{Rows n°$(i)$ and $n^\circ(i + 1)$:}] we impose + \[ + \left\{ \begin{array}{l} + \oobCallToLt + {i}{0} + {\locXbsHi}{\locXbsLo} + {0}{512 + 1} + \vspace{2mm} \\ + \oobCallToLt + {i}{1} + {0}{\locXbsLo} + {0}{\locYbsLo} + \vspace{2mm} \\ + \oobCallToIszero + {i}{2} + {0}{\locXbsLo} + \end{array} \right. + \] + we further impose the following constraints + \[ + \left\{ \begin{array}{lclr} + \locComputeMax \cdot (1 - \locComputeMax) & = & 0 & \qquad (\trash) \\ + \locCompToFiveTwelve & = & 1 \\ + \end{array} \right. + \] + where we further define the shorthands + \[ + \left\{ \begin{array}{lcl} + \locCompToFiveTwelve & \define & \outgoingResLo _{i } \\ + \locCmp & \define & \outgoingResLo _{i + 1} \\ + \end{array} \right. + \] + \saNote{} The constraint $\outgoingResLo_{i} = 1$ enforces that the comparison ``$\locXbs < 512 + 1$'' i.e. ``$\locXbs \leq 512$'' return \texttt{true}. + \item[\underline{Justifying \hubMod{} predictions:}] we impose + we further impose that + \begin{enumerate} + \item \If $\locComputeMax = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \locMax & = & 0 \\ + \locXbsNonzero & = & 0 \\ + \end{array} \right. + \] + \item \If $\locComputeMax = 1$ \Then + \begin{enumerate} + \item $\locXbsNonzero = 1 - \outgoingResLo_{i + 2}$ + \item \If $\locCmp = 0$ \Then $\locMax = \locXbsLo$ + \item \If $\locCmp = 1$ \Then $\locMax = \locYbsLo$ + \end{enumerate} + \end{enumerate} +\end{description} diff --git a/oob/precompiles/shorthands.tex b/oob/precompiles/shorthands.tex new file mode 100644 index 0000000..566efcd --- /dev/null +++ b/oob/precompiles/shorthands.tex @@ -0,0 +1,20 @@ +We will regularly, though not always, make use the following shorthands when dealing with precompiles. +\[ + \left\{ \begin{array}{lclr} + \locCallGas & \define & \oobDataCol{1}_{i} \\ + \locCds & \define & \oobDataCol{2}_{i} \\ + \locRac & \define & \oobDataCol{3}_{i} \\ + \locHubSuccess & \define & \oobDataCol{4}_{i} & \quad \prediction \\ + \locRamSuccess & \define & \oobDataCol{4}_{i} & \quad \prediction \\ + \locReturnGas & \define & \oobDataCol{5}_{i} & \quad \prediction \\ + \locExtractCallData & \define & \oobDataCol{6}_{i} & \quad \prediction \\ + \locEmptyCallData & \define & \oobDataCol{7}_{i} & \quad \prediction \\ + \locRacIsNonzero & \define & \oobDataCol{8}_{i} & \quad \prediction \\ + \end{array} \right. +\] +\saNote{} The shorthands +\locHubSuccess{} and +\locRamSuccess{} +refer to \textbf{the same underlying cell} but at one of these names makes sense in any given context within the \oobMod{} module processing of any one precompile related \oobMod{}-instruction. + +\saNote{} The decorator ``$\prediction$'' is used to label (\hubMod{} module) predictions. diff --git a/oob/shorthands.tex b/oob/shorthands.tex new file mode 100644 index 0000000..03852fb --- /dev/null +++ b/oob/shorthands.tex @@ -0,0 +1,253 @@ +We use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locInstFlagSum_{i} & \define & + \left[ \begin{array}{cl} + + & \oobInstIsJump _{i} \\ + + & \oobInstIsJumpI _{i} \\ + + & \oobInstIsRdc _{i} \\ + + & \oobInstIsCdl _{i} \\ + + & \oobInstIsCall _{i} \\ + + & \oobInstIsXcall _{i} \\ + + & \oobInstIsCreate _{i} \\ + + & \oobInstIsSstore _{i} \\ + + & \oobInstIsDeployment _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locPrcFlagSumCommon_{i} & \define & + \left[ \begin{array}{cl} + + & \oobInstIsEcrecover _{i} \\ + + & \oobInstIsShaTwo _{i} \\ + + & \oobInstIsRipemd _{i} \\ + + & \oobInstIsIdentity _{i} \\ + + & \oobInstIsEcadd _{i} \\ + + & \oobInstIsEcmul _{i} \\ + + & \oobInstIsEcpairing _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locPrcFlagSumBlake_{i} & \define & + \left[ \begin{array}{cl} + + & \oobInstIsBlakeCds _{i} \\ + + & \oobInstIsBlakeParams _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locPrcFlagSumModexp_{i} & \define & + \left[ \begin{array}{cl} + + & \oobInstIsModexpCds _{i} \\ + + & \oobInstIsModexpXbs _{i} \\ + + & \oobInstIsModexpLead _{i} \\ + + & \oobInstIsModexpPricing _{i} \\ + + & \oobInstIsModexpExtract _{i} \\ + \end{array} \right] + \end{array} \right. +\] +we also set +\[ + \left\{ \begin{array}{lcl} + \locPrcFlagSum_{i} & \define & + \left[ \begin{array}{cl} + + & \locPrcFlagSumCommon_{i} \\ + + & \locPrcFlagSumBlake_{i} \\ + + & \locPrcFlagSumModexp_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \flagSum_{i} & \define & + \left[ \begin{array}{cl} + + & \locInstFlagSum_{i} \\ + + & \locPrcFlagSum_{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \weightedFlagSumInst_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobInstJump & \cdot & \oobInstIsJump _{i} \\ + + & \oobInstJumpI & \cdot & \oobInstIsJumpI _{i} \\ + + & \oobInstRdc & \cdot & \oobInstIsRdc _{i} \\ + + & \oobInstCdl & \cdot & \oobInstIsCdl _{i} \\ + + & \oobInstXcall & \cdot & \oobInstIsXcall _{i} \\ + + & \oobInstCall & \cdot & \oobInstIsCall _{i} \\ + + & \oobInstCreate & \cdot & \oobInstIsCreate _{i} \\ + + & \oobInstSstore & \cdot & \oobInstIsSstore _{i} \\ + + & \oobInstDeployment & \cdot & \oobInstIsDeployment _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedPrcFlagSumCommon_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobInstEcrecover & \cdot & \oobInstIsEcrecover_{i} \\ + + & \oobInstShaTwo & \cdot & \oobInstIsShaTwo_{i} \\ + + & \oobInstRipemd & \cdot & \oobInstIsRipemd_{i} \\ + + & \oobInstIdentity & \cdot & \oobInstIsIdentity_{i} \\ + + & \oobInstEcadd & \cdot & \oobInstIsEcadd_{i} \\ + + & \oobInstEcmul & \cdot & \oobInstIsEcmul_{i} \\ + + & \oobInstEcpairing & \cdot & \oobInstIsEcpairing_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedPrcFlagSumBlake_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobInstBlakeCds & \cdot & \oobInstIsBlakeCds _{i} \\ + + & \oobInstBlakeParams & \cdot & \oobInstIsBlakeParams _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedPrcFlagSumModexp_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobInstModexpCds & \cdot & \oobInstIsModexpCds _{i} \\ + + & \oobInstModexpXbs & \cdot & \oobInstIsModexpXbs _{i} \\ + + & \oobInstModexpLead & \cdot & \oobInstIsModexpLead _{i} \\ + + & \oobInstModexpPricing & \cdot & \oobInstIsModexpPricing _{i} \\ + + & \oobInstModexpExtract & \cdot & \oobInstIsModexpExtract _{i} \\ + \end{array} \right] + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \weightedPrcFlagSum_{i} & \define & + \left[ \begin{array}{cl} + + & \weightedPrcFlagSumCommon_{i} \\ + + & \weightedPrcFlagSumBlake_{i} \\ + + & \weightedPrcFlagSumModexp_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedFlagSum_{i} & \define & + \left[ \begin{array}{cl} + + & \weightedFlagSumInst_{i} \\ + + & \weightedPrcFlagSum_{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +where +\[ + \left\{ \begin{array}{lclcl} + \oobInstJump & \define & \texttt{0x\,56} \\ + \oobInstJumpI & \define & \texttt{0x\,57} \\ + \oobInstRdc & \define & \texttt{0x\,3E} \\ + \oobInstCdl & \define & \texttt{0x\,35} \\ + \oobInstXcall & \define & \oxXcall \\ + \oobInstCall & \define & \oxCall \\ + \oobInstCreate & \define & \oxCreate \\ + \oobInstSstore & \define & \texttt{0x\,55} \\ + \oobInstDeployment & \define & \texttt{0x\,F3} \\ + \end{array} \right. + , + \left\{ \begin{array}{lclcr} + \oobInstEcrecover & \define & \oxEcrecover \\ + \oobInstShaTwo & \define & \oxShaTwo \\ + \oobInstRipemd & \define & \oxRipemd \\ + \oobInstIdentity & \define & \oxIdentity \\ + \oobInstEcadd & \define & \oxEcadd \\ + \oobInstEcmul & \define & \oxEcmul \\ + \oobInstEcpairing & \define & \oxEcpairing \\ + \oobInstBlakeCds & \define & \oxBlakeCds \\ + \oobInstBlakeParams & \define & \oxBlakeParams \\ + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lclcr} + \oobInstModexpCds & \define & \oxModexpCds \\ + \oobInstModexpXbs & \define & \oxModexpXbs \\ + \oobInstModexpLead & \define & \oxModexpLead \\ + \oobInstModexpPricing & \define & \oxModexpPricing \\ + \oobInstModexpExtract & \define & \oxModexpExtract \\ + \end{array} \right. +\] +\saNote{} In the above we use the notation $\oxXcall$, $\oxCall$, $\oxCreate$, $\oxEcrecover$, \dots, $\oxBlakeParams$ as \textbf{placeholders} for some actual, fixed values. +The only requirement for these constants must satisfy is that all constants defined above be \textbf{nonzero} and \textbf{pairwise distinct}. + +We further set +\[ + \left\{ \begin{array}{lcl} + \maxCtFlagSumInst_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobCtMaxJump & \cdot & \oobInstIsJump _{i} \\ + + & \oobCtMaxJumpI & \cdot & \oobInstIsJumpI _{i} \\ + + & \oobCtMaxRdc & \cdot & \oobInstIsRdc _{i} \\ + + & \oobCtMaxCdl & \cdot & \oobInstIsCdl _{i} \\ + + & \oobCtMaxXcall & \cdot & \oobInstIsXcall _{i} \\ + + & \oobCtMaxCall & \cdot & \oobInstIsCall _{i} \\ + + & \oobCtMaxCreate & \cdot & \oobInstIsCreate _{i} \\ + + & \oobCtMaxSstore & \cdot & \oobInstIsSstore _{i} \\ + + & \oobCtMaxDeployment & \cdot & \oobInstIsDeployment _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \maxCtFlagSumPrcCommon_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobCtMaxEcrecover & \cdot & \oobInstIsEcrecover _{i} \\ + + & \oobCtMaxShaTwo & \cdot & \oobInstIsShaTwo _{i} \\ + + & \oobCtMaxRipemd & \cdot & \oobInstIsRipemd _{i} \\ + + & \oobCtMaxIdentity & \cdot & \oobInstIsIdentity _{i} \\ + + & \oobCtMaxEcadd & \cdot & \oobInstIsEcadd _{i} \\ + + & \oobCtMaxEcmul & \cdot & \oobInstIsEcmul _{i} \\ + + & \oobCtMaxEcpairing & \cdot & \oobInstIsEcpairing _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \maxCtFlagSumPrcBlake_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobCtMaxBlakeCds & \cdot & \oobInstIsBlakeCds _{i} \\ + + & \oobCtMaxBlakeParams & \cdot & \oobInstIsBlakeParams _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \maxCtFlagSumPrcModexp_{i} & \define & + \left[ \begin{array}{crcl} + + & \oobCtMaxModexpCds & \cdot & \oobInstIsModexpCds _{i} \\ + + & \oobCtMaxModexpXbs & \cdot & \oobInstIsModexpXbs _{i} \\ + + & \oobCtMaxModexpLead & \cdot & \oobInstIsModexpLead _{i} \\ + + & \oobCtMaxModexpPricing & \cdot & \oobInstIsModexpPricing _{i} \\ + + & \oobCtMaxModexpExtract & \cdot & \oobInstIsModexpExtract _{i} \\ + \end{array} \right] + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \maxCtFlagSumPrc_{i} & \define & + \left[ \begin{array}{cl} + + & \maxCtFlagSumPrcCommon_{i} \\ + + & \maxCtFlagSumPrcBlake_{i} \\ + + & \maxCtFlagSumPrcModexp_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \maxCtFlagSum_{i} & \define & + \left[ \begin{array}{cl} + + & \weightedFlagSumInst_{i} \\ + + & \weightedPrcFlagSum_{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +where +\[ +\begin{array}{ll} + \left\{ \begin{array}{lcl} + \oobCtMaxJump & \define & 0 \\ + \oobCtMaxJumpI & \define & 1 \\ + \oobCtMaxRdc & \define & 2 \\ + \oobCtMaxCdl & \define & 0 \\ + \oobCtMaxXcall & \define & 0 \\ + \oobCtMaxCall & \define & 2 \\ + \oobCtMaxCreate & \define & 2 \\ + \oobCtMaxSstore & \define & 0 \\ + \oobCtMaxDeployment & \define & 0 \\ + \end{array} \right. + & + \left\{ \begin{array}{lcl} + \oobCtMaxEcrecover & \define & 2 \\ + \oobCtMaxShaTwo & \define & 3 \\ + \oobCtMaxRipemd & \define & 3 \\ + \oobCtMaxIdentity & \define & 3 \\ + \oobCtMaxEcadd & \define & 2 \\ + \oobCtMaxEcmul & \define & 2 \\ + \oobCtMaxEcpairing & \define & 4 \\ + \end{array} \right. \\ + \left\{ \begin{array}{lcl} + \oobCtMaxBlakeCds & \define & 1 \\ + \oobCtMaxBlakeParams & \define & 1 \\ + \end{array} \right. + & + \left\{ \begin{array}{lcl} + \oobCtMaxModexpCds & \define & 2 \\ + \oobCtMaxModexpXbs & \define & 2 \\ + \oobCtMaxModexpLead & \define & 3 \\ + \oobCtMaxModexpPricing & \define & 5 \\ + \oobCtMaxModexpExtract & \define & 3 \\ + \end{array} \right. +\end{array} +\] + +We consider the following shorthands: +\[ + \left\{ \begin{array}{lcrcrcr} + \locLookupSum _{i} & \define & \addFlag_{i} & + & \modFlag_{i} & + & \wcpFlag_{i} \\ + \locWeightedLookupSum _{i} & \define & \locAdd \cdot \addFlag_{i} & + & \locMod \cdot \modFlag_{i} & + & \locWcp \cdot \wcpFlag_{i} \\ + \end{array} \right. +\] diff --git a/oob/specialized.tex b/oob/specialized.tex new file mode 100644 index 0000000..d760d81 --- /dev/null +++ b/oob/specialized.tex @@ -0,0 +1,100 @@ +We define a series of simple parametrized constraint systems for instructions that are sent to the \addMod{} module, the \modMod{} module and the \wcpMod{} module. +Let $\relof$ be a small nonnegative integer. +\[ + \left\{ \begin{array}{lcl} + \oobCallToAdd + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + {\locArgTwoHi}{\locArgTwoLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locAdd \\ + \outgoingInst _{i + \relof} & = & \inst{ADD} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & \locArgTwoHi \\ + \outgoingData {4} _{i + \relof} & = & \locArgTwoLo \\ + \end{array} \right. \vspace{2mm} \\ + \oobCallToDiv + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + {\locArgTwoHi}{\locArgTwoLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locMod \\ + \outgoingInst _{i + \relof} & = & \inst{DIV} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & \locArgTwoHi \\ + \outgoingData {4} _{i + \relof} & = & \locArgTwoLo \\ + \end{array} \right. \vspace{2mm} \\ + \oobCallToMod + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + {\locArgTwoHi}{\locArgTwoLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locMod \\ + \outgoingInst _{i + \relof} & = & \inst{MOD} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & \locArgTwoHi \\ + \outgoingData {4} _{i + \relof} & = & \locArgTwoLo \\ + \end{array} \right. \vspace{2mm} \\ + \oobCallToLt + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + {\locArgTwoHi}{\locArgTwoLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locWcp \\ + \outgoingInst _{i + \relof} & = & \inst{LT} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & \locArgTwoHi \\ + \outgoingData {4} _{i + \relof} & = & \locArgTwoLo \\ + \end{array} \right. \vspace{2mm} \\ + \oobCallToGt + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + {\locArgTwoHi}{\locArgTwoLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locWcp \\ + \outgoingInst _{i + \relof} & = & \inst{GT} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & \locArgTwoHi \\ + \outgoingData {4} _{i + \relof} & = & \locArgTwoLo \\ + \end{array} \right. \vspace{2mm} \\ + \oobCallToIszero + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locWcp \\ + \outgoingInst _{i + \relof} & = & \inst{ISZERO} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & 0 \quad (\trash) \\ + \outgoingData {4} _{i + \relof} & = & 0 \quad (\trash) \\ + \end{array} \right. \vspace{2mm} \\ + \oobCallToEq + {i}{\relof} + {\locArgOneHi}{\locArgOneLo} + {\locArgTwoHi}{\locArgTwoLo} + & \iff & + \left\{ \begin{array}{lcl} + \locWeightedLookupSum _{i + \relof} & = & \locWcp \\ + \outgoingInst _{i + \relof} & = & \inst{EQ} \\ + \outgoingData {1} _{i + \relof} & = & \locArgOneHi \\ + \outgoingData {2} _{i + \relof} & = & \locArgOneLo \\ + \outgoingData {3} _{i + \relof} & = & \locArgTwoHi \\ + \outgoingData {4} _{i + \relof} & = & \locArgTwoLo \\ + \end{array} \right. \vspace{2mm} \\ + \oobNoCall + {i}{\relof} + & \iff & + \locLookupSum _{i + \relof} = 0 \\ + \end{array} \right. +\] diff --git a/pkg/IEEEtrantools.sty b/pkg/IEEEtrantools.sty new file mode 100644 index 0000000..e4a808c --- /dev/null +++ b/pkg/IEEEtrantools.sty @@ -0,0 +1,2799 @@ +%% +%% IEEEtrantools.sty 2015/08/26 version V1.5 +%% +%% +%% This package provides several popular and unique commands from the +%% IEEEtran.cls class (version 1.8b) file. +%% +%% The provided commands include \IEEEPARstart, \IEEEitemize, \IEEEenumerate, +%% \IEEEdescription as well as the \IEEEeqnarray, \IEEEeqnarraybox family +%% of commands including support commands such as \IEEEstrut, the IEEEproof +%% environment and its support commands and the \IEEEauthorrefmark command. +%% Also provides the \bstctlcite command for the control entry types of +%% IEEEtran.bst V1.00 and later, as well as \IEEEnoauxwrite. +%% +%% IEEEtrantools.sty should not be used with IEEEtran.cls. +%% +%% Support sites: +%% http://www.michaelshell.org/tex/ieeetran/ +%% http://www.ctan.org/pkg/ieeetran +%% +%% +%% Copyright (c) 2002-2015 by Michael Shell +%% See: http://www.michaelshell.org/ +%% for current contact information. +%% +%%************************************************************************* +%% Legal Notice: +%% This code is offered as-is without any warranty either expressed or +%% implied; without even the implied warranty of MERCHANTABILITY or +%% FITNESS FOR A PARTICULAR PURPOSE! +%% User assumes all risk. +%% In no event shall the IEEE or any contributor to this code be liable for +%% any damages or losses, including, but not limited to, incidental, +%% consequential, or any other damages, resulting from the use or misuse +%% of any information contained here. +%% +%% All comments are the opinions of their respective authors and are not +%% necessarily endorsed by the IEEE. +%% +%% This work is distributed under the LaTeX Project Public License (LPPL) +%% ( http://www.latex-project.org/ ) version 1.3, and may be freely used, +%% distributed and modified. A copy of the LPPL, version 1.3, is included +%% in the base LaTeX documentation of all distributions of LaTeX released +%% 2003/12/01 or later. +%% Retain all contribution notices and credits. +%% ** Modified files should be clearly indicated as such, including ** +%% ** renaming them and changing author support contact information. ** +%% +%% File list of work: IEEEtrantools.sty, IEEEtrantools_doc.txt +%%************************************************************************* +%% +%% +%% +%% Available package options (e.g., \usepackage[redeflists]{IEEEtrantools} +%% +%% redeflists +%% Causes IEEEtrantools to redefine the standard itemize, enumerate and +%% description (IED) list environments to their IEEE versions. +%% IEEEitemize, IEEEenumerate and IEEEdescription remain available in any +%% case. This option may not be compatible with packages that alter the +%% standard IED list environments. +%% +%% +%%********************************************************************** + + +\ProvidesPackage{IEEEtrantools}[2015/08/26 V1.5 by Michael Shell] +\typeout{-- See the "IEEEtrantools_doc.txt" manual for usage information.} +\typeout{-- http://www.michaelshell.org/tex/ieeetran/tools/} +\NeedsTeXFormat{LaTeX2e} + + +% If \@IEEEeqnarray is detected, error. +{\@ifundefined{@IEEEeqnarray}{\relax}{% +\PackageError{IEEEtrantools}{The IEEEtrantools package is not for use\MessageBreak + with classes that already provide it}% + {Do not load IEEEtrantools - you don't need it.}% +}} + + +% hook to allow easy changeover to IEEEtran.cls/tools.sty error reporting +\def\@IEEEclspkgerror{\PackageError{IEEEtrantools}} + + +% define needed flags to indicate document options +\newif\if@IEEETOOLSredeflists +\global\@IEEETOOLSredeflistsfalse + + +% IEEEtran class scratch pad registers +% dimen +\newdimen\@IEEEtrantmpdimenA +\newdimen\@IEEEtrantmpdimenB +\newdimen\@IEEEtrantmpdimenC +% count +\newcount\@IEEEtrantmpcountA +\newcount\@IEEEtrantmpcountB +\newcount\@IEEEtrantmpcountC +% token list +\newtoks\@IEEEtrantmptoksA + + +% declare the options +\DeclareOption{redeflists}{\@IEEETOOLSredefliststrue} +% provide legacy support for retainorgcmds which does nothing now. +\DeclareOption{retainorgcmds}{\@IEEETOOLSredeflistsfalse} + +% get and process any supplied options +\ProcessOptions + + +% store the nominal value of jot +\newdimen\IEEEnormaljot +\IEEEnormaljot\jot\relax +% V1.4 allow for other packages that later change \jot +\AtBeginDocument{\IEEEnormaljot\jot\relax} + + + + +%% -- Command Argument Scanning Support Functions -- + +% Sets the category codes for punctuation to their normal values. +% For local use with argument scanning. +\def\IEEEnormalcatcodespunct{\catcode`\!=12 \catcode`\,=12 \catcode`\:=12 +\catcode`\;=12 \catcode`\`=12 \catcode`\'=12 \catcode`\"=12 \catcode`\.=12 +\catcode`\/=12 \catcode`\?=12 \catcode`\*=12 \catcode`\+=12 \catcode`\-=12 +\catcode`\<=12 \catcode`\>=12 \catcode`\(=12 \catcode`\)=12 \catcode`\[=12 +\catcode`\]=12 \catcode`\==12 \catcode`\|=12} +% Sets the category codes for numbers to their normal values. +% For local use with argument scanning. +\def\IEEEnormalcatcodesnum{\catcode`\0=12 \catcode`\1=12 \catcode`\2=12 +\catcode`\3=12 \catcode`\4=12 \catcode`\5=12 \catcode`\6=12 \catcode`\7=12 +\catcode`\8=12 \catcode`\9=12} +% combined action of \IEEEnormalcatcodespunct and \IEEEnormalcatcodesnum +\def\IEEEnormalcatcodes{\IEEEnormalcatcodespunct\IEEEnormalcatcodesnum} + + +% usage: \@IEEEstripouterbraces*{} +% \@IEEEstripouterbraces fully expands its argument (which it then stores +% in \@IEEEstripouterbracesarg) via \edef, then removes any outer enclosing +% braces, and finally stores the result in the macro +% \@IEEEstrippedouterbraces. +% +% For example: +% \@IEEEstripouterbraces{{{{ab}c}}} +% results in: +% +% \@IEEEstripouterbracesarg ==> a macro containing {{{ab}c}} +% \@IEEEstrippedouterbraces ==> a macro containing {ab}c +% +% the *-star form,\@IEEEstripouterbraces*, does not expand the argument +% contents during processing +\def\@IEEEstripouterbraces{\@ifstar{\let\@IEEEstripouterbracesdef=\def\@@IEEEstripouterbraces}{\let\@IEEEstripouterbracesdef=\edef\@@IEEEstripouterbraces}} + +\def\@@IEEEstripouterbraces#1{\@IEEEstripouterbracesdef\@IEEEstripouterbracesarg{#1}\relax +% If the macro is unchanged after being acquired as a single delimited +% argument, we know we have one sequence of tokens without any enclosing +% braces. Loop until this is true. +\loop + \expandafter\@@@IEEEstripouterbraces\@IEEEstripouterbracesarg\@IEEEgeneralsequenceDELIMITER +\ifx\@IEEEstrippedouterbraces\@IEEEstripouterbracesarg +\else + \let\@IEEEstripouterbracesarg\@IEEEstrippedouterbraces +\repeat} + +\def\@@@IEEEstripouterbraces#1\@IEEEgeneralsequenceDELIMITER{\def\@IEEEstrippedouterbraces{#1}} + + + +% usage: \@IEEEextractgroup*{} +% \@IEEEextractgroup fully expands its argument (which it then stores in +% \@IEEEextractgrouparg) via \edef and then assigns the first "brace group" +% of tokens to the macro \@IEEEextractedgroup. +% The remaining groups, if any, are stored in the macro +% \@IEEEextractedgroupremain. If the argument does not contain the requisite +% groups, the respective macros will be defined to be empty. +% There is an asymmetry in that \@IEEEextractedgroup is stripped of its first +% outer grouping while \@IEEEextractedgroupremain retains even the outer +% grouping (if present) that originally identified it as a group. +% +% For example: +% \@IEEEextractgroup{{{ab}}{c{de}}} +% results in: +% +% \@IEEEextractgrouparg ==> a macro containing {{ab}}{c{de}} +% \@IEEEextractedgroup ==> a macro containing {ab} +% \@IEEEextractedgroupremain ==> a macro containing {c{de}} +% +% The *-star form, \@IEEEextractgroup*, does not expand its argument +% contents during processing. +\def\@IEEEextractgroup{\@ifstar{\let\@IEEEextractgroupdef=\def\@@IEEEextractgroup}{\let\@IEEEextractgroupdef=\edef\@@IEEEextractgroup}} + +\def\@@IEEEextractgroup#1{\@IEEEextractgroupdef\@IEEEextractgrouparg{#1}\relax +% trap the case of an empty extracted group as this would cause problems with +% \@IEEEextractgroupremain's argument acquisition +\ifx\@IEEEextractgrouparg\@empty + \def\@IEEEextractedgroup{}\relax + \def\@IEEEextractedgroupremain{}\relax +\else + % We have to use some dirty tricks here. We want to insert {} around + % whatever remains after the first group so that TeX's argument scanner + % will preserve any originally enclosing braces as well as provide an + % empty argument to acquire even if there isn't a second group. + % In this first of two dirty tricks, we put a } at the end of the structure + % we are going to extract from. The \ifnum0=`{\fi keeps TeX happy to allow + % what would otherwise be an unbalanced macro definition for + % \@@IEEEextractgroup to be acceptable to it. + \ifnum0=`{\fi\expandafter\@IEEEextractgroupremain\@IEEEextractgrouparg}\relax +\fi} + +% In the second part of the dirty tricks, we insert a leading { right after +% the first group is acquired, but before the remainder is. Again, the +% \ifnum0=`}\fi keeps TeX happy during definition time, but will disappear +% during run time. +\def\@IEEEextractgroupremain#1{\def\@IEEEextractedgroup{#1}\expandafter\@@IEEEextractgroupremain\expandafter{\ifnum0=`}\fi} + +\def\@@IEEEextractgroupremain#1{\def\@IEEEextractedgroupremain{#1}} + + + +% usage: \@IEEEextracttoken*{} +% \@IEEEextracttoken fully expands its argument (which it then stores in +% \@IEEEextracttokenarg) via \edef and then the meaning of the first +% nonbrace (but including the empty group) token found is assigned via \let +% to \@IEEEextractedtoken as well as stored in the macro +% \@IEEEextractedtokenmacro. Tokens that would otherwise be discarded during +% the acquisition of the first are stored in \@IEEEextractedtokensdiscarded, +% however their original relative brace nesting depths are not guaranteed to +% be preserved. +% If the argument is empty, or if a first nonbrace token does not exist (or +% is an empty group), \@IEEEextractedtoken will be \relax and +% \@IEEEextractedtokenmacro and \@IEEEextractedtokensdiscarded will be empty. +% +% For example: +% \@IEEEextracttoken{{{ab}{cd}}{{ef}g}} +% results in: +% +% \@IEEEextracttokenarg ==> a macro containing {{ab}{cd}}{{ef}g} +% \@IEEEextractedtoken ==> the letter a +% \@IEEEextractedtokenmacro ==> a macro containing a +% \@IEEEextractedtokensdiscarded ==> a macro containing bcd{ef}g +% +% the *-star form, \@IEEEextracttoken*, does not expand its argument +% contents during processing. +\def\@IEEEextracttoken{\@ifstar{\let\@IEEEextracttokendef=\def\@@IEEEextracttoken}{\let\@IEEEextracttokendef=\edef\@@IEEEextracttoken}} + +\def\@@IEEEextracttoken#1{\@IEEEextracttokendef\@IEEEextracttokenarg{#1}\relax +\def\@IEEEextractedtokensdiscarded{}\relax % initialize to empty +% if the macro is unchanged after being acquired as a single undelimited argument +% with anything after it being stripped off as a delimited argument +% we know we have one token without any enclosing braces. loop until this is true. +\let\@IEEEextracttokencurgroup\@IEEEextracttokenarg +\loop + % trap case of an empty argument as this would cause a problem with + % \@@@IEEEextracttoken's first (nondelimited) argument acquisition + \ifx\@IEEEextracttokencurgroup\@empty + \def\@IEEEextractedtokenmacro{}\relax + \else + \expandafter\@@@IEEEextracttoken\@IEEEextracttokencurgroup\@IEEEgeneralsequenceDELIMITER\relax + \fi + \ifx\@IEEEextractedtokenmacro\@IEEEextracttokencurgroup + \else + \let\@IEEEextracttokencurgroup=\@IEEEextractedtokenmacro +\repeat +% we can safely do a \let= here because there should be at most one token +% the relax is needed to handle the case of no token found +\expandafter\let\expandafter\@IEEEextractedtoken\@IEEEextractedtokenmacro\relax} + +\def\@@@IEEEextracttoken#1#2\@IEEEgeneralsequenceDELIMITER{\def\@IEEEextractedtokenmacro{#1}\relax +\def\@@IEEEextractedtokensdiscarded{#2}\expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter +\@IEEEextractedtokensdiscarded\expandafter\expandafter\expandafter +{\expandafter\@@IEEEextractedtokensdiscarded\@IEEEextractedtokensdiscarded}} + + + +% usage: \@IEEEextracttokengroups*{} +% \@IEEEextracttokengroups fully expands its argument (which it then stores +% in \@IEEEextracttokengroupsarg) and then assigns the first "brace group" of +% tokens (with the outermost braces removed) to the macro +% \@IEEEextractedfirstgroup. +% The meaning of the first nonbrace (but including the empty group) token +% within this first group is assigned via \let to \@IEEEextractedfirsttoken +% as well as stored in the macro \@IEEEextractedfirsttokenmacro. If a first +% nonbrace token does not exist (or is an empty group), these will be \relax +% and empty, respectively. Tokens that would otherwise be discarded during +% the acquisition of the first token in the first group are stored in +% \@IEEEextractedfirsttokensdiscarded, however their original relative brace +% nesting depths are not guaranteed to be preserved. +% The first group within this first group is stored in the macro +% \@IEEEextractedfirstfirstgroup. +% Likewise for the next group after the first: \@IEEEextractednextgroup, +% \@IEEEextractednextfirstgroup, \@IEEEextractednextgroupfirsttoken, +% \@IEEEextractednextgroupfirsttokenmacro, and +% \@IEEEextractednextfirsttokensdiscarded. +% All tokens/groups after the first group, including any enclosing braces, +% are stored in the macro \@IEEEextractedafterfirstgroupremain which will +% be empty if none exist. +% +% For example: +% \@IEEEextracttokengroups{{{ab}{cd}}{{ef}g}} +% will result in: +% +% \@IEEEextracttokengroupsarg ==> a macro containing {{ab}{cd}}{{ef}g} +% \@IEEEextractedfirstgroup ==> a macro containing {ab}{cd} +% \@IEEEextractedafterfirstgroupremain ==> a macro containing {{ef}g} +% \@IEEEextractedfirsttoken ==> the letter a +% \@IEEEextractedfirsttokenmacro ==> a macro containing a +% \@IEEEextractedfirsttokensdiscarded ==> a macro containing bcd +% \@IEEEextractedfirstfirstgroup ==> a macro containing ab +% \@IEEEextractednextgroup ==> a macro containing {ef}g +% \@IEEEextractednextfirsttoken ==> the letter e +% \@IEEEextractednextfirsttokenmacro ==> a macro containing e +% \@IEEEextractednextfirsttokensdiscarded ==> a macro containing fg +% \@IEEEextractednextfirstgroup ==> a macro containing ef +% +% If given an empty argument, \@IEEEextractedfirsttoken and +% \@IEEEextractednextfirsttoken will be set to \relax +% and all the macros will be empty. +% the *-star form, \@IEEEextracttokengroups*, does not expand its argument +% contents during processing. +% +% Depends on: \@IEEEextractgroup, \@IEEEextracttoken +\def\@IEEEextracttokengroups{\@ifstar{\let\@IEEEextracttokengroupsdef=\def\@@IEEEextracttokengroups}{\let\@IEEEextracttokengroupsdef=\edef\@@IEEEextracttokengroups}} +\def\@@IEEEextracttokengroups#1{\@IEEEextracttokengroupsdef\@IEEEextracttokengroupsarg{#1}\relax +% begin extraction, these functions are safe with empty arguments +% first group +\expandafter\@IEEEextractgroup\expandafter*\expandafter{\@IEEEextracttokengroupsarg}\relax +\let\@IEEEextractedfirstgroup\@IEEEextractedgroup +\let\@IEEEextractedafterfirstgroupremain\@IEEEextractedgroupremain +\expandafter\@IEEEextracttoken\expandafter*\expandafter{\@IEEEextractedfirstgroup}\relax +\let\@IEEEextractedfirsttoken\@IEEEextractedtoken +\let\@IEEEextractedfirsttokenmacro\@IEEEextractedtokenmacro +\let\@IEEEextractedfirsttokensdiscarded\@IEEEextractedtokensdiscarded +% first first group +\expandafter\@IEEEextractgroup\expandafter*\expandafter{\@IEEEextractedfirstgroup}\relax +\let\@IEEEextractedfirstfirstgroup\@IEEEextractedgroup +% next group +\expandafter\@IEEEextractgroup\expandafter*\expandafter{\@IEEEextractedafterfirstgroupremain}\relax +\let\@IEEEextractednextgroup\@IEEEextractedgroup +\expandafter\@IEEEextracttoken\expandafter*\expandafter{\@IEEEextractednextgroup}\relax +\let\@IEEEextractednextfirsttoken\@IEEEextractedtoken +\let\@IEEEextractednextfirsttokenmacro\@IEEEextractedtokenmacro +\let\@IEEEextractednextfirsttokensdiscarded\@IEEEextractedtokensdiscarded +% next first group +\expandafter\@IEEEextractgroup\expandafter*\expandafter{\@IEEEextractednextgroup}\relax +\let\@IEEEextractednextfirstgroup\@IEEEextractedgroup} + + +%% +%% -- End of Command Argument Scanning Support Functions -- + + + + +% -- page setup commands -- + +% The default sample text for calculating margins +\def\IEEEdefaultsampletext{\normalfont\normalsize gT} +\def\IEEEdefaultheadersampletext{\normalfont\normalsize T} +\def\IEEEdefaultfootersampletext{\normalfont\normalsize gT} + + + +% usage: \IEEEsettextwidth{inner margin}{outer margin} +% Sets \textwidth to allow the specified inner and outer margins +% for the current \paperwidth. +\def\IEEEsettextwidth#1#2{\@IEEEtrantmpdimenA\paperwidth +\@IEEEtrantmpdimenB#1\relax +\advance\@IEEEtrantmpdimenA by -\@IEEEtrantmpdimenB +\@IEEEtrantmpdimenB#2\relax +\advance\@IEEEtrantmpdimenA by -\@IEEEtrantmpdimenB +\textwidth\@IEEEtrantmpdimenA} + + + +% usage: \IEEEsetsidemargin{mode: i, o, c, a}{margin/offset} +% Sets \oddsidemargin and \evensidemargin to yield the specified margin +% of the given mode. +% The available modes are: +% i = inner margin +% o = outer margin +% c = centered, with the given offset +% a = adjust the margins using the given offset +% For the offsets, positive values increase the inner margin. +% \textwidth should be set properly for the given margins before calling this +% function. +\def\IEEEsetsidemargin#1#2{\@IEEEtrantmpdimenA #2\relax +\@IEEEextracttoken{#1}\relax +% check for mode errors +\ifx\@IEEEextractedtokenmacro\@empty + \@IEEEclspkgerror{Empty mode type in \string\IEEEsetsidemargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `i'}{Valid modes for \string\IEEEsetsidemargin\space are: i, o, c and a.}\relax + \let\@IEEEextractedtoken=i\relax + \def\@IEEEextractedtokenmacro{i}\relax +\else + \ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: \string\IEEEsetsidemargin\space mode specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax + \fi +\fi +% handle each mode +\if\@IEEEextractedtoken a\relax + \advance\oddsidemargin by \@IEEEtrantmpdimenA\relax +\else +\if\@IEEEextractedtoken c\relax + \oddsidemargin\paperwidth + \advance\oddsidemargin by -\textwidth + \divide\oddsidemargin by 2\relax + \advance\oddsidemargin by -1in\relax + \advance\oddsidemargin by \@IEEEtrantmpdimenA\relax +\else +\if\@IEEEextractedtoken o\relax + \oddsidemargin\paperwidth + \advance\oddsidemargin by -\textwidth + \advance\oddsidemargin by -\@IEEEtrantmpdimenA + \advance\oddsidemargin by -1in\relax +\else + \if\@IEEEextractedtoken i\relax + \else + \@IEEEclspkgerror{Unknown mode type `\@IEEEextractedtokenmacro' in \string\IEEEsetsidemargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `i'}% + {Valid modes for \string\IEEEsetsidemargin\space are: i, o, c and a.}% + \fi + \oddsidemargin\@IEEEtrantmpdimenA + \advance\oddsidemargin by -1in\relax +\fi\fi\fi +% odd and even side margins both mean "inner" for single sided pages +\evensidemargin\oddsidemargin +% but are mirrors of each other when twosided is in effect +\if@twoside + \evensidemargin\paperwidth + \advance\evensidemargin by -\textwidth + \advance\evensidemargin by -\oddsidemargin + % have to compensate for both the builtin 1in LaTex offset + % and the fact we already subtracted this offset from \oddsidemargin + \advance\evensidemargin -2in\relax +\fi} + + + +% usage: \IEEEsettextheight[sample text]{top text margin}{bottom text margin} +% Sets \textheight based on the specified top margin and bottom margin. +% Takes into consideration \paperheight, \topskip, and (by default) the +% the actual height and depth of the \IEEEdefaultsampletext text. +\def\IEEEsettextheight{\@ifnextchar [{\@IEEEsettextheight}{\@IEEEsettextheight[\IEEEdefaultsampletext]}} +\def\@IEEEsettextheight[#1]#2#3{\textheight\paperheight\relax + \@IEEEtrantmpdimenA #2\relax + \advance \textheight by -\@IEEEtrantmpdimenA% subtract top margin + \@IEEEtrantmpdimenA #3\relax + \advance \textheight by -\@IEEEtrantmpdimenA% subtract bottom margin + \advance \textheight by \topskip% add \topskip + % subtract off everything above the top, and below the bottom, baselines + \settoheight{\@IEEEtrantmpdimenA}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance \textheight by -\@IEEEtrantmpdimenA + \settodepth{\@IEEEtrantmpdimenA}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance \textheight by -\@IEEEtrantmpdimenA} + + + +\newdimen\IEEEquantizedlength +\IEEEquantizedlength 0sp\relax +\newdimen\IEEEquantizedlengthdiff +\IEEEquantizedlengthdiff 0sp\relax +\def\IEEEquantizedlengthint{0} + +% usage: \IEEEquantizelength{mode: d, c, i}{base unit}{length} +% Sets the length \IEEEquantizedlength to be an integer multiple of the given +% (nonzero) base unit such that \IEEEquantizedlength approximates the given +% length. +% \IEEEquantizedlengthdiff is a length equal to the difference between the +% \IEEEquantizedlength and the given length. +% \IEEEquantizedlengthint is a macro containing the integer number of base units +% in \IEEEquantizedlength. +% i.e., \IEEEquantizedlength = \IEEEquantizedlengthint * base unit +% The mode determines how \IEEEquantizedlength is quantized: +% d = always decrease (always round down \IEEEquantizeint) +% c = use the closest match +% i = always increase (always round up \IEEEquantizeint) +% In anycase, if the given length is already quantized, +% \IEEEquantizedlengthdiff will be set to zero. +\def\IEEEquantizelength#1#2#3{\begingroup +% work in isolation so as not to externally disturb the \@IEEEtrantmp +% variables +% load the argument values indirectly via \IEEEquantizedlengthdiff +% in case the user refers to our \@IEEEtrantmpdimenX, \IEEEquantizedlength, +% etc. in the arguments. we also will work with these as counters, +% i.e., in sp units +% A has the base unit +\IEEEquantizedlengthdiff #2\relax\relax\relax\relax +\@IEEEtrantmpcountA\IEEEquantizedlengthdiff +% B has the input length +\IEEEquantizedlengthdiff #3\relax\relax\relax\relax +\@IEEEtrantmpcountB\IEEEquantizedlengthdiff +\@IEEEtrantmpdimenA\the\@IEEEtrantmpcountA sp\relax +\@IEEEtrantmpdimenB\the\@IEEEtrantmpcountB sp\relax +% \@IEEEtrantmpcountC will have the quantized int +% \IEEEquantizedlength will have the quantized length +% \@IEEEtrantmpdimenC will have the quantized diff +% initialize them to zero as this is what will be +% exported if an error occurs +\@IEEEtrantmpcountC 0\relax +\IEEEquantizedlength 0sp\relax +\@IEEEtrantmpdimenC 0sp\relax +% extract mode +\@IEEEextracttoken{#1}\relax +% check for mode errors +\ifx\@IEEEextractedtokenmacro\@empty + \@IEEEclspkgerror{Empty mode type in \string\IEEEquantizelength\space (line \the\inputlineno).\MessageBreak + Defaulting to `d'}{Valid modes for \string\IEEEquantizelength\space are: d, c and i.}\relax + \let\@IEEEextractedtoken=d\relax + \def\@IEEEextractedtokenmacro{d}\relax +\else + \ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: \string\IEEEquantizelength\space mode specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax + \fi +\fi +% check for base unit is zero error +\ifnum\@IEEEtrantmpcountA=0\relax +\@IEEEclspkgerror{Base unit is zero in \string\IEEEquantizelength\space (line \the\inputlineno).\MessageBreak + \string\IEEEquantizedlength\space and \string\IEEEquantizedlengthdiff\space are set to zero}{Division by zero is not allowed.}\relax +\else% base unit is nonzero + % \@IEEEtrantmpcountC carries the number of integer units + % in the quantized length (integer length \ base) + \@IEEEtrantmpcountC\@IEEEtrantmpcountB\relax + \divide\@IEEEtrantmpcountC by \@IEEEtrantmpcountA\relax + % \IEEEquantizedlength has the (rounded down) quantized length + % = base * int + \IEEEquantizedlength\@IEEEtrantmpdimenA\relax + \multiply\IEEEquantizedlength by \@IEEEtrantmpcountC\relax + % \@IEEEtrantmpdimenC has the difference + % = quantized length - length + \@IEEEtrantmpdimenC\IEEEquantizedlength\relax + \advance\@IEEEtrantmpdimenC by -\@IEEEtrantmpdimenB\relax + % trap special case of length being already quantized + % to avoid a roundup under i option + \ifdim\@IEEEtrantmpdimenC=0sp\relax + \else % length not is already quantized + % set dimenA to carry the upper quantized (absolute value) difference: + % quantizedlength + base - length + \advance\@IEEEtrantmpdimenA by \IEEEquantizedlength\relax + \advance\@IEEEtrantmpdimenA by -\@IEEEtrantmpdimenB\relax + % set dimenB to carry the lower quantized (absolute value) difference: + % length - quantizedlength + \advance\@IEEEtrantmpdimenB by -\IEEEquantizedlength\relax + % handle each mode + \if\@IEEEextractedtoken c\relax + % compare upper and lower amounts, select upper if lower > upper + \ifdim\@IEEEtrantmpdimenB>\@IEEEtrantmpdimenA\relax + % use upper + \advance\IEEEquantizedlength by \the\@IEEEtrantmpcountA sp\relax + \advance\@IEEEtrantmpcountC by 1\relax + \@IEEEtrantmpdimenC\@IEEEtrantmpdimenA + \else% <=. uselower + % no need to do anything for lower, use output values already setup + \fi + \else% not mode c + \if\@IEEEextractedtoken i\relax + % always round up under i mode + \advance\IEEEquantizedlength by \the\@IEEEtrantmpcountA sp\relax + \advance\@IEEEtrantmpcountC by 1\relax + \@IEEEtrantmpdimenC\@IEEEtrantmpdimenA + \else + \if\@IEEEextractedtoken d\relax + \else + \@IEEEclspkgerror{Unknown mode type `\@IEEEextractedtokenmacro' in \string\IEEEquantizelength\space (line \the\inputlineno).\MessageBreak + Defaulting to `d'}% + {Valid modes for \string\IEEEquantizelength\space are: d, c, and i.}\relax + \fi % if d + % no need to do anything for d, use output values already setup + \fi\fi % if i, c + \fi % if length is already quantized +\fi% if base unit is zero +% globally assign the results to macros we use here to escape the enclosing +% group without needing to call \global on any of the \@IEEEtrantmp variables. +% \@IEEEtrantmpcountC has the quantized int +% \IEEEquantizedlength has the quantized length +% \@IEEEtrantmpdimenC has the quantized diff +\xdef\@IEEEquantizedlengthintmacro{\the\@IEEEtrantmpcountC}\relax +\@IEEEtrantmpcountC\IEEEquantizedlength\relax +\xdef\@IEEEquantizedlengthmacro{\the\@IEEEtrantmpcountC}\relax +\@IEEEtrantmpcountC\@IEEEtrantmpdimenC\relax +\xdef\@IEEEquantizedlengthdiffmacro{\the\@IEEEtrantmpcountC}\relax +\endgroup +% locally assign the outputs here from the macros +\expandafter\IEEEquantizedlength\@IEEEquantizedlengthmacro sp\relax +\expandafter\IEEEquantizedlengthdiff\@IEEEquantizedlengthdiffmacro sp\relax +\edef\IEEEquantizedlengthint{\@IEEEquantizedlengthintmacro}\relax} + + + +\newdimen\IEEEquantizedtextheightdiff +\IEEEquantizedtextheightdiff 0sp\relax + +% usage: \IEEEquantizetextheight[base unit]{mode: d, c, i} +% Sets \textheight to be an integer multiple of the current \baselineskip +% (or the optionally specified base unit) plus the first (\topskip) line. +% \IEEEquantizedtextheightdiff is a length equal to the difference between +% the new quantized and original \textheight. +% \IEEEquantizedtextheightlpc is a macro containing the integer number of +% lines per column under the quantized \textheight. i.e., +% \textheight = \IEEEquantizedtextheightlpc * \baselineskip + \topskip +% The mode determines how \textheight is quantized: +% d = always decrease (always round down the number of lines per column) +% c = use the closest match +% i = always increase (always round up the number of lines per column) +% In anycase, if \textheight is already quantized, it will remain unchanged, +% and \IEEEquantizedtextheightdiff will be set to zero. +% Depends on: \IEEEquantizelength +\def\IEEEquantizetextheight{\@ifnextchar [{\@IEEEquantizetextheight}{\@IEEEquantizetextheight[\baselineskip]}} +\def\@IEEEquantizetextheight[#1]#2{\begingroup +% use our \IEEEquantizedtextheightdiff as a scratch pad +% we need to subtract off \topskip before quantization +\IEEEquantizedtextheightdiff\textheight +\advance\IEEEquantizedtextheightdiff by -\topskip\relax +\IEEEquantizelength{#2}{#1}{\IEEEquantizedtextheightdiff} +% add back \topskip line +\advance\IEEEquantizedlength by \topskip +\@IEEEtrantmpcountC\IEEEquantizedlengthint\relax +\advance\@IEEEtrantmpcountC by 1\relax +% globally assign the results to macros we use here to escape the enclosing +% group without needing to call \global on any of the \@IEEEtrantmp variables. +\xdef\@IEEEquantizedtextheightlpcmacro{\the\@IEEEtrantmpcountC}\relax +\@IEEEtrantmpcountC\IEEEquantizedlength\relax +\xdef\@IEEEquantizedtextheightmacro{\the\@IEEEtrantmpcountC}\relax +\@IEEEtrantmpcountC\IEEEquantizedlengthdiff\relax +\xdef\@IEEEquantizedtextheightdiffmacro{\the\@IEEEtrantmpcountC}\relax +\endgroup +% locally assign the outputs here from the macros +\textheight\@IEEEquantizedtextheightmacro sp\relax +\IEEEquantizedtextheightdiff\@IEEEquantizedtextheightdiffmacro sp\relax +\edef\IEEEquantizedtextheightlpc{\@IEEEquantizedtextheightlpcmacro}} + + + +% usage: \IEEEsettopmargin[sample text]{mode: t, b, c, a, q}{margin/offset} +% Sets \topmargin based on the specified vertical margin. +% Takes into consideration the base 1in offset, \headheight, \headsep, +% \topskip, and (by default) the the actual height (or, for the bottom, depth) +% of the \IEEEdefaultsampletext text. +% The available modes are: +% t = top margin +% b = bottom margin +% c = vertically centered, with the given offset +% a = adjust the vertical margins using the given offset +% q = adjust the margins using \IEEEquantizedtextheightdiff and the given offset +% For the offsets, positive values increase the top margin. +% \headheight, \headsep, \topskip and \textheight should be set properly for the +% given margins before calling this function. +\def\IEEEsettopmargin{\@ifnextchar [{\@IEEEsettopmargin}{\@IEEEsettopmargin[\IEEEdefaultsampletext]}} +\def\@IEEEsettopmargin[#1]#2#3{\@IEEEtrantmpdimenA #3\relax +\@IEEEextracttoken{#2}\relax +% check for mode errors +\ifx\@IEEEextractedtokenmacro\@empty + \@IEEEclspkgerror{Empty mode type in \string\IEEEsettopmargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `t'}{Valid modes for \string\IEEEsettopmargin\space are: t, b, c, a and q.}\relax + \let\@IEEEextractedtoken=t\relax + \def\@IEEEextractedtokenmacro{t}\relax +\else + \ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: \string\IEEEsettopmargin\space mode specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax + \fi +\fi +% handle each mode +\if\@IEEEextractedtoken a\relax + \advance\topmargin by \@IEEEtrantmpdimenA\relax +\else +\if\@IEEEextractedtoken q\relax + % we need to adjust by half the \IEEEquantizedtextheightdiff value + \@IEEEtrantmpdimenB\IEEEquantizedtextheightdiff\relax + \divide\@IEEEtrantmpdimenB by 2\relax + % a positive \IEEEquantizedtextheightdiff means we need to reduce \topmargin + % because \textheight has been lenghtened + \advance\topmargin by -\@IEEEtrantmpdimenB\relax + \advance\topmargin by \@IEEEtrantmpdimenA\relax +\else +\if\@IEEEextractedtoken c\relax + \topmargin\paperheight + \advance\topmargin by -\textheight + % \textheight includes \topskip, but we should not count topskip whitespace here, backout + \advance \topmargin by \topskip + \settoheight{\@IEEEtrantmpdimenB}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\topmargin by -\@IEEEtrantmpdimenB\relax + \settodepth{\@IEEEtrantmpdimenB}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\topmargin by -\@IEEEtrantmpdimenB\relax + \divide\topmargin by 2\relax + \advance\topmargin by \@IEEEtrantmpdimenA\relax +\else +\if\@IEEEextractedtoken b\relax + \topmargin\paperheight + \advance\topmargin by -\textheight + % \textheight includes \topskip, but we should not count topskip whitespace here, backout + \advance \topmargin by \topskip + \settodepth{\@IEEEtrantmpdimenB}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\topmargin by -\@IEEEtrantmpdimenB\relax + \advance\topmargin by -\@IEEEtrantmpdimenA\relax +\else + \if\@IEEEextractedtoken t\relax + \else + \@IEEEclspkgerror{Unknown mode type `\@IEEEextractedtokenmacro' in \string\IEEEsettopmargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `t'}% + {Valid modes for \string\IEEEsettopmargin\space are: t, b, c, a and q.}\relax + \fi + \topmargin\@IEEEtrantmpdimenA\relax + \settoheight{\@IEEEtrantmpdimenB}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\topmargin by \@IEEEtrantmpdimenB\relax +\fi\fi % if t, b, c +% convert desired top margin into actual \topmargin +% this is not done for the q or a modes because they are only adjustments +\advance \topmargin by -\topskip +\advance \topmargin by -1in +\advance \topmargin by -\headheight +\advance \topmargin by -\headsep +\fi\fi % if q, a +} + + + +% usage: \IEEEsetheadermargin[header sample][text sample]{mode: t, b, c, a}{margin/offset} +% Differentially adjusts \topmargin and \headsep (such that their sum is unchanged) +% based on the specified header margin. +% Takes into consideration the base 1in offset, \headheight, \topskip, and (by default) +% the actual height (or depth) of the \IEEEdefaultheadersampletext and +% \IEEEdefaultsampletext text. +% The available modes are: +% t = top margin (top of the header text to the top of the page) +% b = bottom margin (bottom of the header text to the top of the main text) +% c = vertically centered between the main text and the top of the page, +% with the given offset +% a = adjust the vertical position using the given offset +% For the offsets, positive values move the header downward. +% \headheight, \headsep, \topskip and \topmargin should be set properly before +% calling this function. +\def\IEEEsetheadermargin{\@ifnextchar [{\@IEEEsetheadermargin}{\@IEEEsetheadermargin[\IEEEdefaultheadersampletext]}} +\def\@IEEEsetheadermargin[#1]{\@ifnextchar [{\@@IEEEsetheadermargin[#1]}{\@@IEEEsetheadermargin[#1][\IEEEdefaultsampletext]}} +\def\@@IEEEsetheadermargin[#1][#2]#3#4{\@IEEEtrantmpdimenA #4\relax +\@IEEEextracttoken{#3}\relax +% check for mode errors +\ifx\@IEEEextractedtokenmacro\@empty + \@IEEEclspkgerror{Empty mode type in \string\IEEEsetheadermargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `t'}{Valid modes for \string\IEEEsetheadermargin\space are: t, b, c, and a.}\relax + \let\@IEEEextractedtoken=t\relax + \def\@IEEEextractedtokenmacro{t}\relax +\else + \ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: \string\IEEEsetheadermargin\space mode specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax + \fi +\fi +% handle each mode +\if\@IEEEextractedtoken a\relax + % No need to do anything here and can pass through the adjustment + % value as is. The end adjustment of \topmargin and \headsep will + % do all that is needed +\else +\if\@IEEEextractedtoken c\relax + % get the bottom margin + \@IEEEtrantmpdimenB\headsep\relax + \settodepth{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + \advance\@IEEEtrantmpdimenB by \topskip + \settoheight{\@IEEEtrantmpdimenC}{\begingroup #2\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the actual header bottom margin + % subtract from it the top header margin + \advance\@IEEEtrantmpdimenB -1in\relax % take into consideration the system 1in offset of the top margin + \advance\@IEEEtrantmpdimenB by -\topmargin + \advance\@IEEEtrantmpdimenB by -\headheight + \settoheight{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by \@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the difference between the bottom and top margins + % we need to adjust by half this amount to center the header + \divide\@IEEEtrantmpdimenB by 2\relax + % and add to offset + \advance\@IEEEtrantmpdimenA by \@IEEEtrantmpdimenB +\else +\if\@IEEEextractedtoken b\relax + \@IEEEtrantmpdimenB\headsep\relax + \settodepth{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + \advance\@IEEEtrantmpdimenB by \topskip + \settoheight{\@IEEEtrantmpdimenC}{\begingroup #2\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the actual header bottom margin + % get the difference between the actual and the desired + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenA + \@IEEEtrantmpdimenA\@IEEEtrantmpdimenB +\else + \if\@IEEEextractedtoken t\relax + \else + \@IEEEclspkgerror{Unknown mode type `\@IEEEextractedtokenmacro' in \string\IEEEsetheadermargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `t'}% + {Valid modes for \string\IEEEsetheadermargin\space are: t, b, c and a.}\relax + \fi + \@IEEEtrantmpdimenB 1in\relax % take into consideration the system 1in offset of the top margin + \advance\@IEEEtrantmpdimenB by \topmargin + \advance\@IEEEtrantmpdimenB by \headheight + \settoheight{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the actual header top margin + % get the difference between the desired and the actual + \advance\@IEEEtrantmpdimenA by -\@IEEEtrantmpdimenB +\fi\fi % if t, b, c +\fi % if a +% advance \topmargin by the needed amount and reduce \headsep by the same +% so as not to disturb the location of the main text +\advance\topmargin by \@IEEEtrantmpdimenA\relax +\advance\headsep by -\@IEEEtrantmpdimenA\relax +} + + + +% usage: \IEEEsetfootermargin[footer sample][text sample]{mode: t, b, c, a}{margin/offset} +% Adjusts \footskip based on the specified footer margin. +% Takes into consideration the base 1in offset, \paperheight, \headheight, +% \headsep, \textheight and (by default) the actual height (or depth) of the +% \IEEEdefaultfootersampletext and \IEEEdefaultsampletext text. +% The available modes are: +% t = top margin (top of the footer text to the bottom of the main text) +% b = bottom margin (bottom of the footer text to the bottom of page) +% c = vertically centered between the main text and the bottom of the page, +% with the given offset +% a = adjust the vertical position using the given offset +% For the offsets, positive values move the footer downward. +% \headheight, \headsep, \topskip, \topmargin, and \textheight should be set +% properly before calling this function. +\def\IEEEsetfootermargin{\@ifnextchar [{\@IEEEsetfootermargin}{\@IEEEsetfootermargin[\IEEEdefaultfootersampletext]}} +\def\@IEEEsetfootermargin[#1]{\@ifnextchar [{\@@IEEEsetfootermargin[#1]}{\@@IEEEsetfootermargin[#1][\IEEEdefaultsampletext]}} +\def\@@IEEEsetfootermargin[#1][#2]#3#4{\@IEEEtrantmpdimenA #4\relax +\@IEEEextracttoken{#3}\relax +% check for mode errors +\ifx\@IEEEextractedtokenmacro\@empty + \@IEEEclspkgerror{Empty mode type in \string\IEEEsetfootermargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `t'}{Valid modes for \string\IEEEsetfootermargin\space are: t, b, c, and a.}\relax + \let\@IEEEextractedtoken=t\relax + \def\@IEEEextractedtokenmacro{t}\relax +\else + \ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: \string\IEEEsetfootermargin\space mode specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax + \fi +\fi +% handle each mode +\if\@IEEEextractedtoken a\relax + % No need to do anything here and can pass through the adjustment + % value as is. The end adjustment of \footskip will do all that + % is needed +\else +\if\@IEEEextractedtoken c\relax + % calculate the bottom margin + \@IEEEtrantmpdimenB 1in\relax % system 1in offset + \advance\@IEEEtrantmpdimenB\topmargin\relax + \advance\@IEEEtrantmpdimenB\headheight\relax + \advance\@IEEEtrantmpdimenB\headsep\relax + \advance\@IEEEtrantmpdimenB\textheight\relax + \advance\@IEEEtrantmpdimenB\footskip\relax + \settodepth{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenC by \@IEEEtrantmpdimenB + \@IEEEtrantmpdimenB\paperheight + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the actual footer bottom margin + % now subtract off the footer top margin + \advance\@IEEEtrantmpdimenB -\footskip\relax + \settodepth{\@IEEEtrantmpdimenC}{\begingroup #2\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by \@IEEEtrantmpdimenC + \settoheight{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by \@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the difference between the bottom + % and top footer margins + % our adjustment must be half this value to center the footer + \divide\@IEEEtrantmpdimenB by 2\relax + % add to the offset + \advance\@IEEEtrantmpdimenA by \@IEEEtrantmpdimenB +\else +\if\@IEEEextractedtoken b\relax + % calculate the bottom margin + \@IEEEtrantmpdimenB 1in\relax % system 1in offset + \advance\@IEEEtrantmpdimenB\topmargin\relax + \advance\@IEEEtrantmpdimenB\headheight\relax + \advance\@IEEEtrantmpdimenB\headsep\relax + \advance\@IEEEtrantmpdimenB\textheight\relax + \advance\@IEEEtrantmpdimenB\footskip\relax + \settodepth{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenC by \@IEEEtrantmpdimenB + \@IEEEtrantmpdimenB\paperheight + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the actual footer bottom margin + % get the difference between the actual and the desired + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenA + \@IEEEtrantmpdimenA\@IEEEtrantmpdimenB +\else + \if\@IEEEextractedtoken t\relax + \else + \@IEEEclspkgerror{Unknown mode type `\@IEEEextractedtokenmacro' in \string\IEEEsetfootermargin\space (line \the\inputlineno).\MessageBreak + Defaulting to `t'}% + {Valid modes for \string\IEEEsetfootermargin\space are: t, b, c and a.}\relax + \fi + \@IEEEtrantmpdimenB\footskip\relax + \settodepth{\@IEEEtrantmpdimenC}{\begingroup #2\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + \settoheight{\@IEEEtrantmpdimenC}{\begingroup #1\relax\relax\relax\endgroup}\relax + \advance\@IEEEtrantmpdimenB by -\@IEEEtrantmpdimenC + % at this point \@IEEEtrantmpdimenB has the actual footer top margin + % get the difference between the desired and the actual + \advance\@IEEEtrantmpdimenA by -\@IEEEtrantmpdimenB +\fi\fi % if t, b, c +\fi % if a +% advance \footskip by the needed amount +\advance\footskip by \@IEEEtrantmpdimenA\relax +} + + +% -- End page setup commands -- + + + + +% Itemize, Enumerate and Description (IED) List Controls +% *************************** +% +% +% The IEEE seems to use at least two different values by +% which ITEMIZED list labels are indented to the right +% For The Journal of Lightwave Technology (JLT) and The Journal +% on Selected Areas in Communications (JSAC), they tend to use +% an indention equal to \parindent. For Transactions on Communications +% they tend to indent ITEMIZED lists a little more--- 1.3\parindent. +% We'll provide both values here for you so that you can choose +% which one you like in your document using a command such as: +% setlength{\IEEEilabelindent}{\IEEEilabelindentB} +\newdimen\IEEEilabelindentA +\IEEEilabelindentA \parindent + +\newdimen\IEEEilabelindentB +\IEEEilabelindentB 1.3\parindent +% However, we'll default to using \parindent +% which makes more sense to me +\newdimen\IEEEilabelindent +\IEEEilabelindent \IEEEilabelindentA + + +% This controls the default amount the enumerated list labels +% are indented to the right. +% Normally, this is the same as the paragraph indention +\newdimen\IEEEelabelindent +\IEEEelabelindent \parindent + +% This controls the default amount the description list labels +% are indented to the right. +% Normally, this is the same as the paragraph indention +\newdimen\IEEEdlabelindent +\IEEEdlabelindent \parindent + +% This is the value actually used within the IED lists. +% The IED environments automatically set its value to +% one of the three values above, so global changes do +% not have any effect +\newdimen\IEEElabelindent +\IEEElabelindent \parindent + +% The actual amount labels will be indented is +% \IEEElabelindent multiplied by the factor below +% corresponding to the level of nesting depth +% This provides a means by which the user can +% alter the effective \IEEElabelindent for deeper +% levels +% There may not be such a thing as correct "standard IEEE" +% values. What the IEEE actually does may depend on the specific +% circumstances. +% The first list level almost always has full indention. +% The second levels I've seen have only 75% of the normal indentation +% Three level or greater nestings are very rare. I am guessing +% that they don't use any indentation. +\def\IEEElabelindentfactori{1.0} % almost always one +\def\IEEElabelindentfactorii{0.75} % 0.0 or 1.0 may be used in some cases +\def\IEEElabelindentfactoriii{0.0} % 0.75? 0.5? 0.0? +\def\IEEElabelindentfactoriv{0.0} +\def\IEEElabelindentfactorv{0.0} +\def\IEEElabelindentfactorvi{0.0} + +% value actually used within IED lists, it is auto +% set to one of the 6 values above +% global changes here have no effect +\def\IEEElabelindentfactor{1.0} + +% This controls the default spacing between the end of the IED +% list labels and the list text, when normal text is used for +% the labels. +\newdimen\IEEEiednormlabelsep +\IEEEiednormlabelsep 0.6em + +% This controls the default spacing between the end of the IED +% list labels and the list text, when math symbols are used for +% the labels (nomenclature lists). The IEEE usually increases the +% spacing in these cases +\newdimen\IEEEiedmathlabelsep +\IEEEiedmathlabelsep 1.2em + +% This controls the extra vertical separation put above and +% below each IED list. The IEEE usually puts a little extra spacing +% around each list. However, this spacing is barely noticeable. +\newskip\IEEEiedtopsep +\IEEEiedtopsep 2pt plus 1pt minus 1pt + + +% This command is executed within each IED list environment +% at the beginning of the list. You can use this to set the +% parameters for some/all your IED list(s) without disturbing +% global parameters that affect things other than lists. +% i.e., renewcommand{\IEEEiedlistdecl}{\setlength{\labelsep}{5em}} +% will alter the \labelsep for the next list(s) until +% \IEEEiedlistdecl is redefined. +\def\IEEEiedlistdecl{\relax} + +% This command provides an easy way to set \leftmargin based +% on the \labelwidth, \labelsep and the argument \IEEElabelindent +% Usage: \IEEEcalcleftmargin{width-to-indent-the-label} +% output is in the \leftmargin variable, i.e., effectively: +% \leftmargin = argument + \labelwidth + \labelsep +% Note controlled spacing here, shield end of lines with % +\def\IEEEcalcleftmargin#1{\setlength{\leftmargin}{#1}% +\addtolength{\leftmargin}{\labelwidth}% +\addtolength{\leftmargin}{\labelsep}} + +% This command provides an easy way to set \labelwidth to the +% width of the given text. It is the same as +% \settowidth{\labelwidth}{label-text} +% and useful as a shorter alternative. +% Typically used to set \labelwidth to be the width +% of the longest label in the list +\def\IEEEsetlabelwidth#1{\settowidth{\labelwidth}{#1}} + +% When this command is executed, IED lists will use the +% IEEEiedmathlabelsep label separation rather than the normal +% spacing. To have an effect, this command must be executed via +% the \IEEEiedlistdecl or within the option of the IED list +% environments. +\def\IEEEusemathlabelsep{\setlength{\labelsep}{\IEEEiedmathlabelsep}} + +% A flag which controls whether the IED lists automatically +% calculate \leftmargin from \IEEElabelindent, \labelwidth and \labelsep +% Useful if you want to specify your own \leftmargin +% This flag must be set (\IEEEnocalcleftmargintrue or \IEEEnocalcleftmarginfalse) +% via the \IEEEiedlistdecl or within the option of the IED list +% environments to have an effect. +\newif\ifIEEEnocalcleftmargin +\IEEEnocalcleftmarginfalse + +% A flag which controls whether \IEEElabelindent is multiplied by +% the \IEEElabelindentfactor for each list level. +% This flag must be set via the \IEEEiedlistdecl or within the option +% of the IED list environments to have an effect. +\newif\ifIEEEnolabelindentfactor +\IEEEnolabelindentfactorfalse + + +% internal variable to indicate type of IED label +% justification +% 0 - left; 1 - center; 2 - right +\def\@IEEEiedjustify{0} + + + +% commands to allow the user to control IED +% label justifications. Use these commands within +% the IED environment option or in the \IEEEiedlistdecl +% Note that changing the normal list justifications +% is nonstandard and the IEEE may not like it if you do so! +% I include these commands as they may be helpful to +% those who are using these enhanced list controls for +% other non-IEEE related LaTeX work. +% itemize and enumerate automatically default to right +% justification, description defaults to left. +\def\IEEEiedlabeljustifyl{\def\@IEEEiedjustify{0}}%left +\def\IEEEiedlabeljustifyc{\def\@IEEEiedjustify{1}}%center +\def\IEEEiedlabeljustifyr{\def\@IEEEiedjustify{2}}%right + + + + +% commands to save to and restore from the list parameter copies +% this allows us to set all the list parameters within +% the list_decl and prevent \list (and its \@list) +% from overriding any of our parameters +% V1.6 use \edefs instead of dimen's to conserve dimen registers +% Note controlled spacing here, shield end of lines with % +\def\@IEEEsavelistparams{\edef\@IEEEiedtopsep{\the\topsep}% +\edef\@IEEEiedlabelwidth{\the\labelwidth}% +\edef\@IEEEiedlabelsep{\the\labelsep}% +\edef\@IEEEiedleftmargin{\the\leftmargin}% +\edef\@IEEEiedpartopsep{\the\partopsep}% +\edef\@IEEEiedparsep{\the\parsep}% +\edef\@IEEEieditemsep{\the\itemsep}% +\edef\@IEEEiedrightmargin{\the\rightmargin}% +\edef\@IEEEiedlistparindent{\the\listparindent}% +\edef\@IEEEieditemindent{\the\itemindent}} + +% Note controlled spacing here +\def\@IEEErestorelistparams{\topsep\@IEEEiedtopsep\relax% +\labelwidth\@IEEEiedlabelwidth\relax% +\labelsep\@IEEEiedlabelsep\relax% +\leftmargin\@IEEEiedleftmargin\relax% +\partopsep\@IEEEiedpartopsep\relax% +\parsep\@IEEEiedparsep\relax% +\itemsep\@IEEEieditemsep\relax% +\rightmargin\@IEEEiedrightmargin\relax% +\listparindent\@IEEEiedlistparindent\relax% +\itemindent\@IEEEieditemindent\relax} + + +% v1.6b provide original LaTeX IED list environments +% note that latex.ltx defines \itemize and \enumerate, but not \description +% which must be created by the base classes +% save original LaTeX itemize and enumerate +\let\LaTeXitemize\itemize +\let\endLaTeXitemize\enditemize +\let\LaTeXenumerate\enumerate +\let\endLaTeXenumerate\endenumerate +% base class should define \description +\let\LaTeXdescription\description +\let\endLaTeXdescription\enddescription + + +% override LaTeX's default IED lists, if the user requested it +\if@IEEETOOLSredeflists +\def\itemize{\@IEEEitemize} +\def\enditemize{\@endIEEEitemize} +\def\enumerate{\@IEEEenumerate} +\def\endenumerate{\@endIEEEenumerate} +\def\description{\@IEEEdescription} +\def\enddescription{\@endIEEEdescription} +\fi + + +% provide the user with the IEEE IED commands +\def\IEEEitemize{\@IEEEitemize} +\def\endIEEEitemize{\@endIEEEitemize} +\def\IEEEenumerate{\@IEEEenumerate} +\def\endIEEEenumerate{\@endIEEEenumerate} +\def\IEEEdescription{\@IEEEdescription} +\def\endIEEEdescription{\@endIEEEdescription} + + +% V1.6 we want to keep the IEEEtran IED list definitions as our own internal +% commands so they are protected against redefinition +\def\@IEEEitemize{\@ifnextchar[{\@@IEEEitemize}{\@@IEEEitemize[\relax]}} +\def\@IEEEenumerate{\@ifnextchar[{\@@IEEEenumerate}{\@@IEEEenumerate[\relax]}} +\def\@IEEEdescription{\@ifnextchar[{\@@IEEEdescription}{\@@IEEEdescription[\relax]}} +\def\@endIEEEitemize{\endlist} +\def\@endIEEEenumerate{\endlist} +\def\@endIEEEdescription{\endlist} + + +% DO NOT ALLOW BLANK LINES TO BE IN THESE IED ENVIRONMENTS +% AS THIS WILL FORCE NEW PARAGRAPHS AFTER THE IED LISTS +% IEEEtran itemized list MDS 1/2001 +% Note controlled spacing here, shield end of lines with % +\def\@@IEEEitemize[#1]{% + \ifnum\@itemdepth>3\relax\@toodeep\else% + \ifnum\@listdepth>5\relax\@toodeep\else% + \advance\@itemdepth\@ne% + \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}% + % get the IEEElabelindentfactor for this level + \advance\@listdepth\@ne% we need to know what the level WILL be + \edef\IEEElabelindentfactor{\csname IEEElabelindentfactor\romannumeral\the\@listdepth\endcsname}% + \advance\@listdepth-\@ne% undo our increment + \def\@IEEEiedjustify{2}% right justified labels are default + % set other defaults + \IEEEnocalcleftmarginfalse% + \IEEEnolabelindentfactorfalse% + \topsep\IEEEiedtopsep% + \IEEElabelindent\IEEEilabelindent% + \labelsep\IEEEiednormlabelsep% + \partopsep 0ex% + \parsep 0ex% + \itemsep 0ex% + \rightmargin 0em% + \listparindent 0em% + \itemindent 0em% + % calculate the label width + % the user can override this later if + % they specified a \labelwidth + \settowidth{\labelwidth}{\csname labelitem\romannumeral\the\@itemdepth\endcsname}% + \@IEEEsavelistparams% save our list parameters + \list{\csname\@itemitem\endcsname}{% + \@IEEErestorelistparams% override any list{} changes + % to our globals + \let\makelabel\@IEEEiedmakelabel% v1.6b setup \makelabel + \IEEEiedlistdecl% let user alter parameters + #1\relax% + % If the user has requested not to use the + % IEEElabelindent factor, don't revise \IEEElabelindent + \ifIEEEnolabelindentfactor\relax% + \else\IEEElabelindent=\IEEElabelindentfactor\IEEElabelindent% + \fi% + % Unless the user has requested otherwise, + % calculate our left margin based + % on \IEEElabelindent, \labelwidth and + % \labelsep + \ifIEEEnocalcleftmargin\relax% + \else\IEEEcalcleftmargin{\IEEElabelindent}% + \fi}\fi\fi}% + + +% DO NOT ALLOW BLANK LINES TO BE IN THESE IED ENVIRONMENTS +% AS THIS WILL FORCE NEW PARAGRAPHS AFTER THE IED LISTS +% IEEEtran enumerate list MDS 1/2001 +% Note controlled spacing here, shield end of lines with % +\def\@@IEEEenumerate[#1]{% + \ifnum\@enumdepth>3\relax\@toodeep\else% + \ifnum\@listdepth>5\relax\@toodeep\else% + \advance\@enumdepth\@ne% + \edef\@enumctr{enum\romannumeral\the\@enumdepth}% + % get the IEEElabelindentfactor for this level + \advance\@listdepth\@ne% we need to know what the level WILL be + \edef\IEEElabelindentfactor{\csname IEEElabelindentfactor\romannumeral\the\@listdepth\endcsname}% + \advance\@listdepth-\@ne% undo our increment + \def\@IEEEiedjustify{2}% right justified labels are default + % set other defaults + \IEEEnocalcleftmarginfalse% + \IEEEnolabelindentfactorfalse% + \topsep\IEEEiedtopsep% + \IEEElabelindent\IEEEelabelindent% + \labelsep\IEEEiednormlabelsep% + \partopsep 0ex% + \parsep 0ex% + \itemsep 0ex% + \rightmargin 0em% + \listparindent 0em% + \itemindent 0em% + % calculate the label width + % We'll set it to the width suitable for all labels using + % normalfont 1) to 9) + % The user can override this later + \settowidth{\labelwidth}{9)}% + \@IEEEsavelistparams% save our list parameters + \list{\csname label\@enumctr\endcsname}{\usecounter{\@enumctr}% + \@IEEErestorelistparams% override any list{} changes + % to our globals + \let\makelabel\@IEEEiedmakelabel% v1.6b setup \makelabel + \IEEEiedlistdecl% let user alter parameters + #1\relax% + % If the user has requested not to use the + % IEEElabelindent factor, don't revise \IEEElabelindent + \ifIEEEnolabelindentfactor\relax% + \else\IEEElabelindent=\IEEElabelindentfactor\IEEElabelindent% + \fi% + % Unless the user has requested otherwise, + % calculate our left margin based + % on \IEEElabelindent, \labelwidth and + % \labelsep + \ifIEEEnocalcleftmargin\relax% + \else\IEEEcalcleftmargin{\IEEElabelindent}% + \fi}\fi\fi}% + + +% DO NOT ALLOW BLANK LINES TO BE IN THESE IED ENVIRONMENTS +% AS THIS WILL FORCE NEW PARAGRAPHS AFTER THE IED LISTS +% IEEEtran description list MDS 1/2001 +% Note controlled spacing here, shield end of lines with % +\def\@@IEEEdescription[#1]{% + \ifnum\@listdepth>5\relax\@toodeep\else% + % get the IEEElabelindentfactor for this level + \advance\@listdepth\@ne% we need to know what the level WILL be + \edef\IEEElabelindentfactor{\csname IEEElabelindentfactor\romannumeral\the\@listdepth\endcsname}% + \advance\@listdepth-\@ne% undo our increment + \def\@IEEEiedjustify{0}% left justified labels are default + % set other defaults + \IEEEnocalcleftmarginfalse% + \IEEEnolabelindentfactorfalse% + \topsep\IEEEiedtopsep% + \IEEElabelindent\IEEEdlabelindent% + % assume normal labelsep + \labelsep\IEEEiednormlabelsep% + \partopsep 0ex% + \parsep 0ex% + \itemsep 0ex% + \rightmargin 0em% + \listparindent 0em% + \itemindent 0em% + % Bogus label width in case the user forgets + % to set it. + % TIP: If you want to see what a variable's width is you + % can use the TeX command \showthe\width-variable to + % display it on the screen during compilation + % (This might be helpful to know when you need to find out + % which label is the widest) + \settowidth{\labelwidth}{Hello}% + \@IEEEsavelistparams% save our list parameters + \list{}{\@IEEErestorelistparams% override any list{} changes + % to our globals + \let\makelabel\@IEEEiedmakelabel% v1.6b setup \makelabel + \IEEEiedlistdecl% let user alter parameters + #1\relax% + % If the user has requested not to use the + % labelindent factor, don't revise \IEEElabelindent + \ifIEEEnolabelindentfactor\relax% + \else\IEEElabelindent=\IEEElabelindentfactor\IEEElabelindent% + \fi% + % Unless the user has requested otherwise, + % calculate our left margin based + % on \IEEElabelindent, \labelwidth and + % \labelsep + \ifIEEEnocalcleftmargin\relax% + \else\IEEEcalcleftmargin{\IEEElabelindent}\relax% + \fi}\fi} + +% v1.6b we use one makelabel that does justification as needed. +\def\@IEEEiedmakelabel#1{\relax\if\@IEEEiedjustify 0\relax +\makebox[\labelwidth][l]{\normalfont #1}\else +\if\@IEEEiedjustify 1\relax +\makebox[\labelwidth][c]{\normalfont #1}\else +\makebox[\labelwidth][r]{\normalfont #1}\fi\fi} + + + + + + + + + +% used only by IEEEtran's IEEEeqnarray as other packages may +% have their own, different, implementations +\newcounter{IEEEsubequation}[equation] + +% e.g., "1a" (used only by IEEEtran's IEEEeqnarray) +\def\theIEEEsubequation{\theequation\alph{IEEEsubequation}} +% just like LaTeX2e's \@eqnnum +\def\theequationdis{(\theequation)}% (1) +% IEEEsubequation used only by IEEEtran's IEEEeqnarray +\def\theIEEEsubequationdis{(\theIEEEsubequation)}% (1a) + + + + +%% +%% START OF IEEEeqnarray DEFINITIONS +%% +%% Inspired by the concepts, examples, and previous works of LaTeX +%% coders and developers such as Donald Arseneau, Fred Bartlett, +%% David Carlisle, Tony Liu, Frank Mittelbach, Piet van Oostrum, +%% Roland Winkler and Mark Wooding. +%% I don't make the claim that my work here is even near their calibre. ;) + + +\newif\if@IEEEeqnarrayboxnojot% flag to indicate if the environment was called as the star form +\@IEEEeqnarrayboxnojotfalse + +\newif\if@advanceIEEEeqncolcnt% tracks if the environment should advance the col counter +% allows a way to make an \IEEEeqnarraybox that can be used within an \IEEEeqnarray +% used by IEEEeqnarraymulticol so that it can work properly in both +\@advanceIEEEeqncolcnttrue + +\newcount\@IEEEeqnnumcols % tracks how many IEEEeqnarray cols are defined +\newcount\@IEEEeqncolcnt % tracks how many IEEEeqnarray cols the user actually used + + +% The default math style used by the columns +\def\IEEEeqnarraymathstyle{\displaystyle} +% The default text style used by the columns +% default to using the current font +\def\IEEEeqnarraytextstyle{\relax} + +% like the iedlistdecl but for \IEEEeqnarray +\def\IEEEeqnarraydecl{\relax} +\def\IEEEeqnarrayboxdecl{\relax} + + + +% V1.8 flags to indicate that equation numbering is to persist +\newif\if@IEEEeqnumpersist% +\@IEEEeqnumpersistfalse +\newif\if@IEEEsubeqnumpersist% +\@IEEEsubeqnumpersistfalse +% +% V1.8 flags to indicate if (sub)equation number of last line was preadvanced +\newif\if@IEEEeqnumpreadv% +\@IEEEeqnumpreadvfalse +\newif\if@IEEEsubeqnumpreadv% +\@IEEEsubeqnumpreadvfalse + +\newcount\@IEEEsubeqnnumrollback% saves previous value of IEEEsubequation number in case we need to restore it + +% \yesnumber is the opposite of \nonumber +% a novel concept with the same def as the equationarray package +% However, we give IEEE versions too since some LaTeX packages such as +% the MDWtools mathenv.sty redefine \nonumber to something else. +% This command is intended for use in non-IEEEeqnarray math environments +\providecommand{\yesnumber}{\global\@eqnswtrue} + + +% IEEEyes/nonumber +% V1.8 add persistant * forms +% These commands can alter the type of equation an IEEEeqnarray line is. +\def\IEEEyesnumber{\@ifstar{\global\@IEEEeqnumpersisttrue\global\@IEEEsubeqnumpersistfalse\@IEEEyesnumber}{\@IEEEyesnumber}} + +\def\@IEEEyesnumber{\global\@eqnswtrue +\if@IEEEeqnarrayISinner% alter counters and label only inside an IEEEeqnarray +\ifnum\c@IEEEsubequation>0\relax + \stepcounter{equation}\setcounter{IEEEsubequation}{0}\gdef\@currentlabel{\p@equation\theequation}\relax + \gdef\@currentHref{\@IEEEtheHrefequation}% setup hyperref label +\fi +% even if we reached this eqn num via a preadv, it is legit now +\global\@IEEEeqnumpreadvfalse\global\@IEEEsubeqnumpreadvfalse +\fi} + +\def\IEEEnonumber{\@ifstar{\global\@IEEEeqnumpersistfalse\global\@IEEEsubeqnumpersistfalse\global\@eqnswfalse}{\global\@eqnswfalse}} + + +\def\IEEEyessubnumber{\@ifstar{\global\@IEEEsubeqnumpersisttrue\@IEEEyessubnumber}{\@IEEEyessubnumber}} +% +\def\@IEEEyessubnumber{\if@IEEEeqnarrayISinner% alter counters and label only inside an IEEEeqnarray + \ifnum\c@IEEEsubequation>0\relax% if it already is a subequation, we are good to go as-is + \else% if we are a regular equation we have to watch out for two cases + \if@IEEEeqnumpreadv% if this equation is the result of a preadvance, backout and bump the sub eqnnum + \global\advance\c@equation\m@ne\global\c@IEEEsubequation=\@IEEEsubeqnnumrollback\addtocounter{IEEEsubequation}{1}\relax + \else% non-preadvanced equations just need initialization of their sub eqnnum + \setcounter{IEEEsubequation}{1}\relax + \fi + \fi% fi already is subequation + \gdef\@currentlabel{\p@IEEEsubequation\theIEEEsubequation}\relax + \gdef\@currentHref{\@IEEEtheHrefsubequation}% setup hyperref label + \global\@IEEEeqnumpreadvfalse\global\@IEEEsubeqnumpreadvfalse% no longer a preadv anymore + \global\@eqnswtrue +\fi} + + +\def\IEEEnosubnumber{\@ifstar{\global\@IEEEsubeqnumpersistfalse\@IEEEnosubnumber}{\@IEEEnosubnumber}} +% +\def\@IEEEnosubnumber{\if@IEEEeqnarrayISinner% alter counters and label only inside an IEEEeqnarray + \if@eqnsw % we do nothing unless we know we will display because we play with the counters here + % if it currently is a subequation, bump up to the next equation number and turn off the subequation + \ifnum\c@IEEEsubequation>0\relax\addtocounter{equation}{1}\setcounter{IEEEsubequation}{0}\relax + \fi + \global\@IEEEeqnumpreadvfalse\global\@IEEEsubeqnumpreadvfalse% no longer a preadv anymore + \gdef\@currentlabel{\p@equation\theequation}\relax + \gdef\@currentHref{\@IEEEtheHrefequation}% setup hyperref label + \fi +\fi} + + + +% allows users to "push away" equations that get too close to the equation numbers +\def\IEEEeqnarraynumspace{\hphantom{\ifnum\c@IEEEsubequation>0\relax\theIEEEsubequationdis\else\theequationdis\fi}} + +% provides a way to span multiple columns within IEEEeqnarray environments +% will consider \if@advanceIEEEeqncolcnt before globally advancing the +% column counter - so as to work within \IEEEeqnarraybox +% usage: \IEEEeqnarraymulticol{number cols. to span}{col type}{cell text} +\long\def\IEEEeqnarraymulticol#1#2#3{\multispan{#1}\relax +% check if column is defined for the precolumn definition +% We have to be careful here because TeX scans for & even within an \iffalse +% where it does not expand macros. So, if we used only one \ifx and a #3 +% appeared in the false branch and the user inserted another alignment +% structure that uses & in the \IEEEeqnarraymulticol{}, TeX will not see that +% there is an inner alignment in the false branch yet still will see any & +% there and will think that they apply to the outer alignment resulting in an +% incomplete \ifx error. +% So, here we use separate checks for the pre and post parts in order to keep +% the #3 outside of all conditionals. +\relax\expandafter\ifx\csname @IEEEeqnarraycolDEF#2\endcsname\@IEEEeqnarraycolisdefined\relax +\csname @IEEEeqnarraycolPRE#2\endcsname +\else% if not, error and use default type +\@IEEEclspkgerror{Invalid column type "#2" in \string\IEEEeqnarraymulticol.\MessageBreak +Using a default centering column instead}% +{You must define IEEEeqnarray column types before use.}% +\csname @IEEEeqnarraycolPRE@IEEEdefault\endcsname +\fi +% The ten \relax are to help prevent misleading error messages in case a user +% accidently inserted a macro that tries to acquire additional arguments. +#3\relax\relax\relax\relax\relax\relax\relax\relax\relax\relax +% check if column is defined for the postcolumn definition +\expandafter\ifx\csname @IEEEeqnarraycolDEF#2\endcsname\@IEEEeqnarraycolisdefined\relax +\csname @IEEEeqnarraycolPOST#2\endcsname +\else% if not, use the default type +\csname @IEEEeqnarraycolPOST@IEEEdefault\endcsname +\fi +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by #1\relax\fi} + +% like \omit, but maintains track of the column counter for \IEEEeqnarray +\def\IEEEeqnarrayomit{\omit\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by 1\relax\fi} + + +% provides a way to define a letter referenced column type +% usage: \IEEEeqnarraydefcol{col. type letter/name}{pre insertion text}{post insertion text} +\def\IEEEeqnarraydefcol#1#2#3{\expandafter\def\csname @IEEEeqnarraycolPRE#1\endcsname{#2}% +\expandafter\def\csname @IEEEeqnarraycolPOST#1\endcsname{#3}% +\expandafter\def\csname @IEEEeqnarraycolDEF#1\endcsname{1}} + + +% provides a way to define a numerically referenced inter-column glue types +% usage: \IEEEeqnarraydefcolsep{col. glue number}{glue definition} +\def\IEEEeqnarraydefcolsep#1#2{\expandafter\def\csname @IEEEeqnarraycolSEP\romannumeral #1\endcsname{#2}% +\expandafter\def\csname @IEEEeqnarraycolSEPDEF\romannumeral #1\endcsname{1}} + + +\def\@IEEEeqnarraycolisdefined{1}% just a macro for 1, used for checking undefined column types + + +% expands and appends the given argument to the \@IEEEtrantmptoksA token list +% used to build up the \halign preamble +\def\@IEEEappendtoksA#1{\edef\@@IEEEappendtoksA{\@IEEEtrantmptoksA={\the\@IEEEtrantmptoksA #1}}% +\@@IEEEappendtoksA} + +% also appends to \@IEEEtrantmptoksA, but does not expand the argument +% uses \toks8 as a scratchpad register +\def\@IEEEappendNOEXPANDtoksA#1{\toks8={#1}% +\edef\@@IEEEappendNOEXPANDtoksA{\@IEEEtrantmptoksA={\the\@IEEEtrantmptoksA\the\toks8}}% +\@@IEEEappendNOEXPANDtoksA} + +% define some common column types for the user +% math +\IEEEeqnarraydefcol{l}{$\IEEEeqnarraymathstyle}{$\hfil} +\IEEEeqnarraydefcol{c}{\hfil$\IEEEeqnarraymathstyle}{$\hfil} +\IEEEeqnarraydefcol{r}{\hfil$\IEEEeqnarraymathstyle}{$} +\IEEEeqnarraydefcol{L}{$\IEEEeqnarraymathstyle{}}{{}$\hfil} +\IEEEeqnarraydefcol{C}{\hfil$\IEEEeqnarraymathstyle{}}{{}$\hfil} +\IEEEeqnarraydefcol{R}{\hfil$\IEEEeqnarraymathstyle{}}{{}$} +% text +\IEEEeqnarraydefcol{s}{\IEEEeqnarraytextstyle}{\hfil} +\IEEEeqnarraydefcol{t}{\hfil\IEEEeqnarraytextstyle}{\hfil} +\IEEEeqnarraydefcol{u}{\hfil\IEEEeqnarraytextstyle}{} + +% vertical rules +\IEEEeqnarraydefcol{v}{}{\vrule width\arrayrulewidth} +\IEEEeqnarraydefcol{vv}{\vrule width\arrayrulewidth\hfil}{\hfil\vrule width\arrayrulewidth} +\IEEEeqnarraydefcol{V}{}{\vrule width\arrayrulewidth\hskip\doublerulesep\vrule width\arrayrulewidth} +\IEEEeqnarraydefcol{VV}{\vrule width\arrayrulewidth\hskip\doublerulesep\vrule width\arrayrulewidth\hfil}% +{\hfil\vrule width\arrayrulewidth\hskip\doublerulesep\vrule width\arrayrulewidth} + +% horizontal rules +\IEEEeqnarraydefcol{h}{}{\leaders\hrule height\arrayrulewidth\hfil} +\IEEEeqnarraydefcol{H}{}{\leaders\vbox{\hrule width\arrayrulewidth\vskip\doublerulesep\hrule width\arrayrulewidth}\hfil} + +% plain +\IEEEeqnarraydefcol{x}{}{} +\IEEEeqnarraydefcol{X}{$}{$} + +% the default column type to use in the event a column type is not defined +\IEEEeqnarraydefcol{@IEEEdefault}{\hfil$\IEEEeqnarraymathstyle}{$\hfil} + + +% a zero tabskip (used for "-" col types) +\def\@IEEEeqnarraycolSEPzero{0pt plus 0pt minus 0pt} +% a centering tabskip (used for "+" col types) +\def\@IEEEeqnarraycolSEPcenter{1000pt plus 0pt minus 1000pt} + +% top level default tabskip glues for the start, end, and inter-column +% may be reset within environments not always at the top level, e.g., \IEEEeqnarraybox +\edef\@IEEEeqnarraycolSEPdefaultstart{\@IEEEeqnarraycolSEPcenter}% default start glue +\edef\@IEEEeqnarraycolSEPdefaultend{\@IEEEeqnarraycolSEPcenter}% default end glue +\edef\@IEEEeqnarraycolSEPdefaultmid{\@IEEEeqnarraycolSEPzero}% default inter-column glue + + + +% creates a vertical rule that extends from the bottom to the top a a cell +% Provided in case other packages redefine \vline some other way. +% usage: \IEEEeqnarrayvrule[rule thickness] +% If no argument is provided, \arrayrulewidth will be used for the rule thickness. +\newcommand\IEEEeqnarrayvrule[1][\arrayrulewidth]{\vrule\@width#1\relax} + +% creates a blank separator row +% usage: \IEEEeqnarrayseprow[separation length][font size commands] +% default is \IEEEeqnarrayseprow[0.25\normalbaselineskip][\relax] +% blank arguments inherit the default values +% uses \skip5 as a scratch register - calls \@IEEEeqnarraystrutsize which uses more scratch registers +\def\IEEEeqnarrayseprow{\relax\@ifnextchar[{\@IEEEeqnarrayseprow}{\@IEEEeqnarrayseprow[0.25\normalbaselineskip]}} +\def\@IEEEeqnarrayseprow[#1]{\relax\@ifnextchar[{\@@IEEEeqnarrayseprow[#1]}{\@@IEEEeqnarrayseprow[#1][\relax]}} +\def\@@IEEEeqnarrayseprow[#1][#2]{\def\@IEEEeqnarrayseprowARGONE{#1}% +\ifx\@IEEEeqnarrayseprowARGONE\@empty% +% get the skip value, based on the font commands +% use skip5 because \IEEEeqnarraystrutsize uses \skip0, \skip2, \skip3 +% assign within a bogus box to confine the font changes +{\setbox0=\hbox{#2\relax\global\skip5=0.25\normalbaselineskip}}% +\else% +{\setbox0=\hbox{#2\relax\global\skip5=#1}}% +\fi% +\@IEEEeqnarrayhoptolastcolumn\IEEEeqnarraystrutsize{\skip5}{0pt}[\relax]\relax} + +% creates a blank separator row, but omits all the column templates +% usage: \IEEEeqnarrayseprowcut[separation length][font size commands] +% default is \IEEEeqnarrayseprowcut[0.25\normalbaselineskip][\relax] +% blank arguments inherit the default values +% uses \skip5 as a scratch register - calls \@IEEEeqnarraystrutsize which uses more scratch registers +\def\IEEEeqnarrayseprowcut{\multispan{\@IEEEeqnnumcols}\relax% span all the cols +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by \@IEEEeqnnumcols\relax\fi% +\@ifnextchar[{\@IEEEeqnarrayseprowcut}{\@IEEEeqnarrayseprowcut[0.25\normalbaselineskip]}} +\def\@IEEEeqnarrayseprowcut[#1]{\relax\@ifnextchar[{\@@IEEEeqnarrayseprowcut[#1]}{\@@IEEEeqnarrayseprowcut[#1][\relax]}} +\def\@@IEEEeqnarrayseprowcut[#1][#2]{\def\@IEEEeqnarrayseprowARGONE{#1}% +\ifx\@IEEEeqnarrayseprowARGONE\@empty% +% get the skip value, based on the font commands +% use skip5 because \IEEEeqnarraystrutsize uses \skip0, \skip2, \skip3 +% assign within a bogus box to confine the font changes +{\setbox0=\hbox{#2\relax\global\skip5=0.25\normalbaselineskip}}% +\else% +{\setbox0=\hbox{#2\relax\global\skip5=#1}}% +\fi% +\IEEEeqnarraystrutsize{\skip5}{0pt}[\relax]\relax} + + + +% draws a single rule across all the columns optional +% argument determines the rule width, \arrayrulewidth is the default +% updates column counter as needed and turns off struts +% usage: \IEEEeqnarrayrulerow[rule line thickness] +\def\IEEEeqnarrayrulerow{\multispan{\@IEEEeqnnumcols}\relax% span all the cols +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by \@IEEEeqnnumcols\relax\fi% +\@ifnextchar[{\@IEEEeqnarrayrulerow}{\@IEEEeqnarrayrulerow[\arrayrulewidth]}} +\def\@IEEEeqnarrayrulerow[#1]{\leaders\hrule height#1\hfil\relax% put in our rule +% turn off any struts +\IEEEeqnarraystrutsize{0pt}{0pt}[\relax]\relax} + + +% draws a double rule by using a single rule row, a separator row, and then +% another single rule row +% first optional argument determines the rule thicknesses, \arrayrulewidth is the default +% second optional argument determines the rule spacing, \doublerulesep is the default +% usage: \IEEEeqnarraydblrulerow[rule line thickness][rule spacing] +\def\IEEEeqnarraydblrulerow{\multispan{\@IEEEeqnnumcols}\relax% span all the cols +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by \@IEEEeqnnumcols\relax\fi% +\@ifnextchar[{\@IEEEeqnarraydblrulerow}{\@IEEEeqnarraydblrulerow[\arrayrulewidth]}} +\def\@IEEEeqnarraydblrulerow[#1]{\relax\@ifnextchar[{\@@IEEEeqnarraydblrulerow[#1]}% +{\@@IEEEeqnarraydblrulerow[#1][\doublerulesep]}} +\def\@@IEEEeqnarraydblrulerow[#1][#2]{\def\@IEEEeqnarraydblrulerowARG{#1}% +% we allow the user to say \IEEEeqnarraydblrulerow[][] +\ifx\@IEEEeqnarraydblrulerowARG\@empty% +\@IEEEeqnarrayrulerow[\arrayrulewidth]% +\else% +\@IEEEeqnarrayrulerow[#1]\relax% +\fi% +\def\@IEEEeqnarraydblrulerowARG{#2}% +\ifx\@IEEEeqnarraydblrulerowARG\@empty% +\\\IEEEeqnarrayseprow[\doublerulesep][\relax]% +\else% +\\\IEEEeqnarrayseprow[#2][\relax]% +\fi% +\\\multispan{\@IEEEeqnnumcols}% +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by \@IEEEeqnnumcols\relax\fi% +\def\@IEEEeqnarraydblrulerowARG{#1}% +\ifx\@IEEEeqnarraydblrulerowARG\@empty% +\@IEEEeqnarrayrulerow[\arrayrulewidth]% +\else% +\@IEEEeqnarrayrulerow[#1]% +\fi% +} + +% draws a double rule by using a single rule row, a separator (cutting) row, and then +% another single rule row +% first optional argument determines the rule thicknesses, \arrayrulewidth is the default +% second optional argument determines the rule spacing, \doublerulesep is the default +% usage: \IEEEeqnarraydblrulerow[rule line thickness][rule spacing] +\def\IEEEeqnarraydblrulerowcut{\multispan{\@IEEEeqnnumcols}\relax% span all the cols +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by \@IEEEeqnnumcols\relax\fi% +\@ifnextchar[{\@IEEEeqnarraydblrulerowcut}{\@IEEEeqnarraydblrulerowcut[\arrayrulewidth]}} +\def\@IEEEeqnarraydblrulerowcut[#1]{\relax\@ifnextchar[{\@@IEEEeqnarraydblrulerowcut[#1]}% +{\@@IEEEeqnarraydblrulerowcut[#1][\doublerulesep]}} +\def\@@IEEEeqnarraydblrulerowcut[#1][#2]{\def\@IEEEeqnarraydblrulerowARG{#1}% +% we allow the user to say \IEEEeqnarraydblrulerow[][] +\ifx\@IEEEeqnarraydblrulerowARG\@empty% +\@IEEEeqnarrayrulerow[\arrayrulewidth]% +\else% +\@IEEEeqnarrayrulerow[#1]% +\fi% +\def\@IEEEeqnarraydblrulerowARG{#2}% +\ifx\@IEEEeqnarraydblrulerowARG\@empty% +\\\IEEEeqnarrayseprowcut[\doublerulesep][\relax]% +\else% +\\\IEEEeqnarrayseprowcut[#2][\relax]% +\fi% +\\\multispan{\@IEEEeqnnumcols}% +% advance column counter only if the IEEEeqnarray environment wants it +\if@advanceIEEEeqncolcnt\global\advance\@IEEEeqncolcnt by \@IEEEeqnnumcols\relax\fi% +\def\@IEEEeqnarraydblrulerowARG{#1}% +\ifx\@IEEEeqnarraydblrulerowARG\@empty% +\@IEEEeqnarrayrulerow[\arrayrulewidth]% +\else% +\@IEEEeqnarrayrulerow[#1]% +\fi% +} + + + +% inserts a full row's worth of &'s +% relies on \@IEEEeqnnumcols to provide the correct number of columns +% uses \@IEEEtrantmptoksA, \count0 as scratch registers +\def\@IEEEeqnarrayhoptolastcolumn{\@IEEEtrantmptoksA={}\count0=1\relax% +\loop% add cols if the user did not use them all +\ifnum\count0<\@IEEEeqnnumcols\relax% +\@IEEEappendtoksA{&}% +\advance\count0 by 1\relax% update the col count +\repeat% +\the\@IEEEtrantmptoksA%execute the &'s +} + + + +\newif\if@IEEEeqnarrayISinner % flag to indicate if we are within the lines +\@IEEEeqnarrayISinnerfalse % of an IEEEeqnarray - after the IEEEeqnarraydecl + +\edef\@IEEEeqnarrayTHEstrutheight{0pt} % height and depth of IEEEeqnarray struts +\edef\@IEEEeqnarrayTHEstrutdepth{0pt} + +\edef\@IEEEeqnarrayTHEmasterstrutheight{0pt} % default height and depth of +\edef\@IEEEeqnarrayTHEmasterstrutdepth{0pt} % struts within an IEEEeqnarray + +\edef\@IEEEeqnarrayTHEmasterstrutHSAVE{0pt} % saved master strut height +\edef\@IEEEeqnarrayTHEmasterstrutDSAVE{0pt} % and depth + +\newif\if@IEEEeqnarrayusemasterstrut % flag to indicate that the master strut value +\@IEEEeqnarrayusemasterstruttrue % is to be used + + + +% saves the strut height and depth of the master strut +\def\@IEEEeqnarraymasterstrutsave{\relax% +\expandafter\skip0=\@IEEEeqnarrayTHEmasterstrutheight\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEmasterstrutdepth\relax% +% remove stretchability +\dimen0\skip0\relax% +\dimen2\skip2\relax% +% save values +\edef\@IEEEeqnarrayTHEmasterstrutHSAVE{\the\dimen0}% +\edef\@IEEEeqnarrayTHEmasterstrutDSAVE{\the\dimen2}} + +% restores the strut height and depth of the master strut +\def\@IEEEeqnarraymasterstrutrestore{\relax% +\expandafter\skip0=\@IEEEeqnarrayTHEmasterstrutHSAVE\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEmasterstrutDSAVE\relax% +% remove stretchability +\dimen0\skip0\relax% +\dimen2\skip2\relax% +% restore values +\edef\@IEEEeqnarrayTHEmasterstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEmasterstrutdepth{\the\dimen2}} + + +% globally restores the strut height and depth to the +% master values and sets the master strut flag to true +\def\@IEEEeqnarraystrutreset{\relax% +\expandafter\skip0=\@IEEEeqnarrayTHEmasterstrutheight\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEmasterstrutdepth\relax% +% remove stretchability +\dimen0\skip0\relax% +\dimen2\skip2\relax% +% restore values +\xdef\@IEEEeqnarrayTHEstrutheight{\the\dimen0}% +\xdef\@IEEEeqnarrayTHEstrutdepth{\the\dimen2}% +\global\@IEEEeqnarrayusemasterstruttrue} + + +% if the master strut is not to be used, make the current +% values of \@IEEEeqnarrayTHEstrutheight, \@IEEEeqnarrayTHEstrutdepth +% and the use master strut flag, global +% this allows user strut commands issued in the last column to be carried +% into the isolation/strut column +\def\@IEEEeqnarrayglobalizestrutstatus{\relax% +\if@IEEEeqnarrayusemasterstrut\else% +\xdef\@IEEEeqnarrayTHEstrutheight{\@IEEEeqnarrayTHEstrutheight}% +\xdef\@IEEEeqnarrayTHEstrutdepth{\@IEEEeqnarrayTHEstrutdepth}% +\global\@IEEEeqnarrayusemasterstrutfalse% +\fi} + + + +% usage: \IEEEeqnarraystrutsize{height}{depth}[font size commands] +% If called outside the lines of an IEEEeqnarray, sets the height +% and depth of both the master and local struts. If called inside +% an IEEEeqnarray line, sets the height and depth of the local strut +% only and sets the flag to indicate the use of the local strut +% values. If the height or depth is left blank, 0.7\normalbaselineskip +% and 0.3\normalbaselineskip will be used, respectively. +% The optional argument can be used to evaluate the lengths under +% a different font size and styles. If none is specified, the current +% font is used. +% uses scratch registers \skip0, \skip2, \skip3, \dimen0, \dimen2 +\def\IEEEeqnarraystrutsize#1#2{\relax\@ifnextchar[{\@IEEEeqnarraystrutsize{#1}{#2}}{\@IEEEeqnarraystrutsize{#1}{#2}[\relax]}} +\def\@IEEEeqnarraystrutsize#1#2[#3]{\def\@IEEEeqnarraystrutsizeARG{#1}% +\ifx\@IEEEeqnarraystrutsizeARG\@empty% +{\setbox0=\hbox{#3\relax\global\skip3=0.7\normalbaselineskip}}% +\skip0=\skip3\relax% +\else% arg one present +{\setbox0=\hbox{#3\relax\global\skip3=#1\relax}}% +\skip0=\skip3\relax% +\fi% if null arg +\def\@IEEEeqnarraystrutsizeARG{#2}% +\ifx\@IEEEeqnarraystrutsizeARG\@empty% +{\setbox0=\hbox{#3\relax\global\skip3=0.3\normalbaselineskip}}% +\skip2=\skip3\relax% +\else% arg two present +{\setbox0=\hbox{#3\relax\global\skip3=#2\relax}}% +\skip2=\skip3\relax% +\fi% if null arg +% remove stretchability, just to be safe +\dimen0\skip0\relax% +\dimen2\skip2\relax% +% dimen0 = height, dimen2 = depth +\if@IEEEeqnarrayISinner% inner does not touch master strut size +\edef\@IEEEeqnarrayTHEstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEstrutdepth{\the\dimen2}% +\@IEEEeqnarrayusemasterstrutfalse% do not use master +\else% outer, have to set master strut too +\edef\@IEEEeqnarrayTHEmasterstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEmasterstrutdepth{\the\dimen2}% +\edef\@IEEEeqnarrayTHEstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEstrutdepth{\the\dimen2}% +\@IEEEeqnarrayusemasterstruttrue% use master strut +\fi} + + +% usage: \IEEEeqnarraystrutsizeadd{added height}{added depth}[font size commands] +% If called outside the lines of an IEEEeqnarray, adds the given height +% and depth to both the master and local struts. +% If called inside an IEEEeqnarray line, adds the given height and depth +% to the local strut only and sets the flag to indicate the use +% of the local strut values. +% In both cases, if a height or depth is left blank, 0pt is used instead. +% The optional argument can be used to evaluate the lengths under +% a different font size and styles. If none is specified, the current +% font is used. +% uses scratch registers \skip0, \skip2, \skip3, \dimen0, \dimen2 +\def\IEEEeqnarraystrutsizeadd#1#2{\relax\@ifnextchar[{\@IEEEeqnarraystrutsizeadd{#1}{#2}}{\@IEEEeqnarraystrutsizeadd{#1}{#2}[\relax]}} +\def\@IEEEeqnarraystrutsizeadd#1#2[#3]{\def\@IEEEeqnarraystrutsizearg{#1}% +\ifx\@IEEEeqnarraystrutsizearg\@empty% +\skip0=0pt\relax% +\else% arg one present +{\setbox0=\hbox{#3\relax\global\skip3=#1}}% +\skip0=\skip3\relax% +\fi% if null arg +\def\@IEEEeqnarraystrutsizearg{#2}% +\ifx\@IEEEeqnarraystrutsizearg\@empty% +\skip2=0pt\relax% +\else% arg two present +{\setbox0=\hbox{#3\relax\global\skip3=#2}}% +\skip2=\skip3\relax% +\fi% if null arg +% remove stretchability, just to be safe +\dimen0\skip0\relax% +\dimen2\skip2\relax% +% dimen0 = height, dimen2 = depth +\if@IEEEeqnarrayISinner% inner does not touch master strut size +% get local strut size +\expandafter\skip0=\@IEEEeqnarrayTHEstrutheight\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEstrutdepth\relax% +% add it to the user supplied values +\advance\dimen0 by \skip0\relax% +\advance\dimen2 by \skip2\relax% +% update the local strut size +\edef\@IEEEeqnarrayTHEstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEstrutdepth{\the\dimen2}% +\@IEEEeqnarrayusemasterstrutfalse% do not use master +\else% outer, have to set master strut too +% get master strut size +\expandafter\skip0=\@IEEEeqnarrayTHEmasterstrutheight\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEmasterstrutdepth\relax% +% add it to the user supplied values +\advance\dimen0 by \skip0\relax% +\advance\dimen2 by \skip2\relax% +% update the local and master strut sizes +\edef\@IEEEeqnarrayTHEmasterstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEmasterstrutdepth{\the\dimen2}% +\edef\@IEEEeqnarrayTHEstrutheight{\the\dimen0}% +\edef\@IEEEeqnarrayTHEstrutdepth{\the\dimen2}% +\@IEEEeqnarrayusemasterstruttrue% use master strut +\fi} + + +% allow user a way to see the struts +\newif\ifIEEEvisiblestruts +\IEEEvisiblestrutsfalse + +% inserts an invisible strut using the master or local strut values +% uses scratch registers \skip0, \skip2, \dimen0, \dimen2 +\def\@IEEEeqnarrayinsertstrut{\relax% +\if@IEEEeqnarrayusemasterstrut +% get master strut size +\expandafter\skip0=\@IEEEeqnarrayTHEmasterstrutheight\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEmasterstrutdepth\relax% +\else% +% get local strut size +\expandafter\skip0=\@IEEEeqnarrayTHEstrutheight\relax% +\expandafter\skip2=\@IEEEeqnarrayTHEstrutdepth\relax% +\fi% +% remove stretchability, probably not needed +\dimen0\skip0\relax% +\dimen2\skip2\relax% +% dimen0 = height, dimen2 = depth +% allow user to see struts if desired +\ifIEEEvisiblestruts% +\vrule width0.2pt height\dimen0 depth\dimen2\relax% +\else% +\vrule width0pt height\dimen0 depth\dimen2\relax\fi} + + +% creates an invisible strut, useable even outside \IEEEeqnarray +% if \IEEEvisiblestrutstrue, the strut will be visible and 0.2pt wide. +% usage: \IEEEstrut[height][depth][font size commands] +% default is \IEEEstrut[0.7\normalbaselineskip][0.3\normalbaselineskip][\relax] +% blank arguments inherit the default values +% uses \dimen0, \dimen2, \skip0, \skip2 +\def\IEEEstrut{\relax\@ifnextchar[{\@IEEEstrut}{\@IEEEstrut[0.7\normalbaselineskip]}} +\def\@IEEEstrut[#1]{\relax\@ifnextchar[{\@@IEEEstrut[#1]}{\@@IEEEstrut[#1][0.3\normalbaselineskip]}} +\def\@@IEEEstrut[#1][#2]{\relax\@ifnextchar[{\@@@IEEEstrut[#1][#2]}{\@@@IEEEstrut[#1][#2][\relax]}} +\def\@@@IEEEstrut[#1][#2][#3]{\mbox{#3\relax% +\def\@IEEEstrutARG{#1}% +\ifx\@IEEEstrutARG\@empty% +\skip0=0.7\normalbaselineskip\relax% +\else% +\skip0=#1\relax% +\fi% +\def\@IEEEstrutARG{#2}% +\ifx\@IEEEstrutARG\@empty% +\skip2=0.3\normalbaselineskip\relax% +\else% +\skip2=#2\relax% +\fi% +% remove stretchability, probably not needed +\dimen0\skip0\relax% +\dimen2\skip2\relax% +\ifIEEEvisiblestruts% +\vrule width0.2pt height\dimen0 depth\dimen2\relax% +\else% +\vrule width0.0pt height\dimen0 depth\dimen2\relax\fi}} + + +% enables strut mode by setting a default strut size and then zeroing the +% \baselineskip, \lineskip, \lineskiplimit and \jot +\def\IEEEeqnarraystrutmode{\IEEEeqnarraystrutsize{0.7\normalbaselineskip}{0.3\normalbaselineskip}[\relax]% +\baselineskip=0pt\lineskip=0pt\lineskiplimit=0pt\jot=0pt} + + +% equation and subequation forms to use to setup hyperref's \@currentHref +\def\@IEEEtheHrefequation{equation.\theHequation} +\def\@IEEEtheHrefsubequation{equation.\theHequation\alph{IEEEsubequation}} + + +\def\IEEEeqnarray{\@IEEEeqnumpersisttrue\@IEEEsubeqnumpersistfalse\@IEEEeqnarray} +\def\endIEEEeqnarray{\end@IEEEeqnarray} + +\@namedef{IEEEeqnarray*}{\@IEEEeqnumpersistfalse\@IEEEsubeqnumpersistfalse\@IEEEeqnarray} +\@namedef{endIEEEeqnarray*}{\end@IEEEeqnarray} + + +% \IEEEeqnarray is an enhanced \eqnarray. +% The star form defaults to not putting equation numbers at the end of each row. +% usage: \IEEEeqnarray[decl]{cols} +\def\@IEEEeqnarray{\relax\@ifnextchar[{\@@IEEEeqnarray}{\@@IEEEeqnarray[\relax]}} +% We have to be careful here to normalize catcodes just before acquiring the +% cols as that specification may contain punctuation which could be subject +% to document catcode changes. +\def\@@IEEEeqnarray[#1]{\begingroup\IEEEnormalcatcodes\@@@IEEEeqnarray[#1]} +\def\@@@IEEEeqnarray[#1]#2{\endgroup + % default to showing the equation number or not based on whether or not + % the star form was involked + \if@IEEEeqnumpersist\global\@eqnswtrue + \else% not the star form + \global\@eqnswfalse + \fi% if star form + % provide a basic hyperref \theHequation if this has not already been setup (hyperref not loaded, or no section counter) + \@ifundefined{theHequation}{\def\theHequation{\arabic{equation}}}{}\relax + % provide dummy hyperref commands in case hyperref is not loaded + \providecommand{\Hy@raisedlink}[1]{}\relax + \providecommand{\hyper@anchorstart}[1]{}\relax + \providecommand{\hyper@anchorend}{}\relax + \providecommand{\@currentHref}{}\relax + \@IEEEeqnumpreadvfalse% reset eqnpreadv flag + \@IEEEsubeqnumpreadvfalse% reset subeqnpreadv flag + \@IEEEeqnarrayISinnerfalse% not yet within the lines of the halign + \@IEEEeqnarraystrutsize{0pt}{0pt}[\relax]% turn off struts by default + \@IEEEeqnarrayusemasterstruttrue% use master strut till user asks otherwise + \IEEEvisiblestrutsfalse% diagnostic mode defaults to off + % no extra space unless the user specifically requests it + \lineskip=0pt\relax + \lineskiplimit=0pt\relax + \baselineskip=\normalbaselineskip\relax% + \jot=\IEEEnormaljot\relax% + \mathsurround\z@\relax% no extra spacing around math + \@advanceIEEEeqncolcnttrue% advance the col counter for each col the user uses, + % used in \IEEEeqnarraymulticol and in the preamble build + %V1.8 Here we preadvance to the next equation number. + % If the user later wants a continued subequation, we can roll back. + \global\@IEEEsubeqnnumrollback=\c@IEEEsubequation% + \stepcounter{equation}\@IEEEeqnumpreadvtrue% advance equation counter before first line + \setcounter{IEEEsubequation}{0}% no subequation yet + \let\@IEEEcurrentlabelsave\@currentlabel% save current label as we later change it globally + \let\@IEEEcurrentHrefsave\@currentHref% save current href label as we later change it globally + \def\@currentlabel{\p@equation\theequation}% redefine the ref label + \def\@currentHref{\@IEEEtheHrefequation}% setup hyperref label + \IEEEeqnarraydecl\relax% allow a way for the user to make global overrides + #1\relax% allow user to override defaults + \let\\\@IEEEeqnarraycr% replace newline with one that can put in eqn. numbers + \global\@IEEEeqncolcnt\z@% col. count = 0 for first line + \@IEEEbuildpreamble{#2}\relax% build the preamble and put it into \@IEEEtrantmptoksA + % put in the column for the equation number + \ifnum\@IEEEeqnnumcols>0\relax\@IEEEappendtoksA{&}\fi% col separator for those after the first + \toks0={##}% + % advance the \@IEEEeqncolcnt for the isolation col, this helps with error checking + \@IEEEappendtoksA{\global\advance\@IEEEeqncolcnt by 1\relax}% + % add the isolation column + \@IEEEappendtoksA{\tabskip\z@skip\bgroup\the\toks0\egroup}% + % advance the \@IEEEeqncolcnt for the equation number col, this helps with error checking + \@IEEEappendtoksA{&\global\advance\@IEEEeqncolcnt by 1\relax}% + % add the equation number col to the preamble + \@IEEEappendtoksA{\tabskip\z@skip\hb@xt@\z@\bgroup\hss\the\toks0\egroup}% + % note \@IEEEeqnnumcols does not count the equation col or isolation col + % set the starting tabskip glue as determined by the preamble build + \tabskip=\@IEEEBPstartglue\relax + % begin the display alignment + \@IEEEeqnarrayISinnertrue% commands are now within the lines + $$\everycr{}\halign to\displaywidth\bgroup + % "exspand" the preamble + \span\the\@IEEEtrantmptoksA\cr} + +% enter isolation/strut column (or the next column if the user did not use +% every column), record the strut status, complete the columns, do the strut if needed, +% restore counters (to backout any equation setup for a next line that was never used) +% to their correct values and exit +\def\end@IEEEeqnarray{\@IEEEeqnarrayglobalizestrutstatus&\@@IEEEeqnarraycr\egroup +\if@IEEEsubeqnumpreadv\global\advance\c@IEEEsubequation\m@ne\fi +\if@IEEEeqnumpreadv\global\advance\c@equation\m@ne\global\c@IEEEsubequation=\@IEEEsubeqnnumrollback\fi +\global\let\@currentlabel\@IEEEcurrentlabelsave% restore current label +\global\let\@currentHref\@IEEEcurrentHrefsave% restore current href label +$$\@ignoretrue} + + +% IEEEeqnarray uses a modifed \\ instead of the plain \cr to +% end rows. This allows for things like \\*[vskip amount] +% These "cr" macros are modified versions of those for LaTeX2e's eqnarray +% the {\ifnum0=`} braces must be kept away from the last column to avoid +% altering spacing of its math, so we use & to advance to the next column +% as there is an isolation/strut column after the user's columns +\def\@IEEEeqnarraycr{\@IEEEeqnarrayglobalizestrutstatus&% save strut status and advance to next column + {\ifnum0=`}\fi + \@ifstar{% + \global\@eqpen\@M\@IEEEeqnarrayYCR + }{% + \global\@eqpen\interdisplaylinepenalty \@IEEEeqnarrayYCR + }% +} + +\def\@IEEEeqnarrayYCR{\@testopt\@IEEEeqnarrayXCR\z@skip} + +\def\@IEEEeqnarrayXCR[#1]{% + \ifnum0=`{\fi}% + \@@IEEEeqnarraycr + \noalign{\penalty\@eqpen\vskip\jot\vskip #1\relax}}% + +\def\@@IEEEeqnarraycr{\@IEEEtrantmptoksA={}% clear token register + \advance\@IEEEeqncolcnt by -1\relax% adjust col count because of the isolation column + \ifnum\@IEEEeqncolcnt>\@IEEEeqnnumcols\relax + \@IEEEclspkgerror{Too many columns within the IEEEeqnarray\MessageBreak + environment}% + {Use fewer \string &'s or put more columns in the IEEEeqnarray column\MessageBreak + specifications.}\relax% + \else + \loop% add cols if the user did not use them all + \ifnum\@IEEEeqncolcnt<\@IEEEeqnnumcols\relax + \@IEEEappendtoksA{&}% + \advance\@IEEEeqncolcnt by 1\relax% update the col count + \repeat + % this number of &'s will take us the the isolation column + \fi + % execute the &'s + \the\@IEEEtrantmptoksA% + % handle the strut/isolation column + \@IEEEeqnarrayinsertstrut% do the strut if needed + \@IEEEeqnarraystrutreset% reset the strut system for next line or IEEEeqnarray + &% and enter the equation number column + \if@eqnsw% only if we display something + \Hy@raisedlink{\hyper@anchorstart{\@currentHref}}% start a hyperref anchor + \global\@IEEEeqnumpreadvfalse\relax% displaying an equation number means + \global\@IEEEsubeqnumpreadvfalse\relax% the equation counters point to valid equations + % V1.8 Here we setup the counters, currentlabel and status for what would be the *next* + % equation line as would be the case under the current settings. However, there are two problems. + % One problem is that there might not ever be a next line. The second problem is that the user + % may later alter the meaning of a line with commands such as \IEEEyessubnumber. So, to handle + % these cases we have to record the current values of the (sub)equation counters and revert back + % to them if the next line is changed or never comes. The \if@IEEEeqnumpreadv, \if@IEEEsubeqnumpreadv + % and \@IEEEsubeqnnumrollback stuff tracks this. + % The logic to handle all this is surprisingly complex, but a nice feature of the approach here is + % that the equation counters and labels remain valid for what the line would be unless a + % \IEEEyessubnumber et al. later changes it. So, any hyperref links are always correct. + \ifnum\c@IEEEsubequation>0\relax% handle subequation + \theIEEEsubequationdis\relax + \if@IEEEsubeqnumpersist% setup for default type of next line + \stepcounter{IEEEsubequation}\global\@IEEEsubeqnumpreadvtrue\relax + \gdef\@currentlabel{\p@IEEEsubequation\theIEEEsubequation}\relax + \gdef\@currentHref{\@IEEEtheHrefsubequation}% setup hyperref label + \else + % if no subeqnum persist, go ahead and setup for a new equation number + \global\@IEEEsubeqnnumrollback=\c@IEEEsubequation + \stepcounter{equation}\global\@IEEEeqnumpreadvtrue\relax + \setcounter{IEEEsubequation}{0}\gdef\@currentlabel{\p@equation\theequation}\relax + \gdef\@currentHref{\@IEEEtheHrefequation}% setup hyperref label + \fi + \else% display a standard equation number + \theequationdis\relax + \setcounter{IEEEsubequation}{0}\relax% not really needed + \if@IEEEsubeqnumpersist% setup for default type of next line + % subequations that follow plain equations carry the same equation number e.g, 5, 5a rather than 5, 6a + \stepcounter{IEEEsubequation}\global\@IEEEsubeqnumpreadvtrue\relax + \gdef\@currentlabel{\p@IEEEsubequation\theIEEEsubequation}\relax + \gdef\@currentHref{\@IEEEtheHrefsubequation}% setup hyperref label + \else + % if no subeqnum persist, go ahead and setup for a new equation number + \global\@IEEEsubeqnnumrollback=\c@IEEEsubequation + \stepcounter{equation}\global\@IEEEeqnumpreadvtrue\relax + \setcounter{IEEEsubequation}{0}\gdef\@currentlabel{\p@equation\theequation}\relax + \gdef\@currentHref{\@IEEEtheHrefequation}% setup hyperref label + \fi + \fi% + \Hy@raisedlink{\hyper@anchorend}% end hyperref anchor + \fi% fi only if we display something + % reset the flags to indicate the default preferences of the display of equation numbers + \if@IEEEeqnumpersist\global\@eqnswtrue\else\global\@eqnswfalse\fi + \if@IEEEsubeqnumpersist\global\@eqnswtrue\fi% ditto for the subequation flag + % reset the number of columns the user actually used + \global\@IEEEeqncolcnt\z@\relax + % the real end of the line + \cr} + + + + + +% \IEEEeqnarraybox is like \IEEEeqnarray except the box form puts everything +% inside a vtop, vbox, or vcenter box depending on the letter in the second +% optional argument (t,b,c). Vbox is the default. Unlike \IEEEeqnarray, +% equation numbers are not displayed and \IEEEeqnarraybox can be nested. +% \IEEEeqnarrayboxm is for math mode (like \array) and does not put the vbox +% within an hbox. +% \IEEEeqnarrayboxt is for text mode (like \tabular) and puts the vbox within +% a \hbox{$ $} construct. +% \IEEEeqnarraybox will auto detect whether to use \IEEEeqnarrayboxm or +% \IEEEeqnarrayboxt depending on the math mode. +% The third optional argument specifies the width this box is to be set to - +% natural width is the default. +% The * forms do not add \jot line spacing +% usage: \IEEEeqnarraybox[decl][pos][width]{cols} +\def\IEEEeqnarrayboxm{\@IEEEeqnarrayboxnojotfalse\@IEEEeqnarrayboxHBOXSWfalse\@IEEEeqnarraybox} +\def\endIEEEeqnarrayboxm{\end@IEEEeqnarraybox} +\@namedef{IEEEeqnarrayboxm*}{\@IEEEeqnarrayboxnojottrue\@IEEEeqnarrayboxHBOXSWfalse\@IEEEeqnarraybox} +\@namedef{endIEEEeqnarrayboxm*}{\end@IEEEeqnarraybox} + +\def\IEEEeqnarrayboxt{\@IEEEeqnarrayboxnojotfalse\@IEEEeqnarrayboxHBOXSWtrue\@IEEEeqnarraybox} +\def\endIEEEeqnarrayboxt{\end@IEEEeqnarraybox} +\@namedef{IEEEeqnarrayboxt*}{\@IEEEeqnarrayboxnojottrue\@IEEEeqnarrayboxHBOXSWtrue\@IEEEeqnarraybox} +\@namedef{endIEEEeqnarrayboxt*}{\end@IEEEeqnarraybox} + +\def\IEEEeqnarraybox{\@IEEEeqnarrayboxnojotfalse\ifmmode\@IEEEeqnarrayboxHBOXSWfalse\else\@IEEEeqnarrayboxHBOXSWtrue\fi% +\@IEEEeqnarraybox} +\def\endIEEEeqnarraybox{\end@IEEEeqnarraybox} + +\@namedef{IEEEeqnarraybox*}{\@IEEEeqnarrayboxnojottrue\ifmmode\@IEEEeqnarrayboxHBOXSWfalse\else\@IEEEeqnarrayboxHBOXSWtrue\fi% +\@IEEEeqnarraybox} +\@namedef{endIEEEeqnarraybox*}{\end@IEEEeqnarraybox} + +% flag to indicate if the \IEEEeqnarraybox needs to put things into an hbox{$ $} +% for \vcenter in non-math mode +\newif\if@IEEEeqnarrayboxHBOXSW% +\@IEEEeqnarrayboxHBOXSWfalse + +\def\@IEEEeqnarraybox{\relax\@ifnextchar[{\@@IEEEeqnarraybox}{\@@IEEEeqnarraybox[\relax]}} +% We have to be careful here to normalize catcodes just before acquiring the +% cols as that specification may contain punctuation which could be subject +% to document catcode changes. +\def\@@IEEEeqnarraybox[#1]{\relax\begingroup\IEEEnormalcatcodes\@ifnextchar[{\@@@IEEEeqnarraybox[#1]}{\@@@IEEEeqnarraybox[#1][b]}} +\def\@@@IEEEeqnarraybox[#1][#2]{\relax\@ifnextchar[{\@@@@IEEEeqnarraybox[#1][#2]}{\@@@@IEEEeqnarraybox[#1][#2][\relax]}} + +% #1 = decl; #2 = t,b,c; #3 = width, #4 = col specs +\def\@@@@IEEEeqnarraybox[#1][#2][#3]#4{\endgroup\@IEEEeqnarrayISinnerfalse % not yet within the lines of the halign + \@IEEEeqnarraymasterstrutsave% save current master strut values + \@IEEEeqnarraystrutsize{0pt}{0pt}[\relax]% turn off struts by default + \@IEEEeqnarrayusemasterstruttrue% use master strut till user asks otherwise + \IEEEvisiblestrutsfalse% diagnostic mode defaults to off + % no extra space unless the user specifically requests it + \lineskip=0pt\relax% + \lineskiplimit=0pt\relax% + \baselineskip=\normalbaselineskip\relax% + \jot=\IEEEnormaljot\relax% + \mathsurround\z@\relax% no extra spacing around math + % the default end glues are zero for an \IEEEeqnarraybox + \edef\@IEEEeqnarraycolSEPdefaultstart{\@IEEEeqnarraycolSEPzero}% default start glue + \edef\@IEEEeqnarraycolSEPdefaultend{\@IEEEeqnarraycolSEPzero}% default end glue + \edef\@IEEEeqnarraycolSEPdefaultmid{\@IEEEeqnarraycolSEPzero}% default inter-column glue + \@advanceIEEEeqncolcntfalse% do not advance the col counter for each col the user uses, + % used in \IEEEeqnarraymulticol and in the preamble build + \IEEEeqnarrayboxdecl\relax% allow a way for the user to make global overrides + #1\relax% allow user to override defaults + \let\\\@IEEEeqnarrayboxcr% replace newline with one that allows optional spacing + \@IEEEbuildpreamble{#4}\relax% build the preamble and put it into \@IEEEtrantmptoksA + % add an isolation column to the preamble to stop \\'s {} from getting into the last col + \ifnum\@IEEEeqnnumcols>0\relax\@IEEEappendtoksA{&}\fi% col separator for those after the first + \toks0={##}% + % add the isolation column to the preamble + \@IEEEappendtoksA{\tabskip\z@skip\bgroup\the\toks0\egroup}% + % set the starting tabskip glue as determined by the preamble build + \tabskip=\@IEEEBPstartglue\relax + % begin the alignment + \everycr{}% + % use only the very first token to determine the positioning + \@IEEEextracttoken{#2}\relax + \ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: IEEEeqnarraybox position specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax + \fi + % \@IEEEextractedtoken has the first token, the rest are ignored + % if we need to put things into and hbox and go into math mode, do so now + \if@IEEEeqnarrayboxHBOXSW \leavevmode \hbox \bgroup $\fi% + % use the appropriate vbox type + \if\@IEEEextractedtoken t\relax\vtop\else\if\@IEEEextractedtoken c\relax% + \vcenter\else\vbox\fi\fi\bgroup% + \@IEEEeqnarrayISinnertrue% commands are now within the lines + \ifx#3\relax\halign\else\halign to #3\relax\fi% + \bgroup + % "exspand" the preamble + \span\the\@IEEEtrantmptoksA\cr} + +% carry strut status and enter the isolation/strut column, +% exit from math mode if needed, and exit +\def\end@IEEEeqnarraybox{\@IEEEeqnarrayglobalizestrutstatus% carry strut status +&% enter isolation/strut column +\@IEEEeqnarrayinsertstrut% do strut if needed +\@IEEEeqnarraymasterstrutrestore% restore the previous master strut values +% reset the strut system for next IEEEeqnarray +% (sets local strut values back to previous master strut values) +\@IEEEeqnarraystrutreset% +% ensure last line, exit from halign, close vbox +\crcr\egroup\egroup% +% exit from math mode and close hbox if needed +\if@IEEEeqnarrayboxHBOXSW $\egroup\fi} + + + +% IEEEeqnarraybox uses a modifed \\ instead of the plain \cr to +% end rows. This allows for things like \\[vskip amount] +% This "cr" macros are modified versions those for LaTeX2e's eqnarray +% For IEEEeqnarraybox, \\* is the same as \\ +% the {\ifnum0=`} braces must be kept away from the last column to avoid +% altering spacing of its math, so we use & to advance to the isolation/strut column +% carry strut status into isolation/strut column +\def\@IEEEeqnarrayboxcr{\@IEEEeqnarrayglobalizestrutstatus% carry strut status +&% enter isolation/strut column +\@IEEEeqnarrayinsertstrut% do strut if needed +% reset the strut system for next line or IEEEeqnarray +\@IEEEeqnarraystrutreset% +{\ifnum0=`}\fi% +\@ifstar{\@IEEEeqnarrayboxYCR}{\@IEEEeqnarrayboxYCR}} + +% test and setup the optional argument to \\[] +\def\@IEEEeqnarrayboxYCR{\@testopt\@IEEEeqnarrayboxXCR\z@skip} + +% IEEEeqnarraybox does not automatically increase line spacing by \jot +\def\@IEEEeqnarrayboxXCR[#1]{\ifnum0=`{\fi}% +\cr\noalign{\if@IEEEeqnarrayboxnojot\else\vskip\jot\fi\vskip#1\relax}} + + + +% usage: \@IEEEbuildpreamble{column specifiers} +% starts the halign preamble build +% the assembled preamble is put in \@IEEEtrantmptoksA +\def\@IEEEbuildpreamble#1{\@IEEEtrantmptoksA={}% clear token register +\let\@IEEEBPcurtype=u%current column type is not yet known +\let\@IEEEBPprevtype=s%the previous column type was the start +\let\@IEEEBPnexttype=u%next column type is not yet known +% ensure these are valid +\def\@IEEEBPcurglue={0pt plus 0pt minus 0pt}% +\def\@IEEEBPcurcolname{@IEEEdefault}% name of current column definition +% currently acquired numerically referenced glue +% use a name that is easier to remember +\let\@IEEEBPcurnum=\@IEEEtrantmpcountA% +\@IEEEBPcurnum=0% +% tracks number of columns in the preamble +\@IEEEeqnnumcols=0% +% record the default end glues +\edef\@IEEEBPstartglue{\@IEEEeqnarraycolSEPdefaultstart}% +\edef\@IEEEBPendglue{\@IEEEeqnarraycolSEPdefaultend}% +\edef\@IEEEedefMACRO{#1}\relax% fully expand the preamble to support macro containers +% now parse the user's column specifications +% \ignorespaces is used as a delimiter, need at least one trailing \relax because +% \@@IEEEbuildpreamble looks into the future +\expandafter\@@IEEEbuildpreamble\@IEEEedefMACRO\ignorespaces\relax\relax} + + +% usage: \@@IEEEbuildpreamble{current column}{next column} +% parses and builds the halign preamble +\def\@@IEEEbuildpreamble#1#2{\let\@@nextIEEEbuildpreamble=\@@IEEEbuildpreamble% +% use only the very first token to check the end +\@IEEEextracttokengroups{#1}\relax +\ifx\@IEEEextractedfirsttoken\ignorespaces\let\@@nextIEEEbuildpreamble=\@@IEEEfinishpreamble\else% +% identify current and next token type +\@IEEEgetcoltype{#1}{\@IEEEBPcurtype}{1}% current, error on invalid +\@IEEEgetcoltype{#2}{\@IEEEBPnexttype}{0}% next, no error on invalid next +% if curtype is a glue, get the glue def +\if\@IEEEBPcurtype g\@IEEEgetcurglue{#1}{\@IEEEBPcurglue}\fi% +% if curtype is a column, get the column def and set the current column name +\if\@IEEEBPcurtype c\@IEEEgetcurcol{#1}\fi% +% if curtype is a numeral, acquire the user defined glue +\if\@IEEEBPcurtype n\@IEEEprocessNcol{#1}\fi% +% process the acquired glue +\if\@IEEEBPcurtype g\@IEEEprocessGcol\fi% +% process the acquired col +\if\@IEEEBPcurtype c\@IEEEprocessCcol\fi% +% ready prevtype for next col spec. +\let\@IEEEBPprevtype=\@IEEEBPcurtype% +% be sure and put back the future token(s) as a group +\fi\@@nextIEEEbuildpreamble{#2}} + + +% usage: \@@IEEEfinishpreamble{discarded} +% executed just after preamble build is completed +% warn about zero cols, and if prevtype type = u, put in end tabskip glue +% argument is not used +\def\@@IEEEfinishpreamble#1{\ifnum\@IEEEeqnnumcols<1\relax +\@IEEEclspkgerror{No column specifiers declared for IEEEeqnarray}% +{At least one column type must be declared for each IEEEeqnarray.}% +\fi%num cols less than 1 +%if last type undefined, set default end tabskip glue +\if\@IEEEBPprevtype u\@IEEEappendtoksA{\tabskip=\@IEEEBPendglue}\fi} + + +% usage: \@IEEEgetcoltype{col specifier}{\output}{error more} +% Identify and return the column specifier's type code in the given +% \output macro: +% n = number +% g = glue (any other char in catagory 12) +% c = letter +% e = \ignorespaces (end of sequence) +% u = undefined +% error mode: 0 = no error message, 1 = error on invalid char +\def\@IEEEgetcoltype#1#2#3{% +% use only the very first token to determine the type +\@IEEEextracttoken{#1}\relax +% \@IEEEextractedtoken has the first token, the rest are discarded +\let#2=u\relax% assume invalid until know otherwise +\ifx\@IEEEextractedtoken\ignorespaces\let#2=e\else +\ifcat\@IEEEextractedtoken\relax\else% screen out control sequences +\if0\@IEEEextractedtoken\let#2=n\else +\if1\@IEEEextractedtoken\let#2=n\else +\if2\@IEEEextractedtoken\let#2=n\else +\if3\@IEEEextractedtoken\let#2=n\else +\if4\@IEEEextractedtoken\let#2=n\else +\if5\@IEEEextractedtoken\let#2=n\else +\if6\@IEEEextractedtoken\let#2=n\else +\if7\@IEEEextractedtoken\let#2=n\else +\if8\@IEEEextractedtoken\let#2=n\else +\if9\@IEEEextractedtoken\let#2=n\else +\ifcat,\@IEEEextractedtoken\let#2=g\relax +\else\ifcat a\@IEEEextractedtoken\let#2=c\relax\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi +\if#2u\relax +\if0\noexpand#3\relax\else\@IEEEclspkgerror{Invalid character in column specifications}% +{Only letters, numerals and certain other symbols are allowed \MessageBreak +as IEEEeqnarray column specifiers.}\fi\fi} + + +% usage: \@IEEEgetcurcol{col specifier} +% verify the letter referenced column exists +% and return its name in \@IEEEBPcurcolname +% if column specifier is invalid, use the default column @IEEEdefault +\def\@IEEEgetcurcol#1{\expandafter\ifx\csname @IEEEeqnarraycolDEF#1\endcsname\@IEEEeqnarraycolisdefined% +\def\@IEEEBPcurcolname{#1}\else% invalid column name +\@IEEEclspkgerror{Invalid column type "#1" in column specifications.\MessageBreak +Using a default centering column instead}% +{You must define IEEEeqnarray column types before use.}% +\def\@IEEEBPcurcolname{@IEEEdefault}\fi} + + +% usage: \@IEEEgetcurglue{glue specifier}{\output} +% identify the predefined (punctuation) glue value +% and return it in the given output macro +\def\@IEEEgetcurglue#1#2{% +% ! = \! (neg small) -0.16667em (-3/18 em) +% , = \, (small) 0.16667em ( 3/18 em) +% : = \: (med) 0.22222em ( 4/18 em) +% ; = \; (large) 0.27778em ( 5/18 em) +% ' = \quad 1em +% " = \qquad 2em +% . = 0.5\arraycolsep +% / = \arraycolsep +% ? = 2\arraycolsep +% * = 1fil +% + = \@IEEEeqnarraycolSEPcenter +% - = \@IEEEeqnarraycolSEPzero +% Note that all em values are referenced to the math font (textfont2) fontdimen6 +% value for 1em. +% +% use only the very first token to determine the type +\@IEEEextracttoken{#1}\relax +\ifx\@IEEEextractedtokensdiscarded\@empty\else + \typeout{** WARNING: IEEEeqnarray predefined inter-column glue type specifiers after the first in `\@IEEEextracttokenarg' ignored (line \the\inputlineno).}\relax +\fi +% get the math font 1em value +% LaTeX2e's NFSS2 does not preload the fonts, but \IEEEeqnarray needs +% to gain access to the math (\textfont2) font's spacing parameters. +% So we create a bogus box here that uses the math font to ensure +% that \textfont2 is loaded and ready. If this is not done, +% the \textfont2 stuff here may not work. +% Thanks to Bernd Raichle for his 1997 post on this topic. +{\setbox0=\hbox{$\displaystyle\relax$}}% +% fontdimen6 has the width of 1em (a quad). +\@IEEEtrantmpdimenA=\fontdimen6\textfont2\relax% +% identify the glue value based on the first token +% we discard anything after the first +\if!\@IEEEextractedtoken\@IEEEtrantmpdimenA=-0.16667\@IEEEtrantmpdimenA\edef#2{\the\@IEEEtrantmpdimenA}\else +\if,\@IEEEextractedtoken\@IEEEtrantmpdimenA=0.16667\@IEEEtrantmpdimenA\edef#2{\the\@IEEEtrantmpdimenA}\else +\if:\@IEEEextractedtoken\@IEEEtrantmpdimenA=0.22222\@IEEEtrantmpdimenA\edef#2{\the\@IEEEtrantmpdimenA}\else +\if;\@IEEEextractedtoken\@IEEEtrantmpdimenA=0.27778\@IEEEtrantmpdimenA\edef#2{\the\@IEEEtrantmpdimenA}\else +\if'\@IEEEextractedtoken\@IEEEtrantmpdimenA=1\@IEEEtrantmpdimenA\edef#2{\the\@IEEEtrantmpdimenA}\else +\if"\@IEEEextractedtoken\@IEEEtrantmpdimenA=2\@IEEEtrantmpdimenA\edef#2{\the\@IEEEtrantmpdimenA}\else +\if.\@IEEEextractedtoken\@IEEEtrantmpdimenA=0.5\arraycolsep\edef#2{\the\@IEEEtrantmpdimenA}\else +\if/\@IEEEextractedtoken\edef#2{\the\arraycolsep}\else +\if?\@IEEEextractedtoken\@IEEEtrantmpdimenA=2\arraycolsep\edef#2{\the\@IEEEtrantmpdimenA}\else +\if *\@IEEEextractedtoken\edef#2{0pt plus 1fil minus 0pt}\else +\if+\@IEEEextractedtoken\edef#2{\@IEEEeqnarraycolSEPcenter}\else +\if-\@IEEEextractedtoken\edef#2{\@IEEEeqnarraycolSEPzero}\else +\edef#2{\@IEEEeqnarraycolSEPzero}% +\@IEEEclspkgerror{Invalid predefined inter-column glue type "#1" in\MessageBreak +column specifications. Using a default value of\MessageBreak +0pt instead}% +{Only !,:;'"./?*+ and - are valid predefined glue types in the\MessageBreak +IEEEeqnarray column specifications.}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi} + + +% usage: \@IEEEprocessNcol{digit} +% process a numerical digit from the column specification +% and look up the corresponding user defined glue value +% can transform current type from n to g or a as the user defined glue is acquired +\def\@IEEEprocessNcol#1{\if\@IEEEBPprevtype g% +\@IEEEclspkgerror{Back-to-back inter-column glue specifiers in column\MessageBreak +specifications. Ignoring consecutive glue specifiers\MessageBreak +after the first}% +{You cannot have two or more glue types next to each other\MessageBreak +in the IEEEeqnarray column specifications.}% +\let\@IEEEBPcurtype=a% abort this glue, future digits will be discarded +\@IEEEBPcurnum=0\relax% +\else% if we previously aborted a glue +\if\@IEEEBPprevtype a\@IEEEBPcurnum=0\let\@IEEEBPcurtype=a%maintain digit abortion +\else%acquire this number +% save the previous type before the numerical digits started +\if\@IEEEBPprevtype n\else\let\@IEEEBPprevsavedtype=\@IEEEBPprevtype\fi% +\multiply\@IEEEBPcurnum by 10\relax% +\advance\@IEEEBPcurnum by #1\relax% add in number, \relax is needed to stop TeX's number scan +\if\@IEEEBPnexttype n\else%close acquisition +\expandafter\ifx\csname @IEEEeqnarraycolSEPDEF\expandafter\romannumeral\number\@IEEEBPcurnum\endcsname\@IEEEeqnarraycolisdefined% +\edef\@IEEEBPcurglue{\csname @IEEEeqnarraycolSEP\expandafter\romannumeral\number\@IEEEBPcurnum\endcsname}% +\else%user glue not defined +\@IEEEclspkgerror{Invalid user defined inter-column glue type "\number\@IEEEBPcurnum" in\MessageBreak +column specifications. Using a default value of\MessageBreak +0pt instead}% +{You must define all IEEEeqnarray numerical inter-column glue types via\MessageBreak +\string\IEEEeqnarraydefcolsep \space before they are used in column specifications.}% +\edef\@IEEEBPcurglue{\@IEEEeqnarraycolSEPzero}% +\fi% glue defined or not +\let\@IEEEBPcurtype=g% change the type to reflect the acquired glue +\let\@IEEEBPprevtype=\@IEEEBPprevsavedtype% restore the prev type before this number glue +\@IEEEBPcurnum=0\relax%ready for next acquisition +\fi%close acquisition, get glue +\fi%discard or acquire number +\fi%prevtype glue or not +} + + +% process an acquired glue +% add any acquired column/glue pair to the preamble +\def\@IEEEprocessGcol{\if\@IEEEBPprevtype a\let\@IEEEBPcurtype=a%maintain previous glue abortions +\else +% if this is the start glue, save it, but do nothing else +% as this is not used in the preamble, but before +\if\@IEEEBPprevtype s\edef\@IEEEBPstartglue{\@IEEEBPcurglue}% +\else%not the start glue +\if\@IEEEBPprevtype g%ignore if back to back glues +\@IEEEclspkgerror{Back-to-back inter-column glue specifiers in column\MessageBreak +specifications. Ignoring consecutive glue specifiers\MessageBreak +after the first}% +{You cannot have two or more glue types next to each other\MessageBreak +in the IEEEeqnarray column specifications.}% +\let\@IEEEBPcurtype=a% abort this glue +\else% not a back to back glue +\if\@IEEEBPprevtype c\relax% if the previoustype was a col, add column/glue pair to preamble +\ifnum\@IEEEeqnnumcols>0\relax\@IEEEappendtoksA{&}\fi +\toks0={##}% +% make preamble advance col counter if this environment needs this +\if@advanceIEEEeqncolcnt\@IEEEappendtoksA{\global\advance\@IEEEeqncolcnt by 1\relax}\fi +% insert the column defintion into the preamble, being careful not to expand +% the column definition +\@IEEEappendtoksA{\tabskip=\@IEEEBPcurglue}% +\@IEEEappendNOEXPANDtoksA{\begingroup\csname @IEEEeqnarraycolPRE}% +\@IEEEappendtoksA{\@IEEEBPcurcolname}% +\@IEEEappendNOEXPANDtoksA{\endcsname}% +\@IEEEappendtoksA{\the\toks0}% +\@IEEEappendNOEXPANDtoksA{\relax\relax\relax\relax\relax% +\relax\relax\relax\relax\relax\csname @IEEEeqnarraycolPOST}% +\@IEEEappendtoksA{\@IEEEBPcurcolname}% +\@IEEEappendNOEXPANDtoksA{\endcsname\relax\relax\relax\relax\relax% +\relax\relax\relax\relax\relax\endgroup}% +\advance\@IEEEeqnnumcols by 1\relax%one more column in the preamble +\else% error: non-start glue with no pending column +\@IEEEclspkgerror{Inter-column glue specifier without a prior column\MessageBreak +type in the column specifications. Ignoring this glue\MessageBreak +specifier}% +{Except for the first and last positions, glue can be placed only\MessageBreak +between column types.}% +\let\@IEEEBPcurtype=a% abort this glue +\fi% previous was a column +\fi% back-to-back glues +\fi% is start column glue +\fi% prev type not a +} + + +% process an acquired letter referenced column and, if necessary, add it to the preamble +\def\@IEEEprocessCcol{\if\@IEEEBPnexttype g\else +\if\@IEEEBPnexttype n\else +% we have a column followed by something other than a glue (or numeral glue) +% so we must add this column to the preamble now +\ifnum\@IEEEeqnnumcols>0\relax\@IEEEappendtoksA{&}\fi%col separator for those after the first +\if\@IEEEBPnexttype e\@IEEEappendtoksA{\tabskip=\@IEEEBPendglue\relax}\else%put in end glue +\@IEEEappendtoksA{\tabskip=\@IEEEeqnarraycolSEPdefaultmid\relax}\fi% or default mid glue +\toks0={##}% +% make preamble advance col counter if this environment needs this +\if@advanceIEEEeqncolcnt\@IEEEappendtoksA{\global\advance\@IEEEeqncolcnt by 1\relax}\fi +% insert the column definition into the preamble, being careful not to expand +% the column definition +\@IEEEappendNOEXPANDtoksA{\begingroup\csname @IEEEeqnarraycolPRE}% +\@IEEEappendtoksA{\@IEEEBPcurcolname}% +\@IEEEappendNOEXPANDtoksA{\endcsname}% +\@IEEEappendtoksA{\the\toks0}% +\@IEEEappendNOEXPANDtoksA{\relax\relax\relax\relax\relax% +\relax\relax\relax\relax\relax\csname @IEEEeqnarraycolPOST}% +\@IEEEappendtoksA{\@IEEEBPcurcolname}% +\@IEEEappendNOEXPANDtoksA{\endcsname\relax\relax\relax\relax\relax% +\relax\relax\relax\relax\relax\endgroup}% +\advance\@IEEEeqnnumcols by 1\relax%one more column in the preamble +\fi%next type not numeral +\fi%next type not glue +} + + +%% +%% END OF IEEEeqnarray DEFINITIONS +%% + + + + +% \IEEEPARstart +% Definition for the big two line drop cap letter at the beginning of the +% first paragraph of journal papers. The first argument is the first letter +% of the first word, the second argument is the remaining letters of the +% first word which will be rendered in upper case. +% In V1.6 this has been completely rewritten to: +% +% 1. no longer have problems when the user begins an environment +% within the paragraph that uses \IEEEPARstart. +% 2. auto-detect and use the current font family +% 3. revise handling of the space at the end of the first word so that +% interword glue will now work as normal. +% 4. produce correctly aligned edges for the (two) indented lines. +% +% We generalize things via control macros - playing with these is fun too. +% +% V1.7 added more control macros to make it easy for IEEEtrantools.sty users +% to change the font style. +% +% the number of lines that are indented to clear it +% may need to increase if using decenders +\providecommand{\IEEEPARstartDROPLINES}{2} +% minimum number of lines left on a page to allow a \@IEEEPARstart +% Does not take into consideration rubber shrink, so it tends to +% be overly cautious +\providecommand{\IEEEPARstartMINPAGELINES}{2} +% V1.7 the height of the drop cap is adjusted to match the height of this text +% in the current font (when \IEEEPARstart is called). +\providecommand{\IEEEPARstartHEIGHTTEXT}{T} +% the depth the letter is lowered below the baseline +% the height (and size) of the letter is determined by the sum +% of this value and the height of the \IEEEPARstartHEIGHTTEXT in the current +% font. It is a good idea to set this value in terms of the baselineskip +% so that it can respond to changes therein. +\providecommand{\IEEEPARstartDROPDEPTH}{1.1\baselineskip} +% V1.7 the font the drop cap will be rendered in, +% can take zero or one argument. +\providecommand{\IEEEPARstartFONTSTYLE}{\bfseries} +% V1.7 any additional, non-font related commands needed to modify +% the drop cap letter, can take zero or one argument. +\providecommand{\IEEEPARstartCAPSTYLE}{\MakeUppercase} +% V1.7 the font that will be used to render the rest of the word, +% can take zero or one argument. +\providecommand{\IEEEPARstartWORDFONTSTYLE}{\relax} +% V1.7 any additional, non-font related commands needed to modify +% the rest of the word, can take zero or one argument. +\providecommand{\IEEEPARstartWORDCAPSTYLE}{\MakeUppercase} +% This is the horizontal separation distance from the drop letter to the main text. +% Lengths that depend on the font (e.g., ex, em, etc.) will be referenced +% to the font that is active when \IEEEPARstart is called. +\providecommand{\IEEEPARstartSEP}{0.15em} +% V1.7 horizontal offset applied to the left of the drop cap. +\providecommand{\IEEEPARstartHOFFSET}{0em} +% V1.7 Italic correction command applied at the end of the drop cap. +\providecommand{\IEEEPARstartITLCORRECT}{\/} + +% width of the letter output, set globally. Can be used in \IEEEPARstartSEP +% or \IEEEPARstartHOFFSET, but not the height lengths. +\newdimen\IEEEPARstartletwidth +\IEEEPARstartletwidth 0pt\relax + +% definition of \IEEEPARstart +% THIS IS A CONTROLLED SPACING AREA, DO NOT ALLOW SPACES WITHIN THESE LINES +% +% The token \@IEEEPARstartfont will be globally defined after the first use +% of \IEEEPARstart and will be a font command which creates the big letter +% The first argument is the first letter of the first word and the second +% argument is the rest of the first word(s). +\def\IEEEPARstart#1#2{\par{% +% if this page does not have enough space, break it and lets start +% on a new one +\@IEEEtranneedspace{\IEEEPARstartMINPAGELINES\baselineskip}{\relax}% +% V1.7 move this up here in case user uses \textbf for \IEEEPARstartFONTSTYLE +% which uses command \leavevmode which causes an unwanted \indent to be issued +\noindent +% calculate the desired height of the big letter +% it extends from the top of \IEEEPARstartHEIGHTTEXT in the current font +% down to \IEEEPARstartDROPDEPTH below the current baseline +\settoheight{\@IEEEtrantmpdimenA}{\IEEEPARstartHEIGHTTEXT}% +\addtolength{\@IEEEtrantmpdimenA}{\IEEEPARstartDROPDEPTH}% +% extract the name of the current font in bold +% and place it in \@IEEEPARstartFONTNAME +\def\@IEEEPARstartGETFIRSTWORD##1 ##2\relax{##1}% +{\IEEEPARstartFONTSTYLE{\selectfont\edef\@IEEEPARstartFONTNAMESPACE{\fontname\font\space}% +\xdef\@IEEEPARstartFONTNAME{\expandafter\@IEEEPARstartGETFIRSTWORD\@IEEEPARstartFONTNAMESPACE\relax}}}% +% define a font based on this name with a point size equal to the desired +% height of the drop letter +\font\@IEEEPARstartsubfont\@IEEEPARstartFONTNAME\space at \@IEEEtrantmpdimenA\relax% +% save this value as a counter (integer) value (sp points) +\@IEEEtrantmpcountA=\@IEEEtrantmpdimenA% +% now get the height of the actual letter produced by this font size +\settoheight{\@IEEEtrantmpdimenB}{\@IEEEPARstartsubfont\IEEEPARstartCAPSTYLE{#1}}% +% If something bogus happens like the first argument is empty or the +% current font is strange, do not allow a zero height. +\ifdim\@IEEEtrantmpdimenB=0pt\relax% +\typeout{** WARNING: IEEEPARstart drop letter has zero height! (line \the\inputlineno)}% +\typeout{ Forcing the drop letter font size to 10pt.}% +\@IEEEtrantmpdimenB=10pt% +\fi% +% and store it as a counter +\@IEEEtrantmpcountB=\@IEEEtrantmpdimenB% +% Since a font size doesn't exactly correspond to the height of the capital +% letters in that font, the actual height of the letter, \@IEEEtrantmpcountB, +% will be less than that desired, \@IEEEtrantmpcountA +% we need to raise the font size, \@IEEEtrantmpdimenA +% by \@IEEEtrantmpcountA / \@IEEEtrantmpcountB +% But, TeX doesn't have floating point division, so we have to use integer +% division. Hence the use of the counters. +% We need to reduce the denominator so that the loss of the remainder will +% have minimal affect on the accuracy of the result +\divide\@IEEEtrantmpcountB by 200% +\divide\@IEEEtrantmpcountA by \@IEEEtrantmpcountB% +% Then reequalize things when we use TeX's ability to multiply by +% floating point values +\@IEEEtrantmpdimenB=0.005\@IEEEtrantmpdimenA% +\multiply\@IEEEtrantmpdimenB by \@IEEEtrantmpcountA% +% \@IEEEPARstartfont is globaly set to the calculated font of the big letter +% We need to carry this out of the local calculation area to to create the +% big letter. +\global\font\@IEEEPARstartfont\@IEEEPARstartFONTNAME\space at \@IEEEtrantmpdimenB% +% Now set \@IEEEtrantmpdimenA to the width of the big letter +% We need to carry this out of the local calculation area to set the +% hanging indent +\settowidth{\global\@IEEEtrantmpdimenA}{\@IEEEPARstartfont +\IEEEPARstartCAPSTYLE{#1\IEEEPARstartITLCORRECT}}}% +% end of the isolated calculation environment +\global\IEEEPARstartletwidth\@IEEEtrantmpdimenA\relax% +% add in the extra clearance we want +\advance\@IEEEtrantmpdimenA by \IEEEPARstartSEP\relax% +% add in the optional offset +\advance\@IEEEtrantmpdimenA by \IEEEPARstartHOFFSET\relax% +% V1.7 don't allow negative offsets to produce negative hanging indents +\@IEEEtrantmpdimenB\@IEEEtrantmpdimenA +\ifnum\@IEEEtrantmpdimenB < 0 \@IEEEtrantmpdimenB 0pt\fi +% \@IEEEtrantmpdimenA has the width of the big letter plus the +% separation space and \@IEEEPARstartfont is the font we need to use +% Now, we make the letter and issue the hanging indent command +% The letter is placed in a box of zero width and height so that other +% text won't be displaced by it. +\hangindent\@IEEEtrantmpdimenB\hangafter=-\IEEEPARstartDROPLINES% +\makebox[0pt][l]{\hspace{-\@IEEEtrantmpdimenA}% +\raisebox{-\IEEEPARstartDROPDEPTH}[0pt][0pt]{\hspace{\IEEEPARstartHOFFSET}% +\@IEEEPARstartfont\IEEEPARstartCAPSTYLE{#1\IEEEPARstartITLCORRECT}% +\hspace{\IEEEPARstartSEP}}}% +{\IEEEPARstartWORDFONTSTYLE{\IEEEPARstartWORDCAPSTYLE{\selectfont#2}}}} + + + + + + +% determines if the space remaining on a given page is equal to or greater +% than the specified space of argument one +% if not, execute argument two (only if the remaining space is greater than zero) +% and issue a \newpage +% +% example: \@IEEEtranneedspace{2in}{\vfill} +% +% Does not take into consideration rubber shrinkage, so it tends to +% be overly cautious +% Based on an example posted by Donald Arseneau +% Note this macro uses \@IEEEtrantmpdimenB internally for calculations, +% so DO NOT PASS \@IEEEtrantmpdimenB to this routine +% if you need a dimen register, import with \@IEEEtrantmpdimenA instead +\def\@IEEEtranneedspace#1#2{\penalty-100\begingroup%shield temp variable +\@IEEEtrantmpdimenB\pagegoal\advance\@IEEEtrantmpdimenB-\pagetotal% space left +\ifdim #1>\@IEEEtrantmpdimenB\relax% not enough space left +\ifdim\@IEEEtrantmpdimenB>\z@\relax #2\fi% +\newpage% +\fi\endgroup} + + +% \IEEEauthorrefmark +\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{\ifcase#1\or *\or \dagger\or \ddagger\or% + \mathsection\or \mathparagraph\or \|\or **\or \dagger\dagger% + \or \ddagger\ddagger \else\textsuperscript{\expandafter\romannumeral#1}\fi}}}} + + +% V1.3 IEEEQED and IEEEproof +\def\IEEEproofname{Proof} + +\def\IEEEQEDclosed{\mbox{\rule[0pt]{1.3ex}{1.3ex}}} % for a filled box +\def\IEEEQEDopen{{\setlength{\fboxsep}{0pt}\setlength{\fboxrule}{0.2pt}\fbox{\rule[0pt]{0pt}{1.3ex}\rule[0pt]{1.3ex}{0pt}}}} +\def\IEEEQED{\IEEEQEDclosed} % default to closed + +%V1.8 flag to indicate if QED symbol is to be shown +\newif\if@IEEEQEDshow \@IEEEQEDshowtrue +\def\IEEEproofindentspace{2\parindent}% V1.8 allow user to change indentation amount if desired +% v1.7 name change to avoid namespace collision with amsthm. Also add support +% for an optional argument. +\def\IEEEproof{\@ifnextchar[{\@IEEEproof}{\@IEEEproof[\IEEEproofname]}} +\def\@IEEEproof[#1]{\@IEEEQEDshowtrue\par\noindent\hspace{\IEEEproofindentspace}{\itshape #1: }} +\def\endIEEEproof{\if@IEEEQEDshow\hspace*{\fill}\nobreakspace\IEEEQED\fi\par} +% qedhere for equation environments, similar to AMS \qedhere +\def\IEEEQEDhereeqn{\global\@IEEEQEDshowfalse\eqno\let\eqno\relax\let\leqno\relax + \let\veqno\relax\hbox{\IEEEQED}} +% IEEE style qedhere for IEEEeqnarray and other environments +\def\IEEEQEDhere{\global\@IEEEQEDshowfalse\IEEEQED} +% command to disable QED at end of IEEEproof +\def\IEEEQEDoff{\global\@IEEEQEDshowfalse} + + +% Provide support for the control entries of IEEEtran.bst V1.00 and later. +% V1.7 optional argument allows for a different aux file to be specified in +% order to handle multiple bibliographies. For example, with multibib.sty: +% \newcites{sec}{Secondary Literature} +% \bstctlcite[@auxoutsec]{BSTcontrolhak} +% V1.7 I see no need for \providecommand here. +\def\bstctlcite{\@ifnextchar[{\@bstctlcite}{\@bstctlcite[@auxout]}} +\def\@bstctlcite[#1]#2{\@bsphack + \@for\@citeb:=#2\do{% + \edef\@citeb{\expandafter\@firstofone\@citeb}% + \if@filesw\immediate\write\csname #1\endcsname{\string\citation{\@citeb}}\fi}% + \@esphack} + +% \IEEEnoauxwrite{} allows for citations that do not add to or affect +% the order of the existing citation list. Can be useful for \cite +% within \thanks{}. +\DeclareRobustCommand{\IEEEnoauxwrite}[1]{\relax +\if@filesw +\@fileswfalse +#1\relax\relax\relax\relax\relax +\@fileswtrue +\else +#1\relax\relax\relax\relax\relax +\fi} + +% need a backslash character for typeout output +{\catcode`\|=0 \catcode`\\=12 +|xdef|@IEEEbackslash{\}} + + +% hook to allow easy disabling of all legacy warnings +\def\@IEEElegacywarn#1#2{\typeout{** ATTENTION: \@IEEEbackslash #1 is deprecated (line \the\inputlineno). +Use \@IEEEbackslash #2 instead.}} + + +% V1.4 no longer support these legacy commands +% \def\PARstart{\@IEEElegacywarn{PARstart}{IEEEPARstart}\IEEEPARstart} +% \let\labelindent\IEEElabelindent +% \def\calcleftmargin{\@IEEElegacywarn{calcleftmargin}{IEEEcalcleftmargin}\IEEEcalcleftmargin} +% \def\setlabelwidth{\@IEEElegacywarn{setlabelwidth}{IEEEsetlabelwidth}\IEEEsetlabelwidth} +% \def\usemathlabelsep{\@IEEElegacywarn{usemathlabelsep}{IEEEusemathlabelsep}\IEEEusemathlabelsep} +% \def\iedlabeljustifyc{\@IEEElegacywarn{iedlabeljustifyc}{IEEEiedlabeljustifyc}\IEEEiedlabeljustifyc} +% \def\iedlabeljustifyl{\@IEEElegacywarn{iedlabeljustifyl}{IEEEiedlabeljustifyl}\IEEEiedlabeljustifyl} +% \def\iedlabeljustifyr{\@IEEElegacywarn{iedlabeljustifyr}{IEEEiedlabeljustifyr}\IEEEiedlabeljustifyr} + + +\endinput +%%%%%%%%%%%%%%%%%%%%%%%%%% End of IEEEtrantools.sty %%%%%%%%%%%%%%%%%%%%%% +% That's all folks! + diff --git a/pkg/abort.sty b/pkg/abort.sty new file mode 100644 index 0000000..872c418 --- /dev/null +++ b/pkg/abort.sty @@ -0,0 +1,40 @@ +% automaticlaly generated via "python3 abortCallCreate.py > abort.sty" + + +% call Stack Depth abort columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\csdAbortSH}{\texttt{callStackDepthAbort}} % short hand for the snail case name +\newcommand{\csdABORT}{\col{CALL\_STACK\_DEPTH\_ABORT}} +\newcommand{\csdAbort}{\col{CSDABORT}} + + + +% insufficient Balance abort columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\balAbortSH}{\texttt{insufficientBalanceAbort}} % short hand for the snail case name +\newcommand{\balABORT}{\col{INSUFFICIENT\_BALANCE\_ABORT}} +\newcommand{\balAbort}{\col{BALABORT}} + + + +% precompile Failure Condition abort columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\precAbortSH}{\texttt{precompileFailureConditionAbort}} % short hand for the snail case name +\newcommand{\precABORT}{\col{PRECOMPILE\_FAILURE\_CONDITION\_ABORT}} +\newcommand{\precAbort}{\col{PRECABORT}} + + + +% account Isnt Dead abort columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\deadAbortSH}{\texttt{accountIsntDeadAbort}} % short hand for the snail case name +\newcommand{\deadABORT}{\col{ACCOUNT\_ISNT\_DEAD\_ABORT}} +\newcommand{\deadAbort}{\col{DEADABORT}} + + + + diff --git a/pkg/abortCallCreate.py b/pkg/abortCallCreate.py new file mode 100644 index 0000000..1374d73 --- /dev/null +++ b/pkg/abortCallCreate.py @@ -0,0 +1,47 @@ +""" +e.g.: + +\newcommand{\oogxSc}{\texttt{outOfGasException}} % snail case name +\newcommand{\oogx}{\col{OOGX}} +\newcommand{\oogxFull}{\col{OUT\_OF\_GAS\_EXCEPTION}} + +""" + + +exceptions = { + # aborting conditions + "csd": "call Stack Depth", + "bal": "insufficient Balance", + "prec": "precompile Failure Condition", + "dead": "account Isnt Dead", +} + +def exception_macros(s): + + f = exceptions[s] + fsc = f.replace(" ", "") # f in snail case + fcu = f.replace(" ", "\\_").upper() # f capitalized, underscores + S = s[0].upper() + s[1:] + + res = f"% {f} abort columns:\n" + res += len(res) * "%" + res += "\n\n" + res += f"\\newcommand{{\\{s}AbortSH}}{{\\texttt{{{fsc}Abort}}}} % short hand for the snail case name\n" + res += f"\\newcommand{{\\{s}ABORT}}{{\\col{{{fcu}\\_ABORT}}}}\n" + res += f"\\newcommand{{\\{s}Abort}}{{\\col{{{s.upper()}ABORT}}}}\n" + res += "\n\n\n" + + return res + + +def all_commands(): + + res = "" + res += "% automaticlaly generated via \"python3 abortCallCreate.py > abort.sty\"\n\n\n" + + for name in exceptions: + res += exception_macros(name) + + print(res) + +all_commands() \ No newline at end of file diff --git a/pkg/access.sty b/pkg/access.sty new file mode 100644 index 0000000..d6074fd --- /dev/null +++ b/pkg/access.sty @@ -0,0 +1,22 @@ +% \usepackage{emoji} +% \setemojifont{TwemojiMozilla} +%\newcommand{\fire}{\emoji{fire}} +%\newcommand{\fire}{\emoji{🔥}} +\newcommand{\fire}{🔥} + +\newcommand{\accessStamp}{\col{ACCESS\_STAMP}} +\newcommand{\accessFlag}{\col{ACCESS\_FLAG}} % access stamp, triggered by every call / create etc ... + +\newcommand{\WARM}{\col{ADDRESS\_IS\_WARM}} % +\newcommand{\warm}{\col{WARM}} + +\newcommand{\PREWARMEDADDR}{\col{TX\_PREWARMED\_ADDRESS}} % +\newcommand{\preWarmedAddr}{\col{PREWARMED\_ADDR}} + +\newcommand{\KEY}{\col{STORAGE\_KEY}} % storage key +\newcommand{\key}{\col{KEY}} + +\newcommand{\PREWARMSKEYS}{\col{HAS\_PREWARMED\_STORAGE\_KEYS}} +\newcommand{\preWarmsKeys}{\col{PREWARMED\_KEY}} + +\newcommand{\txDep}{\col{TX\_DEP}} \ No newline at end of file diff --git a/pkg/account.sty b/pkg/account.sty new file mode 100644 index 0000000..c5323b0 --- /dev/null +++ b/pkg/account.sty @@ -0,0 +1,52 @@ +\newcommand{\sourceAddr}{\imported{\col{SADDR}}} +\newcommand{\targetAddr}{\imported{\col{TADDR}}} +\newcommand{\sourceBal}{\col{SBAL}} +\newcommand{\targetBal}{\col{TBAL}} +\newcommand{\balance}{\col{BAL}} +\newcommand{\transferValue}{\col{VAL}} +\newcommand{\sourceNonce}{\col{NONCE}} +\newcommand{\willFail}{\col{WILL\_FAIL}} +\newcommand{\iInstOutput}{\imported{\col{OUT}}} +% \newcommand{\iValHi}{\imported{\transferValue\high}} +% \newcommand{\iValLo}{\imported{\transferValue\low}} +% \newcommand{}{\col{}} +\newcommand{\txInit}{\col{TX\_INIT}} +\newcommand{\txExec}{\col{TX\_EXEC}} +\newcommand{\txTerm}{\col{TX\_TERM}} +\newcommand{\gasEndowment}{\col{T}_{\col{g}}} +\newcommand{\gasPrice}{\col{T}_{\col{p}}} +\newcommand{\iGasEndowment}{\imported{\gasEndowment}} +\newcommand{\iGasPrice}{\imported{\gasPrice}} + +\newcommand{\From}{\col{FROM}} +\newcommand{\To}{\col{TO}} +\newcommand{\Val}{\col{VAL}} +\newcommand{\Nonce}{\col{NONCE}} + +\newcommand{\iFrom}{\imported{\From}} +\newcommand{\iTo}{\imported{\To}} +\newcommand{\iCType}{\imported{\CType}} + +\newcommand{\ts}{S(T)} +%\renewcommand{\tt}{\col{T}_{\col{t}}} +%\newcommand{\tv}{\col{T}_{\col{v}}} +%\newcommand{\tn}{\col{T}_{\col{n}}} +%\newcommand{\tg}{\col{T}_{\col{g}}} +%\newcommand{\tp}{\col{T}_{\col{p}}} +%\newcommand{\txType}{\col{T}_{\col{x}}} +\renewcommand{\tt}{\col{T[t]}} +\newcommand{\tv}{\col{T[v]}} +\newcommand{\tn}{\col{T[n]}} +\newcommand{\tg}{\col{T[g]}} +\newcommand{\tp}{\col{T[p]}} +\newcommand{\txType}{\col{T[x]}} +\newcommand{\iTs}{\imported{\ts}} +\newcommand{\iTt}{\imported{\tt}} +\newcommand{\iTv}{\imported{\tv}} +\newcommand{\iTn}{\imported{\tn}} +\newcommand{\iTg}{\imported{\tg}} +\newcommand{\iTp}{\imported{\tp}} + +\newcommand{\dataGasCost}{\col{DATA\_COST}} +\newcommand{\warmGasCost}{\col{WARM\_COST}} +\newcommand{\initGas}{\col{INIT\_GAS}} diff --git a/pkg/alu.sty b/pkg/alu.sty new file mode 100644 index 0000000..1afb292 --- /dev/null +++ b/pkg/alu.sty @@ -0,0 +1,51 @@ +\newcommand{\CMP}{\col{CMP}} +\newcommand{\cmp}[1]{\col{CMP\_#1}} +\newcommand{\msb}[1]{\col{MSB\_#1}} +\newcommand{\overflow}{\col{OF}} +\newcommand{\of}[1]{\col{OF\_#1}} +\newcommand{\instSigned}{\col{SIGNED}} +\newcommand{\instOutput}{\col{OUTPUT}} +\newcommand{\decInstSigned}{\decoded{\instSigned}} +\newcommand{\decInstOutput}{\decoded{\instOutput}} +\newcommand{\SNM}{\col{SQUARE\_AND\_MULTIPLY}} +\newcommand{\snm}{\col{S\&M}} +\newcommand{\mul}{\col{MUL}} +\newcommand{\EXPBITSRC}{\col{EXPONENT\_BIT\_SOURCE}} +\newcommand{\expBitSrc}{\col{ESRC}} +\newcommand{\EXPBIT}{\col{EXPONENT\_BIT}} +\newcommand{\expBit}{\col{EBIT}} +\newcommand{\EXPBITACC}{\col{EXPONENT\_BIT\_ACCUMULATOR}} +\newcommand{\expBitAcc}{\col{EACC}} +\newcommand{\RESVANISHES}{\col{RESULT\_VANISHES}} +\newcommand{\resVanishes}{\col{RESV}} +\newcommand{\witness}{\col{WITNESS}} + +\newcommand{\TINYBASE}{\col{TINY\_BASE}} +\newcommand{\tinyBase}{\col{TINYB}} +\newcommand{\TINYEXPONENT}{\col{TINY\_EXPONENT}} +\newcommand{\tinyExponent}{\col{TINYE}} + +\newcommand{\nBits}{\col{BIT\_NUM}} + + +\newcommand{\aHi}{\col{A}\high} +\newcommand{\aLo}{\col{A}\low} +\newcommand{\bHi}{\col{B}\high} +\newcommand{\bLo}{\col{B}\low} +\newcommand{\qHi}{\col{Q}\high} +\newcommand{\qLo}{\col{Q}\low} +\newcommand{\rHi}{\col{R}\high} +\newcommand{\rLo}{\col{R}\low} + +\newcommand{\setNegative}{\texttt{setNegative}} +\newcommand{\setAddition}{\texttt{setAddition}} +\newcommand{\setSubtraction}{\texttt{setSubtraction}} +\newcommand{\setMultiplication}{\texttt{setMultiplication}} +\newcommand{\setAbsoluteValue}{\texttt{setAbsoluteValue}} +\newcommand{\prepareLowerBoundOnTwoAdicity}{\texttt{prepareLowerBoundOnTwoAdicity}} + +\newcommand{\oneTwoSeven}{\red{127}} +\newcommand{\oneTwoEight}{\red{128}} + +\newcommand{\mmedium}{\red{8}} +\newcommand{\mmediumMO}{\red{7}} diff --git a/pkg/alu_old.sty b/pkg/alu_old.sty new file mode 100644 index 0000000..1e14d40 --- /dev/null +++ b/pkg/alu_old.sty @@ -0,0 +1,20 @@ +\newcommand{\aluDispatcher}{\col{DISP}} +\newcommand{\stepFlag}{\col{STEP\_FLAG}} +\newcommand{\stepCounter}{\col{STEP\_COUNTER}} +\newcommand{\remainder}{\col{REM}} +\newcommand{\carryRes}{\col{CARRY\_RES}} +\newcommand{\overflowSum}{\col{OVERFLOW\_SUM}} +\newcommand{\overflowFlag}{\col{OVERFLOW\_FLAG}} +\newcommand{\result}{\col{OUT}} +\newcommand{\inputAlu}{\col{ARG}} +\newcommand{\dividend}{\col{DIVIDEND}} +%\newcommand{\quotient}{\col{QUOT}} +%\newcommand{\decAddFlag}{\decoded{\col{ADD\_FLAG}}} +%\newcommand{\decMulFlag}{\decoded{\col{MUL\_FLAG}}} +\newcommand{\decSubFlag}{\decoded{\col{SUB\_FLAG}}} +\newcommand{\decDivFlag}{\decoded{\col{DIV\_FLAG}}} +\newcommand{\decSdivFlag}{\decoded{\col{SDIV\_FLAG}}} +%\newcommand{\decModFlag}{\decoded{\col{MOD\_FLAG}}} +\newcommand{\decSmodFlag}{\decoded{\col{SMOD\_FLAG}}} +\newcommand{\decAddmodFlag}{\decoded{\col{ADDMOD\_FLAG}}} +\newcommand{\decExpFlagAlu}{\decoded{\col{EXP\_FLAG}}} \ No newline at end of file diff --git a/pkg/batch_data.sty b/pkg/batch_data.sty new file mode 100644 index 0000000..c959815 --- /dev/null +++ b/pkg/batch_data.sty @@ -0,0 +1,24 @@ +\newcommand{\relTxMax} {\col{REL\_TX}^\infty} +\newcommand{\relTx} {\col{REL\_TX}} +\newcommand{\relBlock} {\col{REL\_BLOCK}} +\newcommand{\absBlock} {\col{ABS\_BLOCK}} + + +%\newcommand{\coinbase} {\col{COINBASE}} +\newcommand{\blockGasLimit} {\col{BLOCK\_GAS\_LIMIT}} +\newcommand{\basefee} {\col{BASEFEE}} + +\newcommand{\lineaChainId} {\redm{\texttt{LINEA\_CHAIN\_ID}}} +\newcommand{\lineaBaseFee} {\redm{\texttt{LINEA\_BASE\_FEE}}} +\newcommand{\lineaDifficulty} {\redm{\texttt{LINEA\_DIFFICULTY}}} + +\newcommand{\maxCtBtcData} {\redm{7}} + +\newcommand{\rowShiftCoinbase} {\redm{0}} +\newcommand{\rowShiftTimestamp} {\redm{1}} +\newcommand{\rowShiftNumber} {\redm{2}} +\newcommand{\rowShiftDifficulty} {\redm{3}} +\newcommand{\rowShiftPrevandao} {\redm{3}} +\newcommand{\rowShiftGaslimit} {\redm{4}} +\newcommand{\rowShiftChainId} {\redm{5}} +\newcommand{\rowShiftBaseFee} {\redm{6}} diff --git a/pkg/bin.sty b/pkg/bin.sty new file mode 100644 index 0000000..63a5bc5 --- /dev/null +++ b/pkg/bin.sty @@ -0,0 +1,161 @@ +% BINARY MODULE + + +\newcommand{\isAnd} {\col{IS\_AND}} +\newcommand{\isOr} {\col{IS\_OR}} +\newcommand{\isXor} {\col{IS\_XOR}} +\newcommand{\isNot} {\col{IS\_NOT}} +\newcommand{\isByte} {\col{IS\_BYTE}} +\newcommand{\isSignextend} {\col{IS\_SIGNEXTEND}} + +%\newcommand{\CT}{\col{COUNTER}} +%\newcommand{\ct}{\col{CT}} +\newcommand{\BS}{\col{BINARY\_STAMP}} +\newcommand{\bs}{\col{BS}} +\newcommand{\MSHP}{\col{MICRO\_SHIFT\_PARAM}} % micro shift parameter +\newcommand{\mshp}{\col{$\mu$SHP}} +\newcommand{\LT}{\col{LOW\_3}} % not a column but still used from time to time +\newcommand{\IRF}{\col{IN\_RANGE\_FLAG}} % shift parameter in range flag +\newcommand{\irf}{\col{IRF}} +\newcommand{\MSHF}{\col{$\mu$SHIFT\_FLAG}} +\newcommand{\mshf}{\col{$\mu$SHF}} +\newcommand{\SHF}{\col{SHIFT\_FLAG}} +\newcommand{\shf}{\col{SHF}} +\newcommand{\ZB}{\col{ZERO\_BACP}} +\newcommand{\zb}{\col{ZB}} +\newcommand{\ZP}{\col{ZERO\_BACP\_PARAM}} +\newcommand{\zp}{\col{ZP}} +\newcommand{\SHD}{\col{SHIFT\_DIRECTION}} +\newcommand{\shd}{\col{SHD}} +\newcommand{\IO}{\col{INPUT\_1}} +\newcommand{\io}{\col{I1}} +\newcommand{\IT}{\col{INPUT\_2}} +\renewcommand{\it}{\col{I2}} +\newcommand{\R}{\col{RES}} +\newcommand{\PB}{\col{PIVOT\_BYTE}} +\newcommand{\pb}{\col{PB}} +\newcommand{\BO}{\col{BYTE\_1}} +\newcommand{\bo}{\col{B1}} +\newcommand{\BT}{\col{BYTE\_2}} +\newcommand{\bt}{\col{B2}} +\newcommand{\BR}{\col{BYTE\_RES}} +\newcommand{\br}{\col{BR}} +\newcommand{\PO}{\col{PREFIX\_1}} +\newcommand{\po}{\col{P1}} +\newcommand{\PT}{\col{PREFIX\_2}} +\newcommand{\pt}{\col{P2}} +\newcommand{\PR}{\col{PREFIX\_RES}} +\newcommand{\pr}{\col{PR}} +\newcommand{\BB}{\col{BYTE\_BITS}} +\newcommand{\bb}{\col{BB}} +\newcommand{\DB}{\col{DECISION\_BIT}} +\newcommand{\db}{\col{DB}} +\newcommand{\NEG}{\col{NEG}} % should rename it to SIGN_BIT / SGN +\newcommand{\negCol}[1]{\col{NEG\_#1}} +\newcommand{\eqHi}{\bit{\col{eq\_hi}}} +\newcommand{\eqLo}{\bit{\col{eq\_lo}}} +\newcommand{\gtHi}{\bit{\col{gt\_hi}}} +\newcommand{\gtLo}{\bit{\col{gt\_lo}}} +\newcommand{\SNSP}{\decoded{\col{SPLIT\_AND\_SHIFTED\_PREFIX}}} +\newcommand{\snsp}{\decoded{\col{SNS\_PREFIX}}} +\newcommand{\SNSS}{\decoded{\col{SPLIT\_AND\_SHIFTED\_SUFFIX}}} +\newcommand{\snss}{\decoded{\col{SNS\_SUFFIX}}} +\newcommand{\ONES}{\decoded{\col{ONES}}} +\newcommand{\SGNXF}{\col{SIGNEXTEND\_FLAG}} +\newcommand{\sgnxf}{\col{SGNXF}} +\newcommand{\PIVF}{\col{PIVOT\_FLAG}} +\newcommand{\pivf}{\col{PF}} +%\newcommand{\INST}{\col{INST}} +\newcommand{\ANDF}{\col{AND\_FLAG}} +\newcommand{\andf}{\col{ANDF}} +\newcommand{\ORF}{\col{OR\_FLAG}} +\newcommand{\orf}{\col{ORF}} +\newcommand{\XORF}{\col{XOR\_FLAG}} +\newcommand{\xorf}{\col{XORF}} +\newcommand{\NOTF}{\col{NOT\_FLAG}} +\newcommand{\notf}{\col{NOTF}} +\newcommand{\SARF}{\col{SAR\_FLAG}} +\newcommand{\sarf}{\col{SARF}} +\newcommand{\LEADINGBIT}{\col{LEADING\_BIT}} +\newcommand{\leadingBit}{\col{LB}} +\newcommand{\decXXX}[1]{\decoded{\col{XXX\_BYTE\_#1}}} +\newcommand{\decAND}[1]{\decoded{\col{AND\_BYTE\_#1}}} +\newcommand{\decNOT}[1]{\decoded{\col{NOT\_BYTE\_#1}}} +\newcommand{\decOR}[1]{\decoded{\col{OR\_BYTE\_#1}}} +\newcommand{\decXOR}[1]{\decoded{\col{XOR\_BYTE\_#1}}} +\newcommand{\lowFour}{\col{LOW\_4}} +\newcommand{\smallness}{\col{SMALL}} +\newcommand{\pivotByte}{\col{PIVOT}} + +\newcommand{\sgnxParam}{\mathsf{p}} + +\newcommand{\SGNX}{\inst{SIGNEXTEND}} +\newcommand{\sgnx}{\inst{SGNX}} + +\newcommand{\BIT}[1]{\col{BIT\_{#1}}} +%\newcommand{\bit}[1]{[\![{#1}]\!]} +%\newcommand{\negbit}[1]{\bit{#1}^\vee} + +\newcommand{\LSB}{\texttt{LSB}} + +\newcommand{\binc}[1]{{#1}_i\cdot(1-{#1}_i) = 0} + +\newcommand{\constantBs}[2]{% +\begin{tikzpicture} +\draw[fill=#2] (0, 0) rectangle (1, -3); +\draw (0.5, -0.25) node {#1}; +\draw (0.5, -1.5) node {$\vdots$}; +\draw (0.5, -2.75) node {#1}; +\end{tikzpicture} +} + + +\def\lightGreen{solarized-green!75} + +\newcommand{\bsAndZeros}{% +\begin{tikzpicture} + \draw[fill=\lightGreen] (0, 0) rectangle (1, -1.5); + \draw (0,-1.5) rectangle (1, -3); + % zeros + \draw (0.5, -0.25) node {0}; + \draw (0.5, -0.75) node {$\vdots$}; + \draw (0.5, -1.25) node {0}; + % lsb bits + \draw (0.5, -1.75) node {$\texttt{LSB}_7$}; + \draw (0.5, -2.25) node {$\vdots$}; + \draw (0.5, -2.75) node {$\texttt{LSB}_0$}; +\end{tikzpicture}} + +\def\zeros{% +\begin{tikzpicture}[scale=1] + \draw[fill=\lightGreen] (0, 0) rectangle (1, -3); +\end{tikzpicture}} + +\def\intensity{20} + +\def\nscdot{\!\!\!\!\!\cdot\!\!\!\!\!} % no space \cdot +\def\nsplus{\!\!\!\!\!+\!\!\!\!\!} % no space + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% SIGNEXTEND full COUNTER-cycle % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\def\sepr{3.5} +\def\colH{1.15} +\def\colV{0.6} +\def\hori{1} +\def\verti{0.45} +\def\fullCol{(1-\colH, 1-\colV) rectangle (1+\colH, 32+\colV)} +\newcommand{\cell}[1]{(1-\hori, #1-\verti) rectangle (1+\hori, #1+\verti)} % rectangular cell +\newcommand{\cnt}[2]{(1, #1) node {#2}} % cell content +\def\psepr{\p*\sepr} +\def\shift{\draw[shift={(\psepr, 0)}]} +\newcommand{\shiftfill}[1]{\draw[shift={(\psepr, 0)}, fill=#1]} +\newcommand{\colName}[1]{\shift \cnt{33.2}{#1};} % column name +\newcommand{\colCarOne}[1]{\shift \cnt{-0.2}{\textit{#1}};} % column caracteristics +\newcommand{\colCarTwo}[1]{\shift \cnt{-1.2}{\textit{#1}};} % column caracteristics + +\newcommand{\hyp}[1]{\fcolorbox{red}{yellow}{#1}} + +\newcommand{\opRequiresByteDecomposition} {\col{op\_requires\_byte\_decomposition}} diff --git a/pkg/block_hash.sty b/pkg/block_hash.sty new file mode 100644 index 0000000..6baa90b --- /dev/null +++ b/pkg/block_hash.sty @@ -0,0 +1,9 @@ +\newcommand{\blockNumberOfFirstBlockInConflation} {\col{FIRST\_BLOCK\_NUMBER}} +\newcommand{\blockShift} {\col{BLOCK\_SHIFT}} +\newcommand{\blockNumber} {\col{BLOCK\_NUMBER}} +\newcommand{\blockHash} {\col{BLOCK\_HASH}} +\newcommand{\lowerBoundCheck} {\col{LOWER\_BOUND\_CHECK}} +\newcommand{\upperBoundCheck} {\col{UPPER\_BOUND\_CHECK}} +\newcommand{\inRange} {\col{IN\_RANGE}} + +\newcommand{\blockHashInstMaxHistory} {\redm{256}} diff --git a/pkg/bytecode0 b/pkg/bytecode0 new file mode 100644 index 0000000..19864eb --- /dev/null +++ b/pkg/bytecode0 @@ -0,0 +1,47 @@ +60 60 PUSH1 60 |60] +60 40 PUSH1 40 |60|40] +52 MSTORE |] +34 CALLVALUE |val] +15 ISZERO |(val == 0)] +60 0e PUSH1 0e |(val == 0)|0e] +57 JUMPI |] // we jump to 0e if (val == 00); if (val != 0) we continue +60 00 PUSH1 00 |00] +80 DUP1 |00|00] +fd REVERT |] -> exit the program as if nothing happened +----------------------------------- // potential exit point +5b JUMPDEST // byte offset = 0x0e = 14 (decimal) (we start counting at 0) +5b JUMPDEST // serves no discernable purpose +60 01 PUSH1 01 |01] +60 00 PUSH1 00 |01|00] +81 DUP2 |01|00|01] +90 SWAP1 |01|01|00] +55 SSTORE |01] // stored 01 at address 00 +50 POP | +5b JUMPDEST (nothing happens) +5b JUMPDEST (nothing happens) +60 36 PUSH1 36 |36] +80 DUP1 |36|36] +60 26 PUSH1 26 |36|36|26] +60 00 PUSH1 00 |36|36|26|00] // 36 | size | codeOffset | destOffset ] +39 CODECOPY |36] // copying code from ROM +60 00 PUSH1 00 |36|00] +f3 RETURN // return 0x36 = 54 bytes from RAM starting at offset 0x26 = 38 +00 STOP // offset <- fucking nailed it ^^ +=================================== // end of init code +=================================== \\ start of actual bytecode to deploy ... +60 60 PUSH1 60 +60 40 PUSH1 40 +52 MSTORE +5b JUMPDEST +60 00 PUSH1 00 +80 DUP1 +fd REVERT +00 STOP +=================================== // 11 bytes so far +=================================== \\ 43 bytes below; 11 + 43 = 54! We copy this shit into the bytecode ... what the hell ? It's not runnable! The 10th byte, af, it's not an opcode ... +auxData: +0xa165627a7a72305820af3193f6fd31031a0e0d2de1ad2c27352b1ce081b4f3c92b5650ca4dd542bb770029 +a1 65 +62 7a 7a 72 30 // b z z 0 r +5820af3193f6fd31031a0e0d2de1ad2c27352b1ce081b4f3c92b5650ca4dd542bb77 +00 29 \ No newline at end of file diff --git a/pkg/call_stack.sty b/pkg/call_stack.sty new file mode 100644 index 0000000..5397329 --- /dev/null +++ b/pkg/call_stack.sty @@ -0,0 +1,131 @@ +% call stack +\newcommand{\TXNUM}{\col{RELATIVE\_TRANSACTION\_NUMBER}} % \geq 0, context ``number'' +\newcommand{\txNum}{\col{REL\_TX\_NUM}} +\newcommand{\relTxNumMax}{\txNum^\infty} +\newcommand{\iTxNum}{\imported{\txNum}} + +\newcommand{\ABSTXNUM}{\col{ABSOLUTE\_TRANSACTION\_NUMBER}} +\newcommand{\TOTTXNUM}{\col{TOTAL\_TRANSACTION\_NUMBER}} +\newcommand{\absTxNum}{\col{ABS\_TX\_NUM}} +\newcommand{\absTxNumMax}{\col{ABS\_TX\_NUM}^\infty} +% +\newcommand{\outgoingDataSymb} {\col{OUTGOING}} +\newcommand{\outgoingData} [1] {\outgoingDataSymb\col{\_#1}} +\newcommand{\outgoingDataHi} {\outgoingDataSymb\col{\_HI}} +\newcommand{\outgoingDataLo} {\outgoingDataSymb\col{\_LO}} + +\newcommand{\oobCallToAdd } [6] {\texttt{callToADD} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument one high:} & #3 \\ + \utt{Argument one low:} & #4 \\ + \utt{Argument two high:} & #5 \\ + \utt{Argument two low:} & #6 \\ +\end{array} \right]} +\newcommand{\oobCallToDiv } [6] {\texttt{callToDIV} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Dividend high:} & #3 \\ + \utt{Dividend low:} & #4 \\ + \utt{Divisor high:} & #5 \\ + \utt{Divisor low:} & #6 \\ +\end{array} \right]} +\newcommand{\oobCallToMod } [6] {\texttt{callToMOD} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Dividend high:} & #3 \\ + \utt{Dividend low:} & #4 \\ + \utt{Divisor high:} & #5 \\ + \utt{Divisor low:} & #6 \\ +\end{array} \right]} +\newcommand{\oobCallToEq } [6] {\texttt{callToEQ} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument one high:} & #3 \\ + \utt{Argument one low:} & #4 \\ + \utt{Argument two high:} & #5 \\ + \utt{Argument two low:} & #6 \\ +\end{array} \right]} +\newcommand{\oobCallToLt } [6] {\texttt{callToLT} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Left hand side high:} & #3 \\ + \utt{Left hand side low:} & #4 \\ + \utt{Right hand side high:} & #5 \\ + \utt{Right hand side low:} & #6 \\ +\end{array} \right]} +\newcommand{\oobCallToGt } [6] {\texttt{callToGT} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Left hand side high:} & #3 \\ + \utt{Left hand side low:} & #4 \\ + \utt{Right hand side high:} & #5 \\ + \utt{Right hand side low:} & #6 \\ +\end{array} \right]} +\newcommand{\oobCallToIszero} [4] {\texttt{callToISZERO} _{#1} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument high:} & #3 \\ + \utt{Argument low:} & #4 \\ +\end{array} \right]} +\newcommand{\oobNoCall} [2] {\texttt{noCall} _{#1} \big[ \utt{Rel. row offset:} \; #2 \big]} + +\newcommand{\phaseNum}{\col{PHASE}} + +\newcommand{\CN}{\col{CONTEXT\_NUMBER}} % \geq 0, context ``number'' +\newcommand{\cn}{\col{CN}} + +\newcommand{\CTYPE}{\col{CONTEXT\_TYPE}} % binary flag that equals 1 for init code and zero otherwise +\newcommand{\cType}{\col{CTYPE}} + +\newcommand{\CSTAT}{\col{CONTEXT\_STATIC}} % binary flag that equals 1 for init code and zero otherwise +\newcommand{\staticContext}{\col{STATIC\_CN}} +% staticContext + +\newcommand{\CALLER}{\col{CALLER\_CONTEXT}} +\newcommand{\caller}{\col{CALLER\_CONTEXT\_NUMBER}} +% \newcommand{\CDO}{\col{CALLDATA\_OFFSET}} % offset in the caller's RAM +% \newcommand{\cdo}{\col{CDO}} +% \newcommand{\CDS}{\col{CALLDATA\_SIZE}} +% \newcommand{\cds}{\col{CDS}} + +\newcommand{\RETATOFF}{\col{RETURN@OFFSET}} +\newcommand{\retAtOff}{\col{R@O}} +\newcommand{\CODEADDR}{\col{BYTECODE\_ADDRESS}} +\newcommand{\codeAddr}{\col{BC\_ADDR}} +\newcommand{\STORAGEADDR}{\col{STORAGE\_ADDRESS}} +\newcommand{\storageAddr}{\col{STO\_ADDR}} + +\newcommand{\RETATCAP}{\col{RETURN@CAPACITY}} +\newcommand{\retAtCap}{\col{R@C}} + +\newcommand{\RETURNER}{\col{RETURN\_CONTEXT}} +\newcommand{\returner}{\col{RETURN\_DATA\_CONTEXT\_NUMBER}} +% \newcommand{\RDO}{\col{RETURNDATA\_OFFSET}} % offset in the returner's RAM +% \newcommand{\rdo}{\col{RDO}} +% \newcommand{\RDS}{\col{RETURNDATA\_SIZE}} +% \newcommand{\rds}{\col{RDS}} + +\newcommand{\CRC}{\col{CONTEXT\_REVERTS\_BY\_CHOICE}} +\newcommand{\crc}{\col{CREVC}} + +\newcommand{\CRF}{\col{CONTEXT\_REVERTS\_BY\_FORCE}} +\newcommand{\crf}{\col{CREVF}} + +\newcommand{\COOG}{\col{CONTEXT\_RUNS\_OUT\_OF\_GAS}} +\newcommand{\coog}{\col{COOG}} + +\newcommand{\CERR}{\col{CONTEXT\_ERROR}} +\newcommand{\cerr}{\col{CERR}} + +\newcommand{\CREV}{\col{CONTEXT\_REVERTS}} +\newcommand{\crev}{\col{CREV}} + +\newcommand{\CREVST}{\col{CONTEXT\_REVERT\_STORAGE\_STAMP}} +\newcommand{\crevst}{\col{CREVST}} + +\newcommand{\MAXC}{\col{MAXIMUM\_CONTEXT}} +\newcommand{\maxCn}{\col{MAX\_CN}} + +\newcommand{\CSTACKXFLAG}{\col{CALLSTACK\_EXCEPTION\_FLAG}} +\newcommand{\cstackXFlag}{\col{CS}\mathscr{X}\col{F}} diff --git a/pkg/column_generator.py b/pkg/column_generator.py new file mode 100644 index 0000000..1582338 --- /dev/null +++ b/pkg/column_generator.py @@ -0,0 +1,183 @@ +full_names = { + "acc": "account Data", + "add": "adder", + "alu": "alu", + "btc": "block Data", + "blockHash": "block Hash", + "bin": "binary", + "con": "context", + "exp": "exponent", + "euc": "euclidean Division", + "env": "environment", + "ext": "extended Modular Arithmetic", + "gas": "gas", + "hub": "hub", + "kec": "kec", + "log": "log Info", + "mmu": "mmu", + "mmio": "mmio", + "mul": "multiplier", + "mod": "modular Arithmetic", + "mxp": "memory Expansion", + "oob": "out Of Bounds", + "ram": "ram", + "rom": "rom", + "shf": "shift", + "stp": "stipend", + "sto": "storage", + "trm": "address Trimming", + "wcp": "word Comparison", + "wrm": "warmth", + # precompiles + "ecaddD": "ecadd Data", + "ecaddI": "ecadd Info", + "ecmulD": "ecmul Data", + "ecmulI": "ecmul Info", + "idRD": "identity Return Data", + # info / data module pairs + "logInfo": "log Info", + "logData": "log Data", + "hashInfo": "hash Info", + "hashData": "hash Data", + "modexp": "modexp", + "blakeData": "blake Data", + "blake": "blake", + "ecData": "ec Data", + "precInfo": "prec Info", + "txnData": "txn Data", + "txnComp": "txn Comp", + "romLex": "rom Lex", + "shakira": "shakira", + "ripSha": "rip Sha", + "blkMdx": "blk Mdx", + # flags + "txn": "txn", + "stackRam": "stack Ram", + "machineState": "machine State", + "pushPop": "push Pop", + "dup": "dup", + "swap": "swap", + "invalid": "invalid", + # rlp modules + "rlpAddr": "address Rlp", # I'm taking out the d for readability + "rlpTxn": "transaction Rlp", + "rlpTxnRcpt": "transaction Receipt Rlp", + # instruction decoder + "id": "instruction Decoder", +} + +def module_list(): + + ncols = 3 + ncols_string = "3" + + t = "% automaticlaly generated via \"python3 column_generator.py > ../spec/modules.tex\"\n\n" + + l = len(full_names) + s = "\\begin{multicols}{" + ncols_string +"}\n\\begin{enumerate}\n" + + for name in full_names: + s += "\t\\item $\\" + name + "Mod{}$\n" + + if (l % ncols) != 0: + for i in range(ncols - (l % ncols)): + s += "\t\\item[\\vspace{\\fill}]\n" + + s += "\\end{enumerate}\n\\end{multicols}\n" + + print(s) + +def UPPER(s): + s = s.upper() + return s.replace(" ", "\\_") + +def snail(s): + return s[0].upper() + s[1:] + +def three_letter_identifier(short): + + if short == "acc" or short == "log" or short == "exp": + return "\\newcommand{\\" + short + "Mod}{\\col{" + short.upper() + "}}\n\n" + + # s = "" + # s += "\\newcommand{\\" + short + "}{\\col{" + short.upper() + "}}\n\n" + return "\\newcommand{\\" + short + "Mod}{\\col{" + short.upper() + "}}\n\n" + +def stamp_columns(short): + + full = full_names[short] + stamp = "Stamp" + + c = short + stamp + C = short + stamp.upper() + ic = "i" + snail(c) + iC = "i" + snail(C) + s = "" + s += "\\newcommand{\\" + C + "}{\\col{" + UPPER(full) + "\\_" + "STAMP" + "}}\n" + s += "\\newcommand{\\" + c + "}{\\col{" + short.upper() + "}\\stamp}\n" + s += "\\newcommand{\\" + iC + "}{\\imported{\\" + C + "}}\n" + s += "\\newcommand{\\" + ic + "}{\\imported{\\" + c + "}}\n" + s += "\\newcommand{\\" + short + "Rev" + stamp + "}{\\col{" + short.upper() + "}\\stamp\\,\\col{REV}}\n" + s += "\\newcommand{\\i" + snail(short) + "Rev" + stamp + "}{\\imported{\\" + short + "Rev" + stamp + "}}\n" + + return s + + +def flag_columns(short): + + full = full_names[short] + Flag = "Flag" + + c = short + Flag + C = short + Flag.upper() + decc = "dec" + snail(c) + decC = "dec" + snail(C) + s = "" + s += "\\newcommand{\\" + C + "}{\\col{" + UPPER(full) + "\\_" + "FLAG" + "}}\n" + s += "\\newcommand{\\" + c + "}{\\col{" + short.upper() + "}\\" + Flag.lower() + "}\n" + s += "\\newcommand{\\" + decC + "}{\\decoded{\\" + C + "}}\n" + s += "\\newcommand{\\" + decc + "}{\\decoded{\\" + c + "}}\n" + s += "\\newcommand{\\" + "i" + decC + "}{\\imported{\\" + decC + "}}\n" + s += "\\newcommand{\\" + "i" + decc + "}{\\imported{\\" + decc + "}}\n" + + return s + +def selector_columns(short): + + full = full_names[short] + selector = "Select" + + c = short + selector + C = short + selector.upper() + ic = "i" + snail(c) + iC = "i" + snail(C) + s = "" + s += "\\newcommand{\\" + C + "}{\\col{" + UPPER(full) + "\\_" + "SELECTOR" + "}}\n" + s += "\\newcommand{\\" + c + "}{\\col{" + short.upper() + "}\\" + selector.lower() + "}\n" + s += "\\newcommand{\\" + iC + "}{\\imported{\\" + C + "}}\n" + s += "\\newcommand{\\" + ic + "}{\\imported{\\" + c + "}}\n" + s += f'\\newcommand{{\\stackDec{short[0].upper() + short[1:]}Flag}}{{\\stackInstructionDecodedColumn{{\\{short}Flag}}}}\n' + + return s + +def standard_columns_of(s): + + cols = "% " + full_names[s].lower() + " columns:\n" + cols += (2 + len(full_names[s]) + len(" columns:")) * "%" + "\n\n" + cols += three_letter_identifier(s) + cols += stamp_columns(s) + "\n" + cols += flag_columns(s) + "\n" + cols += selector_columns(s) + "\n" + + return cols + +def all_standard_columns(): + t = "% automaticlaly generated via \"python3 column_generator.py > flags_stamps_selectors.sty\"\n\n" + for name in full_names: + t += standard_columns_of(name) + + print(t) + +#module_list() + +all_standard_columns() diff --git a/pkg/common.sty b/pkg/common.sty new file mode 100644 index 0000000..fec7554 --- /dev/null +++ b/pkg/common.sty @@ -0,0 +1,272 @@ +\def\xcolor{Green} + +\usepackage{xcolor-solarized} +%\makeatletter +%\newcommand\solarized@definecolor[2]{\expandafter\definecolor\expandafter{\solarized@prefix #1}{RGB}{#2}} +%\solarized@definecolor{base02}{007, 054, 066} +%\makeatother + +% \definecolor{myBGcolor}{HTML}{F6F0D6} +% \pagecolor{myBGcolor} +%\pagecolor{solarized-base01} +%\pagecolor{solarized-base01!70!black} +%\pagecolor{gray!60!black} + +\newcommand{\X}{\begin{color}{\xcolor}X\end{color}} +%\newcommand{\If}{\textcolor{red}{If - }} +%\newcommand{\ElseIf}{\textcolor{orange}{Else If - }} +%\newcommand{\Else}{\textcolor{orange}{Else - }} +\newcommand{\AND}{\textcolor{purple}{ AND }} +\newcommand{\et}{{\color{solarized-magenta}\textsc{ and }}} +\newcommand{\OR}{{\color{solarized-magenta}\textsc{ or }}} +\newcommand{\If}{{\color{solarized-red}\textsc{if }}} +\newcommand{\ElseIf}{{\color{solarized-red}\textsc{elseif }}} +\newcommand{\Else}{{\color{solarized-red}\textsc{else }}} +\newcommand{\Then}{{\color{solarized-blue}\textsc{then }}} +\newcommand{\Or}{{\color{solarized-green}\textsc{or }}} + +% \usepackage[mono]{zi4} +\newcommand{\inst}[1]{\texttt{#1}} +% \newcommand{\col}[1]{ +% \ifmmode +% \mathsf{#1} +% \else +% \textsf{#1} +% \fi +% } +\newcommand{\col} [1]{\textsf{#1}} +\newcommand{\colm}[1]{\mathsf{#1}} +\newcommand{\stampSignifier}{\stamp}%{\blacksquare} +%\newcommand{\stampCol}[1]{\prescript{\stampSignifier}{}{#1}} +\newcommand{\stampCol}[1]{#1\stampSignifier} + +\newcommand{\utt} [1] {\underline{\texttt{#1}}} % utt = U(nderline with \text)TT + +%\blacklozenge +%\lozenge +%\faQrcode +%\faAslInterpreting +%\faBook +%\faClone +%\faEye +%\faFileTextO +%\faLink +%\faQuoteLeft +\newcommand{\decodedSignifier}{\lozenge} +\newcommand{\decoded}[1]{\prescript{\decodedSignifier}{}{#1}} +% \newcommand{\decoded}[1]{\langle\!\langle#1\rangle\!\rangle} +%\newcommand{\decoded}[1]{\prescript{\ulcorner\!\!}{\llcorner\!\!}{#1}^{\!\!\urcorner}_{\!\!\lrcorner}} +\newcommand{\imported}[1]{\langle{}#1\rangle{}} + +\newcommand{\zkevm}{\texttt{zk}} + +\newcommand{\ordA}[1]{\widetilde{\col{#1}}} +\newcommand{\ordB}[1]{\widetilde{\widetilde{\col{#1}}}} +\newcommand{\ordC}[2]{\widetilde{\widetilde{\col{#1} \odot \col{#2}}}} + +% \newcommand{\order}[1]{\widetilde{#1}} +% \faSortAmountAsc +% \faRandom +\newcommand{\order}[1]{\left[#1\right]^{\text{\faRandom}}} + +\newcommand{\gray} [1] {{\color{gray!60}{#1}}} +\newcommand{\graym} [1] {{\color{gray!60}{\bm{#1}}}} + +% red +\newcommand{\red} [1] {{\color{solarized-cyan}{\textbf{#1}}}} +\newcommand{\redm} [1] {{\color{solarized-cyan}{\bm{#1}}}} + +% actual red +\newcommand{\ared} [1] {{\color{solarized-red}{\textbf{#1}}}} +\newcommand{\aredm} [1] {{\color{solarized-red}{\bm{#1}}}} + + +% green +\newcommand{\green} [1] {{\color{solarized-green}{\textbf{#1}}}} +\newcommand{\greenm} [1] {{\color{solarized-green}{\bm{#1}}}} + +% blue +\newcommand{\blue} [1] {{\color{solarized-blue}{\textbf{#1}}}} +\newcommand{\bluem} [1] {{\color{solarized-blue}{\bm{#1}}}} + +% orange +\newcommand{\orange} [1] {{\color{solarized-orange}{\textbf{#1}}}} +\newcommand{\orangem} [1] {{\color{solarized-orange}{\bm{#1}}}} + +% yellow (formerly solarized-yellow!80!Yellow) +\newcommand{\yellow} [1] {{\color{draculaorange}{\textbf{#1}}}} +\newcommand{\yellowm} [1] {{\color{draculaorange}{\bm{#1}}}} + +% comments +% \newcommand{\ob}[1]{} +\newcommand{\ob} [1] {\red{#1}} +\newcommand{\issue} [1] {\noindent\orange{TODO: #1}} + +\def\backgroundColor{lightgray!50!black} +\newcommand{\redundant}[1]{\fcolorbox{\backgroundColor!40}{\backgroundColor!80}{#1}} +\newcommand{\ns}[1]{\!\!\!\!#1\!\!\!\!} % no space + +%\newcommand{\old}[1]{\textsc{\textbf{{\color{red}Old Old Old! }}}\hl{#1}} + +\newcommand{\plusEq}{\mathrel{+}=} +\newcommand{\minusEq}{\mathrel{-}=} + +% sizes +\newcommand{\verySsmall} {\redm{2}} % smallness minus one +\newcommand{\ssmall} {\redm{4}} % smallness +\newcommand{\ssmallMO} {\redm{3}} % smallness minus one +\newcommand{\medium} {\redm{6}} % mediumness +\newcommand{\mediumMO} {\redm{5}} % mediumness minus one +\newcommand{\eight} {\redm{8}} % eight +\newcommand{\eightMO} {\redm{7}} % eight minus one +\newcommand{\llarge} {\redm{16}} % largeness +\newcommand{\llargeMO} {\redm{15}} % largeness minus one +\newcommand{\llargePO} {\redm{17}} % largeness minus one +\newcommand{\lllarge} {\redm{17}} % Largeness +\newcommand{\lllargeMO} {\redm{16}} % Largeness minus one +\newcommand{\evmWordSize} {\redm{32}} +\newcommand{\smallCurvePointSize} {\redm{64}} +\newcommand{\largeCurvePointSize} {\redm{128}} +\newcommand{\blakeReturnDataSize} {\redm{64}} +\newcommand{\evmWordSizeMO} {\redm{31}} +\newcommand{\yellowPaperFailureCondition} {F} + +\newcommand{\prediction} {[\![~\bm{\pi}~]\!]} % used to label (typically HUB) predictions + +\newcommand{\dataCol} [1] {\col{DATA\_#1}} + +% flag symbols +% \faFlag +% \faFlagO +% \faFlagCheckered +% \faFa +\newcommand{\flag}{\text{\,\faFlagO}} +% \faCodeFork +% \faPowerOff +% \faForward +% \faBolt +% \faGears +% \faLevelUp +% \faMailReply +% \faPlug +% \faBookmarkO +% \faCheckSquareO +% \faCheckCircleO +% \faCheck +\newcommand{\select}{\text{\,\faBolt}} +\newcommand{\stamp}{\raisebox{-0.25pt}{\text{\,\faSquareO}\,}} + +\newcommand{\trash}{\text{\faTrashO}} + +\newcommand{\eye} {\text{\,\faEye}} +\newcommand{\accountSignifier} {\text{\,\faDatabase\,}} +\newcommand{\batchSignifier} {\text{\,\faFilesO\,}} +\newcommand{\contextSignifier} {\text{\,\faCubes\,}} +\newcommand{\miscSignifier} {\text{\,\faCloudUpload\,}} % \faCloudUpload \faExchange \faExternalLink \faShareSquare \faShareSquareO \faSignOut \faExpeditedssl \faExternalLink \faMailForward +\newcommand{\scenarioSignifier} {\text{\,\faCodeFork\,}} % \faArrows \faArrowsAlt \faCodeFork +\newcommand{\stackSignifier} {\text{\,\faStackOverflow\,}} +\newcommand{\storageSignifier} {\text{\,\faHddO\,}} % \faHddO, \faFilesO, \faSave +\newcommand{\transactionSignifier} {\text{\,\faSend\,}} % \faSend, \faSendO, \faFileO, \faFileTextO +\newcommand{\familySignifier} {\text{\,\faWarehouse\,}} % don't have any good candidate + +\newcommand{\done} {\text{\faCheckSquareO}} +\newcommand{\godGiven} {\colorbox{solarized-green} {\textbf{~~God Given~~}}} +\newcommand{\partiallyGodGiven} {\colorbox{solarized-yellow} {\textbf{~~Partially God Given~~}}} +\newcommand{\deprecated} {\colorbox{solarized-green} {\textbf{~~Deprecated~~}}} +\newcommand{\markAsExtractedFromBtc} {\colorbox{solarized-red} {\textbf{~~Extracted from \btcMod{}~~}}} +\newcommand{\markAsExtractedFromRlpTxn} {\colorbox{solarized-blue} {\textbf{~~Extracted from \rlpTxnMod{}~~}}} +\newcommand{\markAsSometimesExtractedFromRlpTxn} {\colorbox{solarized-blue} {\textbf{~~Sometimes extracted from \rlpTxnMod{}~~}}} +\newcommand{\markAsExtractedFromHub} {\colorbox{solarized-orange} {\textbf{~~Extracted from \hubMod{}~~}}} +\newcommand{\markAsPartiallyComputedHere} {\colorbox{solarized-yellow} {\textbf{~~Partially computed here~~}}} +\newcommand{\markAsComputedHere} {\colorbox{solarized-yellow} {\textbf{~~Computed here~~}}} +\newcommand{\markAsPartiallyJustifiedHere} {\colorbox{solarized-yellow} {\textbf{~~Partially justified here~~}}} +\newcommand{\markAsJustifiedHere} {\colorbox{solarized-yellow} {\textbf{~~Justified here~~}}} +\newcommand{\markAsExtractedFromEcrecover} {\colorbox{solarized-yellow} {\textbf{~~Extracted from ECRECOVER~~}}} + + +% \newcommand{\define} {\triangleq} +\newcommand{\define} {~\overset{\redm{\mathrm{def}}}\equiv~} +\newcommand{\nothing} {\graym{\varnothing}} +\newcommand{\alreadySet} {\gray{\texttt{}}} +\newcommand{\leftUndefined} {\gray{\texttt{}}} +\newcommand{\relevantValue} {\texttt{}} +\newcommand{\valueToBeSet} {\texttt{}} +\newcommand{\valueUnknown} {\gray{\texttt{}}} +\newcommand{\toBeSet} {\orange{TO BE SET}} +\newcommand{\justifiedByExternalCircuit}{\texttt{}} + +\newcommand{\lispNone} {--- {\textcolor{draculaorange} {\texttt{Lisp NONE}}}} +\newcommand{\lispDone} {--- \colorbox{Green} {\textcolor{Yellow} {\texttt{Lisp DONE}}}} +\newcommand{\lispTodo} {--- \colorbox{Red} {\textcolor{Yellow} {\texttt{Lisp TODO}}}} +\newcommand{\lispWip} {--- \colorbox{NavyBlue} {\textcolor{Yellow} {\texttt{Lisp WIP}}}} +\newcommand{\lispCommented} {--- \colorbox{Gray} {\textcolor{Yellow} {\texttt{Lisp COMMENTED}}}} +\newcommand{\missingParameter} {\colorbox{Red} {\textcolor{Yellow} {\textbf{\texttt{}}}}} + +\newcommand{\zkEvm} {\textsc{zk-evm}} +\newcommand{\evm} {\textsc{evm}} +\newcommand{\constraintAst} {\textsc{ast}} + +\newcommand{\ccc} {{\color{solarized-yellow}\col{c.c.c.}}} % counter-constant column +\newcommand{\ccbc} {{\color{solarized-yellow}\col{c.c.b.c.}}} % counter-constant binary column +\newcommand{\cncc} {{\color{solarized-yellow}\col{cn.c.c.}}} % context-constant column +\newcommand{\cncbc} {{\color{solarized-yellow}\col{cn.c.b.c.}}} % context-constant column binary column + +\newcommand{\module}{\col{MOD}} + +% separator +\newcommand{\separator}{\col{/}} + +\newcommand{\lex}{\col{LEX}} +\newcommand{\ord}{\col{ORD}} +\newcommand{\aux}{\col{AUX}} + +\newcommand{\rlp}{\texttt{RLP}} + +% TODO: clean up and homogenize notations between bits and bytes + +% accumulators +\newcommand{\ACC} {\col{ACC}} +\newcommand{\acc}[1] {\ACC\col{\_#1}} + +% bit columns +\newcommand{\genBit} {\col{BIT}} % generic bit column +\newcommand{\genBitAcc} {\genBit\col{\_}\ACC} % associated accumulator column +\newcommand{\bit}[1] {[\![#1]\!]} +\newcommand{\negbit}[1] {\bit{#1}^\vee} + +% byte columns +\newcommand{\BYTE} {\col{BYTE}} % generic byte column % generic bit column +\newcommand{\genByte} {\col{BYTE}} % generic byte column % generic bit column +\newcommand{\genByteAcc} {\genByte\col{\_}\ACC} % associated accumulator column +\newcommand{\byteCol}[1] {\genByte\col{\_#1}} +\newcommand{\byteAcc}[1] {\byteCol{#1}\col{\_}\ACC} + +\newcommand{\saNote}{\noindent{\color{solarized-green}\textbf{Note.}}} % stand alone note + +\newcommand{\state} {\bm{\sigma}} +\newcommand{\zkEvmConstRel} {\mathcal{R}_{\zkEvm}} +\newcommand{\zkEvmModuleRel} {\mathcal{R}^{\textsc{mod}}} +\newcommand{\zkEvmLookupRel} {\mathcal{R}^{\textsc{lookup}}} +\newcommand{\fullTrace} {\textbf{T}} +\newcommand{\moduleTrace} {\fullTrace} +\newcommand{\modules} {\col{Modules}} +\newcommand{\moduleName} {\col{m}} +\newcommand{\lookups} {\col{Lookups}} +\newcommand{\constraints} {\mathcal{C}} +\newcommand{\fullConstraints} {\constraints\zkEvm} +\newcommand{\true} {\texttt{true}} +\newcommand{\false} {\texttt{false}} +\newcommand{\mTrue} {\mathtt{true}} +\newcommand{\mFalse} {\mathtt{false}} + +% for account, storage, ... macros + +% \newcommand{\relof} {\textcolor{draculaorange}{\bm{\omega}}} % {\texttt{ro}} % relative offset +\newcommand{\relof} {\texorpdfstring{\textcolor{draculaorange}{\bm{\omega}}}{\omega}} % fix of the above for titles +\newcommand{\reluo} {\textcolor{draculaorange}{\bm{\alpha}}} % {\texttt{ru}} % relative undoing offset +\newcommand{\reldo} {\textcolor{draculaorange}{\bm{\delta}}} % {\texttt{rd}} % relative doing offset +\newcommand{\undefinedStar} {(\textcolor{draculaorange}{\bigstar})} + +% TODO: for ecdata or general? +\newcommand{\hubMmuMmioPrediction} {\colorbox{solarized-orange}{\textbf{~~$\hubMod \rightarrow \mmuMod \rightarrow \mmioMod \rightarrow \ecDataMod$ prediction~~}}} +\newcommand{\ecDataPrediction} {\colorbox{solarized-orange}{\textbf{~~$\ecDataMod$ prediction~~}}} diff --git a/pkg/common_light.sty b/pkg/common_light.sty new file mode 100644 index 0000000..193c009 --- /dev/null +++ b/pkg/common_light.sty @@ -0,0 +1,105 @@ +% \def\xcolor{Green} +% +% \usepackage{xcolor-solarized} +% % \def\backgroundColor{lightgray!50!black} +% %\pagecolor{lightgray!50!black} +% %\color{solarized-base2} +% \def\backgroundColor{lightgray!50!black} +% +% \newcommand{\X}{\begin{color}{\xcolor}X\end{color}} +% %\newcommand{\If}{\textcolor{red}{If - }} +% %\newcommand{\ElseIf}{\textcolor{orange}{Else If - }} +% %\newcommand{\Else}{\textcolor{orange}{Else - }} +% \newcommand{\AND}{\textcolor{purple}{ AND }} +% \newcommand{\et}{{\color{solarized-magenta}\textsc{ and }}} +% \newcommand{\OR}{{\color{solarized-magenta}\textsc{ or }}} +% \newcommand{\If}{{\color{solarized-red}\textsc{if }}} +% \newcommand{\ElseIf}{{\color{solarized-red}\textsc{elseif }}} +% \newcommand{\Else}{{\color{solarized-red}\textsc{else }}} +% \newcommand{\Then}{{\color{solarized-blue}\textsc{then }}} +% \newcommand{\Or}{{\color{solarized-green}\textsc{or }}} +% +% \newcommand{\inst}[1]{\texttt{#1}} +% \newcommand{\col}[1]{ +% \ifmmode +% \mathsf{#1} +% \else +% \textsf{#1} +% \fi +% } +% \newcommand{\colm}[1]{\col{#1}} +% \newcommand{\stampSignifier}{\stamp}%{\blacksquare} +% %\newcommand{\stampCol}[1]{\prescript{\stampSignifier}{}{#1}} +% \newcommand{\stampCol}[1]{#1\stampSignifier} +% %\blacklozenge +% %\lozenge +% %\faQrcode +% %\faAslInterpreting +% %\faBook +% %\faClone +% %\faEye +% %\faFileTextO +% %\faLink +% %\faQuoteLeft +% \newcommand{\decodedSignifier}{\lozenge} +% \newcommand{\decoded}[1]{\prescript{\decodedSignifier}{}{#1}} +% % \newcommand{\decoded}[1]{\langle\!\langle#1\rangle\!\rangle} +% %\newcommand{\decoded}[1]{\prescript{\ulcorner\!\!}{\llcorner\!\!}{#1}^{\!\!\urcorner}_{\!\!\lrcorner}} +% \newcommand{\imported}[1]{\langle{}#1\rangle{}} +% +% \newcommand{\zkevm}{\texttt{zk}} +% +% \newcommand{\ordA}[1]{\widetilde{\col{#1}}} +% \newcommand{\ordB}[1]{\widetilde{\widetilde{\col{#1}}}} +% \newcommand{\ordC}[2]{\widetilde{\widetilde{\col{#1} \odot \col{#2}}}} +% +% % \newcommand{\order}[1]{\widetilde{#1}} +% % \faSortAmountAsc +% % \faRandom +% \newcommand{\order}[1]{\left[#1\right]^{\text{\faRandom}}} +% +% \newcommand{\gray}[1]{{\color{gray!60}{#1}}} +% \newcommand{\graym}[1]{{\color{gray!60}{\bm{#1}}}} +% +% % red +% \newcommand{\red}[1]{{\color{solarized-cyan}{\textbf{#1}}}} +% \newcommand{\redm}[1]{{\color{solarized-cyan}{\bm{#1}}}} +% +% % green +% \newcommand{\green}[1]{{\color{solarized-green}{\textbf{#1}}}} +% \newcommand{\greenm}[1]{{\color{solarized-green}{\bm{#1}}}} +% +% % blue +% \newcommand{\blue}[1]{{\color{solarized-blue}{\textbf{#1}}}} +% \newcommand{\bluem}[1]{{\color{solarized-blue}{\bm{#1}}}} +% +% % orange +% \newcommand{\orange}[1]{{\color{solarized-violet}{\textbf{#1}}}} +% \newcommand{\orangem}[1]{{\color{solarized-violet}{\bm{#1}}}} +% +% % yellow +% \newcommand{\yellow}[1]{{\color{solarized-yellow}{\textbf{#1}}}} +% \newcommand{\yellowm}[1]{{\color{solarized-yellow}{\bm{#1}}}} +% +% % comments +% \newcommand{\ob}[1]{\red{#1}} +% +% +% \newcommand{\redundant}[1]{\fcolorbox{\backgroundColor!40}{\backgroundColor!80}{#1}} +% \newcommand{\ns}[1]{\!\!\!\!#1\!\!\!\!} % no space +% +% %\newcommand{\old}[1]{\textsc{\textbf{{\color{red}Old Old Old! }}}\hl{#1}} +% +% \newcommand{\plusEq}{\mathrel{+}=} +% \newcommand{\minusEq}{\mathrel{-}=} +% +% +% % sizes +% \newcommand{\ssmall}{\redm{4}} % smallness +% \newcommand{\ssmallMO}{\redm{3}} % smallness minus one +% \newcommand{\medium}{\redm{6}} % mediumness +% \newcommand{\mediumMO}{\redm{5}} % mediumness minus one +% \newcommand{\llarge}{\redm{16}} % largeness +% \newcommand{\llargeMO}{\redm{15}} % largeness minus one +% \newcommand{\lllarge}{\redm{17}} % Largeness +% \newcommand{\lllargeMO}{\redm{16}} % Largeness minus one diff --git a/pkg/common_shorthands.sty b/pkg/common_shorthands.sty new file mode 100644 index 0000000..0018173 --- /dev/null +++ b/pkg/common_shorthands.sty @@ -0,0 +1,23 @@ +\newcommand{\locInst} {\col{inst}} +\newcommand{\locFlagSum} {\col{flag\_sum}} +\newcommand{\locAddressSum} {\col{address\_sum}} +\newcommand{\locWeightedFlagSum} {\col{wght\_sum}} +\newcommand{\locMaxCtSum} {\col{max\_ct\_sum}} +\newcommand{\locIndexMaxSum} {\col{index\_max\_sum}} +\newcommand{\locTransitionBit} {\col{transition\_bit}} +\newcommand{\locTransitionToData} {\col{transition\_to\_data}} +\newcommand{\locTransitionToResult} {\col{transition\_to\_result}} +\newcommand{\locSignedInst} {\col{signed\_inst}} +\newcommand{\locOli} {\col{one\_line\_inst}} +\newcommand{\locMli} {\col{multi\_line\_inst}} +\newcommand{\locVli} {\col{variable\_length\_inst}} +% \newcommand{\loc} {\col{}} +% \newcommand{\loc} {\col{}} +% \newcommand{\loc} {\col{}} +% \newcommand{\loc} {\col{}} +% \newcommand{\loc} {\col{}} +% \newcommand{\loc} {\col{}} +\newcommand{\isSmod} {\col{IS\_SMOD}} +\newcommand{\isMod} {\col{IS\_MOD}} +\newcommand{\isSdiv} {\col{IS\_SDIV}} +\newcommand{\isDiv} {\col{IS\_DIV}} diff --git a/pkg/comparisons.sty b/pkg/comparisons.sty new file mode 100644 index 0000000..e153c56 --- /dev/null +++ b/pkg/comparisons.sty @@ -0,0 +1,31 @@ +% +\newcommand{\compXToHi}{\texttt{CompareXtoHigh}} +\newcommand{\compXToLo}{\texttt{CompareXtoLow}} +% +\newcommand{\storeXinAtre}{\texttt{StoreXinAthreeRequired}} +\newcommand{\storeXinAtwo}{\texttt{StoreXinAtwoRequired}} +\newcommand{\storeXinAone}{\texttt{StoreXinAoneRequired}} +\newcommand{\storeXinB}{\texttt{StoreXinB}} +\newcommand{\storeXinC}{\texttt{StoreXinC}} +% +\newcommand{\pushStackToRam}{\texttt{PushTwoStackToRam}} +\newcommand{\pushRamToStackTwo}{\texttt{PushTwoRamToStack}} +\newcommand{\pushRamToStackOne}{\texttt{PushOneRamToStack}} +% +\newcommand{\killingOne}{\texttt{killOneRamLimb}} +\newcommand{\killingTwo}{\texttt{killTwoRamLimbs}} +\newcommand{\killingTre}{\texttt{killThreeRamLimbs}} +% + +\newcommand{\ramToRam}{\texttt{RamToRam}} +\newcommand{\exoToRam}{\texttt{ExoToRam}} +\newcommand{\ramIsExo}{\texttt{RamIsExo}} + +\newcommand{\ERF}{\col{EXCEPTIONAL\_RETENTION\_FLAG}} % +\newcommand{\erf}{\col{ERF}} +\newcommand{\iERF}{\imported{\ERF}} % +\newcommand{\iErf}{\imported{\erf}} + + +\newcommand{\doTheWork}{\qquad(\bigstar)} +\newcommand{\removeThis}{\qquad(\trash)} diff --git a/pkg/dark_theme.sty b/pkg/dark_theme.sty new file mode 100644 index 0000000..25fd0e1 --- /dev/null +++ b/pkg/dark_theme.sty @@ -0,0 +1,2 @@ +\pagecolor{lightgray!50!black} +\color{solarized-base2} diff --git a/pkg/draculatheme.sty b/pkg/draculatheme.sty new file mode 100644 index 0000000..548640e --- /dev/null +++ b/pkg/draculatheme.sty @@ -0,0 +1,18 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{draculatheme}[2021/02/26 Dracula Theme] +\RequirePackage{xcolor} + +\definecolor{draculabg} {RGB} {40, 42, 54} +\definecolor{draculacl} {RGB} {68, 71, 90} +\definecolor{draculafg} {RGB} {248, 248, 242} +\definecolor{draculacomment} {RGB} {98, 114, 164} +\definecolor{draculacyan} {RGB} {139, 233, 253} +\definecolor{draculagreen} {RGB} {80, 250, 123} +\definecolor{draculaorange} {RGB} {255, 184, 108} +\definecolor{draculapink} {RGB} {255, 121, 198} +\definecolor{draculapurple} {RGB} {189, 147, 249} +\definecolor{draculared} {RGB} {255, 85, 85} +\definecolor{draculayellow} {RGB} {241, 250, 140} + +\pagecolor{draculabg} +\color{draculafg} diff --git a/pkg/env.sty b/pkg/env.sty new file mode 100644 index 0000000..a25741c --- /dev/null +++ b/pkg/env.sty @@ -0,0 +1,444 @@ +\newcommand{\Hori} {\texttt{}} +\newcommand{\Verti} {\texttt{}} +\newcommand{\paramVerti}[1] {\texttt{<-#1>}} + +\newcommand{\BATCHNUM} {\col{BATCH\_NUMBER}} +\newcommand{\batchNum} {\col{BTC\_NUM}} +\newcommand{\totBatchNum} {\col{BTC\_NUM}^\infty} + + +\newcommand{\ACCOUNTADDRESS} {\col{ACCOUNT\_ADDRESS}} +\newcommand{\accountAddress} {\col{aADDR}} +\newcommand{\CODEADDRESS} {\col{BYTECODE\_ADDRESS}} +\newcommand{\codeAddress} {\col{bADDR}} +\newcommand{\CALLERADDRESS} {\col{CALLER\_ADDRESS}} +\newcommand{\callerAddress} {\col{cADDR}} + +\newcommand{\callValue} {\col{CALL\_VALUE}} + +\newcommand{\TX} {\col{TRANSACTION}} +\newcommand{\tx} {\col{TX}} + +\newcommand{\TXWARM} {\tx\col{\_PREWARMING\_PHASE}} +\newcommand{\txWarm} {\tx\col{\_WARM}} +\newcommand{\TXINIT} {\tx\col{\_INITIALIZATION\_PHASE}} +\newcommand{\txInit} {\tx\col{\_INIT}} +\newcommand{\TXEXEC} {\tx\col{\_EXECUTION\_PHASE}} +\newcommand{\txExec} {\tx\col{\_EXEC}} +\newcommand{\TXFINL} {\tx\col{\_FINALIZATION\_PHASE}} +\newcommand{\txFinl} {\tx\col{\_FINL}} +\newcommand{\TXSKIP} {\tx\col{\_SKIP\_EXECUTION}} +\newcommand{\txSkip} {\tx\col{\_SKIP}} + +\newcommand{\TXENDSTAMP} {\hubSTAMP\col{\_\TX\_END}} +\newcommand{\txEndStamp} {\hubStamp\col{TX\_END}} +\newcommand{\TXREVERTS} {\TX\col{\_REVERTS}} +\newcommand{\txReverts} {\tx\col{\_REV}} +\newcommand{\TXREVERTSGRACEFULLY} {\TX\col{\_REVERTS\_GRACEFULLY}} +\newcommand{\txRevertsGracefully} {\tx\col{\_REVGRACE}} + +\newcommand{\CNREVSTAMP} {\CN\col{\_REVERT\_STAMP}} +\newcommand{\CNREVERTS} {\CN\col{\_REVERTS}} +\newcommand{\CNREVERTSGRACEFULLY} {\CN\col{\_REVERTS\_GRACEFULLY}} +\newcommand{\cnRevStamp} {\cn\stampSignifier\col{REV}} +\newcommand{\cnReverts} {\cn\col{\_REV}} +\newcommand{\cnRevertsGracefully} {\cn\col{\_REVGRA}} +\newcommand{\cnWillRev} {\cn\col{\_WILL\_REV}} +\newcommand{\cnGetsRev} {\cn\col{\_GETS\_REV}} +\newcommand{\cnSelfRev} {\cn\col{\_SELF\_REV}} + +\newcommand{\PEEKSTACK} {\col{PEEK\_AT\_STACK\_ROW}} +\newcommand{\peekStack} {\col{STACK}^{\eye}} +\newcommand{\peekStackFour} {\col{STACK}^{\eye, \cc4}} +\newcommand{\PEEKCONTEXT} {\col{PEEK\_AT\_CONTEXT\_ROW}} +\newcommand{\peekContext} {\col{CON}^{\eye}} +\newcommand{\PEEKACCOUNT} {\col{PEEK\_AT\_ACCOUNT\_ROW}} +\newcommand{\peekAccount} {\col{ACC}^{\eye}} +\newcommand{\PEEKSTORAGE} {\col{PEEK\_AT\_STORAGE\_ROW}} +\newcommand{\peekStorage} {\col{STO}^{\eye}} +\newcommand{\PEEKBATCH} {\decoded{\col{PEEK\_AT\_BATCH}\_ROW}} +\newcommand{\peekBatch} {\decoded{\col{BATCH}^{\eye}}} +\newcommand{\PEEKTRANSACTION} {\col{PEEK\_AT\_TRANSACTION\_ROW}} +\newcommand{\peekTransaction} {\col{TXN}^{\eye}} +\newcommand{\PEEKMISC} {\col{PEEK\_AT\_MISCELLEANOUS\_ROW}} +\newcommand{\peekMisc} {\col{MISC}^{\eye}} +\newcommand{\PEEKSCENARIO} {\col{PEEK\_AT\_SCENARIO\_ROW}} +\newcommand{\peekScenario} {\col{SCN}^{\eye}} + +\newcommand{\debit} {\col{DEBIT}} +\newcommand{\cost} {\col{COST}} +\newcommand{\sufficientBalance} {\col{SUFFICIENT\_}\balance} +\newcommand{\createAddr} {\col{CREATE\_ADDR}} + +\newcommand{\hubLambda} {\redm{\lambda}} % dom stamp multiplier +\newcommand{\hubTau} {\redm{\tau}} % stack stamp multiplier +\newcommand{\revertEpsilon} {\redm{\epsilon_{\text{rev}}}} +\newcommand{\selfdestructEpsilon} {\redm{\epsilon_{\text{selfdest}}}} +% \newcommand{\cPreWarming} {\red{c}_\red{pw}} +% \newcommand{\cInit} {\red{c}_\red{in}} +% \newcommand{\cSelfDestruct} {\red{c}_\red{sd}} +% \newcommand{\cRollback} {\red{c}_\red{rb}} +% \newcommand{\cRefund} {\red{c}_\red{rf}} + +\newcommand{\emptyKeccak} {\redm{\texttt{KECCAK}\big((~)\big)}} +\newcommand{\emptyKeccakHi} {\redm{\emptyKeccak\high}} +\newcommand{\emptyKeccakLo} {\redm{\emptyKeccak\low}} + +\newcommand{\emptyShaTwo} {\redm{\texttt{SHA2-256}\big((~)\big)}} +\newcommand{\emptyShaTwoHi} {\redm{\emptyShaTwo\high}} +\newcommand{\emptyShaTwoLo} {\redm{\emptyShaTwo\low}} + +\newcommand{\emptyRipemd} {\redm{\texttt{RIPEMD-160}\big((~)\big)}} +\newcommand{\emptyRipemdHi} {\redm{\emptyRipemd\high}} +\newcommand{\emptyRipemdLo} {\redm{\emptyRipemd\low}} + +\newcommand{\nonce} {\col{NONCE}} +\newcommand{\balance} {\col{BALANCE}} +\newcommand{\codeSize} {\col{CODESIZE}} +\newcommand{\codeHash} {\col{CODEHASH}} +\newcommand{\existence} {\col{EXISTS}} +\newcommand{\hasCode} {\col{HASCODE}} + +\newcommand{\creatorAddress} {\col{ADDR}} +\newcommand{\createdAddress} {\col{DEP\_ADDR}} +\newcommand{\salt} {\col{SALT}} + +\newcommand{\DEPNUMBER} {\col{DEPLOYMENT\_NUMBER}} +\newcommand{\depNumber} {\col{DEPNUM}} +\newcommand{\DEPSTATUS} {\col{DEPLOYMENT\_STATUS}} +\newcommand{\depStatus} {\col{DEPSTATUS}} + +\newcommand{\accDepNum} {\col{a}\depNumber} +\newcommand{\codeDepNum} {\col{b}\depNumber} +\newcommand{\codeDepStatus} {\col{b}\depStatus} +\newcommand{\codeCfi} {\col{b}\cfi} + +% state column aliases +% \accountSignifier + +\newcommand{\accAddress} {\accountSignifier\addr} +\newcommand{\accAddressHi} {\accAddress\high} +\newcommand{\accAddressLo} {\accAddress\low } +\newcommand{\accNonce} {\accountSignifier\nonce} +\newcommand{\accBalance} {\accountSignifier\balance} +\newcommand{\accCodesize} {\accountSignifier\codeSize} +\newcommand{\accCodehash} {\accountSignifier\codeHash} +\newcommand{\accCodehashHi} {\accountSignifier\codeHash\col{\_HI}} +\newcommand{\accCodehashLo} {\accountSignifier\codeHash\col{\_LO}} +\newcommand{\accCfi} {\accountSignifier\cfi} +% \newcommand{\accCfiRequired} {\accountSignifier\cfi\col{\_REQUIRED}} +\newcommand{\accWarmth} {\accountSignifier\warm} +\newcommand{\accDepNumber} {\accountSignifier\depNumber} +\newcommand{\accDepStatus} {\accountSignifier\depStatus} +\newcommand{\accExists} {\accountSignifier\existence} +\newcommand{\accHasCode} {\accountSignifier\hasCode} +\newcommand{\accDebit} {\accountSignifier\debit} +\newcommand{\accCost} {\accountSignifier\cost} +\newcommand{\accSufficientBalance} {\accountSignifier\sufficientBalance} +\newcommand{\accCreateAddr} {\accountSignifier\createAddr} +\newcommand{\accMarkedForSelfdestruct} {\accountSignifier\col{MARKED\_FOR\_SELFDESTRUCT}} +\newcommand{\accAddressAgain} {\order{\accountSignifier\col{ADDR\_AGAIN}}} +\newcommand{\accAddressFirst} {\order{\accountSignifier\col{ADDR\_FIRST}}} +\newcommand{\accAbsTxNumAgain} {\order{\accountSignifier\absTxNum\col{\_AGAIN}}} +\newcommand{\accAbsTxNumFirst} {\order{\accountSignifier\absTxNum\col{\_FIRST}}} +\newcommand{\accFinal} {\order{\accountSignifier\col{FINAL}}} +\newcommand{\accFirst} {\order{\accountSignifier\col{FIRST}}} + +\newcommand{\accSameMarkedForSelfdestructFlag} [2] {\accountSignifier\sameSignifier\texttt{MarkedForSelfdestructFlag} _{#1} \big[#2\big]} +\newcommand{\accTurnOnMarkedForSelfdestructFlag} [2] {\accountSignifier\texttt{markAccountForSelfdestruct} _{#1} \big[#2\big]} + + +% lookup into ROM_LEX +\newcommand{\accRomLexFlag} {\accountSignifier\romLexMod\flag} + +% lookup into RLP_ADDR +\newcommand{\accRlpAddrKecHi} {\accountSignifier\rlpAddrMod\separator\kec\high} +\newcommand{\accRlpAddrKecLo} {\accountSignifier\rlpAddrMod\separator\kec\low} +\newcommand{\accRlpAddrSaltHi} {\accountSignifier\rlpAddrMod\separator\salt\high} +\newcommand{\accRlpAddrSaltLo} {\accountSignifier\rlpAddrMod\separator\salt\low} +\newcommand{\accRlpAddrDepAddrHi} {\accountSignifier\rlpAddrMod\separator\depAddr\high} +\newcommand{\accRlpAddrDepAddrLo} {\accountSignifier\rlpAddrMod\separator\depAddr\low} +\newcommand{\accRlpAddrRecipe} {\accountSignifier\rlpAddrMod\separator\rlpAddrInst} +\newcommand{\accRlpAddrFlag} {\accountSignifier\rlpAddrMod\flag} +\newcommand{\accTrmFlag} {\accountSignifier\trmMod\flag} +\newcommand{\accTrmRawAddrHi} {\accountSignifier\trmMod\separator\rawAddrHi} +\newcommand{\accTrmIsPrecompile} {\accountSignifier\trmMod\separator\isPrecompile} + +% +\newcommand{\accFreshNewDeploymentStatusAndNumber} [1] {\accountSignifier\texttt{freshNewDepNumAndStatus} \big[ #1 \big] } +\newcommand{\accInitiateForDeployment} [4] {\accountSignifier\texttt{initiateForDeployment} _{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Init code size:} & #3 \\ + \utt{Value:} & #4 \\ + \end{array}\right]} + +\newcommand{\sameSignifier}{\textcolor{draculagreen} {\texttt{same}}} +\newcommand{\undoSignifier}{\textcolor{draculared} {\texttt{undo}}} + +\newcommand{\accSameDeploymentNumber} [2] {\accountSignifier\sameSignifier\texttt{DepNumber} _{#1} \big[ #2 \big] } +\newcommand{\accSameDeploymentStatus} [2] {\accountSignifier\sameSignifier\texttt{DepStatus} _{#1} \big[ #2 \big] } +\newcommand{\accSameDeployment} [2] {\accountSignifier\sameSignifier\texttt{DepNumAndStatus} _{#1} \big[ #2 \big] } +\newcommand{\accSameCode} [2] {\accountSignifier\sameSignifier\texttt{Code} _{#1} \big[ #2 \big] } +\newcommand{\accSameCodeHash} [2] {\accountSignifier\sameSignifier\texttt{CodeHash} _{#1} \big[ #2 \big] } +\newcommand{\accSameCodeSize} [2] {\accountSignifier\sameSignifier\texttt{CodeSize} _{#1} \big[ #2 \big] } +\newcommand{\accSameNonce} [2] {\accountSignifier\sameSignifier\texttt{Nonce} _{#1} \big[ #2 \big] } +\newcommand{\accSameBalance} [2] {\accountSignifier\sameSignifier\texttt{Balance} _{#1} \big[ #2 \big] } +\newcommand{\accSameWarmth} [2] {\accountSignifier\sameSignifier\texttt{AccountWarmth} _{#1} \big[ #2 \big] } +% +\newcommand{\accIncrementNonce} [2] {\accountSignifier\texttt{incrementNonce} _{#1} \big[ #2 \big] } +\newcommand{\accIncrementBalance} [3] {\accountSignifier\texttt{incrementBalance} _{#1} \big[ #2 \big] \big[#3 \big] } +\newcommand{\accIncrementDeploymentNumber} [2] {\accountSignifier\texttt{incrementDepNumber} _{#1} \big[ #2 \big] } +\newcommand{\accTurnOnWarmth} [2] {\accountSignifier\texttt{turnOnAccountWarmth} _{#1} \big[ #2 \big] } +\newcommand{\accTurnOnDepStatus} [2] {\accountSignifier\texttt{turnOnDepStatus} _{#1} \big[ #2 \big] } +\newcommand{\accDecrementBalance} [3] {\accountSignifier\texttt{decrementBalance} _{#1} \big[ #2 \big] \big[#3 \big] } +% \newcommand{\accDecrementNonce} {\accountSignifier\texttt{decrementNonce}\Hori} +\newcommand{\accOpening} [1] {\accountSignifier\texttt{accountOpening} \big[ #1 \big] } +\newcommand{\accViewing} [1] {\accountSignifier\texttt{accountViewing} \big[ #1 \big] } +% \newcommand{\accDeployEmptyBytecode} [1] {\accountSignifier\texttt{deployEmptyBytecode} \big[ #1 \big] } +\newcommand{\accDeletion} [2] {\accountSignifier\texttt{accountDeletion} _{#1} \big[ #2 \big] } +\newcommand{\accRetrieveCodeFragmentIndex} [2] {\accountSignifier\texttt{retrieveCodeFragmentIndex} _{#1} \big[ #2 \big] } +\newcommand{\accTrimAddress} [4] {\accountSignifier\texttt{trimAddress} _{#1} +\left[ \begin{array}{ll} +\utt{Rel. row offset:} & #2 \\ +\utt{Raw address (high part):} & #3 \\ +\utt{Raw address (low part):} & #4 \\ +\end{array} \right]} + +\newcommand{\accIsntPrecompile} [2] {\accountSignifier\texttt{isntPrecompile} _{#1} \big[ #2 \big] } +\newcommand{\accIsPrecompile} [2] {\accountSignifier\texttt{isPrecompile} _{#1} \big[ #2 \big] } + + +\newcommand{\undoingDoingOffsets} [2] {\big[ \utt{Undo:} ~ #1; ~ \underline{\texttt{Done:}} ~ #2 \big]} +\newcommand{\currentReferenceOffsets} [2] {\big[ \utt{Curr.:} ~ #1; ~ \underline{\texttt{Ref.:}} ~ #2 \big]} + +% names +\newcommand{\accSameAddrName} {\accountSignifier\sameSignifier\texttt{AddressAs}} +\newcommand{\accSameAddrAndDepNumName} {\accountSignifier\sameSignifier\texttt{AddressAndDepNumAs}} +\newcommand{\accSameAddrDepNumAndDepStageName} {\accountSignifier\sameSignifier\texttt{AddressDepNumAndDepStageAs}} +\newcommand{\accUndoBalanceUpdateName} {\accountSignifier\undoSignifier\texttt{BalanceUpdate}} +\newcommand{\accUndoNonceUpdateName} {\accountSignifier\undoSignifier\texttt{NonceUpdate}} +\newcommand{\accUndoWarmthUpdateName} {\accountSignifier\undoSignifier\texttt{WarmthUpdate}} +\newcommand{\accUndoCodeSizeUpdateName} {\accountSignifier\undoSignifier\texttt{CodeSizeUpdate}} +\newcommand{\accUndoCodeHashUpdateName} {\accountSignifier\undoSignifier\texttt{CodeHashUpdate}} +\newcommand{\accUndoCodeUpdateName} {\accountSignifier\undoSignifier\texttt{CodeUpdate}} +\newcommand{\accUndoDeploymentStatusAndNumberUpdateName} {\accountSignifier\undoSignifier\texttt{DepStatusAndNumberUpdate}} +\newcommand{\accUndoDeploymentNumberUpdateName} {\accountSignifier\undoSignifier\texttt{DepNumberUpdate}} +\newcommand{\accUndoDeploymentStatusUpdateName} {\accountSignifier\undoSignifier\texttt{DepStatusUpdate}} + +% account constraints +\newcommand{\accSameAddr} [3] {\accSameAddrName _{#1} \currentReferenceOffsets {#2}{#3} } +\newcommand{\accSameAddrAndDepNum} [3] {\accSameAddrAndDepNumName _{#1} \currentReferenceOffsets {#2}{#3} } +\newcommand{\accSameAddrDepNumAndDepStage} [3] {\accSameAddrDepNumAndDepStageName _{#1} \currentReferenceOffsets {#2}{#3} } +\newcommand{\accUndoBalanceUpdate} [3] {\accUndoBalanceUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoNonceUpdate} [3] {\accUndoNonceUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoWarmthUpdate} [3] {\accUndoWarmthUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoCodeSizeUpdate} [3] {\accUndoCodeSizeUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoCodeHashUpdate} [3] {\accUndoCodeHashUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoCodeUpdate} [3] {\accUndoCodeUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoDeploymentStatusAndNumberUpdate} [3] {\accUndoDeploymentStatusAndNumberUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoDeploymentNumberUpdate} [3] {\accUndoDeploymentNumberUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } +\newcommand{\accUndoDeploymentStatusUpdate} [3] {\accUndoDeploymentStatusUpdateName _{#1} \undoingDoingOffsets {#2}{#3} } + + +\newcommand{\storageReading} [2] {\storageSignifier\texttt{storageReading} _{#1} \big[ #2 \big] } % \big[\utt{Rel. row offset:} ~ #1 \big] } +\newcommand{\stoTurnOnWarmth} [2] {\storageSignifier\texttt{turnOnStorageWarmth} _{#1} \big[ #2 \big] } % \big[\utt{Rel. row offset:} ~ #1 \big] } +\newcommand{\stoSameStorageSlot} [3] {\storageSignifier\texttt{sameStorageSlot} _{#1} \currentReferenceOffsets {#2}{#3} } % \left[ \begin{array}{ll} \utt{Undoing offset:} & #1 \\ \underline{\texttt{Doing offset:}} & #2 \\ \end{array} \right] } +\newcommand{\stoUndoWarmthUpdate} [3] {\storageSignifier\texttt{undoStorageWarmthUpdate} _{#1} \undoingDoingOffsets {#2}{#3} } % \left[ \begin{array}{ll} \utt{Undoing offset:} & #1 \\ \underline{\texttt{Doing offset:}} & #2 \\ \end{array} \right] } +\newcommand{\stoUndoValueUpdate} [3] {\storageSignifier\texttt{undoStorageValueUpdate} _{#1} \undoingDoingOffsets {#2}{#3} } % \left[ \begin{array}{ll} \utt{Undoing offset:} & #1 \\ \underline{\texttt{Doing offset:}} & #2 \\ \end{array} \right] } +\newcommand{\stoUndoWarmthAndValueUpdate} [3] {\storageSignifier\texttt{undoStorageWarmthAndValueUpdate} _{#1} \undoingDoingOffsets {#2}{#3} } % \left[ \begin{array}{ll} \utt{Undoing offset:} & #1 \\ \underline{\texttt{Doing offset:}} & #2 \\ \end{array} \right] } + +% transaction column aliases +% \transactionSignifier + +\newcommand{\coinbase} {\col{COINBASE} } + + + +% storage column aliases +% \faHddO + +\newcommand{\stoAddressHi} {\storageSignifier\addr\high} +\newcommand{\stoAddressLo} {\storageSignifier\addr\low} +\newcommand{\stoDeploymentNumber} {\storageSignifier\depNumber} +\newcommand{\stoKeyHi} {\storageSignifier\key\high} +\newcommand{\stoKeyLo} {\storageSignifier\key\low} +% +\newcommand{\stoOrigValue} {\storageSignifier\col{VAL\_ORIG}} +\newcommand{\stoOrigValueHi} {\stoOrigValue\col{\_HI}} +\newcommand{\stoOrigValueLo} {\stoOrigValue\col{\_LO}} +% +\newcommand{\stoCurrValue} {\storageSignifier\col{VAL\_CURR}} +\newcommand{\stoCurrValueHi} {\stoCurrValue\col{\_HI}} +\newcommand{\stoCurrValueLo} {\stoCurrValue\col{\_LO}} + +\newcommand{\stoNextValue} {\storageSignifier\col{VAL\_NEXT}} +\newcommand{\stoNextValueHi} {\stoNextValue\col{\_HI}} +\newcommand{\stoNextValueLo} {\stoNextValue\col{\_LO}} + +\newcommand{\stoWarmth} {\storageSignifier\warm} +\newcommand{\stoNewSlot} {\storageSignifier\col{NEW\_SLOT}} +\newcommand{\stoOrigValueIsZero} {\stoOrigValue\col{\_IS\_ZERO}} +\newcommand{\stoCurrValueIsZero} {\stoCurrValue\col{\_IS\_ZERO}} +\newcommand{\stoCurrValueIsOrig} {\stoCurrValue\col{\_IS\_ORIG}} +\newcommand{\stoNextValueIsCurr} {\stoNextValue\col{\_IS\_CURR}} +\newcommand{\stoNextValueIsZero} {\stoNextValue\col{\_IS\_ZERO}} +\newcommand{\stoNextValueIsOrig} {\stoNextValue\col{\_IS\_ORIG}} + +\newcommand{\stoFirst} {\order{\storageSignifier\col{FIRST}}} +\newcommand{\stoFinal} {\order{\storageSignifier\col{FINAL}}} + +\newcommand{\blockData} {\batchSignifier\col{DATA}} +\newcommand{\blockDataHi} {\blockData\col{\_HI}} +\newcommand{\blockDataLo} {\blockData\col{\_LO}} + +\newcommand{\gas}{\col{GAS}} +\newcommand{\gasExpected} {\gas\col{\_XPCT}} +\newcommand{\gasActual} {\gas\col{\_ACTL}} +\newcommand{\gasCost} {\gas\col{\_COST}} +\newcommand{\gasNext} {\gas\col{\_NEXT}} +\newcommand{\gasMxp} {\gas\col{\_MXP}} +\newcommand{\gasStipend} {\gas\col{\_STPD}} % call / create gas stipend +\newcommand{\callGas} {\col{CALL}\_\gas} % call / create gas stipend +\newcommand{\gasPoop} {\gas\col{\_POOP}} % call / create gas stipend +\newcommand{\gasUpfront} {\gas\col{\_UPFRONT}} % call / create gas stipend + +\newcommand{\toExists} {\col{TO\_EXISTS}} +\newcommand{\toWarm} {\col{TO\_WARM}} + + +\newcommand{\cnCn} {\contextSignifier\cn} +% \newcommand{\cnCaller} {\contextSignifier\caller} +\newcommand{\cnCallDataContextNumber} {\contextSignifier\col{CALL\_DATA\_CONTEXT\_NUMBER}} +\newcommand{\cnCsd} {\contextSignifier\csd} +\newcommand{\cnStatic} {\contextSignifier\col{IS\_STATIC}} +\newcommand{\cnIsRootContext} {\contextSignifier\col{IS\_ROOT}} + +\newcommand{\cnAccountAddress} {\contextSignifier\accountAddress} +\newcommand{\cnAccDepNum} {\contextSignifier\accDepNum} +\newcommand{\cnCodeAddress} {\contextSignifier\codeAddress} %? +\newcommand{\cnCodeDepNum} {\contextSignifier\codeDepNum} %? +\newcommand{\cnCodeDepStatus} {\contextSignifier\codeDepStatus} %? +\newcommand{\cnCodeCfi} {\contextSignifier\codeCfi} %? +\newcommand{\cnCallerAddress} {\contextSignifier\callerAddress} +\newcommand{\cnCallValue} {\contextSignifier\callValue} +\newcommand{\cnCdo} {\contextSignifier\cdo} +\newcommand{\cnCds} {\contextSignifier\cds} +\newcommand{\cnRao} {\contextSignifier\rao} +\newcommand{\cnRac} {\contextSignifier\rac} +\newcommand{\cnUpdate} {\contextSignifier\col{UPDATE}} +\newcommand{\cnReturner} {\contextSignifier\returner} +\newcommand{\cnRdo} {\contextSignifier\rdo} +\newcommand{\cnRds} {\contextSignifier\rds} +% \newcommand{\cnType} {\contextSignifier\cType} % TODO: erase +% capitalized versions +\newcommand{\cnCDS} {\contextSignifier\CDS} +\newcommand{\cnCDO} {\contextSignifier\CDO} +\newcommand{\cnRAO} {\contextSignifier\RAO} +\newcommand{\cnRAC} {\contextSignifier\RAC} +\newcommand{\cnRDO} {\contextSignifier\RDO} +\newcommand{\cnRDS} {\contextSignifier\RDS} +\newcommand{\conContextFirst} {\order{\contextSignifier\col{CN\_FIRST}}} +\newcommand{\conContextAgain} {\order{\contextSignifier\col{CN\_AGAIN}}} + +% +\newcommand{\executionProvidesEmptyReturnData} [2] {\contextSignifier\texttt{executionProvidesEmptyReturnData} _{#1} \Big[\, \utt{Rel. row offset:} \; #2 \Big]} +\newcommand{\nonContextProvidesEmptyReturnData} [2] {\contextSignifier\texttt{nonContextProvidesEmptyReturnData} _{#1} \Big[\, \utt{Rel. row offset:} \; #2 \Big]} +\newcommand{\readContextData} [3] {\contextSignifier\texttt{readContextData} _{#1} \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Context number:} & #3 \\ +\end{array} \right]} +\newcommand{\nextContextIsNew} {\texttt{nextContextIsNew}} +\newcommand{\nextContextIsCurrent} {\texttt{nextContextIsCurrent}} +\newcommand{\nextContextIsCaller} {\texttt{nextContextIsCaller}} + +% \newcommand{\initializeContext} [1] {\texttt{initializeContext} \big[\, #1 \,\big]} +% \initializeContext{\relof}_{i} +% \left[ \begin{array}{llr} +% \utt{context number:} & \col{context\_number} \\ +% \utt{call data context:} & \col{call\_data\_context} \\ +% \utt{call stack depth:} & \col{call\_stack\_depth} \\ +% \utt{is root:} & \col{is\_root} \\ +% \utt{is static:} & \col{is\_static} \\ +% \utt{account address high:} & \col{account\_address\_hi} \\ +% \utt{account address low:} & \col{account\_address\_lo} \\ +% \utt{account deployment number:} & \col{account\_deployment\_number} \\ +% \utt{byte code address high:} & \col{byte\_code\_address\_hi} \\ +% \utt{byte code address low:} & \col{byte\_code\_address\_lo} \\ +% \utt{byte code deployment number:} & \col{byte\_code\_deployment\_number} \\ +% \utt{byte code deployment status:} & \col{byte\_code\_deployment\_status} \\ +% \utt{byte code code fragment index:} & \col{code\_fragment\_index} & (\trash) \\ +% \utt{caller address high:} & \col{caller\_address\_hi} \\ +% \utt{caller address low:} & \col{caller\_address\_lo} \\ +% \utt{call value:} & \col{call\_value} \\ +% \utt{call data context number:} & \col{call\_data\_context\_number} & (\trash) \\ +% \utt{call data offset:} & \col{call\_data\_offset} \\ +% \utt{call data size:} & \col{call\_data\_size} \\ +% \utt{return at offset:} & \col{return\_at\_offset} \\ +% \utt{return at capacity:} & \col{return\_at\_size} \\ +% % \utt{returner context:} & \col{returnerCn} \\ +% % \utt{return data offset:} & \col{returnDataOffset} \\ +% % \utt{return data size:} & \col{returnDataSize} \\ +% \end{array} \right] +\newcommand{\justifyCalleeRevertData} [2] {\texttt{justifyCalleeRevertData} _{#1} \big[\, #2 \,\big]} +\newcommand{\justifyCreateeRevertData} [2] {\texttt{justifyCreateeRevertData} _{#1} \big[\, #2 \,\big]} +\newcommand{\firstRowOfCallee} [2] {\texttt{firstRowOfCalleeContext} _{#1} \big[\, #2 \,\big]} +\newcommand{\firstRowOfDeployment} [2] {\texttt{firstRowOfDeploymentContext}_{#1} \big[\, #2 \,\big]} +\newcommand{\firstRowOfNewContext} [2] {\texttt{firstRowOfNewContext} _{#1} \big[\, #2 \,\big]} +\newcommand{\precompileScenarioRow} [2] {\texttt{precompileScenarioRow} _{#1} \big[\, #2 \,\big]} +% +\newcommand{\unsuccessfulCall} {\texttt{unsucessfulCall}} +\newcommand{\successfulCall} {\texttt{sucessfulCall}} +% +\newcommand{\CONTEXTMAYCHANGE} {\col{CONTEXT\_MAY\_CHANGE}} +\newcommand{\cmc} {\col{CMC}\flag} +% +\newcommand{\XAHOY} {\col{EXCEPTIONS\_AHOY}} +\newcommand{\xAhoy} {\col{XAHOY}\flag} +% +\newcommand{\FCOND} {\col{FAILURE\_CONDITION\_CALL\_OR\_CREATE}} +\newcommand{\ABORT} {\col{ABORT\_BEFORE\_CALL\_OR\_CREATE}} +\newcommand{\abort} {\col{ABORT}\flag} +\newcommand{\fCond} {\col{FCOND}\flag} + +\newcommand{\unexceptionalCall} {\texttt{unexceptionalCall}} +\newcommand{\unexceptionalCreate} {\texttt{unexceptionalCreate}} +\newcommand{\abortedCall} {\texttt{abortedCall}} +\newcommand{\abortedCreate} {\texttt{abortedCreate}} +\newcommand{\unexceptional} {\leftarrow~\texttt{no exception!}} + +% create +\newcommand{\nontrivialCreate} {\texttt{nontrivialCreateInst}} +\newcommand{\createCommonRows} {\texttt{createCommonRows}} +\newcommand{\createException} {\texttt{createException}} +\newcommand{\createAbort} {\texttt{createAbort}} +\newcommand{\createFcondWillRevert} {\texttt{createFcondWillRevert}} +\newcommand{\createFcondWontRevert} {\texttt{createFcondWontRevert}} +\newcommand{\createEntryWithInitcode} {\texttt{createEntryWithInitcode}} +\newcommand{\createEntryWithoutInitcode} {\texttt{createEntryWithoutInitcode}} + +% curr revert vs child self revert scenarios: +\newcommand{\currWillRevChildWillSelfRev} {\texttt{currWillRevertChildWillSelfRevert}} +\newcommand{\currWillRevChildWontSelfRev} {\texttt{currWillRevertChildWontSelfRevert}} +\newcommand{\currWontRevChildWillSelfRev} {\texttt{currWontRevertChildWillSelfRevert}} +\newcommand{\currWontRevChildWontSelfRev} {\texttt{currWontRevertChildWontSelfRevert}} + +\newcommand{\staticInst} {\col{STATIC\flag}} +\newcommand{\decStaticInst} {\decoded{\staticInst}} + +\newcommand{\topic}[1]{\col{TOPIC\_#1}} % for logs and the LOG_INFO module + +\newcommand{\creator} {\text{``creator''}} +\newcommand{\createe} {\text{``createe''}} +\newcommand{\callerr} {\text{``caller''}} +\newcommand{\calleee} {\text{``callee''}} +% +\newcommand{\Creator} {\text{``Creator''}} +\newcommand{\Createe} {\text{``Createe''}} +\newcommand{\Callerr} {\text{``Caller''}} +\newcommand{\Calleee} {\text{``Callee''}} + +\newcommand{\nsrTransactionFinalizationPhaseWontRevert} {\redm{3}} +\newcommand{\nsrTransactionFinalizationPhaseWillRevert} {\redm{4}} +\newcommand{\nsrTransactionSkippingPhase} {\redm{4}} +\newcommand{\nsrTransactionInitializationPhase} {\redm{5}} diff --git a/pkg/euc.sty b/pkg/euc.sty new file mode 100644 index 0000000..b5c0c15 --- /dev/null +++ b/pkg/euc.sty @@ -0,0 +1,8 @@ +\newcommand{\dividend} {\col{DIVIDEND}} +\newcommand{\divisor} {\col{DIVISOR}} +\newcommand{\remainder} {\col{REMAINDER}} +\newcommand{\ceiling} {\col{CEIL}} +\newcommand{\dividendByte} {\col{DIVIDEND\_BYTE}} +\newcommand{\divisorByte} {\col{DIVISOR\_BYTE}} +\newcommand{\quotientByte} {\col{QUOTIENT\_BYTE}} +\newcommand{\remainderByte} {\col{REMAINDER\_BYTE}} diff --git a/pkg/exceptions.py b/pkg/exceptions.py new file mode 100644 index 0000000..79089bf --- /dev/null +++ b/pkg/exceptions.py @@ -0,0 +1,67 @@ +""" +e.g.: + +\newcommand{\oogxSc}{\texttt{outOfGasException}} % snail case name +\newcommand{\oogx}{\col{OOGX}} +\newcommand{\oogxFull}{\col{OUT\_OF\_GAS\_EXCEPTION}} + +""" + + +exceptions = { + "oog": "out Of Gas", + "opc": "invalid Opcode", + "su": "stack Underflow", + "so": "stack Overflow", + "st": "stack", + "rdc": "return Data Copy", + "jump": "invalid Jump", + "static": "static Context", + "sstore": "sstore Gas", + # invalid first byte of bytecode to deploy + # https://github.com/ethereum/execution-specs/blob/9aeb242ea757cdc2234beb2cf37a61aecbbf0687/src/ethereum/shanghai/vm/exceptions.py + "icp": "invalid Code Prefix", + # not quite an exception + "maxcs": "max Code Size", + # aborting condition or so ... + "csd": "call Stack Overflow", + "bal": "insufficient Balance", + "rev": "revert", + "mxp": "memory Expansion", + "gen": "general", + "oob": "out Of Bounds", +} + +def exception_macros(s): + + f = exceptions[s] + fsc = f.replace(" ", "") # f in snail case + fcu = f.replace(" ", "\\_").upper() # f capitalized, underscores + S = s[0].upper() + s[1:] + + res = f"% {f} exception columns:\n" + res += len(res) * "%" + res += "\n\n" + res += f"\\newcommand{{\\{s}xSH}}{{\\texttt{{{fsc}Exception}}}} % short hand for the snail case name\n" + res += f"\\newcommand{{\\{s}X}}{{\\col{{{fcu}\\_EXCEPTION}}}}\n" + res += f"\\newcommand{{\\{s}x}}{{\\col{{{s.upper()}X}}}}\n" + res += f"\\newcommand{{\\stack{S}x}}{{\\stackSignifier\\{s}x}}\n" + res += f"\\newcommand{{\\dec{s}x}}{{\\decoded{{\\{s}x}}}}\n" + res += f"\\newcommand{{\\i{s}X}}{{\\imported{{\\{s}X}}}}\n" + res += f"\\newcommand{{\\i{s}x}}{{\\imported{{\\{s}x}}}}\n" + res += "\n\n\n" + + return res + + +def all_commands(): + + res = "" + res += "% automaticlaly generated via \"python3 exceptions.py > exceptions.sty\"\n\n\n" + + for name in exceptions: + res += exception_macros(name) + + print(res) + +all_commands() diff --git a/pkg/exceptions.sty b/pkg/exceptions.sty new file mode 100644 index 0000000..3610330 --- /dev/null +++ b/pkg/exceptions.sty @@ -0,0 +1,225 @@ +% automaticlaly generated via "python3 exceptions.py > exceptions.sty" + + +% out Of Gas exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\oogxSH}{\texttt{outOfGasException}} % short hand for the snail case name +\newcommand{\oogX}{\col{OUT\_OF\_GAS\_EXCEPTION}} +\newcommand{\oogx}{\col{OOGX}} +\newcommand{\stackOogx}{\stackSignifier\oogx} +\newcommand{\decoogx}{\decoded{\oogx}} +\newcommand{\ioogX}{\imported{\oogX}} +\newcommand{\ioogx}{\imported{\oogx}} + + + +% invalid Opcode exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\opcxSH}{\texttt{invalidOpcodeException}} % short hand for the snail case name +\newcommand{\opcX}{\col{INVALID\_OPCODE\_EXCEPTION}} +\newcommand{\opcx}{\col{OPCX}} +\newcommand{\stackOpcx}{\stackSignifier\opcx} +\newcommand{\decopcx}{\decoded{\opcx}} +\newcommand{\iopcX}{\imported{\opcX}} +\newcommand{\iopcx}{\imported{\opcx}} + + + +% stack Underflow exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\suxSH}{\texttt{stackUnderflowException}} % short hand for the snail case name +\newcommand{\suX}{\col{STACK\_UNDERFLOW\_EXCEPTION}} +\newcommand{\sux}{\col{SUX}} +\newcommand{\stackSux}{\stackSignifier\sux} +\newcommand{\decsux}{\decoded{\sux}} +\newcommand{\isuX}{\imported{\suX}} +\newcommand{\isux}{\imported{\sux}} + + + +% stack Overflow exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\soxSH}{\texttt{stackOverflowException}} % short hand for the snail case name +\newcommand{\soX}{\col{STACK\_OVERFLOW\_EXCEPTION}} +\newcommand{\sox}{\col{SOX}} +\newcommand{\stackSox}{\stackSignifier\sox} +\newcommand{\decsox}{\decoded{\sox}} +\newcommand{\isoX}{\imported{\soX}} +\newcommand{\isox}{\imported{\sox}} + + + +% stack exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\stxSH}{\texttt{stackException}} % short hand for the snail case name +\newcommand{\stX}{\col{STACK\_EXCEPTION}} +\newcommand{\stx}{\col{STX}} +\newcommand{\stackStx}{\stackSignifier\stx} +\newcommand{\decstx}{\decoded{\stx}} +\newcommand{\istX}{\imported{\stX}} +\newcommand{\istx}{\imported{\stx}} + + + +% return Data Copy exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\rdcxSH}{\texttt{returnDataCopyException}} % short hand for the snail case name +\newcommand{\rdcX}{\col{RETURN\_DATA\_COPY\_EXCEPTION}} +\newcommand{\rdcx}{\col{RDCX}} +\newcommand{\stackRdcx}{\stackSignifier\rdcx} +\newcommand{\decrdcx}{\decoded{\rdcx}} +\newcommand{\irdcX}{\imported{\rdcX}} +\newcommand{\irdcx}{\imported{\rdcx}} + + + +% invalid Jump exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\jumpxSH}{\texttt{invalidJumpException}} % short hand for the snail case name +\newcommand{\jumpX}{\col{INVALID\_JUMP\_EXCEPTION}} +\newcommand{\jumpx}{\col{JUMPX}} +\newcommand{\stackJumpx}{\stackSignifier\jumpx} +\newcommand{\decjumpx}{\decoded{\jumpx}} +\newcommand{\ijumpX}{\imported{\jumpX}} +\newcommand{\ijumpx}{\imported{\jumpx}} + + + +% static Context exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\staticxSH}{\texttt{staticContextException}} % short hand for the snail case name +\newcommand{\staticX}{\col{STATIC\_CONTEXT\_EXCEPTION}} +\newcommand{\staticx}{\col{STATICX}} +\newcommand{\stackStaticx}{\stackSignifier\staticx} +\newcommand{\decstaticx}{\decoded{\staticx}} +\newcommand{\istaticX}{\imported{\staticX}} +\newcommand{\istaticx}{\imported{\staticx}} + + + +% sstore Gas exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\sstorexSH}{\texttt{sstoreGasException}} % short hand for the snail case name +\newcommand{\sstoreX}{\col{SSTORE\_GAS\_EXCEPTION}} +\newcommand{\sstorex}{\col{SSTOREX}} +\newcommand{\stackSstorex}{\stackSignifier\sstorex} +\newcommand{\decsstorex}{\decoded{\sstorex}} +\newcommand{\isstoreX}{\imported{\sstoreX}} +\newcommand{\isstorex}{\imported{\sstorex}} + + + +% invalid Code Prefix exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\icpxSH}{\texttt{invalidCodePrefixException}} % short hand for the snail case name +\newcommand{\icpX}{\col{INVALID\_CODE\_PREFIX\_EXCEPTION}} +\newcommand{\icpx}{\col{ICPX}} +\newcommand{\stackIcpx}{\stackSignifier\icpx} +\newcommand{\decicpx}{\decoded{\icpx}} +\newcommand{\iicpX}{\imported{\icpX}} +\newcommand{\iicpx}{\imported{\icpx}} + + + +% max Code Size exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\maxcsxSH}{\texttt{maxCodeSizeException}} % short hand for the snail case name +\newcommand{\maxcsX}{\col{MAX\_CODE\_SIZE\_EXCEPTION}} +\newcommand{\maxcsx}{\col{MAXCSX}} +\newcommand{\stackMaxcsx}{\stackSignifier\maxcsx} +\newcommand{\decmaxcsx}{\decoded{\maxcsx}} +\newcommand{\imaxcsX}{\imported{\maxcsX}} +\newcommand{\imaxcsx}{\imported{\maxcsx}} + + + +% call Stack Overflow exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\csdxSH}{\texttt{callStackOverflowException}} % short hand for the snail case name +\newcommand{\csdX}{\col{CALL\_STACK\_OVERFLOW\_EXCEPTION}} +\newcommand{\csdx}{\col{CSDX}} +\newcommand{\stackCsdx}{\stackSignifier\csdx} +\newcommand{\deccsdx}{\decoded{\csdx}} +\newcommand{\icsdX}{\imported{\csdX}} +\newcommand{\icsdx}{\imported{\csdx}} + + + +% insufficient Balance exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\balxSH}{\texttt{insufficientBalanceException}} % short hand for the snail case name +\newcommand{\balX}{\col{INSUFFICIENT\_BALANCE\_EXCEPTION}} +\newcommand{\balx}{\col{BALX}} +\newcommand{\stackBalx}{\stackSignifier\balx} +\newcommand{\decbalx}{\decoded{\balx}} +\newcommand{\ibalX}{\imported{\balX}} +\newcommand{\ibalx}{\imported{\balx}} + + + +% revert exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\revxSH}{\texttt{revertException}} % short hand for the snail case name +\newcommand{\revX}{\col{REVERT\_EXCEPTION}} +\newcommand{\revx}{\col{REVX}} +\newcommand{\stackRevx}{\stackSignifier\revx} +\newcommand{\decrevx}{\decoded{\revx}} +\newcommand{\irevX}{\imported{\revX}} +\newcommand{\irevx}{\imported{\revx}} + + + +% memory Expansion exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\mxpxSH}{\texttt{memoryExpansionException}} % short hand for the snail case name +\newcommand{\mxpX}{\col{MEMORY\_EXPANSION\_EXCEPTION}} +\newcommand{\mxpx}{\col{MXPX}} +\newcommand{\stackMxpx}{\stackSignifier\mxpx} +\newcommand{\decmxpx}{\decoded{\mxpx}} +\newcommand{\imxpX}{\imported{\mxpX}} +\newcommand{\imxpx}{\imported{\mxpx}} + + + +% general exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\genxSH}{\texttt{generalException}} % short hand for the snail case name +\newcommand{\genX}{\col{GENERAL\_EXCEPTION}} +\newcommand{\genx}{\col{GENX}} +\newcommand{\stackGenx}{\stackSignifier\genx} +\newcommand{\decgenx}{\decoded{\genx}} +\newcommand{\igenX}{\imported{\genX}} +\newcommand{\igenx}{\imported{\genx}} + + + +% out Of Bounds exception columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\oobxSH}{\texttt{outOfBoundsException}} % short hand for the snail case name +\newcommand{\oobX}{\col{OUT\_OF\_BOUNDS\_EXCEPTION}} +\newcommand{\oobx}{\col{OOBX}} +\newcommand{\stackOobx}{\stackSignifier\oobx} +\newcommand{\decoobx}{\decoded{\oobx}} +\newcommand{\ioobX}{\imported{\oobX}} +\newcommand{\ioobx}{\imported{\oobx}} + + + + diff --git a/pkg/exceptions_old.sty b/pkg/exceptions_old.sty new file mode 100644 index 0000000..c37886a --- /dev/null +++ b/pkg/exceptions_old.sty @@ -0,0 +1,15 @@ +% \newcommand{}{\col{}} +\newcommand{\OOGX}{\col{OUT\_OF\_GAS\_EXCEPTION}} +\newcommand{\oogx}{\col{OOGX}} +\newcommand{\DYNGAS}{\col{DYNAMIC\_GAS}} +\newcommand{\dynGas}{\col{DYNG}} +\newcommand{\MEMEXP}{\col{MEMORY\_EXPANSION}} +\newcommand{\memExp}{\col{MEXP}} +\newcommand{\CSX}{\col{MAXCODESIZE\_EXCEPTION}} +\newcommand{\csx}{\col{MCSX}} +\newcommand{\RDCX}{\col{RETURNDATACOPY\_EXCEPTION}} +\newcommand{\rdcx}{\col{RDCX}} +\newcommand{\GENX}{\col{GENERAL\_EXCEPTION}} +\newcommand{\genx}{\col{GENX}} +\newcommand{\CSDX}{\col{CALL\_STACK\_DEPTH\_EXCEPTION}} +\newcommand{\csdx}{\col{CSDX}} \ No newline at end of file diff --git a/pkg/expansion.sty b/pkg/expansion.sty new file mode 100644 index 0000000..035f1ba --- /dev/null +++ b/pkg/expansion.sty @@ -0,0 +1,111 @@ +\newcommand{\MEMEXPSTAMP} {\col{MEMORY\_EXPANSION\_STAMP}} +\newcommand{\memExpStamp} {\col{MX}\square} +\newcommand{\iMEMEXPSTAMP} {\imported{\MEMEXPSTAMP}} +\newcommand{\iMemExpStamp} {\imported{\memExpStamp}} + +\newcommand{\MEMEXPFLAG} {\col{MEMORY\_EXPANSION\_FLAG}} +\newcommand{\memExpFlag} {\col{MXF}} +\newcommand{\decMEMEXPFLAG} {\decoded{\MEMEXPFLAG}} +\newcommand{\decMemExpFlag} {\decoded{\memExpFlag}} + +\newcommand{\MEXPEVENT} {\col{MEMORY\_EXPANSION\_EVENT}} +\newcommand{\mexpEvent} {\col{EXPANDS}} + +\newcommand{\expByte} {\col{EXP\_BYTE}} +\newcommand{\expAcc} {\col{EXP\_ACC}} + +\newcommand{\lastOffset}[1] {\col{MAX\_\offset\_#1}} +\newcommand{\maxOffset} {\col{MAX\_\offset}} + +\newcommand{\MEMSIZE} {\col{ACTIVE\_WORDS\_IN\_MEMORY}} +\newcommand{\memSize} {\col{WORDS}} +\newcommand{\iMemSize} {\imported{\memSize}} +\newcommand{\iMemSizeNew} {\imported{\memSize\new}} + +\newcommand{\EXPCOST} {\col{ACCRUED\_QUADRATIC\_COST}} +\newcommand{\expCost} {\col{C\_MEM}} + +\newcommand{\codeDeployment} {\col{DEPLOYS}} + +\newcommand{\mxpQuadGas} {\col{QUAD\_COST}} +\newcommand{\mxpLinGas} {\col{LIN\_COST}} + +\newcommand{\iMXPGAS} {\imported{\MXPGAS}} +\newcommand{\iMxpGas} {\imported{\mxpGas}} + +\newcommand{\EVMWORDS} {\col{SIZE\_IN\_EVM\_WORDS}} +\newcommand{\evmWords} {\col{SEVMW}} +\newcommand{\iEVMWORDS} {\imported{\EVMWORDS}} +\newcommand{\iEvmWords} {\imported{\evmWords}} + +\newcommand{\INSTTYPE} {\col{MEMORY\_EXPANSION\_TYPE}} +\newcommand{\instType} {\col{TYPE}} +\newcommand{\INSTRUCTIONTYPE} {\col{INSTRUCTION\_TYPE}} + +\newcommand{\OOOB} {\col{OFFSET\_OUT\_OF\_BOUNDS}} +\newcommand{\ooob} {\col{OOOB}} + +\newcommand{\MXX} {\col{MEMORY\_EXPANSION\_EXCEPTION}} +\newcommand{\iMXX} {\imported{\MXX}} + +\newcommand{\mxx} {\col{MXX}} +\newcommand{\imxx} {\imported{\mxx}} + +\newcommand{\ROOB} {\col{RIDICULOUSLY\_OUT\_OF\_BOUNDS}} +\newcommand{\roob} {\col{ROOB}} + +\newcommand{\LOOB} {\col{LUDICROUSLY\_OUT\_OF\_BOUNDS}} +\newcommand{\loob} {\col{lOOB}} + +\newcommand{\offByte} {\col{BYTE}} +\newcommand{\offAcc} {\col{ACC}} + +\newcommand{\compByte} {\Delta\col{\_BYTE}} +\newcommand{\compAcc} {\Delta\col{\_ACC}} + +\newcommand{\quotient} {\col{QUOTIENT}} +\newcommand{\residue} {\col{RESIDUE}} + +\newcommand{\comp} {\col{COMP}} +% \newcommand{}{\col{}} + +\newcommand{\qOffsetOne} {\col{QUOT\_1}} +\newcommand{\qOffsetOneByte} {\col{QUOT\_1\_BYTE}} +\newcommand{\qOffsetOneAcc} {\col{QUOT\_1\_ACC}} +\newcommand{\auxByteOne} {\col{AUX\_1}} + +\newcommand{\qOffsetTwo} {\col{QUOT\_2}} +\newcommand{\qOffsetTwoByte} {\col{QUOT\_2\_BYTE}} +\newcommand{\qOffsetTwoAcc} {\col{QUOT\_2\_ACC}} +\newcommand{\auxByteTwo} {\col{AUX\_2}} + +\newcommand{\MEMEXPTYPE} {\col{MEMORY\_EXPANSION\_TYPE}} +\newcommand{\decMEMEXPTYPE} {\decoded{\MEMEXPTYPE}} +\newcommand{\iMEMEXPTYPE} {\imported{\decMEMEXPTYPE}} +\newcommand{\memExpType} {\col{MXT}} +\newcommand{\decMemExpType} {\decoded{\memExpType}} +\newcommand{\iMemExpType} {\imported{\decMemExpType}} + +\newcommand{\typeZero} {\texttt{memExpType0}} +\newcommand{\typeOneA} {\texttt{memExpType1a}} +\newcommand{\typeOneB} {\texttt{memExpType1b}} +\newcommand{\typeTwo} {\texttt{memExpType2}} +\newcommand{\typeTre} {\texttt{memExpType3}} + +\newcommand{\noop} {\col{NOOP}} + +\newcommand{\offsetHi}[1] {\offset\col{\_#1}\high} +\newcommand{\offsetLo}[1] {\offset\col{\_#1}\low} +\newcommand{\sizeHi}[1] {\size\col{\_#1}\high} +\newcommand{\sizeLo}[1] {\size\col{\_#1}\low} + +\newcommand{\mxpType}[1] {\col{TYPE\_#1}} +\newcommand{\decMxpType}[1] {\decoded{\mxpType{#1}}} + +\newcommand{\wordCost} {\col{GWORD}} +\newcommand{\decWordCost} {\decoded{\wordCost}} +\newcommand{\byteCost} {\col{GBYTE}} +\newcommand{\decByteCost} {\decoded{\byteCost}} + +\newcommand{\YNMO} {\col{TYPE\_4\_INSTRUCTION\_MAY\_TRIGGER\_NONTRIVIAL\_MMU\_OPERATION}} +\newcommand{\mayTriggerNonTrivialOperation} {\col{T4MTNTOP}} diff --git a/pkg/exponent.sty b/pkg/exponent.sty new file mode 100644 index 0000000..bcc94c3 --- /dev/null +++ b/pkg/exponent.sty @@ -0,0 +1,61 @@ +\newcommand{\lorenzo} [1] {\textcolor{Magenta}{\textbf{Lorenzo: #1}}} % Used for comments + +% General +\newcommand{\expCtMaxComputationExpLog} {\texttt{CT\_MAX\_CMPTN\_EXP\_LOG}} +\newcommand{\expCtMaxMacroExpLog} {\texttt{CT\_MAX\_MACRO\_EXP\_LOG}} +\newcommand{\expCtMaxPreprocessingExpLog} {\texttt{CT\_MAX\_PRPRC\_EXP\_LOG}} + +\newcommand{\expCtMaxComputationModexpLog} {\texttt{CT\_MAX\_CMPTN\_MODEXP\_LOG}} +\newcommand{\expCtMaxMacroModexpLog} {\texttt{CT\_MAX\_MACRO\_MODEXP\_LOG}} +\newcommand{\expCtMaxPreprocessingModexpLog} {\texttt{CT\_MAX\_PRPRC\_MODEXP\_LOG}} + +\newcommand{\flagSumPerspective} {\flagSum\col{\_perspective}} +\newcommand{\flagSumMacro} {\flagSum\col{\_macro}} +\newcommand{\weightedFlagSumMacro} {\weightedFlagSum\col{\_macro}} +\newcommand{\expLog} {\texttt{EXP\_LOG}} +\newcommand{\modexpLog} {\texttt{MODEXP\_LOG}} +\newcommand{\expInst} [1] {\red{[\![\inst{#1}]\!]}} +\newcommand{\expInstExpLog} {\expInst{EXP\_INST\_EXPLOG}} +\newcommand{\expInstModexpLog} {\expInst{EXP\_INST\_MODEXPLOG}} +\newcommand{\exponent} {\col{e}} +\newcommand{\ehi} {\exponent\high} +\newcommand{\elo} {\exponent\low} + +% Computation columns +\newcommand{\compRawByte} {\expComputationColumn{\col{RAW\_}\BYTE}} +\newcommand{\compRawAcc} {\expComputationColumn{\col{RAW\_}\ACC}} +\newcommand{\compTrimByte} {\expComputationColumn{\col{TRIM\_}\BYTE}} +\newcommand{\compTrimAcc} {\expComputationColumn{\col{TRIM\_}\ACC}} +\newcommand{\compMsb} {\expComputationColumn{\col{MSB}}} +\newcommand{\compMsbBit} {\expComputationColumn{\col{MSB\_BIT}}} +\newcommand{\compMsbAcc} {\expComputationColumn{\col{MSB\_}\ACC}} +\newcommand{\compPlateauBit} {\expComputationColumn{PLT\_BIT}} +\newcommand{\compPlateauJmp} {\expComputationColumn{PLT\_JMP}} +\newcommand{\compPlateauAcc} {\expComputationColumn{PLT\_ACC}} + +\newcommand{\compTanzb} {\expComputationColumn{TANZB}} +\newcommand{\compTanzbAcc} {\expComputationColumn{TANZB\_ACC}} + +\newcommand{\compManzb} {\expComputationColumn{MANZB}} +\newcommand{\compManzbAcc} {\expComputationColumn{MANZB\_ACC}} + +% Macro columns +\newcommand{\expMacroInst} {\expMacroColumn\expMod\col{\_INST}} +\newcommand{\expMacroData} [1] {\expMacroColumn{\dataCol{#1}}} + +% Macros for perspectives + +\newcommand{\expComputationSymbol} {\texttt{CMPTN}} +\newcommand{\expMacroSymbol} {\texttt{MACRO}} +\newcommand{\expPreprocessingSymbol} {\texttt{PRPRC}} +% +\newcommand{\expComputationColumn} [1] {\expComputationSymbol\separator{\col{#1}}} +\newcommand{\expMacroColumn} [1] {\expMacroSymbol\separator{\col{#1}}} +\newcommand{\expPreprocessingColumn} [1] {\expPreprocessingSymbol\separator{\col{#1}}} + +% Shared columns +\newcommand{\isComputation} {\expComputationSymbol ^\eye} +% \newcommand{\isMacro} {\expMacroSymbol ^\eye} +% \newcommand{\isPreprocessing} {\expPreprocessingSymbol ^\eye} +\newcommand{\isExpLog} {\col{IS\_EXP\_LOG}} +\newcommand{\isModexpLog} {\col{IS\_MODEXP\_LOG}} diff --git a/pkg/flags_stamps_selectors.sty b/pkg/flags_stamps_selectors.sty new file mode 100644 index 0000000..e2de921 --- /dev/null +++ b/pkg/flags_stamps_selectors.sty @@ -0,0 +1,1503 @@ +% automaticlaly generated via "python3 column_generator.py > flags_stamps_selectors.sty" + +% account data columns: +%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\accMod}{\col{ACC}} + +\newcommand{\accSTAMP}{\col{ACCOUNT\_DATA\_STAMP}} +\newcommand{\accStamp}{\col{ACC}\stamp} +\newcommand{\iAccSTAMP}{\imported{\accSTAMP}} +\newcommand{\iAccStamp}{\imported{\accStamp}} +\newcommand{\accRevStamp}{\col{ACC}\stamp\,\col{REV}} +\newcommand{\iAccRevStamp}{\imported{\accRevStamp}} + +\newcommand{\accFLAG}{\col{ACCOUNT\_DATA\_FLAG}} +\newcommand{\accFlag}{\col{ACC}\flag} +\newcommand{\decAccFLAG}{\decoded{\accFLAG}} +\newcommand{\decAccFlag}{\decoded{\accFlag}} +\newcommand{\idecAccFLAG}{\imported{\decAccFLAG}} +\newcommand{\idecAccFlag}{\imported{\decAccFlag}} + +\newcommand{\accSELECT}{\col{ACCOUNT\_DATA\_SELECTOR}} +\newcommand{\accSelect}{\col{ACC}\select} +\newcommand{\iAccSELECT}{\imported{\accSELECT}} +\newcommand{\iAccSelect}{\imported{\accSelect}} +\newcommand{\stackDecAccFlag}{\stackInstructionDecodedColumn{\accFlag}} + +% adder columns: +%%%%%%%%%%%%%%%% + +\newcommand{\addMod}{\col{ADD}} + +\newcommand{\addSTAMP}{\col{ADDER\_STAMP}} +\newcommand{\addStamp}{\col{ADD}\stamp} +\newcommand{\iAddSTAMP}{\imported{\addSTAMP}} +\newcommand{\iAddStamp}{\imported{\addStamp}} +\newcommand{\addRevStamp}{\col{ADD}\stamp\,\col{REV}} +\newcommand{\iAddRevStamp}{\imported{\addRevStamp}} + +\newcommand{\addFLAG}{\col{ADDER\_FLAG}} +\newcommand{\addFlag}{\col{ADD}\flag} +\newcommand{\decAddFLAG}{\decoded{\addFLAG}} +\newcommand{\decAddFlag}{\decoded{\addFlag}} +\newcommand{\idecAddFLAG}{\imported{\decAddFLAG}} +\newcommand{\idecAddFlag}{\imported{\decAddFlag}} + +\newcommand{\addSELECT}{\col{ADDER\_SELECTOR}} +\newcommand{\addSelect}{\col{ADD}\select} +\newcommand{\iAddSELECT}{\imported{\addSELECT}} +\newcommand{\iAddSelect}{\imported{\addSelect}} +\newcommand{\stackDecAddFlag}{\stackInstructionDecodedColumn{\addFlag}} + +% alu columns: +%%%%%%%%%%%%%% + +\newcommand{\aluMod}{\col{ALU}} + +\newcommand{\aluSTAMP}{\col{ALU\_STAMP}} +\newcommand{\aluStamp}{\col{ALU}\stamp} +\newcommand{\iAluSTAMP}{\imported{\aluSTAMP}} +\newcommand{\iAluStamp}{\imported{\aluStamp}} +\newcommand{\aluRevStamp}{\col{ALU}\stamp\,\col{REV}} +\newcommand{\iAluRevStamp}{\imported{\aluRevStamp}} + +\newcommand{\aluFLAG}{\col{ALU\_FLAG}} +\newcommand{\aluFlag}{\col{ALU}\flag} +\newcommand{\decAluFLAG}{\decoded{\aluFLAG}} +\newcommand{\decAluFlag}{\decoded{\aluFlag}} +\newcommand{\idecAluFLAG}{\imported{\decAluFLAG}} +\newcommand{\idecAluFlag}{\imported{\decAluFlag}} + +\newcommand{\aluSELECT}{\col{ALU\_SELECTOR}} +\newcommand{\aluSelect}{\col{ALU}\select} +\newcommand{\iAluSELECT}{\imported{\aluSELECT}} +\newcommand{\iAluSelect}{\imported{\aluSelect}} +\newcommand{\stackDecAluFlag}{\stackInstructionDecodedColumn{\aluFlag}} + +% block data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\btcMod}{\col{BTC}} + +\newcommand{\btcSTAMP}{\col{BLOCK\_DATA\_STAMP}} +\newcommand{\btcStamp}{\col{BTC}\stamp} +\newcommand{\iBtcSTAMP}{\imported{\btcSTAMP}} +\newcommand{\iBtcStamp}{\imported{\btcStamp}} +\newcommand{\btcRevStamp}{\col{BTC}\stamp\,\col{REV}} +\newcommand{\iBtcRevStamp}{\imported{\btcRevStamp}} + +\newcommand{\btcFLAG}{\col{BLOCK\_DATA\_FLAG}} +\newcommand{\btcFlag}{\col{BTC}\flag} +\newcommand{\decBtcFLAG}{\decoded{\btcFLAG}} +\newcommand{\decBtcFlag}{\decoded{\btcFlag}} +\newcommand{\idecBtcFLAG}{\imported{\decBtcFLAG}} +\newcommand{\idecBtcFlag}{\imported{\decBtcFlag}} + +\newcommand{\btcSELECT}{\col{BLOCK\_DATA\_SELECTOR}} +\newcommand{\btcSelect}{\col{BTC}\select} +\newcommand{\iBtcSELECT}{\imported{\btcSELECT}} +\newcommand{\iBtcSelect}{\imported{\btcSelect}} +\newcommand{\stackDecBtcFlag}{\stackInstructionDecodedColumn{\btcFlag}} + +% block hash columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\blockHashMod}{\col{BLOCKHASH}} + +\newcommand{\blockHashSTAMP}{\col{BLOCK\_HASH\_STAMP}} +\newcommand{\blockHashStamp}{\col{BLOCKHASH}\stamp} +\newcommand{\iBlockHashSTAMP}{\imported{\blockHashSTAMP}} +\newcommand{\iBlockHashStamp}{\imported{\blockHashStamp}} +\newcommand{\blockHashRevStamp}{\col{BLOCKHASH}\stamp\,\col{REV}} +\newcommand{\iBlockHashRevStamp}{\imported{\blockHashRevStamp}} + +\newcommand{\blockHashFLAG}{\col{BLOCK\_HASH\_FLAG}} +\newcommand{\blockHashFlag}{\col{BLOCKHASH}\flag} +\newcommand{\decBlockHashFLAG}{\decoded{\blockHashFLAG}} +\newcommand{\decBlockHashFlag}{\decoded{\blockHashFlag}} +\newcommand{\idecBlockHashFLAG}{\imported{\decBlockHashFLAG}} +\newcommand{\idecBlockHashFlag}{\imported{\decBlockHashFlag}} + +\newcommand{\blockHashSELECT}{\col{BLOCK\_HASH\_SELECTOR}} +\newcommand{\blockHashSelect}{\col{BLOCKHASH}\select} +\newcommand{\iBlockHashSELECT}{\imported{\blockHashSELECT}} +\newcommand{\iBlockHashSelect}{\imported{\blockHashSelect}} +\newcommand{\stackDecBlockHashFlag}{\stackInstructionDecodedColumn{\blockHashFlag}} + +% binary columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\binMod}{\col{BIN}} + +\newcommand{\binSTAMP}{\col{BINARY\_STAMP}} +\newcommand{\binStamp}{\col{BIN}\stamp} +\newcommand{\iBinSTAMP}{\imported{\binSTAMP}} +\newcommand{\iBinStamp}{\imported{\binStamp}} +\newcommand{\binRevStamp}{\col{BIN}\stamp\,\col{REV}} +\newcommand{\iBinRevStamp}{\imported{\binRevStamp}} + +\newcommand{\binFLAG}{\col{BINARY\_FLAG}} +\newcommand{\binFlag}{\col{BIN}\flag} +\newcommand{\decBinFLAG}{\decoded{\binFLAG}} +\newcommand{\decBinFlag}{\decoded{\binFlag}} +\newcommand{\idecBinFLAG}{\imported{\decBinFLAG}} +\newcommand{\idecBinFlag}{\imported{\decBinFlag}} + +\newcommand{\binSELECT}{\col{BINARY\_SELECTOR}} +\newcommand{\binSelect}{\col{BIN}\select} +\newcommand{\iBinSELECT}{\imported{\binSELECT}} +\newcommand{\iBinSelect}{\imported{\binSelect}} +\newcommand{\stackDecBinFlag}{\stackInstructionDecodedColumn{\binFlag}} + +% context columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\conMod}{\col{CON}} + +\newcommand{\conSTAMP}{\col{CONTEXT\_STAMP}} +\newcommand{\conStamp}{\col{CON}\stamp} +\newcommand{\iConSTAMP}{\imported{\conSTAMP}} +\newcommand{\iConStamp}{\imported{\conStamp}} +\newcommand{\conRevStamp}{\col{CON}\stamp\,\col{REV}} +\newcommand{\iConRevStamp}{\imported{\conRevStamp}} + +\newcommand{\conFLAG}{\col{CONTEXT\_FLAG}} +\newcommand{\conFlag}{\col{CON}\flag} +\newcommand{\decConFLAG}{\decoded{\conFLAG}} +\newcommand{\decConFlag}{\decoded{\conFlag}} +\newcommand{\idecConFLAG}{\imported{\decConFLAG}} +\newcommand{\idecConFlag}{\imported{\decConFlag}} + +\newcommand{\conSELECT}{\col{CONTEXT\_SELECTOR}} +\newcommand{\conSelect}{\col{CON}\select} +\newcommand{\iConSELECT}{\imported{\conSELECT}} +\newcommand{\iConSelect}{\imported{\conSelect}} +\newcommand{\stackDecConFlag}{\stackInstructionDecodedColumn{\conFlag}} + +% exponent columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\expMod}{\col{EXP}} + +\newcommand{\expSTAMP}{\col{EXPONENT\_STAMP}} +\newcommand{\expStamp}{\col{EXP}\stamp} +\newcommand{\iExpSTAMP}{\imported{\expSTAMP}} +\newcommand{\iExpStamp}{\imported{\expStamp}} +\newcommand{\expRevStamp}{\col{EXP}\stamp\,\col{REV}} +\newcommand{\iExpRevStamp}{\imported{\expRevStamp}} + +\newcommand{\expFLAG}{\col{EXPONENT\_FLAG}} +\newcommand{\expFlag}{\col{EXP}\flag} +\newcommand{\decExpFLAG}{\decoded{\expFLAG}} +\newcommand{\decExpFlag}{\decoded{\expFlag}} +\newcommand{\idecExpFLAG}{\imported{\decExpFLAG}} +\newcommand{\idecExpFlag}{\imported{\decExpFlag}} + +\newcommand{\expSELECT}{\col{EXPONENT\_SELECTOR}} +\newcommand{\expSelect}{\col{EXP}\select} +\newcommand{\iExpSELECT}{\imported{\expSELECT}} +\newcommand{\iExpSelect}{\imported{\expSelect}} +\newcommand{\stackDecExpFlag}{\stackInstructionDecodedColumn{\expFlag}} + +% euclidean division columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\eucMod}{\col{EUC}} + +\newcommand{\eucSTAMP}{\col{EUCLIDEAN\_DIVISION\_STAMP}} +\newcommand{\eucStamp}{\col{EUC}\stamp} +\newcommand{\iEucSTAMP}{\imported{\eucSTAMP}} +\newcommand{\iEucStamp}{\imported{\eucStamp}} +\newcommand{\eucRevStamp}{\col{EUC}\stamp\,\col{REV}} +\newcommand{\iEucRevStamp}{\imported{\eucRevStamp}} + +\newcommand{\eucFLAG}{\col{EUCLIDEAN\_DIVISION\_FLAG}} +\newcommand{\eucFlag}{\col{EUC}\flag} +\newcommand{\decEucFLAG}{\decoded{\eucFLAG}} +\newcommand{\decEucFlag}{\decoded{\eucFlag}} +\newcommand{\idecEucFLAG}{\imported{\decEucFLAG}} +\newcommand{\idecEucFlag}{\imported{\decEucFlag}} + +\newcommand{\eucSELECT}{\col{EUCLIDEAN\_DIVISION\_SELECTOR}} +\newcommand{\eucSelect}{\col{EUC}\select} +\newcommand{\iEucSELECT}{\imported{\eucSELECT}} +\newcommand{\iEucSelect}{\imported{\eucSelect}} +\newcommand{\stackDecEucFlag}{\stackInstructionDecodedColumn{\eucFlag}} + +% environment columns: +%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\envMod}{\col{ENV}} + +\newcommand{\envSTAMP}{\col{ENVIRONMENT\_STAMP}} +\newcommand{\envStamp}{\col{ENV}\stamp} +\newcommand{\iEnvSTAMP}{\imported{\envSTAMP}} +\newcommand{\iEnvStamp}{\imported{\envStamp}} +\newcommand{\envRevStamp}{\col{ENV}\stamp\,\col{REV}} +\newcommand{\iEnvRevStamp}{\imported{\envRevStamp}} + +\newcommand{\envFLAG}{\col{ENVIRONMENT\_FLAG}} +\newcommand{\envFlag}{\col{ENV}\flag} +\newcommand{\decEnvFLAG}{\decoded{\envFLAG}} +\newcommand{\decEnvFlag}{\decoded{\envFlag}} +\newcommand{\idecEnvFLAG}{\imported{\decEnvFLAG}} +\newcommand{\idecEnvFlag}{\imported{\decEnvFlag}} + +\newcommand{\envSELECT}{\col{ENVIRONMENT\_SELECTOR}} +\newcommand{\envSelect}{\col{ENV}\select} +\newcommand{\iEnvSELECT}{\imported{\envSELECT}} +\newcommand{\iEnvSelect}{\imported{\envSelect}} +\newcommand{\stackDecEnvFlag}{\stackInstructionDecodedColumn{\envFlag}} + +% extended modular arithmetic columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\extMod}{\col{EXT}} + +\newcommand{\extSTAMP}{\col{EXTENDED\_MODULAR\_ARITHMETIC\_STAMP}} +\newcommand{\extStamp}{\col{EXT}\stamp} +\newcommand{\iExtSTAMP}{\imported{\extSTAMP}} +\newcommand{\iExtStamp}{\imported{\extStamp}} +\newcommand{\extRevStamp}{\col{EXT}\stamp\,\col{REV}} +\newcommand{\iExtRevStamp}{\imported{\extRevStamp}} + +\newcommand{\extFLAG}{\col{EXTENDED\_MODULAR\_ARITHMETIC\_FLAG}} +\newcommand{\extFlag}{\col{EXT}\flag} +\newcommand{\decExtFLAG}{\decoded{\extFLAG}} +\newcommand{\decExtFlag}{\decoded{\extFlag}} +\newcommand{\idecExtFLAG}{\imported{\decExtFLAG}} +\newcommand{\idecExtFlag}{\imported{\decExtFlag}} + +\newcommand{\extSELECT}{\col{EXTENDED\_MODULAR\_ARITHMETIC\_SELECTOR}} +\newcommand{\extSelect}{\col{EXT}\select} +\newcommand{\iExtSELECT}{\imported{\extSELECT}} +\newcommand{\iExtSelect}{\imported{\extSelect}} +\newcommand{\stackDecExtFlag}{\stackInstructionDecodedColumn{\extFlag}} + +% gas columns: +%%%%%%%%%%%%%% + +\newcommand{\gasMod}{\col{GAS}} + +\newcommand{\gasSTAMP}{\col{GAS\_STAMP}} +\newcommand{\gasStamp}{\col{GAS}\stamp} +\newcommand{\iGasSTAMP}{\imported{\gasSTAMP}} +\newcommand{\iGasStamp}{\imported{\gasStamp}} +\newcommand{\gasRevStamp}{\col{GAS}\stamp\,\col{REV}} +\newcommand{\iGasRevStamp}{\imported{\gasRevStamp}} + +\newcommand{\gasFLAG}{\col{GAS\_FLAG}} +\newcommand{\gasFlag}{\col{GAS}\flag} +\newcommand{\decGasFLAG}{\decoded{\gasFLAG}} +\newcommand{\decGasFlag}{\decoded{\gasFlag}} +\newcommand{\idecGasFLAG}{\imported{\decGasFLAG}} +\newcommand{\idecGasFlag}{\imported{\decGasFlag}} + +\newcommand{\gasSELECT}{\col{GAS\_SELECTOR}} +\newcommand{\gasSelect}{\col{GAS}\select} +\newcommand{\iGasSELECT}{\imported{\gasSELECT}} +\newcommand{\iGasSelect}{\imported{\gasSelect}} +\newcommand{\stackDecGasFlag}{\stackInstructionDecodedColumn{\gasFlag}} + +% hub columns: +%%%%%%%%%%%%%% + +\newcommand{\hubMod}{\col{HUB}} + +\newcommand{\hubSTAMP}{\col{HUB\_STAMP}} +\newcommand{\hubStamp}{\col{HUB}\stamp} +\newcommand{\iHubSTAMP}{\imported{\hubSTAMP}} +\newcommand{\iHubStamp}{\imported{\hubStamp}} +\newcommand{\hubRevStamp}{\col{HUB}\stamp\,\col{REV}} +\newcommand{\iHubRevStamp}{\imported{\hubRevStamp}} + +\newcommand{\hubFLAG}{\col{HUB\_FLAG}} +\newcommand{\hubFlag}{\col{HUB}\flag} +\newcommand{\decHubFLAG}{\decoded{\hubFLAG}} +\newcommand{\decHubFlag}{\decoded{\hubFlag}} +\newcommand{\idecHubFLAG}{\imported{\decHubFLAG}} +\newcommand{\idecHubFlag}{\imported{\decHubFlag}} + +\newcommand{\hubSELECT}{\col{HUB\_SELECTOR}} +\newcommand{\hubSelect}{\col{HUB}\select} +\newcommand{\iHubSELECT}{\imported{\hubSELECT}} +\newcommand{\iHubSelect}{\imported{\hubSelect}} +\newcommand{\stackDecHubFlag}{\stackInstructionDecodedColumn{\hubFlag}} + +% kec columns: +%%%%%%%%%%%%%% + +\newcommand{\kecMod}{\col{KEC}} + +\newcommand{\kecSTAMP}{\col{KEC\_STAMP}} +\newcommand{\kecStamp}{\col{KEC}\stamp} +\newcommand{\iKecSTAMP}{\imported{\kecSTAMP}} +\newcommand{\iKecStamp}{\imported{\kecStamp}} +\newcommand{\kecRevStamp}{\col{KEC}\stamp\,\col{REV}} +\newcommand{\iKecRevStamp}{\imported{\kecRevStamp}} + +\newcommand{\kecFLAG}{\col{KEC\_FLAG}} +\newcommand{\kecFlag}{\col{KEC}\flag} +\newcommand{\decKecFLAG}{\decoded{\kecFLAG}} +\newcommand{\decKecFlag}{\decoded{\kecFlag}} +\newcommand{\idecKecFLAG}{\imported{\decKecFLAG}} +\newcommand{\idecKecFlag}{\imported{\decKecFlag}} + +\newcommand{\kecSELECT}{\col{KEC\_SELECTOR}} +\newcommand{\kecSelect}{\col{KEC}\select} +\newcommand{\iKecSELECT}{\imported{\kecSELECT}} +\newcommand{\iKecSelect}{\imported{\kecSelect}} +\newcommand{\stackDecKecFlag}{\stackInstructionDecodedColumn{\kecFlag}} + +% log info columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\logMod}{\col{LOG}} + +\newcommand{\logSTAMP}{\col{LOG\_INFO\_STAMP}} +\newcommand{\logStamp}{\col{LOG}\stamp} +\newcommand{\iLogSTAMP}{\imported{\logSTAMP}} +\newcommand{\iLogStamp}{\imported{\logStamp}} +\newcommand{\logRevStamp}{\col{LOG}\stamp\,\col{REV}} +\newcommand{\iLogRevStamp}{\imported{\logRevStamp}} + +\newcommand{\logFLAG}{\col{LOG\_INFO\_FLAG}} +\newcommand{\logFlag}{\col{LOG}\flag} +\newcommand{\decLogFLAG}{\decoded{\logFLAG}} +\newcommand{\decLogFlag}{\decoded{\logFlag}} +\newcommand{\idecLogFLAG}{\imported{\decLogFLAG}} +\newcommand{\idecLogFlag}{\imported{\decLogFlag}} + +\newcommand{\logSELECT}{\col{LOG\_INFO\_SELECTOR}} +\newcommand{\logSelect}{\col{LOG}\select} +\newcommand{\iLogSELECT}{\imported{\logSELECT}} +\newcommand{\iLogSelect}{\imported{\logSelect}} +\newcommand{\stackDecLogFlag}{\stackInstructionDecodedColumn{\logFlag}} + +% mmu columns: +%%%%%%%%%%%%%% + +\newcommand{\mmuMod}{\col{MMU}} + +\newcommand{\mmuSTAMP}{\col{MMU\_STAMP}} +\newcommand{\mmuStamp}{\col{MMU}\stamp} +\newcommand{\iMmuSTAMP}{\imported{\mmuSTAMP}} +\newcommand{\iMmuStamp}{\imported{\mmuStamp}} +\newcommand{\mmuRevStamp}{\col{MMU}\stamp\,\col{REV}} +\newcommand{\iMmuRevStamp}{\imported{\mmuRevStamp}} + +\newcommand{\mmuFLAG}{\col{MMU\_FLAG}} +\newcommand{\mmuFlag}{\col{MMU}\flag} +\newcommand{\decMmuFLAG}{\decoded{\mmuFLAG}} +\newcommand{\decMmuFlag}{\decoded{\mmuFlag}} +\newcommand{\idecMmuFLAG}{\imported{\decMmuFLAG}} +\newcommand{\idecMmuFlag}{\imported{\decMmuFlag}} + +\newcommand{\mmuSELECT}{\col{MMU\_SELECTOR}} +\newcommand{\mmuSelect}{\col{MMU}\select} +\newcommand{\iMmuSELECT}{\imported{\mmuSELECT}} +\newcommand{\iMmuSelect}{\imported{\mmuSelect}} +\newcommand{\stackDecMmuFlag}{\stackInstructionDecodedColumn{\mmuFlag}} + +% mmio columns: +%%%%%%%%%%%%%%% + +\newcommand{\mmioMod}{\col{MMIO}} + +\newcommand{\mmioSTAMP}{\col{MMIO\_STAMP}} +\newcommand{\mmioStamp}{\col{MMIO}\stamp} +\newcommand{\iMmioSTAMP}{\imported{\mmioSTAMP}} +\newcommand{\iMmioStamp}{\imported{\mmioStamp}} +\newcommand{\mmioRevStamp}{\col{MMIO}\stamp\,\col{REV}} +\newcommand{\iMmioRevStamp}{\imported{\mmioRevStamp}} + +\newcommand{\mmioFLAG}{\col{MMIO\_FLAG}} +\newcommand{\mmioFlag}{\col{MMIO}\flag} +\newcommand{\decMmioFLAG}{\decoded{\mmioFLAG}} +\newcommand{\decMmioFlag}{\decoded{\mmioFlag}} +\newcommand{\idecMmioFLAG}{\imported{\decMmioFLAG}} +\newcommand{\idecMmioFlag}{\imported{\decMmioFlag}} + +\newcommand{\mmioSELECT}{\col{MMIO\_SELECTOR}} +\newcommand{\mmioSelect}{\col{MMIO}\select} +\newcommand{\iMmioSELECT}{\imported{\mmioSELECT}} +\newcommand{\iMmioSelect}{\imported{\mmioSelect}} +\newcommand{\stackDecMmioFlag}{\stackInstructionDecodedColumn{\mmioFlag}} + +% multiplier columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\mulMod}{\col{MUL}} + +\newcommand{\mulSTAMP}{\col{MULTIPLIER\_STAMP}} +\newcommand{\mulStamp}{\col{MUL}\stamp} +\newcommand{\iMulSTAMP}{\imported{\mulSTAMP}} +\newcommand{\iMulStamp}{\imported{\mulStamp}} +\newcommand{\mulRevStamp}{\col{MUL}\stamp\,\col{REV}} +\newcommand{\iMulRevStamp}{\imported{\mulRevStamp}} + +\newcommand{\mulFLAG}{\col{MULTIPLIER\_FLAG}} +\newcommand{\mulFlag}{\col{MUL}\flag} +\newcommand{\decMulFLAG}{\decoded{\mulFLAG}} +\newcommand{\decMulFlag}{\decoded{\mulFlag}} +\newcommand{\idecMulFLAG}{\imported{\decMulFLAG}} +\newcommand{\idecMulFlag}{\imported{\decMulFlag}} + +\newcommand{\mulSELECT}{\col{MULTIPLIER\_SELECTOR}} +\newcommand{\mulSelect}{\col{MUL}\select} +\newcommand{\iMulSELECT}{\imported{\mulSELECT}} +\newcommand{\iMulSelect}{\imported{\mulSelect}} +\newcommand{\stackDecMulFlag}{\stackInstructionDecodedColumn{\mulFlag}} + +% modular arithmetic columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\modMod}{\col{MOD}} + +\newcommand{\modSTAMP}{\col{MODULAR\_ARITHMETIC\_STAMP}} +\newcommand{\modStamp}{\col{MOD}\stamp} +\newcommand{\iModSTAMP}{\imported{\modSTAMP}} +\newcommand{\iModStamp}{\imported{\modStamp}} +\newcommand{\modRevStamp}{\col{MOD}\stamp\,\col{REV}} +\newcommand{\iModRevStamp}{\imported{\modRevStamp}} + +\newcommand{\modFLAG}{\col{MODULAR\_ARITHMETIC\_FLAG}} +\newcommand{\modFlag}{\col{MOD}\flag} +\newcommand{\decModFLAG}{\decoded{\modFLAG}} +\newcommand{\decModFlag}{\decoded{\modFlag}} +\newcommand{\idecModFLAG}{\imported{\decModFLAG}} +\newcommand{\idecModFlag}{\imported{\decModFlag}} + +\newcommand{\modSELECT}{\col{MODULAR\_ARITHMETIC\_SELECTOR}} +\newcommand{\modSelect}{\col{MOD}\select} +\newcommand{\iModSELECT}{\imported{\modSELECT}} +\newcommand{\iModSelect}{\imported{\modSelect}} +\newcommand{\stackDecModFlag}{\stackInstructionDecodedColumn{\modFlag}} + +% memory expansion columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\mxpMod}{\col{MXP}} + +\newcommand{\mxpSTAMP}{\col{MEMORY\_EXPANSION\_STAMP}} +\newcommand{\mxpStamp}{\col{MXP}\stamp} +\newcommand{\iMxpSTAMP}{\imported{\mxpSTAMP}} +\newcommand{\iMxpStamp}{\imported{\mxpStamp}} +\newcommand{\mxpRevStamp}{\col{MXP}\stamp\,\col{REV}} +\newcommand{\iMxpRevStamp}{\imported{\mxpRevStamp}} + +\newcommand{\mxpFLAG}{\col{MEMORY\_EXPANSION\_FLAG}} +\newcommand{\mxpFlag}{\col{MXP}\flag} +\newcommand{\decMxpFLAG}{\decoded{\mxpFLAG}} +\newcommand{\decMxpFlag}{\decoded{\mxpFlag}} +\newcommand{\idecMxpFLAG}{\imported{\decMxpFLAG}} +\newcommand{\idecMxpFlag}{\imported{\decMxpFlag}} + +\newcommand{\mxpSELECT}{\col{MEMORY\_EXPANSION\_SELECTOR}} +\newcommand{\mxpSelect}{\col{MXP}\select} +\newcommand{\iMxpSELECT}{\imported{\mxpSELECT}} +\newcommand{\iMxpSelect}{\imported{\mxpSelect}} +\newcommand{\stackDecMxpFlag}{\stackInstructionDecodedColumn{\mxpFlag}} + +% out of bounds columns: +%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\oobMod}{\col{OOB}} + +\newcommand{\oobSTAMP}{\col{OUT\_OF\_BOUNDS\_STAMP}} +\newcommand{\oobStamp}{\col{OOB}\stamp} +\newcommand{\iOobSTAMP}{\imported{\oobSTAMP}} +\newcommand{\iOobStamp}{\imported{\oobStamp}} +\newcommand{\oobRevStamp}{\col{OOB}\stamp\,\col{REV}} +\newcommand{\iOobRevStamp}{\imported{\oobRevStamp}} + +\newcommand{\oobFLAG}{\col{OUT\_OF\_BOUNDS\_FLAG}} +\newcommand{\oobFlag}{\col{OOB}\flag} +\newcommand{\decOobFLAG}{\decoded{\oobFLAG}} +\newcommand{\decOobFlag}{\decoded{\oobFlag}} +\newcommand{\idecOobFLAG}{\imported{\decOobFLAG}} +\newcommand{\idecOobFlag}{\imported{\decOobFlag}} + +\newcommand{\oobSELECT}{\col{OUT\_OF\_BOUNDS\_SELECTOR}} +\newcommand{\oobSelect}{\col{OOB}\select} +\newcommand{\iOobSELECT}{\imported{\oobSELECT}} +\newcommand{\iOobSelect}{\imported{\oobSelect}} +\newcommand{\stackDecOobFlag}{\stackInstructionDecodedColumn{\oobFlag}} + +% ram columns: +%%%%%%%%%%%%%% + +\newcommand{\ramMod}{\col{RAM}} + +\newcommand{\ramSTAMP}{\col{RAM\_STAMP}} +\newcommand{\ramStamp}{\col{RAM}\stamp} +\newcommand{\iRamSTAMP}{\imported{\ramSTAMP}} +\newcommand{\iRamStamp}{\imported{\ramStamp}} +\newcommand{\ramRevStamp}{\col{RAM}\stamp\,\col{REV}} +\newcommand{\iRamRevStamp}{\imported{\ramRevStamp}} + +\newcommand{\ramFLAG}{\col{RAM\_FLAG}} +\newcommand{\ramFlag}{\col{RAM}\flag} +\newcommand{\decRamFLAG}{\decoded{\ramFLAG}} +\newcommand{\decRamFlag}{\decoded{\ramFlag}} +\newcommand{\idecRamFLAG}{\imported{\decRamFLAG}} +\newcommand{\idecRamFlag}{\imported{\decRamFlag}} + +\newcommand{\ramSELECT}{\col{RAM\_SELECTOR}} +\newcommand{\ramSelect}{\col{RAM}\select} +\newcommand{\iRamSELECT}{\imported{\ramSELECT}} +\newcommand{\iRamSelect}{\imported{\ramSelect}} +\newcommand{\stackDecRamFlag}{\stackInstructionDecodedColumn{\ramFlag}} + +% rom columns: +%%%%%%%%%%%%%% + +\newcommand{\romMod}{\col{ROM}} + +\newcommand{\romSTAMP}{\col{ROM\_STAMP}} +\newcommand{\romStamp}{\col{ROM}\stamp} +\newcommand{\iRomSTAMP}{\imported{\romSTAMP}} +\newcommand{\iRomStamp}{\imported{\romStamp}} +\newcommand{\romRevStamp}{\col{ROM}\stamp\,\col{REV}} +\newcommand{\iRomRevStamp}{\imported{\romRevStamp}} + +\newcommand{\romFLAG}{\col{ROM\_FLAG}} +\newcommand{\romFlag}{\col{ROM}\flag} +\newcommand{\decRomFLAG}{\decoded{\romFLAG}} +\newcommand{\decRomFlag}{\decoded{\romFlag}} +\newcommand{\idecRomFLAG}{\imported{\decRomFLAG}} +\newcommand{\idecRomFlag}{\imported{\decRomFlag}} + +\newcommand{\romSELECT}{\col{ROM\_SELECTOR}} +\newcommand{\romSelect}{\col{ROM}\select} +\newcommand{\iRomSELECT}{\imported{\romSELECT}} +\newcommand{\iRomSelect}{\imported{\romSelect}} +\newcommand{\stackDecRomFlag}{\stackInstructionDecodedColumn{\romFlag}} + +% shift columns: +%%%%%%%%%%%%%%%% + +\newcommand{\shfMod}{\col{SHF}} + +\newcommand{\shfSTAMP}{\col{SHIFT\_STAMP}} +\newcommand{\shfStamp}{\col{SHF}\stamp} +\newcommand{\iShfSTAMP}{\imported{\shfSTAMP}} +\newcommand{\iShfStamp}{\imported{\shfStamp}} +\newcommand{\shfRevStamp}{\col{SHF}\stamp\,\col{REV}} +\newcommand{\iShfRevStamp}{\imported{\shfRevStamp}} + +\newcommand{\shfFLAG}{\col{SHIFT\_FLAG}} +\newcommand{\shfFlag}{\col{SHF}\flag} +\newcommand{\decShfFLAG}{\decoded{\shfFLAG}} +\newcommand{\decShfFlag}{\decoded{\shfFlag}} +\newcommand{\idecShfFLAG}{\imported{\decShfFLAG}} +\newcommand{\idecShfFlag}{\imported{\decShfFlag}} + +\newcommand{\shfSELECT}{\col{SHIFT\_SELECTOR}} +\newcommand{\shfSelect}{\col{SHF}\select} +\newcommand{\iShfSELECT}{\imported{\shfSELECT}} +\newcommand{\iShfSelect}{\imported{\shfSelect}} +\newcommand{\stackDecShfFlag}{\stackInstructionDecodedColumn{\shfFlag}} + +% stipend columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\stpMod}{\col{STP}} + +\newcommand{\stpSTAMP}{\col{STIPEND\_STAMP}} +\newcommand{\stpStamp}{\col{STP}\stamp} +\newcommand{\iStpSTAMP}{\imported{\stpSTAMP}} +\newcommand{\iStpStamp}{\imported{\stpStamp}} +\newcommand{\stpRevStamp}{\col{STP}\stamp\,\col{REV}} +\newcommand{\iStpRevStamp}{\imported{\stpRevStamp}} + +\newcommand{\stpFLAG}{\col{STIPEND\_FLAG}} +\newcommand{\stpFlag}{\col{STP}\flag} +\newcommand{\decStpFLAG}{\decoded{\stpFLAG}} +\newcommand{\decStpFlag}{\decoded{\stpFlag}} +\newcommand{\idecStpFLAG}{\imported{\decStpFLAG}} +\newcommand{\idecStpFlag}{\imported{\decStpFlag}} + +\newcommand{\stpSELECT}{\col{STIPEND\_SELECTOR}} +\newcommand{\stpSelect}{\col{STP}\select} +\newcommand{\iStpSELECT}{\imported{\stpSELECT}} +\newcommand{\iStpSelect}{\imported{\stpSelect}} +\newcommand{\stackDecStpFlag}{\stackInstructionDecodedColumn{\stpFlag}} + +% storage columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\stoMod}{\col{STO}} + +\newcommand{\stoSTAMP}{\col{STORAGE\_STAMP}} +\newcommand{\stoStamp}{\col{STO}\stamp} +\newcommand{\iStoSTAMP}{\imported{\stoSTAMP}} +\newcommand{\iStoStamp}{\imported{\stoStamp}} +\newcommand{\stoRevStamp}{\col{STO}\stamp\,\col{REV}} +\newcommand{\iStoRevStamp}{\imported{\stoRevStamp}} + +\newcommand{\stoFLAG}{\col{STORAGE\_FLAG}} +\newcommand{\stoFlag}{\col{STO}\flag} +\newcommand{\decStoFLAG}{\decoded{\stoFLAG}} +\newcommand{\decStoFlag}{\decoded{\stoFlag}} +\newcommand{\idecStoFLAG}{\imported{\decStoFLAG}} +\newcommand{\idecStoFlag}{\imported{\decStoFlag}} + +\newcommand{\stoSELECT}{\col{STORAGE\_SELECTOR}} +\newcommand{\stoSelect}{\col{STO}\select} +\newcommand{\iStoSELECT}{\imported{\stoSELECT}} +\newcommand{\iStoSelect}{\imported{\stoSelect}} +\newcommand{\stackDecStoFlag}{\stackInstructionDecodedColumn{\stoFlag}} + +% address trimming columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\trmMod}{\col{TRM}} + +\newcommand{\trmSTAMP}{\col{ADDRESS\_TRIMMING\_STAMP}} +\newcommand{\trmStamp}{\col{TRM}\stamp} +\newcommand{\iTrmSTAMP}{\imported{\trmSTAMP}} +\newcommand{\iTrmStamp}{\imported{\trmStamp}} +\newcommand{\trmRevStamp}{\col{TRM}\stamp\,\col{REV}} +\newcommand{\iTrmRevStamp}{\imported{\trmRevStamp}} + +\newcommand{\trmFLAG}{\col{ADDRESS\_TRIMMING\_FLAG}} +\newcommand{\trmFlag}{\col{TRM}\flag} +\newcommand{\decTrmFLAG}{\decoded{\trmFLAG}} +\newcommand{\decTrmFlag}{\decoded{\trmFlag}} +\newcommand{\idecTrmFLAG}{\imported{\decTrmFLAG}} +\newcommand{\idecTrmFlag}{\imported{\decTrmFlag}} + +\newcommand{\trmSELECT}{\col{ADDRESS\_TRIMMING\_SELECTOR}} +\newcommand{\trmSelect}{\col{TRM}\select} +\newcommand{\iTrmSELECT}{\imported{\trmSELECT}} +\newcommand{\iTrmSelect}{\imported{\trmSelect}} +\newcommand{\stackDecTrmFlag}{\stackInstructionDecodedColumn{\trmFlag}} + +% word comparison columns: +%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\wcpMod}{\col{WCP}} + +\newcommand{\wcpSTAMP}{\col{WORD\_COMPARISON\_STAMP}} +\newcommand{\wcpStamp}{\col{WCP}\stamp} +\newcommand{\iWcpSTAMP}{\imported{\wcpSTAMP}} +\newcommand{\iWcpStamp}{\imported{\wcpStamp}} +\newcommand{\wcpRevStamp}{\col{WCP}\stamp\,\col{REV}} +\newcommand{\iWcpRevStamp}{\imported{\wcpRevStamp}} + +\newcommand{\wcpFLAG}{\col{WORD\_COMPARISON\_FLAG}} +\newcommand{\wcpFlag}{\col{WCP}\flag} +\newcommand{\decWcpFLAG}{\decoded{\wcpFLAG}} +\newcommand{\decWcpFlag}{\decoded{\wcpFlag}} +\newcommand{\idecWcpFLAG}{\imported{\decWcpFLAG}} +\newcommand{\idecWcpFlag}{\imported{\decWcpFlag}} + +\newcommand{\wcpSELECT}{\col{WORD\_COMPARISON\_SELECTOR}} +\newcommand{\wcpSelect}{\col{WCP}\select} +\newcommand{\iWcpSELECT}{\imported{\wcpSELECT}} +\newcommand{\iWcpSelect}{\imported{\wcpSelect}} +\newcommand{\stackDecWcpFlag}{\stackInstructionDecodedColumn{\wcpFlag}} + +% warmth columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\wrmMod}{\col{WRM}} + +\newcommand{\wrmSTAMP}{\col{WARMTH\_STAMP}} +\newcommand{\wrmStamp}{\col{WRM}\stamp} +\newcommand{\iWrmSTAMP}{\imported{\wrmSTAMP}} +\newcommand{\iWrmStamp}{\imported{\wrmStamp}} +\newcommand{\wrmRevStamp}{\col{WRM}\stamp\,\col{REV}} +\newcommand{\iWrmRevStamp}{\imported{\wrmRevStamp}} + +\newcommand{\wrmFLAG}{\col{WARMTH\_FLAG}} +\newcommand{\wrmFlag}{\col{WRM}\flag} +\newcommand{\decWrmFLAG}{\decoded{\wrmFLAG}} +\newcommand{\decWrmFlag}{\decoded{\wrmFlag}} +\newcommand{\idecWrmFLAG}{\imported{\decWrmFLAG}} +\newcommand{\idecWrmFlag}{\imported{\decWrmFlag}} + +\newcommand{\wrmSELECT}{\col{WARMTH\_SELECTOR}} +\newcommand{\wrmSelect}{\col{WRM}\select} +\newcommand{\iWrmSELECT}{\imported{\wrmSELECT}} +\newcommand{\iWrmSelect}{\imported{\wrmSelect}} +\newcommand{\stackDecWrmFlag}{\stackInstructionDecodedColumn{\wrmFlag}} + +% ecadd data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecaddDMod}{\col{ECADDD}} + +\newcommand{\ecaddDSTAMP}{\col{ECADD\_DATA\_STAMP}} +\newcommand{\ecaddDStamp}{\col{ECADDD}\stamp} +\newcommand{\iEcaddDSTAMP}{\imported{\ecaddDSTAMP}} +\newcommand{\iEcaddDStamp}{\imported{\ecaddDStamp}} +\newcommand{\ecaddDRevStamp}{\col{ECADDD}\stamp\,\col{REV}} +\newcommand{\iEcaddDRevStamp}{\imported{\ecaddDRevStamp}} + +\newcommand{\ecaddDFLAG}{\col{ECADD\_DATA\_FLAG}} +\newcommand{\ecaddDFlag}{\col{ECADDD}\flag} +\newcommand{\decEcaddDFLAG}{\decoded{\ecaddDFLAG}} +\newcommand{\decEcaddDFlag}{\decoded{\ecaddDFlag}} +\newcommand{\idecEcaddDFLAG}{\imported{\decEcaddDFLAG}} +\newcommand{\idecEcaddDFlag}{\imported{\decEcaddDFlag}} + +\newcommand{\ecaddDSELECT}{\col{ECADD\_DATA\_SELECTOR}} +\newcommand{\ecaddDSelect}{\col{ECADDD}\select} +\newcommand{\iEcaddDSELECT}{\imported{\ecaddDSELECT}} +\newcommand{\iEcaddDSelect}{\imported{\ecaddDSelect}} +\newcommand{\stackDecEcaddDFlag}{\stackInstructionDecodedColumn{\ecaddDFlag}} + +% ecadd info columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecaddIMod}{\col{ECADDI}} + +\newcommand{\ecaddISTAMP}{\col{ECADD\_INFO\_STAMP}} +\newcommand{\ecaddIStamp}{\col{ECADDI}\stamp} +\newcommand{\iEcaddISTAMP}{\imported{\ecaddISTAMP}} +\newcommand{\iEcaddIStamp}{\imported{\ecaddIStamp}} +\newcommand{\ecaddIRevStamp}{\col{ECADDI}\stamp\,\col{REV}} +\newcommand{\iEcaddIRevStamp}{\imported{\ecaddIRevStamp}} + +\newcommand{\ecaddIFLAG}{\col{ECADD\_INFO\_FLAG}} +\newcommand{\ecaddIFlag}{\col{ECADDI}\flag} +\newcommand{\decEcaddIFLAG}{\decoded{\ecaddIFLAG}} +\newcommand{\decEcaddIFlag}{\decoded{\ecaddIFlag}} +\newcommand{\idecEcaddIFLAG}{\imported{\decEcaddIFLAG}} +\newcommand{\idecEcaddIFlag}{\imported{\decEcaddIFlag}} + +\newcommand{\ecaddISELECT}{\col{ECADD\_INFO\_SELECTOR}} +\newcommand{\ecaddISelect}{\col{ECADDI}\select} +\newcommand{\iEcaddISELECT}{\imported{\ecaddISELECT}} +\newcommand{\iEcaddISelect}{\imported{\ecaddISelect}} +\newcommand{\stackDecEcaddIFlag}{\stackInstructionDecodedColumn{\ecaddIFlag}} + +% ecmul data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecmulDMod}{\col{ECMULD}} + +\newcommand{\ecmulDSTAMP}{\col{ECMUL\_DATA\_STAMP}} +\newcommand{\ecmulDStamp}{\col{ECMULD}\stamp} +\newcommand{\iEcmulDSTAMP}{\imported{\ecmulDSTAMP}} +\newcommand{\iEcmulDStamp}{\imported{\ecmulDStamp}} +\newcommand{\ecmulDRevStamp}{\col{ECMULD}\stamp\,\col{REV}} +\newcommand{\iEcmulDRevStamp}{\imported{\ecmulDRevStamp}} + +\newcommand{\ecmulDFLAG}{\col{ECMUL\_DATA\_FLAG}} +\newcommand{\ecmulDFlag}{\col{ECMULD}\flag} +\newcommand{\decEcmulDFLAG}{\decoded{\ecmulDFLAG}} +\newcommand{\decEcmulDFlag}{\decoded{\ecmulDFlag}} +\newcommand{\idecEcmulDFLAG}{\imported{\decEcmulDFLAG}} +\newcommand{\idecEcmulDFlag}{\imported{\decEcmulDFlag}} + +\newcommand{\ecmulDSELECT}{\col{ECMUL\_DATA\_SELECTOR}} +\newcommand{\ecmulDSelect}{\col{ECMULD}\select} +\newcommand{\iEcmulDSELECT}{\imported{\ecmulDSELECT}} +\newcommand{\iEcmulDSelect}{\imported{\ecmulDSelect}} +\newcommand{\stackDecEcmulDFlag}{\stackInstructionDecodedColumn{\ecmulDFlag}} + +% ecmul info columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecmulIMod}{\col{ECMULI}} + +\newcommand{\ecmulISTAMP}{\col{ECMUL\_INFO\_STAMP}} +\newcommand{\ecmulIStamp}{\col{ECMULI}\stamp} +\newcommand{\iEcmulISTAMP}{\imported{\ecmulISTAMP}} +\newcommand{\iEcmulIStamp}{\imported{\ecmulIStamp}} +\newcommand{\ecmulIRevStamp}{\col{ECMULI}\stamp\,\col{REV}} +\newcommand{\iEcmulIRevStamp}{\imported{\ecmulIRevStamp}} + +\newcommand{\ecmulIFLAG}{\col{ECMUL\_INFO\_FLAG}} +\newcommand{\ecmulIFlag}{\col{ECMULI}\flag} +\newcommand{\decEcmulIFLAG}{\decoded{\ecmulIFLAG}} +\newcommand{\decEcmulIFlag}{\decoded{\ecmulIFlag}} +\newcommand{\idecEcmulIFLAG}{\imported{\decEcmulIFLAG}} +\newcommand{\idecEcmulIFlag}{\imported{\decEcmulIFlag}} + +\newcommand{\ecmulISELECT}{\col{ECMUL\_INFO\_SELECTOR}} +\newcommand{\ecmulISelect}{\col{ECMULI}\select} +\newcommand{\iEcmulISELECT}{\imported{\ecmulISELECT}} +\newcommand{\iEcmulISelect}{\imported{\ecmulISelect}} +\newcommand{\stackDecEcmulIFlag}{\stackInstructionDecodedColumn{\ecmulIFlag}} + +% identity return data columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\idRDMod}{\col{IDRD}} + +\newcommand{\idRDSTAMP}{\col{IDENTITY\_RETURN\_DATA\_STAMP}} +\newcommand{\idRDStamp}{\col{IDRD}\stamp} +\newcommand{\iIdRDSTAMP}{\imported{\idRDSTAMP}} +\newcommand{\iIdRDStamp}{\imported{\idRDStamp}} +\newcommand{\idRDRevStamp}{\col{IDRD}\stamp\,\col{REV}} +\newcommand{\iIdRDRevStamp}{\imported{\idRDRevStamp}} + +\newcommand{\idRDFLAG}{\col{IDENTITY\_RETURN\_DATA\_FLAG}} +\newcommand{\idRDFlag}{\col{IDRD}\flag} +\newcommand{\decIdRDFLAG}{\decoded{\idRDFLAG}} +\newcommand{\decIdRDFlag}{\decoded{\idRDFlag}} +\newcommand{\idecIdRDFLAG}{\imported{\decIdRDFLAG}} +\newcommand{\idecIdRDFlag}{\imported{\decIdRDFlag}} + +\newcommand{\idRDSELECT}{\col{IDENTITY\_RETURN\_DATA\_SELECTOR}} +\newcommand{\idRDSelect}{\col{IDRD}\select} +\newcommand{\iIdRDSELECT}{\imported{\idRDSELECT}} +\newcommand{\iIdRDSelect}{\imported{\idRDSelect}} +\newcommand{\stackDecIdRDFlag}{\stackInstructionDecodedColumn{\idRDFlag}} + +% log info columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\logInfoMod}{\col{LOGINFO}} + +\newcommand{\logInfoSTAMP}{\col{LOG\_INFO\_STAMP}} +\newcommand{\logInfoStamp}{\col{LOGINFO}\stamp} +\newcommand{\iLogInfoSTAMP}{\imported{\logInfoSTAMP}} +\newcommand{\iLogInfoStamp}{\imported{\logInfoStamp}} +\newcommand{\logInfoRevStamp}{\col{LOGINFO}\stamp\,\col{REV}} +\newcommand{\iLogInfoRevStamp}{\imported{\logInfoRevStamp}} + +\newcommand{\logInfoFLAG}{\col{LOG\_INFO\_FLAG}} +\newcommand{\logInfoFlag}{\col{LOGINFO}\flag} +\newcommand{\decLogInfoFLAG}{\decoded{\logInfoFLAG}} +\newcommand{\decLogInfoFlag}{\decoded{\logInfoFlag}} +\newcommand{\idecLogInfoFLAG}{\imported{\decLogInfoFLAG}} +\newcommand{\idecLogInfoFlag}{\imported{\decLogInfoFlag}} + +\newcommand{\logInfoSELECT}{\col{LOG\_INFO\_SELECTOR}} +\newcommand{\logInfoSelect}{\col{LOGINFO}\select} +\newcommand{\iLogInfoSELECT}{\imported{\logInfoSELECT}} +\newcommand{\iLogInfoSelect}{\imported{\logInfoSelect}} +\newcommand{\stackDecLogInfoFlag}{\stackInstructionDecodedColumn{\logInfoFlag}} + +% log data columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\logDataMod}{\col{LOGDATA}} + +\newcommand{\logDataSTAMP}{\col{LOG\_DATA\_STAMP}} +\newcommand{\logDataStamp}{\col{LOGDATA}\stamp} +\newcommand{\iLogDataSTAMP}{\imported{\logDataSTAMP}} +\newcommand{\iLogDataStamp}{\imported{\logDataStamp}} +\newcommand{\logDataRevStamp}{\col{LOGDATA}\stamp\,\col{REV}} +\newcommand{\iLogDataRevStamp}{\imported{\logDataRevStamp}} + +\newcommand{\logDataFLAG}{\col{LOG\_DATA\_FLAG}} +\newcommand{\logDataFlag}{\col{LOGDATA}\flag} +\newcommand{\decLogDataFLAG}{\decoded{\logDataFLAG}} +\newcommand{\decLogDataFlag}{\decoded{\logDataFlag}} +\newcommand{\idecLogDataFLAG}{\imported{\decLogDataFLAG}} +\newcommand{\idecLogDataFlag}{\imported{\decLogDataFlag}} + +\newcommand{\logDataSELECT}{\col{LOG\_DATA\_SELECTOR}} +\newcommand{\logDataSelect}{\col{LOGDATA}\select} +\newcommand{\iLogDataSELECT}{\imported{\logDataSELECT}} +\newcommand{\iLogDataSelect}{\imported{\logDataSelect}} +\newcommand{\stackDecLogDataFlag}{\stackInstructionDecodedColumn{\logDataFlag}} + +% hash info columns: +%%%%%%%%%%%%%%%%%%%% + +\newcommand{\hashInfoMod}{\col{HASHINFO}} + +\newcommand{\hashInfoSTAMP}{\col{HASH\_INFO\_STAMP}} +\newcommand{\hashInfoStamp}{\col{HASHINFO}\stamp} +\newcommand{\iHashInfoSTAMP}{\imported{\hashInfoSTAMP}} +\newcommand{\iHashInfoStamp}{\imported{\hashInfoStamp}} +\newcommand{\hashInfoRevStamp}{\col{HASHINFO}\stamp\,\col{REV}} +\newcommand{\iHashInfoRevStamp}{\imported{\hashInfoRevStamp}} + +\newcommand{\hashInfoFLAG}{\col{HASH\_INFO\_FLAG}} +\newcommand{\hashInfoFlag}{\col{HASHINFO}\flag} +\newcommand{\decHashInfoFLAG}{\decoded{\hashInfoFLAG}} +\newcommand{\decHashInfoFlag}{\decoded{\hashInfoFlag}} +\newcommand{\idecHashInfoFLAG}{\imported{\decHashInfoFLAG}} +\newcommand{\idecHashInfoFlag}{\imported{\decHashInfoFlag}} + +\newcommand{\hashInfoSELECT}{\col{HASH\_INFO\_SELECTOR}} +\newcommand{\hashInfoSelect}{\col{HASHINFO}\select} +\newcommand{\iHashInfoSELECT}{\imported{\hashInfoSELECT}} +\newcommand{\iHashInfoSelect}{\imported{\hashInfoSelect}} +\newcommand{\stackDecHashInfoFlag}{\stackInstructionDecodedColumn{\hashInfoFlag}} + +% hash data columns: +%%%%%%%%%%%%%%%%%%%% + +\newcommand{\hashDataMod}{\col{HASHDATA}} + +\newcommand{\hashDataSTAMP}{\col{HASH\_DATA\_STAMP}} +\newcommand{\hashDataStamp}{\col{HASHDATA}\stamp} +\newcommand{\iHashDataSTAMP}{\imported{\hashDataSTAMP}} +\newcommand{\iHashDataStamp}{\imported{\hashDataStamp}} +\newcommand{\hashDataRevStamp}{\col{HASHDATA}\stamp\,\col{REV}} +\newcommand{\iHashDataRevStamp}{\imported{\hashDataRevStamp}} + +\newcommand{\hashDataFLAG}{\col{HASH\_DATA\_FLAG}} +\newcommand{\hashDataFlag}{\col{HASHDATA}\flag} +\newcommand{\decHashDataFLAG}{\decoded{\hashDataFLAG}} +\newcommand{\decHashDataFlag}{\decoded{\hashDataFlag}} +\newcommand{\idecHashDataFLAG}{\imported{\decHashDataFLAG}} +\newcommand{\idecHashDataFlag}{\imported{\decHashDataFlag}} + +\newcommand{\hashDataSELECT}{\col{HASH\_DATA\_SELECTOR}} +\newcommand{\hashDataSelect}{\col{HASHDATA}\select} +\newcommand{\iHashDataSELECT}{\imported{\hashDataSELECT}} +\newcommand{\iHashDataSelect}{\imported{\hashDataSelect}} +\newcommand{\stackDecHashDataFlag}{\stackInstructionDecodedColumn{\hashDataFlag}} + +% modexp columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\modexpMod}{\col{MODEXP}} + +\newcommand{\modexpSTAMP}{\col{MODEXP\_STAMP}} +\newcommand{\modexpStamp}{\col{MODEXP}\stamp} +\newcommand{\iModexpSTAMP}{\imported{\modexpSTAMP}} +\newcommand{\iModexpStamp}{\imported{\modexpStamp}} +\newcommand{\modexpRevStamp}{\col{MODEXP}\stamp\,\col{REV}} +\newcommand{\iModexpRevStamp}{\imported{\modexpRevStamp}} + +\newcommand{\modexpFLAG}{\col{MODEXP\_FLAG}} +\newcommand{\modexpFlag}{\col{MODEXP}\flag} +\newcommand{\decModexpFLAG}{\decoded{\modexpFLAG}} +\newcommand{\decModexpFlag}{\decoded{\modexpFlag}} +\newcommand{\idecModexpFLAG}{\imported{\decModexpFLAG}} +\newcommand{\idecModexpFlag}{\imported{\decModexpFlag}} + +\newcommand{\modexpSELECT}{\col{MODEXP\_SELECTOR}} +\newcommand{\modexpSelect}{\col{MODEXP}\select} +\newcommand{\iModexpSELECT}{\imported{\modexpSELECT}} +\newcommand{\iModexpSelect}{\imported{\modexpSelect}} +\newcommand{\stackDecModexpFlag}{\stackInstructionDecodedColumn{\modexpFlag}} + +% blake data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\blakeDataMod}{\col{BLAKEDATA}} + +\newcommand{\blakeDataSTAMP}{\col{BLAKE\_DATA\_STAMP}} +\newcommand{\blakeDataStamp}{\col{BLAKEDATA}\stamp} +\newcommand{\iBlakeDataSTAMP}{\imported{\blakeDataSTAMP}} +\newcommand{\iBlakeDataStamp}{\imported{\blakeDataStamp}} +\newcommand{\blakeDataRevStamp}{\col{BLAKEDATA}\stamp\,\col{REV}} +\newcommand{\iBlakeDataRevStamp}{\imported{\blakeDataRevStamp}} + +\newcommand{\blakeDataFLAG}{\col{BLAKE\_DATA\_FLAG}} +\newcommand{\blakeDataFlag}{\col{BLAKEDATA}\flag} +\newcommand{\decBlakeDataFLAG}{\decoded{\blakeDataFLAG}} +\newcommand{\decBlakeDataFlag}{\decoded{\blakeDataFlag}} +\newcommand{\idecBlakeDataFLAG}{\imported{\decBlakeDataFLAG}} +\newcommand{\idecBlakeDataFlag}{\imported{\decBlakeDataFlag}} + +\newcommand{\blakeDataSELECT}{\col{BLAKE\_DATA\_SELECTOR}} +\newcommand{\blakeDataSelect}{\col{BLAKEDATA}\select} +\newcommand{\iBlakeDataSELECT}{\imported{\blakeDataSELECT}} +\newcommand{\iBlakeDataSelect}{\imported{\blakeDataSelect}} +\newcommand{\stackDecBlakeDataFlag}{\stackInstructionDecodedColumn{\blakeDataFlag}} + +% blake columns: +%%%%%%%%%%%%%%%% + +\newcommand{\blakeMod}{\col{BLAKE}} + +\newcommand{\blakeSTAMP}{\col{BLAKE\_STAMP}} +\newcommand{\blakeStamp}{\col{BLAKE}\stamp} +\newcommand{\iBlakeSTAMP}{\imported{\blakeSTAMP}} +\newcommand{\iBlakeStamp}{\imported{\blakeStamp}} +\newcommand{\blakeRevStamp}{\col{BLAKE}\stamp\,\col{REV}} +\newcommand{\iBlakeRevStamp}{\imported{\blakeRevStamp}} + +\newcommand{\blakeFLAG}{\col{BLAKE\_FLAG}} +\newcommand{\blakeFlag}{\col{BLAKE}\flag} +\newcommand{\decBlakeFLAG}{\decoded{\blakeFLAG}} +\newcommand{\decBlakeFlag}{\decoded{\blakeFlag}} +\newcommand{\idecBlakeFLAG}{\imported{\decBlakeFLAG}} +\newcommand{\idecBlakeFlag}{\imported{\decBlakeFlag}} + +\newcommand{\blakeSELECT}{\col{BLAKE\_SELECTOR}} +\newcommand{\blakeSelect}{\col{BLAKE}\select} +\newcommand{\iBlakeSELECT}{\imported{\blakeSELECT}} +\newcommand{\iBlakeSelect}{\imported{\blakeSelect}} +\newcommand{\stackDecBlakeFlag}{\stackInstructionDecodedColumn{\blakeFlag}} + +% ec data columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\ecDataMod}{\col{ECDATA}} + +\newcommand{\ecDataSTAMP}{\col{EC\_DATA\_STAMP}} +\newcommand{\ecDataStamp}{\col{ECDATA}\stamp} +\newcommand{\iEcDataSTAMP}{\imported{\ecDataSTAMP}} +\newcommand{\iEcDataStamp}{\imported{\ecDataStamp}} +\newcommand{\ecDataRevStamp}{\col{ECDATA}\stamp\,\col{REV}} +\newcommand{\iEcDataRevStamp}{\imported{\ecDataRevStamp}} + +\newcommand{\ecDataFLAG}{\col{EC\_DATA\_FLAG}} +\newcommand{\ecDataFlag}{\col{ECDATA}\flag} +\newcommand{\decEcDataFLAG}{\decoded{\ecDataFLAG}} +\newcommand{\decEcDataFlag}{\decoded{\ecDataFlag}} +\newcommand{\idecEcDataFLAG}{\imported{\decEcDataFLAG}} +\newcommand{\idecEcDataFlag}{\imported{\decEcDataFlag}} + +\newcommand{\ecDataSELECT}{\col{EC\_DATA\_SELECTOR}} +\newcommand{\ecDataSelect}{\col{ECDATA}\select} +\newcommand{\iEcDataSELECT}{\imported{\ecDataSELECT}} +\newcommand{\iEcDataSelect}{\imported{\ecDataSelect}} +\newcommand{\stackDecEcDataFlag}{\stackInstructionDecodedColumn{\ecDataFlag}} + +% prec info columns: +%%%%%%%%%%%%%%%%%%%% + +\newcommand{\precInfoMod}{\col{PRECINFO}} + +\newcommand{\precInfoSTAMP}{\col{PREC\_INFO\_STAMP}} +\newcommand{\precInfoStamp}{\col{PRECINFO}\stamp} +\newcommand{\iPrecInfoSTAMP}{\imported{\precInfoSTAMP}} +\newcommand{\iPrecInfoStamp}{\imported{\precInfoStamp}} +\newcommand{\precInfoRevStamp}{\col{PRECINFO}\stamp\,\col{REV}} +\newcommand{\iPrecInfoRevStamp}{\imported{\precInfoRevStamp}} + +\newcommand{\precInfoFLAG}{\col{PREC\_INFO\_FLAG}} +\newcommand{\precInfoFlag}{\col{PRECINFO}\flag} +\newcommand{\decPrecInfoFLAG}{\decoded{\precInfoFLAG}} +\newcommand{\decPrecInfoFlag}{\decoded{\precInfoFlag}} +\newcommand{\idecPrecInfoFLAG}{\imported{\decPrecInfoFLAG}} +\newcommand{\idecPrecInfoFlag}{\imported{\decPrecInfoFlag}} + +\newcommand{\precInfoSELECT}{\col{PREC\_INFO\_SELECTOR}} +\newcommand{\precInfoSelect}{\col{PRECINFO}\select} +\newcommand{\iPrecInfoSELECT}{\imported{\precInfoSELECT}} +\newcommand{\iPrecInfoSelect}{\imported{\precInfoSelect}} +\newcommand{\stackDecPrecInfoFlag}{\stackInstructionDecodedColumn{\precInfoFlag}} + +% txn data columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\txnDataMod}{\col{TXNDATA}} + +\newcommand{\txnDataSTAMP}{\col{TXN\_DATA\_STAMP}} +\newcommand{\txnDataStamp}{\col{TXNDATA}\stamp} +\newcommand{\iTxnDataSTAMP}{\imported{\txnDataSTAMP}} +\newcommand{\iTxnDataStamp}{\imported{\txnDataStamp}} +\newcommand{\txnDataRevStamp}{\col{TXNDATA}\stamp\,\col{REV}} +\newcommand{\iTxnDataRevStamp}{\imported{\txnDataRevStamp}} + +\newcommand{\txnDataFLAG}{\col{TXN\_DATA\_FLAG}} +\newcommand{\txnDataFlag}{\col{TXNDATA}\flag} +\newcommand{\decTxnDataFLAG}{\decoded{\txnDataFLAG}} +\newcommand{\decTxnDataFlag}{\decoded{\txnDataFlag}} +\newcommand{\idecTxnDataFLAG}{\imported{\decTxnDataFLAG}} +\newcommand{\idecTxnDataFlag}{\imported{\decTxnDataFlag}} + +\newcommand{\txnDataSELECT}{\col{TXN\_DATA\_SELECTOR}} +\newcommand{\txnDataSelect}{\col{TXNDATA}\select} +\newcommand{\iTxnDataSELECT}{\imported{\txnDataSELECT}} +\newcommand{\iTxnDataSelect}{\imported{\txnDataSelect}} +\newcommand{\stackDecTxnDataFlag}{\stackInstructionDecodedColumn{\txnDataFlag}} + +% txn comp columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\txnCompMod}{\col{TXNCOMP}} + +\newcommand{\txnCompSTAMP}{\col{TXN\_COMP\_STAMP}} +\newcommand{\txnCompStamp}{\col{TXNCOMP}\stamp} +\newcommand{\iTxnCompSTAMP}{\imported{\txnCompSTAMP}} +\newcommand{\iTxnCompStamp}{\imported{\txnCompStamp}} +\newcommand{\txnCompRevStamp}{\col{TXNCOMP}\stamp\,\col{REV}} +\newcommand{\iTxnCompRevStamp}{\imported{\txnCompRevStamp}} + +\newcommand{\txnCompFLAG}{\col{TXN\_COMP\_FLAG}} +\newcommand{\txnCompFlag}{\col{TXNCOMP}\flag} +\newcommand{\decTxnCompFLAG}{\decoded{\txnCompFLAG}} +\newcommand{\decTxnCompFlag}{\decoded{\txnCompFlag}} +\newcommand{\idecTxnCompFLAG}{\imported{\decTxnCompFLAG}} +\newcommand{\idecTxnCompFlag}{\imported{\decTxnCompFlag}} + +\newcommand{\txnCompSELECT}{\col{TXN\_COMP\_SELECTOR}} +\newcommand{\txnCompSelect}{\col{TXNCOMP}\select} +\newcommand{\iTxnCompSELECT}{\imported{\txnCompSELECT}} +\newcommand{\iTxnCompSelect}{\imported{\txnCompSelect}} +\newcommand{\stackDecTxnCompFlag}{\stackInstructionDecodedColumn{\txnCompFlag}} + +% rom lex columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\romLexMod}{\col{ROMLEX}} + +\newcommand{\romLexSTAMP}{\col{ROM\_LEX\_STAMP}} +\newcommand{\romLexStamp}{\col{ROMLEX}\stamp} +\newcommand{\iRomLexSTAMP}{\imported{\romLexSTAMP}} +\newcommand{\iRomLexStamp}{\imported{\romLexStamp}} +\newcommand{\romLexRevStamp}{\col{ROMLEX}\stamp\,\col{REV}} +\newcommand{\iRomLexRevStamp}{\imported{\romLexRevStamp}} + +\newcommand{\romLexFLAG}{\col{ROM\_LEX\_FLAG}} +\newcommand{\romLexFlag}{\col{ROMLEX}\flag} +\newcommand{\decRomLexFLAG}{\decoded{\romLexFLAG}} +\newcommand{\decRomLexFlag}{\decoded{\romLexFlag}} +\newcommand{\idecRomLexFLAG}{\imported{\decRomLexFLAG}} +\newcommand{\idecRomLexFlag}{\imported{\decRomLexFlag}} + +\newcommand{\romLexSELECT}{\col{ROM\_LEX\_SELECTOR}} +\newcommand{\romLexSelect}{\col{ROMLEX}\select} +\newcommand{\iRomLexSELECT}{\imported{\romLexSELECT}} +\newcommand{\iRomLexSelect}{\imported{\romLexSelect}} +\newcommand{\stackDecRomLexFlag}{\stackInstructionDecodedColumn{\romLexFlag}} + +% shakira columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\shakiraMod}{\col{SHAKIRA}} + +\newcommand{\shakiraSTAMP}{\col{SHAKIRA\_STAMP}} +\newcommand{\shakiraStamp}{\col{SHAKIRA}\stamp} +\newcommand{\iShakiraSTAMP}{\imported{\shakiraSTAMP}} +\newcommand{\iShakiraStamp}{\imported{\shakiraStamp}} +\newcommand{\shakiraRevStamp}{\col{SHAKIRA}\stamp\,\col{REV}} +\newcommand{\iShakiraRevStamp}{\imported{\shakiraRevStamp}} + +\newcommand{\shakiraFLAG}{\col{SHAKIRA\_FLAG}} +\newcommand{\shakiraFlag}{\col{SHAKIRA}\flag} +\newcommand{\decShakiraFLAG}{\decoded{\shakiraFLAG}} +\newcommand{\decShakiraFlag}{\decoded{\shakiraFlag}} +\newcommand{\idecShakiraFLAG}{\imported{\decShakiraFLAG}} +\newcommand{\idecShakiraFlag}{\imported{\decShakiraFlag}} + +\newcommand{\shakiraSELECT}{\col{SHAKIRA\_SELECTOR}} +\newcommand{\shakiraSelect}{\col{SHAKIRA}\select} +\newcommand{\iShakiraSELECT}{\imported{\shakiraSELECT}} +\newcommand{\iShakiraSelect}{\imported{\shakiraSelect}} +\newcommand{\stackDecShakiraFlag}{\stackInstructionDecodedColumn{\shakiraFlag}} + +% rip sha columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\ripShaMod}{\col{RIPSHA}} + +\newcommand{\ripShaSTAMP}{\col{RIP\_SHA\_STAMP}} +\newcommand{\ripShaStamp}{\col{RIPSHA}\stamp} +\newcommand{\iRipShaSTAMP}{\imported{\ripShaSTAMP}} +\newcommand{\iRipShaStamp}{\imported{\ripShaStamp}} +\newcommand{\ripShaRevStamp}{\col{RIPSHA}\stamp\,\col{REV}} +\newcommand{\iRipShaRevStamp}{\imported{\ripShaRevStamp}} + +\newcommand{\ripShaFLAG}{\col{RIP\_SHA\_FLAG}} +\newcommand{\ripShaFlag}{\col{RIPSHA}\flag} +\newcommand{\decRipShaFLAG}{\decoded{\ripShaFLAG}} +\newcommand{\decRipShaFlag}{\decoded{\ripShaFlag}} +\newcommand{\idecRipShaFLAG}{\imported{\decRipShaFLAG}} +\newcommand{\idecRipShaFlag}{\imported{\decRipShaFlag}} + +\newcommand{\ripShaSELECT}{\col{RIP\_SHA\_SELECTOR}} +\newcommand{\ripShaSelect}{\col{RIPSHA}\select} +\newcommand{\iRipShaSELECT}{\imported{\ripShaSELECT}} +\newcommand{\iRipShaSelect}{\imported{\ripShaSelect}} +\newcommand{\stackDecRipShaFlag}{\stackInstructionDecodedColumn{\ripShaFlag}} + +% blk mdx columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\blkMdxMod}{\col{BLKMDX}} + +\newcommand{\blkMdxSTAMP}{\col{BLK\_MDX\_STAMP}} +\newcommand{\blkMdxStamp}{\col{BLKMDX}\stamp} +\newcommand{\iBlkMdxSTAMP}{\imported{\blkMdxSTAMP}} +\newcommand{\iBlkMdxStamp}{\imported{\blkMdxStamp}} +\newcommand{\blkMdxRevStamp}{\col{BLKMDX}\stamp\,\col{REV}} +\newcommand{\iBlkMdxRevStamp}{\imported{\blkMdxRevStamp}} + +\newcommand{\blkMdxFLAG}{\col{BLK\_MDX\_FLAG}} +\newcommand{\blkMdxFlag}{\col{BLKMDX}\flag} +\newcommand{\decBlkMdxFLAG}{\decoded{\blkMdxFLAG}} +\newcommand{\decBlkMdxFlag}{\decoded{\blkMdxFlag}} +\newcommand{\idecBlkMdxFLAG}{\imported{\decBlkMdxFLAG}} +\newcommand{\idecBlkMdxFlag}{\imported{\decBlkMdxFlag}} + +\newcommand{\blkMdxSELECT}{\col{BLK\_MDX\_SELECTOR}} +\newcommand{\blkMdxSelect}{\col{BLKMDX}\select} +\newcommand{\iBlkMdxSELECT}{\imported{\blkMdxSELECT}} +\newcommand{\iBlkMdxSelect}{\imported{\blkMdxSelect}} +\newcommand{\stackDecBlkMdxFlag}{\stackInstructionDecodedColumn{\blkMdxFlag}} + +% txn columns: +%%%%%%%%%%%%%% + +\newcommand{\txnMod}{\col{TXN}} + +\newcommand{\txnSTAMP}{\col{TXN\_STAMP}} +\newcommand{\txnStamp}{\col{TXN}\stamp} +\newcommand{\iTxnSTAMP}{\imported{\txnSTAMP}} +\newcommand{\iTxnStamp}{\imported{\txnStamp}} +\newcommand{\txnRevStamp}{\col{TXN}\stamp\,\col{REV}} +\newcommand{\iTxnRevStamp}{\imported{\txnRevStamp}} + +\newcommand{\txnFLAG}{\col{TXN\_FLAG}} +\newcommand{\txnFlag}{\col{TXN}\flag} +\newcommand{\decTxnFLAG}{\decoded{\txnFLAG}} +\newcommand{\decTxnFlag}{\decoded{\txnFlag}} +\newcommand{\idecTxnFLAG}{\imported{\decTxnFLAG}} +\newcommand{\idecTxnFlag}{\imported{\decTxnFlag}} + +\newcommand{\txnSELECT}{\col{TXN\_SELECTOR}} +\newcommand{\txnSelect}{\col{TXN}\select} +\newcommand{\iTxnSELECT}{\imported{\txnSELECT}} +\newcommand{\iTxnSelect}{\imported{\txnSelect}} +\newcommand{\stackDecTxnFlag}{\stackInstructionDecodedColumn{\txnFlag}} + +% stack ram columns: +%%%%%%%%%%%%%%%%%%%% + +\newcommand{\stackRamMod}{\col{STACKRAM}} + +\newcommand{\stackRamSTAMP}{\col{STACK\_RAM\_STAMP}} +\newcommand{\stackRamStamp}{\col{STACKRAM}\stamp} +\newcommand{\iStackRamSTAMP}{\imported{\stackRamSTAMP}} +\newcommand{\iStackRamStamp}{\imported{\stackRamStamp}} +\newcommand{\stackRamRevStamp}{\col{STACKRAM}\stamp\,\col{REV}} +\newcommand{\iStackRamRevStamp}{\imported{\stackRamRevStamp}} + +\newcommand{\stackRamFLAG}{\col{STACK\_RAM\_FLAG}} +\newcommand{\stackRamFlag}{\col{STACKRAM}\flag} +\newcommand{\decStackRamFLAG}{\decoded{\stackRamFLAG}} +\newcommand{\decStackRamFlag}{\decoded{\stackRamFlag}} +\newcommand{\idecStackRamFLAG}{\imported{\decStackRamFLAG}} +\newcommand{\idecStackRamFlag}{\imported{\decStackRamFlag}} + +\newcommand{\stackRamSELECT}{\col{STACK\_RAM\_SELECTOR}} +\newcommand{\stackRamSelect}{\col{STACKRAM}\select} +\newcommand{\iStackRamSELECT}{\imported{\stackRamSELECT}} +\newcommand{\iStackRamSelect}{\imported{\stackRamSelect}} +\newcommand{\stackDecStackRamFlag}{\stackInstructionDecodedColumn{\stackRamFlag}} + +% machine state columns: +%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\machineStateMod}{\col{MACHINESTATE}} + +\newcommand{\machineStateSTAMP}{\col{MACHINE\_STATE\_STAMP}} +\newcommand{\machineStateStamp}{\col{MACHINESTATE}\stamp} +\newcommand{\iMachineStateSTAMP}{\imported{\machineStateSTAMP}} +\newcommand{\iMachineStateStamp}{\imported{\machineStateStamp}} +\newcommand{\machineStateRevStamp}{\col{MACHINESTATE}\stamp\,\col{REV}} +\newcommand{\iMachineStateRevStamp}{\imported{\machineStateRevStamp}} + +\newcommand{\machineStateFLAG}{\col{MACHINE\_STATE\_FLAG}} +\newcommand{\machineStateFlag}{\col{MACHINESTATE}\flag} +\newcommand{\decMachineStateFLAG}{\decoded{\machineStateFLAG}} +\newcommand{\decMachineStateFlag}{\decoded{\machineStateFlag}} +\newcommand{\idecMachineStateFLAG}{\imported{\decMachineStateFLAG}} +\newcommand{\idecMachineStateFlag}{\imported{\decMachineStateFlag}} + +\newcommand{\machineStateSELECT}{\col{MACHINE\_STATE\_SELECTOR}} +\newcommand{\machineStateSelect}{\col{MACHINESTATE}\select} +\newcommand{\iMachineStateSELECT}{\imported{\machineStateSELECT}} +\newcommand{\iMachineStateSelect}{\imported{\machineStateSelect}} +\newcommand{\stackDecMachineStateFlag}{\stackInstructionDecodedColumn{\machineStateFlag}} + +% push pop columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\pushPopMod}{\col{PUSHPOP}} + +\newcommand{\pushPopSTAMP}{\col{PUSH\_POP\_STAMP}} +\newcommand{\pushPopStamp}{\col{PUSHPOP}\stamp} +\newcommand{\iPushPopSTAMP}{\imported{\pushPopSTAMP}} +\newcommand{\iPushPopStamp}{\imported{\pushPopStamp}} +\newcommand{\pushPopRevStamp}{\col{PUSHPOP}\stamp\,\col{REV}} +\newcommand{\iPushPopRevStamp}{\imported{\pushPopRevStamp}} + +\newcommand{\pushPopFLAG}{\col{PUSH\_POP\_FLAG}} +\newcommand{\pushPopFlag}{\col{PUSHPOP}\flag} +\newcommand{\decPushPopFLAG}{\decoded{\pushPopFLAG}} +\newcommand{\decPushPopFlag}{\decoded{\pushPopFlag}} +\newcommand{\idecPushPopFLAG}{\imported{\decPushPopFLAG}} +\newcommand{\idecPushPopFlag}{\imported{\decPushPopFlag}} + +\newcommand{\pushPopSELECT}{\col{PUSH\_POP\_SELECTOR}} +\newcommand{\pushPopSelect}{\col{PUSHPOP}\select} +\newcommand{\iPushPopSELECT}{\imported{\pushPopSELECT}} +\newcommand{\iPushPopSelect}{\imported{\pushPopSelect}} +\newcommand{\stackDecPushPopFlag}{\stackInstructionDecodedColumn{\pushPopFlag}} + +% dup columns: +%%%%%%%%%%%%%% + +\newcommand{\dupMod}{\col{DUP}} + +\newcommand{\dupSTAMP}{\col{DUP\_STAMP}} +\newcommand{\dupStamp}{\col{DUP}\stamp} +\newcommand{\iDupSTAMP}{\imported{\dupSTAMP}} +\newcommand{\iDupStamp}{\imported{\dupStamp}} +\newcommand{\dupRevStamp}{\col{DUP}\stamp\,\col{REV}} +\newcommand{\iDupRevStamp}{\imported{\dupRevStamp}} + +\newcommand{\dupFLAG}{\col{DUP\_FLAG}} +\newcommand{\dupFlag}{\col{DUP}\flag} +\newcommand{\decDupFLAG}{\decoded{\dupFLAG}} +\newcommand{\decDupFlag}{\decoded{\dupFlag}} +\newcommand{\idecDupFLAG}{\imported{\decDupFLAG}} +\newcommand{\idecDupFlag}{\imported{\decDupFlag}} + +\newcommand{\dupSELECT}{\col{DUP\_SELECTOR}} +\newcommand{\dupSelect}{\col{DUP}\select} +\newcommand{\iDupSELECT}{\imported{\dupSELECT}} +\newcommand{\iDupSelect}{\imported{\dupSelect}} +\newcommand{\stackDecDupFlag}{\stackInstructionDecodedColumn{\dupFlag}} + +% swap columns: +%%%%%%%%%%%%%%% + +\newcommand{\swapMod}{\col{SWAP}} + +\newcommand{\swapSTAMP}{\col{SWAP\_STAMP}} +\newcommand{\swapStamp}{\col{SWAP}\stamp} +\newcommand{\iSwapSTAMP}{\imported{\swapSTAMP}} +\newcommand{\iSwapStamp}{\imported{\swapStamp}} +\newcommand{\swapRevStamp}{\col{SWAP}\stamp\,\col{REV}} +\newcommand{\iSwapRevStamp}{\imported{\swapRevStamp}} + +\newcommand{\swapFLAG}{\col{SWAP\_FLAG}} +\newcommand{\swapFlag}{\col{SWAP}\flag} +\newcommand{\decSwapFLAG}{\decoded{\swapFLAG}} +\newcommand{\decSwapFlag}{\decoded{\swapFlag}} +\newcommand{\idecSwapFLAG}{\imported{\decSwapFLAG}} +\newcommand{\idecSwapFlag}{\imported{\decSwapFlag}} + +\newcommand{\swapSELECT}{\col{SWAP\_SELECTOR}} +\newcommand{\swapSelect}{\col{SWAP}\select} +\newcommand{\iSwapSELECT}{\imported{\swapSELECT}} +\newcommand{\iSwapSelect}{\imported{\swapSelect}} +\newcommand{\stackDecSwapFlag}{\stackInstructionDecodedColumn{\swapFlag}} + +% invalid columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\invalidMod}{\col{INVALID}} + +\newcommand{\invalidSTAMP}{\col{INVALID\_STAMP}} +\newcommand{\invalidStamp}{\col{INVALID}\stamp} +\newcommand{\iInvalidSTAMP}{\imported{\invalidSTAMP}} +\newcommand{\iInvalidStamp}{\imported{\invalidStamp}} +\newcommand{\invalidRevStamp}{\col{INVALID}\stamp\,\col{REV}} +\newcommand{\iInvalidRevStamp}{\imported{\invalidRevStamp}} + +\newcommand{\invalidFLAG}{\col{INVALID\_FLAG}} +\newcommand{\invalidFlag}{\col{INVALID}\flag} +\newcommand{\decInvalidFLAG}{\decoded{\invalidFLAG}} +\newcommand{\decInvalidFlag}{\decoded{\invalidFlag}} +\newcommand{\idecInvalidFLAG}{\imported{\decInvalidFLAG}} +\newcommand{\idecInvalidFlag}{\imported{\decInvalidFlag}} + +\newcommand{\invalidSELECT}{\col{INVALID\_SELECTOR}} +\newcommand{\invalidSelect}{\col{INVALID}\select} +\newcommand{\iInvalidSELECT}{\imported{\invalidSELECT}} +\newcommand{\iInvalidSelect}{\imported{\invalidSelect}} +\newcommand{\stackDecInvalidFlag}{\stackInstructionDecodedColumn{\invalidFlag}} + +% address rlp columns: +%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\rlpAddrMod}{\col{RLPADDR}} + +\newcommand{\rlpAddrSTAMP}{\col{ADDRESS\_RLP\_STAMP}} +\newcommand{\rlpAddrStamp}{\col{RLPADDR}\stamp} +\newcommand{\iRlpAddrSTAMP}{\imported{\rlpAddrSTAMP}} +\newcommand{\iRlpAddrStamp}{\imported{\rlpAddrStamp}} +\newcommand{\rlpAddrRevStamp}{\col{RLPADDR}\stamp\,\col{REV}} +\newcommand{\iRlpAddrRevStamp}{\imported{\rlpAddrRevStamp}} + +\newcommand{\rlpAddrFLAG}{\col{ADDRESS\_RLP\_FLAG}} +\newcommand{\rlpAddrFlag}{\col{RLPADDR}\flag} +\newcommand{\decRlpAddrFLAG}{\decoded{\rlpAddrFLAG}} +\newcommand{\decRlpAddrFlag}{\decoded{\rlpAddrFlag}} +\newcommand{\idecRlpAddrFLAG}{\imported{\decRlpAddrFLAG}} +\newcommand{\idecRlpAddrFlag}{\imported{\decRlpAddrFlag}} + +\newcommand{\rlpAddrSELECT}{\col{ADDRESS\_RLP\_SELECTOR}} +\newcommand{\rlpAddrSelect}{\col{RLPADDR}\select} +\newcommand{\iRlpAddrSELECT}{\imported{\rlpAddrSELECT}} +\newcommand{\iRlpAddrSelect}{\imported{\rlpAddrSelect}} +\newcommand{\stackDecRlpAddrFlag}{\stackInstructionDecodedColumn{\rlpAddrFlag}} + +% transaction rlp columns: +%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\rlpTxnMod}{\col{RLPTXN}} + +\newcommand{\rlpTxnSTAMP}{\col{TRANSACTION\_RLP\_STAMP}} +\newcommand{\rlpTxnStamp}{\col{RLPTXN}\stamp} +\newcommand{\iRlpTxnSTAMP}{\imported{\rlpTxnSTAMP}} +\newcommand{\iRlpTxnStamp}{\imported{\rlpTxnStamp}} +\newcommand{\rlpTxnRevStamp}{\col{RLPTXN}\stamp\,\col{REV}} +\newcommand{\iRlpTxnRevStamp}{\imported{\rlpTxnRevStamp}} + +\newcommand{\rlpTxnFLAG}{\col{TRANSACTION\_RLP\_FLAG}} +\newcommand{\rlpTxnFlag}{\col{RLPTXN}\flag} +\newcommand{\decRlpTxnFLAG}{\decoded{\rlpTxnFLAG}} +\newcommand{\decRlpTxnFlag}{\decoded{\rlpTxnFlag}} +\newcommand{\idecRlpTxnFLAG}{\imported{\decRlpTxnFLAG}} +\newcommand{\idecRlpTxnFlag}{\imported{\decRlpTxnFlag}} + +\newcommand{\rlpTxnSELECT}{\col{TRANSACTION\_RLP\_SELECTOR}} +\newcommand{\rlpTxnSelect}{\col{RLPTXN}\select} +\newcommand{\iRlpTxnSELECT}{\imported{\rlpTxnSELECT}} +\newcommand{\iRlpTxnSelect}{\imported{\rlpTxnSelect}} +\newcommand{\stackDecRlpTxnFlag}{\stackInstructionDecodedColumn{\rlpTxnFlag}} + +% transaction receipt rlp columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\rlpTxnRcptMod}{\col{RLPTXNRCPT}} + +\newcommand{\rlpTxnRcptSTAMP}{\col{TRANSACTION\_RECEIPT\_RLP\_STAMP}} +\newcommand{\rlpTxnRcptStamp}{\col{RLPTXNRCPT}\stamp} +\newcommand{\iRlpTxnRcptSTAMP}{\imported{\rlpTxnRcptSTAMP}} +\newcommand{\iRlpTxnRcptStamp}{\imported{\rlpTxnRcptStamp}} +\newcommand{\rlpTxnRcptRevStamp}{\col{RLPTXNRCPT}\stamp\,\col{REV}} +\newcommand{\iRlpTxnRcptRevStamp}{\imported{\rlpTxnRcptRevStamp}} + +\newcommand{\rlpTxnRcptFLAG}{\col{TRANSACTION\_RECEIPT\_RLP\_FLAG}} +\newcommand{\rlpTxnRcptFlag}{\col{RLPTXNRCPT}\flag} +\newcommand{\decRlpTxnRcptFLAG}{\decoded{\rlpTxnRcptFLAG}} +\newcommand{\decRlpTxnRcptFlag}{\decoded{\rlpTxnRcptFlag}} +\newcommand{\idecRlpTxnRcptFLAG}{\imported{\decRlpTxnRcptFLAG}} +\newcommand{\idecRlpTxnRcptFlag}{\imported{\decRlpTxnRcptFlag}} + +\newcommand{\rlpTxnRcptSELECT}{\col{TRANSACTION\_RECEIPT\_RLP\_SELECTOR}} +\newcommand{\rlpTxnRcptSelect}{\col{RLPTXNRCPT}\select} +\newcommand{\iRlpTxnRcptSELECT}{\imported{\rlpTxnRcptSELECT}} +\newcommand{\iRlpTxnRcptSelect}{\imported{\rlpTxnRcptSelect}} +\newcommand{\stackDecRlpTxnRcptFlag}{\stackInstructionDecodedColumn{\rlpTxnRcptFlag}} + +% instruction decoder columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\idMod}{\col{ID}} + +\newcommand{\idSTAMP}{\col{INSTRUCTION\_DECODER\_STAMP}} +\newcommand{\idStamp}{\col{ID}\stamp} +\newcommand{\iIdSTAMP}{\imported{\idSTAMP}} +\newcommand{\iIdStamp}{\imported{\idStamp}} +\newcommand{\idRevStamp}{\col{ID}\stamp\,\col{REV}} +\newcommand{\iIdRevStamp}{\imported{\idRevStamp}} + +\newcommand{\idFLAG}{\col{INSTRUCTION\_DECODER\_FLAG}} +\newcommand{\idFlag}{\col{ID}\flag} +\newcommand{\decIdFLAG}{\decoded{\idFLAG}} +\newcommand{\decIdFlag}{\decoded{\idFlag}} +\newcommand{\idecIdFLAG}{\imported{\decIdFLAG}} +\newcommand{\idecIdFlag}{\imported{\decIdFlag}} + +\newcommand{\idSELECT}{\col{INSTRUCTION\_DECODER\_SELECTOR}} +\newcommand{\idSelect}{\col{ID}\select} +\newcommand{\iIdSELECT}{\imported{\idSELECT}} +\newcommand{\iIdSelect}{\imported{\idSelect}} +\newcommand{\stackDecIdFlag}{\stackInstructionDecodedColumn{\idFlag}} + + diff --git a/pkg/gas.sty b/pkg/gas.sty new file mode 100644 index 0000000..1fef294 --- /dev/null +++ b/pkg/gas.sty @@ -0,0 +1,42 @@ +\newcommand{\GAS}{\col{GAS}} +\newcommand{\gasOld}{\GAS\oldd} % old gas value +\newcommand{\gasRef}{\GAS\rrefund} % gasRef = gasOld + refund (from exiting child context) +\newcommand{\gasCur}{\GAS\cur} % gasCur = gasRef - costs + % [¤] staticGas + % [¤] memExp + % [¤] linGas + % [¤] instruction specific (SLOAD, SSTORE, EXP) + % [¤] addressExistence + % [¤] addressWarmth + % [¤] transfer funds +\newcommand{\gasNew}{\GAS\new} % +\newcommand{\gasEnd}{\GAS\Endowment} % part of next context's gas endowment + +\newcommand{\iGasCur}{\imported{\gasCur}} +\newcommand{\iGasNew}{\imported{\gasNew}} +\newcommand{\iGasOld}{\imported{\gasOld}} +\newcommand{\iGasEnd}{\imported{\gasEnd}} + +\newcommand{\LINGAS}{\col{LINEAR\_GAS\_COST}} +\newcommand{\linGas}{\col{LING}} +\newcommand{\iLINGAS}{\imported{\LINGAS}} +\newcommand{\iLinGas}{\imported{\linGas}} + +\newcommand{\GASDECREQ}{\col{LARGE\_BYTE\_DECOMPOSITION\_FLAG}} +\newcommand{\gasDecReq}{\col{LBDF}} + +\newcommand{\iExist}{\imported{\exists}} + +\newcommand{\SATICGAS}{\col{STATIC\_GAS}} +\newcommand{\saticGas}{\col{SGAS}} +\newcommand{\iSTATICGAS}{\imported{\SATICGAS}} +\newcommand{\iStaticGas}{\imported{\saticGas}} + + +\newcommand{\iCTYPE}{\imported{\CTYPE}} + +\newcommand{\GASSTAMP}{\col{GAS\_STAMP}} +\newcommand{\iGASSTAMP}{\imported{\GASSTAMP}} + +\newcommand{\LFlag}{\decoded{\col{L\_FLAG}}} +\newcommand{\iLFlag}{\imported{\LFlag}} \ No newline at end of file diff --git a/pkg/instruction_columns.py b/pkg/instruction_columns.py new file mode 100644 index 0000000..677ac1b --- /dev/null +++ b/pkg/instruction_columns.py @@ -0,0 +1,58 @@ +""" +e.g.: + +\newcommand{\callFLAG}{\col{CALL\_FLAG}} +\newcommand{\callFlag}{\col{CALL}\flag} +\newcommand{\decCallFlag}{\decoded{\callFlag}} +\newcommand{\iCallFlag}{\imported{\decCallFlag}} +\newcommand{\idecCallFlag}{\imported{\decCallFlag}} + +""" + +instructions = { + "call": "call", + "copy": "copy", + "create": "create", + "CDC": "CALLDATACOPY", + "CDL": "CALLDATALOAD", + "halt": "halting", + # "invalid": "invalid", + "jump": "jump", + "push": "push", + "RDC": "RETURNDATACOPY", + "return": "return", + "revert": "revert", + "selfDestruct": "SELFDESTRUCT", + } + +def new_commands(s): + + full = instructions[s].upper() + + m = s.lower() # m <> moniker + M = m[0].upper() + m[1:] # M <> Moniker + + res = "% " + s + " columns:\n" + res += (2 + len(s) + len(" columns:")) * "%" + "\n\n" + res += "\\newcommand{\\" + m + "FLAG}{\\col{" + full + "\\_FLAG}}\n" + res += "\\newcommand{\\" + m + "Flag}{\\col{" + s.upper() + "}\\flag}\n" + res += f"\\newcommand{{\\stackDec{s.capitalize()}Flag}}{{\\stackInstructionDecodedColumn{{\\{m}Flag}}}}\n" + res += "\\newcommand{\\i" + M + "Flag}{\\imported{\\dec" + M + "Flag}}\n" + res += "\\newcommand{\\idec" + M + "Flag}{\\imported{\\dec" + M + "Flag}}\n" + res += "\n\n" + + return res + + +def all_commands(): + + res = "" + res += "% automaticlaly generated via \"python3 instruction_columns.py > instruction_flags.sty\"\n" + res += "% yes, \\iBlaFlag and \\idecBlaFlag define the same macro.\n\n\n" + + for name in instructions: + res += new_commands(name) + + print(res) + +all_commands() diff --git a/pkg/instruction_flags.sty b/pkg/instruction_flags.sty new file mode 100644 index 0000000..943ab03 --- /dev/null +++ b/pkg/instruction_flags.sty @@ -0,0 +1,125 @@ +% automaticlaly generated via "python3 instruction_columns.py > instruction_flags.sty" +% yes, \iBlaFlag and \idecBlaFlag define the same macro. + + +% call columns: +%%%%%%%%%%%%%%% + +\newcommand{\callFLAG}{\col{CALL\_FLAG}} +\newcommand{\callFlag}{\col{CALL}\flag} +\newcommand{\stackDecCallFlag}{\stackInstructionDecodedColumn{\callFlag}} +\newcommand{\iCallFlag}{\imported{\decCallFlag}} +\newcommand{\idecCallFlag}{\imported{\decCallFlag}} + + +% copy columns: +%%%%%%%%%%%%%%% + +\newcommand{\copyFLAG}{\col{COPY\_FLAG}} +\newcommand{\copyFlag}{\col{COPY}\flag} +\newcommand{\stackDecCopyFlag}{\stackInstructionDecodedColumn{\copyFlag}} +\newcommand{\iCopyFlag}{\imported{\decCopyFlag}} +\newcommand{\idecCopyFlag}{\imported{\decCopyFlag}} + + +% create columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\createFLAG}{\col{CREATE\_FLAG}} +\newcommand{\createFlag}{\col{CREATE}\flag} +\newcommand{\stackDecCreateFlag}{\stackInstructionDecodedColumn{\createFlag}} +\newcommand{\iCreateFlag}{\imported{\decCreateFlag}} +\newcommand{\idecCreateFlag}{\imported{\decCreateFlag}} + + +% CDC columns: +%%%%%%%%%%%%%% + +\newcommand{\cdcFLAG}{\col{CALLDATACOPY\_FLAG}} +\newcommand{\cdcFlag}{\col{CDC}\flag} +\newcommand{\stackDecCdcFlag}{\stackInstructionDecodedColumn{\cdcFlag}} +\newcommand{\iCdcFlag}{\imported{\decCdcFlag}} +\newcommand{\idecCdcFlag}{\imported{\decCdcFlag}} + + +% CDL columns: +%%%%%%%%%%%%%% + +\newcommand{\cdlFLAG}{\col{CALLDATALOAD\_FLAG}} +\newcommand{\cdlFlag}{\col{CDL}\flag} +\newcommand{\stackDecCdlFlag}{\stackInstructionDecodedColumn{\cdlFlag}} +\newcommand{\iCdlFlag}{\imported{\decCdlFlag}} +\newcommand{\idecCdlFlag}{\imported{\decCdlFlag}} + + +% halt columns: +%%%%%%%%%%%%%%% + +\newcommand{\haltFLAG}{\col{HALTING\_FLAG}} +\newcommand{\haltFlag}{\col{HALT}\flag} +\newcommand{\stackDecHaltFlag}{\stackInstructionDecodedColumn{\haltFlag}} +\newcommand{\iHaltFlag}{\imported{\decHaltFlag}} +\newcommand{\idecHaltFlag}{\imported{\decHaltFlag}} + + +% jump columns: +%%%%%%%%%%%%%%% + +\newcommand{\jumpFLAG}{\col{JUMP\_FLAG}} +\newcommand{\jumpFlag}{\col{JUMP}\flag} +\newcommand{\stackDecJumpFlag}{\stackInstructionDecodedColumn{\jumpFlag}} +\newcommand{\iJumpFlag}{\imported{\decJumpFlag}} +\newcommand{\idecJumpFlag}{\imported{\decJumpFlag}} + + +% push columns: +%%%%%%%%%%%%%%% + +\newcommand{\pushFLAG}{\col{PUSH\_FLAG}} +\newcommand{\pushFlag}{\col{PUSH}\flag} +\newcommand{\stackDecPushFlag}{\stackInstructionDecodedColumn{\pushFlag}} +\newcommand{\iPushFlag}{\imported{\decPushFlag}} +\newcommand{\idecPushFlag}{\imported{\decPushFlag}} + + +% RDC columns: +%%%%%%%%%%%%%% + +\newcommand{\rdcFLAG}{\col{RETURNDATACOPY\_FLAG}} +\newcommand{\rdcFlag}{\col{RDC}\flag} +\newcommand{\stackDecRdcFlag}{\stackInstructionDecodedColumn{\rdcFlag}} +\newcommand{\iRdcFlag}{\imported{\decRdcFlag}} +\newcommand{\idecRdcFlag}{\imported{\decRdcFlag}} + + +% return columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\returnFLAG}{\col{RETURN\_FLAG}} +\newcommand{\returnFlag}{\col{RETURN}\flag} +\newcommand{\stackDecReturnFlag}{\stackInstructionDecodedColumn{\returnFlag}} +\newcommand{\iReturnFlag}{\imported{\decReturnFlag}} +\newcommand{\idecReturnFlag}{\imported{\decReturnFlag}} + + +% revert columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\revertFLAG}{\col{REVERT\_FLAG}} +\newcommand{\revertFlag}{\col{REVERT}\flag} +\newcommand{\stackDecRevertFlag}{\stackInstructionDecodedColumn{\revertFlag}} +\newcommand{\iRevertFlag}{\imported{\decRevertFlag}} +\newcommand{\idecRevertFlag}{\imported{\decRevertFlag}} + + +% selfDestruct columns: +%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\selfdestructFLAG}{\col{SELFDESTRUCT\_FLAG}} +\newcommand{\selfdestructFlag}{\col{SELFDESTRUCT}\flag} +\newcommand{\stackDecSelfdestructFlag}{\stackInstructionDecodedColumn{\selfdestructFlag}} +\newcommand{\iSelfdestructFlag}{\imported{\decSelfdestructFlag}} +\newcommand{\idecSelfdestructFlag}{\imported{\decSelfdestructFlag}} + + + diff --git a/pkg/iomf_done.sty b/pkg/iomf_done.sty new file mode 100644 index 0000000..af12688 --- /dev/null +++ b/pkg/iomf_done.sty @@ -0,0 +1,2 @@ +\newcommand{\iomf}{\col{IOMF}} +\renewcommand{\done}{\col{DONE}} diff --git a/pkg/lex.sty b/pkg/lex.sty new file mode 100644 index 0000000..7cca589 --- /dev/null +++ b/pkg/lex.sty @@ -0,0 +1,2 @@ +\newcommand{\weakLexConstraint}{\texttt{weakLexConstraint}} +\newcommand{\strictLexConstraint}{\texttt{strictLexConstraint}} diff --git a/pkg/log_info.sty b/pkg/log_info.sty new file mode 100644 index 0000000..44da905 --- /dev/null +++ b/pkg/log_info.sty @@ -0,0 +1,10 @@ +\newcommand{\absLogNum} {\col{ABS\_LOG\_NUM}} +\newcommand{\absLogNumMax} {\col{ABS\_LOG\_NUM\_MAX}} +\newcommand{\topicHi}[1] {\col{TOPIC\_#1\_HI}} +\newcommand{\topicLo}[1] {\col{TOPIC\_#1\_LO}} +\newcommand{\logLogsData} {\col{LOGS\_DATA}} +\newcommand{\isLog}[1] {\col{IS\_LOG\_#1}} +\newcommand{\txEmitsLogs} {\col{TX\_EMITS\_LOGS}} +\newcommand{\logDataSize} {\col{TOTAL\_SIZE}} +\newcommand{\cumulSize} {\col{SIZE\_ACC}} +\newcommand{\limbSize} {\col{SIZE\_LIMB}} diff --git a/pkg/misc.sty b/pkg/misc.sty new file mode 100644 index 0000000..8deda35 --- /dev/null +++ b/pkg/misc.sty @@ -0,0 +1,156 @@ +% misc/MMU/ columns +% old +% \newcommand{\miscMmuStamp} {\miscSignifier\mmuMod\separator\mmuStamp} +\newcommand{\miscMmuInfo} {\miscSignifier\mmuMod\separator\infoBit} +\newcommand{\miscMmuInstParamOne} {\miscSignifier\mmuMod\separator\col{PARAM\_1}} +\newcommand{\miscMmuInstParamTwo} {\miscSignifier\mmuMod\separator\col{PARAM\_2}} +\newcommand{\miscMmuCn} {\miscSignifier\mmuMod\separator\cn} +\newcommand{\miscMmuCaller} {\miscSignifier\mmuMod\separator\caller} +\newcommand{\miscMmuReturner} {\miscSignifier\mmuMod\separator\returner} +% \newcommand{\miscMmuRefOffset} {\miscSignifier\mmuMod\separator\col{\refOff}} +% \newcommand{\miscMmuRefSize} {\miscSignifier\mmuMod\separator\refSize} +\newcommand{\miscMmuOffsetOneHi} {\miscSignifier\mmuMod\separator\col{OFFSET\_1\_HI}} +\newcommand{\miscMmuOffsetOneLo} {\miscSignifier\mmuMod\separator\col{OFFSET\_1\_LO}} +\newcommand{\miscMmuOffsetTwoHi} {\miscSignifier\mmuMod\separator\col{OFFSET\_2\_HI}} +\newcommand{\miscMmuOffsetTwoLo} {\miscSignifier\mmuMod\separator\col{OFFSET\_2\_LO}} +% \newcommand{\miscMmuSize} {\miscSignifier\mmuMod\separator\size} +\newcommand{\miscMmuStackValHi} {\miscSignifier\mmuMod\separator\col{STACK\_VAL\_HI}} +\newcommand{\miscMmuStackValLo} {\miscSignifier\mmuMod\separator\col{STACK\_VAL\_LO}} +% \newcommand{\miscMmuExoSum} {\miscSignifier\mmuMod\separator\col{EXO\_SUM}} + + +\newcommand{\miscMmuColumn} [1] {\miscSignifier\mmuMod\separator\col{#1}} +\newcommand{\miscMmuStamp} {\miscMmuColumn{\stamp}} +\newcommand{\miscMmuInst} {\miscMmuColumn{INST}} +\newcommand{\miscMmuSrcId} {\miscMmuColumn{SRC\_ID}} +\newcommand{\miscMmuTgtId} {\miscMmuColumn{TGT\_ID}} +\newcommand{\miscMmuAuxId} {\miscMmuColumn{AUX\_ID}} +\newcommand{\miscMmuSrcOffsetHi} {\miscMmuColumn{SRC\_OFFSET\_HI}} +\newcommand{\miscMmuSrcOffsetLo} {\miscMmuColumn{SRC\_OFFSET\_LO}} +\newcommand{\miscMmuTgtOffsetLo} {\miscMmuColumn{TGT\_OFFSET\_LO}} +\newcommand{\miscMmuSize} {\miscMmuColumn{SIZE}} +\newcommand{\miscMmuRefOffset} {\miscMmuColumn{REF\_OFFSET}} +\newcommand{\miscMmuRefSize} {\miscMmuColumn{REF\_SIZE}} +\newcommand{\miscMmuSuccessBit} {\miscMmuColumn{SUCCESS\_BIT}} +\newcommand{\miscMmuLimbOne} {\miscMmuColumn{LIMB\_1}} +\newcommand{\miscMmuLimbTwo} {\miscMmuColumn{LIMB\_2}} +\newcommand{\miscMmuPhase} {\miscMmuColumn{PHASE}} +\newcommand{\miscMmuExoSum} {\miscMmuColumn{EXO\_SUM}} + +% new : ) +% \newcommand{\miscMmuInst} {\miscSignifier\mmuMod\separator\INST} +% \newcommand{\miscMmuSrcId} {\miscSignifier\mmuMod\separator\col{SRC\_ID}} +% \newcommand{\miscMmuTgtId} {\miscSignifier\mmuMod\separator\col{TGT\_ID}} +% \newcommand{\miscMmuAuxId} {\miscSignifier\mmuMod\separator\col{AUX\_ID}} +% \newcommand{\miscMmuSrcOffsetHi} {\miscSignifier\mmuMod\separator\col{SRC\_OFFSET\_HI}} +% \newcommand{\miscMmuSrcOffsetLo} {\miscSignifier\mmuMod\separator\col{SRC\_OFFSET\_LO}} +% \newcommand{\miscMmuTgtOffsetLo} {\miscSignifier\mmuMod\separator\col{TGT\_OFFSET\_LO}} +% \newcommand{\miscMmuSize} {\miscSignifier\mmuMod\separator\size} +% \newcommand{\miscMmuRefOffset} {\miscSignifier\mmuMod\separator\col{REF\_OFFSET}} +% \newcommand{\miscMmuRefSize} {\miscSignifier\mmuMod\separator\col{REF\_SIZE}} +% \newcommand{\miscMmuSuccessBit} {\miscSignifier\mmuMod\separator\col{SUCCESS\_BIT}} +% \newcommand{\miscMmuValHi} {\miscSignifier\mmuMod\separator\col{VAL\_HI}} +% \newcommand{\miscMmuValLo} {\miscSignifier\mmuMod\separator\col{VAL\_LO}} +% \newcommand{\miscMmuLimbOne} {\miscSignifier\mmuMod\separator\col{LIMB\_1}} +% \newcommand{\miscMmuLimbTwo} {\miscSignifier\mmuMod\separator\col{LIMB\_2}} +% \newcommand{\miscMmuPhase} {\miscSignifier\mmuMod\separator\col{PHASE}} +% \newcommand{\miscMmuExoSum} {\miscSignifier\mmuMod\separator\col{EXO\_SUM}} + +% misc/OOB/ columns +\newcommand{\miscOobInst} {\miscSignifier\oobMod\separator\INST} +\newcommand{\miscOobDataCol} [1] {\miscSignifier\oobMod\separator\dataCol{#1}} + +% misc/MXP/ columns +\newcommand{\miscMxpStamp} {\miscSignifier\mxpMod\separator\mxpStamp} +\newcommand{\miscMxpInst} {\miscSignifier\mxpMod\separator\INST} +\newcommand{\miscMxpSizeOneHi} {\miscSignifier\mxpMod\separator\col{SIZE\_1\_HI}} +\newcommand{\miscMxpSizeOneLo} {\miscSignifier\mxpMod\separator\col{SIZE\_1\_LO}} +\newcommand{\miscMxpSizeTwoHi} {\miscSignifier\mxpMod\separator\col{SIZE\_2\_HI}} +\newcommand{\miscMxpSizeTwoLo} {\miscSignifier\mxpMod\separator\col{SIZE\_2\_LO}} +\newcommand{\miscMxpOffsetOneHi} {\miscSignifier\mxpMod\separator\col{OFFSET\_1\_HI}} +\newcommand{\miscMxpOffsetOneLo} {\miscSignifier\mxpMod\separator\col{OFFSET\_1\_LO}} +\newcommand{\miscMxpOffsetTwoHi} {\miscSignifier\mxpMod\separator\col{OFFSET\_2\_HI}} +\newcommand{\miscMxpOffsetTwoLo} {\miscSignifier\mxpMod\separator\col{OFFSET\_2\_LO}} +\newcommand{\miscMxpMxpx} {\miscSignifier\mxpMod\separator\mxpx} +\newcommand{\miscMxpGasMxp} {\miscSignifier\mxpMod\separator\gasMxp} +\newcommand{\miscMxpWords} {\miscSignifier\mxpMod\separator\memSize} +\newcommand{\miscMxpCodeDeployment} {\miscSignifier\mxpMod\separator\codeDeployment} +\newcommand{\miscMxpTypeFourInstMayTriggerMmu} {\miscSignifier\mxpMod\separator\mayTriggerNonTrivialOperation} + + +% misc/ module flags +\newcommand{\miscExpFlag} {\miscSignifier\expFlag} +\newcommand{\miscMmuFlag} {\miscSignifier\mmuFlag} +\newcommand{\miscMxpFlag} {\miscSignifier\mxpFlag} +\newcommand{\miscOobFlag} {\miscSignifier\oobFlag} +\newcommand{\miscPrecInfoFlag} {\miscSignifier\precInfoFlag} %TODO: remove +\newcommand{\miscStpFlag} {\miscSignifier\stpFlag} + +% misc/ module flag weights +\newcommand{\miscWeight} [1] {\redm{[\![\inst{MISC\_weight\_#1}]\!]}} +\newcommand{\miscExpWeight} {\miscWeight{EXP}} +\newcommand{\miscMmuWeight} {\miscWeight{MMU}} +\newcommand{\miscMxpWeight} {\miscWeight{MXP}} +\newcommand{\miscOobWeight} {\miscWeight{OOB}} +\newcommand{\miscStpWeight} {\miscWeight{STP}} + +\newcommand{\weightedMiscFlagSumName} {\miscSignifier\texttt{weightedMiscFlagSum}} +\newcommand{\weightedMiscFlagSum} [2] { + \weightedMiscFlagSumName + _{#1} \big[\;#2\;\big] +} + +% misc/EXP/ columns +\newcommand{\setExpInstruction } [2] {\texttt{setExpInstruction} _{#1} \big[~#2~\big]} +\newcommand{\setExpInstructionParametersExpLog } [2] {\texttt{setExpInstExpLog} _{#1} \big[~#2~\big]} +\newcommand{\setExpInstructionParametersModexpLog } [2] {\texttt{setExpInstModexpLog} _{#1} \big[~#2~\big]} +\newcommand{\miscExpInstruction } {\miscSignifier\expMod\separator\INST} +\newcommand{\miscExpDataCol } [1] {\miscSignifier\expMod\separator\dataCol{#1}} + + +% misc/STP/ columns +\newcommand{\miscStpInst} {\miscSignifier\stpMod\separator\INST} +\newcommand{\miscStpGasHi} {\miscSignifier\stpMod\separator\gasHi} +\newcommand{\miscStpGasLo} {\miscSignifier\stpMod\separator\gasLo} +\newcommand{\miscStpValueHi} {\miscSignifier\stpMod\separator\valHi} +\newcommand{\miscStpValueLo} {\miscSignifier\stpMod\separator\valLo} +\newcommand{\miscStpAccBalance} {\miscSignifier\stpMod\separator\balance} +\newcommand{\miscStpAccExists} {\miscSignifier\stpMod\separator\existence} +\newcommand{\miscStpAccWarmth} {\miscSignifier\stpMod\separator\warm} +\newcommand{\miscStpGasPoop} {\miscSignifier\stpMod\separator\gasPoop} +\newcommand{\miscStpGasUpfront} {\miscSignifier\stpMod\separator\gasUpfront} +\newcommand{\miscStpGasMxp} {\miscSignifier\stpMod\separator\gasMxp} +\newcommand{\miscStpGasStipend} {\miscSignifier\stpMod\separator\gasStipend} +\newcommand{\miscStpOogx} {\miscSignifier\stpMod\separator\oogx} + + + + +% misc/PRECINFO/ columns +\newcommand{\precinfoAddr} {\miscSignifier\precInfoMod\separator\addressLo} +\newcommand{\precinfoSuccess} {\miscSignifier\precInfoMod\separator\success} +\newcommand{\precinfoTouchesRam} {\miscSignifier\precInfoMod\separator\touchesRam} +\newcommand{\precinfoProvidesReturnData} {\miscSignifier\precInfoMod\separator\providesReturnData} +\newcommand{\precinfoReturnDataSize} {\miscSignifier\precInfoMod\separator\rds} +\newcommand{\precinfoCallDataSize} {\miscSignifier\precInfoMod\separator\cds} +\newcommand{\precinfoCost} {\miscSignifier\precInfoMod\separator\executionCost} + +% miscellaneous CALL/CREATE related columns +\newcommand{\miscAbort} {\miscSignifier\col{ABORT}\flag} +\newcommand{\miscFcond} {\miscSignifier\col{FCOND}\flag} +\newcommand{\miscChildSelfReverts} {\miscSignifier\col{CCSR}\flag} +\newcommand{\miscChildRevertStamp} {\miscSignifier\col{CCRS}\stamp} + + +% misc MMU instructions +% \newcommand{\setMmuInstruction } [2] {\texttt{setMmuInstruction} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersMload } [2] {\texttt{setMmuInstMload} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersMstore } [2] {\texttt{setMmuInstMstore} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersMstoreEight } [2] {\texttt{setMmuInstMstore8} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersInvalidCodePrefix } [2] {\texttt{setMmuInstInvalidCodePrefix} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersExoToRamTransplants } [2] {\texttt{setMmuInstExoToRamTransplants} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersRamToRamSansPadding } [2] {\texttt{setMmuInstRamToRamSansPadding} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersAnyToRamWithPadding } [2] {\texttt{setMmuInstAnyToRamWithPadding} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersModexpZero } [2] {\texttt{setMmuInstModexpZero} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersModexpData } [2] {\texttt{setMmuInstModexpData} _{#1} \big[\;#2\;\big]} +% \newcommand{\setMmuInstructionParametersBlake } [2] {\texttt{setMmuInstBlake} _{#1} \big[\;#2\;\big]} diff --git a/pkg/mmio_instructions.sty b/pkg/mmio_instructions.sty new file mode 100644 index 0000000..9d86b2f --- /dev/null +++ b/pkg/mmio_instructions.sty @@ -0,0 +1,45 @@ +\newcommand{\mmioInstruction} [1] {\red{[\![\inst{MMIO\_INST\_#1}]\!]}} +\newcommand{\isMmioInstruction} [1] {\col{IS\_#1}} + +% Limb +\newcommand{\mmioInstLimbVanishes} {\mmioInstruction{limbVanishes}} + +% Limb to Ram +\newcommand{\mmioInstLimbToRamTransplant} {\mmioInstruction{limbToRamTransplant}} +\newcommand{\mmioInstLimbToRamOneTarget} {\mmioInstruction{limbToRamOneTarget}} +\newcommand{\mmioInstLimbToRamTwoTarget} {\mmioInstruction{limbToRamTwoTarget}} + +% Ram to Limb +\newcommand{\mmioInstRamToLimbTransplant} {\mmioInstruction{ramToLimbTransplant}} +\newcommand{\mmioInstRamToLimbOneSource} {\mmioInstruction{ramToLimbOneSource}} +\newcommand{\mmioInstRamToLimbTwoSource} {\mmioInstruction{ramToLimbTwoSource}} + +% RAM to RAM +\newcommand{\mmioInstRamToRamTransplant} {\mmioInstruction{ramToRamTransplant}} +\newcommand{\mmioInstRamToRamPartial} {\mmioInstruction{ramToRamPartial}} +\newcommand{\mmioInstRamToRamTwoTarget} {\mmioInstruction{ramToRamTwoTarget}} +\newcommand{\mmioInstRamToRamTwoSource} {\mmioInstruction{ramToRamTwoSource}} + +% RAM +\newcommand{\mmioInstRamExcision} {\mmioInstruction{ramExcision}} +\newcommand{\mmioInstRamVanishes} {\mmioInstruction{ramVanishes}} + + +%% IS\_INST FLAG +\newcommand{\isMmioInstLimbVanishes} {\isMmioInstruction{LIMB\_VANISHES}} + +\newcommand{\isMmioInstRamToLimbTransplant} {\isMmioInstruction{RAM\_TO\_LIMB\_TRANSPLANT}} +\newcommand{\isMmioInstRamToLimbOneSource} {\isMmioInstruction{RAM\_TO\_LIMB\_ONE\_SOURCE}} +\newcommand{\isMmioInstRamToLimbTwoSource} {\isMmioInstruction{RAM\_TO\_LIMB\_TWO\_SOURCE}} + +\newcommand{\isMmioInstLimbToRamTransplant} {\isMmioInstruction{LIMB\_TO\_RAM\_TRANSPLANT}} +\newcommand{\isMmioInstLimbToRamOneTarget} {\isMmioInstruction{LIMB\_TO\_RAM\_ONE\_TARGET}} +\newcommand{\isMmioInstLimbToRamTwoTarget} {\isMmioInstruction{LIMB\_TO\_RAM\_TWO\_TARGET}} + +\newcommand{\isMmioInstRamToRamTransplant} {\isMmioInstruction{RAM\_TO\_RAM\_TRANSPLANT}} +\newcommand{\isMmioInstRamToRamPartial} {\isMmioInstruction{RAM\_TO\_RAM\_PARTIAL}} +\newcommand{\isMmioInstRamToRamTwoTarget} {\isMmioInstruction{RAM\_TO\_RAM\_TWO\_TARGET}} +\newcommand{\isMmioInstRamToRamTwoSource} {\isMmioInstruction{RAM\_TO\_RAM\_TWO\_SOURCE}} + +\newcommand{\isMmioInstRamExcision} {\isMmioInstruction{RAM\_EXCISION}} +\newcommand{\isMmioInstRamVanishes} {\isMmioInstruction{RAM\_VANISHES}} diff --git a/pkg/mmu.sty b/pkg/mmu.sty new file mode 100644 index 0000000..ae76c9d --- /dev/null +++ b/pkg/mmu.sty @@ -0,0 +1,185 @@ +% this allows us to have text mu's +\usepackage{textcomp} +% +\newcommand{\mmuMacroInstructionSymbol} {\texttt{MACRO}} +\newcommand{\mmuPreprocessingSymbol} {\texttt{PRPRC}} +\newcommand{\mmuMicroInstructionSymbol} {\texttt{MICRO}} +% +\newcommand{\mmuMacroInstructionColumn} [1] {\mmuMacroInstructionSymbol\separator{\col{#1}}} +\newcommand{\mmuPreprocessingColumn} [1] {\mmuPreprocessingSymbol\separator{\col{#1}}} +\newcommand{\mmuMicroInstructionColumn} [1] {\mmuMicroInstructionSymbol\separator{\col{#1}}} + +% SHARED columns +% \newcommand{\mmuStamp} {\col{}} +\newcommand{\microStamp} {\col{{\textmu}INST}\stamp} +\newcommand{\isMacro} {\mmuMacroInstructionSymbol ^\eye} +\newcommand{\isPreprocessing} {\mmuPreprocessingSymbol ^\eye} +\newcommand{\isMicro} {\mmuMicroInstructionSymbol ^\eye} +\newcommand{\ppOutputCol} [1] {\col{OUT\_#1}} +\newcommand{\ppOutputColBin} [1] {\col{BIN\_#1}} + +% % MACRO INST columns +\newcommand{\SOURCE} {SRC} +\newcommand{\TARGET} {TGT} +\newcommand{\AUXILIARY} {AUX} +\newcommand{\ID} {ID} +\newcommand{\OFFSET} {OFFSET} +\newcommand{\SIZE} {SIZE} +\newcommand{\REFERENCE} {REF} +\newcommand{\HI} {HI} +\newcommand{\LO} {LO} +% +\newcommand{\macroInst} {\mmuMacroInstructionColumn{\INST}} +\newcommand{\macroSrcId} {\mmuMacroInstructionColumn{\SOURCE\_\ID}} +\newcommand{\macroTgtId} {\mmuMacroInstructionColumn{\TARGET\_\ID}} +\newcommand{\macroAuxId} {\mmuMacroInstructionColumn{\AUXILIARY\_\ID}} +\newcommand{\macroSrcOffsetHi} {\mmuMacroInstructionColumn{\SOURCE\_\OFFSET\_\HI}} +\newcommand{\macroSrcOffsetLo} {\mmuMacroInstructionColumn{\SOURCE\_\OFFSET\_\LO}} +\newcommand{\macroTgtOffsetLo} {\mmuMacroInstructionColumn{\TARGET\_\OFFSET\_\LO}} +\newcommand{\macroSize} {\mmuMacroInstructionColumn{\SIZE}} +\newcommand{\macroRefOffset} {\mmuMacroInstructionColumn{\REFERENCE\_\OFFSET}} +\newcommand{\macroRefSize} {\mmuMacroInstructionColumn{\REFERENCE\_\SIZE}} +\newcommand{\macroSuccessBit} {\mmuMacroInstructionColumn{\successBit}} +\newcommand{\macroLimbOne} {\mmuMacroInstructionColumn{LIMB\_1}} +\newcommand{\macroLimbTwo} {\mmuMacroInstructionColumn{LIMB\_2}} +\newcommand{\macroPhase} {\mmuMacroInstructionColumn{\Phase}} +\newcommand{\macroExoSum} {\mmuMacroInstructionColumn{\exoSum}} + +% % DECODING columns +% \newcommand{\} {\mmuDecodingColumn{}} +\newcommand{\mmuInstFlag} [1] {\col{IS\_#1}} +\newcommand{\mmuInstFlagMload} {\mmuInstFlag{MLOAD}} +\newcommand{\mmuInstFlagMstore} {\mmuInstFlag{MSTORE}} +\newcommand{\mmuInstFlagMstoreEight} {\mmuInstFlag{MSTORE\_8}} +\newcommand{\mmuInstFlagInvalidCodePrefix} {\mmuInstFlag{INVALID\_CODE\_PREFIX}} +\newcommand{\mmuInstFlagRightPaddedWordExtraction} {\mmuInstFlag{RIGHT\_PADDED\_WORD\_EXTRACTION}} +\newcommand{\mmuInstFlagRamToExoWithPadding} {\mmuInstFlag{RAM\_TO\_EXO\_WITH\_PADDING}} +\newcommand{\mmuInstFlagRamToRamSansPadding} {\mmuInstFlag{RAM\_TO\_RAM\_SANS\_PADDING}} +\newcommand{\mmuInstFlagAnyToRamWithPadding} {\mmuInstFlag{any\_to\_ram\_with\_padding}} +% \newcommand{\mmuInstFlagAnyToRamWithPaddingPureData} {\mmuInstFlag{ANY\_TO\_RAM\_WITH\_PADDING\_PURE\_DATA}} +% \newcommand{\mmuInstFlagAnyToRamWithPaddingMixed} {\mmuInstFlag{ANY\_TO\_RAM\_WITH\_PADDING\_MIXED}} +\newcommand{\mmuInstFlagAnyToRamWithPaddingSomeData} {\mmuInstFlag{ANY\_TO\_RAM\_WITH\_PADDING\_SOME\_DATA}} +\newcommand{\mmuInstFlagAnyToRamWithPaddingPurePadding} {\mmuInstFlag{ANY\_TO\_RAM\_WITH\_PADDING\_PURE\_PADDING}} +\newcommand{\mmuInstFlagExoToRamTransplants} {\mmuInstFlag{EXO\_TO\_RAM\_TRANSPLANTS}} +\newcommand{\mmuInstFlagModexpZero} {\mmuInstFlag{MODEXP\_ZERO}} +\newcommand{\mmuInstFlagModexpData} {\mmuInstFlag{MODEXP\_DATA}} +\newcommand{\mmuInstFlagBlake} {\mmuInstFlag{BLAKE\_PARAM}} + +% % PRE PROCESSING columns +\newcommand{\ppCt} {\mmuPreprocessingColumn{CT}} +\newcommand{\ppEucFlag} {\mmuPreprocessingColumn{\eucFlag}} +\newcommand{\ppEucA} {\mmuPreprocessingColumn{\eucMod\_A}} +\newcommand{\ppEucB} {\mmuPreprocessingColumn{\eucMod\_B}} +\newcommand{\ppEucQuot} {\mmuPreprocessingColumn{\eucMod\_QUOT}} +\newcommand{\ppEucRem} {\mmuPreprocessingColumn{\eucMod\_REM}} +\newcommand{\ppEucCeil} {\mmuPreprocessingColumn{\eucMod\_CEIL}} +\newcommand{\ppWcpFlag} {\mmuPreprocessingColumn{\wcpFlag}} +\newcommand{\ppWcpArgOneHi} {\mmuPreprocessingColumn{\wcpMod\_ARG\_1\_HI}} +\newcommand{\ppWcpArgOneLo} {\mmuPreprocessingColumn{\wcpMod\_ARG\_1\_LO}} +\newcommand{\ppWcpArgTwoHi} {\mmuPreprocessingColumn{\wcpMod\_ARG\_2\_HI}} +\newcommand{\ppWcpArgTwoLo} {\mmuPreprocessingColumn{\wcpMod\_ARG\_2\_LO}} +\newcommand{\ppWcpRes} {\mmuPreprocessingColumn{\wcpMod\_RES}} +\newcommand{\ppWcpInst} {\mmuPreprocessingColumn{\wcpMod\_INST}} + +\newcommand{\callEuc} {\texttt{callToEUC}} +\newcommand{\callLt} {\texttt{callToLT}} +\newcommand{\callEq} {\texttt{callToEQ}} +\newcommand{\callIszero} {\texttt{callToISZERO}} + +\newcommand{\callToEuc} [4] {% + \callEuc _{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Dividend:} & #3 \\ + \utt{Divisor:} & #4 \\ + \end{array} \right]} + +\newcommand{\callToLt}[5]{ + \callLt_{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument 1 hi:} & #3 \\ + \utt{Argument 1 lo:} & #4 \\ + \utt{Argument 2 lo:} & #5 \\ + \end{array} \right]} + +\newcommand{\callToEq}[5]{ + \callEq_{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument 1 hi:} & #3 \\ + \utt{Argument 1 lo:} & #4 \\ + \utt{Argument 2 lo:} & #5 \\ + \end{array} \right]} + +\newcommand{\callToIszero}[4]{ + \callIszero_{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument 1 hi:} & #3 \\ + \utt{Argument 1 lo:} & #4 \\ + \end{array} \right]} + + +% % MICRO INST columns +% internal: +% \newcommand{\micro} {\mmuMicroInstructionColumn{}} +\newcommand{\ppTot} {\col{TOT}} +\newcommand{\ppTotLZ} {\col{TOTLZ}} +\newcommand{\ppTotNT} {\col{TOTNT}} +\newcommand{\ppTotRZ} {\col{TOTRZ}} +% +\newcommand{\microInst} {\mmuMicroInstructionColumn{INST}} +\newcommand{\microSize} {\mmuMicroInstructionColumn{\size}} +\newcommand{\microSlo} {\mmuMicroInstructionColumn{\slo}} +\newcommand{\microSbo} {\mmuMicroInstructionColumn{\sbo}} +\newcommand{\microTlo} {\mmuMicroInstructionColumn{\tlo}} +\newcommand{\microTbo} {\mmuMicroInstructionColumn{\tbo}} +\newcommand{\microCns} {\mmuMicroInstructionColumn{\cnS}} +\newcommand{\microCnt} {\mmuMicroInstructionColumn{\cnT}} +\newcommand{\microLimb} {\mmuMicroInstructionColumn{\limb}} +\newcommand{\microSuccessBit} {\mmuMicroInstructionColumn{\successBit}} +\newcommand{\microExoSum} {\mmuMicroInstructionColumn{\exoSum}} +\newcommand{\microPhase} {\mmuMicroInstructionColumn{\Phase}} +\newcommand{\microIdOne} {\mmuMicroInstructionColumn{\idOne}} +\newcommand{\microIdTwo} {\mmuMicroInstructionColumn{\idTwo}} +\newcommand{\microTotalSize} {\mmuMicroInstructionColumn{\totalSize}} + +\newcommand{\idOne} {\col{EXO\_ID}} +\newcommand{\idTwo} {\col{KEC\_ID}} +\newcommand{\totalSize} {\col{TOTAL\_SIZE}} + + +% micro instruction writing rows more granularity +\newcommand{\leftPaddingRow} {\texttt{leftPaddingRow}} +\newcommand{\nontrivialRow} {\texttt{nonTrivialRow}} +\newcommand{\rightPaddingRow} {\texttt{rightPaddingRow}} +\newcommand{\firstTerm} {\texttt{firstTerm}} +\newcommand{\middleTerm} {\texttt{middleTerm}} +\newcommand{\lastTerm} {\texttt{lastTerm}} + +\newcommand{\mmuInstFlagSum} {\col{inst\_flag\_sum}} +\newcommand{\mmuInstWeightedSum} {\col{wght\_flag\_sum}} + +% row type binary columns +\newcommand{\isLEFTZERO} {\col{IS\_LEFT\_ZERO\_ROW}} +\newcommand{\isONLY} {\col{IS\_ONLY\_NONTRIVIAL\_ROW}} +\newcommand{\isFIRST} {\col{IS\_FIRST\_NONTRIVIAL\_ROW}} +\newcommand{\isMIDDLE} {\col{IS\_MIDDLE\_NONTRIVIAL\_ROW}} +\newcommand{\isLAST} {\col{IS\_LAST\_NONTRIVIAL\_ROW}} +\newcommand{\isRIGHTZERO} {\col{IS\_RIGHT\_ZERO\_ROW}} + +\newcommand{\isLeftZero} {\col{LZRO}^\rho} +\newcommand{\isNontrivial} {\col{ntrv}^\rho} +\newcommand{\isOnlyNT} {\col{NT\_ONLY}^\rho} +\newcommand{\isFirstNT} {\col{NT\_FRST}^\rho} +\newcommand{\isMiddleNT} {\col{NT\_MDDL}^\rho} +\newcommand{\isLastNT} {\col{NT\_LAST}^\rho} +\newcommand{\isRightZero} {\col{rzro}^\rho} +\newcommand{\isOnlyRZ} {\col{RZ\_ONLY}^\rho} +\newcommand{\isFirstRZ} {\col{RZ\_FRST}^\rho} +\newcommand{\isMiddleRZ} {\col{RZ\_MDDL}^\rho} +\newcommand{\isLastRZ} {\col{RZ\_LAST}^\rho} +\newcommand{\isZero} {\col{zero}^\rho} + +\newcommand{\stdProgression} {\texttt{stdProgression}} diff --git a/pkg/mmu_custom_instructions.sty b/pkg/mmu_custom_instructions.sty new file mode 100644 index 0000000..dcf5f1d --- /dev/null +++ b/pkg/mmu_custom_instructions.sty @@ -0,0 +1,65 @@ +\newcommand{\mmuInstruction} [1] {\red{[\![\inst{MMU\_INST\_#1}]\!]}} + + +% from MMU_v2 +\newcommand{\mmuInstMload } {\mmuInstruction{mload}} +\newcommand{\mmuInstMstore } {\mmuInstruction{mstore}} +\newcommand{\mmuInstMstoreEight } {\mmuInstruction{mstore8}} +\newcommand{\mmuInstInvalidCodePrefix } {\mmuInstruction{invalidCodePrefix}} +\newcommand{\mmuInstRightPaddedWordExtraction } {\mmuInstruction{rightPaddedWordExtraction}} +\newcommand{\mmuInstRamToExoWithPadding } {\mmuInstruction{ramToExoWithPadding}} +\newcommand{\mmuInstExoToRamTransplants } {\mmuInstruction{exoToRamTransplants}} +\newcommand{\mmuInstRamToRamSansPadding } {\mmuInstruction{ramToRamSansPadding}} +\newcommand{\mmuInstAnyToRamWithPadding } {\mmuInstruction{anyToRamWithPadding}} +\newcommand{\mmuInstModexpZero } {\mmuInstruction{modexpZero}} +\newcommand{\mmuInstModexpData } {\mmuInstruction{modexpData}} +\newcommand{\mmuInstBlake } {\mmuInstruction{blake}} + +\newcommand{\exoModulePhase } [1] {\redm{[\![\Phi\texttt{\_#1}]\!]}} +% +\newcommand{\phaseTransactionCallData} {\exoModulePhase{transaction\_call\_data}} +% +\newcommand{\phaseKeccakData } {\exoModulePhase{KECCAK\_DATA}} +\newcommand{\phaseEcrecoverData } {\exoModulePhase{ECRECOVER\_DATA}} +\newcommand{\phaseShaTwoData } {\exoModulePhase{SHA2\_DATA}} +\newcommand{\phaseRipemdData } {\exoModulePhase{RIPEMD\_DATA}} +\newcommand{\phaseEcaddData } {\exoModulePhase{ECADD\_DATA}} +\newcommand{\phaseEcmulData } {\exoModulePhase{ECMUL\_DATA}} +\newcommand{\phaseEcpairingData } {\exoModulePhase{ECPAIRING\_DATA}} + +\newcommand{\phaseKeccakResult } {\exoModulePhase{KECCAK\_RESULT}} +\newcommand{\phaseEcrecoverResult } {\exoModulePhase{ECRECOVER\_RESULT}} +\newcommand{\phaseShaTwoResult } {\exoModulePhase{SHA2\_RESULT}} +\newcommand{\phaseRipemdResult } {\exoModulePhase{ripemd\_result}} +\newcommand{\phaseEcaddResult } {\exoModulePhase{ECADD\_RESULT}} +\newcommand{\phaseEcmulResult } {\exoModulePhase{ECMUL\_RESULT}} +\newcommand{\phaseEcpairingResult } {\exoModulePhase{ECPAIRING\_RESULT}} + +\newcommand{\phaseModexpBase } {\exoModulePhase{MODEXP\_BASE}} +\newcommand{\phaseModexpExponent } {\exoModulePhase{MODEXP\_EXPONENT}} +\newcommand{\phaseModexpModulus } {\exoModulePhase{MODEXP\_MODULUS}} +\newcommand{\phaseModexpResult } {\exoModulePhase{MODEXP\_RESULT}} + +\newcommand{\phaseBlakeParams } {\exoModulePhase{BLAKE\_PARAMS}} +\newcommand{\phaseBlakeData } {\exoModulePhase{BLAKE\_DATA}} +\newcommand{\phaseBlakeResult } {\exoModulePhase{BLAKE\_RESULT}} + +\newcommand{\exoWeight } [1] {\redm{[\![\inst{1 << #1}]\!]}} +\newcommand{\exoWeightRom } {\exoWeight{rom}} +\newcommand{\exoWeightKec } {\exoWeight{kec}} +\newcommand{\exoWeightLog } {\exoWeight{log}} +\newcommand{\exoWeightRlpTxn } {\exoWeight{txcd}} +\newcommand{\exoWeightEcdata } {\exoWeight{ecdata}} +\newcommand{\exoWeightRipSha } {\exoWeight{ripsha}} +\newcommand{\exoWeightBlakeModexp } {\exoWeight{blakeModexp}} + +%% EXO IS X flags +\newcommand{\isExoFlag } [1] {\col{EXO\_IS\_#1}} + +\newcommand{\isExoFlagRom } {\isExoFlag{ROM}} +\newcommand{\isExoFlagKec } {\isExoFlag{KEC}} +\newcommand{\isExoFlagLog } {\isExoFlag{LOG}} +\newcommand{\isExoFlagRlpTxn } {\isExoFlag{TXCD}} +\newcommand{\isExoFlagEcdata } {\isExoFlag{ECDATA}} +\newcommand{\isExoFlagRipSha } {\isExoFlag{RIPSHA}} +\newcommand{\isExoFlagBlakeModexp } {\isExoFlag{BLAKEMODEXP}} diff --git a/pkg/mmu_precompiles.sty b/pkg/mmu_precompiles.sty new file mode 100644 index 0000000..a392d8d --- /dev/null +++ b/pkg/mmu_precompiles.sty @@ -0,0 +1,34 @@ +% 0x01 - ECRECOVER +\newcommand{\EcrecoverExtractData}{\texttt{CALL\_0x01\_XTRCT} +\newcommand{\EcrecoverWriteResult}{\texttt{CALL\_0x01\_WRSLT}} +\newcommand{\EcrecoverPasteResult}{\texttt{CALL\_0x01\_PASTE}} +% 0x02 - SHA2-256 +\newcommand{\ShaTwoExtractData}{\texttt{CALL\_0x02\_XTRCT}} +\newcommand{\ShaTwoWriteResult}{\texttt{CALL\_0x02\_WRSLT}} +\newcommand{\ShaTwoPasteResult}{\texttt{CALL\_0x02\_PASTE}} +% 0x03 - RIPEMD-160 +\newcommand{\RipemdExtractData}{\texttt{CALL\_0x03\_XTRCT}} +\newcommand{\RipemdWriteResult}{\texttt{CALL\_0x03\_WRSLT}} +\newcommand{\RipemdPasteResult}{\texttt{CALL\_0x03\_PASTE}} +% 0x04 - IDENTITY +\newcommand{\IdentityExtract}{\texttt{CALL\_0x04\_COPY}} +\newcommand{\IdentityWriteResult}{\texttt{CALL\_0x04\_PASTE}} +% 0x05 - MODEXP +\newcommand{\ModexpExtractData}{\texttt{CALL\_0x05\_XTRCT}}}} +\newcommand{\ModexpWriteResult}{\texttt{CALL\_0x05\_WRSLT}} +\newcommand{\ModexpPasteResult}{\texttt{CALL\_0x05\_PASTE}} +% 0x06 - ECADD +\newcommand{\EcaddExtractData}{\texttt{CALL\_0x06\_XTRCT}} +\newcommand{\EcaddWriteResult}{\texttt{CALL\_0x06\_WRSLT}} +\newcommand{\EcaddPasteResult}{\texttt{CALL\_0x06\_PASTE}} +% 0x07 - ECMUL +\newcommand{\EcmulExtractData}{\texttt{CALL\_0x07\_XTRCT}} +\newcommand{\EcmulWriteResult}{\texttt{CALL\_0x07\_WRSLT}} +\newcommand{\EcmulPasteResult}{\texttt{CALL\_0x07\_PASTE}} +% 0x08 - ECPAIRING +\newcommand{\EcpairingExtractData}{\texttt{CALL\_0x08\_XTRCT}} +\newcommand{\EcpairingWriteResult}{\texttt{CALL\_0x08\_WRSLT}} +\newcommand{\EcpairingPasteResult}{\texttt{CALL\_0x08\_PASTE}} +% 0x09 - BLAKE2f +\newcommand{\BlakeExtractData}{\texttt{CALL\_0x09\_XTRCTE}} +\newcommand{\BlakeWriteResult}{\texttt{CALL\_0x09\_WRSLT}} \newcommand{\BlakePasteResult}{\texttt{CALL\_0x09\_PASTE}} diff --git a/pkg/mmu_writing.sty b/pkg/mmu_writing.sty new file mode 100644 index 0000000..b08c62f --- /dev/null +++ b/pkg/mmu_writing.sty @@ -0,0 +1,73 @@ +% modifying one target limb (surgery) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\modifyOneLimb}{\texttt{modifyOneLimb}} +\newcommand{\modifyOneLimbConstraints}{% +\left\{ +\begin{array}{l} + \If \precomputation_{i} = \typeFourCC + ~ \Then + \microInst_{i} = \ExoToRamSlideChunk \\ + \If \precomputation_{i} = \typeFourRD + ~ \Then + \microInst_{i} = \RamToRamSlideChunk \\ + \If \precomputation_{i} = \typeFourCD + ~ \Then + \begin{cases} + \If \iInfoBit{} = 0 + ~ \Then + \microInst_{i} = \RamToRamSlideChunk \\ + \If \iInfoBit{} = 1 + ~ \Then + \microInst_{i} = \ExoToRamSlideChunk \\ + \end{cases} +\end{array} +\right. +} + +% modifying two target limbs (surgery) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\modifyTwoLimbs}{\texttt{modifyTwoLimbs}} +\newcommand{\modifyTwoLimbsConstraints}{% +\left\{ +\begin{array}{l} + \If \precomputation_{i} = \typeFourCC + ~ \Then + \microInst_{i} = \ExoToRamSlideOverlappingChunk \\ + \If \precomputation_{i} = \typeFourRD + ~ \Then + \microInst_{i} = \RamToRamSlideOverlappingChunk \\ + \If \precomputation_{i} = \typeFourCD + ~ \Then + \begin{cases} + \If \iInfoBit{} = 0 + ~ \Then + \microInst_{i} = \RamToRamSlideOverlappingChunk \\ + \If \iInfoBit{} = 1 + ~ \Then + \microInst_{i} = \ExoToRamSlideOverlappingChunk \\ + \end{cases} +\end{array} +\right. +} + +% modifying one target limb (transplant) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\swapOneLimb}{\texttt{swapOneLimb}} +\newcommand{\swapOneLimbConstraints}{% +\left\{ +\begin{array}{l} + \If \precomputation_{i} = \typeFourCC ~ \Then + \microInst_{i} = \exoToRam \\ + \If \precomputation_{i} = \typeFourRD ~ \Then + \microInst_{i} = \ramToRam \\ + \If \precomputation_{i} = \typeFourCD ~ \Then + \begin{cases} + \If \iInfoBit_i = 0 ~ \Then \microInst_{i} = \ramToRam \\ + \If \iInfoBit_i = 1 ~ \Then \microInst_{i} = \exoToRam \\ + \end{cases} \\ +\end{array} +\right. +} \ No newline at end of file diff --git a/pkg/modexp.sty b/pkg/modexp.sty new file mode 100644 index 0000000..d7a4e67 --- /dev/null +++ b/pkg/modexp.sty @@ -0,0 +1,7 @@ +\newcommand{\BEMR} {\col{BASE\_EXPONENT\_MODULUS\_RESULT}} +\newcommand{\bemr} {\col{BEMR}} +\newcommand{\returnDataContext} {\col{RDCN}} +\newcommand{\RETURNDATACONTEXT} {\col{RETURN\_DATA\_CONTEXT\_NUMBER}} +\newcommand{\oneTwoSeven} {\red{127}} +\newcommand{\modexpMaxLimbs} {\red{32}} +\newcommand{\modexpMaxLimbsMO} {\red{31}} diff --git a/pkg/nsr_constants.sty b/pkg/nsr_constants.sty new file mode 100644 index 0000000..dff5ba7 --- /dev/null +++ b/pkg/nsr_constants.sty @@ -0,0 +1,76 @@ +\newcommand{\nsrCallAbort} {\redm{\mathtt{nsr}_{\col{callAbort}}}} +\newcommand{\nsrCallEoaCallerWillRevert} {\redm{\mathtt{nsr}_{\col{callEoaRev}}}} +\newcommand{\nsrCallEoaCallerWontRevert} {\redm{\mathtt{nsr}_{\col{callEoaNoRev}}}} +\newcommand{\nsrCallSmcCallerWontRevertCalleeSuccess} {\redm{\mathtt{nsr}_{\col{callSmcNoRevSuccess}}}} +\newcommand{\nsrCallSmcCallerWontRevertCalleeFailure} {\redm{\mathtt{nsr}_{\col{callSmcNoRevFailure}}}} +\newcommand{\nsrCallSmcCallerWillRevertCalleeSuccess} {\redm{\mathtt{nsr}_{\col{callSmcRevSuccess}}}} +\newcommand{\nsrCallSmcCallerWillRevertCalleeFailure} {\redm{\mathtt{nsr}_{\col{callSmcRevFailure}}}} +% \newcommand{\nsrCall} {\redm{c_{\col{}}} +% \newcommand{\nsrCall} {\redm{c_{\col{}}} +% \newcommand{\nsrCall} {\redm{c_{\col{}}} +% \newcommand{\nsrCall} {\redm{c_{\col{}}} +% \newcommand{\nsrCall} {\redm{c_{\col{}}} +% +% non stack row constants for precompiles +% +% Ecrecover +\newcommand{\nsrEcrecoverFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{ECREC}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrEcrecoverFailureEmptyCallData} {\redm{\texttt{nsr}^{\texttt{ECREC}}_{\colm{\orangem{\colm{fail}}/\bm{\varnothing}\_call\_data}}}} +\newcommand{\nsrEcrecoverFailureNonEmptyMalformed} {\redm{\texttt{nsr}^{\texttt{ECREC}}_{\colm{\orangem{\colm{fail}}/malformed}}}} +\newcommand{\nsrEcrecoverFailureNonEmptyUnrecoverable} {\redm{\texttt{nsr}^{\texttt{ECREC}}_{\colm{\orangem{\colm{fail}}/unrecoverable}}}} +\newcommand{\nsrEcrecoverSuccessSansRac} {\redm{\texttt{nsr}^{\texttt{ECREC}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrEcrecoverSuccessWithRac} {\redm{\texttt{nsr}^{\texttt{ECREC}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% ShaTwo +\newcommand{\nsrShaTwoFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{SHA2}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrShaTwoSuccessEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{SHA2}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/\bm{\varnothing}}}}} +\newcommand{\nsrShaTwoSuccessEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{SHA2}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/w}}}} +\newcommand{\nsrShaTwoSuccessNonEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{SHA2}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrShaTwoSuccessNonEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{SHA2}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% Ripemd +\newcommand{\nsrRipemdFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{RIPE}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrRipemdSuccessEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{RIPE}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/\bm{\varnothing}}}}} +\newcommand{\nsrRipemdSuccessEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{RIPE}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/w}}}} +\newcommand{\nsrRipemdSuccessNonEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{RIPE}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrRipemdSuccessNonEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{RIPE}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% Identity +\newcommand{\nsrIdentityFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{ID}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrIdentitySuccessEmptyCallData} {\redm{\texttt{nsr}^{\texttt{ID}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}\_call\_data}}}} +\newcommand{\nsrIdentitySuccessNonEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ID}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrIdentitySuccessNonEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ID}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% MODEXP TODO +% +% Ecadd +\newcommand{\nsrEcaddFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{ECADD}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrEcaddFailureMalformedCallData} {\redm{\texttt{nsr}^{\texttt{ECADD}}_{\colm{\orangem{\colm{fail}}/malformed}}}} +\newcommand{\nsrEcaddSuccessEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ECADD}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/\bm{\varnothing}}}}} +\newcommand{\nsrEcaddSuccessEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ECADD}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/w}}}} +\newcommand{\nsrEcaddSuccessNonEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ECADD}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrEcaddSuccessNonEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ECADD}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% Ecmul +\newcommand{\nsrEcmulFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{ECMUL}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrEcmulFailureMalformedCallData} {\redm{\texttt{nsr}^{\texttt{ECMUL}}_{\colm{\orangem{\colm{fail}}/malformed}}}} +\newcommand{\nsrEcmulSuccessEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ECMUL}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/\bm{\varnothing}}}}} +\newcommand{\nsrEcmulSuccessEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ECMUL}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/w}}}} +\newcommand{\nsrEcmulSuccessNonEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ECMUL}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrEcmulSuccessNonEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ECMUL}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% Ecpairing +\newcommand{\nsrEcpairingFailureIncongruentSize} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\orangem{\colm{fail}}}}}} +\newcommand{\nsrEcpairingFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrEcpairingFailureMalformedCallData} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\orangem{\colm{fail}}/malformed}}}} +\newcommand{\nsrEcpairingSuccessEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/\bm{\varnothing}}}}} +\newcommand{\nsrEcpairingSuccessEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\greenm{\colm{succ}}/\bm{\varnothing}/w}}}} +\newcommand{\nsrEcpairingSuccessNonEmptyCallDataZeroRac} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\greenm{\colm{succ}}/rd/\bm{\varnothing}}}}} +\newcommand{\nsrEcpairingSuccessNonEmptyCallDataNonZeroRac} {\redm{\texttt{nsr}^{\texttt{ECPAIR}}_{\colm{\greenm{\colm{succ}}/rd/w}}}} +% +% Blake +\newcommand{\nsrBlakeFailureIllegalSize} {\redm{\texttt{nsr}^{\texttt{BLAKE}}_{\colm{\orangem{\colm{fail}}/size\_not\_213}}}} +\newcommand{\nsrBlakeFailureFNotABit} {\redm{\texttt{nsr}^{\texttt{BLAKE}}_{\colm{\orangem{\colm{fail}}/f\_not\_a\_bit}}}} +\newcommand{\nsrBlakeFailureInsufficientGas} {\redm{\texttt{nsr}^{\texttt{BLAKE}}_{\colm{\orangem{\colm{fail}}/gas}}}} +\newcommand{\nsrBlakeSuccessZeroRac} {\redm{\texttt{nsr}^{\texttt{BLAKE}}_{\colm{\greenm{\colm{succ}}/213/\bm{\varnothing}}}}} +\newcommand{\nsrBlakeSuccessNonZeroRac} {\redm{\texttt{nsr}^{\texttt{BLAKE}}_{\colm{\greenm{\colm{succ}}/213/w}}}} diff --git a/pkg/offset_processor.sty b/pkg/offset_processor.sty new file mode 100644 index 0000000..7f7efcf --- /dev/null +++ b/pkg/offset_processor.sty @@ -0,0 +1,159 @@ +% +\newcommand{\iInst}{\imported{\INST}} % imported instruction column + +% \newcommand{\REFSIZE} {\col{REFERENCE\_SIZE}} +\newcommand{\iREFSIZE} {\imported{\REFSIZE}} +% \newcommand{\refSize} {\col{REFS}} +\newcommand{\iRefSize} {\imported{\refSize}} +\newcommand{\REFOFF} {\col{REFERENCE\_OFFSET}} +\newcommand{\iREFOFF} {\imported{\REFOFF}} +\newcommand{\refOff} {\col{REFO}} +\newcommand{\iRefOff} {\imported{\refOff}} +% + +% \newcommand{\off}{\col{OFF}} +% \newcommand{\codeSize}{\col{CODESIZE}} + +\newcommand{\destOff}{\col{T\_OFF}} +\newcommand{\srcOff}{\col{S\_OFF}} + +\newcommand{\depNum}{\col{DEP\#}} +% \newcommand{\shaNum}{\col{SHA\#}} +\newcommand{\depAddr}{\col{DEP\_ADDR}} + +\newcommand{\PRECOMPUTATION}{\decoded{\col{PRECOMPUTATION}}} +\newcommand{\precomputation}{\decoded{\col{PRE}}} +\newcommand{\typeFourCC}{\texttt{type4CC}} +\newcommand{\typeFourCD}{\texttt{type4CD}} +\newcommand{\typeFourRD}{\texttt{type4RD}} + +\newcommand{\infoBit}{\col{INFO}} +\newcommand{\iInfoBit}{\imported{\infoBit}} +\newcommand{\refNum}{\col{\#}} + + +% + +\newcommand{\MICROSTAMP}{\mu\col{INSTRUCTION\_STAMP}} +%\newcommand{\microStamp}{\stampCol{\mu\col{INST}}} + +\newcommand{\ISMICROINST}{\col{IS\_MICRO\_INSTRUCTION}} +\newcommand{\isMicroInst}{\col{IS}\_\mu} + +\newcommand{\MICROINST}{\col{MICRO\_INSTRUCTION}} +%\newcommand{\microInst}{\mu\col{INST}} + +\newcommand{\TOTAL}{\col{TOTAL\_NUMBER\_OF\_MICRO\_INSTRUCTIONS}} +\newcommand{\TOTALREADS}{\col{TOTAL\_NUMBER\_OF\_DATA\_READING\_MICRO\_INSTRUCTIONS}} +\newcommand{\TOTALPADDINGS}{\col{TOTAL\_NUMBER\_OF\_ZERO\_PADDING\_MICRO\_INSTRUCTIONS}} + +\newcommand{\total}{\col{TOT}^\mu} +\newcommand{\totalReads}{\col{TOTRD}} +\newcommand{\totalPaddings}{\col{TOTPD}} + + +\newcommand{\CNS}{\col{CONTEXT\_SOURCE}} +\newcommand{\CNT}{\col{CONTEXT\_TARGET}} +\newcommand{\cnS}{\col{CN\_S}} +\newcommand{\cnT}{\col{CN\_T}} + +\newcommand{\OFFOOB}{\col{OFFSET\_OUT\_OF\_BOUNDS}} +\newcommand{\offOob}{\col{OFF\_OOB}} + +\newcommand{\iCN}{\imported{\CN}} +\newcommand{\iCn}{\imported{\cn}} +\newcommand{\iCaller}{\imported{\caller}} +\newcommand{\iReturner}{\imported{\returner}} +\newcommand{\icType}{\imported{\cType}} +\newcommand{\iRdo}{\imported{\rdo}} +\newcommand{\iRds}{\imported{\rds}} +\newcommand{\iCdo}{\imported{\cdo}} +\newcommand{\iCds}{\imported{\cds}} +\newcommand{\iRetAtOff}{\imported{\retAtOff}} +\newcommand{\iRetAtCap}{\imported{\retAtCap}} + +\newcommand{\instParam}[1]{\col{INST\_PARAM\_#1}} +\newcommand{\exoSum}{\col{EXO\_SUM}} + +\newcommand{\minSize}{\col{MIN}} +\newcommand{\adjDiff}{\Delta^\col{adj}} + + +\newcommand{\offOne}{\off{}\col{\_1}} +\newcommand{\offTwo}{\off{}\col{\_2}} +\newcommand{\iOffOne}{\imported{\offOne}} +\newcommand{\iOffTwo}{\imported{\offTwo}} +% \newcommand{\iSize}{\imported{\size{}}} +\newcommand{\valHi}{\val\col{\_HI}} +\newcommand{\valLo}{\val\col{\_LO}} +\newcommand{\iValHi}{\imported{\val\high}} +\newcommand{\iValLo}{\imported{\val\low}} +\newcommand{\iVal}{\imported{\val}} +\newcommand{\iLimb}{\imported{\limb}} +\newcommand{\iTotSize}{\imported{\col{TOTAL\_SIZE}}} +\newcommand{\iExoSum}{\imported{\exoSum}} +\newcommand{\iIdOne}{\imported{\col{ID\_1}}} +\newcommand{\iIdTwo}{\imported{\col{ID\_2}}} +\newcommand{\successBit}{\col{SUCCESS\_BIT}} + +\newcommand{\fastOp}{\col{FAST}} +\newcommand{\slowOp}{\col{SLOW}} +\newcommand{\offAlign}{\col{ALIGNED}} + +% +\newcommand{\Ione}{\col{INDEX}^1} +% \newcommand{\IoneByte}{\col{INDEX}^1\col{B}} +% \newcommand{\IonePref}{\col{INDEX}^1\col{P}} +\newcommand{\Rone}{\col{REM}^1} +% +\newcommand{\Itwo}{\col{INDEX}^2} +% \newcommand{\ItwoByte}{\col{INDEX}^2\col{B}} +% \newcommand{\ItwoPref}{\col{INDEX}^2\col{P}} +\newcommand{\Rtwo}{\col{REM}^2} +% +\newcommand{\quot}[1]{\col{QUOT}^{#1}} +\newcommand{\nibble}[1]{\col{NIB\_#1}} +% \newcommand{\sz}{\col{size}} + +\newcommand{\SLO}{\col{SOURCE\_LIMB\_OFFSET}} +\newcommand{\slo}{\col{SLO}} +\newcommand{\SBO}{\col{SOURCE\_BYTE\_OFFSET}} +\newcommand{\sbo}{\col{SBO}} + +\newcommand{\TLO}{\col{TARGET\_LIMB\_OFFSET}} +\newcommand{\tlo}{\col{TLO}} +\newcommand{\TBO}{\col{TARGET\_BYTE\_OFFSET}} +\newcommand{\tbo}{\col{TBO}} + +% \newcommand{\byteCol}[1]{\col{BYTE\_#1}} +\newcommand{\prefCol}[1]{\col{PREF}^{#1}} + +\newcommand{\precomputationType}[1]{\texttt{Type\_#1}} + +\newcommand{\decToRam}{\decoded{\col{TO\_RAM}}} + +\newcommand{\decxRom}{\decoded{\col{X\_ROM}}} +\newcommand{\decxLog}{\decoded{\col{X\_LOG}}} +\newcommand{\decxSha}{\decoded{\col{X\_SHA3}}} +\newcommand{\decxTxcd}{\decoded{\col{X\_TXCD}}} + +\newcommand{\bitParam}[1]{\col{BIT}^{#1}} + +\DeclareFontFamily{U}{wncy}{} +\DeclareFontShape{U}{wncy}{m}{n}{<->wncyr10}{} +\DeclareSymbolFont{mcy}{U}{wncy}{m}{n} +\DeclareMathSymbol{\peigneDeDirac}{\mathord}{mcy}{"58} + +\newcommand{\TERNARY}{\col{TERNARY}} +\newcommand{\ternary}{\col{TERN}} + +\newcommand{\nBytes}{\col{nBYTES}} + +\newcommand{\limbOff}{\col{LO}} +\newcommand{\byteOff}{\col{BO}} + +\newcommand{\limbOffOne}{\col{LO\_1}} +\newcommand{\byteOffOne}{\col{BO\_1}} + +\newcommand{\limbOffTwo}{\col{LO\_2}} +\newcommand{\byteOffTwo}{\col{BO\_2}} diff --git a/pkg/oob.sty b/pkg/oob.sty new file mode 100644 index 0000000..51b7dd5 --- /dev/null +++ b/pkg/oob.sty @@ -0,0 +1,153 @@ +% \newcommand{}{\imported{}} +% \newcommand{}{\col{}} + +\newcommand{\oobType}[1]{\col{TYPE\_#1}} +\newcommand{\maxCodeSize}{\texttt{maxCodeSize}} +\newcommand{\NONNEGATIVITYCHECKREQUIRED}{\col{REQUIRES\_NONNEGATIVITY\_CHECK}} +\newcommand{\requiresNonnegativityCheck}{\col{RNNC}} + +\newcommand{\fast}{\col{FAST}} +\newcommand{\jumpOob}{\col{JOOB}} +\newcommand{\iJumpOob}{\imported{\jumpOob}} +\newcommand{\xRdc}{\col{RETDCX}} +\newcommand{\xMax}{\col{MAXCSX}} +\newcommand{\ixRdc}{\imported{\xRdc}} +\newcommand{\ixMax}{\imported{\xMax}} +\newcommand{\iCodeSize}{\imported{\codeSize}} + + +% \newcommand{\}{\col{}} +% \newcommand{\i}{\imported{\}} + +% \newcommand{\jumpFlag}{\col{JUMPF}} +% \newcommand{\iJumpFlag}{\imported{\jumpFlag}} + + +\newcommand{\REFSIZE}{\col{REFERENCE\_SIZE}} +\newcommand{\refSize}{\col{REFS}} + +\newcommand{\isVal}[1]{\imported{\sVal{#1}}} + +\newcommand{\BOOB}{\col{RIDICULOUSLY\_OOB}} +\newcommand{\bOob}{\col{ROOB}} +\newcommand{\CDLOOB}{\col{CALLDATALOAD\_OOB}} +\newcommand{\cdlOob}{\col{CDL\_OOB}} +\newcommand{\iCdlOob}{\imported{\cdlOob}} + +\newcommand{\oob} {\col{OOB}} + +\newcommand{\Input}[1]{\col{INPUT\_#1}} +\newcommand{\iInput}[1]{\imported{\Input{#1}}} + +\newcommand{\oobDataCol} [1] {\dataCol{#1}} + +\newcommand{\outgoingInst} {\col{OUTGOING\_INST}} +\newcommand{\outgoingDataCol} [1] {\col{OUTGOING\_DATA\_#1}} +\newcommand{\outgoingResLo} {\col{OUTGOING\_RES\_LO}} +\newcommand{\out} [1] {\col{OUT\_#1}} + +% standard instructions +\newcommand{\oobInstructionFlag} [1] {\col{IS\_#1}} +\newcommand{\oobInstIsJump} {\oobInstructionFlag{JUMP}} +\newcommand{\oobInstIsJumpI} {\oobInstructionFlag{JUMPI}} +\newcommand{\oobInstIsRdc} {\oobInstructionFlag{RDC}} +\newcommand{\oobInstIsCdl} {\oobInstructionFlag{CDL}} +\newcommand{\oobInstIsCreate} {\oobInstructionFlag{CREATE}} +\newcommand{\oobInstIsCall} {\oobInstructionFlag{CALL}} +\newcommand{\oobInstIsXcall} {\oobInstructionFlag{XCALL}} +\newcommand{\oobInstIsSstore} {\oobInstructionFlag{SSTORE}} +\newcommand{\oobInstIsDeployment} {\oobInstructionFlag{DEPLOYMENT}} +% precompiles +\newcommand{\oobInstIsEcrecover } {\oobInstructionFlag{ECRECOVER}} +\newcommand{\oobInstIsShaTwo } {\oobInstructionFlag{SHA2}} +\newcommand{\oobInstIsRipemd } {\oobInstructionFlag{RIPEMD}} +\newcommand{\oobInstIsIdentity } {\oobInstructionFlag{IDENTITY}} +\newcommand{\oobInstIsEcadd } {\oobInstructionFlag{ECADD}} +\newcommand{\oobInstIsEcmul } {\oobInstructionFlag{ECMUL}} +\newcommand{\oobInstIsEcpairing } {\oobInstructionFlag{ECPAIRING}} +\newcommand{\oobInstIsBlakeCds } {\oobInstructionFlag{BLAKE2F\_CDS}} +\newcommand{\oobInstIsBlakeParams } {\oobInstructionFlag{BLAKE2F\_PARAMS}} +\newcommand{\oobInstIsModexpCds } {\oobInstructionFlag{MODEXP\_CDS}} +\newcommand{\oobInstIsModexpXbs } {\oobInstructionFlag{MODEXP\_XBS}} +\newcommand{\oobInstIsModexpLead } {\oobInstructionFlag{MODEXP\_LEAD}} +\newcommand{\oobInstIsModexpPricing } {\oobInstructionFlag{MODEXP\_PRICING}} +\newcommand{\oobInstIsModexpExtract } {\oobInstructionFlag{MODEXP\_EXTRACT}} + +\newcommand{\oobInstruction} [1] {\col{OOB\_INST}} + +\newcommand{\oobInst} [1] {\red{[\![\inst{OOB\_INST\_#1}]\!]}} + +\newcommand{\oobInstJump } {\oobInst{JUMP} } +\newcommand{\oobInstJumpI } {\oobInst{JUMPI} } +\newcommand{\oobInstRdc } {\oobInst{RDC} } +\newcommand{\oobInstCdl } {\oobInst{CDL} } +\newcommand{\oobInstXcall } {\oobInst{XCALL} } +\newcommand{\oobInstCall } {\oobInst{CALL} } +\newcommand{\oobInstCreate } {\oobInst{CREATE} } +\newcommand{\oobInstSstore } {\oobInst{SSTORE} } +\newcommand{\oobInstDeployment } {\oobInst{DEPLOYMENT} } +% +\newcommand{\oobInstEcrecover } {\oobInst{ECRECOVER} } +\newcommand{\oobInstShaTwo } {\oobInst{SHA2} } +\newcommand{\oobInstRipemd } {\oobInst{RIPEMD} } +\newcommand{\oobInstIdentity } {\oobInst{IDENTITY} } +\newcommand{\oobInstEcadd } {\oobInst{ECADD} } +\newcommand{\oobInstEcmul } {\oobInst{ECMUL} } +\newcommand{\oobInstEcpairing } {\oobInst{ECPAIRING} } +% +\newcommand{\oobInstBlakeCds } {\oobInst{BLAKE\_CDS} } +\newcommand{\oobInstBlakeParams } {\oobInst{BLAKE\_PARAMS} } +% +\newcommand{\oobInstModexpCds } {\oobInst{MODEXP\_CDS} } +\newcommand{\oobInstModexpXbs } {\oobInst{MODEXP\_XBS} } +\newcommand{\oobInstModexpLead } {\oobInst{MODEXP\_LEAD} } +\newcommand{\oobInstModexpPricing } {\oobInst{MODEXP\_PRICING} } +\newcommand{\oobInstModexpExtract } {\oobInst{MODEXP\_EXTRACT} } + +% +\newcommand{\oxConst } [1] {\red{\texttt{0x\,#1}}} +\newcommand{\oxXcall } {\oxConst{XCALL}} +\newcommand{\oxCall } {\oxConst{CALL}} +\newcommand{\oxCreate } {\oxConst{CREATE}} +\newcommand{\oxBlakeCds } {\oxConst{BLAKE\_CDS}} +\newcommand{\oxBlakeParams } {\oxConst{BLAKE\_PARAMS}} +\newcommand{\oxModexpCds } {\oxConst{MODEXP\_CDS}} +\newcommand{\oxModexpXbs } {\oxConst{MODEXP\_XBS}} +\newcommand{\oxModexpLead } {\oxConst{MODEXP\_LEAD}} +\newcommand{\oxModexpPricing } {\oxConst{MODEXP\_PRICING}} +\newcommand{\oxModexpExtract } {\oxConst{MODEXP\_EXTRACT}} +% + +\newcommand{\oxEcrecover} {\red{\texttt{0x\,ERCV}}} +\newcommand{\oxShaTwo} {\red{\texttt{0x\,SHA2}}} +\newcommand{\oxRipemd} {\red{\texttt{0x\,RIPE}}} +\newcommand{\oxIdentity} {\red{\texttt{0x\,IDEN}}} +\newcommand{\oxEcadd} {\red{\texttt{0x\,EADD}}} +\newcommand{\oxEcmul} {\red{\texttt{0x\,EMUL}}} +\newcommand{\oxEcpairing} {\red{\texttt{0x\,PAIR}}} + +\newcommand{\oobCtMaxJump} {\texttt{CT\_MAX\_JUMP}} +\newcommand{\oobCtMaxJumpI} {\texttt{CT\_MAX\_JUMPI}} +\newcommand{\oobCtMaxRdc} {\texttt{CT\_MAX\_RDC}} +\newcommand{\oobCtMaxCdl} {\texttt{CT\_MAX\_CDL}} +\newcommand{\oobCtMaxXcall} {\texttt{CT\_MAX\_XCALL}} +\newcommand{\oobCtMaxCall} {\texttt{CT\_MAX\_CALL}} +\newcommand{\oobCtMaxCreate} {\texttt{CT\_MAX\_CREATE}} +\newcommand{\oobCtMaxSstore} {\texttt{CT\_MAX\_SSTORE}} +\newcommand{\oobCtMaxDeployment} {\texttt{CT\_MAX\_DEPLOYMENT}} + +\newcommand{\oobCtMaxEcrecover} {\texttt{CT\_MAX\_ECRECOVER}} +\newcommand{\oobCtMaxShaTwo} {\texttt{CT\_MAX\_SHA2-256}} +\newcommand{\oobCtMaxRipemd} {\texttt{CT\_MAX\_RIPEMD-160}} +\newcommand{\oobCtMaxIdentity} {\texttt{CT\_MAX\_IDENTITY}} +\newcommand{\oobCtMaxEcadd} {\texttt{CT\_MAX\_ECADD}} +\newcommand{\oobCtMaxEcmul} {\texttt{CT\_MAX\_ECMUL}} +\newcommand{\oobCtMaxEcpairing} {\texttt{CT\_MAX\_ECPAIRING}} +\newcommand{\oobCtMaxBlakeCds } {\texttt{CT\_MAX\_BLAKE2F\_CDS}} +\newcommand{\oobCtMaxBlakeParams} {\texttt{CT\_MAX\_BLAKE2F\_PARAMS}} + +\newcommand{\oobCtMaxModexpCds } {\texttt{CT\_MAX\_MODEXP\_CDS}} +\newcommand{\oobCtMaxModexpXbs } {\texttt{CT\_MAX\_MODEXP\_XBS}} +\newcommand{\oobCtMaxModexpLead } {\texttt{CT\_MAX\_MODEXP\_LEAD}} +\newcommand{\oobCtMaxModexpPricing } {\texttt{CT\_MAX\_MODEXP\_PRICING}} +\newcommand{\oobCtMaxModexpExtract } {\texttt{CT\_MAX\_MODEXP\_EXTRACT}} diff --git a/pkg/prc.sty b/pkg/prc.sty new file mode 100644 index 0000000..8a81512 --- /dev/null +++ b/pkg/prc.sty @@ -0,0 +1,33 @@ +\newcommand{\ecPhase} {\col{PHASE}} +\newcommand{\ecId} {\col{ID}} + +\newcommand{\shakiraPhase} {\col{PHASE}} +\newcommand{\shakiraId} {\col{ID}} +\newcommand{\isShakiraKeccakData} {\col{IS\_KECCAK\_DATA}} +\newcommand{\isShakiraKeccakResult} {\col{IS\_KECCAK\_RESULT}} +\newcommand{\isShakiraShaTwoData} {\col{IS\_SHA2\_DATA}} +\newcommand{\isShakiraShaTwoResult} {\col{IS\_SHA2\_RESULT}} +\newcommand{\isShakiraRipemdData} {\col{IS\_RIPEMD\_DATA}} +\newcommand{\isShakiraRipemdResult} {\col{IS\_RIPEMD\_RESULT}} +\newcommand{\isShakiraExtra} {\col{IS\_EXTRA}} +\newcommand{\shakiraTotalSize} {\col{TOTAL\_SIZE}} + +\newcommand{\modexpBlakePhase} {\col{PHASE}} +\newcommand{\modexpBlakeId} {\col{ID}} +\newcommand{\isModexpBase} {\col{IS\_MODEXP\_BASE}} +\newcommand{\isModexpExponent} {\col{IS\_MODEXP\_EXPONENT}} +\newcommand{\isModexpModulus} {\col{IS\_MODEXP\_MODULUS}} +\newcommand{\isModexpResult} {\col{IS\_MODEXP\_RESULT}} +\newcommand{\isBlakeData} {\col{IS\_BLAKE\_DATA}} +\newcommand{\isBlakeParams} {\col{IS\_BLAKE\_PARAMS}} +\newcommand{\isBlakeResult} {\col{IS\_BLAKE\_RESULT}} +\newcommand{\deltaByte} {\Delta\col{\_BYTE}} +\newcommand{\blakeRowsMO} {\redm{29}} +\newcommand{\blakeRows} {\redm{30}} + + +% \newcommand{\flagSumShakira} {\col{flag\_sum}} +% \newcommand{} {\col{}} +% \newcommand{} {\col{}} +% \newcommand{} {\col{}} +% \newcommand{} {\col{}} diff --git a/pkg/precompiles.sty b/pkg/precompiles.sty new file mode 100644 index 0000000..6d82d66 --- /dev/null +++ b/pkg/precompiles.sty @@ -0,0 +1,309 @@ +% TODO: move to file for global macros +\newcommand{\both}[1] {#1[] \textcolor{magenta}{$\equiv$} #1} +\newcommand{\newcol}[3] {\newcommand{#1}[1][\empty]{\ifx\empty##1\col{#2}\else\col{#3}\fi}} + +% SHAKIRA +\newcommand{\selectorKeccakRes} {\col{SELECTOR\_KECCAK\_RES}} +\newcommand{\selectorShaTwoRes} {\col{SELECTOR\_SHA2\_RES}} +\newcommand{\selectorRipemdRes} {\col{SELECTOR\_RIPEMD\_RES}} + +% EC_DATA +\newcommand{\ecdataId} {\col{ID}} +\newcommand{\ecdataIndex} {\col{\index}} +\newcommand{\ecdataLimb} {\col{\limb}} +\newcommand{\ecdataTotalSize} {\col{TOTAL\_SIZE}} +\newcommand{\ecdataPhase} {\col{PHASE}} +\newcommand{\ecdataSuccessBit} {\col{SUCCESS\_BIT}} +% +\newcommand{\indexMaxEcrecoverData} {\texttt{INDEX\_MAX\_ECRECOVER\_DATA}} +\newcommand{\indexMaxEcaddData} {\texttt{INDEX\_MAX\_ECADD\_DATA}} +\newcommand{\indexMaxEcmulData} {\texttt{INDEX\_MAX\_ECMUL\_DATA}} +\newcommand{\indexMaxEcPairingDataMin} {\texttt{INDEX\_MAX\_ECPAIRING\_DATA\_MIN}} +\newcommand{\indexMaxEcrecoverResult} {\texttt{INDEX\_MAX\_ECRECOVER\_RESULT}} +\newcommand{\indexMaxEcaddResult} {\texttt{INDEX\_MAX\_ECADD\_RESULT}} +\newcommand{\indexMaxEcmulResult} {\texttt{INDEX\_MAX\_ECMUL\_RESULT}} +\newcommand{\indexMaxEcpairingResult} {\texttt{INDEX\_MAX\_ECPAIRING\_RESULT}} +% +\newcommand{\ctMaxSmallPoint} {\texttt{CT\_MAX\_SMALL\_POINT}} +\newcommand{\ctMaxLargePoint} {\texttt{CT\_MAX\_LARGE\_POINT}} +% +\newcommand{\totalSizeEcrecoverData}{\texttt{TOTAL\_SIZE\_ECRECOVER\_DATA}} +\newcommand{\totalSizeEcaddData}{\texttt{TOTAL\_SIZE\_ECADD\_DATA}} +\newcommand{\totalSizeEcmulData}{\texttt{TOTAL\_SIZE\_ECMUL\_DATA}} +\newcommand{\totalSizeEcpairingDataMin}{\texttt{TOTAL\_SIZE\_ECPAIRING\_DATA\_MIN}} +\newcommand{\totalSizeEcrecoverResult}{\texttt{TOTAL\_SIZE\_ECRECOVER\_RESULT}} +\newcommand{\totalSizeEcaddResult}{\texttt{TOTAL\_SIZE\_ECADD\_RESULT}} +\newcommand{\totalSizeEcmulResult}{\texttt{TOTAL\_SIZE\_ECMUL\_RESULT}} +\newcommand{\totalSizeEcpairingResult}{\texttt{TOTAL\_SIZE\_ECPAIRING\_RESULT}} +% +\newcommand{\gms} {\col{STAMP}} % Generic Module Stamp +\newcommand{\addressLo} {\col{ADDR\_LO}} +\newcommand{\ecRecover} {\col{ECRECOVER}\flag} +\newcommand{\ecAdd} {\col{ECADD}\flag} +\newcommand{\ecMul} {\col{ECMUL}\flag} +\newcommand{\ecPairing} {\col{ECPAIRING}\flag} +% +\newcommand{\locIsEcrecover} {\col{is\_ecrecover}} +\newcommand{\locIsEcadd} {\col{is\_ecadd}} +\newcommand{\locIsEcmul} {\col{is\_ecmul}} +\newcommand{\locIsEcpairing} {\col{is\_ecpairing}} +% +\newcommand{\isEcrecoverData} {\col{IS\_ECRECOVER\_DATA}\flag} +\newcommand{\isEcrecoverResult} {\col{IS\_ECRECOVER\_RESULT}\flag} +\newcommand{\isEcaddData} {\col{IS\_ECADD\_DATA}\flag} +\newcommand{\isEcaddResult} {\col{IS\_ECADD\_RESULT}\flag} +\newcommand{\isEcmulData} {\col{IS\_ECMUL\_DATA}\flag} +\newcommand{\isEcmulResult} {\col{IS\_ECMUL\_RESULT}\flag} +\newcommand{\isEcpairingData} {\col{IS\_ECPAIRING\_DATA}\flag} +\newcommand{\isEcpairingResult} {\col{IS\_ECPAIRING\_RESULT}\flag} +% +\newcommand{\totalPairings} {\col{TOTAL\_PAIRINGS}} +\newcommand{\accPairings} {\col{ACC\_PAIRINGS}} +\newcommand{\limb} {\col{LIMB}} + +% \renewcommand{\comp} {\col{COMP}} +\newcommand{\fail} {\col{FAIL}} +\newcommand{\eqn} {\col{EQN}} +\newcommand{\evenOdd} {\col{EVENODD}} +\newcommand{\inputsAreValid} {\col{VALID\_INPUTS}} +\newcommand{\isOnCurve} {\col{IS\_ON\_CURVE}} +\newcommand{\midCycle} {\col{MIDCYCLE}} +\newcommand{\comparisons} {\col{COMPARISONS}} +\newcommand{\equalities} {\col{EQUALITIES}} +\newcommand{\hurdle} {\col{HURDLE}} +\newcol{\internalChecksPassed} {ICP}{INTERNAL\_CHECKS\_PASSED} +\newcommand{\ctMin} {\col{CT\_MIN}} +\newcommand{\allChecksPassed} {\col{ALL\_CHECKS\_PASSED}} +\newcommand{\returnData} {\col{RETURN\_DATA}} +\newcommand{\ecdsaRecoverPassed} {\col{ECDSA\_RECOVER\_PASSED}} + +\newcommand{\cyclicCol}[1] {\col{CYC\_#1}} + +\newcommand{\wcpArgOneHi} {\col{WCP\_ARG1\_HI}} +\newcommand{\wcpArgOneLo} {\col{WCP\_ARG1\_LO}} +\newcommand{\wcpArgTwoHi} {\col{WCP\_ARG2\_HI}} +\newcommand{\wcpArgTwoLo} {\col{WCP\_ARG2\_LO}} +\newcommand{\wcpInst} {\col{WCP\_INST}} +\newcommand{\wcpRes} {\col{WCP\_RES}} + +\newcommand{\extArgOneLo} {\col{EXT\_ARG1\_LO}} +\newcommand{\extArgOneHi} {\col{EXT\_ARG1\_HI}} +\newcommand{\extArgTwoLo} {\col{EXT\_ARG2\_LO}} +\newcommand{\extArgTwoHi} {\col{EXT\_ARG2\_HI}} +\newcommand{\extArgThreeLo} {\col{EXT\_ARG3\_LO}} +\newcommand{\extArgThreeHi} {\col{EXT\_ARG3\_HI}} +\newcommand{\extInst} {\col{EXT\_INST}} +\newcommand{\extResLo} {\col{EXT\_RES\_LO}} +\newcommand{\extResHi} {\col{EXT\_RES\_HI}} + +\newcommand{\ecCycleMax} {\redm{11}} +\newcommand{\ecCycleMed} {\redm{7}} +\newcommand{\ecCycleMin} {\redm{5}} +\newcommand{\notOnGTwo} {\col{NOT\_ON\_G2}} +\newcommand{\notOnGTwoAcc} {\col{NOT\_ON\_G2\_ACC}} +\newcommand{\notOnGTwoAccMax} {\col{NOT\_ON\_G2\_ACC\_MAX}} +\newcommand{\isInfinity} {\col{IS\_INFINITY}} +\newcommand{\selector} {\col{sel}} +\newcommand{\bnOuterPrime} {\texttt{P\_BN}} +\newcommand{\secpN} {\texttt{SECP256K1N}} +\newcommand{\bnOuterPrimeHi} {\bnOuterPrime\texttt{\_HI}} +\newcommand{\bnOuterPrimeLo} {\bnOuterPrime\texttt{\_LO}} +\newcommand{\secpNHi} {\secpN\texttt{\_HI}} +\newcommand{\secpNLo} {\secpN\texttt{\_LO}} + +\newcommand{\bnOuterPrimeHex} {\texttt{0x\,30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47}} +\newcommand{\bnOuterPrimeHexHi} {\texttt{0x\,30644e72e131a029b85045b68181585d}} +\newcommand{\bnOuterPrimeHexLo} {\texttt{0x\,97816a916871ca8d3c208c16d87cfd47}} + +\newcommand{\secpNHex} {\texttt{0x\,fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f}} +\newcommand{\secpNHexHi} {\texttt{0x\,ffffffffffffffffffffffffffffffff}} +\newcommand{\secpNHexLo} {\texttt{0x\,fffffffffffffffffffffffefffffc2f}} + +% Recently added columns +\newcommand{\isSmallPoint} {\col{IS\_SMALL\_POINT}} +\newcommand{\isLargePoint} {\col{IS\_LARGE\_POINT}} + +\newcol{\membershipTestRequired} {G2MTR}{G2\_MEMBERSHIP\_TEST\_REQUIRED} +\newcol{\acceptablePairOfPoints} {ACCPC}{ACCEPTABLE\_PAIR\_OF\_POINTS\_FOR\_PAIRING\_CIRCUIT} +\newcol{\csEcrecover} {CS\_ECRECOVER}{CIRCUIT\_SELECTOR\_ECRECOVER} +\newcol{\csEcadd} {CS\_ECADD}{CIRCUIT\_SELECTOR\_ECADD} +\newcol{\csEcmul} {CS\_ECMUL}{CIRCUIT\_SELECTOR\_ECMUL} +\newcol{\csEcpairing} {CS\_ECPAIRING}{CIRCUIT\_SELECTOR\_ECPAIRING} +\newcol{\csGTwo} {CS\_G2\_MEMBERSHIP}{CIRCUIT\_SELECTOR\_G2\_MEMBERSHIP} +\newcol{\trivialPairing} {TRIVIAL\_PAIRING}{OVERALL\_TRIVIAL\_PAIRING} + +% System of constraints +\newcommand{\callCOneMembership} {\texttt{callToC1Membership}} + +\newcommand{\callToCOneMembership}[6]{ + \callCOneMembership_{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{First argument (high):} & \col{#3} \\ + \utt{First argument (low):} & \col{#4} \\ + \utt{Second argument (high):} & \col{#5} \\ + \utt{Second argument (low):} & \col{#6} \\ + \end{array} \right]} + +\newcommand{\callCOneMembershipWCP} {\texttt{callToC1MembershipWCP}} + +\newcommand{\callToCOneMembershipWCP}[6]{ + \callCOneMembershipWCP_{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{First argument (high):} & \col{#3} \\ + \utt{First argument (low):} & \col{#4} \\ + \utt{Second argument (high):} & \col{#5} \\ + \utt{Second argument (low):} & \col{#6} \\ + \end{array} \right]} + +\newcommand{\callCOneMembershipEXT} {\texttt{callToC1MembershipEXT}} + +\newcommand{\callToCOneMembershipEXT}[6]{ + \callCOneMembershipEXT_{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{First argument (high):} & \col{#3} \\ + \utt{First argument (low):} & \col{#4} \\ + \utt{Second argument (high):} & \col{#5} \\ + \utt{Second argument (low):} & \col{#6} \\ + \end{array} \right]} + +\newcommand{\callWellFormedCoordinates} {\texttt{callToWellFormedCoordinates}} + +\newcommand{\callToWellFormedCoordinates}[9]{ % TODO: a standard macro cannot have more than 9 arguments, thus here 'i' is hardcoded: use xkeyval + \callWellFormedCoordinates_{i} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #1 \\ + \utt{First argument (high):} & \col{#2} \\ + \utt{First argument (low):} & \col{#3} \\ + \utt{Second argument (high):} & \col{#4} \\ + \utt{Second argument (low):} & \col{#5} \\ + \utt{Third argument (high):} & \col{#6} \\ + \utt{Third argument (low):} & \col{#7} \\ + \utt{Fourth argument (high):} & \col{#8} \\ + \utt{Fourth argument (low):} & \col{#9} \\ + \end{array} \right]} + +% base 10 : 21888242871839275222246405745257275088696311157297823662689037894645226208583 +% base 16 : 30644E72E131A029B85045B68181585D97816A916871CA8D3C208C16D87CFD47 +% high part : 30644e72e131a029b85045b68181585d +% low part : 97816a916871ca8d3c208c16d87cfd47 +\newcommand{\ttx} {\texttt{x}} +\newcommand{\tty} {\texttt{y}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +\newcommand{\PRECOMPILESUCCEDES} {\col{PRECOMPILE\_SUCCEDES}} +\newcommand{\precompileSuccedes} {\col{PREC\_SUCC}} +\newcommand{\PRECOMPILEPROVIDESRETURNDATA} {\col{PRECOMPILE\_PROVIDES\_RETURNDATA}} +\newcommand{\precompileProvidesReturndata} {\col{PREC\_PRVD}} +\newcommand{\PRECOMPILETOUCHESRAM} {\col{PRECOMPILE\_TOUCHES\_RAM}} +\newcommand{\precompileTouchesRam} {\col{PREC\_TCHR}} +\newcommand{\PRECOMPILERDS} {\col{PRECCOMPILE\_RETURNDATASIZE}} +\newcommand{\precompileRds} {\col{PREC\_RDS}} + +\newcommand{\sendToRamSum} {\miscSignifier\col{MMU\_INST\_SUM}} % weighted sum of the RAM instruction flag for CALLs +\newcommand{\sendToRam} {\miscSignifier\col{MMU\_INST}} % binary column which indicates which rows contain RAM instructions + + +% obsolete ? +\newcommand{\mmuInstInstruction} {\miscSignifier\mmuMod\col{/INST}} +\newcommand{\mmuInstRamToRam} {\texttt{RamToRam}} +\newcommand{\mmuInstRamToExo} {\texttt{RamToExo}} +\newcommand{\mmuInstExoToRam} {\texttt{ExoToRam}} +\newcommand{\mmuInstStkToRam} {\texttt{StkToRam}} +\newcommand{\mmuInstRamToStk} {\texttt{RamToStk}} +\newcommand{\mmuInstSrcOffset} {\miscSignifier\mmuMod\col{/SOURCE\_OFFSET}} +\newcommand{\mmuInstSrcSize} {\miscSignifier\mmuMod\col{/SOURCE\_SIZE}} +\newcommand{\mmuInstTgtOffset} {\miscSignifier\mmuMod\col{/TARGET\_OFFSET}} +\newcommand{\mmuInstTgtSize} {\miscSignifier\mmuMod\col{/TARGET\_SIZE}} +\newcommand{\mmuInstPadBynd} {\miscSignifier\mmuMod\col{/PAD\_BYND}} +\newcommand{\mmuInstPadUpTo} {\miscSignifier\mmuMod\col{/PAD\_UPTO}} +\newcommand{\mmuInstStamp} {\miscSignifier\mmuMod\col{/STAMP}} +\newcommand{\mmuInstWeightedExoSum} {\miscSignifier\mmuMod\col{/WEIGHTED\_EXO\_FLAG\_SUM}} +\newcommand{\mmuInstCnS} {\miscSignifier\mmuMod\col{/CN\_S}} +\newcommand{\mmuInstCnT} {\miscSignifier\mmuMod\col{/CN\_T}} +\newcommand{\mmuInstRefSize} {\miscSignifier\mmuMod\col{/REF\_SIZE}} +\newcommand{\mmuInstExoIsROM} {\texttt{exoIsROM}} +\newcommand{\mmuInstExoIsTXCD} {\texttt{exoIsTXCD}} +\newcommand{\mmuInstExoIsLOG} {\texttt{exoIsLOGDATA}} +\newcommand{\mmuInstExoIsKECData} {\texttt{exoIsKECDATA}} +\newcommand{\mmuInstExoIsKECInfo} {\texttt{exoIsKECINFO}} +\newcommand{\mmuInstExoIsECData} {\texttt{exoIsECDATA}} +\newcommand{\mmuInstExoIsEXPMODData} {\texttt{exoIsEXPMODDATA}} +\newcommand{\mmuInstExoIsSHAData} {\texttt{exoIsSHA2DATA}} +\newcommand{\mmuInstExoIsSHAInfo} {\texttt{exoIsSHA2INFO}} +\newcommand{\mmuInstExoIsBLAKE} {\texttt{exoIsBLAKE}} +\newcommand{\mmuInstExoIsRIPEMDInfo} {\texttt{exoIsRIPEMDDATA}} +\newcommand{\mmuInstExoIsRIPEMDData} {\texttt{exoIsRIPEMDINFO}} +\newcommand{\mmuInstExoModuleIds} {\col{MMU\_EXO\_MODULE\_ID\_SUM}} +\newcommand{\mmuInstExoModuleStamp} {\col{MMU\_EXO\_MODULE\_STAMP}} + +% PRECOMPILE_INFO + +\newcommand{\counter} {\col{COUNTER}} + +\newcommand{\ceil}[1] {\left\lceil #1 \right\rceil} +\newcommand{\floor}[1] {\left\lfloor #1 \right\rfloor} + +\newcommand{\shaTwo} {\col{SHA2}\flag} +\newcommand{\ripemd} {\col{RIPEMD}\flag} +\newcommand{\identity} {\col{IDENTITY}\flag} +\newcommand{\modexp} {\col{MODEXP}\flag} +\newcommand{\blake} {\col{BLAKE2f}\flag} +\newcommand{\gasReturned} {\col{GAS\_RETURNED}} +\newcommand{\callDataSize} {\col{CALL\_DATA\_SIZE}} +\newcommand{\returnDataSize} {\col{RETURN\_DATA\_SIZE}} +\newcommand{\pairingCount} {\col{PAIRING\_COUNT}} +\newcommand{\modexpParams} {\col{MODEXP\_PARAMS}} +\newcommand{\blakeF} {\col{BLAKE\_f}} +\newcommand{\blakeR} {\col{BLAKE\_r}} +% \newcommand{\consumedGas} {\col{EXEC\_COST}} +\newcommand{\executionCost} {\col{EXEC\_COST}} +\newcommand{\success} {\col{SUCCESS}} +\newcommand{\providesReturnData} {\col{PROVIDES\_RETURN\_DATA}} +\newcommand{\touchesRam} {\col{TOUCHES\_RAM}} +\newcommand{\malformedData} {\col{MALFORMED\_DATA}} +\newcommand{\enoughGas} {\col{ENOUGH\_GAS}} +\newcommand{\callDataWords} {\col{CALL\_DATA\_WORDS}} +\newcommand{\ecDataChecksPassed} {\col{EC\_DATA\_CHECKS\_PASSED}} +\newcommand{\modexpBytes} {\col{MODEXP\_BYTES}} +\newcommand{\modexpByteAcc} {\col{MODEXP\_BYTE\_ACC}} +\newcommand{\modexpByteSwitch} {\col{MODEXP\_BYTE\_SWITCH}} +\newcommand{\modexpByteSwitchIndex} {\col{MODEXP\_BYTE\_SWITCH\_INDEX}} +\newcommand{\modexpELeadingWordFirstByte} {\col{MODEXP\_E\_LEADING\_WORD\_FIRST\_BYTE}} +\newcommand{\modexpBits} {\col{MODEXP\_BITS}} +\newcommand{\modexpBitAcc} {\col{MODEXP\_BIT\_ACC}} +\newcommand{\modexpBitSwitch} {\col{MODEXP\_BIT\_SWITCH}} +\newcommand{\modexpBitSwitchIndex} {\col{MODEXP\_BIT\_SWITCH\_INDEX}} +\newcommand{\modexpELeadingWordBitLength} {\col{MODEXP\_E\_LEADING\_WORD\_BIT\_LENGTH}} +\newcommand{\modexpELeadingWordLog} {\col{MODEXP\_E\_LEADING\_WORD\_LOG}} +\newcommand{\modexpLEPrime} {\col{MODEXP\_LE\_PRIME}} +\newcommand{\modexpMaxLEPrimeAndOne} {\col{MODEXP\_MAX\_LE\_PRIME\_AND\_1}} +\newcommand{\modexpBigFraction} {\col{MODEXP\_BIG\_FRACTION}} +\newcommand{\ecdsaRecoverWorked} {\col{ECDSA\_RECOVER\_WORKED}} +\newcommand{\requiresEcData} {\col{REQUIRES\_EC\_DATA}} + +\newcommand{\modArgOneLo} {\col{MOD\_ARG1\_LO}} +\newcommand{\modArgTwoLo} {\col{MOD\_ARG2\_LO}} +\newcommand{\modRes} {\col{MOD\_RES}} + +\newcommand{\GQuadDivisor} {G_{\text{quaddivisor}}} +\newcommand{\GQuadDivisorValue} {3} +\newcommand{\cycleModexp} {\redm{15}} +\newcommand{\cycleNotModexp} {\redm{3}} +\newcommand{\weightedPhaseFlagSum} {\col{phase\_sum}} +\newcommand{\indexMaxFlagSum} {\col{index\_max\_sum}} +\newcommand{\flagSum} {\col{flag\_sum}} +\newcommand{\weightedFlagSum} {\col{wght\_sum}} +\newcommand{\weightedFlagSumInst} {\weightedFlagSum\col{\_inst}} +\newcommand{\weightedPrcFlagSum} {\weightedFlagSum\col{\_prc}} +\newcommand{\weightedPrcFlagSumCommon} {\weightedPrcFlagSum\col{\_common}} +\newcommand{\weightedPrcFlagSumBlake} {\weightedPrcFlagSum\col{\_blake}} +\newcommand{\weightedPrcFlagSumModexp} {\weightedPrcFlagSum\col{\_modexp}} +\newcommand{\maxCtFlagSum} {\col{ct\_max\_sum}} +\newcommand{\maxCtFlagSumInst} {\maxCtFlagSum\col{\_inst}} +\newcommand{\maxCtFlagSumPrc} {\maxCtFlagSum\col{\_prc}} +\newcommand{\maxCtFlagSumPrcCommon} {\maxCtFlagSumPrc\col{\_common}} +\newcommand{\maxCtFlagSumPrcBlake} {\maxCtFlagSumPrc\col{\_blake}} +\newcommand{\maxCtFlagSumPrcModexp} {\maxCtFlagSumPrc\col{\_modexp}} diff --git a/pkg/public.sty b/pkg/public.sty new file mode 100644 index 0000000..6090903 --- /dev/null +++ b/pkg/public.sty @@ -0,0 +1,28 @@ +% \newcommand{}{\col{}} + +\newcommand{\EXOSTAMP}{\col{EXO\_STAMP}} +\newcommand{\exoStamp}{\stampCol{\col{EXO}}} +\newcommand{\logNum}{\col{LOG\#}} +\newcommand{\shaNum}{\col{SHA\#}} +\newcommand{\initNum}{\col{INIT\#}} +\newcommand{\iNum}{\imported{\#}} + +% \renewcommand{\iAddr}{\imported{\addr}} +\newcommand{\txCdSize}{\col{TXCD\_SIZE}} +\newcommand{\txcdGasCost}{\col{TXCD\_GASCOST}} +\newcommand{\RUNTOT}{\col{RUNNING\_TOTAL}} +\newcommand{\runTot}{\col{RTOT}} +\newcommand{\GASTOT}{\col{TOTAL\_GAS}} +\newcommand{\gasTot}{\col{TOTG}} +\newcommand{\BYTEINDEX}{\col{BYTE\_INDEX}} +\newcommand{\byteIndex}{\col{BIX}} +\newcommand{\LIMBINDEX}{\col{LIMB\_INDEX}} +\newcommand{\limbIndex}{\col{LIX}} +\newcommand{\ISB}{\col{IS\_TXCD\_BYTE}} +\newcommand{\isb}{\col{ISB}} +\newcommand{\gnz}{G_{\text{nz}}} +\newcommand{\gz}{G_{\text{z}}} +% \newcommand{}{\col{}} +% \newcommand{}{\col{}} +% \newcommand{}{\col{}} +% \newcommand{}{\col{}} \ No newline at end of file diff --git a/pkg/ram.sty b/pkg/ram.sty new file mode 100644 index 0000000..eb38d04 --- /dev/null +++ b/pkg/ram.sty @@ -0,0 +1,396 @@ +\def\ramCol{solarized-blue} +\def\romCol{solarized-green} +\def\stackCol{solarized-yellow} +\def\logCol{solarized-magenta} +\def\txcdCol{solarized-orange} +\def\shaCol{solarized-cyan} + +\newcommand{\mmioInst} {\col{MMIO\_INSTRUCTION}} + +% aggregated contexts +\newcommand{\CNABC}{\col{CONTEXT\_ABC}} +\newcommand{\cnABC}{\col{CN\_ABC}} + +% individual contexts +\newcommand{\CNA}{\col{CONTEXT\_A}} +\newcommand{\cnA}{\col{CN\_A}} +\newcommand{\CNB}{\col{CONTEXT\_B}} +\newcommand{\cnB}{\col{CN\_B}} +\newcommand{\CNC}{\col{CONTEXT\_C}} +\newcommand{\cnC}{\col{CN\_C}} +%\newcommand{\iCNS}{\imported{\col{CONTEXT\_SOURCE}}} +%\newcommand{\iCnS}{\imported{\col{CN\_S}}} +%\newcommand{\iCNT}{\imported{\col{CONTEXT\_TARGET}}} +%\newcommand{\iCnT}{\imported{\col{CN\_T}}} + +\newcommand{\LOA}{\col{LIMB\_OFFSET\_A}} +\newcommand{\loA}{\col{LO\_A}} +\newcommand{\VALA}{\col{VALUE\_A}} +\newcommand{\VALANEW}{\col{VALUE\_A\_NEW}} +\newcommand{\valA}{\col{VAL\_A}} +\newcommand{\BYTEA}{\col{BYTE\_A}} +\newcommand{\byteA}{\col{BYTE\_A}} + + +\newcommand{\LOB}{\col{LIMB\_OFFSET\_B}} +\newcommand{\loB}{\col{LO\_B}} +\newcommand{\VALB}{\col{VALUE\_B}} +\newcommand{\VALBNEW}{\col{VALUE\_B\_NEW}} +\newcommand{\valB}{\col{VAL\_B}} +\newcommand{\BYTEB}{\col{BYTE\_B}} +\newcommand{\byteB}{\col{BYTE\_B}} + + +\newcommand{\LOC}{\col{LIMB\_OFFSET\_C}} +\newcommand{\loC}{\col{LO\_C}} +\newcommand{\VALC}{\col{VALUE\_C}} +\newcommand{\VALCNEW}{\col{VALUE\_C\_NEW}} +\newcommand{\valC}{\col{VAL\_C}} +\newcommand{\BYTEC}{\col{BYTE\_C}} +\newcommand{\byteC}{\col{BYTE\_C}} + +\newcommand{\byteHi}{\col{BYTE\_HI}} +\newcommand{\byteLo}{\col{BYTE\_LO}} +\newcommand{\valX}{\col{VAL\_X}} +\newcommand{\iValX}{\imported{\valX}} +\newcommand{\byteX}{\col{BYTE\_X}} + +\newcommand{\byteLimb}{\col{BYTE\_LIMB}} + +\newcommand{\byteSValHi}{\col{BYTE\_V}\high} +\newcommand{\byteSValLo}{\col{BYTE\_V}\low} + +% +\newcommand{\valABC}{\col{VAL\_ABC}} + +% ramA +\newcommand{\ramA}{\col{RAM\_A}} +\newcommand{\ramAbyte}{\col{RAM\_A\_BYTE}} +\newcommand{\ramAacc}{\col{RAM\_A\_ACC}} +\newcommand{\ramAnew}{\col{RAM\_A\_NEW}} + +% ramB +\newcommand{\ramB}{\col{RAM\_B}} +\newcommand{\ramBbyte}{\col{RAM\_B\_BYTE}} +\newcommand{\ramBacc}{\col{RAM\_B\_ACC}} +\newcommand{\ramBnew}{\col{RAM\_B\_NEW}} + +% ramC +\newcommand{\ramC}{\col{RAM\_C}} +\newcommand{\ramCbyte}{\col{RAM\_C\_BYTE}} +\newcommand{\ramCacc}{\col{RAM\_C\_ACC}} +\newcommand{\ramCnew}{\col{RAM\_C\_NEW}} + +% concatenation +\newcommand{\ramABC}{\col{RAM\_ABC}} + +% limb offset in RAM are ``indices'' +\newcommand{\INDEX}{\col{INDEX}} +\renewcommand{\index}{\col{INDEX}} +\newcommand{\indexMax}{\col{INDEX\_MAX}} +\newcommand{\indexA}{\col{INDEX\_A}} +\newcommand{\indexB}{\col{INDEX\_B}} +\newcommand{\indexC}{\col{INDEX\_C}} +\newcommand{\indexABC}{\col{INDEX\_ABC}} + +%% instruction offsets +%\newcommand{\ISLO}{\imported{\SLO}} +%\newcommand{\iSlo}{\imported{\slo}} +%\newcommand{\ISBO}{\imported{\SBO}} +%\newcommand{\iSbo}{\imported{\sbo}} +% +%\newcommand{\ITLO}{\imported{\TLO}} +%\newcommand{\iTlo}{\imported{\tlo}} +%\newcommand{\ITBO}{\imported{\TBO}} +%\newcommand{\iTbo}{\imported{\tbo}} +%% +%\newcommand{\iSize}{\imported{\col{SIZE}}} + + +% limb offset in exodata +\newcommand{\indexX}{\col{INDEX\_X}} + +%% RAM stamp +%\newcommand{\STAMP}{\col{RAM\_TIMESTAMP}} +% \newcommand{\stampTre}{\stamp^{\cc3}} + +%% byte columns +%\newcommand{\byteU}{\col{B1}} % byte "un" +%\newcommand{\byteD}{\col{B2}} % byte "deux" +%\newcommand{\byteT}{\col{B3}} % byte "trois" +%\newcommand{\byteQ}{\col{B4}} % byte "quatre" + +%% remainder columns +%\renewcommand{\rem}{\col{REM\_}} % remainder +%\newcommand{\remU}{\col{REM\_1}} % imported remainder columns +%\newcommand{\remD}{\col{REM\_2}} % imported remainder columns +%\newcommand{\remT}{\col{REM\_3}} % imported remainder columns +%\newcommand{\remQ}{\col{REM\_4}} % imported remainder columns + +% indices +\newcommand{\IA}{\col{INDEX\_A}} +\newcommand{\ia}{\col{IA}} +\newcommand{\IB}{\col{INDEX\_B}} +\newcommand{\ib}{\col{IB}} +\newcommand{\IC}{\col{INDEX\_C}} +\newcommand{\ic}{\col{IC}} + +%% SC_NUMs +%% \newcommand{\CN}{\col{CONTEXT\_NUMBER}} % \geq 0, context ``number'' +%% \newcommand{\cn}{\col{CN}} +%\newcommand{\SCNCAL}{\col{SC\_NUMBER\_CALLER}} +%\newcommand{\scncal}{\col{SCN\_CALLER}} +%\newcommand{\SCNRET}{\col{SC\_NUMBER\_RETURNER}} +%\newcommand{\scnret}{\col{SCN\_RETURNER}} +%\newcommand{\SCNMAX}{\col{SC\_NUMBER\_MAX}} +%\newcommand{\scnmax}{\col{SCN\_MAX}} +%\newcommand{\SCNLR}{\col{SC\_NUMBER\_LEFT\_RIGHT}} +%\newcommand{\scnlr}{\col{SCN\_LR}} +%\newcommand{\SCNOTH}{\col{SC\_NUMBER\_OTHER}} +%\newcommand{\scnoth}{\col{SCN\_O}} +%% +%\newcommand{\SCNABC}{\col{SC\_NUMBER\_ABC}} +%\newcommand{\scnAB}{\col{SCN\_AB}} +%\newcommand{\scnC}{\col{SCN\_C}} +%\newcommand{\scnABC}{\col{SCN\_ABC}} + +%% Exo High +%\newcommand{\XHI}{\col{EXO\HIGH}} +%\newcommand{\xhi}{\col{X}\high} +% +%\newcommand{\XHIB}{\col{EXO\HIGH\_BYTE}} +%\newcommand{\xhib}{\col{XB}\high} +% +%\newcommand{\XHIA}{\col{EXO\HIGH\_ACC}} +%\newcommand{\xhia}{\col{XA}\high} +% +%% Exo Low +%\newcommand{\XLO}{\col{EXO\LOW}} +%\newcommand{\xlo}{\col{X}\low} +% +%\newcommand{\XLOB}{\col{EXO\LOW\_BYTE}} +%\newcommand{\xlob}{\col{XB}\low} +% +%\newcommand{\XLOA}{\col{EXO\LOW\_ACC}} +%\newcommand{\xloa}{\col{XA}\low} + +% markers +\newcommand{\markL}{\col{MARK\_L}} +\newcommand{\markR}{\col{MARK\_R}} +\newcommand{\markO}{\col{MARK\_O}} +\newcommand{\markXhi}{\col{MARK\_X}\high} +\newcommand{\markXlo}{\col{MARK\_X}\low} + +%% imported offsets +% \newcommand{\SLO}{\col{SOURCE\_LIMB\_OFFSET}} +% \newcommand{\slo}{\col{SLO}} +% \newcommand{\SBO}{\col{SOURCE\_BYTE\_OFFSET}} +% \newcommand{\sbo}{\col{SBO}} +% \newcommand{\TLO}{\col{TARGET\_LIMB\_OFFSET}} +% \newcommand{\tlo}{\col{TLO}} +% \newcommand{\TBO}{\col{TARGET\_BYTE\_OFFSET}} +% \newcommand{\tbo}{\col{TBO}} + +%% Transaction number +%\newcommand{\TXN}{\col{TRANSACTION\_NUMBER}} +%\newcommand{\txn}{\col{TXNUM}} + +%% padded transaction call data +%\newcommand{\TXCD}{\col{TRANSACTION\_CALLDATA\_PADDED}} +%\newcommand{\txcd}{\col{TXCD}} + +%% initialization code +%\newcommand{\INITCODE}{\col{INITIALIZATION\_CODE}} +%\newcommand{\initcode}{\col{INITCODE}} +%\newcommand{\isInit}{\col{IS\_INIT}} + +% binary columns +\newcommand{\BITS}{\col{BITS}} +\newcommand{\bits}{\col{BITS}} +%\newcommand{\iFastOp}{\imported{\fastOp}} + +\newcommand{\CDO}{\col{CALL\_DATA\_OFFSET}} % offset in the caller's RAM +\newcommand{\cdo}{\col{CDO}} +\newcommand{\CDS}{\col{CALL\_DATA\_SIZE}} +\newcommand{\cds}{\col{CDS}} +\newcommand{\RAO}{\col{RETURN\_AT\_OFFSET}} % offset in the returner's RAM +\newcommand{\rao}{\col{R@O}} +\newcommand{\RAC}{\col{RETURN\_AT\_CAPACITY}} +\newcommand{\rac}{\col{R@C}} +% +\newcommand{\RDO}{\col{RETURN\_DATA\_OFFSET}} % offset in the returner's RAM +\newcommand{\rdo}{\col{RDO}} +\newcommand{\RDS}{\col{RETURN\_DATA\_SIZE}} +\newcommand{\rds}{\col{RDS}} + +\newcommand{\CSD}{\col{CALLSTACK\_DEPTH}} +\newcommand{\csd}{\col{CSD}} + +%% stack +%\newcommand{\STACK}{\col{STACK\_VALUE}} +%\newcommand{\stack}{\col{VAL\_S}} + +%% transaction call data flag +%\newcommand{\TXCDF}{\col{TX\_CALLDATA\_FLAG}} % signals acces to transaction CALLDATA +%\newcommand{\txcdf}{\col{TXCDF}} +%\newcommand{\TXCDVF}{\col{TX\_CALLDATA\_VETTING\_FLAG}} +%\newcommand{\txcdvf}{\col{TXCDVF}} +%\newcommand{\txcdfAB}{\col{TXCDF\_AB}} +%\newcommand{\txcdfC}{\col{TXCDF\_C}} +%\newcommand{\txcdfABC}{\col{TXCDF\_ABC}} + +%% instruction decoded flags +%\newcommand{\WTC}{\col{WRITE\_TO\_CURRENT}} +%\newcommand{\wtc}{\col{WTC}} +%\newcommand{\BSF}{\col{BULLSHIT\_FLAG}} +%\newcommand{\bsf}{\col{BSF}} + +%% Stack/RAM instructions +%\newcommand{\stackF}{\col{STACK\_FLAG}} +%% RAM/RAM instructions +%\newcommand{\ramF}{\col{RAM\_FLAG}} +%% ROM/RAM instructions +%\newcommand{\romF}{\col{ROM\_FLAG}} +%% Log/RAM instructions +%\newcommand{\logF}{\col{LOG\_FLAG}} +% +%\newcommand{\XROM}{\col{EXO\_IS\_ROM}} +%\newcommand{\xRom}{\col{X\_ROM}} +%\newcommand{\iXROM}{\imported{\XROM}} +%\newcommand{\ixRom}{\imported{\xRom}} +%% +%\newcommand{\XLOG}{\col{EXO\_IS\_LOG}} +%\newcommand{\xLog}{\col{X\_LOG}} +%\newcommand{\iXLOG}{\imported{\XLOG}} +%\newcommand{\ixLog}{\imported{\xLog}} +%% +%\newcommand{\XSHA}{\col{EXO\_IS\_SHA3}} +%\newcommand{\xSha}{\col{X\_SHA3}} +%\newcommand{\iXSHA}{\imported{\XSHA}} +%\newcommand{\ixSha}{\imported{\xSha}} +%% +%\newcommand{\iTXCD}{\col{EXO\_IS\_TXCD}} +%\newcommand{\xTxcd}{\col{X\_TXCD}} +%\newcommand{\iXTXCD}{\imported{\iTXCD}} +%\newcommand{\ixTxcd}{\imported{\xTxcd}} +%% +%\newcommand{\XDEP}{\col{EXO\_IS\_DEP}} +%\newcommand{\xDep}{\col{X\_DEP}} +%\newcommand{\iXDEP}{\imported{\XDEP}} +%\newcommand{\ixDep}{\imported{\xDep}} +% + +%% call instructions +%\newcommand{\callF}{\col{CALL\_FLAG}} +%% size instructions CALLDATASIZE, RETURNDATASIZE and maybe MSIZE ... +%\newcommand{\sizeF}{\col{SIZE\_FLAG}} +%% \newcommand{}{\col{}} + +%\newcommand{\limbOffset}{\col{LIMB\_OFFSET}} +%\newcommand{\LIMB}{\col{LIMB\_}} + +\newcommand{\pow}[1]{\col{POW\_256\_#1}} % we need 2 of these + +% elementary sugeries +\newcommand{\compSuffix}{\texttt{IsolateSuffix}} +\newcommand{\compPrefix}{\texttt{IsolatePrefix}} +\newcommand{\compChunk}{\texttt{IsolateChunk}} +\newcommand{\plateau}{\texttt{Plateau}} +\newcommand{\power}{\texttt{Power}} +\newcommand{\antiPower}{\texttt{antiPower}} +\newcommand{\byteSwap}{\texttt{ByteSwap}} +\DeclareMathOperator{\oneToOnePadded}{\mathtt{[1\Rightarrow1\,Padded]}} +\DeclareMathOperator{\twoToOnePadded}{\mathtt{[2\Rightarrow1\,Padded]}} +\DeclareMathOperator{\onePartialToOne}{\mathtt{[1\,Partial\Rightarrow1]}} +\DeclareMathOperator{\onePartialToTwo}{\mathtt{[1\,Partial\Rightarrow2]}} +\DeclareMathOperator{\twoPartialToOne}{\mathtt{[2\,Partial\Rightarrow1]}} +\DeclareMathOperator{\twoToOneFull}{\mathtt{[2\Rightarrow 1\,Full]}} +\DeclareMathOperator{\readFromExo}{\texttt{ReadFromExo}} +\newcommand{\byteDec}{\texttt{ByteDec}} +\DeclareMathOperator{\oneFullToTwo}{\mathtt{[1\,Full\Rightarrow2]}} +\DeclareMathOperator{\twoFullToThree}{\mathtt{[2\,Full\Rightarrow 3]}} +\DeclareMathOperator{\threeToTwoFull}{\mathtt{[3\Rightarrow2\,Full]}} + +% limb surgeries +\newcommand{\excision}{\texttt{Excision}} +\newcommand{\RamLimbExcision}{\texttt{RamLimbExcision}} +% \DeclareMathOperator{\mstore}{\texttt{MStore}} +% \DeclareMathOperator{\mstoreEight}{\texttt{MStore8}} +\newcommand{\RamToRamSlideChunk}{\texttt{RamToRamSlideChunk}} +\newcommand{\ExoToRamSlideChunk}{\texttt{ExoToRamSlideChunk}} +\newcommand{\RamToRamSlideOverlappingChunk}{\texttt{RamToRamSlideOverlappingChunk}} +\newcommand{\ExoToRamSlideOverlappingChunk}{\texttt{ExoToRamSlideOverlappingChunk}} +\newcommand{\PaddedExoFromOne}{\texttt{PaddedExoFromOne}} +\newcommand{\PaddedExoFromTwo}{\texttt{PaddedExoFromTwo}} +\newcommand{\FullExoFromTwo}{\texttt{FullExoFromTwo}} +\newcommand{\FullStackToRAM}{\texttt{FullStackToRAM}} +\newcommand{\lsbFromStackToRAM}{\texttt{LsbFromStackToRAM}} +\newcommand{\firstFastSecondPadded}{\texttt{FirstFastSecondPadded}} +\newcommand{\firstPaddedSecondZero}{\texttt{FirstPaddedSecondZero}} +% +\newcommand{\exceptionalThreeRamToStack}{\texttt{Exceptional\_RamToStack\_3To2Full}} +\newcommand{\exceptionalThreeRamToStackFast}{\texttt{Exceptional\_RamToStack\_3To2Full\_Fast}} +% +\newcommand{\nonAlignedRamToStackOne}{\texttt{NA\_RamToStack\_3To2Full}} +\newcommand{\nonAlignedRamToStackTwo}{\texttt{NA\_RamToStack\_3To2Padded}} +\newcommand{\nonAlignedRamToStackTre}{\texttt{NA\_RamToStack\_2To2Padded}} +\newcommand{\nonAlignedRamToStackFou}{\texttt{NA\_RamToStack\_2To1FullAndZero}} +\newcommand{\nonAlignedRamToStackFiv}{\texttt{NA\_RamToStack\_2To1PaddedAndZero}} +\newcommand{\nonAlignedRamToStackSix}{\texttt{NA\_RamToStack\_1To1PaddedAndZero}} + + +\newcommand{\source}{\col{S}} +\newcommand{\sourceOne}{\col{S1}} +\newcommand{\sourceTwo}{\col{S2}} +\newcommand{\sourceTre}{\col{S3}} +\newcommand{\target}{\col{T}} +\newcommand{\targetOne}{\col{T1}} +\newcommand{\targetTwo}{\col{T2}} +\newcommand{\targetTre}{\col{T3}} + + +\renewcommand{\mark}{\col{M}} +\newcommand{\byte}{\col{B}} +\newcommand{\cur}{^{\relof}} +\newcommand{\new}{^{\nu}} +\newcommand{\oldd}{^{\omega}} +\newcommand{\rrefund}{^{\rho}} +\newcommand{\Endowment}{^\varepsilon} + +%% exo column interpretations +%% rom +%% logs +%\newcommand{\exoLog}{\col{LOG}} +%\newcommand{\exoLogNum}{\col{LOG\_NUM}} % counts the logs :) counter += 1 with every log +%\newcommand{\exoLogIndex}{\col{LOG\_INDEX}} % for the log table, row index of a log +%% stack +%\newcommand{\exoVal}{\col{VAL}} % stack value high +%\newcommand{\exoOffset}{\col{OFFSET}} +%\newcommand{\exoRetOffset}{\col{RET\_OFFSET}} +%\newcommand{\exoRetSize}{\col{RET\_SIZE}} +%% parent ram columns +\newcommand{\val}{\col{VALUE}} +\newcommand{\size}{\col{SIZE}} +%\newcommand{\OFF}{\col{OFFSET}} +%\newcommand{\off}{\col{OFF}} +\newcommand{\offset}{\col{OFFSET}} +%% +%\newcommand{\ROFF}{\col{RETURN\_OFFSET}} +%\newcommand{\roff}{\col{ROFF}} +%\newcommand{\RS}{\col{RETURN\_SIZE}} +%\newcommand{\rs}{\col{RSIZE}} +%% +%\newcommand{\Lmb}{^\col{limb}} +%\newcommand{\Int}{^\col{int}} +% +\newcommand{\MST}{\imported{\col{MICRO\_RAM\_STAMP}}} +\newcommand{\mst}{\imported{\mu\col{RST}}} +%\newcommand{\RST}{\imported{\col{RAM\_STAMP}}} +%\newcommand{\rst}{\imported{\col{RST}}} +%\newcommand{\IMICROINST}{\imported{\MICROINST}} +%\newcommand{\iMicroInst}{\imported{\microInst}} +% +%\newcommand{\surgery}{\col{SURGERY}} + +\newcommand{\fromLU}{\texttt{}} +\newcommand{\TBA}{\graym{to\_be\_announced}} diff --git a/pkg/ram_fig.sty b/pkg/ram_fig.sty new file mode 100644 index 0000000..35ca0a4 --- /dev/null +++ b/pkg/ram_fig.sty @@ -0,0 +1,24 @@ +\def\hori{16} +\def\offone{11} +\def\offtwo{5} +\def\verti{1.3} +\def\rowsep{5} +\def\xtra{0.33} +\def\xxtra{0.67} +\def\hxtra{0.5} +\def\vxtra{0.2} +\newcommand{\boxx}[2]{% + \draw[fill = #2] + #1 + -- coordinate (top) ++ (\hori, 0) + -- ++ (0, -\verti) + -- coordinate (bot) ++ (-\hori, 0) + -- cycle; +} +\newcommand{\fboxx}[3]{% x, delta, color + \draw[fill=#3] + #1 -- ++ (#2, 0) + -- ++ (0, -\verti) + -- ++ (-#2, 0) + -- cycle; +} \ No newline at end of file diff --git a/pkg/rlp_addr.sty b/pkg/rlp_addr.sty new file mode 100644 index 0000000..3865032 --- /dev/null +++ b/pkg/rlp_addr.sty @@ -0,0 +1,10 @@ +\newcommand{\kec} {\col{KEC}} +\newcommand{\recipe}[1] {\col{RECIPE\_#1}} +\newcommand{\rlpAddrInst} {\col{RECIPE}} +\newcommand{\TINYNONZERONONCE} {\col{TINY\_NONZERO\_NONCE}} +\newcommand{\tinyNonzeroNonce} {\col{TNZN}} +% Number +\newcommand{\mediumPO} {\redm{7}} % mediumness plus one + +\newcommand{\addressCreationRecipeConstantStd} {\red{[\![\texttt{RECIPE\_1}]\!]}} +\newcommand{\addressCreationRecipeConstantTwo} {\red{[\![\texttt{RECIPE\_2}]\!]}} diff --git a/pkg/rlp_log.sty b/pkg/rlp_log.sty new file mode 100644 index 0000000..2f510b6 --- /dev/null +++ b/pkg/rlp_log.sty @@ -0,0 +1,25 @@ +\newcommand{\Done}{\col{DONE}} +\newcommand{\isOt}{\col{IS\_TOPIC}} +\newcommand{\isOd}{\col{IS\_DATA}} +\newcommand{\logsize}{\col{TXRCPT\_SIZE}} +\newcommand{\logentrysize}{\col{LOG\_ENTRY\_SIZE}} +\newcommand{\localsize}{\col{LOCAL\_SIZE}} +\newcommand{\indexlocal}{\col{INDEX\_LOCAL}} +\newcommand{\absTxNumInfty}{\col{ABS\_TX\_NUM\_MAX}} + +% Special numbers: +\newcommand{\subPhaseIdType}{\red{7}} +\newcommand{\subPhaseIdStatusCode}{\red{2}} +\newcommand{\subPhaseIdCumulGas}{\red{3}} +\newcommand{\subPhaseIdNoLogEntry}{\red{11}} +\newcommand{\subPhaseIdAddr}{\red{53}} +\newcommand{\subPhaseIdTopicBase}{\red{65}} +\newcommand{\subPhaseIdDataLimb}{\red{77}} +\newcommand{\subPhaseIdDataSize}{\red{83}} +\newcommand{\subPhaseIdTopicDelta}{\red{96}} + +\newcommand{\subPhaseIdWeightIsPrefix}{\red{6}} +\newcommand{\subPhaseIdWeightIsOt}{\red{12}} +\newcommand{\subPhaseIdWeightIsOd}{\red{24}} +\newcommand{\subPhaseIdWeightDepth}{\red{48}} +\newcommand{\subPhaseIdWeightIndexLocal}{\red{96}} \ No newline at end of file diff --git a/pkg/rlp_patterns.sty b/pkg/rlp_patterns.sty new file mode 100644 index 0000000..133428e --- /dev/null +++ b/pkg/rlp_patterns.sty @@ -0,0 +1,8 @@ +\newcommand{\rlpPrefixInt} {\texttt{rlpPrefixInt}} +\newcommand{\rlpPrefixIntLong} {\texttt{rlpPrefixLongInt}} +\newcommand{\rlpPrefixByteString} {\texttt{rlpPrefixOfByteString}} +\newcommand{\rlpByteCounting} {\texttt{byteCountAndPower}} +\newcommand{\compareFiftyFive} {\texttt{compTo55}} +\newcommand{\fiftyFive} {\red{55}} +\newcommand{\Power}{\col{POWER}} +\newcommand{\limbShifting}{\texttt{limbShifting}} \ No newline at end of file diff --git a/pkg/rlp_tx.sty b/pkg/rlp_tx.sty new file mode 100644 index 0000000..905f308 --- /dev/null +++ b/pkg/rlp_tx.sty @@ -0,0 +1,71 @@ +%Column's names +\newcommand{\Depth} [1] {\col{DEPTH\_#1}} +\newcommand{\phase} [1] {\col{PHASE\_#1}} +\newcommand{\Phase} {\col{PHASE}} +\newcommand{\inputsize} {\col{INPUT1\_SIZE}} +\newcommand{\isprefix} {\col{IS\_PREFIX}} +\newcommand{\ispadding} {\col{LC\_CORRECTION}} +\newcommand{\nbstep} {\col{nSTEP}} +\renewcommand{\done} {\col{DONE}} +\newcommand{\limbsize} {\col{nBYTES}} +\newcommand{\nbAddr} {\col{nADDR}} +\newcommand{\nStorageKeysInAccessList} {\col{nKEYS}^\infty} +\newcommand{\nStorageKeysInAccessEntry} {\col{nKEYS}} +\newcommand{\lc} {\col{LC}} +\newcommand{\transactionType} {\col{TX\_TYPE}} +\newcommand{\phasend} {\col{PHASE\_END}} +\newcommand{\phasesize} {\col{PHASE\_SIZE}} +\newcommand{\lt} {\col{LT}} +\newcommand{\lx} {\col{LX}} +\newcommand{\indext} {\col{INDEX\_LT}} +\newcommand{\indexx} {\col{INDEX\_LX}} +\newcommand{\rlptsize} {\col{RLP\_LT\_BYTESIZE}} +\newcommand{\rlpxsize} {\col{RLP\_LX\_BYTESIZE}} +\newcommand{\accsize} {\col{ACC\_BYTESIZE}} +\newcommand{\indexData} {\col{INDEX\_DATA}} +\newcommand{\dataGasCost} {\col{DATA\_GAS\_COST}} +\newcommand{\toHashByProver} {\col{TO\_HASH\_BY\_PROVER}} + +% +\newcommand{\rlpTxnPhase } [1] {\redm{[\![\mathtt{\rlpTxnMod\_}\Phi\mathtt{\_#1}]\!]}} +% +\newcommand{\phaseRlpPrefixValue} {\rlpTxnPhase{rlp\_prefix}} +\newcommand{\phaseChainIdValue} {\rlpTxnPhase{chain\_id}} +\newcommand{\phaseNonceValue} {\rlpTxnPhase{nonce}} +\newcommand{\phaseGasPriceValue} {\rlpTxnPhase{gas\_price}} +\newcommand{\phaseMaxPriorityFeePerGasValue} {\rlpTxnPhase{max\_priority\_fee\_per\_gas}} +\newcommand{\phaseMaxFeePerGasValue} {\rlpTxnPhase{max\_fee\_per\_gas}} +\newcommand{\phaseGasLimitValue} {\rlpTxnPhase{gas\_limit}} +\newcommand{\phaseToValue} {\rlpTxnPhase{to}} +\newcommand{\phaseValueValue} {\rlpTxnPhase{value}} +\newcommand{\phaseDataValue} {\rlpTxnPhase{data}} +\newcommand{\phaseAccessListValue} {\rlpTxnPhase{access\_list}} +\newcommand{\phaseBetaValue} {\rlpTxnPhase{beta}} +\newcommand{\phaseYValue} {\rlpTxnPhase{y}} +\newcommand{\phaseRValue} {\rlpTxnPhase{r}} +\newcommand{\phaseSValue} {\rlpTxnPhase{s}} + + + +\newcommand{\phaseRlpPrefix} {\col{IS\_PHASE\_RLP\_PREFIX}} +\newcommand{\phaseChainId} {\col{IS\_PHASE\_CHAIN\_ID}} +\newcommand{\phaseNonce} {\col{IS\_PHASE\_NONCE}} +\newcommand{\phaseGasPrice} {\col{IS\_PHASE\_GAS\_PRICE}} +\newcommand{\phaseMaxPriorityFeePerGas} {\col{IS\_PHASE\_MAX\_PRIORITY\_FEE\_PER\_GAS}} +\newcommand{\phaseMaxFeePerGas} {\col{IS\_PHASE\_MAX\_FEE\_PER\_GAS}} +\newcommand{\phaseGasLimit} {\col{IS\_PHASE\_GAS\_LIMIT}} +\newcommand{\phaseTo} {\col{IS\_PHASE\_TO}} +\newcommand{\phaseValue} {\col{IS\_PHASE\_VALUE}} +\newcommand{\phaseData} {\col{IS\_PHASE\_DATA}} +\newcommand{\phaseAccessList} {\col{IS\_PHASE\_ACCESS\_LIST}} +\newcommand{\phaseBeta} {\col{IS\_PHASE\_BETA}} +\newcommand{\phaseY} {\col{IS\_PHASE\_Y}} +\newcommand{\phaseR} {\col{IS\_PHASE\_R}} +\newcommand{\phaseS} {\col{IS\_PHASE\_S}} + + +%Special RLP numbers +\newcommand{\rlprefixShortInt} {\redm{128}} % base RLP prefix of a short integer (<56 bytes long) +\newcommand{\rlprefixLongInt} {\redm{183}} % base RLP prefix of a long integer (>= 56 bytes long) +\newcommand{\rlprefixShortList} {\redm{192}} % base RLP prefix of a short list (<56 bytes long) +\newcommand{\rlprefixLongList} {\redm{247}} % base RLP prefix of a long list (>= 56 bytes long) diff --git a/pkg/rom.sty b/pkg/rom.sty new file mode 100644 index 0000000..5ca4dd4 --- /dev/null +++ b/pkg/rom.sty @@ -0,0 +1,116 @@ +% WORD COMPARISON module +\newcommand{\CT}{\col{COUNTER}} +\newcommand{\ct}{\col{CT}} +\newcommand{\maxCt}{\col{CT\_MAX}} + +\newcommand{\CS}{\col{CODESIZE}} +\newcommand{\cs}{\col{CS}} + +% \newcommand{\DCS}{\Delta\col{\_CODESIZE}} +% \newcommand{\dcs}{\Delta\col{\_CS}} + +\newcommand{\CH}{\col{CODEHASH}} +\newcommand{\ch}{\col{CH}} + +\newcommand{\CFI}{\col{CODE\_FRAGMENT\_INDEX}} +\newcommand{\cfi}{\col{CFI}} +\newcommand{\cfiMax}{\col{CFI}^\infty} + +\newcommand{\PBCB}{\col{PADDED\_BYTECODE\_BYTE}} +\newcommand{\pbcb}{\col{PBCB}} + +\newcommand{\opc}{\col{OPCODE}} +\newcommand{\pc}{\col{PC}} + +\newcommand{\CSR}{\col{CODESIZE\_REACHED}} +\newcommand{\csr}{\col{CSR}} + +\newcommand{\IBC}{\col{IS\_BYTECODE}} +\newcommand{\ibc}{\col{IBC}} + +\newcommand{\LSHH}{\col{LEFT\_ALIGNED\_CODESUFFIX}\HIGH} +\newcommand{\LSHL}{\col{LEFT\_ALIGNED\_CODESUFFIX}\LOW} +\newcommand{\lsh}{\col{LACS}} + +\newcommand{\ADDR}{\col{SC\_ADDRESS}} +\newcommand{\addr}{\col{ADDR}} +\newcommand{\iAddr}{\imported{\addr}} + +\newcommand{\INIT}{\col{IS\_INITCODE}} +\newcommand{\init}{\col{INIT}} + +\renewcommand{\DH}{\col{DO\_HASH}} +\renewcommand{\dh}{\col{DH}} + +\newcommand{\IPD}{\col{IS\_PUSH\_DATA}} +\newcommand{\ipd}{\col{IPD}} +\newcommand{\IPI}{\col{IS\_PUSH\_INSTRUCTION}} +\newcommand{\ipi}{\col{IPI}} + +\newcommand{\IL}{\col{IS\_LOADED}} +\newcommand{\LOAD}{\col{LOAD}} +\newcommand{\PADB}{\col{PADDING\_BIT}} +\newcommand{\padb}{\col{PAD}} + +% MET imported inputs +\newcommand{\addrh}{\col{ADDR}\high} +\newcommand{\addrl}{\col{ADDR}\low} +\newcommand{\addrHi}{\col{ADDR}\high} +\newcommand{\addrLo}{\col{ADDR}\low} +\newcommand{\keyh}{\col{KEY}\high} +\newcommand{\keyl}{\col{KEY}\low} + +% \newcommand{\DBZ}{\Delta\col{\_BYTE\_0}} +% \newcommand{\dbz}{\Delta\col{B0}} + +% \newcommand{\DBO}{\Delta\col{\_BYTE\_1}} +% \newcommand{\dbo}{\Delta\col{B1}} + +% \newcommand{\DPS}{\Delta\col{\_PUSH\_SPACE}} +% \newcommand{\dps}{\Delta\col{PS}} + +% push related +\newcommand{\PP}{\col{PUSH\_PARAMETER}} +\newcommand{\pp}{\col{PP}} + +\newcommand{\PV}{\col{PUSH\_VALUE}} +\newcommand{\pv}{\col{PV}} + +\newcommand{\IP}{\col{IS\_PUSH}} % TODO IS\_PUSH +\newcommand{\ip}{\col{IP}} + +\newcommand{\PPO}{\col{PUSH\_PARAMETER\_OFFSET}} % TODO PUSH\_PARAMETER\_OFFSET +\newcommand{\ppo}{\col{PPO}} + +\newcommand{\PVA}{\col{PUSH\_VALUE\_ACC}} % TODO PUSH\_VALUE\_AX/ACC, ax = x86 reg for accumulation, could be ACC too +\newcommand{\pva}{\col{PVA}} + +\newcommand{\PFB}{\col{PUSH\_FUNNEL\_BIT}} % TODO PUSH\_FUNNEL\_BIT +\newcommand{\pfb}{\col{PFB}} + +\newcommand{\INST}{\col{INST}} + +\newcommand{\HIGH}{\col{\_HIGH}} +\newcommand{\LOW}{\col{\_LOW}} +\newcommand{\high}{^\colm{\,hi}} +\newcommand{\low}{^\colm{\,lo}} + +\DeclareMathOperator{\cc}{\boxplus} % concatenation operator + +\newcommand{\hasinitcode}{\col{HAS\_INITCODE}} +\newcommand{\isinitcode}{\col{IS\_INITCODE}} +\newcommand{\deploymentSuccess}{\col{DEPLOYMENT\_SUCCESSFUL}} + +\newcommand{\ISVALIDJUMPDESTINATION}{\col{VALID\_JUMP\_DESTINATION}} +\newcommand{\isValidJumpDestination}{\col{VJD}} + +\newcommand{\CP}{\col{COUNTER\_PUSH}} +\newcommand{\cp}{\col{CP}} + +\newcommand{\ctMax}{\col{COUNTER\_MAX}} + + +\newcommand{\readFromState}{\col{READ\_FROM\_STATE}} +\newcommand{\commitToState}{\col{COMMIT\_TO\_STATE}} + +\newcommand{\nBytesAcc}{\col{nBYTES\_ACC}} diff --git a/pkg/scenario.sty b/pkg/scenario.sty new file mode 100644 index 0000000..ba24861 --- /dev/null +++ b/pkg/scenario.sty @@ -0,0 +1,312 @@ +\newcommand{\sanss} {\col{SANS\_}} +\newcommand{\withh} {\col{WITH\_}} +\newcommand{\ssanss} {\col{\_SANS\_}} +\newcommand{\wwithh} {\col{\_WITH\_}} +\newcommand{\callerWontRevert} {\col{\_CALLER\_WONT\_REVERT}} +\newcommand{\callerWillRevert} {\col{\_CALLER\_WILL\_REVERT}} +\newcommand{\calleeWontSelfRevert} {\col{\_CALL\_SUCCESS}} +\newcommand{\calleeWillSelfRevert} {\col{\_CALL\_FAILURE}} +\newcommand{\creatorWontRevert} {\col{\_WONT\_REVERT}} +\newcommand{\creatorWillRevert} {\col{\_WILL\_REVERT}} +\newcommand{\createeWontSelfRevert} {\col{\_SUCCESS}} +\newcommand{\createeWillSelfRevert} {\col{\_FAILURE}} +\newcommand{\precompileFailure} {\col{PRC\_FAILURE}} +\newcommand{\precompileSuccess} {\col{PRC\_SUCCESS}} +\newcommand{\insufficientGas} {\col{insufficient\_gas}} +\newcommand{\Success} {\green {\col{success}}} +\newcommand{\Failure} {\orange{\col{failure}}} +\newcommand{\ssum} {\col{sum}} +\newcommand{\wsum} {\col{weighted\_sum}} +% precompile macros +\newcommand{\macroSomePrecompile} {\col{}} +\newcommand{\macroEcrecover} {\col{ECRECOVER}} +\newcommand{\macroShaTwo} {\col{SHA2-256}} +\newcommand{\macroRipemd} {\col{RIPEMD-160}} +\newcommand{\macroIdentity} {\col{IDENTITY}} +\newcommand{\macroModexp} {\col{MODEXP}} +\newcommand{\macroEcadd} {\col{ECADD}} +\newcommand{\macroEcmul} {\col{ECMUL}} +\newcommand{\macroEcpairing} {\col{ECPAIRING}} +\newcommand{\macroBlake} {\col{BLAKE2f}} +% narratives +% +% \newcommand{\scenCodeDeposit} {\scenarioSignifier\col{CODEDEPOSIT}} +% \newcommand{\scenCodeDepositSum} {\scenarioSignifier\col{CODEDEPOSIT}\separator\ssum} +\newcommand{\scenReturn} {\scenarioSignifier\col{RETURN}} +\newcommand{\scenReturnException} {\scenReturn\separator\col{EXCEPTION}} +\newcommand{\scenReturnFromMessageCallWillTouchRam} {\scenReturn\separator\col{FROM\_MESSAGE\_CALL\_WILL\_TOUCH\_RAM}} +\newcommand{\scenReturnFromMessageCallWontTouchRam} {\scenReturn\separator\col{FROM\_MESSAGE\_CALL\_WONT\_TOUCH\_RAM}} +\newcommand{\scenReturnFromDeploymentEmptyByteCodeWillRevert} {\scenReturn\separator\col{FROM\_DEPLOYMENT\_EMPTY\_CODE\_WILL\_REVERT}} +\newcommand{\scenReturnFromDeploymentEmptyByteCodeWontRevert} {\scenReturn\separator\col{FROM\_DEPLOYMENT\_EMPTY\_CODE\_WONT\_REVERT}} +\newcommand{\scenReturnFromDeploymentNonemptyByteCodeWillRevert} {\scenReturn\separator\col{FROM\_DEPLOYMENT\_NONEMPTY\_CODE\_WILL\_REVERT}} +\newcommand{\scenReturnFromDeploymentNonemptyByteCodeWontRevert} {\scenReturn\separator\col{FROM\_DEPLOYMENT\_NONEMPTY\_CODE\_WONT\_REVERT}} +% RETURN related shorthands +\newcommand{\scenReturnSum} {\scenReturn\separator\ssum} +\newcommand{\scenReturnRaisesNoException} {\scenReturn\separator\col{unexceptional}} +\newcommand{\scenReturnFromDeployment} {\scenReturn\separator\col{deployment}} +\newcommand{\scenReturnNonemptyDeployment} {\scenReturn\separator\col{nonempty\_deployment}} +\newcommand{\scenReturnEmptyDeployment} {\scenReturn\separator\col{empty\_deployment}} +\newcommand{\scenReturnFromMessageCall} {\scenReturn\separator\col{message\_call}} +\newcommand{\scenReturnDeploymentWillRevert} {\scenReturn\separator\col{deployment\_will\_revert}} +% +\newcommand{\scenSelfdestruct} {\scenarioSignifier\col{SELFDESTRUCT}} +\newcommand{\scenSelfdestructCol} [1] {\scenSelfdestruct\separator\col{#1}} +\newcommand{\scenSelfdestructException} {\scenSelfdestructCol{EXCEPTION}} +\newcommand{\scenSelfdestructWillRevert} {\scenSelfdestructCol{WILL\_REVERT}} +\newcommand{\scenSelfdestructWontRevertAlreadyMarked} {\scenSelfdestructCol{WONT\_REVERT\_ALREADY\_MARKED}} +\newcommand{\scenSelfdestructWontRevertNotYetMarked} {\scenSelfdestructCol{WONT\_REVERT\_NOT\_YET\_MARKED}} +\newcommand{\scenSelfdestructSum} {\scenSelfdestructCol{sum}} +\newcommand{\scenSelfdestructUnexceptional} {\scenSelfdestructCol{unexceptional}} +\newcommand{\scenSelfdestructWontRevert} {\scenSelfdestructCol{wont\_revert}} + +% subscenarios flags: +\newcommand{\scenario} [1] {\scenarioSignifier\col{SCN\_#1}} +\newcommand{\scenarioA}[1] {\scenario{\orange{\col{FAIL}}\_#1}} +\newcommand{\scenarioB}[1] {\scenario{\green {\col{SUCC}}\_#1}} +\newcommand{\scenarioSum} {\scenarioSignifier\col{SCN}\separator\ssum} +\newcommand{\scenarioSumA} {\scenarioSignifier\col{SCN\_}\orange{\col{FAIL}}\separator\ssum} +\newcommand{\scenarioSumB} {\scenarioSignifier\col{SCN\_}\green {\col{SUCC}}\separator\ssum} +% +% +% CALL scenarios +% +% +\newcommand{\scenCall} {\scenarioSignifier\col{CALL}} +\newcommand{\scenCallException} {\scenCall\separator\col{EXCEPTION}} +\newcommand{\scenCallAbortWillRevert} {\scenCall\separator\col{ABORT\_WILL\_REVERT}} +\newcommand{\scenCallAbortWontRevert} {\scenCall\separator\col{ABORT\_WONT\_REVERT}} +\newcommand{\scenCallToPrecompileSuccess} {\scenCall\separator\col{precompile\_success}} +\newcommand{\scenCallEoaSuccessWillRevert} {\scenCall\separator\col{EOA\_SUCCESS\_WILL\_REVERT}} +\newcommand{\scenCallEoaSuccessWontRevert} {\scenCall\separator\col{EOA\_SUCCESS\_WONT\_REVERT}} +\newcommand{\scenCallSmcFailureWillRevert} {\scenCall\separator\col{SMC\_FAILURE\_WILL\_REVERT}} +\newcommand{\scenCallSmcFailureWontRevert} {\scenCall\separator\col{SMC\_FAILURE\_WONT\_REVERT}} +\newcommand{\scenCallSmcSuccessWillRevert} {\scenCall\separator\col{SMC\_SUCCESS\_WILL\_REVERT}} +\newcommand{\scenCallSmcSuccessWontRevert} {\scenCall\separator\col{SMC\_SUCCESS\_WONT\_REVERT}} +\newcommand{\scenCallPrcFailure} {\scenCall\separator\precompileFailure} +\newcommand{\scenCallPrcSuccessWillRevert} {\scenCall\separator\precompileSuccess\col{\_WILL\_REVERT}} +\newcommand{\scenCallPrcSuccessWontRevert} {\scenCall\separator\precompileSuccess\col{\_WONT\_REVERT}} +% +\newcommand{\scenCallEoa} {\scenCall\separator\col{externally\_owned\_account}} +\newcommand{\scenCallSmc} {\scenCall\separator\col{smart\_contract}} +\newcommand{\scenCallPrc} {\scenCall\separator\col{precompile}} +\newcommand{\scenCallNoPrc} {\scenCall\separator\col{no\_precompile}} +\newcommand{\scenCallAbort} {\scenCall\separator\col{abort}} +\newcommand{\scenCallNoAbort} {\scenCall\separator\col{no\_abort}} +\newcommand{\scenCallEntry} {\scenCall\separator\col{entry}} +\newcommand{\scenCallSum} {\scenCall\separator\ssum} +\newcommand{\scenCallUnexceptional} {\scenCall\separator\col{unexceptional}} +\newcommand{\scenCallPrecompileSuccess} {\scenCall\separator\col{precompile\_success}} +\newcommand{\scenCallEntryKnownWillRevert} {\scenCall\separator\col{execution\_known\_to\_revert}} +\newcommand{\scenCallEntryKnownWontRevert} {\scenCall\separator\col{execution\_known\_to\_not\_revert}} +\newcommand{\scenCallSuccess} {\scenCall\separator\col{success}} +\newcommand{\scenCallSmcSuccess} {\scenCall\separator\col{smc\_success}} +\newcommand{\scenCallSmcFailure} {\scenCall\separator\col{smc\_failure}} +\newcommand{\scenCallFailure} {\scenCall\separator\col{failure}} +\newcommand{\scenCallNoContextChange} {\scenCall\separator\col{no\_context\_change}} +\newcommand{\scenCallRequiresBothAccountsTwice} {\scenCall\separator\col{requires\_both\_accounts\_twice}} +% +\newcommand{\scenCallCalleeWarmthUpdateNotRequired} {\scenCall\separator\col{callee\_warmth\_update\_not\_required}} +\newcommand{\scenCallCalleeWarmthUpdateRequired} {\scenCall\separator\col{callee\_warmth\_update\_required}} +\newcommand{\scenCallBalanceUpdateNotRequired} {\scenCall\separator\col{balance\_update\_not\_required}} +\newcommand{\scenCallBalanceUpdateRequired} {\scenCall\separator\col{balance\_update\_required}} +\newcommand{\scenCallBalanceUpdateUndoneWithCalleeFailure} {\scenCall\separator\col{balance\_update\_undone\_with\_callee\_failure}} +\newcommand{\scenCallBalanceUpdateUndoneWithCallerRevert} {\scenCall\separator\col{balance\_update\_undone\_with\_caller\_revert}} +% +\newcommand{\relofPrcFailure }{\redm{\relof[\inst{PRC}] ^ \text{fail}}} +\newcommand{\relofPrcSuccessWillRevert}{\redm{\relof[\inst{PRC}]_{\text{rev}} ^ \text{succ}}} +\newcommand{\relofPrcSuccessWontRevert}{\redm{\relof[\inst{PRC}]_{\text{norev}} ^ \text{succ}}} +\newcommand{\relofSmcFailureWillRevert}{\redm{\relof[\inst{SMC}]_{\text{rev}} ^ \text{fail}}} +\newcommand{\relofSmcFailureWontRevert}{\redm{\relof[\inst{SMC}]_{\text{norev}} ^ \text{fail}}} +\newcommand{\relofSmcSuccessWillRevert}{\redm{\relof[\inst{SMC}]_{\text{rev}} ^ \text{succ}}} +\newcommand{\relofSmcSuccessWontRevert}{\redm{\relof[\inst{SMC}]_{\text{norev}} ^ \text{succ}}} + + +% +% +\newcommand{\scenCallColumn} [1] {\scenCall\separator\col{#1}} +\newcommand{\scenCallerWillRevert} {\scenCallColumn{caller\_will\_revert}} +\newcommand{\scenCallToEoa} {\scenCallColumn{externally\_owned\_account}} +\newcommand{\scenCallToPrecompile} {\scenCallColumn{precompile}} +\newcommand{\scenCallToSmartContract} {\scenCallColumn{smart\_contract}} +\newcommand{\scenCallNoValueTransfer} {\scenCallColumn{no\_value\_transfer}} +\newcommand{\scenCallValueTransferAndWarmth} {\scenCallColumn{value\_transfer\_and\_warmth}} +\newcommand{\scenCallUndoValueTransfer} {\scenCallColumn{undo\_value\_transfer}} +\newcommand{\scenCallUndoWithCaller} {\scenCallColumn{undo\_with\_caller}} +\newcommand{\scenCallUndoWithCallee} {\scenCallColumn{undo\_with\_callee}} +% +\newcommand{\scenPrecompileColumn} [1] {\scenPrecompile\separator\col{#1}} +\newcommand{\scenPrecompile} {\scenarioSignifier\col{PRC}} +\newcommand{\scenPrecompileSum} {\scenPrecompileColumn{\ssum}} +\newcommand{\scenPrecompileWeightedSum} {\scenPrecompileColumn{\wsum}} +\newcommand{\scenSomePrecompile} {\scenPrecompileColumn{\macroSomePrecompile}} +\newcommand{\scenPrecompileCommonNotIdentity} {\scenPrecompileColumn{common\_except\_identity}} +\newcommand{\scenPrecompileCommon} {\scenPrecompileColumn{common}} +\newcommand{\scenPrecompileMayOnlyFailInHub} {\scenPrecompileColumn{may\_only\_fail\_in\_HUB}} +\newcommand{\scenPrecompileMayOnlyFailInRam} {\scenPrecompileColumn{may\_only\_fail\_in\_RAM}} +\newcommand{\scenEcrecover} {\scenPrecompileColumn{\macroEcrecover}} +\newcommand{\scenShaTwo} {\scenPrecompileColumn{\macroShaTwo}} +\newcommand{\scenRipemd} {\scenPrecompileColumn{\macroRipemd}} +\newcommand{\scenIdentity} {\scenPrecompileColumn{\macroIdentity}} +\newcommand{\scenModexp} {\scenPrecompileColumn{\macroModexp}} +\newcommand{\scenEcadd} {\scenPrecompileColumn{\macroEcadd}} +\newcommand{\scenEcmul} {\scenPrecompileColumn{\macroEcmul}} +\newcommand{\scenEcpairing} {\scenPrecompileColumn{\macroEcpairing}} +\newcommand{\scenBlake} {\scenPrecompileColumn{\macroBlake}} +% +\newcommand{\scenPrcCurrentlyValidCallerGas } {\scenPrecompileColumn{CALLER\_GAS}} +\newcommand{\scenPrcGasAllowance } {\scenPrecompileColumn{CALLEE\_GAS}} +\newcommand{\scenPrcGasOwedToCaller } {\scenPrecompileColumn{RETURN\_GAS}} +\newcommand{\scenPrcCdo } {\scenPrecompileColumn{CDO}} +\newcommand{\scenPrcCds } {\scenPrecompileColumn{CDS}} +\newcommand{\scenPrcRao } {\scenPrecompileColumn{RAO}} +\newcommand{\scenPrcRac } {\scenPrecompileColumn{RAC}} +\newcommand{\scenPrcFailureKnownToHub } {\scenPrecompileColumn{FAILURE\_KNOWN\_TO\_HUB}} +\newcommand{\scenPrcFailureKnownToRam } {\scenPrecompileColumn{FAILURE\_KNOWN\_TO\_RAM}} +\newcommand{\scenPrcSuccessWillRevert } {\scenPrecompileColumn{SUCCESS\_WILL\_REVERT}} +\newcommand{\scenPrcSuccessWontRevert } {\scenPrecompileColumn{SUCCESS\_WONT\_REVERT}} +\newcommand{\scenPrcSuccess } {\scenPrecompileColumn{success}} +\newcommand{\scenPrcFailure } {\scenPrecompileColumn{failure}} +\newcommand{\scenPrcScenarioSum } {\scenPrecompileColumn{scenario\_sum}} +% +\newcommand{\scenPrecompileNsrPreamble} {\scenarioSignifier\col{precompile\_nsr\_preamble}} +\newcommand{\scenEcrecoverNsrEpilogue} {\scenEcrecover\separator\col{nsr\_epilogue}} +\newcommand{\scenShaTwoNsrEpilogue} {\scenShaTwo\separator\col{nsr\_epilogue}} +\newcommand{\scenRipemdNsrEpilogue} {\scenRipemd\separator\col{nsr\_epilogue}} +\newcommand{\scenIdentityNsrEpilogue} {\scenIdentity\separator\col{nsr\_epilogue}} +\newcommand{\scenModexpNsrEpilogue} {\scenModexp\separator\col{nsr\_epilogue}} +\newcommand{\scenEcaddNsrEpilogue} {\scenEcadd\separator\col{nsr\_epilogue}} +\newcommand{\scenEcmulNsrEpilogue} {\scenEcmul\separator\col{nsr\_epilogue}} +\newcommand{\scenEcpairingNsrEpilogue} {\scenEcpairing\separator\col{nsr\_epilogue}} +\newcommand{\scenBlakeNsrEpilogue} {\scenBlake\separator\col{nsr\_epilogue}} +% +% +% +% CREATE scenarios +% ================ +% +% +% +\newcommand{\scenCreate} {\scenarioSignifier\col{CREATE}} +\newcommand{\scenCreateColumn} [1] {\scenCreate\separator\col{#1}} +\newcommand{\scenCreateException} {\scenCreateColumn{EXCEPTION}} % SCN_4 +\newcommand{\scenCreateAbort} {\scenCreateColumn{ABORT}} % SCN_4 +\newcommand{\scenCreateFCondWontRevert} {\scenCreateColumn{FAILURE\_CONDITION}\creatorWontRevert} % SCN_1 +\newcommand{\scenCreateFCondWillRevert} {\scenCreateColumn{FAILURE\_CONDITION}\creatorWillRevert} % SCN_1 +\newcommand{\scenCreateNonEmptyInitCodeFailureWontRevert} {\scenCreateColumn{NONEMPTY\_INIT\_CODE\_FAILURE\_WONT\_REVERT}} % SCN_5 +\newcommand{\scenCreateNonEmptyInitCodeSuccessWontRevert} {\scenCreateColumn{NONEMPTY\_INIT\_CODE\_SUCCESS\_WONT\_REVERT}} % SCN_6 +\newcommand{\scenCreateNonEmptyInitCodeFailureWillRevert} {\scenCreateColumn{NONEMPTY\_INIT\_CODE\_FAILURE\_WILL\_REVERT}} % SCN_7 +\newcommand{\scenCreateNonEmptyInitCodeSuccessWillRevert} {\scenCreateColumn{NONEMPTY\_INIT\_CODE\_SUCCESS\_WILL\_REVERT}} % SCN_8 +\newcommand{\scenCreateEmptyInitCodeWontRevert} {\scenCreateColumn{EMPTY\_INIT\_CODE\_WONT\_REVERT}} % SCN_9 +\newcommand{\scenCreateEmptyInitCodeWillRevert} {\scenCreateColumn{EMPTY\_INIT\_CODE\_WILL\_REVERT}} % SCN_10 +% +\newcommand{\scenCreateSum} {\scenCreateColumn{\ssum}} +\newcommand{\scenCreateNoContextChange} {\scenCreateColumn{no\_context\_change}} +\newcommand{\scenCreateUnexceptional} {\scenCreateColumn{unexceptional}} +\newcommand{\scenCreateComputeAddress} {\scenCreateColumn{compute\_deployment\_address}} +\newcommand{\scenCreateFCond} {\scenCreateColumn{failure\_condition}} +\newcommand{\scenCreateWillRevert} {\scenCreateColumn{will\_revert}} +\newcommand{\scenCreateNoCreatorStateChange} {\scenCreateColumn{no\_creator\_state\_change}} +\newcommand{\scenCreateCreatorStateChange} {\scenCreateColumn{creator\_state\_change}} +\newcommand{\scenCreateCreatorStateChangeWillRevert} {\scenCreateColumn{creator\_state\_change\_will\_revert}} +\newcommand{\scenCreateCreatorStateChangeWontRevert} {\scenCreateColumn{creator\_state\_change\_wont\_revert}} +\newcommand{\scenCreateRebuffed} {\scenCreateColumn{rebuffed}} +\newcommand{\scenCreateNotRebuffed} {\scenCreateColumn{not\_rebuffed}} +\newcommand{\scenCreateExecution} {\scenCreateColumn{not\_rebuffed}} +\newcommand{\scenCreateExecutionEmptyInitCode} {\scenCreateColumn{not\_rebuffed\_empty\_init\_code}} +\newcommand{\scenCreateExecutionNonEmptyInitCode} {\scenCreateColumn{not\_rebuffed\_nonempty\_init\_code}} +\newcommand{\scenCreateSimpleRevert} {\scenCreateColumn{simple\_revert}} +\newcommand{\scenCreateSuccess} {\scenCreateColumn{deployment\_success}} +\newcommand{\scenCreateFailure} {\scenCreateColumn{deployment\_failure}} +% +% +% +% Deployment scenarios +% ==================== +% +% +% +\newcommand{\scenCodeDepositInvalidCodePrefix} {\scenCodeDeposit\separator\col{INVALID\_CODE\_PREFIX}} +\newcommand{\scenCodeDepositValidCodePrefix} {\scenCodeDeposit\separator\col{VALID\_CODE\_PREFIX}} +% +% PRECOMPILES +% +% ECRECOVER +\newcommand{\scenEcrecoverSum} {\scenEcrecover\separator\ssum} +\newcommand{\scenEcrecoverSuccess} {\scenEcrecover\separator\Success} +\newcommand{\scenEcrecoverFailure} {\scenEcrecover\separator\Failure} +\newcommand{\scenEcrecoverInsufficientGas} {\scenEcrecover\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenEcrecoverSufficientGasSansCallData} {\scenEcrecover\separator\Failure\col{\_sans\_call\_data}} +\newcommand{\scenEcrecoverSufficientGasWithMalformedCallData} {\scenEcrecover\separator\Failure\col{\_with\_call\_data\_malformed}} +\newcommand{\scenEcrecoverSufficientGasWithUnrecoverableCallData} {\scenEcrecover\separator\Failure\col{\_with\_call\_data\_unrecoverable}} +\newcommand{\scenEcrecoverSufficientGasWithCallDataSansReturnAtCapacity} {\scenEcrecover\separator\Success\col{\_sans\_}\retAtCap} +\newcommand{\scenEcrecoverSufficientGasWithCallDataWithReturnAtCapacity} {\scenEcrecover\separator\Success\col{\_with\_}\retAtCap} +% SHA2-256 +\newcommand{\scenShaTwoSum} {\scenShaTwo\separator\ssum} +\newcommand{\scenShaTwoSuccess} {\scenShaTwo\separator\Success} +\newcommand{\scenShaTwoFailure} {\scenShaTwo\separator\Failure} +\newcommand{\scenShaTwoInsufficientGas} {\scenShaTwo\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenShaTwoSufficientGasSansCallDataSansReturnAtCapacity} {\scenShaTwo\separator\Success\col{\_sans\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenShaTwoSufficientGasSansCallDataWithReturnAtCapacity} {\scenShaTwo\separator\Success\col{\_sans\_call\_data\_with\_}\retAtCap} +\newcommand{\scenShaTwoSufficientGasWithCallDataSansReturnAtCapacity} {\scenShaTwo\separator\Success\col{\_with\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenShaTwoSufficientGasWithCallDataWithReturnAtCapacity} {\scenShaTwo\separator\Success\col{\_with\_call\_data\_with\_}\retAtCap} +% RIPEMD-160 +\newcommand{\scenRipemdSum} {\scenRipemd\separator\ssum} +\newcommand{\scenRipemdSuccess} {\scenRipemd\separator\Success} +\newcommand{\scenRipemdFailure} {\scenRipemd\separator\Failure} +\newcommand{\scenRipemdInsufficientGas} {\scenRipemd\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenRipemdSufficientGasSansCallDataSansReturnAtCapacity} {\scenRipemd\separator\Success\col{\_sans\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenRipemdSufficientGasSansCallDataWithReturnAtCapacity} {\scenRipemd\separator\Success\col{\_sans\_call\_data\_with\_}\retAtCap} +\newcommand{\scenRipemdSufficientGasWithCallDataSansReturnAtCapacity} {\scenRipemd\separator\Success\col{\_with\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenRipemdSufficientGasWithCallDataWithReturnAtCapacity} {\scenRipemd\separator\Success\col{\_with\_call\_data\_with\_}\retAtCap} +% IDENTITY +\newcommand{\scenIdentitySum} {\scenIdentity\separator\ssum} +\newcommand{\scenIdentitySuccess} {\scenIdentity\separator\Success} +\newcommand{\scenIdentityFailure} {\scenIdentity\separator\Failure} +\newcommand{\scenIdentityInsufficientGas} {\scenIdentity\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenIdentitySufficientGasSansCallData} {\scenIdentity\separator\Success\col{\_sans\_call\_data}} +\newcommand{\scenIdentitySufficientGasWithCallDataSansReturnAtCapacity} {\scenIdentity\separator\Success\col{\_with\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenIdentitySufficientGasWithCallDataWithReturnAtCapacity} {\scenIdentity\separator\Success\col{\_with\_call\_data\_with\_}\retAtCap} +% MODEXP TODO!!! +\newcommand{\scenModexpSum} {\scenModexp\separator\ssum} +\newcommand{\scenModexpSuccess} {\scenModexp\separator\Success} +\newcommand{\scenModexpFailure} {\scenModexp\separator\Failure} +% ECADD +\newcommand{\scenEcaddSum} {\scenEcadd\separator\ssum} +\newcommand{\scenEcaddSuccess} {\scenEcadd\separator\Success} +\newcommand{\scenEcaddFailure} {\scenEcadd\separator\Failure} +\newcommand{\scenEcaddInsufficientGas} {\scenEcadd\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenEcaddSufficientGasWithMalformedCallData} {\scenEcadd\separator\Failure\col{\_with\_call\_data\_malformed}} +\newcommand{\scenEcaddSufficientGasSansCallDataSansReturnAtCapacity} {\scenEcadd\separator\Success\col{\_sans\_call\_data\_sans\_}\retAtCap} % then everything is the point at infinity +\newcommand{\scenEcaddSufficientGasSansCallDataWithReturnAtCapacity} {\scenEcadd\separator\Success\col{\_sans\_call\_data\_with\_}\retAtCap} % then everything is the point at infinity +\newcommand{\scenEcaddSufficientGasWithCallDataSansReturnAtCapacity} {\scenEcadd\separator\Success\col{\_with\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenEcaddSufficientGasWithCallDataWithReturnAtCapacity} {\scenEcadd\separator\Success\col{\_with\_call\_data\_with\_}\retAtCap} +% ECMUL +\newcommand{\scenEcmulSum} {\scenEcmul\separator\ssum} +\newcommand{\scenEcmulSuccess} {\scenEcmul\separator\Success} +\newcommand{\scenEcmulFailure} {\scenEcmul\separator\Failure} +\newcommand{\scenEcmulInsufficientGas} {\scenEcmul\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenEcmulSufficientGasWithMalformedCallData} {\scenEcmul\separator\Failure\col{\_with\_call\_data\_malformed}} +\newcommand{\scenEcmulSufficientGasSansCallDataSansReturnAtCapacity} {\scenEcmul\separator\Success\col{\_sans\_call\_data\_sans\_}\retAtCap} % then everything is the point at infinity +\newcommand{\scenEcmulSufficientGasSansCallDataWithReturnAtCapacity} {\scenEcmul\separator\Success\col{\_sans\_call\_data\_with\_}\retAtCap} % then everything is the point at infinity +\newcommand{\scenEcmulSufficientGasWithCallDataSansReturnAtCapacity} {\scenEcmul\separator\Success\col{\_with\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenEcmulSufficientGasWithCallDataWithReturnAtCapacity} {\scenEcmul\separator\Success\col{\_with\_call\_data\_with\_}\retAtCap} +% ECPAIRING +\newcommand{\scenEcpairingSum} {\scenEcpairing\separator\ssum} +\newcommand{\scenEcpairingSuccess} {\scenEcpairing\separator\Success} +\newcommand{\scenEcpairingFailure} {\scenEcpairing\separator\Failure} +\newcommand{\scenEcpairingImpossibleSize} {\scenEcpairing\separator\Failure\col{\_size\_not\_multiple\_of\_192}} +\newcommand{\scenEcpairingInsufficientGas} {\scenEcpairing\separator\Failure\col{\_}\insufficientGas} +\newcommand{\scenEcpairingSufficientGasWithMalformedCallData} {\scenEcpairing\separator\Failure\col{\_with\_call\_data\_malformed}} +\newcommand{\scenEcpairingSufficientGasSansCallDataSansReturnAtCapacity} {\scenEcpairing\separator\Success\col{\_sans\_call\_data\_sans\_}\retAtCap} % then everything is the point at infinity +\newcommand{\scenEcpairingSufficientGasSansCallDataWithReturnAtCapacity} {\scenEcpairing\separator\Success\col{\_sans\_call\_data\_with\_}\retAtCap} % then everything is the point at infinity +\newcommand{\scenEcpairingSufficientGasWithCallDataSansReturnAtCapacity} {\scenEcpairing\separator\Success\col{\_with\_call\_data\_sans\_}\retAtCap} +\newcommand{\scenEcpairingSufficientGasWithCallDataWithReturnAtCapacity} {\scenEcpairing\separator\Success\col{\_with\_call\_data\_with\_}\retAtCap} +% BLAKE2f +\newcommand{\scenBlakeSum} {\scenBlake\separator\ssum} +\newcommand{\scenBlakeSuccess} {\scenBlake\separator\Success} +\newcommand{\scenBlakeFailure} {\scenBlake\separator\Failure} +\newcommand{\scenBlakeInsufficientGas} {\scenBlake\separator\Failure\col{\_}\insufficientGas} % requires access to RAM !!! +\newcommand{\scenBlakeImpossibleSize} {\scenBlake\separator\Failure\col{\_size\_not\_213}} +\newcommand{\scenBlakeFNotABit} {\scenBlake\separator\Failure\col{\_f\_not\_a\_bit}} % requires access to RAM !!! +\newcommand{\scenBlakeSufficientGasWithCallDataSansReturnAtCapacity} {\scenBlake\separator\Success\col{\_sans\_}\retAtCap} +\newcommand{\scenBlakeSufficientGasWithCallDataWithReturnAtCapacity} {\scenBlake\separator\Success\col{\_with\_}\retAtCap} diff --git a/pkg/shifting.sty b/pkg/shifting.sty new file mode 100644 index 0000000..0f3a782 --- /dev/null +++ b/pkg/shifting.sty @@ -0,0 +1,23 @@ +\newcommand{\shiftedBytes}[1]{\col{SHB\_#1}} +\newcommand{\someBits}{\col{BITS}} + +\newcommand{\LA}{\col{LEFT\_ALIGNED}} +\newcommand{\RA}{\col{RIGHT\_ALIGNED}} +\newcommand{\la}{\col{LA}} +\newcommand{\ra}{\col{RA}} + +\newcommand{\laHi}{\col{LA}\high} +\newcommand{\raHi}{\col{RA}\high} +\newcommand{\laLo}{\col{LA}\low} +\newcommand{\raLo}{\col{RA}\low} + + +\newcommand{\decLaHi}{\decoded{\laHi}} +\newcommand{\decRaHi}{\decoded{\raHi}} +\newcommand{\decLaLo}{\decoded{\laLo}} +\newcommand{\decRaLo}{\decoded{\raLo}} + +\newcommand{\rightShiftBy}{\texttt{rightShiftBy}} +\newcommand{\leftShiftBy}{\texttt{leftShiftBy}} + +\newcommand{\known}{\col{KNOWN}} \ No newline at end of file diff --git a/pkg/stack.sty b/pkg/stack.sty new file mode 100644 index 0000000..a950946 --- /dev/null +++ b/pkg/stack.sty @@ -0,0 +1,261 @@ +% \newcommand{\depth}{\col{DEPTH}} +% \newcommand{\sDepth}[1]{\prescript{}{#1}{\col{DEPTH}}} +% \newcommand{\height}{\col{HEIGHT}} +% \newcommand{\HEIGHTUNDER}{\col{HEIGHT\_UNDER}} +% \newcommand{\HEIGHTOVER}{\col{HEIGHT\_OVER}} +% \newcommand{\heightUnder}{\col{HU}} +% \newcommand{\heightOver}{\col{HO}} +% \newcommand{\sHeight}[1]{\prescript{}{#1}{\col{HEIGHT}}} +% \newcommand{\sVal}[1]{\prescript{}{#1}{\col{VAL}}} +% \newcommand{\sValHi}[1]{\prescript{}{#1}{\col{VAL}\high}} +% \newcommand{\sValLo}[1]{\prescript{}{#1}{\col{VAL}\low}} +% \newcommand{\isValHi}[1]{\imported{\sValHi{#1}}} +% \newcommand{\isValLo}[1]{\imported{\sValLo{#1}}} +% \newcommand{\sPop}[1]{\prescript{}{#1}{\col{POP}}} +% \newcommand{\sStamp}[1]{\prescript{\stampSignifier}{#1}{\col{STACK}}} +% \newcommand{\stackItem}[1]{\prescript{}{#1}{\col{ITEM}}} + +\newcommand{\depth} {\col{DEPTH}} +\newcommand{\sDepth}[1] {\prescript{}{#1}{\col{DEPTH}}} +\newcommand{\height} {\col{HEIGHT}} +\newcommand{\HEIGHTUNDER} {\col{HEIGHT\_UNDER}} +\newcommand{\HEIGHTOVER} {\col{HEIGHT\_OVER}} +\newcommand{\heightUnder} {\col{HU}} +\newcommand{\heightOver} {\col{HO}} +\newcommand{\sHeight}[1] {{\col{HEIGHT\_#1}}} +\newcommand{\sVal}[1] {{\col{VAL\_#1}}} +\newcommand{\sValHi}[1] {{\sVal{#1}\high}} +\newcommand{\sValLo}[1] {{\sVal{#1}\low}} +\newcommand{\isValHi}[1] {\imported{\sValHi{#1}}} +\newcommand{\isValLo}[1] {\imported{\sValLo{#1}}} +\newcommand{\sPop}[1] {\col{POP\_#1}} +\newcommand{\sStamp}[1] {{\col{STACK}\stampSignifier\col{\_#1}}} +\newcommand{\stackItem}[1] {\col{ITEM\_#1}} + + +\newcommand{\TLI}{\col{TWO\_LINE\_INSTRUCTION}} +\newcommand{\tli}{\col{TLI}} +\newcommand{\IPARAM}{\decoded{\col{INST\_PARAMETER}}} +\newcommand{\param}{\col{PARAM}} +\newcommand{\iParam}{\decoded{\col{PARAM}}} + +\newcommand{\STACKINSTTYPE}{\imported{\col{STACK\_INST\_TYPE}}} +\newcommand{\stackInstType}{\imported{\col{SIT}}} + +\newcommand{\ISTAMP}{\col{INSTRUCTION\_STAMP}} +\newcommand{\iStamp}{\stampCol{\col{INST}}} + +\newcommand{\sInst}{\imported{\col{INST}}} + +\newcommand{\PATTERN}{\decoded{\col{STACK\_PATTERN}}} +\newcommand{\pattern}{\decoded{\col{PAT}}} + +\newcommand{\IARG}{\imported{\col{INSTRUCTION\_ARGUMENT}}} +\newcommand{\iArg}{\imported{\col{ARG}}} + +\newcommand{\stackHeight} {\stackSignifier\height} +\newcommand{\stackHEIGHTUNDER} {\stackSignifier\HEIGHTUNDER} +\newcommand{\stackHEIGHTOVER} {\stackSignifier\HEIGHTOVER} +\newcommand{\stackHeightUnder} {\stackSignifier\heightUnder} +\newcommand{\stackHeightOver} {\stackSignifier\heightOver} +\newcommand{\stackItemHeight}[1] {\stackSignifier\sHeight{#1}} +\newcommand{\stackItemVal}[1] {\stackSignifier\sVal{#1}} +\newcommand{\stackItemValHi}[1] {\stackSignifier\col{VALUE\_{#1}\_HI}} +\newcommand{\stackItemValLo}[1] {\stackSignifier\col{VALUE\_{#1}\_LO}} +\newcommand{\stackItemPop}[1] {\stackSignifier\sPop{#1}} +\newcommand{\stackItemStamp}[1] {\stackSignifier\sStamp{#1}} +\newcommand{\stackInst} {\stackSignifier\INST} +\newcommand{\stackPushParamHi} {\stackSignifier\pushParamHi} +\newcommand{\stackPushParamLo} {\stackSignifier\pushParamLo} +\newcommand{\stackJUMPDESTINATIONVETTING} {\stackSignifier\col{JUMP\_DESTINATION\_VETTING}} +\newcommand{\stackJumpDestinationVetting} {\stackSignifier\col{JDV}} + +\newcommand{\stackContextFirst} {\order{\stackSignifier\col{CN\_FIRST}}} +\newcommand{\stackContextAgain} {\order{\stackSignifier\col{CN\_AGAIN}}} +\newcommand{\stackHeightFirst} {\order{\stackSignifier\col{HEIGHT\_FIRST}}} +\newcommand{\stackHeightAgain} {\order{\stackSignifier\col{HEIGHT\_AGAIN}}} +\newcommand{\stackSpotFirst} {\order{\stackSignifier\col{SPOT\_FIRST}}} +\newcommand{\stackSpotAgain} {\order{\stackSignifier\col{SPOT\_AGAIN}}} + +% +\newcommand{\hashInfoValHi} {\col{KEC\_HI}} +\newcommand{\hashInfoValLo} {\col{KEC\_LO}} +% \newcommand{\hashInfoSize} {\col{TOTAL\_SIZE}} +% micro sub-perspective: +\newcommand{\stackHashInfoFlag} {\stackSignifier\hashInfoMod\flag} +\newcommand{\stackHashInfoValHi} {\stackSignifier\hashInfoMod\separator\hashInfoValHi} +\newcommand{\stackHashInfoValLo} {\stackSignifier\hashInfoMod\separator\hashInfoValLo} +% \newcommand{\stackHashInfoSize} {\stackSignifier\hashInfoMod\separator\hashInfoSize} +% +\newcommand{\stackLogFlag} {\stackSignifier\logMod\flag} + +%\newcommand{\emptyStackItem}[1]{\prescript{}{#1}{\texttt{EmptyStackItem}}} +\newcommand{\emptyStackItem}[1]{\texttt{emptyStackItem\_#1}} +% \newcommand{}{\texttt{}} +\newcommand{\zzSP}{\texttt{zeroItemPattern}} +\newcommand{\singleSP}{\texttt{oneItemPattern}} +\newcommand{\uzSP}{\texttt{1\_0\_Pattern}} +\newcommand{\zuSP}{\texttt{0\_1\_Pattern}} +\newcommand{\uuSP}{\texttt{1\_1\_Pattern}} +\newcommand{\duSP}{\texttt{2\_1\_Pattern}} +\newcommand{\tzSP}{\texttt{3\_0\_Pattern}} +\newcommand{\tuSP}{\texttt{3\_1\_Pattern}} +% aliases +\newcommand{\stackPattern} {\texttt{StackPattern}} + +\newcommand{\emptySP} {\texttt{empty}\stackPattern} +\newcommand{\zeroZeroSP} {\texttt{(0,0)-}\stackPattern} +\newcommand{\zeroOneSP} {\texttt{(0,1)-}\stackPattern} +\newcommand{\oneZeroSP} {\texttt{(1,0)-}\stackPattern} +\newcommand{\oneOneSP} {\texttt{(1,1)-}\stackPattern} +\newcommand{\twoZeroSP} {\texttt{(2,0)-}\stackPattern} +\newcommand{\twoOneSP} {\texttt{(2,1)-}\stackPattern} +\newcommand{\threeZeroSP} {\texttt{(3,0)-}\stackPattern} +\newcommand{\threeOneSP} {\texttt{(3,1)-}\stackPattern} +\newcommand{\loadStoreSP} {\texttt{loadStore}\stackPattern} +\newcommand{\swapSP} {\texttt{swap}\stackPattern} +\newcommand{\dupSP} {\texttt{dup}\stackPattern} +\newcommand{\logSP} {\texttt{log}\stackPattern} +\newcommand{\copySP} {\texttt{copy}\stackPattern} +\newcommand{\createSP} {\texttt{create}\stackPattern} +\newcommand{\callSP} {\texttt{call}\stackPattern} +% +\newcommand{\stdSP}{\texttt{standardPattern}} +\newcommand{\twoItemSP}{\texttt{twoItemPattern}} +\newcommand{\storageSP}{\texttt{storagePattern}} +\newcommand{\retrevSP}{\texttt{returnRevertPattern}} +\newcommand{\selfdestructSP}{\texttt{selfdestructPattern}} + +\newcommand{\stackColumn} [1] {\stackSignifier\col{#1}} +\newcommand{\stackInstructionDecodedColumn} [1] {\stackColumn{\idMod\separator\col{#1}}} +\newcommand{\flagColumn} [1] {\col{FLAG\_#1}} +\newcommand{\decFlag} [1] {\stackInstructionDecodedColumn{\flagColumn{#1}}} + + +\newcommand{\decAlpha} {\decoded{\col{ALPHA}}} +\newcommand{\decDelta} {\decoded{\col{DELTA}}} +\newcommand{\idAlpha} {\col{ALPHA}} +\newcommand{\idDelta} {\col{DELTA}} +\newcommand{\idNbRemove} {\col{nREMOVE}} +\newcommand{\idNbAdd} {\col{nADD}} +\newcommand{\staticFlag} {\col{STATIC}\flag} +\newcommand{\stackDecStaticFlag} {\stackInstructionDecodedColumn{\staticFlag}} +\newcommand{\stackAlpha} {\stackInstructionDecodedColumn{\idAlpha}} +\newcommand{\stackDelta} {\stackInstructionDecodedColumn{\idDelta}} +\newcommand{\stackNbRemove} {\stackInstructionDecodedColumn{\idNbRemove}} +\newcommand{\stackNbAdd} {\stackInstructionDecodedColumn{\idNbAdd}} +% \newcommand{\stackPATTERN} {\stackInstructionDecodedColumn{STACK\_PATTERN}} +% \newcommand{\stackPattern} {\stackInstructionDecodedColumn{PAT}} +\newcommand{\stackSTATICGAS} {\stackInstructionDecodedColumn{STATIC\_GAS}} +\newcommand{\stackStaticGas} {\stackInstructionDecodedColumn{STATIC\_GAS}} + + +\newcommand{\PC}{\col{PROGRAM\_COUNTER}} +% \renewcommand{\pc}{\col{PC}} +% +\newcommand{\pushParam} {\col{PUSH\_VALUE}} +\newcommand{\pushParamHi} {\pushParam\col{\_HI}} +\newcommand{\pushParamLo} {\pushParam\col{\_LO}} +\newcommand{\iPushParam} {\imported{\pushParam}} +\newcommand{\decPushParam} {\decoded{\pushParam}} +% +\newcommand{\JUMPDESTX}{\col{JUMP\_DESTINATION\_EXCEPTION}} +\newcommand{\jumpDestX}{\col{JUMPX}} +% \newcommand{}{\col{}} \PV\high +\newcommand{\iPushValHi}{\imported{\PV\high}} +\newcommand{\iPushValLo}{\imported{\PV\low}} + +\newcommand{\VALUETRANSFERFLAG}{\col{VALUE\_TRANSFER\_FLAG}} +\newcommand{\valueTransferFlag}{\col{VALTF}} + +\newcommand{\STATICGAS}{\col{STATIC\_GAS}} +\newcommand{\decSTATICGAS}{\decoded{\STATICGAS}} +\newcommand{\staticGas}{\STATICGAS} +\newcommand{\decStaticGas}{\decoded{\staticGas}} + +\newcommand{\exponentSizeInBytes}{\col{EXPONENT\_SIZE\_IN\_BYTES}} + +\newcommand{\deadAccountFlag}{\col{DEAD\_FLAG}} +\newcommand{\iExistenceFlag}{\imported{\deadAccountFlag}} + +\newcommand{\hashFlag}{\col{HASH\_FLAG}} +\newcommand{\decHashFlag}{\decoded{\hashFlag}} +\newcommand{\haltingFLAG}{\col{HALTING\_FLAG}} +\newcommand{\haltingFlag}{\col{HALT}\flag} +\newcommand{\decHaltingFLAG}{\decoded{\haltingFLAG}} +\newcommand{\decHaltingFlag}{\decoded{\haltingFlag}} +\newcommand{\gasTrigger}{\col{GAS\_TRIGGER}} + +\makeatletter + +\define@cmdkey [HASH] {var} {anchorRow} {} +\define@cmdkey [HASH] {var} {relOffset} {} +\define@cmdkey [HASH] {var} {requestBit} {} + +\presetkeys [HASH] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + requestBit = \missingParameter, +}{} + + +\newcommand{\requestHashName} {\texttt{requestHash}} +\newcommand{\requestHash} [1] { + \setkeys[HASH]{var}{#1} + \requestHashName _{\cmdHASH@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdHASH@var@relOffset \\ + \end{array} \right] } + +\newcommand{\maybeRequestHashName} {\texttt{maybeRequestHash}} +\newcommand{\maybeRequestHash} [1] { + \setkeys[HASH]{var}{#1} + \maybeRequestHashName _{\cmdHASH@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdHASH@var@relOffset \\ + \utt{Request bit:} & \cmdHASH@var@requestBit \\ + \end{array} \right] } + +\makeatother + +\newcommand{\BALANCE}{\col{BALANCE}} +\newcommand{\CURRENTACCOUNTHASBALANCE}{\col{ACCOUNT\_HAS\_BALANCE\_FLAG}} +\newcommand{\currentAccountHasBalance}{\col{ACCHB}} + +% stack +\newcommand{\STACKSTAMP}{\col{STACK\_STAMP}} +\newcommand{\stackStamp}{\stampCol{\col{STACK}}} +\newcommand{\BINSTAMP}{\col{BINARY\_STAMP}} + +\newcommand{\ALUSELECTOR}{\col{ALU\_SELECTOR}} +\newcommand{\aluSelector}{\col{ALU}\selector} +\newcommand{\BINSELECTOR}{\col{BIN\_SELECTOR}} +\newcommand{\binSelector}{\col{BIN}\selector} +\newcommand{\EXPSELECTOR}{\col{EXPONENT\_SELECTOR}} +\newcommand{\expSelector}{\col{EXP}\selector} +\newcommand{\GASSELECTOR}{\col{GAS\_SELECTOR}} +\newcommand{\gasSelector}{\col{GAS}\selector} +\newcommand{\HASHINFOSELECTOR}{\col{HASH\_INFO\_SELECTOR}} +\newcommand{\hashSelector}{\col{HASH}\selector} +\newcommand{\LOGINFOSELECTOR}{\col{LOG\_INFO\_SELECTOR}} +\newcommand{\logSelector}{\col{LOG}\selector} +\newcommand{\MEMEXPSELECTOR}{\col{MEMORY\_EXPANSION\_SELECTOR}} +\newcommand{\memExpSelector}{\col{MX}\selector} +\newcommand{\MMUSELECTOR}{\col{MMU\_SELECTOR}} +\newcommand{\mmuSelector}{\col{MMU}\selector} +\newcommand{\RARESELECTOR}{\col{RARE\_CHECKS\_SELECTOR}} +\newcommand{\rareSelector}{\col{RARE}\selector} +\newcommand{\SHAVESELECTOR}{\col{SHAVE\_SELECTOR}} +\newcommand{\shaveSelector}{\col{SHAVE}\selector} +\newcommand{\STORAGESTAMP}{\col{STORAGE\_STAMP}} +\newcommand{\storageStamp}{\col{STORAGE\_STAMP}} +\newcommand{\WARMSELECTOR}{\col{WARMTH\_SELECTOR}} +\newcommand{\warmSelector}{\col{WARM}\selector} +\newcommand{\WCSELECTOR}{\col{WORD\_COMPARISON\_SELECTOR}} +\newcommand{\wcSelector}{\col{WC}\selector} + +\newcommand{\stdMmuInst}{\col{STD}} + +\newcommand{\nonStackRows}{\col{\#NSR}} +\newcommand{\nonStackRowsCounter}{\ct\col{\_NSR}} + diff --git a/pkg/std.sty b/pkg/std.sty new file mode 100644 index 0000000..ca6f2a4 --- /dev/null +++ b/pkg/std.sty @@ -0,0 +1,87 @@ +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} % codage moderne des caract?res sous Latex +\usepackage[english]{babel} +\usepackage[dvipsnames]{xcolor} +\usepackage[table]{colortbl} +\usepackage{tikz} +\usetikzlibrary{positioning} +%\usetikzlibrary{patterns} +\usepackage{mathtools, amssymb, amsthm, amsmath, mathrsfs} +%\usepackage[color=yellow!75]{todonotes} +\usepackage{graphicx} +\usepackage{subcaption} +\usepackage{authblk} +\usepackage{float} +\usepackage{bm} +\usepackage{soul} +\usepackage{enumitem} +\usepackage{multicol} +\usepackage{cancel} +\usepackage{pdflscape} % https://tex.stackexchange.com/a/354/15489 +% \usepackage{nicematrix} % https://tex.stackexchange.com/a/593848/15489 +\usepackage{multirow} +% \usepackage{MnSymbol} +\usepackage{fontawesome} +\usepackage{pdfpages} + +% % https://latex.org/forum/viewtopic.php?t=34161 +% \begin{filecontents}[force]{\jobname.bib} +% @online{EYP, +% title = {Ethereum: A secure decentralised generalised transaction ledger (Paris version c74b55f – 2024-01-29)}, +% author = {Gavin Wood}, +% year = {2024}, +% url = {https://github.com/ethereum/yellowpaper}, +% } +% \end{filecontents} +% \usepackage{csquotes} +% \usepackage{biblatex} +% \addbibresource{\jobname.bib} + +% % https://tex.stackexchange.com/a/1248/15489 +% % allows to write \item[Bla \label{sec: truc: bla}] to reference description items +% \usepackage{nameref} +% \makeatletter +% \let\orgdescriptionlabel\descriptionlabel +% \renewcommand*{\descriptionlabel}[1]{% +% \let\orglabel\label +% \let\label\@gobble +% \phantomsection +% \edef\@currentlabel{#1}% +% %\edef\@currentlabelname{#1}% +% \let\label\orglabel +% \orgdescriptionlabel{#1}% +% } +% \makeatother + +\usepackage[cm]{fullpage} + +\usepackage{hyperref} +\hypersetup{ + colorlinks=true, + linkcolor=solarized-blue, + % linkcolor=black, + filecolor=magenta, + urlcolor=cyan, + % pdftitle={some title}, + % pdfpagemode=FullScreen, + } + +\usepackage{cleveref} +\crefformat{footnote}{#2\footnotemark[#1]#3} + +\urlstyle{same} + +\usepackage{appendix} + +\theoremstyle{remark} +\newtheorem{rem}{Remark} + +\usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm]{geometry} + +\usepackage{mdframed} + +\usepackage[section]{placeins} % https://tex.stackexchange.com/a/282/15489 + +\usepackage{csquotes} % quotes \begin{displayquote} ... \end{displayquote} environment + +\setlistdepth{10} diff --git a/pkg/storage.sty b/pkg/storage.sty new file mode 100644 index 0000000..3506dc3 --- /dev/null +++ b/pkg/storage.sty @@ -0,0 +1,47 @@ +\DeclareRobustCommand*{\ulaPrimitive}{\underleftarrow} +\DeclareRobustCommand*{\uraPrimitive}{\underrightarrow} +\newcommand{\ula}[1]{\ulaPrimitive{\,\,#1}} +\newcommand{\ura}[1]{\uraPrimitive{#1\,\,}} +\newcommand{\COUNTER}{\col{COUNTER}} +\newcommand{\STOSTP}{\col{STORAGE\_STAMP}} +\newcommand{\iSTOSTP}{\imported{\STOSTP}} +\newcommand{\stoStp}{\col{STO}\square} +\newcommand{\iStoStp}{\imported{\stoStp}} +%\newcommand{\REVSTOSTP}{\ula{\col{STORAGE\_STAMP}}} +%\newcommand{\revStoStp}{\ula{\col{STO}\square}} +\newcommand{\ORIGVALHI}{\col{ORIGINAL\_VALUE}\high} +\newcommand{\ORIGVALLO}{\col{ORIGINAL\_VALUE}\low} +\newcommand{\origValHi}{\col{ORIG}\high} +\newcommand{\origValLo}{\col{ORIG}\low} +\newcommand{\STOGAS}{\col{STORAGE\_GAS}} +\newcommand{\stoGas}{\col{STOGAS}} +\newcommand{\REFUND}{\col{REFUND\_GAS}} +\newcommand{\refund}{\col{REFGAS}} +\newcommand{\iSTOGAS}{\imported{\STOGAS}} +\newcommand{\iStoGas}{\imported{\stoGas}} +\newcommand{\iREFUND}{\imported{\REFUND}} +\newcommand{\iRefund}{\imported{\refund}} +\newcommand{\revStamp}{\stoStp\col{REV}} +%\newcommand{\revStamp}{\stoStp\col{REV}} +\newcommand{\iRevStamp}{\imported{\revStamp}} +%\newcommand{\iRevStamp}{\imported{\revStamp}} +\newcommand{\STOADDR}{\col{STORAGE\_ADDRESS}} +\newcommand{\stoAddress}{\col{SADDR}} +\newcommand{\STOKEY}{\col{STORAGE\_KEY}} +\newcommand{\stoKey}{\col{KEY}} +\newcommand{\iSTOKEY}{\imported{\STOKEY}} +\newcommand{\iStoKey}{\imported{\stoKey}} +\newcommand{\iSTOADDR}{\imported{\STOADDR}} +\newcommand{\iStoAddr}{\imported{\stoAddress}} +\newcommand{\FIRSTOCCFLAG}{\col{FIRST\_ACCESS\_FLAG}} +\newcommand{\firstOccFlag}{\col{FACCF}} +\newcommand{\LASTOCCFLAG}{\col{LAST\_ACCESS\_FLAG}} +\newcommand{\lastOccFlag}{\col{LACCF}} +% \newcommand{\TXFPEF}{\col{TX\_FIRST\_PROPER\_ENCOUNTER\_FLAG}} +% \newcommand{\txfpef}{\col{TXFPEF}} +\newcommand{\preWarm}{\col{PREWARM}} + +\newcommand{\DIRTYCLEAR}{\col{REFUND\_DIRTY\_CLEAR}} +\newcommand{\dirtyClear}{\col{REFDC}} +\newcommand{\DIRTYRESET}{\col{REFUND\_DIRTY\_RESET}} +\newcommand{\dirtyReset}{\col{REFDR}} diff --git a/pkg/stp.sty b/pkg/stp.sty new file mode 100644 index 0000000..e93e271 --- /dev/null +++ b/pkg/stp.sty @@ -0,0 +1,14 @@ +\newcommand{\wcpLookupFlag} {\wcpMod\flag} +\newcommand{\divLookupFlag} {\modMod\flag} +\newcommand{\valueHi} {\col{VALUE\_HI}} +\newcommand{\valueLo} {\col{VALUE\_LO}} +\newcommand{\gasHi} {\col{GAS\_HI}} +\newcommand{\gasLo} {\col{GAS\_LO}} +\newcommand{\instructionType} {\col{TYPE}} +\newcommand{\exoInst} {\col{EXO\_INST}} +\newcommand{\stpCreate} {\col{IS\_CREATE}} +\newcommand{\stpCreateTwo} {\col{IS\_CREATE2}} +\newcommand{\stpCall} {\col{IS\_CALL}} +\newcommand{\stpCallCode} {\col{IS\_CALLCODE}} +\newcommand{\stpDelegateCall} {\col{IS\_DELEGATECALL}} +\newcommand{\stpStaticCall} {\col{IS\_STATICCALL}} diff --git a/pkg/subsubsubsection.sty b/pkg/subsubsubsection.sty new file mode 100644 index 0000000..649881a --- /dev/null +++ b/pkg/subsubsubsection.sty @@ -0,0 +1,19 @@ +\usepackage{titlesec} +\usepackage{hyperref} + +\titleclass{\subsubsubsection}{straight}[\subsection] + +\newcounter{subsubsubsection}[subsubsection] +\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}} +% \renewcommand\theparagraph{\thesubsubsubsection.\arabic{paragraph}} % optional; useful if paragraphs are to be numbered + +\titleformat{\subsubsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{} +\titlespacing*{\subsubsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} + +\makeatletter +\def\toclevel@subsubsubsection{4} +\def\l@subsubsubsection{\@dottedtocline{4}{10em}{6.7em}} +\makeatother + +\setcounter{secnumdepth}{4} +\setcounter{tocdepth}{4} diff --git a/pkg/thm_env.sty b/pkg/thm_env.sty new file mode 100644 index 0000000..71f8e11 --- /dev/null +++ b/pkg/thm_env.sty @@ -0,0 +1,8 @@ +\theoremstyle{theorem} +\newtheorem{lem}{Lemma} +\newtheorem{thm}{Theorem} +\newtheorem{conjecture}{Conjecture} + +\theoremstyle{remark} +\newtheorem{rmk}{Remark} +\newtheorem{question}{Question} diff --git a/pkg/trm.sty b/pkg/trm.sty new file mode 100644 index 0000000..50b78ee --- /dev/null +++ b/pkg/trm.sty @@ -0,0 +1,7 @@ +\newcommand{\iAddrHi} {\imported{\addr\high}} +\newcommand{\iAddrLo} {\imported{\addr\low}} +\newcommand{\trmAddrHi} {\trmMod\col{\_}\addr\col{\_HI}} +\newcommand{\rawAddrHi} {\col{RAW\_ADDR\_HI}} +\newcommand{\rawAddrLo} {\col{RAW\_ADDR\_LO}} +\newcommand{\isPrecompile} {\col{IS\_PRECOMPILE}} +\newcommand{\plateauBit} {\col{PLATEAU\_BIT}} diff --git a/pkg/txn_data.sty b/pkg/txn_data.sty new file mode 100644 index 0000000..9fdd384 --- /dev/null +++ b/pkg/txn_data.sty @@ -0,0 +1,59 @@ +\newcommand{\txTxNum} {\transactionSignifier\txNum} +\newcommand{\txBatchNum} {\transactionSignifier\batchNum} +\newcommand{\txNonce} {\transactionSignifier\col{NONCE}} +\newcommand{\txTo} {\transactionSignifier\col{TO}} +\newcommand{\txCoinbase} {\transactionSignifier\coinbase} +\newcommand{\txFrom} {\transactionSignifier\col{FROM}} +% \newcommand{\txToHi} {\transactionSignifier\col{TO\_HI}} +% \newcommand{\txToLo} {\transactionSignifier\col{TO\_LO}} +% \newcommand{\txFromHi} {\transactionSignifier\col{FROM\_HI}} +% \newcommand{\txFromLo} {\transactionSignifier\col{FROM\_LO}} +\newcommand{\txGasLimit} {\transactionSignifier\col{GAS\_LIMIT}} +\newcommand{\txGasPrice} {\transactionSignifier\col{GAS\_PRICE}} % effective_gas_price +\newcommand{\txPriorityFeePerGas} {\transactionSignifier\col{PRIORITY\_FEE\_PER\_GAS}} % priority_fee_per_gas +\newcommand{\txInitialGas} {\transactionSignifier\col{GAS\_INITIALLY\_AVAILABLE}} +\newcommand{\txInitialGasCost} {\transactionSignifier\col{GAS\_INITIAL\_COST}} +\newcommand{\txMaxFee} {\transactionSignifier\col{MAX\_FEE}} % max_fee_per_gas +\newcommand{\txMaxTip} {\transactionSignifier\col{MAX\_PRIORITY\_FEE}} % max_priority_fee_per_gas +\newcommand{\txValue} {\transactionSignifier\col{VALUE}} +\newcommand{\txIsDeployment} {\transactionSignifier\col{IS\_DEP}} +\newcommand{\txType} {\transactionSignifier\col{TYPE}} +\newcommand{\txNumPrewarmAddr} {\transactionSignifier\col{NUM\_PREWARM\_ADDR}} +\newcommand{\txNumPrewarmKeys} {\transactionSignifier\col{NUM\_PREWARM\_KEYS}} +\newcommand{\txDataSize} {\transactionSignifier\col{DATASIZE}} +\newcommand{\txCallDataSize} {\transactionSignifier\col{CALL\_DATA\_SIZE}} +\newcommand{\txInitCodeSize} {\transactionSignifier\col{INIT\_CODE\_SIZE}} +\newcommand{\txDataCost} {\transactionSignifier\col{DATACOST}} +\newcommand{\txBasefee} {\transactionSignifier\col{BASEFEE}} +\newcommand{\txFullTip} {\transactionSignifier\col{FULL\_TIP}} +\newcommand{\txTypeBit} {\transactionSignifier\col{TYPE\_BIT}} +\newcommand{\txIsLegacy} {\transactionSignifier\col{TYPE\_0}} +\newcommand{\txIsAccessSet} {\transactionSignifier\col{TYPE\_1}} +\newcommand{\txIsTypeTwo} {\transactionSignifier\col{TYPE\_2}} + + +\newcommand{\maxCtTypeZero} {\redm{6}} +\newcommand{\maxCtTypeOne} {\redm{7}} +\newcommand{\maxCtTypeTwo} {\redm{7}} + +\newcommand{\txInitialBalance} {\transactionSignifier\col{INIT\_BALANCE}} +\newcommand{\txRequiresEvmExecution} {\transactionSignifier\col{REQUIRES\_EVM\_EXECUTION}} +\newcommand{\txCopyTxcd} {\transactionSignifier\col{COPY\_TXCD}} +\newcommand{\txStatusCode} {\transactionSignifier\col{STATUS\_CODE}} +\newcommand{\txLeftoverGas} {\transactionSignifier\col{GAS\_LEFTOVER}} +\newcommand{\txFinalRefundCounter} {\transactionSignifier\col{REFUND\_COUNTER}^\infty} +\newcommand{\txEffectiveRefund} {\transactionSignifier\col{REFUND\_EFFECTIVE}} +\newcommand{\txCumulativeConsumedGas} {\transactionSignifier\col{GAS\_CUMULATIVE}} + +\newcommand{\typeZeroRows}{\redm{7}} +\newcommand{\typeOneRows}{\redm{9}} +\newcommand{\typeTwoRows}{\redm{10}} + +\newcommand{\phaseNumRlpTxn}{\col{PHASE\_RLP\_TXN}} +\newcommand{\phaseNumRlpTxnRcpt}{\col{PHASE\_RLP\_TXNRCPT}} +\newcommand{\outgoingTxrcpt}{\col{OUTGOING\_RLP\_TXRCPT}} + +\newcommand{\isLastTxOfBlock} {\col{IS\_LAST\_TX\_OF\_BLOCK}} + +\newcommand{\lineaBlockGasLimit} {\redm{\texttt{LINEA\_BLOCK\_GAS\_LIMIT}}} +\newcommand{\maxRefundQuotient} {\redm{\texttt{MAX\_REFUND\_QUOTIENT}}} diff --git a/pkg/warm.sty b/pkg/warm.sty new file mode 100644 index 0000000..b26b822 --- /dev/null +++ b/pkg/warm.sty @@ -0,0 +1,27 @@ +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +%\newcommand{}{\col{}} +\newcommand{\WARMTHSTAMP}{\col{WARMTH\_STAMP}} +\newcommand{\warmthStamp}{\col{WARM}\stamp} +\newcommand{\REVWARMTHSTAMP}{\col{REVERT\_WARMTH\_STAMP}} +\newcommand{\revWarmthStamp}{\col{WARM}\stamp\col{REV}} +\newcommand{\OPPWARMTHSTAMP}{\ula{\WARMTHSTAMP}} +\newcommand{\oppWarmthStamp}{\ula{\warmthStamp}} +% +\newcommand{\iWARMTHFLAG}{\imported{\WARMTHFLAG}} +\newcommand{\iWarmthFlag}{\imported{\warmthFlag}} +\newcommand{\iWARMTHSTAMP}{\imported{\WARMTHSTAMP}} +\newcommand{\iWarmthStamp}{\imported{\warmthStamp}} +\newcommand{\iWarm}{\imported{\warm}} +\newcommand{\iREVWARMTHSTAMP}{\imported{\REVWARMTHSTAMP}} +\newcommand{\iRevWarmthStamp}{\imported{\revWarmthStamp}} + +\newcommand{\domStamp}{\ura{\col{DOM}\stamp}} +\newcommand{\subStamp}{\ula{\col{SUB}\stamp}} \ No newline at end of file diff --git a/pkg/wc.sty b/pkg/wc.sty new file mode 100644 index 0000000..2ec52a9 --- /dev/null +++ b/pkg/wc.sty @@ -0,0 +1,131 @@ +% WORD COMPARISON module +\newcommand{\CT}{\col{COUNTER}} +\newcommand{\ct}{\col{CT}} +\newcommand{\WCTS}{\col{WC\_TIME\_STAMP}} +\newcommand{\wcts}{\col{WCTS}} +\newcommand{\SWF}{\col{SWITCH\_FLAG}} +\newcommand{\swf}{\col{SF}} +\newcommand{\EQF}{\col{EQ\_FLAG}} +\newcommand{\eqf}{\col{EQF}} +% comp +\newcommand{\CMPH}{\col{COMP}\HIGH} +\newcommand{\cmph}{\col{CMP}\high} +\newcommand{\CMPL}{\col{COMP}\LOW} +\newcommand{\cmpl}{\col{CMP}\low} +\newcommand{\CMP}{\col{COMP}} +\newcommand{\cmp}{\col{CMP}} +% eq +\newcommand{\EQH}{\col{EQ}\HIGH} +\newcommand{\EQL}{\col{EQ}\LOW} +\newcommand{\EQ}{\col{EQ}} +\newcommand{\eqh}{\col{EQ}\high} +\newcommand{\eql}{\col{EQ}\low} +\newcommand{\eq}{\col{EQ}} +% +\newcommand{\R}{\col{RES}} +% inputs +\newcommand{\IO}{\col{INPUT\_1}} +\newcommand{\IT}{\col{INPUT\_2}} +% input 1 high +\newcommand{\IOH}{\col{INPUT\_1}\HIGH} +\newcommand{\ioh}{\col{I1}\high} +\newcommand{\BOH}{\col{BYTE\_1}\HIGH} +\newcommand{\boh}{\col{B1}\high} +\newcommand{\POH}{\col{PREFIX\_1}\HIGH} +\newcommand{\poh}{\col{P1}\high} +% input 1 low +\newcommand{\IOL}{\col{INPUT\_1}\LOW} +\newcommand{\iol}{\col{I1}\low} +\newcommand{\BOL}{\col{BYTE\_1}\LOW} +\newcommand{\bol}{\col{B1}\low} +\newcommand{\POL}{\col{PREFIX\_1}\LOW} +\newcommand{\pol}{\col{P1}\low} +% input 2 high +\newcommand{\ITH}{\col{INPUT\_2}\HIGH} +\newcommand{\ith}{\col{I2}\high} +\newcommand{\BTH}{\col{BYTE\_2}\HIGH} +\newcommand{\bth}{\col{B2}\high} +\newcommand{\PTH}{\col{PREFIX\_2}\HIGH} +\newcommand{\pth}{\col{P2}\high} +% input 2 low +\newcommand{\ITL}{\col{INPUT\_2}\LOW} +\newcommand{\itl}{\col{I2}\low} +\newcommand{\BTL}{\col{BYTE\_2}\LOW} +\newcommand{\btl}{\col{B2}\low} +\newcommand{\PTL}{\col{PREFIX\_2}\LOW} +\newcommand{\ptl}{\col{P2}\low} +% delta high +\newcommand{\Dh}{\Delta\high} +\newcommand{\BDH}{BYTES\_\Delta\HIGH} +\newcommand{\PDH}{PREFIX\_\Delta\HIGH} +\newcommand{\bdh}{B\Delta\high} +\newcommand{\pdh}{P\Delta\high} +% delta low +\newcommand{\Dl}{\Delta\low} +\newcommand{\BDL}{BYTES\_\Delta\LOW} +\newcommand{\PDL}{PREFIX\_\Delta\LOW} +\newcommand{\bdl}{B\Delta\low} +\newcommand{\pdl}{P\Delta\low} + +\newcommand{\INST}{\col{INST}} + +\newcommand{\bit}[1]{[\![#1]\!]} +\newcommand{\negbit}[1]{\bit{#1}^\vee} + +\newcommand{\HIGH}{\col{\_HIGH}} +\newcommand{\LOW}{\col{\_LOW}} +\newcommand{\high}{^\col{\,hi}} +\newcommand{\low}{^\col{\,lo}} + +\newcommand{\LT}{\inst{LT}} +\newcommand{\GT}{\inst{GT}} +\newcommand{\SLT}{\inst{SLT}} +\newcommand{\SGT}{\inst{SGT}} + +\newcommand{\met}{\col{MET}} +\newcommand{\rom}{\col{ROM}} +\newcommand{\adr}{\col{Addr}} +\newcommand{\key}{\col{Key}} + + +\def\leftCol{gray!60} +\def\rightCol{gray!10} + +\newcommand{\shadedRect}[1]{ + \draw[ + shading = axis, + rectangle, + left color=\leftCol, + right color=\rightCol, + %shading angle=135, + %anchor=north, + %minimum width=\paperwidth, + %minimum height=5.5cm, + ] (#1 + #1 + #1 + 0.05,0) rectangle (3 - 0.05 + #1 + #1 + #1,0.5) +} + +\def\CTcycle{ + \!\!\!\! + \begin{array}{|c|c|c|c|c|c|c|} + \hline + 15&14&\cdots&2&1&0\\ + \hline + \end{array} +} + +\def\CTcycles{ + \begin{array}{% + |c|c|c|c|c|c||% + c|c|c|c|c|c||% + %c|c|c|c|c|c||% + c||% + c|c|c|c|c|c|} + \hline + \redm{15}&14&\cdots&2&1&0& + \redm{15}&14&\cdots&2&1&0& + %\bm{15}&14&\cdots&2&1&0& + \qquad\phantom{\Big|}\cdots\phantom{\Big|}\qquad& + \redm{15}&14&\cdots&2&1&0\\ + \hline + \end{array} +} \ No newline at end of file diff --git a/pkg/wc2.sty b/pkg/wc2.sty new file mode 100644 index 0000000..157597e --- /dev/null +++ b/pkg/wc2.sty @@ -0,0 +1,152 @@ +% WORD COMPARISON module +\newcommand{\CT}{\col{COUNTER}} +\newcommand{\ct}{\col{CT}} +\newcommand{\MI}{\col{MODULE\_INDEX}} % with values in {0, 1, 2} +\newcommand{\mi}{\col{MI}} % with values in {0, 1, 2} +\newcommand{\metn}{\col{NMET}} % number of the instruction of that module +\newcommand{\romn}{\col{NROM}} % number of the instruction of that module +\newcommand{\ston}{\col{NSTO}} % number of the instruction of that module +\newcommand{\WCTS}{\col{WC\_TIME\_STAMP}} +\newcommand{\wcts}{\col{WCTS}} +\newcommand{\SWF}{\col{SWITCH\_FLAG}} +\newcommand{\swf}{\col{SWF}} +\newcommand{\EQF}{\col{EQ\_FLAG}} +\newcommand{\eqf}{\col{EQF}} +% comp +\newcommand{\CMPH}{\col{COMP}\HIGH} +\newcommand{\cmph}{\col{CMP}\high} +\newcommand{\CMPL}{\col{COMP}\LOW} +\newcommand{\cmpl}{\col{CMP}\low} +\newcommand{\CMP}{\col{COMP}} +\newcommand{\cmp}{\col{CMP}} +% eq +\newcommand{\EQH}{\col{EQ}\HIGH} +\newcommand{\EQL}{\col{EQ}\LOW} +\newcommand{\EQ}{\col{EQ}} +\newcommand{\eqh}{\col{EQ}\high} +\newcommand{\eql}{\col{EQ}\low} +\newcommand{\eq}{\col{EQ}} +% +\newcommand{\R}{\col{RES}} +% inputs +\newcommand{\IO}{\col{INPUT\_1}} +\newcommand{\IT}{\col{INPUT\_2}} +% input 1 high +\newcommand{\IOH}{\col{INPUT\_1}\HIGH} +\newcommand{\ioh}{\col{I1}\high} +\newcommand{\BOH}{\col{BYTE\_1}\HIGH} +\newcommand{\boh}{\col{B1}\high} +\newcommand{\POH}{\col{PREFIX\_1}\HIGH} +\newcommand{\poh}{\col{P1}\high} +% input 1 low +\newcommand{\IOL}{\col{INPUT\_1}\LOW} +\newcommand{\iol}{\col{I1}\low} +\newcommand{\BOL}{\col{BYTE\_1}\LOW} +\newcommand{\bol}{\col{B1}\low} +\newcommand{\POL}{\col{PREFIX\_1}\LOW} +\newcommand{\pol}{\col{P1}\low} +% input 2 high +\newcommand{\ITH}{\col{INPUT\_2}\HIGH} +\newcommand{\ith}{\col{I2}\high} +\newcommand{\BTH}{\col{BYTE\_2}\HIGH} +\newcommand{\bth}{\col{B2}\high} +\newcommand{\PTH}{\col{PREFIX\_2}\HIGH} +\newcommand{\pth}{\col{P2}\high} +% input 2 low +\newcommand{\ITL}{\col{INPUT\_2}\LOW} +\newcommand{\itl}{\col{I2}\low} +\newcommand{\BTL}{\col{BYTE\_2}\LOW} +\newcommand{\btl}{\col{B2}\low} +\newcommand{\PTL}{\col{PREFIX\_2}\LOW} +\newcommand{\ptl}{\col{P2}\low} +% delta high +\renewcommand{\DH}{\Delta\col{\_HIGH}} +\renewcommand{\dh}{\Delta\high} +\newcommand{\BDH}{\col{BYTES}\_\Delta\HIGH} +\newcommand{\PDH}{\col{PREFIX}\_\Delta\HIGH} +\newcommand{\bdh}{\col{B}\Delta\high} +\newcommand{\pdh}{\col{P}\Delta\high} +% delta low +\newcommand{\DL}{\Delta\col{\_LOW}} +\newcommand{\dl}{\Delta\low} +\newcommand{\BDL}{\col{BYTES}\_\Delta\LOW} +\newcommand{\PDL}{\col{PREFIX}\_\Delta\LOW} +\newcommand{\bdl}{\col{B}\Delta\low} +\newcommand{\pdl}{\col{P}\Delta\low} +% MET imported inputs +\newcommand{\iometh}{\met\_\col{1}\high} +\newcommand{\iometl}{\met\_\col{1}\low} +\newcommand{\itmeth}{\met\_\col{2}\high} +\newcommand{\itmetl}{\met\_\col{2}\low} +% MET imported inputs +\newcommand{\romh}{\rom\high} +\newcommand{\roml}{\rom\low} +% MET imported inputs +\newcommand{\addrh}{\col{ADDR}\high} +\newcommand{\addrl}{\col{ADDR}\low} +\newcommand{\keyh}{\col{KEY}\high} +\newcommand{\keyl}{\col{KEY}\low} + +\newcommand{\INST}{\col{INST}} + +\newcommand{\bit}[1]{[\![#1]\!]} +\newcommand{\negbit}[1]{\bit{#1}^\vee} + +\newcommand{\HIGH}{\col{\_HIGH}} +\newcommand{\LOW}{\col{\_LOW}} +\newcommand{\high}{^\col{\,hi}} +\newcommand{\low}{^\col{\,lo}} + +\newcommand{\LT}{\inst{LT}} +\newcommand{\GT}{\inst{GT}} +\newcommand{\SLT}{\inst{SLT}} +\newcommand{\SGT}{\inst{SGT}} + +\newcommand{\met}{\col{MET}} +\newcommand{\rom}{\col{ROM}} +\newcommand{\sto}{\col{STO}} +\newcommand{\adr}{\col{Addr}} +\newcommand{\key}{\col{Key}} + + +\def\leftCol{gray!60} +\def\rightCol{gray!10} + +\newcommand{\shadedRect}[1]{ + \draw[ + shading = axis, + rectangle, + left color=\leftCol, + right color=\rightCol, + %shading angle=135, + %anchor=north, + %minimum width=\paperwidth, + %minimum height=5.5cm, + ] (#1 + #1 + #1 + 0.05,0) rectangle (3 - 0.05 + #1 + #1 + #1,0.5) +} + +\def\CTcycle{ + \!\!\!\! + \begin{array}{|c|c|c|c|c|c|c|} + \hline + 15&14&\cdots&2&1&0\\ + \hline + \end{array} +} + +\def\CTcycles{ + \begin{array}{% + |c|c|c|c|c|c||% + c|c|c|c|c|c||% + %c|c|c|c|c|c||% + c||% + c|c|c|c|c|c|} + \hline + \redm{15}&14&\cdots&2&1&0& + \redm{15}&14&\cdots&2&1&0& + %\bm{15}&14&\cdots&2&1&0& + \qquad\phantom{\Big|}\cdots\phantom{\Big|}\qquad& + \redm{15}&14&\cdots&2&1&0\\ + \hline + \end{array} +} \ No newline at end of file diff --git a/pkg/wc3.sty b/pkg/wc3.sty new file mode 100644 index 0000000..e9c7e35 --- /dev/null +++ b/pkg/wc3.sty @@ -0,0 +1,60 @@ +\newcommand{\OLI} {\col{ONE\_LINE\_INSTRUCTION}} +\newcommand{\oli} {\col{OLI}} +\newcommand{\MLI} {\col{MULTI\_LINE\_INSTRUCTION}} +\newcommand{\mli} {\col{MLI}} +\newcommand{\VLI} {\col{VARIABLE\_LENGTH\_INSTRUCTION}} +\newcommand{\vli} {\col{VLI}} +\newcommand{\ARGONEHI} {\col{ARGUMENT\_1\_HIGH}} +\newcommand{\ARGONELO} {\col{ARGUMENT\_1\_LOW}} +\newcommand{\ARGTWOHI} {\col{ARGUMENT\_2\_HIGH}} +\newcommand{\ARGTWOLO} {\col{ARGUMENT\_2\_LOW}} +\newcommand{\ARGTREHI} {\col{ARGUMENT\_3\_HIGH}} +\newcommand{\ARGTRELO} {\col{ARGUMENT\_3\_LOW}} +\newcommand{\RESHI} {\col{RESULT\_HIGH}} +\newcommand{\RESLO} {\col{RESULT\_LOW}} +\renewcommand{\arg} {\col{ARG}} +\newcommand{\argOne} {\arg\col{1}} +\newcommand{\argTwo} {\arg\col{2}} +\newcommand{\argTre} {\arg\col{3}} +\newcommand{\res} {\col{RES}} +\newcommand{\iArgOne} {\imported{\argOne}} +\newcommand{\iArgTwo} {\imported{\argTwo}} +\newcommand{\iArgTre} {\imported{\argTre}} +\newcommand{\argHi} {\arg\col{\_HI}} +\newcommand{\argLo} {\arg\col{\_LO}} +\newcommand{\argOneHi} {\argOne\col{\_HI}} +\newcommand{\argOneLo} {\argOne\col{\_LO}} +\newcommand{\argTwoHi} {\argTwo\col{\_HI}} +\newcommand{\argTwoLo} {\argTwo\col{\_LO}} +\newcommand{\argTreHi} {\argTre\col{\_HI}} +\newcommand{\argTreLo} {\argTre\col{\_LO}} +\newcommand{\resHi} {\res\col{\_HI}} +\newcommand{\resLo} {\res\col{\_LO}} + +\newcommand{\isLt} {\col{IS\_LT}} +\newcommand{\isGt} {\col{IS\_GT}} +\newcommand{\isSlt} {\col{IS\_SLT}} +\newcommand{\isSgt} {\col{IS\_SGT}} +\newcommand{\isEq} {\col{IS\_EQ}} +\newcommand{\isIszero} {\col{IS\_ISZERO}} +\newcommand{\isGeq} {\col{IS\_GEQ}} +\newcommand{\isLeq} {\col{IS\_LEQ}} + +\newcommand{\iARGONEHI} {\imported{\ARGONEHI}} +\newcommand{\iARGONELO} {\imported{\ARGONELO}} +\newcommand{\iARGTWOHI} {\imported{\ARGTWOHI}} +\newcommand{\iARGTWOLO} {\imported{\ARGTWOLO}} +\newcommand{\iARGTREHI} {\imported{\ARGTREHI}} +\newcommand{\iARGTRELO} {\imported{\ARGTRELO}} +\newcommand{\iRESHI} {\imported{\RESHI}} +\newcommand{\iRESLO} {\imported{\RESLO}} +\newcommand{\iArgOneHi} {\imported{\argOneHi}} +\newcommand{\iArgOneLo} {\imported{\argOneLo}} +\newcommand{\iArgTwoHi} {\imported{\argTwoHi}} +\newcommand{\iArgTwoLo} {\imported{\argTwoLo}} +\newcommand{\iArgTreHi} {\imported{\argTreHi}} +\newcommand{\iArgTreLo} {\imported{\argTreLo}} +\newcommand{\iRes} {\imported{\res}} +\newcommand{\iResHi} {\imported{\resHi}} +\newcommand{\iResLo} {\imported{\resLo}} + diff --git a/pkg/xkeyval_macros/context.sty b/pkg/xkeyval_macros/context.sty new file mode 100644 index 0000000..821e529 --- /dev/null +++ b/pkg/xkeyval_macros/context.sty @@ -0,0 +1,179 @@ +\makeatletter + +\define@cmdkey [CONTEXT] {var} {anchorRow} {} +\define@cmdkey [CONTEXT] {var} {relOffset} {} +\define@cmdkey [CONTEXT] {var} {contextNumber} {} +\define@cmdkey [CONTEXT] {var} {callDataContext} {} +\define@cmdkey [CONTEXT] {var} {callStackDepth} {} +\define@cmdkey [CONTEXT] {var} {isRoot} {} +\define@cmdkey [CONTEXT] {var} {isStatic} {} +\define@cmdkey [CONTEXT] {var} {accountAddressHigh} {} +\define@cmdkey [CONTEXT] {var} {accountAddressLow} {} +\define@cmdkey [CONTEXT] {var} {accountDeploymentNumber} {} +\define@cmdkey [CONTEXT] {var} {byteCodeAddressHi} {} +\define@cmdkey [CONTEXT] {var} {byteCodeAddressLo} {} +\define@cmdkey [CONTEXT] {var} {byteCodeDeploymentNumber} {} +\define@cmdkey [CONTEXT] {var} {byteCodeDeploymentStatus} {} +\define@cmdkey [CONTEXT] {var} {byteCodeCodeFragmentIndex} {} +\define@cmdkey [CONTEXT] {var} {callerAddressHi} {} +\define@cmdkey [CONTEXT] {var} {callerAddressLo} {} +\define@cmdkey [CONTEXT] {var} {callValue} {} +\define@cmdkey [CONTEXT] {var} {callDataContextNumber} {} +\define@cmdkey [CONTEXT] {var} {callDataOffset} {} +\define@cmdkey [CONTEXT] {var} {callDataSize} {} +\define@cmdkey [CONTEXT] {var} {returnAtOffset} {} +\define@cmdkey [CONTEXT] {var} {returnAtCapacity} {} +\define@cmdkey [CONTEXT] {var} {initializationParameters} {} +\define@cmdkey [CONTEXT] {var} {relOffset} {} +\define@cmdkey [CONTEXT] {var} {returnDataReceiver} {} +\define@cmdkey [CONTEXT] {var} {returnDataProvider} {} +\define@cmdkey [CONTEXT] {var} {returnDataOffset} {} +\define@cmdkey [CONTEXT] {var} {returnDataSize} {} + + +\presetkeys [CONTEXT] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + contextNumber = \missingParameter, + callStackDepth = \missingParameter, + isRoot = \missingParameter, + isStatic = \missingParameter, + accountAddressHigh = \missingParameter, + accountAddressLow = \missingParameter, + accountDeploymentNumber = \missingParameter, + byteCodeAddressHi = \missingParameter, + byteCodeAddressLo = \missingParameter, + byteCodeDeploymentNumber = \missingParameter, + byteCodeDeploymentStatus = \missingParameter, + byteCodeCodeFragmentIndex = \missingParameter, + callerAddressHi = \missingParameter, + callerAddressLo = \missingParameter, + callValue = \missingParameter, + callDataContextNumber = \missingParameter, + callDataOffset = \missingParameter, + callDataSize = \missingParameter, + returnAtOffset = \missingParameter, + returnAtCapacity = \missingParameter, + initializationParameters = \missingParameter, + relOffset = \missingParameter, + returnDataReceiver = \missingParameter, + returnDataProvider = \missingParameter, + returnDataOffset = \missingParameter, + returnDataSize = \missingParameter, +}{} + +% \cmdCONTEXT@var@contextNumber +% \cmdCONTEXT@var@callStackDepth +% \cmdCONTEXT@var@isRoot +% \cmdCONTEXT@var@isStatic +% \cmdCONTEXT@var@accountAddressHigh +% \cmdCONTEXT@var@accountAddressLow +% \cmdCONTEXT@var@accountDeploymentNumber +% \cmdCONTEXT@var@byteCodeAddressHi +% \cmdCONTEXT@var@byteCodeAddressLo +% \cmdCONTEXT@var@byteCodeDeploymentNumber +% \cmdCONTEXT@var@byteCodeDeploymentStatus +% \cmdCONTEXT@var@byteCodeCodeFragmentIndex +% \cmdCONTEXT@var@callerAddressHi +% \cmdCONTEXT@var@callerAddressLo +% \cmdCONTEXT@var@callValue +% \cmdCONTEXT@var@callDataContextNumber +% \cmdCONTEXT@var@callDataOffset +% \cmdCONTEXT@var@callDataSize +% \cmdCONTEXT@var@returnAtOffset +% \cmdCONTEXT@var@returnAtCapacity + +% anchorRow = , +% relOffset = , +% contextNumber = , +% callStackDepth = , +% isRoot = , +% isStatic = , +% accountAddressHigh = , +% accountAddressLow = , +% accountDeploymentNumber = , +% byteCodeAddressHi = , +% byteCodeAddressLo = , +% byteCodeDeploymentNumber = , +% byteCodeDeploymentStatus = , +% byteCodeCodeFragmentIndex = , +% callerAddressHi = , +% callerAddressLo = , +% callValue = , +% callDataContextNumber = , +% callDataOffset = , +% callDataSize = , +% returnAtOffset = , +% returnAtCapacity = , + +% misc CONTEXT instructions +\newcommand{\initializeContextName} {\texttt{initializeContext}} +\newcommand{\initializeContext} [1] { + \setkeys[CONTEXT]{var}{#1} + \initializeContextName _{\cmdCONTEXT@var@anchorRow} + \left[ \begin{array}{llr} + \utt{Rel. row offset:} & \cmdCONTEXT@var@relOffset \\ + \utt{Context number:} & \cmdCONTEXT@var@contextNumber \\ + \utt{Call stack depth:} & \cmdCONTEXT@var@callStackDepth \\ + \utt{Is root context:} & \cmdCONTEXT@var@isRoot \\ + \utt{Is static context:} & \cmdCONTEXT@var@isStatic \\ + \utt{Account address high:} & \cmdCONTEXT@var@accountAddressHigh \\ + \utt{Account address low:} & \cmdCONTEXT@var@accountAddressLow \\ + \utt{Account deployment number:} & \cmdCONTEXT@var@accountDeploymentNumber \\ + \utt{Byte code address high:} & \cmdCONTEXT@var@byteCodeAddressHi \\ + \utt{Byte code address low:} & \cmdCONTEXT@var@byteCodeAddressLo \\ + \utt{Byte code deployment number:} & \cmdCONTEXT@var@byteCodeDeploymentNumber \\ + \utt{Byte code deployment status:} & \cmdCONTEXT@var@byteCodeDeploymentStatus \\ + \utt{Byte code code fragment index:} & \cmdCONTEXT@var@byteCodeCodeFragmentIndex \\ + \utt{Caller address high:} & \cmdCONTEXT@var@callerAddressHi \\ + \utt{Caller address low:} & \cmdCONTEXT@var@callerAddressLo \\ + \utt{Call value:} & \cmdCONTEXT@var@callValue \\ + \utt{Call data context number:} & \cmdCONTEXT@var@callDataContextNumber \\ + \utt{Call data offset:} & \cmdCONTEXT@var@callDataOffset \\ + \utt{Call data size:} & \cmdCONTEXT@var@callDataSize \\ + \utt{Return at offset:} & \cmdCONTEXT@var@returnAtOffset \\ + \utt{Return at capacity:} & \cmdCONTEXT@var@returnAtCapacity \\ + % \utt{returner context:} & 0 \\ + % \utt{return data offset:} & 0 \\ + % \utt{return data size:} & 0 \\ + \end{array} \right] + } + +\newcommand{\initializeCalleeContextName} {\texttt{initializeCalleeContext}} +\newcommand{\initializeCalleeContext} [1] { + \setkeys[CONTEXT]{var}{#1} + \initializeCalleeContextName + _{\cmdCONTEXT@var@anchorRow} + \left[ \begin{array}{llr} + \utt{Rel. row offset:} & \cmdCONTEXT@var@relOffset \\ + \utt{Parameters:} & \cmdCONTEXT@var@initializationParameters \\ + \end{array} \right] +} + +\newcommand{\initializeDeploymentContext} [2] {\texttt{initializeDeploymentContext}_{#1} \big[\, #2 \,\big]} + + +\newcommand{\provideReturnDataName} {\contextSignifier\texttt{provideReturnData}} +\newcommand{\provideReturnData} [1] { + \setkeys[CONTEXT]{var}{#1} + \provideReturnDataName + _{\cmdCONTEXT@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdCONTEXT@var@relOffset \\ + \utt{Return data receiver:} & \cmdCONTEXT@var@returnDataReceiver \\ + \utt{Return data provider:} & \cmdCONTEXT@var@returnDataProvider \\ + \utt{Return data offset:} & \cmdCONTEXT@var@returnDataOffset \\ + \utt{Return data size:} & \cmdCONTEXT@var@returnDataSize \\ + \end{array} \right] +} + +% \provideReturnData { +% anchorRow = , +% relOffset = , +% returnDataReceiver = , +% returnDataProvider = , +% returnDataOffset = , +% returnDataSize = , +% } + +\makeatother diff --git a/pkg/xkeyval_macros/dom_sub_stamps.sty b/pkg/xkeyval_macros/dom_sub_stamps.sty new file mode 100644 index 0000000..a305cbf --- /dev/null +++ b/pkg/xkeyval_macros/dom_sub_stamps.sty @@ -0,0 +1,109 @@ +\makeatletter + +\define@cmdkey [DOMSUB] {var} {anchorRow} {} +\define@cmdkey [DOMSUB] {var} {relOffset} {} +\define@cmdkey [DOMSUB] {var} {domOffset} {} +\define@cmdkey [DOMSUB] {var} {subOffset} {} +\define@cmdkey [DOMSUB] {var} {revertStamp} {} +\define@cmdkey [DOMSUB] {var} {childRevertStamp} {} + + +\presetkeys [DOMSUB] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + revertStamp = \missingParameter, + childRevertStamp = \missingParameter, + domOffset = \missingParameter, + subOffset = \missingParameter, +}{} + +% \cmdDOMSUB@var@anchorRow +% \cmdDOMSUB@var@relOffset +% \cmdDOMSUB@var@domOffset +% \cmdDOMSUB@var@subOffset +% \cmdDOMSUB@var@revertStamp +% \cmdDOMSUB@var@childRevertStamp + +% anchorRow = , +% relOffset = , +% domOffset = , +% subOffset = , +% revertStamp = , +% childRevertStamp = , + +% \standardDomSubStamps { +% anchorRow = , +% relOffset = , +% domOffset = , +% } + +\newcommand{\standardDomSubStampsName} {\stampSignifier\texttt{standardDomSubStamps}} +\newcommand{\standardDomSubStamps} [1] { + \setkeys[DOMSUB]{var}{#1} + \standardDomSubStampsName _{\cmdDOMSUB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdDOMSUB@var@relOffset \\ + \utt{Dom offset:} & \cmdDOMSUB@var@domOffset \\ + \end{array} \right] +} + +\newcommand{\genericUndoingDomSubStampsName} {\stampSignifier\texttt{genericUndoingDomSubStamps}} +\newcommand{\genericUndoingDomSubStamps} [1] { + \setkeys[DOMSUB]{var}{#1} + \genericUndoingDomSubStampsName _{\cmdDOMSUB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdDOMSUB@var@relOffset \\ + \utt{Revert stamp:} & \cmdDOMSUB@var@revertStamp \\ + \utt{Dom offset:} & \cmdDOMSUB@var@domOffset \\ + \utt{Sub offset:} & \cmdDOMSUB@var@subOffset \\ + \end{array} \right] +} + +% \genericUndoingDomSubStamps { +% anchorRow = , +% relOffset = , +% revertStamp = , +% domOffset = , +% subOffset = , +% } + +\newcommand{\revertDomSubStampsName} {\stampSignifier\texttt{revertDomSubStamps}} +\newcommand{\revertDomSubStamps} [1] { + \setkeys[DOMSUB]{var}{#1} + \revertDomSubStampsName _{\cmdDOMSUB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdDOMSUB@var@relOffset \\ + \utt{Sub offset:} & \cmdDOMSUB@var@subOffset \\ + \end{array} \right] +} + +% \revertDomSubStamps { +% anchorRow = , +% relOffset = , +% subOffset = , +% } + +\newcommand{\revertWithChildFailureDomSubStampsName} {\stampSignifier\texttt{revertWithChildFailureDomSubStamps}} +\newcommand{\revertWithChildFailureDomSubStamps} [1] { + \setkeys[DOMSUB]{var}{#1} + \revertWithChildFailureDomSubStampsName _{\cmdDOMSUB@var@anchorRow} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdDOMSUB@var@relOffset \\ + \utt{Child revert stamp:} & \cmdDOMSUB@var@childRevertStamp \\ + \utt{Sub offset:} & \cmdDOMSUB@var@subOffset \\ +\end{array} \right] +} + +% \revertWithChildFailureDomSubStamps { +% anchorRow = , +% relOffset = , +% childRevertStamp = , +% subOffset = , +% } + + % \stampSignifier\texttt{childContextRevertsDomSubStamps} _{#1} \big[ #2 \big] \big[ #3, #4 \big]} +\newcommand{\selfdestructDomSubStamps} [2] {\stampSignifier\texttt{selfdestructDomSubStamps} _{#1} \big[\utt{Rel. row offset:} ~ #2\big]} + +\newcommand{\zeroDomSubStamps} [2] {\stampSignifier\texttt{zeroDomSubStamps} _{#1} \big[\utt{Rel. row offset:} ~ #2\big]} + +\makeatother diff --git a/pkg/xkeyval_macros/ext_calls.sty b/pkg/xkeyval_macros/ext_calls.sty new file mode 100644 index 0000000..be47891 --- /dev/null +++ b/pkg/xkeyval_macros/ext_calls.sty @@ -0,0 +1,58 @@ +\makeatletter +% DEFINING KEYS + +\define@cmdkey [EXT] {var} {anchorRow} {} % "i" in the spec, ALWAYS use this name +\define@cmdkey [EXT] {var} {relOffset} {} % relative offset, ALWAYS use this name +\define@cmdkey [EXT] {var} {argOneHi} {} +\define@cmdkey [EXT] {var} {argOneLo} {} +\define@cmdkey [EXT] {var} {argTwoHi} {} +\define@cmdkey [EXT] {var} {argTwoLo} {} +\define@cmdkey [EXT] {var} {argThreeHi} {} +\define@cmdkey [EXT] {var} {argThreeLo} {} +% the above defines macros à la "\cmdEXT@var@anchorRow" + +% DEFAULT VALUES +\presetkeys [EXT] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + argOneHi = \missingParameter, + argOneLo = \missingParameter, + argTwoHi = \missingParameter, + argTwoLo = \missingParameter, + argThreeHi = \missingParameter, + argThreeLo = \missingParameter +}{} + +% "call to ADDMOD" macro +\newcommand{\extCallToAddModName} {\texttt{extCallToADDMOD}} +\newcommand{\extCallToAddMod} [1] { + \setkeys[EXT]{var}{#1} + \extCallToAddModName _{\cmdEXT@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdEXT@var@relOffset \\ + \utt{First argument (high):} & \cmdEXT@var@argOneHi \\ + \utt{First argument (low):} & \cmdEXT@var@argOneLo \\ + \utt{Second argument (high):} & \cmdEXT@var@argTwoHi \\ + \utt{Second argument (low):} & \cmdEXT@var@argTwoLo \\ + \utt{Third argument (high):} & \cmdEXT@var@argThreeHi \\ + \utt{Third argument (low):} & \cmdEXT@var@argThreeLo \\ + \end{array} \right] +} + +% "call to MULLMOD" macro +\newcommand{\extCallToMulModName} {\texttt{extCallToMULMOD}} +\newcommand{\extCallToMulMod} [1] { + \setkeys[EXT]{var}{#1} + \extCallToMulModName _{\cmdEXT@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdEXT@var@relOffset \\ + \utt{First argument (high):} & \cmdEXT@var@argOneHi \\ + \utt{First argument (low):} & \cmdEXT@var@argOneLo \\ + \utt{Second argument (high):} & \cmdEXT@var@argTwoHi \\ + \utt{Second argument (low):} & \cmdEXT@var@argTwoLo \\ + \utt{Third argument (high):} & \cmdEXT@var@argThreeHi \\ + \utt{Third argument (low):} & \cmdEXT@var@argThreeLo \\ + \end{array} \right] +} + +\makeatother diff --git a/pkg/xkeyval_macros/mmu_instructions.sty b/pkg/xkeyval_macros/mmu_instructions.sty new file mode 100644 index 0000000..10656ad --- /dev/null +++ b/pkg/xkeyval_macros/mmu_instructions.sty @@ -0,0 +1,503 @@ +\makeatletter + +\define@cmdkey [MMU] {var} {anchorRow} {} +\define@cmdkey [MMU] {var} {relOffset} {} +\define@cmdkey [MMU] {var} {mmuInstruction} {} +\define@cmdkey [MMU] {var} {sourceId} {} +\define@cmdkey [MMU] {var} {targetId} {} +\define@cmdkey [MMU] {var} {auxiliaryId} {} +\define@cmdkey [MMU] {var} {sourceOffsetHi} {} +\define@cmdkey [MMU] {var} {sourceOffsetLo} {} +\define@cmdkey [MMU] {var} {targetOffsetLo} {} +\define@cmdkey [MMU] {var} {size} {} +\define@cmdkey [MMU] {var} {referenceOffset} {} +\define@cmdkey [MMU] {var} {referenceSize} {} +\define@cmdkey [MMU] {var} {successBit} {} +\define@cmdkey [MMU] {var} {limbOne} {} +\define@cmdkey [MMU] {var} {limbTwo} {} +\define@cmdkey [MMU] {var} {exoSum} {} +\define@cmdkey [MMU] {var} {phase} {} + +\presetkeys [MMU] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + mmuInstruction = \missingParameter, + sourceId = \missingParameter, + targetId = \missingParameter, + auxiliaryId = \missingParameter, + sourceOffsetHi = \missingParameter, + sourceOffsetLo = \missingParameter, + targetOffsetLo = \missingParameter, + size = \missingParameter, + referenceOffset = \missingParameter, + referenceSize = \missingParameter, + successBit = \missingParameter, + limbOne = \missingParameter, + limbTwo = \missingParameter, + exoSum = \missingParameter, + phase = \missingParameter, +}{} + +% misc MMU instructions +\newcommand{\setMmuInstructionName} {\miscSignifier\texttt{setMmuInstruction}} +\newcommand{\setMmuInstructionParametersMloadName} {\setMmuInstructionName\texttt{Mload}} +\newcommand{\setMmuInstructionParametersMstoreName} {\setMmuInstructionName\texttt{Mstore}} +\newcommand{\setMmuInstructionParametersMstoreEightName} {\setMmuInstructionName\texttt{Mstore8}} +\newcommand{\setMmuInstructionParametersInvalidCodePrefixName} {\setMmuInstructionName\texttt{InvalidCodePrefix}} +\newcommand{\setMmuInstructionParametersRightPaddedWordExtractionName} {\setMmuInstructionName\texttt{RightPaddedWordExtraction}} +\newcommand{\setMmuInstructionParametersRamToExoWithPaddingName} {\setMmuInstructionName\texttt{RamToExoWithPadding}} +\newcommand{\setMmuInstructionParametersExoToRamTransplantsName} {\setMmuInstructionName\texttt{ExoToRamTransplants}} +\newcommand{\setMmuInstructionParametersRamToRamSansPaddingName} {\setMmuInstructionName\texttt{RamToRamSansPadding}} +\newcommand{\setMmuInstructionParametersAnyToRamWithPaddingName} {\setMmuInstructionName\texttt{AnyToRamWithPadding}} +\newcommand{\setMmuInstructionParametersModexpZeroName} {\setMmuInstructionName\texttt{ModexpZero}} +\newcommand{\setMmuInstructionParametersModexpDataName} {\setMmuInstructionName\texttt{ModexpData}} +\newcommand{\setMmuInstructionParametersBlakeName} {\setMmuInstructionName\texttt{Blake}} + +% misc MMU instructions +\newcommand{\setMmuInstruction} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionName + _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + \utt{Size:} & \cmdMMU@var@size \\ + \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + \utt{Success bit:} & \cmdMMU@var@successBit \\ + \utt{Limb one:} & \cmdMMU@var@limbOne \\ + \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstruction{ +% anchorRow = , +% relOffset = , +% mmuInstruction = , +% sourceId = , +% targetId = , +% auxiliaryId = , +% sourceOffsetHi = , +% sourceOffsetLo = , +% targetOffsetLo = , +% size = , +% referenceOffset = , +% referenceSize = , +% successBit = , +% limbOne = , +% limbTwo = , +% exoSum = , +% phase = , +% } + +\newcommand{\setMmuInstructionParametersMload} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersMloadName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + % \utt{Target ID:} & \col{tgt\_id} \\ + % \utt{Auxiliary ID:} & \col{aux\_id} \\ + % \utt{Source offset high:} & \col{src\_offset\_hi} \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \col{tgt\_offset\_lo} \\ + % \utt{Size:} & \col{size} \\ + % \utt{Reference offset:} & \col{ref\_offset} \\ + % \utt{Reference size:} & \col{ref\_size} \\ + % \utt{Success bit:} & \col{success\_bit} \\ + \utt{Limb one:} & \cmdMMU@var@limbOne \\ + \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \col{exo\_sum} \\ + % \utt{Phase:} & \col{phase} \\ + \end{array} \right] + } + +% \setMmuInstructionParametersMload { +% anchorRow = , +% relOffset = , +% sourceId = , +% sourceOffsetLo = , +% limbOne = , +% limbTwo = , +% } + +\newcommand{\setMmuInstructionParametersMstore} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersMstoreName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + % \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + % \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + % \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + \utt{Limb one:} & \cmdMMU@var@limbOne \\ + \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstructionParametersMstore { +% anchorRow = , +% relOffset = , +% targetId = , +% targetOffsetLo = , +% limbOne = , +% limbTwo = , +% } + +\newcommand{\setMmuInstructionParametersMstoreEight} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersMstoreEightName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + % \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + % \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + % \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + \utt{Limb one:} & \cmdMMU@var@limbOne \\ + \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstructionParametersMstoreEight { +% anchorRow = , +% relOffset = , +% targetId = , +% targetOffsetLo = , +% limbOne = , +% limbTwo = , +% } + +\newcommand{\setMmuInstructionParametersInvalidCodePrefix} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersInvalidCodePrefixName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + % \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + % \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + % \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] + } + +% \setMmuInstructionParametersInvalidCodePrefix { +% anchorRow = , +% relOffset = , +% sourceId = , +% sourceOffsetLo = , +% successBit = , +% } + +\newcommand{\setMmuInstructionParametersRightPaddedWordExtraction} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersRightPaddedWordExtractionName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + % \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + % \utt{Size:} & \cmdMMU@var@size \\ + \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + \utt{Limb one:} & \cmdMMU@var@limbOne \\ + \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] + } + +% \setMmuInstructionParametersRightPaddedWordExtraction { +% anchorRow = , +% relOffset = , +% sourceId = , +% sourceOffsetLo = , +% referenceOffset = , +% referenceSize = , +% limbOne = , +% limbTwo = , +% } + +\newcommand{\setMmuInstructionParametersRamToExoWithPadding} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersRamToExoWithPaddingName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] + } + +% \setMmuInstructionParametersRamToExoWithPadding { +% anchorRow = , +% relOffset = , +% sourceId = , +% targetId = , +% auxiliaryId = , +% sourceOffsetLo = , +% size = , +% referenceSize = , +% successBit = , +% exoSum = , +% phase = , +% } + +\newcommand{\setMmuInstructionParametersExoToRamTransplants} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersExoToRamTransplantsName _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + % \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + % \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstructionParametersExoToRamTransplants { +% anchorRow = , +% relOffset = , +% sourceId = , +% targetId = , +% size = , +% exoSum = , +% phase = , +% } + +\newcommand{\setMmuInstructionParametersRamToRamSansPadding} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersRamToRamSansPaddingName + _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + \utt{Size:} & \cmdMMU@var@size \\ + \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstructionParametersRamToRamSansPadding { +% anchorRow = , +% relOffset = , +% sourceId = , +% targetId = , +% sourceOffsetLo = , +% size = , +% referenceOffset = , +% referenceSize = , +% } + +\newcommand{\setMmuInstructionParametersAnyToRamWithPadding} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersAnyToRamWithPaddingName + _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + \utt{Size:} & \cmdMMU@var@size \\ + \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstructionParametersAnyToRamWithPadding { +% anchorRow = , +% relOffset = , +% sourceId = , +% targetId = , +% sourceOffsetHi = , +% sourceOffsetLo = , +% targetOffsetLo = , +% size = , +% referenceOffset = , +% referenceSize = , +% exoSum = , +% } + +\newcommand{\setMmuInstructionParametersModexpZero} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersModexpZeroName + _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + % \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + % \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + % \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + % \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + +% \setMmuInstructionParametersModexpZero { +% anchorRow = , +% relOffset = , +% targetId = , +% phase = , +% } + +\newcommand{\setMmuInstructionParametersModexpData} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersModexpDataName + _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + \utt{Size:} & \cmdMMU@var@size \\ + \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + % \utt{Success bit:} & \cmdMMU@var@successBit \\ + % \utt{Limb one:} & \cmdMMU@var@limbOne \\ + % \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] + } + +% \setMmuInstructionParametersModexpData { +% anchorRow = , +% relOffset = , +% sourceId = , +% targetId = , +% sourceOffsetLo = , +% size = , +% referenceOffset = , +% referenceSize = , +% phase = , +% } + +\newcommand{\setMmuInstructionParametersBlake} [1] { + \setkeys[MMU]{var}{#1} + \setMmuInstructionParametersBlakeName + _{\cmdMMU@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMMU@var@relOffset \\ + % \utt{\mmuMod{} instruction:} & \cmdMMU@var@mmuInstruction \vspace{2mm} \\ + \utt{Source ID:} & \cmdMMU@var@sourceId \\ + \utt{Target ID:} & \cmdMMU@var@targetId \\ + % \utt{Auxiliary ID:} & \cmdMMU@var@auxiliaryId \\ + % \utt{Source offset high:} & \cmdMMU@var@sourceOffsetHi \\ + \utt{Source offset low:} & \cmdMMU@var@sourceOffsetLo \\ + % \utt{Target offset low:} & \cmdMMU@var@targetOffsetLo \\ + % \utt{Size:} & \cmdMMU@var@size \\ + % \utt{Reference offset:} & \cmdMMU@var@referenceOffset \\ + % \utt{Reference size:} & \cmdMMU@var@referenceSize \\ + \utt{Success bit:} & \cmdMMU@var@successBit \\ + \utt{Limb one:} & \cmdMMU@var@limbOne \\ + \utt{Limb two:} & \cmdMMU@var@limbTwo \\ + % \utt{Exo sum:} & \cmdMMU@var@exoSum \\ + % \utt{Phase:} & \cmdMMU@var@phase \\ + \end{array} \right] +} + + +% \setMmuInstructionParametersBlake { +% anchorRow = , +% relOffset = , +% sourceId = , +% targetId = , +% sourceOffsetLo = , +% successBit = , +% limbOne = , +% limbTwo = , +% } + +\makeatother diff --git a/pkg/xkeyval_macros/mxp_instructions.sty b/pkg/xkeyval_macros/mxp_instructions.sty new file mode 100644 index 0000000..737facb --- /dev/null +++ b/pkg/xkeyval_macros/mxp_instructions.sty @@ -0,0 +1,73 @@ +\makeatletter + +\define@cmdkey [MXP] {var} {anchorRow} {} +\define@cmdkey [MXP] {var} {relOffset} {} +\define@cmdkey [MXP] {var} {instruction} {} +\define@cmdkey [MXP] {var} {callDataOffsetHi} {} +\define@cmdkey [MXP] {var} {callDataOffsetLo} {} +\define@cmdkey [MXP] {var} {callDataSizeHi} {} +\define@cmdkey [MXP] {var} {callDataSizeLo} {} +\define@cmdkey [MXP] {var} {returnAtOffsetHi} {} +\define@cmdkey [MXP] {var} {returnAtOffsetLo} {} +\define@cmdkey [MXP] {var} {returnAtCapacityHi} {} +\define@cmdkey [MXP] {var} {returnAtCapacityLo} {} + + +\presetkeys [MXP] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + instruction = \missingParameter, + callDataOffsetHi = \missingParameter, + callDataOffsetLo = \missingParameter, + callDataSizeHi = \missingParameter, + callDataSizeLo = \missingParameter, + returnAtOffsetHi = \missingParameter, + returnAtOffsetLo = \missingParameter, + returnAtCapacityHi = \missingParameter, + returnAtCapacityLo = \missingParameter, +}{} + +% misc/MXP instruction names +\newcommand{\setMxpInstructionTypeOneName } {\texttt{setMxpInstructionType\_1}} +\newcommand{\setMxpInstructionTypeTwoName } {\texttt{setMxpInstructionType\_2}} +\newcommand{\setMxpInstructionTypeThreeName} {\texttt{setMxpInstructionType\_3}} +\newcommand{\setMxpInstructionTypeFourName } {\texttt{setMxpInstructionType\_4}} +\newcommand{\setMxpInstructionTypeFiveName } {\texttt{setMxpInstructionType\_5}} + +% misc/MXP instructions +\newcommand{\setMxpInstructionTypeOne} [2] {\setMxpInstructionTypeOneName _{#1} \big[\;#2\;]} +\newcommand{\setMxpInstructionTypeTwo} [2] {\setMxpInstructionTypeTwoName _{#1} \big[\;#2\;]} +\newcommand{\setMxpInstructionTypeThree} [2] {\setMxpInstructionTypeThreeName _{#1} \big[\;#2\;]} +\newcommand{\setMxpInstructionTypeFour} [2] {\setMxpInstructionTypeFourName _{#1} \big[\;#2\;]} +\newcommand{\setMxpInstructionTypeFive} [1] { + \setkeys[MXP]{var}{#1} + \setMxpInstructionTypeFiveName _{\cmdMXP@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdMXP@var@relOffset \\ + \utt{Instruction:} & \cmdMXP@var@instruction \\ + \utt{Call data offset high part:} & \cmdMXP@var@callDataOffsetHi \\ + \utt{Call data offset low part:} & \cmdMXP@var@callDataOffsetLo \\ + \utt{Call data size high part:} & \cmdMXP@var@callDataSizeHi \\ + \utt{Call data size low part:} & \cmdMXP@var@callDataSizeLo \\ + \utt{Return at offset high part:} & \cmdMXP@var@returnAtOffsetHi \\ + \utt{Return at offset low part:} & \cmdMXP@var@returnAtOffsetLo \\ + \utt{Return at capacity high part:} & \cmdMXP@var@returnAtCapacityHi \\ + \utt{Return at capacity low part:} & \cmdMXP@var@returnAtCapacityLo \\ + \end{array} \right] +} + +\iffalse +\setMxpInstructionTypeFive { + anchorRow = , + relOffset = , + instruction = , + callDataOffsetHi = , + callDataOffsetLo = , + callDataSizeHi = , + callDataSizeLo = , + returnAtOffsetHi = , + returnAtOffsetLo = , + returnAtCapacityHi = , + returnAtCapacityLo = , + } +\fi diff --git a/pkg/xkeyval_macros/oob_instructions.sty b/pkg/xkeyval_macros/oob_instructions.sty new file mode 100644 index 0000000..5698a44 --- /dev/null +++ b/pkg/xkeyval_macros/oob_instructions.sty @@ -0,0 +1,267 @@ +\makeatletter + +\define@cmdkey [OOB] {var} {anchorRow} {} +\define@cmdkey [OOB] {var} {relOffset} {} +\define@cmdkey [OOB] {var} {valueHi} {} +\define@cmdkey [OOB] {var} {valueLo} {} +\define@cmdkey [OOB] {var} {balance} {} +\define@cmdkey [OOB] {var} {nonce} {} +\define@cmdkey [OOB] {var} {hasCode} {} +\define@cmdkey [OOB] {var} {callStackDepth} {} +\define@cmdkey [OOB] {var} {oobInstruction} {} +\define@cmdkey [OOB] {var} {callGas} {} +\define@cmdkey [OOB] {var} {callDataSize} {} +\define@cmdkey [OOB] {var} {returnAtCapacity} {} +\define@cmdkey [OOB] {var} {xbsHi} {} +\define@cmdkey [OOB] {var} {xbsLo} {} +\define@cmdkey [OOB] {var} {ybsLo} {} +\define@cmdkey [OOB] {var} {bbsLo} {} +\define@cmdkey [OOB] {var} {ebsLo} {} +\define@cmdkey [OOB] {var} {mbsLo} {} +\define@cmdkey [OOB] {var} {computeMax} {} +\define@cmdkey [OOB] {var} {blakeR} {} +\define@cmdkey [OOB] {var} {blakeF} {} +\define@cmdkey [OOB] {var} {exponentLog} {} +\define@cmdkey [OOB] {var} {maxMbsBbs} {} + + +\presetkeys [OOB] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + valueHi = \missingParameter, + valueLo = \missingParameter, + balance = \missingParameter, + nonce = \missingParameter, + hasCode = \missingParameter, + callStackDepth = \missingParameter, + oobInstruction = \missingParameter, + callGas = \missingParameter, + callDataSize = \missingParameter, + returnAtCapacity = \missingParameter, + xbsHi = \missingParameter, + xbsLo = \missingParameter, + ybsLo = \missingParameter, + computeMax = \missingParameter, + bbsLo = \missingParameter, + ebsLo = \missingParameter, + mbsLo = \missingParameter, + blakeR = \missingParameter, + blakeF = \missingParameter, + exponentLog = \missingParameter, + maxMbsBbs = \missingParameter, +}{} + +% misc OOB instructions +% opcode related +\newcommand{\oobInstructionNamePrefix } {\miscSignifier\texttt{setOobInstruction}} +\newcommand{\setOobInstructionJumpName } {\oobInstructionNamePrefix\texttt{Jump}} +\newcommand{\setOobInstructionJumpIName } {\oobInstructionNamePrefix\texttt{Jumpi}} +\newcommand{\setOobInstructionRdcName } {\oobInstructionNamePrefix\texttt{Rdc}} +\newcommand{\setOobInstructionCdlName } {\oobInstructionNamePrefix\texttt{Cdl}} +\newcommand{\setOobInstructionXcallName } {\oobInstructionNamePrefix\texttt{Xcall}} +\newcommand{\setOobInstructionCallName } {\oobInstructionNamePrefix\texttt{Call}} +\newcommand{\setOobInstructionCreateName } {\oobInstructionNamePrefix\texttt{Create}} +\newcommand{\setOobInstructionSstoreName } {\oobInstructionNamePrefix\texttt{Sstore}} +\newcommand{\setOobInstructionDeploymentName } {\oobInstructionNamePrefix\texttt{Deployment}} + +\newcommand{\setOobInstruction } [1] {\oobInstructionNamePrefix _{#1}} + +\newcommand{\setOobInstructionJump } [2] {\setOobInstructionJumpName _{#1} \big[ \, #2 \, \big]} +\newcommand{\setOobInstructionJumpI } [2] {\setOobInstructionJumpIName _{#1} \big[ \, #2 \, \big]} +\newcommand{\setOobInstructionRdc } [2] {\setOobInstructionRdcName _{#1} \big[ \, #2 \, \big]} +\newcommand{\setOobInstructionCdl } [2] {\setOobInstructionCdlName _{#1} \big[ \, #2 \, \big]} + +\newcommand{\setOobInstructionXcall } [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionXcallName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Value high:} & \cmdOOB@var@valueHi \\ + \utt{Value low:} & \cmdOOB@var@valueLo \\ + \end{array} \right] +} + +\newcommand{\setOobInstructionCall } [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionCallName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Value high:} & \cmdOOB@var@valueHi \\ + \utt{Value low:} & \cmdOOB@var@valueLo \\ + \utt{Balance:} & \cmdOOB@var@balance \\ + \utt{Call stack depth:} & \cmdOOB@var@callStackDepth \\ + \end{array} \right] +} + +\newcommand{\setOobInstructionCreate } [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionCreateName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Value high:} & \cmdOOB@var@valueHi \\ + \utt{Value low:} & \cmdOOB@var@valueLo \\ + \utt{Balance:} & \cmdOOB@var@balance \\ + \utt{Createe nonce:} & \cmdOOB@var@nonce \\ + \utt{Createe has code:} & \cmdOOB@var@hasCode \\ + \utt{Call stack depth:} & \cmdOOB@var@callStackDepth \\ + \end{array} \right] +} + +\newcommand{\setOobInstructionSstore } [2] {\setOobInstructionSstoreName _{#1} \big[ \, #2 \, \big]} +\newcommand{\setOobInstructionDeployment } [2] {\setOobInstructionDeploymentName _{#1} \big[ \, #2 \, \big]} + +% precompile related +\newcommand{\setOobInstructionCommonName } {\oobInstructionNamePrefix\texttt{Common}} +\newcommand{\setOobInstructionBlakeCdsName } {\oobInstructionNamePrefix\texttt{Blake/Cds}} +\newcommand{\setOobInstructionBlakeParamsName } {\oobInstructionNamePrefix\texttt{Blake/Params}} +\newcommand{\setOobInstructionModexpCdsName } {\oobInstructionNamePrefix\texttt{Modexp/Cds}} +\newcommand{\setOobInstructionModexpXbsName } {\oobInstructionNamePrefix\texttt{Modexp/Xbs}} +\newcommand{\setOobInstructionModexpLeadName } {\oobInstructionNamePrefix\texttt{Modexp/Lead}} +\newcommand{\setOobInstructionModexpPricingName } {\oobInstructionNamePrefix\texttt{Modexp/Pricing}} +\newcommand{\setOobInstructionModexpExtractName } {\oobInstructionNamePrefix\texttt{Modexp/Extract}} + +\newcommand{\setOobInstructionCommon} [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionCommonName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{OOB instruction:} & \cmdOOB@var@oobInstruction \\ + \utt{Call gas:} & \cmdOOB@var@callGas \\ + \utt{Call data size:} & \cmdOOB@var@callDataSize \\ + \utt{Return at capacity:} & \cmdOOB@var@returnAtCapacity \\ + \end{array} \right] +} + +\newcommand{\setOobInstructionBlakeCds} [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionBlakeCdsName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Call data size:} & \cmdOOB@var@callDataSize \\ + \utt{Return at capacity:} & \cmdOOB@var@returnAtCapacity \\ + \end{array} \right] +} + +% \setOobInstructionBlakeCds { +% anchorRow = , +% relOffset = , +% callDataSize = , +% returnAtCapacity = , +% } + +\newcommand{\setOobInstructionBlakeParams } [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionBlakeParamsName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Call gas:} & \cmdOOB@var@callGas \\ + \utt{Rounds ``r'':} & \cmdOOB@var@blakeR \\ + \utt{Final block indicator ``f'':} & \cmdOOB@var@blakeF \\ + \end{array} \right] +} + +% \setOobInstructionBlakeParams { +% anchorRow = , +% relOffset = , +% callGas = , +% blakeR = , +% blakeF = , +% } + +\newcommand{\setOobInstructionModexpCds } [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionModexpCdsName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Call data size:} & \cmdOOB@var@callDataSize \\ + \end{array} \right] +} + +% \setOobInstructionModexpCds { +% anchorRow = , +% relOffset = , +% callDataSize = , +% } + +\newcommand{\setOobInstructionModexpXbs} [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionModexpXbsName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{``xbs'' high:} & \cmdOOB@var@xbsHi \\ + \utt{``xbs'' low:} & \cmdOOB@var@xbsLo \\ + \utt{``ybs'' low:} & \cmdOOB@var@ybsLo \\ + \utt{Extra computation bit:} & \cmdOOB@var@computeMax \\ + \end{array} \right] +} + +% \setOobInstructionModexpXbs { +% anchorRow = , +% relOffset = , +% xbsHi = , +% xbsLo = , +% ybsLo = , +% computeMax = , +% } + +\newcommand{\setOobInstructionModexpLead} [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionModexpLeadName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Base byte size:} & \cmdOOB@var@bbsLo \\ + \utt{Call data size:} & \cmdOOB@var@callDataSize \\ + \utt{Exponent byte size:} & \cmdOOB@var@ebsLo \\ + \end{array} \right] +} + +% \setOobInstructionModexpLead { +% anchorRow = , +% relOffset = , +% bbsLo = , +% callDataSize = , +% ebsLo = , +% } + +\newcommand{\setOobInstructionModexpPricing} [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionModexpPricingName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Call gas:} & \cmdOOB@var@callGas \\ + \utt{Return at capacity:} & \cmdOOB@var@returnAtCapacity \\ + \utt{Exponent log:} & \cmdOOB@var@exponentLog \\ + \utt{Max(mbs, bbs):} & \cmdOOB@var@maxMbsBbs \\ + \end{array} \right] +} + +% \setOobInstructionModexpPricing { +% relOffset = , +% callGas = , +% returnAtCapacity = , +% exponentLog = , +% maxMbsBbs = , +% } + +\newcommand{\setOobInstructionModexpExtract} [1] { + \setkeys[OOB]{var}{#1} + \setOobInstructionModexpExtractName _{\cmdOOB@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdOOB@var@relOffset \\ + \utt{Call data size:} & \cmdOOB@var@callDataSize \\ + \utt{Base byte size:} & \cmdOOB@var@bbsLo \\ + \utt{Exponent byte size:} & \cmdOOB@var@ebsLo \\ + \utt{Modulus byte size:} & \cmdOOB@var@mbsLo \\ + \end{array} \right] +} + +% \setOobInstructionModexpExtract { +% anchorRow = , +% relOffset = , +% callDataSize = , +% bbsLo = , +% ebsLo = , +% mbsLo = , +% } + +\makeatother diff --git a/pkg/xkeyval_macros/stp_instructions.sty b/pkg/xkeyval_macros/stp_instructions.sty new file mode 100644 index 0000000..9f77d1a --- /dev/null +++ b/pkg/xkeyval_macros/stp_instructions.sty @@ -0,0 +1,56 @@ +\makeatletter + +\define@cmdkey [STP] {var} {anchorRow} {} +\define@cmdkey [STP] {var} {relOffset} {} +\define@cmdkey [STP] {var} {instruction} {} +\define@cmdkey [STP] {var} {gasHi} {} +\define@cmdkey [STP] {var} {gasLo} {} +\define@cmdkey [STP] {var} {valueHi} {} +\define@cmdkey [STP] {var} {valueLo} {} +\define@cmdkey [STP] {var} {warmth} {} +\define@cmdkey [STP] {var} {exists} {} +\define@cmdkey [STP] {var} {mxpGas} {} + +\presetkeys [STP] {var} { +anchorRow = \missingParameter, +relOffset = \missingParameter, +instruction = \missingParameter, +gasHi = \missingParameter, +gasLo = \missingParameter, +valueHi = \missingParameter, +valueLo = \missingParameter, +warmth = \missingParameter, +exists = \missingParameter, +mxpGas = \missingParameter, +}{} + + + +% STP +\newcommand{\setStpInstructionCall}[1]{ + \setkeys[STP]{var}{#1} + \texttt{setStpInstructionCall} _{\cmdSTP@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdSTP@var@relOffset \\ + \utt{Instruction:} & \cmdSTP@var@instruction \\ + \utt{Gas high:} & \cmdSTP@var@gasHi \\ + \utt{Gas low:} & \cmdSTP@var@gasLo \\ + \utt{Value high:} & \cmdSTP@var@valueHi \\ + \utt{Value low:} & \cmdSTP@var@valueLo \\ + \utt{Target exists:} & \cmdSTP@var@warmth \\ + \utt{Target warmth:} & \cmdSTP@var@exists \\ + \utt{Memory expansion gas:} & \cmdSTP@var@mxpGas \\ + \end{array} \right] } + +\newcommand{\setStpInstructionCreate} [1] { +\setkeys[STP]{var}{#1} +\texttt{setStpInstructionCreate} _{\cmdSTP@var@anchorRow} +\left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdSTP@var@relOffset \\ + \utt{Instruction:} & \cmdSTP@var@instruction \\ + \utt{Value high:} & \cmdSTP@var@valueHi \\ + \utt{Value low:} & \cmdSTP@var@valueLo \\ + \utt{Memory expansion gas:} & \cmdSTP@var@mxpGas \\ +\end{array} \right] } + +\makeatother diff --git a/pkg/xkeyval_macros/wcp_calls.sty b/pkg/xkeyval_macros/wcp_calls.sty new file mode 100644 index 0000000..a4d97b7 --- /dev/null +++ b/pkg/xkeyval_macros/wcp_calls.sty @@ -0,0 +1,78 @@ +\makeatletter +% DEFINING KEYS + +\define@cmdkey [WCP] {var} {anchorRow} {} % "i" in the spec, ALWAYS use this name +\define@cmdkey [WCP] {var} {relOffset} {} % relative offset, ALWAYS use this name +\define@cmdkey [WCP] {var} {argOneHi} {} +\define@cmdkey [WCP] {var} {argOneLo} {} +\define@cmdkey [WCP] {var} {argTwoHi} {} +\define@cmdkey [WCP] {var} {argTwoLo} {} +% the above defines macros à la "\cmdWCP@var@anchorRow" + +% DEFAULT VALUES +\presetkeys [WCP] {var} { + anchorRow = \missingParameter, + relOffset = \missingParameter, + argOneHi = \missingParameter, + argOneLo = \missingParameter, + argTwoHi = \missingParameter, + argTwoLo = \missingParameter, +}{} + +% "call to LT" macro +\newcommand{\wcpCallToLtName} {\texttt{wcpCallToLT}} +\newcommand{\wcpCallToLt} [1] { + \setkeys[WCP]{var}{#1} + \wcpCallToLtName _{\cmdWCP@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdWCP@var@relOffset \\ + \utt{First argument (high):} & \cmdWCP@var@argOneHi \\ + \utt{First argument (low):} & \cmdWCP@var@argOneLo \\ + \utt{Second argument (high):} & \cmdWCP@var@argTwoHi \\ + \utt{Second argument (low):} & \cmdWCP@var@argTwoLo \\ + \end{array} \right] +} +% Note: \utt{...} is a Latex macro for \underline{\texttt{...}} +% \utt is the recommended style for such macros + +% "call to GT" macro +\newcommand{\wcpCallToGtName} {\texttt{wcpCallToGT}} +\newcommand{\wcpCallToGt} [1] { + \setkeys[WCP]{var}{#1} + \wcpCallToLtName _{\cmdWCP@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdWCP@var@relOffset \\ + \utt{First argument (high):} & \cmdWCP@var@argOneHi \\ + \utt{First argument (low):} & \cmdWCP@var@argOneLo \\ + \utt{Second argument (high):} & \cmdWCP@var@argTwoHi \\ + \utt{Second argument (low):} & \cmdWCP@var@argTwoLo \\ + \end{array} \right] +} + +% "call to EQ" macro +\newcommand{\wcpCallToEqName} {\texttt{wcpCallToEQ}} +\newcommand{\wcpCallToEq} [1] { + \setkeys[WCP]{var}{#1} + \wcpCallToEqName _{\cmdWCP@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdWCP@var@relOffset \\ + \utt{First argument (high):} & \cmdWCP@var@argOneHi \\ + \utt{First argument (low):} & \cmdWCP@var@argOneLo \\ + \utt{Second argument (high):} & \cmdWCP@var@argTwoHi \\ + \utt{Second argument (low):} & \cmdWCP@var@argTwoLo \\ + \end{array} \right] +} + +% "call to ISZERO" macro +\newcommand{\wcpCallToIszeroName} {\texttt{wcpCallToISZERO}} +\newcommand{\wcpCallToIszero} [1] { + \setkeys[WCP]{var}{#1} + \wcpCallToIszeroName _{\cmdWCP@var@anchorRow} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & \cmdWCP@var@relOffset \\ + \utt{Argument (high):} & \cmdWCP@var@argOneHi \\ + \utt{Argument (low):} & \cmdWCP@var@argOneLo \\ + \end{array} \right] +} + +\makeatother diff --git a/prc/_all_prc.maf b/prc/_all_prc.maf new file mode 100644 index 0000000..fef0175 --- /dev/null +++ b/prc/_all_prc.maf @@ -0,0 +1,5 @@ +_all_prc.mtc +_all_prc.mtc0 +_all_prc.mtc3 +_all_prc.mtc2 +_all_prc.mtc1 diff --git a/prc/_all_prc.tex b/prc/_all_prc.tex new file mode 100644 index 0000000..d3e0e2a --- /dev/null +++ b/prc/_all_prc.tex @@ -0,0 +1,53 @@ +\documentclass[fleqn]{report} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/wc3} +\usepackage{../pkg/stack} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/modexp} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/expansion} +\usepackage{../pkg/iomf_done} +\usepackage{fontawesome} +\usepackage{../pkg/exponent} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/mmu_custom_instructions} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/prc} +\usepackage{../pkg/common_shorthands} +\usepackage{../pkg/xkeyval_macros/wcp_calls} +\usepackage{../pkg/xkeyval_macros/ext_calls} +\usepackage{../pkg/draculatheme} +\usepackage{changepage} +\usetikzlibrary{calc} +\usepackage[nohints]{minitoc} + +\usepackage{makecell} +\renewcommand\theadalign{bc} +\renewcommand\theadfont{\bfseries} +\renewcommand\theadgape{\Gape[4pt]} +\renewcommand\cellgape{\Gape[4pt]} + +\title{The precompile data modules} +\author{Rollup team} +\date{January 2023} + +\begin{document} + +\maketitle +\dominitoc +\setcounter{tocdepth}{0} +\tableofcontents +\setcounter{tocdepth}{5} + +\input{_inputs} + +\end{document} diff --git a/prc/_inputs.tex b/prc/_inputs.tex new file mode 100644 index 0000000..d94da23 --- /dev/null +++ b/prc/_inputs.tex @@ -0,0 +1,5 @@ +\input{_local} + +\chapter{The \shakiraMod{} module} \label{chap: shakira data} \minitoc \input{shakira/_inputs} +\chapter{The \blkMdxMod{} module} \label{chap: blake modexp data} \minitoc \input{blkmdx/_inputs} +\chapter{The \ecDataMod{} module} \label{chap: ec data} \minitoc \input{ecdata/_inputs} diff --git a/prc/_local.tex b/prc/_local.tex new file mode 100644 index 0000000..e79ef0b --- /dev/null +++ b/prc/_local.tex @@ -0,0 +1,168 @@ +\def\locStampIncrement {\col{stamp\_increment}} +\def\locTransitionBit {\col{transition\_bit}} +\def\locIndexResetBit {\col{index\_reset\_bit}} +\def\locLegalTransitionsBit {\col{legal\_transitions\_bit}} +\def\locShakiraIsKeccak {\col{is\_keccak}} +\def\locShakiraIsShaTwo {\col{is\_sha2}} +\def\locShakiraIsRipemd {\col{is\_ripemd}} +\def\locShakiraIsResult {\col{is\_result}} +\def\locIsData {\col{is\_data}} +\def\locIsResult {\col{is\_result}} +\def\locIsFinalDataRow {\col{is\_final\_data\_row}} +\def\locIsFirstDataRow {\col{is\_first\_data\_row}} + + + + +%\newcommand{\myCds}[1][\empty]{\ifx\empty#1 \col{CDS} \else \col{CALL\_DATA\_SIZE} \fi} +%\myCds +%\myCds[] + +\def\isInRange {\col{\_is\_in\_range}} + +% ecadd +\def\locP {\col{P}} +\def\locPX {\locP\col{\_x}} +\def\locPY {\locP\col{\_y}} + +\def\locPXHi {\locPX\col{\_hi}} +\def\locPXLo {\locPX\col{\_lo}} +\def\locPYHi {\locPY\col{\_hi}} +\def\locPYLo {\locPY\col{\_lo}} + +\def\locQ {\col{Q}} +\def\locQX {\locQ\col{\_x}} +\def\locQY {\locQ\col{\_y}} + +\def\locQXHi {\locQX\col{\_hi}} +\def\locQXLo {\locQX\col{\_lo}} +\def\locQYHi {\locQY\col{\_hi}} +\def\locQYLo {\locQY\col{\_lo}} + +\def\locPXIsInRange {\locPX\isInRange} +\def\locPYIsInRange {\locPY\isInRange} +\def\locPIsInRange {\locP\isInRange} +\def\locPXIsZero {\locPX\col{\_is\_zero}} +\def\locPYIsZero {\locPY\col{\_is\_zero}} + +\def\locLargeSum {\col{large\_sum}} +\def\locPXxYIsInfinity {\locP\col{\_is\_point\_at\_infinity}} + +\def\locPYSquare {\locPY\col{\_square}} +\def\locPYSquareHi {\locPYSquare\col{\_hi}} +\def\locPYSquareLo {\locPYSquare\col{\_lo}} +\def\locPXSquare {\locPX\col{\_square}} +\def\locPXSquareHi {\locPXSquare\col{\_hi}} +\def\locPXSquareLo {\locPXSquare\col{\_lo}} +\def\locPXCube {\locPX\col{\_cube}} +\def\locPXCubeHi {\locPXCube\col{\_hi}} +\def\locPXCubeLo {\locPXCube\col{\_lo}} +\def\locPXCubePlusThree {\locPXCube\col{\_plus\_three}} +\def\locPXCubePlusThreeHi {\locPXCubePlusThree\col{\_hi}} +\def\locPXCubePlusThreeLo {\locPXCubePlusThree\col{\_lo}} + +\def\locPSatisfiesCubic {\locP\col{\_satisfies\_cubic}} + +\def\locResult {\col{RES}} +\def\locResultX {\locResult\col{\_x}} +\def\locResultY {\locResult\col{\_y}} + +\def\locResultXHi {\locResultX\col{\_hi}} +\def\locResultXLo {\locResultX\col{\_lo}} +\def\locResultYHi {\locResultY\col{\_hi}} +\def\locResultYLo {\locResultY\col{\_lo}} + +% ecmul + +\def\locN {\col{n}} + +\def\locNHi {\locN\col{\_hi}} +\def\locNLo {\locN\col{\_lo}} + +% ecrecovering +\def\locH {\col{h}} +\def\locHHi {\locH\col{\_hi}} +\def\locHLo {\locH\col{\_lo}} + +\def\locV {\col{v}} +\def\locVHi {\locV\col{\_hi}} +\def\locVLo {\locV\col{\_lo}} + +\def\locR {\col{r}} +\def\locRHi {\locR\col{\_hi}} +\def\locRLo {\locR\col{\_lo}} + +\def\locS {\col{s}} +\def\locSHi {\locS\col{\_hi}} +\def\locSLo {\locS\col{\_lo}} + +\def\locRIsInRange {\locR\isInRange} +\def\locSIsInRange {\locS\isInRange} +\def\locRIsPositive {\locR\col{\_is\_positive}} +\def\locSIsPositive {\locS\col{\_is\_positive}} +\def\locVIsTwentyseven {\locV\col{\_is\_27}} +\def\locVIsTwentyeight {\locV\col{\_is\_28}} + +\def\locRecoveredAddress {\col{recovered\_address}} +\def\locRecoveredAddressHi {\locRecoveredAddress\col{\_hi}} +\def\locRecoveredAddressLo {\locRecoveredAddress\col{\_lo}} + +% ecpairing +\def\locA {\col{A}} +\def\locAX {\locA\col{\_x}} +\def\locAY {\locA\col{\_y}} + +\def\locAXHi {\locAX\col{\_hi}} +\def\locAXLo {\locAX\col{\_lo}} +\def\locAYHi {\locAY\col{\_hi}} +\def\locAYLo {\locAY\col{\_lo}} + +\def\locB {\col{B}} +\def\locBX {\locB\col{\_x}} +\def\locBY {\locB\col{\_y}} +\def\locBXIm {\locBX\col{\_Im}} +\def\locBXRe {\locBX\col{\_Re}} +\def\locBYIm {\locBY\col{\_Im}} +\def\locBYRe {\locBY\col{\_Re}} + +\def\locBXImHi {\locBXIm\col{\_hi}} +\def\locBXImLo {\locBXIm\col{\_lo}} +\def\locBXReHi {\locBXRe\col{\_hi}} +\def\locBXReLo {\locBXRe\col{\_lo}} +\def\locBYImHi {\locBYIm\col{\_hi}} +\def\locBYImLo {\locBYIm\col{\_lo}} +\def\locBYReHi {\locBYRe\col{\_hi}} +\def\locBYReLo {\locBYRe\col{\_lo}} + +\def\locBXImIsInRange {\locBXIm\isInRange} +\def\locBXReIsInRange {\locBXRe\isInRange} +\def\locBYImIsInRange {\locBYIm\isInRange} +\def\locBYReIsInRange {\locBYRe\isInRange} + +% \def\locBIsInRange {\locB\isInRange} +\def\locBXIsInRange {\locBX\isInRange} +\def\locBYIsInRange {\locBY\isInRange} + +\def\locVeryLargeSum {\col{very\_large\_sum}} +\def\locBXbYIsInfinity {\locB\col{\_is\_point\_at\_infinity}} + +\def\locSmallPointInfinity {\col{small\_point\_is\_at\_infinity}} +\def\locLargePointInfinity {\col{large\_point\_is\_at\_infinity}} + +\def\locCOneMembership {\col{C1\_membership}} +\def\locCOneMembershipFirstPoint {\col{C1\_membership\_first\_point}} +\def\locCOneMembershipSecondPoint {\col{C1\_membership\_second\_point}} +\def\locWellFormedCoordinates {\col{well\_formed\_coordinates}} + +\def\locInternalChecksPassed {\col{internal\_checks\_passed}} +\def\locPreviousInternalChecksPassed {\col{prev\_}\locInternalChecksPassed} + +\def\locPairingsResult {\col{pairings\_result}} +\def\locPairingsResultHi {\locPairingsResult\col{\_hi}} +\def\locPairingsResultLo {\locPairingsResult\col{\_lo}} + +\def\locTransitionFromSmallToLarge {\col{transition\_from\_small\_to\_large}} +\def\locTransitionFromLargeToSmall {\col{transition\_from\_large\_to\_small}} + +\def\locExceptionalPairingSum {\col{exceptional\_pairing\_sum}} +\def\locExceptionalPairingFlag {\col{exceptional\_pairing\_flag}} diff --git a/prc/blkmdx/_inputs.tex b/prc/blkmdx/_inputs.tex new file mode 100644 index 0000000..950140d --- /dev/null +++ b/prc/blkmdx/_inputs.tex @@ -0,0 +1,14 @@ +\section{\blkMdxMod{} module} +\subsection{Introduction} \label{blake + modexp: intro} \input{blkmdx/intro} +\subsection{Columns} \label{blake + modexp: columns} \input{blkmdx/columns} + +\section{General constraints} +\subsection{Binary columns} \label{blake + modexp: binary} \input{blkmdx/binary} +\subsection{Decoding constraints} \label{blake + modexp: decoding} \input{blkmdx/decoding} +\subsection{Constancies} \label{blake + modexp: constancies} \input{blkmdx/constancies} +\subsection{Heartbeat} \label{blake + modexp: heartbeat} \input{blkmdx/heartbeat} +\subsection{Representation} \label{blake + modexp: representation} \includepdf[fitpaper=true]{blkmdx/lua/modexp.pdf} + +\section{Lookups} +\subsection{Into \wcpMod{}} \label{blake + modexp: lookups: into wcp} \input{blkmdx/lookups/blakemodxp_into_wcp} + \includepdf[fitpaper=true]{blkmdx/lua/blake.pdf} diff --git a/prc/blkmdx/binary.tex b/prc/blkmdx/binary.tex new file mode 100644 index 0000000..3767bce --- /dev/null +++ b/prc/blkmdx/binary.tex @@ -0,0 +1,13 @@ +We impose that the following columns be \textbf{binary}: +\begin{multicols}{2} + \begin{enumerate} + \item \isModexpBase + \item \isModexpExponent + \item \isModexpModulus + \item \isModexpResult + \item \isBlakeData + \item \isBlakeParams + \item \isBlakeResult + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/prc/blkmdx/columns.tex b/prc/blkmdx/columns.tex new file mode 100644 index 0000000..d61a279 --- /dev/null +++ b/prc/blkmdx/columns.tex @@ -0,0 +1,43 @@ +\begin{enumerate} + \item \blkMdxStamp{}: + module stamp column; + \item \modexpBlakeId{}: + unique data identifier; + can have large increments but must be listed in ascending order; + \item \modexpBlakePhase{}: + ``phase'' column; + \item \index{}: + index column + \item \indexMax{}: + associated ``maximum index'' column; +\end{enumerate} +A data limb is uniquely determined by +(\emph{a}) a unique identifier, +(\emph{b}) a phase and +(\emph{c}) an index. +These are provided above. + +\saNote{} The present module only stores data with size which is known ahead of time. It therefore doesn't require an \nBytes{} column. + +The following column is a ``limb'' which contains limbs (i.e. $\llarge$-byte integers) representing data. +This data may be either input data +(\inst{MODEXP} base, exponent or modulus, \inst{BLAKE2f} ``\col{rounds}'' and ``\col{f}'' parameters and \col{h}, \col{m} and \col{t} parameters) +or ouput data +(\inst{MODEXP} result or \inst{BLAKE2f} result.) +\begin{enumerate}[resume] + \item \limb{}: + data limb column; +\end{enumerate} +The following columns are exclusive binary columns that allow the present module to identify the nature of the data it holds. +\begin{multicols}{2} + \begin{enumerate}[resume] + \item \isModexpBase{} + \item \isModexpExponent{} + \item \isModexpModulus{} + \item \isModexpResult{} + \item \isBlakeData{} + \item \isBlakeParams{} + \item \isBlakeResult{} + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/prc/blkmdx/constancies.tex b/prc/blkmdx/constancies.tex new file mode 100644 index 0000000..fe60ff3 --- /dev/null +++ b/prc/blkmdx/constancies.tex @@ -0,0 +1,38 @@ +We define a column \col{X} to be \textbf{stamp-constant} if it satisfies the following: +\[ + \If \blkMdxStamp_{i} \neq 1 + \blkMdxStamp_{i - 1} ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +We impose that the following column(s) be stamp-constant +\begin{enumerate} + \item \modexpBlakeId +\end{enumerate} +We define a column \col{X} to be \textbf{index-constant} if it satisfies the following: +\[ + \If \index_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose that the following columns be index-constant: +\begin{enumerate} + \item \weightedPhaseFlagSum{} +\end{enumerate} +\saNote{}\label{blake + modexp: constancies: implied index constancy of the binary flags} +It is crucial that the weights used in the definition of \weightedPhaseFlagSum{} (i.e. $\phaseModexpBase{}$, $\phaseModexpExponent{}$, \dots) be \textbf{pairwise distinct nonzero}. +Combined with the fact that the columns which appear in the defining expression of \weightedPhaseFlagSum{} are \textbf{exclusive binary columns}, the index-constancy of \weightedPhaseFlagSum{} implies index-constancy of the underlying columns: +\begin{multicols}{2} + \begin{enumerate}[resume] + \item \isModexpBase{} \quad(\trash) + \item \isModexpExponent{} \quad(\trash) + \item \isModexpModulus{} \quad(\trash) + \item \isModexpResult{} \quad(\trash) + \item \isBlakeData{} \quad(\trash) + \item \isBlakeParams{} \quad(\trash) + \item \isBlakeResult{} \quad(\trash) + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +These index-constancies also imply index-constancy of the columns derived from them: +\begin{multicols}{2} + \begin{enumerate}[resume] + \item \modexpBlakePhase{} \quad(\trash) + \item \indexMax{} \quad(\trash) + \end{enumerate} +\end{multicols} diff --git a/prc/blkmdx/decoding.tex b/prc/blkmdx/decoding.tex new file mode 100644 index 0000000..ae16920 --- /dev/null +++ b/prc/blkmdx/decoding.tex @@ -0,0 +1,64 @@ +We define the following shorthand +\[ + \left\{ \begin{array}{lcl} + \flagSum_{i} & \define & + \left[ \begin{array}{cr} + + & \isModexpBase _{i} \\ + + & \isModexpExponent _{i} \\ + + & \isModexpModulus _{i} \\ + + & \isModexpResult _{i} \\ + + & \isBlakeData _{i} \\ + + & \isBlakeParams _{i} \\ + + & \isBlakeResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedPhaseFlagSum_{i} & \define & + \left[ \begin{array}{crcl} + + & \phaseModexpBase & \!\!\!\cdot\!\!\! & \isModexpBase _{i} \\ + + & \phaseModexpExponent & \!\!\!\cdot\!\!\! & \isModexpExponent _{i} \\ + + & \phaseModexpModulus & \!\!\!\cdot\!\!\! & \isModexpModulus _{i} \\ + + & \phaseModexpResult & \!\!\!\cdot\!\!\! & \isModexpResult _{i} \\ + + & \phaseBlakeData & \!\!\!\cdot\!\!\! & \isBlakeData _{i} \\ + + & \phaseBlakeParams & \!\!\!\cdot\!\!\! & \isBlakeParams _{i} \\ + + & \phaseBlakeResult & \!\!\!\cdot\!\!\! & \isBlakeResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \indexMaxFlagSum _{i} & \define & + \left[ \begin{array}{crcl} + + & ( 32 - 1 ) & \!\!\!\cdot\!\!\! & \isModexpBase _{i} \\ + + & ( 32 - 1 ) & \!\!\!\cdot\!\!\! & \isModexpExponent _{i} \\ + + & ( 32 - 1 ) & \!\!\!\cdot\!\!\! & \isModexpModulus _{i} \\ + + & ( 32 - 1 ) & \!\!\!\cdot\!\!\! & \isModexpResult _{i} \\ + + & ( 13 - 1 ) & \!\!\!\cdot\!\!\! & \isBlakeData _{i} \\ + + & ( 2 - 1 ) & \!\!\!\cdot\!\!\! & \isBlakeParams _{i} \\ + + & ( 4 - 1 ) & \!\!\!\cdot\!\!\! & \isBlakeResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \end{array} \right. +\] +and impose the following: +\begin{enumerate} + \item $\flagSum$ is binary; + \item \If $\blkMdxStamp_{i} = 0$ \Then $\flagSum_{i} = 0$ + \item \If $\blkMdxStamp_{i} \neq 0$ \Then $\flagSum_{i} = 1$ + \item furthermore + \[ + \left\{ \begin{array}{lcl} + \modexpBlakePhase _{i} & \!\!\!=\!\!\! & \weightedPhaseFlagSum _{i} \\ + \indexMax _{i} & \!\!\!=\!\!\! & \indexMaxFlagSum _{i} \\ + \end{array} \right. + \] +\end{enumerate} +The above thus enforces that +\isModexpBase {}, +\isModexpExponent{}, +\isModexpModulus {}, +\isModexpResult {}, +\isBlakeData {}, +\isBlakeParams {} and +\isBlakeResult {} +are indeed \textbf{exclusive binary columns}. +It also enforces that every non-padding-row is part of precisely one of these perspectives. + +\saNote{} The only requirement we place on the weights +$\phaseModexpBase$, +$\phaseModexpExponent$, \dots, +is that they be \textbf{pairwise distinct and nonzero}. +See note~(\ref{blake + modexp: constancies: implied index constancy of the binary flags}). diff --git a/prc/blkmdx/heartbeat.tex b/prc/blkmdx/heartbeat.tex new file mode 100644 index 0000000..cc4e528 --- /dev/null +++ b/prc/blkmdx/heartbeat.tex @@ -0,0 +1,74 @@ +We impose the following +\begin{enumerate} + \item $\blkMdxStamp_{0} = 0$ + \item \If $\blkMdxStamp_{i} = 0$\footnote{The condition ``\If $\blkMdxStamp_{i} = 0$'' could be remplaced by the lower degree condition ``\If $\flagSum_{i} = 0$''.} \Then + \[ + \left\{ \begin{array}{lclr} + \modexpBlakeId _{i} & = & 0 \\ + \index _{i} & = & 0 \\ + \index _{i + 1} & = & 0 \\ + \indexMax _{i} & = & 0 & (\trash) \\ + \end{array} \right. + \] + \item $\blkMdxStamp_{i + 1} \in \{ \blkMdxStamp_{i}, 1 + \blkMdxStamp_{i} \}$ \quad (\trash) + \item we impose + \( + \blkMdxStamp_{i + 1} + = + \blkMdxStamp_{i} + + + \locStampIncrement + \) + where + \[ + \locStampIncrement + \define + \left[ \begin{array}{crcl} + + & (1 - \isModexpBase _{i}) & \!\!\!\cdot\!\!\! & \isModexpBase _{i + 1} \\ + + & (1 - \isBlakeData _{i}) & \!\!\!\cdot\!\!\! & \isBlakeData _{i + 1} \\ + \end{array} \right] + \] +\end{enumerate} +\saNote{} \locStampIncrement{} is binary by construction. + +We define the following ``transition bit'' shorthand +\[ + \locTransitionBit_{i} + \define + \left[ \begin{array}{crcl} + + & \isModexpBase _{i} & \!\!\!\cdot\!\!\! & \isModexpExponent _{i + 1} \\ + + & \isModexpExponent _{i} & \!\!\!\cdot\!\!\! & \isModexpModulus _{i + 1} \\ + + & \isModexpModulus _{i} & \!\!\!\cdot\!\!\! & \isModexpResult _{i + 1} \\ + + & \isModexpResult _{i} & \!\!\!\cdot\!\!\! & \Big[ \isModexpBase _{i + 1} + \isBlakeData _{i + 1} \Big] \vspace{2mm} \\ + + & \isBlakeData _{i} & \!\!\!\cdot\!\!\! & \isBlakeParams _{i + 1} \\ + + & \isBlakeParams _{i} & \!\!\!\cdot\!\!\! & \isBlakeResult _{i + 1} \\ + + & \isBlakeResult _{i} & \!\!\!\cdot\!\!\! & \Big[ \isModexpBase _{i + 1} + \isBlakeData _{i + 1} \Big] \vspace{2mm} \\ + \end{array} \right] +\] +\begin{enumerate}[resume] + \item \If $\blkMdxStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\index_{i} \neq \indexMax_{i}$ \Then + \[ + \left\{ \begin{array}{lclr} + \index_{i + 1} & = & 1 + \index_{i} \\ + \locTransitionBit_{i} & = & 0 & (\trash) \\ + \end{array} \right. + \] + \item \If $\index_{i} = \indexMax_{i}$ \Then + \[ + \left\{ \begin{array}{lclr} + \index_{i + 1} & = & 0 & (\trash) \\ + \locTransitionBit_{i} & = & 1 \\ + \end{array} \right. + \] + \end{enumerate} + \item \If $\blkMdxStamp_{N} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \index _{N} = \indexMax_{N} & \quad(\trash) \\ + \isModexpResult _{N} + \isBlakeResult _{N} = 1 & \quad(\trash) \\ + \end{array} \right. + \] + \saNote{}\label{blkmdx: finalization constraints are useless} These finalization constraints may be dropped as the only way the results may find their way into \textsc{ram} is by being fully loaded into \textsc{ram}, which requires the index to reach its maximal value in the present module. +\end{enumerate} diff --git a/prc/blkmdx/intro.tex b/prc/blkmdx/intro.tex new file mode 100644 index 0000000..2d2f389 --- /dev/null +++ b/prc/blkmdx/intro.tex @@ -0,0 +1,3 @@ +The \blkMdxMod{} module is a data module for the \inst{MODEXP} and \inst{BLAKE2f} precompiles. +It serves as a passage point for data extracted from \textsc{ram} to be funneled to the relevant \inst{MODEXP} and \inst{BLAKE2f} circuits. +It serves no purpose beyond storing data. diff --git a/prc/blkmdx/lookups/blakemodxp_into_wcp.tex b/prc/blkmdx/lookups/blakemodxp_into_wcp.tex new file mode 100644 index 0000000..a62c917 --- /dev/null +++ b/prc/blkmdx/lookups/blakemodxp_into_wcp.tex @@ -0,0 +1,32 @@ +The purpose of the present lookup argument is to delegate the proof of lexicographic ordering of $\modexpBlakeId$ to the \wcpMod{} module. +We define the shorthand $\locIsFirstDataRow$: +\begin{enumerate} + \item \If $\blkMdxStamp_{i} = 0$ \Then $\locIsFirstDataRow_{i} = 0$ + \item \If $\blkMdxStamp_{i} \neq 0$ \Then $\locIsFirstDataRow_{i} = \blkMdxStamp_{i} - \blkMdxStamp_{i-1}$ +\end{enumerate} +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\locIsFirstDataRow_{i}$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $0$ + \item $\modexpBlakeId_{i - 1}$ + \item $0$ + \item $\modexpBlakeId_{i}$ + \item $1$ + \item $\inst{LT}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/prc/blkmdx/lua/blake.lua.tex b/prc/blkmdx/lua/blake.lua.tex new file mode 100644 index 0000000..857cb6b --- /dev/null +++ b/prc/blkmdx/lua/blake.lua.tex @@ -0,0 +1,108 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + ███████\ ██\ ██████\ ██\ ██\ ████████\ ██████\ ██████\ + ██ __██\ ██ | ██ __██\ ██ | ██ |██ _____|██ __██\ ██ __██\ + ██ | ██ |██ | ██ / ██ |██ |██ / ██ | \__/ ██ |██ / \__| + ███████\ |██ | ████████ |█████ / █████\ ██████ |████\ + ██ __██\ ██ | ██ __██ |██ ██< ██ __| ██ ____/ ██ _| + ██ | ██ |██ | ██ | ██ |██ |\██\ ██ | ██ | ██ | + ███████ |████████\ ██ | ██ |██ | \██\ ████████\ ████████\ ██ | + \_______/ \________|\__| \__|\__| \__|\________|\________|\__| + + + +|----+------------------+-----------+-------+----------------+---------------+-----------------+-----------------| +| ID | PHASE | INDEX_MAX | INDEX | LIMB | IS_BLAKE_DATA | IS_BLAKE_PARAMS | IS_BLAKE_RESULT | +|:--:+:----------------:+:---------:+:-----:+:--------------:+:-------------:+:---------------:+:---------------:| +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +|----+------------------+-----------+-------+----------------+---------------+-----------------+-----------------| +| s | ⟦Φ_blake_data⟧ | 12 | 0 | h_0 , h_1 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 1 | h_2 , h_3 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 2 | h_4 , h_5 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 3 | h_6 , h_7 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 4 | m_0 , m_1 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 5 | m_2 , m_3 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 6 | m_4 , m_5 | 1 | | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | | +| s | ⟦Φ_blake_data⟧ | 12 | 11 | m_14 , m_15 | 1 | | | +| s | ⟦Φ_blake_data⟧ | 12 | 12 | t_low , t_high | 1 | | | +|----+------------------+-----------+-------+----------------+---------------+-----------------+-----------------| +| s | ⟦Φ_blake_params⟧ | 1 | 0 | r | | 1 | | +| s | ⟦Φ_blake_params⟧ | 1 | 1 | f | | 1 | | +|----+------------------+-----------+-------+----------------+---------------+-----------------+-----------------| +| s | ⟦Φ_blake_res⟧ | 3 | 0 | res_3 | | | 1 | +| s | ⟦Φ_blake_res⟧ | 3 | 1 | res_2 | | | 1 | +| s | ⟦Φ_blake_res⟧ | 3 | 2 | res_1 | | | 1 | +| s | ⟦Φ_blake_res⟧ | 3 | 3 | res_0 | | | 1 | +|----+------------------+-----------+-------+----------------+---------------+-----------------+-----------------| +|----+------------------+-----------+-------+----------------+---------------+-----------------+-----------------| +| s' | ⟦Φ_blake_data⟧ | 12 | 0 | h_0' , h_1' | 1 | | | +| s' | ⟦Φ_blake_data⟧ | 12 | 1 | h_2' , h_3' | 1 | | | +| s' | ⟦Φ_blake_data⟧ | 12 | 2 | h_4' , h_5' | 1 | | | +| s' | ⟦Φ_blake_data⟧ | 12 | 3 | h_6' , h_7' | 1 | | | +| s' | ⟦Φ_blake_data⟧ | 12 | 4 | m_0' , m_1' | 1 | | | +| s' | ⟦Φ_blake_data⟧ | 12 | 5 | m_2' , m_3' | 1 | | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | | + +Let D ∈ 𝔹[213] represent the input data slice. Inputs (i.e. call data) of the wrong size are weeded out in the HUB module and +don't make it to the present module. The ⟦Φ_blake_params⟧ phase serves up the data of the integers r and f. These are defined +from input data as follows: + + r ≡ D[0..4], r = [r0, r1, r2, r3] + f ≡ D[212] + +They are respectively a 4 byte integer and a byte. If r > call_gas or f ∉ { 0, 1 } the data doesn't make it to the present +module' tracing. These are represented as the following integers in the traces + + r ⇔ 0x 00 00 00 00 00 00 00 00 00 00 00 00 r0 r1 r2 r3 + f ⇔ 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f + +NOTE. the final byte is the value of the BLAKE parameter f (0 or 1) not the hex value "0x 0f" (15). +There are then the data fields. We take the input data I + + I ≡ D[4..212] ∈ 𝔹[208] + +and chop it up into thirteen 16-byte slices as follows + + I[0..16] ∈ 𝔹[16] + I[16..32] ∈ 𝔹[16] + ⋮ + I[192..208] ∈ 𝔹[16] + +These get written in the 13 consecutive rows of the ⟦Φ_blake_data⟧ phase. + +NOTE. What we have represented above as "h_0, h_1" etc is the concatenation of the 8 byte integers that underlie these values. +See [EYP]. + +The result of BLAKE2f is a slice of bytes res ∈ 𝔹[64] which the present module serves up as four 16 byte slices res_k ∈ 𝔹[16] + + res_3 ≡ res[ 0..16] + res_2 ≡ res[16..32] + res_1 ≡ res[32..48] + res_0 ≡ res[48..64] +\end{verbatim} + +\end{document} + + diff --git a/prc/blkmdx/lua/modexp.lua.tex b/prc/blkmdx/lua/modexp.lua.tex new file mode 100644 index 0000000..3bd0e60 --- /dev/null +++ b/prc/blkmdx/lua/modexp.lua.tex @@ -0,0 +1,145 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\begin{document} +\begin{verbatim} + ██\ ██\ ██████\ ███████\ ████████\ ██\ ██\ ███████\ + ███\ ███ |██ __██\ ██ __██\ ██ _____|██ | ██ |██ __██\ + ████\ ████ |██ / ██ |██ | ██ |██ | \██\ ██ |██ | ██ | + ██\██\██ ██ |██ | ██ |██ | ██ |█████\ \████ / ███████ | + ██ \███ ██ |██ | ██ |██ | ██ |██ __| ██ ██< ██ ____/ + ██ |\█ /██ |██ | ██ |██ | ██ |██ | ██ /\██\ ██ | + ██ | \_/ ██ | ██████ |███████ |████████\ ██ / ██ |██ | + \__| \__| \______/ \_______/ \________|\__| \__|\__| + + + +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| ID | PHASE | INDEX_MAX | INDEX | LIMB | IS_MODEXP_BASE | IS_MODEXP_EXPONENT | IS_MODEXP_MODULUS | IS_MODEXP_RESULT | +|:---:+:-------------------:+:---------:+:-----:+:--------------------------------------------------:+:--------------:+:------------------:+:-----------------:+:----------------:| +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| s | ⟦Φ_modexp_base⟧ | 31 | 0 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 1 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 2 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 3 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 4 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 5 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 6 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 26 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 27 | 0x 00 00 00 00 00 00 00 00 00 9f a0 61 82 c5 19 78 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 28 | 0x 79 a5 24 c2 00 b2 d6 29 c7 38 c9 14 17 87 f7 9a | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 29 | 0x 89 81 2d 52 54 06 55 a6 08 cd 5b c2 de 4b f3 d0 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 30 | 0x 6a fd ca 5e d6 d5 70 df 10 4d a6 9f 7f c1 64 46 | 1 | | | | +| s | ⟦Φ_modexp_base⟧ | 31 | 31 | 0x 95 b4 d5 f3 1c 60 03 3d 3e 0e b0 ab 41 b2 1a 0a | 1 | | | | +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| s | ⟦Φ_modexp_exponent⟧ | 31 | 0 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | 1 | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 1 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | 1 | | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | ⋮ | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 26 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | 1 | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 27 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e5 25 | | 1 | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 28 | 0x 34 7e 60 f2 b1 b8 f0 22 3d 64 b4 e3 cf 6c 66 51 | | 1 | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 29 | 0x 43 a1 10 af da a0 55 49 75 67 7a 20 4b 9c 0a c6 | | 1 | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 30 | 0x e6 5b 55 95 a9 8d 2d 70 49 41 c1 e5 c0 87 7f be | | 1 | | | +| s | ⟦Φ_modexp_exponent⟧ | 31 | 31 | 0x b9 79 c2 23 06 98 b0 29 8f cd 8b f5 41 62 e8 08 | | 1 | | | +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| s | ⟦Φ_modexp_modulus⟧ | 31 | 0 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | | 1 | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 1 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | | 1 | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | | ⋮ | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 26 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | | 1 | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 27 | 0x 00 00 00 00 00 00 00 60 99 29 45 82 26 d6 69 af | | | 1 | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 28 | 0x d9 69 75 be 66 8e df 2e cd 22 6d 7e 49 f7 04 47 | | | 1 | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 29 | 0x 20 d2 74 13 f2 61 ab fb ee c4 36 29 62 5b 33 b8 | | | 1 | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 30 | 0x 38 1f cd bf df a4 f7 7c f1 8a ed 2b 7c 43 66 be | | | 1 | | +| s | ⟦Φ_modexp_modulus⟧ | 31 | 31 | 0x 16 7f 8f a2 2b 8f d2 32 46 bc cd 94 eb d8 f7 53 | | | 1 | | +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| s | ⟦Φ_modexp_res⟧ | 31 | 0 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | | | 1 | +| s | ⟦Φ_modexp_res⟧ | 31 | 1 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | | | 1 | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | | | ⋮ | +| s | ⟦Φ_modexp_res⟧ | 31 | 26 | 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | | | | 1 | +| s | ⟦Φ_modexp_res⟧ | 31 | 27 | 0x 00 00 00 00 00 00 00 30 81 4a e5 de 86 55 2e 2d | | | | 1 | +| s | ⟦Φ_modexp_res⟧ | 31 | 28 | 0x 1b 46 df 79 20 2a 54 da 13 83 a6 a8 f7 4b 35 4c | | | | 1 | +| s | ⟦Φ_modexp_res⟧ | 31 | 29 | 0x fd 5d d6 7e d0 1c fb a0 d8 87 45 a2 d0 ad 13 60 | | | | 1 | +| s | ⟦Φ_modexp_res⟧ | 31 | 30 | 0x d3 5c 27 5a b7 ce 78 26 66 5f 08 82 70 1c 29 e5 | | | | 1 | +| s | ⟦Φ_modexp_res⟧ | 31 | 31 | 0x 33 11 4a 90 70 85 a1 6b 65 1e 78 3b 00 67 7a 51 | | | | 1 | +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| s' | ⟦Φ_modexp_base⟧ | 31 | 0 | 0x ... | 1 | | | | +| s' | ⟦Φ_modexp_base⟧ | 31 | 1 | 0x ... | 1 | | | | +| s' | ⟦Φ_modexp_base⟧ | 31 | 2 | 0x ... | 1 | | | | +| s' | ⟦Φ_modexp_base⟧ | 31 | 3 | 0x ... | 1 | | | | +| s' | ⟦Φ_modexp_base⟧ | 31 | 4 | 0x ... | 1 | | | | +| s' | ⟦Φ_modexp_base⟧ | 31 | 5 | 0x ... | 1 | | | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | +| s' | ⟦Φ_modexp_res⟧ | 31 | 30 | 0x ... | | | | 1 | +| s' | ⟦Φ_modexp_res⟧ | 31 | 31 | 0x ... | | | | 1 | +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +|-----+---------------------+-----------+-------+----------------------------------------------------+----------------+--------------------+-------------------+------------------| +| s'' | ⟦Φ_modexp_base⟧ | 31 | 0 | 0x ... | 1 | | | | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | +\end{verbatim} +\end{document} + +% Φ_modexp_base +% Φ_modexp_exponent +% Φ_modexp_modulus +% Φ_modexp_res + +\iffalse +B: 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 9f a0 61 82 c5 19 78 + 79 a5 24 c2 00 b2 d6 29 c7 38 c9 14 17 87 f7 9a + 89 81 2d 52 54 06 55 a6 08 cd 5b c2 de 4b f3 d0 + 6a fd ca 5e d6 d5 70 df 10 4d a6 9f 7f c1 64 46 + 95 b4 d5 f3 1c 60 03 3d 3e 0e b0 ab 41 b2 1a 0a +E: 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e5 25 + 34 7e 60 f2 b1 b8 f0 22 3d 64 b4 e3 cf 6c 66 51 + 43 a1 10 af da a0 55 49 75 67 7a 20 4b 9c 0a c6 + e6 5b 55 95 a9 8d 2d 70 49 41 c1 e5 c0 87 7f be + b9 79 c2 23 06 98 b0 29 8f cd 8b f5 41 62 e8 08 +M: 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 60 99 29 45 82 26 d6 69 af + d9 69 75 be 66 8e df 2e cd 22 6d 7e 49 f7 04 47 + 20 d2 74 13 f2 61 ab fb ee c4 36 29 62 5b 33 b8 + 38 1f cd bf df a4 f7 7c f1 8a ed 2b 7c 43 66 be + 16 7f 8f a2 2b 8f d2 32 46 bc cd 94 eb d8 f7 53 +R: 0x 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 + 00 00 00 00 00 00 00 30 81 4a e5 de 86 55 2e 2d + 1b 46 df 79 20 2a 54 da 13 83 a6 a8 f7 4b 35 4c + fd 5d d6 7e d0 1c fb a0 d8 87 45 a2 d0 ad 13 60 + d3 5c 27 5a b7 ce 78 26 66 5f 08 82 70 1c 29 e5 + 33 11 4a 90 70 85 a1 6b 65 1e 78 3b 00 67 7a 51 +\fi + +\iffalse +computations done using https://www.boxentriq.com/code-breaking/modular-exponentiation +B: +00000000000000000000000000000000009fa06182c5197879a524c200b2d629c738c9141787f79a89812d52540655a608cd5bc2de4bf3d06afdca5ed6d570df104da69f7fc1644695b4d5f31c60033d3e0eb0ab41b21a0a +E: +00000000000000000000000000000000000000000000e525347e60f2b1b8f0223d64b4e3cf6c665143a110afdaa0554975677a204b9c0ac6e65b5595a98d2d704941c1e5c0877fbeb979c2230698b0298fcd8bf54162e808 +M: +000000000000000000000000000000609929458226d669afd96975be668edf2ecd226d7e49f7044720d27413f261abfbeec43629625b33b8381fcdbfdfa4f77cf18aed2b7c4366be167f8fa22b8fd23246bccd94ebd8f753 +R: +00000000000000000000000000000030814ae5de86552e2d1b46df79202a54da1383a6a8f74b354cfd5dd67ed01cfba0d88745a2d0ad1360d35c275ab7ce7826665f0882701c29e533114a907085a16b651e783b00677a51 +\fi + + diff --git a/prc/ecdata/_inputs.tex b/prc/ecdata/_inputs.tex new file mode 100644 index 0000000..b75d12f --- /dev/null +++ b/prc/ecdata/_inputs.tex @@ -0,0 +1,39 @@ +\section{Introduction} \label{ec data: intro} \input{ecdata/intro} +\section{Columns} \label{ec data: columns} \input{ecdata/columns} +%\subsection{\ecdataSuccessBit{} interpretation \deprecated} \label{ec data: success bit interpretation} \input{ecdata/success_bit} + +\section{Constraints} +\subsection{Binary constraints} \label{ec data: binary} \input{ecdata/binary} +\subsection{Macro instruction decoding and shorthands} \label{ec data: type constraints} \input{ecdata/decoding} +\subsection{Constancy conditions} \label{ec data: counter constancies} \input{ecdata/constancies} +\subsection{Setting \indexMax{}} \label{ec data: setting index max} \input{ecdata/index_max} +\subsection{Setting \ecdataTotalSize{}} \label{ec data: setting total size} \input{ecdata/total_size} +\subsection{Setting \ct{}, \maxCt{}, \isSmallPoint{} and \isLargePoint{}} \label{ec data: setting ct, ct_max, is_large, is_small} \input{ecdata/ct_ctmax_issmall_islarge} +\subsection{Setting \accPairings{}} \label{ec data: setting acc pairings} \input{ecdata/acc_pairings} +\subsection{Setting \internalChecksPassed{}} \label{ec data: setting internal checks have passed} \input{ecdata/internal_checks_passed} +\subsection{Generalities for \membershipTestRequired{}} \label{ec data: generalities for G2 membership test} \input{ecdata/generalities_for_membership_test_required} +\subsection{Generalities for \acceptablePairOfPoints{}} \label{ec data: generalities for acceptable pairs of points} \input{ecdata/generalities_for_acceptable_pairs_of_points} +\subsection{Setting \trivialPairing{}} \label{ec data: setting trivial pairing} \input{ecdata/trivial_pairing} + +\subsection{Heartbeat} \label{ec data: heartbeat} \input{ecdata/heartbeat} +\subsection{Bytehood constraints} \label{ec data: bytehood and accumulator} \input{ecdata/bytehood} +\subsection{\ecdataId{} increment constraints} \label{ec data: stamp increments} \input{ecdata/increments} +\subsection{Setting \notOnGTwo{} and \notOnGTwoAcc{}} \label{ec data: this point is not on G2 and acc} \input{ecdata/this_point_is_not_on_G2} + +\section{Utilities} +\subsection{\wcpMod{} utilities} \label{ec data: wcp utilities} \input{ecdata/utils/wcp} +\subsection{\extMod{} utilities} \label{ec data: ext utilities} \input{ecdata/utils/ext} +\subsection{$C_1$ membership utilities} \label{ec data: c1 membership utilities} \input{ecdata/utils/c1_membership} +\subsection{Well formed coordinates utilities} \label{ec data: c2 membership maybe utilities} \input{ecdata/utils/well_formed_coordinates} + +\section{Lookups} +\subsection{Lookup to the \wcpMod{} module} \label{ec data: lookups: wcp} \input{ecdata/lookup/wcp} +\subsection{Lookup to the \extMod{} module} \label{ec data: lookups: ext} \input{ecdata/lookup/ext} + +\section{Specialized constraints} \label{ec data: specialized constraints} \input{ecdata/specialized/_inputs} + +\section{Elliptic curve circuit flags} \label{ec data: circuits} \input{ecdata/circuits/_inputs} + +\newpage +\section{Trace representations} \label{ec data: trace representations} \input{ecdata/trace_representations} +\section{Visual representation for \inst{ECPAIRING}} \label{ec data: visual representation of ecpairing} \input{ecdata/visual_representation_for_pairings} diff --git a/prc/ecdata/acc_pairings.tex b/prc/ecdata/acc_pairings.tex new file mode 100644 index 0000000..217e573 --- /dev/null +++ b/prc/ecdata/acc_pairings.tex @@ -0,0 +1,17 @@ +We further constrain the $\accPairings$ column as follows: +\begin{enumerate} + \item \accPairings{} is counter-constant \quad (\trash) + \item \If $\isEcpairingData_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accPairings_{i} & = & 0 \\ + \accPairings_{i + 1} & = & \isEcpairingData_{i + 1} \\ + \end{array} \right. + \] + \item \If $\isEcpairingData_{i} = 1$ \Then + \[ + \accPairings_{i+1} + = + \isEcpairingData_{i+1} \cdot (\accPairings_{i} + \locTransitionFromLargeToSmall_{i}) + \] +\end{enumerate} diff --git a/prc/ecdata/all_checks_passed.tex b/prc/ecdata/all_checks_passed.tex new file mode 100644 index 0000000..f95e7b6 --- /dev/null +++ b/prc/ecdata/all_checks_passed.tex @@ -0,0 +1,11 @@ +\begin{enumerate} + \item \If $\ecAdd_i + \ecMul_i \neq 0$ \Then $\allChecksPassed_i = \internalChecksPassed_i$ + \item \If $\ecRecover_i \neq 0$ \Then $\allChecksPassed_i = \internalChecksPassed_i \cdot \ecdsaRecoverPassed_i$ + \item \If $\ecPairing_i \neq 0$ \Then $\allChecksPassed_i = \internalChecksPassed_i \cdot (1 - \notOnGTwoAccMax)$ +\end{enumerate} + +In case of an invalid call, there is no return data: + +\begin{enumerate}[resume] + \item \If $\allChecksPassed_i = 0$ \Then $\returnData_i = 0$ +\end{enumerate} \ No newline at end of file diff --git a/prc/ecdata/binary.tex b/prc/ecdata/binary.tex new file mode 100644 index 0000000..c90598a --- /dev/null +++ b/prc/ecdata/binary.tex @@ -0,0 +1,32 @@ +The following columns must be binary: +\begin{multicols}{2} + \begin{enumerate} + \item \isEcrecoverData + \item \isEcrecoverResult + \item \isEcaddData + \item \isEcaddResult + \item \isEcmulData + \item \isEcmulResult + \item \isEcpairingData + \item \isEcpairingResult + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\noindent We further impose binarity constraints on the following +\begin{multicols}{2} + \begin{enumerate} + \item \wcpFlag + \item \extFlag + \item \hurdle + \item \internalChecksPassed + \item \notOnGTwo + \item \notOnGTwoAcc + \item \isInfinity + \item \notOnGTwoAccMax + \item \isSmallPoint + \item \isLargePoint + \item \membershipTestRequired + \item \trivialPairing + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/prc/ecdata/bytehood.tex b/prc/ecdata/bytehood.tex new file mode 100644 index 0000000..9814c2e --- /dev/null +++ b/prc/ecdata/bytehood.tex @@ -0,0 +1,4 @@ +We impose bytehood constraints on $\byteCol{$\Delta$}$: +\begin{enumerate} + \item $\byteCol{$\Delta$}$ must be a byte column +\end{enumerate} diff --git a/prc/ecdata/circuits/G2_non_membership.tex b/prc/ecdata/circuits/G2_non_membership.tex new file mode 100644 index 0000000..6cb1691 --- /dev/null +++ b/prc/ecdata/circuits/G2_non_membership.tex @@ -0,0 +1,17 @@ +The present section selects the rows of supposed $G_2$ points that are predicted not to belong to $G_2$. +These are sent off to the relevant ``$G_2$ membership'' circuit. +\begin{enumerate} + \item \If $\notOnGTwoAccMax_{i} = 1$ \Then + \begin{enumerate} + \item + $\acceptablePairOfPoints_{i} = 0$ + \item\label{prc: ec data: successful pairing: setting G2 non membership} + $\membershipTestRequired _{i} = \notOnGTwo_{i}$ + \item + \If $\membershipTestRequired _{i} = 1$ \Then $\isInfinity_{i} = 0$ + \end{enumerate} +\end{enumerate} +In other words we select a large point for the $G_2$ nonmembership test (i.e. $\membershipTestRequired _{i} \equiv 1$) if and only if said point was (the only) +chosen large point nondeterministically marked as not belonging to the $G_2$ subgroup ($\notOnGTwo_{i} \equiv 1$); +furthermore this point may not be the point at infinity. +for the single (supposedly) $G_{2}$ point of which the \zkEvm{} diff --git a/prc/ecdata/circuits/_inputs.tex b/prc/ecdata/circuits/_inputs.tex new file mode 100644 index 0000000..40ba74e --- /dev/null +++ b/prc/ecdata/circuits/_inputs.tex @@ -0,0 +1,3 @@ +\subsection{$G_2$ non membership} \label{ec data: circuits: G2 non membership} \input{ecdata/circuits/G2_non_membership} +\subsection{Successful \inst{ECPAIRING}} \label{ec data: circuits: successful pairing} \input{ecdata/circuits/successful_pairing} +\subsection{Interface for external circuits} \label{ec data: interface for exernal circuits} \input{ecdata/circuits/interface_for_external_circuits} diff --git a/prc/ecdata/circuits/interface_for_external_circuits.tex b/prc/ecdata/circuits/interface_for_external_circuits.tex new file mode 100644 index 0000000..e4f5472 --- /dev/null +++ b/prc/ecdata/circuits/interface_for_external_circuits.tex @@ -0,0 +1,72 @@ +The present section imposes the behaviour of the various circuit selectors. +\begin{description} + \item[Circuit selector for the \inst{ECRECOVER} circuit:] + $\csEcrecover_{i} = \internalChecksPassed_{i} \cdot \locIsEcrecover_{i}$ + \item[Circuit selector for the \inst{ECADD} circuit:] + $\csEcadd_{i} = \internalChecksPassed_{i} \cdot \locIsEcadd_{i}$ + \item[Circuit selector for the \inst{ECMUL} circuit:] + $\csEcmul_{i} = \internalChecksPassed_{i} \cdot \locIsEcmul_{i}$ + \item[Circuit selector for the \inst{ECPAIRING} circuit:] + \[ + \begin{array}{lcl} + \csEcpairing_{i} & \equiv & + \left[ \begin{array}{clcr} + \wedge & \locIsEcpairing_{i} & \equiv & \texttt{true} \\ + \wedge & \internalChecksPassed_{i} & \equiv & \texttt{true} \\ + \wedge & \notOnGTwoAccMax_{i} & \equiv & \texttt{false} \\ + \wedge & \acceptablePairOfPoints_{i} & \equiv & \texttt{true} \\ + \end{array} \right] \vspace{2mm} \\ + & \equiv & + \left[ \begin{array}{clcr} + \cdot & \locIsEcpairing_{i} \\ + \cdot & \internalChecksPassed_{i} \\ + \cdot & (1 - \notOnGTwoAccMax_{i}) \\ + \cdot & \acceptablePairOfPoints_{i} \\ + \end{array} \right] \vspace{2mm} \\ + & = & \acceptablePairOfPoints_{i} \\ + \end{array} + \] + \item[Circuit selector for the \inst{G2\_MEMBERSHIP\_TEST} circuit:] + \[ + \begin{array}{lcl} + \csGTwo_{i} & \equiv & + \left[ \begin{array}{clcr} + \wedge & \isEcpairingData_{i} & \equiv & \texttt{true} \\ + \wedge & \internalChecksPassed_{i} & \equiv & \texttt{true} \\ + \wedge & \membershipTestRequired_{i} & \equiv & \texttt{true} \\ + \end{array} \right] \vspace{2mm} \\ + & \equiv & + \left[ \begin{array}{clcr} + \cdot & \isEcpairingData_{i} \\ + \cdot & \internalChecksPassed_{i} \\ + \cdot & \membershipTestRequired_{i} \\ + \end{array} \right] \vspace{2mm} \\ + & = & \membershipTestRequired_{i} \\ + \end{array} + \] +\end{description} + +Note that, at most one of the circuit selectors may light up for a given row: +\begin{enumerate} + \item $\csEcrecover_{i} + \csEcadd_{i} + \csEcmul_{i} + \csEcpairing_{i} + \csGTwo_{i}$ is binary \quad (\trash) +\end{enumerate} +The data that should be read by external circuits are always the following: +\begin{enumerate} + \item \ecdataId{} + \item \ecdataIndex{} + \item \ecdataLimb{} + \item \ecdataSuccessBit{} +\end{enumerate} + +\saNote{} +Whenever $\ecdataSuccessBit = 0$ then $\csEcpairing = 0$, while if $\ecdataSuccessBit = 1$ then $\csEcpairing = \acceptablePairOfPoints$. + +\saNote{} +Given the \ecDataMod{} is processing \inst{ECPAIRING} instructions, the $\csGTwo$ flag lights up under two circumstances: +\begin{enumerate} + \item $\internalChecksPassed = 1$, $\ecdataSuccessBit = 0$ along the rows of first large point that is predicted not to lie on the $G_2$ subgroup; + \item $\internalChecksPassed = 1$, $\ecdataSuccessBit = 1$ along the rows of the large point of every pair of the form $(\infty, \locB)$; +\end{enumerate} + + + diff --git a/prc/ecdata/circuits/successful_pairing.tex b/prc/ecdata/circuits/successful_pairing.tex new file mode 100644 index 0000000..3af80bb --- /dev/null +++ b/prc/ecdata/circuits/successful_pairing.tex @@ -0,0 +1,38 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \left\{ \begin{array}{lcl} + \isEcpairingData _{i} & = & 1 \\ + \accPairings _{i} & \neq & \accPairings _{i - 1} \\ + \end{array} \right. + } +\] +We are thus assuming that the $i$-th row is the first row of either the first (or a new) pair of points passed on to the \inst{ECPAIRING} precompile. +We introduce the following shorthands: +\[ + \left\{ \begin{array}{lclr} + \locSmallPointInfinity & \define & \isInfinity_{i} \\ + \locLargePointInfinity & \define & \isInfinity_{i + 4} \\ + \end{array} \right. +\] +\begin{enumerate} + \item \If $\ecdataSuccessBit _{i} = 1$ \Then + \begin{enumerate} + \item \If $\locLargePointInfinity = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \membershipTestRequired _{i + 4} & = & 0 \\ + \acceptablePairOfPoints _{i} & = & 0 \\ + \end{array} \right. + \] + \item\label{prc: ec data: successful pairing: setting membershipTestRequired} \If $\locLargePointInfinity = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \membershipTestRequired _{i + 4} & = & \locSmallPointInfinity \\ + \acceptablePairOfPoints _{i} & = & (1 - \locSmallPointInfinity) \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} +\saNote{} +\acceptablePairOfPoints{} is \textbf{pair-of-points-constant} and \membershipTestRequired{} are \textbf{counter-constant}. + diff --git a/prc/ecdata/columns.tex b/prc/ecdata/columns.tex new file mode 100644 index 0000000..634fb9b --- /dev/null +++ b/prc/ecdata/columns.tex @@ -0,0 +1,110 @@ +The first batch of columns arrives to the present module from the \mmioMod{} module: +\begin{enumerate} + \item \ecDataStamp{}: %\markAsExtractedFromMmio{}: + module stamp; has simple $0/1$ increments; + \item \ecdataId{}: %\markAsExtractedFromMmio{}: + unique identifier of a precompile \inst{CALL} triggering the present module; + contains a context number derived from the \hubStamp{}; + \item \ecdataIndex{}: %\markAsExtractedFromMmio{}: + data limb index; + \item \ecdataLimb{}: %\markAsExtractedFromMmio{}: + data limb; either input or output; + \item \ecdataTotalSize{}: %\markAsExtractedFromMmio{}: + total size of input or output; Especially relevant for \inst{ECPAIRING} which has variable size inputs; + \item \ecdataPhase{}: %\markAsExtractedFromMmio{}: + phase identifying which precompile is being called and whether the data represents inputs or outputs; + \item \indexMax{}: %\markAsExtractedFromMmio{}: + maximum value of \ecdataIndex{} for a given phase; + \item \ecdataSuccessBit{} \hubMmuMmioPrediction{} \markAsPartiallyJustifiedHere{}: + success bit of the operation; +\end{enumerate} + +The following columns partake in the ``instruction decoding'' of the above: +\begin{multicols}{2} + \begin{enumerate}[resume] + \item \isEcrecoverData + \item \isEcrecoverResult + \item \isEcaddData + \item \isEcaddResult + \item \isEcmulData + \item \isEcmulResult + \item \isEcpairingData + \newcounter{enumTemp} + \setcounter{enumTemp}{\theenumi}\item \isEcpairingResult + \end{enumerate} +\end{multicols} +The following columns partake in the ``instruction decoding'' of the above: +\begin{enumerate}[resume] \setcounter{enumi}{1+\theenumTemp} + \item \totalPairings: + In the context of pairings, equals to the number of pairings passed to the precompile; + \item \accPairings: In the context of pairings, counts the pairs starting from 1. It is equal to 0 otherwise. + \item \both{\internalChecksPassed}: + binary column, constant for a given \ecdataId, which lights up when all the internal checks passed. + \item \hurdle: + binary columns used to compute the value of \internalChecksPassed; + \item $\byteCol{$\Delta$}$: + byte column; used to justify that \ecdataId{} increments; +\end{enumerate} + +The following batch of columns is relevant in the context of \inst{ECPAIRING}. +In what follows we refer to data supposedly containing a $C_1$ point as \textbf{small points} and to data supposedly containing a $G_2$ point as \textbf{large points}. +\begin{enumerate}[resume] + \item \ct: + for each pair of points, counts from 0 to \ctMaxSmallPoint{} and from 0 to \ctMaxLargePoint{} (see definitions in \ref{ec data: setting ct, ct_max, is_large, is_small}) along the coordinate of the small and large point respectively; + \item \maxCt: + the maximum value $\ct$ should count to; + \item \isSmallPoint: + binary column, which lights up when the point is small; + \item \isLargePoint: + binary column, which lights up when the point is large; + \item \notOnGTwo{} \ecDataPrediction{}: + binary column, which lights up on the 8 lines of a point that is not on $G_2$ (the second point, in the context of pairings). If 2 (or more) points are not on $G_2$, it only lights up for the first one. An external circuit must then justify that this point is indeed not on $G_2$; + \item \notOnGTwoAcc: + binary column which lignts up when $\notOnGTwo$ equals $1$; + \item \notOnGTwoAccMax: + binary column which lights up if there is a point that is not on $G_2$ (equals to the final value of \notOnGTwoAcc); + \item \isInfinity: + binary column; + constant along the 4 or 8 rows occupied by a (supposed) curve point; + lights up precisely when all coordinates of said point vanish; + \item \both{\trivialPairing}: binary column; the last data row of each pairing indicates if we are in a trivial case, in the sense that all small points belongs to $C_1$ and all large points are points at infinity; + \item \both{\membershipTestRequired}: + constant along the 8 rows containing a supposed $G_2$ point and zero along $C_1$ points. It lights up when the large point is predicted to be not on $G_2$ or when the small point is the point at infinity; + \item \both{\acceptablePairOfPoints}: + constant along the 12 rows of a pair of points. It lights up when the small point is on the curve, the large point is predicted to be on the $G_2$ subgroup and neither of the points is the point at infinity; +\end{enumerate} + +The following columns defines the external circuits interface: +\begin{enumerate}[resume] + \item \both{\csEcrecover}: indicates if inputs should be sent to the circuit for \inst{ECRECOVER}; + \item \both{\csEcadd}: indicates if inputs should be sent to the circuit for \inst{ECADD}; + \item \both{\csEcmul}: indicates if inputs should be sent to the circuit for \inst{ECMUL}; + \item \both{\csEcpairing}: indicates if inputs should be sent to the circuit for \inst{ECPAIRING}; + \item \both{\csGTwo}: indicates if inputs should be sent to the circuit for $G_2$ membership test; +\end{enumerate} +The following columns are used for the $\wcpMod$ lookup and the $\extMod$ lookup respectively +\begin{multicols}{2} + \begin{enumerate}[resume] + \item \wcpFlag + \item \wcpArgOneHi + \item \wcpArgOneLo + \item \wcpArgTwoHi + \item \wcpArgTwoLo + \item \wcpRes + \item \wcpInst + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \item \extFlag + \item \extArgOneHi + \item \extArgOneLo + \item \extArgTwoHi + \item \extArgTwoLo + \item \extArgThreeHi + \item \extArgThreeLo + \item \extResHi + \item \extResLo + \item \extInst + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/prc/ecdata/constancies.tex b/prc/ecdata/constancies.tex new file mode 100644 index 0000000..2fbaa1f --- /dev/null +++ b/prc/ecdata/constancies.tex @@ -0,0 +1,60 @@ +% \lorenzo{double check this} + +A column $\col{X}$ is \textbf{stamp-constant} if +\[ + \If \ecDataStamp_{i} \neq 1 + \ecDataStamp_{i - 1} ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +A column $\col{X}$ is \textbf{index-constant} if +\[ + \If \ecdataIndex_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +A colum \col{X} is \textbf{counter-constant} if +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1} +\] +A colum \col{X} is \textbf{pair-of-points-constant} if +\[ + \If + \left\{ \begin{array}{lcl} + \accPairings_{i} & \neq & 0 \\ + \accPairings_{i + 1} & \neq & 1 + \accPairings_{i} \\ + \end{array} \right. + \Then + \col{X}_{i + 1} = \col{X}_{i} +\] +We impose stamp-constancy on the following columns +\begin{multicols}{2} + \begin{enumerate} + \item \ecdataId{} + \item \ecdataSuccessBit{} + \item \totalPairings{} + \item \internalChecksPassed{} + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +We impose index-constancy on the following columns +\begin{multicols}{1} + \begin{enumerate} + \item \ecdataPhase{} + \item \indexMax{} + \item \notOnGTwoAccMax{} + \end{enumerate} +\end{multicols} +We impose counter-constancy on the following columns +\begin{multicols}{3} + \begin{enumerate} + \item \maxCt + \item \isInfinity + \item \accPairings + \item \trivialPairing + \item \membershipTestRequired{} + \item \notOnGTwo{} + \item \notOnGTwoAcc{} + \end{enumerate} +\end{multicols} +We impose pair-of-points-constant on the following column +\begin{multicols}{3} + \begin{enumerate} + \item \acceptablePairOfPoints{} + \end{enumerate} +\end{multicols} diff --git a/prc/ecdata/ct_ctmax_issmall_islarge.tex b/prc/ecdata/ct_ctmax_issmall_islarge.tex new file mode 100644 index 0000000..771513e --- /dev/null +++ b/prc/ecdata/ct_ctmax_issmall_islarge.tex @@ -0,0 +1,76 @@ +The present section provides constraints for +\isSmallPoint{}, \isLargePoint{}, +\maxCt{} and \ct{}. +The constraints for these columns are tightly intertwined. +We start by defining the following module constants +\[ + \left\{ \begin{array}{lcl} + \ctMaxSmallPoint & \!\!\! \define \!\!\! & \redm{3} \\ + \ctMaxLargePoint & \!\!\! \define \!\!\! & \redm{7} \\ + \end{array} \right. +\] +Then, impose the following constraints +\begin{enumerate} + \item $\isSmallPoint$ and $\isLargePoint$ are binary \quad (\trash) + \item $\isEcpairingData_{i} = \isSmallPoint_{i} + \isLargePoint_{i}$ +\end{enumerate} +\saNote{} +\isEcpairingData{} being binary implicitly enforces that +$\isSmallPoint$ and $\isLargePoint$ are \textbf{exclusive binary flags}. +\begin{enumerate}[resume] + \item we unconditionally impose that + \[ + \begin{array}{l} + \maxCt _{i} = + \left[ \begin{array}{clcl} + + & \ctMaxSmallPoint & \cdot & \isSmallPoint_{i} \\ + + & \ctMaxLargePoint & \cdot & \isLargePoint_{i} \\ + \end{array} \right] \\ + \end{array} + \] + \item $\maxCt$ is counter-constant \quad (\trash) + \item $\isSmallPoint$ and $\isLargePoint$ are counter-constant \quad (\trash) +\end{enumerate} +\saNote{} Counter-constancy of \maxCt{} and binaryness of $\isSmallPoint$ and $\isLargePoint$ implicitly imposes counter-constancy of $\isSmallPoint$ and $\isLargePoint$, +whence the (\trash) symbol. + +We now move on to the \textbf{transitions} of $\isSmallPoint$ and $\isLargePoint$. +The first constraint below imposes that small points appear before large points, +while the second constraint imposes that small and large points ``alternate.'' +\begin{enumerate}[resume] + \item \If $\isEcpairingData_{i} = 0$ \Then $\isSmallPoint_{i + 1} = \isEcpairingData_{i + 1}$ + \item \If $\isEcpairingData_{i} = 1$ \et $\isEcpairingData_{i+1} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then + \[ + \locTransitionFromSmallToLarge_{i} + \locTransitionFromLargeToSmall_{i} = 0 \quad (\trash) + \] + \item \If $\ct_{i} = \maxCt_{i}$ \Then + \[ + \locTransitionFromSmallToLarge_{i} + \locTransitionFromLargeToSmall_{i} = 1 + \] + \end{enumerate} + where we use the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locTransitionFromSmallToLarge_{i} & \define & \isSmallPoint_{i} \cdot \isLargePoint_{i + 1} \\ + \locTransitionFromLargeToSmall_{i} & \define & \isLargePoint_{i} \cdot \isSmallPoint_{i + 1} \\ + \end{array} \right. + \] + \saNote{} The ``$\ct_{i} \neq \maxCt_{i}$'' case is redundant by counter-constancy of $\isSmallPoint$ and $\isLargePoint$, + whence the (\trash) symbol. +\end{enumerate} +We now impose standard constraints on the \ct, \maxCt{} pair: +\begin{enumerate}[resume] + \item \If $\isEcpairingData_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \ct_{i} & = & 0 \\ + \ct_{i + 1} & = & 0 \\ + \end{array} \right. + \] + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then $\ct_{i + 1} = 0$ +\end{enumerate} + +\saNote{} These columns are only pertinent for the processing of \inst{ECPAIRING}'s. diff --git a/prc/ecdata/decoding.tex b/prc/ecdata/decoding.tex new file mode 100644 index 0000000..49f3fda --- /dev/null +++ b/prc/ecdata/decoding.tex @@ -0,0 +1,125 @@ +We define the usual shorthands +\[ + \left\{ \begin{array}{lcl} + \locIsEcrecover_{i} & \define & + \left[ \begin{array}{cr} + + & \isEcrecoverData _{i} \\ + + & \isEcrecoverResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locIsEcadd_{i} & \define & + \left[ \begin{array}{cr} + + & \isEcaddData _{i} \\ + + & \isEcaddResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locIsEcmul_{i} & \define & + \left[ \begin{array}{cr} + + & \isEcmulData _{i} \\ + + & \isEcmulResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locIsEcpairing_{i} & \define & + \left[ \begin{array}{cr} + + & \isEcpairingData _{i} \\ + + & \isEcpairingResult _{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcl} + \locFlagSum_{i} & \define & + \left[ \begin{array}{cr} + + & \locIsEcrecover _{i} \\ + + & \locIsEcadd _{i} \\ + + & \locIsEcmul _{i} \\ + + & \locIsEcpairing _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locAddressSum_{i} & \define & + \left[ \begin{array}{crcl} + + & 1 & \!\!\!\cdot\!\!\! & \locIsEcrecover _{i} \\ + + & 6 & \!\!\!\cdot\!\!\! & \locIsEcadd _{i} \\ + + & 7 & \!\!\!\cdot\!\!\! & \locIsEcmul _{i} \\ + + & 8 & \!\!\!\cdot\!\!\! & \locIsEcpairing _{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +and +\[ + \weightedPhaseFlagSum_{i} \define + \left[ \begin{array}{crcl} + + & \phaseEcrecoverData & \!\!\!\cdot\!\!\! & \isEcrecoverData _{i} \\ + + & \phaseEcrecoverResult & \!\!\!\cdot\!\!\! & \isEcrecoverResult _{i} \\ + + & \phaseEcaddData & \!\!\!\cdot\!\!\! & \isEcaddData _{i} \\ + + & \phaseEcaddResult & \!\!\!\cdot\!\!\! & \isEcaddResult _{i} \\ + + & \phaseEcmulData & \!\!\!\cdot\!\!\! & \isEcmulData _{i} \\ + + & \phaseEcmulResult & \!\!\!\cdot\!\!\! & \isEcmulResult _{i} \\ + + & \phaseEcpairingData & \!\!\!\cdot\!\!\! & \isEcpairingData _{i} \\ + + & \phaseEcpairingResult & \!\!\!\cdot\!\!\! & \isEcpairingResult _{i} \\ + \end{array} \right] \\ +\] +and we further define the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locIsData_{i} & \define & + \left[ \begin{array}{cr} + + & \isEcrecoverData _{i} \\ + + & \isEcaddData _{i} \\ + + & \isEcmulData _{i} \\ + + & \isEcpairingData _{i} \\ + % + & \isEcrecoverResult _{i} \\ + % + & \isEcaddResult _{i} \\ + % + & \isEcmulResult _{i} \\ + % + & \isEcpairingResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locIsResult_{i} & \define & + \left[ \begin{array}{crcl} + % + & \isEcrecoverData _{i} \\ + % + & \isEcaddData _{i} \\ + % + & \isEcmulData _{i} \\ + % + & \isEcpairingData _{i} \\ + + & \isEcrecoverResult _{i} \\ + + & \isEcaddResult _{i} \\ + + & \isEcmulResult _{i} \\ + + & \isEcpairingResult _{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{lcrcl} + \locTransitionToData _{i} & \define & (1 - \locIsData_{i}) & \cdot & \locIsData_{i + 1} \\ + \locTransitionToResult _{i} & \define & (1 - \locIsResult_{i}) & \cdot & \locIsResult_{i + 1} \vspace{2mm} \\ + \locTransitionBit_{i} & \define & + \multicolumn{3}{l}{ + \left[ \begin{array}{cl} + + & \locTransitionToData _{i} \\ + + & \locTransitionToResult _{i} \\ + \end{array} \right]} \\ + \end{array} \right. +\] +\saNote{} This quantity is indeed a bit. + +and impose that +\begin{enumerate} + \item $\If \ecDataStamp_{i} = 0$ \Then $\locFlagSum_{i} = 0$ + \item $\If \ecDataStamp_{i} \neq 0$ \Then $\locFlagSum_{i} = 1$ + \item we further impose + \[ + \ecdataPhase_{i} + = + \weightedPhaseFlagSum_{i} + \] +\end{enumerate} +\saNote{} It follows that +\begin{multicols}{4} + \begin{enumerate} + \item \locIsData{} + \item \locIsResult{} + \item \locIsEcrecover{} + \item \locIsEcadd{} + \item \locIsEcmul{} + \item \locIsEcpairing{} + \item \locFlagSum{} + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\noindent are binary. diff --git a/prc/ecdata/generalities_for_acceptable_pairs_of_points.tex b/prc/ecdata/generalities_for_acceptable_pairs_of_points.tex new file mode 100644 index 0000000..e53cdf8 --- /dev/null +++ b/prc/ecdata/generalities_for_acceptable_pairs_of_points.tex @@ -0,0 +1,11 @@ +We impose the following constraints on \acceptablePairOfPoints{}: +\begin{enumerate} + \item \acceptablePairOfPoints{} is \textbf{pair-of-points-constant, binary} \quad (\trash) + \item \If $\acceptablePairOfPoints_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \ecdataSuccessBit _{i} & = & 1 \\ + \locIsEcpairing _{i} & = & 1 \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/prc/ecdata/generalities_for_membership_test_required.tex b/prc/ecdata/generalities_for_membership_test_required.tex new file mode 100644 index 0000000..fefc124 --- /dev/null +++ b/prc/ecdata/generalities_for_membership_test_required.tex @@ -0,0 +1,14 @@ +We impose the following constraints on \membershipTestRequired{}: +\begin{enumerate} + \item \membershipTestRequired{} is \textbf{counter-constant, binary} \quad (\trash) + \item \If $\membershipTestRequired_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \internalChecksPassed _{i} & = & 1 \\ + \isLargePoint_{i} & = & 1 \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{} The purpose of \membershipTestRequired{} is twofold: +(\emph{a}) in case the present module predicts that some point in the data of a call to the \inst{ECPAIRING} precompile is not on $G_2$ the \membershipTestRequired{} flag selects that point, see section~(\ref{prc: ec data: successful pairing: setting G2 non membership}) +(\emph{b}) in case the present module predicts that all points in the data of the same call are on $G_2$ the \membershipTestRequired{} flag selects for every pair of points $(P,Q)$ those $Q$ whose accompanying $P$ is the point at infinity, see section~(\ref{prc: ec data: successful pairing: setting membershipTestRequired}). diff --git a/prc/ecdata/heartbeat.tex b/prc/ecdata/heartbeat.tex new file mode 100644 index 0000000..2b39488 --- /dev/null +++ b/prc/ecdata/heartbeat.tex @@ -0,0 +1,68 @@ +We impose the following constraints +\begin{enumerate} + \item $\ecDataStamp_{0} = 0$ + \item \If $\locFlagSum_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \ecdataIndex_{i} & = & 0 \\ + \ecdataId_{i} & = & 0 \\ + \end{array} \right. + \] + \item $\ecDataStamp_{i + 1} \in \{ \ecDataStamp_{i}, 1 + \ecDataStamp_{i} \}$ \quad (\trash) + \item we impose $ \ecDataStamp_{i + 1} = \ecDataStamp_{i} + \locTransitionToData _{i} $ + \item \locAddressSum{} is \ecDataStamp{}-constant + \item \If $\ecDataStamp_{i} \neq 0$ \Then we impose + \[ + \left[ \begin{array}{crcl} + + & \isEcrecoverData_{i} & \cdot & \locIsEcrecover_{i + 1} \\ + + & \isEcaddData_{i} & \cdot & \locIsEcadd_{i + 1} \\ + + & \isEcmulData_{i} & \cdot & \locIsEcmul_{i + 1} \\ + + & \isEcpairingData_{i} & \cdot & \locIsEcpairing_{i + 1} \vspace{1mm} \\ + + & \isEcrecoverResult_{i} & \cdot & \isEcrecoverResult_{i + 1} \\ + + & \isEcaddResult_{i} & \cdot & \isEcaddResult_{i + 1} \\ + + & \isEcmulResult_{i} & \cdot & \isEcmulResult_{i + 1} \\ + + & \isEcpairingResult_{i} & \cdot & \isEcpairingResult_{i + 1} \vspace{1mm} \\ + + & \multicolumn{3}{c}{\locTransitionToData _{i}} \\ + % \locIsResult_{i} & \cdot & \locIsData_{i + 1} \\ + \end{array} \right] + = 1 + \] + \item \If $\locTransitionBit_{i} = 1$ \Then $\ecdataIndex_{i + 1} = 0$ + \item \If $\ecDataStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\ecdataIndex_{i} \neq \indexMax_{i}$ \Then $\ecdataIndex_{i + 1} = 1 + \ecdataIndex_{i}$ + \item \If $\ecdataIndex_{i} = \indexMax_{i}$ \Then $\locTransitionBit_{i} = 1$ + \end{enumerate} + \item \ecdataPhase{} is \ecdataIndex{}-constant \quad (\trash) +\end{enumerate} +\saNote{} \ecdataIndex{}-constancy of \ecdataPhase{} implies \ecdataIndex{}-constancy of all of +\begin{multicols}{2} + \begin{enumerate} + \item \isEcrecoverData + \item \isEcrecoverResult + \item \isEcaddData + \item \isEcaddResult + \item \isEcmulData + \item \isEcmulResult + \item \isEcpairingData + \item \isEcpairingResult + \end{enumerate} +\end{multicols} +\noindent We resume stating the ``heartbeat'' constraints. +\begin{enumerate}[resume] + % \item \If $\ecDataStamp_{i} \neq 0$ \et $\ecdataIndex_{i} = \indexMax_{i}$ \Then + % \[ + % \left[ \begin{array}{rcl} + % \locIsResult _{i} & \cdot & \locIsData _{i + 1} \\ + % \locIsData _{i} & \cdot & \locIsResult _{i + 1} \\ + % \end{array} \right] + % = 1 + % \] + \item \If $\ecDataStamp_{N} \neq 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \locIsResult_{N} & = & 1 \\ + \ecdataIndex_{N} & = & \indexMax_{N} \\ + \end{array} \right. + \] +\end{enumerate} diff --git a/prc/ecdata/increments.tex b/prc/ecdata/increments.tex new file mode 100644 index 0000000..ae00f3d --- /dev/null +++ b/prc/ecdata/increments.tex @@ -0,0 +1,14 @@ +The constraint below imposes \textbf{small, positive jumps} (i.e. $0 < \col{jumps} \leq 256^{4}$) in the \ecdataId: +\begin{enumerate} + \item \If $\ecDataStamp_{i + 1} \neq \ecDataStamp_i$ \Then + \[ + \ecdataId_{i + 1} = \ecdataId_{i} + 1 + + \left[ \begin{array}{rcr} + + 256 ^ {3} &\cdot& \byteCol{$\Delta$}_{i + 1} \\ + + 256 ^ {2} &\cdot& \byteCol{$\Delta$}_{i + 2} \\ + + 256 ^ {1} &\cdot& \byteCol{$\Delta$}_{i + 3} \\ + + 256 ^ {0} &\cdot& \byteCol{$\Delta$}_{i + 4} \\ + \end{array} \right] + \] +\end{enumerate} +\saNote{} We imposed that \ecdataId{} starts out at $0$. This imposes that the entries in the \ecdataId{} column are remain relatively small and be listed in ascending order. diff --git a/prc/ecdata/index_max.tex b/prc/ecdata/index_max.tex new file mode 100644 index 0000000..766e712 --- /dev/null +++ b/prc/ecdata/index_max.tex @@ -0,0 +1,46 @@ +We define the following module constants +\[ + \left\{ \begin{array}{lcl} + \indexMaxEcrecoverData & \!\!\! \define \!\!\! & \redm{7} \\ + \indexMaxEcaddData & \!\!\! \define \!\!\! & \redm{7} \\ + \indexMaxEcmulData & \!\!\! \define \!\!\! & \redm{5} \\ + \indexMaxEcPairingDataMin & \!\!\! \define \!\!\! & \redm{11} \\ + \indexMaxEcrecoverResult & \!\!\! \define \!\!\! & \redm{1} \\ + \indexMaxEcaddResult & \!\!\! \define \!\!\! & \redm{3} \\ + \indexMaxEcmulResult & \!\!\! \define \!\!\! & \redm{3} \\ + \indexMaxEcpairingResult & \!\!\! \define \!\!\! & \redm{1} \\ + \end{array} \right. +\] +and define the following shorthand +\[ + \locIndexMaxSum _{i} \define + \left[ \begin{array}{crcl} + + & \indexMaxEcrecoverData & \!\!\!\cdot\!\!\! & \isEcrecoverData _{i} \\ + + & \indexMaxEcaddData & \!\!\!\cdot\!\!\! & \isEcaddData _{i} \\ + + & \indexMaxEcmulData & \!\!\!\cdot\!\!\! & \isEcmulData _{i} \vspace{2mm} \\ + % + & \indexMaxEcpairingData & \!\!\!\cdot\!\!\! & \isEcpairingData _{i} \vspace{1mm} \\ + + & \indexMaxEcrecoverResult & \!\!\!\cdot\!\!\! & \isEcrecoverResult _{i} \\ + + & \indexMaxEcaddResult & \!\!\!\cdot\!\!\! & \isEcaddResult _{i} \\ + + & \indexMaxEcmulResult & \!\!\!\cdot\!\!\! & \isEcmulResult _{i} \\ + + & \indexMaxEcpairingResult & \!\!\!\cdot\!\!\! & \isEcpairingResult _{i} \\ + \end{array} \right] +\] +We then impose the following constraint +\[ + \llarge \cdot \indexMax_{i} + = + \left[ \begin{array}{crcl} + + & \llarge & \!\!\!\cdot\!\!\! & \locIndexMaxSum_{i} \\ + + & \isEcpairingData_{i} & \!\!\!\cdot\!\!\! & \Big[ \ecdataTotalSize_{i} - \llarge \Big] \\ + \end{array} \right] +\] +The above constraint can be rewritten as +\[ + \indexMax_{i} + = + \left[ \begin{array}{crcl} + + & & & \locIndexMaxSum_{i} \\ + + & \isEcpairingData_{i} & \!\!\!\cdot\!\!\! & \Big[ (\indexMaxEcPairingDataMin + 1) \cdot \totalPairings_{i} - 1 \Big] \\ + \end{array} \right] +\] +\saNote{} The (input) data size of a call to the \inst{ECPAIRING} precompile, given that it makes its way into the present module, is always a \textbf{nonzero multiple of 192}. Contrary to other precompile calls dealt with by the present module its size (and hence the associated \indexMax{} value) isn't a fixed constant. \ No newline at end of file diff --git a/prc/ecdata/internal_checks_passed.tex b/prc/ecdata/internal_checks_passed.tex new file mode 100644 index 0000000..624e860 --- /dev/null +++ b/prc/ecdata/internal_checks_passed.tex @@ -0,0 +1,19 @@ +We impose the following constraints: +\begin{enumerate} + \item \internalChecksPassed{} is binary \quad (\trash) + \item \internalChecksPassed{} is stamp-constant \quad (\trash) + \item \If $\locFlagSum _{i} = 0$ \Then $\internalChecksPassed _{i} = 0$ + \item \If $\locTransitionToResult _{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \locInternalChecksPassed & \define & \hurdle _{i} \\ + \internalChecksPassed _{i} & = & \locInternalChecksPassed \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{} Each precompile uses the last data row of the \hurdle{} column to write whether the internal checks passed. This value is indicated through the shorthand \locInternalChecksPassed{}. Then, due to \textbf{stamp-constantcy}, \internalChecksPassed{} column is constant and equal to \locInternalChecksPassed{} for a given \ecDataStamp{}. +\begin{enumerate}[resume] + \item \If $\ecdataSuccessBit _{i} = 1$ \Then $\internalChecksPassed _{i} = 1$ $(\trash)$ +\end{enumerate} +\saNote{} +We label the final constraint (imposing that for an operation to be successful it must have passed the internal checks hurdle) with a $(\trash)$ only because it will be imposed explicitly in the sequel for every elliptic curve operation dealt with in the present module. diff --git a/prc/ecdata/intro.tex b/prc/ecdata/intro.tex new file mode 100644 index 0000000..f1f151c --- /dev/null +++ b/prc/ecdata/intro.tex @@ -0,0 +1,25 @@ +In $\ecDataMod$ module we detect a subset of the possible ways precompiles execution related to elliptic curves can fail. Specifically, for $\ecAdd$ and $\ecMul$ we can determine if they fail or succed. While, in the case of $\ecRecover$ and $\ecPairing$, we can determine if they surely fail or we need to rely on external circuits for determining the outcome of the execution. +This goal is to perform some preliminary checks to avoid sending to the external circuits inputs that are +trivially wrong. + +We define the following shorthands: +\[ + \left\{ + \begin{array}{lcl} + \bnOuterPrime + & \!\!\! = \!\!\! & \bnOuterPrimeHex \\ + \bnOuterPrimeHi + & \!\!\! = \!\!\! & \bnOuterPrimeHexHi \\ + \bnOuterPrimeLo + & \!\!\! = \!\!\! & \bnOuterPrimeHexLo \\ + \secpN + & \!\!\! = \!\!\! & \secpNHex \\ + \secpNHi + & \!\!\! = \!\!\! & \secpNHexHi \\ + \secpNLo + & \!\!\! = \!\!\! & \secpNHexLo \\ + C_1 + & \!\!\! = \!\!\! & \{ (\ttx, \tty) \in F_{\bnOuterPrime}^2 \mid \tty^2 = \ttx^3 + 3 \} \cup \{ (0, 0)\} + \end{array} + \right. +\] diff --git a/prc/ecdata/lookup/ext.tex b/prc/ecdata/lookup/ext.tex new file mode 100644 index 0000000..222bc10 --- /dev/null +++ b/prc/ecdata/lookup/ext.tex @@ -0,0 +1,37 @@ +The lookup to the $\extMod$ is constructed as follows: + +\begin{description} + \item[\underline{Selector:}] \extFlag{} + \item[\underline{Source columns:}] from the \ecDataMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\extArgOneHi$ + \item $\extArgOneLo$ + \item $\extArgTwoHi$ + \item $\extArgTwoLo$ + \item $\extArgThreeHi$ + \item $\extArgThreeLo$ + \item $\extResHi$ + \item $\extResLo$ + \item $\extInst$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \extMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\argTreHi$ + \item $\argTreLo$ + \item $\resHi$ + \item $\resLo$ + \item $\INST$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + +\newpage \ No newline at end of file diff --git a/prc/ecdata/lookup/wcp.tex b/prc/ecdata/lookup/wcp.tex new file mode 100644 index 0000000..5c4aa0e --- /dev/null +++ b/prc/ecdata/lookup/wcp.tex @@ -0,0 +1,27 @@ +The lookup to the $\wcpMod$ is constructed as follows: + +\begin{description} + \item[\underline{Selector:}] \wcpFlag{} + \item[\underline{Source columns:}] from the \ecDataMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\wcpArgOneHi$ + \item $\wcpArgOneLo$ + \item $\wcpArgTwoHi$ + \item $\wcpArgTwoLo$ + \item $\wcpRes$ + \item $\wcpInst$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] from the \wcpMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} \ No newline at end of file diff --git a/prc/ecdata/notes/pairing_checks_spec.md b/prc/ecdata/notes/pairing_checks_spec.md new file mode 100644 index 0000000..9bbdd21 --- /dev/null +++ b/prc/ecdata/notes/pairing_checks_spec.md @@ -0,0 +1,63 @@ +ECPAIRING requires detecting the points at infinity +- small point is the poitn at infinity + - this never matters +- large point is the point at infinity + - +- small = (0, 0), large is not the point at infinity <== should go to a dedicated G2-membership circuit + + +When do we need gnark for pairings ? +- the stuff below assumes that the preliminary checks passed +- some point was not on G2 + - single call to the "G2-membership circuit" with MEMBERSHIP_BIT = 0 +- all large points are on G2; this determines two different calls to Gnark: + - (∞, ∞): this point will be ignored (it's well formed and its contribution to the pairing is nil) + - (P, ∞): this point will be ignored (it's well formed and its contribution to the pairing is nil) + - (∞, Q) with Q ≠ ∞: we must send Q to the "G2-membership circuit" with MEMBERSHIP_BIT = 1 + - (P, Q) with P ≠ ∞ and Q ≠ ∞: we must send all of these points to Gnark in the pairing +- we probably need the following columns: + - G2_MEMBERSHIP_TEST_REQUIRED ≡ G2MTR + - ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT ≡ ACCPC + + +ACCPC ≡ constant along the 4 + 8 = 12 rows of a pair of points +G2MTR ≡ constant along the 8 rows containing a supposed G2 point and zero along C1 points + +G2_MEMBERSHIP_BIT ≡ 0 if G2MTR ≡ false + + +SOMETHING_WASNT_ON_G2 ≡ false +============================= + +| Pair of points | G2_MEMBERSHIP_BIT | G2MTR | ACCPC | Gnark circuit | +|----------------+-------------------+-------+-------+---------------------------------------------| +| (∞, ∞) | none required | 0 | 0 | | +| (P, ∞) | none required | 0 | 0 | | +| (∞, Q) | 1 | 1 | 0 | G2-membership-circuit | +| (P, Q) | none required | 0 | 1 | Pairing-circuit (implicit membership test) | + + +SOMETHING_WASNT_ON_G2 ≡ true +============================ + +The ECDATA module predicts that some Q isn't on G2, +we (nondeterministically) select one of these points +among all those given in the pairing data and + +| Pair of points | MEMBERSHIP_BIT | G2MTR | ACCPC | Gnark circuit | +|----------------+----------------+-------+-------+-----------------------| +| (∞, Q) | 0 | 1 | 0 | G2-membership-circuit | +| (P, Q) | 0 | 1 | 0 | G2-membership-circuit | + + +INTERNAL tests are the first hurdle. +Then there are two cases: + +- SOMETHING_WASNT_ON_G2 = true + - we nondeterministically select one of the supposed G2 points that isn't part of G2 and send it to the G2-membership-circuit with a MEMBERSHIP_BIT = false +- SOMETHING_WASNT_ON_G2 = false + - every nontrivial pair of points has to go somewhere + - trivial pairs are of the form (P, ∞) + - nontrivial is everything else + - see row 3 and 4 of the first table + - we nondeterministically select one of the supposed G2 points that isn't part of G2 and send it to the G2-membership-circuit with a MEMBERSHIP_BIT = false diff --git a/prc/ecdata/notes/send_to_gnark.md b/prc/ecdata/notes/send_to_gnark.md new file mode 100644 index 0000000..af544e5 --- /dev/null +++ b/prc/ecdata/notes/send_to_gnark.md @@ -0,0 +1,58 @@ +# ECRECOVER + +- we compute INTERNAL_CHECKS_PASSED +- this column should be stamp constant (OK) +- the prover "glue" needs to be able to extract the stuff to send to GNARK easily, for this we need to know + - INTERNAL_CHECKS_PASSED (computed) + - SUCCESS_BIT (prediction propagated from HUB --> MMU --> MMIO --> ECDATA) + - SEND_TO_GNARK +- in the ECRECOVER case SEND_TO_GNARK ≡ INTERNAL_CHECKS_PASSED + +The prover can detect stuff to send to Gnark in our traces using the following selector + +CIRCUIT_SELECTOR_ECRECOVER ≡ INTERNAL_CHECKS_PASSED * (IS_ECRECOVER_DATA + IS_ECRECOVER_RESULT) +CIRCUIT_SELECTOR_ECADD ≡ INTERNAL_CHECKS_PASSED * (IS_ECADD_DATA + IS_ECADD_RESULT) +CIRCUIT_SELECTOR_ECMUL ≡ INTERNAL_CHECKS_PASSED * (IS_ECMUL_DATA + IS_ECMUL_RESULT) +CIRCUIT_SELECTOR_ECPAIRING ≡ INTERNAL_CHECKS_PASSED * (IS_ECPAIRING_DATA + IS_ECPAIRING_RESULT) * (1 - SOMETHING_WASNT_ON_G2) * ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT + ≡ ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT +CIRCUIT_SELECTOR_ECPAIRING_G2_MEMBERSHIP ≡ INTERNAL_CHECKS_PASSED * (IS_ECPAIRING_DATA + IS_ECPAIRING_RESULT) * G2_MEMBERSHIP_TEST_REQUIRED + ≡ G2_MEMBERSHIP_TEST_REQUIRED (has to be enforced) + +stuff to send will always be the same for everything except the membership test ? +- ID +- INDEX +- LIMB +- SUCCESS_BIT + +stuff to send for G2_MEMBERSHIP circuit +- ID (refined to allow for several points on G2, may require a new column) +- CT +- LIMB +- THIS_IS_NOT_ON_G2 + +Test: call ECPAIRING with CHECKS_SUCCEED and several trivial pairs of points on it that will trigger calls to MEMBERSHIP + +Question: how do we handle the case where ECPAIRING is given only trivial points ? in the sense of points of the form (P, ∞) ? Where all P are C1 points. + +EVERYTHING_TRIVIAL_ACCUMULATOR +- binary +- If INTERNAL_CHECKS_PASSED = 0 Then 0 +- monotony condition +- constant along small points +- constant along large points +- inherited at large => small point transitions +- set at small => large point transitions (= 1 iff large point is the point at infinity) + +If at transition from data to result EVERYTHING_TRIVIAL_ACCUMULATOR = 1 Then we manually set the result to 0x 00 ... 00 01 (in B_{32}) +If IS_ECPAIRING_DATA[i - 1] = 1 and IS_ECPAIRING_RESULT[i] = 1 and EVERYTHING_TRIVIAL_ACCUMULATOR[i - 1] = 1 +- SUCCESS_BIT[i] = 1 +- LIMB[i] = 0 +- LIMB[i + 1] = 1 + + + + + + + + diff --git a/prc/ecdata/specialized/_inputs.tex b/prc/ecdata/specialized/_inputs.tex new file mode 100644 index 0000000..99e9099 --- /dev/null +++ b/prc/ecdata/specialized/_inputs.tex @@ -0,0 +1,5 @@ +\subsection{The \inst{ECRECOVER} case} \label{ec data: ecrecover} \input{ecdata/specialized/ecrecover} +\subsection{The \inst{ECADD} case} \label{ec data: ecadd} \input{ecdata/specialized/ecadd} +\subsection{The \inst{ECMUL} case} \label{ec data: ecmul} \input{ecdata/specialized/ecmul} +\subsection{The \inst{ECPAIRING} case} \label{ec data: ecpairing} \input{ecdata/specialized/ecpairing} + diff --git a/prc/ecdata/specialized/ecadd.tex b/prc/ecdata/specialized/ecadd.tex new file mode 100644 index 0000000..3808bf7 --- /dev/null +++ b/prc/ecdata/specialized/ecadd.tex @@ -0,0 +1,64 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \left\{ \begin{array}{lcl} + \isEcaddData_{i} & = & 1 \\ + \ecdataId_{i} & \neq & \ecdataId_{i-1} \\ + \end{array} \right. + } +\] + +We introduce the following (local) shorthands: +\[ + \left\{ \begin{array}{lclr} + \locPXHi & \define & \ecdataLimb_{i} \\ + \locPXLo & \define & \ecdataLimb_{i+1} \\ + \locPYHi & \define & \ecdataLimb_{i+2} \\ + \locPYLo & \define & \ecdataLimb_{i+3} \\ + \end{array} \right. + \qquad + \left\{ \begin{array}{lclr} + \locQXHi & \define & \ecdataLimb_{i+4} \\ + \locQXLo & \define & \ecdataLimb_{i+5} \\ + \locQYHi & \define & \ecdataLimb_{i+6} \\ + \locQYLo & \define & \ecdataLimb_{i+7} \\ + \end{array} \right. +\] + +We set the following constraints: + +\begin{description} + \item[\underline{Row $n^°(i)$:}] + we impose + \[ + \callToCOneMembership + {i}{0} + {\locPXHi}{\locPXLo}{\locPYHi}{\locPYLo} + \] + as well as define the shorthand + \[ + \locCOneMembershipFirstPoint \define \hurdle_{i} + \] + \item[\underline{Row $n^°(i+4)$:}] + we impose + \[ + \callToCOneMembership + {i}{4} + {\locQXHi}{\locQXLo}{\locQYHi}{\locQYLo} + \] + as well as define the shorthand + \[ + \locCOneMembershipSecondPoint \define \hurdle_{i+4} + \] + \item[\underline{Justifying the \ecdataSuccessBit{}:}] + we define the following shorthands + \[ + \locInternalChecksPassed \define \hurdle_{i+\indexMaxEcaddData} + \] + and impose the following constraints + \[ + \left\{ \begin{array}{lcl} + \locInternalChecksPassed & = & \locCOneMembershipFirstPoint \cdot \locCOneMembershipSecondPoint \\ + \ecdataSuccessBit_{i} & = & \locInternalChecksPassed \\ + \end{array} \right. + \] +\end{description} diff --git a/prc/ecdata/specialized/ecmul.tex b/prc/ecdata/specialized/ecmul.tex new file mode 100644 index 0000000..f92d973 --- /dev/null +++ b/prc/ecdata/specialized/ecmul.tex @@ -0,0 +1,52 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \left\{ \begin{array}{lcl} + \isEcmulData_{i} & = & 1 \\ + \ecdataId_{i} & \neq & \ecdataId_{i-1} \\ + \end{array} \right. + } +\] + +We introduce the following (local) shorthands: + +\[ + \left\{ \begin{array}{lclr} + \locPXHi & \define & \ecdataLimb_{i} \\ + \locPXLo & \define & \ecdataLimb_{i+1} \\ + \locPYHi & \define & \ecdataLimb_{i+2} \\ + \locPYLo & \define & \ecdataLimb_{i+3} \\ + \end{array} \right. + \qquad + \left\{ \begin{array}{lclr} + \locNHi & \define & \ecdataLimb{}_{i+4} \\ + \locNLo & \define & \ecdataLimb{}_{i+5} \\ + \end{array} \right. +\] + +We set the following constraints: + +\begin{description} + \item[\underline{Row $n^°(i)$:}] + we impose + \[ + \callToCOneMembership + {i}{0} + {\locPXHi}{\locPXLo}{\locPYHi}{\locPYLo} + \] + as well as define the shorthand + \[ + \locCOneMembership \define \hurdle_{i} + \] + \item[\underline{Justifying the \ecdataSuccessBit{}:}] + we define the following shorthand + \[ + \locInternalChecksPassed \define \hurdle_{i+\indexMaxEcmulData} + \] + and impose the following constraints + \[ + \left\{ \begin{array}{lcl} + \locInternalChecksPassed & = & \locCOneMembership \\ + \ecdataSuccessBit_{i} & = & \locInternalChecksPassed \\ + \end{array} \right. + \] +\end{description} diff --git a/prc/ecdata/specialized/ecpairing.tex b/prc/ecdata/specialized/ecpairing.tex new file mode 100644 index 0000000..2a84eff --- /dev/null +++ b/prc/ecdata/specialized/ecpairing.tex @@ -0,0 +1,86 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \left\{ \begin{array}{lcl} + \isEcpairingData _{i} & = & 1 \\ + \accPairings _{i} & \neq & \accPairings_{i - 1} \\ + \end{array} \right. + } +\] +We introduce the following (local) shorthands: +\[ + \left\{ \begin{array}{lclr} + \locAXHi & \define & \ecdataLimb _{i} \\ + \locAXLo & \define & \ecdataLimb _{i + 1} \\ + \locAYHi & \define & \ecdataLimb _{i + 2} \\ + \locAYLo & \define & \ecdataLimb _{i + 3} \\ + \locBXImHi & \define & \ecdataLimb _{i + 4} \\ + \locBXImLo & \define & \ecdataLimb _{i + 5} \\ + \locBXReHi & \define & \ecdataLimb _{i + 6} \\ + \locBXReLo & \define & \ecdataLimb _{i + 7} \\ + \locBYImHi & \define & \ecdataLimb _{i + 8} \\ + \locBYImLo & \define & \ecdataLimb _{i + 9} \\ + \locBYReHi & \define & \ecdataLimb _{i + 10} \\ + \locBYReLo & \define & \ecdataLimb _{i + 11} \\ + \locInternalChecksPassed & \define & \hurdle _{i + \indexMaxEcPairingDataMin} \\ + \locPreviousInternalChecksPassed & \define & \hurdle _{i - \redm{1}} \\ + \end{array} \right. +\] +We introduce the following constraints: +\begin{description} + \item[\underline{Row $n^°(i)$:}] + \[ + \callToCOneMembership + {i}{0} + {\locAXHi}{\locAXLo}{\locAYHi}{\locAYLo} + \] + + \[ + \locCOneMembership \define \hurdle_{i} + \] +\end{description} + +\begin{description} + \item[\underline{Row $n^°(i+4)$:}] + \[ + \callToWellFormedCoordinates{4}{\locBXImHi}{\locBXImLo}{\locBXReHi}{\locBXReLo}{\locBYImHi}{\locBYImLo}{\locBYReHi}{\locBYReLo} + \] + + \[ + \locWellFormedCoordinates \define \hurdle_{i+4} + \] +\end{description} +\begin{description} + \item[\underline{Propagation of \locInternalChecksPassed:}] + The following constraint defines the value of $\locInternalChecksPassed$ for the first pair and the subsequents, if any. + For each subsequent, $\locPreviousInternalChecksPassed$ is propagated so as to compute the latest $\locInternalChecksPassed$. + Note that this approach is adopted to deal with an arbitrary number of input pairings: + \begin{enumerate} + \item \If $\accPairings_{i} = 1$ \Then + \[ + \locInternalChecksPassed = \locCOneMembership \cdot \locWellFormedCoordinates + \] + \item \If $\accPairings_{i} \neq 1$ \Then + \begin{enumerate} + \item $\hurdle_{i + 10} = \locCOneMembership \cdot \locWellFormedCoordinates$ + \item $\locInternalChecksPassed = \hurdle_{i + 10} \cdot \locPreviousInternalChecksPassed$ + \end{enumerate} + \end{enumerate} +\end{description} +\saNote{} \If $\isEcpairingData_{i} = 0$ \Then $\accPairings_{i} = 0$ and the first pair corresponds to $\accPairings_{i} = 1$. +\begin{description} + \item[\underline{Justifying the \ecdataSuccessBit{}:}] + We impose the following constraints + \begin{enumerate} + \item \If $\internalChecksPassed _{i}= 0$ \Then $\ecdataSuccessBit _{i} = 0$ + % \item \If $\internalChecksPassed _{i}= 1 ~ \Then \ecdataSuccessBit_{i} = \justifiedByExternalCircuit$ + \item \If $\internalChecksPassed _{i}= 1$ \Then $\ecdataSuccessBit_{i} = 1 - \notOnGTwoAccMax _{i}$ + % \item \If $\notOnGTwoAccMax_{i} = 1$ \Then $\ecdataSuccessBit _{i} = 0$ + % \item \If $\ecdataSuccessBit _{i} = 1$ \Then + % \[ + % \left\{ \begin{array}{lcl} + % \internalChecksPassed _{i} & = & 1 \\ + % \notOnGTwoAccMax _{i} & = & 0 \\ + % \end{array} \right. \quad (\trash) + % \] + \end{enumerate} +\end{description} diff --git a/prc/ecdata/specialized/ecrecover.tex b/prc/ecdata/specialized/ecrecover.tex new file mode 100644 index 0000000..1fcd768 --- /dev/null +++ b/prc/ecdata/specialized/ecrecover.tex @@ -0,0 +1,163 @@ +\[ + \boxed{\text{All constraints in this subsection assume } + \left\{ \begin{array}{lcl} + \isEcrecoverData_{i} & = & 1 \\ + \ecdataId_{i} & \neq & \ecdataId_{i-1} \\ + \end{array} \right. + } +\] + +We introduce the following (local) shorthands: +\[ + \left\{ \begin{array}{lclr} + \locHHi & \define & \ecdataLimb_{i} \\ + \locHLo & \define & \ecdataLimb_{i + 1} \\ + \locVHi & \define & \ecdataLimb_{i + 2} \\ + \locVLo & \define & \ecdataLimb_{i + 3} \\ + \locRHi & \define & \ecdataLimb_{i + 4} \\ + \locRLo & \define & \ecdataLimb_{i + 5} \\ + \locSHi & \define & \ecdataLimb_{i + 6} \\ + \locSLo & \define & \ecdataLimb_{i + 7} \\ + \end{array} \right. +\] + +We set the following constraints: + +\begin{description} + \item[\underline{Row $n^°(i)$:}] + we impose + \[ + % \callToLt + % {i} + % {\locRHi}{\locRLo} + % {$\secpNHi$}{$\secpNLo$} + \wcpCallToLt { + anchorRow = i , + relOffset = 0 , + argOneHi = \locRHi , + argOneLo = \locRLo , + argTwoHi = \secpNHi , + argTwoLo = \secpNLo , + } + \] + as well as define the shorthand + \[ + \locRIsInRange \define \wcpRes_{i} + \] + \item[\underline{Row $n^°(i + 1)$:}] + we impose + \[ + % \callToLt + % {i + 1} + % {0}{0} + % {\locRHi}{\locRLo} + \wcpCallToLt { + anchorRow = i , + relOffset = 1 , + argOneHi = 0 , + argOneLo = 0 , + argTwoHi = \locRHi , + argTwoLo = \locRLo , + } + \] + as well as define the shorthand + \[ + \locRIsPositive \define \wcpRes_{i + 1} + \] + \item[\underline{Row $n^°(i + 2)$:}] + we impose + \[ + % \callToLt + % {i + 2} + % {\locSHi}{\locSHi} + % {$\secpNHi$}{$\secpNLo$} + \wcpCallToLt { + anchorRow = i , + relOffset = 2 , + argOneHi = \locSHi , + argOneLo = \locSHi , + argTwoHi = \secpNHi , + argTwoLo = \secpNLo , + } + \] + as well as define the shorthand + \[ + \locSIsInRange \define \wcpRes_{i + 2} + \] + \item[\underline{Row $n^°(i + 3)$:}] + we impose + \[ + % \callToLt + % {i + 3} + % {0}{0} + % {\locSHi}{\locSLo} + \wcpCallToLt { + anchorRow = i , + relOffset = 3 , + argOneHi = 0 , + argOneLo = 0 , + argTwoHi = \locSHi , + argTwoLo = \locSLo , + } + \] + as well as define the shorthand + \[ + \locSIsPositive \define \wcpRes_{i + 3} + \] + \item[\underline{Row $n^°(i + 4)$:}] + we impose + \[ + % \callToEq + % {i + 4} + % {\locVHi}{\locVLo} + % {0}{27} + \wcpCallToEq { + anchorRow = i , + relOffset = 4 , + argOneHi = \locVHi , + argOneLo = \locVLo , + argTwoHi = 0 , + argTwoLo = 27 , + } + \] + as well as define the shorthand + \[ + \locVIsTwentyseven \define \wcpRes_{i + 4} + \] + \item[\underline{Row $n^°(i + 5)$:}] + we impose + \[ + % \callToEq + % {i + 5} + % {\locVHi}{\locVLo} + % {0}{28} + \wcpCallToEq { + anchorRow = i , + relOffset = 5 , + argOneHi = \locVHi , + argOneLo = \locVLo , + argTwoHi = 0 , + argTwoLo = 28 , + } + \] + as well as define the shorthand + \[ + \locVIsTwentyeight \define \wcpRes_{i + 5} + \] + \item[\underline{Justifying the \ecdataSuccessBit{}:}] + we define the following shorthand + \[ + \locInternalChecksPassed \define \hurdle_{i+\indexMaxEcrecoverData} \\ + \] + and impose the following constraints + \[ + \left\{ \begin{array}{lcl} + \hurdle_{i} & = & \locRIsInRange \cdot \locRIsPositive \\ + \hurdle_{i + 1} & = & \locSIsInRange \cdot \locSIsPositive \\ + \hurdle_{i + 2} & = & \hurdle_{i} \cdot \hurdle_{i + 1} \\ + \locInternalChecksPassed & = & \hurdle_{i + 2} \cdot (\locVIsTwentyseven + \locVIsTwentyeight) \\ + \If \locInternalChecksPassed & = & 0 ~ \Then \ecdataSuccessBit _{i} = 0 \\ + \If \locInternalChecksPassed & = & 1 ~ \Then \ecdataSuccessBit _{i} \equiv \justifiedByExternalCircuit \\ + \end{array} \right. + \] +\end{description} diff --git a/prc/ecdata/success_bit.tex b/prc/ecdata/success_bit.tex new file mode 100644 index 0000000..967281e --- /dev/null +++ b/prc/ecdata/success_bit.tex @@ -0,0 +1,27 @@ +We remind the reader that +for \inst{ECRECOVER} +the interpretation of \ecdataSuccessBit{} is +\[ + \ecdataSuccessBit \equiv 1 \iff \text{well formed inputs and public address recovered} +\] +this is the difference the precompile returning $()$ and returning $\textbf{o} \in \mathbb{B}_{\,\evmWordSize}$ represening 12 zero bytes followed the 20 bytes of the recovered address; + +\par +for \inst{ECADD} and \inst{ECMUL} +the interpretation of \ecdataSuccessBit{} is +\[ + \ecdataSuccessBit \equiv 1 \iff \text{well formed inputs} +\] +this is the difference between +the precopile failing (consuming all the call gas and putting $0$ on the caller's stack) and returning $()$ i.e. nothing +the precompile succeeding (putring $1$ on the caller stack) and returning some $\textbf{o} \in \mathbb{B}_{\,\redm{64}}$; + +\par +for \inst{ECPAIRING} +the interpretation of \ecdataSuccessBit{} is +\[ + \ecdataSuccessBit \equiv 1 \iff \text{well formed inputs} +\] +this is the difference between +the precopile failing (consuming all the call gas and putting $0$ on the caller's stack) and returning $()$ i.e. nothing +the precompile succeeding (putring $1$ on the caller stack) and returning some $\textbf{o} \in \mathbb{B}_{\,\evmWordSize}$. diff --git a/prc/ecdata/this_point_is_not_on_G2.tex b/prc/ecdata/this_point_is_not_on_G2.tex new file mode 100644 index 0000000..6ab2e7e --- /dev/null +++ b/prc/ecdata/this_point_is_not_on_G2.tex @@ -0,0 +1,49 @@ +The intent with the \notOnGTwo{} column is that this column may only turn on for a single \textbf{large} point within a given call to the \inst{ECPAIRING} precompile. Furthermore it should only be able to turn on if internal checks of the module passed. +These two requirements (turning on at most once and only if internal checks passed) will follow from constraints on \notOnGTwoAcc{} and $\notOnGTwoAccMax$. +\begin{enumerate} + \item \notOnGTwo{} is binary \quad (\trash) + \item \notOnGTwo{} is counter-constant \quad (\trash) + \item \If $\notOnGTwo_{i} = 1$ \Then $\isLargePoint_{i} = 1$ +\end{enumerate} +We now specify the associated accumulator column: +\begin{enumerate}[resume] + \item \notOnGTwoAcc{} is binary \quad (\trash) + \item \notOnGTwoAcc{} is counter-constant \quad (\trash) + \item \If $\isEcpairingData_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \notOnGTwoAcc _{i} & = & 0 \\ + \notOnGTwoAcc _{i + 1} & = & 0 \\ + \end{array} \right. + \] + \item \If $\locTransitionFromSmallToLarge_{i} = 1$ \Then + \[ + \notOnGTwoAcc _{i + 1} = + \left[ \begin{array}{cr} + + & \notOnGTwoAcc _{i} \\ + + & \notOnGTwo _{i + 1} \\ + \end{array} \right] + \] + \saNote{} The above has the following implicit consequence: \textbf{at most one} (supposedly) $G_2$ point pertaining to a particular \ecdataId{} may be be tagged as ``\notOnGTwo.'' + \item \If $\locTransitionFromLargeToSmall_{i} = 1$ \Then + \[ + \notOnGTwoAcc _{i + 1} = \notOnGTwoAcc _{i} + \] +\end{enumerate} +We finish this section by constraining the \notOnGTwoAccMax{} column: +\begin{enumerate}[resume] + \item \notOnGTwoAccMax{} is binary \quad (\trash) + \item \notOnGTwoAccMax{} is index-constant \quad (\trash) + \item \If $\notOnGTwoAccMax_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \isEcpairingData _{i} & = & 1 \\ + \internalChecksPassed _{i} & = & 1 \\ + \end{array} \right. + \] + \saNote{} The above has the following implicit consequence: \notOnGTwoAcc{} (and hence \notOnGTwo{}) column may only turn on if all checks have passed. + \item \If $\isEcpairingData _{i} = 1$ \et $\isEcpairingResult _{i + 1} = 1$ \Then + \[ + \notOnGTwoAccMax_{i} = \notOnGTwoAcc _{i} + \] +\end{enumerate} diff --git a/prc/ecdata/total_size.tex b/prc/ecdata/total_size.tex new file mode 100644 index 0000000..29c7742 --- /dev/null +++ b/prc/ecdata/total_size.tex @@ -0,0 +1,42 @@ +The $\ecdataTotalSize$ varies depending on the precompile, if data or results are considered and whether the call is successful (if it fails, $\ecdataTotalSize = 0$). In the case of $\inst{ECPAIRING}$, the total size is influenced by the number of pairings. + +We define the following module constants +\[ + \left\{ \begin{array}{lcl} + \totalSizeEcrecoverData & \!\!\! \define \!\!\! & \redm{128} \\ + \totalSizeEcaddData & \!\!\! \define \!\!\! & \redm{128} \\ + \totalSizeEcmulData & \!\!\! \define \!\!\! & \redm{96} \\ + \totalSizeEcpairingDataMin & \!\!\! \define \!\!\! & \redm{192} \\ + \totalSizeEcrecoverResult & \!\!\! \define \!\!\! & \redm{32} \\ + \totalSizeEcaddResult & \!\!\! \define \!\!\! & \redm{64} \\ + \totalSizeEcmulResult & \!\!\! \define \!\!\! & \redm{64} \\ + \totalSizeEcpairingResult & \!\!\! \define \!\!\! & \redm{32} \\ + \end{array} \right. +\] +Thus we impose the following constraints: +\[ + \ecdataTotalSize _{i} + = + \left[ \begin{array}{crcccl} + + & \isEcrecoverData _{i} & \cdot & \totalSizeEcrecoverData \\ + + & \isEcaddData _{i} & \cdot & \totalSizeEcaddData \\ + + & \isEcmulData _{i} & \cdot & \totalSizeEcmulData \\ + + & \isEcpairingData _{i} & \cdot & \totalSizeEcpairingDataMin & \cdot & \totalPairings _{i} \\ + + & \isEcrecoverResult _{i} & \cdot & \totalSizeEcrecoverResult & \cdot & \ecdataSuccessBit _{i} \\ + + & \isEcaddResult _{i} & \cdot & \totalSizeEcaddResult & \cdot & \ecdataSuccessBit _{i} \\ + + & \isEcmulResult _{i} & \cdot & \totalSizeEcmulResult & \cdot & \ecdataSuccessBit _{i} \\ + + & \isEcpairingResult _{i} & \cdot & \totalSizeEcpairingResult & \cdot & \ecdataSuccessBit _{i} \\ + \end{array} \right] +\] + +\saNote{} The above translates to the following: +\begin{enumerate} + \item \If $\isEcrecoverData$ \Then $\ecdataTotalSize = \totalSizeEcrecoverData$ + \item \If $\isEcaddData$ \Then $\ecdataTotalSize = \totalSizeEcaddData$ + \item \If $\isEcmulData$ \Then $\ecdataTotalSize = \totalSizeEcmulData$ + \item \If $\isEcpairingData$ \Then $\ecdataTotalSize = \totalSizeEcpairingDataMin \cdot \totalPairings$ % we provide it ... it's a little strange + \item \If $\isEcrecoverResult$ \Then $\ecdataTotalSize = \totalSizeEcrecoverResult \cdot \ecdataSuccessBit$ + \item \If $\isEcaddResult$ \Then $\ecdataTotalSize = \totalSizeEcaddResult \cdot \ecdataSuccessBit$ + \item \If $\isEcmulResult$ \Then $\ecdataTotalSize = \totalSizeEcmulResult \cdot \ecdataSuccessBit$ + \item \If $\isEcpairingResult$ \Then $\ecdataTotalSize = \totalSizeEcpairingResult \cdot \ecdataSuccessBit$ +\end{enumerate} diff --git a/prc/ecdata/trace_representations.tex b/prc/ecdata/trace_representations.tex new file mode 100644 index 0000000..bf42ee6 --- /dev/null +++ b/prc/ecdata/trace_representations.tex @@ -0,0 +1,113 @@ +\definecolor{mybackground}{cmyk}{0.40, 0.30, 0.0, 0.36} + +\begin{figure}[h!] + \[ + \centering + \begin{array}{|c|c|c|c|c|c|c|} + \hline + \rotatebox{90}{\ecdataId} & \rotatebox{90}{\isEcrecoverData \quad} & \rotatebox{90}{\isEcrecoverResult \quad} & \rotatebox{90}{\index} & \limb & \hurdle \\ \hline + 12 & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + 18 & 1 & 0 & 0 & \locHHi & \hurdle_{i} = \locRIsInRange \cdot \locRIsPositive \\ \hline + 18 & 1 & 0 & 1 & \locHLo & \hurdle_{i+1} = \locSIsInRange \cdot \locSIsPositive \\ \hline + 18 & 1 & 0 & 2 & \locVHi & \hurdle_{i+2} = \hurdle_{i} \cdot \hurdle_{i+1} \\ \hline + 18 & 1 & 0 & 3 & \locVLo & \\ \hline + 18 & 1 & 0 & 4 & \locRHi & \\ \hline + 18 & 1 & 0 & 5 & \locRLo & \\ \hline + 18 & 1 & 0 & 6 & \locSHi & \\ \hline + 18 & 1 & 0 & \ecCycleMed & \locSLo & \locInternalChecksPassed = \hurdle_{i+2} \cdot (\locVIsTwentyseven + \locVIsTwentyeight) \\ \hline + 18 & 0 & 1 & 0 & \locRecoveredAddressHi & \vdots \\ \hline + 18 & 0 & 1 & \redm{1} & \locRecoveredAddressLo & \vdots \\ \hline + \end{array} + \] + \caption{Behaviour of \hurdle ~ in the context of a call to \inst{ECRECOVER}.} +\end{figure} + +\begin{figure}[h!] + \begin{adjustwidth}{-2cm}{-2cm} + \centering + \[ + \begin{array}{|c|c|c|c|c|c|c|} + \hline + \rotatebox{90}{\ecdataId} & \rotatebox{90}{\isEcaddData \quad} & \rotatebox{90}{\isEcaddResult \quad} & \rotatebox{90}{\index} & \limb & \hurdle \\ \hline + 7 & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + 9 & 1 & 0 & 0 & \locPXHi & \locCOneMembershipFirstPoint = \locPIsInRange \cdot (\locPXxYIsInfinity + \locPSatisfiesCubic ) \\ \hline + 9 & 1 & 0 & 1 & \locPXLo & \locPIsInRange = \locPXIsInRange \cdot \locPYIsInRange \\ \hline + 9 & 1 & 0 & 2 & \locPYHi & \\ \hline + 9 & 1 & 0 & 3 & \locPYLo & \\ \hline + 9 & 1 & 0 & 4 & \locQXHi & \locCOneMembershipSecondPoint = \col{Q\_is\_in\_range} \cdot (\col{Q\_is\_point\_at\_infinity} + \col{Q\_satisfies\_cubic}) \\ \hline + 9 & 1 & 0 & 5 & \locQXLo & \col{Q\_is\_in\_range} = \col{Q\_x\_is\_in\_range} \cdot \col{Q\_y\_is\_in\_range} \\ \hline + 9 & 1 & 0 & 6 & \locQYHi & \\ \hline + 9 & 1 & 0 & \ecCycleMed & \locQYLo & \locInternalChecksPassed = \locCOneMembershipFirstPoint \cdot \locCOneMembershipSecondPoint \\ \hline + 9 & 0 & 1 & 0 & \locResultXHi & \vdots \\ \hline + 9 & 0 & 1 & 1 & \locResultXLo & \vdots \\ \hline + 9 & 0 & 1 & 2 & \locResultYHi & \vdots \\ \hline + 9 & 0 & 1 & \redm{3} & \locResultYLo & \vdots \\ \hline + \end{array} + \] + \end{adjustwidth} + \caption{Behaviour of \hurdle~ in the context of a call to \inst{ECADD}.} +\end{figure} + +\begin{figure}[h!] + \[ + \centering + \begin{array}{|c|c|c|c|c|c|c|} + \hline + \rotatebox{90}{\ecdataId} & \rotatebox{90}{\isEcmulData \quad} & \rotatebox{90}{\isEcmulResult \quad} & \rotatebox{90}{\index} & \limb & \hurdle \\ \hline + 9 & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + 12 & 1 & 0 & 0 & \locPXHi & \locCOneMembership = \locPIsInRange \cdot (\locPXxYIsInfinity + \locPSatisfiesCubic ) \\ \hline + 12 & 1 & 0 & 1 & \locPXLo & \locPIsInRange = \locPXIsInRange \cdot \locPYIsInRange \\ \hline + 12 & 1 & 0 & 2 & \locPYHi & \\ \hline + 12 & 1 & 0 & 3 & \locPYLo & \\ \hline + 12 & 1 & 0 & 4 & \locNHi & \\ \hline + 12 & 1 & 0 & \ecCycleMin & \locNLo & \locInternalChecksPassed = \locCOneMembership \\ \hline + 12 & 0 & 1 & 0 & \locResultXHi & \vdots \\ \hline + 12 & 0 & 1 & 1 & \locResultXLo & \vdots \\ \hline + 12 & 0 & 1 & 2 & \locResultYHi & \vdots \\ \hline + 12 & 0 & 1 & \redm{3} & \locResultYLo & \vdots \\ \hline + \end{array} + \] + \caption{Behaviour of \hurdle ~ in the context of a call to \inst{ECMUL}.} +\end{figure} + + + +\begin{figure}[h!] + \begin{adjustwidth}{-2cm}{-2cm} + \resizebox{13cm}{!}{% + \[ + \begin{array}{|c|c|c|c|c|c|c|c|c|} \hline + \rotatebox{90}{\ecdataId} & \rotatebox{90}{\isEcpairingData} & \rotatebox{90}{\isEcpairingResult} & \rotatebox{90}{\index} & \rotatebox{90}{\ct} & \rotatebox{90}{\totalPairings \quad} & \rotatebox{90}{\accPairings} & \limb & \hurdle \\ \hline + 4 & \vdots & \vdots & \vdots & 0 & \vdots & 0 & \vdots & \vdots \\ \hline + 7 & 1 & 0 & 0 & 0 & 2 & 1 & \locAXHi & \locCOneMembership = \col{A\_is\_in\_range} \cdot (\col{A\_is\_point\_at\_infinity} + \col{A\_satisfies\_cubic}) \\ \hline + 7 & 1 & 0 & 1 & 1 & 2 & 1 & \locAXLo & \col{A\_is\_in\_range} = \col{A\_x\_is\_in\_range} \cdot \col{A\_y\_is\_in\_range} \\ \hline + 7 & 1 & 0 & 2 & 2 & 2 & 1 & \locAYHi & \\ \hline + 7 & 1 & 0 & 3 & \redm{3} & 2 & 1 & \locAYLo & \\ \hline + 7 & 1 & 0 & 4 & 0 & 2 & 1 & \locBXImHi & \locWellFormedCoordinates = \locBXIsInRange \cdot \locBYIsInRange \\ \hline + 7 & 1 & 0 & 5 & 1 & 2 & 1 & \locBXImLo & \locBYIsInRange = \locBYImIsInRange \cdot \locBYReIsInRange \\ \hline + 7 & 1 & 0 & 6 & 2 & 2 & 1 & \locBXReHi & \locBXIsInRange = \locBXImIsInRange \cdot \locBXReIsInRange \\ \hline + 7 & 1 & 0 & 7 & 3 & 2 & 1 & \locBXReLo & \\ \hline + 7 & 1 & 0 & 8 & 4 & 2 & 1 & \locBYImHi & \\ \hline + 7 & 1 & 0 & 9 & 5 & 2 & 1 & \locBYImLo & \\ \hline + 7 & 1 & 0 & 10 & 6 & 2 & 1 & \locBYReHi & \\ \hline + 7 & 1 & 0 & \redm{11} & \redm{7} & 2 & 1 & \locBYReLo & \locInternalChecksPassed = \locCOneMembership \cdot \locWellFormedCoordinates = \textcolor{magenta}{\locPreviousInternalChecksPassed} \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 12 & 0 & 2 & 2 & \locAXHi & \locCOneMembership = \col{A\_is\_in\_range} \cdot (\col{A\_is\_point\_at\_infinity} + \col{A\_satisfies\_cubic}) \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 13 & 1 & 2 & 2 & \locAXLo & \col{A\_is\_in\_range} = \col{A\_x\_is\_in\_range} \cdot \col{A\_y\_is\_in\_range} \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 14 & 2 & 2 & 2 & \locAYHi & \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 15 & \redm{3} & 2 & 2 & \locAYLo & \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 16 & 0 & 2 & 2 & \locBXImHi & \locWellFormedCoordinates = \locBXIsInRange \cdot \locBYIsInRange \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 17 & 1 & 2 & 2 & \locBXImLo & \locBYIsInRange = \locBYImIsInRange \cdot \locBYReIsInRange \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 18 & 2 & 2 & 2 & \locBXReHi & \locBXIsInRange = \locBXImIsInRange \cdot \locBXReIsInRange \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 19 & 3 & 2 & 2 & \locBXReLo & \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 20 & 4 & 2 & 2 & \locBYImHi & \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 21 & 5 & 2 & 2 & \locBYImLo & \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & 22 & 6 & 2 & 2 & \locBYReHi & \hurdle_{i+10} = \locCOneMembership \cdot \locWellFormedCoordinates \\ \hline + \rowcolor{mybackground} 7 & 1 & 0 & \redm{23} & \redm{7} & 2 & 2 & \locBYReLo & \locInternalChecksPassed = \hurdle_{i+10} \cdot \textcolor{magenta}{\locPreviousInternalChecksPassed} = \textcolor{orange}{\locPreviousInternalChecksPassed} \\ \hline + 7 & 0 & 1 & 0 & 0 & \vdots & 0 & \locPairingsResultHi & \vdots \\ \hline + 7 & 0 & 1 & \redm{1} & 0 & \vdots & 0 & \locPairingsResultLo & \vdots \\ \hline + \end{array} + \] + } + \end{adjustwidth} + \caption{Behaviour of \hurdle ~ in the context of a call to \inst{ECPAIRING}, with 2 pairings. The different background colors emphasise the rows corresponding to the different pairings. For each pairing, the corresponding constraints are defined considering its first row as $i$. For each pairing after the first one, $\locPreviousInternalChecksPassed$ is used to compute $\locInternalChecksPassed$.} +\end{figure} diff --git a/prc/ecdata/trivial_pairing.tex b/prc/ecdata/trivial_pairing.tex new file mode 100644 index 0000000..3bb3fad --- /dev/null +++ b/prc/ecdata/trivial_pairing.tex @@ -0,0 +1,37 @@ +We enforce the following constraints: +\begin{enumerate} + % \item \If $\internalChecksPassed_{i} = 0$ \Then $\trivialPairing_{i} = 0$ + % \item \If $\notOnGTwoAccMax_{i} = 1$ \Then $\trivialPairing_{i} = 0$ + \item \trivialPairing{} is \textbf{counter-constant binary} \quad (\trash) + \item \If $\isEcpairingData _{i} = 0$ \Then $\trivialPairing _{i} = 0$ + \item \If $\isEcpairingData_{i - 1} = 0$ \et $\isEcpairingData _{i} = 1$ \Then $\trivialPairing_{i} = 1$ + \item \If $\locTransitionFromLargeToSmall_{i} = 1$ \Then $\trivialPairing_{i+1} = \trivialPairing_{i}$ + \item \If $\locTransitionFromSmallToLarge_{i} = 1$ \Then + \begin{enumerate} + \item \If $\trivialPairing _{i} = 0$ \Then $\trivialPairing _{i + 1} = 0$ + \item \If $\trivialPairing _{i} = 1$ \Then $\trivialPairing _{i + 1} = \isInfinity_{i + 1}$ + \end{enumerate} +\end{enumerate} +\saNote{} The above means that \trivialPairing{} records whether or not the pairing data contains at least one large (supposed $G_2$) point that isn't the point at infinity. + +We use the \trivialPairing{} flag to set the result of unexceptional yet trivial pairings: +\begin{enumerate}[resume] + \item we impose that + \[ + \If + \left\{ \begin{array}{lcl} + \locTransitionToResult _{i} & = & 1 \\ + \internalChecksPassed _{i} & = & 1 \\ + \notOnGTwoAccMax _{i} & = & 0 \\ + \trivialPairing _{i} & = & 1 \\ + \end{array} \right. + \Then + \left\{ \begin{array}{lcl} + \locPairingsResultHi & \define & \ecdataLimb _{i + 1} \\ + \locPairingsResultLo & \define & \ecdataLimb _{i + 2} \\ + \ecdataSuccessBit_{i} & = & 1 \\ + \locPairingsResultHi & = & 0 \\ + \locPairingsResultLo & = & 1 + \end{array} \right. + \] +\end{enumerate} diff --git a/prc/ecdata/utils/c1_membership.tex b/prc/ecdata/utils/c1_membership.tex new file mode 100644 index 0000000..79874e8 --- /dev/null +++ b/prc/ecdata/utils/c1_membership.tex @@ -0,0 +1,154 @@ +\[ + \left\{ \begin{array}{l} + \callToCOneMembership + {i}{\relof} + {\locPXHi}{\locPXLo }{\locPYHi }{\locPYLo} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{l} + \callToCOneMembershipWCP{i}{\relof}{\locPXHi}{\locPXLo}{\locPYHi}{\locPYLo} \\ + \locPXIsInRange \define \wcpRes_{i+\relof} \\ + \locPYIsInRange \define \wcpRes_{i+\relof+1} \\ + \locPSatisfiesCubic \define \wcpRes_{i+\relof+2} \\ + \vspace{1mm} \\ + % + \callToCOneMembershipEXT{i}{\relof}{\locPXHi}{\locPXLo}{\locPYHi}{\locPYLo} \\ + \locPYSquareHi \define \extResHi_{i+\relof} \\ + \locPYSquareLo \define \extResLo_{i+\relof} \\ + \locPXSquareHi \define \extResHi_{i+\relof+1} \\ + \locPXSquareLo \define \extResLo_{i+\relof+1} \\ + \locPXCubeHi \define \extResHi_{i+\relof+2} \\ + \locPXCubeLo \define \extResLo_{i+\relof+2} \\ + \locPXCubePlusThreeHi \define \extResHi_{i+\relof+3} \\ + \locPXCubePlusThreeLo \define \extResLo_{i+\relof+3} \\ + \vspace{1mm} \\ + \locPIsInRange \define \hurdle_{i + \relof + 1} \\ + \locCOneMembership \define \hurdle_{i + \relof} \\ + \vspace{1mm} \\ + % + \locPIsInRange = \locPXIsInRange \cdot \locPYIsInRange \\ + \locCOneMembership = \locPIsInRange \cdot (\locPXxYIsInfinity + \locPSatisfiesCubic ) \\ + \vspace{1mm} \\ + % + \locLargeSum \define + \left[ \begin{array}{l} + + \locPXHi + \locPXLo \\ + + \locPYHi + \locPYLo \\ + \end{array} \right] \\ + \locPXxYIsInfinity \define \isInfinity_{i+\relof} \\ + \If \locPIsInRange = 0 ~ \Then \locPXxYIsInfinity = 0 \\ + \If \locPIsInRange = 1 ~ \Then \\ + \qquad \If \locLargeSum = 0 ~ \Then \locPXxYIsInfinity = 1 \\ + \qquad \If \locLargeSum \neq 0 ~ \Then \locPXxYIsInfinity = 0 \\ + \end{array} \right. + \end{array} \right. +\] + +\saNote{} $\hurdle_{i + \relof}$ is expected to contain the final result. Intermediate results are contained in the subsequents rows, potentially up to $\relof + 2$. + +\[ + \left\{ \begin{array}{l} + \callToCOneMembershipWCP{i}{\relof}{\locPXHi}{\locPXLo}{\locPYHi}{\locPYLo} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + % \callToLt + % {i + \relof} + % {$\locPXHi$}{$\locPXLo$} + % {$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} + + + \wcpCallToLt { + anchorRow = i , + relOffset = \relof , + argOneHi = \locPXHi , + argOneLo = \locPXLo , + argTwoHi = \bnOuterPrimeHi , + argTwoLo = \bnOuterPrimeLo , + } \\ + + % \callToLt + % {i+\relof+1} + % {$\locPYHi$}{$\locPYHi$} + % {$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} + + + \wcpCallToLt { + anchorRow = i , + relOffset = \relof+1 , + argOneHi = \locPYHi , + argOneLo = \locPYLo , + argTwoHi = \bnOuterPrimeHi , + argTwoLo = \bnOuterPrimeLo , + } \\ + + % \callToEq + % {i+\relof+2} + % {$\locPXSquareHi$}{$\locPXSquareLo$} + % {$\locPXCubePlusThreeHi$}{$\locPXCubePlusThreeLo$} + + \wcpCallToEq { + anchorRow = i , + relOffset = \relof+2 , + argOneHi = \locPYSquareHi , + argOneLo = \locPYSquareLo , + argTwoHi = \locPXCubePlusThreeHi , + argTwoLo = \locPXCubePlusThreeLo , + } + \end{array} \right. + \end{array} \right. +\] + +\[ + \left\{ \begin{array}{l} + \callToCOneMembershipEXT{i}{\relof}{\locPXHi}{\locPXLo }{\locPYHi }{\locPYLo} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + % \callToMulMod{i+\relof}{$\locPYHi$}{$\locPYLo$}{$\locPYHi$}{$\locPYLo$}{$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} + \extCallToMulMod { + anchorRow = i , + relOffset = \relof , + argOneHi = \locPYHi , + argOneLo = \locPYLo , + argTwoHi = \locPYHi , + argTwoLo = \locPYLo , + argThreeHi = \bnOuterPrimeHi , + argThreeLo = \bnOuterPrimeLo , + } \\ + + % \callToMulMod{i+\relof+1}{$\locPXHi$}{$\locPXLo$}{$\locPXHi$}{$\locPXLo$}{$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} + \extCallToMulMod { + anchorRow = i , + relOffset = \relof+1 , + argOneHi = \locPXHi , + argOneLo = \locPXLo , + argTwoHi = \locPXHi , + argTwoLo = \locPXLo , + argThreeHi = \bnOuterPrimeHi , + argThreeLo = \bnOuterPrimeLo , + } \\ + + % \callToMulMod{i+\relof+2}{$\locPXSquareHi $}{$\locPXSquareLo$}{$\locPXHi$}{$\locPXLo$}{$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} + \extCallToMulMod { + anchorRow = i , + relOffset = \relof+2 , + argOneHi = \locPXSquareHi , + argOneLo = \locPXSquareLo , + argTwoHi = \locPXHi , + argTwoLo = \locPXLo , + argThreeHi = \bnOuterPrimeHi , + argThreeLo = \bnOuterPrimeLo , + } \\ + + % \callToAddMod{i+\relof+3}{$\locPXCubeHi$}{$\locPXCubeLo$}{0}{3}{$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} + \extCallToAddMod { + anchorRow = i , + relOffset = \relof+3 , + argOneHi = \locPXCubeHi , + argOneLo = \locPXCubeLo , + argTwoHi = 0 , + argTwoLo = 3 , + argThreeHi = \bnOuterPrimeHi , + argThreeLo = \bnOuterPrimeLo , + } + \end{array} \right. + \end{array} \right. +\] diff --git a/prc/ecdata/utils/ext.tex b/prc/ecdata/utils/ext.tex new file mode 100644 index 0000000..d86c050 --- /dev/null +++ b/prc/ecdata/utils/ext.tex @@ -0,0 +1,56 @@ +The present section provides the facilities to trigger the \extMod{} module. +We define the following constraint: + +\[ + \left\{ \begin{array}{l} + \extCallToAddMod { + anchorRow = i , + relOffset = \relof , + argOneHi = \col{a} , + argOneLo = \col{b} , + argTwoHi = \col{c} , + argTwoLo = \col{d} , + argThreeHi = \col{e} , + argThreeLo = \col{f} , + } + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \extFlag _{i+\relof} & = & 1 \\ + \extInst _{i+\relof} & = & \inst{ADDMOD} \\ + \extArgOneHi _{i+\relof} & = & \col{a} \\ + \extArgOneLo _{i+\relof} & = & \col{b} \\ + \extArgTwoHi _{i+\relof} & = & \col{c} \\ + \extArgTwoLo _{i+\relof} & = & \col{d} \\ + \extArgThreeHi _{i+\relof} & = & \col{e} \\ + \extArgThreeLo _{i+\relof} & = & \col{f} \\ + \end{array} \right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \extCallToMulMod { + anchorRow = i , + relOffset = \relof , + argOneHi = \col{a} , + argOneLo = \col{b} , + argTwoHi = \col{c} , + argTwoLo = \col{d} , + argThreeHi = \col{e} , + argThreeLo = \col{f} , + } + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \extFlag _{i+\relof} & = & 1 \\ + \extInst _{i+\relof} & = & \inst{ADDMUL} \\ + \extArgOneHi _{i+\relof} & = & \col{a} \\ + \extArgOneLo _{i+\relof} & = & \col{b} \\ + \extArgTwoHi _{i+\relof} & = & \col{c} \\ + \extArgTwoLo _{i+\relof} & = & \col{d} \\ + \extArgThreeHi _{i+\relof} & = & \col{e} \\ + \extArgThreeLo _{i+\relof} & = & \col{f} \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/prc/ecdata/utils/wcp.tex b/prc/ecdata/utils/wcp.tex new file mode 100644 index 0000000..ad4bc92 --- /dev/null +++ b/prc/ecdata/utils/wcp.tex @@ -0,0 +1,68 @@ +The present section provides the facilities to trigger the \wcpMod{} module. +We define the following constraint: +\[ + \left\{ \begin{array}{l} + \wcpCallToLt { + anchorRow = i , + relOffset = \relof , + argOneHi = \col{a} , + argOneLo = \col{b} , + argTwoHi = \col{c} , + argTwoLo = \col{d} , + } + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \wcpFlag _{i+\relof} & = & 1 \\ + \wcpInst _{i+\relof} & = & \inst{LT} \\ + \wcpArgOneHi _{i+\relof} & = & \col{a} \\ + \wcpArgOneLo _{i+\relof} & = & \col{b} \\ + \wcpArgTwoHi _{i+\relof} & = & \col{c} \\ + \wcpArgTwoLo _{i+\relof} & = & \col{d} \\ + \end{array} \right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \wcpCallToEq { + anchorRow = i , + relOffset = \relof , + argOneHi = \col{a} , + argOneLo = \col{b} , + argTwoHi = \col{c} , + argTwoLo = \col{d} , + } + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \wcpFlag _{i+\relof} & = & 1 \\ + \wcpInst _{i+\relof} & = & \inst{EQ} \\ + \wcpArgOneHi _{i+\relof} & = & \col{a} \\ + \wcpArgOneLo _{i+\relof} & = & \col{b} \\ + \wcpArgTwoHi _{i+\relof} & = & \col{c} \\ + \wcpArgTwoLo _{i+\relof} & = & \col{d} \\ + \end{array} \right. + \end{array} \right. +\] +and +\[ + \left\{ \begin{array}{l} + \wcpCallToIszero { + anchorRow = i , + relOffset = \relof , + argOneHi = \col{a} , + argOneLo = \col{b} , + } + \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{lcl} + \wcpFlag _{i+\relof} & = & 1 \\ + \wcpInst _{i+\relof} & = & \inst{ISZERO} \\ + \wcpArgOneHi _{i+\relof} & = & \col{a} \\ + \wcpArgOneLo _{i+\relof} & = & \col{b} \\ + \wcpArgTwoHi _{i+\relof} & = & 0 \quad (\trash) \\ + \wcpArgTwoLo _{i+\relof} & = & 0 \quad (\trash) \\ + \end{array} \right. + \end{array} \right. +\] diff --git a/prc/ecdata/utils/well_formed_coordinates.tex b/prc/ecdata/utils/well_formed_coordinates.tex new file mode 100644 index 0000000..11810ba --- /dev/null +++ b/prc/ecdata/utils/well_formed_coordinates.tex @@ -0,0 +1,88 @@ +\[ + \left\{ \begin{array}{l} + \callToWellFormedCoordinates{\relof}{\locBXImHi}{\locBXImLo}{\locBXReHi}{\locBXReLo}{\locBYImHi}{\locBYImLo}{\locBYReHi}{\locBYReLo} \vspace{4mm} \\ + \qquad \qquad \iff + \left\{ \begin{array}{l} + % \callToLt + % {i + \relof} + % {\locBXImHi}{\locBXImLo} + % {$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} \\ + \wcpCallToLt { + anchorRow = i , + relOffset = \relof , + argOneHi = \locBXImHi , + argOneLo = \locBXImLo , + argTwoHi = \bnOuterPrimeHi , + argTwoLo = \bnOuterPrimeLo , + } \\ + \locBXImIsInRange \define \wcpRes_{i+\relof} \\ + % + % \callToLt + % {i + \relof+1} + % {\locBXReHi}{\locBXReLo} + % {$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} \\ + \wcpCallToLt { + anchorRow = i , + relOffset = \relof+1 , + argOneHi = \locBXReHi , + argOneLo = \locBXReLo , + argTwoHi = \bnOuterPrimeHi , + argTwoLo = \bnOuterPrimeLo , + } \\ + \locBXReIsInRange \define \wcpRes_{i+\relof+1} \\ + % + % \callToLt + % {i + \relof+2} + % {\locBYImHi}{\locBYImLo} + % {$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} \\ + \wcpCallToLt { + anchorRow = i , + relOffset = \relof+2 , + argOneHi = \locBYImHi , + argOneLo = \locBYImLo , + argTwoHi = \bnOuterPrimeHi , + argTwoLo = \bnOuterPrimeLo , + } \\ + \locBYImIsInRange \define \wcpRes_{i+\relof+2} \\ + % + % \callToLt + % {i+\relof+3} + % {\locBYReHi}{\locBYReLo} + % {$\bnOuterPrimeHi$}{$\bnOuterPrimeLo$} \\ + \wcpCallToLt { + anchorRow = i , + relOffset = \relof+3 , + argOneHi = \locBYReHi , + argOneLo = \locBYReLo , + argTwoHi = \bnOuterPrimeHi , + argTwoLo = \bnOuterPrimeLo , + } \\ + \locBYReIsInRange \define \wcpRes_{i+\relof+3} \\ + %\vspace{1mm} \\ + % + \locBXIsInRange \define \hurdle_{i + \relof + 2} \\ + \locBYIsInRange \define \hurdle_{i + \relof + 1} \\ + + \locWellFormedCoordinates \define \hurdle_{i + \relof} \\ + \vspace{1mm} + % + \locBXIsInRange = \locBXImIsInRange \cdot \locBXReIsInRange \\ + \locBYIsInRange = \locBYImIsInRange \cdot \locBYReIsInRange \\ + \locWellFormedCoordinates = \locBXIsInRange \cdot \locBYIsInRange \\ + \vspace{1mm} + % + \locVeryLargeSum \define + \left[ \begin{array}{r} + + \locBXImHi + \locBXReHi + \locBYImHi + \locBYReHi \\ + + \locBXImLo + \locBXReLo + \locBYImLo + \locBYReLo \\ + \end{array} \right] \\ + \locBXbYIsInfinity \define \isInfinity_{i+\relof} \\ + \If \locWellFormedCoordinates = 0 ~ \Then \locBXbYIsInfinity = 0 \\ + \If \locWellFormedCoordinates = 1 ~ \Then \\ + \qquad \If \locVeryLargeSum = 0 ~ \Then \locBXbYIsInfinity = 1 \\ + \qquad \If \locVeryLargeSum \neq 0 ~ \Then \locBXbYIsInfinity = 0 \\ + \end{array} \right. + \end{array} \right. +\] +% +\saNote{} $\hurdle_{\relof}$ is expected to contain the final result. Intermediate results are contained in the subsequents rows, potentially up to $\relof + 5$. diff --git a/prc/ecdata/visual_representation_for_pairings.tex b/prc/ecdata/visual_representation_for_pairings.tex new file mode 100644 index 0000000..f767a69 --- /dev/null +++ b/prc/ecdata/visual_representation_for_pairings.tex @@ -0,0 +1,90 @@ +In this section, we provide a visual representation of the branching behaviour implemented by the constraints for dealing with an \inst{ECPAIRING} call +with inputs $(\locA_1,\locB_1),\dots,(\locA_n,\locB_n)$. + +\begin{figure}[htb] + \centering + \begin{tikzpicture}[sibling distance=15em, + level distance=6em, + every node/.style = {align=center, font=\scriptsize}, + edge from parent/.style = {draw, -}, + level 1/.style={sibling distance=15em}, + level 2/.style={sibling distance=15em}, + level 3/.style={sibling distance=15em}, + level 4/.style={sibling distance=7.5em}, + level 5/.style={sibling distance=15em}, + level 6/.style={sibling distance=15em} + ] + \node {$\{(\locA_1,\locB_1),\dots,(\locA_n,\locB_n)\}$} + child { node[coordinate] {} + child { node {\begin{tabular}{lcl} + \ecdataSuccessBit & = & 0 \\ + \csGTwo & = & 1 \text{ for } $\locB_{k_0}$\\ + \csEcpairing & = & 0 \\ + \end{tabular}} + edge from parent node[midway, above left] {$\exists k_0,~\locB_{k_0} \notin G_2$} + } + child { node[coordinate] {} + child { node[coordinate] {} + child {node[coordinate] {} + edge from parent node[midway, above left] {$1$} + edge from parent node[midway, above right] {$~~~~\dots$} + } + child { node[coordinate] {} + child { node[coordinate] {} + child { node {\begin{tabular}{lcl} + \ecdataSuccessBit & = & 1 \\ + \csGTwo & = & 0 \\ + \csEcpairing & = & 1 \\ + \end{tabular}} + edge from parent node[midway, above left] {$\locA \neq \infty$} + } + child { node {\begin{tabular}{lcl} + \ecdataSuccessBit & = & 1 \\ + \csGTwo & = & 1 \\ + \csEcpairing & = & 0 \\ + \end{tabular}} + edge from parent node[midway, above right] {$\locA = \infty$} + } + edge from parent node[midway, above left] {$\locB_k \neq \infty$} + } + child { node {\begin{tabular}{lcl} + \ecdataSuccessBit & = & 1 \\ + \csGTwo & = & 0 \\ + \csEcpairing & = & 0 \\ + \end{tabular}} + edge from parent node[midway, above right] {$\locB_k = \infty$} + } + edge from parent node[midway, above left] {$k$} + } + child {node[coordinate] {} + edge from parent node[midway, above right] {$n$} + edge from parent node[midway, above left] {$\dots~~~~$} + } + edge from parent node[midway, above left] {$\exists k,~\locB_k \neq \infty$} + } + child { node {\begin{tabular}{lcl} + \ecdataSuccessBit & = & 1 \\ + \csGTwo & = & 0 \\ + \csEcpairing & = & 0 \\ + \trivialPairing & = & 1 \\ + \end{tabular}} + edge from parent node[midway, above right] {$\forall k,~\locB_k = \infty$} + } + edge from parent node[midway, above right] {$\forall k,~\locB_k \in G_2$} + } + edge from parent node[midway, above left] {$\internalChecksPassed = 1$} + } + child { node {\begin{tabular}{lcl} + \ecdataSuccessBit & = & 0 \\ + \csGTwo & = & 0 \\ + \csEcpairing & = & 0 \\ + \end{tabular}} + edge from parent node[midway, above right] {$\internalChecksPassed = 0$} + }; + \end{tikzpicture} + \caption{% + Visual representation of the branching behaviour of \inst{ECPAIRING}. In the imeplementation, $\locB_{k_0} \notin G_2$ is the first one appearing in the input.} + \label{fig:visual_representation} +\end{figure} + + diff --git a/prc/shakira/_inputs.tex b/prc/shakira/_inputs.tex new file mode 100644 index 0000000..5d48ada --- /dev/null +++ b/prc/shakira/_inputs.tex @@ -0,0 +1,16 @@ +\section{Introduction} \label{shakira: introduction} \input{shakira/intro} + +\section{Columns} \label{shakira: columns} \input{shakira/columns} + +\section{General constraints} +\subsection{Binary columns} \label{shakira: binary} \input{shakira/binary} +\subsection{Shorthands} \label{shakira: shorthands} \input{shakira/shorthands} +\subsection{Constancies} \label{shakira: constancies} \input{shakira/constancies} +\subsection{Decoding constraints} \label{shakira: decoding} \input{shakira/decoding} +\subsection{\shakiraTotalSize{} generalities} \label{shakira: total size} \input{shakira/total_size} +\subsection{Heartbeat} \label{shakira: heartbeat} \input{shakira/heartbeat} +\subsection{\nBytes{} accumulation} \label{shakira: stamp increment} \input{shakira/accumulation} +\subsection{Result selectors} \label{shakira: result selectors} \input{shakira/result_selector} +\subsection{Graphical representation} \label{shakira: representation} \includepdf[fitpaper=true]{shakira/lua/layout.pdf} + +\section{Lookups} \label{shakira: lookups} \input{shakira/lookups/_inputs} diff --git a/prc/shakira/accumulation.tex b/prc/shakira/accumulation.tex new file mode 100644 index 0000000..9e5165d --- /dev/null +++ b/prc/shakira/accumulation.tex @@ -0,0 +1,34 @@ +We impose constraints on the $\big( \nBytes, \nBytesAcc \big)$ pair. +\begin{enumerate} + \item \If $\shakiraStamp_{i} \neq \shakiraStamp_{i - 1}$ \Then $\nBytes_{i} = \nBytesAcc_{i}$ + \item \If \Big($\locIsData_{i - 1} = 1$ \et $\locIsData_{i} = 1$\Big) + \Then + \[ + \left\{ \begin{array}{lcl} + \nBytes _{i - 1} & = & \llarge \\ + \nBytesAcc _{i} & = & \nBytesAcc_{i - 1} + \nBytes_{i} \\ + \end{array} \right. + \] + \item \If \Big($\locIsData_{i - 1} = 1$ \et $\locIsResult_{i} = 1$\Big) + \[ + \nBytesAcc _{i - 1} = \shakiraTotalSize_{i - 1} + \] +\end{enumerate} +\saNote{} +The two lookups from +section~(\ref{shakira: lookups: nonzero last nBYTES}) and +section~(\ref{shakira: lookups: small last nBYTES}) +impose that the final value of \nBytes{} along \textbf{data-rows} (i.e. rows satisfying $\locIsData \equiv 1$) is in the range $\{1, 2, \dots, \llarge\}$. +Along with the above this enforces that along data-rows $i$ one has +\[ + \nBytes_{i} \equiv + \left\{ \begin{array}{ll} + \llarge & \text{if the next row is also a data-row} \\ + \in \{ 1, 2, \dots, \llarge \} & \text{otherwise} \\ + \end{array} \right. +\] +Together with the target constraint happening when swithching from data to result this imposes implicitly that along data-rows +\[ + \indexMax \equiv ( \shakiraTotalSize - 1 ) ~ /\!/ ~ \llarge +\] +where $/\!/$ stands for integer division (i.e. the quotient of the euclidean division.) diff --git a/prc/shakira/binary.tex b/prc/shakira/binary.tex new file mode 100644 index 0000000..f787c3b --- /dev/null +++ b/prc/shakira/binary.tex @@ -0,0 +1,15 @@ +We impose binarity constraints on the following columns: +\begin{multicols}{3} + \begin{enumerate} + \item \isShakiraKeccakData + \item \isShakiraShaTwoData + \item \isShakiraRipemdData + \item \isShakiraKeccakResult + \item \isShakiraShaTwoResult + \item \isShakiraRipemdResult + \item $\selectorKeccakRes\high$ (\trash) + \item $\selectorShaTwoRes\high$ (\trash) + \item $\selectorRipemdRes\high$ (\trash) + %\item[\vspace{\fill}] + \end{enumerate} +\end{multicols} diff --git a/prc/shakira/columns.tex b/prc/shakira/columns.tex new file mode 100644 index 0000000..a7d4fe8 --- /dev/null +++ b/prc/shakira/columns.tex @@ -0,0 +1,46 @@ +\begin{enumerate} + \item \shakiraStamp{}: + module stamp + \item \shakiraId{}: + unique data identifier; + can have large increments but must be listed in ascending order; + \item \shakiraPhase{}: + ``phase'' column; + \item \index{}: + index column + \item \indexMax{}: + associated ``maximum index'' column; +\end{enumerate} +A data limb is uniquely determined by +(\emph{a}) a unique identifier, +(\emph{b}) a phase and +(\emph{c}) an index. +These are provided above. +\begin{enumerate}[resume] + \item \limb{}: + data limb column; + \item $\nBytes$: + column containing the number of bytes $\in \{ 1, 2, \dots, \llarge \}$ of a particular limb; + equal to $\llarge$ on all data-rows besides possibly the last one; + \item $\nBytesAcc$: + column accumulating the $\nBytes$ column; + \item $\shakiraTotalSize$: + column containing the total data size; +\end{enumerate} +The following columns are exclusive binary columns that allow the present module to identify the nature of the data it holds. +\begin{multicols}{2} + \begin{enumerate}[resume] + \item \isShakiraKeccakData{} + \item \isShakiraShaTwoData{} + \item \isShakiraRipemdData{} + \item \isShakiraKeccakResult{} + \item \isShakiraShaTwoResult{} + \item \isShakiraRipemdResult{} + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +The following columns are bit columns that light up exactly when the \limb{} contains the high part of the result of an instruction. It plays no rôle in the arithmetization \emph{per se} but proves useful to the prover. +\begin{enumerate} + \item $\selectorKeccakRes\high$, $\selectorShaTwoRes\high$ and $\selectorRipemdRes\high$: +\end{enumerate} diff --git a/prc/shakira/constancies.tex b/prc/shakira/constancies.tex new file mode 100644 index 0000000..f34f0ec --- /dev/null +++ b/prc/shakira/constancies.tex @@ -0,0 +1,23 @@ +As per usual we declare a column \col{X} to be \textbf{stamp-constant} if it satisfies +\[ + \If \shakiraStamp_{i} \neq 1 + \shakiraStamp_{i - 1} ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose stamp-constancy on +\begin{enumerate} + \item \shakiraId{} +\end{enumerate} +\noindent As per usual we declare a column \col{X} to be \textbf{index-constant} if it satisfies +\[ + \If \index_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose index-constancy on +\begin{multicols}{2} + \begin{enumerate} + \item \weightedPhaseFlagSum + \item \indexMax + \item \shakiraTotalSize{} + \end{enumerate} +\end{multicols} +\saNote{} +Index-constancy of \weightedPhaseFlagSum{} will implicitly impose index-constancy of the binary flags from section~(\ref{shakira: binary}). +This will follow from the constraints imposed on \flagSum{} in section~(\ref{shakira: decoding}). diff --git a/prc/shakira/decoding.tex b/prc/shakira/decoding.tex new file mode 100644 index 0000000..b657e77 --- /dev/null +++ b/prc/shakira/decoding.tex @@ -0,0 +1,17 @@ +\begin{enumerate} + \item $\flagSum$ is binary \quad (\trash) + \item \If $\shakiraStamp_{i} = 0$ \Then $\flagSum_{i} = 0$ + \item \If $\shakiraStamp_{i} \neq 0$ \Then $\flagSum_{i} = 1$ + \item Furthermore + \[ + \shakiraPhase_{i} = \weightedPhaseFlagSum_{i} + \] +\end{enumerate} +\saNote{} The above enforces that the following binary columns +\isShakiraKeccakData {}, +\isShakiraKeccakResult {}, +\isShakiraShaTwoData {}, +\isShakiraShaTwoResult {}, +\isShakiraRipemdData {} and +\isShakiraRipemdResult {} +be \textbf{mutually exclusive binary columns}. diff --git a/prc/shakira/heartbeat.tex b/prc/shakira/heartbeat.tex new file mode 100644 index 0000000..735f9c1 --- /dev/null +++ b/prc/shakira/heartbeat.tex @@ -0,0 +1,49 @@ +\saNote{} All of \locStampIncrement{}, \locIndexResetBit{} and \locLegalTransitionsBit{} are in fact \textbf{binary} expressions. + +\noindent We impose the following +\begin{enumerate} + \item $\shakiraStamp_{0} = 0$ + \item \If $\flagSum_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \shakiraId _{i} & = & 0 \\ + \index _{i} & = & 0 \\ + \indexMax _{i} & = & 0 & (\trash) \\ + \end{array} \right. + \] + \item $\shakiraStamp_{i + 1} \in \{ \shakiraStamp_{i}, 1 + \shakiraStamp_{i} \}$ \quad(\trash) + \item $\shakiraStamp_{i + 1} = \shakiraStamp_{i} + \locStampIncrement_{i}$ + \item \If $\locIndexResetBit_{i} = 1$ \Then $\index_{i + 1} = 0$ + \item \If $\shakiraStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item $\locLegalTransitionsBit_{i} = 1$ + \item \If $\index_{i} \neq \indexMax_{i}$ \Then $\index_{i + 1} = 1 + \index_{i}$ + % \[ + % \left\{ \begin{array}{lclr} + % \index_{i + 1} & = & 1 + \index_{i} \\ + % \locTransitionBit_{i} & = & 0 & (\trash) \\ + % \end{array} \right. + % \] + \item \If $\index_{i} = \indexMax_{i}$ \Then $\locIndexResetBit_{i} = 1$ + % \[ + % \left\{ \begin{array}{lclr} + % \index_{i + 1} & = & 0 & (\trash) \\ + % \locTransitionBit_{i} & = & 1 \\ + % \end{array} \right. + % \] + \end{enumerate} + \item \If $\locIsResult_{i} = 1$ \Then + \[ + \indexMax_{i} = 1 + \] + \item \If $\shakiraStamp_{N} \neq 0$ \Then + \[ + \left\{ \begin{array}{lclr} + \index _{N} & = & \indexMax_{N} & \quad (\trash) \\ + \locIsResult _{N} & = & 1 & \quad (\trash) \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{} The same remark applies for note~(\ref{blkmdx: finalization constraints are useless}). + +\saNote{} We are unable to set the value of \indexMax{} at this level of generality. We will do so implicitly in section~(\ref{shakira: stamp increment}). diff --git a/prc/shakira/intro.tex b/prc/shakira/intro.tex new file mode 100644 index 0000000..e69de29 diff --git a/prc/shakira/lookups/_inputs.tex b/prc/shakira/lookups/_inputs.tex new file mode 100644 index 0000000..42cceb5 --- /dev/null +++ b/prc/shakira/lookups/_inputs.tex @@ -0,0 +1,4 @@ +\subsection{Introduction} \label{shakira: lookups: intro} \input{shakira/lookups/intro} +\subsection{Into \wcpMod{}: increasing \shakiraId{}} \label{shakira: lookups: increasing Id} \input{shakira/lookups/shakira_into_wcp_increasing_id} +\subsection{Into \wcpMod{}: non-zero last \nBytes{}} \label{shakira: lookups: nonzero last nBYTES} \input{shakira/lookups/shakira_into_wcp_nonzero_last_nbytes} +\subsection{Into \wcpMod{}: small last \nBytes{}} \label{shakira: lookups: small last nBYTES} \input{shakira/lookups/shakira_into_wcp_small_last_nbytes} diff --git a/prc/shakira/lookups/intro.tex b/prc/shakira/lookups/intro.tex new file mode 100644 index 0000000..07a0689 --- /dev/null +++ b/prc/shakira/lookups/intro.tex @@ -0,0 +1,7 @@ +We will use the following shorthands in what follows: +\[ + \left\{ \begin{array}{lcl} + \locIsFirstDataRow _{i} & = & \locIsData _{i} \cdot (1 - \locIsData _{i - 1}) \\ + \locIsFinalDataRow _{i} & = & \locIsData _{i} \cdot \locIsResult _{i + 1} \\ + \end{array} \right. +\] diff --git a/prc/shakira/lookups/shakira_into_wcp_increasing_id.tex b/prc/shakira/lookups/shakira_into_wcp_increasing_id.tex new file mode 100644 index 0000000..937cc28 --- /dev/null +++ b/prc/shakira/lookups/shakira_into_wcp_increasing_id.tex @@ -0,0 +1,27 @@ +The purpose of the present lookup argument is to delegate the proof of lexicographic ordering of $\shakiraId$ to the \wcpMod{} module. +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\locIsFirstDataRow$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $0$ + \item $\shakiraId_{i - 1}$ + \item $0$ + \item $\shakiraId_{i}$ + \item $1$ + \item $\inst{LT}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/prc/shakira/lookups/shakira_into_wcp_nonzero_last_nbytes.tex b/prc/shakira/lookups/shakira_into_wcp_nonzero_last_nbytes.tex new file mode 100644 index 0000000..34e249b --- /dev/null +++ b/prc/shakira/lookups/shakira_into_wcp_nonzero_last_nbytes.tex @@ -0,0 +1,26 @@ +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\locIsFinalDataRow _{i}$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $0$ + \item $\nBytes_{i}$ + \item $0$ + \item $0$ + \item $1$ + \item $\inst{GT}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/prc/shakira/lookups/shakira_into_wcp_small_last_nbytes.tex b/prc/shakira/lookups/shakira_into_wcp_small_last_nbytes.tex new file mode 100644 index 0000000..08b0e18 --- /dev/null +++ b/prc/shakira/lookups/shakira_into_wcp_small_last_nbytes.tex @@ -0,0 +1,26 @@ +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] $\locIsFinalDataRow _{i}$: + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $0$ + \item $\nBytes_{i}$ + \item $0$ + \item $\llarge$ + \item $1$ + \item $\inst{LEQ}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/prc/shakira/lua/layout.lua.tex b/prc/shakira/lua/layout.lua.tex new file mode 100644 index 0000000..088048b --- /dev/null +++ b/prc/shakira/lua/layout.lua.tex @@ -0,0 +1,114 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} +\usepackage{../../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + ██\ ██\ ████████\ ██████\ ██\ ██████\ ██\ ██\ ██████\ ██\ ███████\ ██████\ ███████\ + ██ | ██ |██ _____|██ __██\ ██ | ██ __██\ ██ | ██ |██ __██\ ██ | ██ __██\ \_██ _|██ __██\ + ██ |██ / ██ | ██ / \__| ██ / ██ / \__|██ | ██ |██ / ██ | ██ / ██ | ██ | ██ | ██ | ██ | + █████ / █████\ ██ | ██ / \██████\ ████████ |████████ | ██ / ███████ | ██ | ███████ | + ██ ██< ██ __| ██ | ██ / \____██\ ██ __██ |██ __██ | ██ / ██ __██< ██ | ██ ____/ + ██ |\██\ ██ | ██ | ██\ ██ / ██\ ██ |██ | ██ |██ | ██ | ██ / ██ | ██ | ██ | ██ | + ██ | \██\ ████████\ \██████ | ██ / \██████ |██ | ██ |██ | ██ | ██ / ██ | ██ |██████\ ██ | + \__| \__|\________| \______/ \__/ \______/ \__| \__|\__| \__| \__/ \__| \__|\______|\__| + + + +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| STAMP | ID | PHASE | INDEX | INDEX_MAX | LIMB | nBYTES | nBYTES_ACC | SIZE | IS_SHA2_DATA | IS_SHA2_RESULT | IS_RIPEMD_DATA | IS_RIPEMD_RESULT | IS_KECCAK_DATA | IS_KECCAK_RESULT | +|:-----:+:----:+:---------------:+:-----:+:---------:+:-----------------------------------:+:------:+:----------:+:----:+:------------:+:--------------:+:--------------:+:----------------:+:--------------:+:----------------:| +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| 1 | 311 | ⟦Φ_sha2_data⟧ | 0 | 11 | 0x 11111111111111111111111111111111 | 16 | 16 | 179 | 1 | | | | | | +| 1 | 311 | ⟦Φ_sha2_data⟧ | 1 | 11 | 0x 22222222222222222222222222222222 | 16 | 32 | 179 | 1 | | | | | | +| 1 | 311 | ⟦Φ_sha2_data⟧ | 2 | 11 | 0x 33333333333333333333333333333333 | 16 | 48 | 179 | 1 | | | | | | +| ⋮ | ⋮ | ⋮ | ⋮ | 11 | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | | | | | +| 1 | 311 | ⟦Φ_sha2_data⟧ | 10 | 11 | 0x aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 16 | 160 | 179 | 1 | | | | | | +| 1 | 311 | ⟦Φ_sha2_data⟧ | 10 | 11 | 0x bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | 16 | 176 | 179 | 1 | | | | | | +| 1 | 311 | ⟦Φ_sha2_data⟧ | 11 | 11 | 0x cccccc.......................... | 3 | 179 | 179 | 1 | | | | | | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| 1 | 311 | ⟦Φ_sha2_res⟧ | 0 | 1 | 0x f1e6d28733798b6e820a372e917474e5 | | | 32 | | 1 | | | | | +| 1 | 311 | ⟦Φ_sha2_res⟧ | 1 | 1 | 0x 5168c5d7d5bb21a1d0dd3348bb1a527b | | | 32 | | 1 | | | | | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| 2 | 1359 | ⟦Φ_ripe_data⟧ | 0 | 3 | 0x blabla | 16 | 16 | 64 | | | 1 | | | | +| 2 | 1359 | ⟦Φ_ripe_data⟧ | 1 | 3 | 0x blabla | 16 | 32 | 64 | | | 1 | | | | +| 2 | 1359 | ⟦Φ_ripe_data⟧ | 2 | 3 | 0x blabla | 16 | 48 | 64 | | | 1 | | | | +| 2 | 1359 | ⟦Φ_ripe_data⟧ | 3 | 3 | 0x blabla | 16 | 64 | 64 | | | 1 | | | | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| 2 | 1359 | ⟦Φ_ripe_res⟧ | 0 | 1 | 0x res_hi | | | 32 | | | | 1 | | | +| 2 | 1359 | ⟦Φ_ripe_res⟧ | 1 | 1 | 0x res_lo | | | 32 | | | | 1 | | | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| 3 | 8801 | ⟦Φ_keccak_data⟧ | 0 | 0 | 0x deadbeef000000.................. | 7 | 7 | 7 | | | | | 1 | | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| 3 | 8801 | ⟦Φ_keccak_res⟧ | 0 | 1 | 0x 346a46007b196aee621ab966ab92e170 | | | 32 | | | | | | 1 | +| 3 | 8801 | ⟦Φ_keccak_res⟧ | 1 | 1 | 0x a0915cdbc736b93c7492711be58c1c2f | | | 32 | | | | | | 1 | +|-------+------+-----------------+-------+-----------+-------------------------------------+--------+------------+------+--------------+----------------+----------------+------------------+----------------+------------------| +| ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | | + +NOTE. We wrote "0x cccccc.........................." in stead of "0x cccccc00000000000000000000000000" to make the table more readable. +In the above example the final input data limb is the 16 byte integer + + "0x cccccc00000000000000000000000000" i.e. 0xcccccc • (256 ** 13) + +NOTE. We similarly wrote "0x deadbeef000000.................." in stead of "0x deadbeef000000000000000000000000". + +\end{verbatim} +\end{document} + + +11111111111111111111111111111111 +22222222222222222222222222222222 +33333333333333333333333333333333 +44444444444444444444444444444444 +55555555555555555555555555555555 +66666666666666666666666666666666 +77777777777777777777777777777777 +88888888888888888888888888888888 +99999999999999999999999999999999 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +cccccc00000000000000000000000000 + +f1e6d28733798b6e820a372e917474e5 +5168c5d7d5bb21a1d0dd3348bb1a527b + + +111111111111111111111111111111112222222222222222222222222222222233333333333333333333333333333333444444444444444444444444444444445555555555555555555555555555555566666666666666666666666666666666777777777777777777777777777777778888888888888888888888888888888899999999999999999999999999999999aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc00000000000000000000000000 + +111111111111111111111111111111112222222222222222222222222222222233333333333333333333333333333333444444444444444444444444444444445555555555555555555555555555555566666666666666666666666666666666777777777777777777777777777777778888888888888888888888888888888899999999999999999999999999999999aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc + +5f78c33274e43fa9de5659265c1d917e +25c03722dcb0b8d27db8d5feaa813953 + +4c0d9602ae0a7b154a6b6d131e11902a +608ffb2367a00356e2275f2035245a49 + +346a46007b196aee621ab966ab92e170 +a0915cdbc736b93c7492711be58c1c2f + + ███████\ ██████\ ███████\ ██\ ██████\ ██\ ██\ ██████\ + ██ __██\ \_██ _|██ __██\ ██ | ██ __██\ ██ | ██ |██ __██\ + ██ | ██ | ██ | ██ | ██ | ██ / ██ / \__|██ | ██ |██ / ██ | + ███████ | ██ | ███████ | ██ / \██████\ ████████ |████████ | + ██ __██< ██ | ██ ____/ ██ / \____██\ ██ __██ |██ __██ | + ██ | ██ | ██ | ██ | ██ / ██\ ██ |██ | ██ |██ | ██ | + ██ | ██ |██████\ ██ | ██ / \██████ |██ | ██ |██ | ██ | + \__| \__|\______|\__| \__/ \______/ \__| \__|\__| \__| + diff --git a/prc/shakira/result_selector.tex b/prc/shakira/result_selector.tex new file mode 100644 index 0000000..8ab8c8a --- /dev/null +++ b/prc/shakira/result_selector.tex @@ -0,0 +1,8 @@ +We constrain $\selectorKeccakRes\high$ (resp. $\selectorKeccakRes\low$) to light up exactly when the \limb{} contains the high (resp. low) part of the \inst{KEC} result: +\begin{enumerate} + \item $\selectorKeccakRes\high_{i} = \isShakiraKeccakResult_{i} \cdot (1 - \index_{i})$ + \item $\selectorShaTwoRes\high_{i} = \isShakiraShaTwoResult_{i} \cdot (1 - \index_{i})$ + \item $\selectorRipemdRes\high_{i} = \isShakiraRipemdResult_{i} \cdot (1 - \index_{i})$ +\end{enumerate} +\saNote{} These columns play no rôle in the arithmetization \emph{per se}. +Instead they are used for data extraction by the prover. diff --git a/prc/shakira/shorthands.tex b/prc/shakira/shorthands.tex new file mode 100644 index 0000000..71bf0fb --- /dev/null +++ b/prc/shakira/shorthands.tex @@ -0,0 +1,78 @@ +We define the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locShakiraIsKeccak_{i} & \define & + \left[ \begin{array}{cl} + + & \isShakiraKeccakData _{i} \\ + + & \isShakiraKeccakResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locShakiraIsShaTwo_{i} & \define & + \left[ \begin{array}{cl} + + & \isShakiraShaTwoData _{i} \\ + + & \isShakiraShaTwoResult _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locShakiraIsRipemd_{i} & \define & + \left[ \begin{array}{cl} + + & \isShakiraRipemdData _{i} \\ + + & \isShakiraRipemdResult _{i} \\ + \end{array} \right] \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcr} + \locIsData _{i} & \define & + \left[ \begin{array}{cr} + + & \isShakiraKeccakData _{i} \\ + + & \isShakiraShaTwoData _{i} \\ + + & \isShakiraRipemdData _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locIsResult _{i} & \define & + \left[ \begin{array}{cr} + + & \isShakiraKeccakResult _{i} \\ + + & \isShakiraShaTwoResult _{i} \\ + + & \isShakiraRipemdResult _{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +We further set +\[ + \left\{ \begin{array}{lcl} + \flagSum_{i} & \define & + \left[ \begin{array}{cr} + + & \locShakiraIsKeccak_{i} \\ + + & \locShakiraIsShaTwo_{i} \\ + + & \locShakiraIsRipemd_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \weightedPhaseFlagSum_{i} & \define & + \left[ \begin{array}{crcl} + + & \phaseKeccakData & \!\!\!\cdot\!\!\! & \isShakiraKeccakData _{i} \\ + + & \phaseKeccakResult & \!\!\!\cdot\!\!\! & \isShakiraKeccakResult _{i} \\ + + & \phaseShaTwoData & \!\!\!\cdot\!\!\! & \isShakiraShaTwoData _{i} \\ + + & \phaseShaTwoResult & \!\!\!\cdot\!\!\! & \isShakiraShaTwoResult _{i} \\ + + & \phaseRipemdData & \!\!\!\cdot\!\!\! & \isShakiraRipemdData _{i} \\ + + & \phaseRipemdResult & \!\!\!\cdot\!\!\! & \isShakiraRipemdResult _{i} \\ + \end{array} \right] \\ + \end{array} \right. +\] +We further define the following shorthands which will come in handy in the heartbeat section: +\[ + \left\{ \begin{array}{lcl} + \locStampIncrement_{i} & \define & (1 - \locIsData_{i}) \cdot \locIsData_{i + 1} \\ + \locIndexResetBit_{i} & \define & + \left[ \begin{array}{crcl} + + & (1 - \locIsData_{i}) & \!\!\!\cdot\!\!\! & \locIsData_{i + 1} \\ + + & (1 - \locIsResult_{i}) & \!\!\!\cdot\!\!\! & \locIsResult_{i + 1} \\ + \end{array} \right] \vspace{2mm} \\ + \locLegalTransitionsBit_{i} & \define & + \left[ \begin{array}{crcl} + + & \isShakiraKeccakData _{i} & \!\!\!\cdot\!\!\! & \locShakiraIsKeccak _{i + 1} \\ + + & \isShakiraShaTwoData _{i} & \!\!\!\cdot\!\!\! & \locShakiraIsShaTwo _{i + 1} \\ + + & \isShakiraRipemdData _{i} & \!\!\!\cdot\!\!\! & \locShakiraIsRipemd _{i + 1} \vspace{2mm} \\ + % + + & \isShakiraKeccakResult _{i} & \!\!\!\cdot\!\!\! & \isShakiraKeccakResult _{i + 1} \\ + + & \isShakiraShaTwoResult _{i} & \!\!\!\cdot\!\!\! & \isShakiraShaTwoResult _{i + 1} \\ + + & \isShakiraRipemdResult _{i} & \!\!\!\cdot\!\!\! & \isShakiraRipemdResult _{i + 1} \vspace{2mm} \\ + % + + & \locIsResult _{i} & \!\!\!\cdot\!\!\! & \locIsData _{i + 1} \\ + \end{array} \right] \\ + \end{array} \right. +\] diff --git a/prc/shakira/stamp.tex b/prc/shakira/stamp.tex new file mode 100644 index 0000000..e69de29 diff --git a/prc/shakira/total_size.tex b/prc/shakira/total_size.tex new file mode 100644 index 0000000..4d444f2 --- /dev/null +++ b/prc/shakira/total_size.tex @@ -0,0 +1,5 @@ +We impose the following constraints for \shakiraTotalSize{}: +\begin{enumerate} + \item \If $\locIsResult _{i} = 1$ \Then $\shakiraTotalSize_{i} = \evmWordSize$ +\end{enumerate} +In the $\locIsData$ case the \shakiraTotalSize{} is imposed in the \mmioMod{} module. diff --git a/pub/_data.tex b/pub/_data.tex new file mode 100644 index 0000000..7292e1b --- /dev/null +++ b/pub/_data.tex @@ -0,0 +1,29 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/stack} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/thm_env} + +\title{Data module} +\author{Rollup team} +\date{August 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\section{Columns} + \input{columns} + +\section{Constraints} + \input{constraints} + +\end{document} \ No newline at end of file diff --git a/pub/_info.pdf b/pub/_info.pdf new file mode 100644 index 0000000..bd8ba85 Binary files /dev/null and b/pub/_info.pdf differ diff --git a/pub/_info.tex b/pub/_info.tex new file mode 100644 index 0000000..af28f77 --- /dev/null +++ b/pub/_info.tex @@ -0,0 +1,38 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/stack} +\usepackage{../pkg/public} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/thm_env} + +\title{Info module} +\author{Rollup team} +\date{August 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\section{Purpose} + \input{./info/purpose} + +\subsection{Public data} + \input{../ram/public_data} +\subsection{Exogenous data shape} + \input{../ram/exo_data_shape} + +\section{Columns} + \input{./info/columns} + +\section{Constraints} + \input{./info/constraints} + +\end{document} \ No newline at end of file diff --git a/pub/_info.xdv b/pub/_info.xdv new file mode 100644 index 0000000..706005c Binary files /dev/null and b/pub/_info.xdv differ diff --git a/pub/block/commitment.tex b/pub/block/commitment.tex new file mode 100644 index 0000000..e7ea0bf --- /dev/null +++ b/pub/block/commitment.tex @@ -0,0 +1,18 @@ +There is a commitment to the following data +\begin{enumerate} + \item \col{TX\_NUM} + \item \col{FROM} + \item \col{TO} + \item \col{VALUE} + \item \col{GAS} + \item \col{GAS\_PRICE} + \item \col{TRANSACTION\_CALLDATASIZE} + \item \col{INITIALIZATION\_CODESIZE} +\end{enumerate} +It is padded with zeros to a power of 2. The constraints are that when \col{TX\_NUM} is nonzero then +\begin{enumerate} + \item it grows by 1 with every row + \item the product of the two columns \col{TRANSACTION\_CALLDATASIZE} and \col{INITIALIZATION\_CODESIZE} is zero + \item if \col{TO} is 0 then the \col{TRANSACTION\_CALLDATASIZE} is zero +\end{enumerate} +The idea is the following: when \col{TX\_NUM} changes in the MET we have a special binary flag that lights up for 16 rows. This flag indicates transaction initialization. It also won't be part of the plookup into ROM. It's about computing the cost of entering the transaction given call data / init code etc. \ No newline at end of file diff --git a/pub/data/_all.tex b/pub/data/_all.tex new file mode 100644 index 0000000..203653a --- /dev/null +++ b/pub/data/_all.tex @@ -0,0 +1,30 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../../pkg/common} +% \usepackage{../../pkg/dark_theme} +\usepackage{../../pkg/std} +\usepackage{../../pkg/IEEEtrantools} +\usepackage{../../pkg/rom} +\usepackage{../../pkg/ram} +\usepackage{../../pkg/comparisons} +\usepackage{../../pkg/call_stack} +\usepackage{../../pkg/stack} +\usepackage{../../pkg/public} +\usepackage{../../pkg/offset_processor} +\usepackage{../../pkg/env} + +\title{Info module} +\author{Rollup team} +\date{August 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\section{Purpose} \input{purpose} +\section{Columns} \input{columns} +\section{Heartbeat} \input{heartbeat} +\section{Constraints} \input{constraints} + +\end{document} diff --git a/pub/data/_all.xdv b/pub/data/_all.xdv new file mode 100644 index 0000000..77b42d2 Binary files /dev/null and b/pub/data/_all.xdv differ diff --git a/pub/data/columns.tex b/pub/data/columns.tex new file mode 100644 index 0000000..a4a43bf --- /dev/null +++ b/pub/data/columns.tex @@ -0,0 +1,13 @@ +\begin{enumerate} + \item $\txNum$: transaction number; + \item $\txCdSize$: transaction call data size (in bytes); + \item $\txcdGasCost$: total gas cost of transaction call data; + \item $\RUNTOT:$ running gas total; abbreviated to $\runTot$ + \item $\GASTOT:$ total gas cost of transaction call data; abbreviated to $\gasTot$ +\end{enumerate} +The columns that follow are, along with $\txNum$, ``heartbeat''-columns. +\begin{enumerate}[resume] + \item $\LIMBINDEX$: counter that increases by 1 with every 16 bytes of transaction call data; abbreviated to $\limbIndex$; + \item $\ISB$: binary column; is on for all bytes that are part of transaction call data; abbreviated to $\isb$; + \item $\BYTEINDEX$: counter that increases by 1 with every transaction call data byte ; abbreviated to $\byteIndex$; +\end{enumerate} diff --git a/pub/data/constraints.tex b/pub/data/constraints.tex new file mode 100644 index 0000000..e69de29 diff --git a/pub/data/heartbeat.tex b/pub/data/heartbeat.tex new file mode 100644 index 0000000..c94b759 --- /dev/null +++ b/pub/data/heartbeat.tex @@ -0,0 +1,60 @@ +I'm a bit at a crossroads with transaction call data (txcd) and init code i.e. the data provided in a transaction. In some sense txcd and init code should live in the same public data module: + +\begin{enumerate} +\item both need to be billed (4 gas per 0x00, 16 gas for nonzero bytes) +\item both need to be laid out byte by byte: +\begin{enumerate} + \item for txcd: + \begin{enumerate} + \item for byte billing + \item to build data limbs for ram instructions touching txcd + \end{enumerate} + \item for init code: + \begin{enumerate} + \item for byte billing + \item to build limbs for the CODECOPY instruction + \end{enumerate} +\end{enumerate} +\item both are indexed by txNum +\end{enumerate} + +On the other hand we do much more with init code than with txcd. With init code we further need to + +\begin{enumerate} + \item perform jump destination analysis and replace PUSH-shadowed bytes by INVALID instructions + \item build push values +\end{enumerate} + +Something I just realized is that outside observers know the sender address and the sender nonce, it is part of the transaction data ($T_\text{n}$). Of course a connection to a permanent state must prove its validity but it's there. So we can know deployment address (which are then verified in the proof.) We can do a 2 sided plookup inclusion proof of the init code commitment into ROM. We could have both live in the same place or in different commitments + +There is a further difference: the nonce update of an deployment transaction is definitive. There are no rollbacks that can take it back. So the deployment number stuff should be $=0$ or $=1$. + +We can do all of this stuff in a single module. There is no issue wrt to loading code: there can only be two code fragments for such an address: init code and deployed code, there are no revert + \inst{CREATE} in this context. + +The thing is that in order to connect the txcd/initcode module to ROM I require the address. And this is something we know how to produce --- the nonce is part of the block data. + +Ok in essence: +\begin{enumerate} + \item txcd is tied to a txNum + \item init code is tied to + \begin{enumerate} + \item the from address + \item its nonce delta + \item (implicitly to a txNum) + \end{enumerate} + \item ROM is indexed by address, deployment number and the \col{isInitCode} bit + \item we can + \begin{enumerate} + \item do the byte billing in the call data module + \item import the stream of + \[ + \col{isInitCode} + \cdot + (\addr, \col{isInitCode}, \col{byteCounter}, \col{bytes}, \col{txcdSize}) + \] + into the ROM where they would be sent to the tuple + \[ + (\addr, \col{isInitCode}, \col{bytecounter}, \col{rawBytes}, \codeSize) + \] + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/pub/data/purpose.tex b/pub/data/purpose.tex new file mode 100644 index 0000000..86961da --- /dev/null +++ b/pub/data/purpose.tex @@ -0,0 +1,6 @@ +The purpose of the current module is twofold: +\begin{enumerate} + \item justify the gas cost of transaction call data; + \item package individual bytes of transaction call data into limbs for \inst{CALLDATA}-accessing operations to access. +\end{enumerate} +Recall that every byte of transaction call data is billed: a zero byte \texttt{0x00} costs $\gz := G_{\text{txdatazero}} = 4$ gas and every nonzero byte cost $\gnz := G_{\text{txdatanonzero}} = 16$ gas. The present module keeps a $\RUNTOT$ which it compares to the $\GASTOT$. \ No newline at end of file diff --git a/pub/info/columns.tex b/pub/info/columns.tex new file mode 100644 index 0000000..8aeb522 --- /dev/null +++ b/pub/info/columns.tex @@ -0,0 +1,13 @@ +\begin{enumerate} + \item $\EXOSTAMP{}$: stamp column of the public data info module; starts at zero, may stay there for a few rows; as soon as nonzero it increments by one with every row; abbreviated to $\exoStamp{}$; + \item $\shaNum$: counts the number of \inst{SHA3} instructions that took place in a batch; + \item $\logNum$: counts the number of \inst{LOG0}-\inst{LOG4} instructions that took place in a batch; + \item $\txNum$: counts the number of transactions that are in a batch; + \item $\iNum$: imported column; depending on the instruction, contains either $\shaNum$, $\logNum$ or $\txNum$; + \item $\iAddr$ + \item $\iXSHA$: imported binary flag that lights up for \inst{SHA3} instructions; abbreviated to $\ixSha$; + \item $\iXLOG$: imported binary flag that lights up for \inst{LOG0}-\inst{LOG4} instructions; abbreviated to $\decxLog$; + \item $\iXROM$: imported binary flag that lights up for temporarily successful deployments; abbreviated to $\ixRom$; + % \item $\iXTXCD$: imported binary flag that lights up with every new transaction; abbreviated to $\ixTxcd$; +\end{enumerate} + diff --git a/pub/info/constraints.tex b/pub/info/constraints.tex new file mode 100644 index 0000000..50d0bf2 --- /dev/null +++ b/pub/info/constraints.tex @@ -0,0 +1,25 @@ +\begin{enumerate} + \item $\exoStamp_0 = 0$ + \item \If $\exoStamp_{i} = 0$ \Then the entire row is zero + \item \If $\exoStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item $\exoStamp_{i} = 1 + \exoStamp_{i - 1}$ + \item $\iXLOG{}_{i} + \iXSHA{}_{i} + \iXROM{}_{i} = 1$; + + in other words, precisely one of the flags is on; note that $\iXLOG{}$, $\iXSHA{}$ and $\iXROM{}$ are imports of binary flags; + \item $\logNum_{i} = \logNum_{i - 1} + \iXLOG_{i}$ + \item $\shaNum_{i} = \shaNum_{i - 1} + \iXSHA_{i}$ + \item $\depNum_{i} = \depNum_{i - 1} + \iXTXCD_{i}$ + \item the constraint below enforces that $\iNum_{i}$ (which is imported from the stack) contains the correct number: log number, sha number or deployment number. + \[ + \begin{array}{rcl} + \iNum_{i} + & = & + \iXLOG{}_{i} \cdot \logNum_{i} \\ + &&\quad + \iXSHA{}_{i} \cdot \shaNum_{i} \\ + &&\quad\quad + \iXROM{}_{i} \cdot \initNum_{i} \\ + &&\quad\quad\quad + \iXDEP{}_{i} \cdot \txNum_{i} \\ + \end{array} + \] + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/pub/info/purpose.tex b/pub/info/purpose.tex new file mode 100644 index 0000000..df579b6 --- /dev/null +++ b/pub/info/purpose.tex @@ -0,0 +1,13 @@ +The purpose of this small submodule is to record information and data (in separate modules) relative to +\begin{enumerate} + \item logging operations, + \item hashing operations, + \item and \inst{CREATE} / \inst{CREATE2} triggered deployments. +\end{enumerate} +The information part allows us to uniquely tag individual operations of that kind and extract metadata relevant to this operation. For instance: +\begin{description} + \item[For \inst{LOG0}-\inst{LOG4}:] the transaction number, the logger address, the log parameter ($\in\{0,1,2,3,4\}$), the size of the data to log, four topics (set to 0 for when there are fewer than 4 topics), the log number. + \item[For \inst{SHA3}:] the size of the data to hash, the result of the hash, the hash number. + \item[For \inst{CREATE}/\inst{CREATE2}:] a bit which distinguishes between \inst{CREATE} and \inst{CREATE2} instructions, the address which runs the deployment, its nonce delta, the salt, the size of the initialization code, the resulting deployment address, the deployment number. +\end{description} +The Data part allows us to extract relevant data and submit it to the outside proving scheme. \ No newline at end of file diff --git a/pub/keccak/_all.tex b/pub/keccak/_all.tex new file mode 100644 index 0000000..613958a --- /dev/null +++ b/pub/keccak/_all.tex @@ -0,0 +1,33 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../../pkg/common} +\usepackage{../../pkg/std} +\usepackage{../../pkg/IEEEtrantools} +\usepackage{../../pkg/rom} +\usepackage{../../pkg/ram} +\usepackage{../../pkg/comparisons} +\usepackage{../../pkg/call_stack} +\usepackage{../../pkg/stack} +\usepackage{../../pkg/public} +\usepackage{../../pkg/offset_processor} +\usepackage{../../pkg/env} + +\title{Info module} +\author{Rollup team} +\date{August 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\section{Purpose} + \input{purpose} + +\section{Columns} + \input{columns} + +\section{Constraints} + \input{constraints} + +\end{document} \ No newline at end of file diff --git a/pub/keccak/_all.xdv b/pub/keccak/_all.xdv new file mode 100644 index 0000000..f257151 Binary files /dev/null and b/pub/keccak/_all.xdv differ diff --git a/pub/keccak/columns.tex b/pub/keccak/columns.tex new file mode 100644 index 0000000..e69de29 diff --git a/pub/keccak/constraints.tex b/pub/keccak/constraints.tex new file mode 100644 index 0000000..e69de29 diff --git a/pub/keccak/purpose.tex b/pub/keccak/purpose.tex new file mode 100644 index 0000000..58e56bd --- /dev/null +++ b/pub/keccak/purpose.tex @@ -0,0 +1 @@ +The Keccak-256 module is comprised of two independent modules which we call the \textbf{Keccak Info Module} and the \textbf{Keccak Data Module} respectively. The purpose is simple: the Keccak info module is connected to the main execution trace. The connection flares up whenever a (paid for) instruction requires one to compute the \texttt{Keccak-256} hash of a slice of bytes, i.e. for the \inst{SHA3} and \inst{CREATE2} instructions. Every such event triggers \ No newline at end of file diff --git a/rlp_addr/_all_rlp_addr.tex b/rlp_addr/_all_rlp_addr.tex new file mode 100644 index 0000000..bdde31b --- /dev/null +++ b/rlp_addr/_all_rlp_addr.tex @@ -0,0 +1,44 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/rlp_patterns} + +\title{Address RLP module} +\author{Rollup team} +\date{May 2023} + +\begin{document} + +\maketitle +\tableofcontents +\input{_inputs} + +\end{document} diff --git a/rlp_addr/_inputs.tex b/rlp_addr/_inputs.tex new file mode 100644 index 0000000..5cf9925 --- /dev/null +++ b/rlp_addr/_inputs.tex @@ -0,0 +1,22 @@ +\def\zero{\graym{0}} +\def\one {\redm{1}} +\def\locRlpNonceSize{\col{rlp\_nonce\_size}} + +\section{Introduction} \input{intro} \label{rlp_addr: intro} + +\section{Column descriptions} \input{columns} \label{rlp_addr: columns} + +\section{General constraints} +\subsection{Heartbeat} \input{heartbeat} \label{rlp_addr: heartbeat} +\subsection{Constancies} \input{constancies} \label{rlp_addr: constancies} +\subsection{Binary constraints} \input{binary} \label{rlp_addr: binary} +\subsection{Byte and bit decomposition constraints} \input{byteDec} \label{rlp_addr: byteDec} +\subsection{\rlpAddrInst{} and \recipe{k} constraints} \input{recipes} \label{rlp_addr: recipes} +\subsection{\selectorKeccakRes{} constraints} \input{keccak_result} \label{rlp_addr: result_selector} + +\section{Building the bytestring} +\subsection{The \recipe{1} case} \input{recipe_1} \label{rlp_addr: recipe_1} +\subsection{The \recipe{2} case} \input{recipe_2} \label{rlp_addr: recipe_2} + +\section{Lookups} +\subsection{Into \trmMod{} module} \input{lookups/rlp_addr_into_trm} \label{rlp_addr: lookups: into_trm} \ No newline at end of file diff --git a/rlp_addr/binary.tex b/rlp_addr/binary.tex new file mode 100644 index 0000000..b358d74 --- /dev/null +++ b/rlp_addr/binary.tex @@ -0,0 +1,11 @@ +We impose binary constraints on the following columns: +\begin{multicols}{3} + \begin{enumerate} + \item \recipe{1} + \item \recipe{2} + \item \genBit{} + \item \tinyNonzeroNonce{} + \item \lc{} + \item \selectorKeccakRes{} (\quad \trash) + \end{enumerate} +\end{multicols} diff --git a/rlp_addr/byteDec.tex b/rlp_addr/byteDec.tex new file mode 100644 index 0000000..a568643 --- /dev/null +++ b/rlp_addr/byteDec.tex @@ -0,0 +1,12 @@ +We impose the following byte constraints on the byte decomposition columns: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\genByteAcc_{i} = \genByte_{i}$ + \item \If $\ct_{i} \neq 0$ \Then $\genByteAcc_{i} = 256 \cdot \genByteAcc_{i - 1} + \genByte_{i}$ +\end{enumerate} +We further impose bytehood constraints on $\genByte$. + +We similarly impose bit decomposition constraints on the bit decomposition columns: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\genBitAcc_{i} = \genBit_{i}$ + \item \If $\ct_{i} \neq 0$ \Then $\genBitAcc_{i} = 2 \cdot \genBitAcc_{i - 1} + \genBit_{i}$ +\end{enumerate} diff --git a/rlp_addr/columns.tex b/rlp_addr/columns.tex new file mode 100644 index 0000000..51ba964 --- /dev/null +++ b/rlp_addr/columns.tex @@ -0,0 +1,73 @@ +The RLP module makes use of the following columns: +\begin{enumerate} + \item $\rlpAddrStamp$: uniquely identifies the current encoding operation and is incremented after each one; + \item $\rlpAddrInst$: + \godGiven{} + \ccc{}; defines which recipe to apply; + \item $\recipe{1}$ and $\recipe{2}$ + \ccbc{}'s; light up for the respective recipes; + \item \ct: counter column; +% \item \done: a bit column which lights up at the end of every \ct-cycle; +\end{enumerate} +The interpretation of the \recipe{k} columns is that +$\recipe{1} \equiv 1$ for deployment transactions and deployments triggered by the \inst{CREATE} opcode, while +$\recipe{2} \equiv 1$ for deployments triggered by the \inst{CREATE2} opcode. +The counter cycle length depends on which recipe is being executed. + +The following colums are useful when $\recipe{1} \equiv 1$: +\begin{enumerate}[resume] + \item \genByte{} and \genByteAcc: + bytes column and associated accumulator; together they provide the byte decomposition of the nonce; + \item \accsize: + computes the size in bytes of the nonce; + \item $\col{POWER}$: + ``powers of $256$ column''; + used to perform appropriate byte shifts when constituting the desired byte string; + \item $\genBit$ and $\genBitAcc$: + binary column and its associated accumulator; used to provide binary decompositions; + \item $\TINYNONZERONONCE$: + \ccbc{} + equals $1$ if $0 < \nonce < \rlprefixShortInt$, otherwise it equals $0$; abbreviated to \tinyNonzeroNonce{}; +\end{enumerate} +The following columns are input columns to the module and arrive to it from either the \txnDataMod{} or from the \hubMod{}: +\begin{enumerate}[resume] + \item $\addr\high$ and $\addr\low$: + \godGiven{} + \ccc{} containing the high and low parts of the \creator{} address; + \item $\depAddr\high$ and $\depAddr\low$: + \godGiven{} + \ccc{} containing the high and low parts of the \createe{} address; + \item $\rawAddrHi$: + \godGiven{} + contains the high part of the \texttt{KECCAK} hash of the $\texttt{bs}$ defined in the intrduction, to be interpreted as the high part of an address after trimming; +\end{enumerate} +The nonce is used in the first recipe which applies to deployment transactions and to deployments triggered by the \inst{CREATE} opcode: +\begin{enumerate}[resume] + \item $\nonce$: + \godGiven{} + the nonce of the \creator's account (an $8$ byte integer); +\end{enumerate} +The following columns are used in contract deployments triggered by the \inst{CREATE2} opcode: +\begin{enumerate}[resume] + \item $\col{SALT} \high$ and $\col{SALT} \low$: + \godGiven{} + the high and low parts of the ``salt'' $\zeta$; + \item $\col{KEC} \high$ and $\col{KEC} \low$: + \godGiven{} + the high and low parts of $\texttt{KEC}(\textbf{i})$ where \textbf{i} is the initialization code used during deployment; +\end{enumerate} +The columns below provide the output of the present module +\begin{enumerate}[resume] + \item \limb{}: + a column containing the output byte string, split in left-aligned, zero-padded 16-bytes limb, starting from the last line of each encoding operation; + \item \lc{}: + binary column, is one when the \limb{} is usefull for the extraction to create the byte string to hash; + short hand for \col{LIMB\_CONSTRUCTED}; + \item \limbsize{}: + the total number of bytes to read from \limb{}; + \item \index{}: + gives the index of the current limb to reconstruct the data to hash (starts at 0); + \item \selectorKeccakRes{}: + bit column, lights up exactly once for each operation; +\end{enumerate} + diff --git a/rlp_addr/constancies.tex b/rlp_addr/constancies.tex new file mode 100644 index 0000000..09f1f95 --- /dev/null +++ b/rlp_addr/constancies.tex @@ -0,0 +1,48 @@ +As is customary, we declare a column $\col{X}$ to be \textbf{counter-constant} if it satisfies the following: +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i-1} = \col{X}_{i}. +\] + +\begin{enumerate} + \item We impose that the following columns be counter-constant: + \begin{multicols}{3} + \begin{enumerate} + \item $\addr\high$ + \item $\addr\low $ + \item $\depAddr\high$ + \item $\depAddr\low $ + \item $\rawAddrHi$ + \item $\salt \high$ + \item $\salt \low $ + \item $\kec \high$ + \item $\kec \low $ + \item $\nonce$ + \item $\rlpAddrInst$ + \item $\recipe{1}$ (\trash) + \item $\recipe{2}$ (\trash) + \item $\tinyNonzeroNonce$ + \item[\vspace{\fill}] + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{enumerate} +A column $\col{X}$ is \textbf{counter-incrementing} if it satisfies the following: +\[ + \If \ct_{i} \ne 0~ \Then \col{X}_{i} \in \{\col{X}_{i-1}; \col{X}_{i-1} +1 \}. +\] +We ask that the following columns be counter-incrementing: +\begin{multicols}{2} + \begin{enumerate} + \item $\index$ + \item $\lc$ + \end{enumerate} +\end{multicols} +\saNote{} If $\col{X}$ is a counter-incrementing \textbf{binary} column then within a counter-cycle the values of $\col{X}$ satisfy one of the following patterns: +\begin{itemize} + \item \col{X} is constant equal to $0$ along the entire counter-cycle; + \item \col{X} starts at $0$ and jumps to $1$ at some point, remaining there until the end of the counter-cycle; + \item \col{X} is constant equal to $1$ along the entire counter-cycle. +\end{itemize} diff --git a/rlp_addr/heartbeat.tex b/rlp_addr/heartbeat.tex new file mode 100644 index 0000000..7be5cd0 --- /dev/null +++ b/rlp_addr/heartbeat.tex @@ -0,0 +1,43 @@ +The heartbeat of the rlp module is very simple: +\begin{enumerate} + \item $\rlpAddrStamp_{0} = 0$; + \item \If $\recipe{1}_{i} + \recipe{2}_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \ct_{i} & = & 0 \quad (\trash) \\ + \addr\high_{i} & = & 0 \\ + \addr\low _{i} & = & 0 \\ + \rawAddrHi _{i} & = & 0 \\ + \depAddr\high_{i} & = & 0 \\ + \depAddr\low _{i} & = & 0 \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcl} + \salt\high_{i} & = & 0 \quad (\trash) \\ + \salt\low _{i} & = & 0 \quad (\trash) \\ + \nonce_{i} & = & 0 \quad (\trash) \\ + \genByte_{i} & = & 0 \quad (\trash) \\ + \genBit_{i} & = & 0 \quad (\trash) \\ + \end{array} \right. + \] + \item $\rlpAddrStamp_{i + 1} \in \{ \rlpAddrStamp_{i}, 1 + \rlpAddrStamp_{i} \}$; + \item \If $\rlpAddrStamp_{i} \neq \rlpAddrStamp_{i - 1}$ \Then $\ct_{i} = 0$; +\end{enumerate} +We now lay out the \textbf{counter-cycle} length depending on the ``recipe'': +\begin{enumerate}[resume] + \item \If $\recipe{1}_{i} = 1$ + \begin{enumerate} + \item \If $\ct_{i} \neq \mediumPO$ \Then $\ct_{i + 1} = 1 + \ct_{i}$; + \item \If $\ct_{i} = \mediumPO$ \Then $\rlpAddrStamp_{i + 1} = 1 + \rlpAddrStamp_{i}$; + \end{enumerate} + \item \If $\recipe{2}_{i} = 1$ + \begin{enumerate} + \item \If $\ct_{i} \neq \mediumMO$ \Then $\ct_{i + 1} = 1 + \ct_{i}$; + \item \If $\ct_{i} = \mediumMO$ \Then $\rlpAddrStamp_{i + 1} = 1 + \rlpAddrStamp_{i}$; + \end{enumerate} +\end{enumerate} +What follows are finalization constraints which ensure that the last counter-cycle doesn't end ``midway'': +\begin{enumerate}[resume] + \item \If $\recipe{1}_{N} = 1$ \Then $\ct_{N} = \mediumPO$ + \item \If $\recipe{2}_{N} = 1$ \Then $\ct_{N} = \mediumMO$ +\end{enumerate} diff --git a/rlp_addr/intro.tex b/rlp_addr/intro.tex new file mode 100644 index 0000000..3846115 --- /dev/null +++ b/rlp_addr/intro.tex @@ -0,0 +1,17 @@ +The \rlpAddrMod{} module does preliminary work required to compute addresses of accounts created through deployment transactions, \inst{CREATE} or \inst{CREATE2} instructions. This work consists in defining a byte string $\texttt{bs}$, the \texttt{KECCAK} hash of which (trimmed of its leading 12 bytes, trimming being delegated to the \trmMod{} module) defines the deployment address. + +There are two recipes for creating said byte string \texttt{bs}. The \textbf{first recipe} applies for deployment transactions and for accounts spawned through \inst{CREATE} instructions. The string is defined as +\[ + \texttt{bs} = \textsc{rlp}\big((s,n)\big) +\] +i.e. the \textsc{rlp} encoding of a pair $(s, n)$ where $s \in \mathbb{B}_{20}$ and $n \in \mathbb{N}_{256}$\footnote{In reality: $n \in \mathbb{N}_{64}$}. In applications $s$ is the address of the deployer account and $n$ is the nonce of said address \emph{prior} to its incrementation as part of deployment. + +The \textbf{second recipe} for defining this byte string defines it as a the concatenation of the following: a single byte \texttt{0xff}, an address $s\in\mathbb{B}_{20}$, a parameter $\zeta \in \mathbb{B}_{32}$ and a hash $h \in\mathbb{B}_{32}$: +\[ + \texttt{bs} = + \texttt{0xff} \cdot + s \cdot + \zeta \cdot + h +\] +In applications this method is used by the \inst{CREATE2} opcode: the address $s$ is that of the creator account, $\zeta$ (the ``salt'') is a stack argument and $h = \texttt{KECCAK}(\textbf{i})$ is the hash of the initalization code $\textbf{i}$. diff --git a/rlp_addr/keccak_result.tex b/rlp_addr/keccak_result.tex new file mode 100644 index 0000000..7201df2 --- /dev/null +++ b/rlp_addr/keccak_result.tex @@ -0,0 +1,6 @@ +The \selectorKeccakRes{} is a bit column that lights up at the first row of each operation. +It plays no rôle in the aritmetization \emph{per se} but will prove useful to the prover. +\begin{enumerate} + \item \If $\rlpAddrStamp_{i} = 0$ \Then $\selectorKeccakRes_{i} = 0$ + \item \If $\rlpAddrStamp_{i} \neq 0$ \Then $\selectorKeccakRes_{i} = \rlpAddrStamp_{i} - \rlpAddrStamp_{i-1}$ +\end{enumerate} diff --git a/rlp_addr/lookups/rlp_addr_into_trm.tex b/rlp_addr/lookups/rlp_addr_into_trm.tex new file mode 100644 index 0000000..36229f5 --- /dev/null +++ b/rlp_addr/lookups/rlp_addr_into_trm.tex @@ -0,0 +1,16 @@ +The lookup to the $\trmMod$ module is constructed as follows: +\begin{description} + \item[\underline{Selector:}] none required; + \item[\underline{Source columns:}] from the \rlpAddrMod{} module: + \begin{enumerate} + \item $\rawAddrHi_{i}$ + \item $\depAddr\high_{i}$ + \item $\depAddr\low_{i}$ + \end{enumerate} + \item[\underline{Target columns:}] from the \trmMod{} module: + \begin{enumerate} + \item $\rawAddrHi_{j}$ + \item $\trmAddrHi_{j}$ + \item $\rawAddrLo_{j}$ + \end{enumerate} +\end{description} diff --git a/rlp_addr/recipe_1.tex b/rlp_addr/recipe_1.tex new file mode 100644 index 0000000..fe88b04 --- /dev/null +++ b/rlp_addr/recipe_1.tex @@ -0,0 +1,138 @@ +\begin{center} + \boxed{\text{In all this section, it is assumed that $\recipe{1}_{i} = 1$.}} +\end{center} + +We remind the reader that +\genByte{} and \genByteAcc{} satisfy byte decomposition constraints while +\genBit{} and \genBitAcc{} satisfy bit decomposition constraints. + +The first batch of constraints concerns the first row of the counter-cycle: +\begin{enumerate} + \item \If $\ct_{i}=0$ \Then + \begin{enumerate} + \item We initialize the (counter-incrementing) \index{} column: \( \index_{i} = 0 \); + \item \If $\genByteAcc_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accsize_{i} & = & 0 \\ + \col{POWER}_{i} & = & 256^{8} \\ + \end{array} \right. + \] + \item \If $\genByteAcc_{i} \ne 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accsize_{i} & = & 1 \\ + \col{POWER}_{i} & = & 256^{7} \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} +We next tackle intermediate rows (including the final row) of the counter-cycle: +\begin{enumerate}[resume] + \item \If $\ct_{i} \ne 0$ \Then + \begin{enumerate} + \item \If $\genByteAcc_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accsize_{i} & = & \accsize_{i - 1} \\ + \col{POWER}_{i} & = & 256 \cdot \col{POWER}_{i - 1} \\ + \end{array} \right. + \] + \item \If $\genByteAcc_{i} \ne 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \accsize_{i} & = & 1 + \accsize_{i - 1} \\ + \col{POWER}_{i} & = & \col{POWER}_{i - 1} \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} +The final batch of constraints pertain the the construction of the limbs which carry the \rlp{} prefixes and underlying data. The table below describes the size in bytes of the \rlp{}-ization of the nonce, an integer in the range $[\![\,0, 256^\redm{8} \,[\![$. +We will use the following shorthand (only on the final row of the counter-cycle, i.e. the row with $\ct_{i} = \mediumPO$) +\[ + \locRlpNonceSize = \accsize_{i} + (1 - \tinyNonzeroNonce_{i}) +\] +which gives the bytesize of RLP(nonce) for the three different cases. +\begin{table}[h] \label{fig: rlp of nonce cases} + \centering + \renewcommand{\arraystretch}{1.3} + \begin{tabular}{|c|c|c|c|} + \hline + \nonce & \accsize & \tinyNonzeroNonce & \locRlpNonceSize \\ \hline + 0 & 0 & $\zero$ & 1 \\ \hline + $0 < \col{nonce} < 128$ & 1 & $\one $ & 1 \\ \hline + $128 \leq \col{nonce} < 256^\redm{8}$ & \col{acc\_size} & $\zero$ & \col{acc\_size} + 1 \\ \hline + \end{tabular} +\end{table} + +\begin{enumerate}[resume] + \item \If $\ct_{i}=\mediumPO$ \Then: + \begin{description} + \item[Target constraints:] we impose + \[ + \left\{ \begin{array}{lcl} + \genByteAcc_{i} & = & \nonce_{i} \\ + \genBitAcc_{i} & = & \genByte_{i} \\ + \end{array} \right. + \] + \item[Setting \TINYNONZERONONCE:] + \If ($\accsize_{i}=1$ \et $\genBit_{i-\mediumPO}=0$) \Then $\tinyNonzeroNonce_{i}=1$ \Else $\tinyNonzeroNonce_{i}=0$ + \item[The last few rows contain data limbs:] we set + \[ \lc_{i-4}+\lc_{i-3}=1 \] + In other words, by monotony, the final 4 rows have $\lc \equiv 1$; + \item[Setting the global \rlp{} prefix:] We impose + \[ + \begin{cases} + \limb_{i-3} = (\rlprefixShortList + (1 + 20) + \locRlpNonceSize ) \cdot 256^{\llargeMO} \\ + \limbsize_{i-3} = 1 \\ + \index_{i-3} = 0 \\ + \end{cases} + \] + \saNote{} + The byte length of the concatenation $\rlp(s) \cdot \rlp(n)$ of the \rlp{}-izations of an address ($s$) and a nonce ($n$) is $(1 + 20) + \locRlpNonceSize$ + \item[\rlp{} prefix of the address and its first 4 bytes:] + \[ + \begin{cases} + \limb_{i-2} = (\rlprefixShortInt+20) \cdot 256^{\llargeMO} + \addr \high _{i} \cdot 256^{11} \\ + \limbsize_{i-2} = 5 \\ + \index_{i-2} = 1 (\trash) \\ + \end{cases} + \] + \item[The remaining $\llarge$ bytes of the address:] + \[ + \begin{cases} + \limb_{i-1} = \addr \low _{i} \\ + \limbsize_{i-1} = \llarge \\ + \index_{i-1} = 2 (\trash) \\ + \end{cases} + \] + \item[\rlp{} of the nonce:] we must distinguish between three cases for the \rlp{}-ization of the nonce, see figure~(\ref{fig: rlp of nonce cases}): + \[ + \begin{cases} + \limbsize_{i} = \locRlpNonceSize \\ + \index_{i} = 3 \\ + \end{cases} + \] + \saNote{} Given that $\index$ is counter-incrementing, was initialized at $0$ when $\ct_{j} = 0$, $j = i - \mediumPO$, set to $0$ at $i - 3$ and to $3$ at the current $i$, this implies that it takes on the values from 0 to 3 on the last 4 rows of the counter-cycle. + \item \If $\nonce_{i}=0$ \Then $\limb_{i}= \rlprefixShortInt \cdot 256^{\llargeMO}$ + \item \If $\nonce_{i} \ne 0$ \Then: + \begin{enumerate} + \item \If $\TINYNONZERONONCE_{i} = 1$ \Then $\limb_{i}= \nonce_{i} \cdot 256^{\llargeMO}$ + \item \If $\TINYNONZERONONCE_{i} = 0$ \Then $\limb_{i}= (\rlprefixShortInt + \accsize_{i}) \cdot 256^{\llargeMO} + \nonce_{i} \cdot \col{POWER}_{i}$ + \end{enumerate} + \end{description} +\end{enumerate} + +The following table summarizes the value of the outputs for the last rows: +\begin{figure}[h] + \centering + \begin{tabular}{|c|c|c|c|} + \hline + \ct & \limb & \limbsize & \index \\ \hline + 4 & \rlp{} Prefix & 1 & 0 \\ \hline + 5 & \rlp{} prefix of an address concatenated with $\addr \high$ & 5 & 1 \\ \hline + 6 & $\addr \low$ & $\llarge$ & 2 \\ \hline + 7 & \rlp{}(\col{nonce}) & \locRlpNonceSize & 3 \\ \hline + \end{tabular} + \caption{The above summarizes the final 4 rows wherein the byte string is constructed according to the \textbf{first recipe}} +\end{figure} diff --git a/rlp_addr/recipe_2.tex b/rlp_addr/recipe_2.tex new file mode 100644 index 0000000..f9cca98 --- /dev/null +++ b/rlp_addr/recipe_2.tex @@ -0,0 +1,43 @@ +\begin{center} + \boxed{\text{In all this section, it is assumed that $\recipe{2}_{i} = 1$.}} +\end{center} + +The \textbf{second recipe} requires no byte decompositions, byte counting or simila procedures. It furthermore produces a byte string of fixed length (85). The data is laid out according to the following schemata: +\begin{table}[h!] + \renewcommand{\arraystretch}{1.3} + \[ \begin{array}{|c|c|c|c|} + \hline + \ct & \limb & \limbsize & \index \\ \hline + 0 & \texttt{0xff}\text{ concatenated with }\addr \high & 5 & 0 \\ \hline + 1 & \addr \low & \llarge & 1 \\ \hline + 2 & \salt \high & \llarge & 2 \\ \hline + 3 & \salt \low & \llarge & 3 \\ \hline + 4 & \kec \high & \llarge & 4 \\ \hline + 5 & \kec \low & \llarge & 5 \\ \hline + \end{array} + \] +\end{table} + +The corresponding constraints are as follows: +\begin{enumerate} + \item $\index_{i}=\ct_{i}$ + \item \If $\ct_{i}=\mediumMO$ \Then: + \begin{enumerate} + \item $\lc_{i-5}=1$ + + \saNote{} This imposes that the counter-incrementing binary column \lc{} remains $\equiv 1$ throughout the current counter-cycle; + \item $\limb_{i-5} = \mathtt{0xff} \cdot 256^{\llargeMO} + \addr \high _{i} \cdot 256^{11}$ + \item $\limbsize_{i-5} = 5$ + \item $\limb_{i-4} = \addr \low _{i}$ + \item $\limbsize_{i-4}=\llarge$ + \item $\limb_{i-3} = \salt \high _{i}$ + \item $\limbsize_{i-3}=\llarge$ + \item $\limb_{i-2} = \salt \low _{i}$ + \item $\limbsize_{i-2}=\llarge$ + \item $\limb_{i-1} = \kec \high _{i}$ + \item $\limbsize_{i-1}=\llarge$ + \item $\limb_{i} = \kec \low _{i}$ + \item $\limbsize_{i}=\llarge$ + \end{enumerate} +\end{enumerate} + diff --git a/rlp_addr/recipes.tex b/rlp_addr/recipes.tex new file mode 100644 index 0000000..d6cf0cb --- /dev/null +++ b/rlp_addr/recipes.tex @@ -0,0 +1,20 @@ +We impose the following standard constraints on the \recipe{k}, $k = 1, 2$, colunms: +\begin{enumerate} + \item \If $\rlpAddrStamp_{i} = 0$ \Then $\recipe{1}_{i} + \recipe{2}_{i} = 0$ + \item \If $\rlpAddrStamp_{i} \neq 0$ \Then $\recipe{1}_{i} + \recipe{2}_{i} = 1$ + \item \label{rlpAddr: create computation constants} + We impose + \[ + \rlpAddrInst_{i} = + \addressCreationRecipeConstantStd \cdot \recipe{1}_{i} + + \addressCreationRecipeConstantTwo \cdot \recipe{2}_{i} + \] + for some (arbitrary, \textbf{distinct}) constants + \[ + \left\{ \begin{array}{lcl} + \addressCreationRecipeConstantStd = 1 \\ + \addressCreationRecipeConstantTwo = 2 \\ + \end{array} \right. + \] +\end{enumerate} +In other words, outside of padding rows precisely one of the \recipe{k} columns is active. diff --git a/rlp_patterns/_all_rlp_patterns.tex b/rlp_patterns/_all_rlp_patterns.tex new file mode 100644 index 0000000..f96270c --- /dev/null +++ b/rlp_patterns/_all_rlp_patterns.tex @@ -0,0 +1,46 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/alu} +\usepackage{../pkg/std} +\usepackage{../pkg/env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/stack} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_patterns} + +\title{\rlp{} patterns} +\author{Rollup team} +\date{July 2023} + +\begin{document} + +\maketitle +\tableofcontents +\input{_inputs} + +\end{document} diff --git a/rlp_patterns/_inputs.tex b/rlp_patterns/_inputs.tex new file mode 100644 index 0000000..b30752f --- /dev/null +++ b/rlp_patterns/_inputs.tex @@ -0,0 +1,8 @@ +\section{Introduction} + +\section{Constraint patterns} +\subsection{Comparison to 55} \input{fifty_five} +\subsection{Byte counting constraints} \input{byte_counting} +\subsection{RLP prefix constraints for a small (less than 16 bytes long) integer} \input{rlp_prefix_int} +\subsection{RLP prefix constraints for a bytestring} \input{rlp_prefix_bytestring} +\subsection{Limb Shifting} \input{limb_shifting} \ No newline at end of file diff --git a/rlp_patterns/byte_counting.tex b/rlp_patterns/byte_counting.tex new file mode 100644 index 0000000..b68d612 --- /dev/null +++ b/rlp_patterns/byte_counting.tex @@ -0,0 +1,65 @@ +The present describes a constraint system that +(\emph{a}) +extracts the number of significant bytes from a ``small'' input +(\emph{b}) +produces the appropriate power of $256$ which, when multiplied with the input, aligns its most significant byte on the $\llarge$-th byte\footnote{given that the input is nonzero}. +The input itself is not required here, rather this constraint system works with the input's byte decomposition. +There are two cases of interest: $\mmedium$-byte inputs and $\llarge$-byte inputs. We shall assume the following: we are provided with columns +\begin{itemize} + \item $\col{ct}$: a counter column; + \item $\col{nStep}$: a column that gives the \emph{expected} maximal byte size; \\ + \saNote{In our arithmetisation, there are only two cases of interest: either $\mmedium$ or $\llarge$.} + \item $\col{acc}$: an accumulator column that accumulates the bytes of an input; + \item $\col{byteSize}$: column counting the number of significant bytes of said input; + \item $\col{power}$: a ``power of 256'' column; +\end{itemize} +In applications the \col{acc} column will partake in a byte decomposition constraint system of an auxiliary colum pegged against the same \col{ct} counter column; the \col{ct} column will grow monotonically by 1 with every row until it resets after either $\mmedium$ rows or $\llarge$ rows. + +\noindent We subsume under the shorthand +\[ + \rlpByteCounting\left( + \col{ct}, + \col{nStep}, + \col{done}, + \col{acc}, + \col{byteSize}, + \col{power} + \right) +\] +the following collection of constraints: +\begin{enumerate} + \item \If $\col{ct}_{i}=0$ \Then: + \begin{enumerate} + \item \If $\col{acc}_{i}=0$ \Then + \begin{enumerate} + \item $\col{byteSize}_{i}=0$ + \item we impose the following: + \begin{enumerate} + \item \If $\col{nStep}_{i} = \mmedium$ \Then $\col{power}_{i}=256^{9}$ + \item \If $\col{nStep}_{i} = \llarge$ \Then $\col{power}_{i}=256^{1}$ + \end{enumerate} + \end{enumerate} + \item \If $\col{acc}_{i} \ne 0$ \Then + \begin{enumerate} + \item $\col{byteSize}_{i}=1$ + \item we impose the following: + \begin{enumerate} + \item \If $\col{nStep}_{i} = \mmedium$ \Then $\col{power}_{i}=256^{8}$ + \item \If $\col{nStep}_{i} = \llarge$ \Then $\col{power}_{i}=256^{0}$ + \end{enumerate} + \end{enumerate} + \end{enumerate} + \item \If $\col{ct}_{i} \ne 0$ \Then: + \begin{enumerate} + \item \If ($\col{acc}_{i}=0$ \et $\col{done}_{i}=0$) \Then + \begin{enumerate} + \item $\col{byteSize}_{i}=0$ + \item $\col{power}_{i}=256\cdot \col{power}_{i-1}$ + \end{enumerate} + \item \If ($\col{acc}_{i} \ne 0$ \Or $\col{done}_{i}=1$) \Then + \begin{enumerate} + \item $\col{byteSize}_{i}=\col{byteSize}_{i-1} + 1$ + \item $\col{power}_{i}=\col{power}_{i-1}$ + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/rlp_patterns/fifty_five.tex b/rlp_patterns/fifty_five.tex new file mode 100644 index 0000000..6d22ab0 --- /dev/null +++ b/rlp_patterns/fifty_five.tex @@ -0,0 +1,20 @@ +The present section details a simple ``comparison'' constraint which will be used to compare inputs representing the length of a byte string to $\fiftyFive$. We are given the following: +\begin{itemize} +\item \col{length}; +\item \col{comp} a binary column; +\item \col{acc}: an ``accumulator column''; +\end{itemize} +The interpretation will be as follows: +\col{length} will be the length we are interested in comparing to $\fiftyFive$; +\col{comp} will be the comparison bit ($=0$ \emph{iff} $\col{length} \leq \fiftyFive$) +\col{acc} will be a byte accumulation column (such constraints will be imposed elsewhere) such that on the row where the constraint below applies one is assured that its value is relatively small. + +\noindent We subsume under the shorthand +\[ + \compareFiftyFive_{i}(\col{length}, \col{comp}, \col{acc}) +\] +The following single constraint: +\[ + (2 \cdot \col{comp}_{i} - 1) \cdot (\col{length}_{i} - \fiftyFive) - \col{comp}_{i} = \col{acc}_{i} +\] +\saNote{} This equation enforces the desired interpretation for the comparison bit. diff --git a/rlp_patterns/limb_shifting.tex b/rlp_patterns/limb_shifting.tex new file mode 100644 index 0000000..2eab280 --- /dev/null +++ b/rlp_patterns/limb_shifting.tex @@ -0,0 +1,25 @@ +The present describes a contraint system that, giving +\emph{1} $\col{input}_{i}$ an integer +\emph{2} $\col{power}_{i}$ a power of 256, +\emph{3} $\col{input\_length}_{i}$ an integer (representing the number of bytes of $\col{input}_{i}$) writes +\emph{a} $\col{limb}_{i}$ +\emph{b} $\col{nBytes}_{i}$. + +\noindent We subsume under the shorthand +\[ + \limbShifting_{i} + \left( + \begin{array}{r} + \col{input}, + \col{power}, + \col{inputLength}; \\ + \col{limb}, + \col{nBytes}; \\ + \end{array} + \right) +\] +the following collection of constraints: +\begin{enumerate} + \item $\col{limb}_{i}=\col{input}_{i} \cdot \col{power}_{i}$ + \item $\col{nBytes}_{i} = \col{inputLength}_{i}$ +\end{enumerate} \ No newline at end of file diff --git a/rlp_patterns/rlp_prefix_bytestring.tex b/rlp_patterns/rlp_prefix_bytestring.tex new file mode 100644 index 0000000..f615b5e --- /dev/null +++ b/rlp_patterns/rlp_prefix_bytestring.tex @@ -0,0 +1,70 @@ +The present describes a contraint system that gives the RLP prefix of a bytestring. +We shall assume that \textbf{the underlying byte string contains at least two bytes} (i.e. it's not empty and not composed of a single byte.) The other cases (empty byte string or single byte) are handled differently. We shall assume that we are provided with columns +\begin{itemize} + \item $\col{length}$: integer containing the length of the bytestring; \emph{ought to be counter-constant}; + \item $\col{ct}$: a counter column; + \item $\col{nStep}$: a constant column giving the size of the ct-loop; + \item $\col{done}$: binary column that turns on a the end of every counter-cycle; + \item $\col{isList}$: a binary column; + \item $\col{byteSize}$: column counting the number of significant bytes of said input; + \item $\col{power}$: a ``power of 256'' column; + \item $\col{comp}$: a binary column used to compare the input with 55; + \item $\col{acc1}$: an accumulator column that accumulates the bytes of an input; + \item $\col{acc2}$: an accumulator column; + \item $\col{lc}$: binary column that turns on the row where $\col{limb}$ is constructed; + \item $\col{limb}$: column which will contain the prefix; + \item $\col{nBytes}$: number of meaningful bytes in the prefix itself; +\end{itemize} +In applications the interpretation will be as follows: +\col{acc1} will accumulate the bytes of an integer \col{length} representing the byte size of the underlying bytestring; +\col{isList} will distinguish between the two cases of interest: that of computing the \textsc{rlp} prefix of a simple byte string ($\in\mathbb{B}^*$) vs. of a list of items ($\in\mathbb{L} \setminus \mathbb{B}^*$); +the binary column \col{lc} will further satisfy a monotony condition (counter-incrementing) forcing it to remain $=1$ for the remainder of any counter-cycle as soon as it hits the value 1. + +\saNote{}\label{rlp patterns: bytestring prefix: note: purpose of counter constancy of length} The only row on which the \col{length} column is constrained is the last one (i.e. any row with $\done \equiv 1$). The implied counter-constancy condition isn't all that important: in applications the value that one would like to use is the final one, but the \emph{correct} value to use might only be known at the start of the counter-cycle. In such cases one may use a counter-constant column, \emph{initialize} it at the start of the \ct{}-cycle with the desired value, and carry that value through to the end of the counter-cycle by means of counter-constancy. + +\noindent We subsume under the shorthand +\[ + \rlpPrefixByteString_{i} + \left( + \begin{array}{r} + \col{length}, + \col{ct}, + \col{nStep}, + \col{done}, + \col{isList}; \\ + \col{byteSize}, + \col{power}, + \col{comp}, + \col{acc1}, + \col{acc2}; \\ + \col{lc}, + \col{limb}, + \col{nBytes}; \\ + \end{array} + \right) +\] + +\begin{enumerate} + \item $\rlpByteCounting_{i} (\col{ct}, \col{nStep}, \col{done}, \col{acc1}, \col{byteSize}, \col{power})$ + \item \If $\col{done}_{i} = 1$ \Then: + \begin{enumerate} + \item $\col{acc1}_{i} = \col{length}_{i}$ + \item $\compareFiftyFive_{i}(\col{length}_{i},\col{comp}_{i},\col{acc2}_{i})$ + \item \If $\col{comp}_{i} = 0$ (case short input) \Then + \begin{enumerate} + \item $\col{lc}_{i - 1} + \col{lc}_{i} = 1$ + \item $\col{limb}_{i} = (\rlprefixShortInt \cdot (1 - \col{isList}) + \rlprefixShortList \cdot \col{isList}+\col{length}_{i})\cdot256^{\llargeMO}$ + \item $\col{nBytes}_{i} = 1$ + \end{enumerate} + In the ``short input'' case the prefix occupies a single row containing (essentially) the \col{byteSize} itself. + \item \If $\col{comp}_{i} = 1$ (case long input) \Then + \begin{enumerate} + \item $\col{lc}_{i - 2} + \col{lc}_{i - 1} = 1$ + \item $\col{limb}_{i - 1} = (\rlprefixLongInt \cdot (1 - \col{isList}) + \rlprefixLongList \cdot \col{isList}+\col{byteSize}_{i})\cdot256^{\llargeMO}$ + \item $\col{nBytes}_{i - 1} = 1$ + \item $\col{limb}_{i} = \col{length}_{i} \cdot \col{power}_{i}$ + \item $\col{nBytes}_{i} = \col{byteSize}_{i}$ + \end{enumerate} + In the ``long input'' case the prefix of the \textsc{rlp} encoding occupies two rows: the first one containing (essentially) the size in bytes of the length of the byte string (one byte suffices), the second containing (essentially) the byte size itself (which requires $\col{bytesize}\geq 1$ bytes) + \end{enumerate} +\end{enumerate} diff --git a/rlp_patterns/rlp_prefix_int.tex b/rlp_patterns/rlp_prefix_int.tex new file mode 100644 index 0000000..02134fe --- /dev/null +++ b/rlp_patterns/rlp_prefix_int.tex @@ -0,0 +1,73 @@ +The present describes a contraint system that writes the \rlp{}-prefix of certain data types given certain size constraints. The present pattern can be applied in the following situations: +(\emph{a}) +obtaining the \rlp{}-prefix of (\emph{nonzero}) integers $n\in\mathbb{N}$ satisfying $0 < n < 256^{\llarge}$, +(\emph{b}) +obtaining the \rlp{}-prefix of bytestrings of length $\leq \llarge$. \saNote{} Recall that the \rlp{} encoding of the integer $0\in\mathbb{N}$ is that of the empty bytestring $(\,) \in \mathbb{B}_0 \subset \mathbb{B}^*$, i.e. $\rlprefixShortInt$, while the \rlp{} encoding of the zero byte $\texttt{0x\,00}\in\mathbb{B}$ is itself. + +We shall assume the following: we are provided with columns +\begin{itemize} + \item $\col{input}$: an integer; + \item $\col{ct}$: a counter; + \item $\col{nStep}$: a column which distinguishes between the \emph{expected} maximal byte size; + \item $\col{done}$: a binary columns which lights up at the end of the byte decomposition; \\ + \saNote{We have $\col{done}_{i}=1 \iff \col{ct}_{i}=\col{nStep}_{i}-1$.} + \item $\col{limb}$: a column where the output is written; + \item $\col{lc}$: a bit column, is 1 when something is written in the $\col{limb}$, else 0; + \item $\col{nBytes}$: number of meaningfull bytes of the $\col{limb}$; + \item $\col{byte}$: a byte column which is accumulated; + \item $\col{acc}$: an accumulator column that accumulates the bytes of an input; + \item $\col{byteSize}$: column counting the number of significant bytes of said input; + \item $\col{power}$: a ``power of 256'' column; + \item $\col{bit}$: a binary column used to do a bit decomposition; + \item $\col{bitAcc}$: a bit accumulator. +\end{itemize} + +\noindent We subsume under the short hand +\[ + \rlpPrefixInt_{i} + \left( + \begin{array}{r} + \col{input}, + \col{ct}, + \col{nStep}, + \col{done}; \\ + \col{byte}, + \col{acc}, + \col{byteSize}, + \col{power}, + \col{bit}, + \col{bitAcc}; \\ + \col{limb}, + \col{lc}, + \col{nBytes}; \\ + \end{array} + \right) +\] + +\begin{enumerate} + \item \rlpByteCounting (\col{ct}, \col{nStep}, \col{acc}, \col{byteSize}, \col{power}) + \item \If $\col{done}_{i}=1$ \Then: + \begin{enumerate} + \item $\col{acc}_{i}=\col{input}_{i}$ + \item $\col{bitAcc}_{i}=\col{byte}_{i}$ + \item \If ($\col{byteSize}_{i} = 1$ \et $\col{bit}_{i-7} = 0$) \Then $\col{lc}_{i-1}=0$ + \item \If $\col{byteSize}_{i} \ne 1$ \Then $\texttt{rlpPrefixOfIntegerGeq128}$ + \item \If $\col{bitAcc}_{i-7} \ne 0$ \Then $\texttt{rlpPrefixOfIntegerGeq128}$ + \end{enumerate} +\end{enumerate} + +Where we use the following local shorthand: +\[ + \texttt{rlpPrefixOfIntegerGeq128} \iff + \begin{cases} + \col{lc}_{i-2} + \col{lc}_{i-1}=1 \\ + \col{limb}_{i-1}=(\rlprefixShortInt + \col{byteSize}_{i}) \cdot 256^{\llargeMO} \\ + \col{nBytes}_{i-1}=1 \\ + \end{cases} +\] + +\saNote{}The constraint $\col{lc}_{i-2} + \col{lc}_{i-1}=1 \iff \col{lc}_{i-2} = 0$ \et $\col{lc}_{i-1}=1$ as it will apply to a counter-incrementing column. +\saNote{}The case \col{input}=0 is the integer 0 is not handled in this pattern. +\saNote{}In the case \col{input} < 128, there is nothing to write in the \col{limb} as there are no prefixs. + + diff --git a/rlp_txn/_all_rlp_txn.tex b/rlp_txn/_all_rlp_txn.tex new file mode 100644 index 0000000..8328f9b --- /dev/null +++ b/rlp_txn/_all_rlp_txn.tex @@ -0,0 +1,49 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +\usepackage{xkeyval} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/rlp_patterns} +\usepackage{../pkg/txn_data} + +\usepackage{../pkg/draculatheme} + +\title{Transaction RLP module} +\author{Rollup team} +\date{May 2023} + +\begin{document} + +\maketitle +\tableofcontents +\input{_inputs} + +\end{document} diff --git a/rlp_txn/_inputs.tex b/rlp_txn/_inputs.tex new file mode 100644 index 0000000..6e9c772 --- /dev/null +++ b/rlp_txn/_inputs.tex @@ -0,0 +1,12 @@ +\section{Introduction} \input{intro} +\section{Global Behavior} +\subsection{Column descriptions} \input{columns} +\subsection{Phase definition} \input{phase_constraints/definition} +\subsection{Binary constraints} \input{generalities/binarities} +\subsection{Global Constraints} \input{generalities/global_constraint} + +\section{Constraint patterns} \input{patterns/_inputs} + +\section{Phase constraints} \input{phase_constraints/_inputs} + +\section{Lookups} \input{lookups/_inputs} diff --git a/rlp_txn/columns.tex b/rlp_txn/columns.tex new file mode 100644 index 0000000..47ca2c2 --- /dev/null +++ b/rlp_txn/columns.tex @@ -0,0 +1,102 @@ +\begin{enumerate} + \item Output columns: + \begin{enumerate} + \item $\limb$: + output of the module, contains 16 bytes data. + \item $\limbsize$: + number of meaningful bytes of the $\limb$. Those bytes are shifted to the left with $\llarge - \limbsize$ zeros on the right; + \item \col{LIMB\_CONSTRUCTED}: + binary column; equals $1$ when the $\limb$ is in one of the two RLP bytestring $\widetilde{L}_{\mathrm{T}}$ or $\widetilde{L}_{\mathrm{X}}$, otherwise equals $0$; + abbreviated to $\lc$; + \item $\lt$: + binary column; equals $1$ when the constructed $\limb$ is in $\widetilde{L}_{\mathrm{T}}$, otherwise equals $0$; + \item $\lx$: + binary column; equals $1$ when the constructed $\limb$ is in $\widetilde{L}_{\mathrm{X}}$, otherwise equals $0$; + \item $\indext$: + index of the current limb within the current string of $\widetilde{L}_{\mathrm{T}}$. Starts at 0 when starting a new transaction and increments by 1 when $\lc$ and $\lt$ are one; + \item $\indexx$: + index of the current limb within the current string of $\widetilde{L}_{\mathrm{X}}$. Starts at 0 when starting a new transaction and increments by 1 when $\lc$ and $\lx$ are one; + \item \toHashByProver{}: + binary column; equals $\lc \cdot \lx$; is a selector to extract data for the prover. + \end{enumerate} + \item Columns used exclusively for lookup connexion with other modules: + \begin{enumerate} + \item $\absTxNum$: + transaction number column, starts at 0 and is incremented by one when starting a new transaction. + \item $\outgoingDataSymb\high$ and $\outgoingDataSymb\low$: + used for lookup with the transaction data module. + \item \CFI{}: + an unique (block)-identifier of a code fragment; + \item \txRequiresEvmExecution{}: + binary column; is 1 when the transaction requires evm execution (ie when calling a smart contract, or when a contract creation with a non-empty init code) + \item \Phase{}: + column used as an identifier for the lookups; + \end{enumerate} + \item Columns used for heartbeat + \begin{enumerate} + \item $\phaseRlpPrefix{}, \dots, \phaseS{}$: + exclusive binary columns which light up in the corresponding phase. + \item $\phasend$: + binary column; equals $1$ on the last row of any phase, $0$ elsewhere; + \item \txType{}: + defines the type of transaction, can be $0$, $1$ or $2$. The phase heartbeat depends of the \transactionType{} of the transaction. + \item \CT{}, abbreviated $\ct$: + internal counter, byte column. Counts from 0 to $\nbstep - 1$ and resets. + \item $\done$: + binary column; equal to $1$ on the final row of every \ct{} cycle; equal to $0$ otherwise; + \end{enumerate} + \item Columns used in several phase for computation + \begin{enumerate} + \item $\nbstep$: + byte column, with value between 1 and $\llarge$. + \item $\Input k$, $k=1,2$: + 0-16 bytes data. + \item $\byteCol{k}$, $k=1,2$: + byte columns used for byte decompositions, and its accumulators $\acc{k}$. + \item $\accsize$: + byte column used to count the bytesize of one of the two $\acc{k}$. + \item \genBit{}: + bit columns and its accumulator \genBitAcc{}, used for bit decomposition. + \item \Power{} abbreviate with $P$, to calculate the offset (left shifting) for the $\limb$. + \item $\rlptsize$: + number of bytes of $L_{\mathrm{T}}$ of the current transaction, used in \phaseRlpPrefix{} to verify the RLP prefix. Decreases by $\limbsize$ when $\lc$ and $\lt$ are one, must be 0 at the end of the transaction. + \item $\rlpxsize$: + number of bytes of $L_{\mathrm{X}}$ of the current transaction, used in \phaseRlpPrefix{} to verify the RLP prefix. Decreases by $\limbsize$ when $\lc$ and $\lx$ are one, must be 0 at the end of the transaction. + \end{enumerate} + \item Columns used only at certain phases, are null outside those phases. + \begin{enumerate} + \item Used when \phaseRlpPrefix{}, \phaseData{} or \phaseBeta{} are $\equiv 1$: + \begin{enumerate} + \item \ispadding: + bit column, used to declare when there is no limb constructed in the $\ct$-loop. + \end{enumerate} + \item Used when \phaseData{} or \phaseAccessList{} are $\equiv 1$: + \begin{enumerate} + \item \isprefix: + bit column, to declare when to compute a RLP prefix. + \item $\phasesize$: + similar to $\rlptsize$. Size (in bytes) of the bytestring of this phase. Usefull to compute the RLP prefix of the byte string of this phase. + \end{enumerate} + \item Used in \phaseData{} + \begin{enumerate} + \item \indexData{}: + similar to \index. Index of the given limb in the data phase (phase 9). Starts at 0 at the begining of the data phase and increments by 1 after $\lc = 1$. + \item \dataGasCost{}: + gas cost of the Data. Decreases during \phase9, must be 0 at the end of the \phase9. + \end{enumerate} + \item Used in \phaseAccessList{} + \begin{enumerate} + \item $\Depth1$ and $\Depth2$: + binary columns to define loop intrication. + \item $\col{Addr}\high$ and $\col{Addr}\low$ used to store high and low part of the address of an \textbf{accessList} item during the \textbf{accessList} phase. + \item \col{ACCESS\_TUPLE\_BYTESIZE}: + similar to $\rlptsize$. Size (in bytes) of an \textbf{accessList} tuple. + \item $\nbAddr$: + number of Address in the \textbf{accessList}. Decreases during \phase{10}, must be 0 at the end of the \phase{10}. + \item $\nStorageKeysInAccessList$: + total number of StorageKey in the \textbf{accessList}. Decreases during \phase{10}, must be 0 at the end of the \phase{10}. + \item $\nStorageKeysInAccessEntry$: + number of StorageKey in an \textbf{accessList} tuple. + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/generalities/binarities.tex b/rlp_txn/generalities/binarities.tex new file mode 100644 index 0000000..00a55b7 --- /dev/null +++ b/rlp_txn/generalities/binarities.tex @@ -0,0 +1,17 @@ +We impose the following columns to be binary columns: +\begin{multicols}{3} + \begin{enumerate} + \item \phaseRlpPrefix{} to \phaseS{} + \item \lc{} + \item \lt{} \quad (\trash) + \item \lx{} \quad (\trash) + \item \toHashByProver{} \quad (\trash) + \item \txRequiresEvmExecution{} \quad (\trash) + \item \phasend{} \quad (\trash) + \item \done{} \quad (\trash) + \item \genBit{} + \item \ispadding{} + \item \isprefix{} \quad (\trash) + \item $\Depth{1}$ and $\Depth{2}$ \quad (\trash) + \end{enumerate} +\end{multicols} \ No newline at end of file diff --git a/rlp_txn/generalities/global_constraint.tex b/rlp_txn/generalities/global_constraint.tex new file mode 100644 index 0000000..e06374d --- /dev/null +++ b/rlp_txn/generalities/global_constraint.tex @@ -0,0 +1,203 @@ +\subsubsection{Constancy columns} \label{constancy_constraints} +We define that a column \col{X} is +\begin{enumerate} + \item transaction-constant: \If $\absTxNum_{i} = \absTxNum_{i-1}$ \Then $\col{X}_{i} = \col{X}_{i-1}$ + \item counter-constant: \If $\ct_{i} \ne 0$ \Then $\col{X}_{i} = \col{X}_{i-1}$ + \item counter-incrementing: \If $\ct_{i} \ne 0$ \Then $\col{X}_{i} \in \{\col{X}_{i-1}; \col{X}_{i-1} + 1 \}$. If \col{X} is a bit column, it implies $\col{X}_{i} \in \{\col{X}_{i-1}; 1 \}$. + \item $\phase{k}$-constant: \If $\phase{k}_{i-1} + \phase{k}_{i} = 2$ \Then $\col{X}_{i} = \col{X}_{i-1}$. + \item $\phase{k}$-incrementing: \If $\phase{k}_{i-1} + \phase{k}_{i} = 2$ \Then $\col{X}_{i} \in \{\col{X}_{i-1}; \col{X}_{i-1} + 1 \}$. If \col{X} is a bit column, it implies $\col{X}_{i} \in \{\col{X}_{i-1}; 1 \}$. + \item $\phase{k}$-decrementing: \If $\phase{k}_{i-1} + \phase{k}_{i} = 2$ \Then $\col{X}_{i} \in \{\col{X}_{i-1} -1; \col{X}_{i-1} \}$. If \col{X} is a bit column, it implies $\col{X}_{i} \in \{0 ; \col{X}_{i-1}\}$. + \item block-constant: \If $\absTxNum_{i} \ne 0$ \Then $X_{i} = X_{i + 1}$ \et \If $\absTxNum_{i} = 0$ \Then $X_{i} = 0$ +\end{enumerate} + +We constrain: +\begin{enumerate} + \item \txType{}, \txRequiresEvmExecution{} and \CFI{} are transaction-constant. + \item $\Input k$ (for $k = 1 ; 2$), $\nbstep$, $\lt$, $\lx$, $\isprefix$, $\nbAddr$, $\nStorageKeysInAccessList$, $\nStorageKeysInAccessEntry$, and $\Depth k$ (for $k = 1 ; 2$) are counter-constant. + \item $\ispadding$ is counter-incrementing. + \item \If $\phaseData{}_{i} = 0$ \Or $\isprefix_{i} = 0$ \Then $\lc$ is counter-incrementing. + \item $\rlptsize$ and $\rlpxsize$ are $\phaseRlpPrefix{}$-constant. + \item $\isprefix$ is $\phaseData$-decrementing. + \item $\outgoingDataSymb\high$ and $\outgoingDataSymb\low$ are $\phase{k}$-constant for $k \in \{ \phaseRlpPrefixValue \} \cup [\![ \phaseNonceValue ; \phaseAccessListValue ]\!] $ + \item $\absTxNumInfty$ is block-constant. +\end{enumerate} +The following constraints hold by construction, there is therfore no reason to explictly constrain them: +\begin{enumerate}[resume] + \item $\ispadding$ is $\phaseRlpPrefix$-decrementing; \quad (\trash) + \item $\done$ and $\accsize$ are $\ct$-incrementing; \quad (\trash) + \item $\phasend$ is $\phase{k}$-incrementing; \quad (\trash) + \item \indexData{} is $\phaseData{}$-incrementing; \quad (\trash) + \item $\phasesize$ is \phaseData{} and \phaseAccessList{}-decreasing; \quad (\trash) + \item $\rlptsize$ and $\rlpxsize$ are transaction-decreasing; \quad (\trash) + \item $\col{INDEX\_T}$ and $\col{INDEX\_X}$ are transaction-incrementing; \quad (\trash) +\end{enumerate} + +\subsubsection{Global phase constrains} \label{Global phase constraints} +Constraints on the transaction number: +\begin{enumerate} + \item $\absTxNum_{0} = 0$ + \item \If $\absTxNum_{i} = 0$ \Then $\sum_{k = \phaseRlpPrefixValue}^{\phaseSValue} \phase{k}_{i} = 0$ + \item \If $\absTxNum_{i} \ne 0$ \Then $\sum_{k = \phaseRlpPrefixValue}^{\phaseSValue} \phase{k}_{i} = 1$ in other words, you must be in one and only phase at a time. + \item $\absTxNum_{i} = \absTxNum_{i-1} + \phaseRlpPrefix_{i} \cdot (\phaseRlpPrefix_{i}-\phaseRlpPrefix_{i-1})$ in other words $\absTxNum$ is constant except increasing by one when starting a new transaction. +\end{enumerate} +The bytestring that needs to be hashed by the prover is the bytestring reconstruction of $\widetilde{L}_{\mathrm{X}}(T)$ as defined in the \cite{EYP}. +\begin{enumerate}[resume] + \item $\toHashByProver_{i} = \lc_{i} \cdot \lx_{i}$ +\end{enumerate} +Constraints on $\lt$ and $\lx$: \footnote{Constraints in $\phaseRlpPrefix $ and $\phaseBeta$ are given in the phase description.} +\begin{enumerate}[resume] + \item \If $\sum_{k = \phaseChainIdValue}^{\phaseAccessListValue} \phase{k}_{i} = 1$ \Then $\lt_{i} = \lx_{i} = 1$ + \item \If $\sum_{k = \phaseYValue}^{\phaseSValue} \phase{k}_{i} = 1$ \Then + \begin{enumerate} + \item $\lt_{i} = 1$ + \item $\lx_{i} = 0$ + \end{enumerate} +\end{enumerate} +Constraints on the phase transition: +\begin{enumerate}[resume] + \item \If ($\absTxNum_{i} \neq 0$ \et $\done_{i} = 0$) \Then $\phasend_{i} = 0$. Note that constraining $\phasend$ to be nonzero inside \ct -loop is not sufficient to prevent unwanted phase transition in every phases, additional constrains are defined for some phases. + \item \If $\phasend_{i} = 0$ \Then $\phase{k}_{i + 1} = \phase{k}_{i}$ for every $k \in [\![ \phaseRlpPrefixValue ; \phaseSValue ]\!]$. \footnote{It is implemented \If $\phasend_{i} = 0$ \Then $\sum _{k = 0}^{14} k \cdot (\phase{k}_{i + 1} - \phase{k}_{i}) = 0$.} + \item \If $\phasend_{i} = 1$ \Then + \begin{enumerate} + \item \If $\phaseRlpPrefix_{i} = 1$ \Then + \begin{enumerate} + \item \If $\txType_{i} = 0$ \Then $\phaseNonce_{i + 1} = 1$ + \item \If $\txType_{i} \ne 0$ \Then $\phaseChainId_{i + 1} = 1$ + \end{enumerate} + \item \If $\phaseChainId_{i} = 1$ \Then $\phaseNonce_{i + 1} = 1$ + \item \If $\phaseNonce_{i} = 1$ \Then + \begin{enumerate} + \item \If $\txType_{i} \ne 2$ \Then $\phaseGasPrice_{i + 1} = 1$ + \item \If $\txType_{i} = 2$ \Then $\phaseMaxPriorityFeePerGas_{i + 1} = 1$ + \end{enumerate} + \item \If $\phaseGasPrice_{i} = 1$ \Then $\phaseGasLimit_{i + 1} = 1$ + \item \If $\phaseMaxPriorityFeePerGas_{i} = 1$ \Then $\phaseMaxFeePerGas_{i + 1} = 1$ + \item \If $\phaseMaxFeePerGas_{i} = 1$ \Then $\phaseGasLimit_{i + 1} = 1$ + \item \If $\phaseGasLimit_{i} = 1$ \Then $\phaseTo_{i + 1} = 1$ + \item \If $\phaseTo_{i} = 1$ \Then $\phaseValue_{i + 1} = 1$ + \item \If $\phaseValue_{i} = 1$ \Then $\phaseData_{i + 1} = 1$ + \item \If $\phaseData_{i} = 1$ \Then + \begin{enumerate} + \item \trash $\phasesize_{i} = 0$ + \item $\dataGasCost_{i} = 0$ + \item \If $\txType_{i} = 0$ \Then $\phaseBeta_{i + 1} = 1$ + \item \If $\txType_{i} \ne 0$ \Then $\phaseAccessList_{i + 1} = 1$ + \end{enumerate} + \item \If $\phaseAccessList_{i} = 1$ \Then + \begin{enumerate} + \item \trash $\phasesize_{i} = 0$ + \item $\nbAddr_{i} = 0$ + \item $\nStorageKeysInAccessList_{i} = 0$ + \item $\nStorageKeysInAccessEntry_{i} = 0$ + \item $\phaseY_{i + 1} = 1$ + \end{enumerate} + \item \If $\phaseBeta_{i} = 1$ \Then $\phaseR_{i + 1} = 1$ + \item \If $\phaseY_{i} = 1$ \Then $\phaseR_{i + 1} = 1$ + \item \If $\phaseR_{i} = 1$ \Then $\phaseS_{i + 1} = 1$ + \item \If $\phaseS_{i} = 1$ \Then: + \begin{enumerate} + \item $\rlptsize_{i} = 0$ + \item $\rlpxsize_{i} = 0$ + \item $\phaseRlpPrefix_{i + 1} = 1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} + +In other words, a phase transition happens if and only if $\phasend_{i} = 1$ and means $\phase{p}_{i} = 1$ and $\phase{q}_{i + 1} = 1$ with the only given possibility for p and q, depending of $\txType$: + +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|} \hline + $\phase{p}_{i}$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 \\ \hline \hline + $\phase{q}_{i + 1}$ (for $\txType = 0$) & 2 & & 3 & 6 & & & 7 & 8 & 9 & 11 & & 13 & & 14 & 0 \\ \hline + $\phase{q}_{i + 1}$ (for $\txType = 1$) & 1 & 2 & 3 & 6 & & & 7 & 8 & 9 & 10 & 12 & & 13 & 14 & 0 \\ \hline + $\phase{q}_{i + 1}$ (for $\txType = 2$) & 1 & 2 & 4 & & 5 & 6 & 7 & 8 & 9 & 10 & 12 & & 13 & 14 & 0 \\ \hline + \end{tabular} + \caption{Possible phase transition} + \label{tab:Possible phase transition} +\end{table} + +\subsubsection{Byte decomposition's loop Heartbeat} +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\absTxNum_{i} \ne 0$.}} +\end{center} +We remind the reader that $\nbstep$ and $\oli$ are $\ct$-constant, and $\lc$ is $\ct$-incrementing (see \ref{constancy_constraints}). +\begin{enumerate} + \item \If $\ct_{i} = \nbstep_{i}-1$ \Then $\done_{i} = 1$ + \item \If $\ct_{i} \ne \nbstep_{i}-1$ \Then $\done_{i} = 0$ in other words, $\done$ is nonzero only at the last row of a loop. + \item \If $\done_{i} = 0$ \Then $\ct_{i + 1} = \ct_{i} + 1$ + \item \If $\done_{i} = 1$ \Then + \begin{enumerate} + \item $\lc_{i} = 1-\ispadding_{i}$ + \item $\ct_{i + 1} = 0$ + \end{enumerate} +\end{enumerate} + +\subsubsection{Blind byte and bit decomposition} +We build some blind byte and bit accumulators. There are more constaints when those decomposition and accumulators are used, depending of the phase. +\begin{enumerate} + \item Constraints on the bytes accumulator columns for $k = 1,2$. + \begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\byteCol{k}_{i} = \acc{k}_{i}$ + \item \If $\ct_{i} \ne 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i-1} + \byteCol{k}_{i}$ + \item we constraint those columbs to be byte: $\byteCol{k}$, $k = 1,2$ + \end{enumerate} + \item Constraint on the bit accumulator column: + \begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\genBitAcc_{i} = \genBit_{i}$ + \item \If $\ct_{i} \ne 0$ \Then $\genBitAcc_{i} = 2 \cdot \genBitAcc_{i-1} + \genBit_{i}$ + \end{enumerate} +\end{enumerate} + +\subsubsection{Global constraints} +We define the shorthand $\col{phase\_weight\_sum}$ defined by the following expression +\[ + \col{phase\_weight\_sum}_{i} \define + \left[ \begin{array}{crcl} + + & \phaseRlpPrefixValue & \!\!\!\cdot\!\!\! & \phaseRlpPrefix _{i} \\ + + & \phaseChainIdValue & \!\!\!\cdot\!\!\! & \phaseChainId _{i} \\ + + & \phaseNonceValue & \!\!\!\cdot\!\!\! & \phaseNonce _{i} \\ + + & \phaseGasPriceValue & \!\!\!\cdot\!\!\! & \phaseGasPrice _{i} \\ + + & \phaseMaxPriorityFeePerGasValue & \!\!\!\cdot\!\!\! & \phaseMaxPriorityFeePerGas _{i} \\ + + & \phaseMaxFeePerGasValue & \!\!\!\cdot\!\!\! & \phaseMaxFeePerGas _{i} \\ + + & \phaseGasLimitValue & \!\!\!\cdot\!\!\! & \phaseGasLimit _{i} \\ + + & \phaseToValue & \!\!\!\cdot\!\!\! & \phaseTo _{i} \\ + + & \phaseValueValue & \!\!\!\cdot\!\!\! & \phaseValue _{i} \\ + + & \phaseDataValue & \!\!\!\cdot\!\!\! & \phaseData _{i} \\ + + & \phaseAccessListValue & \!\!\!\cdot\!\!\! & \phaseAccessList _{i} \\ + + & \phaseBetaValue & \!\!\!\cdot\!\!\! & \phaseBeta _{i} \\ + + & \phaseYValue & \!\!\!\cdot\!\!\! & \phaseY _{i} \\ + + & \phaseRValue & \!\!\!\cdot\!\!\! & \phaseR _{i} \\ + + & \phaseSValue & \!\!\!\cdot\!\!\! & \phaseS _{i} \\ + \end{array} \right] +\] +\begin{enumerate} + \item $\Phase_{i} = \col{phase\_weight\_sum}_{i}$ + \item \If $\absTxNum_{i} \ne \absTxNum_{i-1}$ \Then: + \begin{enumerate} + \item $\indext_{i} = 0$ + \item $\indexx_{i} = 0$ + \end{enumerate} + \item \If $\absTxNum_{i} = \absTxNum_{i-1}$ \Then: + \begin{enumerate} + \item $\indext_{i} = \indext_{i-1} + \lc_{i-1} \cdot \lt_{i-1}$ + \item $\indexx_{i} = \indexx_{i-1} + \lc_{i-1} \cdot \lx_{i-1}$. In other words, $\indext$ (resp. $\indexx$) resets to 0 at the begining of a new transaction, and increases by one after $\lc$ and $\lt$ (resp. $\lx$) is one. + \end{enumerate} + + \item \If $\sum_{k = \phaseChainIdValue}^{\phaseSValue} \phase{k}_{i} = 1$ \Then \footnote{We remind the reader that $\rlptsize$ and $\rlpxsize$ are $\phaseRlpPrefix$-constant integer (see \ref{constancy_constraints}).} + \begin{enumerate} + \item $\rlptsize_{i} = \rlptsize_{i-1} - \lc_{i} \cdot \lt_{i} \cdot\limbsize_{i}$ + \item $\rlpxsize_{i} = \rlpxsize_{i-1} - \lc_{i} \cdot \lx_{i} \cdot\limbsize_{i}$ + \end{enumerate} + + \item \If ($\phaseRlpPrefix_{i} = 0$ \et $\phaseData_{i} = 0$ \et $\phaseBeta_{i} = 0$) \Then $\ispadding_{i} = 0$. +\end{enumerate} + +\subsubsection{Finalisation constraints} +\If $\absTxNum_{N} \ne 0$ \Then +\begin{enumerate} + \item $\phasend_{N} = 1$ + \item $\phaseS_{N} = 1$ + \item $\absTxNum_{N} = \absTxNum_{N}^{\infty}$ +\end{enumerate} +In other words, we constrain the last row of the trace to be the end of the last phase of a transaction (condition one and two), and that all the transaction has been compited (condition 3). diff --git a/rlp_txn/intro.tex b/rlp_txn/intro.tex new file mode 100644 index 0000000..402a783 --- /dev/null +++ b/rlp_txn/intro.tex @@ -0,0 +1,46 @@ +The present module performs the \rlp{} \textbf{decodings} and \textbf{encodings} associated with processing a batch of \textsc{Ethereum} transactions; it thereby justifies the functional fields of the transactions that enter the \zkEvm{}. +Transactions enter the present module\footnote{and the \zkEvm{}!} through their ``full'' \rlp{} encodings, i.e. as a rather arbitrary looking string. +In order to makes sense of a transaction the \zkEvm{} must decode this string and verify the validity of the underlying transaction (e.g. verifying the signature but also verifying the sender has sufficient balance and the transaction nonce is correct.) +The present module takes care of the ``making sense of a transaction'' part of this. +It furthermore produces the message whose hash along with the signature are provided as inputs to \inst{ECRECOVER} to obtain the sender address. +We provide more details below. + +Recall that there are two \rlp{} strings of interest associated with a transaction $T$. +There is the ``full'' \rlp{} encoding of a transaction, $\widetilde{L}_{\mathrm{T}}(T)$ as defined in the \cite{EYP}. +This contains all the fields of the transaction as well as a signature. +Then there is the \rlp{} string obtained by \rlp{} encoding the ``functional fields'' of a transaction, $\widetilde{L}_{\mathrm{X}}(T)$ as defined in the \cite{EYP}. +This defines the message whose hash is (supposedly) signed in the full transaction. + +The present module thus does the following two things. +First, it \textbf{successfully} performs the \rlp{} \textbf{decoding} of some input string\footnote{The present module isn't equipped to deal with malformed transactions.}. +It verifies that this string is of the form $\widetilde{L}_{\mathrm{T}}(T)$ for some well-formed transaction $T$. +In the process it extracts the fields of that transaction (GasPrice, Value, \textbf{accessList}, etc\dots{}). +Any such ``extraction step'' comprises one of the various ``\textbf{phases}'' of the arithmetization presented here. +Note that this \textbf{does not} include the verification of the validity of these fields (e.g. value, gas price, nonce, \dots) against account data. +The associated checks are performed in the \txnDataMod{} and \hubMod{} modules. +Second, it performs the \rlp{} \textbf{encoding} of the relevant data to construct $\widetilde{L}_{\mathrm{X}}(T)$. + +Since the layout of the fields of a transaction varies according to the \textbf{transaction type} our arithmetization distinguishes between +\textsc{legacy} transations (i.e. Type 0), +\textsc{access list} transations (i.e. Type 1) and +\textsc{eip-1559} transations (i.e. Type 2). +There are furthermore phases which deal with the complexities of the \rlp{} encoding itself. +These comprise justifying \textbf{sizes} (in bytes) as well \textbf{sizes of sizes} and various comparisons against protocol-specific constants. +Since most of the fields that make up a transction are shared among the ``full'' transaction \rlp{} and the \rlp{} of the submessage which was signed we are able to run decoding and encoding in parallel. + +\subsection{Data extraction} +For a given transaction $T$, labelled in this module by its absolute transaction number +$\absTxNum$, the concatenation of the most significant +$\limbsize$ bytes of the +$\limb$ when +$\lc$ and +$\lt$ (resp. +$\lx$) is one, and ordered by growing +$\indext$\footnote{starting at zero.} (resp. $\indexx$) gives $\widetilde{L}_{\mathrm{T}}(T)$ (resp. $\widetilde{L}_{\mathrm{X}}(T)$) of this transaction $T$. +\newline +For a given transaction $T$, labelled in this module by its absolute transaction number $\absTxNum$ +the concatenation of the +$\limb$ when +$\phase{9}_{i}=1$ \et{} +$\isprefix_{i}=0$, indexed by +$\indexData$ gives the Data. diff --git a/rlp_txn/lookups/_inputs.tex b/rlp_txn/lookups/_inputs.tex new file mode 100644 index 0000000..9bfc10a --- /dev/null +++ b/rlp_txn/lookups/_inputs.tex @@ -0,0 +1,4 @@ +\input{../hub/lookups/_local} +\section{Lookups} +\subsection{\rlpTxnMod{} $\hookrightarrow$ \romMod{} \lispDone{}} \label{hub: lookups: into the rom} \input{lookups/into_rom} +\subsection{\rlpTxnMod{} $\hookrightarrow$ \hubMod{} \lispDone{}} \label{hub: lookups: into the hub} \input{lookups/into_hub} diff --git a/rlp_txn/lookups/into_hub.tex b/rlp_txn/lookups/into_hub.tex new file mode 100644 index 0000000..8302a61 --- /dev/null +++ b/rlp_txn/lookups/into_hub.tex @@ -0,0 +1,40 @@ +The present section describes the lookup emanating from the \rlpTxnMod{} and targeting the \hubMod{} module. +This lookup is require to ensure that the \hubMod{} performs \textbf{all} required pre-warming operations of addresses and storage keys \textbf{as required} i.e. only for transactions presenting an access list and requiring \evm{} execution. +\begin{description} + \item[Source selector column:] + we use the following selector: + $\col{sel} + \define + (1 - \isprefix_{i}) + \cdot \txRequiresEvmExecution _{i} + \cdot \phaseAccessList _{i}$ + \item[Source columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $1 _{i}$ + \item $\absTxNum _{i}$ + \item $1 - \Depth{2} _{i}$ + \item $\Depth{2} _{i}$ + \item $\addr\high _{i}$ + \item $\addr\low _{i}$ + \item $\Input{1} \cdot \Depth{2} _{i}$ + \item $\Input{2} \cdot \Depth{2} _{i}$ + \end{enumerate} + \end{multicols} + \item[Target columns:] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\txWarm _{j}$ + \item $\absTxNum _{j}$ + \item $\peekAccount _{j}$ + \item $\peekStorage _{j}$ + \item $\locAddressHi _{j}$ + \item $\locAddressLo _{j}$ + \item $\locStorageKeyHi _{j}$ + \item $\locStorageKeyLo _{j}$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} +We have used shorthands introduced in section~(\ref{hub: lookups: into rlpTxn}): +\input{../hub/lookups/address_and_storage_key_shorthand_definitions} diff --git a/rlp_txn/lookups/into_rom.tex b/rlp_txn/lookups/into_rom.tex new file mode 100644 index 0000000..3360f71 --- /dev/null +++ b/rlp_txn/lookups/into_rom.tex @@ -0,0 +1,22 @@ +The lookup from the $\rlpTxnMod$ module is constructed as follows: +\begin{description} + \item[\underline{Selector:}] $\CFI_{i} \cdot \phaseData_{i} \cdot (1 - \isprefix_{i}) \cdot \lc_{i} \ne 0$; + \item[\underline{Source columns:}] from the \rlpTxnMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi_{i}$ + \item $\limb_{i}$ + \item $\indexData_{i}$ + \item $\nBytes_{i}$ + \end{enumerate} + \end{multicols} +\item[\underline{Target columns:}] from the \romMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi_{j}$ + \item $\limb_{j}$ + \item $\index_{j}$ + \item $\nBytes_{j}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/rlp_txn/patterns/_inputs.tex b/rlp_txn/patterns/_inputs.tex new file mode 100644 index 0000000..b518877 --- /dev/null +++ b/rlp_txn/patterns/_inputs.tex @@ -0,0 +1,3 @@ +\subsection{\rlp{} encoding constraints for integers in $\mathbb{N}_{256}$} \input{patterns/integers_up_to_32_bytes} +\subsection{\rlp{} encoding constraints for addresses} \input{patterns/addresses} +\subsection{\rlp{} encoding constraints for storage keys} \input{patterns/storage_keys} diff --git a/rlp_txn/patterns/addresses.tex b/rlp_txn/patterns/addresses.tex new file mode 100644 index 0000000..1e1fa6b --- /dev/null +++ b/rlp_txn/patterns/addresses.tex @@ -0,0 +1,33 @@ +The $\texttt{rlpAddressConstraints}_{i}(\col{input}\high, \col{input}\low, \col{ct})$ is a pattern that computes the RLP of an address, concatanated with the address. This constraints pattern is called during $\phase7$ and $\phase{10}$. +\newline +\begin{enumerate} + \item \If $\nbstep_{i}=1$ \Then + \begin{enumerate} + \item $\limb_{i}=\rlprefixShortInt\cdot256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + + \item \If $\nbstep_{i} \ne 1 $ \Then + \begin{enumerate} + \item $\nbstep_{i}=\llarge$ + \item \If $\done_{i}=1$, \Then + \begin{enumerate} + \item $\acc{1}_{i}=\col{input}\high_{i}$ + \item $\acc{1}_{i-4}=0$ + \end{enumerate} + We impose this as we want the address to be 20 byte long, so the address's high part is only four bytes. + \begin{enumerate}[resume] + \item $\acc{2}_{i}=\col{input}\low_{i}$ + \item $\lc_{i-3}+\lc_{i-2}=1$ + \item $\limb_{i-2}=(\rlprefixShortInt+20)\cdot256^{\llargeMO}$ + \item $\limbsize_{i-2}=1$ + \item $\limb_{i-2}=\col{input}\high_{i}\cdot256^{12}$ + \item $\limbsize_{i-2}=4$ + \item $\limb_{i}=\col{input}\low_{i}$ + \item $\limbsize_{i}=\llarge$ + \end{enumerate} + \end{enumerate} + +\end{enumerate} + + \ No newline at end of file diff --git a/rlp_txn/patterns/integers_up_to_32_bytes.tex b/rlp_txn/patterns/integers_up_to_32_bytes.tex new file mode 100644 index 0000000..6c91758 --- /dev/null +++ b/rlp_txn/patterns/integers_up_to_32_bytes.tex @@ -0,0 +1,80 @@ +The present describes a contraint system for the \textsc{rlp}-ization of somewhat large integers, that is: integers in $\mathbb{N}_{256}$ i.e. integers occupying (up to) 32 bytes. Such a constraint system is required in particular for the \rlpTxnMod{} module where one must deal with the signature and in particular $T_\text{r}$ and $T_\text{s}$, both in $\mathbb{N}_{256}$. An extra challenge comes from the fact that such integers will present themselves through \emph{two} coliumns. We shall assume the following +\begin{itemize} + \item $\col{input} \high$ and $\col{input} \high$: high and low parts of an integer; + \item $\col{ct}$: a counter column; + \item $\col{nStep}$: a constant column giving the size of the ct-loop; + \item $\col{done}$: a binary columns which lights up at the end of the byte decomposition; + \saNote{We have $\col{done}_{i}=1 \iff \col{ct}_{i}=\col{nStep}_{i}-1$.} + \item $\col{limb}$: a column where the output is written; + \item $\col{lc}$: a bit column, is 1 when something is written in the $\col{limb}$, else 0; + \item $\col{nBytes}$: number of meaningfull bytes of the $\col{limb}$; + \item $\col{byte} \high$ and $\col{byte} \low$: byte columns; + \item $\col{acc} \high$ and $\col{acc} \low$: associated accumulator columns; + \item $\col{byteSize}$: column counting a number of significant bytes of the input; + \item $\col{power}$: a ``power of 256'' column; + \item $\col{bit}$: a binary column used to do a bit decomposition; + \item $\col{bitAcc}$: a bit accumulator. +\end{itemize} + +\noindent We subsume under the shorthand +\[ + \rlpPrefixIntLong_{i} + \left( + \begin{array}{r} + \col{input}\high, + \col{input}\low, + \col{ct}, + \col{nStep}, + \col{done};\\ + \col{byte}\high, + \col{byte}\low, + \col{acc}\high, + \col{acc}\low, + \col{byteSize}, + \col{power}, + \col{bit}, + \col{bitAcc}; \\ + \col{limb}, + \col{lc}, + \col{nBytes}, + \end{array} + \right) +\] + +\begin{enumerate} + \item \If $\col{input}\high_{i}=0$ \Then \rlpByteCounting (\col{ct}, \col{nStep}, \col{done}, $\col{acc} \low$, \col{byteSize}, \col{power}) + \item \If $\col{input}\high_{i} \ne 0$ \Then \rlpByteCounting (\col{ct}, \col{nStep}, \col{done}, $\col{acc} \high$, \col{byteSize}, \col{power}) + \item \If $\col{done}_{i}= 1$ \Then: + \begin{enumerate} + \item $\col{acc} \high_{i}=\col{input}\high_{i}$ + \item $\col{acc} \low_{i}=\col{input}\low_{i}$ + \item \If $\col{input}\high_{i}=0$ \Then: + \begin{enumerate} + \item $\col{bitAcc}_{i}= \col{byte} \low_{i}$ + \item \If $\col{byteSize}_{i} = 1$ \et $\col{bit}_{i-7}=0$ \Then: + \begin{itemize} + \item $\col{lc}_{i-1}=0$ + \item $\col{limb}_{i}=\col{input}\low_{i}\cdot \col{power}_{i}$ + \item $\col{nBytes}_{i}=\col{byteSize}_{i}$ + \end{itemize} + \item \If $\col{byteSize}_{i} \ne 1$ or $\col{bit}_{i-7}\ne 0$ \Then: + \begin{itemize} + \item $\col{lc}_{i-2}+\col{lc}_{i-1}=1$ + \item $\col{limb}_{i-1}=(\rlprefixShortInt+\col{byteSize}_{i})\cdot256^{\llargeMO}$ + \item $\col{nBytes}_{i-1}=1$ + \item $\col{limb}_{i}=\col{input}\low_{i} \cdot \col{power}_{i}$ + \item $\col{nBytes}_{i}=\col{byteSize}_{i}$ + \end{itemize} + \end{enumerate} + \item \If $\col{input}\high_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\col{lc}_{i-3}+\col{lc}_{i-2}=1$ + \item $\col{limb}_{i-2}=(\rlprefixShortInt+\llarge+\col{byteSize}_{i}) \cdot 256^{\llargeMO}$ + \item $\col{nBytes}_{i-2}=1$ + \item $\col{limb}_{i-1}=\col{input}\high_{i} \cdot \col{power}_{i}$ + \item $\col{nBytes}_{i-1}=\col{byteSize}_{i}$ + \item $\col{limb}_{i}=\col{input}\low_{i}$ + \item $\col{nBytes}_{i}=\llarge$ + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/patterns/storage_keys.tex b/rlp_txn/patterns/storage_keys.tex new file mode 100644 index 0000000..15f0a2b --- /dev/null +++ b/rlp_txn/patterns/storage_keys.tex @@ -0,0 +1,16 @@ +The $\texttt{rlpStorageKeyConstraints}_{i}(\col{input}\high, \col{input}\low, \col{ct})$ is a pattern that takes the high part of a storage key in $\col{input}\high$ and its low part in $\col{input}\low$ and computes its RLP prefix, concatanated with the storage key. This pattern is only called in $\phase{10}$. +\begin{enumerate} + \item $\nbstep_{i}=\llarge$ + \item \If $\done_{i}=1$, \Then + \begin{enumerate} + \item $\acc{1}_{i}=\col{input}\high_{i}$ + \item $\acc{2}_{i}=\col{input}\low_{i}$ + \item $\lc_{i-3} + \lc_{i-2}=1$ + \item $\limb_{i-2} = (\rlprefixShortInt+32)\cdot256^{\llargeMO}$ + \item $\limbsize_{i-2}=1$ + \item $\limb_{i-1}=\col{input}\high_{i}$ + \item $\limbsize_{i-1}=\llarge$ + \item $\limb_{i}=\col{input}\low_{i}$ + \item $\limbsize_{i}=\llarge$ + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/rlp_txn/phase_constraints/_inputs.tex b/rlp_txn/phase_constraints/_inputs.tex new file mode 100644 index 0000000..ea1f2a2 --- /dev/null +++ b/rlp_txn/phase_constraints/_inputs.tex @@ -0,0 +1,9 @@ +\subsection{Global \rlp{} prefix (\phaseRlpPrefix)} \input{phase_constraints/rlp_prefix} +\subsection{\rlp-ization of the integers \texttt{chainId}, \texttt{nonce}, \texttt{gasPrice}, \texttt{maxProrityFeePerGas}, \texttt{maxFeePerGas}, \texttt{gasLimit} and \texttt{value} (\phaseChainId{}, \dots, \phaseGasLimit{} and \phaseValue{})} + \input{phase_constraints/int} +\subsection{\rlp-ization of \texttt{to} address (\phaseTo)} \input{phase_constraints/to_address} +\subsection{\rlp-ization of \texttt{data} (\phaseData)} \input{phase_constraints/data/_inputs} +\subsection{\rlp-ization of \texttt{access list} (\phaseAccessList)} \input{phase_constraints/access_list/_inputs} +\subsection{\rlp-ization of \texttt{beta} (\phaseBeta)} \input{phase_constraints/beta} +\subsection{\rlp-ization of \texttt{y} (\phaseY)} \input{phase_constraints/y} +\subsection{\rlp-ization of \texttt{r} and \texttt{s} (\phaseR{} and \phaseS)} \input{phase_constraints/r_and_s} diff --git a/rlp_txn/phase_constraints/access_list/_inputs.tex b/rlp_txn/phase_constraints/access_list/_inputs.tex new file mode 100644 index 0000000..884f3e9 --- /dev/null +++ b/rlp_txn/phase_constraints/access_list/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Introduction} \label{rlp_txn: phase constraints: access list: intro} \input{phase_constraints/access_list/intro} +\subsubsection{Constraints} \label{rlp_txn: phase constraints: access list: constraints} \input{phase_constraints/access_list/constraints} + diff --git a/rlp_txn/phase_constraints/access_list/constraints.tex b/rlp_txn/phase_constraints/access_list/constraints.tex new file mode 100644 index 0000000..89f944f --- /dev/null +++ b/rlp_txn/phase_constraints/access_list/constraints.tex @@ -0,0 +1,225 @@ +\begin{center} + \boxed{\text{Throughout this section it is assumed that $\phaseAccessList_{i}=1$.}} +\end{center} + +We remind the reader that $\nbAddr$, $\nStorageKeysInAccessList$, $\nStorageKeysInAccessEntry$, $\Depth1$ and $\Depth2$ are counter-constant (see \ref{constancy_constraints}). +\newline +Constraints on the end of the phase: +\begin{enumerate} + \item \If $\phasesize_{i} \ne 0$ \Then $\phasend_{i}=0$ + \item\label{constraint: end of access set phase} \If ($\phasesize_{i}=0$ \et $\done_{i}=1$) \Then $\phasend_{i}=1$. +\end{enumerate} +Constraint on $\outgoingDataSymb$ as $\nbAddr$ and $\nStorageKeysInAccessList$ are initialised at the begining of the phase: +\begin{enumerate}[resume] + \item \If $\phaseAccessList_{i-1}=0$ \Then: + \begin{enumerate} + \item $\outgoingDataSymb\high_{i}=\nStorageKeysInAccessList_{i}$ + \item $\outgoingDataSymb\low_{i}=\nbAddr_{i}$ + \item $\isprefix_{i}=1$ + \item $\Depth1_{i} = 0$ + \item $\Depth2_{i} = 0$ + \item $\Input1_{i} = \phasesize_{i}$ + \item \If $\nbAddr_{i}=0$ \Then: + \begin{enumerate} + \item $\nbstep_{i}=1$ + \item $\limb_{i}=\rlprefixShortList \cdot 256 ^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + \item \If $\nbAddr_{i} \ne 0$ \Then $\nbstep_{i}=8$ + \end{enumerate} +\end{enumerate} +We first compute the RLP prefix and in the case of an empty list, end the phase: +\begin{enumerate}[resume] + \item \If ($\Depth 1_{i}=0$ \et $\nbAddr_{i} \ne 0$) \Then: + \begin{enumerate} + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{10}; \\ + \accsize, + \Power, + \phaseAccessList, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=1$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=0$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +We now deal with an access list item. We first compute the RLP prefix of an access tuple: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i}=1$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=0$) \footnote{It is implemented \If $\isprefix_{i} \cdot \Depth1_{i} - \Depth2_{i}=1$ \Then:} \Then: + \begin{enumerate} + \item $\Input1_{i} = \col{ACCESS\_TUPLE\_BYTESIZE}_{i}$ + \item $\nbstep_{i}=8$ + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{10}; \\ + \accsize, + \Power, + \phaseAccessList, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=0$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=0$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +Then we compute the RLP of an address: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i}=0$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=0$) \footnote{It is implemented \If $\Depth1_{i} - \isprefix_{i} - \Depth2_{i}=1$ \Then:} \Then: + \begin{enumerate} + \item + \[ + \left\{ + \begin{array}{lcl} + \Input1_{i} & \!\!\! = \!\!\! & \col{Addr}^{hi}_{i} \\ + \Input2_{i} & \!\!\! = \!\!\! & \col{Addr}^{lo}_{i} \\ + \nbstep & \!\!\! = \!\!\! & 16 \vspace{2mm} \\ + \multicolumn{3}{l}{\texttt{rlpAddressConstraints}_{i}(\Input1, \Input2, \oli, \ct)} \\ + \end{array} + \right. + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=1$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +Then we compute the RLP prefix of the list of StorageKey in this access tuple: +\begin{enumerate}[resume] + + \item \If ($\isprefix_{i}=1$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=1$) \footnote{It is implemented \If $\isprefix_{i} \cdot \Depth1_{i} \cdot \Depth2_{i}=1$ \Then:} \Then: + + \begin{enumerate} + \item \If $\nStorageKeysInAccessEntry_{i}=0$ \Then: + \begin{enumerate} + \item $\nbstep_{i}=1$ + \item $\limb_{i}=\rlprefixShortList \cdot 256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + \item \If $\nStorageKeysInAccessEntry_{i} \ne 0$ \Then: + \item $\nbstep_{i}=8$ + \item $\Input1_{i} = 33\cdot\nStorageKeysInAccessEntry_{i} \footnote{As a storage key in 32 bytes long, RLP(StorageKey) is 33 bytes long.}$ + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{10}; \\ + \accsize, + \Power, + \phaseAccessList, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \end{enumerate} +\end{enumerate} +Then, if relevant, we compute the RLP of a StorageKey: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i}=0$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=1$)\footnote{It is implemented \If $\Depth1_{i} \cdot \Depth2_{i} - \isprefix_{i}=1$ \Then:} \linebreak \Then $\texttt{rlpStorageKeyConstraints}_{i}(\Input1, \Input2, \ct)$ +\end{enumerate} +Hereafter we give the condition on the step to do after computing the RLP prefix of the list of StorageKey, or the RLP of a StorageKey. It is either compute a RLP(StorageKey) if $\nStorageKeysInAccessEntry_{i} \ne 0$, a RLP(access tuple) if ($\nStorageKeysInAccessEntry_{i} = 0$ and $\nbAddr \ne 0$), ot the end of the phase if $\nbAddr_{i}=\nStorageKeysInAccessList_{i}=0$: +\begin{enumerate}[resume] + \item \If ($\Depth2_{i}=1$ \et $\done_{i}=1$) \Then: + \begin{enumerate} + \item \If $\nStorageKeysInAccessEntry_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=0$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=1$ + \end{enumerate} + \item \If $\nStorageKeysInAccessEntry_{i}=0$ \Then: + \begin{enumerate} + \item $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=0$ + \item \If $\nbAddr_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=1$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=0$ + \end{enumerate} + \item \trash We remind the reader of constraint~\ref{constraint: end of access set phase}. At this point, $\phasesize_{i}=0$ is equivalent to ($\nbAddr_{i} = 0$ and $\nStorageKeysInAccessList_{i}=0$), so the phase ends. + \end{enumerate} + \end{enumerate} +\end{enumerate} +Here we define initialisation and decrementation of $\phasesize$, $\col{ACCESS\_TUPLE\_BYTESIZE}$, $\nbAddr$, $\nStorageKeysInAccessList$ and $\nStorageKeysInAccessEntry$. +\begin{enumerate}[resume] + \item \If $\Depth1_{i}=0$ \Then $\phasesize_{i} = \phasesize_{i+1}$. + \item \If $\Depth1_{i}=1$ \Then $\phasesize_{i} = \phasesize_{i-1} - \lc_{i} \cdot \limbsize_{i}$. +\end{enumerate} +In other words $\phasesize$ is initialized at the begining of $\phase{10}$ and then decreased by the number of bytes in the $\limb$ when $\lc$ is nonzero. +\begin{enumerate}[resume] + + \item \If ($\Depth1_{i}=1$ \et ($\isprefix_{i}=0$ \Or $\Depth2_{i}=1$) \footnote{It is implemented \If $\isprefix_{i} \cdot (1 - \Depth2_{i})=0$ \Then} \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=\col{ACCESS\_TUPLE\_BYTESIZE}_{i-1} - \lc_{i} \cdot \limbsize_{i}$ + +\end{enumerate} +In other words $\col{ACCESS\_TUPLE\_BYTESIZE}$ is initialized at the begining of an access tuple loop, with initialisation value only depending on the value of $\nStorageKeysInAccessEntry$ +\footnote{The bytesize of an access tuple is 21 (20 for address + 1 for its RLP prefix) + RLP of the list of StorageKey (from 1 to 4 depending of the length of the bytesize of the list of StorageKeys) + 33 per StorageKeys (32 + 1 for its RLP prefix). The RLP prefix of the list of StorageKey is computed when $\isprefix = 1$, $\Depth 1 =1$ and $\Depth 2 = 1$ thus constraining the value of $\col{ACCESS\_TUPLE\_BYTESIZE}$. +\begin{enumerate} + \item \If $\nStorageKeysInAccessEntry_{i}=0$ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=(1+20) + 1$ + \item \If $\nStorageKeysInAccessEntry_{i}=1$ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=(1+20) + 1 + (1+32)$ + \item \If $\nStorageKeysInAccessEntry_{i} \in [\![ 2 ; 7 ]\!] $ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}= (1+20) + 2 + (1+32) \cdot \nStorageKeysInAccessEntry$ + \item \If $\nStorageKeysInAccessEntry_{i} \in [\![ 8 ; 1985 ]\!]$ \footnote{In this case the bytesize of $\nStorageKeysInAccessEntry$ RLP(StorageKey) is a two bytes integer.} \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}= (1+20) + 3 + (1+32) \cdot \nStorageKeysInAccessEntry$ + \item \If $\nStorageKeysInAccessEntry_{i} \in [\![ 1986 ; 508400]\!]$ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}= (1+20) + 4 + (1+32) \cdot \nStorageKeysInAccessEntry$ +\end{enumerate} +} +and decreased by the number of bytes in the $\limb$ when $\lc$ is nonzero during the loop (except during the access tuple RLP prefix). +\newline +For the following, we remind the reader that $\nbAddr$, $\nStorageKeysInAccessList$ and $\nStorageKeysInAccessEntry$ are $\ct$-constant (see \ref{constancy_constraints}). +\begin{enumerate}[resume] + \item \If ($\Depth1_{i}=1$ \et $\ct_{i}=0$) \Then $\nbAddr_{i} = \nbAddr_{i-1} - \isprefix_{i} \cdot (1 - \Depth2_{i})$ +\end{enumerate} +In other words, $\nbAddr$ is initialized at the begining of the phase, and then decrease by one at the begining of each RLP(access tuple). +\begin{enumerate}[resume] + \item \If ($\Depth1_{i}=1$ \et $\ct_{i}=0$) \Then $\nStorageKeysInAccessList_{i} = \nStorageKeysInAccessList_{i-1} - (1- \isprefix_{i}) \cdot \Depth2_{i}$ +\end{enumerate} +In other words, $\nStorageKeysInAccessList$ is initialized at the begining of the phase, and then decrease by one at the begining of each RLP(Sto). +\begin{enumerate}[resume] + \item \If (($\isprefix_{i}=0$ \Or $\Depth2_{i}=1$) \et $\ct_{i}=0$) \footnote{It is implemented \If $\isprefix_{i} \cdot (\Depth2_{i}-1) +\ct_{i} =0$ \Then} \Then $\nStorageKeysInAccessEntry_{i} = \nStorageKeysInAccessEntry_{i-1} - (1- \isprefix_{i}) \cdot \Depth2_{i})$ +\end{enumerate} +In other words$\nStorageKeysInAccessEntry$ is initialized at the begining of an access tuple loop, and then decrease by one at the begining of each RLP(Sto). +\begin{enumerate}[resume] + \item \If ($\Depth1_{i}=0$ \et $\nbAddr_{i}=\nbAddr_{i-1}$) \Then + \begin{enumerate} + \item $\col{Addr}\high_{i} = \col{Addr}\high_{i-1}$ + \item $\col{Addr}\low_{i} = \col{Addr}\low_{i-1}$ + \end{enumerate} +\end{enumerate} +In other words $\col{Addr}\high$ and $\col{Addr}\low$ are constant all along an AccessTuple. + diff --git a/rlp_txn/phase_constraints/access_list/intro.tex b/rlp_txn/phase_constraints/access_list/intro.tex new file mode 100644 index 0000000..87e54f5 --- /dev/null +++ b/rlp_txn/phase_constraints/access_list/intro.tex @@ -0,0 +1,34 @@ +The \textbf{accessList} $T_\textbf{A}$ is a list of \textbf{access entries} $E \equiv (E_\text{a}, E_\textbf{s})$ comprised of an address $E_\text{a}$ and a (possibly empty) list of $E_\textbf{s}$ of storage keys. +We provide the desired interpretation of some columns pertinent to the current phase: +\[ + \left\{ \begin{array}{lclcl} + \nbAddr & \equiv & \| T_\textbf{A} \| \vspace{1mm} \\ + \nStorageKeysInAccessEntry & \equiv & \| T_\textbf{A}[j]_\textbf{s} \| \vspace{1mm} \quad = \quad |E_\textbf{s}| \\ + \nStorageKeysInAccessList & \equiv & \sum_{j = 0}^{\| T_\textbf{A} \| - 1} \| T_\textbf{A}[j]_\textbf{s} \| \\ + \end{array} \right. +\] +In this phase, we start by computing the \textbf{accessList} \rlp{} prefix (number of bytes given by $\phasesize$, and then we do $\nbAddr$ access tuple item loops. +An access tuple loop is composed of : +\begin{enumerate} + \item access tuple \rlp{} prefix (number of bytes given by $\col{ACCESS\_TUPLE\_BYTESIZE}$) + \item Address \rlp{} + \item List of StorageKey \rlp{} prefix + \item If relevant, $\nStorageKeysInAccessEntry$ loops over StorageKey \rlp{}s +\end{enumerate} +The general loop intrication is resumed in the next table. +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|c|} \hline + \isprefix & $\Depth1$ & \Depth2 & \nbAddr & $\nStorageKeysInAccessList$ & \nStorageKeysInAccessEntry & Action \\ \hline + 1 & 0 & 0 & init & init & 0 & \rlp{} prefix of \textbf{accessList} \\ \hline \hline + 1 & 1 & 0 & & & 0 & \rlp{} prefix of an access tuple \\ \hline + 0 & 1 & 0 & -=1 & & 0 & \rlp{}(Addr) \\ \hline + 1 & 1 & 1 & & & init & \rlp{} prefix of (Sto 1, Sto2, ...) \\ \hline + 0 & 1 & 1 & & -=1 & -=1 & \rlp{}($Sto_{1}$) \\ + 0 & 1 & 1 & & : & : & : \\ + 0 & 1 & 1 & & -=1 & 0 & \rlp{}($Sto_{n}$) \\ \hline + : & : & : & : & : & : & : \\ \hline + 0 or 1 & 1 & 1 & 0 & 0 & 0 & $\rightsquigarrow$ end phase \\ \hline + \end{tabular} + \caption{Loop structure} +\end{table} diff --git a/rlp_txn/phase_constraints/beta.tex b/rlp_txn/phase_constraints/beta.tex new file mode 100644 index 0000000..a8f9754 --- /dev/null +++ b/rlp_txn/phase_constraints/beta.tex @@ -0,0 +1,111 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phaseBeta_{i}=1$.}} +\end{center} + +We first compute $\mathtt{RLP}(w)$ which is in $\widetilde{L}_{\mathrm{T}}(T)$ only: +\begin{enumerate} + \item \If $\phaseBeta_{i-1}=0$ \Then: + \begin{enumerate} + \item $\lt_{i}=1$ + \item $\lx_{i}=0$ + \item $\nbstep_{i}=8$ + \end{enumerate} + \item \If ($\lt_{i}=1$ \et $\lx_{i}=0$) + \begin{enumerate} + \item + \[ + \rlpPrefixInt_{i} + \left( \begin{array}{r} + \Input{1}, + \ct, + \nbstep, + \done; \\ + \byteCol{1}, + \acc{1}, + \accsize, + \Power, + \genBit, + \genBit; \\ + \limb, + \lc, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item + \[ + \limbShifting + \left( \begin{array}{r} + \Input 1_{i}, + \Power_{i}, + \accsize_{i}; \\ + \limb_{i}, + \limbsize_{i}; \\ + \end{array} \right) + \] + \item $\ispadding_{i}=0$ + \item $\Input 1_{i} = 27$ \Or $\Input 1_{i} = 28$ \footnote{It is implemented \If $(\Input 1 _{i} -27)^{2} = (\Input 1 _{i} -27)$ \Then:} \Then: + \begin{enumerate} + \item $\phasend_{i}=1$ + \end{enumerate} + \item $\Input 1_{i} \neq 27$ \et $\Input 1_{i} \neq 28$ \Then: + \begin{enumerate} + \item $\phasend_{i}=0$ + \item $\lt_{i+1}=0$ + \item $\lx_{i+1}=1$ + \item $\isprefix_{i+1}=1$ + \end{enumerate} + \end{enumerate} + \end{enumerate} +\end{enumerate} +We now compute the postfix of $\widetilde{L}_{\mathrm{X}}(T)$ which is $\mathtt{RLP}(\beta) \cdot \mathtt{RLP}(\varnothing) \cdot \mathtt{RLP}(\varnothing)$ when $\beta = ChainId$ is different to 0 (equivalently $w \notin \{27 , 28 \}$.) +\begin{enumerate}[resume] + \item \If ($\lx_{i}=1$ \et $\isprefix_{i}=1$) \Then: + \begin{enumerate} + \item $\nbstep_{i}=8$ + \item + \[ + \rlpPrefixInt_{i} + \left( \begin{array}{r} + \Input{1}, + \ct, + \nbstep, + \done; \\ + \byteCol{1}, + \acc{1}, + \accsize, + \Power, + \genBit, + \genBitAcc; \\ + \limb, + \lc, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item + \[ + \limbShifting + \left( \begin{array}{r} + \Input 1_{i}, + \Power_{i}, + \accsize_{i}; \\ + \limb_{i}, + \limbsize_{i}; \\ + \end{array} \right) + \] + \item $\ispadding_{i}=0$ + \item $\phasend_{i}=0$ + \item $\isprefix_{i+1}=0$ + \item $\nbstep_{i+1}=1$ + \item $\lt_{i+1}=0$ + \item $\lx_{i+1}=1$ + \item $\ispadding_{i+1}=0$ + \item $\limb_{i+1}=\rlprefixShortInt \cdot 256^{15} + \rlprefixShortInt \cdot 256^{14}$ + \item $\limbsize_{i+1}=2$ + \item $\phasend_{i+1}=1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/phase_constraints/data/_inputs.tex b/rlp_txn/phase_constraints/data/_inputs.tex new file mode 100644 index 0000000..1168943 --- /dev/null +++ b/rlp_txn/phase_constraints/data/_inputs.tex @@ -0,0 +1,3 @@ +\subsubsection{Introduction} \input{phase_constraints/data/intro} +\subsubsection{Constraints} \input{phase_constraints/data/constraints} + diff --git a/rlp_txn/phase_constraints/data/constraints.tex b/rlp_txn/phase_constraints/data/constraints.tex new file mode 100644 index 0000000..d0b2607 --- /dev/null +++ b/rlp_txn/phase_constraints/data/constraints.tex @@ -0,0 +1,153 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phaseData_{i}=1$.}} +\end{center} + +We remind the reader that $\ispadding$ is $\ct$-constant, and $\isprefix$ is $\ct$-constant and $\phase9$-decrementing(see \ref{constancy_constraints}). +\begin{enumerate} + \item \If $\isprefix_{i}=1$ \Then $\indexData_{i}=0$ + \item \If $\isprefix_{i}=0$ \Then: + \begin{enumerate} + \item \If ($\isprefix_{i-1}=0$ \et ($\lc_{i-1}=1$ or $\ispadding_{i-1}=1$)) \Then $\indexData_{i}=\indexData_{i-1} + 1$ + \item \Else $\indexData_{i}=\indexData_{i-1}$ + \end{enumerate} +\end{enumerate} +In other words, $\indexData$ starts at 0 and increases by one after a $\limb$ is constructed during the data concatenation phase or after a padding row. %It is equivalent to $\indexData_{i} = (1 - \isprefix_{i}) \cdot (\indexData_{i-1} + (1 - \isprefix_{i-1}) \cdot \lc_{i-1} + \ispadding_{i-1})$. Note that this column is useful only to reconstruct the data. +\begin{enumerate}[resume] + \item \If $\ispadding_{i} = 0$ \Or $\isprefix_{i}=1$ \Then $\phasend_{i}=0$. In other words we prevent a phase transition before the padding rows. + \item \If ($\isprefix_{i}=0$ \et $\ispadding_{i} = 1$ \et $\done_{i}=1$) \Then $\phasend_{i}=1$ + \item \If $\phaseData_{i-1}=0$ \Then: + Constraint on $\outgoingDataSymb$ as DataSize and DataCost are initialised at the begining of the phase: + \begin{enumerate} + \item $\outgoingDataSymb\high_{i}=\dataGasCost_{i}$ + \item $\outgoingDataSymb\low_{i}=\phasesize_{i}$ + \end{enumerate} + We define the trivial case with no data: + \begin{enumerate}[resume] + \item $\isprefix_{i}=1$ + \item \If $\phasesize_{i}=0$ \Then $\nbstep_{i}=1$ + \item \If $\phasesize_{i} \ne 0$ \Then $\nbstep_{i}=8$ + \end{enumerate} +\end{enumerate} +We constrain the trivial case: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i} \ne 0$ \et $\nbstep_{i} \ne 8$) \Then: + \begin{enumerate} + \item $\limb_{i}=\rlprefixShortInt \cdot 256 ^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \item $\ispadding_{i} =0$ + \item $\isprefix_{i+1}=0$ + \item $\ispadding_{i+1}=1$ + \item $\nbstep_{i+1}=1$ + \saNote{} We remind the reader that, as $\nbstep_{i+1}=1$, then $\done_{i+1}=1$ and then $\phasend_{i+1}=1$. + \end{enumerate} +\end{enumerate} +We constrain the general case, we first compute the RLP prefix: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i} \ne 0$ \et $\nbstep_{i} \ne 1$) \Then + \begin{enumerate} + \item $\phasesize_{i} = \phasesize_{i+1}$ + \item $\dataGasCost_{i} = \dataGasCost_{i+1}$ + \item \If $\phasesize_{i} = 1$ \Then + \begin{enumerate} + \item + \[ + \rlpPrefixInt + \left( \begin{array}{r} + \Input2, + \ct, + \nbstep, + \done; \\ + \byteCol1, + \acc1, + \accsize, + \Power, + \genBit, + \genBitAcc; \\ + \limb, + \lc, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\ct_{i} \ne \nbstep_{i}-2$ \Then $\lc_{i}=0$ + \item \If $\done_{i}=1$ \Then + \begin{itemize} + \item $\ispadding_{i-1} + \ispadding_{i} = 1$ + \item $\Input1_{i+1} = \Input1_{i} \cdot 256^{\llargeMO}$ + \end{itemize} + \end{enumerate} + \item \If $\phasesize_{i} \ne 1$ \Then: + \begin{enumerate} + \item $\phasesize_{i} = \Input1_{i}$ + \item $\ispadding_{i}=0$ + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{0}; \\ + \accsize, + \Power, + \phaseRlpPrefix, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\Done_{i}=0$ \et $\ct_{i} \ne \nbstep_{i}-2$ \Then $\lc_{i}=0$ + \end{enumerate} + \item \If $\done_{i}=1$ \Then + \begin{itemize} + \item $\isprefix_{i+1}=0$ + \item $\ispadding_{i+1}=0$ + \end{itemize} + \end{enumerate} + \item \If ($\isprefix_{i}=0$ \et $\ispadding_{i}=0$ \Then + \begin{enumerate} + \item $\nbstep_{i}=\llarge$ + \item \If $\phasesize_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\phasesize_{i+1}=\phasesize_{i}-1$ + \item \If $\byteCol{1}_{i}=0$ \Then $\dataGasCost_{i+1} = \dataGasCost_{i} - G_{\mathrm{txdatazero}}$ + \item \If $\byteCol{1}_{i} \ne 0$ \Then $\dataGasCost_{i+1} = \dataGasCost_{i} - G_{\mathrm{txdatanonzero}}$ \footnote{Define in the EYP, $G_{\mathrm{txdatanonzero}}=16$ and $G_{\mathrm{txdatazero}}=4$} + \end{enumerate} + \item \If $\phasesize_{i}=0$ \Then + \begin{enumerate} + \item $\phasesize_{i + 1} = \phasesize_{i}$ + \item $\dataGasCost_{i + 1} = \dataGasCost_{i}$ + \end{enumerate} + \item \If $\ct_{i}=0$ \Then $\accsize_{i}= 1$ + \item \If $\ct_{i} \ne 0$ \Then + \begin{enumerate} + \item \If $\phasesize_{i} \ne 0$ \Then $\accsize_{i}=\accsize_{i-1}+1$ + \item \If $\phasesize_{i}=0$ \Then: + \begin{itemize} + \item $\accsize_{i}=\accsize_{i-1}$ + \item $\byteCol{1}_{i}=0$ + \end{itemize} + \end{enumerate} + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\ispadding_{i}=0$ + \item $\lc_{i-1}=0$ + \item $\acc{1}_{i} = \Input1_{i}$ + \item $\limb_{i} = \Input1_{i}$ + \item $\limbsize_{i}=\accsize_{i}$ + \item \If $\phasesize_{i} \in \{0, 1\}$ \footnote{It is implemented \If $\phasesize_{i}^{2} = \phasesize_{i}$ \Then:} \Then: + \begin{itemize} + \item $\nbstep_{i+1}=2$ + \item $\ispadding_{i+1} = 1$ + \item $\phasesize_{i + 1} = \phasesize_{i+2}$ + \item $\dataGasCost_{i + 1} = \dataGasCost_{i+2}$ + \end{itemize} + \item \If ($\phasesize_{i} \ne 1$ \et $\phasesize_{i} \ne 0$) \footnote{It is implemented \If $\phasesize_{i}^{2} \ne \phasesize_{i}$ \Then:} \Then + \begin{itemize} + \item $\ispadding_{i+1} = 0$ + \end{itemize} + \end{enumerate} + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/phase_constraints/data/intro.tex b/rlp_txn/phase_constraints/data/intro.tex new file mode 100644 index 0000000..8f4f5bf --- /dev/null +++ b/rlp_txn/phase_constraints/data/intro.tex @@ -0,0 +1,37 @@ +The \rlp{}-ization of data, when present, proceeds through three distinct phases. +The first phase occupies 8 rows and computes the \rlp{} prefix of the data slice; this phase is characterized by $\isprefix=1$ and $\ispadding=0$. +The second phase is a succession of $\llarge$-row loops where the data bytes are concatenated into $\llarge$-byte data limbs; this phase is characterized by $\isprefix=0$ and $\ispadding=0$. +The third phase occupies two rows and pertains to padding; it is characterized by $\ispadding=1$. +With each row of the concatenation the $\phasesize$ decrements by one until it reaches $0$\footnote{Decrementing \textbf{after} the row implies that if $\phasesize \equiv 0 \pmod{\llarge}$ then $\phasesize$ will be equal to one on the last row of the concatenation loop.} + +When the transaction provides no data payload to \rlp{}-ize the arithmetization of that phase occupies a single row for the insertion of $\rlp(\varnothing)$ followed by one row of padding. +The table below is a depiction of the nontrivial case i.e. the case where data is present. +\begin{figure} +\[ + \renewcommand{\arraystretch}{1.5} + \begin{array}{|c|c|c|c|c|c|} \hline + \isprefix & \ispadding & \ct & \phasesize & \lc & \indexData \\ \hline + 1 & 0 & 0 & init & 0 & 0 \\ \hline + \vdots & \vdots & \vdots & & \vdots & \vdots \\ \hline + \vdots & \vdots & 6 & & 0 & 0 \\ \hline + 1 & \vdots & 7 & & 1 & 0 \\ \hline \hline \hline + 0 & \vdots & 0 & -=1 & 0 & 0 \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \vdots & \vdots & 15 & \vdots & 1 & 0 \\ \hline \hline + \vdots & \vdots & 0 & \vdots & 0 & 1 \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \vdots & \vdots & 15 & \vdots & 1 & 1 \\ \hline \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline \hline + \vdots & \vdots & 0 & \vdots & 0 & init // 16 \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \vdots & \vdots & \vdots & -=1 & \vdots & \vdots \\ \hline + \vdots & \vdots & (init \% 16) -1 & 0 & \vdots & \vdots \\ \hline + \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline + \vdots & 0 & 15 & 0 & 1 & init // 16 \\ \hline \hline \hline + \vdots & 1 & 0 & 0 & 0 & (init // 16)+1 \\ \hline + 0 & 1 & 1 & 0 & 0 & (init // 16)+2 \\ \hline + \end{array} +\] +\caption{Loop structure for \ob{TODO}} +\label{Phase 9 loop} +\end{figure} diff --git a/rlp_txn/phase_constraints/definition.tex b/rlp_txn/phase_constraints/definition.tex new file mode 100644 index 0000000..6a58606 --- /dev/null +++ b/rlp_txn/phase_constraints/definition.tex @@ -0,0 +1,26 @@ +Each phase represents an entry of the transaction list to RLPised, as described in the yellow paper. \phaseRlpPrefix{} is the phase where the $\transactionType$ of transaction, concatanated with the RLP prefix of the total list is computed. Not all phases are accessible for any transaction type. On a same phase will occur the same treatment, independently of the transaction type. For the majority of $\col{PHASE}$ we have $\lx = \lt =1$ which means the constructed $\limb$ is both in $\widetilde{L}_{\mathrm{T}}(T)$ and in $\widetilde{L}_{\mathrm{X}}(T)$. In \phaseRlpPrefix{} and \phaseBeta{}, some $\limb$ are in $\widetilde{L}_{\mathrm{T}}(T)$, some in $\widetilde{L}_{\mathrm{X}}(T)$, some in both. We write it $\lt (resp. \lt) \in \{0 ; 1\}$ in the next table. In \phaseY{}, \phaseR{} and in \phaseS{}, the $\limb$ is only in $\widetilde{L}_{\mathrm{T}}(T)$. The table \ref{tab:Phase definition} shows accessible phases for every transaction \transactionType. + +{\renewcommand{\arraystretch}{1.5} +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|c|c|c|} \hline + \phase{\#} & Description & \transactionType=0 & \transactionType=1 & \transactionType=2 & $\lt$ & $\lx$ \\ \hline \hline + $\phaseRlpPrefixValue$ & \rlp{} prefix & \checkmark & \checkmark & \checkmark & \{0 ; 1\} & \{0 ; 1\} \\ \hline + $\phaseChainIdValue$ & \textbf{chainId} & & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseNonceValue$ & \textbf{nonce} & \checkmark & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseGasPriceValue$ & \textbf{gasPrice} & \checkmark & \checkmark & & 1 & 1 \\ \hline + $\phaseMaxPriorityFeePerGasValue$ & \textbf{maxPriorityFeePerGas} & & & \checkmark & 1 & 1 \\ \hline + $\phaseMaxFeePerGasValue$ & \textbf{maxFeePerGas} & & & \checkmark & 1 & 1 \\ \hline + $\phaseGasLimitValue$ & \textbf{gasLimit} & \checkmark & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseToValue$ & \textbf{to} & \checkmark & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseValueValue$ & \textbf{value} & \checkmark & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseDataValue$ & \textbf{data} & \checkmark & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseAccessListValue$ & \textbf{accessList} & & \checkmark & \checkmark & 1 & 1 \\ \hline + $\phaseBetaValue$ & $\beta$ or w & \checkmark & & & \{0 ; 1\} & \{0 ; 1\} \\ \hline + $\phaseYValue$ & \textbf{yParity} & & \checkmark & \checkmark & 1 & 0 \\ \hline + $\phaseRValue$ & \textbf{r} & \checkmark & \checkmark & \checkmark & 1 & 0 \\ \hline + $\phaseSValue$ & \textbf{s} & \checkmark & \checkmark & \checkmark & 1 & 0 \\ \hline + \end{tabular} + \caption{Phase definition} + \label{tab:Phase definition} +\end{table}} diff --git a/rlp_txn/phase_constraints/int.tex b/rlp_txn/phase_constraints/int.tex new file mode 100644 index 0000000..35288a4 --- /dev/null +++ b/rlp_txn/phase_constraints/int.tex @@ -0,0 +1,74 @@ +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\sum_{\substack{ \phaseChainId \leq k \leq \phaseGasLimit }} \phase{k}_{i} + \phaseValue_{i} = 1$.}} +\end{center} + +This phase computes \rlp($\Input 1$) where $\Input 1$ is an integer. +Let Max number of Bytes as given in the following table. We assume all entries can be written on up to 8 bytes ($\approx 10^{19}$), except the value (phase 8) who can be written in 16 bytes. \footnote{ChainId can be arbitrary great, but we assume it will be a 8 bytes integer.} + +\begin{table}[h] + \renewcommand{\arraystretch}{1.3} + \centering + \begin{tabular}{|c|c|c|} \hline + Phase & Name & Max number of Bytes \\ \hline + 1 & ChainID & 8 \\ \hline + 2 & nonce & 8 \\ \hline + 3 & GasPrice & 8 \\ \hline + 4 & MaxPriorityFeePerGas & 8 \\ \hline + 5 & MaxFeePerGas & 8 \\ \hline + 6 & GasLimit & 8 \\ \hline + 8 & Value & 16 \\ \hline + \end{tabular} +\end{table} + +\begin{enumerate} + \item \If $\Input1 = 0$ \Then: + \begin{enumerate} + \item $\nbstep = 1$ + \item $\limb_{i} = \rlprefixShortInt \cdot 256 ^{\llargeMO}$ + \item $\limbsize_{i} = 1$ + \end{enumerate} + \item \If $\Input1 \ne 0$ \Then: + \begin{enumerate} + \item $\nbstep_{i} = 8 \cdot (\sum_{k = \phaseChainIdValue}^{\phaseGasLimitValue} \phase{k}_{i}) + \llarge \cdot \phaseValue_{i}$ + \item + \[ + \rlpPrefixInt_{i} + \left( + \begin{array}{r} + \Input{1}, + \ct, + \nbstep, + \done; \\ + \byteCol{1}, + \acc{1}, + \accsize, + \Power, + \genBit, + \genBitAcc; \\ + \limb, + \lc, + \limbsize; \\ + \end{array} + \right) + \] + \item \If $\done_{i} = 1$ \Then: + \[ + \limbShifting + \left( + \begin{array}{r} + \Input 1_{i}, + \Power_{i}, + \accsize_{i}; \\ + \limb_{i}, + \limbsize_{i}; \\ + \end{array} + \right) + \] + \end{enumerate} + \item \If $\Done_{i} = 1$ \Then: + \begin{enumerate} + \item $\phasend_{i} = 1$. + \item \If $\phaseNonce_{i} + \phaseGasPrice_{i} + \phaseMaxFeePerGas_{i} + \phaseGasLimit_{i} + \phaseValue_{i} = 1$ \Then $\outgoingDataSymb\low_{i} = \Input1_{i}$ + \item \If $\phaseMaxPriorityFeePerGas_{i} = 1$ \Then $\outgoingDataSymb\high_{i + 1} = \Input1_{i}$ + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/phase_constraints/phaseAccessList.tex b/rlp_txn/phase_constraints/phaseAccessList.tex new file mode 100644 index 0000000..3d76c64 --- /dev/null +++ b/rlp_txn/phase_constraints/phaseAccessList.tex @@ -0,0 +1,252 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phaseAccessList_{i}=1$.}} +\end{center} + +\subsubsection{Introduction} +The AccessList is a list of access tuple, where an access tuple is a list containing two items: an address, and a (possibly empty) list of StorageKey. We have $\nbAddr$ access tuple in the AccessList, $\nbStoPerAddr$ StorageKeys for each access tuple, and $\nbSto=\sum_{access tuple} \nbStoPerAddr$. In this phase, we start by computing the AccessList RLP prefix (number of bytes given by $\phasesize$, and then we do $\nbAddr$ access tuple item loops. An access tuple loop is composed of : +\begin{enumerate} + \item access tuple RLP prefix (number of bytes given by $\col{ACCESS\_TUPLE\_BYTESIZE}$) + \item Address RLP + \item List of StorageKey RLP prefix + \item If relevant, $\nbStoPerAddr$ loops over StorageKey RLPs +\end{enumerate} +The general loop intrication is resumed in the next table. +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|c|} \hline + \isprefix & $\Depth1$ & \Depth2 & \nbAddr & \nbSto & \nbStoPerAddr & Action \\ \hline + 1 & 0 & 0 & init & init & 0 & RLP prefix of AccessList \\ \hline \hline + 1 & 1 & 0 & & & 0 & RLP prefix of an access tuple \\ \hline + 0 & 1 & 0 & -=1 & & 0 & RLP(Addr) \\ \hline + 1 & 1 & 1 & & & init & RLP prefix of (Sto 1, Sto2, ...) \\ \hline + 0 & 1 & 1 & & -=1 & -=1 & RLP($Sto_{1}$) \\ + 0 & 1 & 1 & & : & : & : \\ + 0 & 1 & 1 & & -=1 & 0 & RLP($Sto_{n}$) \\ \hline + : & : & : & : & : & : & : \\ \hline + 0 or 1 & 1 & 1 & 0 & 0 & 0 & $\rightsquigarrow$ end phase \\ \hline + \end{tabular} + \caption{Loop intrication} +\end{table} + + +\subsubsection{Phase's constraints} +We remind the reader that $\nbAddr$, $\nbSto$, $\nbStoPerAddr$, $\Depth1$ and $\Depth2$ are counter-constant (see \ref{constancy_constraints}). +\newline +Constraints on the end of the phase: +\begin{enumerate} + \item \If $\phasesize_{i} \ne 0$ \Then $\phasend_{i}=0$ + \item\label{constraint: end of access set phase} \If ($\phasesize_{i}=0$ \et $\done_{i}=1$) \Then $\phasend_{i}=1$. +\end{enumerate} +Constraint on $\outgoingDataSymb$ as $\nbAddr$ and $\nbSto$ are initialised at the begining of the phase: +\begin{enumerate}[resume] + \item \If $\phaseAccessList_{i-1}=0$ \Then: + \begin{enumerate} + \item $\outgoingDataSymb\high_{i}=\nbSto_{i}$ + \item $\outgoingDataSymb\low_{i}=\nbAddr_{i}$ + \item $\isprefix_{i}=1$ + \item $\Depth1_{i} = 0$ + \item $\Depth2_{i} = 0$ + \item $\Input1_{i} = \phasesize_{i}$ + \item \If $\nbAddr_{i}=0$ \Then: + \begin{enumerate} + \item $\nbstep_{i}=1$ + \item $\limb_{i}=\rlprefixShortList \cdot 256 ^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + \item \If $\nbAddr_{i} \ne 0$ \Then $\nbstep_{i}=8$ + \end{enumerate} +\end{enumerate} +We first compute the RLP prefix and in the case of an empty list, end the phase: +\begin{enumerate}[resume] + \item \If ($\Depth 1_{i}=0$ \et $\nbAddr_{i} \ne 0$) \Then: + \begin{enumerate} + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{10}; \\ + \accsize, + \Power, + \phaseAccessList, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=1$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=0$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +We now deal with an access list item. We first compute the RLP prefix of an access tuple: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i}=1$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=0$) \footnote{It is implemented \If $\isprefix_{i} \cdot \Depth1_{i} - \Depth2_{i}=1$ \Then:} \Then: + \begin{enumerate} + \item $\Input1_{i} = \col{ACCESS\_TUPLE\_BYTESIZE}_{i}$ + \item $\nbstep_{i}=8$ + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{10}; \\ + \accsize, + \Power, + \phaseAccessList, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=0$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=0$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +Then we compute the RLP of an address: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i}=0$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=0$) \footnote{It is implemented \If $\Depth1_{i} - \isprefix_{i} - \Depth2_{i}=1$ \Then:} \Then: + \begin{enumerate} + \item + \[ + \left\{ + \begin{array}{lcl} + \Input1_{i} & \!\!\! = \!\!\! & \col{Addr}^{hi}_{i} \\ + \Input2_{i} & \!\!\! = \!\!\! & \col{Addr}^{lo}_{i} \\ + \nbstep & \!\!\! = \!\!\! & 16 \vspace{2mm} \\ + \multicolumn{3}{l}{\texttt{rlpAddressConstraints}_{i}(\Input1, \Input2, \oli, \ct)} \\ + \end{array} + \right. + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=1$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +Then we compute the RLP prefix of the list of StorageKey in this access tuple: +\begin{enumerate}[resume] + + \item \If ($\isprefix_{i}=1$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=1$) \footnote{It is implemented \If $\isprefix_{i} \cdot \Depth1_{i} \cdot \Depth2_{i}=1$ \Then:} \Then: + + \begin{enumerate} + \item \If $\nbStoPerAddr_{i}=0$ \Then: + \begin{enumerate} + \item $\nbstep_{i}=1$ + \item $\limb_{i}=\rlprefixShortList \cdot 256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + \item \If $\nbStoPerAddr_{i} \ne 0$ \Then: + \item $\nbstep_{i}=8$ + \item $\Input1_{i} = 33\cdot\nbStoPerAddr_{i} \footnote{As a storage key in 32 bytes long, RLP(StorageKey) is 33 bytes long.}$ + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{10}; \\ + \accsize, + \Power, + \phaseAccessList, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \end{enumerate} +\end{enumerate} +Then, if relevant, we compute the RLP of a StorageKey: +\begin{enumerate}[resume] + \item \If ($\isprefix_{i}=0$ \et $\Depth1_{i}=1$ \et $\Depth2_{i}=1$)\footnote{It is implemented \If $\Depth1_{i} \cdot \Depth2_{i} - \isprefix_{i}=1$ \Then:} \linebreak \Then $\texttt{rlpStorageKeyConstraints}_{i}(\Input1, \Input2, \ct)$ +\end{enumerate} +Hereafter we give the condition on the step to do after computing the RLP prefix of the list of StorageKey, or the RLP of a StorageKey. It is either compute a RLP(StorageKey) if $\nbStoPerAddr_{i} \ne 0$, a RLP(access tuple) if ($\nbStoPerAddr_{i} = 0$ and $\nbAddr \ne 0$), ot the end of the phase if $\nbAddr_{i}=\nbSto_{i}=0$: +\begin{enumerate}[resume] + \item \If ($\Depth2_{i}=1$ \et $\done_{i}=1$) \Then: + \begin{enumerate} + \item \If $\nbStoPerAddr_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=0$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=1$ + \end{enumerate} + \item \If $\nbStoPerAddr_{i}=0$ \Then: + \begin{enumerate} + \item $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=0$ + \item \If $\nbAddr_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\isprefix_{i+1}=1$ + \item $\Depth1_{i+1}=1$ + \item $\Depth2_{i+1}=0$ + \end{enumerate} + \item \trash We remind the reader of constraint~\ref{constraint: end of access set phase}. At this point, $\phasesize_{i}=0$ is equivalent to ($\nbAddr_{i} = 0$ and $\nbSto_{i}=0$), so the phase ends. + \end{enumerate} + \end{enumerate} +\end{enumerate} +Here we define initialisation and decrementation of $\phasesize$, $\col{ACCESS\_TUPLE\_BYTESIZE}$, $\nbAddr$, $\nbSto$ and $\nbStoPerAddr$. +\begin{enumerate}[resume] + \item \If $\Depth1_{i}=0$ \Then $\phasesize_{i} = \phasesize_{i+1}$. + \item \If $\Depth1_{i}=1$ \Then $\phasesize_{i} = \phasesize_{i-1} - \lc_{i} \cdot \limbsize_{i}$. +\end{enumerate} +In other words $\phasesize$ is initialized at the begining of $\phase{10}$ and then decreased by the number of bytes in the $\limb$ when $\lc$ is nonzero. +\begin{enumerate}[resume] + + \item \If ($\Depth1_{i}=1$ \et ($\isprefix_{i}=0$ \Or $\Depth2_{i}=1$) \footnote{It is implemented \If $\isprefix_{i} \cdot (1 - \Depth2_{i})=0$ \Then} \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=\col{ACCESS\_TUPLE\_BYTESIZE}_{i-1} - \lc_{i} \cdot \limbsize_{i}$ + +\end{enumerate} +In other words $\col{ACCESS\_TUPLE\_BYTESIZE}$ is initialized at the begining of an access tuple loop, with initialisation value only depending on the value of $\nbStoPerAddr$ + \footnote{The bytesize of an access tuple is 21 (20 for address + 1 for its RLP prefix) + RLP of the list of StorageKey (from 1 to 4 depending of the length of the bytesize of the list of StorageKeys) + 33 per StorageKeys (32 + 1 for its RLP prefix). The RLP prefix of the list of StorageKey is computed when $\isprefix = 1$, $\Depth 1 =1$ and $\Depth 2 = 1$ thus constraining the value of $\col{ACCESS\_TUPLE\_BYTESIZE}$. + \begin{enumerate} + \item \If $\nbStoPerAddr_{i}=0$ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=(1+20) + 1$ + \item \If $\nbStoPerAddr_{i}=1$ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}=(1+20) + 1 + (1+32)$ + \item \If $\nbStoPerAddr_{i} \in [\![ 2 ; 7 ]\!] $ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}= (1+20) + 2 + (1+32) \cdot \nbStoPerAddr$ + \item \If $\nbStoPerAddr_{i} \in [\![ 8 ; 1985 ]\!]$ \footnote{In this case the bytesize of $\nbStoPerAddr$ RLP(StorageKey) is a two bytes integer.} \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}= (1+20) + 3 + (1+32) \cdot \nbStoPerAddr$ + \item \If $\nbStoPerAddr_{i} \in [\![ 1986 ; 508400]\!]$ \Then $\col{ACCESS\_TUPLE\_BYTESIZE}_{i}= (1+20) + 4 + (1+32) \cdot \nbStoPerAddr$ + \end{enumerate} + } +and decreased by the number of bytes in the $\limb$ when $\lc$ is nonzero during the loop (except during the access tuple RLP prefix). +\newline +For the following, we remind the reader that $\nbAddr$, $\nbSto$ and $\nbStoPerAddr$ are $\ct$-constant (see \ref{constancy_constraints}). +\begin{enumerate}[resume] + \item \If ($\Depth1_{i}=1$ \et $\ct_{i}=0$) \Then $\nbAddr_{i} = \nbAddr_{i-1} - \isprefix_{i} \cdot (1 - \Depth2_{i})$ +\end{enumerate} +In other words, $\nbAddr$ is initialized at the begining of the phase, and then decrease by one at the begining of each RLP(access tuple). +\begin{enumerate}[resume] + \item \If ($\Depth1_{i}=1$ \et $\ct_{i}=0$) \Then $\nbSto_{i} = \nbSto_{i-1} - (1- \isprefix_{i}) \cdot \Depth2_{i}$ +\end{enumerate} +In other words, $\nbSto$ is initialized at the begining of the phase, and then decrease by one at the begining of each RLP(Sto). +\begin{enumerate}[resume] + \item \If (($\isprefix_{i}=0$ \Or $\Depth2_{i}=1$) \et $\ct_{i}=0$) \footnote{It is implemented \If $\isprefix_{i} \cdot (\Depth2_{i}-1) +\ct_{i} =0$ \Then} \Then $\nbStoPerAddr_{i} = \nbStoPerAddr_{i-1} - (1- \isprefix_{i}) \cdot \Depth2_{i})$ +\end{enumerate} +In other words$\nbStoPerAddr$ is initialized at the begining of an access tuple loop, and then decrease by one at the begining of each RLP(Sto). +\begin{enumerate}[resume] + \item \If ($\Depth1_{i}=0$ \et $\nbAddr_{i}=\nbAddr_{i-1}$) \Then + \begin{enumerate} + \item $\col{Addr}\high_{i} = \col{Addr}\high_{i-1}$ + \item $\col{Addr}\low_{i} = \col{Addr}\low_{i-1}$ + \end{enumerate} +\end{enumerate} +In other words $\col{Addr}\high$ and $\col{Addr}\low$ are constant all along an AccessTuple. diff --git a/rlp_txn/phase_constraints/r_and_s.tex b/rlp_txn/phase_constraints/r_and_s.tex new file mode 100644 index 0000000..d62a939 --- /dev/null +++ b/rlp_txn/phase_constraints/r_and_s.tex @@ -0,0 +1,33 @@ +\begin{center} + \boxed{\text{In all this section, it is assumed that $\phaseR_{i}+\phaseS_{i}=1$.}} +\end{center} +\begin{enumerate} + \item \If $\Input1_{i} = \Input2_{i}=0$ \Then $\nbstep_{i}=1$ \et $\limb_{i}=\rlprefixShortInt \cdot 256 ^{\llargeMO}$ \et $\limbsize_{i}=1$ + \item \If $\Input2_{i} \ne 0$ \Then $\nbstep_{i}=16$ + \item \If $\Input1_{i} \ne 0$ \Then $\nbstep_{i}=16$ + \item \If $\nbstep_{i} \ne 1$ \Then + \[ + \rlpPrefixIntLong_{i} + \left( + \begin{array}{r} + \Input1, + \Input2, + \ct, + \nbstep, + \Done;\\ + \byteCol{1}, + \byteCol{2}, + \acc{1}, + \acc{2}, + \accsize, + \Power, + \genBit, + \genBitAcc; \\ + \limb, + \lc, + \limbsize, + \end{array} + \right) + \] + \item \If $\done_{i}=1$ \Then $\phasend_{i}=1$ +\end{enumerate} diff --git a/rlp_txn/phase_constraints/rlp_prefix.tex b/rlp_txn/phase_constraints/rlp_prefix.tex new file mode 100644 index 0000000..5d3dd9a --- /dev/null +++ b/rlp_txn/phase_constraints/rlp_prefix.tex @@ -0,0 +1,91 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phaseRlpPrefix_{i}=1$.}} +\end{center} + +We first determine the $\transactionType$ prefix concatenation on the first row: +\begin{enumerate} + \item \If $\phaseRlpPrefix_{i-1}=0$ \Then + \begin{enumerate} + \item $\nbstep_{i}=1$ + \item $\lt_{i}=1$ + \item $\lx_{i}=1$ + \item $\phasend_{i}=0$ + \item \If $\transactionType_{i}=0$ \Then $\ispadding_{i}=1$ + \item \If $\transactionType_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\ispadding_{i}=0$ + \item $\limb_{i}=\transactionType_{i}\cdot256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + \item $\outgoingDataSymb\low_{i}=\transactionType_{i}$ + \item $\lt_{i+1}=1$ + \item $\lx_{i+1}=0$ + \end{enumerate} +\end{enumerate} +We now compute the RLP prefix of $L_{\mathrm{T}}(T)$, and we remind the reader that $\rlptsize$ and $\rlpxsize$ are $\phase{0}$-constant integer (see \ref{constancy_constraints}): +\begin{enumerate}[resume] + \item \If ($\lt_{i}=1$ \et $\lx_{i}=0$) \Then + \begin{enumerate} + \item $\ispadding_{i}=0$ + \item $\phasend_{i}=0$ + \item $\Input1_{i} = \rlptsize_{i}$ + \item $\nbstep_{i}=8$ + \item + \[ + \rlpPrefixByteString_{i} + \left( + \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{0}; \\ + \accsize, + \Power, + \phaseRlpPrefix, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} + \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\lt_{i+1}=0$ + \item $\lx_{i+1}=1$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +We now compute the RLP prefix of $L_{\mathrm{X}}(T)$: +\begin{enumerate}[resume] + \item \If ($\lt_{i}=0$ \et $\lx_{i}=1$) \Then + \begin{enumerate} + \item $\ispadding_{i}=0$ + \item $\Input1_{i} = \rlpxsize_{i}$ + \item $\nbstep_{i}=8$ + \item + \[ + \rlpPrefixByteString_{i} + \left( + \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{0}; \\ + \accsize, + \Power, + \phaseRlpPrefix, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} + \right) + \] + \item \If $\done_{i}=1$ \Then $\phasend_{i}=1$ + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/phase_constraints/to_address.tex b/rlp_txn/phase_constraints/to_address.tex new file mode 100644 index 0000000..6dbee9a --- /dev/null +++ b/rlp_txn/phase_constraints/to_address.tex @@ -0,0 +1,27 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phaseTo_{i}=1$.}} +\end{center} + +In this phase is computed RLP(Addr). + +\begin{enumerate} + \item + \[ + \left\{ + \begin{array}{lcl} + % \col{input}\high & \!\!\! = \!\!\! & Addr\high \\ + % \col{input}\low & \!\!\! = \!\!\! & Addr\low \\ + % \bit{oli} & \!\!\! = \!\!\! & \oli \vspace{2mm} \\ + \multicolumn{3}{l}{\texttt{rlpAddressConstraints}_{i}(\Input1, \Input2, \ct)} \\ + \end{array} + \right. + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item $\phasend_{i}=1$. + \item $\outgoingDataSymb\high_{i}=\Input1_{i}$ + \item $\outgoingDataSymb\low_{i}=\Input2_{i}$ + \item \If $\nbstep_{i}=1$ \Then $\outgoingDataSymb\high_{i+1}=1$ + \item \If $\nbstep_{i}=\llarge$ \Then $\outgoingDataSymb\high_{i+1}=0$ + \end{enumerate} +\end{enumerate} diff --git a/rlp_txn/phase_constraints/y.tex b/rlp_txn/phase_constraints/y.tex new file mode 100644 index 0000000..57394e8 --- /dev/null +++ b/rlp_txn/phase_constraints/y.tex @@ -0,0 +1,12 @@ +\begin{center} +\boxed{\text{All constraints in this subsection assume that $\phaseY_{i}= 1$.}} +\end{center} + +\begin{enumerate} + \item $\Input 1_{i} = 0$ \Or $\Input 1_{i} = 1$ + \item $\nbstep_{i}=1$ + \item \If $\Input 1 _{i}=0$ \Then $\limb_{i}=\rlprefixShortInt \cdot 256 ^{\llargeMO}$ + \item \If $\Input 1 _{i} \ne 0$ \Then $\limb_{i}=\Input 1 \cdot 256 ^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \item $\phasend_{i}=1$ +\end{enumerate} \ No newline at end of file diff --git a/rlp_txnrcpt/_all_rlp_txnrcpt.tex b/rlp_txnrcpt/_all_rlp_txnrcpt.tex new file mode 100644 index 0000000..a6e79db --- /dev/null +++ b/rlp_txnrcpt/_all_rlp_txnrcpt.tex @@ -0,0 +1,45 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_patterns} +\usepackage{../pkg/log_info} + +\title{Transaction receipt module} +\author{Rollup team} +\date{August 2023} + +\begin{document} + +\maketitle +\tableofcontents +\input{_inputs} + +\end{document} diff --git a/rlp_txnrcpt/_inputs.tex b/rlp_txnrcpt/_inputs.tex new file mode 100644 index 0000000..bb35773 --- /dev/null +++ b/rlp_txnrcpt/_inputs.tex @@ -0,0 +1,17 @@ +\section{Introduction} \input{intro} + +\section{Global behaviour} +\subsection{Columns description} \input{columns} +\subsection{Loop summary} \input{tx_loop} + +\section{Lookups} \input{lookup} + +\section{Constraints} +\subsection{Global Constraints} \input{global_constraint} + +\subsection{Phase constraints} +\subsubsection{\phase{1} --- global \textsc{rlp} prefix} \input{phase1} +\subsubsection{\phase{2} --- status code $R_\text{z}$} \input{phase2} +\subsubsection{\phase{3} --- cumulative gas $R_\text{u}$} \input{phase3} +\subsubsection{\phase{4} --- bloom filter $R_\text{b}$} \input{phase4} +\subsubsection{\phase{5} --- logs series $R_\text{l}$} \input{phase5} diff --git a/rlp_txnrcpt/columns.tex b/rlp_txnrcpt/columns.tex new file mode 100644 index 0000000..8baf74f --- /dev/null +++ b/rlp_txnrcpt/columns.tex @@ -0,0 +1,51 @@ +\begin{enumerate} + \item $\absTxNum$: transaction number column, starts at 0 and is incremented by one when starting a new transaction. + \item $\absTxNumInfty$: batch constant column, indicating the number of transaction in the batch; + \item $\absLogNum$: number of the current log entry, only used in $\phase{5}$; + \item $\absLogNumMax$: number of log entries in a given transaction; + \item Output columns: + \begin{enumerate} + \item $\limb$: output of the module, contains $\llarge$ byte integers left aligned on the $\llarge$-th byte\footnote{ and thus with $\llarge - \limbsize$ zeros occupying the least significant bytes} + \item $\limbsize$: number of meaningful bytes of the $\limb$ + \item \col{LIMB\_CONSTRUCTED} abbreviated $\lc$: binary column. + \item $\index$: index of the current limb within the current string; starts at 0 when starting a new transaction and increments by 1 in the row \emph{following} $\lc = 1$. + \item $\indexlocal$: local index, used to reconstruct data $O_{\mathbf{d}}$ and the 256 bytes hash $R_{\mathrm{b}}$. + \end{enumerate} + \item Columns used for heartbeat + \begin{enumerate} + \item \phase{1} to \phase{5}: 5 binary columns that indicates the phase. + \item $\phasend$: binary column. Is one at the last row of a phase, 0 elsewhere. + \item $\col{COUNTER}$, abbreviated $\ct$: internal counter, byte column. Counts from 0 to $\nbstep - 1$ and resets. + \item $\nbstep$: byte column, with value between 1 and $\llarge$. + \item $\Done$: binary column to be one when at the end of a \ct-loop, else 0. + \end{enumerate} + \item Columns used in several phase for computation + \begin{enumerate} + \item $\logsize$: Byte size of the log, must be 0 at the end of the transaction. + \item $\Input k$, $k=1,2, 3, 4$: 0-16 bytes data. + \item $\byteCol{k}$, $k=1,2, 3, 4$: byte columns used for byte decompositions, and its accumulators $\acc{k}$. + \item $\accsize$: byte column used to count the bytesize of $\acc{1}$. + \item $\col{BIT}$: binary column. + \item $\col{BIT\_ACC}$, bit accumulator column. + \item $\Power$, a power of 256, to calculate the offset (left shifting) for the $\limb$. + \item \isprefix: binary column, to declare when computing a \rlp{} prefix ($\phase{4}$ and $\phase{5}$) or concatenating the type of the transaction ($\phase{1}$). + \item \ispadding: binary column; equals $1$ \emph{iff} the current \ct{}-loop produces no limb; + \end{enumerate} + \saNote{} \ispadding{} can only be on during phase 1 or phase 5: for phase 1 it turns on for transactions of type 0 (which require not prepending of a transaction type byte); during phase 5 it turns on whenever the data consists of a single byte in the range $\texttt{0x\,00} < \texttt{b} < \texttt{0x\,80}$. + \item Columns used in phase 4 and 5 only + \begin{enumerate} + \item $\phasesize$: size (in bytes) of the bytestring of this phase; used to compute the \rlp{} prefix of the byte string of this phase; decrements as the module accounts for these bytes; + % \item $\isEightByteInput$: binary column used to distinguish between 8 byte inputs for + \end{enumerate} + \item Columns used in phase 5 only + \begin{enumerate} + \item $\Depth1$: binary column to define loop intrication. + \item $\isOt$: binary column to define when dealing with $O_{\mathbf{t}}$. + \item $\isOd$: binary column to define when dealing with $O_{\mathbf{d}}$. + \item $\logentrysize$: byte size of a \rlp{}-ization of log entry; decrements as the module accounts for these bytes; + \item $\localsize$: byte size of either the data being logged in a log entry or of the size of concatenation of the \rlp{}-izations of the log topics of a log item; decrements as the module accounts for these bytes; + \end{enumerate} + \item \Phase{}: column used as an identifier for the lookups; + +\end{enumerate} +\saNote{} \textbf{All sizes} referred to by the columns of the present module are measured in \textbf{bytes}. diff --git a/rlp_txnrcpt/global_constraint.tex b/rlp_txnrcpt/global_constraint.tex new file mode 100644 index 0000000..0b89b79 --- /dev/null +++ b/rlp_txnrcpt/global_constraint.tex @@ -0,0 +1,195 @@ +\subsubsection{Binarity} +We constrain those columns to be binary: +\begin{multicols}{2} +\begin{enumerate} + \item \lc{} + \item \phase{k} for $k = 1 .. 5$ + \item \phasend{} \quad (\trash) + \item \done{} \quad (\trash) + \item \col{BIT} + \item \isprefix{} \quad (\trash) + \item \ispadding{} + \item \Depth{1} \quad (\trash) + \item \isOt{} \quad (\trash) + \item \isOd{} \quad (\trash) +\end{enumerate} +\end{multicols} + +\subsubsection{Bytehood} +We constraint those columbs to be byte: +\begin{enumerate} + \item $\byteCol{k}$, $k=1,2, 3, 4$ +\end{enumerate} + +\subsubsection{Constancy columns} \label{constancy_constraints} +We define that a column \col{X} is +\begin{enumerate} + \item \textbf{block-constant}: \If $\absTxNum_{i} \ne 0$ \Then $\col{X}_{i}=\col{X}_{i+1}$ + % \item \textbf{transaction-constant}: \If $\absTxNum_{i} \ne \absTxNum_{i-1} + 1$ \Then $\col{X}_{i}=\col{X}_{i-1}$ + \item \textbf{counter-constant}: \If $\ct_{i} \ne 0$ \Then $\col{X}_{i}=\col{X}_{i-1}$ + \item \textbf{counter-incrementing}: \If $\ct_{i} \ne 0$ \Then $\col{X}_{i} \in \{\col{X}_{i-1}; \col{X}_{i-1} +1 \}$. If \col{X} is a bit column, it implies $\col{X}_{i} \in \{\col{X}_{i-1}; 1 \}$. + \item \textbf{$\bm{\phase{k}}$-constant}: \If $\phase{k}_{i-1} = 1$ \et $\phase{k}_{i}=1$ \Then $\col{X}_{i}=\col{X}_{i-1}$. + \item \textbf{$\phase{k}$-incrementing}: \If $\phase{k}_{i-1} = 1$ \et $\phase{k}_{i}=1$ \Then $\col{X}_{i} \in \{\col{X}_{i-1}; \col{X}_{i-1} +1 \}$. If \col{X} is a bit column, it implies $\col{X}_{i} \in \{\col{X}_{i-1}; 1 \}$. + \item \textbf{$\bm{\phase{k}}$-decrementing}: \If $\phase{k}_{i-1} = 1$ \et $\phase{k}_{i}=1$ \Then $\col{X}_{i} \in \{\col{X}_{i-1} -1; \col{X}_{i-1} \}$. If \col{X} is a bit column, it implies $\col{X}_{i} \in \{0 ; \col{X}_{i-1}\}$. +\end{enumerate} + +We constrain: +\begin{enumerate} + \item $\absTxNumInfty$ and $\absLogNumMax$ to be block-constant; + \item $\Input k$ (for $k= 2, 3, 4$), $\nbstep$, $\isprefix$, $\Depth 1$, $\isOt$, $\isOd$ are counter-constant; + \item \If ($\phase 5_{i} \ne 1$ \Or $\Depth1_{i} \ne 1$ \Or $\isprefix_{i} \ne 0$ \Or $\isOd_{i} \ne 1$) \Then $\Input 1$ is counter-constant; + \saNote{} We impose the counter constancy of $\Input 1$ on all the trace but when dealing with $O_{\textbf{d}}$. + + \item $\ispadding$ is counter-incrementing; + \item \If ($\isprefix_{i}=0$ \Or $\isOd_{i}=0$) \Then $\lc$ is counter-incrementing; + \item $\isprefix$ is $\phase 4$-decrementing; + \item $\Depth 1$ is $\phase 5$-incrementing; + \item $\indexlocal$ is $\isOt$-incrementing; + \item $\logsize$ is $\phase{1}$-constant. +\end{enumerate} + +\subsubsection{Global phase constrains} \label{Global phase constraints} +Constraints on the transaction number: +\begin{enumerate} + \item $\col{ABS\_TX\_NUM}_{0}=0$ + \item \If $\col{ABS\_TX\_NUM}_{i}=0$ \Then $\sum_{k=1}^{5} \phase{k}_{i} = 0$ + \item \If $\col{ABS\_TX\_NUM}_{i} \ne 0$ \Then $\sum_{k=1}^{5} \phase{k}_{i} = 1$; +\end{enumerate} +In other words padding rows have all phase flags turned off while every non padding row has precisely \emph{one} phase column turned on. +\begin{enumerate}[resume] + \item $\col{ABS\_TX\_NUM}_{i}=\col{ABS\_TX\_NUM}_{i-1} + \phase{1}_{i} \cdot (\phase{1}_{i}-\phase{1}_{i-1})$ in other words $\col{ABS\_TX\_NUM}$ is constant except increasing by one when starting a new transaction. +\end{enumerate} +Constraint on \Phase{}: +\begin{enumerate} + \item $\Phase_{i} = \sum_{k=1}^{5} k \cdot \phase{k}_{i} + \subPhaseIdWeightIsPrefix \cdot \isprefix_{i} + \subPhaseIdWeightIsOt \cdot \isOt_{i} + \subPhaseIdWeightIsOd \cdot \isOd_{i} + \subPhaseIdWeightDepth \cdot \Depth1_{i} + \subPhaseIdWeightIndexLocal \cdot \isOt_{i} \cdot \indexlocal_{i}$ \label{RlpTxrcpt: subPhaseId} +\end{enumerate} +Explanation +\begin{enumerate} + \item $\phase{k}$ are exclusive binary column; + \item $\isprefix$, $\isOt$ and $\isOd$ are binary columns; + \item When $\isOt_{i} = 1$, we store in $\indexlocal$ the number of the current topic (between 0 and 4) for this logentry; +\end{enumerate} +Constraints on $\absLogNum$ +\begin{enumerate} + \item $\absLogNum_{0}=0$ + \item \If ($\phase{5}_{i}=1$ \et $\Depth 1_{i}=1$ \et $\isprefix_{i}=1$ \et $\isOt_{i}=0$ \et $\isOd_{i}=0$ \et $\ct_{i}=0$) + \begin{enumerate} + \item \Then $\absLogNum_{i}=\absLogNum_{i-1}+1$ + \item \Else $\absLogNum_{i}=\absLogNum_{i-1}$ + \end{enumerate} +\end{enumerate} +In other words, $\absLogNum$ starts at 0, and is constant except increasing by one when starting a new log entry. +Constraints on nullity of $\limb$ +\begin{enumerate}[resume] + \item \If $\lc_{i}=0$ \Then $\limb_{i}=0$ (\trash); +\end{enumerate} +Constraints on the phase transition: +\begin{enumerate}[resume] + \item \If $\Done_{i}=0$ \Then $\phasend_{i}=0$. + \item \If $\phasesize \ne 0$ \Then $\phasend_{i}=0$ + \item \If ($\absTxNum_{i} \ne 0$ \et $\phasend_{i}=0$) \Then $\sum_{k=1}^{5} k \cdot \phase{k}_{i} = \sum_{k=1}^{5} k \cdot \phase{k}_{i+1}$ \\ + In other words $\phase{k}_{i+1}=\phase{k}_{i}$ for every $k \in [\![ 0 ; 4 ]\!]$. + \item \If $\phasend_{i}=1$ \Then + \begin{enumerate} + \item We impose phase transition constraints: + \[ + \left[ + \begin{array}{r} + \phase{1}_{i} \cdot \phase{2}_{i+1} + + \phase{2}_{i} \cdot \phase{3}_{i+1} \\ + + \phase{3}_{i} \cdot \phase{4}_{i+1} + + \phase{4}_{i} \cdot \phase{5}_{i+1} \\ + + \phase{5}_{i} \cdot \phase{1}_{i+1} \\ + \end{array} + \right] + = 1 + \] + In other words, at rows $i$ that mark the end of a phase the phase transition is one of the following: + \begin{enumerate} + \item \If $\phase{1}_{i}=1$ \Then $\phase{2}_{i+1}=1$ + \item \If $\phase{2}_{i}=1$ \Then $\phase{3}_{i+1}=1$ + \item \If $\phase{3}_{i}=1$ \Then $\phase{4}_{i+1}=1$ + \item \If $\phase{4}_{i}=1$ \Then $\phase{5}_{i+1}=1$ + \item \If $\phase{5}_{i}=1$ \Then $\phase{1}_{i+1}=1$ + \end{enumerate} + \item \If $\phase{5}_{i}=1$ \Then $\logsize_{i}=0$ + The above signifies that all bytes constituting the \rlp{}-ization of the log series were used up. + \end{enumerate} +\end{enumerate} + +\subsubsection{Byte decomposition's loop Heartbeat} +\begin{center} +\boxed{\text{All constraints in this subsection assume that $\absTxNum_{i} \ne 0$.}} +\end{center} +We remind the reader that $\nbstep$ is $\ct$-constant, and $\lc$ is $\ct$-incrementing (see \ref{constancy_constraints}). +\begin{enumerate} + \item \If $\ct_{i}=\nbstep_{i}-1$ \Then $\Done_{i}=1$ + \item \If $\ct_{i} \ne \nbstep_{i}-1$ \Then $\Done_{i}=0$ +\end{enumerate} +In other words, $\Done$ is nonzero only at the last row of a loop. +\begin{enumerate}[resume] + \item \If $\Done_{i}=0$ \Then $\ct_{i+1} = \ct_{i} +1$ + \item \If $\Done_{i}=1$ \Then + \begin{enumerate} + \item $\lc_{i}=1-\ispadding_{i}$ + \item $\ct_{i+1} = 0$ + \end{enumerate} +\end{enumerate} + +\subsubsection{Byte and bit accumulation constraints} +We build some blind byte and bit accumulators. There are more constaints when those decomposition and accumulators are used, depending of the phase. +\begin{enumerate} + \item Constraints on the bytes accumulator columns for $k= 1,2, 3, 4$. + \begin{enumerate} + \item \If $\ct_{i}=0$ \Then $\byteCol{k}_{i} = \acc{k}_{i}$ + \item \If $\ct_{i} \ne 0$ \Then $\acc{k}_{i}=256 \cdot \acc{k}_{i-1} + \byteCol{k}_{i}$ + \end{enumerate} + \item Constraint on the bit accumulator column: + \begin{enumerate} + \item \If $\ct_{i}=0$ \Then $\col{BIT\_ACC}_{i} = \col{BIT}_{i}$ + \item \If $\ct_{i} \ne 0$ \Then $\col{BIT\_ACC}_{i}=2 \cdot \col{BIT\_ACC}_{i-1} + \col{BIT}_{i}$ + \end{enumerate} +\end{enumerate} + +\subsubsection{Index updates} + +\noindent Incrementation of $\index$: +\begin{enumerate} + \item \If $\col{ABS\_TX\_NUM}_{i} \ne \col{ABS\_TX\_NUM}_{i-1}$ \Then $\index_{i}=0$ + \item \If $\col{ABS\_TX\_NUM}_{i} \neq 1 + \col{ABS\_TX\_NUM}_{i-1}$ \Then $\index_{i}=\index_{i-1} + \lc_{i-1}$ +\end{enumerate} + +\subsubsection{Byte size updates} + +\begin{description} + \item[{Updating $\logsize$:}] with every finished construction of a limb of the \rlp{} string the \limbsize{} column diminishes by the size of the constructed limb on the row of the limb construction: + \begin{enumerate} + \item \If $\sum_{k=2}^{5} \phase{k}_{i}=1$ \Then + \[ + \logsize_{i} = \logsize_{i-1} - \lc_{i} \cdot\limbsize_{i} + \] + We remind the reader that $\logsize$ is $\phase{1}$-constant, see \ref{constancy_constraints}. + \end{enumerate} + \item[{Updating $\phasesize$:}] the only phases that require the \phasesize{} columnms are phase 4 and phase 5. We leave the column unconstrained outside of these: + \begin{enumerate} + \item \If \Big($(\phase{4}_{i}=1 \et \isprefix_{i}=0)$ \Or $(\phase{5}_{i}=1 \et \Depth 1 _{i}=1)$\Big) \Then + \[ \phasesize_{i} = \phasesize_{i-1} - \lc_{i} \cdot \limbsize_{i} \] + \end{enumerate} +\end{description} + +\subsubsection{\ispadding{} updates} + +\noindent Miscelanous: +\begin{enumerate}[resume] + \item \If $(\phase{1}_{i}=0 \et (\phase{5}_{i}=0 \Or \isOd_{i}=0))$ \Then $\ispadding_{i}=0$ +\end{enumerate} + +\subsubsection{Finalisation constraints} +\If $\absTxNum_{N} \ne 0$ \Then +\begin{enumerate} + \item $\phasend_{N}=1$ + \item $\phase{5}_{N}=1$ + \item $\absTxNum_{N}=\absTxNumInfty_{N}$ + \item $\absLogNum_{N}=\absLogNumMax_{N}$ +\end{enumerate} +In other words, we constrain the last row of the trace to be the end of the last phase of the last transaction. diff --git a/rlp_txnrcpt/intro.tex b/rlp_txnrcpt/intro.tex new file mode 100644 index 0000000..2bc4c14 --- /dev/null +++ b/rlp_txnrcpt/intro.tex @@ -0,0 +1,12 @@ +This module aims to construct the \textsc{rlp} encoding $\widetilde{L}_{\mathrm{R}}(R)$ of a give transaction receipt $R$, as defined in the Ethereum Yellow Paper. Recall that a transaction receipt contains the following data: +\begin{enumerate} + \item the \texttt{status code} of the transaction $R_{\mathrm{z}}$ (0 or 1), encoded in $\phase{2}$; + \item the \texttt{cumulative gas} used in the block immediately after the transaction happened $R_{\text{u}}$ (assumed to be an 8 byte integer in what follows), encoded in $\phase{3}$; + \item a 256 byte hash $R_\textbf{b}$, encoded in $\phase{4}$; + \item a tuple of log entries $R_{\textbf{l}}$, encoded in $\phase{5}$; recall that a \texttt{log entry} is a tuple $(O_\text{a}, O_\textbf{t}, O_\textbf{l})$ where: + \begin{enumerate} + \item $O_{\text{a}} \in \mathbb{B}_{20}$ is the \texttt{logger address}; + \item $O_{\textbf{t}}$ a (possibly empty) tuple of $\inst{k}\in\{0,1,\dots,4\}$ so-called \texttt{log topics} $\in \mathbb{B}_{32}$ if the logging operation was a \inst{LOGk}; + \item $O_{\textbf{d}} \in \mathbb{B}^*$ is an arbitrary slice of bytes; + \end{enumerate} +\end{enumerate} diff --git a/rlp_txnrcpt/lookup.tex b/rlp_txnrcpt/lookup.tex new file mode 100644 index 0000000..a6912eb --- /dev/null +++ b/rlp_txnrcpt/lookup.tex @@ -0,0 +1,54 @@ +This module takes information from three different modules through lookup : \logInfoMod, \logDataMod and \txnDataMod. + +\subsection{Lookup emanating from LOGINFO}{} +\label{lookup_log_info} + +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|c|} + \hline + $\col{ABSTX}^{\infty}$ & \col{ABSTX} & $\col{ABSLOG}^{\infty}$ & \col{ABSLOG} & \Phase{} & \col{DATA\_1} & \col{DATA\_2} \\ \hline + & & abs & nLog & \subPhaseIdAddr & (\col{ADDR\_HI}) & (\col{ADDR\_LOW}) \\ \hline + & & abs & nLog & $\subPhaseIdTopicBase + \subPhaseIdTopicDelta \cdot \col{topic}$ & (\col{TOPIC\_HI}) & (\col{TOPIC\_LOW}) \\ \hline + & & abs & nLog & \subPhaseIdDataSize & (\col{DATASIZE}) & \col{nbTopic} \\ \hline + \end{tabular} + \caption{\logInfoMod{} Source. \col{topic} ranges from 1 to \col{nbTopic} which equals \inst{X} for \inst{LOGX} instructions. We use the following shorthand: $\col{ABSTX}^{\infty}$ for \absTxNumInfty, \col{ABSTX} for \absTxNum, $\col{ABSLOG}^{\infty}$ for \absLogNumMax, \col{ABSLOG} for \absLogNum.} +\end{table} + +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|} + \hline + \absTxNum & \logNum & \Phase{} & \Input{1} & \Input{2} \\ \hline + abs & nLog & ... & ... & ... \\ \hline + \end{tabular} + \caption{RLP\_TXRCPT Target} +\end{table} + +\subsection{Lookup emanating from LOGDATA} +\label{lookup_log_data} + +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|} + \hline + \absTxNum & \logNum & \Phase{} & \indexlocal & \limb & \limbsize \\ \hline + abs & nLog & \subPhaseIdDataLimb & & & \\ \hline + \end{tabular} + \caption{LOGDATA Source} +\end{table} + +\begin{table}[h] + \centering + \begin{tabular}{|c|c|c|c|c|c|} + \hline + \absTxNum & \logNum & \Phase & \indexlocal & \limb & \limbsize \\ \hline + ... & ... & ... & ... & ... & ... \\ \hline + \end{tabular} + \caption{RLP\_TXRCPT Target} +\end{table} + + +\subsection{Lookup emanating from TXNDATA} +See \ref{txData: lookups: rlp txnrcpt}, page \pageref{txData: lookups: rlp txnrcpt}. + diff --git a/rlp_txnrcpt/phase1.tex b/rlp_txnrcpt/phase1.tex new file mode 100644 index 0000000..65e3ad9 --- /dev/null +++ b/rlp_txnrcpt/phase1.tex @@ -0,0 +1,54 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phase{1}{i}=1$.}} +\end{center} + +Phase 0 always lasts 9 rows. +The first row deals with the $\texttt{type}$ prefix. Recall that the transaction type is pre-pended to the \textsc{rlp} string of the transaction receipt for type 1 and type 2 transactions. +Therefore, and only on the first row of the $0^{th}$ phase, one must interpret the value contained in $\Input{1}$ as the transaction type, see section \ref{lookup_txn_data}. +\begin{enumerate} + \item \If $\phase1_{i-1}=0$ \Then + \begin{enumerate} + \item $\isprefix_{i}=1$ + \item $\nbstep_{i}=1$ + \item $\phasend_{i}=0$ + \item \If $\Input{1}_{i}=0$ \Then $\ispadding_{i}=1$ + \item \If $\Input{1}_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\ispadding_{i}=0$ + \item $\limb_{i}=\Input{1}_{i}\cdot256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \end{enumerate} + \item $\isprefix_{i+1}=0$ + \end{enumerate} +\end{enumerate} +We now compute the RLP prefix of the whole log list, and we remind the reader that $\logsize$ is a $\phase{0}$-constant integer: +\begin{enumerate}[resume] + \item \If $\isprefix_{i}=0$ \Then + \begin{enumerate} + \item $\nbstep_{i}=8$ + \item $\ispadding_{i}=0$ + \item $\Input1_{i} = \logsize_{i}$ + \item + \[ + \rlpPrefixByteString_{i} + \left( + \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{0}; \\ + \accsize, + \col{POWER}, + \col{BIT}, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} + \right) + \] + \item \If $\Done_{i}=1$ \Then $\phasend_{i}=1$ + \end{enumerate} +\end{enumerate} diff --git a/rlp_txnrcpt/phase2.tex b/rlp_txnrcpt/phase2.tex new file mode 100644 index 0000000..b7a1fb7 --- /dev/null +++ b/rlp_txnrcpt/phase2.tex @@ -0,0 +1,13 @@ +\begin{center} +\boxed{\text{In all this section, it is assumed that $\phase{2}_{i}=1$.}} +\end{center} + +This phase deals with the success bit $R_\text{z} \in \mathbb{N}$ of the status code of the transaction. Recall that, while it is serialized as an \emph{integer}, the status code may only take on one of two values: 0 or 1. This phase thus computes \textsc{rlp}($\Input 1$) where $\Input 1$ is either 0 or 1. + +\begin{enumerate} + \item $\nbstep_{i}=1$ + \item \If $\Input{1}_{i} =1$ \Then $\limb_{i}= \Input{1} \cdot 256^{\llargeMO}$ + \item \If $\Input{1}_{i} =0$ \Then $\limb_{i}= \rlprefixShortInt \cdot 256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \item $\phasend_{i}=1$ +\end{enumerate} diff --git a/rlp_txnrcpt/phase3.tex b/rlp_txnrcpt/phase3.tex new file mode 100644 index 0000000..2754684 --- /dev/null +++ b/rlp_txnrcpt/phase3.tex @@ -0,0 +1,47 @@ +\begin{center} +\boxed{\text{All constraints in this subsection assume that $\phase{3}_{i} = 1$.}} +\end{center} + +This phase computes $\textsc{rlp}(R_\text{u})$ where $R_\text{u} \in \mathbb{N}$ is the (8 byte) integer representing the cumulative gas consumption of all the transactions in the current batch up to (and including) the current transaction. Its value is accessible through $\Input 1$. \saNote{} Every transaction consumes a nonzero amount gas (at least $G_\text{transaction} = 21000$) as such the integer to \textsc{rlp}-ize will necessarily be \emph{nonzero}. Also, gas consumption is limited by the batch's \textbf{gasLimit}, which in practice is much smaller than the $8$ bytes of room it is provided with. + +\begin{enumerate} + % \item \If $\Input1 = 0$ \Then $\nbstep = 1$ (\trash) % see comment about nonzeroness + \item $\nbstep_{i} = 8$ + \item + \[ + \rlpPrefixInt_{i} + \left( + \begin{array}{r} + \Input{1}, + \ct, + \nbstep, + \done; \\ + \byteCol{1}, + \acc{1}, + \accsize, + \Power, + \col{BIT}, + \col{BIT\_ACC}; \\ + \limb, + \lc, + \limbsize; \\ + \end{array} + \right) + \] + \item \If $\done_{i}=1$ \Then: + \begin{enumerate} + \item \[ + \limbShifting + \left( + \begin{array}{r} + \Input 1_{i}, + \Power_{i}, + \accsize_{i}; \\ + \limb_{i}, + \limbsize_{i}; \\ + \end{array} + \right) +\] + \item $\phasend_{i}=1$. + \end{enumerate} +\end{enumerate} diff --git a/rlp_txnrcpt/phase4.tex b/rlp_txnrcpt/phase4.tex new file mode 100644 index 0000000..28a8f4e --- /dev/null +++ b/rlp_txnrcpt/phase4.tex @@ -0,0 +1,38 @@ +\begin{center} +\boxed{\text{All constraints in this subsection assume that $\phase{4}_{i} = 1$.}} +\end{center} + +The present section deals with the \textsc{rlp}-ization of the logs bloom $R_\text{b}$, a slice of 256 bytes. It establishes that what is being encoded is indeed a bytestring of size $256$. The actual value is not justified. The first row establishes the \textsc{rlp}-prefix associated with an element of $\mathbb{B}_{256}$. The $64 = 4 \cdot \llarge$ following rows perform byte decompositions of four $\llarge$-byte integers in parallel. Every $\llarge$ rows populate the $\limb$ column with four new $\llarge$-byte integers from the logs bloom. +We remind the reader that $\isprefix$ is $\phase 3$-decrementing. +\begin{enumerate} + \item \If $\phase{3}_{i-1}=0$ \Then + \begin{enumerate} + \item $\isprefix_{i}=1$ + \item $\phasesize_{i}=256$ + \item $\nbstep_{i}=1$ + \item $\limb_{i}=(\rlprefixLongInt + 2) \cdot 256^{\llargeMO} + \phasesize_{i} \cdot 256 ^{13}$ + \item $\limbsize_{i}=3$ + \item $\phasend_{i}=0$ + \item $\isprefix_{i+1}=0$ + \item $\indexlocal_{i}=0$ + \end{enumerate} + \item \If $\isprefix_{i}=0$ \Then + \begin{enumerate} + \item $\nbstep_{i}=\llarge$ + \item \If $\Done_{i}=1$ \Then: + \begin{enumerate} + \item $\acc 1_{i}=\Input 1_{i}$ + \item $\acc 2_{i}=\Input 2_{i}$ + \item $\acc 3_{i}=\Input 3_{i}$ + \item $\acc 4_{i}=\Input 4_{i}$ + \item $\lc_{i-4}+\lc_{i-3}=1$ + \item $\limb_{i-3}=\Input 1 _{i}$ \et $\limbsize_{i-3}=\llarge$ + \item $\limb_{i-2}=\Input 2 _{i}$ \et $\limbsize_{i-2}=\llarge$ + \item $\limb_{i-1}=\Input 3 _{i}$ \et $\limbsize_{i-1}=\llarge$ + \item $\limb_{i}=\Input 4 _{i}$ \et $\limbsize_{i}=\llarge$ + \item \If $\phasesize_{i}=0$ \Then $\phasend_{i}=1$ + \item \If $\phasesize_{i} \ne 0$ \Then $\phasend_{i}=0$ (\trash) + \end{enumerate} + \item $\indexlocal_{i}=\indexlocal_{i-1}+\lc_{i-1} \cdot (1 - \isprefix_{i-1})$ + \end{enumerate} +\end{enumerate} diff --git a/rlp_txnrcpt/phase5.tex b/rlp_txnrcpt/phase5.tex new file mode 100644 index 0000000..f85c1cc --- /dev/null +++ b/rlp_txnrcpt/phase5.tex @@ -0,0 +1,451 @@ +\begin{center} + \boxed{\text{All constraints in this subsection assume that $\phase{5}_{i} = 1$.}} +\end{center} +The present phase deals with the \rlp{}-ification of the series of \textbf{log entries} $R_\mathbf{l} = (O_0, O_1, \dots)$. Recall that this is a list of so-called \textbf{log entries}, i.e. tuples $O = (O_\text{a}, O_\textbf{t}, O_\textbf{d})$ consisting of the logger’s address, $O_\text{a}$, a possibly empty series of (up to four) 32-byte log topics, $O_\textbf{t}$, and some number of bytes of data, $O_\textbf{d}$. +The phase is composed of several sub-phases (some of which are \colorbox{solarized-green}{optional} depending on the underlying logging instruction.) +The general loop intrication is resumed in the next table. +\begin{table}[h] + \def\zero{\gray{\textbf{0}}} + \def\one{\textbf{1}} + \renewcommand{\arraystretch}{1.3} + \centering + \caption{The first phase (establishing the \rlp{} prefix of $R_\mathbf{l}$) is performed once at the start. The \rlp{}-ization of the log entries is done as many times as there are log entries for that transaction.} + \[ + \begin{tabular}{|c|c|c|c|c|c|c|c|c|} + \hline + $\Depth1$ & \isprefix & $\isOt $ & \isOd & Subphase \\ \hline + \zero & \one & \zero & \zero & \rlp{} prefix of $R_\mathbf{l}$ \\ \hline \hline + \one & \one & \zero & \zero & \rlp{} prefix of log entry $O$ \\ \hline + \one & \zero & \zero & \zero & \rlp{} of $O_\text{a}$ \\ \hline + \one & \one & \one & \zero & \rlp{} prefix of $O_\textbf{t}$ \\ \hline + \one & \zero & \one & \zero & \cellcolor{solarized-green} \rlp{} of log topics \\ \hline + \one & \one & \zero & \one & \rlp{} prefix of $O_\textbf{d}$ \\ \hline + \one & \zero & \zero & \one & \cellcolor{solarized-green} log data \\ \hline + \end{tabular} + \quad + \setlength{\arraycolsep}{0pt} % Avoid any column space in arrays that follow + \begin{array}{ c } + \vphantom{a_N} \\ % First row + \vphantom{a_N} \\ % First row + \left.\kern-\nulldelimiterspace + \vphantom{\begin{array}{ c } + \text{Hello} \\ % Second row + \vdots \\ % Third row + % \vdots \\ % Third row + \vdots \\ % Third row + \vdots \\ % Third row + \text{Hello} \\ % Second row + \end{array}} \right\} + \begin{array}{r} + \text{many times per} \\ + \text{transaction} \\ + \end{array} + \end{array} + \] + \caption{\ob{TODO: possibility to have 7 binary columns (one per sub-phase.)} + Optional phases are \colorbox{solarized-green}{highlighted}. The ``log topics'' phase is skipped for \inst{LOG0} instructions. The ``log data'' phase is skipped for logging operations that don't log any data.} + \label{fig: phase 4 subphase table} +\end{table} +\begin{description} + \item[\underline{The RLP-\textbf{prefix} of $R_\mathbf{l}$:}] --- + \begin{enumerate}[resume] + \item \If $\phase{4}_{i-1}=0$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lcl} + \Depth 1_{i} & = & 0 \\ + \isprefix_{i} & = & 1 \\ + \isOt_{i} & = & 0 \\ + \isOd_{i} & = & 0 \\ + \end{array} \right. + \] + \saNote{} The above sets the subphase to wherein one sets the \rlp{}-prefix for the totality of the log series $R_\textbf{l}$. + \item \If ($\Depth 1_{i}=0$ \et $\isprefix_{i}=1$ (\trash) \et $\isOt_{i}=0$ (\trash) \et $\isOd_{i}=0$ (\trash)) \Then: + \begin{enumerate} + \item $\Input 1_{i} = \phasesize_{i}$ (\emph{initializes} the \ct{}-constant column $\Input{1}$, cf. \ref{rlp patterns: bytestring prefix: note: purpose of counter constancy of length}) + \item \If $\Input 1_{i}=0$ \Then: + \begin{enumerate} + \item $\nbstep_{i}=1$ + \item $\limb_{i}=\rlprefixShortList \cdot 256 ^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \item $\phasend_{i}=1$ + \end{enumerate} + \item \If $\Input 1_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\nbstep_{i} = 8$ + \item + \[ + \rlpPrefixByteString_{i} + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{4}; \\ + \accsize, + \col{POWER}, + \col{BIT}, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \saNote{} In the above $\phase{4}\equiv 1$; in the constraint this indicates that it is the \rlp{} prefix of a \textbf{list} which is computed. \ref{bla} + \item \If $\Done_{i}=1$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lcl} + \Depth 1_{i + 1} & = & 1 \\ + \isprefix_{i + 1} & = & 1 \\ + \isOt_{i + 1} & = & 0 \\ + \isOd_{i + 1} & = & 0 \\ + \end{array} \right. + \] + % + % \begin{enumerate} + % \item $\Depth 1_{i+1}=1$ + % \item $\isprefix_{i+1}=1$ + % \item $\isOt_{i+1}=0$ + % \item $\isOd_{i+1}=0$ + % \end{enumerate} + \end{enumerate} + \end{enumerate} + \end{enumerate} + \item[\underline{RLP\textbf{-prefix} of the log entry:}] --- + \begin{enumerate}[resume] + \item \If ($\Depth 1_{i}=1$ \et $\isprefix_{i}=1$ \et $\isOt_{i}=0$ \et $\isOd_{i}=0$) \Then: + \begin{enumerate} + \item \label{spec of logentrysize missing case} $\Input 1_{i} = \logentrysize_{i}$ + \saNote{} This endows $\logentrysize$ with the counter-constancy of $\Input{1}$ during this subphase. This provides the behaviour of $\logentrysize$ during the only regime not specified in \ref{spec of logentrysize}. + \item $\nbstep_{i} = 8$ + \item + \[ + \rlpPrefixByteString_{i} + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{4}; \\ + \accsize, + \col{POWER}, + \col{BIT}, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \item \If $\Done_{i}=1$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 0 & \\ + \isOt_{i + 1} & = & 0 & \\ + \isOd_{i + 1} & = & 0 & \\ + \end{array} \right. + \] + \saNote{} The constraint on $\Depth{1}$ is useless given that this binary column is $\phase{4}$-incrementing. + \end{enumerate} + \end{enumerate} + \item[\underline{RLP of the address $O_\text{a}$:}] We deal with the address in one fell swoop (the high and low parts of the address are provided in $\Input1$ and $\Input2$ respectively, see \ref{}): + \begin{enumerate}[resume] + \item \If ($\Depth 1_{i}=1$ (\trash) \et $\isprefix_{i}=0$ \et $\isOt_{i}=0$ \et $\isOd_{i}=0$) \Then: + \begin{enumerate} + \item $\nbstep_{i}=3$ + \item $\lc_{i}=1$ + \item \If $\Done_{i}=1$ \Then: + \begin{enumerate} + \item $\limb_{i-2}=(\rlprefixShortInt+20) \cdot 256^{\llargeMO}$ + \item $\limbsize_{i-2}=1$ + \item $\limb_{i-1}=\Input 1 _{i} \cdot 256 ^{12}$ + \item $\limbsize_{i-1}=4$ + \item $\limb_{i}=\Input 2_{i}$ + \item $\limbsize_{i}=\llarge$ + \item We switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 1 & \\ + \isOt_{i + 1} & = & 1 & \\ + \isOd_{i + 1} & = & 0 & \\ + \end{array} \right. + \] + \end{enumerate} + \end{enumerate} + \end{enumerate} + \item[\underline{RLP prefix of $O_{\mathbf{t}}$:}] the purpose of this subphase is to produce the \rlp{}-prefix of the list of log topics $O_\textbf{t}$; this list is either empty or composed of 1, 2, 3 or 4 topics ($\in\mathbb{B}_{32}$); as such the size of its \rlp{}-ization and the associated \rlp{} prefix are simple to determine: they are a deterministic function of the underlying logging instruction, and their computation does not require a call to a comlex constraint system. \saNote{} This subphase applies even for \inst{LOG0} isntructions (whose series of log topics, $(\,)$, must also be \rlp{}-ized). \\ + We provide a little more insight. The main distinctions are as follows: + (\emph{a}) + is the list empty? + (\emph{b}) + is the list comprised of a single topic (so that its \rlp{}-ization has length $1 + 32 = 33$)? + \saNote{} $33 < 56$ so that the prefix consists of a single byte; + (\emph{c}) + does the sequence of log topics contain 2 or more topics (so that its \rlp{}-ization has length 66, 99 or 132 bytes)? + \saNote{} $56 \leq 66, 99, 132$: the prefix is thus comprised of 2 bytes: the first one containing \emph{essentially} the ``length of the length'' (which is 1 given that $132 < 256$) and the second one being the length proper. + \saNote{} For a logging operation triggered by a \inst{LOGX} instruction, with $\col{X} \in \{0, 1,\dots, 4\}$, the following relationship will hold \emph{at the beginning of this subphase} $\localsize = 33 \cdot \col{X}$. + The constraints are thus as follows: + \begin{enumerate}[resume] + \item \If ($\Depth 1_{i}=1$ (\trash) \et $\isprefix_{i}=1$ \et $\isOt_{i}=1$ \et $\isOd_{i}=0$(\trash)) \Then: + \begin{enumerate} + % \item $\Input 1_{i} = \localsize_{i}$ + \item $\indexlocal_{i} = 0$ + \item $\nbstep_{i}=1$ + \item \If $\localsize_{i}=0$ \Then: + \begin{enumerate} + \item $\limb = \rlprefixShortList \cdot 256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \item $\Input{2}_{i+1}=\indexlocal_{i}$ (see section \ref{lookup_log_info}) + \item We switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 1 & \\ + \isOt_{i + 1} & = & 0 & \\ + \isOd_{i + 1} & = & 1 & \\ + \end{array} \right. + \] + \end{enumerate} + \saNote{} When the $\localsize$ column vanishes in the subphase, the module immediately switches to the data phase(s), cf. table~\ref{fig: phase 4 subphase table}; + \item \If $\localsize_{i} \ne 0$ \Then: + \begin{enumerate} + \item \If $\localsize_{i} = 33$ \Then: + \begin{enumerate} + \item $\limb_{i}= (\rlprefixShortList + \localsize_{i}) \cdot 256^{\llargeMO}$ + \item $\limbsize_{i} = 1$ + \end{enumerate} + \item \If $\localsize_{i} \ne 33$ \Then: + \begin{enumerate} + \item $\limb_{i}= (\rlprefixLongList + 1) \cdot 256^{\llargeMO} + \localsize_{i} \cdot 256^{14}$ + \item $\limbsize_{i} = 2$ + \end{enumerate} + \item We switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 0 & \\ + \isOt_{i + 1} & = & 1 & \\ + \isOd_{i + 1} & = & 0 & \\ + \end{array} \right. + \] + \end{enumerate} + \end{enumerate} + \end{enumerate} + \item[\underline{RLP of the log topics $O_{\mathbf{t_{i}}}$:}] the constraints below apply only when this subphase isn't skipped (i.e. for logging operations other than \inst{LOG0}): + \begin{enumerate}[resume] + \item \If ($\Depth 1_{i}=1$ (\trash) \et $\isprefix_{i}=0$ \et $\isOt_{i}=1$ \et $\isOd_{i}=0$ (\trash)) \Then: + \begin{enumerate} + \item $\nbstep_{i}=3$ + \item \If $\Done_{i}=1$ \Then: + \item $\lc_{i-2}=1$ + In other words all three rows of the current counter-cycle contribute limbs of data. The contents of that data aresettled below: the first part is the $\rlp{}$ prefix associated with a slice of bytes of length 32, followed by the llarge-leading bytes of the current topic and the next $\llarge$ lower bytes of the topic (as found in the inputcolumns): + \begin{enumerate} + \item $\indexlocal_{i} + \indexlocal_{i - 2} = 2 \cdot (\indexlocal_{i-3} + 1)$ + In other words: the local index jumps by 1 from row $i-3$ to $i-2$ and remains at that value until the end of the current counter-cycle. + \saNote{} For a \inst{LOGX} instruction with nonzero $\col{X}$ the \indexlocal{} column will count from $1$ to $\col{X}$ (incrementing by 1 with every new log topic.) See also + \item $\limb_{i-2}= (\rlprefixShortInt + 32) \cdot 256^{\llargeMO}$ + \item $\limbsize_{i-2}=1$ + \item $\limb_{i-1}=\Input 1 _{i}$ + \item $\limbsize_{i-1}=\llarge$ + \item $\limb_{i}=\Input 2 _{i}$ + \item $\limbsize_{i}=\llarge$ + \item \If $\localsize_{i} \ne 0$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 0 & \\ + \isOt_{i + 1} & = & 1 & \\ + \isOd_{i + 1} & = & 0 & \\ + \end{array} \right. + \] + \saNote{} In other words the module remains in the current subphase. + \item \If $\localsize_{i}=0$ \Then: + \begin{enumerate} + \item $\Input 2_{i+1} = \indexlocal_{i}$ + \saNote{} This constraint is important: it is what achieves the desired property that a \inst{LOGX} instruction be provided with precisely \col{X} topics. Indeed, when the present constraint is active, the contents of $\Input{2}_{i + 1}$ is precisely \col{X}, see section \ref{lookup_log_info}. + \item We switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 1 & \\ + \isOt_{i + 1} & = & 0 & \\ + \isOd_{i + 1} & = & 1 & \\ + \end{array} \right. + \] + \end{enumerate} + \saNote{} This marks the end of the current subphase and the transition the ``log data'' subphase(s). + \end{enumerate} + \end{enumerate} + \end{enumerate} + \item[\underline{RLP prefix of $O_{\mathbf{d}}$:}] the prefix to prepend to the data slice $O_{\mathbf{d}}$ is a function of its size, and, for log data of size 1, of its content. Recall that during the log data prefix phase the contents of the $\Input{1}$ column is the \textbf{(log) data size} of the instruction. + \begin{enumerate}[resume] + \item \If %($\Depth 1_{i}=1$ (\trash) \et $\isprefix_{i}=1$ \et $\isOt_{i}=0$ (\trash) \et $\isOd_{i}=1$) \Then: + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i} & = & 1 & (\trash) \\ + \isprefix_{i} & = & 1 & \\ + \isOt_{i} & = & 0 & (\trash) \\ + \isOd_{i} & = & 1 & \\ + \end{array} \right. + \] + \Then + \begin{enumerate} + \item $\Input 1_{i} = \localsize_{i}$ \\ + \saNote{} $\Input{1}_{i}$ will contain the size of the data to log, see section~(\ref{}). \\ + \saNote{} $\localsize$ thus inherits $\Input{1}$'s counter-constancy during this subphase. + \item \If $\localsize_{i}=0$ \Then: + \begin{enumerate} + \item $\nbstep_{i} = 1$ + \item $\ispadding_{i}=0$ + \item $\limb_{i}=\rlprefixShortInt \cdot 256^{\llargeMO}$ + \item $\limbsize_{i}=1$ + \item $\logentrysize_{i}=0$ + + \saNote{} the above expresses the requirement that there remain no more data to log for the present log entry. + \item \If $\phasesize_{i} \ne 0$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 1 & \\ + \isOt_{i + 1} & = & 0 & \\ + \isOd_{i + 1} & = & 0 & \\ + \end{array} \right. + \] + \saNote{} The above applies when there are remaining log entries for the present transaction. The next subphase is thus the beginning subphase of a new log entry. + \item \If $\phasesize_{i}=0$ \Then $\phasend_{i}=1$. \saNote{} This applies at the end of the \rlp{}-ization of the transaction receipt. + \end{enumerate} + \item \If $\localsize_{i} \ne 0$ \Then: + \begin{enumerate} + \item $\nbstep_{i}=8$ + \item \If $\localsize_{i} = 1$ \Then: + \begin{enumerate} + \item + \[ + \rlpPrefixInt + \left( \begin{array}{r} + \Input3, + \ct, + \nbstep, + \done; \\ + \byteCol1, + \acc1, + \accsize, + \col{POWER}, + \col{BIT}, + \col{BIT\_ACC}; \\ + \limb, + \lc, + \limbsize; \\ + \end{array} \right) + \] + \item $\ct_{i} \ne \nbstep_{i}-2$ \Then $\lc_{i}=0$ + \item \If $\done_{i}=1$ \Then: + \begin{itemize} + \item $\ispadding_{i-1} + \ispadding_{i} = 1$ + \item $\Input3_{i} \cdot 256^{\llargeMO}= \Input1_{i+1}$ + \end{itemize} + \end{enumerate} + \item \If $\localsize_{i} \ne 1$ \Then: + \begin{enumerate} + \item $\ispadding_{i}=0$ + \item $\lc$ is counter-incrementing + \item + \[ + \rlpPrefixByteString + \left( \begin{array}{r} + \Input1, + \ct, + \nbstep, + \done, + \phase{0}; \\ + \accsize, + \Power, + \col{BIT}, + \acc1, + \acc2; \\ + \lc, + \limb, + \limbsize; \\ + \end{array} \right) + \] + \end{enumerate} + \item \If $\Done_{i}=1$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 0 & \\ + \isOt_{i + 1} & = & 0 & \\ + \isOd_{i + 1} & = & 1 & \\ + \end{array} \right. + \] + \end{enumerate} + \end{enumerate} + \end{enumerate} + \item[\underline{Listing the data limbs of $O_{\mathbf{d}}$:}] recall that this is an optional phase (triggered \emph{iff} $\|O_\textbf{d}\|\neq0$): + \saNote{} Contrary to other subphases of phase 4, the $\nbstep$ column will remain (partially) \emph{unconstrained}, i.e. we won't set it \emph{explicitly} in the constraints themselves. General constraints remain true (counter-constancy and \ct{} counting from $0$ to $\nbstep - 1$ before resetting to $0$.) + \begin{enumerate}[resume] + \item \If %($\Depth 1_{i}=1$ (\trash) \et $\isprefix_{i}=0$ \et $\isOt_{i}=0$ (\trash) \et $\isOd_{i}=1$) \Then: + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i} & = & 1 & (\trash) \\ + \isprefix_{i} & = & 0 & \\ + \isOt_{i} & = & 0 & (\trash) \\ + \isOd_{i} & = & 1 & \\ + \end{array} \right. + \] + \Then + \begin{enumerate} + \item $\indexlocal_{i}=\ct_{i}$ + \item $\lc_{i}=1$ + \item $\limb_{i}=\Input 1 _{i}$ + \item \If $\Done_{i} = 0 $ \Then $\limbsize_{i}=\llarge$ + \item \If $\Done_{i}=1$ \Then + \begin{enumerate} + \item $\limbsize_{i}=\localsize_{i-1}$ $(\trash)$ + \item $\localsize_{i}=0$ + \item $\logentrysize_{i}=0$ + \item \If $\phasesize_{i} \ne 0$ \Then we switch to the following subphase + \[ + \left\{ \begin{array}{lclr} + \Depth 1_{i + 1} & = & 1 & (\trash) \\ + \isprefix_{i + 1} & = & 1 & \\ + \isOt_{i + 1} & = & 0 & \\ + \isOd_{i + 1} & = & 0 & \\ + \end{array} \right. + \] + \item \If $\phasesize_{i}=0$ \Then $\phasend_{i}=1$ + \end{enumerate} + \end{enumerate} + \end{enumerate} + \end{description} + We now specify some ``subphase independent'' behaviour of certain columns + \begin{description} + \item[\underline{Decrementation of $\logentrysize$:}] \label{spec of logentrysize} \If $\Depth{1}_{i}=1$ \Then + \begin{enumerate} + \item \If \Big( + $\isprefix_{i} = 1$ + \et $\isOt_{i} = 0$ + \et $\isOd_{i} = 0$ + \Big) \Then see constraint (\ref{spec of logentrysize missing case}) + \item \If \Big( + $\isprefix_{i} = 0$ + \Or $\isOt_{i} = 1$ + \Or $\isOd_{i} = 1$ + \Big)\footnote{In the implementation one may realize this condition (including that on $\Depth{1}$) through + ``\If $(1 - \Depth{1}_{i}) + + (1 - \isprefix_{i}) + + \isOt_{i} + + \isOd_{i} \neq 0$ \Then \dots{}''} \Then + \[ + \logentrysize_{i} = \logentrysize_{i-1} - \lc_{i} \cdot \limbsize_{i} + \] + \end{enumerate} + \saNote{} There is no need to constrain $\logentrysize$ when $\Depth{1}_{i}=0$. + \item[\underline{Decrementation of $\localsize$:}] --- + \begin{enumerate} + \item \If $\isprefix_{i}=0$ \et ($\isOt_{i} + \isOd_{i} \neq 0$) \Then + \[ \localsize_{i} = \localsize_{i-1} - \lc_{i} \cdot \limbsize_{i} \] + \end{enumerate} + \end{description} diff --git a/rlp_txnrcpt/tx_loop.tex b/rlp_txnrcpt/tx_loop.tex new file mode 100644 index 0000000..cb984ca --- /dev/null +++ b/rlp_txnrcpt/tx_loop.tex @@ -0,0 +1,23 @@ +The following table provides an explanation of what every phase is responsible for: +\begin{table}[h] + \centering + \def\noOrigin{$\graym{\varnothing}$} + \begin{tabular}{|c|c|c|c|c|c|c|c|c|c||c|} + \hline + \col{PHASE\_k} & \isprefix & $\Depth1$ & $\isOt $ & \isOd & Action & Origin \\ \hline + 1 & 1 & 0 & 0 & 0 & concatenation of the $TYPE$ byte & \txnMod{} \\ \hline + 1 & 0 & 0 & 0 & 0 & RLP prefix of the whole log tuple & \noOrigin{} \\ \hline + 2 & 0 & 0 & 0 & 0 & $\texttt{Rz}$ & \txnMod{} \\ \hline + 3 & 0 & 0 & 0 & 0 & $\texttt{Ru}$ & \txnMod{} \\ \hline + 4 & 1 & 0 & 0 & 0 & RLP prefix of $\texttt{Rb}$ & \noOrigin{} \\ \hline + 4 & 0 & 0 & 0 & 0 & concatenation of the byte of $\texttt{Rb}$ & \noOrigin{} \\ \hline + 5 & 1 & 0 & 0 & 0 & RLP prefix of $\texttt{Rl}$ & \noOrigin{} \\ \hline + 5 & 1 & 1 & 0 & 0 & RLP prefix of a log entry \texttt{O} & \noOrigin{} \\ \hline + 5 & 0 & 1 & 0 & 0 & RLP(\texttt{Oa}) & \logInfoMod{} \\ \hline + 5 & 1 & 1 & 1 & 0 & RLP prefix of \texttt{Ot} & \logInfoMod{} \\ \hline + 5 & 0 & 1 & 1 & 0 & RLP(log topics) & \logInfoMod{} \\ \hline + 5 & 1 & 1 & 0 & 1 & RLP prefix of \texttt{Od} & \logInfoMod{} \\ \hline + 5 & 0 & 1 & 0 & 1 & concatenation of the bytes of \texttt{Od} & \logDataMod{} \\ \hline + \end{tabular} + \caption{Transaction's loop} +\end{table} diff --git a/rom/_all_rom.tex b/rom/_all_rom.tex new file mode 100644 index 0000000..86b3b98 --- /dev/null +++ b/rom/_all_rom.tex @@ -0,0 +1,48 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{fontspec} +\usepackage{../pkg/common} +\usepackage{../pkg/std} +\usepackage{../pkg/env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/stack} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_patterns} +\usepackage{../pkg/log_info} + +\title{ROM module} +\author{Rollup team} +\date{July 2022} + +\begin{document} + + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/rom/_inputs.tex b/rom/_inputs.tex new file mode 100644 index 0000000..88c4344 --- /dev/null +++ b/rom/_inputs.tex @@ -0,0 +1,22 @@ +\def\es {\col{INV.}} +\def\ip {\col{PUSH4}} +\def\pe {\col{PUSH18}} +\def\gz {{\color{gray!60}\mathtt{0x\,0}}} +\def\qmda {{\color{gray!60}\overset{\displaystyle\vdots}?}} % Question Mark Dots Above +\def\qmdb {{\color{gray!60}\underset{\displaystyle\vdots}?}} % Question Mark Dots Bbove + +\section{The \romMod{} module} +\input{intro} +\input{columns} +\subsection{Constraints} +\input{binarity} +\input{bytehood} +\input{constancies} +\input{heartbeat} +\input{codesize_reached} +\subsubsection{\nBytes{} constraints} \input{nBytes} +\input{index} +\input{programe_counter} +\input{end_of_cfi} +\input{push} +\subsection{Instruction decoding of \inst{PUSHX} and \inst{JUMPDEST}} \label{rom: instruction decoding} \input{lookup_inst_decoder} diff --git a/rom/binarity.tex b/rom/binarity.tex new file mode 100644 index 0000000..7d22188 --- /dev/null +++ b/rom/binarity.tex @@ -0,0 +1,13 @@ +\subsubsection{Binarity} +The following columns are binary columns: +\begin{multicols}{2} +\begin{enumerate} + \item \CSR{} + \item \IPD{} + \item \PFB{} + \item \IP{} \quad (\trash) + \item \ISVALIDJUMPDESTINATION{} \quad (\trash) + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\saNote{} both \IP{} and \ISVALIDJUMPDESTINATION{} are instruction decoded, see section~(\ref{rom: instruction decoding}); their ``binary-ness'' is thus a given. diff --git a/rom/bytehood.tex b/rom/bytehood.tex new file mode 100644 index 0000000..b33fd85 --- /dev/null +++ b/rom/bytehood.tex @@ -0,0 +1,6 @@ +\subsubsection{Bytehood} +The following columns are byte: +\begin{enumerate} + \item \PBCB{} + \item \opc{} \quad (\trash{}) +\end{enumerate} \ No newline at end of file diff --git a/rom/codesize.tex b/rom/codesize.tex new file mode 100644 index 0000000..7632fa3 --- /dev/null +++ b/rom/codesize.tex @@ -0,0 +1,9 @@ +\subsubsection{\cs{} constraints and bytehood proofs} + + +The bytecode of a smartcontract cannot contain more than \texttt{0x6000} = 24576 bytes. We must thus enforce that $0\leq \CS{}\leq 24576$, for which it is enough to prove that +\begin{enumerate} + \item $0\leq \CS{} $ fits into two bytes, + \item $0\leq \DCS{}$ fits into two bytes where $\DCS{} = 24576 - \CS{}$. +\end{enumerate} +Note that $0=\CS{}$ is true of externally owned accounts. We thus introduce four byte columns (two which handle the byte decomposition of $\CS{}$ into two bytes, two that do the same for $\DCS{}$.) We interleave these columns with \opc{} and produce an associated bytehood proof. \ No newline at end of file diff --git a/rom/codesize_reached.tex b/rom/codesize_reached.tex new file mode 100644 index 0000000..caf0cdb --- /dev/null +++ b/rom/codesize_reached.tex @@ -0,0 +1,20 @@ +\subsubsection{\CSR{} constraints} + +\CSR{} equals 0 while the \pc{} hasn't reached \CS{}, at which point it equals 1 until the end of the current \cfi{}. We remind the reader that \CSR{} is \textbf{CFI-incrementing}. +\begin{enumerate} + \item \If $\pc_{i}=\cs_{i}-1$ \Then $\csr_{i}+\csr_{i+1}=1$ +\end{enumerate} + +Before \CSR{} switches to one, +we are given with \limb{} +of $\llarge$ bytes, +therefore a $\llarge$ long \ct{}-loop. +After the \CSR{} switches to one, we want at least $\evmWordSize$ padded bytes after, in case the last opcode is a \inst{PUSH\_32}. +\begin{enumerate}[resume] + \item \If $\cfi_{i} \neq 0$ \et $\ct_{i}=0$ \Then: + \begin{enumerate} + \item \If $\CSR_{i}=0$ \Then $\ctMax_{i} = \llargeMO$ + \item \If $\CSR_{i}=1$ \Then $\ctMax_{i} = \evmWordSizeMO$ + \end{enumerate} +\end{enumerate} + diff --git a/rom/columns.tex b/rom/columns.tex new file mode 100644 index 0000000..302e97c --- /dev/null +++ b/rom/columns.tex @@ -0,0 +1,39 @@ +\subsection{Columns description} + +The following column is used for book-keeping of different code fragments within the ROM. +\begin{enumerate} + \item \CFI{}: code-fragment-constant column; an unique (block)-identifier of a code fragment; abbreviated to \cfi{}; + \item $\cfiMax$: batch-wide maximal code fragment index; + \item \CS{}: a code-fragment-constant column containing the code size of the bytecode currently being loaded into ROM; abbreviated to \cs{}; + \item \CSR{}: a binary column that equals 0 at the onset of a given bytecode and reaches 1 at the point where $\pc_i=\CS_i$; abbreviated to \csr{}; + \item \pc{}: program counter (i.e. index of the byte in the current bytecode); + \item \limb{}: containing the 16 bytes slice of the padded bytecode; + \item \index{}: contains the index of the current \limb{}; starts at 0: + \item \nBytes{}: number of non-padded bytes of the \limb; + \item \nBytesAcc{}: an accumulator for \nBytes{}; + \item \ct{}: a periodic counter; it counts up from 0 to \ctMax{} in increments of 1 and resets; + \item \ctMax{}: a \ct{}-constant colomn, gives the high bound of \ct{}; + \item \PBCB{}: raw byte from the \limb{}; the \pbcb{} column lists the bytes from said bytecode one by one as well as some extraneous \texttt{0x00}'s beyond the \CS{} (padding); abbreviated to \pbcb{}; + \item \ACC{}: accumulate the \pbcb{} bytes; +\end{enumerate} +The following columns relate to the \inst{PUSH\_X} instructions that require particular constraints to work properly. +\begin{enumerate}[resume] + \item \IP{}: instruction decoded binary flag column that lights up for push instructions; abbreviated to \ip{}; + \item \PP{}: contains $X$ for \inst{PUSH\_X} instruction and the (\col{X}) data rows that follow that instruction; abbreviated to \pp{}; + \item \CP{}: counter who counts from 1 to \PP{} while under a \inst{PUSH}, else 0; + \item \IPD{}: binary flag that lights up for the $\col{X}$ rows following a \inst{PUSH\_X} instruction i.e. while $\ppo{} \neq 0$; abbreviated to \ipd{}; this flag selects those bytes from the bytecode that contribute to a push instruction's $\PV\HIGH$ or $\PV\LOW$; it also sets the \opc{} of said lines to \inst{INVALID}; abbreviated to \ipd{}; + \item \PV\HIGH{} and \PV\LOW{}: high and low part of the value that a push instruction pushes on stack; abbreviated to $\pv\high$ and $\pv\low$ respectively; + \item \PVA: ``accumulator'' variables used to construct $\PV\HIGH$ and $\PV\LOW$ byte by byte out of ``data carrying bytes''; abbreviated to $\pva$; + \item \PFB{}: a binary flag that matters for correctly contructing \PV\HIGH{} and \PV\LOW{}; abbreviated to \pfb{}; +\end{enumerate} + +The columns below are related to the bytecode itself: the bytes that make it up, how to interpret them (i.e. do they code for instructions or are they data carriers for a \inst{PUSH\_X} instruction?), how much to pad with \texttt{0x00}'s etc\dots: +\begin{enumerate}[resume] + \item \opc{}: the opcode associated to the \pbcb{}; depends on the the context i.e. on whether the byte is shadowed by a \inst{PUSH} instruction (i.e. \( \ipd{}=1 \)) and whether the \CSR{} flag is on (at which point we impose $\pbcb=\opc=\texttt{0x00}$); in all other circumstances \( \opc{} = \PBCB{} \); +\end{enumerate} + +The last column is a binary column: +\begin{enumerate}[resume] + \item \ISVALIDJUMPDESTINATION{}: lights up when the \opc{} is a \inst{JUMPDEST}; +\end{enumerate} +\saNote{} The \opc{} and \pbcb{} columns differ and what may be a byte corresponding to the \inst{JUMPDEST} opcode in the \pbcb{} column may be obscured in the \opc{} column if that byte pertains to a \inst{PUSH} instruction. As such the above precisely recognizes valid jump destinations as specified in the \ob{ref. to the EYP}. diff --git a/rom/constancies.tex b/rom/constancies.tex new file mode 100644 index 0000000..a6bf553 --- /dev/null +++ b/rom/constancies.tex @@ -0,0 +1,56 @@ +\subsubsection{Constancies} + +A column $\col{X}$ is \textbf{CFI-constant}\label{def: CFI constant} if it satisfies +\[ + \If ~ \Big(\cfi_i \ne \cfi_{i-1} +1 \Big) ~ \Then \col{X}_{i} = \col{X}_{i-1} +\] + +\noindent A column $\col{X}$ is \textbf{CFI-incrementing}\label{def: CFI incrementing} if it satisfies +\[ + \If ~ \Big(\cfi_i \ne \cfi_{i-1} + 1 \Big) ~ \Then \col{X}_{i} \in \{ \col{X}_{i-1} , 1 + \col{X}_{i-1}\} +\] + +\noindent A column $\col{X}$ is \textbf{counter-constant}\label{def: counter constant} if it satisfies +\[ + \If ~ \ct_i \neq \ctMax_{i} ~ \Then \col{X}_{i+1} = \col{X}_{i} +\] + +\noindent A column $\col{X}$ is \textbf{push-constant}\label{def: push constant} if it satisfies +\[ + \If ~ \CP_i \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i-1} +\] + +\noindent A column $\col{X}$ is \textbf{push-incrementing}\label{def: push incrementing} if it satisfies +\[ + \If ~ \CP_i \neq 0 ~ \Then \col{X}_{i} \in \{ \col{X}_{i-1} , 1 + \col{X}_{i-1}\} +\] + +\noindent The following columns are CFI constant: +\begin{enumerate} + \item \CS{} +\end{enumerate} + +\noindent The following columns are CFI incrementing: +\begin{enumerate} + \item \pc{} (\trash{}) + \item \CSR{} +\end{enumerate} + +\noindent The following columns are counter-constant: +\begin{enumerate} + \item \limb + \item \nBytes + \item \ctMax +\end{enumerate} + +\noindent The following columns are push-constant: +\begin{enumerate} + \item \PP{} + \item \PV\HIGH{} + \item \PV\LOW{} +\end{enumerate} + +\noindent The following columns are push-incrementing: +\begin{enumerate} + \item \PFB{} \quad (\trash) +\end{enumerate} diff --git a/rom/constancy.tex b/rom/constancy.tex new file mode 100644 index 0000000..3dc1455 --- /dev/null +++ b/rom/constancy.tex @@ -0,0 +1,7 @@ +\subsubsection{Constancy constraints} + +A column $X$ satisfies \textbf{full \CT{} constancy} if +\begin{enumerate} + \item \If $\ct_i \neq 15$ \Then $X_i=X_{i+1}$, + \item \If $\ct_i = 15$ \et $\cb_i = 0$ \Then $X_i=X_{i+1}$. +\end{enumerate} \ No newline at end of file diff --git a/rom/counter.tex b/rom/counter.tex new file mode 100644 index 0000000..9d89f0b --- /dev/null +++ b/rom/counter.tex @@ -0,0 +1,11 @@ +\subsubsection{\CT{} constraints} + +\begin{enumerate} + \item Initialization constraint: $\ct_{0} = 0$ + \item Transition constraints: + \begin{enumerate} + \item \If $\ct_{i}\neq 15$ \Then $\ct_{i+1} = \ct_{i} + 1$ + \item \If $\ct_{i}= 15$ \Then $\ct_{i+1} = 0$ + \end{enumerate} + \item Finalization constraint $\ct_{N-1} = 15$ (where the ROM execution trace has length $N$) +\end{enumerate} \ No newline at end of file diff --git a/rom/end_of_cfi.tex b/rom/end_of_cfi.tex new file mode 100644 index 0000000..37b6eb7 --- /dev/null +++ b/rom/end_of_cfi.tex @@ -0,0 +1,9 @@ +\subsubsection{End of the \cfi{}} +The constraints below impose that within the padding bytes\footnote{of which there are at least $\evmWordSize{}$ and at most $\evmWordSize + \llargeMO$} the \PBCB's are all zero. This is compatible with the final instruction of a code fragment being some \inst{PUSHX} instruction. +\begin{enumerate} + \item \If $\CSR_{i} = 1$ \Then: + \begin{enumerate} + \item $\PBCB_{i}=0$ + \item $\IP_{i}=0$ \quad (\trash) + \end{enumerate} +\end{enumerate} diff --git a/rom/heartbeat.tex b/rom/heartbeat.tex new file mode 100644 index 0000000..d50f908 --- /dev/null +++ b/rom/heartbeat.tex @@ -0,0 +1,56 @@ +\subsubsection{Heartbeat} + +The $\CFI{}$ acts as a "stamp" of the module: +\begin{enumerate} + \item $\cfi_{0}=0$ + \item $\cfi_{i + 1} \in \{ \cfi_{i}, 1 + \cfi_{i} \}$ + \item \If $\cfi_{i}=0$ \Then + \[ + \left\{ \begin{array}{lclr} + \ct_{i} & = & 0 \\ + \ctMax_{i} & = & 0 \\ + \pbcb_{i} & = & 0 \\ + \IP_{i} & = & 0 & (\trash) \\ + \IPD_{i} & = & 0 & (\trash) \\ + \CP & = & 0 & (\trash) \\ + \PP & = & 0 & (\trash) \\ + \PC & = & 0 & (\trash) \\ + \end{array} \right. + \] + \item \If $\cfi_{i} \neq 0$ \Then + \begin{enumerate} + \item $\ctMax_{i} \in \{ \llargeMO, \evmWordSizeMO \}$ (\trash) + \item \If $\ctMax_{i} = \llargeMO$ \Then $\cfi_{i+1}=\cfi_{i}$ + \item \If $\ct_{i} \ne \ctMax_{i}$ \Then $\cfi_{i+1}=\cfi_{i}$ + \item \If ($\ctMax_{i} = \evmWordSizeMO$ \et $\ct_{i} = \ctMax_{i}$) \Then $\cfi_{i+1}=\cfi_{i}+1$ + \end{enumerate} +\end{enumerate} + +\noindent The \CT{} column imposes cycles of \ctMax{} rows inside each \CFI{}. +\begin{enumerate}[resume] + % \item \If $\cfi_{i} \ne 0$ \Then + % \begin{enumerate} + \item \If $\ct_{i} \neq \ctMax_{i}$ \Then $\ct_{i+1} = \ct_{i} + 1$, + \item \If $\ct_{i} = \ctMax_{i}$ \Then $\ct_{i+1} = 0$, + % \end{enumerate} +\end{enumerate} +We impose the following constraint on the \textbf{last row}: +\begin{enumerate}[resume] + \item \If $\CFI_{N} \ne 0$ \Then + \begin{enumerate} + \item $\ct_{N} = \ctMax_{N}$ + \item $\ctMax_{N} = \evmWordSizeMO$ + \item $\cfi_{N}= \cfiMax_{N}$ + \end{enumerate} +\end{enumerate} +And we impose $\cfiMax$ to be constant all along the trace, except during the padding rows: +\begin{enumerate}[resume] + \item \If $\cfi_{i}=0$ \Then $\cfiMax_{i}=0$ + \item \If $\cfi_{i} \ne 0$ \Then $\cfiMax_{i}=\cfiMax_{i+1}$ +\end{enumerate} +We build an accumulator: +\begin{enumerate}[resume] + \item \If $\ct_{i}=0$ \Then $\ACC_{i} = \pbcb_{i}$ + \item \If $\ct_{i} \ne 0$ \Then $\ACC_{i} = 256 \cdot \ACC_{i-1} + \pbcb_{i}$ + \item \If $\ct_{i} = \ctMax_{i} $ \Then $\ACC_{i}=\limb_{i}$ +\end{enumerate} diff --git a/rom/index.tex b/rom/index.tex new file mode 100644 index 0000000..f05bdf8 --- /dev/null +++ b/rom/index.tex @@ -0,0 +1,17 @@ +\subsubsection{\index{} constraints} +\begin{enumerate} + \item \If $\cfi_{i} = 0$ \Then $\index_{i}= 0$ + \item \If $\cfi_{i} \neq \cfi_{i-1}$ \Then $\index_{i}= 0$ + \item \If \Big($\cfi_{i} \neq 0$ \et $\cfi_{i} \neq \cfi_{i-1} + 1$ \et $\ct_{i} = 0$\Big) \Then: + \[ \index_{i} = \index_{i-1}+1 \] + \item \If $\ct_{i} = \llarge$ \Then $\index_{i} = \index_{i-1}+1$ + \item \If ($\ct_{i} \ne 0$ \et $\ct_{i} \ne \llarge$) \Then $\index_{i} = \index_{i-1}$ +\end{enumerate} +\saNote{} The condition ``$\ct_{i} = \llarge$'' is only triggered in the zero-padding of bytecode that happens at the end of every code fragment tracing. This constraint imposes that the index grow by one at the expected row. + +\saNote{} The requirement to add two full zero limbs at the end of the code fragment stems from two different reasons: +(\emph{a}) +allowing for simple push value construction +(\emph{b}) +making the lookup $\rlpTxnMod \hookrightarrow \romMod$ work seamlessly. +The former module indeed appends two padding limbs to the end of initialization code. diff --git a/rom/intro.tex b/rom/intro.tex new file mode 100644 index 0000000..cd8e82d --- /dev/null +++ b/rom/intro.tex @@ -0,0 +1,28 @@ +\subsection{Introduction} + +The ROM contains the bytecodes of the contracts used within a batch of transaction as well as some associated metadata such as code size and code hash. Its main role in the overall design is to provide the Main Execution Trace with the correct sequence of instructions. Most of the arithmetization below focuses on building the ROM as a seqence of padded byte codes and of extracting the correct push values from it (i.e. the $X$-byte long arguments of actual \inst{PUSH\_X} instructions). + +There are three kinds of accesses to bytecode that the ROM deals with, with contract deployment being subdivided into 1 or 2 phases (since deployments may fail): +\begin{enumerate} +% \item loading auxiliary data associated to an address (i.e. its code size (\cs{})) for \inst{EXTCODESIZE} instructions); + \item loading the full bytecode of an already deployed smart contract to run it or to \inst{EXTCODECOPY} from it (or both); + \item deploying a smart contract through a transaction or \inst{CREATE(2)}: + \begin{enumerate} + \item loading the init code into ROM; + \item for successful deployments loading the bytecode that will be deployed at the relevant address into ROM. + \end{enumerate} +\end{enumerate} +\iffalse +\begin{enumerate} + \item the bytecodes of contracts whose bytecode is executed, + \item the initcodes of contract deployment (both through a deployment transaction and by means of \inst{CREATE} and \inst{CREATE2} instructions), whether deployment is successful or not, + \item the deployed bytecodes of contracts created during the transaction (regardless of whether it gets executed or not in that same transaction), + \item the bytecodes read through \inst{EXTCODECOPY}. +\end{enumerate} +The overarching proof system must check that the loaded bytecodes match the originally deployed bytecode. This requires hashing the bytecode and comparing it to the codehash found in the matching account. This validates the claimed codehash, codesize and the bytecode itself. + +But the ROM also contains small fragments of information about bytecodes that were accessed without being executed, i.e. +\begin{enumerate} + \item smart contracts whose bytecode was indirectly accessed through \inst{EXTCODEHASH} and \inst{EXTCODESIZE}. +\end{enumerate} +\fi diff --git a/rom/lookup_inst_decoder.tex b/rom/lookup_inst_decoder.tex new file mode 100644 index 0000000..85e60e4 --- /dev/null +++ b/rom/lookup_inst_decoder.tex @@ -0,0 +1,22 @@ +The lookup to the $\idMod$ module is constructed as follows: +\begin{description} + \item[\underline{Selector:}] none required; + \item[\underline{Source columns:}] from the \romMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\opc_{i}$ + \item $\IP_{i}$ + \item $\ISVALIDJUMPDESTINATION_{i}$ + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\item[\underline{Target columns:}] from the \idMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\opc_{j}$ + \item $\IP_{j}$ + \item $\ISVALIDJUMPDESTINATION_{j}$ + % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/rom/nBytes.tex b/rom/nBytes.tex new file mode 100644 index 0000000..e3d5cd4 --- /dev/null +++ b/rom/nBytes.tex @@ -0,0 +1,21 @@ +\begin{enumerate} + \item \If $\cfi_{i} \ne 0$ \Then: + \begin{enumerate} + \item \If $\ct_{i}=0$ \Then: + \begin{enumerate} + \item \If $\CSR_{i}=0$ \Then $\nBytesAcc_{i}=1$ + \item \If $\CSR_{i}=1$ \Then $\nBytesAcc_{i}=0$ + \end{enumerate} + \item \If $\ct_{i} \neq 0$ \Then: + \begin{enumerate} + \item \If $\CSR_{i}=0$ \Then $\nBytesAcc_{i}=\nBytesAcc_{i-1}+1$ + \item \If $\CSR_{i}=1$ \Then $\nBytesAcc_{i}=\nBytesAcc_{i-1}$ + \end{enumerate} + \end{enumerate} + \item \If $\ct_{i}=\ctMax_{i}$ \Then $\nBytesAcc_{i}=\nBytes_{i}$ +\end{enumerate} + +Note that by construction: +\begin{enumerate}[resume] + \item \nBytesAcc{} is CT-incrementing \quad \trash +\end{enumerate} \ No newline at end of file diff --git a/rom/programe_counter.tex b/rom/programe_counter.tex new file mode 100644 index 0000000..86ab2a4 --- /dev/null +++ b/rom/programe_counter.tex @@ -0,0 +1,11 @@ +\subsubsection{\PC{} constraints} + +The program counter \pc{} is local to a code fragment index; it starts at 0 and increases by 1 with every byte in the code fragment (i.e. padded bytecode): +\begin{enumerate} + \item \If \Big($\cfi_{i} \neq 0$ \et $\cfi_{i+1} \neq 1 + \cfi_{i}$\Big) \Then $\pc_{i+1}=1+\pc_{i}$; + \item \If $\cfi_{i+1}\neq \cfi_{i}$ \Then $\pc_{i+1}=0$ + % \begin{enumerate} + % \item $\pc_{i+1}=0$ + % \item $\ct_{i+1}=0$ + % \end{enumerate} +\end{enumerate} diff --git a/rom/push.tex b/rom/push.tex new file mode 100644 index 0000000..e12b47d --- /dev/null +++ b/rom/push.tex @@ -0,0 +1,94 @@ +\subsection{Constraints related to \inst{PUSH} instructions} + +The constraints below construct (the high and low parts of) the \PV{} for \inst{PUSH} instructions. We start by describing the ``non push data'' case: % We have an equivalence between the binary \IPD{} and the nullity of \CP{}. +\begin{enumerate} + \item \If $\IPD_{i}=0$ \Then: + \begin{enumerate} + \item $\CP_{i}=0$ + \item $\opc_{i}=\PBCB_{i}$ + % \item \If $\IP_{i}=0$ \Then $\IPD_{i + 1}=0$ + \end{enumerate} +\end{enumerate} +We now deal with the ``push data'' case. +Constraints when not in a \inst{PUSH} instruction: +Initialisation of a \inst{PUSH} instruction: +\begin{enumerate}[resume] + \item We impose $\IP_{i} \cdot \IPD_{i} = 0$ + \item We impose $(1 - \IP_{i}) \cdot (1 - \PFB_{i}) = 0$ \quad (\trash) + \item \If $\IP_{i}=1$ \Then $\IPD_{i + 1}=1$ + \item \If $\IPD_{i}=1$ \Then \Big($\IPD_{i-1} + \IP_{i-1} = 1$\Big) +\end{enumerate} +We further initialize some data when encountering a \inst{PUSHX} instruction: +\begin{enumerate}[resume] + \item \If $\IP_{i}=1$ \Then: + \begin{enumerate} + \item $\PP_{i} = \opc_{i} - \inst{PUSH1} + 1 \in \{ 1, 2, \dots, 31, 32 \}$ + \item $\PVA_{i}=0$ + \item $\pfb_{i} + \pfb_{i + 1} = 0$ + \end{enumerate} +\end{enumerate} +Construction of (the high and low parts of) the \PV{}: +\begin{enumerate}[resume] + \item \If $\IPD_{i}=1$ \Then + \begin{enumerate} + \item $\opc_i=\inst{INVALID}$; + \item $\CP_{i}=\CP_{i-1}+1$ + \item \If $\CP_{i} + \llarge \ne \PP_{i}$ \Then: + \begin{enumerate} + \item \If $\ipd_{i + 1} = 1$ \Then $\pfb_{i + 1}=\pfb_{i}$ + \end{enumerate} + \item \If $\CP_{i} + \llarge = \PP_{i}$ \Then: + \begin{enumerate} + \item $\pfb_{i + 1} = 1 + \pfb_{i}$\footnote{i.e., since \pfb{} is push-incrementing, $\pfb_{i} = 0$ \et $\pfb_{i + 1}=1$ or alternatively $\pfb_{i} + \pfb_{i + 1}=1$} + % \item $\PVA_{i + 1} = \PBCB_{i + 1}$ + \item $\PVA_{i}=\PV\high_{i}$ + \end{enumerate} + \item \If ($\pfb_{i} = \pfb_{i - 1}$) \Then $\pva_{i} = 256 \cdot \pva_{i - 1} + \pbcb_{i}$ + \item \If ($\pfb_{i} \neq \pfb_{i - 1}$) \Then $\pva_{i} = \pbcb_{i}$ + \item \If $\CP_{i} = \PP_{i}$ \Then: + \begin{enumerate} + \item \If $\PFB_{i} = 0$ \Then $\PV\high_{i} = 0$ + \item $\PVA_{i}=\PV\low_{i}$ + \item $\IPD_{i + 1}=0$ + \end{enumerate} + \end{enumerate} +\end{enumerate} +% We prevent an unwanted switch to \IPD{}: +% \begin{enumerate}[resume] +% \end{enumerate} +Note that we have implicitly +\begin{enumerate}[resume] + \item \If $\IPD_{i}=1$ \Then $\CP_{i} \ne 0$ \quad (\trash) +\end{enumerate} + + +The table below shows two exemples, for \inst{PUSH4} and \inst{PUSH20}. + +\[ +\begin{array}{|c|c|c|c|c|c|c|c|c|c|} +\hline +\opc & \ip{} & \pp{} & \ipd{} & \cp{} & \pbcb{} & \pfb{} & \pva & \pv\high{} & \pv\low{} \\\hline +\inst{PUSH4} & 1 & 4 & 0 & 0 & \mathtt{0x\,63} & 0 & 0 & 0 & \mathtt{0x\,abcd} \\\hline +\inst{INVALID} & 0 & 4 & 1 & 1 & \mathtt{0x\,a} & 0 & \mathtt{0x\,a} & 0 & \mathtt{0x\,abcd} \\\hline +\inst{INVALID} & 0 & 4 & 1 & 2 & \mathtt{0x\,b} & 0 & \mathtt{0x\,ab} & 0 & \mathtt{0x\,abcd} \\\hline +\inst{INVALID} & 0 & 4 & 1 & 3 & \mathtt{0x\,c} & 0 & \mathtt{0x\,abc} & 0 & \mathtt{0x\,abcd} \\\hline +\inst{INVALID} & 0 & 4 & 1 & 4 & \mathtt{0x\,d} & 0 & \mathtt{0x\,abcd} & 0 & \mathtt{0x\,abcd} \\\hline +\end{array} +\] + + +\[ +\begin{array}{|c|c|c|c|c|c|c|c|c|c|} \hline +\opc & \ip{} & \pp{} & \ipd{} & \cp{} & \pbcb{} & \pfb{} & \pva & \pv\high{} & \pv\low{} \\ \hline +\inst{PUSH20} & 1 & 20 & 0 & 0 & \mathtt{0x\,73} & 0 & 0 & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 1 & \mathtt{0x\,a} & 0 & \mathtt{0x\,a} & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 2 & \mathtt{0x\,b} & 0 & \mathtt{0x\,ab} & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 3 & \mathtt{0x\,c} & 0 & \mathtt{0x\,abc} & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 4 & \mathtt{0x\,d} & 0 & {\cellcolor{\romCol}\mathtt{0x\,abcd}} & {\cellcolor{\romCol}\mathtt{0x\,abcd}} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 5 & \mathtt{0x\,e} & 1 & \mathtt{0x\,e} & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 6 & \mathtt{0x\,f} & 1 & \mathtt{0x\,ef} & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\vdots & \vdots & 20 & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 19 & \mathtt{0x\,s} & 1 & \mathtt{0x\,efghijklmnopqrs} & \mathtt{0x\,abcd} & \mathtt{0x\,efghijklmnopqrst} \\ \hline +\inst{INVALID} & 0 & 20 & 1 & 20 & \mathtt{0x\,t} & 1 & {\cellcolor{\romCol}\mathtt{0x\,efghijklmnopqrst}} & \mathtt{0x\,abcd} & {\cellcolor{\romCol}\mathtt{0x\,efghijklmnopqrst}} \\ \hline +\end{array} +\] diff --git a/rom_lex/_all_rom_lex.tex b/rom_lex/_all_rom_lex.tex new file mode 100644 index 0000000..2bb631a --- /dev/null +++ b/rom_lex/_all_rom_lex.tex @@ -0,0 +1,43 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/env} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/lex} + +\title{Lexicographic ordering constraints} +\author{Rollup team} +\date{July 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/rom_lex/_inputs.tex b/rom_lex/_inputs.tex new file mode 100644 index 0000000..ef750ac --- /dev/null +++ b/rom_lex/_inputs.tex @@ -0,0 +1,9 @@ +\section{The \romLexMod{} module} +\subsection{Introduction} \input{intro} +\subsection{Columns} \input{columns} +\subsection{Binary and bytehood constraints} \input{binary_bytes} +\subsection{Heartbeat} \input{heartbeat} +\subsection{$\CH$ constraints} \input{codehash} +\subsection{Lexicographic ordering constraints} \input{constraints} +\section{Lookups} +\input{lookup_rom} diff --git a/rom_lex/binary_bytes.tex b/rom_lex/binary_bytes.tex new file mode 100644 index 0000000..04fcda1 --- /dev/null +++ b/rom_lex/binary_bytes.tex @@ -0,0 +1,8 @@ +We impose that the following columns be \textbf{binary}: +\begin{enumerate} + \item \depStatus{} + \item \readFromState{} + \item \commitToState{} + \item $[\col{@}_{k}]$, for $k \in \{1, 2, \dots, 4 \}$ +\end{enumerate} +We further impose \textbf{bytehood} constraints on the following $\llarge$ columns: $\byteCol{k}$ for $k \in \{0, 1, \dots, \llargeMO\}$. diff --git a/rom_lex/codehash.tex b/rom_lex/codehash.tex new file mode 100644 index 0000000..e324219 --- /dev/null +++ b/rom_lex/codehash.tex @@ -0,0 +1,10 @@ +We impose the value of the codehash for init code: +\begin{enumerate} + \item \If $\depStatus_{i}=1$ \Then + \[ + \left\{\begin{array}{lcl} + \CH\high_{i} & = & \emptyKeccakHi \\ + \CH\high_{i} & = & \emptyKeccakLo \\ + \end{array}\right. + \] +\end{enumerate} diff --git a/rom_lex/columns.tex b/rom_lex/columns.tex new file mode 100644 index 0000000..c9f706f --- /dev/null +++ b/rom_lex/columns.tex @@ -0,0 +1,13 @@ +\begin{enumerate} + \item \cfi{}: code fragment index; + \item $\cfiMax{}$: batch-wide maximal code fragment index; + \item $\codeSize$: containing the code size of the bytecode; + \item $\addrHi{}$ and $\addrLo{}$: high and low part of an address; + \item \depNum{}: deployment number + \item \depStatus{}: deployment status; + \item $\CH\high$ and $\CH\low$ high and low parts of the code hash; + \item \readFromState: binary column; + \item \commitToState: binary column; + \item $[\col{@}_{1}]$, $[\col{@}_{2}]$, $[\col{@}_{3}]$, $[\col{@}_{4}]$: binary columns; + \item $\byteCol{k}$, $k\in\{0, 1,\dots,\llargeMO\}$: byte columns; +\end{enumerate} diff --git a/rom_lex/constraints.tex b/rom_lex/constraints.tex new file mode 100644 index 0000000..cb46390 --- /dev/null +++ b/rom_lex/constraints.tex @@ -0,0 +1,14 @@ +We impose strict lexicographic constraints: +\begin{enumerate} + \item \If $\cfi_{i} \neq 0$ \Then + \[ + \strictLexConstraint\big[ +, +, +, - \big] + \left( + \begin{array}{c} + \addrHi, \addrLo, \depNum, \depStatus; \\ + \big[@_{1}\big], \big[@_{2}\big], \big[@_{2}\big], \big[@_{4}\big]; \\ + \byteCol{$\llargeMO$}, \dots, \byteCol{1}, \byteCol{0}, \\ + \end{array} + \right)_{i} + \] +\end{enumerate} diff --git a/rom_lex/heartbeat.tex b/rom_lex/heartbeat.tex new file mode 100644 index 0000000..7d52071 --- /dev/null +++ b/rom_lex/heartbeat.tex @@ -0,0 +1,15 @@ +The heartbeat of the present module is very, very simple: \cfi{} serves as its ``stamp'' and every stamp occupies a single row. The $\cfiMax$ column remains constant outside of padding and coincides with the final value of \cfi{}. +\begin{enumerate} + \item $\cfi_{0} = 0$ + \item \If $\cfi_{i} = 0$ \Then $\cfiMax_{i} = 0$; + \item $\cfi_{i + 1} \in \{ \cfi_{i}, 1 + \cfi_{i}\}$ + \item \If $\cfi_{i} \neq 0$ \Then + \[ + \left\{\begin{array}{lcl} + % \sum_{k = 1}^4 [\col{@}_{k}]_{i} = 1 \\ + \cfi_{i + 1} & = & 1 + \cfi_{i} \\ + \cfiMax_{i + 1} & = & \cfiMax_{i} \\ + \end{array}\right. + \] + \item \If $\cfi_{N} \neq 0$ \Then $\cfi_{N} = \cfiMax_{N}$ +\end{enumerate} diff --git a/rom_lex/intro.tex b/rom_lex/intro.tex new file mode 100644 index 0000000..e23545b --- /dev/null +++ b/rom_lex/intro.tex @@ -0,0 +1,3 @@ +The present module performs a simple function: enact the lexicographic ordering constraints required by the \romMod{} module. The lexicographic ordering constraints in the \romMod{} module serve a single purpose: ensure code uniqueness i.e. that any \textbf{code fragment identifier} uniquely identifies a particular piece of bytecode. What we call code fragment identifier is the following data: address, deployment number and deployment status. Allowing for two different code fragments to have the same identifier would have deleterious consequences. Indeed, the \hubMod{} references instructions by means of (\emph{a}) a code fragment identifier and (\emph{b}) a program counter \pc{} (index of opcode in the bytecode.) If a given identifier were be associated with several code fragments a malicious prover could potentially choose, for a given \pc{} value, between several opcodes. A malicious attacker could furthermore perform illegal jumps i.e. jump to positions within the code that are precluded under jump destination analysis or on the contrary declare a legal jump illegal. Finally a malicious attacker could return a given code fragment when deploying a smart contract but commit to a different one in the state. Ensuring a one to one correspondence between code fragment identifiers and code fragments is thus of paramount importance. + +The \romMod{} module enables this one to one correspondence by requiring code fragments to be listed according to a lexical order imposed on code fragment identifiers. Enforcing such constraints inside of the \romMod{} would be very expensive: (\emph{a}) the \romMod{} module is consistently several million rows deep (\emph{b}) verifying \emph{weak} lexicographic ordering constraints on $n$ columns (here $n=4$) require the introduction of $n+1$ boolean columns and $\llarge$ byte columns. In applications the number of referenced code fragments in a block on the order of a few hundred at most. The present module will therefore also only contain on the order of a few hundred (non padding) rows. Also since it enforces a \emph{strict} lexicographic ordering it only requires $n$ boolean columns. It therefore pays off to off-load this constraint system to a dedicated, much shallower module. diff --git a/rom_lex/lookup_rom.tex b/rom_lex/lookup_rom.tex new file mode 100644 index 0000000..b558a29 --- /dev/null +++ b/rom_lex/lookup_rom.tex @@ -0,0 +1,22 @@ +\subsubsection{\romLexMod{} $\hookrightarrow$ \romMod{}} +The lookup from the $\romLexMod$ module connects the \CFI{} associated in the \romLexMod{} to an address, a deployment number and deployment status, to the associated bytecode in the \romMod{}; it is constructed as follows: +\begin{description} + \item[\underline{Selector:}] none; + \item[\underline{Source columns:}] from the \romLexMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi_{i}$ + \item $\cfiMax_{i}$ + \item $\codeSize_{i}$ + \end{enumerate} + \end{multicols} +\item[\underline{Target columns:}] from the \romMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi_{j}$ + \item $\cfiMax_{j}$ + \item $\codeSize_{j}$ + \end{enumerate} + \end{multicols} +\end{description} +\saNote{} This is the only place where the $\cfiMax{}$ column is properly constrained (in the present module it is only required to be constant along non padding rows.) diff --git a/shf/_all_shf.tex b/shf/_all_shf.tex new file mode 100644 index 0000000..6c4a6c2 --- /dev/null +++ b/shf/_all_shf.tex @@ -0,0 +1,43 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +\usepackage{xkeyval} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu_old} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/public} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/stack} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/shifting} +\usepackage{../pkg/iomf_done} + +\title{Shift module} +\author{Rollup team} +\date{October 2022 / January 2023} + +\begin{document} + +\maketitle +\tableofcontents +\input{_inputs} + +\end{document} diff --git a/shf/_inputs.tex b/shf/_inputs.tex new file mode 100644 index 0000000..9788a36 --- /dev/null +++ b/shf/_inputs.tex @@ -0,0 +1,19 @@ +\section{Shift module} +\subsection{Introduction} \input{instructions} +\subsection{Columns} \input{columns} +\section{Constraints} +\subsection{Heartbeat} \label{shf: heartbeat} \input{heartbeat} +\subsection{Constancies} \label{shf: constancies} \input{constancies} +\subsection{Binary columns} +\subsubsection{Binary constraints} \input{binary} +\subsubsection{\shd{} constraints} \input{shd} +\subsubsection{\oli{} constraints} \input{oli} +\subsubsection{Plateau constraints} \input{plateau} % TODO: was previously commented for some reason ... +\subsubsection{\someBits{} constraints} \input{someBits} \input{someBits_bits} +\subsubsection{\known{} constraints} \input{known} +\subsection{Byte decompositions and bytehood constraints} \label{shf: byte dec} \input{byteDec} \input{bytehood} +\subsection{Target constraints} \label{shf: target} \input{target} +\subsection{Shifting constraints} \input{shift_by} +\subsection{Shifted bytes constraints} \input{shiftedBytes} +\subsection{Result bytes constraints} \input{result} +\subsection{\col{LA}, \col{RA} and \col{ONES}} \input{la_ra_ones} diff --git a/shf/binary.tex b/shf/binary.tex new file mode 100644 index 0000000..add9ca9 --- /dev/null +++ b/shf/binary.tex @@ -0,0 +1,12 @@ +We impose binary constraints on the following columns: +\begin{multicols}{3} +\begin{enumerate} + \item $\bit{k}$ for $k \in \{1, 2, 3, 4\}$ + \item $\bit{b_{k}}$ for $k \in \{3, 4, 5, 6, 7\}$ + \item $\someBits$ + \item $\NEG$ + \item $\oli$ + \item $\shd$ + \item $\known$ +\end{enumerate} +\end{multicols} \ No newline at end of file diff --git a/shf/byteDec.tex b/shf/byteDec.tex new file mode 100644 index 0000000..300a161 --- /dev/null +++ b/shf/byteDec.tex @@ -0,0 +1,9 @@ +We impose the following byte decomposition constraints: +\begin{enumerate} + \item \If $\shfStamp_{i} \neq 0$ \et $\oli_{i} = 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_i$ + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i - 1} + \byteCol{k}_i$ + \end{enumerate} +\end{enumerate} +for $k = 1,2,3,4,5$. \ No newline at end of file diff --git a/shf/bytehood.tex b/shf/bytehood.tex new file mode 100644 index 0000000..4febabf --- /dev/null +++ b/shf/bytehood.tex @@ -0,0 +1,5 @@ +We impose bytehood constraints on the following columns: +\begin{enumerate} + \item $\byteCol{k}$, $k\in\{1, 2, 3, 4, 5 \}$ + \item $\shiftedBytes{k}$, $k\in\{3, 4, 5, 6 \}$ +\end{enumerate} \ No newline at end of file diff --git a/shf/columns.tex b/shf/columns.tex new file mode 100644 index 0000000..b609c4b --- /dev/null +++ b/shf/columns.tex @@ -0,0 +1,48 @@ +The following are the columns of the shifting module. The first collection of columns determines the heartbeat. +\begin{enumerate} + \item $\iShfSTAMP$: imported column containing the shifting module stamp; grows monotonically; abbreviatged to $\iShfStamp$ + \item \iomf{}: + bit column, is zero when the stamp is zero, one when the stamp is not zero; + \item $\CT$: column which either hovers around 0 or grows monotonically from $0$ to $\llargeMO$ and resets to $0$; abbreviated to $\ct$; + \item $\OLI$: counter-constant binary column; determines if an instruction can be dealt with in one line or requires $\llarge$ lines to process; abbreviated to $\oli$; +\end{enumerate} +The first argument $\iArgOne = \col{s}$ of a shift instruction is the integer by which one shifts, the second argument $\iArgTwo = \col{v}$ is the value which one shifts. For instance: $\inst{SHL}$ computes $\col{v}\ll\col{s}$ and \inst{SHR} computes $\col{v}\gg\col{s}$. The result is recorded in $\iRes$. +\begin{enumerate}[resume] + \item $\iArgOneHi$, $\iArgOneLo$: high and low part of the first argument of a shift instruction; + \item $\iArgTwoHi$, $\iArgTwoLo$: high and low part of the second argument of a shift instruction; + \item $\iResHi$, $\iResLo$: high and low part of the result of executing the opcode; +\end{enumerate} +Given the stack pattern used for shift-instructions (i.e. $\stdSP$) +$\iArgOneHi$ and $\iArgOneLo$ are imports of $\sValHi{1}$ and $\sValLo{1}$, +$\iArgTwoHi$ and $\iArgTwoLo$ are imports of $\sValHi{3}$ and $\sValLo{3}$, +$\iResHi$ and $\iResLo$ are imports of $\sValHi{4}$ and $\sValLo{4}$ respectively. +\begin{enumerate}[resume] + \item $\iInst$: imported instruction column; + \item $\SHD$: binary column; abbreviated to $\shd$ + \item $\someBits$: binary column; + \item $\NEG$: counter-constant binary column; + \item $\known$: counter-constant binary column; +\end{enumerate} +When $\oli = 1$ the \someBits{} column is made to contain the bit decomposition of the most significant byte of $\iArgTwo$ and the least significant byte of $\iArgOne$. The most significant bit of $\iArgTwo$ is stored in the (counter-constant binary) column $\NEG$: when $\iArgTwo$ is interpreted as a signed integer, as in the case of a \inst{SAR} instruction, $\NEG$ thus contains the sign bit. If $\iArgOne$ differs from its least significant byte the result of applying \inst{SHR} or \inst{SHL} will be zero. The binary column $\known$ determines how $\iResHi$ and $\iResLo$ are computed: when $\known = 1$ the result of the shift is ``known in advance.'' +\begin{enumerate}[resume] + \item $\decLaHi$, $\decRaHi$, $\decLaLo$, $\decRaLo$: instruction decoded byte columns; + \item $\LT$: counter-constant columns with values in $\{0,1,\dots,7\}$; + \item $\MSHP$: counter-constant column with values in $\{0,1,\dots,7,8\}$; abbreviated to $\mshp$; +\end{enumerate} +The interpretation is as follows: +$\LT$ records the 3 least significant bits of $\iArgOne$; +$\mshp$ equals either $\LT$ or to $8 - \LT$ depending on whether the instruction shifts to the right or to the left; +$\decLaHi$, $\decRaHi$ are left aligned suffixes and right aligned prefixes of $\iArgTwoHi$ respectively; +$\decLaLo$, $\decRaLo$ are left aligned suffixes and right aligned prefixes of $\iArgTwoLo$ respectively. +Thus $\argTwoHi$ and $\argTwoLo$ are split in half at the bit index $\mshp$ and the resulting prefix and suffix are right-shifted and left-shifted respectively. +\begin{enumerate}[resume] + \item $\bit{k}$ for $k \in \{1, 2, 3, 4\}$: counter-constant binary columns + \item $\bit{b_{k}}$ for $k \in \{3, 4, 5, 6, 7\}$: counter-constant binary columns +\end{enumerate} +We introduce some byte columns: +\begin{enumerate}[resume] + \item $\byteCol{k}$, $k=1,2,3,4,5$: byte columns for byte accumulation; + \item $\acc{k}$, $k=1,2,3,4,5$: the corresponding accumulator columns; + \item $\shiftedBytes{k}\high, \shiftedBytes{k}\low$ for $k=3,4,5,6,7$: byte columns that contain the result of progressive shifts; +\end{enumerate} +\noindent Note that the ``final'' shifted bytes column one might expect from the arithmetization below is $\byteCol{5}$ \ No newline at end of file diff --git a/shf/constancies.tex b/shf/constancies.tex new file mode 100644 index 0000000..7dfc3ea --- /dev/null +++ b/shf/constancies.tex @@ -0,0 +1,34 @@ +We say that a column \col{X} is \textbf{stamp-constant} if it satisfies +\[ + \shfStamp_{i} = \shfStamp_{i-1} \implies \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose stamp constancy on the following columns: +\begin{multicols}{4} +\begin{enumerate} + \item $\iArgOneHi$ + \item $\iArgOneLo$ + \item $\iArgTwoHi$ + \item $\iArgTwoLo$ + \item $\iResHi$ + \item $\iResLo$ + \item $\iInst$ + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\noindent We say that a column \col{X} is \textbf{counter-constant} if it satisfies +\[ + \ct_{i} \neq 0 \implies \col{X}_{i} = \col{X}_{i - 1}. +\] +Note that the heartbeat constraints impose that $\iShfStamp$ is counter-constant. It follows that all imported columns are counter-constant. Note furthermore that $\shd$, which is derived from the (imported and thus) counter-constant column $\iInst$ is automatically counter constant. We further impose counter-constancy on the following columns: +\begin{multicols}{3} +\begin{enumerate} + \item $\bit{b_{k}}$ for $k \in \{3, 4, 5, 6, 7\}$ + \item $\NEG$ + \item $\shd$ + \item $\LT$ + \item $\mshp$ + \item $\oli$ + \item $\known$ +\end{enumerate} +\end{multicols} +Note that counter-constancy of $\shd$ and $\oli$ follows by construction. Note similarly that counter constancy of $\shd$ and of $\LT$ entail counter-constancy of $\mshp$. The associated counter-constancy constraints for $\shd$ and $\mshp$ may thus be omitted. \ No newline at end of file diff --git a/shf/counter_constancy.tex b/shf/counter_constancy.tex new file mode 100644 index 0000000..e69de29 diff --git a/shf/heartbeat.tex b/shf/heartbeat.tex new file mode 100644 index 0000000..1f274b6 --- /dev/null +++ b/shf/heartbeat.tex @@ -0,0 +1,27 @@ +The heartbeat of the shifting module is simple: once the $\iShfStamp$ is nonzero every instruction occupies either $1$ line or $\llarge$ lines depending on whether $\oli = 1$ or $\oli = 0$. +\begin{enumerate} + \item $\iShfStamp_0 = 0$ + \item $\iShfStamp_{i + 1} \in \{ \iShfStamp_{i}, 1 + \iShfStamp_{i} \}$ + \item \If $\iShfStamp_{i} = 0$ \Then $\iomf_{i} = 0$ + \item \If $\iShfStamp_{i} \neq 0$ \Then $\iomf_{i} = 1$ + \item \If $\iShfStamp_{i + 1} \neq \iShfStamp_{i}$ \Then $\ct_{i + 1} = 0$ + \item \If $\iShfStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\oli_{i} = 1$ \Then $\iShfStamp_{i + 1} = 1 + \iShfStamp_{i}$ + \item \If $\oli_{i} = 0$ + \begin{enumerate} + \item \If $\ct_{i} \neq \llargeMO$ \Then + \[ + \left\{ + \begin{array}{lcl} + \ct_{i + 1} & \!\!\! = \!\!\! & 1 + \ct_{i} \\ + \oli_{i + 1} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right. + \] + \item \If $\ct_{i} = \llargeMO$ \Then $\iShfStamp_{i + 1} = 1 + \iShfStamp_{i}$ + \end{enumerate} + \end{enumerate} + \item \If $\iShfStamp_{N} \neq 0$ \et $\oli_{N} = 0$ \Then $\ct_{N} = \llargeMO$ +\end{enumerate} +\ob{TODO: do we need to impose that instructions be $\in\{\inst{SHL}, \inst{SHR}, \inst{SAR}\}$ when $\shfStamp \neq 0$ and $0$ otherwise ? We do it in some modules \dots{}} \ No newline at end of file diff --git a/shf/instructions.tex b/shf/instructions.tex new file mode 100644 index 0000000..8155449 --- /dev/null +++ b/shf/instructions.tex @@ -0,0 +1,9 @@ +The \textbf{shifting module} deals with the following instrutions: +\begin{multicols}{3} +\begin{enumerate} + \item \inst{SHR} + \item \inst{SHL} + \item \inst{SAR} +\end{enumerate} +\end{multicols} +\noindent In previous iterations of our \zkEvm{} these instructions were dealt with in the binary module. \ No newline at end of file diff --git a/shf/known.tex b/shf/known.tex new file mode 100644 index 0000000..01b0900 --- /dev/null +++ b/shf/known.tex @@ -0,0 +1,26 @@ +The (counter-constant binary) column $\known{}$ matters only when $\oli = 0$ (i.e. $\iInst = \inst{SAR}$ or $\iArgOneHi = 0$.) It lights up whenever the result of the shifting operation is known in advance, that is the shift parameter is larger than a byte. In other words +\begin{enumerate} + \item \If $\ct_{i} = \llargeMO$ \Then + \begin{enumerate} + \item \If $\iInst_{i} = \inst{SAR}$ \Then + \[ + \left\{ + \begin{array}{lcl} + \If \iArgOneHi_{i} \neq 0 ~ \Then \known_{i} = 1 \\ + \If \iArgOneHi_{i} = 0 ~ \Then + \begin{cases} + \If \iArgOneLo_{i} \neq \byteCol{1}_{i} ~ \Then \known_{i} = 1 \\ + \If \iArgOneLo_{i} = \byteCol{1}_{i} ~ \Then \known_{i} = 0 \\ + \end{cases} \\ + \end{array} + \right. + \] + \item \If $\iInst_{i} \neq \inst{SAR}$ \Then + \[ + \begin{cases} + \If \iArgOneLo_{i} \neq \byteCol{1}_{i} ~ \Then \known_{i} = 1 \\ + \If \iArgOneLo_{i} = \byteCol{1}_{i} ~ \Then \known_{i} = 0 \\ + \end{cases} + \] + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/shf/la_ra_ones.tex b/shf/la_ra_ones.tex new file mode 100644 index 0000000..8e751aa --- /dev/null +++ b/shf/la_ra_ones.tex @@ -0,0 +1,146 @@ +The first two tables below represent the expected $\decoded{\la}$ and $\decoded{\ra}$ computed on a byte with (big endian) bit decomposition \texttt{abcdefgh} according to \LT{} and shift direction. The bottom table combines the two and outputs the expected left aligned suffix and right aligned prefix in terms of $\mshp{}$ (either $\LT$ or $8-\LT$ depending on $\shd$.) It also features the associated $\ONES{}$ column. + +\begin{figure}[!h] +\renewcommand{\arraystretch}{1.2} +\[ + \begin{array}{|c|r|l|} + \hline + \multicolumn{3}{|c|}{\phantom{\Big(}\textsc{left shift}\phantom{\Big(}} \\ + \hline + \LT{} & \multicolumn{1}{c|}{\decoded{\ra}} & \multicolumn{1}{c|}{\decoded{\la}} \\ \hline + 0 + &\texttt{\gray{0\,0\,0\,0\,0\,0\,0\,0}} + &\texttt{a\,b\,c\,d\,e\,f\,g\,h} + \\ \hline + 1 + &\texttt{\gray{0\,0\,0\,0\,0\,0\,0}\,a} + &\texttt{b\,c\,d\,e\,f\,g\,h\,\gray{0}} + \\ \hline + 2 + &\texttt{\gray{0\,0\,0\,0\,0\,0}\,a\,b} + &\texttt{c\,d\,e\,f\,g\,h\,\gray{0\,0}} + \\ \hline + 3 + &\texttt{\gray{0\,0\,0\,0\,0}\,a\,b\,c} + &\texttt{d\,e\,f\,g\,h\,\gray{0\,0\,0}} + \\ \hline + 4 + &\texttt{\gray{0\,0\,0\,0}\,a\,b\,c\,d} + &\texttt{e\,f\,g\,h\,\gray{0\,0\,0\,0}} + \\ \hline + 5 + &\texttt{\gray{0\,0\,0}\,a\,b\,c\,d\,e} + &\texttt{f\,g\,h\,\gray{0\,0\,0\,0\,0}} + \\ \hline + 6 + &\texttt{\gray{0\,0}\,a\,b\,c\,d\,e\,f} + &\texttt{g\,h\,\gray{0\,0\,0\,0\,0\,0}} + \\ \hline + 7 + &\texttt{\gray{0}\,a\,b\,c\,d\,e\,f\,g} + &\texttt{h\,\gray{0\,0\,0\,0\,0\,0\,0}} + \\ \hline + \end{array} + \qquad + \begin{array}{|c|r|l|} + \hline + \multicolumn{3}{|c|}{\phantom{\Big(}\textsc{right shift}\phantom{\Big(}} \\ + \hline + \LT{} & \multicolumn{1}{c|}{\decoded{\ra}} & \multicolumn{1}{c|}{\decoded{\la}} \\ \hline + 0 + &\texttt{a\,b\,c\,d\,e\,f\,g\,h} + &\texttt{\gray{0\,0\,0\,0\,0\,0\,0\,0}} + \\ \hline + 1 + &\texttt{\gray{0\,}a\,b\,c\,d\,e\,f\,g} + &\texttt{h\,\gray{0\,0\,0\,0\,0\,0\,0}} + \\ \hline + 2 + &\texttt{\gray{0\,0\,}a\,b\,c\,d\,e\,f} + &\texttt{g\,h\,\gray{0\,0\,0\,0\,0\,0}} + \\ \hline + 3 + &\texttt{\gray{0\,0\,0\,}a\,b\,c\,d\,e} + &\texttt{f\,g\,h\,\gray{0\,0\,0\,0\,0}} + \\ \hline + 4 + &\texttt{\gray{0\,0\,0\,0\,}a\,b\,c\,d} + &\texttt{e\,f\,g\,h\,\gray{0\,0\,0\,0}} + \\ \hline + 5 + &\texttt{\gray{0\,0\,0\,0\,0\,}a\,b\,c} + &\texttt{d\,e\,f\,g\,h\,\gray{0\,0\,0}} + \\ \hline + 6 + &\texttt{\gray{0\,0\,0\,0\,0\,0\,}a\,b} + &\texttt{c\,d\,e\,f\,g\,h\,\gray{0\,0}} + \\ \hline + 7 + &\texttt{\gray{0\,0\,0\,0\,0\,0\,0\,}a} + &\texttt{b\,c\,d\,e\,f\,g\,h\,\gray{0}} + \\ \hline + \end{array} +\] +\centering +\[ + \begin{array}{|c|c|c|c|} + \hline + \mshp{} & \multicolumn{1}{c|}{\decoded{\ra}} & \multicolumn{1}{c|}{\decoded{\la}} & \ONES{} \\ % & \leadingBit{}\\ + \hline + 0 + & \texttt{a\,b\,c\,d\,e\,f\,g\,h} + & \texttt{\gray{0\,0\,0\,0\,0\,0\,0\,0}} + & \texttt{\gray{0\,0\,0\,0\,0\,0\,0\,0}} \\ + % & \texttt{a}\\ + \hline + 1 + & \texttt{\gray{0}\,a\,b\,c\,d\,e\,f\,g} + & \texttt{h\,\gray{0\,0\,0\,0\,0\,0\,0}} + & \texttt{1\,\gray{0\,0\,0\,0\,0\,0\,0}} \\ + % & \texttt{a}\\ + \hline + 2 + & \texttt{\gray{0\,0}\,a\,b\,c\,d\,e\,f} + & \texttt{g\,h\,\gray{0\,0\,0\,0\,0\,0}} + & \texttt{1\,1\,\gray{0\,0\,0\,0\,0\,0}} \\ + % & \texttt{a}\\ + \hline + 3 + & \texttt{\gray{0\,0\,0}\,a\,b\,c\,d\,e} + & \texttt{f\,g\,h\,\gray{0\,0\,0\,0\,0}} + & \texttt{1\,1\,1\,\gray{0\,0\,0\,0\,0}} \\ + % & \texttt{a}\\ + \hline + 4 + & \texttt{\gray{0\,0\,0\,0}\,a\,b\,c\,d} + & \texttt{e\,f\,g\,h\,\gray{0\,0\,0\,0}} + & \texttt{1\,1\,1\,1\,\gray{0\,0\,0\,0}} \\ + % & \texttt{a}\\ + \hline + 5 &\texttt{\gray{0\,0\,0\,0\,0}\,a\,b\,c} + & \texttt{d\,e\,f\,g\,h\,\gray{0\,0\,0}} + & \texttt{1\,1\,1\,1\,1\,\gray{0\,0\,0}} \\ + % & \texttt{a}\\ + \hline + 6 + & \texttt{\gray{0\,0\,0\,0\,0\,0}\,a\,b} + & \texttt{c\,d\,e\,f\,g\,h\,\gray{0\,0}} + & \texttt{1\,1\,1\,1\,1\,1\,\gray{0\,0}} \\ + % & \texttt{a}\\ + \hline + 7 + & \texttt{\gray{0\,0\,0\,0\,0\,0\,0}\,a} + & \texttt{b\,c\,d\,e\,f\,g\,h\,\gray{0}} + & \texttt{1\,1\,1\,1\,1\,1\,1\,\gray{0}}\\ + % & \texttt{a}\\ + \hline + 8 &\texttt{\gray{0\,0\,0\,0\,0\,0\,0\,0}} + & \texttt{a\,b\,c\,d\,e\,f\,g\,h} + & \texttt{\gray{unspecified}} \\ + % & \texttt{a}\\ + \hline + \end{array} +\] +% \caption{} +\label{fig: split and shift bytes and ones} +\end{figure} \ No newline at end of file diff --git a/shf/oli.tex b/shf/oli.tex new file mode 100644 index 0000000..04d5c62 --- /dev/null +++ b/shf/oli.tex @@ -0,0 +1,17 @@ +The $\OLI$ column determines whether an instruction can be carried out in a single line. This happens \emph{iff} its result of the instruction is obvious from the start\footnote{Note that instructions with $\iArgOne\high = \iArgOne\low = 0$ could also be carried out in one line.}. +\begin{enumerate} + \item \If $\iShfStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\iInst_{i} \neq \inst{SAR}$ \et $\iArgOneHi_{i} \neq 0$ \Then $\oli_{i} = 1$, + \item \If $\iInst_{i} = \inst{SAR}$ \OR $\iArgOneHi_{i} = 0$ \Then $\oli_{i} = 0$. + \end{enumerate} +\end{enumerate} +In other words, +\[ +\left\{ +\begin{array}{lcl} + \oli_{i} = 1 & \iff & (\iInst_{i} - \inst{SAR}) \cdot \iArgOneHi_{i} \neq 0 \\ + \oli_{i} = 0 & \iff & (\iInst_{i} - \inst{SAR}) \cdot \iArgOneHi_{i} = 0 \\ +\end{array} +\right. +\] \ No newline at end of file diff --git a/shf/plateau.tex b/shf/plateau.tex new file mode 100644 index 0000000..7f4669a --- /dev/null +++ b/shf/plateau.tex @@ -0,0 +1,20 @@ +We impose the following plateau constraints: +\begin{enumerate} + \item \If $\shfStamp_{i} \neq 0$ \et $\oli_{i} = 0$ \Then + \begin{enumerate} + \item \If $\shd_{i} = 1$ \Then + \begin{enumerate} + \item $\plateau(\bit{1}, 1)$ \red{Deprecated $\dots$} + \item $\plateau(\bit{2}, 2)$ + \item $\plateau(\bit{3}, 4)$ + \item $\plateau(\bit{4}, 8)$ + \end{enumerate} + \item \If $\shd_{i} = 0$ \Then + \begin{enumerate} + \item $\plateau(\bit{1}, 15)$ \red{Deprecated $\dots$} + \item $\plateau(\bit{2}, 14)$ + \item $\plateau(\bit{3}, 12)$ + \item $\plateau(\bit{4}, 8)$ + \end{enumerate} + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/shf/result.tex b/shf/result.tex new file mode 100644 index 0000000..7527432 --- /dev/null +++ b/shf/result.tex @@ -0,0 +1,89 @@ +In this subsection we specify the bytes of the result columns $\iResHi$ and $\iResLo$. +Recall that given the target constraints from subsection~\ref{subsec: target}, these are recorded in the $\byteCol{4}$ and $\byteCol{5}$ byte columns. +Part of the specification of these columns is already done (the case where $\oli_{i} = 1$ sees the result columns $=0$.) +\[ + \boxed{\text{All constraints below are written under the assumption that }\shfStamp_{i}\neq 0\text{ and }\oli_{i} = 0.} +\] + +%\paragraph{$\iResHi$ and $\iResLo$ when $\known = 1$:} --- +%\paragraph{$\byteCol{4}$ and $\byteCol{5}$ when $\known = 1$:} --- +\begin{enumerate} + \item \If $\known_{i} = 1$ \Then + \begin{enumerate} + \item \If $\iInst_{i} \neq \inst{SAR}$ \Then + \[ + \left\{ + \begin{array}{l} +% \iResHi_{i} = 0 \\ +% \iResLo_{i} = 0 \\ + \byteCol{4}_{i} = 0 \\ + \byteCol{5}_{i} = 0 \\ + \end{array} + \right. + \] + \item \If $\iInst_{i} = \inst{SAR}$ \Then + \[ + \left\{ + \begin{array}{l} +% \iResHi_{i} = \NEG_{i} \cdot \left( 256^{\llarge} - 1 \right) \\ +% \iResLo_{i} = \NEG_{i} \cdot \left( 256^{\llarge} - 1 \right) \\ + \byteCol{4}_{i} = 255 \cdot \NEG_{i} \\ + \byteCol{5}_{i} = 255 \cdot \NEG_{i} \\ + \end{array} + \right. + \] + \end{enumerate} +%\end{enumerate} +% +%\paragraph{$\byteCol{4}$ and $\byteCol{5}$ when $\known = 0$.} --- +%\begin{enumerate} + \item \If $\known_{i} = 0$ \Then + \begin{enumerate} + \item \If $\shd_{i} = 0$ \Then + \begin{enumerate} + \item \If $\bit{b_7}_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{l} + \byteCol{4}_{i} = \shiftedBytes{7}\high_{i} \\ + \byteCol{5}_{i} = \shiftedBytes{7}\low_{i} \\ + \end{array} + \right. + \] + \item \If $\bit{b_7}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \byteCol{4}_{i} = \shiftedBytes{7}\low_{i} \\ + \byteCol{5}_{i} = 0 \\ + \end{array} + \right. + \] + \end{enumerate} + \item \If $\shd_{i} = 1$ \Then + \begin{enumerate} + \item \If $\bit{b_7}_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{l} + \byteCol{4}_{i} = \shiftedBytes{7}\high_{i} \\ + \byteCol{5}_{i} = \shiftedBytes{7}\low_{i} \\ + \end{array} + \right. + \] + \item \If $\bit{b_7}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \byteCol{4}_{i} = + \begin{cases} + \If \INST_{i} \neq \inst{SAR}:& 0 \\ + \If \INST_{i} \neq \inst{SHR}:& 255 \cdot \NEG_{i} \\ + \end{cases} \\ + \byteCol{5}_{i} = \shiftedBytes{7}\high_{i} \\ + \end{array} + \right. + \] + \end{enumerate} + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/shf/shd.tex b/shf/shd.tex new file mode 100644 index 0000000..69e4e38 --- /dev/null +++ b/shf/shd.tex @@ -0,0 +1,13 @@ +This subsection is about constraining $\shd$: it should equal $1$ \emph{iff} the instruction is a type of right shift i.e. \emph{iff} $\iInst\in\{\inst{SHR}, \inst{SAR}\}$. +\begin{enumerate} + \item \If $\shfStamp_{i}\neq 0$ Then + \[ + \left\{ + \begin{array}{l} + \If \iInst_{i} \neq \inst{SHL} ~ \Then \shd_{i} = 1 \\ + \If \iInst_{i} = \inst{SHL} ~ \Then \shd_{i} = 0 \\ + \end{array} + \right. + \] +\end{enumerate} +Note that (given that $\shfStamp_{i}\neq 0$) the constraint ``$\iInst_{i} = \inst{SHL}$'' may alternatively be cast as ``$\iInst_{i} \neq \inst{SHR}, \inst{SAR}$.'' \ No newline at end of file diff --git a/shf/shf_into_shfrt.tex b/shf/shf_into_shfrt.tex new file mode 100644 index 0000000..b2b8182 --- /dev/null +++ b/shf/shf_into_shfrt.tex @@ -0,0 +1,57 @@ +The \shfMod{} module requires two lookups to a \textbf{shift reference table}. The first lookup deals with the bytes from the high parts of both arguments and the $\ONES{}$ column, the second with the low parts of both arguments. + + +\begin{description} + \item[\underline{Selector:}] none required. + \item[\underline{Source columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\iomf_{i}$ + \item $\byteCol{2}{i}$ + \item $\MSHP_{i}$ + \item $\decLaHi_{i}$ + \item $\decRaHi_{i}$ + \item $\ONES_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\iomf_{j}$ + \item $\col{BYTE}_{j}$ + \item $\col{MSHP}_{j}$ + \item $\col{LAS}_{j}$ + \item $\col{RAP}_{j}$ + \item $\col{ONES}_{j}$ + \end{enumerate} + \end{multicols} +\end{description} + +\begin{description} + \item[\underline{Selector:}] none required. + \item[\underline{Source columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\iomf_{i}$ + \item $\byteCol{2}{i}$ + \item $\MSHP_{i}$ + \item $\decLaLo_{i}$ + \item $\decRaLo_{i}$ + \item [\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\iomf_{j}$ + \item $\col{BYTE}_{j}$ + \item $\col{MSHP}_{j}$ + \item $\col{LAS}_{j}$ + \item $\col{RAP}_{j}$ + \item [\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + + + diff --git a/shf/shift_by.tex b/shf/shift_by.tex new file mode 100644 index 0000000..08b3578 --- /dev/null +++ b/shf/shift_by.tex @@ -0,0 +1,120 @@ +This section contains the desription of two families of constraints: $\rightShiftBy_{k}$ and $\leftShiftBy_{k}$ indexed by $k\in\{1,\dots,\llargeMO\}$. +Their ``signatures'' differ slightly because \rightShiftBy{} is used both by \inst{SHR} and \inst{SAR}. + +\subsubsection{\leftShiftBy{} constraints} + +Suppose we are given an integer $k\in\{1,\dots,\llargeMO\}$ and +\begin{enumerate} + \item a locally-constant binary column $\bit{b}$; + \item a binary column $\bit{1}$; + \item two byte columns $\byteCol{1}$ and $\byteCol{2}$; + \item two byte columns $\byteCol{1}^\sigma$ and $\byteCol{2}^\sigma$; +\end{enumerate} +The desired interpretation is as follows: +$\bit{b}$ is either all $1$'s or all $0$'s; +$\bit{b}$ decides if a left shift is to take place or not; +$\bit{1}$ satisfies a plateau constraint with jump at $\ct = \llarge - k$; +$\byteCol{1}$ and $\byteCol{2}$ contain ``source bytes''; +together they make up the byte decomposition of two limbs (the high and low parts respectively of some EVM word); +$\byteCol{1}^\sigma$ and $\byteCol{2}^\sigma$ either coincide with $\byteCol{1}$ and $\byteCol{2}$ +(if $\bit{b} = 0$) or contain the bytes of the two limbs which represent the high and low part respectively of the left shift by $k$ bytes of the previously mentioned EVM word (if $\bit{b} = 1$.) + +We collect under the moniker $\leftShiftBy_{k}$ the following constraints: +\begin{description} + \item[Plateau constraint.] We impose $\plateau(\bit{1}, \llarge - k)$ + \item[Shifts / non shifts.] We impose that, + \begin{enumerate} + \item \If $\bit{b}_{i} = 0$ \Then + \[ + \begin{cases} + \byteCol{1}^\sigma_{i} = \byteCol{1}_{i} \\ + \byteCol{2}^\sigma_{i} = \byteCol{2}_{i} \\ + \end{cases} + \] + \item \If $\bit{b}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{lcl} + \If \bit{1}_{i} = 0 ~ \Then \byteCol{1}^\sigma_{i} & \!\!\! = \!\!\! & \byteCol{1}_{i + k} \\ + \If \bit{1}_{i} = 1 ~ \Then \byteCol{1}^\sigma_{i} & \!\!\! = \!\!\! & \byteCol{2}_{i - (\llarge - k)} \vspace{2mm} \\ + \If \bit{1}_{i} = 0 ~ \Then \byteCol{2}^\sigma_{i} & \!\!\! = \!\!\! & \byteCol{2}_{i + k} \\ + \If \bit{1}_{i} = 1 ~ \Then \byteCol{2}^\sigma_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right. + \] + \end{enumerate} +\end{description} +We subsume the preceding constraints in the expression +\[ + \leftShiftBy_{k} + \left( + \begin{array}{c} + \bit{b}, \bit{1}; \\ + \byteCol{1}, \byteCol{2}; \\ + \byteCol{1}^\sigma, \byteCol{2}^\sigma; \\ + \end{array} + \right) +\] +Again, the dependence on $\ct$ is implicit. + +\subsubsection{\rightShiftBy{} constraints} + +Suppose we are given an integer $k\in\{1,\dots,\llargeMO\}$ and +\begin{enumerate} + \item a locally-constant binary column $\bit{b}$; + \item a locally-constant binary column $\col{N}$; + \item a locally-constant column $\INST$; + \item a binary column $\bit{1}$; + \item two byte columns $\byteCol{1}$ and $\byteCol{2}$; + \item two byte columns $\byteCol{1}^\sigma$ and $\byteCol{2}^\sigma$; +\end{enumerate} +The desired interpretation is as follows: +$\bit{b}$ is either all $1$'s or all $0$'s; +$\bit{b}$ decides whether a right shift is to take place or not; +the locally-constant binary $\col{N}$ column is a ``sign bit''; +the locally-constant column $\INST$ equals either \inst{SHR} or \inst{SAR}; +$\bit{1}$ satisfies a plateau constraint with jump at $\ct = k$; +$\byteCol{1}$ and $\byteCol{2}$ contain ``source bytes''; +together they make up the byte decomposition of two limbs (the high and low parts respectively of some EVM word); +if $\bit{b} \equiv 0$ then $\byteCol{1}^\sigma$ and $\byteCol{2}^\sigma$ coincide with $\byteCol{1}$ and $\byteCol{2}$; +if $\bit{b} \equiv 1$ then $\byteCol{1}^\sigma$ and $\byteCol{2}^\sigma$ contain the bytes of the two limbs which represent the high and low part respectively of the right shift by $k$ bytes of the previously mentioned EVM word padded with $\texttt{11111111} = \texttt{0x\;ff}$'s if the ``sign bit'' $\col{N}$ is one and the ``instruction column'' $\INST$ equals \inst{SAR}. +Note that the constraints depend (implicitly) on the $\ct$ column. + +We collect under the moniker $\rightShiftBy_{k}$ the following constraints: +\begin{description} + \item[Plateau constraint.] We impose $\plateau(\bit{1}, k)$ + \item[Non shifts.] We impose that, \If $\bit{b}_{i} = 0$ \Then + \[ + \begin{cases} + \byteCol{1}^\sigma_{i} = \byteCol{1}_{i} \\ + \byteCol{2}^\sigma_{i} = \byteCol{2}_{i} \\ + \end{cases} + \] + \item[Shifts.] We impose that, \If $\bit{b}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{lcl} + \If \bit{1}_{i} = 0 ~ \Then \byteCol{1}^\sigma_{i} & \!\!\! = \!\!\! & + \begin{cases} + \If \INST_{i} \neq \inst{SAR}:& 0 \\ + \If \INST_{i} \neq \inst{SHR}:& 255 \cdot \col{N}_{i} \\ + \end{cases} \\ + \If \bit{1}_{i} = 1 ~ \Then \byteCol{1}^\sigma_{i} & \!\!\! = \!\!\! & \byteCol{1}_{i - k} \vspace{2mm} \\ + \If \bit{1}_{i} = 0 ~ \Then \byteCol{2}^\sigma_{i} & \!\!\! = \!\!\! & \byteCol{1}_{i + (\llarge - k)} \\ + \If \bit{1}_{i} = 1 ~ \Then \byteCol{2}^\sigma_{i} & \!\!\! = \!\!\! & \byteCol{2}_{i - k} \\ + \end{array} + \right. + \] +\end{description} +We subsume the preceding constraints in the expression +\[ + \rightShiftBy_{k} + \left( + \begin{array}{c} + \bit{b}, \bit{1}, \col{N}, \INST{}; \\ + \byteCol{1}, \byteCol{2}; \\ + \byteCol{1}^\sigma, \byteCol{2}^\sigma; \\ + \end{array} + \right) +\] +Again, the dependence on $\ct$ is implicit. \ No newline at end of file diff --git a/shf/shiftedBytes.tex b/shf/shiftedBytes.tex new file mode 100644 index 0000000..eef9a53 --- /dev/null +++ b/shf/shiftedBytes.tex @@ -0,0 +1,247 @@ +The present section constrains the byte column pairs +$\shiftedBytes{3}\high$ and $\shiftedBytes{3}\low$, +$\shiftedBytes{4}\high$ and $\shiftedBytes{4}\low$, +$\shiftedBytes{5}\high$ and $\shiftedBytes{5}\low$, +$\shiftedBytes{6}\high$ and $\shiftedBytes{6}\low$, +$\shiftedBytes{7}\high$ and $\shiftedBytes{7}\low$, +and $\byteCol{4}$, $\byteCol{5}$. +\[ + \boxed{\text{All constraints below are written under the assumption that }\shfStamp_{i}\neq 0\text{ and }\oli_{i} = 0.} +\] + +\paragraph{Constraining $\shiftedBytes{3}$.} --- +\begin{enumerate} + \item \If $\shd_{i} = 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \llargeMO$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{3}\high_{i} = \decLaHi_{i} + \decRaHi_{i + 1} \\ + \shiftedBytes{3}\low_{i} = \decLaLo_{i} + \decRaLo_{i + 1} \\ + \end{array} + \right. + \] + \item \If $\ct_{i} = \llargeMO$ + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{3}\high_{i} = \decLaHi_{i} + \decRaLo_{i - \llargeMO} \\ + \shiftedBytes{3}\low_{i} = \decLaLo_{i} \\ + \end{array} + \right. + \] + \end{enumerate} + \item \If $\shd_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} = 0$ + \[ + \left\{ + \begin{array}{l} + \If \iInst_{i} = \inst{SAR} ~ \Then \shiftedBytes{3}\high_{i} + = \NEG_{i} \cdot \ONES_{i} + + \decRaLo_{i} \\ + \If \iInst_{i} = \inst{SHR} ~ \Then \shiftedBytes{3}\high_{i} + = \decRaLo_{i} \\ + \shiftedBytes{3}\low_{i} = \decLaHi_{i + \llargeMO} + \decRaLo_{i}\\ + \end{array} + \right. + \] + \item \If $\ct_{i} \neq 0$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{3}\high_{i} = \decLaHi_{i - 1} + \decRaHi_{i} \\ + \shiftedBytes{3}\low_{i} = \decLaLo_{i - 1} + \decRaLo_{i} \\ + \end{array} + \right. + \] + \end{enumerate} + Note that (given $\shd_{i} = 1$) the constraints + ``$\If \iInst_{i} = \inst{SAR}$'' and ``$\If \iInst_{i} = \inst{SHR}$'' can be replaced by + ``$\If \iInst_{i}\neq\inst{SHR}$'' and ``$\If \iInst_{i}\neq\inst{SAR}$'' respectively. +\end{enumerate} + +\paragraph{Constraining $\shiftedBytes{4}$.} --- +\begin{enumerate} + \item \If $\shd_{i} = 0$ \Then $\leftShiftBy_{1}\left( + \begin{array}{c} + \bit{b_{3}}, \bit{1}; \\ + \shiftedBytes{3}\high_{i}, \shiftedBytes{3}\low_{i}; \\ + \shiftedBytes{4}\high_{i}, \shiftedBytes{4}\low_{i}; \\ + \end{array}\right)$ + \item \If $\shd_{i} = 1$ \Then $\rightShiftBy_{1}\left( + \begin{array}{c} + \bit{b_{3}}, \bit{1}, \NEG, \iInst; \\ + \shiftedBytes{3}\high_{i}, \shiftedBytes{3}\low_{i}; \\ + \shiftedBytes{4}\high_{i}, \shiftedBytes{4}\low_{i}; \\ + \end{array}\right)$ +\end{enumerate} + +\paragraph{Constraining $\shiftedBytes{5}$.} --- +\begin{enumerate} + \item \If $\shd_{i} = 0$ \Then $\leftShiftBy_{2}\left( + \begin{array}{c} + \bit{b_{4}}, \bit{2}; \\ + \shiftedBytes{4}\high_{i}, \shiftedBytes{4}\low_{i}; \\ + \shiftedBytes{5}\high_{i}, \shiftedBytes{5}\low_{i}; \\ + \end{array}\right)$ + \item \If $\shd_{i} = 1$ \Then $\rightShiftBy_{2}\left( + \begin{array}{c} + \bit{b_{4}}, \bit{2}, \NEG, \iInst; \\ + \shiftedBytes{4}\high_{i}, \shiftedBytes{4}\low_{i}; \\ + \shiftedBytes{5}\high_{i}, \shiftedBytes{5}\low_{i}; \\ + \end{array}\right)$ +\end{enumerate} + +\paragraph{Constraining $\shiftedBytes{6}$.} --- +\begin{enumerate} + \item \If $\shd_{i} = 0$ \Then $\leftShiftBy_{4}\left( + \begin{array}{c} + \bit{b_{5}}, \bit{3}; \\ + \shiftedBytes{5}\high_{i}, \shiftedBytes{5}\low_{i}; \\ + \shiftedBytes{6}\high_{i}, \shiftedBytes{6}\low_{i}; \\ + \end{array}\right)$ + \item \If $\shd_{i} = 1$ \Then $\rightShiftBy_{4}\left( + \begin{array}{c} + \bit{b_{5}}, \bit{3}, \NEG, \iInst; \\ + \shiftedBytes{5}\high_{i}, \shiftedBytes{5}\low_{i}; \\ + \shiftedBytes{6}\high_{i}, \shiftedBytes{6}\low_{i}; \\ + \end{array}\right)$ +\end{enumerate} + +\paragraph{Constraining $\shiftedBytes{7}$.} --- +\begin{enumerate} + \item \If $\shd_{i} = 0$ \Then $\leftShiftBy_{8}\left( + \begin{array}{c} + \bit{b_{6}}, \bit{4}; \\ + \shiftedBytes{6}\high_{i}, \shiftedBytes{6}\low_{i}; \\ + \shiftedBytes{7}\high_{i}, \shiftedBytes{7}\low_{i}; \\ + \end{array}\right)$ + \item \If $\shd_{i} = 1$ \Then $\rightShiftBy_{8}\left( + \begin{array}{c} + \bit{b_{6}}, \bit{4}, \NEG, \iInst; \\ + \shiftedBytes{6}\high_{i}, \shiftedBytes{6}\low_{i}; \\ + \shiftedBytes{7}\high_{i}, \shiftedBytes{7}\low_{i}; \\ + \end{array}\right)$ +\end{enumerate} + +\iffalse +\paragraph{Constraining $\shiftedBytes{4}$.} --- +\begin{enumerate} + \item \If $\bit{b_3}_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{4}\high_{i} = \shiftedBytes{3}\high_{i} \\ + \shiftedBytes{4}\low_{i} = \shiftedBytes{3}\low_{i} \\ + \end{array} + \right. + \] + \item \If $\bit{b_3}_{i} = 1$ \Then + \begin{enumerate} + \item \If $\shd_{i} = 0$ \Then + \begin{enumerate} + \item \If $\bit{2}_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{4}\high_{i} = \shiftedBytes{3}\high_{i + 2} \\ + \shiftedBytes{4}\low_{i} = \shiftedBytes{3}\low_{i + 2} \\ + \end{array} + \right. + \] + \item \If $\bit{2}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{4}\high_{i} = \shiftedBytes{3}\low_{i - 14} \\ + \shiftedBytes{4}\low_{i} = 0 \\ + \end{array} + \right. + \] +% \[ +% \left\{ +% \begin{array}{l} +% \shiftedBytes{4}\high_{i} = +% \begin{cases} +% \If \bit{b_3}_{i} = 1:& +% \shiftedBytes{4}\high_{i} \\ +% \If \bit{b_3}_{i} = 1:& +% \shiftedBytes{3}\low_{i - 14} \\ +% \end{cases} +% % \shiftedBytes{3}\low_{i - 14} +% \\ +% \shiftedBytes{4}\low_{i} = 0 \\ +% \end{array} +% \right. +% \] + \end{enumerate} + \item \If $\shd_{i} = 1$ \Then + \begin{enumerate} + \item \If $\bit{2}_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{4}\high_{i} = 0 \\ + \shiftedBytes{4}\low_{i} = \shiftedBytes{3}\high_{i + 14} \\ + \end{array} + \right. + \] + \item \If $\bit{2}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{4}\high_{i} = \shiftedBytes{3}\high_{i - 2} \\ + \shiftedBytes{4}\low_{i} = \shiftedBytes{3}\low_{i - 2} \\ + \end{array} + \right. + \] +% \[ +% \left\{ +% \begin{array}{l} +% \shiftedBytes{4}\high_{i} = +% \begin{cases} +% \If \bit{b_3}_{i} = 1:& +% \shiftedBytes{4}\high_{i} \\ +% \If \bit{b_3}_{i} = 1:& +% \shiftedBytes{3}\low_{i - 14} \\ +% \end{cases} +% % \shiftedBytes{3}\low_{i - 14} +% \\ +% \shiftedBytes{4}\low_{i} = 0 \\ +% \end{array} +% \right. +% \] + \end{enumerate} + \end{enumerate} + \item \If $\shd_{i} = 1$ \Then + \begin{enumerate} + \item \If $\bit{2}_{i} = 0$ + \[ + \left\{ + \begin{array}{l} + \If \iInst_{i} = \inst{SAR} ~ \Then \shiftedBytes{4}\high_{i} + = \NEG_{i} \cdot \ONES_{i} + + \decRaLo_{i} \\ + \If \iInst_{i} = \inst{SHR} ~ \Then \shiftedBytes{4}\high_{i} + = \decRaLo_{i} \\ + \shiftedBytes{3}\low_{i} = \decLaHi_{i + \llargeMO} + \decRaLo_{i}\\ + \end{array} + \right. + \] + \item \If $\bit{2}_{i} = 1$ \Then + \[ + \left\{ + \begin{array}{l} + \shiftedBytes{3}\high_{i} = \decLaHi_{i - 1} + \decRaHi_{i} \\ + \shiftedBytes{3}\low_{i} = \decLaLo_{i - 1} + \decRaLo_{i} \\ + \end{array} + \right. + \] + \end{enumerate} + Note that (given $\shd_{i} = 1$) the constraints + ``$\If \iInst_{i} = \inst{SAR}$'' and ``$\If \iInst_{i} = \inst{SHR}$'' can be replaced by + ``$\If \iInst_{i}\neq\inst{SHR}$'' and ``$\If \iInst_{i}\neq\inst{SAR}$'' respectively. +\end{enumerate} +\fi \ No newline at end of file diff --git a/shf/someBits.tex b/shf/someBits.tex new file mode 100644 index 0000000..eda60e1 --- /dev/null +++ b/shf/someBits.tex @@ -0,0 +1,20 @@ +This section constrains the $\someBits$ column. Recall that $\someBits$ should contain the bits of the leading byte of $\iArgTwo$ and the bits of the least significant byte of $\iArgOne$. +\begin{enumerate} + \item $\someBits$ is a binary column; + \item \If $\shfStamp_{i}\neq 0$ \et $\oli_{i} = 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{lcl} + \byteCol{2}_{i} & \!\!\! = \!\!\! & \displaystyle \sum_{k = 0}^{7} 2^{7 - k} \cdot \someBits_{i + k} \\ + \NEG_{i} & \!\!\! = \!\!\! & \someBits_{i} \\ + \end{array} + \right. + \] + \item \If $\ct_{i} = \llargeMO$ \Then + \[ + \byteCol{1}_{i} = \sum_{k = 0}^{7} 2^{k} \cdot \someBits_{i - k} + \] + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/shf/someBits_bits.tex b/shf/someBits_bits.tex new file mode 100644 index 0000000..134c5d1 --- /dev/null +++ b/shf/someBits_bits.tex @@ -0,0 +1,30 @@ +We impose the following constraints on the $\bit{b_{k}}$, $k=3,\dots,7$: +\begin{enumerate}[resume] + \item \If $\ct_{i} = \llargeMO$ \Then +% \[ +% \left\{ +% \begin{array}{l} +% \shfStamp_{i} \neq 0 \\ +% \ct_{i} = \llargeMO \\ +% \end{array} +% \right. +% \] +% \Then + \begin{enumerate} + \item $\LT_{i} = \sum_{k = 0}^2 2^{k} \cdot \someBits_{i-k}$ + \item we set $\mshp$: + \[ + \left\{ + \begin{array}{l} + \If \shd_{i} = 0 ~ \Then \mshp_{i} = 8 - \LT_{i} \\ + \If \shd_{i} = 1 ~ \Then \mshp_{i} = \LT_{i} \\ + \end{array} + \right. + \] + \item $\bit{b_3}_{i} = \someBits_{i-3}$, + \item $\bit{b_4}_{i} = \someBits_{i-4}$, + \item $\bit{b_5}_{i} = \someBits_{i-5}$, + \item $\bit{b_6}_{i} = \someBits_{i-6}$, + \item $\bit{b_7}_{i} = \someBits_{i-7}$; + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/shf/target.tex b/shf/target.tex new file mode 100644 index 0000000..ee88fb6 --- /dev/null +++ b/shf/target.tex @@ -0,0 +1,15 @@ +We impose the following target constraints: +\begin{enumerate} + \item \If $\ct_{i} = \llargeMO$ \Then + \[ + \left\{ + \begin{array}{lcl} + \acc{1}_{i} & = & \iArgOneLo_{i} \\ + \acc{2}_{i} & = & \iArgTwoHi_{i} \\ + \acc{3}_{i} & = & \iArgTwoLo_{i} \\ + \acc{4}_{i} & = & \iResHi_{i} \\ + \acc{5}_{i} & = & \iResLo_{i} \\ + \end{array} + \right. + \] +\end{enumerate} \ No newline at end of file diff --git a/spec/__test.tex b/spec/__test.tex new file mode 100644 index 0000000..f802690 --- /dev/null +++ b/spec/__test.tex @@ -0,0 +1,175 @@ +\documentclass[fleqn]{report} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +% % \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/xkeyval_macros/context} +\usepackage{../pkg/xkeyval_macros/dom_sub_stamps} +\usepackage{../pkg/xkeyval_macros/mmu_instructions} +\usepackage{../pkg/xkeyval_macros/mxp_instructions} +\usepackage{../pkg/xkeyval_macros/oob_instructions} +\usepackage{../pkg/xkeyval_macros/stp_instructions} +\usepackage{../pkg/xkeyval_macros/wcp_calls} +\usepackage{../pkg/xkeyval_macros/ext_calls} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/env} +\usepackage{../pkg/euc} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/mmu} +\usepackage{../pkg/mmu_writing} +\usepackage{../pkg/oob} +\usepackage{../pkg/misc} +\usepackage{../pkg/public} +\usepackage{../pkg/shifting} +\usepackage{../pkg/stp} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/block_hash} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/stack} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/abort} +\usepackage{../pkg/scenario} +\usepackage{../pkg/iomf_done} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/rlp_patterns} +\usepackage{../pkg/lex} +\usepackage{../pkg/log_info} +\usepackage{../pkg/txn_data} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/nsr_constants} +\usepackage{../pkg/subsubsubsection} +\usepackage{../pkg/mmu_custom_instructions} +\usepackage{../pkg/mmio_instructions} +\usepackage{../pkg/common_shorthands} +\usepackage{../pkg/prc} +\usepackage{subfiles} +\usepackage{multirow} +\usepackage{hhline} +\usepackage{makecell} +\usepackage{csquotes} +\usepackage{svg} +\usepackage[normalem]{ulem} +\usepackage{changepage} +\usetikzlibrary{calc} + +\usepackage{../pkg/draculatheme} + +\usepackage{tocloft} +\addtolength{\cftsecnumwidth}{5pt} +\addtolength{\cftsubsecnumwidth}{8pt} +\addtolength{\cftsubsubsecnumwidth}{13pt} + +\newcounter{alu_ext_counter} + +\makeatletter +%\renewcommand\@pnumwidth{1em} % <-- depending on the total number of pages +\patchcmd{\@tocline} + {\hfil} + {\leaders\hbox{\,.\,}\hfil} + {}{} +\makeatother + +\usepackage[sorting=none, backend=bibtex]{biblatex} +\addbibresource{references.bib} + +\title{A \textsc{zk-evm} specification} +\author{% +Olivier Bégassat, +Alexandre Belling, +François Bojarski - Nasretdinov, +Franklin Delehelle, +Lorenzo Gentile, +Emile Hautefeuille, +Nicolas Liochon +} +\date{March 2024} + +\begin{document} + +\maketitle +\tableofcontents + + +\chapter{Hii there!} +\section{How have you been?} +\subsection{How have you been?} +\subsubsection{How have you been?} +\subsubsubsection{How have you been?} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\chapter{Hi there!} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\section{How have you been?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsection{How are your mother and father?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsection{How are your brothers and sisters?} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\paragraph*{WTF?} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} +\subsubsubsection{See you around!} + +\end{document} diff --git a/spec/_all_spec.maf b/spec/_all_spec.maf new file mode 100644 index 0000000..2e86ae2 --- /dev/null +++ b/spec/_all_spec.maf @@ -0,0 +1,37 @@ +_all_spec.mtc +_all_spec.mtc0 +_all_spec.mtc35 +_all_spec.mtc34 +_all_spec.mtc33 +_all_spec.mtc32 +_all_spec.mtc31 +_all_spec.mtc30 +_all_spec.mtc29 +_all_spec.mtc28 +_all_spec.mtc27 +_all_spec.mtc26 +_all_spec.mtc25 +_all_spec.mtc24 +_all_spec.mtc23 +_all_spec.mtc22 +_all_spec.mtc21 +_all_spec.mtc20 +_all_spec.mtc19 +_all_spec.mtc18 +_all_spec.mtc17 +_all_spec.mtc16 +_all_spec.mtc15 +_all_spec.mtc14 +_all_spec.mtc13 +_all_spec.mtc12 +_all_spec.mtc11 +_all_spec.mtc10 +_all_spec.mtc9 +_all_spec.mtc8 +_all_spec.mtc7 +_all_spec.mtc6 +_all_spec.mtc5 +_all_spec.mtc4 +_all_spec.mtc3 +_all_spec.mtc2 +_all_spec.mtc1 diff --git a/spec/_all_spec.tex b/spec/_all_spec.tex new file mode 100644 index 0000000..2833c72 --- /dev/null +++ b/spec/_all_spec.tex @@ -0,0 +1,143 @@ +\documentclass[fleqn]{report} +\usepackage[dvipsnames]{xcolor} +\usepackage{xkeyval} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/xkeyval_macros/context} +\usepackage{../pkg/xkeyval_macros/dom_sub_stamps} +\usepackage{../pkg/xkeyval_macros/mmu_instructions} +\usepackage{../pkg/xkeyval_macros/mxp_instructions} +\usepackage{../pkg/xkeyval_macros/oob_instructions} +\usepackage{../pkg/xkeyval_macros/stp_instructions} +\usepackage{../pkg/xkeyval_macros/wcp_calls} +\usepackage{../pkg/xkeyval_macros/ext_calls} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/access} +\usepackage{../pkg/trm} +\usepackage{../pkg/alu} +\usepackage{../pkg/bin} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/gas} +\usepackage{../pkg/env} +\usepackage{../pkg/euc} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/mmu} +\usepackage{../pkg/mmu_writing} +\usepackage{../pkg/oob} +\usepackage{../pkg/misc} +\usepackage{../pkg/public} +\usepackage{../pkg/shifting} +\usepackage{../pkg/stp} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/block_hash} +\usepackage{../pkg/ram} +\usepackage{../pkg/rom} +\usepackage{../pkg/stack} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/storage} +\usepackage{../pkg/warm} +\usepackage{../pkg/wc3} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/abort} +\usepackage{../pkg/scenario} +\usepackage{../pkg/iomf_done} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/rlp_patterns} +\usepackage{../pkg/lex} +\usepackage{../pkg/log_info} +\usepackage{../pkg/txn_data} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/nsr_constants} +\usepackage{../pkg/subsubsubsection} +\usepackage{../pkg/mmu_custom_instructions} +\usepackage{../pkg/mmio_instructions} +\usepackage{../pkg/common_shorthands} +\usepackage{../pkg/prc} +\usepackage{subfiles} +\usepackage{multirow} +\usepackage{hhline} +\usepackage{makecell} +\usepackage{csquotes} +\usepackage{svg} +\usepackage[normalem]{ulem} +\usepackage{changepage} +\usetikzlibrary{calc} +\usepackage[nohints]{minitoc} + +\usepackage{../pkg/draculatheme} + +\usepackage{tocloft} +\addtolength{\cftsecnumwidth}{5pt} +\addtolength{\cftsubsecnumwidth}{8pt} +\addtolength{\cftsubsubsecnumwidth}{13pt} + +\newcounter{alu_ext_counter} + +\usepackage[sorting=none, backend=bibtex]{biblatex} +\addbibresource{references.bib} + +\title{A \textsc{zk-evm} specification} +\author{% +Olivier Bégassat, +Alexandre Belling, +François Bojarski - Nasretdinov, +Franklin Delehelle, +Lorenzo Gentile, +Emile Hautefeuille, +Nicolas Liochon +} +\date{March 2024} + +\begin{document} + +\maketitle +\setcounter{tocdepth}{0} +\dominitoc +\tableofcontents + +\setcounter{tocdepth}{4} + +\chapter*{Introduction} \label{chap: spec intro} \minitoc \subfile{./_inputs} +\chapter{The \hubMod{} module} \label{chap: hub} \minitoc \subfile{../hub/_inputs} +\chapter{The \mmuMod{} module} \label{chap: mmu} \minitoc \subfile{../mmu/_inputs} +\chapter{The \mmioMod{} module} \label{chap: ram} \minitoc \subfile{../mmio/_inputs} +\chapter{The \romMod{} module} \label{chap: rom} \minitoc \subfile{../rom/_inputs} +\chapter{The \romLexMod{} module} \label{chap: rom lex} \minitoc \subfile{../rom_lex/_inputs} +\chapter{The \oobMod{} module} \label{chap: oob} \minitoc \subfile{../oob/_inputs} +\chapter{The \mxpMod{} module} \label{chap: mxp} \minitoc \subfile{../mxp/_inputs} +\chapter{The \stpMod{} module} \label{chap: stp} \minitoc \subfile{../stp/_inputs} +\chapter{The \expMod{} module} \label{chap: exp} \minitoc \subfile{../exp/_inputs} +\chapter{The \gasMod{} module} \label{chap: gas} \minitoc \subfile{../gas/_inputs} +\chapter{The \trmMod{} module} \label{chap: trm} \minitoc \subfile{../trm/_inputs} +\iffalse \fi \subfile{../alu/_inputs} +\chapter{The \eucMod{} module} \label{chap: euc} \minitoc \subfile{../euc/_inputs} +\chapter{The \binMod{} module} \label{chap: bin} \minitoc \subfile{../bin/_inputs} +\chapter{The \shfMod{} module} \label{chap: shf} \minitoc \subfile{../shf/_inputs} +\chapter{The \wcpMod{} module} \label{chap: wcp} \minitoc \subfile{../wcp/_inputs} +\chapter{The \btcMod{} module} \label{chap: block data} \minitoc \subfile{../block_data/_inputs} +\chapter{The \blockHashMod{} module} \label{chap: block hash} \minitoc \subfile{../block_hash/_inputs} +\chapter{The \rlpTxnMod{} module} \label{chap: txn rlp} \minitoc \subfile{../rlp_txn/_inputs} +\chapter{The \txnDataMod{} module} \label{chap: txn data} \minitoc \subfile{../txn_data/_inputs} +\chapter{The \rlpAddrMod{} module} \label{chap: addr rlp} \minitoc \subfile{../rlp_addr/_inputs} +\chapter{The \rlpTxnRcptMod{} module} \label{chap: log rlp} \minitoc \subfile{../rlp_txnrcpt/_inputs} +\chapter{The \logInfoMod{} module} \label{chap: log info} \minitoc \subfile{../log_info/_inputs} +\chapter{The \logDataMod{} module} \label{chap: log data} \minitoc \subfile{../log_data/_inputs} +\chapter{Precompile data modules} \label{chap: precompile data} \minitoc \subfile{../prc/_inputs} + +\appendix +\chapter{Lexicographic ordering constraints} \label{chap: lex} \minitoc \subfile{../lex/_inputs} +\chapter{Generic data module} \label{chap: generic data} \minitoc \subfile{../generic/data/_inputs} +\chapter{Generic info module} \label{chap: generic info} \minitoc \subfile{../generic/info/_inputs} +\printbibliography + +\end{document} diff --git a/spec/_bibliography.tex b/spec/_bibliography.tex new file mode 100644 index 0000000..06559d3 --- /dev/null +++ b/spec/_bibliography.tex @@ -0,0 +1,2 @@ +\begin{filecontents}[force]{\jobname.bib} +\begin{document} diff --git a/spec/_inputs.tex b/spec/_inputs.tex new file mode 100644 index 0000000..67f4794 --- /dev/null +++ b/spec/_inputs.tex @@ -0,0 +1,5 @@ +\section{Purpose} \input{purpose} +\section{Context and results} \input{context} +\section{Conventions} \label{sec: introduction/conventions} \input{conventions} +\section{Organization} \label{sec: introduction/organization} \input{organization} \input{modules_desc} +\section{Suggestions for reading this document} \input{suggested} diff --git a/spec/compatibility.tex b/spec/compatibility.tex new file mode 100644 index 0000000..abc08af --- /dev/null +++ b/spec/compatibility.tex @@ -0,0 +1,27 @@ +\subsection{Interpretations of the term zk-EVM} +Several interpretations of what is a zk-EVM have been given. We aim here to describe more clearly these different definitions. + +\subsubsection{Solidity/Yul and EVM} +To begin with, we will make one first important distinction between Solidity/Yul compatibility and EVM-bytecode compatibility. +\begin{itemize} + \item \textit{Solidity/Yul compatibility:} a special compiler/transpiler transforms the smart contract codes written in Solidity/Yul into a zk-EVM compatible bytecode/programming language. For now, this is the approach taken by zkSync \cite{mediumZKEVM, zksynczkEVM}, that compiles Solidity into a zk-VM friendly bytecode using a LLVM compiler. Another project, currently developed by \textit{Nethermind}, (which initially aimed to build a EVM bytecode to Cairo transpiler \cite{nethermindEvmCairo}) has opted to convert Yul into Cairo \cite{nethermindSolCairo}. Working directly with Solidity/Yul has both advantages and disadvantages: + \begin{itemize} + \item \textbf{Pros:} easier to adapt the generated bytecode to the technical constraints of the zk-EVMs - code execution, proof generation and verification are three very different processes that impose multiple architectural constraints that are non-trivial to overcome. + \item \textbf{Cons:} harder to prove that the behaviour of the EVM is well respected in this zk-system. Unpredictable edge cases may be left out, and new security holes may appear in this new compilation process. Besides, this approach completely discards the work that have been done on the solidity to EVM compiler, which has benefited from years of smart contract execution. + \end{itemize} + + \item \textit{EVM bytecode compatibility:} rather than giving Solidity/Yul code as an input to the zk-EVM, one may provide \textit{EVM bytecode} directly. Quite often, the EVM bytecode is converted in a zk-EVM friendly bytecode/language, that would lead to a proof of execution generation. In addition to the approach presented in this note, other zk-EVM projects like Hermez's \cite{hermez} and Scroll tech's \cite{scroll} aim to provide \textit{full-EVM} compatibility. Working with the EVM bytecode directly also comes with Pros/Cons: + \begin{itemize} + \item \textbf{Pros:} easier to be compliant with the EVM behaviour as defined in the Ethereum yellow paper \cite{EthYellowpaperBerlin}, hence \textit{a priori} less prone to introduce new security issues - the description of the EVM is given at the bytecode level. Benefits from the work that have been done on the Solidity to EVM compiler. Easier to adapt to the new EIPs (defined at the Bytecode level). + \item \textbf{Cons:} \textit{a priori} harder to optimize and adapt to the zk-EVM - more rigidity on the instruction level. Requires the correct emulation of the totality of the EVM instruction set - which is both rich and complex. + \end{itemize} +\end{itemize} + + +\subsubsection{Hash function compatibility} +Another important point in defining \textit{full-EVM} compatibility is the matter of \textit{hash functions}. Ethereum relies on SHA3 (Keccak), a notoriously SNARK unfriendly (almost prohibitively so) hash function. + +For one, the EVM has a KECCAK instruction. Thus, to be \textit{fully-EVM} compatible, a zk-EVM must include this functionality. + +The \textit{keccak} hash function is also used when computing the root hashes of an account's storage and the codehashes of contract bytecodes deployed on mainnet. Since smart contracts would have to be redeployed in our zk-rollup, we have have the freedom to replace keccak with a snark-friendly hash function such as \textit{MIMC} for the storage root hash and codehash computations. This significantly reduces the computational overhead. We also include a new \textit{MiMC} opcode to the set of available EVM instructions to let the choice of the hash function used within the smart contract execution. + diff --git a/spec/context.tex b/spec/context.tex new file mode 100644 index 0000000..d02d4f4 --- /dev/null +++ b/spec/context.tex @@ -0,0 +1 @@ +Rollups are a family of powerful scaling technologies which promise to considerably increase the capacity of the Ethereum Blockchain. An introduction to Rollups, zk-EVMs and their role in improving Ethereum capacity can be respectively found in \cite{vitalik_rollup_2021, mediumZKEVM}. Multiple attempts at building scalable and practical rollup solutions have been positively received. zkSync \cite{zksync}, for instance, transpiles Yul into a zk-VM friendly bytecode. Cairo \cite{cairo}, on the other hand, uses a custom architecture adapted to an efficient STARK prover for smart contracts written in Cairo . Other projects, such as Hermez \cite{hermez} or Scroll Tech \cite{scroll} and this project aim to interpret native EVM bytecode, without transpilation or further compilation steps. \ No newline at end of file diff --git a/spec/conventions.tex b/spec/conventions.tex new file mode 100644 index 0000000..a3055d8 --- /dev/null +++ b/spec/conventions.tex @@ -0,0 +1,34 @@ +Throughout the document we use a number of notational conventions which we explain here. These conventions apply to column names and are meant to clarify the origin and purpose of certain columns within a given trace. Others should be viewed as constructors which define new columns from existing ones. + +\paragraph{Module stamps.} Module stamps count calls to a given module; most modules have a single stamp though the hub and ALU have several. Stamp columns are adorned with a $\stamp$, thus the $\stoStamp$ is the module stamp of the storage module. Module stamps are typically computed/updated in the hub module whose main purpose is to dispatch (paid for an otherwise valid) instructions to the module(s) that are equipped to carry them out. Associating a unique identifier (i.e. stamp) to such ``module-calls'' is crucial when the order of operations matters. This is the case for instructions pertaining to (address) warmth (i.e. the \wrmMod{} module), required gas computations (i.e. \gasMod{}), RAM (i.e. \mmuMod{} and \ramMod{}), the stack (i.e. \hubMod{}), storage (i.e. \stoMod{}), $\dots{}$ to cite a few. Stateless modules such as the modules handling arithmetic (i.e. the \aluMod{} module), binary (i.e. \binMod{}) or word comparison (i.e. \wcpMod{}) opcodes don't \emph{require} a time stamp \emph{per se} yet are given one nonetheless. + +\paragraph{Imported columns.} Angular parentheses $\langle\,\cdots\rangle$ +signal columns whose contents are \textbf{imported} from other modules by +means of a lookup argument. By way of example: all +modules\footnote{which are connected to the hub} import their module stamp from the hub. +Modules tasked with executing certain opcodes will typically import values from the stack +(e.g. pairs of stack values $\isValHi{k}, \isValLo{k}$, for various $k\in\{1,2,3,4\}$.) +Many modules also imports values that aren't borrowed from the stack. +E.g. the hub module imports the instruction $\iInst{}$ from the ROM, +e.g. the \gasMod{} module imports the current, new and endowment gas values +($\gasCur$, $\gasNew$ and $\gasEnd$ respectively) from the hub, e.g. the \oobMod{} +module imports execution context dependent data such exception flags, +the size of return data $\iRds{}$, the size of call data $\iCds$ or the code +size $\iCodeSize$. + +\paragraph{Decoded columns.} A particular case of the above arises with \textbf{decoded columns}. Those are columns whose contents are extracted from a hardcoded collection of columns using a lookup argument. They are adorned with a lozenge as in $\decoded{\col{COL}}$. By way of example: the hub contains various instruction decoded flag columns but also a $\PATTERN$ column whose contents are deduced from an immutable reference table called the \textbf{instruction decoder}. Similarly the binary module imports the results of binary operations performed on pairs of bytes (and injects the relevant one into the result.) + +\paragraph{Flag columns.} Among the instruction decoded columns on finds various binary flags columns (e.g. $\decAluFlag$, $\decMmuFlag$, $\decExpFlag$, $\dots{}$). These serve several purposes. The first is to provide an \emph{indication} as to when modules \emph{may} be sollicited by the hub to carry out an instruction. Thus arithmetic instructions raise the $\decAluFlag$, instructions that involve the RAM raise the $\decMmuFlag$ etc $\dots$ Other flags trigger particular behaviours. For instance the $\pushFlag$ and the $\jumpFlag$ trigger the expected behaviour of the program counter in the hub. + +\paragraph{Module selector columns.} When an instruction raises an instruction flag the associated module \emph{may} get triggered. The actual trigger is usually deduced form this flag and exception flags. Such columns are tagged with a $\select$ symbol + +\paragraph{Interleaved columns.} Certain arguments require us to merge columns of the same size into a single column. We use $\cc$ to signify the formation of such interleaved columns. E.g. starting with columns $\col{A}$, $\col{B}$ and $\col{C}$ of size $n$ we may form the column $\col{X} := \col{A}\cc\col{B}\cc\col{C}$ defined as having length $3n$ and values +\[ + \begin{cases} + \col{X}_{3\cdot i + 0} = \col{A}_{i} \\ + \col{X}_{3\cdot i + 1} = \col{B}_{i} \\ + \col{X}_{3\cdot i + 2} = \col{C}_{i} \\ + \end{cases} +\] + +\paragraph{Row permutations.} Our arithmetization requires row permutation arguments. These usually take the following form: we are given a small family of reference columns $\col{REF}_1,\dots,\col{REF}_p$ of equal size $n$ (which we view as the columns of a $n\times p$ reference matrix $\col{REF}$). We are further given the description of an essentially unique permutation of the set $\{0,1,\dots,n-1\}$ of rows indices, e.g. ``(the essentially unique) row permutation of the matrix $\col{REF}$ under which its rows appear lexicographically sorted''. We then write $\col{AUX}_j\mapsto\order{\col{AUX}_j}$ for the mapping which takes an arbitrary column of the same size and applies the aforementioned row permutation to its rows. diff --git a/spec/modules.tex b/spec/modules.tex new file mode 100644 index 0000000..9be288a --- /dev/null +++ b/spec/modules.tex @@ -0,0 +1,723 @@ +% automaticlaly generated via "python3 column_generator.py > flags_stamps_selectors.sty" + +% account data columns: +%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\accMod}{\col{ACC}} + +\newcommand{\accSTAMP}{\col{ACCOUNT\_DATA\_STAMP}} +\newcommand{\accStamp}{\col{ACC}\stamp} +\newcommand{\iAccSTAMP}{\imported{\accSTAMP}} +\newcommand{\iAccStamp}{\imported{\accStamp}} +\newcommand{\accRevStamp}{\col{ACC}\stamp\,\col{REV}} +\newcommand{\iAccRevStamp}{\imported{\accRevStamp}} + +\newcommand{\accFLAG}{\col{ACCOUNT\_DATA\_FLAG}} +\newcommand{\accFlag}{\col{ACC}\flag} +\newcommand{\decAccFLAG}{\decoded{\accFLAG}} +\newcommand{\decAccFlag}{\decoded{\accFlag}} +\newcommand{\idecAccFLAG}{\imported{\decAccFLAG}} +\newcommand{\idecAccFlag}{\imported{\decAccFlag}} + +\newcommand{\accSELECT}{\col{ACCOUNT\_DATA\_SELECTOR}} +\newcommand{\accSelect}{\col{ACC}\select} +\newcommand{\iAccSELECT}{\imported{\accSELECT}} +\newcommand{\iAccSelect}{\imported{\accSelect}} + +% adder columns: +%%%%%%%%%%%%%%%% + +\newcommand{\addMod}{\col{ADD}} + +\newcommand{\addSTAMP}{\col{ADDER\_STAMP}} +\newcommand{\addStamp}{\col{ADD}\stamp} +\newcommand{\iAddSTAMP}{\imported{\addSTAMP}} +\newcommand{\iAddStamp}{\imported{\addStamp}} +\newcommand{\addRevStamp}{\col{ADD}\stamp\,\col{REV}} +\newcommand{\iAddRevStamp}{\imported{\addRevStamp}} + +\newcommand{\addFLAG}{\col{ADDER\_FLAG}} +\newcommand{\addFlag}{\col{ADD}\flag} +\newcommand{\decAddFLAG}{\decoded{\addFLAG}} +\newcommand{\decAddFlag}{\decoded{\addFlag}} +\newcommand{\idecAddFLAG}{\imported{\decAddFLAG}} +\newcommand{\idecAddFlag}{\imported{\decAddFlag}} + +\newcommand{\addSELECT}{\col{ADDER\_SELECTOR}} +\newcommand{\addSelect}{\col{ADD}\select} +\newcommand{\iAddSELECT}{\imported{\addSELECT}} +\newcommand{\iAddSelect}{\imported{\addSelect}} + +% alu columns: +%%%%%%%%%%%%%% + +\newcommand{\aluMod}{\col{ALU}} + +\newcommand{\aluSTAMP}{\col{ALU\_STAMP}} +\newcommand{\aluStamp}{\col{ALU}\stamp} +\newcommand{\iAluSTAMP}{\imported{\aluSTAMP}} +\newcommand{\iAluStamp}{\imported{\aluStamp}} +\newcommand{\aluRevStamp}{\col{ALU}\stamp\,\col{REV}} +\newcommand{\iAluRevStamp}{\imported{\aluRevStamp}} + +\newcommand{\aluFLAG}{\col{ALU\_FLAG}} +\newcommand{\aluFlag}{\col{ALU}\flag} +\newcommand{\decAluFLAG}{\decoded{\aluFLAG}} +\newcommand{\decAluFlag}{\decoded{\aluFlag}} +\newcommand{\idecAluFLAG}{\imported{\decAluFLAG}} +\newcommand{\idecAluFlag}{\imported{\decAluFlag}} + +\newcommand{\aluSELECT}{\col{ALU\_SELECTOR}} +\newcommand{\aluSelect}{\col{ALU}\select} +\newcommand{\iAluSELECT}{\imported{\aluSELECT}} +\newcommand{\iAluSelect}{\imported{\aluSelect}} + +% batch data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\btcMod}{\col{BTC}} + +\newcommand{\btcSTAMP}{\col{BATCH\_DATA\_STAMP}} +\newcommand{\btcStamp}{\col{BTC}\stamp} +\newcommand{\iBtcSTAMP}{\imported{\btcSTAMP}} +\newcommand{\iBtcStamp}{\imported{\btcStamp}} +\newcommand{\btcRevStamp}{\col{BTC}\stamp\,\col{REV}} +\newcommand{\iBtcRevStamp}{\imported{\btcRevStamp}} + +\newcommand{\btcFLAG}{\col{BATCH\_DATA\_FLAG}} +\newcommand{\btcFlag}{\col{BTC}\flag} +\newcommand{\decBtcFLAG}{\decoded{\btcFLAG}} +\newcommand{\decBtcFlag}{\decoded{\btcFlag}} +\newcommand{\idecBtcFLAG}{\imported{\decBtcFLAG}} +\newcommand{\idecBtcFlag}{\imported{\decBtcFlag}} + +\newcommand{\btcSELECT}{\col{BATCH\_DATA\_SELECTOR}} +\newcommand{\btcSelect}{\col{BTC}\select} +\newcommand{\iBtcSELECT}{\imported{\btcSELECT}} +\newcommand{\iBtcSelect}{\imported{\btcSelect}} + +% binary columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\binMod}{\col{BIN}} + +\newcommand{\binSTAMP}{\col{BINARY\_STAMP}} +\newcommand{\binStamp}{\col{BIN}\stamp} +\newcommand{\iBinSTAMP}{\imported{\binSTAMP}} +\newcommand{\iBinStamp}{\imported{\binStamp}} +\newcommand{\binRevStamp}{\col{BIN}\stamp\,\col{REV}} +\newcommand{\iBinRevStamp}{\imported{\binRevStamp}} + +\newcommand{\binFLAG}{\col{BINARY\_FLAG}} +\newcommand{\binFlag}{\col{BIN}\flag} +\newcommand{\decBinFLAG}{\decoded{\binFLAG}} +\newcommand{\decBinFlag}{\decoded{\binFlag}} +\newcommand{\idecBinFLAG}{\imported{\decBinFLAG}} +\newcommand{\idecBinFlag}{\imported{\decBinFlag}} + +\newcommand{\binSELECT}{\col{BINARY\_SELECTOR}} +\newcommand{\binSelect}{\col{BIN}\select} +\newcommand{\iBinSELECT}{\imported{\binSELECT}} +\newcommand{\iBinSelect}{\imported{\binSelect}} + +% context columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\conMod}{\col{CON}} + +\newcommand{\conSTAMP}{\col{CONTEXT\_STAMP}} +\newcommand{\conStamp}{\col{CON}\stamp} +\newcommand{\iConSTAMP}{\imported{\conSTAMP}} +\newcommand{\iConStamp}{\imported{\conStamp}} +\newcommand{\conRevStamp}{\col{CON}\stamp\,\col{REV}} +\newcommand{\iConRevStamp}{\imported{\conRevStamp}} + +\newcommand{\conFLAG}{\col{CONTEXT\_FLAG}} +\newcommand{\conFlag}{\col{CON}\flag} +\newcommand{\decConFLAG}{\decoded{\conFLAG}} +\newcommand{\decConFlag}{\decoded{\conFlag}} +\newcommand{\idecConFLAG}{\imported{\decConFLAG}} +\newcommand{\idecConFlag}{\imported{\decConFlag}} + +\newcommand{\conSELECT}{\col{CONTEXT\_SELECTOR}} +\newcommand{\conSelect}{\col{CON}\select} +\newcommand{\iConSELECT}{\imported{\conSELECT}} +\newcommand{\iConSelect}{\imported{\conSelect}} + +% exponent columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\expMod}{\col{EXP}} + +\newcommand{\expSTAMP}{\col{EXPONENT\_STAMP}} +\newcommand{\expStamp}{\col{EXP}\stamp} +\newcommand{\iExpSTAMP}{\imported{\expSTAMP}} +\newcommand{\iExpStamp}{\imported{\expStamp}} +\newcommand{\expRevStamp}{\col{EXP}\stamp\,\col{REV}} +\newcommand{\iExpRevStamp}{\imported{\expRevStamp}} + +\newcommand{\expFLAG}{\col{EXPONENT\_FLAG}} +\newcommand{\expFlag}{\col{EXP}\flag} +\newcommand{\decExpFLAG}{\decoded{\expFLAG}} +\newcommand{\decExpFlag}{\decoded{\expFlag}} +\newcommand{\idecExpFLAG}{\imported{\decExpFLAG}} +\newcommand{\idecExpFlag}{\imported{\decExpFlag}} + +\newcommand{\expSELECT}{\col{EXPONENT\_SELECTOR}} +\newcommand{\expSelect}{\col{EXP}\select} +\newcommand{\iExpSELECT}{\imported{\expSELECT}} +\newcommand{\iExpSelect}{\imported{\expSelect}} + +% environment columns: +%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\envMod}{\col{ENV}} + +\newcommand{\envSTAMP}{\col{ENVIRONMENT\_STAMP}} +\newcommand{\envStamp}{\col{ENV}\stamp} +\newcommand{\iEnvSTAMP}{\imported{\envSTAMP}} +\newcommand{\iEnvStamp}{\imported{\envStamp}} +\newcommand{\envRevStamp}{\col{ENV}\stamp\,\col{REV}} +\newcommand{\iEnvRevStamp}{\imported{\envRevStamp}} + +\newcommand{\envFLAG}{\col{ENVIRONMENT\_FLAG}} +\newcommand{\envFlag}{\col{ENV}\flag} +\newcommand{\decEnvFLAG}{\decoded{\envFLAG}} +\newcommand{\decEnvFlag}{\decoded{\envFlag}} +\newcommand{\idecEnvFLAG}{\imported{\decEnvFLAG}} +\newcommand{\idecEnvFlag}{\imported{\decEnvFlag}} + +\newcommand{\envSELECT}{\col{ENVIRONMENT\_SELECTOR}} +\newcommand{\envSelect}{\col{ENV}\select} +\newcommand{\iEnvSELECT}{\imported{\envSELECT}} +\newcommand{\iEnvSelect}{\imported{\envSelect}} + +% extended modular arithmetic columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\extMod}{\col{EXT}} + +\newcommand{\extSTAMP}{\col{EXTENDED\_MODULAR\_ARITHMETIC\_STAMP}} +\newcommand{\extStamp}{\col{EXT}\stamp} +\newcommand{\iExtSTAMP}{\imported{\extSTAMP}} +\newcommand{\iExtStamp}{\imported{\extStamp}} +\newcommand{\extRevStamp}{\col{EXT}\stamp\,\col{REV}} +\newcommand{\iExtRevStamp}{\imported{\extRevStamp}} + +\newcommand{\extFLAG}{\col{EXTENDED\_MODULAR\_ARITHMETIC\_FLAG}} +\newcommand{\extFlag}{\col{EXT}\flag} +\newcommand{\decExtFLAG}{\decoded{\extFLAG}} +\newcommand{\decExtFlag}{\decoded{\extFlag}} +\newcommand{\idecExtFLAG}{\imported{\decExtFLAG}} +\newcommand{\idecExtFlag}{\imported{\decExtFlag}} + +\newcommand{\extSELECT}{\col{EXTENDED\_MODULAR\_ARITHMETIC\_SELECTOR}} +\newcommand{\extSelect}{\col{EXT}\select} +\newcommand{\iExtSELECT}{\imported{\extSELECT}} +\newcommand{\iExtSelect}{\imported{\extSelect}} + +% gas columns: +%%%%%%%%%%%%%% + +\newcommand{\gasMod}{\col{GAS}} + +\newcommand{\gasSTAMP}{\col{GAS\_STAMP}} +\newcommand{\gasStamp}{\col{GAS}\stamp} +\newcommand{\iGasSTAMP}{\imported{\gasSTAMP}} +\newcommand{\iGasStamp}{\imported{\gasStamp}} +\newcommand{\gasRevStamp}{\col{GAS}\stamp\,\col{REV}} +\newcommand{\iGasRevStamp}{\imported{\gasRevStamp}} + +\newcommand{\gasFLAG}{\col{GAS\_FLAG}} +\newcommand{\gasFlag}{\col{GAS}\flag} +\newcommand{\decGasFLAG}{\decoded{\gasFLAG}} +\newcommand{\decGasFlag}{\decoded{\gasFlag}} +\newcommand{\idecGasFLAG}{\imported{\decGasFLAG}} +\newcommand{\idecGasFlag}{\imported{\decGasFlag}} + +\newcommand{\gasSELECT}{\col{GAS\_SELECTOR}} +\newcommand{\gasSelect}{\col{GAS}\select} +\newcommand{\iGasSELECT}{\imported{\gasSELECT}} +\newcommand{\iGasSelect}{\imported{\gasSelect}} + +% hub columns: +%%%%%%%%%%%%%% + +\newcommand{\hubMod}{\col{HUB}} + +\newcommand{\hubSTAMP}{\col{HUB\_STAMP}} +\newcommand{\hubStamp}{\col{HUB}\stamp} +\newcommand{\iHubSTAMP}{\imported{\hubSTAMP}} +\newcommand{\iHubStamp}{\imported{\hubStamp}} +\newcommand{\hubRevStamp}{\col{HUB}\stamp\,\col{REV}} +\newcommand{\iHubRevStamp}{\imported{\hubRevStamp}} + +\newcommand{\hubFLAG}{\col{HUB\_FLAG}} +\newcommand{\hubFlag}{\col{HUB}\flag} +\newcommand{\decHubFLAG}{\decoded{\hubFLAG}} +\newcommand{\decHubFlag}{\decoded{\hubFlag}} +\newcommand{\idecHubFLAG}{\imported{\decHubFLAG}} +\newcommand{\idecHubFlag}{\imported{\decHubFlag}} + +\newcommand{\hubSELECT}{\col{HUB\_SELECTOR}} +\newcommand{\hubSelect}{\col{HUB}\select} +\newcommand{\iHubSELECT}{\imported{\hubSELECT}} +\newcommand{\iHubSelect}{\imported{\hubSelect}} + +% keccak info columns: +%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\kecMod}{\col{KEC}} + +\newcommand{\kecSTAMP}{\col{KECCAK\_INFO\_STAMP}} +\newcommand{\kecStamp}{\col{KEC}\stamp} +\newcommand{\iKecSTAMP}{\imported{\kecSTAMP}} +\newcommand{\iKecStamp}{\imported{\kecStamp}} +\newcommand{\kecRevStamp}{\col{KEC}\stamp\,\col{REV}} +\newcommand{\iKecRevStamp}{\imported{\kecRevStamp}} + +\newcommand{\kecFLAG}{\col{KECCAK\_INFO\_FLAG}} +\newcommand{\kecFlag}{\col{KEC}\flag} +\newcommand{\decKecFLAG}{\decoded{\kecFLAG}} +\newcommand{\decKecFlag}{\decoded{\kecFlag}} +\newcommand{\idecKecFLAG}{\imported{\decKecFLAG}} +\newcommand{\idecKecFlag}{\imported{\decKecFlag}} + +\newcommand{\kecSELECT}{\col{KECCAK\_INFO\_SELECTOR}} +\newcommand{\kecSelect}{\col{KEC}\select} +\newcommand{\iKecSELECT}{\imported{\kecSELECT}} +\newcommand{\iKecSelect}{\imported{\kecSelect}} + +% log info columns: +%%%%%%%%%%%%%%%%%%% + +\newcommand{\logMod}{\col{LOG}} + +\newcommand{\logSTAMP}{\col{LOG\_INFO\_STAMP}} +\newcommand{\logStamp}{\col{LOG}\stamp} +\newcommand{\iLogSTAMP}{\imported{\logSTAMP}} +\newcommand{\iLogStamp}{\imported{\logStamp}} +\newcommand{\logRevStamp}{\col{LOG}\stamp\,\col{REV}} +\newcommand{\iLogRevStamp}{\imported{\logRevStamp}} + +\newcommand{\logFLAG}{\col{LOG\_INFO\_FLAG}} +\newcommand{\logFlag}{\col{LOG}\flag} +\newcommand{\decLogFLAG}{\decoded{\logFLAG}} +\newcommand{\decLogFlag}{\decoded{\logFlag}} +\newcommand{\idecLogFLAG}{\imported{\decLogFLAG}} +\newcommand{\idecLogFlag}{\imported{\decLogFlag}} + +\newcommand{\logSELECT}{\col{LOG\_INFO\_SELECTOR}} +\newcommand{\logSelect}{\col{LOG}\select} +\newcommand{\iLogSELECT}{\imported{\logSELECT}} +\newcommand{\iLogSelect}{\imported{\logSelect}} + +% mmu columns: +%%%%%%%%%%%%%% + +\newcommand{\mmuMod}{\col{MMU}} + +\newcommand{\mmuSTAMP}{\col{MMU\_STAMP}} +\newcommand{\mmuStamp}{\col{MMU}\stamp} +\newcommand{\iMmuSTAMP}{\imported{\mmuSTAMP}} +\newcommand{\iMmuStamp}{\imported{\mmuStamp}} +\newcommand{\mmuRevStamp}{\col{MMU}\stamp\,\col{REV}} +\newcommand{\iMmuRevStamp}{\imported{\mmuRevStamp}} + +\newcommand{\mmuFLAG}{\col{MMU\_FLAG}} +\newcommand{\mmuFlag}{\col{MMU}\flag} +\newcommand{\decMmuFLAG}{\decoded{\mmuFLAG}} +\newcommand{\decMmuFlag}{\decoded{\mmuFlag}} +\newcommand{\idecMmuFLAG}{\imported{\decMmuFLAG}} +\newcommand{\idecMmuFlag}{\imported{\decMmuFlag}} + +\newcommand{\mmuSELECT}{\col{MMU\_SELECTOR}} +\newcommand{\mmuSelect}{\col{MMU}\select} +\newcommand{\iMmuSELECT}{\imported{\mmuSELECT}} +\newcommand{\iMmuSelect}{\imported{\mmuSelect}} + +% multiplier columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\mulMod}{\col{MUL}} + +\newcommand{\mulSTAMP}{\col{MULTIPLIER\_STAMP}} +\newcommand{\mulStamp}{\col{MUL}\stamp} +\newcommand{\iMulSTAMP}{\imported{\mulSTAMP}} +\newcommand{\iMulStamp}{\imported{\mulStamp}} +\newcommand{\mulRevStamp}{\col{MUL}\stamp\,\col{REV}} +\newcommand{\iMulRevStamp}{\imported{\mulRevStamp}} + +\newcommand{\mulFLAG}{\col{MULTIPLIER\_FLAG}} +\newcommand{\mulFlag}{\col{MUL}\flag} +\newcommand{\decMulFLAG}{\decoded{\mulFLAG}} +\newcommand{\decMulFlag}{\decoded{\mulFlag}} +\newcommand{\idecMulFLAG}{\imported{\decMulFLAG}} +\newcommand{\idecMulFlag}{\imported{\decMulFlag}} + +\newcommand{\mulSELECT}{\col{MULTIPLIER\_SELECTOR}} +\newcommand{\mulSelect}{\col{MUL}\select} +\newcommand{\iMulSELECT}{\imported{\mulSELECT}} +\newcommand{\iMulSelect}{\imported{\mulSelect}} + +% modular arithmetic columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\modMod}{\col{MOD}} + +\newcommand{\modSTAMP}{\col{MODULAR\_ARITHMETIC\_STAMP}} +\newcommand{\modStamp}{\col{MOD}\stamp} +\newcommand{\iModSTAMP}{\imported{\modSTAMP}} +\newcommand{\iModStamp}{\imported{\modStamp}} +\newcommand{\modRevStamp}{\col{MOD}\stamp\,\col{REV}} +\newcommand{\iModRevStamp}{\imported{\modRevStamp}} + +\newcommand{\modFLAG}{\col{MODULAR\_ARITHMETIC\_FLAG}} +\newcommand{\modFlag}{\col{MOD}\flag} +\newcommand{\decModFLAG}{\decoded{\modFLAG}} +\newcommand{\decModFlag}{\decoded{\modFlag}} +\newcommand{\idecModFLAG}{\imported{\decModFLAG}} +\newcommand{\idecModFlag}{\imported{\decModFlag}} + +\newcommand{\modSELECT}{\col{MODULAR\_ARITHMETIC\_SELECTOR}} +\newcommand{\modSelect}{\col{MOD}\select} +\newcommand{\iModSELECT}{\imported{\modSELECT}} +\newcommand{\iModSelect}{\imported{\modSelect}} + +% memory expansion columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\mxpMod}{\col{MXP}} + +\newcommand{\mxpSTAMP}{\col{MEMORY\_EXPANSION\_STAMP}} +\newcommand{\mxpStamp}{\col{MXP}\stamp} +\newcommand{\iMxpSTAMP}{\imported{\mxpSTAMP}} +\newcommand{\iMxpStamp}{\imported{\mxpStamp}} +\newcommand{\mxpRevStamp}{\col{MXP}\stamp\,\col{REV}} +\newcommand{\iMxpRevStamp}{\imported{\mxpRevStamp}} + +\newcommand{\mxpFLAG}{\col{MEMORY\_EXPANSION\_FLAG}} +\newcommand{\mxpFlag}{\col{MXP}\flag} +\newcommand{\decMxpFLAG}{\decoded{\mxpFLAG}} +\newcommand{\decMxpFlag}{\decoded{\mxpFlag}} +\newcommand{\idecMxpFLAG}{\imported{\decMxpFLAG}} +\newcommand{\idecMxpFlag}{\imported{\decMxpFlag}} + +\newcommand{\mxpSELECT}{\col{MEMORY\_EXPANSION\_SELECTOR}} +\newcommand{\mxpSelect}{\col{MXP}\select} +\newcommand{\iMxpSELECT}{\imported{\mxpSELECT}} +\newcommand{\iMxpSelect}{\imported{\mxpSelect}} + +% out of bounds columns: +%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\oobMod}{\col{OOB}} + +\newcommand{\oobSTAMP}{\col{OUT\_OF\_BOUNDS\_STAMP}} +\newcommand{\oobStamp}{\col{OOB}\stamp} +\newcommand{\iOobSTAMP}{\imported{\oobSTAMP}} +\newcommand{\iOobStamp}{\imported{\oobStamp}} +\newcommand{\oobRevStamp}{\col{OOB}\stamp\,\col{REV}} +\newcommand{\iOobRevStamp}{\imported{\oobRevStamp}} + +\newcommand{\oobFLAG}{\col{OUT\_OF\_BOUNDS\_FLAG}} +\newcommand{\oobFlag}{\col{OOB}\flag} +\newcommand{\decOobFLAG}{\decoded{\oobFLAG}} +\newcommand{\decOobFlag}{\decoded{\oobFlag}} +\newcommand{\idecOobFLAG}{\imported{\decOobFLAG}} +\newcommand{\idecOobFlag}{\imported{\decOobFlag}} + +\newcommand{\oobSELECT}{\col{OUT\_OF\_BOUNDS\_SELECTOR}} +\newcommand{\oobSelect}{\col{OOB}\select} +\newcommand{\iOobSELECT}{\imported{\oobSELECT}} +\newcommand{\iOobSelect}{\imported{\oobSelect}} + +% ram columns: +%%%%%%%%%%%%%% + +\newcommand{\ramMod}{\col{RAM}} + +\newcommand{\ramSTAMP}{\col{RAM\_STAMP}} +\newcommand{\ramStamp}{\col{RAM}\stamp} +\newcommand{\iRamSTAMP}{\imported{\ramSTAMP}} +\newcommand{\iRamStamp}{\imported{\ramStamp}} +\newcommand{\ramRevStamp}{\col{RAM}\stamp\,\col{REV}} +\newcommand{\iRamRevStamp}{\imported{\ramRevStamp}} + +\newcommand{\ramFLAG}{\col{RAM\_FLAG}} +\newcommand{\ramFlag}{\col{RAM}\flag} +\newcommand{\decRamFLAG}{\decoded{\ramFLAG}} +\newcommand{\decRamFlag}{\decoded{\ramFlag}} +\newcommand{\idecRamFLAG}{\imported{\decRamFLAG}} +\newcommand{\idecRamFlag}{\imported{\decRamFlag}} + +\newcommand{\ramSELECT}{\col{RAM\_SELECTOR}} +\newcommand{\ramSelect}{\col{RAM}\select} +\newcommand{\iRamSELECT}{\imported{\ramSELECT}} +\newcommand{\iRamSelect}{\imported{\ramSelect}} + +% rom columns: +%%%%%%%%%%%%%% + +\newcommand{\romMod}{\col{ROM}} + +\newcommand{\romSTAMP}{\col{ROM\_STAMP}} +\newcommand{\romStamp}{\col{ROM}\stamp} +\newcommand{\iRomSTAMP}{\imported{\romSTAMP}} +\newcommand{\iRomStamp}{\imported{\romStamp}} +\newcommand{\romRevStamp}{\col{ROM}\stamp\,\col{REV}} +\newcommand{\iRomRevStamp}{\imported{\romRevStamp}} + +\newcommand{\romFLAG}{\col{ROM\_FLAG}} +\newcommand{\romFlag}{\col{ROM}\flag} +\newcommand{\decRomFLAG}{\decoded{\romFLAG}} +\newcommand{\decRomFlag}{\decoded{\romFlag}} +\newcommand{\idecRomFLAG}{\imported{\decRomFLAG}} +\newcommand{\idecRomFlag}{\imported{\decRomFlag}} + +\newcommand{\romSELECT}{\col{ROM\_SELECTOR}} +\newcommand{\romSelect}{\col{ROM}\select} +\newcommand{\iRomSELECT}{\imported{\romSELECT}} +\newcommand{\iRomSelect}{\imported{\romSelect}} + +% shift columns: +%%%%%%%%%%%%%%%% + +\newcommand{\shfMod}{\col{SHF}} + +\newcommand{\shfSTAMP}{\col{SHIFT\_STAMP}} +\newcommand{\shfStamp}{\col{SHF}\stamp} +\newcommand{\iShfSTAMP}{\imported{\shfSTAMP}} +\newcommand{\iShfStamp}{\imported{\shfStamp}} +\newcommand{\shfRevStamp}{\col{SHF}\stamp\,\col{REV}} +\newcommand{\iShfRevStamp}{\imported{\shfRevStamp}} + +\newcommand{\shfFLAG}{\col{SHIFT\_FLAG}} +\newcommand{\shfFlag}{\col{SHF}\flag} +\newcommand{\decShfFLAG}{\decoded{\shfFLAG}} +\newcommand{\decShfFlag}{\decoded{\shfFlag}} +\newcommand{\idecShfFLAG}{\imported{\decShfFLAG}} +\newcommand{\idecShfFlag}{\imported{\decShfFlag}} + +\newcommand{\shfSELECT}{\col{SHIFT\_SELECTOR}} +\newcommand{\shfSelect}{\col{SHF}\select} +\newcommand{\iShfSELECT}{\imported{\shfSELECT}} +\newcommand{\iShfSelect}{\imported{\shfSelect}} + +% storage columns: +%%%%%%%%%%%%%%%%%% + +\newcommand{\stoMod}{\col{STO}} + +\newcommand{\stoSTAMP}{\col{STORAGE\_STAMP}} +\newcommand{\stoStamp}{\col{STO}\stamp} +\newcommand{\iStoSTAMP}{\imported{\stoSTAMP}} +\newcommand{\iStoStamp}{\imported{\stoStamp}} +\newcommand{\stoRevStamp}{\col{STO}\stamp\,\col{REV}} +\newcommand{\iStoRevStamp}{\imported{\stoRevStamp}} + +\newcommand{\stoFLAG}{\col{STORAGE\_FLAG}} +\newcommand{\stoFlag}{\col{STO}\flag} +\newcommand{\decStoFLAG}{\decoded{\stoFLAG}} +\newcommand{\decStoFlag}{\decoded{\stoFlag}} +\newcommand{\idecStoFLAG}{\imported{\decStoFLAG}} +\newcommand{\idecStoFlag}{\imported{\decStoFlag}} + +\newcommand{\stoSELECT}{\col{STORAGE\_SELECTOR}} +\newcommand{\stoSelect}{\col{STO}\select} +\newcommand{\iStoSELECT}{\imported{\stoSELECT}} +\newcommand{\iStoSelect}{\imported{\stoSelect}} + +% address trimming columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\trmMod}{\col{TRM}} + +\newcommand{\trmSTAMP}{\col{ADDRESS\_TRIMMING\_STAMP}} +\newcommand{\trmStamp}{\col{TRM}\stamp} +\newcommand{\iTrmSTAMP}{\imported{\trmSTAMP}} +\newcommand{\iTrmStamp}{\imported{\trmStamp}} +\newcommand{\trmRevStamp}{\col{TRM}\stamp\,\col{REV}} +\newcommand{\iTrmRevStamp}{\imported{\trmRevStamp}} + +\newcommand{\trmFLAG}{\col{ADDRESS\_TRIMMING\_FLAG}} +\newcommand{\trmFlag}{\col{TRM}\flag} +\newcommand{\decTrmFLAG}{\decoded{\trmFLAG}} +\newcommand{\decTrmFlag}{\decoded{\trmFlag}} +\newcommand{\idecTrmFLAG}{\imported{\decTrmFLAG}} +\newcommand{\idecTrmFlag}{\imported{\decTrmFlag}} + +\newcommand{\trmSELECT}{\col{ADDRESS\_TRIMMING\_SELECTOR}} +\newcommand{\trmSelect}{\col{TRM}\select} +\newcommand{\iTrmSELECT}{\imported{\trmSELECT}} +\newcommand{\iTrmSelect}{\imported{\trmSelect}} + +% word comparison columns: +%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\wcpMod}{\col{WCP}} + +\newcommand{\wcpSTAMP}{\col{WORD\_COMPARISON\_STAMP}} +\newcommand{\wcpStamp}{\col{WCP}\stamp} +\newcommand{\iWcpSTAMP}{\imported{\wcpSTAMP}} +\newcommand{\iWcpStamp}{\imported{\wcpStamp}} +\newcommand{\wcpRevStamp}{\col{WCP}\stamp\,\col{REV}} +\newcommand{\iWcpRevStamp}{\imported{\wcpRevStamp}} + +\newcommand{\wcpFLAG}{\col{WORD\_COMPARISON\_FLAG}} +\newcommand{\wcpFlag}{\col{WCP}\flag} +\newcommand{\decWcpFLAG}{\decoded{\wcpFLAG}} +\newcommand{\decWcpFlag}{\decoded{\wcpFlag}} +\newcommand{\idecWcpFLAG}{\imported{\decWcpFLAG}} +\newcommand{\idecWcpFlag}{\imported{\decWcpFlag}} + +\newcommand{\wcpSELECT}{\col{WORD\_COMPARISON\_SELECTOR}} +\newcommand{\wcpSelect}{\col{WCP}\select} +\newcommand{\iWcpSELECT}{\imported{\wcpSELECT}} +\newcommand{\iWcpSelect}{\imported{\wcpSelect}} + +% warmth columns: +%%%%%%%%%%%%%%%%% + +\newcommand{\wrmMod}{\col{WRM}} + +\newcommand{\wrmSTAMP}{\col{WARMTH\_STAMP}} +\newcommand{\wrmStamp}{\col{WRM}\stamp} +\newcommand{\iWrmSTAMP}{\imported{\wrmSTAMP}} +\newcommand{\iWrmStamp}{\imported{\wrmStamp}} +\newcommand{\wrmRevStamp}{\col{WRM}\stamp\,\col{REV}} +\newcommand{\iWrmRevStamp}{\imported{\wrmRevStamp}} + +\newcommand{\wrmFLAG}{\col{WARMTH\_FLAG}} +\newcommand{\wrmFlag}{\col{WRM}\flag} +\newcommand{\decWrmFLAG}{\decoded{\wrmFLAG}} +\newcommand{\decWrmFlag}{\decoded{\wrmFlag}} +\newcommand{\idecWrmFLAG}{\imported{\decWrmFLAG}} +\newcommand{\idecWrmFlag}{\imported{\decWrmFlag}} + +\newcommand{\wrmSELECT}{\col{WARMTH\_SELECTOR}} +\newcommand{\wrmSelect}{\col{WRM}\select} +\newcommand{\iWrmSELECT}{\imported{\wrmSELECT}} +\newcommand{\iWrmSelect}{\imported{\wrmSelect}} + +% ecadd data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecaddDataMod}{\col{ECADDDATA}} + +\newcommand{\ecaddDataSTAMP}{\col{ECADD\_DATA\_STAMP}} +\newcommand{\ecaddDataStamp}{\col{ECADDDATA}\stamp} +\newcommand{\iEcaddDataSTAMP}{\imported{\ecaddDataSTAMP}} +\newcommand{\iEcaddDataStamp}{\imported{\ecaddDataStamp}} +\newcommand{\ecaddDataRevStamp}{\col{ECADDDATA}\stamp\,\col{REV}} +\newcommand{\iEcaddDataRevStamp}{\imported{\ecaddDataRevStamp}} + +\newcommand{\ecaddDataFLAG}{\col{ECADD\_DATA\_FLAG}} +\newcommand{\ecaddDataFlag}{\col{ECADDDATA}\flag} +\newcommand{\decEcaddDataFLAG}{\decoded{\ecaddDataFLAG}} +\newcommand{\decEcaddDataFlag}{\decoded{\ecaddDataFlag}} +\newcommand{\idecEcaddDataFLAG}{\imported{\decEcaddDataFLAG}} +\newcommand{\idecEcaddDataFlag}{\imported{\decEcaddDataFlag}} + +\newcommand{\ecaddDataSELECT}{\col{ECADD\_DATA\_SELECTOR}} +\newcommand{\ecaddDataSelect}{\col{ECADDDATA}\select} +\newcommand{\iEcaddDataSELECT}{\imported{\ecaddDataSELECT}} +\newcommand{\iEcaddDataSelect}{\imported{\ecaddDataSelect}} + +% ecadd info columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecaddInfoMod}{\col{ECADDINFO}} + +\newcommand{\ecaddInfoSTAMP}{\col{ECADD\_INFO\_STAMP}} +\newcommand{\ecaddInfoStamp}{\col{ECADDINFO}\stamp} +\newcommand{\iEcaddInfoSTAMP}{\imported{\ecaddInfoSTAMP}} +\newcommand{\iEcaddInfoStamp}{\imported{\ecaddInfoStamp}} +\newcommand{\ecaddInfoRevStamp}{\col{ECADDINFO}\stamp\,\col{REV}} +\newcommand{\iEcaddInfoRevStamp}{\imported{\ecaddInfoRevStamp}} + +\newcommand{\ecaddInfoFLAG}{\col{ECADD\_INFO\_FLAG}} +\newcommand{\ecaddInfoFlag}{\col{ECADDINFO}\flag} +\newcommand{\decEcaddInfoFLAG}{\decoded{\ecaddInfoFLAG}} +\newcommand{\decEcaddInfoFlag}{\decoded{\ecaddInfoFlag}} +\newcommand{\idecEcaddInfoFLAG}{\imported{\decEcaddInfoFLAG}} +\newcommand{\idecEcaddInfoFlag}{\imported{\decEcaddInfoFlag}} + +\newcommand{\ecaddInfoSELECT}{\col{ECADD\_INFO\_SELECTOR}} +\newcommand{\ecaddInfoSelect}{\col{ECADDINFO}\select} +\newcommand{\iEcaddInfoSELECT}{\imported{\ecaddInfoSELECT}} +\newcommand{\iEcaddInfoSelect}{\imported{\ecaddInfoSelect}} + +% ecmul data columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecmulDataMod}{\col{ECMULDATA}} + +\newcommand{\ecmulDataSTAMP}{\col{ECMUL\_DATA\_STAMP}} +\newcommand{\ecmulDataStamp}{\col{ECMULDATA}\stamp} +\newcommand{\iEcmulDataSTAMP}{\imported{\ecmulDataSTAMP}} +\newcommand{\iEcmulDataStamp}{\imported{\ecmulDataStamp}} +\newcommand{\ecmulDataRevStamp}{\col{ECMULDATA}\stamp\,\col{REV}} +\newcommand{\iEcmulDataRevStamp}{\imported{\ecmulDataRevStamp}} + +\newcommand{\ecmulDataFLAG}{\col{ECMUL\_DATA\_FLAG}} +\newcommand{\ecmulDataFlag}{\col{ECMULDATA}\flag} +\newcommand{\decEcmulDataFLAG}{\decoded{\ecmulDataFLAG}} +\newcommand{\decEcmulDataFlag}{\decoded{\ecmulDataFlag}} +\newcommand{\idecEcmulDataFLAG}{\imported{\decEcmulDataFLAG}} +\newcommand{\idecEcmulDataFlag}{\imported{\decEcmulDataFlag}} + +\newcommand{\ecmulDataSELECT}{\col{ECMUL\_DATA\_SELECTOR}} +\newcommand{\ecmulDataSelect}{\col{ECMULDATA}\select} +\newcommand{\iEcmulDataSELECT}{\imported{\ecmulDataSELECT}} +\newcommand{\iEcmulDataSelect}{\imported{\ecmulDataSelect}} + +% ecmul info columns: +%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\ecmulInfoMod}{\col{ECMULINFO}} + +\newcommand{\ecmulInfoSTAMP}{\col{ECMUL\_INFO\_STAMP}} +\newcommand{\ecmulInfoStamp}{\col{ECMULINFO}\stamp} +\newcommand{\iEcmulInfoSTAMP}{\imported{\ecmulInfoSTAMP}} +\newcommand{\iEcmulInfoStamp}{\imported{\ecmulInfoStamp}} +\newcommand{\ecmulInfoRevStamp}{\col{ECMULINFO}\stamp\,\col{REV}} +\newcommand{\iEcmulInfoRevStamp}{\imported{\ecmulInfoRevStamp}} + +\newcommand{\ecmulInfoFLAG}{\col{ECMUL\_INFO\_FLAG}} +\newcommand{\ecmulInfoFlag}{\col{ECMULINFO}\flag} +\newcommand{\decEcmulInfoFLAG}{\decoded{\ecmulInfoFLAG}} +\newcommand{\decEcmulInfoFlag}{\decoded{\ecmulInfoFlag}} +\newcommand{\idecEcmulInfoFLAG}{\imported{\decEcmulInfoFLAG}} +\newcommand{\idecEcmulInfoFlag}{\imported{\decEcmulInfoFlag}} + +\newcommand{\ecmulInfoSELECT}{\col{ECMUL\_INFO\_SELECTOR}} +\newcommand{\ecmulInfoSelect}{\col{ECMULINFO}\select} +\newcommand{\iEcmulInfoSELECT}{\imported{\ecmulInfoSELECT}} +\newcommand{\iEcmulInfoSelect}{\imported{\ecmulInfoSelect}} + +% identity return data columns: +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand{\idretMod}{\col{IDRET}} + +\newcommand{\idretSTAMP}{\col{IDENTITY\_RETURN\_DATA\_STAMP}} +\newcommand{\idretStamp}{\col{IDRET}\stamp} +\newcommand{\iIdretSTAMP}{\imported{\idretSTAMP}} +\newcommand{\iIdretStamp}{\imported{\idretStamp}} +\newcommand{\idretRevStamp}{\col{IDRET}\stamp\,\col{REV}} +\newcommand{\iIdretRevStamp}{\imported{\idretRevStamp}} + +\newcommand{\idretFLAG}{\col{IDENTITY\_RETURN\_DATA\_FLAG}} +\newcommand{\idretFlag}{\col{IDRET}\flag} +\newcommand{\decIdretFLAG}{\decoded{\idretFLAG}} +\newcommand{\decIdretFlag}{\decoded{\idretFlag}} +\newcommand{\idecIdretFLAG}{\imported{\decIdretFLAG}} +\newcommand{\idecIdretFlag}{\imported{\decIdretFlag}} + +\newcommand{\idretSELECT}{\col{IDENTITY\_RETURN\_DATA\_SELECTOR}} +\newcommand{\idretSelect}{\col{IDRET}\select} +\newcommand{\iIdretSELECT}{\imported{\idretSELECT}} +\newcommand{\iIdretSelect}{\imported{\idretSelect}} + + diff --git a/spec/modules_desc.tex b/spec/modules_desc.tex new file mode 100644 index 0000000..7b03d1c --- /dev/null +++ b/spec/modules_desc.tex @@ -0,0 +1,77 @@ +The \zkEvm{} follows a modular archicture. Modules are given short acronyms / identifiers. The modules are the following: +\begin{enumerate} + \item $\rlpTxnMod$: + this module receives the raw \textsc{rlp}-encoded transactions; its purpose is to re-construct said \textsc{rlp} using the fields of a transaction used by the \zkEvm{} (as well as the signature of the transaction); it further constructs the \textsc{rlp} encoding of the transaction stripped of its signature; this string (along with the transaction signature) provides the input for the \texttt{KEC} constraint system and \texttt{ECRECOVER}y which vet said transaction; see chapter~\ref{chap: txn rlp}; + %%% + \item $\txnDataMod{}$: + this module corrals the (\textsc{evm}-relevant) transaction data contained in the transaction \textsc{rlp}; it provides that data in an easily accessible and exportable format; see chapter~\ref{chap: txn data}; + \saNote{} the \btcMod{} module is used to off-load computations performed on transaction data (such as determining the \inst{GASPRICE} of \textsc{eip1559} transactions); see chapter~\ref{chap: txn comp}; + %%% + \item $\btcMod{}$: + this module corrals some (\textsc{evm}-relevant) batch data (such as \inst{COINBASE}, \inst{TIMESTAMP}, \dots); see chapter~\ref{chap: btc data}; + % \ref{chap: log rlp}; + % \ref{chap: addr rlp}; + %%% + \item $\hubMod{}$: + logical centerpiece of the \zkEvm{}: this modules is in charge of the stack, execution context(s) (including gas and program counter), account data, account storage; it further loads instructions from the bytecode found in the \romMod{} module; it dispatches a lot of the work to other more "functional modules" and to the \textsc{ram}; see chapter~\ref{chap: hub}; + %%% + \item $\addMod{}, \extMod{}, \modMod{}, \mulMod{}$: + these modules deal with the arithmetic instructions of the \textsc{evm}; addition and subtraction, extended modular arithmetic, modular arithmetic and multiplication and exponentiation respectively; + \item $\binMod{}$: + binary module; deals with opcodes performing binary operations; see chapter~\ref{chap: }; + %%% + \item $\shfMod{}$: + shifting module; deals with opcodes performing bit shifts; see chapter~\ref{chap: shf}; + %%% + \item $\wcpMod{}$: + word comparison module; deals with opcodes performing integer comparisons; see chapter~\ref{chap: wcp}; + %%% + \item $\mxpMod{}$: + computes memory expansion costs; may raise a flag ($\mxpx$) if offsets are wildly out of bounds; see chapter~\ref{chap: mxp}; + %%% + \item $\romMod{}$: + contains the bytecodes (as well as initialization codes) which are run, read (e.g. through \inst{EXTCODECOPY}) and or (temporarily) deployed in a batch of transactions; see chapter~\ref{chap: rom}; + %%% + \item $\mmuMod{}$: + first stop in the life time of an opcode execution which touches RAM; performs arithmetic on offsets and various sizes to cut down execution of a single opcode into a sequence of smaller queries; see chapter~\ref{chap: mmu}; + %%% + \item $\ramMod{}$: + contains the RAM of all execution context and can communicate with other data sources such as ROM and other data stores; carries out the sequence of small queries commissioned by the $\mmuMod{}$; see chapter~\ref{chap: ram}; + %%% + \item $\oobMod{}$: + performs certain range checks required by instructions, e.g. \inst{JUMP}s and \inst{JUMPI}s; see chapter~\ref{chap: oob}; + %%% + \item $\stpMod$: + computes the gas stipend provided to new execution contexts (or precompiles) spawned through a \inst{CREATE}-type or \inst{CALL}-type instruction; in particular computes the $L$ function $L(n) = n - \lfloor n/64 \rceil$; + %%% + \item $\precInfoMod$: + performs some computations when a \inst{CALL} is made to a precompiled contract; these computations include determining whether executing the \inst{CALL} requires the \hubMod{} to send instructions to RAM or not, whether the \inst{CALL} is successful or not and the return data size; + %%% + \item $\trmMod{}$: + shaves the leading 12 bytes off addresses; see chapter~\ref{chap: trm}; + % \item $\stoMod{}$: + storage module; unique among all modules other than the hub in that it computes its own gas costs; see chapter~\ref{chap: sto}; + %%% + % \item $\accMod{}$: + address existence module; loads and udpates account data from the state; \texttt{WIP}; + %%% + % \item $\wrmMod{}$: + address warmth module: loads prewarmed addresses; handles address warmth in general; built on similar principles as the storage module; see chapter~\ref{chap: wrm}; + %%% + %\item[\vspace{\fill}] +\end{enumerate} +The following are a few very small modules that either perform a very specific task or are used for reference for the prover +\begin{enumerate}[resume] + \item $\ecDataMod$: + recipient of data extracted from RAM and provided to specialized circuits computing elliptic curve primitives (e.g. \texttt{ECRECOVER}, \texttt{ECADD}, \texttt{ECMUL}, \texttt{ECPAIRING}) + \item $\blkMdxMod$: + recipient of data extracted from RAM and provided to the \texttt{MODEXP} and the \texttt{BLAKE2f} circuits; + \item $\shakiraMod$: + recipient of data extracted from RAM and provided to the \texttt{KECCAK}, \texttt{SHA2-256} and the \texttt{RIPEMD-160} circuits; + also contains the output of said hash functions; + \item $\logMod{}$: + same idea for logs; the information module extracts the log parameter ($\in\{09,1,2,3,4\}$), logger address and size in bytes; the second module serves as a data store for the log message; + \item $\expMod{}$: + computes the dynamic gas cost of the \inst{EXP} instruction; see chapter~\ref{chap: exp}; +\end{enumerate} + diff --git a/spec/organization.tex b/spec/organization.tex new file mode 100644 index 0000000..169f1e9 --- /dev/null +++ b/spec/organization.tex @@ -0,0 +1,4 @@ +\begin{figure} + \includegraphics[width = \textwidth]{../img/zkevm_better_arrow_heads.png} +\caption{Modular architecture of the zk-evm. Boxes represent modules and arrows represent lookup inclusions. If an arrow points from module \col{ABC} to module \col{XYZ} then \col{XYZ} imports a portion of its data from \col{ABC}. Arrows may be bidirectional which signals a ``bilateral'' inclusion proof.} +\end{figure} diff --git a/spec/purpose.tex b/spec/purpose.tex new file mode 100644 index 0000000..e9b9038 --- /dev/null +++ b/spec/purpose.tex @@ -0,0 +1 @@ +The present document contains a full specification for a \zkEvm{}. Some simpler data and info modules (which typically contain data extracted from the RAM) are omitted. It is based on the previously published \href{https://ethresear.ch/t/a-zk-evm-specification-part-2/13903}{A ZK-EVM specification - Part 2}, itself an expanded version of an older (partial) \href{https://ethresear.ch/t/a-zk-evm-specification/11549}{specification of a zk-evm}. diff --git a/spec/related_work.tex b/spec/related_work.tex new file mode 100644 index 0000000..dc3f7fc --- /dev/null +++ b/spec/related_work.tex @@ -0,0 +1,2 @@ +\subsection{Related projects} +Our work draws inspiration from the existing design of Cairo \cite{cairo} from which we borrow the concepts of \textit{execution traces}, \textit{small-range range-proofs} and \textit{permutation arguments for memory integrity}. We borrow Hermez's modular approach \cite{HermezEthCC4}. \ No newline at end of file diff --git a/spec/suggested.tex b/spec/suggested.tex new file mode 100644 index 0000000..a383d37 --- /dev/null +++ b/spec/suggested.tex @@ -0,0 +1,3 @@ +We suggest the reader start with the chapter on the \textbf{hub}~\ref{chap: hub}. The hub is the center piece of our zk-evm design. It reads instructions from the \textbf{ROM}~\ref{chap: rom} and dispatches instructions to other modules. Various smaller modules which are directly connected to the hub (e.g. the word comparison module\ref{chap: wcp} or out of bounds module~\ref{chap: oob}) may prove helpful to develop some intuition for the techniques used elsewhere. After the hub, the main module of interest is certainly the RAM. In our design the RAM is split into 2 pieces: the memory management unit~\ref{chap: mmu} (or offset processor) and the memory mapped input output module\ref{chap: mmio}. The \textbf{mmu} receives instructions from the hub and is tasked with breaking them down into smaller ``elementary'' operations. This reduction is a two phase process: the first phase (``precomputation'' or ``establishing'' phase) extracts auxiliary data from the arguments of the opcode (offset and size parameters). The second ``micro-instruction writing'' phase uses these numerical parameters to build a sequence of micro-instructions (\textbf{surgeries} and \textbf{transplants}) which the \textbf{mmio} imports and carries out. + +The reader should be warned: this document is a work in progress: typos --- even outright mistakes --- are to be expected. One module (the \textbf{address existence} module) is presently missing from the spec --- it is a work in progress. Some sections have received more attention than others. The \textbf{hub}~\ref{chap: hub}, the memory-mapped-input-output module~\ref{chap: ram} are among them as are various other ``smaller'' modules such as the binary module, the word comparison module and others. diff --git a/stp/_all_stp.tex b/stp/_all_stp.tex new file mode 100644 index 0000000..5df412d --- /dev/null +++ b/stp/_all_stp.tex @@ -0,0 +1,40 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/alu} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/comparisons} +\usepackage{../pkg/public} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/oob} +\usepackage{../pkg/iomf_done} +\usepackage{../pkg/env} +\usepackage{../pkg/wc3} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/abort} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/stp} +\usepackage{../pkg/draculatheme} + +\title{\inst{CALL} / \inst{CREATE} gas stipend module} +\author{Rollup team} +\date{April 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/stp/_inputs.tex b/stp/_inputs.tex new file mode 100644 index 0000000..3b09f3d --- /dev/null +++ b/stp/_inputs.tex @@ -0,0 +1,21 @@ +\input{_local} + +\section{\inst{CALL} / \inst{CREATE} pricing module} +\subsection{Introduction} \label{stp: intro} \input{intro} +\subsection{Columns} \label{stp: columns} \input{columns} + +\section{Constraints} \label{stp: constraints} +\subsection{Binary constraints} \label{stp: constraints: binary} \input{binary} +\subsection{Instruction decoding} \label{stp: constraints: instructions} \input{instructions} +\subsection{Heartbeat} \label{stp: constraints: heartbeat} \input{heartbeat} +\subsection{Constancy constraints} \label{stp: constraints: constancy} \input{constancies} +\subsection{Vanishing constraints} \label{stp: constraints: vanishing} \input{vanishing} +\subsection{Common shorthands} \label{stp: constraints: shorthands} \input{shorthands} + +\section{\inst{CREATE} case} \label{stp: creates} \input{create/_inputs} + +\section{\inst{CALL} case} \label{stp: calls} \input{call/_inputs} + +\section{Lookups} +\subsection{Into the \wcpMod{} module} \label{stp: lookups: wcp} \input{lookups/wcp} +\subsection{Into the \modMod{} module} \label{stp: lookups: mod} \input{lookups/mod} diff --git a/stp/_local.tex b/stp/_local.tex new file mode 100644 index 0000000..5dea234 --- /dev/null +++ b/stp/_local.tex @@ -0,0 +1,45 @@ +\def\flagSum {\col{flag\_sum}} +\def\instSum {\col{inst\_sum}} +\def\isCreate {\col{create\_type\_inst}} +\def\isCall {\col{call\_type\_inst}} +\def\cctv {\col{cctv}} + +\def\zeroRes {\yellowm{0}} +\def\zero {\graym{0}} +\def\one {\redm{1}} +\def\rZero {\redm{0}} +\def\locCctv {\col{cctv}} +\def\locExists {\col{exists}} +\def\locWarm {\col{warmth}} +\def\locGasActl {\col{gas\_actual}} +\def\locGasMxp {\col{gas\_mxp}} +\def\locGasXtra {\col{gas\_extra}} +\def\locGasCost {\col{gas\_cost}} +\def\locGasAccess {\col{gas\_access}} +\def\locGasNewAcc {\col{gas\_new\_account}} +\def\locGasTransfer {\col{gas\_transfer}} +\def\locDiff {\col{gas\_diff}} +\def\locGasDiff {\locDiff} +\def\locMin {\col{gas\_min}} +\def\locLDiff {L(\locDiff)} +\def\locGasUpfront {\col{gas\_upfront}} +\def\locGasUpfrontCreate {\locGasUpfront\col{\_create}} +\def\locGasUpfrontCall {\locGasUpfront\col{\_call}} +\def\locVal {\col{val}} +\def\locValHi {\locVal\col{\_hi}} +\def\locValLo {\locVal\col{\_lo}} +\def\locZeroValue {\col{zero\_value}} +\def\locTransfersValue {\col{transfers\_value}} +\def\locGas {\col{gas}} +\def\locGasHi {\locwGas\col{\_hi}} +\def\locGasLo {\locwGas\col{\_lo}} +\def\locOogx {\colm{oogx}} +\def\locComp {\colm{comp}} +\def\locOSFth {\lfloor\locDiff\colm{/64}\rfloor} +\def\locOneSixtyFourth {\col{one\_64\_th}} +\def\locLOfGasDiff {\col{L\_of\_gas\_diff}} +\def\locGasCompBit {\col{gas\_vs\_L}} + +\def\unoC {\cellcolor{solarized-orange} \phantom{WW}} +\def\duoC {\cellcolor{solarized-green}} +\def\treC {\cellcolor{solarized-cyan}} diff --git a/stp/binary.tex b/stp/binary.tex new file mode 100644 index 0000000..2df137a --- /dev/null +++ b/stp/binary.tex @@ -0,0 +1,20 @@ +We impose the following binary constraints: +\begin{multicols}{3} + \begin{enumerate} + \item \existence{} (\trash) + \item \warm{} (\trash) + \item \oogx{} (\trash) + \item \wcpLookupFlag{} + \item \divLookupFlag{} + \item \stpCreate{} + \item \stpCreateTwo{} + \item \stpCall{} + \item \stpCallCode{} + \item \stpDelegateCall{} + \item \stpStaticCall{} + % \item[\vspace{\vfill}] + % \item[\vspace{\vfill}] + \end{enumerate} +\end{multicols} +We further impose that the lookup selectors are exclusive, i.e. +\[ \wcpLookupFlag \cdot \divLookupFlag \equiv 0 \] diff --git a/stp/call/_inputs.tex b/stp/call/_inputs.tex new file mode 100644 index 0000000..63a734d --- /dev/null +++ b/stp/call/_inputs.tex @@ -0,0 +1,5 @@ +\subsection{Purpose} \label{stp: lookups: call introduction} \input{call/intro} +\subsection{Shorthands} \label{stp: lookups: call shorthands} \input{call/shorthands} +\subsection{Graphical representation} \label{stp: lookups: call rep} \input{call/representation} +\subsection{Constraints} \label{stp: lookups: call constraints} \input{call/constraints} +\subsection{Gas cost, ``paid out of pocket'' gas and call stipend} \label{stp: lookups: call setting} \input{call/setting} diff --git a/stp/call/constraints.tex b/stp/call/constraints.tex new file mode 100644 index 0000000..565338a --- /dev/null +++ b/stp/call/constraints.tex @@ -0,0 +1,115 @@ +\[ + \boxed{\text{The constaints below assume that } + \begin{cases} + \stpStamp_{i} \neq \stpStamp_{i - 1} \\ + \isCall _{i} = 1 \\ + \end{cases} } +\] + +The present section defines the layout of the data to be used in the lookups to the \wcpMod{} and \modMod{}. The resulting values of the computation are sufficient to justify the \gasStipend{} column. The first two instructions are common to both types of instructions: we make sure that the gas cost does not exceed the available gas and compute the $1/64^{\text{th}}$ of the difference. +\begin{description} + \item[\underline{Row n$°i$:}] we impose the following: + \[ + \left\{ \begin{array}{lclc} + \wcpLookupFlag_{i} & = & 1 \\ + \divLookupFlag_{i} & = & 0 & (\trash) \\ + \argOneHi_{i} & = & 0 \\ + \argOneLo_{i} & = & \locGasActl \\ + \argTwoLo_{i} & = & 0 \\ + \resLo_{i} & = & \zeroRes \\ + \exoInst_{i} & = & \inst{LT} \\ + \end{array} \right. + \] + These constraints ensure that $\gasActual_{i} \geq 0$. + \item[\underline{Row n$°(i + 1)$:}] we impose the following: + \[ + \left\{ \begin{array}{lclc} + \wcpLookupFlag_{i + 1} & = & \cctv_{i} \\ + \divLookupFlag_{i + 1} & = & 0 \\ + \argOneHi_{i + 1} & = & \valHi_{i} \\ + \argOneLo_{i + 1} & = & \valLo_{i} \\ + \argTwoLo_{i + 1} & = & 0 \quad (\trash) \\ + \exoInst_{i + 1} & = & \inst{ISZERO} \\ + \end{array} \right. + \] + These constraints establish whether the value fields are zero or not; indeed, given that $\cctv_{i} = 1$, we have + \[ + \underbrace{\phantom{\Big|}\locZeroValue\phantom{\Big|}}_{=\resLo_{i + 1}} = 1 \iff \Big(\valHi_{i} = \valLo_{i} = 0 \Big) + \] + \item[\underline{Row n$°(i + 2)$:}] we impose the following: + \[ + \left\{ \begin{array}{lclc} + \wcpLookupFlag_{i + 2} & = & 1 \\ + \divLookupFlag_{i + 2} & = & 0 & (\trash) \\ + \argOneHi_{i + 2} & = & 0 \\ + \argOneLo_{i + 2} & = & \locGasActl \\ + \argTwoLo_{i + 2} & = & \locGasUpfrontCall \\ + \resLo_{i + 2} & = & \locOogx \\ + \exoInst_{i + 2} & = & \inst{LT} \\ + \end{array} \right. + \] + % Where we use the following shorthand: + % \[ + % \left[ \begin{array}{lcl} + % \locGasUpfrontCall & := & \gasMxp_{i} + \locGasXtra \\ + % \locGasXtra & := & \locGasAccess + \locGasNewAcc + \locGasTransfer \\ + % \locGasAccess & := & \warm_{i} \cdot G_{\text{warmaccess}} \\ + % & & ~ + (1 - \warm_{i}) \cdot G_{\text{coldaccountaccess}} \\ + % \locGasNewAcc & := & \cctv_{i} \cdot (1 - \resLo_{i + 1}) \cdot (1 - \existence_{i}) \cdot G_{\text{newaccount}} \\ + % \locGasTransfer & := & \cctv_{i} \cdot (1 - \resLo_{i + 1}) \cdot G_{\text{callvalue}} \\ + % \end{array} \right] + % \] +\end{description} +These constraints thus establish $\oogx$; indeed +\[ + \underbrace{\phantom{\Big|}\locOogx\phantom{\Big|}}_{= \oogx_{i}} = 1 \iff \locGasActl < \locGasUpfrontCall. +\] +The constraints below are written under the further assumption that no \oogxSH{} has occurred, as such: +\[ + \boxed{\text{The constaints below further assume that } \locOogx = 0.} +\] +\begin{description} + \item[\underline{Row n$°(i + 3)$:}] we impose the following: + \[ + \left\{ \begin{array}{lclr} + \wcpLookupFlag_{i + 3} & = & 0 & (\trash) \\ + % \divLookupFlag_{i + 3} & = & 1 - \oogx_{i} \\ + \divLookupFlag_{i + 3} & = & 1 \\ + \argOneHi_{i + 3} & = & 0 \\ + \argOneLo_{i + 3} & = & \locDiff \\ + \argTwoLo_{i + 3} & = & 64 \\ + \exoInst_{i + 3} & = & \inst{DIV} \\ + \end{array} \right. + \] + In case where there is no \oogxSH{} (i.e. $\oogx_{i} = 0$) these constraints compute + \[ + \underbrace{\phantom{\Big|}\locOneSixtyFourth\phantom{\Big|}}_{= \resLo_{i + 3}} + = + \left\lfloor\frac{\locDiff}{64} \right\rfloor + \] + \item[\underline{Row n$°(i + 4)$:}] we impose the following: + \[ + \left\{ \begin{array}{lclr} + \wcpLookupFlag_{i + 4} & = & 1 \\ + \divLookupFlag_{i + 4} & = & 0 & (\trash) \\ + \argOneHi_{i + 4} & = & \gasHi_{i} \\ + \argOneLo_{i + 4} & = & \gasLo_{i} \\ + \argTwoLo_{i + 4} & = & \locLOfGasDiff \\ + \exoInst_{i + 4} & = & \inst{LT} \\ + \end{array} \right. + \] + \saNote{} By definition we have + \begin{IEEEeqnarray*}{LCL} + \locLOfGasDiff + & = & \locDiff - \locOneSixtyFourth \\ + & = & \locDiff - \left\lfloor\frac{\locDiff}{64} \right\rfloor \\ + & = & L(\locDiff) + \end{IEEEeqnarray*} + These above constraints enforce that + \[ + \underbrace{\phantom{\Big|}\locGasCompBit\phantom{\Big|}}_{= \resLo_{i + 4}} + = 1 + \iff + \texttt{} < L(\locDiff) + \] +\end{description} diff --git a/stp/call/intro.tex b/stp/call/intro.tex new file mode 100644 index 0000000..f8a4754 --- /dev/null +++ b/stp/call/intro.tex @@ -0,0 +1,12 @@ +We describe the computations/checks which the \stpMod{} module accomplishes for \inst{CALL}-type instructions. +\begin{description} + \item[\colorbox{solarized-orange}{\underline{Row n$°i$:}}] the currently available gas is nonnegative; + \item[\colorbox{solarized-orange}{\underline{Row n$°(i + 1)$:}}] if the \inst{CALL}-type instruction can transfer value, determine if the value is nonzero; + \item[\colorbox{solarized-orange}{\underline{Row n$°(i + 2)$:}}] determine if the instruction provokes an \oogxSH{}; +\end{description} +Furthermore, in case of no \oogxSH{}: +\begin{description} + \item[\colorbox{solarized-green} {\underline{Row n$°(i + 3)$:}}] computation of $(1/64)^\text{th}$ of the leftover gas; + \item[\colorbox{solarized-green} {\underline{Row n$°(i + 4)$:}}] comparison between the maximal value purveyable in the message call and the gas parameter of the instruction; +\end{description} + diff --git a/stp/call/representation.tex b/stp/call/representation.tex new file mode 100644 index 0000000..8275115 --- /dev/null +++ b/stp/call/representation.tex @@ -0,0 +1,33 @@ +In this section we provide the graphical representation of the lookup constraints for \inst{CALL}-type instructions. +\begin{figure} + \centering + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|c||c|c|c|c|c|c|c|c||c|} + \hline + \multicolumn{10}{|c|}{\text{\inst{CALL} representation (for \oogxSH{} i.e. $\locOogx = \one$)}} \\ \hline + \ct & \argOneHi & \argOneLo & \graym{ \argTwoHi } & \argTwoLo & \exoInst & \resLo & \wcpLookupFlag & \divLookupFlag & \\ \hline + 0 & 0 & \locGasActl & \graym{0} & 0 & \inst{LT} & \zeroRes & \one & \zero & \unoC \phantom{WW} \\ \hline + 1 & \valHi & \valLo & \graym{0} & 0 & \inst{ISZERO} & \locZeroValue & \locCctv & \zero & \unoC \\ \hline + 2 & 0 & \locGasActl & \graym{0} & \locGasUpfrontCall & \inst{LT} & \locOogx ~ (=\one) & \one & \zero & \unoC \\ \hline + \end{array} + \] + % + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|c||c|c|c|c|c|c|c|c||c|} + \hline + \multicolumn{10}{|c|}{\text{\inst{CALL} representation (no \oogxSH{} i.e. $\locOogx = \rZero$)}} \\ \hline + \ct & \argOneHi & \argOneLo & \graym{ \argTwoHi } & \argTwoLo & \exoInst & \resLo & \wcpLookupFlag & \divLookupFlag & \\ \hline + 0 & 0 & \locGasActl & \graym{0} & 0 & \inst{LT} & \zeroRes & \one & \zero & \unoC \phantom{WW} \\ \hline + 1 & \valHi & \valLo & \graym{0} & 0 & \inst{ISZERO} & \locZeroValue & \locCctv & \zero & \unoC \\ \hline + 2 & 0 & \locGasActl & \graym{0} & \locGasUpfrontCall & \inst{LT} & \locOogx ~ (=\rZero) & \one & \zero & \unoC \\ \hline + 3 & 0 & {\cellcolor{\ramCol}\locDiff} & \graym{0} & 64 & \inst{DIV} & \locOneSixtyFourth & \zero & \one & \duoC \\ \hline + 4 & \gasHi & \gasLo & \graym{0} & {\cellcolor{\ramCol}\locLOfGasDiff} & \inst{LT} & \locGasCompBit & \one & \zero & \duoC \\ \hline + \end{array} + \] + \captionsetup{singlelinecheck=off} + \caption[.]{We use the following shorthands + The interpretation of the orange zero $\zeroRes$ is that the first comparison is required to return \texttt{false}. + When $\locOogx \equiv 0$ the \locOneSixtyFourth{}-cell contains $\locOSFth{}$.} +\end{figure} diff --git a/stp/call/setting.tex b/stp/call/setting.tex new file mode 100644 index 0000000..cbe7b65 --- /dev/null +++ b/stp/call/setting.tex @@ -0,0 +1,32 @@ +\[ + \boxed{\text{The constaints below assume that } + \begin{cases} + \stpStamp_{i} \neq \stpStamp_{i - 1} \\ + \isCall _{i} = 1 \\ + \end{cases}} +\] +We now settle gas costs and gas stipends for \inst{CALL}'s: +\begin{description} + \item[\underline{The ``no \oogxSH{}'' case:}] \If $\oogx_{i} = 0$ \Then + \begin{enumerate} + \item $\gasUpfront_{i} = \locGasUpfrontCall$ + \item $\gasPoop_{i} = \locMin$ + \item $\gasStipend_{i} = \cctv_{i} \cdot \locTransfersValue \cdot G_{\text{callstipend}}$ + % Where we set + % \begin{IEEEeqnarray*}{LCL} + % \locMin & := & + % \begin{cases} + % \If \resLo_{i + 4} = 0 : & L(\locDiff) \\ + % \If \resLo_{i + 4} = 1 : & \gasLo_{i} \\ + % \end{cases} \\ + % & = & (1 - \resLo_{i + 4}) \cdot (\argOneLo_{i + 3} - \resLo_{i + 3}) \\ + % & & ~ + \resLo_{i + 4} \cdot \gasLo_{i} \\ + % \end{IEEEeqnarray*} + \end{enumerate} + \item[\underline{The ``\oogxSH{}'' case:}] \If $\oogx_{i} = 1$ \Then + \begin{enumerate} + \item $\gasUpfront_{i} = \locGasUpfrontCall$ + \item $\gasPoop_{i} = 0$ + \item $\gasStipend_{i} = 0$ + \end{enumerate} +\end{description} diff --git a/stp/call/shorthands.tex b/stp/call/shorthands.tex new file mode 100644 index 0000000..bb5a775 --- /dev/null +++ b/stp/call/shorthands.tex @@ -0,0 +1,40 @@ +For greater expressivity we use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locTransfersValue & \define & 1 - \resLo_{i + 1} \\ + \locZeroValue & \define & \resLo_{i + 1} \\ + \locGasAccess & \define & + \begin{cases} + \If \locWarm = 1: & G_\text{warmaccess} \\ + \If \locWarm = 0: & G_\text{coldaccountaccess} \\ + \end{cases} \\ + \locGasTransfer & \define & + \begin{cases} + \If \locCctv = 1 \wedge \locTransfersValue = 1: & G_\text{callvalue} \\ + \If \locCctv = 0 \vee \locTransfersValue = 0: & 0 \\ + \end{cases} \\ + \locGasNewAcc & \define & + \begin{cases} + \If \locExists = 1: & 0 \\ + \If \locExists = 0: & G_\text{newaccount} \\ + \end{cases} \\ + \locGasXtra & \define & \locGasAccess + \locGasTransfer + \locGasNewAcc \\ + \locGasUpfrontCall & \define & \locGasMxp + \locGasXtra \\ + \locDiff & \define & \locGasActl ~ - ~ \locGasUpfrontCall \\ + \locOneSixtyFourth & \define & \resLo_{i + 3} \\ + \locLOfGasDiff & \define & \locGasDiff ~ - ~ \locOneSixtyFourth \\ + \locGasCompBit & \define & \resLo_{i + 4} \\ + \locMin & \define & + \begin{cases} + \If \locGasCompBit = 0 : & \locLOfGasDiff \\ + \If \locGasCompBit = 1 : & \gasLo_{i} \\ + \end{cases} \\ + \end{array} \right. +\] +These are only to be used if the row index $i$ is such that +\[ + \begin{cases} + \stpStamp_{i} \neq \stpStamp_{i - 1} \\ + \isCall _{i} = 1 \\ + \end{cases} +\] diff --git a/stp/columns.tex b/stp/columns.tex new file mode 100644 index 0000000..28dcf53 --- /dev/null +++ b/stp/columns.tex @@ -0,0 +1,64 @@ +We begin by listing columns that pertain to the heartbeat of the present module, see section \ref{stp: constraints: heartbeat}: +\begin{enumerate} + \item $\stpStamp{}$: + stamp column for the \stpMod{} module; + \item $\ct{}$: + counter column; counts from 0 to \maxCt{}; + \item $\maxCt{}$: + \ccc{}; its value depends on the instruction an whether or not it produces an \oogxSH{}; +\end{enumerate} +The following columns allow the \stpMod{} to identify the instruction that gave rise to the present instruction. The computation depend on whether the instruction is a \inst{CREATE}-type or \inst{CALL}-type instruction; furthermore among \inst{CALL}-type instruction only some may transfer value, whence the \cctv{} flag. +\begin{enumerate}[resume] + \item $\INST$: \godGiven{}; + \ccc{}; contains the instruction for which a stipend has to be computed; + \item \stpCreate, \stpCreateTwo, \stpCall, \stpCallCode, \stpDelegateCall, \stpStaticCall: + \ccbc{}; exclusive binary columns which light up for the respective instruction; +\end{enumerate} +The following are instruction parameters (not all are provided by all instructions.) +\begin{enumerate}[resume] + \item $\gasHi$ and $\gasLo$: \godGiven{}; + \ccc{}; high and low parts of the stack value (a 256 bit integer) containing the gas parameter of a \inst{CALL}-type instruction; + \item $\valueHi$ and $\valueLo$: \godGiven{}; + \ccc{}; high and low parts of the stack value (a 256 bit integer) containing the value parameter of a \inst{CALL}-type instruction which raises the \cctv{} flag; +\end{enumerate} +The following columns contain account information required to price \inst{CALL}-type instructions correctly as well as the binary flag which recognizes \oogxSH{}. +\begin{enumerate}[resume] + \item $\existence$: \godGiven{}; + \ccbc{}; indicates whether the value transfer recipient address exists; used for \inst{CALL} pricing; + \item $\warm$: \godGiven{}; + \ccbc{}; current warmth of the $\col{to} = \mu_\textbf{s}[1]\texttt{[12:32]}$ address; used for \inst{CALL} pricing; + \item $\oogx$: \godGiven{}; + \ccbc{}; indicates whether an \oogxSH{} occurs; +\end{enumerate} +The following columns pertain to gas values obtained in the \hubMod{}; +one of the main purposes of the present module is to justify some of them, that is +$\gasUpfront$, $\gasPoop$ and $\gasStipend$. +\begin{enumerate}[resume] + \item $\gasActual$: \godGiven{}; + \ccc{}; amount of gas available to the exection context just prior to dealing witht the current \inst{CALL}-type or \inst{CREATE}-type instructions; + \item $\gasMxp$: \godGiven{}; + \ccc{}; memory expansion costs (plus the ``linear'' costs of \inst{CREATE2} instructions); + \item $\gasUpfront$: \godGiven{}; + \ccc{}; cost of the instruction prior to gas refunds coming from leftover gas from the \inst{CALL}/\inst{CREATE}-type instruction; + % \item $\gasNext$: + the amount of gas left over to the caller / creator contract prior just as the \inst{CALL}/\inst{CREATE} instruction is about to start; + \item $\gasPoop$: \godGiven{}; + \ccc{}; gas amount ``paid out of pocket'' from the remaining gas of the \callerr{}/\creator{} to the \calleee{}/\createe{}; + \item $\gasStipend$: \godGiven{}; + \ccc{}; call gas stipend provided to the callee context of a \inst{CALL} or \inst{CALLCODE} if the transfer value is nonzero; +\end{enumerate} +We further introduce columns that allow us to duplicate values from the current module and make them available in a straightforward manner to the \wcpMod{} and \modMod{} modules for certain computations. +\begin{enumerate}[resume] + \item \wcpLookupFlag{}: + binary column which equals $1$ $\iff$ the current row contains parameters for a call to the \wcpMod{} module; + \item \divLookupFlag{}: + binary column which equals $1$ $\iff$ the current row contains parameters for a call to the \modMod{} module; + \item \exoInst{}: + instruction; for calls to the \wcpMod{} will be either \inst{LT} or \inst{ISZERO}; for calls to the \modMod{} will always be \inst{DIV}; + \item $\argOneHi{}$ and $\argOneLo{}$: + high and low parts of the first instruction argument; + \item $\argTwoLo{}$: + low part of the second instruction argument; its high part will always vanish; + \item $\resLo{}$: + instruction result; its high part will also always vanish; +\end{enumerate} diff --git a/stp/constancies.tex b/stp/constancies.tex new file mode 100644 index 0000000..db16181 --- /dev/null +++ b/stp/constancies.tex @@ -0,0 +1,33 @@ +As per usual we declare a column \col{X} to be \textbf{counter-constant} if it satisfies the following: +\[ \If \ct_{i}\neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. \] +The following columns are required to be counter-constant: +\begin{multicols}{4} + \begin{enumerate} + \item \INST + \item \gasActual + \item \gasMxp + \item \gasUpfront + \item \gasStipend + \item \gasHi + \item \gasLo + \item \gasPoop + \item \valueHi + \item \valueLo + \item \warm + \item \existence + \item \oogx + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} Counter-constancy of \INST{}, binaryness of these columns and section~(\ref{stp: constraints: instructions}), implicitly impose counter constancy of +\stpCreate, +\stpCreateTwo, +\stpCall, +\stpCallCode, +\stpDelegateCall{} and +\stpStaticCall{}. +follows from counter-constancy of \INST{}, the + +\saNote{} Counter-constancy of \maxCt{} follows from that of \oogx{} the heartbeat constraints~(\ref{stp: constraints: heartbeat}). diff --git a/stp/create/_inputs.tex b/stp/create/_inputs.tex new file mode 100644 index 0000000..46e32da --- /dev/null +++ b/stp/create/_inputs.tex @@ -0,0 +1,5 @@ +\subsection{Purpose} \label{stp: create: intro} \input{create/intro} +\subsection{Shorthands} \label{stp: create: shorthands} \input{create/shorthands} +\subsection{Graphical representation} \label{stp: create: representation} \input{create/representation} +\subsection{Constraints} \label{stp: create: constraints} \input{create/constraints} +\subsection{Gas cost and ``paid out of pocket'' gas} \label{stp: create: setting} \input{create/setting} diff --git a/stp/create/constraints.tex b/stp/create/constraints.tex new file mode 100644 index 0000000..a6860e4 --- /dev/null +++ b/stp/create/constraints.tex @@ -0,0 +1,63 @@ +\[ + \boxed{\text{The constaints below assume that } + \begin{cases} + \stpStamp_{i} \neq \stpStamp_{i - 1} \\ + \isCreate_{i} = 1 \\ + \end{cases} } +\] + +The present section defines the layout of the data to be used in the lookups to the \wcpMod{} and \modMod{} for \inst{CREATE}-type instructions. The resulting values of the computation are sufficient to justify the \gasStipend{} column. We refer the reader to the explanation and diagrams from section~(\ref{stp: lookups: create rep}) +\begin{description} + \item[\underline{Row n$°i$:}] we ensure that $\gasActual_{i} \geq 0$: + \[ + \left\{\begin{array}{lclc} + \wcpLookupFlag_{i} & = & 1 \\ + \divLookupFlag_{i} & = & 0 & (\trash) \\ + \argOneHi_{i} & = & 0 \\ + \argOneLo_{i} & = & \locGasActl \\ + \argTwoLo_{i} & = & 0 \\ + \resLo_{i} & = & \zeroRes \\ + \exoInst_{i} & = & \inst{LT} \\ + \end{array}\right. + \] + \item[\underline{Row n$°(i + 1)$:}] we establish \oogx: + \[ + \left\{\begin{array}{lclc} + \wcpLookupFlag_{i + 1} & = & 1 \\ + \divLookupFlag_{i + 1} & = & 0 & (\trash) \\ + \argOneHi_{i + 1} & = & 0 \\ + \argOneLo_{i + 1} & = & \locGasActl \\ + \argTwoLo_{i + 1} & = & \locGasUpfrontCreate \\ + \resLo_{i + 1} & = & \locOogx \\ + \exoInst_{i + 1} & = & \inst{LT} \\ + \end{array}\right. + \] + \saNote{} These constraints indeed establish $\oogx$ since by construction: + \begin{IEEEeqnarray*}{LCLCL} + \locOogx = 1 + & \iff & \locGasActl & < & \locGasUpfrontCreate \\ + \end{IEEEeqnarray*} +\end{description} +These constitute the preliminary gas checks. The constraints below assume that no \oogxSH{} has occurred: +\[ + \boxed{\text{The constaints below further assume that } \locOogx = 0.} +\] +\begin{description} + \item[\underline{Row n$°(i + 2)$:}] we impose the following: + \[ + \left\{\begin{array}{lclr} + \wcpLookupFlag_{i + 2} & = & 0 & (\trash) \\ + \divLookupFlag_{i + 2} & = & 1 \\ + \argOneHi_{i + 2} & = & 0 \\ + \argOneLo_{i + 2} & = & \locDiff \\ + \argTwoLo_{i + 2} & = & 64 \\ + \exoInst_{i + 2} & = & \inst{DIV} \\ + \end{array}\right. + \] + In case of no \oogxSH{} (i.e. $\oogx_{i} = 0$) these constraints compute + \[ + \underbrace{\phantom{\Big|}\locOneSixtyFourth\phantom{\Big|}}_{\displaystyle = \resLo_{i + 2}} + = + \left\lfloor\frac{\locDiff}{64}\right\rfloor + \] +\end{description} diff --git a/stp/create/intro.tex b/stp/create/intro.tex new file mode 100644 index 0000000..a198c24 --- /dev/null +++ b/stp/create/intro.tex @@ -0,0 +1,9 @@ +We describe the computations/checks which the \stpMod{} module accomplishes for \inst{CREATE}-type instructions. +\begin{description} + \item[\colorbox{solarized-orange}{\underline{Row n$°(i)$:}}] ensure that the currently available gas is nonnegative; + \item[\colorbox{solarized-orange}{\underline{Row n$°(i + 1)$:}}] justification of the \oogX{}; +\end{description} +Furthermore, in case of no \oogxSH{}: +\begin{description} + \item[\colorbox{solarized-green} {\underline{Row n$°(i + 2)$:}}] computation of the gas stipend for the \emph{createe}; +\end{description} diff --git a/stp/create/representation.tex b/stp/create/representation.tex new file mode 100644 index 0000000..5aeac67 --- /dev/null +++ b/stp/create/representation.tex @@ -0,0 +1,39 @@ +In this section we provide the graphical representation of the lookup constraints for \inst{CREATE}-type instructions. +\begin{figure}[!h] + \centering + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|c||c|c|c|c|c|c|c|c||c|} + \hline + \multicolumn{10}{|c|}{\text{\inst{CREATE} representation (for \oogxSH{} i.e. $\locOogx = \one$)}} \\ \hline + % \rotatebox{90}{$\argOneHi$} & + % \rotatebox{90}{$\argOneLo$} & + % \rotatebox{90}{$\argTwoHi$} & + % \rotatebox{90}{$\argTwoLo$} & + \ct & \argOneHi & \argOneLo & \graym{\argTwoHi} & \argTwoLo & \exoInst & \resLo & \wcpLookupFlag & \divLookupFlag & \\ \hline + 0 & 0 & \locGasActl & \graym{0} & 0 & \inst{LT} & \zeroRes & \one & \zero & \unoC \\ \hline + 1 & 0 & \locGasActl & \graym{0} & \locGasUpfrontCreate & \inst{LT} & \locOogx = \one & \one & \zero & \unoC \\ \hline + \end{array} + \] + % + \[ + \renewcommand{\arraystretch}{1.3} + \begin{array}{|c||c|c|c|c|c|c|c|c||c|} + \hline + \multicolumn{10}{|c|}{\text{\inst{CREATE} representation (no \oogxSH{} i.e. $\locOogx = \rZero$)}} \\ \hline + % \rotatebox{90}{$\argOneHi$} & + % \rotatebox{90}{$\argOneLo$} & + % \rotatebox{90}{$\argTwoHi$} & + % \rotatebox{90}{$\argTwoLo$} & + \ct & \argOneHi & \argOneLo & \graym{\argTwoHi} & \argTwoLo & \exoInst & \resLo & \wcpLookupFlag & \divLookupFlag & \\ \hline + 0 & 0 & \locGasActl & \graym{0} & 0 & \inst{LT} & \zeroRes & \one & \zero & \unoC \\ \hline + 1 & 0 & \locGasActl & \graym{0} & \locGasUpfrontCreate & \inst{LT} & \locOogx = \rZero & \one & \zero & \unoC \\ \hline + 2 & 0 & {\cellcolor{\ramCol}\locDiff} & \graym{0} & 64 & \inst{DIV} & \locOneSixtyFourth & \zero & \one & \duoC \\ \hline + \end{array} + \] + \captionsetup{singlelinecheck=off} + \caption[.]{% + Recall that $G_\text{txcreate} = 32000$. + The interpretation of the orange zero $\zeroRes$ is that the first comparison is \textbf{required} to return \texttt{false}. + When $\locOogx \equiv 0$ the \locOneSixtyFourth{}-cell contains $\locOSFth{}$.} +\end{figure} diff --git a/stp/create/setting.tex b/stp/create/setting.tex new file mode 100644 index 0000000..316023e --- /dev/null +++ b/stp/create/setting.tex @@ -0,0 +1,24 @@ +\[ + \boxed{\text{The constaints below assume that } + \begin{cases} + \stpStamp_{i} \neq \stpStamp_{i - 1} \\ + \isCreate_{i} = 1 \\ + \end{cases} + } +\] +We now settle the gas costs and gas stipends for \inst{CREATE}-type instructions: +\begin{description} + \item[\underline{The ``no \oogxSH{}'' case:}] \If $\oogx_{i} = 0$ \Then + \begin{enumerate} + \item $\gasUpfront_{i} = \locGasUpfrontCreate$ + \item $\gasPoop_{i} = \locDiff - \locOneSixtyFourth$ + \item $\gasStipend_{i} = 0$ + \end{enumerate} + \saNote{} By definition we have $\gasPoop_{i} = L(\locDiff)$ + \item[\underline{The ``\oogxSH{}'' case:}] \If $\oogx_{i} = 1$ \Then + \begin{enumerate} + \item $\gasUpfront_{i} = \locGasUpfrontCreate$ + \item $\gasPoop_{i} = 0$ + \item $\gasStipend_{i} = 0$ + \end{enumerate} +\end{description} diff --git a/stp/create/shorthands.tex b/stp/create/shorthands.tex new file mode 100644 index 0000000..9568dd0 --- /dev/null +++ b/stp/create/shorthands.tex @@ -0,0 +1,16 @@ +For greater expressivity we use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locGasUpfrontCreate & \define & \locGasMxp + G_\text{txcreate} \\ + \locDiff & \define & \locGasActl ~ - ~ \locGasUpfrontCreate \\ + \locOneSixtyFourth & \define & \resLo_{i + 2} + \end{array} \right. +\] +These are only to be used if the row index $i$ is such that +\[ + \begin{cases} + \stpStamp _{i} \neq \stpStamp_{i - 1} \\ + \isCreate _{i} = 1 \\ + \end{cases} +\] +which will be the case starting with section~(\ref{stp: create: constraints}) diff --git a/stp/flags.tex b/stp/flags.tex new file mode 100644 index 0000000..3a64fcb --- /dev/null +++ b/stp/flags.tex @@ -0,0 +1,17 @@ +\def\fullOne{\cellcolor{\romCol}\textbf{1}} +\def\zero{\gray{\textbf{0}}} +In the following we provide the values of \type{} and \cctv{} in terms of \INST{}. +\begin{center} + \renewcommand{\arraystretch}{1.3} + \begin{tabular}{|l|c|c|} + \hline + \INST{} & \type{} & \cctv{} \\ \hline\hline + \inst{CALL} & 0 & \fullOne \\ \hline + \inst{CALLCODE} & 0 & \fullOne \\ \hline + \inst{STATICCALL} & 0 & \zero \\ \hline + \inst{DELEGATECALL} & 0 & \zero \\ \hline + \inst{CREATE} & \fullOne & \zero \\ \hline + \inst{CREATE2} & \fullOne & \zero \\ \hline + \end{tabular} +\end{center} +These values are set by the \hubMod{} module when calling upon the \stpMod{} module. diff --git a/stp/heartbeat.tex b/stp/heartbeat.tex new file mode 100644 index 0000000..eef395a --- /dev/null +++ b/stp/heartbeat.tex @@ -0,0 +1,39 @@ +The heartbeat of the present module falls in line with that of many other modules: it has a stamp that counts monotonically up from 0 jumping by 1 every time an instruction has been dealt with. We further have a counter column with a (variable) cycle length of $\maxCt$. + +\begin{enumerate} + \item $\stpStamp_{0} = 0$ + \item $\stpStamp_{i + 1} \in \{\stpStamp_{i}, 1 + \stpStamp_{i}\}$ + \item \If $\stpStamp_{i} = 0$ \Then + \[ + \begin{cases} + \ct_{i} = 0 \\ + \maxCt_{i} = 0 \\ + \wcpLookupFlag_{i} + \divLookupFlag_{i} = 0 \\ + \end{cases} + \] + \item \If $\stpStamp_{i} \neq \stpStamp_{i + 1}$ \Then $\ct_{i + 1} = 0$; + \item \If $\stpStamp_{i} \neq 0$ \Then we impose + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then $\stpStamp_{i + 1} = 1 + \stpStamp_{i}$ + \end{enumerate} + We further set the value of $\maxCt$ which marks the cut-off point for $\ct$: + \begin{enumerate}[resume] + \item we impose + \[ + \begin{cases} + \left. \begin{array}{l} + \If \isCall _{i} = 1 ~ \et \oogx_{i} = 0 ~ \Then \maxCt_{i} = 4 \\ + \If \isCall _{i} = 1 ~ \et \oogx_{i} = 1 ~ \Then \maxCt_{i} = 2 \\ + \end{array} \right\} & \text{\inst{CALL}-type instruction} \vspace{2mm} \\ + \left. \begin{array}{l} + \If \isCreate_{i} = 1 ~ \et \oogx_{i} = 0 ~ \Then \maxCt_{i} = 2 \\ + \If \isCreate_{i} = 1 ~ \et \oogx_{i} = 1 ~ \Then \maxCt_{i} = 1 \\ + \end{array} \right\} & \text{\inst{CREATE}-type instruction} + \end{cases} + \] + \end{enumerate} + \item \If $\stpStamp_{N} \neq 0$ \Then $\ct_{N} = \maxCt_{N}$ +\end{enumerate} +In other words + diff --git a/stp/instructions.tex b/stp/instructions.tex new file mode 100644 index 0000000..d9c08c0 --- /dev/null +++ b/stp/instructions.tex @@ -0,0 +1,54 @@ +We constrain the binary columns recognizing instructions. We introduce the following shorthands: +\[ + \flagSum_{i} = + \left[ \begin{array}{cr} + + & \stpCreate_{i} \\ + + & \stpCreateTwo_{i} \\ + + & \stpCall_{i} \\ + + & \stpCallCode_{i} \\ + + & \stpDelegateCall_{i} \\ + + & \stpStaticCall_{i} \\ + \end{array} \right] + ,\quad + % \quad\text{and}\quad + \instSum_{i} = + \left[ \begin{array}{crcl} + + & \inst{CREATE} & \!\!\! \cdot \!\!\! & \stpCreate_{i} \\ + + & \inst{CREATE2} & \!\!\! \cdot \!\!\! & \stpCreateTwo_{i} \\ + + & \inst{CALL} & \!\!\! \cdot \!\!\! & \stpCall_{i} \\ + + & \inst{CALLCODE} & \!\!\! \cdot \!\!\! & \stpCallCode_{i} \\ + + & \inst{DELEGATECALL} & \!\!\! \cdot \!\!\! & \stpDelegateCall_{i} \\ + + & \inst{STATICCALL} & \!\!\! \cdot \!\!\! & \stpStaticCall_{i} \\ + \end{array} \right] +\] +The constraints are thus as follows: +\begin{enumerate} + \item \If $\stpStamp_{i} = 0$ \Then $\flagSum_{i} = 0$ + \item \If $\stpStamp_{i} \neq 0$ \Then $\flagSum_{i} = 1$ + \item $\INST_{i} = \instSum_{i}$ +\end{enumerate} +We further introduce the following shorthands +\[ +\left\{ \begin{array}{lcl} + \isCreate_{i} & = & + \left[ \begin{array}{cr} + + & \stpCreate_{i} \\ + + & \stpCreateTwo_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \isCall _{i} & = & + \left[ \begin{array}{cr} + + & \stpCall_{i} \\ + + & \stpCallCode_{i} \\ + + & \stpDelegateCall_{i} \\ + + & \stpStaticCall_{i} \\ + \end{array} \right] \vspace{2mm} \\ + \cctv_{i} & = & + \left[ \begin{array}{cr} + + & \stpCall_{i} \\ + + & \stpCallCode_{i} \\ + \end{array} \right] \vspace{2mm} \\ +\end{array} \right. +\] +\saNote{} The acronym \cctv{} stands for ``\textbf{c}all \textbf{c}an \textbf{t}ransfer \textbf{v}alue.'' + +\saNote{} These are \emph{de facto} binary columns. diff --git a/stp/intro.tex b/stp/intro.tex new file mode 100644 index 0000000..dff713a --- /dev/null +++ b/stp/intro.tex @@ -0,0 +1,22 @@ +The \stpMod{} module performs computations associated with initiating \inst{CALL}'s and \inst{CREATE}'s. The investigation can be subdivided into three distinct topics: +\begin{description} + \item[\colorbox{solarized-orange}{\textbf{Upfront gas cost computations.}}] + The module checks for \oogxSH{}'s; this requires: + (\emph{a}) establishing that the currently available gas\footnote{before any instruction processing} $\gasActual$ is nonnegative; + (\emph{b}) computing the upfront gas cost \locGasUpfront{} incurred by the instruction; + (\emph{c}) detecting \oogxSH{}'s by comparing $\gasActual$ to $\locGasUpfront$. + \item[\colorbox{solarized-green}{\textbf{Gas cost and gas stipend computations.}}] + Assuming no \oogxSH{} has occurred the quantity $\locDiff := \gasActual - \locGasUpfront$ is nonnegative and the checks continue: + (\emph{d}) + computing the maximum amount of gas $L(\locDiff)$ that may be transfered from the current context to the child context and, + for \inst{CALL}-type instructions specifically, + (\emph{e}) comparing $L(\locDiff)$ to the gas parameter of the instruction and topping off the gas with $G_\text{callstipend}$ if value is being transfered. +\end{description} +The ``difficult'' parts of the computations are off-loaded to the \wcpMod{} and the \modMod{} modules. Indeed, all comparisons are handed off to the \wcpMod{} module, all divisions are handed off to te \modMod{} module. Note that step (\emph{d}) requires the computation of the ``$(63/64)^{\text{ths}}$'' of $\locDiff{}$ i.e. $L(\locDiff)$ where, in accordance with the \cite{EYP}: +\[ L(\col{x}) := \col{x} - \lfloor \col{x}/64 \rfloor . \] +\saNote{} Depending on the instruction-type the \locGasUpfront{} cost is either \locGasUpfrontCall{} / \locGasUpfrontCreate{} + +\saNote{} It is of note that for both instruction families an \oogxSH{}\footnote{an \oogxSH{} which is not an \mxpxSH{}, that is} will be verified twice by the \zkEvm{}: +once in the present \stpMod{} module and +once in the \gasMod{} module, see chapter~(\ref{chap: gas}). +This is a small redundancy that, in the current design, is unavoidable. diff --git a/stp/lookups.tex b/stp/lookups.tex new file mode 100644 index 0000000..1ae14d0 --- /dev/null +++ b/stp/lookups.tex @@ -0,0 +1 @@ +Most of the computation is offloaded to the $\wcpMod$ or $\aluMod$ module. diff --git a/stp/lookups/mod.tex b/stp/lookups/mod.tex new file mode 100644 index 0000000..eea8540 --- /dev/null +++ b/stp/lookups/mod.tex @@ -0,0 +1,30 @@ +The lookup to the $\modMod$ module is constructed as follows: +\begin{description} + \item[\underline{Selector:}] \divLookupFlag{} + \item[\underline{Source columns:}] from the \stpMod{} module: + \begin{multicols}{4} + \begin{enumerate} + \item $\argOneHi_{i}$ + \item $\argOneLo_{i}$ + \item $0$ + \item $\argTwoLo_{i}$ + \item $0$ + \item $\resLo_{i}$ + \item $\exoInst_{i}$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\item[\underline{Target columns:}] from the \modMod{} module: + \begin{multicols}{4} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resHi$ + \item $\resLo$ + \item $\INST$ + \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/stp/lookups/wcp.tex b/stp/lookups/wcp.tex new file mode 100644 index 0000000..276e2b3 --- /dev/null +++ b/stp/lookups/wcp.tex @@ -0,0 +1,27 @@ +The lookup to the $\wcpMod$ is naturally constructed as follows: + +\begin{description} + \item[\underline{Selector:}] \wcpLookupFlag{} + \item[\underline{Source columns:}] from the \stpMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi_{i}$ + \item $\argOneLo_{i}$ + \item $0$ + \item $\argTwoLo_{i}$ + \item $\resLo_{i}$ + \item $\exoInst_{i}$ + \end{enumerate} + \end{multicols} +\item[\underline{Target columns:}] from the \wcpMod{} module: + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/stp/shorthands.tex b/stp/shorthands.tex new file mode 100644 index 0000000..080f3eb --- /dev/null +++ b/stp/shorthands.tex @@ -0,0 +1,12 @@ +We gather here some shared shorthands. Later one we shall define some \inst{CALL}/\inst{CREATE}-specific shorthands. +\[ + \left\{ \begin{array}{lcl} + \locOogx & \define & \oogx_{i} \\ + \locGasActl & \define & \gasActual_{i} \\ + \locGasMxp & \define & \gasMxp_{i} \\ + \locWarm & \define & \warm_{i} \\ + \locExists & \define & \existence_{i} \\ + \end{array} \right. +\] +These are only to be used if the row index $i$ is such that +\( \stpStamp _{i} \neq \stpStamp_{i - 1} \). diff --git a/stp/vanishing.tex b/stp/vanishing.tex new file mode 100644 index 0000000..6c4c25d --- /dev/null +++ b/stp/vanishing.tex @@ -0,0 +1,30 @@ +The present section presents vanishing constraints for columns that aren't used depeding on the instruction type. We \emph{may} impose that +\begin{description} + \item[\underline{\inst{CREATE}-type instructions:}] \If $\isCreate_{i} = 1$ \Then + \[ + \left\{\begin{array}{lclr} + \gasHi_{i} & = & 0 & (\trash) \\ + \gasLo_{i} & = & 0 & (\trash) \\ + \warm_{i} & = & 0 & (\trash) \\ + \existence_{i} & = & 0 & (\trash) \\ + \end{array}\right. + \] + \item[\underline{\inst{CALL} instructions:}] \If $\stpCall_{i} = 1$ \Then we impose nothing; + \item[\underline{\inst{CALLCODE} instructions:}] \If $\stpCallCode_{i} = 1$ \Then we impose \( \existence_{i} = 1 \) + \item[\underline{\inst{DELEGATECALL} instructions:}] \If $\stpDelegateCall_{i} = 1$ \Then + \[ + \left\{\begin{array}{lclr} + \valHi_{i} & = & 0 & (\trash) \\ + \valLo_{i} & = & 0 & (\trash) \\ + \existence_{i} & = & 1 & (\trash) \\ + \end{array}\right. + \] + \item[\underline{\inst{STATICCALL} instructions:}] \If $\stpStaticCall_{i} = 1$ \Then + \[ + \left\{\begin{array}{lclr} + \valHi_{i} & = & 0 & (\trash) \\ + \valLo_{i} & = & 0 & (\trash) \\ + \end{array}\right. + \] +\end{description} +\ob{TODO: are these restrictions desirable ? These are obviously harmless constraints, they make for slighty smaller lookups if we segregate them by instruction type, and potentially add constraints if we don't.} diff --git a/trm/_all_trm.tex b/trm/_all_trm.tex new file mode 100644 index 0000000..a8f1739 --- /dev/null +++ b/trm/_all_trm.tex @@ -0,0 +1,29 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/ram} +\usepackage{../pkg/trm} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/offset_processor} + +\title{Address trimming module} +\author{Rollup team} +\date{September 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/trm/_inputs.tex b/trm/_inputs.tex new file mode 100644 index 0000000..a37acb0 --- /dev/null +++ b/trm/_inputs.tex @@ -0,0 +1,12 @@ +\section{Address trimming module} +\subsection{Introduction} \input{introduction} +\subsection{Columns} \input{columns} + +\section{Constraints} +\subsection{Heartbeat} \label{sec: heartbeat} \input{heartbeat} +\subsection{Counter constancies} \input{constancies} +\subsection{Binary constraints} \input{binary} +\subsection{\plateauBit{} contraints} \input{plateau} +\subsection{Byte decomposition} \input{byteDec} +\subsection{Target constraints} \input{target} +\subsection{Identifying precompiles} \input{precompiles} diff --git a/trm/binary.tex b/trm/binary.tex new file mode 100644 index 0000000..190efe6 --- /dev/null +++ b/trm/binary.tex @@ -0,0 +1,8 @@ +The following columns are binary: +\begin{multicols}{3} +\begin{enumerate} + \item $\isPrecompile$ + \item $\plateauBit$ + \item $\bit{1}$ +\end{enumerate} +\end{multicols} diff --git a/trm/byteDec.tex b/trm/byteDec.tex new file mode 100644 index 0000000..877bbca --- /dev/null +++ b/trm/byteDec.tex @@ -0,0 +1,24 @@ +We impose the following byte decomposition constraints: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then + \[ + \left\{ + \begin{array}{lcl} + \acc{HI}_{i} & \!\!\! = \!\!\! & \byteCol{HI}_{i} \\ + \acc{LO}_{i} & \!\!\! = \!\!\! & \byteCol{LO}_{i} \\ + \acc{T}_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} + \right. + \] + \item \If $\ct_{i} \neq 0$ \Then + \[ + \left\{ + \begin{array}{lcl} + \acc{HI}_{i} & \!\!\! = \!\!\! & 256 \cdot \acc{HI}_{i - 1} + \byteCol{HI}_{i} \\ + \acc{LO}_{i} & \!\!\! = \!\!\! & 256 \cdot \acc{LO}_{i - 1} + \byteCol{LO}_{i} \\ + \acc{T}_{i} & \!\!\! = \!\!\! & 256 \cdot \acc{T}_{i - 1} + \plateauBit_{i} \cdot \byteCol{HI}_{i} \\ + \end{array} + \right. + \] +\end{enumerate} +We further impose that $\byteCol{HI}$ and $\byteCol{LO}$ satisfy bytehood constraints. diff --git a/trm/columns.tex b/trm/columns.tex new file mode 100644 index 0000000..c4aff18 --- /dev/null +++ b/trm/columns.tex @@ -0,0 +1,25 @@ +\begin{enumerate} + \item $\trmStamp$: + stamp column; starts at $0$ and grows by 1 with every served request; like many other stamp columns its main purpose is to separate the different requests to that module; + \item $\rawAddrHi$ and $\rawAddrLo$: + \godGiven{} + \ccc{}; contains the high and low part of some stack value which ought to be interpreted as an address; + \item $\trmAddrHi$: + \godGiven{} + \ccc{}; contains the trimmed version of the high part of the address argument; + \item $\isPrecompile$: + \godGiven{} + \ccbc{}; equals $1$ \emph{if and only if} the trimmed address is in the range $\{1, 2,\dots, 9\}$; + \item $\ct$: + counter column: counts continuously from $0$ to $\llargeMO$ and resets; + \item $\byteCol{HI}$ and $\acc{HI}$: + byte column and associated accumulator column; + \item $\byteCol{LO}$ and $\acc{LO}$: + byte column and associated accumulator column; + \item $\acc{T}$: + accumulator column; accumulates some of the bytes from $\byteCol{HI}$; + \item $\plateauBit$: + binary column that implements a \textbf{binary plateau constraint} in that it switches from $0$ to $1$ when $\ct_{i} = 12$; + \item $\bit{1}$: + binary column; used in establishing that a (trimmed) address is that of a precompile. +\end{enumerate} diff --git a/trm/constancies.tex b/trm/constancies.tex new file mode 100644 index 0000000..e9de036 --- /dev/null +++ b/trm/constancies.tex @@ -0,0 +1,13 @@ +As per usual we say that a column $\col{X}$ is \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose that the following columns be counter constant: +\begin{multicols}{4} +\begin{enumerate} + \item $\rawAddrHi$ + \item $\rawAddrLo$ + \item $\trmAddrHi$ + \item $\isPrecompile$ +\end{enumerate} +\end{multicols} diff --git a/trm/heartbeat.tex b/trm/heartbeat.tex new file mode 100644 index 0000000..e0bafd4 --- /dev/null +++ b/trm/heartbeat.tex @@ -0,0 +1,28 @@ +The heartbeat of the address trimming module is very simple: the \ct{} column counts from $0$ to $\llargeMO$ unless the $\trmStamp$ is zero, in which case it hovers at $0$. +\begin{enumerate} + \item $\trmStamp_{0} = 0$ + \item $\trmStamp_{i + 1} \in \{ \trmStamp_{i}, 1 + \trmStamp_{i} \}$ + \item \If $\trmStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \rawAddrHi_{i} & \!\!\! = \!\!\! & 0 \\ + \rawAddrLo_{i} & \!\!\! = \!\!\! & 0 \\ + \trmAddrHi_{i} & \!\!\! = \!\!\! & 0 \\ + \isPrecompile_{i} & \!\!\! = \!\!\! & 0 \\ + \end{array} \right. + \qquad + \left\{ \begin{array}{lcl} + \ct_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\ + \byteCol{HI}_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\ + \byteCol{LO}_{i} & \!\!\! = \!\!\! & 0 \quad (\trash) \\ + \end{array} \right. + \] + %$\ct_{i} = 0$ + \item \If $\trmStamp_{i + 1} \neq \trmStamp_{i}$ \Then $\ct_{i + 1} = 0$ + \item \If $\trmStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \llargeMO$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \llargeMO$ \Then $\trmStamp_{i + 1} = 1 + \trmStamp_{i}$ + \end{enumerate} + \item \If $\trmStamp_{N} \neq 0$ \Then $\ct_{N} = \llargeMO$ +\end{enumerate} diff --git a/trm/introduction.tex b/trm/introduction.tex new file mode 100644 index 0000000..d4bb1d3 --- /dev/null +++ b/trm/introduction.tex @@ -0,0 +1,26 @@ +The \textbf{address trimming module} is a tiny module whose purpose is twofold: +(\emph{a}) +reduce 32 byte strings modulo $2^{160}$ +(\emph{b}) +identify addresses of precompiles. +Recall that some opcodes take an address stack argument which may require trimming to be interpreted as an address. +Furthermore when computing a deployment address associated with an invokation of a \inst{CREATE}-type instruction the \rlpAddrMod{} module is called, too, to trim down the raw \texttt{KECCAK} hash. +Also every new address appearing in the \hubMod{} module is automatically trimmed upon first encounter. +Note that carrying out the first of these tasks boils down to trimming off the leading bytes off of the high part of the imported address. The following opcodes may trigger it: +\begin{multicols}{4} +\begin{enumerate} + \item \inst{BALANCE} + \item \inst{EXTCODESIZE} + \item \inst{EXTCODECOPY} + \item \inst{EXTCODEHASH} + \item \inst{CALL} + \item \inst{CALLCODE} + \item \inst{STATICCALL} + \item \inst{DELEGATECALL} + \item \inst{SELFDESTRUCT} + \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +These are precisely the instructions which raise the $\trmFlag$ in the \hubMod{}. + +\saNote{} \inst{CREATE}-type instructions (\inst{CREATE} and \inst{CREATE2}) trigger the \trmMod{} module \textbf{indirectly} through the \rlpAddrMod{}. diff --git a/trm/plateau.tex b/trm/plateau.tex new file mode 100644 index 0000000..13497e6 --- /dev/null +++ b/trm/plateau.tex @@ -0,0 +1,8 @@ +The $\plateauBit$ column is a binary colum that hovers around zero until $\ct$ reaches the value 12 at which point it switches to 1. The associated constraints are as follows: +\begin{enumerate} + \item \plateauBit{} is binary; + \item \If $\ct_{i} = 0$ \Then $\plateauBit_{i} = 0$ \quad (\trash); + \item \If $\ct_{i} \neq 0$ \Then $\plateauBit_{i} \in \{ \plateauBit_{i - 1}, 1 + \plateauBit_{i - 1} \}$; + \item \If $\ct_{i} = \llargeMO$ \Then \big($\plateauBit_{i - 4} + \plateauBit_{i - 3} = 1$\big); +\end{enumerate} +These constraints enforce that over a counter-cycle (i.e. $\llarge$ rows where $\ct$ counts from $0$ to $\llargeMO$) $\plateauBit$ is constant $= 0$ for the 12 first rows then jumps to $1$ and stays there until the end of the counter cycle. diff --git a/trm/precompiles.tex b/trm/precompiles.tex new file mode 100644 index 0000000..211105b --- /dev/null +++ b/trm/precompiles.tex @@ -0,0 +1,37 @@ +The present section constrains the $\isPrecompile$ column. +\begin{enumerate} + \item $\isPrecompile$ and $\bit{1}$ are binary; + \item \If $\ct_{i} = \llargeMO$ \Then + \begin{enumerate} + \item \If $\trmAddrHi_{i} + \big(\rawAddrLo_{i} - \byteCol{LO}_{i}\big) \neq 0$ \Then $\isPrecompile_{i} = 0$ + \item \If $\trmAddrHi_{i} + \big(\rawAddrLo_{i} - \byteCol{LO}_{i}\big) = 0$ \Then + \begin{enumerate} + \item \If $\byteCol{LO}_{i} = 0$ \Then $\isPrecompile_{i} = 0$ + \item\label{trm: justifying isPrecompile through a comparion} \If $\byteCol{LO}_{i} \neq 0$ \Then + \[ + \underbrace{\Big( 9 - \byteCol{LO}_{i} \Big) + \cdot + \Big( 2 \cdot \isPrecompile_{i} - 1 \Big) + + + \Big( \isPrecompile_{i} - 1 \Big)}_{\displaystyle (\star) } + = + \sum_{k = 0}^7 + 2^k \cdot \bit{1}_{i - k} + \] + \end{enumerate} + \end{enumerate} +\end{enumerate} +In other words if the (trimmed) address is anything but a byte in the least significant position we set $\isPrecompile{} = 0$. If the (trimmed) address is a single byte but is $=0$ we set $\isPrecompile{} = 0$ again. In the remaining case (the trimmed address is both a single byte and nonzero) the implementer must set the \isPrecompile{} bit manually. This bit is to be $=1$ \emph{if and only if} the (trimmed) address is in the range $\{1, 2,\dots, 9\}$. The \zkEvm{} verifies this claim in the equation \ref{trm: justifying isPrecompile through a comparion} which performs a comparison with $9$. The purpose of the \bit{1}'s column is to contain the bit decomposition of the adjusted, nonnegative difference $(\star)$. The above achieves the desired result that $\isPrecompile = 1 \iff \trmAddrHi = 0$ and $\rawAddrLo_{i} \in \{1, 2, \dots, 9 \}$. + +\saNote{} Given that $\ct_{i} = \llargeMO$, the quantity ``$\col{Q} := \trmAddrHi_{i} + \big(\rawAddrLo_{i} - \byteCol{LO}_{i}\big)$'' is known to be the sum of two ``small nonnegative integers'': $\trmAddrHi_{i}$ is constructed to be a $4$ byte integer and $\rawAddrLo_{i}$ has been verified to be a $\llarge$ integer by means of a byte decomposition, the last byte therein being $\byteCol{LO}_{i}$. Thus both terms in the sum are $\geq$ and ``small''. It therefore makes sense to use the distinction +\[ + \col{Q} \neq 0 + \text{ vs. } + \col{Q} = 0 +\] +in lieu of the following conditions respectively: +\[ + \Big[\big[\trmAddrHi \neq 0\big] ~ \Or \big[\rawAddrLo \geq 256\big]\Big] + \text{ vs. } + \Big[\big[\trmAddrHi = 0\big] \et \big[\rawAddrLo\text{ is a single byte}\big]\Big]. +\] diff --git a/trm/target.tex b/trm/target.tex new file mode 100644 index 0000000..dedb72d --- /dev/null +++ b/trm/target.tex @@ -0,0 +1,13 @@ +We fix the target of the accumulator column: +\begin{enumerate} + \item \If $\ct_{i} = \llargeMO$ \Then + \[ + \left\{ + \begin{array}{lcl} + \rawAddrHi_{i} & \!\!\! = \!\!\! & \acc{HI}_{i} \\ + \rawAddrLo_{i} & \!\!\! = \!\!\! & \acc{LO}_{i} \\ + \trmAddrHi_{i} & \!\!\! = \!\!\! & \acc{T}_{i} \\ + \end{array} + \right. + \] +\end{enumerate} diff --git a/txn_cmp/_all_preliminary_gas_checks.tex b/txn_cmp/_all_preliminary_gas_checks.tex new file mode 100644 index 0000000..3080980 --- /dev/null +++ b/txn_cmp/_all_preliminary_gas_checks.tex @@ -0,0 +1,39 @@ +\documentclass{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/stack} +%\usepackage{../pkg/account} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +%\usepackage{../pkg/offset_processor} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} + +\title{Preliminary gas checks module} +\author{Rollup team} +\date{March 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/txn_cmp/_inputs.tex b/txn_cmp/_inputs.tex new file mode 100644 index 0000000..741d9de --- /dev/null +++ b/txn_cmp/_inputs.tex @@ -0,0 +1,24 @@ +\def\nByteColumns{10} + +\section{Preliminary gas checks module} + \subsection{Introduction} + \input{intro} + \subsection{Columns} + \input{columns} + +\section{Constraints} + \subsection{Heartbeat} + \label{sec: (preliminary gas check) heartbeat} + \input{heartbeat} + \subsection{Constancies} + \label{sec: (preliminary gas check) constancies} + \input{constancies} + \subsection{Binary constraints} + \label{sec: (preliminary gas check) binary} + \input{binary} + \subsection{Byte decomposition and bytehood constraints} + \label{sec: (preliminary gas check) byteDec} + \input{byteDec} + \subsection{Target constraints} + \label{sec: (preliminary gas check) target} + \input{target} \ No newline at end of file diff --git a/txn_cmp/binary.tex b/txn_cmp/binary.tex new file mode 100644 index 0000000..a791122 --- /dev/null +++ b/txn_cmp/binary.tex @@ -0,0 +1,3 @@ +We ask that the columns $\txFullTip$ and $\txIsTypeTwo$ be binary. + +\saNote{} Columns which are preceded by the ``transaction data symbol'' $\transactionSignifier$ are imports from the transaction data module. The binary conditions on $\txIsTypeTwo$ and $\txFullTip$ need not be inforced here and will be omitted from the implementation. \ No newline at end of file diff --git a/txn_cmp/byteDec.tex b/txn_cmp/byteDec.tex new file mode 100644 index 0000000..532a4bf --- /dev/null +++ b/txn_cmp/byteDec.tex @@ -0,0 +1,5 @@ +We impose bytehood constraints on the columns $\byteCol{k}$, $k=1,\dots,\nByteColumns$. We further impose that the pairs $(\byteCol{k}, \acc{k})$, $k=1,\dots,\nByteColumns$, satisfy the following byte decompositions constraints: +\begin{enumerate} + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_{i}$ + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i-1} + \byteCol{k}_{i}$ +\end{enumerate} \ No newline at end of file diff --git a/txn_cmp/columns.tex b/txn_cmp/columns.tex new file mode 100644 index 0000000..b488548 --- /dev/null +++ b/txn_cmp/columns.tex @@ -0,0 +1,27 @@ +\begin{enumerate} + \item $\ct$: initially hovers around $0$ and then perpetually cycles from $0$ to $\mmediumMO$ and resets + \item $\absTxNum$: + counter-constant column which initially stagnates around $0$ and then increases by $1$ with every new counter-cycle; + \item $\txGasLimit$: + counter-constant column containing the gas limit as specified in the transaction; + \item $\txMaxFee$: + counter-constant column containing the gas price of type 0 and type 1 transaction; \texttt{max\_fee\_per\_gas} for type 2 transactions; + \item $\txMaxTip$: + counter-constant column containing the undefined for type 0 and type 1 transaction; \texttt{max\_priority\_fee\_per\_gas} for type 2 transactions; + \item $\txGasPrice$: + counter-constant column containing the gas price as returned by the \inst{GASPRICE} opcode; + \item $\txPriorityFeePerGas$: + counter-constant column containing the gas price at which the \inst{COINBASE} address is paid in fees; + \item $\txInitialGasCost$: + counter-constant column containing the \textbf{intrinsic gas cost} of a transaction\footnote{``the amount of +gas this transaction requires to be paid prior to execution'', see \ob{TODO: add reference ot EYP, page 9}}; + \item $\txBasefee$: + counter-constant column containing the base fee; + \item $\txIsTypeTwo$: + counter-constant binary column which $=1$ \emph{if and only if} the transaction has $\txType = 2$ + \item $\txFullTip$: + counter-constant binary column which $=1$ \emph{if and only if} + \[\txBasefee + \txMaxTip \leq \txMaxFee;\] + \item $\byteCol{k}$ and $\acc{k}$, $k=1, 2,\dots,\nByteColumns$: byte columns and associated accumulator columns; +\end{enumerate} +\saNote{} All columns which are preceded by the ``transaction data symbol'' $\transactionSignifier$ are imports from the transaction data module. diff --git a/txn_cmp/constancies.tex b/txn_cmp/constancies.tex new file mode 100644 index 0000000..93735d7 --- /dev/null +++ b/txn_cmp/constancies.tex @@ -0,0 +1,20 @@ +As per usual we say that a column $\col{X}$ is \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We ask that the following columns be counter-constant: +\begin{multicols}{3} +\begin{enumerate} + \item $\absTxNum$ + \item $\txGasLimit$ + \item $\txMaxFee$ + \item $\txMaxTip$ + \item $\txGasPrice$ + \item $\txPriorityFeePerGas$ + \item $\txInitialGasCost$ + \item $\txIsTypeTwo$ + \item $\txFullTip$ + % \item[\vspace{\fill}] +\end{enumerate} +\end{multicols} +\saNote{} The counter-constancy of $\absTxNum$ follows from the heartbeat constraints. diff --git a/txn_cmp/heartbeat.tex b/txn_cmp/heartbeat.tex new file mode 100644 index 0000000..d09c45b --- /dev/null +++ b/txn_cmp/heartbeat.tex @@ -0,0 +1,92 @@ +The heartbeat of the present module is very standard. +\begin{enumerate} + \item $\absTxNum_{0} = 0$ + \item \If $\absTxNum_{i} = 0$ \Then $\ct_{i} = 0$ + \item $\absTxNum_{i + 1} \in \{ \absTxNum_{i}, 1 + \absTxNum_{i} \}$ + \item \If $\absTxNum_{i + 1} \neq \absTxNum_{i}$ \Then $\ct_{i + 1} = 0$ + \item \If $\absTxNum_{i} \neq 0$ \Then + \[ + \begin{cases} + \If \ct_{i} \neq \mmediumMO ~ \Then \ct_{i + 1} = 1 + \ct_{i} \\ + \If \ct_{i} = \mmediumMO ~ \Then \absTxNum_{i + 1} = 1 + \absTxNum_{i} \\ + \end{cases} + \] + \item \If $\absTxNum_{N} \neq 0$ \Then $\ct_{N} = \mmediumMO$. +\end{enumerate} +In other words, $\absTxNum$ remains constant along counter-cycles ($\mmedium$ consecutive rows where $\ct$ goes from $0$ to $\mmediumMO$.) + +\iffalse +The heartbeat of the present module is simple. +We assume that all transactions dealt with by the \zkEvm{} have their +\texttt{gas\_limit}, +\texttt{max\_priority\_fee\_per\_gas}, +\texttt{max\_fee\_per\_gas} and +\texttt{base\_fee} +be $\mmedium$-byte integers and consequently every transaction in the present module occupies $\mmedium$ rows. +\begin{enumerate} + \item $\batchNum_{0} = 0$ + \item $\batchNum_{i + 1} \in \{ \batchNum_{i}, 1 + \batchNum_{i}\}$ + \item \If $\batchNum_{i} = 0$ \Then + \[ + \begin{cases} + \txNum_{i} = 0 \\ + \ct_{i} = 0 \\ + \end{cases} + \] + \item \If $\batchNum_{i + 1} \neq \batchNum_{i}$ \Then + \[ + \begin{cases} + \txNum_{i + 1} = 1 \\ + \ct_{i + 1} = 0 \\ + \end{cases} + \] + \item \If $\batchNum_{i} \neq 0$ \Then + \[ + \begin{cases} + \If \ct_{i} \neq \mmediumMO ~ \Then + \begin{cases} + \ct_{i + 1} = 1 + \ct_{i} \\ + \txNum_{i + 1} = 1 + \txNum_{i} \\ + \end{cases} \\ + \If \ct_{i} = \mmediumMO ~ \Then \ct_{i + 1} = 0 \\ + \end{cases} + \] + \item \If $\ct_{i} = \mmediumMO$ \Then + $\Big(\batchNum_{i + 1} - \big( 1 + \batchNum_{i} \big)\Big) + \cdot + \Big(\txNum_{i + 1} - \big( 1 + \txNum_{i} \big)\Big) = 0$ + \item \If $\txNum_{i} \neq 0$ \Then $\txNum_{i + 1} = 1 + \txNum_{i}$ + \item \If $\batchNum_{N} \neq 0$ \Then $\ct_{N} = \mmediumMO$ +\end{enumerate} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +Every row outside of the \textbf{padding rows}, which are characterized by $\absTxNum \equiv 0$, contains the data of a transaction along with data pertaining to the initial cost of a transaction (data, pre-warming of addresses and storage keys, deployment surcharge.) Every \textbf{non padding row}, which are characterized by $\absTxNum \neq 0$, represents a unique transaction.characterizedcharacterized +\begin{enumerate} + \item $\absTxNum_{0} = 0$ + \item \If $\absTxNum_{i} = 0$ \Then + \[ + \begin{cases} + \batchNum_{i} = 0 \\ + \txNum_{i} = 0 \\ + \end{cases} + \] + \item \If $\absTxNum_{i} \neq 0$ \Then + \[ + \begin{cases} + \batchNum_{i} \neq 0 \\ + \txNum_{i} \neq 0 & (\trash) \\ + \end{cases} + \] + (the second constraint is obsolete by what follows.) + \item $\absTxNum_{i + 1} \in \{ \absTxNum_{i}, 1 + \absTxNum_{i} \}$ + \item \If $\absTxNum_{i} \neq 0$ \Then $\absTxNum_{i + 1} = 1 + \absTxNum_{i}$ + \item $\batchNum_{i + 1} \in \{ \batchNum_{i}, 1 + \batchNum_{i} \}$ + \item \If $\absTxNum_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\batchNum_{i + 1} = \batchNum_{i}$\footnote{In the implementation one may use ``\If $\batchNum_{i + 1} \neq 1 + \batchNum_{i}$'' instead} \Then $\txNum_{i + 1} = 1 + \txNum_{i}$ + \item \If $\batchNum_{i + 1} \neq \batchNum_{i}$ \Then $\txNum_{i + 1} = 1$ + \end{enumerate} +\end{enumerate} +\fi diff --git a/txn_cmp/intro.tex b/txn_cmp/intro.tex new file mode 100644 index 0000000..c719b0b --- /dev/null +++ b/txn_cmp/intro.tex @@ -0,0 +1,21 @@ +The \textbf{preliminary gas checks} module carries out the initial checks relative to gas (but not balance.) It verifies, for all transaction types that: +\[ +\texttt{gas\_limit} \geq \texttt{intrinsic\_gas} \geq 0 +\] +and for type 2 transactions, i.e. \textsc{EIP-1559} transactions: \ob{TODO: add reference}) +\[ +\left\{ +\begin{array}{lcl} + \texttt{max\_fee\_per\_gas} & \geq & \texttt{max\_priority\_fee\_per\_gas} \\ + \texttt{max\_fee\_per\_gas} & \geq & \texttt{base\_fee} \\ + \texttt{effective\_priority\_fee\_per\_gas} + & = & + \min\left\{ + \begin{array}{c} + \texttt{max\_priority\_fee\_per\_gas}, \\ + \texttt{max\_fee\_per\_gas} - \texttt{base\_fee} + \end{array} + \right\} \\ +\end{array} +\right. +\] \ No newline at end of file diff --git a/txn_cmp/target.tex b/txn_cmp/target.tex new file mode 100644 index 0000000..037a951 --- /dev/null +++ b/txn_cmp/target.tex @@ -0,0 +1,38 @@ +We impose the following target constraints: +\begin{enumerate} + \item \If $\ct_{i} = \mmediumMO$ \Then + \begin{enumerate} + \item The following must always hold + \[ + \left\{ + \begin{array}{lclcl} + \txGasLimit_{i} & \!\!\! = \!\!\! & \acc{1}_{i} \\ + \txInitialGasCost_{i} & \!\!\! = \!\!\! & \acc{2}_{i} \\ + \txBasefee_{i} & \!\!\! = \!\!\! & \acc{3}_{i} \vspace{2mm} \\ + \txGasLimit_{i} & \!\!\! = \!\!\! & \txInitialGasCost & \!\!\! + \!\!\! & \acc{4}_{i} \\ + \end{array} + \right. + \] + \item \If $\txIsTypeTwo_{i} = 1$ \Then we further ask that + \[ + \left\{ + \begin{array}{lclcl} + \txMaxFee_{i} & \!\!\! = \!\!\! & \acc{5}_{i} \\ + \txMaxTip_{i} & \!\!\! = \!\!\! & \acc{6}_{i} \vspace{2mm} \\ + \txMaxFee_{i} & \!\!\! = \!\!\! & \txBasefee_{i} & \!\!\! + \!\!\! & \acc{7}_{i} \\ + \txMaxFee_{i} & \!\!\! = \!\!\! & \txMaxTip_{i} & \!\!\! + \!\!\! & \acc{8}_{i} \\ + \txGasLimit_{i} & \!\!\! = \!\!\! & \txInitialGasCost & \!\!\! + \!\!\! & \acc{9}_{i} \vspace{2mm} \\ + \multicolumn{5}{l}{% + (2 \txFullTip_{i} - 1) + \cdot + \Big( + \txMaxFee_{i} + - \big( \txBasefee_{i} + \txMaxTip_{i} \big) + \Big)} \\ + & \!\!\! = \!\!\! & + \multicolumn{3}{l}{(1 - \txFullTip_{i}) + \acc{10}_{i}} \\ + \end{array} + \right. + \] + \end{enumerate} +\end{enumerate} \ No newline at end of file diff --git a/txn_data/_all_txn_data.tex b/txn_data/_all_txn_data.tex new file mode 100644 index 0000000..50b704f --- /dev/null +++ b/txn_data/_all_txn_data.tex @@ -0,0 +1,49 @@ +\documentclass[fleqn]{article} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/alu} +\usepackage{../pkg/env} +\usepackage{../pkg/warm} +\usepackage{../pkg/storage} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exceptions} +\usepackage{../pkg/exponent} +\usepackage{../pkg/precompiles} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/oob} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/instruction_flags} +\usepackage{../pkg/rlp_tx} +\usepackage{../pkg/rlp_addr} +\usepackage{../pkg/txn_data} +\usepackage{../pkg/batch_data} +\usepackage{../pkg/rlp_log} +\usepackage{../pkg/mmu} +\usepackage{../pkg/euc} +\usepackage{../pkg/iomf_done} + +\usepackage{../pkg/draculatheme} + +\title{Transaction data module} +\author{Rollup team} +\date{March 2023} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/txn_data/_inputs.tex b/txn_data/_inputs.tex new file mode 100644 index 0000000..d1ea82b --- /dev/null +++ b/txn_data/_inputs.tex @@ -0,0 +1,21 @@ +\input{_local} +\section{Transaction data module} \label{txn_data: generalities} +\subsection{Introduction} \label{txn_data: generalities: intro} \input{intro} +\subsection{Columns} \label{txn_data: generalities: columns} \input{columns} + +\section{Constraints} \label{txn_data: constraints} +\subsection{Binary constraints} \label{txn_data: constraints: binary} \input{binary} +\subsection{Constancies} \label{txn_data: constraints: constancies} \input{constancies} +\subsection{Constructing the \ABSTXNUM{}} \label{txn_data: constraints: constructing ABS} \input{constructing_abs_tx_num} +\subsection{Heartbeat} \label{txn_data: constraints: heartbeat} \input{heartbeat} +\subsection{Graphical representation of data} \label{txn_data: constraints: graphical representation} \input{representation} +\subsection{Shorthands} \label{txn_data: constraints: shorthands} \input{shorthands} +\subsection{Horizontalization for \rlpTxnMod{}} \label{txn_data: constraints: horizontalization rlpTxn} \input{horizontalization_rlp_txn} +\subsection{\wcpFlag{}, \eucFlag{} and parametrized constraint systems} \label{txn_data: constraints: comparison constraints} \input{constraint_systems} +\subsection{Shared computations} \label{txn_data: constraints: common computations} \input{shared_computations} +\subsection{Specialized computations} \label{txn_data: constraints: specialized computations} \input{specialized_computations} +\subsection{Setting certain variables} \label{txn_data: constraints: setting variables} \input{setting} +\subsection{Horizontalization for \rlpTxnRcptMod{}} \label{txn_data: constraints: horizontalization rlpTxnRcpt} \input{horizontalization_rlp_txnrcpt} +\subsection{Cumulative gas} \label{txn_data: constraints: cumulative gas} \input{cumulative} + +\section{Lookups} \label{txn_data: lookups} \input{lookups/_inputs} diff --git a/txn_data/_local.tex b/txn_data/_local.tex new file mode 100644 index 0000000..c2b2c20 --- /dev/null +++ b/txn_data/_local.tex @@ -0,0 +1,74 @@ +\def\zero{\graym{0}} +\def\one{\redm{1}} + +\def\gZero {\graym{0}} +\def\gOne {\graym{1}} +\def\rZero {\redm{0}} +\def\rOne {\redm{1}} + +\def\MAX {\col{\_MAX}} +\def\locAbs {\col{ABS}} +\def\locAbsMax {\col{ABS}^\infty} +\def\block {\col{BLK}} +\def\locRel {\col{REL}} +\def\locRelMax {\col{REL}^\infty} +\def\locTxType {\col{tx\_type}} +\def\locToAddrHi {\col{[is\_dep ? 0 : to\_hi]}} +\def\locToAddrLo {\col{[is\_dep ? 0 : to\_lo]}} +\def\locNonce {\col{nonce}} +\def\locValue {\col{value}} +\def\locDataSize {\col{data\_size}} +\def\locDataCost {\col{data\_cost}} +\def\locGasLimit {\col{gas\_limit}} +\def\locIsDep {\col{is\_dep}} +\def\locGasPrice {\col{gas\_price}} +\def\locMaxFee {\col{max\_fee}} +\def\locGetFullTip {\col{get\_full\_tip}} +\def\locMaxPriorityFee {\col{max\_priority\_fee}} +\def\locNumAddr {\col{num\_addr}} +\def\locNumKeys {\col{num\_keys}} +\def\locLegacyUpfrontGasCost {\col{legacy\_upfront\_gas\_cost}} +\def\locAccessUpfrontGasCost {\col{access\_upfront\_gas\_cost}} +\def\locRefundLimit {\col{refund\_limit}} +\def\locGetFullRefund {\col{get\_full\_refund}} +\def\locExecutionGasCost {\col{execution\_gas\_cost}} +\def\locNonzeroDataSize {\col{nonzero\_data\_size}} +\def\fillCell {\cellcolor{gray}} + +\def\locTypeSum {\col{type\_sum}} + +\def\balanceRowOffset {\yellowm{0}} +\def\gasLimitRowOffset {\yellowm{1}} +\def\maxRefundRowOffset {\yellowm{2}} +\def\effectiveRefundRowOffset {\yellowm{3}} +\def\detectingEmptyCallDataRowOffset {\yellowm{4}} +\def\maxFeeVsBaseFeeRowOffset {\yellowm{5}} +\def\maxFeeVsMaxPriorityFee {\yellowm{6}} +\def\effectiveGasPriceRowOffset {\yellowm{7}} + + +\newcommand{\smallCallToLt} [4] { + \texttt{smallCallToLT} _{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument 1:} & #3 \\ + \utt{Argument 2:} & #4 \\ + \end{array} \right]} + +\newcommand{\smallCallToLeq} [4] { + \texttt{smallCallToLEQ} _{#1} + \left[ \begin{array}{ll} + \utt{Row offset:} & #2 \\ + \utt{Argument 1:} & #3 \\ + \utt{Argument 2:} & #4 \\ + \end{array} \right]} + +\newcommand{\smallCallToIszero} [3] { + \texttt{smallCallToISZERO} _{#1} + \left[ \begin{array}{ll} + \utt{Rel. row offset:} & #2 \\ + \utt{Argument 1:} & #3 \\ + \end{array} \right]} + +\newcommand{\resultMustBeFalse} [2] {\texttt{resultMustBeFalse} _{#1} \big[ \, #2 \, \big]} +\newcommand{\resultMustBeTrue} [2] {\texttt{resultMustBeTrue} _{#1} \big[ \, #2 \, \big]} diff --git a/txn_data/binary.tex b/txn_data/binary.tex new file mode 100644 index 0000000..9a0a606 --- /dev/null +++ b/txn_data/binary.tex @@ -0,0 +1,19 @@ +We impose binary constraints on +\begin{multicols}{2} + \begin{enumerate} + \item \txIsLegacy{} + \item \txIsAccessSet{} + \item \txIsTypeTwo{} + \item \txIsDeployment{} + \item \txStatusCode{} + \item \txCopyTxcd{} \quad (\trash) + \item \txRequiresEvmExecution{} + \item \eucFlag{} + \item \wcpFlag{} + \item \isLastTxOfBlock{} \quad (\trash) + %\item[\vspace{\fill}] + %\item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} +There is in reality no reason to require (by constraint) that \txCopyTxcd{} and \isLastTxOfBlock{} be binary as it will be enforced through value assignment. diff --git a/txn_data/columns.tex b/txn_data/columns.tex new file mode 100644 index 0000000..3b6225f --- /dev/null +++ b/txn_data/columns.tex @@ -0,0 +1,147 @@ +The first volley of columns pertain to heartbeat and bookkeeping: +\begin{enumerate} + \item $\relBlock$: + current relative block number in this batch; + \item $\relTxMax$: + total number of transactions in the current block; + \item $\relTx$: + relative transaction number in the current block; + \item $\ABSTXNUM^\infty$: + total number of transactions in the batch; + \item $\ABSTXNUM$: + relative transaction number in the batch; +\end{enumerate} +To simplify notations we use the following abbreviations/shorthands +\[ + \left\{ \begin{array}{lcl} + \block & \!\!\!\define\!\!\! & \relBlock \vspace{2mm} \\ + \locRelMax & \!\!\!\define\!\!\! & \relTxMax \\ + \locRel & \!\!\!\define\!\!\! & \relTx \vspace{2mm} \\ + \locAbsMax & \!\!\!\define\!\!\! & \ABSTXNUM^\infty \\ + \locAbs & \!\!\!\define\!\!\! & \ABSTXNUM \\ + \end{array} \right. +\] +We explain how to extract \locAbs{} from \block{} and \locRel{} in section~(\ref{txn_data: constraints: constructing ABS}). + +The next volley of columns pertains to sender account information: +\begin{enumerate}[resume] + \item $\txFrom\high$, $\txFrom\low$: + \markAsExtractedFromEcrecover{} + high and low parts of the sender address; + \item $\txNonce$: + \markAsExtractedFromRlpTxn{} + transaction nonce; + \item $\txInitialBalance$: + \markAsExtractedFromHub{} + \godGiven{} + sender account's balance right before the transaction starts execution; confirmed against state data in the \hubMod{} module; + \item $\txValue$: + \markAsExtractedFromRlpTxn{} + contains the value to be transferred in the transaction; +\end{enumerate} +The next volley of columns pertains to recipient account information: +\begin{enumerate}[resume] + \item $\txTo\high$, $\txTo\low$: + \markAsSometimesExtractedFromRlpTxn{} + columns containing the high and low part of the recipient address; + \item $\txIsDeployment$: + \markAsExtractedFromRlpTxn{} + binary column; equals $1$ $\iff$ the transaction is a contract creation i.e. $T_\text{t} = \varnothing$; +\end{enumerate} +The next volley of columns pertains to gas and gas price parameters: +\begin{enumerate}[resume] + \item $\txGasLimit$: + \markAsExtractedFromRlpTxn{} + column containing the gas limit as specified in the transaction; + \item $\txInitialGas$: + \markAsComputedHere{} + gas available after deducting the \textbf{intrinsic gas} from the gas limit; + \item $\txGasPrice$: + \markAsComputedHere{} + column containing the gas price as returned by the \inst{GASPRICE} opcode; + \item $\txPriorityFeePerGas$: + \markAsComputedHere{} + column containing the effective rate at which the \inst{COINBASE} address receives fees; + \item $\txBasefee$: + \markAsExtractedFromBtc{} + batch-constant column containing the base fee; + \item $\txCoinbase\high$, $\txCoinbase\low$: + \markAsExtractedFromBtc{} + batch-constant columns containing the (high and low parts of the) coinbase address; + \item $\blockGasLimit$: + \markAsExtractedFromBtc{} + block-constant columns containing the block gas limit; +\end{enumerate} +Recall that the \textbf{intrinsic gas (cost)} is ``the amount of gas this transaction requires to be paid prior to execution'' \ob{TODO: add reference ot EYP, page 9}. + +The following are other data related to the transaction (such as data size and transaction type): +\begin{enumerate}[resume] + \item $\txCallDataSize$: + \markAsExtractedFromRlpTxn{} + column containing the call data size of message call transactions; + \item $\txInitCodeSize$: + \markAsExtractedFromRlpTxn{} + column containing the initialization code size of deployment transactions; + \item $\txIsLegacy$, $\txIsAccessSet$, $\txIsTypeTwo$: + \markAsExtractedFromRlpTxn{} + transaction constant exclusive binary columns; +\end{enumerate} +We now list several columns which record \textbf{transaction data} extracted from the \hubMod{} either at the beginning of a transaction or at transaction end. +\begin{enumerate}[resume] + \item $\txRequiresEvmExecution$: + \markAsComputedHere{} + \markAsExtractedFromHub{} + \partiallyGodGiven{} + binary column; records whether the transaction required \textsc{EVM} execution; confirmed in the \hubMod{} module; + \item \txCopyTxcd{}: + \markAsComputedHere{} + binary columns; + indicates wheter the transaction is provided with call data and whether it needs to be transferred to \textsc{ram} during the \hubMod{}'s initialization phase; + \item $\txLeftoverGas$: + \markAsExtractedFromHub{} + \godGiven{} + left over gas after transaction processing; what the yellow paper calls $g'$; confirmed in the \hubMod{} module; + \item $\txFinalRefundCounter$: + \markAsExtractedFromHub{} + \godGiven{} + sum of all gas refunds accrued during transaction processing; tallied in the \hubMod{} module; + \item $\txEffectiveRefund$: + \markAsComputedHere{} + effective gas refund to the transaction sender; +\end{enumerate} +\saNote{} A transaction requires \textsc{EVM} execution whenever it is a message call to a contract with nonempty code or a contract creation with nonempty initialization code. + +\saNote{} The $\txRequiresEvmExecution$ binary flag must be passed on to the \rlpTxnMod{}. Its purpose there is to filter out those (pathological) transactions which include addresses / storage keys to pre-warm yet target an account with empty bytecode or are deployment transactions with empty initialization code. Indeed these transactions are dealt with in a special way in the \hubMod{} module; in particular address / storage key pre-warming is skipped. + +The following columns are relevant for creating the transaction receipt. +\begin{enumerate}[resume] + \item $\txCumulativeConsumedGas$: + \markAsComputedHere{} + cumulative sum of all consumed gas within a batch of transactions; resets with every new batch of transactions; + \item $\txStatusCode$: + \markAsExtractedFromHub{} + \godGiven{} + binary column which records the status code of the transaction; confirmed in the \hubMod{} module; +\end{enumerate} +The following columns are used in lookup arguments: +\begin{enumerate}[resume] + \item $\ct$: + counter column; used to specify the depth of verticalization; resets with every new transaction; + \item $\phaseNumRlpTxn$: + identifies the phase for the lookup into the \rlpTxnMod{} module lookup; + \item $\phaseNumRlpTxnRcpt$: + identifies the phase for the lookup into the \rlpTxnRcptMod{} module lookup; + \item $\cfi$: + provides nontrivial deployment transactions with a $\CFI$; + \item $\outgoingDataHi$ and $\outgoingDataLo$: + these two columns are connected to the \rlpTxnMod{} module; they are the entry point for transaction data; + \item $\outgoingTxrcpt$: + column connected to the \rlpTxnRcptMod{} through lookup; + \item $\wcpFlag$ and $\eucFlag$: + binary flags used as selectors for lookups; + \item $\argOneLo$, $\argTwoLo$, $\res$, $\INST$: + arguments for calls to the \wcpMod{} module and \eucMod{} module; + \item \isLastTxOfBlock{}: + a bit column that lights up only for the last transaction of each block of the batch; +\end{enumerate} + diff --git a/txn_data/constancies.tex b/txn_data/constancies.tex new file mode 100644 index 0000000..01ed26c --- /dev/null +++ b/txn_data/constancies.tex @@ -0,0 +1,81 @@ +We say that a colum $\col{X}$ is \textbf{transaction-constant} if it satisfies +\[ + \If \locAbs_{i} \neq 1 + \locAbs_{i - 1} ~ \Then + \col{X}_{i} = \col{X}_{i - 1}. +\] +We ask that the following columns be transaction-constant. +We start with the columns containing inputs directly extracted from the transaction itself: +\begin{multicols}{3} + \begin{enumerate} + \item $\txFrom\high$ + \item $\txFrom\low$ + \item $\txNonce$ + \item $\txValue$ + \item $\txGasLimit$ + \item $\txTo\high$ + \item $\txTo\low$ + \item $\txIsDeployment$ + \item $\txCallDataSize$ + \item $\txInitCodeSize$ + \item $\txIsLegacy$ + \item $\txIsAccessSet$ + \item $\txIsTypeTwo$ + \end{enumerate} +\end{multicols} +The following colunms are extracted from the \hubMod{} module +\begin{multicols}{3} + \begin{enumerate} + \item $\txInitialGas$ + \item $\txPriorityFeePerGas$ + \item $\txGasPrice$ + \item $\txCopyTxcd$ + \item $\txCumulativeConsumedGas$ + \item $\cfi$ + \end{enumerate} +\end{multicols} +The following colunms are extracted from the \hubMod{} module +\begin{multicols}{3} + \begin{enumerate} + \item $\txRequiresEvmExecution$ + \item $\txLeftoverGas$ + \item $\txFinalRefundCounter$ + \item $\txEffectiveRefund$ + \item $\txInitialBalance$ + \item $\txStatusCode$ + \end{enumerate} +\end{multicols} +The following colunms are extracted from the \btcMod{} module +\begin{multicols}{2} + \begin{enumerate} + \item $\txCoinbase\high$ \quad (\trash) + \item $\txBasefee$ \quad (\trash) + \item $\txCoinbase\low$ \quad (\trash) + \item $\blockGasLimit$ \quad (\trash) + \end{enumerate} +\end{multicols} +The following columns are required in establishing the \locAbs{}. +\begin{multicols}{3} + \begin{enumerate} + \item $\block$ + \item $\locRel$ + \end{enumerate} +\end{multicols} +\saNote{} The heartbeat makes it so that we may instead ask for \textbf{counter-constancy} i.e. the standard notion where a column $\col{X}$ is \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then + \col{X}_{i} = \col{X}_{i - 1}. +\] +\saNote{} Given the binary nature of certain columns we may reduce the number of constraints by enforcing transaction constancy of +\[ + \weightedFlagSum _{i} \define + \left[ \begin{array}{crcl} + + & 2 ^{0} & \!\!\!\cdot\!\!\! & \txIsDeployment _{i} \\ + + & 2 ^{1} & \!\!\!\cdot\!\!\! & \txIsLegacy _{i} \\ + + & 2 ^{2} & \!\!\!\cdot\!\!\! & \txIsAccessSet _{i} \\ + + & 2 ^{3} & \!\!\!\cdot\!\!\! & \txIsTypeTwo _{i} \\ + + & 2 ^{4} & \!\!\!\cdot\!\!\! & \txRequiresEvmExecution _{i} \\ + + & 2 ^{5} & \!\!\!\cdot\!\!\! & \txCopyTxcd _{i} \\ + + & 2 ^{6} & \!\!\!\cdot\!\!\! & \txStatusCode _{i} \\ + % + & 2 ^{7} & \!\!\!\cdot\!\!\! & _{i} \\ + \end{array} \right] +\] diff --git a/txn_data/constraint_systems.tex b/txn_data/constraint_systems.tex new file mode 100644 index 0000000..41d9e37 --- /dev/null +++ b/txn_data/constraint_systems.tex @@ -0,0 +1,62 @@ +We impose that +\begin{enumerate} + \item \wcpFlag{} is binary (\trash) + \item \eucFlag{} is binary (\trash) + \item $\wcpFlag \cdot \eucFlag \equiv 0$ i.e. \wcpFlag{} and \eucFlag{} are \textbf{exclusive binary flags} +\end{enumerate} +We define parametrized constraint families to deal with setting comparisons +\[ + \left\{ \begin{array}{lcl} + \smallCallToLt + {i}{\relof} + {\col{arg\_1}} + {\col{arg\_2}} + & \iff & + \left\{ \begin{array}{lcl} + \wcpFlag _{i + \relof} & = & \rOne \\ + \eucFlag _{i + \relof} & = & \nothing \\ + \argOneLo _{i + \relof} & = & \col{arg\_1} \\ + \argTwoLo _{i + \relof} & = & \col{arg\_2} \\ + \INST _{i + \relof} & = & \inst{LT} \\ + \end{array} \right. \vspace{2mm} \\ + + \smallCallToLeq + {i}{\relof} + {\col{arg\_1}} + {\col{arg\_2}} + & \iff & + \left\{ \begin{array}{lcl} + \wcpFlag _{i + \relof} & = & \rOne \\ + \eucFlag _{i + \relof} & = & \nothing \\ + \argOneLo _{i + \relof} & = & \col{arg\_1} \\ + \argTwoLo _{i + \relof} & = & \col{arg\_2} \\ + \INST _{i + \relof} & = & \inst{LEQ} \\ + \end{array} \right. \vspace{2mm} \\ + + \smallCallToIszero + {i}{\relof} + {\col{arg\_1}} + & \iff & + \left\{ \begin{array}{lcl} + \wcpFlag _{i + \relof} & = & \rOne \\ + \eucFlag _{i + \relof} & = & \nothing \\ + \argOneLo _{i + \relof} & = & \col{arg\_1} \\ + \argTwoLo _{i + \relof} & = & \nothing \\ + \INST _{i + \relof} & = & \inst{ISZERO} \\ + \end{array} \right. \vspace{2mm} \\ + + \callToEuc + {i}{\relof} + {\col{arg\_1}} + {\col{arg\_2}} + & \iff & + \left\{ \begin{array}{lcl} + \wcpFlag _{i + \relof} & = & \nothing \\ + \eucFlag _{i + \relof} & = & \rOne \\ + \argOneLo _{i + \relof} & = & \col{arg\_1} \\ + \argTwoLo _{i + \relof} & = & \col{arg\_2} \\ + \end{array} \right. \vspace{4mm} \\ + \resultMustBeFalse {i}{\relof} & \iff & \res _{i + \relof} = \rZero \\ + \resultMustBeTrue {i}{\relof} & \iff & \res _{i + \relof} = \rOne \\ + \end{array} \right. +\] diff --git a/txn_data/constructing_abs_tx_num.tex b/txn_data/constructing_abs_tx_num.tex new file mode 100644 index 0000000..96b75c7 --- /dev/null +++ b/txn_data/constructing_abs_tx_num.tex @@ -0,0 +1,81 @@ +The present section explains how the \zkEvm{} constructs +\locAbs {} from +\block {} and +\locRel {} +We ask that $\locAbsMax$ remains constant along non padding rows and that $\locRel$ remain constant along batches: +\begin{enumerate} + \item $\locAbs_{0} = 0$ + \item \If $\locAbs_{i} = 0$ \Then + \[ + \left\{\begin{array}{lclr} + \block _{i} & = & 0 & (\trash) \\ + \locRel _{i} & = & 0 & (\trash) \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lclr} + \locAbsMax _{i} & = & 0 & (\trash) \\ + \locRelMax _{i} & = & 0 & (\trash) \\ + \end{array}\right. + \] + \item $\locAbs_{i + 1} \in \{ \locAbs_{i}, 1 + \locAbs_{i} \}$ + \item $\block_{i + 1} \in \{ \block_{i}, 1 + \block_{i} \}$ + \item \If $\locAbs_{i} \neq 0$ \Then + \[ + \left\{\begin{array}{lcl} + \locAbsMax _{i + 1} & = & \locAbsMax _{i} \\ + \end{array}\right. + \] + \item \If $\block_{i + 1} \neq 1 + \block_{i}$ \Then + \[ + \locRelMax_{i + 1} = \locRelMax_{i} + \] +\end{enumerate} +We now describe the constraints that govern $\big[\block, \locRel\big]$ progression. The constraints below ensure that $\big[\block, \locRel\big]$ start out being $[0,0]$ and remain in that state as long as $\locAbs = 0$. If the row index $i$ is such that $\locAbs_{i - 1} = 0$ and $\locAbs_{i} = 1$, the pair $\big[\block, \locRel\big]$ will jump from $[0,0]$ to $[1,1]$ at those same row indices. Once $\locAbs \neq 0$ the $\big[\block, \locRel\big]$ pair then progresses in such a way that if $\big[\col{b}, \col{t}\big]$ and $\big[\col{b'}, \col{t'}\big]$ represent two consecutive\footnote{i.e. sampled from two consecutive rows with indices $i$ and $i+1$} values of this pair then +\[ + \big[\col{b'}, \col{t'}\big] + = + \begin{cases} + \big[\col{b}, \col{t} \big] & \text{i.e. same transaction, same batch} \\ + \big[\col{b} + 1, 1 \big] & \text{i.e. first transaction of a new batch} \\ + \big[\col{b}, \col{t} + 1 \big] & \text{i.e. next transaction in the batch} \\ + \end{cases} +\] +As a consequence\footnote{and as soon as $\locAbs \neq 0$} the pairs $\big[\block, \locRel\big]$ are listed in ascending order according to the standard lexicographic order on $\mathbb{N}^2$. +\begin{enumerate}[resume] + \item \If $\locAbs_{i} = 0$ \Then + \[ + \left\{\begin{array}{lcl} + \block_{i} & = & 0 \\ + \locRel_{i} & = & 0 \\ + \end{array}\right. + \] + \item \If \big($\locAbs_{i} = 0$ \et $\locAbs_{i + 1} \neq \locAbs_{i}$\big) \Then + \[ + \begin{cases} + \block_{i + 1} = 1 \\ + \locRel_{i + 1} = 1 \\ + \end{cases} + \] + \item \If \big($\locAbs_{i} \neq 0$ \et $\locAbs_{i + 1} \neq \locAbs_{i}$\big) \Then + \begin{enumerate} + \item \If $\locRel_{i} \neq \locRelMax_{i}$ \Then + \[ + \left\{\begin{array}{lcl} + \block_{i + 1} & = & \block_{i} \\ + \locRel_{i + 1} & = & 1 + \locRel_{i} \\ + \end{array}\right. + \] + \item \If $\locRel_{i} = \locRelMax_{i}$ \Then + \[ + \left\{\begin{array}{lcl} + \block_{i + 1} & = & 1 + \block_{i} \\ + \locRel_{i + 1} & = & 1 \\ + \end{array}\right. + \] + \end{enumerate} + \item \If $\locAbs_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\locRel_{i} \neq \locRelMax_{i}$ \Then $\isLastTxOfBlock_{i} = 0$ + \item \If $\locRel_{i} = \locRelMax_{i}$ \Then $\isLastTxOfBlock_{i} = 1$ + \end{enumerate} +\end{enumerate} diff --git a/txn_data/cumulative.tex b/txn_data/cumulative.tex new file mode 100644 index 0000000..f816988 --- /dev/null +++ b/txn_data/cumulative.tex @@ -0,0 +1,66 @@ +The present section constrains the $\txCumulativeConsumedGas$ column. +\begin{enumerate} + \item \If $\locAbs_{i} = 0$ \Then $\txCumulativeConsumedGas_{i} = 0$ + \item \If $\block_{i + 1} \neq \block_{i}$ \Then + \[ \txCumulativeConsumedGas_{i + 1} = \txGasLimit_{i + 1} - \txEffectiveRefund_{i + 1} \] + \item \If $\block_{i + 1} \neq 1 + \block_{i}$ \et $\locAbs_{i + 1} \neq \locAbs_{i}$ \Then + \[ + \txCumulativeConsumedGas_{i + 1} + = + \left[ \begin{array}{ll} + + & \txCumulativeConsumedGas_{i} \\ + + & \big(\txGasLimit_{i + 1} - \txEffectiveRefund_{i + 1}\big) \\ + \end{array}\right] + \] +\end{enumerate} +Recall that $\txCumulativeConsumedGas$ is already constrained to be transaction-constant, see section~(\ref{txData: constraints: constancies}). The constraints above thus enfoce that $\txCumulativeConsumedGas$ tallies the consumed gas in the batch up to and including the current transaction and resets with every batch. + +For the last transaction of each block of the batch, we constrain that the cumulative gas used in this block is less than $\blockGasLimit$: + +\begin{enumerate}[resume] + \item \If $\locAbs_{i} \neq \locAbs_{i - 1}$ \et $\isLastTxOfBlock_{i} = 1$: + \begin{enumerate} + \item \If $\txIsLegacy_{i} = 1$ \Then: + \[ + \left\{ \begin{array}{l} + \smallCallToLeq + {i}{\maxCtTypeZero + 1} + {\txCumulativeConsumedGas} + {\blockGasLimit} + \vspace{2mm} + \\ + \resultMustBeTrue + {i}{\maxCtTypeZero + 1} + \\ + \end{array} \right. + \] + \item \If $\txIsAccessSet_{i} = 1$ \Then: + \[ + \left\{ \begin{array}{l} + \smallCallToLeq + {i}{\maxCtTypeOne + 1} + {\txCumulativeConsumedGas} + {\blockGasLimit} + \vspace{2mm} + \\ + \resultMustBeTrue + {i}{\maxCtTypeOne + 1} + \\ + \end{array} \right. + \] + \item \If $\txIsTypeTwo_{i} = 1$ \Then: + \[ + \left\{ \begin{array}{l} + \smallCallToLeq + {i}{\maxCtTypeTwo + 1} + {\txCumulativeConsumedGas} + {\blockGasLimit} + \vspace{2mm} + \\ + \resultMustBeTrue + {i}{\maxCtTypeTwo + 1} + \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} diff --git a/txn_data/fees.tex b/txn_data/fees.tex new file mode 100644 index 0000000..93df6e3 --- /dev/null +++ b/txn_data/fees.tex @@ -0,0 +1,27 @@ +The present section constrains various \texttt{Wei / gas} rates. +\begin{enumerate} + \item \If $\txIsTypeTwo_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \txGasPrice _{i} & \!\!\! = \!\!\! & \txMaxFee_{i} \\ + \txPriorityFeePerGas _{i} & \!\!\! = \!\!\! & \txMaxFee_{i} \\ + \end{array} \right. + \] + \item \If $\txIsTypeTwo_{i} = 1$ \Then + \begin{enumerate} + \item \If $\txFullTip_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \txGasPrice _{i} & \!\!\! = \!\!\! & \txBasefee_{i} + \txMaxTip_{i} \\ + \txPriorityFeePerGas _{i} & \!\!\! = \!\!\! & \txMaxTip_{i} \\ + \end{array} \right. + \] + \item \If $\txFullTip_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \txGasPrice _{i} & \!\!\! = \!\!\! & \txMaxFee_{i} \\ + \txPriorityFeePerGas _{i} & \!\!\! = \!\!\! & \txMaxFee_{i} - \txBasefee_{i} \\ + \end{array} \right. + \] + \end{enumerate} +\end{enumerate} diff --git a/txn_data/gas.tex b/txn_data/gas.tex new file mode 100644 index 0000000..6108682 --- /dev/null +++ b/txn_data/gas.tex @@ -0,0 +1,56 @@ +\begin{center} +\boxed{\text{All constraints in this subsection assume that $\locAbs_{i} \neq 0$.}} +\end{center} +We constrain the gas columns. +\begin{enumerate} + \item We constrain the intrinsic gas: + \[ + \begin{array}{lcl} + \txInitialGasCost_{i} & \!\!\! = \!\!\! & \phantom{+} ~ \txDataCost_{i} \vspace{1mm} \\ + & & + ~ \, G_{\text{transaction}} \vspace{1mm} \\ + & & + ~ \txIsDeployment_{i} \cdot G_{\text{txcreate}} \vspace{1mm} \\ + & & + ~ \relTxPrewarmAddr \cdot G_{\text{accesslistaddress}} \vspace{1mm} \\ + & & + ~ \relTxPrewarmKeys \cdot G_{\text{accessliststorage}} \\ + \end{array} + \] + \item We constrain the initial gas available in the transaction: + \[ + \txInitialGas_{i} + = + \txGasLimit_{i} - \txInitialGasCost_{i} + \] +\end{enumerate} +Where +\[ +\left\{ +\begin{array}{lcr} + G_\text{transaction} & \!\!\! = \!\!\! & 21\,000 \\ + G_\text{create} & \!\!\! = \!\!\! & 32\,000 \\ + G_\text{accesslistaddress} & \!\!\! = \!\!\! & 2\,400 \\ + G_\text{accessliststorage} & \!\!\! = \!\!\! & 1\,900 \\ +\end{array} +\right. +\] +and +$\txInitialGasCost$, +$\relTxPrewarmAddr$, +$\relTxPrewarmKeys$ +are justified elsewhere. + +We now justify the cumulative gas column. +\begin{enumerate} + \item \If $\block_{i - 1} \neq \block_{i}$ \Then + \[ + \txCumulativeConsumedGas_{i} + = + \txCumulativeConsumedGas_{i - 1} + + + (\txGasLimit_{i} - \txEffectiveRefund_{i}) + \] + \item \If $\block_{i - 1} = \block_{i}$ \Then + \[ + \txCumulativeConsumedGas_{i} + = + \txGasLimit_{i} - \txEffectiveRefund_{i} + \] +\end{enumerate} diff --git a/txn_data/heartbeat.tex b/txn_data/heartbeat.tex new file mode 100644 index 0000000..f906e2c --- /dev/null +++ b/txn_data/heartbeat.tex @@ -0,0 +1,48 @@ +We adopt familiar nomenclature: a \textbf{padding row} is a row such that $\locAbs = 0$, \textbf{non padding rows} have $\locAbs \neq 0$. Non padding rows contains the data of a transaction along with data pertaining to the initial cost of a transaction (data, pre-warming of addresses and storage keys, deployment surcharge.) +\begin{enumerate} + \item $\locAbs_{0} = 0$ \quad (\trash) + \item \If $\locAbs_{i} = 0$ \Then + \[ + \left\{\begin{array}{lclr} + \ct_{i} & = & 0 & \quad (\trash) \\ + \weightedFlagSum _{i} & = & 0 \\ + \end{array}\right. + \] + \saNote{} In particular $\txIsLegacy \equiv \txIsAccessSet \equiv \txIsTypeTwo \equiv 0$ on padding-rows. + \item \If $\locAbs_{i + 1} \neq \locAbs_{i}$ \Then $\ct_{i + 1} = 0$ + \item $\locAbs_{i} \neq 0$ \Then $\txIsLegacy_{i} + \txIsAccessSet_{i} + \txIsTypeTwo_{i} = 1$ + \item \If $\txIsLegacy_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCtTypeZero + \isLastTxOfBlock_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$; + \item \If $\ct_{i} = \maxCtTypeZero + \isLastTxOfBlock_{i}$ \Then $\locAbs_{i + 1} = 1 + \locAbs_{i}$; + \end{enumerate} + \item \If $\txIsAccessSet_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCtTypeOne + \isLastTxOfBlock_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$; + \item \If $\ct_{i} = \maxCtTypeOne + \isLastTxOfBlock_{i}$ \Then $\locAbs_{i + 1} = 1 + \locAbs_{i}$; + \end{enumerate} + \item \If $\txIsTypeTwo_{i} = 1$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCtTypeTwo + \isLastTxOfBlock_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$; + \item \If $\ct_{i} = \maxCtTypeTwo + \isLastTxOfBlock_{i}$ \Then $\locAbs_{i + 1} = 1 + \locAbs_{i}$; + \end{enumerate} +\end{enumerate} +\saNote{} The last transaction of a block requires one more row. +\saNote{} In the implementation one may merge the two last cases under the prefix ``\If $\txIsAccessSet_{i} + \txIsTypeTwo_{i} = 1$.'' +\begin{enumerate}[resume] + \item On the final row we ask that + \[ + \left\{\begin{array}{lcl} + \locAbs_{N} & = & \locAbsMax_{N} \\ + \locRel_{N} & = & \locRelMax_{N} \\ + \isLastTxOfBlock_{N} & = & 1 \quad (\trash) \\ + \multicolumn{3}{l}{% + \begin{cases} + \If \txIsLegacy_{N} = 1 ~ \Then \ct_{N} = \maxCtTypeZero + 1\\ + \If \txIsAccessSet_{N} = 1 ~ \Then \ct_{N} = \maxCtTypeOne + 1\\ + \If \txIsTypeTwo_{N} = 1 ~ \Then \ct_{N} = \maxCtTypeTwo + 1\\ + \end{cases} + } + \end{array}\right. + \] +\end{enumerate} diff --git a/txn_data/horizontalization_rlp_txn.tex b/txn_data/horizontalization_rlp_txn.tex new file mode 100644 index 0000000..54fe7be --- /dev/null +++ b/txn_data/horizontalization_rlp_txn.tex @@ -0,0 +1,104 @@ +The present section describes \textbf{verticalisation constraints}. These are simple constraints with a simple goal: \textbf{data duplication}. Data duplication is required because of the following mismatch: +\begin{enumerate} + \item the \rlpTxnMod{} module extracts and exposes transaction data \emph{vertically} i.e. in column form; + \item the \hubMod{} module consumes transaction data \emph{horizontally} i.e. in row form. +\end{enumerate} +\begin{center} + \boxed{\text{The constraints below assume that } \locAbs_{i} \neq \locAbs_{i - 1}.} +\end{center} +\begin{description} + \item[\underline{Setting phase numbers:}] + we impose that + \[ + \left\{\begin{array}{lcl} + \phaseNumRlpTxn_{i + 0 } & = & \phaseRlpPrefixValue \\ + \phaseNumRlpTxn_{i + 1 } & = & \phaseToValue \\ + \phaseNumRlpTxn_{i + 2 } & = & \phaseNonceValue \\ + \phaseNumRlpTxn_{i + 3 } & = & \phaseValueValue \\ + \phaseNumRlpTxn_{i + 4 } & = & \phaseDataValue \\ + \phaseNumRlpTxn_{i + 5 } & = & \phaseGasLimitValue \\ + \multicolumn{3}{l}{\If \txIsLegacy_{i} = 1 ~ \Then \phaseNumRlpTxn_{i + 6} = \phaseGasPriceValue} \\ + \multicolumn{3}{l}{\If \txIsAccessSet_{i} = 1 ~ \Then + \begin{cases} + \phaseNumRlpTxn_{i + 6} = \phaseGasPriceValue \\ + \phaseNumRlpTxn_{i + 7} = \phaseAccessListValue \\ + \end{cases}} \\ + \multicolumn{3}{l}{\If \txIsTypeTwo_{i} = 1 ~ \Then + \begin{cases} + \phaseNumRlpTxn_{i + 6} = \phaseMaxFeePerGasValue \\ + \phaseNumRlpTxn_{i + 7} = \phaseAccessListValue \\ + \end{cases}} \\ + \end{array}\right. + \] + \item[\underline{Horizontalization:}] + we impose that + \begin{description} + \item[Generalities:] + we impose that + \[ + \left\{ \begin{array}{lcl} + \locTypeSum _{i} & = & \locTxType \\ + \txNonce _{i} & = & \locNonce \\ + \txIsDeployment _{i} & = & \locIsDep \\ + \txValue _{i} & = & \locValue \\ + \txGasLimit _{i} & = & \locGasLimit \\ + \txCallDataSize _{i} & = & \locDataSize \cdot (1 - \locIsDep) \\ + \txInitCodeSize _{i} & = & \locDataSize \cdot \locIsDep \\ + \end{array} \right. + \] + where we set + \[ + \locTypeSum_{i} + \define + 0 \cdot \txIsLegacy _{i} + 1 \cdot \txIsAccessSet_{i} + 2 \cdot \txIsTypeTwo_{i} + \] + \saNote{} The above implements, in effect, + \begin{enumerate} + \item \If $\txIsDeployment_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \txCallDataSize_{i} & = & \locDataSize \\ + \txInitCodeSize_{i} & = & 0 \\ + \end{array} \right. + \] + \item \If $\txIsDeployment_{i} = 1$ \Then + \[ + \left\{ \begin{array}{lcl} + \txCallDataSize_{i} & = & 0 \\ + \txInitCodeSize_{i} & = & \locDataSize \\ + \end{array} \right. + \] + \end{enumerate} + \item[Transaction target address:] + \If $\txIsDeployment_{i} = 0$ \Then we impose + \[ + \left\{ \begin{array}{lcl} + \txTo_{i}\high & = & \locToAddrHi \\ + \txTo_{i}\low & = & \locToAddrLo \\ + \end{array} \right. + \] + \saNote{} + The above constrains $\txTo_{i}\high$ and $\txTo_{i}\low$ only when the transaction is a message call. + When the transaction is a deployment the \zkEvm{} retrieves \txTo{} by other means. + \end{description} + \item[\underline{Optional vanishing constraints}] + the vanishing constraints below are optional in the sense that corresponding fields are never touched by the constraints: + \[ + \left\{\begin{array}{lclr} + \outgoingDataHi_{i} & = & \zero & (\trash) \vspace{1mm} \\ + \outgoingDataHi_{i + 2} & = & \zero & (\trash) \vspace{1mm} \\ + \outgoingDataHi_{i + 5} & = & \zero & (\trash) \vspace{1mm} \\ + \multicolumn{3}{l}{% + \If \txIsTypeTwo_{i} = 0 ~ \Then \outgoingDataHi_{i + 6} = 0} & (\trash) \\ + \end{array}\right. + \] + \saNote{} There are no constraints on the additional row for the last transaction of a block for those columns. + % \item \If $\txIsTypeTwo_{i} = 0$) \Then + % \( + % \txGasPrice_{i} = \outgoingData_{i + 8} + % \) + % \item \If $\txIsTypeTwo_{i} = 1$) \Then + % \[ + % \txGasPrice_{i} = \ob{TODO} + % \] +\end{description} diff --git a/txn_data/horizontalization_rlp_txnrcpt.tex b/txn_data/horizontalization_rlp_txnrcpt.tex new file mode 100644 index 0000000..31bc579 --- /dev/null +++ b/txn_data/horizontalization_rlp_txnrcpt.tex @@ -0,0 +1,26 @@ +The present section describes \textbf{verticalisation constraints}. These are simple constraints with a simple goal: \textbf{data duplication}. Data duplication is required because of the following mismatch: +\begin{enumerate} + \item the \rlpTxnRcptMod{} module extracts and exposes transaction data \emph{vertically} i.e. in column form; + \item the \hubMod{} module consumes transaction data \emph{horizontally} i.e. in row form. +\end{enumerate} +\begin{center} + \boxed{\text{The constraints below assume that } \locAbs_{i} \neq \locAbs_{i - 1}.} +\end{center} +\begin{enumerate} + \item We impose phase numbers: + \[ + \left\{\begin{array}{lcl} + \phaseNumRlpTxnRcpt_{i + 0 } & = & \subPhaseIdType \\ + \phaseNumRlpTxnRcpt_{i + 1 } & = & \subPhaseIdStatusCode \\ + \phaseNumRlpTxnRcpt_{i + 2 } & = & \subPhaseIdCumulGas \\ + \end{array}\right. + \] + \item Some of the vertical data is converted to horizontal data: + \[ + \left\{\begin{array}{lcl} + \outgoingTxrcpt_{i + 0 } & = & \locTxType_{i} \\ + \outgoingTxrcpt_{i + 1 } & = & \txStatusCode_{i} \\ + \outgoingTxrcpt_{i + 2 } & = & \txCumulativeConsumedGas_{i} \\ + \end{array}\right. + \] +\end{enumerate} diff --git a/txn_data/img/rlp_rom_hub_lookups.png b/txn_data/img/rlp_rom_hub_lookups.png new file mode 100644 index 0000000..3c72872 Binary files /dev/null and b/txn_data/img/rlp_rom_hub_lookups.png differ diff --git a/txn_data/img/rlp_rom_hub_lookups.svg b/txn_data/img/rlp_rom_hub_lookups.svg new file mode 100644 index 0000000..21c1c82 --- /dev/null +++ b/txn_data/img/rlp_rom_hub_lookups.svg @@ -0,0 +1,485 @@ + + + + + + + + + + + + + + + + + + + + + + + + + tx/data + + + hub + + + + rom + + + rom/lex + + + + tx/rlp + + + + + + + + + + 2 + + + + 3 + + + + + + 5 + + + + + + + 6 + + + + + + 4 + + + + rlp/addr + + + + + + 1 + + + + + + wcp + + + + + 0 + + + + diff --git a/txn_data/intro.tex b/txn_data/intro.tex new file mode 100644 index 0000000..a6dfd82 --- /dev/null +++ b/txn_data/intro.tex @@ -0,0 +1,26 @@ +The \textbf{transaction data} module \txnDataMod{} is overall a simple module which serves several important and essentially independent functions. +For one it is the \textbf{main entry point for transaction data} contained in the \rlpTxnMod{} module into the ``execution environment" which is the \hubMod{} module. +Direct, un-intermediated, communication between these modules is awkward (if not impossible.) +Indeed the \rlpTxnMod{} module provides transaction data \emph{in column form} while the \hubMod{} module accepts transaction data \emph{in row form}. +The present module thus performs a simple data reformatting step ``\textbf{horizontalization}'', see section~(\ref{txn_data: constraints: horizontalization rlpTxn}). + +The \txnDataMod{} also performs simple computations which occur before transaction execution proper. +These include computing the upfront gas cost of transaction, ensuring that the gas limit covers that cost and ensuring that the underlying account has sufficient balance to cover both for gas and value transfer. +It also computes the effective gas price (for \textbf{type 2} transactions) and the effective ``fee rate'' (i.e. the rate at which the \inst{COINBASE} address collects fees.) + +It is also responsible for constructing the $\ABSTXNUM$ which other modules, in particular the \hubMod{}, rely on (typically under the moniker \absTxNum{}.) +This number serves as a unique identifier for the transactions found within a conflated batch. + +The present module also collects select execution data, in particular as seen at the end of transaction processing. +This includes e.g. (and using notations from the \cite{EYP}): +\begin{enumerate} + \item leftover gas $g'$, + \item total gas refunds $A_\text{r}'$ + \item refundable gas \( \displaystyle g^* \equiv g' + \min\Big\{\Big\lfloor\frac{T_\text{g} - g'}2\Big\rfloor, A_\text{r}'\Big\} \) + \item status code $\Upsilon^z(\bm{\sigma}, T)$, + \item cumulative gas consumption of the batch of transactions up to this point $\Upsilon^u(\bm{\sigma}, T)$, +\end{enumerate} +The present module also serves the \txRequiresEvmExecution{} and \txCopyTxcd{} bits to the \hubMod{} module. +The former is established in cooperation between the two modules while the second is deduced from the first in the present module. + +\saNote{} Refunds are those of the \textsc{London} release of the \evm{}. diff --git a/txn_data/lookups.md b/txn_data/lookups.md new file mode 100644 index 0000000..e7af5e2 --- /dev/null +++ b/txn_data/lookups.md @@ -0,0 +1,275 @@ +What follows are some lookup arguments that we will have to introduce post July 11. + +- [Transaction data fields justification](#transaction-data-fields-justification) + - [✨ TX\_RLP ↪ TX\_DATA ✨](#-tx_rlp--tx_data-) + - [Purpose](#purpose) + - [Lookup](#lookup) + - [✨ TX\_DATA ↪ TX\_RLP ✨](#-tx_data--tx_rlp-) + - [Purpose](#purpose-1) + - [Data duplication](#data-duplication) + - [Purpose](#purpose-2) +- [Transaction init code justification](#transaction-init-code-justification) + - [✨ TX\_DATA ↪ ROM ✨](#-tx_data--rom-) + - [Purpose](#purpose-3) + - [Lookup](#lookup-1) + - [✨ ROM ↪ TX\_RLP ✨](#-rom--tx_rlp-) + - [Purpose](#purpose-4) + - [Lookup](#lookup-2) +- [Deployment / CREATE / CREATE2 address justification](#deployment--create--create2-address-justification) + - [✨ HUB ↪ ADDR\_RLP ✨](#-hub--addr_rlp-) + - [Purpose](#purpose-5) + - [Lookup](#lookup-3) +- [Signature justification](#signature-justification) + - [✨ TX\_DATA signature verification ✨](#-tx_data-signature-verification-) + - [Purpose](#purpose-6) +- [Prewarmed addresses justification](#prewarmed-addresses-justification) + - [Purpose](#purpose-7) + - [✨ HUB ↪ TX\_RLP ✨](#-hub--tx_rlp-) + - [✨ TX\_RLP ↪ HUB ✨](#-tx_rlp--hub-) +- [Prewarmed \[address, storage keys\] pairs justification](#prewarmed-address-storage-keys-pairs-justification) + - [Purpose](#purpose-8) + - [✨ HUB ↪ TX\_RLP ✨](#-hub--tx_rlp--1) + - [✨ TX\_RLP ↪ HUB ✨](#-tx_rlp--hub--1) +- [Some consequences](#some-consequences) + + +# Transaction data fields justification + +## ✨ TX_RLP ↪ TX_DATA ✨ + +### Purpose + +We need to make sure that (1) all transactions are dealt with, (2) no phantom transactions are carried out and (3) the data written in the TX_DATA module coincides with that encoded in the RLP. These 3 tasks aren't all done with the present lookup, rather through a bidirectional lookup arguments. + +### Lookup + +We perform the following lookup: +- tx_rlp.ABS_TX_NUM ↪ tx_data.ABS_TX_NUM. + +**Note.** The above makes sure of the first point: all transactions are accounted for. + +## ✨ TX_DATA ↪ TX_RLP ✨ + +### Purpose + +The above took care of point (1). What comes now takes care of points (2) and (3): data coherence and absence of phantom transactions. + +### Data duplication + +In order to do a single lookup we stack the data from the TX_DATA module (which was designed to occupy a single row per transaction) vertically, too. +- we duplicate the relevant values of TX_DATA as many times as required by the transaction type +- we introduce a PHASE# column to +- we introduce a VAL_HI / VAL_LO column pair into which we extract the value associated with the PHASE# + - TX_TYPE + - NONCE + - IS_DEP + - (1 - IS_DEP) * [ TO_HI, TO_LO ] + - VALUE + - EFFECTIVE_GAS_PRICE (for type 0 & 1) + - MAX_FEE (for type 2) + - MAX_PRIORITY_FEE (for type 2) + - DATASIZE + - DATACOST + - NUM_PREWARM_ADDR (for type 1 & 2) + - NUM_PREWARM_KEYS (for type 1 & 2) + - SIGNATURE fields + +**Note.** This will allow us to perform the requisite computations (sufficient gas + for type 2 computation of the effective gas price). + +### Purpose + +The lookup will take as inputs the following: +- source columns + - tx_data.ABS_TX_NUM + - tx_data.PHASE# + - tx_data.VAL_HI + - tx_data.VAL_LO +- target columns + - tx_rlp.ABS_TX_NUM + - $\sum_i i\cdot$ tx_rlp.PHASE[i] + - tx_rlp.VAL_HI + - tx_rlp.VAL_LO + +**Note.** This requires us to introduce two new data columns tx_rlp.VAL_HI, tx_rlp.VAL_LO which will be used to store values that appear in the inputs / ... columns of TX_RLP. + +# Transaction init code justification + +## ✨ TX_DATA ↪ ROM ✨ + +### Purpose + +We need to make sure that the call data of deployment transactions (which is the associated initialization code) is in the ROM. As such we will need an extra bit in the ROM to signal the bytecodes that are transaction provided initialization codes and a column that indicates the transaction number. + +### Lookup + +We perform the following lookup: +- selector: IS_DEP * [DATASIZE != 0] +- source columns: + - tx_data.ABS_TX_NUM + - tx_data.TO_HI + - tx_data.TO_LO + - tx_data.DATASIZE +- target columns: + - rom.ABS_TX_NUM + - rom.ADDRESS_HI + - rom.ADDRESS_LO + - rom.CODESIZE + + +## ✨ ROM ↪ TX_RLP ✨ + +### Purpose + +We need to make sure that the call data of deployment transactions (which is the associated initialization code) is in the ROM. As such we will need: +- an extra bit, say IS_TX_INIT_CODE, in the ROM to signal transaction provided initialization code +- a column indicating the transaction number (along rows where the IS_TX_INIT_CODE = 1.) + +### Lookup + +We perform the following lookup: +- selector: IS_TX_INIT_CODE +- source columns: + - rom.ABS_TX_NUM + - rom.LIMB + - rom.INDEX + - rom.IS_TX_INIT_CODE +- target columns (where we set φ = tx_rlp.PHASE_[DATA] the phase flag for the data phase): + - tx_rlp.ABS_TX_NUM * φ + - tx_rlp.LIMB * φ + - tx_rlp.INDEX * φ + - φ + +# Deployment / CREATE / CREATE2 address justification + +## ✨ HUB ↪ ADDR_RLP ✨ + +### Purpose + +We need to justify the TO_ADDRESS for deployments: either deployment transactions or CREATE instructions. or so and select the non-updated nonce, creator address and created address values which are found on neighboring rows. This lookup will justify + +### Lookup + +- selector: we use PEEK_ACCOUNT * IS_DEP +- source columns: + - yet to be properly selected, must take a look at the hub spec +- target columns: + - addr_rlp.CREATOR_ADDR_HI + - addr_:w + rlp.CREATOR_ADDR_LO + - addr_rlp.NONCE + - addr_rlp.CREATED_ADDR_HI + - addr_rlp.CREATED_ADDR_LO + - addr_rlp.SALT_HI + - addr_rlp.SALT_LO + - addr_rlp.INST + - addr_rlp.HUB_STAMP + +**Note.** The purpose of the HUB_STAMP column is to allow us to retrieve the following columns + - kec.INITCODE_HASH_HI + - kec.INITCODE_HASH_LO + +from the KECCAK_INFO module (or whatever we will end up calling it.) + +# Signature justification + +## ✨ TX_DATA signature verification ✨ + +### Purpose + +We need to make the signature fields of the transaction available for the ECDSA module. Don't know how we will do this. There is the option to just insert these values into the EC_DATA module. I don't like that solution at all. + + +# Prewarmed addresses justification + +## Purpose + +Simple bilateral lookup to prove the prewarming of all addresses for a transaction. + +**Note.** We have a bit of an issue here: it is conceivable that someone would provide addresses to prewarm to a transaction that requires no EVM execution. There are two solutions to this: +- either we propagate the information (requires EVM execution or not) upwards from the HUB to the TX_DATA module and from there to the TX_RLP module; in this case we can have a transaction constant bit in the TX_RLP which we can use to select only those addresses / storage keys to include in the prewarming phase of the HUB that correspond to transactions requiring actual EVM execution +- either we modify the heartbeat to add phony PREWMARING phases for transactions requiring no EVM execution. + +The first solution is the simplest. We will opt for that one 🏅. + +## ✨ HUB ↪ TX_RLP ✨ + +- selector: PREWARM * PEEK_ACCOUNT +- source columns: + - hub.ABS_TX_NUM + - hub.acc/ADDR_HI + - hub.acc/ADDR_LO + - 1 +- target columns: + - tx_rlp.ABS_TX_NUM + - tx_rlp.ADDR_HI + - tx_rlp.ADDR_LO + - tx_rlp.PHASE[ACCESS_SET] + +## ✨ TX_RLP ↪ HUB ✨ + +- selector: tx_rlp.PHASE[ACCESS_SET] * tx_rlp.REQUIRES_EVM_EXECUTION +- source columns: + - tx_rlp.ABS_TX_NUM + - tx_rlp.ADDR_HI + - tx_rlp.ADDR_LO + - 1 +- target columns (setting wa := hub.PREWARM): + - hub.ABS_TX_NUM * wa + - hub.acc/ADDR_HI * wa + - hub.acc/ADDR_LO * wa + - wa + +# Prewarmed [address, storage keys] pairs justification + +## Purpose + +Simple bilateral lookup to prove the prewarming of all [addresses, storage key] pairs a transaction. + +## ✨ HUB ↪ TX_RLP ✨ + +- selector: PREWARM * PEEK_STORAGE +- source columns: + - hub.ABS_TX_NUM + - hub.sto/ADDR_HI + - hub.sto/ADDR_LO + - hub.sto/SKEY_HI + - hub.sto/SKEY_LO + - 1 +- target columns: + - tx_rlp.ABS_TX_NUM + - tx_rlp.ADDR_HI + - tx_rlp.ADDR_LO + - tx_rlp.SKEY_HI + - tx_rlp.SKEY_LO + - tx_rlp.PHASE[ACCESS_SET] + +## ✨ TX_RLP ↪ HUB ✨ + +- selector: tx_rlp.PHASE[ACCESS_SET] * tx_rlp.REQUIRES_EVM_EXECUTION * [whatever selects for keys, DEPTH1 or DEPTH2 ?] +- source columns: + - tx_rlp.ABS_TX_NUM + - tx_rlp.ADDR_HI + - tx_rlp.ADDR_LO + - tx_rlp.SKEY_HI + - tx_rlp.SKEY_LO + - 1 +- target columns (setting ws := hub.PREWARM * PEEK_STORAGE): + - hub.ABS_TX_NUM * ws + - hub.acc/ADDR_HI * ws + - hub.acc/ADDR_LO * ws + - hub.sto/SKEY_HI * ws + - hub.sto/SKEY_LO * ws + - ws + +# Some consequences + +The TX_RLP and TX_DATA modules must be augmented slightly: +- TX_DATA: + - we need redundancy to reduce the number of lookups + - we need a REQURIES_EVM_EXECUTION binary column (which is justified in the hub) + - we should do the gas price computations (for Type 2 transactions) here +- TX_RLP: + - we require a transaction-constant binary column REQUIRES_EVM_EXECUTION which is justified in TX_DATA +- ROM: + - IS_TX_INIT_CODE + - ABS_TX_NUM \ No newline at end of file diff --git a/txn_data/lookups/_inputs.tex b/txn_data/lookups/_inputs.tex new file mode 100644 index 0000000..c578bba --- /dev/null +++ b/txn_data/lookups/_inputs.tex @@ -0,0 +1,8 @@ +\subsection{\txnDataMod{} $\hookrightarrow$ \wcpMod{} module} \label{txn_data: lookups: wcp} \input{lookups/into_wcp} +\subsection{\txnDataMod{} $\hookrightarrow$ \eucMod{} module} \label{txn_data: lookups: euc} \input{lookups/into_euc} +\subsection{\txnDataMod{} $\hookrightarrow$ \rlpTxnMod{} module} \label{txn_data: lookups: txn rlp} \input{lookups/into_rlp_txn} +\subsection{\txnDataMod{} $\hookrightarrow$ \romLexMod{} module} \label{txn_data: lookups: rom lex} \input{lookups/into_rom_lex} +\subsection{\txnDataMod{} $\hookrightarrow$ \rlpAddrMod{} module} \label{txn_data: lookups: addr rlp} \input{lookups/into_rlp_addr} +\subsection{\txnDataMod{} $\hookrightarrow$ \btcMod{} module} \label{txn_data: lookups: block data} \input{lookups/into_block_data} +\subsection{\txnDataMod{} $\hookrightarrow$ \rlpTxnRcptMod{} module} \label{txn_data: lookups: rlp txnrcpt} \input{lookups/into_rlp_txnrcpt} +\subsection{\txnDataMod{} $\hookrightarrow$ \hubMod{} module} \label{txn_data: lookups: into the hub} \input{lookups/into_hub} diff --git a/txn_data/lookups/hub_deprecated.tex b/txn_data/lookups/hub_deprecated.tex new file mode 100644 index 0000000..a49651d --- /dev/null +++ b/txn_data/lookups/hub_deprecated.tex @@ -0,0 +1,91 @@ +\def\lookupColumnsHubIntoTxnData{% + \item \locAbsMax{} + \item \locAbs{} + \item \block{} + \item $\txFrom\high$ + \item $\txFrom\low$ + \item $\txTo\high$ + \item $\txTo\low$ + \item $\txCoinbase\high$ + \item $\txCoinbase\low$ + \item \txGasLimit{} + \item \txInitialGas{} + \item \txLeftoverGas{} + \item $\txFinalRefundCounter{}$ + \item $\txEffectiveRefund$ + \item \txIsTypeTwo{} + \item \txBasefee{} + \item \txGasPrice{} + \item \txNonce{} + \item $\txValue$ + \item $\txInitialBalance$ + \item \txIsDeployment{} + \item \txCallDataSize{} + \item \txInitCodeSize{} + \item \txStatusCode{} + \item \txRequiresEvmExecution{} + \item[\vspace{\fill}] + \item[\vspace{\fill}] +} + +The purpose of the present lookup is to communicate relevant transaction information to the \hubMod{} module as well as extract some execution related information. The main points are that +(\emph{a}) +the \hubMod{} requires information during either the \textbf{transaction initialization} phase (if $\txRequiresEvmExecution \equiv 1$) or the \textbf{transaction skipping} phase (if $\txRequiresEvmExecution \equiv 0$); this information includes, but is not limited to, the transaction nonce, initial sender balance, transfer value, gas available for bytecode execution; it also includes the \txRequiresEvmExecution{} flag must all be confirmed and some execution context data must be set accordingly; +(\emph{b}) +certain opcodes require access to data contained in the present module (e.g. \inst{GASPRICE}, \inst{ORIGIN}, \dots), these data are retrieved using the current lookup which imports a dedicated transaction-row into the \hubMod{} module; +(\emph{c}) +transaction \textbf{finalization}: the left over gas and applicable refunds are returned to the sender, the coinbase address is paid in accordance with the valid \inst{GASPRICE} (and \inst{BASEFEE} for \textsc{eip1550} transactions), the transaction status code is confirmed etc \dots{} + +\begin{description} + \item[Source columns:] the source module is the \hubMod{} module; it uses the following \textbf{selector} column: + \[ + \col{sel} := \peekTransaction{} + \] + in other words we select for \textbf{transaction-rows}; its source columns are: + \begin{multicols}{3} + \begin{enumerate} + \lookupColumnsHubIntoTxnData{} % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[Target columns:] the target module is the present \txnDataMod{} module; it requires no selector; the required columns are + \begin{multicols}{3} + \begin{enumerate} + \lookupColumnsHubIntoTxnData{} % \item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + +\noindent We provide some context for this rather substantial lookup. Below are \emph{some} of the use-cases for the columns in the lookup above. Listing all use-cases would take us too far afield. Note that some columns have several use cases. +\begin{itemize} + \item + $\locAbsMax$, + $\locAbs$ and $\block$ + are used to identify the transaction in the \hubMod{} module; the batch number is used to initialize the transaction's batch number. + \item + $\txRequiresEvmExecution$, $\txInitialBalance$ are \emph{extracted} from the \hubMod{} module at the beginning of transaction processing; + $\txInitialBalance$ is the the sender account's balance before any modification is made to the account; it is used in the present module to vet \col{gas\_price} parameters for type 0 and type 1 transactions, \col{max\_fee\_per\_gas} for type 2 transactions and $\txValue$; + $\txRequiresEvmExecution$ is set in transaction initialization; the present module passes this information to the \rlpTxnMod{} module; it is used to filter out access sets in the lookup to the \hubMod{} module for transactions that \emph{don't} require \textsc{evm} execution; + \item + $\txFrom\high$, $\txFrom\low$, + $\txNonce$ and $\txValue$ + identify the sender account in transaction initialization, to check the sender account nonce \accNonce{} against the transaction nonce \txNonce{} and perform the initial sender balance update; is also used to initialize, for transactions requiring \textsc{evm} execution, the root execution context's \cnCallValue{}; + \item + $\txTo\high$ and $\txTo\low$ are used to load the recipient account at transaction start + is used to set a context variable declaring the root execution context + $\txInitialGas$ + $\txInitCodeSize$. + \item + $\txStatusCode$, + $\txLeftoverGas$, + $\txFinalRefundCounter$ and + $\txEffectiveRefund$ are \emph{read-off} in the transaction finalization phase ($\txFinl \equiv 1$); + \item + $\txFrom\high$, $\txFrom\low$, + $\txCoinbase\high$, $\txCoinbase\low$, + $\txGasPrice$, + $\txGasLimit{}$ and + $\txEffectiveRefund$ + (as well as $\txBasefee$ and $\txIsTypeTwo$) are \emph{used} in the transaction finalization phase to reimburse left over gas and pay the coinbase address appropriately. + \item + $\txCallDataSize$, $\txIsDeployment$, $\txValue$, $\txInitialGas$, $\txGasPrice$ are used to set context variables; +\end{itemize} diff --git a/txn_data/lookups/into_block_data.tex b/txn_data/lookups/into_block_data.tex new file mode 100644 index 0000000..6475730 --- /dev/null +++ b/txn_data/lookups/into_block_data.tex @@ -0,0 +1,29 @@ +Several columns are direct imports from the \btcMod{} module. +The present lookup justifies them: +\begin{description} + \item[\underline{Selector:}] none required; + \item[\underline{Source columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\relBlock$ + \item $\txCoinbase\high$ + \item $\txCoinbase\low$ + \item $\relTxMax$ + \item $\txBasefee$ + \item $\blockGasLimit$ + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\relBlock$ + \item $\coinbase\high$ + \item $\coinbase\low$ + \item $\relTxMax$ + \item $\basefee$ + \item $\blockGasLimit$ + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} diff --git a/txn_data/lookups/into_euc.tex b/txn_data/lookups/into_euc.tex new file mode 100644 index 0000000..b88cd2a --- /dev/null +++ b/txn_data/lookups/into_euc.tex @@ -0,0 +1,22 @@ +\begin{description} + \item[\underline{Selector:}] + we use $\col{euc\_selector} \define \eucFlag$ + \item[\underline{Source columns:}] --- + \begin{multicols}{4} + \begin{enumerate} + \item $1$ + \item $\argOneLo$ + \item $\argTwoLo$ + \item \res{} + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{4} + \begin{enumerate} + \item \done{} + \item \dividend{} + \item \divisor{} + \item \quotient{} + \end{enumerate} + \end{multicols} +\end{description} diff --git a/txn_data/lookups/into_hub.tex b/txn_data/lookups/into_hub.tex new file mode 100644 index 0000000..76ad57d --- /dev/null +++ b/txn_data/lookups/into_hub.tex @@ -0,0 +1,20 @@ +We impose a lookup into the \hubMod{} module. Its purpose is to enforce that the \hubMod{} module deal with \textbf{all} transactions from the block. The lookup is very simple: +\begin{description} + \item[Selector:] none required; + \item[Source columns:] + the source is the \txnDataMod{} and the source columns are + \begin{multicols}{2} + \begin{enumerate} + \item \locAbs{} + \item \block{} + \end{enumerate} + \end{multicols} + \item[Target columns:] + the target is the \txnDataMod{} and the target columns are + \begin{multicols}{2} + \begin{enumerate} + \item \locAbs{} + \item \block{} + \end{enumerate} + \end{multicols} +\end{description} diff --git a/txn_data/lookups/into_rlp_addr.tex b/txn_data/lookups/into_rlp_addr.tex new file mode 100644 index 0000000..1484619 --- /dev/null +++ b/txn_data/lookups/into_rlp_addr.tex @@ -0,0 +1,26 @@ +The present lookup connects the \txnDataMod{} module to the \rlpAddrMod{} module. It provides justification for deployment addresses. Deployment addresses need to be computed for all deployment transactions, regardless of whether they require \textsc{evm} execution or not: those that don't are automatically successful and lead to the creation of an account with nonzero nonce and potentially nonzero balance. The lookup relation is very simple: +\begin{description} + \item[\underline{Selector:}] $\col{sel} \define \txIsDeployment$ + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\txFrom\high$ + \item $\txFrom\low$ + \item $\txNonce$ + \item $\addressCreationRecipeConstantStd$ + \item $\txTo\high$ + \item $\txTo\low$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\addrHi$ + \item $\addrLo$ + \item $\nonce$ + \item $\rlpAddrInst$ + \item $\depAddr\high$ + \item $\depAddr\low$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/txn_data/lookups/into_rlp_txn.tex b/txn_data/lookups/into_rlp_txn.tex new file mode 100644 index 0000000..b7caf19 --- /dev/null +++ b/txn_data/lookups/into_rlp_txn.tex @@ -0,0 +1,27 @@ +The present lookup relation connects the \txnDataMod{} to the \rlpTxnMod{}. Its purpose is to extract the functional fields of the transaction. +\begin{description} + \item[\underline{Selector:}] none required + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\locAbsMax$ + \item $\locAbs$ + \item $\phaseNumRlpTxn$ + \item $\outgoingDataHi$ + \item $\outgoingDataLo$ + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\locAbsMax$ + \item $\locAbs$ + \item $\Phase$ + \item $\outgoingDataSymb\high$ + \item $\outgoingDataSymb\low$ + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/txn_data/lookups/into_rlp_txnrcpt.tex b/txn_data/lookups/into_rlp_txnrcpt.tex new file mode 100644 index 0000000..4f3b679 --- /dev/null +++ b/txn_data/lookups/into_rlp_txnrcpt.tex @@ -0,0 +1,22 @@ +The present lookup relation connects the \txnDataMod{} to the \rlpTxnRcptMod{}. Its purpose is to give to \rlpTxnRcptMod{} the $\col{TYPE}$ of the transaction, $\txCumulativeConsumedGas$ and teh $\txStatusCode$. +\begin{description} + \item[\underline{Selector:}] $\phaseNumRlpTxnRcpt_{i} \ne 0$ + \item[\underline{Source columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\locAbsMax_{i}$ + \item $\locAbs_{i}$ + \item $\phaseNumRlpTxnRcpt_{i}$ + \item $\outgoingTxrcpt_{i}$ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{2} + \begin{enumerate} + \item $\locAbsMax_{j}$ + \item $\locAbs_{j}$ + \item $\Phase_{j}$ + \item $\Input{1}_{j}$ + \end{enumerate} + \end{multicols} +\end{description} diff --git a/txn_data/lookups/into_rom_lex.tex b/txn_data/lookups/into_rom_lex.tex new file mode 100644 index 0000000..aad0307 --- /dev/null +++ b/txn_data/lookups/into_rom_lex.tex @@ -0,0 +1,35 @@ +The purpose of the present lookup argument is to connect deployment transactions (characterized by $\txIsDeployment \equiv 1$) with the \CFI{} identifying the associated initialization code. Such a connection must be drawn for any deployment which \emph{actually} requires \textsc{evm} execution. As such we set: +\begin{description} + \item[\underline{Selector:}] $\col{sel} := \txIsDeployment \cdot \big[ \txInitCodeSize \neq 0 \big]$ in other words + \[ + \begin{cases} + \If \txInitCodeSize_{i} = 0 ~ \Then \col{sel}_{i} = 0 \\ + \If \txInitCodeSize_{i} \neq 0 ~ \Then \col{sel}_{i} = \txIsDeployment_{i} \\ + \end{cases} + \] + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi$ + \item $\txInitCodeSize$ + \item $\txTo\high$ + \item $\txTo\low$ + \item 1 + \item 1 + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\cfi$ + \item $\codeSize$ + \item $\addr\high$ + \item $\addr\low$ + \item $\depNumber$ + \item $\depStatus$ + %\item[\vspace{\fill}] + \end{enumerate} + \end{multicols} +\end{description} + diff --git a/txn_data/lookups/into_wcp.tex b/txn_data/lookups/into_wcp.tex new file mode 100644 index 0000000..7e8fc35 --- /dev/null +++ b/txn_data/lookups/into_wcp.tex @@ -0,0 +1,39 @@ +The purpose of the present lookup argument is to delegate some of the gas and value comparisons to the \wcpMod{} module. These comprise, \textbf{for type 0, 1 and 2 transactions}: +(\emph{a}) ensuring the initial gas provided in the transaction is $\geq$ to the upfront gas cost of the transaction; +(\emph{b}) ensuring the account balance is sufficient to pay for the initial gas and value transferred; +(\emph{c}) computing $\left \lfloor \frac{T_\text{g} - g'}2 \right \rfloor$ +(\emph{d}) computing $\min \Big \{ \left \lfloor \frac{T_\text{g} - g'}2 \right \rfloor, A'_\text{r} \Big \}$. For \textbf{type 2 transactions} one must add to that list the following: +\begin{enumerate} + \item initial gas consumption vs initial gas + \item initial gas times gas price vs initial balance +\end{enumerate} +The lookup is structured as follows: +\begin{description} + \item[\underline{Selector:}] we use $\col{wcp\_selector} \define \wcpFlag$ + \item[\underline{Source columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $0$ + \item $\argOneLo$ + \item $0$ + \item $\argTwoLo$ + \item $\res $ + \item $\INST $ + \end{enumerate} + \end{multicols} + \item[\underline{Target columns:}] --- + \begin{multicols}{3} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\resLo$ + \item $\INST$ + \end{enumerate} + \end{multicols} +\end{description} +% \saNote{} The computation of $\col{half} := \left \lfloor \frac{T_\text{g} - g'}2 \right \rfloor$ can be carried out in the \wcpMod{} module as follows: the present module proposes two values \col{half} and $\epsilon$ which satisfy the following: $\epsilon \in \{ 0, 1 \}$, $\col{half} \leq T_\text{g} - g'$ and $T_\text{g} - g' = 2 \cdot \col{half} + \epsilon$. This trick works for division by 2 since $2$ divdes $p + 1$ where $p$ is the prime modulus used in the arithmetization. It may not work for other euclidean divisions. + + +\saNote{} We perform the initial comparison against the account balance in the present module rather than in the \hubMod{} for the following reason: for type 2 transactions the value deducted from the account balance isn't the minimum value which must be owned by the account prior to executing the transaction. The former is computed using the effective gas price of the transaction, the latter using the max fee of the transaction. diff --git a/txn_data/lua/computations.lua.tex b/txn_data/lua/computations.lua.tex new file mode 100644 index 0000000..379060d --- /dev/null +++ b/txn_data/lua/computations.lua.tex @@ -0,0 +1,137 @@ + +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +% insert relevant phase numbers ⟦PHASE_TXN_RLP_bla_bla⟧ + +\begin{document} +\begin{verbatim} + + ██████\ ██\ ██\ ██\ +██ __██\ ██ | ██ | \__| +██ / \__| ██████\ ██████\████\ ██████\ ██\ ██\ ██████\ ██████\ ██████\ ██\ ██████\ ███████\ ███████\ +██ | ██ __██\ ██ _██ _██\ ██ __██\ ██ | ██ |\_██ _| \____██\\_██ _| ██ |██ __██\ ██ __██\ ██ _____| +██ | ██ / ██ |██ / ██ / ██ |██ / ██ |██ | ██ | ██ | ███████ | ██ | ██ |██ / ██ |██ | ██ |\██████\ +██ | ██\ ██ | ██ |██ | ██ | ██ |██ | ██ |██ | ██ | ██ |██\ ██ __██ | ██ |██\ ██ |██ | ██ |██ | ██ | \____██\ +\██████ |\██████ |██ | ██ | ██ |███████ |\██████ | \████ |\███████ | \████ |██ |\██████ |██ | ██ |███████ | + \______/ \______/ \__| \__| \__|██ ____/ \______/ \____/ \_______| \____/ \__| \______/ \__| \__|\_______/ + ██ | + ██ | + \__| + + ______ ____ + /_ __/_ ______ ___ / __ \ + / / / / / / __ \/ _ \ / / / / + / / / /_/ / /_/ / __/ / /_/ / + /_/ \__, / .___/\___/ \____/ + /____/_/ + + +|-------+----+--------+--------+--------+--------| +| ABS | CT | Action | TYPE_0 | TYPE_1 | TYPE_2 | +|:-----:+:--:+-------:+:------:+:------:+:------:| +|-------+----+--------+--------+--------+--------| +| t - 1 | ⋯ | | ⋯ | ⋯ | ⋯ | +|-------+----+--------+--------+--------+--------| +|-------+----+--------+--------+--------+--------| +| t | 0 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 1 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 2 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 3 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 4 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 5 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 6 | | 1 | | | +|-------+----+--------+--------+--------+--------| +|-------+----+--------+--------+--------+--------| +| t + 1 | ⋯ | | ⋯ | ⋯ | ⋯ | + + + + ______ ___ + /_ __/_ ______ ___ < / + / / / / / / __ \/ _ \ / / + / / / /_/ / /_/ / __/ / / + /_/ \__, / .___/\___/ /_/ + /____/_/ + + +|-------+----+--------+--------+--------+--------| +| ABS | CT | Action | TYPE_0 | TYPE_1 | TYPE_2 | +|:-----:+:--:+-------:+:------:+:------:+:------:| +|-------+----+--------+--------+--------+--------| +| t - 1 | ⋯ | | ⋯ | ⋯ | ⋯ | +|-------+----+--------+--------+--------+--------| +|-------+----+--------+--------+--------+--------| +| t | 0 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 1 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 2 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 3 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 4 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 5 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 6 | | 1 | | | +|-------+----+--------+--------+--------+--------| +|-------+----+--------+--------+--------+--------| +| t + 1 | ⋯ | | ⋯ | ⋯ | ⋯ | + + + + ______ ___ + /_ __/_ ______ ___ |__ \ + / / / / / / __ \/ _ \ __/ / + / / / /_/ / /_/ / __/ / __/ + /_/ \__, / .___/\___/ /____/ + /____/_/ + + +|-------+----+--------+--------+--------+--------| +| ABS | CT | Action | TYPE_0 | TYPE_1 | TYPE_2 | +|:-----:+:--:+-------:+:------:+:------:+:------:| +|-------+----+--------+--------+--------+--------| +| t - 1 | ⋯ | | ⋯ | ⋯ | ⋯ | +|-------+----+--------+--------+--------+--------| +|-------+----+--------+--------+--------+--------| +| t | 0 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 1 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 2 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 3 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 4 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 5 | | 1 | | | +|-------+----+--------+--------+--------+--------| +| t | 6 | | 1 | | | +|-------+----+--------+--------+--------+--------| +|-------+----+--------+--------+--------+--------| +| t + 1 | ⋯ | | ⋯ | ⋯ | ⋯ | + +\end{verbatim} +\end{document} diff --git a/txn_data/lua/layout.lua.tex b/txn_data/lua/layout.lua.tex new file mode 100644 index 0000000..bd9bea0 --- /dev/null +++ b/txn_data/lua/layout.lua.tex @@ -0,0 +1,150 @@ +% !TeX TS-program = lualatex +\documentclass[varwidth=\maxdimen,margin=0.5cm,multi={verbatim}]{standalone} + +\usepackage{../../pkg/draculatheme} + +\usepackage{fontspec} +\directlua{luaotfload.add_fallback + ("emojifallback", + { + "NotoColorEmoji:mode=harf;" + } + )} + +\setmonofont{JetBrains Mono NF Regular}[ + RawFeature={fallback=emojifallback} +] + +\usepackage{../../pkg/draculatheme} + +\begin{document} +\begin{verbatim} + +███████\ ██\ +██ __██\ ██ | +██ | ██ | ██████\ ██████\ ██████\ +██ | ██ | \____██\\_██ _| \____██\ +██ | ██ | ███████ | ██ | ███████ | +██ | ██ |██ __██ | ██ |██\ ██ __██ | +███████ |\███████ | \████ |\███████ | +\_______/ \_______| \____/ \_______| + +██\ ██\ +██ | ██ | +██ | ██████\ ██\ ██\ ██████\ ██\ ██\ ██████\ +██ | \____██\ ██ | ██ |██ __██\ ██ | ██ |\_██ _| +██ | ███████ |██ | ██ |██ / ██ |██ | ██ | ██ | +██ |██ __██ |██ | ██ |██ | ██ |██ | ██ | ██ |██\ +██ |\███████ |\███████ |\██████ |\██████ | \████ | +\__| \_______| \____██ | \______/ \______/ \____/ + ██\ ██ | + \██████ | + \______/ + + + ______ ____ + /_ __/_ ______ ___ / __ \ + / / / / / / __ \/ _ \ / / / / + / / / /_/ / /_/ / __/ / /_/ / + /_/ \__, / .___/\___/ \____/ + /____/_/ + + +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| ABS | CT | PHASE_RLP_TXN | OUTGOING_HI | OUTGOING_LO | TYPE_0 | TYPE_1 | TYPE_2 | +|:-----:+:--:+:-------------:+:--------------------:+:--------------------:+:------:+:------:+:------:| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t - 1 | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 0 | | | tx_type | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 1 | | [is_dep ? 0 : to_hi] | [is_dep ? 0 : to_lo] | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 2 | | | nonce | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 3 | | is_dep | value | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 4 | | data_cost | data_size | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 5 | | | gas_limit | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 6 | | | gas_price | 1 | | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t + 1 | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | + + + + ______ ___ + /_ __/_ ______ ___ < / + / / / / / / __ \/ _ \ / / + / / / /_/ / /_/ / __/ / / + /_/ \__, / .___/\___/ /_/ + /____/_/ + + +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| ABS | CT | PHASE_RLP_TXN | OUTGOING_HI | OUTGOING_LO | TYPE_0 | TYPE_1 | TYPE_2 | +|:-----:+:--:+:-------------:+:--------------------:+:--------------------:+:------:+:------:+:------:| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t - 1 | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 0 | | | tx_type | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 1 | | [is_dep ? 0 : to_hi] | [is_dep ? 0 : to_lo] | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 2 | | | nonce | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 3 | | is_dep | value | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 4 | | data_cost | data_size | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 5 | | | gas_limit | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 6 | | | gas_price | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 7 | | num_keys | num_addr | | 1 | | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t + 1 | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | + + + + ______ ___ + /_ __/_ ______ ___ |__ \ + / / / / / / __ \/ _ \ __/ / + / / / /_/ / /_/ / __/ / __/ + /_/ \__, / .___/\___/ /____/ + /____/_/ + + +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| ABS | CT | PHASE_RLP_TXN | OUTGOING_HI | OUTGOING_LO | TYPE_0 | TYPE_1 | TYPE_2 | +|:-----:+:--:+:-------------:+:--------------------:+:--------------------:+:------:+:------:+:------:| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t - 1 | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 0 | | | tx_type | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 1 | | [is_dep ? 0 : to_hi] | [is_dep ? 0 : to_lo] | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 2 | | | nonce | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 3 | | is_dep | value | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 4 | | data_cost | data_size | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 5 | | | gas_limit | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 6 | | max_priority_fee | max_fee | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t | 7 | | num_keys | num_addr | | | 1 | +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +|-------+----+---------------+----------------------+----------------------+--------+--------+--------| +| t + 1 | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | ⋯ | + +\end{verbatim} +\end{document} diff --git a/txn_data/representation.tex b/txn_data/representation.tex new file mode 100644 index 0000000..a36087b --- /dev/null +++ b/txn_data/representation.tex @@ -0,0 +1,70 @@ +\includepdf[fitpaper=true, pages={1}]{lua/layout.pdf} + +% The present section shows the expected layout of data. These layouts explain the aliases from section~(\ref{txData: constraints: graphical rep data}) and the verticalization constraints from section~\ref{txData: constraints: verticalization}. \saNote{} We use the shorthand \locAbs{} for \locAbs{} to narrow the first column down. +% \begin{figure}[h!] +% \renewcommand{\arraystretch}{1.3} +% \[ +% \begin{array}{|c|l|r|r|r|c|c|c|} +% \hline +% \locAbs & \ct & \phaseNumRlpTxn & \outgoingDataHi & \outgoingDataLo & \txIsLegacy & \txIsAccessSet & \txIsTypeTwo \\ \hline +% \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline +% \colm{t-1} & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline +% \col{t} & 0 & 0 & \fillCell & \locTxType & \one & \zero & \zero \\ \hline +% \col{t} & 1 & 7 & \locToAddrHi & \locToAddrLo & \one & \zero & \zero \\ \hline +% \col{t} & 2 & 2 & \fillCell & \locNonce & \one & \zero & \zero \\ \hline +% \col{t} & 3 & 8 & \locIsDep & \locValue & \one & \zero & \zero \\ \hline +% \col{t} & 4 & 9 & \locDataCost & \locDataSize & \one & \zero & \zero \\ \hline +% \col{t} & 5 & 6 & \fillCell & \locGasLimit & \one & \zero & \zero \\ \hline +% \col{t} & 6 & 3 & \fillCell & \locGasPrice & \one & \zero & \zero \\ \hline +% \colm{t+1} & 0 & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline +% \end{array} +% \] +% \caption{Data layout for type $0$ transactions} +% \label{fig: type 0} +% \end{figure} +% +% \begin{figure}[h!] +% \[ +% \renewcommand{\arraystretch}{1.3} +% \begin{array}{|c|l|r|r|r|c|c|c|} +% \hline +% \locAbs & \ct & \phaseNumRlpTxn & \outgoingDataHi & \outgoingDataLo & \txIsLegacy & \txIsAccessSet & \txIsTypeTwo \\ \hline +% \vdots & \vdots & \cdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline +% \colm{t-1} & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline +% \col{t} & 0 & 0 & \fillCell & \locTxType & \zero & \one & \zero \\ \hline +% \col{t} & 1 & 7 & \locToAddrHi & \locToAddrLo & \zero & \one & \zero \\ \hline +% \col{t} & 2 & 2 & \fillCell & \locNonce & \zero & \one & \zero \\ \hline +% \col{t} & 3 & 8 & \locIsDep & \locValue & \zero & \one & \zero \\ \hline +% \col{t} & 4 & 9 & \locDataCost & \locDataSize & \zero & \one & \zero \\ \hline +% \col{t} & 5 & 6 & \fillCell & \locGasLimit & \zero & \one & \zero \\ \hline +% \col{t} & 6 & 3 & \fillCell & \locGasPrice & \zero & \one & \zero \\ \hline +% \col{t} & 7 & 10 & \locNumKeys & \locNumAddr & \zero & \one & \zero \\ \hline +% \colm{t+1} & 0 & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline +% \end{array} +% \] +% \caption{Data layout for type $1$ transactions} +% \label{fig: type 1} +% \end{figure} +% +% \begin{figure}[h!] +% \[ +% \renewcommand{\arraystretch}{1.3} +% \begin{array}{|c|l|r|r|r|c|c|c|} +% \hline +% \locAbs & \ct & \phaseNumRlpTxn & \outgoingDataHi & \outgoingDataLo & \txIsLegacy & \txIsAccessSet & \txIsTypeTwo \\ \hline +% \vdots & \vdots & \cdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \hline +% \colm{t-1} & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline +% \col{t} & 0 & 0 & \fillCell & \locTxType & \zero & \zero & \one \\ \hline +% \col{t} & 1 & 7 & \locToAddrHi & \locToAddrLo & \zero & \zero & \one \\ \hline +% \col{t} & 2 & 2 & \fillCell & \locNonce & \zero & \zero & \one \\ \hline +% \col{t} & 3 & 8 & \locIsDep & \locValue & \zero & \zero & \one \\ \hline +% \col{t} & 4 & 9 & \locDataCost & \locDataSize & \zero & \zero & \one \\ \hline +% \col{t} & 5 & 6 & \fillCell & \locGasLimit & \zero & \zero & \one \\ \hline +% \col{t} & 6 & 5 & \locMaxPriorityFee & \locMaxFee & \zero & \zero & \one \\ \hline +% \col{t} & 7 & 10 & \locNumKeys & \locNumAddr & \zero & \zero & \one \\ \hline +% \colm{t+1} & 0 & \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline +% \end{array} +% \] +% \caption{Data layout for type $2$ transactions} +% \label{fig: type 2} +% \end{figure} diff --git a/txn_data/setting.tex b/txn_data/setting.tex new file mode 100644 index 0000000..f80f0d7 --- /dev/null +++ b/txn_data/setting.tex @@ -0,0 +1,50 @@ +\begin{center} + \boxed{\text{The constraints below assume that } \locAbs_{i} \neq \locAbs_{i - 1}.} +\end{center} +With computations out of the way we move on to set certain variables. +\begin{description} + \item[\underline{Setting the \txInitialGas:}] + we impose that + \begin{enumerate} + \item \If $\txIsLegacy _{i} = 1$ \Then + \[ \txInitialGas _{i} = \locGasLimit - \locLegacyUpfrontGasCost \] + \item \If $\txIsAccessSet _{i} + \txIsTypeTwo _{i} = 1$ \Then + \[ \txInitialGas _{i} = \locGasLimit - \locAccessUpfrontGasCost \] + \end{enumerate} + \item[\underline{Setting the \txGasPrice:}] + we impose that + \begin{enumerate} + \item \If $\txIsLegacy _{i} + \txIsAccessSet _{i} = 1$ \Then $\txGasPrice _{i} = \locGasPrice$ + \item \If $\txIsTypeTwo_{i} = 1$ \Then + \begin{enumerate} + \item \If $\locGetFullTip_{i} = 1$ \Then $\txGasPrice _{i} = \txBasefee_{i} + \locMaxPriorityFee$ + \item \If $\locGetFullTip_{i} = 0$ \Then $\txGasPrice _{i} = \locMaxFee$ + \end{enumerate} + \end{enumerate} + \item[\underline{Setting the \txPriorityFeePerGas:}] + we impose that + \begin{enumerate} + \item \If $\txIsLegacy _{i} + \txIsAccessSet _{i} = 1$ \Then $\txPriorityFeePerGas _{i} = \locGasPrice$ + \item \If $\txIsTypeTwo_{i} = 1$ \Then $\txPriorityFeePerGas _{i} = \txGasPrice_{i} - \txBasefee_{i}$ + \end{enumerate} + \item[\underline{Setting the \txEffectiveRefund:}] + we impose that + \begin{enumerate} + \item \If $\locGetFullRefund = 0$ \Then $\txEffectiveRefund _{i} = \txLeftoverGas _{i} + \locRefundLimit$ + \item \If $\locGetFullRefund = 1$ \Then $\txEffectiveRefund _{i} = \txLeftoverGas _{i} + \txFinalRefundCounter _{i}$ + \end{enumerate} + \item[\underline{Partially setting \txRequiresEvmExecution{}:}] + \If $\txIsDeployment_{i} = 1$ \Then we impose that + \[ + \txRequiresEvmExecution_{i} = \locNonzeroDataSize + \] + \saNote{} The above tags deployment transactions as requiring \evm{} execution whenever the associated initialization code is nonempty. + + \saNote{} The message call transaction case (i.e. ``$\txIsDeployment_{i} = 0$'') is settled in the \hubMod{} module. + \item[\underline{Setting \txCopyTxcd{}:}] + we impose that + \[ + \txCopyTxcd_{i} = (1 - \txIsDeployment_{i}) \cdot \txRequiresEvmExecution_{i} \cdot \locNonzeroDataSize + \] +\end{description} + diff --git a/txn_data/shared_computations.tex b/txn_data/shared_computations.tex new file mode 100644 index 0000000..17c51e2 --- /dev/null +++ b/txn_data/shared_computations.tex @@ -0,0 +1,133 @@ +\begin{center} + \boxed{\text{The constraints below assume that } \locAbs_{i} \neq \locAbs_{i - 1}.} +\end{center} +The present section constrains the columns that offload comparisons to the \wcpMod{} module. +The following constraints hold for all transaction types: +\begin{description} + \item[\underline{\underline{Row n$^\circ(i + \balanceRowOffset)$: Initial balance check:}}] + we impose that + \[ + \left\{\begin{array}{l} + \smallCallToLt + {i}{\balanceRowOffset} + {\txInitialBalance_{i}} + {\locValue + \locMaxFee \cdot \locGasLimit} + \vspace{2mm} + \\ + \resultMustBeFalse + {i}{\balanceRowOffset} + \\ + \end{array}\right. + \] + \saNote{} We thus require $\txInitialBalance_{i} \geq \locValue + \locMaxFee \cdot \locGasLimit$. + \item[\underline{\underline{Row n$°(i + \gasLimitRowOffset)$: Sufficient gas limit:}}] + we must distinguish between transaction types that support access sets (types 1 and 2) and those that do not (type 0) + \begin{enumerate} + \item \If $\txIsLegacy_{i} = 1$ \Then + \[ + \left\{\begin{array}{l} + \smallCallToLt + {i}{\gasLimitRowOffset} + {\locGasLimit} + {\locLegacyUpfrontGasCost} + \vspace{2mm} + \\ + \resultMustBeFalse + {i}{\gasLimitRowOffset} + \\ + \end{array}\right. + \] + \item \If $\txIsLegacy_{i} = 0$ \Then + \[ + \left\{\begin{array}{l} + \smallCallToLt + {i}{\gasLimitRowOffset} + {\locGasLimit} + {\locAccessUpfrontGasCost} + \vspace{2mm} + \\ + \resultMustBeFalse + {i}{\gasLimitRowOffset} + \\ + \end{array}\right. + \] + \end{enumerate} + Where we define the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locLegacyUpfrontGasCost & \define & + \left[ \begin{array}{crcl} + + \!\!\! & & & \locDataCost \\ + + \!\!\! & & & G_{\text{transaction}} \\ + + \!\!\! & \locIsDep & \cdot & G_{\text{txcreate}} \\ + \end{array} \right] \vspace{4mm} \\ + \locAccessUpfrontGasCost & \define & + \left[ \begin{array}{crcl} + + \!\!\! & & & \locDataCost \\ + + \!\!\! & & & G_{\text{transaction}} \\ + + \!\!\! & \locIsDep & \!\!\! \cdot \!\!\! & G_{\text{txcreate}} \\ + + \!\!\! & \locNumAddr & \!\!\! \cdot \!\!\! & G_\text{accesslistaddress} \\ + + \!\!\! & \locNumKeys & \!\!\! \cdot \!\!\! & G_\text{accessliststorage} \\ + \end{array} \right] \\ + \end{array} \right. + \] + and we use the following constants + \[ + \left\{ \begin{array}{lcr} + G_\text{transaction} & \!\!\! = \!\!\! & 21\,000 \\ + G_\text{create} & \!\!\! = \!\!\! & 32\,000 \\ + G_\text{accesslistaddress} & \!\!\! = \!\!\! & 2\,400 \\ + G_\text{accessliststorage} & \!\!\! = \!\!\! & 1\,900 \\ + \end{array} \right. + \] + \item[\underline{\underline{Row n$°(i + \maxRefundRowOffset)$: Upper limit for refunds:}}] + we impose that + \[ + \callToEuc + {i}{\maxRefundRowOffset} + {\locExecutionGasCost} + {\maxRefundQuotient} + \] + where we set / have used the following shorthands + \[ + \left\{ \begin{array}{lcl} + \locExecutionGasCost & \define & \locGasLimit - \txLeftoverGas_{i} \\ + \locRefundLimit & \define & \res_{i + \maxRefundRowOffset} \\ + \end{array} \right. + \] + \saNote{} + By construction + \[ + \locRefundLimit \equiv \displaystyle \left\lfloor\frac{\locExecutionGasCost}\maxRefundQuotient\right\rfloor + \] + \item[\underline{\underline{Row n$°(i + \effectiveRefundRowOffset)$: Effective refund:}}] + we impose that + \[ + \smallCallToLt + {i}{\effectiveRefundRowOffset} + {\txFinalRefundCounter _{i}} + {\locRefundLimit} + \] + and define the following shorthand + \[ + \locGetFullRefund + \define + \res_{i + \effectiveRefundRowOffset} + \] + \saNote{} + The interpretation is as follows: + \begin{IEEEeqnarray*}{LCL} + \locGetFullRefund = 1 & \iff & \txFinalRefundCounter _{i} < \locRefundLimit \\ + & \iff & \txFinalRefundCounter _{i} < \left\lfloor\frac{\locGasLimit - \txLeftoverGas_{i}}2\right\rfloor \\ + \end{IEEEeqnarray*} + \item[\underline{\underline{Row n$°(i + \detectingEmptyCallDataRowOffset)$: Detecting empty call data:}}] + \[ + \smallCallToIszero + {i}{\detectingEmptyCallDataRowOffset} + {\locDataSize} + \] + we further set + \[ + \locNonzeroDataSize \define 1 - \res_{i + \detectingEmptyCallDataRowOffset} + \] +\end{description} diff --git a/txn_data/shorthands.tex b/txn_data/shorthands.tex new file mode 100644 index 0000000..936aedb --- /dev/null +++ b/txn_data/shorthands.tex @@ -0,0 +1,24 @@ +To simplify notations in following sections we use the following short hands: +\[ + \left\{ \begin{array}{lcl} + \locTxType & \define & \outgoingDataLo_{i} \vspace{1mm} \\ + \locToAddrHi & \define & \outgoingDataHi_{i + 1} \vspace{1mm} \\ + \locToAddrLo & \define & \outgoingDataLo_{i + 1} \vspace{1mm} \\ + \locNonce & \define & \outgoingDataLo_{i + 2} \vspace{1mm} \\ + \locIsDep & \define & \outgoingDataHi_{i + 3} \vspace{1mm} \\ + \locValue & \define & \outgoingDataLo_{i + 3} \vspace{1mm} \\ + \locDataCost & \define & \outgoingDataHi_{i + 4} \\ + \end{array} \right. + \quad\text{and}\quad + \left\{ \begin{array}{lcl} + \locDataSize & \define & \outgoingDataLo_{i + 4} \vspace{1mm} \\ + \locGasLimit & \define & \outgoingDataLo_{i + 5} \vspace{1mm} \\ + \locGasPrice & \define & \outgoingDataLo_{i + 6} \vspace{1mm} \\ + \locMaxPriorityFee & \define & \outgoingDataHi_{i + 6} \vspace{1mm} \\ + \locMaxFee & \define & \outgoingDataLo_{i + 6} \vspace{1mm} \\ + \locNumKeys & \define & \outgoingDataHi_{i + 7} \vspace{1mm} \\ + \locNumAddr & \define & \outgoingDataLo_{i + 7} \\ + \end{array} \right. +\] +\noindent These aliases should \textbf{only} be used in constraints written under the assumption that $\locAbs_{i} \neq \locAbs_{i - 1}$. See section~(\ref{txData: constraints: graphical rep data}). +\saNote{} $\outgoingDataLo_{i + 6}$ is given two different aliases. For the initial balance comparison we will use $\locMaxFee$ regardless of the transaction type to unify the presentation. Elsewhere, we may use the appropriate alias ($\locGasPrice$ for type $0$ and $1$ transactions, $\locMaxFee$ for type 2 transactions.) diff --git a/txn_data/specialized_computations.tex b/txn_data/specialized_computations.tex new file mode 100644 index 0000000..85251d4 --- /dev/null +++ b/txn_data/specialized_computations.tex @@ -0,0 +1,61 @@ +\begin{center} + \boxed{\text{The constraints below assume that } + \left\{ \begin{array}{lcl} + \locAbs_{i} & \neq & \locAbs_{i - 1} \\ + \txIsTypeTwo_{i} & = & 1 \\ + \end{array} \right.} +\end{center} +The following constraints apply to type 2 transactions only: +\begin{description} + \item[\underline{\underline{Row n$°(i + \maxFeeVsBaseFeeRowOffset)$: Comparing \locMaxFee{} and \txBasefee{}:}}] + we impose that + \[ + \left\{ \begin{array}{l} + \smallCallToLt + {i}{\maxFeeVsBaseFeeRowOffset} + {\locMaxFee} + {\txBasefee} + \vspace{2mm} + \\ + \resultMustBeFalse + {i}{\maxFeeVsBaseFeeRowOffset} + \\ + \end{array} \right. + \] + \saNote{} + The above thus enforces that the result of the comparson $\locMaxFee < \txBasefee$ is \texttt{false}, i.e. that the inequality $\locMaxFee \geq \txBasefee$ is \texttt{true}. + \item[\underline{\underline{Row n$°(i + \maxFeeVsMaxPriorityFee)$: Comparing \locMaxFee{} and \locMaxPriorityFee{}:}}] + we impose that + \[ + \left\{ \begin{array}{l} + \smallCallToLt + {i}{\maxFeeVsMaxPriorityFee} + {\locMaxFee } + {\locMaxPriorityFee} + \vspace{2mm} + \\ + \resultMustBeFalse + {i}{\maxFeeVsMaxPriorityFee} + \\ + \end{array} \right. + \] + \saNote{} + The above thus enforces that the result of the comparson $\locMaxFee < \locMaxPriorityFee$ is \texttt{false}, i.e. that the inequality $\locMaxFee \geq \locMaxPriorityFee$ is \texttt{true}. + \item[\underline{\underline{Row n$°(i + \effectiveGasPriceRowOffset)$: Computing the effective gas price:}}] + we impose that + \[ + \smallCallToLt + {i}{\effectiveGasPriceRowOffset} + {\locMaxFee } + {\locMaxPriorityFee + \txBasefee} + \] + and we define the following shorthand + \[ + \locGetFullTip \define 1 - \res_{i + \effectiveGasPriceRowOffset} + \] + \saNote{} + By construction + \[ + \locGetFullTip = 1 \iff \locMaxFee \geq \locMaxPriorityFee + \txBasefee + \] +\end{description} diff --git a/txn_data/target.tex b/txn_data/target.tex new file mode 100644 index 0000000..9f103db --- /dev/null +++ b/txn_data/target.tex @@ -0,0 +1,28 @@ +The target constraints are simple. +\[ + \boxed{\text{All constraints in this section assume }\locRel_{i} \neq 0.} +\] +\begin{enumerate} + \item + \[ + \txInitialGas_{i} + = +% \tg{}_{i} + - + \left[ + \begin{array}{cr} +% & \dataGasCost_{i} \\ + + & \cType_{i} \cdot G_{\text{txcreate}} \\ + + & G_{\text{transaction}}\\ +% + & \txType{}_{i} \cdot \warmGasCost_{i} \\ + \end{array} + \right] + \] + where $G_{\text{txcreate}} = 32000$ and $G_{\text{transaction}} = 21000$. + \item The initiallly available gas is a relatively small (i.e. $\llarge$-byte) nonnegative integer: + \[ + \txInitialGas_{i} + = + \sum_{k = 0}^{\llargeMO} 256^k \cdot \byteCol{k}_{i} + \] +\end{enumerate} diff --git a/txn_data/wcp_representation.tex b/txn_data/wcp_representation.tex new file mode 100644 index 0000000..0f0b269 --- /dev/null +++ b/txn_data/wcp_representation.tex @@ -0,0 +1,69 @@ +\def\rFaux{\red{\texttt{false}}} +\def\rZero{\redm{0}} +\def\locLT{\redm{<}} +We provide depictions of the comparisons. In the tables below one should interpret +$\rFaux$ as $\rZero$ and +$\locLT$ as \inst{LT}. +\renewcommand{\arraystretch}{1.3} +\begin{figure}[!h] + \[ + \begin{array}{|l|l|c|c|c|c|c|c|} \hline + \ct & \txIsLegacy & \argOneLo & \INST & \argTwoLo & \res \\ \hline + \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + 0 & \one & \txInitialBalance & \locLT & \locValue + \locMaxFee \cdot \locGasLimit & \rFaux \\ \hline + 1 & \one & \locGasLimit & \locLT & \locLegacyUpfrontGasCost & \rFaux \\ \hline + 2 & \one & \locExecutionGasCost & \locLT & \locRefundLimit & \rFaux \\ \hline + 3 & \one & \txFinalRefundCounter & \locLT & \locRefundLimit & \texttt{TBD} \\ \hline + 4 & \one & \locDataSize & \inst{ISZERO} & \nothing & \texttt{TBD} \\ \hline + 5 & \one & \nothing & \nothing & \nothing & \nothing \\ \hline + 6 & \one & \nothing & \nothing & \nothing & \nothing \\ \hline + 0 & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + \end{array} + \] + \caption{% + Comparisons for type 0 transactions. \saNote{} Only one of the comparisons isn't \emph{a priori} constrained.} + % \label{fig: } +\end{figure} + +\begin{figure}[!h] + \[ + \begin{array}{|l|l|c|c|c|c|c|c|} \hline + \ct & \txIsAccessSet & \argOneLo & \INST & \argTwoLo & \res \\ \hline + \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + 0 & \one & \txInitialBalance & \locLT & \locValue + \locMaxFee \cdot \locGasLimit & \rFaux \\ \hline + 1 & \one & \locGasLimit & \locLT & \locAccessUpfrontGasCost & \rFaux \\ \hline + 2 & \one & \locExecutionGasCost & \locLT & \locRefundLimit & \rFaux \\ \hline + 3 & \one & \txFinalRefundCounter & \locLT & \locRefundLimit & \texttt{TBD} \\ \hline + 4 & \one & \locDataSize & \inst{ISZERO} & \nothing & \texttt{TBD} \\ \hline + 5 & \one & \nothing & \nothing & \nothing & \nothing \\ \hline + 6 & \one & \nothing & \nothing & \nothing & \nothing \\ \hline + 7 & \one & \nothing & \nothing & \nothing & \nothing \\ \hline + 0 & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + \end{array} + \] + \caption{% + Comparisons for type 1 transactions. \saNote{} Only one of the comparisons isn't \emph{a priori} constrained.} + % \label{fig: } +\end{figure} + +\begin{figure}[!h] + \[ + \begin{array}{|l|l|c|c|c|c|c|c|} \hline + \ct & \txIsTypeTwo & \argOneLo & \INST & \argTwoLo & \res \\ \hline + \cdots & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + 0 & \one & \txInitialBalance & \locLT & \locValue + \locMaxFee \cdot \locGasLimit & \rFaux \\ \hline + 1 & \one & \locGasLimit & \locLT & \locAccessUpfrontGasCost & \rFaux \\ \hline + 2 & \one & \locExecutionGasCost & \locLT & \locRefundLimit & \rFaux \\ \hline + 3 & \one & \txFinalRefundCounter & \locLT & \locRefundLimit & \texttt{TBD} \\ \hline + 4 & \one & \locDataSize & \inst{ISZERO} & \nothing & \texttt{TBD} \\ \hline + 5 & \one & \locMaxFee & \locLT & \txBasefee & \rFaux \\ \hline + 6 & \one & \locMaxFee & \locLT & \locMaxPriorityFee & \rFaux \\ \hline + 7 & \one & \locMaxFee & \locLT & \locMaxPriorityFee + \txBasefee & \texttt{TBD} \\ \hline + 0 & \cdots & \cdots & \cdots & \cdots & \cdots \\ \hline + \end{array} + \] + \caption{% + Comparisons for type 2 transactions. \saNote{} For \textsc{eip-1559} transactions two of the comparisons aren't \emph{a priori} constrained.} + % \label{fig: } +\end{figure} + diff --git a/wcp/_all_wcp.tex b/wcp/_all_wcp.tex new file mode 100644 index 0000000..d36c8ac --- /dev/null +++ b/wcp/_all_wcp.tex @@ -0,0 +1,36 @@ +\documentclass{article} +\usepackage{xkeyval} +\usepackage[dvipsnames]{xcolor} +\usepackage{../pkg/common} +% \usepackage{../pkg/dark_theme} +\usepackage{../pkg/std} +\usepackage{../pkg/IEEEtrantools} +\usepackage{../pkg/rom} +\usepackage{../pkg/bin} +\usepackage{../pkg/wc3} +\usepackage{../pkg/ram} +\usepackage{../pkg/stack} +\usepackage{../pkg/call_stack} +\usepackage{../pkg/access} +\usepackage{../pkg/expansion} +\usepackage{../pkg/exponent} +\usepackage{../pkg/thm_env} +\usepackage{../pkg/offset_processor} +\usepackage{../pkg/trm} +\usepackage{../pkg/flags_stamps_selectors} +\usepackage{../pkg/common_shorthands} +\usepackage{../pkg/alu} + + +\title{Word comparison module} +\author{Rollup team} +\date{October 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\input{_inputs} + +\end{document} diff --git a/wcp/_inputs.tex b/wcp/_inputs.tex new file mode 100644 index 0000000..863e142 --- /dev/null +++ b/wcp/_inputs.tex @@ -0,0 +1,14 @@ +\section{Word comparison module} +\subsection{Introduction} \label{wcp: intro} \input{intro} +\subsection{Columns} \label{wcp: columns} \input{columns} + +\section{Constraints} +\subsection{Binary constraints} \label{wcp: binary} \input{binary} +\subsection{Shorthands} \label{wcp: shorthands} \input{shorthands} +\subsection{Instruction decoding} \label{wcp: instruction decoding} \input{decoding} +\subsection{Constancy constraints} \label{wcp: constancy} \input{constancy} +\subsection{Heartbeat} \label{wcp: heartbeat} \input{heartbeat} +\subsection{Byte decompositions and bytehood constraints} \label{wcp: byteDec and bytehood} \input{byteDec} +\subsection{\BITS{} and sign bits constraints} \label{wcp: target constraints} \input{bits} +\subsection{Target constraints} \label{wcp: target constraints} \input{target} +\subsection{Result constraints} \label{wcp: result constraints} \input{result} diff --git a/wcp/binary.tex b/wcp/binary.tex new file mode 100644 index 0000000..65f63fb --- /dev/null +++ b/wcp/binary.tex @@ -0,0 +1,23 @@ +We impose binary constraints on the following columns: +\begin{multicols}{4} + \begin{enumerate} + \item $\res$ + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item[\vspace{\fill}] + \item $\negCol{1}$ + \item $\negCol{2}$ + \item $\BITS$ + \item $\bit{k}$, $k = 1,\dots, 4$ + \item \isIszero + \item \isEq + \item \isSgt + \item \isSlt + \item \isLt + \item \isGt + \item \isLeq + \item \isGeq + % \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} Section~(\ref{wcp: instruction decoding}) implicitly imposes binaryness on \oli{} and \vli{}. diff --git a/wcp/bits.tex b/wcp/bits.tex new file mode 100644 index 0000000..c0dacc8 --- /dev/null +++ b/wcp/bits.tex @@ -0,0 +1,16 @@ +We constrain the $\negCol{1}$, $\negCol{2}$ and $\BITS$ columns. +\begin{enumerate} + \item \If \Big($\ct_{i}=\llargeMO$ \et $\isSlt_{i} + \isSgt_{i} \neq 0$\Big) \Then, setting $j := i - \llargeMO$, + \begin{enumerate} + \item $\byteCol{1} _{j} = \sum _{k = 0}^{7} 2^{7 - k} \BITS_{j + k}$ + \item $\byteCol{3} _{j} = \sum _{k = 0}^{7} 2^{7 - k} \BITS_{j + k + 8}$ + \item $\negCol{1} _{j} = \BITS _{j}$ + \item $\negCol{2} _{j} = \BITS _{j + 8}$ + \end{enumerate} + \item \If $\maxCt_{i} \neq \llargeMO$ \Then $\negCol{1}_{i}=\negCol{2}_{i}=0$ +\end{enumerate} +\saNote{} Since the \col{IS\_XXX} flags are \emph{exclusive binary columns}, see note~(\ref{wcp: note: IS_XXX are exclusive binary columns}), the condition ``$\isSlt_{i} + \isSgt_{i} \neq 0$'' is equivalent to ``$\isSlt_{i}=1$ \Or $\isSgt_{i}=1$.'' + +\saNote{} Recall that the purpose of the $\negCol{1}$ and $\negCol{2}$ columns is to capture \emph{when required} the sign bits of the arguments of a \wcpMod{} module instruction. +This is required precisely for signed instructions (i.e. \inst{SLT} and \inst{SGT}) whose arguments are ``large.'' +The above captures the intuition that \If arguments are ``small'', in the sense that performing the byte decompositions of all high and low parts involved can be done in fewer than $\llarge$ rows i.e. $\maxCt \neq \llargeMO$, \Then the sign bits may safely be set to $0$. diff --git a/wcp/byteDec.tex b/wcp/byteDec.tex new file mode 100644 index 0000000..9280260 --- /dev/null +++ b/wcp/byteDec.tex @@ -0,0 +1,6 @@ +We enforce ``byte accumulation constraints'' for $k=1, \dots, 6$: +\begin{enumerate} + \item $\byteCol{k}$, for $k=1, \dots, 6$, contain bytes; + \item \If $\ct_{i} = 0$ \Then $\acc{k}_{i} = \byteCol{k}_{i}$; + \item \If $\ct_{i} \neq 0$ \Then $\acc{k}_{i} = 256 \cdot \acc{k}_{i - 1} + \byteCol{k}_{i}$; +\end{enumerate} diff --git a/wcp/columns.tex b/wcp/columns.tex new file mode 100644 index 0000000..7b9b266 --- /dev/null +++ b/wcp/columns.tex @@ -0,0 +1,54 @@ +We list the named columns of the word comparison module. The first two dictate its (simple) heartbeat. +\begin{enumerate} + \item $\wcpStamp$: + column containing the word comparison stamp; + \item \ct{}: + counter column; + either hovers around $0$ or counts continuously up from $0$ to \maxCt{} whereupon it resets; + \item \maxCt: + counter-constant column; + indicates the value at which \ct{} must reset; +\end{enumerate} +The following columns contain imported values related to the instruction at hand as seen in the hub module. +\begin{enumerate}[resume] + \item $\INST{}$: + \godGiven{} + instruction column; + \item $\argOneHi$, $\argOneLo$: + \godGiven{} + contain the high and low parts respectively of the first instruction argument; + \item $\argTwoHi$, $\argTwoLo$: + \godGiven{} + contain the high and low parts respectively of the second instruction argument; + \item $\res$: + \godGiven{} + contains the (bit) result; + \item \isLt{}, \isGt{}, \isSlt{}, \isSgt{}, \isEq{}, \isIszero{}, \isGeq{}, \isLeq{}: + mutually exclusive binary columns which light up precisely for the eponymous instruction; + \item $\oli{}$: + binary column; equals $1$ \emph{if and only if} $\INST\in\{\inst{EQ},\inst{ISZERO}\}$; + \item $\vli{}$: + binary column; equals $1$ \emph{if and only if} $\INST\in\{\inst{LT}, \inst{GT}, \inst{GEQ}, \inst{LEQ}, \inst{SLT}, \inst{SGT}\}$; +\end{enumerate} +\saNote{} As usual \oli{} is shorthand for \OLI{} and \vli{} is shorthand for \VLI{}; +the \oli{} tag applies to instructions that can \emph{always} be dealt with in a single processing row; +the \vli{} tag applies to instructions that may require a variable number of processing rows. + +\saNote{} The processing of variable length instructions can take anywhere from 1 to $\llarge$ rows. +\begin{enumerate}[resume] + \item $\BITS$: + binary column; + \item $\negCol{1}$, $\negCol{2}$: + counter-constant binary columns; +\end{enumerate} +$\negCol{1}$ and $\negCol{2}$ contain the sign bit of $\argOne$ and $\argTwo$ respectively. +The sign bits are required to deal with the signed comparison operations \inst{SLT} and \inst{SGT}. +To extract them one must provide the bit decomposition of the most significant byte of $\argOne$ and $\argTwo$ respectively: the purpose of the $\BITS$ column is to store those bits. + +\saNote{} For unsigned instructions (\inst{LT}, \inst{GT}, \inst{ISZERO}, \inst{EQ} as well as \inst{LEQ} and \inst{GEQ}) both bits will be set to zero. +\begin{enumerate}[resume] + \item $\byteCol{k}$ and $\acc{k}$ for $k = 1,\dots, 6$: + byte and associated accumulator columns; + \item $\bit{k}$ for $k = 1, \dots, 4$: + counter-constant binary columns; +\end{enumerate} diff --git a/wcp/constancy.tex b/wcp/constancy.tex new file mode 100644 index 0000000..910cb1f --- /dev/null +++ b/wcp/constancy.tex @@ -0,0 +1,25 @@ +As usual, we declare a column $\col{X}$ to be \textbf{counter-constant} if it satisfies +\[ + \If \ct_{i} \neq 0 ~ \Then \col{X}_{i} = \col{X}_{i - 1}. +\] +We impose counter-constancy on the following columns: +\begin{multicols}{6} + \begin{enumerate} + \item $\argOneHi$ + \item $\argOneLo$ + \item $\argTwoHi$ + \item $\argTwoLo$ + \item $\INST$ + \item $\res$ + \item $\negCol{1}$ + \item $\negCol{2}$ + \item $\bit{3}$ + \item $\bit{4}$ + \item \maxCt{} + \item[\vspace{\fill}] + \end{enumerate} +\end{multicols} +\saNote{} \oli{} and \vli{} are counter-constant by virtue of \INST{} being counter-constant. + +\saNote{} $\bit{1}$ and $\bit{2}$ will be counter-constant by construction. + diff --git a/wcp/decoding.tex b/wcp/decoding.tex new file mode 100644 index 0000000..58f245b --- /dev/null +++ b/wcp/decoding.tex @@ -0,0 +1,14 @@ +This section enforces the instruction decoding by means of the +\begin{enumerate} + \item \If $\wcpStamp_{i} = 0$ \Then $\locFlagSum_{i} = 0$ + \item \If $\wcpStamp_{i} \neq 0$ \Then $\locFlagSum_{i} = 1$ + \item We impose the following unique decoding constraint: + \[ + \left\{ \begin{array}{lcl} + \INST_{i} & = & \locWeightedFlagSum_{i} \\ + \oli_{i} & = & \locOli_{i} \\ + \vli_{i} & = & \locVli_{i} \\ + \end{array} \right. + \] +\end{enumerate} +\saNote{}\label{wcp: note: IS_XXX are exclusive binary columns} Since \locFlagSum{} is \emph{de facto} binary but also, by definition, the sum of several binary \col{IS\_XXX} columns, the above enforces that the various \col{IS\_XXX} flags be \textbf{mutually exclusive binary columns}. Furthermore these flags must all vanish on \textbf{padding-rows} (i.e. rows $i$ satisfying $\wcpStamp_{i} = 0$) while precisely one of these flags must be set on \textbf{non-padding-rows} (i.e. rows $i$ satisfying $\wcpStamp_{i} \neq 0$) diff --git a/wcp/heartbeat.tex b/wcp/heartbeat.tex new file mode 100644 index 0000000..5b5b900 --- /dev/null +++ b/wcp/heartbeat.tex @@ -0,0 +1,23 @@ +The heartbeat of the word comparison module is simple: if $\wcpStamp \neq 0$ and $\oli = 0$ then \ct{} counts continuously from $0$ to $\maxCt{}$, otherwise it is $0$. +\begin{enumerate} + \item $\wcpStamp_{0} = 0$ + \item \If $\wcpStamp_{i} = 0$ \Then + \[ + \left\{ \begin{array}{lcl} + \maxCt_{i} & = & 0 \quad (\trash) \\ + \ct_{i} & = & 0 \quad (\trash) \\ + \end{array} \right. + \] + \item $\wcpStamp$ is nondecreasing in the sense that $\wcpStamp_{i + 1} \in \{ \wcpStamp_{i}, 1 + \wcpStamp_{i} \}$ + \item \If $\wcpStamp_{i + 1} \neq \wcpStamp_{i}$ \Then $\ct_{i + 1} = 0$ + \item \If $\oli_{i} = 1$ \Then $\maxCt_{i}=0$ + \item \If $\wcpStamp_{i} \neq 0$ \Then + \begin{enumerate} + \item \If $\ct_{i} \neq \maxCt_{i}$ \Then $\ct_{i + 1} = 1 + \ct_{i}$ + \item \If $\ct_{i} = \maxCt_{i}$ \Then $\wcpStamp_{i + 1} = 1 + \wcpStamp_{i}$ + \end{enumerate} + \item $\ct_{i} \neq \llarge$ + \item $\ct_{N} = \maxCt_{N}$. +\end{enumerate} +\saNote{} We don't explicitly impose anything on the value of $\maxCt_i$ when $\vli_i \equiv 1$. +But the above forces us to have at all times $0 \leq \ct_{i} \leq \maxCt_{i} < \llarge$, at the very least whenever $\wcpStamp_{i} \neq 0$ if the implementation omits the constraints marked with $(\trash)$. diff --git a/wcp/intro.tex b/wcp/intro.tex new file mode 100644 index 0000000..eb712a7 --- /dev/null +++ b/wcp/intro.tex @@ -0,0 +1,19 @@ +The \textbf{word comparison module} deals with the six word comparison instructions of the \evm{} as well as two word comparison instructions that the \zkEvm{} may use but which aren't part of the \evm{} proper: +\begin{multicols}{4} +\begin{itemize} + \item \inst{LT} + \item \inst{GT} + \item \inst{SLT} + \item \inst{SGT} + \item \inst{EQ} + \item \inst{ISZERO} + \item \inst{LEQ} + \item \inst{GEQ} +\end{itemize} +\end{multicols} +\saNote{} +\inst{LEQ} and \inst{GEQ} stand for +``\inst{Less than or EQual}'' and +``\inst{Greater than or EQual}'' respectively. + +The present module is often solicited to perform miscellaneous comparisons on behalf of other modules. diff --git a/wcp/oli.tex b/wcp/oli.tex new file mode 100644 index 0000000..78d0818 --- /dev/null +++ b/wcp/oli.tex @@ -0,0 +1,7 @@ +We constrain the $\oli$ column: +\begin{enumerate} + \item $\oli$ is binary; + \item \If $\iInst_{i} = \inst{EQ}$ \Then $\oli_{i} = 1$ + \item \If $\iInst_{i} = \inst{ISZERO}$ \Then $\oli_{i} = 1$ + \item \If \big($\iInst_{i} \neq \inst{EQ}$ \et $\iInst_{i} \neq \inst{ISZERO}$\big) \Then $\oli_{i} = 0$ +\end{enumerate} \ No newline at end of file diff --git a/wcp/result.tex b/wcp/result.tex new file mode 100644 index 0000000..5d2718a --- /dev/null +++ b/wcp/result.tex @@ -0,0 +1,27 @@ +We will use the following shorthands to express what follows: +\[ + \left\{ \begin{array}{lcl} + \col{eq}_{i} & \!\!\! \define \!\!\! & \bit{1}_{i} \cdot \bit{2}_{i} \\ + \col{gt}_{i} & \!\!\! \define \!\!\! & \bit{3}_{i} + \bit{1}_{i} \cdot \bit{4}_{i} \\ + \col{lt}_{i} & \!\!\! \define \!\!\! & 1 - \Big(\bit{3}_{i} + \bit{1}_{i} \cdot \bit{4}_{i} + \bit{1}_{i} \cdot \bit{2}_{i}\Big) \\ + & \!\!\! = \!\!\!& 1 - \Big( \col{gt}_{i} + \col{eq}_{i}\Big). \\ + \end{array} \right. +\] +The behavior of $\res$ is instruction dependent. We settle its behaviour below: +\begin{enumerate} + \item \If $\oli_{i} = 1$ \Then $\res_{i} = \col{eq}_{i}$ + \item \If $\isLt _{i} = 1$ \Then $\res_{i} = \col{lt}_{i}$ + \item \If $\isGt _{i} = 1$ \Then $\res_{i} = \col{gt}_{i}$ + \item \If $\isLeq _{i} = 1$ \Then $\res_{i} = \col{lt}_{i} + \col{eq}_{i}$ + \item \If $\isGeq _{i} = 1$ \Then $\res_{i} = \col{gt}_{i} + \col{eq}_{i}$ + \item \If $\isSlt _{i} = 1$ \Then + \begin{enumerate} + \item \If $\negCol{1}_{i} \neq \negCol{2}_{i}$ \Then $\res_{i} = \negCol{1}_{i}$ + \item \If $\negCol{1}_{i} = \negCol{1}_{i}$ \Then $\res_{i} = \col{lt}_{i}$ + \end{enumerate} + \item \If $\isSgt _{i} = 1$ \Then + \begin{enumerate} + \item \If $\negCol{1}_{i} \neq \negCol{2}_{i}$ \Then $\res_{i} = \negCol{2}_{i}$ + \item \If $\negCol{1}_{i} = \negCol{1}_{i}$ \Then $\res_{i} = \col{gt}_{i}$ + \end{enumerate} +\end{enumerate} diff --git a/wcp/shorthands.tex b/wcp/shorthands.tex new file mode 100644 index 0000000..892d26f --- /dev/null +++ b/wcp/shorthands.tex @@ -0,0 +1,49 @@ +We use the following shorthands +\[ + \left\{ \begin{array}{lcl} + \locOli_{i} & \define & + \left[ \begin{array}{cr} + + & \isEq _{i} \\ + + & \isIszero _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \locVli_{i} & \define & + \left[ \begin{array}{cr} + + & \isLt _{i} \\ + + & \isGt _{i} \\ + + & \isLeq _{i} \\ + + & \isGeq _{i} \\ + + & \isSlt _{i} \\ + + & \isSgt _{i} \\ + \end{array} \right] \vspace{2mm} \\ + \end{array} \right. +\] +We further define +\[ + \locFlagSum_{i} \define + \left[ \begin{array}{cr} + + & \locOli _{i} \\ + + & \locVli _{i} \\ + \end{array} \right] + \quad\text{and}\quad + \locWeightedFlagSum_{i} \define + \left[ \begin{array}{crcl} + + & \inst{EQ} & \cdot & \isEq _{i} \\ + + & \inst{ISZERO} & \cdot & \isIszero _{i} \\ + + & \inst{LT} & \cdot & \isLt _{i} \\ + + & \inst{GT} & \cdot & \isGt _{i} \\ + + & \inst{GEQ} & \cdot & \isGeq _{i} \\ + + & \inst{LEQ} & \cdot & \isLeq _{i} \\ + + & \inst{SLT} & \cdot & \isSlt _{i} \\ + + & \inst{SGT} & \cdot & \isSgt _{i} \\ + \end{array} \right] +\] +\saNote{} In the above we must introduce numerical values for the ``\inst{LEQ} and \inst{GEQ} instructions.'' +The only requirement is that that these values be different from +\inst{EQ}, \inst{ISZERO}, \inst{LT}, \inst{GT}, \inst{SLT} and \inst{SGT} respectively. +We suggest setting +\[ + \begin{cases} + \inst{LEQ} \define \texttt{0x\,0E} \\ + \inst{GEQ} \define \texttt{0x\,0F} \\ + \end{cases} +\] diff --git a/wcp/target.tex b/wcp/target.tex new file mode 100644 index 0000000..9c6c19c --- /dev/null +++ b/wcp/target.tex @@ -0,0 +1,56 @@ +We first settle the behaviour of the first two bit columns: +\begin{enumerate} + \item \If $\wcpStamp_{i} \neq 0$ \Then + \[ + \left\{ + \begin{array}{l} + \If \argOneHi_{i} = \argTwoHi_{i} ~ \Then \bit{1}_{i} = 1 \\ + \If \argOneHi_{i} \neq \argTwoHi_{i} ~ \Then \bit{1}_{i} = 0 \vspace{2mm} \\ + \If \argOneLo_{i} = \argTwoLo_{i} ~ \Then \bit{2}_{i} = 1 \\ + \If \argOneLo_{i} \neq \argTwoLo_{i} ~ \Then \bit{2}_{i} = 0 \\ + \end{array} + \right. + \] +\end{enumerate} +We fix the targets of the accumulator columns: +\begin{enumerate}[resume] + \item \If ($\vli_{i} = 1$ \et $\ct_{i} = \maxCt_{i}$) \Then + \begin{enumerate} + \item the first four accumulator columns provide the byte decompositions of the arguments, i.e. + \[ + \left\{ + \begin{array}{lcl} + \acc{1}_{i} & \!\!\! = \!\!\! & \argOneHi_{i} \\ + \acc{2}_{i} & \!\!\! = \!\!\! & \argOneLo_{i} \vspace{2mm} \\ + \acc{3}_{i} & \!\!\! = \!\!\! & \argTwoHi_{i} \\ + \acc{4}_{i} & \!\!\! = \!\!\! & \argTwoLo_{i} \\ + \end{array} + \right. + \] + \item the remaining two accumulator columns compute certain nonnegative adjusted differences, i.e. + \[ + \left\{ + \begin{array}{lcl} + \acc{5}_{i} & \!\!\! = \!\!\! & (2\cdot\bit{3}_{i} - 1) \cdot \big(\argOneHi_{i} - \argTwoHi_{i}\big) - \bit{3}_{i} \\ + \acc{6}_{i} & \!\!\! = \!\!\! & (2\cdot\bit{4}_{i} - 1) \cdot \big(\argOneLo_{i} - \argTwoLo_{i}\big) - \bit{4}_{i} \\ + \end{array} + \right. + \] + In other words: + \[ + \left\{ + \begin{array}{l} + \bit{3} \equiv 1 \iff \argOneHi > \argTwoHi \\ + \bit{3} \equiv 0 \iff \argOneHi \leq \argTwoHi \vspace{2mm} \\ + \bit{4} \equiv 1 \iff \argOneLo > \argTwoLo \\ + \bit{4} \equiv 0 \iff \argOneLo \leq \argTwoLo \\ + \end{array} + \right. + \] + \end{enumerate} + \item \If $\isIszero_{i} = 1$ \Then + \begin{enumerate} + \item $\argTwoHi_{i} = 0$ + \item $\argTwoLo_{i} = 0$ + \end{enumerate} +\end{enumerate} \ No newline at end of file