github.com/consensys/gnark@v0.11.0/constraint/log.go (about)

     1  // Copyright 2020 ConsenSys AG
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package constraint
    16  
    17  import (
    18  	"strings"
    19  )
    20  
    21  // LogEntry is used as a shared data structure between the frontend and the backend
    22  // to represent string values (in logs or debug info) where a value is not known at compile time
    23  // (which is the case for variables that need to be resolved in the R1CS)
    24  type LogEntry struct {
    25  	Caller    string
    26  	Format    string
    27  	ToResolve []LinearExpression // TODO @gbotrel we could store here a struct with a flag that says if we expand or evaluate the expression
    28  	Stack     []int
    29  }
    30  
    31  func (l *LogEntry) WriteVariable(le LinearExpression, sbb *strings.Builder) {
    32  	// 77 correspond to the ~len(4 word modulus) in base10 string
    33  	const elSize = 77
    34  	sbb.Grow(len(le) * elSize)
    35  	sbb.WriteString("%s")
    36  	l.ToResolve = append(l.ToResolve, le)
    37  }