validate

package
v1.2.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ControlFlow

func ControlFlow(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError

ControlFlow checks for issues related to the control-flow of a function. For example, where a register is not definitely assigned before being used. Or, a control-flow path exists which is not terminated with ret. This is implemented using a straightforward dataflow analysis. One aspect worth noting is that the dataflow sets hold true for registers which are undefined, and false for registers which are defined.

func CycleDetection

func CycleDetection(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError

CycleDetection traverses the program and detects cyclic definitions in type constants and aliases.

func DebugFunctions

func DebugFunctions(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError

DebugFunctions checks that every function marked with the #[debug] annotation is safe to elide. Calls to debug functions are dropped entirely during code generation unless verbose mode is enabled (like printf statements), so eliding them must not change the observable state of the program. Specifically, a debug function must not:

(1) declare any return values;

(2) write to a writable memory (i.e. a RAM or write-once memory);

(3) call a function which is not itself marked #[debug].

Observe that (3) is (for now) deliberately conservative: it rejects calls to any non-debug function, even one which cannot access memory. Combined with (1) and (2), this ensures nothing reachable from a debug call can affect the observable state of the program.

func EntryPoint

func EntryPoint(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError

EntryPoint checks that the program's entry point (the function named "main", if any) is well-formed. The machine boots "main" with a fresh stack frame whose registers are all zero — there is no caller to supply arguments — so any declared parameter would silently read as zero in every execution mode (reference interpreter, bytecode and generated Go alike). Program inputs must instead flow through declared input memories, which are initialised from the supplied inputs at boot time. Hence, an entry point declaring parameters is almost certainly a mistake, and is rejected here.

func InlineFunctions

func InlineFunctions(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError

InlineFunctions checks that every function marked with the #[inline] annotation can actually be inlined at its call sites (and subsequently removed). Specifically, an inlined function must not be:

(1) the entry function "main", since this must remain to boot the machine;

(2) marked #[native], since native functions have no body to inline;

(3) (mutually) recursive with other inlined functions, since inlining such functions can never terminate.

Observe that (3) only rejects recursive cycles consisting entirely of inlined functions. Recursion through a non-inlined function is fine, since the residual call to that function simply remains in the inlined body.

func Typing

func Typing(program ast.Program, field field.Config, srcmaps source.Maps[any]) []source.SyntaxError

Typing validates that each declaration in a program is "correctly typed". For example, the following constant declaration is ill-typed:

constant u8 MAX_U8 = 256

The reason being that the constant's value does not fit in a u8. Likewise, this set of declarations are ill-typed:

 public input u8[u8] ROM

	function f(val u8) -> (r u10) {
	  r = ROM + 1
	  return
	}

The problem above is that ROM is an input memory and, hence, ROM+1 does not make sense.

Types

type LVal

type LVal = lval.LVal[symbol.Resolved]

LVal is a convenient alias.

type Stmt

type Stmt = stmt.Stmt[symbol.Resolved]

Stmt is a convenient alias.

type Type

type Type = data.Type[symbol.Resolved]

Type is a convenient alias.

type TypeChecker

type TypeChecker struct {
	// contains filtered or unexported fields
}

TypeChecker embodies information needed for type checking a given program.

type VariableMap

type VariableMap = variable.Map[symbol.Resolved]

VariableMap is a convenient alias.

type Worklist

type Worklist struct {
	// contains filtered or unexported fields
}

Worklist encapsulates the notion of a worklist, along with the necessary dataflow sets for a dataflow analysis algorithm.

func NewWorklist

func NewWorklist(nstates uint, start uint, init bit.Set) Worklist

NewWorklist constructs a new worklist of a given capacity.

func (*Worklist) Empty

func (p *Worklist) Empty() bool

Empty determines whether or not this worklist is empty.

func (*Worklist) Join

func (p *Worklist) Join(pc uint, state bit.Set)

Join joins a given state into the state recorded for a given pc location.

func (*Worklist) Pop

func (p *Worklist) Pop() (uint, bit.Set)

Pop removes the next item from the stack, and also returns the relevant dataflow state.

func (*Worklist) Visited

func (p *Worklist) Visited(pc uint) bool

Visited checks whether a given program point was reached during the analysis.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL