-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add available gas and user args (#677)
* Add parsing logic for input user args * Add flags for available gas, input user args, writing args to memory * Fix unit tests for user arguments parsing * Lint the PR * Add user args to hint context * Refactor the code * Fix unconditional append of ExternalWriteArgsToMemory, bug fixes in integration tests * Add fixes of the call size calculation and include ExternalWriteArgsToMemory hint when gas present * Add layouts for integration tests * Add error handling * Fixes in entry code generation * Address changes mentioned in a discussion * Add comment regarding writing to memory in a hint for the future reference in the integration tests with args * Changes in calculations of the initial PC offset, CALL opcode offset incremented by mainFuncOffset, writing user args to the AP in the hint * Turn back VM config to private field * Add error handling on assign of `userArgs` to the initial scope * Lint project * Bump go version from 1.20 -> 1.21 (#678) * Bump go version from 1.20 -> 1.21 * Update golangci-lint * Simplify the Makefile * Correction in the makefile
- Loading branch information
1 parent
cd04099
commit 5eb27ab
Showing
17 changed files
with
326 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package starknet | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/consensys/gnark-crypto/ecc/stark-curve/fp" | ||
) | ||
|
||
type CairoFuncArgs struct { | ||
Single *fp.Element | ||
Array []fp.Element | ||
} | ||
|
||
func ParseCairoProgramArgs(input string) ([]CairoFuncArgs, error) { | ||
re := regexp.MustCompile(`\[[^\]]*\]|\S+`) | ||
tokens := re.FindAllString(input, -1) | ||
var result []CairoFuncArgs | ||
|
||
parseValueToFelt := func(token string) (*fp.Element, error) { | ||
felt, err := new(fp.Element).SetString(token) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid felt value: %v", err) | ||
} | ||
return felt, nil | ||
} | ||
|
||
for _, token := range tokens { | ||
if single, err := parseValueToFelt(token); err == nil { | ||
result = append(result, CairoFuncArgs{ | ||
Single: single, | ||
Array: nil, | ||
}) | ||
} else if strings.HasPrefix(token, "[") && strings.HasSuffix(token, "]") { | ||
arrayStr := strings.Trim(token, "[]") | ||
arrayElements := strings.Fields(arrayStr) | ||
array := make([]fp.Element, len(arrayElements)) | ||
for i, element := range arrayElements { | ||
single, err := parseValueToFelt(element) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid felt value in array: %v", err) | ||
} | ||
array[i] = *single | ||
} | ||
result = append(result, CairoFuncArgs{ | ||
Single: nil, | ||
Array: array, | ||
}) | ||
} else { | ||
return nil, fmt.Errorf("invalid token: %s", token) | ||
} | ||
} | ||
|
||
return result, nil | ||
} |
Oops, something went wrong.