diff --git a/pkg/hintrunner/zero/zerohint.go b/pkg/hintrunner/zero/zerohint.go index fb656dbfb..caf7854ec 100644 --- a/pkg/hintrunner/zero/zerohint.go +++ b/pkg/hintrunner/zero/zerohint.go @@ -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: diff --git a/pkg/hintrunner/zero/zerohint_blake.go b/pkg/hintrunner/zero/zerohint_blake.go index 362a60af1..7b4f2d340 100644 --- a/pkg/hintrunner/zero/zerohint_blake.go +++ b/pkg/hintrunner/zero/zerohint_blake.go @@ -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 diff --git a/pkg/hintrunner/zero/zerohint_ec.go b/pkg/hintrunner/zero/zerohint_ec.go index 69a529f48..c13275b23 100644 --- a/pkg/hintrunner/zero/zerohint_ec.go +++ b/pkg/hintrunner/zero/zerohint_ec.go @@ -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 { @@ -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 { @@ -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 @@ -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 { @@ -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 @@ -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 { diff --git a/pkg/hintrunner/zero/zerohint_keccak.go b/pkg/hintrunner/zero/zerohint_keccak.go index dce85920e..1bc6f5aac 100644 --- a/pkg/hintrunner/zero/zerohint_keccak.go +++ b/pkg/hintrunner/zero/zerohint_keccak.go @@ -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{ diff --git a/pkg/hintrunner/zero/zerohint_memcpy.go b/pkg/hintrunner/zero/zerohint_others.go similarity index 68% rename from pkg/hintrunner/zero/zerohint_memcpy.go rename to pkg/hintrunner/zero/zerohint_others.go index bef67555b..6a79d07d7 100644 --- a/pkg/hintrunner/zero/zerohint_memcpy.go +++ b/pkg/hintrunner/zero/zerohint_others.go @@ -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 { @@ -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", @@ -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 }, @@ -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 -} diff --git a/pkg/hintrunner/zero/zerohint_memcpy_test.go b/pkg/hintrunner/zero/zerohint_others_test.go similarity index 100% rename from pkg/hintrunner/zero/zerohint_memcpy_test.go rename to pkg/hintrunner/zero/zerohint_others_test.go