Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Typo and bug fixes for the ACC instruction family #462

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 68 additions & 65 deletions hub/constraints/instruction-handling/acc.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,45 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;; ROFF ≡ ROW_OFFSET
;; ACC ≡ ACCOUNT_FAMILY
(defconst
ROW_OFFSET___ACC_FAMILY___CONTEXT_ROW 1
ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW 2
ROFF_ACC___CONTEXT_ROW 1
ROFF_ACC___ACCOUNT_READING_ROW 2

ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW 1
ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW 2
ROFF_ACC___ACCOUNT_DOING_ROW 1
ROFF_ACC___ACCOUNT_UNDOING_ROW 2
)


(defun (account-instruction---is-BALANCE) [ stack/DEC_FLAG 1 ] )
(defun (account-instruction---is-EXTCODESIZE) [ stack/DEC_FLAG 2 ] )
(defun (account-instruction---is-EXTCODEHASH) [ stack/DEC_FLAG 3 ] )
(defun (account-instruction---is-CODESIZE) [ stack/DEC_FLAG 4 ] )
(defun (account-instruction---raw-address-hi) [ stack/STACK_ITEM_VALUE_HI 1 ])
(defun (account-instruction---raw-address-lo) [ stack/STACK_ITEM_VALUE_LO 1 ])

(defun (account-instruction---result-hi) [ stack/STACK_ITEM_VALUE_HI 4 ])
(defun (account-instruction---result-lo) [ stack/STACK_ITEM_VALUE_LO 4 ]) ;; ""
(defun (account-instruction---result-lo) [ stack/STACK_ITEM_VALUE_LO 4 ])

(defun (account-instruction---is-BALANCE) [ stack/DEC_FLAG 1 ] )
(defun (account-instruction---is-EXTCODESIZE) [ stack/DEC_FLAG 2 ] )
(defun (account-instruction---is-EXTCODEHASH) [ stack/DEC_FLAG 3 ] )
(defun (account-instruction---is-CODESIZE) [ stack/DEC_FLAG 4 ] ) ;; ""
(defun (account-instruction---is-SELFBALANCE) (- 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

for clarity, maybe better (- 1 (+ _sum shorthands)) ? instead of (- 1 \sum shorthands)

(account-instruction---is-BALANCE)
(account-instruction---is-EXTCODESIZE)
(account-instruction---is-EXTCODEHASH)
(account-instruction---is-CODESIZE)))

(defun (account-instruction---touches-foreign-account) (+ (account-instruction---is-BALANCE)
(account-instruction---is-EXTCODESIZE)
(account-instruction---is-EXTCODEHASH)))
(defun (account-instruction---touches-current-account) (+ (account-instruction---is-CODESIZE)
(account-instruction---is-SELFBALANCE)))
(defun (account-instruction---touches-foreign-account) (+ (account-instruction---is-BALANCE)
(account-instruction---is-EXTCODESIZE)
(account-instruction---is-EXTCODEHASH)))

(defun (account-instruction---touches-current-account) (+ (account-instruction---is-CODESIZE)
(account-instruction---is-SELFBALANCE)))

