Skip to content

Commit

Permalink
[feat]: Annotate Keccak + Others Hints (#388)
Browse files Browse the repository at this point in the history
* keccak hints description

* add memory hints description

* rename memcpy to others

* use hyphen for operanders description

* resolve conflict

* add hyphen to EC + blake hints
  • Loading branch information
TAdev0 committed May 7, 2024
1 parent ddb68e5 commit 998c901
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
6 changes: 3 additions & 3 deletions pkg/hintrunner/zero/zerohint.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ func GetHintFromCode(program *zero.ZeroProgram, rawHint zero.Hint, hintPC uint64
return createSquashDictInnerAssertLenKeysHinter()
// Other hints
case allocSegmentCode:
return createAllocSegmentHinter(resolver)
return createAllocSegmentHinter()
case vmEnterScopeCode:
return createVMEnterScopeHinter(resolver)
return createVMEnterScopeHinter()
case memcpyEnterScopeCode:
return createMemcpyEnterScopeHinter(resolver)
case vmExitScopeCode:
return createVMExitScopeHinter(resolver)
return createVMExitScopeHinter()
case testAssignCode:
return createTestAssignHinter(resolver)
default:
Expand Down
6 changes: 3 additions & 3 deletions pkg/hintrunner/zero/zerohint_blake.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
// Blake2sAddUint256 hint serializes a `uint256` number in a Blake2s compatible way
//
// `newBlake2sAddUint256Hint` takes 3 operanders as arguments
// `low` and `high` are the low and high parts of a `uint256` variable,
// each of them being a `felt` interpreted as a `uint128`
// `data` is a pointer to the starting address in memory where to write the result of the hint
// - `low` and `high` are the low and high parts of a `uint256` variable,
// each of them being a `felt` interpreted as a `uint128`
// - `data` is a pointer to the starting address in memory where to write the result of the hint
//
// `newBlake2sAddUint256Hint` splits each part of the `uint256` in 4 `u32` and writes the result in memory
// This hint is available in Big-Endian or Little-Endian representation
Expand Down
18 changes: 9 additions & 9 deletions pkg/hintrunner/zero/zerohint_ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// EcNegate hint negates the y-coordinate of a point on an elliptic curve modulo SECP_P
//
// `newEcNegateHint` takes 1 operander as argument
// `point` is the point on an elliptic curve to operate on
// - `point` is the point on an elliptic curve to operate on
//
// `newEcNegateHint` assigns the result as `value` in the current scope
func newEcNegateHint(point hinter.ResOperander) hinter.Hinter {
Expand Down Expand Up @@ -80,7 +80,7 @@ func createEcNegateHinter(resolver hintReferenceResolver) (hinter.Hinter, error)
// NondetBigint3V1 hint writes a value to a specified segment of memory
//
// `newNondetBigint3V1Hint` takes 1 operander as argument
// `res` is the location in memory where to write the result
// - `res` is the location in memory where to write the result
//
// `newNondetBigint3V1Hint` uses `SecPSplit` to split the value in 3 felts and writes the result in memory
func newNondetBigint3V1Hint(res hinter.ResOperander) hinter.Hinter {
Expand Down Expand Up @@ -191,8 +191,8 @@ func createFastEcAddAssignNewYHinter() (hinter.Hinter, error) {
// FastEcAddAssignNewX hint computes a new x-coordinate for fast elliptic curve addition
//
// `newFastEcAddAssignNewXHint` takes 3 operanders as arguments
// `slope` is the slope of the line connecting `point0` and `point1`
// `point0` and `point1` are 2 points on an elliptic curve
// - `slope` is the slope of the line connecting `point0` and `point1`
// - `point0` and `point1` are 2 points on an elliptic curve
//
// `newFastEcAddAssignNewXHint` assigns the new x-coordinate as `value` in the current scope
// It also assigns `slope`, `x0`, `y0` and `new_x` in the current scope
Expand Down Expand Up @@ -338,7 +338,7 @@ func createFastEcAddAssignNewXHinter(resolver hintReferenceResolver) (hinter.Hin
// EcDoubleSlopeV1 hint computes the slope for doubling a point on an elliptic curve
//
// `newEcDoubleSlopeV1Hint` takes 1 operander as argument
// `point` is the point on an elliptic curve to operate on
// - `point` is the point on an elliptic curve to operate on
//
// `newEcDoubleSlopeV1Hint` assigns the `slope` result as `value` in the current scope
func newEcDoubleSlopeV1Hint(point hinter.ResOperander) hinter.Hinter {
Expand Down Expand Up @@ -422,8 +422,8 @@ func createEcDoubleSlopeV1Hinter(resolver hintReferenceResolver) (hinter.Hinter,
// EcDoubleAssignNewXV1 hint computes a new x-coordinate for a point being doubled on an elliptic curve
//
// `newEcDoubleAssignNewXV1Hint` takes 2 operanders as arguments
// `slope` is the slope for doubling a point, computed with EcDoubleSlopeV1 hint
// `point` is the point on an elliptic curve to operate on
// - `slope` is the slope for doubling a point, computed with EcDoubleSlopeV1 hint
// - `point` is the point on an elliptic curve to operate on
//
// `newEcDoubleAssignNewXV1Hint` assigns the `new_x` result as `value` in the current scope
// It also assigns `slope`, `x`, `y` and `new_x` in the current scope
Expand Down Expand Up @@ -541,8 +541,8 @@ func createEcDoubleAssignNewXV1Hinter(resolver hintReferenceResolver) (hinter.Hi
// ComputeSlopeV1Hint hint computes the slope between two points on an elliptic curve
//
// `newComputeSlopeV1Hint` takes 2 operanders as arguments
// `point0` is the first point on an elliptic curve to operate on
// `point1` is the second point on an elliptic curve to operate on
// - `point0` is the first point on an elliptic curve to operate on
// - `point1` is the second point on an elliptic curve to operate on
//
// `newComputeSlopeV1Hint` assigns the `slope` result as `value` in the current scope
func newComputeSlopeV1Hint(point0, point1 hinter.ResOperander) hinter.Hinter {
Expand Down
9 changes: 9 additions & 0 deletions pkg/hintrunner/zero/zerohint_keccak.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import (
"github.com/holiman/uint256"
)

// KeccakWriteArgs hint writes Keccak function arguments in memory
//
// `newKeccakWriteArgsHint` takes 3 operanders as arguments
// - `inputs` is the address in memory where to write Keccak arguments
// - `low` is the low part of the `uint256` argument for the Keccac function
// - `high` is the high part of the `uint256` argument for the Keccac function
//
// The `low` and `high` parts are splitted in 64-bit integers
// Ultimately, the result is written into 4 memory cells
func newKeccakWriteArgsHint(inputs, low, high hinter.ResOperander) hinter.Hinter {
name := "KeccakWriteArgs"
return &GenericZeroHinter{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
VM "github.com/NethermindEth/cairo-vm-go/pkg/vm"
)

func createAllocSegmentHinter(resolver hintReferenceResolver) (hinter.Hinter, error) {
// AllocSegment hint adds a new segment to the Cairo VM memory
func createAllocSegmentHinter() (hinter.Hinter, error) {
return &core.AllocSegment{Dst: hinter.ApCellRef(0)}, nil
}

func createVMEnterScopeHinter(resolver hintReferenceResolver) (hinter.Hinter, error) {
// VMEnterScope hint enters a new scope in the Cairo VM
func createVMEnterScopeHinter() (hinter.Hinter, error) {
return &GenericZeroHinter{
Name: "VMEnterScope",
Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error {
Expand All @@ -20,6 +22,20 @@ func createVMEnterScopeHinter(resolver hintReferenceResolver) (hinter.Hinter, er
}, nil
}

// VMExitScop hint exits the current scope in the Cairo VM
func createVMExitScopeHinter() (hinter.Hinter, error) {
return &GenericZeroHinter{
Name: "VMExitScope",
Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error {
return ctx.ScopeManager.ExitScope()
},
}, nil
}

// MemcpyEnterScopeHint hint enters a new scope for the memory copy operation with a specified length
//
// `newMemcpyEnterScopeHint` takes 1 operander as argument
// - `len` is the length value that is added in the new scope
func newMemcpyEnterScopeHint(len hinter.ResOperander) hinter.Hinter {
return &GenericZeroHinter{
Name: "MemcpyEnterScope",
Expand All @@ -29,6 +45,7 @@ func newMemcpyEnterScopeHint(len hinter.ResOperander) hinter.Hinter {
if err != nil {
return err
}

ctx.ScopeManager.EnterScope(map[string]any{"n": len})
return nil
},
Expand All @@ -42,12 +59,3 @@ func createMemcpyEnterScopeHinter(resolver hintReferenceResolver) (hinter.Hinter
}
return newMemcpyEnterScopeHint(len), nil
}

func createVMExitScopeHinter(resolver hintReferenceResolver) (hinter.Hinter, error) {
return &GenericZeroHinter{
Name: "VMExitScope",
Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error {
return ctx.ScopeManager.ExitScope()
},
}, nil
}
File renamed without changes.

0 comments on commit 998c901

Please sign in to comment.