Skip to content

Commit

Permalink
Fix cairo0 hints
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan committed Oct 29, 2024
1 parent 4788f92 commit 34024d5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23.1

require (
github.com/Masterminds/semver/v3 v3.3.0
github.com/NethermindEth/cairo-vm-go v0.0.0-20241022093807-167daddfd4a4
github.com/bits-and-blooms/bitset v1.14.3
github.com/bits-and-blooms/bloom/v3 v3.7.0
github.com/cockroachdb/pebble v1.1.2
Expand Down Expand Up @@ -41,6 +42,7 @@ require (
require (
github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/alecthomas/participle/v2 v2.0.0 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/NethermindEth/cairo-vm-go v0.0.0-20241022093807-167daddfd4a4 h1:sAdffkxtfPBOGjxhyHUC4q0yUQJ/0ut8Rci+hctn/M4=
github.com/NethermindEth/cairo-vm-go v0.0.0-20241022093807-167daddfd4a4/go.mod h1:U1ls2WSMF5cxRI7jjm4G7mnS8f/XiFafMHCikN+tTQw=
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y=
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down Expand Up @@ -228,6 +236,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4=
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
Expand Down
31 changes: 24 additions & 7 deletions rpc/executables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package rpc
import (
"encoding/json"

hintRunnerZero "github.com/NethermindEth/cairo-vm-go/pkg/hintrunner/zero"
"github.com/NethermindEth/cairo-vm-go/pkg/parsers/zero"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/jsonrpc"
Expand Down Expand Up @@ -63,16 +65,31 @@ func adaptCairo0Class(class *core.Cairo0Class) (*CasmCompiledContractClass, erro
return nil, err
}

var cairo0 struct {
Prime string `json:"prime"`
CompilerVersion string `json:"compiler_version,omitempty"`
Data []*felt.Felt `json:"data"`
}
var cairo0 zero.ZeroProgram
err = json.Unmarshal(program, &cairo0)
if err != nil {
return nil, err
}

var bytecode []*felt.Felt
for _, str := range cairo0.Data {
f, err := new(felt.Felt).SetString(str)
if err != nil {
return nil, err
}
bytecode = append(bytecode, f)
}

hints, err := hintRunnerZero.GetZeroHints(&cairo0)
if err != nil {
return nil, err
}

rawHints, err := json.Marshal(hints)
if err != nil {
return nil, err
}

adaptEntryPoint := func(ep core.EntryPoint) CasmEntryPoint {
return CasmEntryPoint{
Offset: ep.Offset,
Expand All @@ -88,9 +105,9 @@ func adaptCairo0Class(class *core.Cairo0Class) (*CasmCompiledContractClass, erro
L1Handler: utils.Map(class.L1Handlers, adaptEntryPoint),
},
Prime: cairo0.Prime,
Bytecode: cairo0.Data,
Bytecode: bytecode,
CompilerVersion: cairo0.CompilerVersion,
Hints: nil, // todo fill this field
Hints: json.RawMessage(rawHints),
BytecodeSegmentLengths: nil, // Cairo 0 classes don't have this field (it was introduced since Sierra 1.5.0)
}
return result, nil
Expand Down

0 comments on commit 34024d5

Please sign in to comment.