(defun (account-instruction---no-trimming) (- stack/ACC_FLAG (account-instruction---touches-foreign-account)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed the no-trimming shorthand in favour of the touches-current-account shorthand

(defun (account-instruction---account-address-hi) (shift context/ACCOUNT_ADDRESS_HI ROW_OFFSET___ACC_FAMILY___CONTEXT_ROW))
(defun (account-instruction---account-address-lo) (shift context/ACCOUNT_ADDRESS_LO ROW_OFFSET___ACC_FAMILY___CONTEXT_ROW))
(defun (account-instruction---byte-code-address-hi) (shift context/BYTE_CODE_ADDRESS_HI ROW_OFFSET___ACC_FAMILY___CONTEXT_ROW))
(defun (account-instruction---byte-code-address-lo) (shift context/BYTE_CODE_ADDRESS_LO ROW_OFFSET___ACC_FAMILY___CONTEXT_ROW))
(defun (account-instruction---foreign-address-warmth) (shift account/WARMTH ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW))
(defun (account-instruction---account-address-hi) (shift context/ACCOUNT_ADDRESS_HI ROFF_ACC___CONTEXT_ROW))
(defun (account-instruction---account-address-lo) (shift context/ACCOUNT_ADDRESS_LO ROFF_ACC___CONTEXT_ROW))
(defun (account-instruction---byte-code-address-hi) (shift context/BYTE_CODE_ADDRESS_HI ROFF_ACC___CONTEXT_ROW))
(defun (account-instruction---byte-code-address-lo) (shift context/BYTE_CODE_ADDRESS_LO ROFF_ACC___CONTEXT_ROW))
(defun (account-instruction---foreign-address-warmth) (shift account/WARMTH ROFF_ACC___ACCOUNT_DOING_ROW))
Copy link
Collaborator Author

@OlivierBBB OlivierBBB Oct 17, 2024

Choose a reason for hiding this comment

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

Bug fix. These shorthands for values in context/ or account/ rows were missing a shift !



;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -79,8 +82,8 @@
(:guard (account-instruction---standard-hypothesis))
;;
(begin
(if-not-zero (account-instruction---touches-foreign-account) (stack-pattern-1-1))
(if-not-zero (account-instruction---no-trimming) (stack-pattern-0-1))))
(if-not-zero (account-instruction---touches-foreign-account) (stack-pattern-1-1))
(if-not-zero (account-instruction---touches-current-account) (stack-pattern-0-1))))

(defconstraint account-instruction---setting-allowable-exceptions
(:guard (account-instruction---standard-hypothesis))
Expand All @@ -92,7 +95,7 @@
;;
(begin
(if-not-zero (account-instruction---touches-foreign-account) (eq! NSR (+ 1 CONTEXT_WILL_REVERT CMC)))
(if-not-zero (account-instruction---no-trimming) (eq! NSR (+ 1 (- 1 CMC))))
(if-not-zero (account-instruction---touches-current-account) (eq! NSR (+ 1 (- 1 CMC))))
(debug (eq! XAHOY CMC))
(debug (eq! XAHOY stack/OOGX))))

Expand All @@ -103,19 +106,19 @@
(if-not-zero (account-instruction---touches-foreign-account)
(if-zero CONTEXT_WILL_REVERT
(eq! NSR
(+ (shift PEEK_AT_ACCOUNT ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(+ (shift PEEK_AT_ACCOUNT ROFF_ACC___ACCOUNT_DOING_ROW)
(* CMC (shift PEEK_AT_CONTEXT 2))))
(eq! NSR
(+ (shift PEEK_AT_ACCOUNT ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(shift PEEK_AT_ACCOUNT ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW)
(+ (shift PEEK_AT_ACCOUNT ROFF_ACC___ACCOUNT_DOING_ROW)
(shift PEEK_AT_ACCOUNT ROFF_ACC___ACCOUNT_UNDOING_ROW)
(* CMC (shift PEEK_AT_CONTEXT 3))))))
(if-not-zero (account-instruction---no-trimming)
(if-not-zero (account-instruction---touches-current-account)
(if-zero XAHOY
(eq! NSR
(+ (shift PEEK_AT_CONTEXT ROW_OFFSET___ACC_FAMILY___CONTEXT_ROW)
(shift PEEK_AT_ACCOUNT ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)))
(+ (shift PEEK_AT_CONTEXT ROFF_ACC___CONTEXT_ROW)
(shift PEEK_AT_ACCOUNT ROFF_ACC___ACCOUNT_READING_ROW)))
(eq! NSR
(shift PEEK_AT_CONTEXT 1))))))
(shift PEEK_AT_CONTEXT ROFF_ACC___CONTEXT_ROW))))))

