-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add basic air public input technology * Iterate on air private input * Iterate on air private input with bitwise * Iterate on air private input with poseidon * Iterate on air private input with pedersen * Iterate on air private input with ecop * Iterate on air private input with poseidon * Clean up empty json response * Iterate on air private input with ecdsa * Some refactoring * Add TODO * Fix unit test * Refactor air private functionality to respective builtin files * Minor updates --------- Co-authored-by: MaksymMalicki <[email protected]>
- Loading branch information
1 parent
4d93227
commit 636d5eb
Showing
10 changed files
with
539 additions
and
5 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
18 changes: 18 additions & 0 deletions
18
integration_tests/cairo_zero_file_tests/keccak_builtin.starknet_with_keccak.cairo
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,18 @@ | ||
%builtins keccak | ||
from starkware.cairo.common.cairo_builtins import KeccakBuiltin | ||
from starkware.cairo.common.keccak_state import KeccakBuiltinState | ||
|
||
func main{keccak_ptr: KeccakBuiltin*}() { | ||
assert keccak_ptr[0].input = KeccakBuiltinState(1, 2, 3, 4, 5, 6, 7, 8); | ||
let result = keccak_ptr[0].output; | ||
let keccak_ptr = keccak_ptr + KeccakBuiltin.SIZE; | ||
assert result.s0 = 528644516554364142278482415480021626364691973678134577961206; | ||
assert result.s1 = 768681319646568210457759892191562701823009052229295869963057; | ||
assert result.s2 = 1439835513376369408063324968379272676079109225238241190228026; | ||
assert result.s3 = 1150396629165612276474514703759718478742374517669870754478270; | ||
assert result.s4 = 1515147102575186161827863034255579930572231617017100845406254; | ||
assert result.s5 = 1412568161597072838250338588041800080889949791225997426843744; | ||
assert result.s6 = 982235455376248641031519404605670648838699214888770304613539; | ||
assert result.s7 = 1339947803093378278438908448344904300127577306141693325151040; | ||
return (); | ||
} |
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,114 @@ | ||
package runner | ||
|
||
import ( | ||
"github.com/NethermindEth/cairo-vm-go/pkg/vm/builtins" | ||
) | ||
|
||
func (runner *ZeroRunner) GetAirPublicInput() (AirPublicInput, error) { | ||
rcMin, rcMax := runner.getPermRangeCheckLimits() | ||
|
||
// TODO: refactor to reuse earlier computed relocated trace | ||
relocatedTrace := runner.vm.RelocateTrace() | ||
firstTrace := relocatedTrace[0] | ||
lastTrace := relocatedTrace[len(relocatedTrace)-1] | ||
memorySegments := make(map[string]AirMemorySegmentEntry) | ||
// TODO: you need to calculate this for each builtin | ||
memorySegments["program"] = AirMemorySegmentEntry{BeginAddr: firstTrace.Pc, StopPtr: lastTrace.Pc} | ||
memorySegments["execution"] = AirMemorySegmentEntry{BeginAddr: firstTrace.Ap, StopPtr: lastTrace.Ap} | ||
|
||
return AirPublicInput{ | ||
Layout: runner.layout.Name, | ||
RcMin: rcMin, | ||
RcMax: rcMax, | ||
NSteps: len(runner.vm.Trace), | ||
DynamicParams: nil, | ||
// TODO: yet to be implemented fully | ||
MemorySegments: memorySegments, | ||
// TODO: yet to be implemented | ||
PublicMemory: make([]AirPublicMemoryEntry, 0), | ||
}, nil | ||
} | ||
|
||
type AirPublicInput struct { | ||
Layout string `json:"layout"` | ||
RcMin uint16 `json:"rc_min"` | ||
RcMax uint16 `json:"rc_max"` | ||
NSteps int `json:"n_steps"` | ||
DynamicParams interface{} `json:"dynamic_params"` | ||
MemorySegments map[string]AirMemorySegmentEntry `json:"memory_segments"` | ||
PublicMemory []AirPublicMemoryEntry `json:"public_memory"` | ||
} | ||
|
||
type AirMemorySegmentEntry struct { | ||
BeginAddr uint64 `json:"begin_addr"` | ||
StopPtr uint64 `json:"stop_ptr"` | ||
} | ||
|
||
type AirPublicMemoryEntry struct { | ||
Address uint16 `json:"address"` | ||
Value string `json:"value"` | ||
Page uint16 `json:"page"` | ||
} | ||
|
||
func (runner *ZeroRunner) GetAirPrivateInput(tracePath, memoryPath string) (AirPrivateInput, error) { | ||
airPrivateInput := AirPrivateInput{ | ||
TracePath: tracePath, | ||
MemoryPath: memoryPath, | ||
} | ||
|
||
for _, bRunner := range runner.layout.Builtins { | ||
builtinName := bRunner.Runner.String() | ||
builtinSegment, ok := runner.vm.Memory.FindSegmentWithBuiltin(builtinName) | ||
if ok { | ||
// some checks might be missing here | ||
switch builtinName { | ||
case "range_check": | ||
{ | ||
airPrivateInput.RangeCheck = bRunner.Runner.(*builtins.RangeCheck).GetAirPrivateInput(builtinSegment) | ||
} | ||
case "bitwise": | ||
{ | ||
airPrivateInput.Bitwise = bRunner.Runner.(*builtins.Bitwise).GetAirPrivateInput(builtinSegment) | ||
} | ||
case "poseidon": | ||
{ | ||
airPrivateInput.Poseidon = bRunner.Runner.(*builtins.Poseidon).GetAirPrivateInput(builtinSegment) | ||
} | ||
case "pedersen": | ||
{ | ||
airPrivateInput.Pedersen = bRunner.Runner.(*builtins.Pedersen).GetAirPrivateInput(builtinSegment) | ||
} | ||
case "ec_op": | ||
{ | ||
airPrivateInput.EcOp = bRunner.Runner.(*builtins.EcOp).GetAirPrivateInput(builtinSegment) | ||
} | ||
case "keccak": | ||
{ | ||
airPrivateInput.Keccak = bRunner.Runner.(*builtins.Keccak).GetAirPrivateInput(builtinSegment) | ||
} | ||
case "ecdsa": | ||
{ | ||
ecdsaAirPrivateInput, err := bRunner.Runner.(*builtins.ECDSA).GetAirPrivateInput(builtinSegment) | ||
if err != nil { | ||
return AirPrivateInput{}, err | ||
} | ||
airPrivateInput.Ecdsa = ecdsaAirPrivateInput | ||
} | ||
} | ||
} | ||
} | ||
|
||
return airPrivateInput, nil | ||
} | ||
|
||
type AirPrivateInput struct { | ||
TracePath string `json:"trace_path"` | ||
MemoryPath string `json:"memory_path"` | ||
Pedersen []builtins.AirPrivateBuiltinPedersen `json:"pedersen"` | ||
RangeCheck []builtins.AirPrivateBuiltinRangeCheck `json:"range_check"` | ||
Ecdsa []builtins.AirPrivateBuiltinECDSA `json:"ecdsa"` | ||
Bitwise []builtins.AirPrivateBuiltinBitwise `json:"bitwise"` | ||
EcOp []builtins.AirPrivateBuiltinEcOp `json:"ec_op"` | ||
Keccak []builtins.AirPrivateBuiltinKeccak `json:"keccak"` | ||
Poseidon []builtins.AirPrivateBuiltinPoseidon `json:"poseidon"` | ||
} |
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
Oops, something went wrong.