Skip to content

Commit 81e9c75

Browse files
committed
support optional padding specifiers
This adds support for (optional) padding specifiers on the parameters of assembly functions. This allows one to effectively provide a "witness" which is always used within the padding region.
1 parent cbee57f commit 81e9c75

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

pkg/asm/assembler/parser.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ func (p *Parser[F]) parseArgsList(kind schema.RegisterType) ([]io.Register, []so
170170
return nil, errs
171171
}
172172
}
173-
// parse name & type
173+
// parse name, type & optional padding
174174
if arg, errs = p.parseIdentifier(); len(errs) > 0 {
175175
return nil, errs
176+
} else if padding, errs = p.parseOptionalPadding(); len(errs) > 0 {
177+
return nil, errs
176178
} else if width, errs = p.parseType(); len(errs) > 0 {
177179
return nil, errs
178180
}
@@ -185,6 +187,23 @@ func (p *Parser[F]) parseArgsList(kind schema.RegisterType) ([]io.Register, []so
185187
return regs, nil
186188
}
187189

190+
func (p *Parser[F]) parseOptionalPadding() (big.Int, []source.SyntaxError) {
191+
var (
192+
padding big.Int
193+
errs []source.SyntaxError
194+
lookahead lex.Token
195+
)
196+
//
197+
if !p.match(EQUALS) {
198+
// no optional padding
199+
return padding, nil
200+
} else if lookahead, errs = p.expect(NUMBER); len(errs) > 0 {
201+
return padding, errs
202+
}
203+
//
204+
return p.number(lookahead), nil
205+
}
206+
188207
func (p *Parser[F]) parseType() (uint, []source.SyntaxError) {
189208
var (
190209
lookahead = p.lookahead()

testdata/asm/add.zkasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; SUB (ARG_1 - ARG_2) % 2^256 0x03
77
;;
88
;; Both of these operate on u256 words with "wrap around" semantics.
9-
fn add(INST u8, ARG_1 u256, ARG_2 u256) -> (RES u256) {
9+
fn add(INST=1 u8, ARG_1 u256, ARG_2 u256) -> (RES u256) {
1010
var c u1
1111
;;
1212
if INST == 0x01 goto insn_add

testdata/asm/wcp.zkasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
;; NOTE: an undocumented feature of the WCP module is that it is often
2525
;; used by other modules to additionally ensure that the given
2626
;; arguments are "small" (i.e. within their designated bitwidths).
27-
fn wcp(INST u8, ARGUMENT_1 u256, ARGUMENT_2 u256) -> (RESULT u1) {
27+
fn wcp(INST=1 u8, ARGUMENT_1 u256, ARGUMENT_2 u256) -> (RESULT u1) {
2828
var delta u256
2929
var arg1bits, arg2bits u255
3030
var borrow,arg1sign,arg2sign u1

0 commit comments

Comments
 (0)