(defconstraint account-instruction---setting-gas-cost
(:guard (account-instruction---standard-hypothesis))
Expand All @@ -125,7 +128,7 @@
(eq! GAS_COST
(+ (* (account-instruction---foreign-address-warmth) GAS_CONST_G_WARM_ACCESS)
(* (- 1 (account-instruction---foreign-address-warmth)) GAS_CONST_G_COLD_ACCOUNT_ACCESS))))
(if-not-zero (account-instruction---no-trimming)
(if-not-zero (account-instruction---touches-current-account)
(eq! GAS_COST
stack/STATIC_GAS))))

Expand All @@ -138,13 +141,13 @@
(eq! account/ROMLEX_FLAG 1)
(eq! account/TRM_RAW_ADDRESS_HI (account-instruction---raw-address-hi))
(eq! account/ADDRESS_LO (account-instruction---raw-address-lo))
(account-same-balance ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-same-nonce ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-same-code ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-same-deployment-number-and-status ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-turn-on-warmth ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-same-marked-for-selfdestruct ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(DOM-SUB-stamps---standard ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW 0)))))
(account-same-balance ROFF_ACC___ACCOUNT_DOING_ROW)
(account-same-nonce ROFF_ACC___ACCOUNT_DOING_ROW)
(account-same-code ROFF_ACC___ACCOUNT_DOING_ROW)
(account-same-deployment-number-and-status ROFF_ACC___ACCOUNT_DOING_ROW)
(account-turn-on-warmth ROFF_ACC___ACCOUNT_DOING_ROW)
(account-same-marked-for-selfdestruct ROFF_ACC___ACCOUNT_DOING_ROW)
(DOM-SUB-stamps---standard ROFF_ACC___ACCOUNT_DOING_ROW 0)))))


(defconstraint account-instruction---trimming-case-garnishing-non-stack-row-undo-account-row
Expand All @@ -154,47 +157,47 @@
(if-not-zero (account-instruction---touches-foreign-account)
(if-not-zero CONTEXT_WILL_REVERT
(begin
(account-same-address-as ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-undo-balance-update ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-undo-nonce-update ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-undo-code-update ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-undo-deployment-status-update ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-undo-warmth-update ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW)
(account-same-marked-for-selfdestruct ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW)
(DOM-SUB-stamps---revert-with-current ROW_OFFSET___ACC_FAMILY___ACCOUNT_UNDOING_ROW 1))))))
(account-same-address-as ROFF_ACC___ACCOUNT_UNDOING_ROW ROFF_ACC___ACCOUNT_DOING_ROW)
(account-undo-balance-update ROFF_ACC___ACCOUNT_UNDOING_ROW ROFF_ACC___ACCOUNT_DOING_ROW)
(account-undo-nonce-update ROFF_ACC___ACCOUNT_UNDOING_ROW ROFF_ACC___ACCOUNT_DOING_ROW)
(account-undo-code-update ROFF_ACC___ACCOUNT_UNDOING_ROW ROFF_ACC___ACCOUNT_DOING_ROW)
(account-undo-deployment-status-update ROFF_ACC___ACCOUNT_UNDOING_ROW ROFF_ACC___ACCOUNT_DOING_ROW)
(account-undo-warmth-update ROFF_ACC___ACCOUNT_UNDOING_ROW ROFF_ACC___ACCOUNT_DOING_ROW)
(account-same-marked-for-selfdestruct ROFF_ACC___ACCOUNT_UNDOING_ROW)
(DOM-SUB-stamps---revert-with-current ROFF_ACC___ACCOUNT_UNDOING_ROW 1))))))

(defconstraint account-instruction---non-trim-case
(:guard (account-instruction---standard-hypothesis))
;;
(begin
(if-not-zero (account-instruction---no-trimming)
(if-not-zero (account-instruction---touches-current-account)
(if-zero XAHOY
(begin
(read-context-data 1 CONTEXT_NUMBER)
(account-same-balance ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)
(account-same-nonce ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)
(account-same-code ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)
(account-same-deployment-number-and-status ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)
(account-turn-on-warmth ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)
(account-same-marked-for-selfdestruct ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW)
(DOM-SUB-stamps---standard ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW 0)
(read-context-data ROFF_ACC___CONTEXT_ROW CONTEXT_NUMBER)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using constant for 1

(account-same-balance ROFF_ACC___ACCOUNT_READING_ROW)
(account-same-nonce ROFF_ACC___ACCOUNT_READING_ROW)
(account-same-code ROFF_ACC___ACCOUNT_READING_ROW)
(account-same-deployment-number-and-status ROFF_ACC___ACCOUNT_READING_ROW)
(account-turn-on-warmth ROFF_ACC___ACCOUNT_READING_ROW)
(account-same-marked-for-selfdestruct ROFF_ACC___ACCOUNT_READING_ROW)
(DOM-SUB-stamps---standard ROFF_ACC___ACCOUNT_READING_ROW 0)
(if-zero (account-instruction---is-CODESIZE)
;; DEC_FLAG_4 = 0
(begin
(eq! (shift account/ADDRESS_HI ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW) (account-instruction---account-address-hi))
(eq! (shift account/ADDRESS_LO ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW) (account-instruction---account-address-lo)))
(eq! (shift account/ADDRESS_HI ROFF_ACC___ACCOUNT_READING_ROW) (account-instruction---account-address-hi))
(eq! (shift account/ADDRESS_LO ROFF_ACC___ACCOUNT_READING_ROW) (account-instruction---account-address-lo)))
;; DEC_FLAG_4 = 1
(begin
(eq! (shift account/ADDRESS_HI ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW) (account-instruction---byte-code-address-hi))
(eq! (shift account/ADDRESS_LO ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW) (account-instruction---byte-code-address-lo)))))))))
(eq! (shift account/ADDRESS_HI ROFF_ACC___ACCOUNT_READING_ROW) (account-instruction---byte-code-address-hi))
(eq! (shift account/ADDRESS_LO ROFF_ACC___ACCOUNT_READING_ROW) (account-instruction---byte-code-address-lo)))))))))


(defun (account-instruction---foreign-balance) (shift account/BALANCE ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW ))
(defun (account-instruction---foreign-code-size) (shift (* account/CODE_SIZE account/HAS_CODE) ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW ))
(defun (account-instruction---foreign-code-hash-hi) (shift (* account/CODE_HASH_HI account/EXISTS) ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW ))
(defun (account-instruction---foreign-code-hash-lo) (shift (* account/CODE_HASH_LO account/EXISTS) ROW_OFFSET___ACC_FAMILY___ACCOUNT_DOING_ROW ))
(defun (account-instruction---current-code-size) (shift account/CODE_SIZE ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW))
(defun (account-instruction---current-balance) (shift account/BALANCE ROW_OFFSET___ACC_FAMILY___ACCOUNT_READING_ROW))
(defun (account-instruction---foreign-balance) (shift account/BALANCE ROFF_ACC___ACCOUNT_DOING_ROW ))
(defun (account-instruction---foreign-code-size) (shift (* account/CODE_SIZE account/HAS_CODE) ROFF_ACC___ACCOUNT_DOING_ROW ))
(defun (account-instruction---foreign-code-hash-hi) (shift (* account/CODE_HASH_HI account/EXISTS) ROFF_ACC___ACCOUNT_DOING_ROW ))
(defun (account-instruction---foreign-code-hash-lo) (shift (* account/CODE_HASH_LO account/EXISTS) ROFF_ACC___ACCOUNT_DOING_ROW ))
(defun (account-instruction---current-code-size) (shift account/CODE_SIZE ROFF_ACC___ACCOUNT_READING_ROW))
(defun (account-instruction---current-balance) (shift account/BALANCE ROFF_ACC___ACCOUNT_READING_ROW))


(defconstraint account-instruction---value-constraints---the-BALANCE-case
Expand Down
Loading