Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
add casm for genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawliet-Chan committed Jan 21, 2024
1 parent a75dbf1 commit 1be3bb9
Show file tree
Hide file tree
Showing 3 changed files with 25,263 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cairoVM/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func DefaultCfg() *Config {
TxVersion: 1,
AccountAddr: "",
AccountCairoVersion: 0,
MaxFee: 10000000,
MaxFee: 0,
}
}
42 changes: 33 additions & 9 deletions cairoVM/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,45 @@ func SetGenesis(state *core.State, dir string) error {
if err != nil {
return err
}
classes := make(map[felt.Felt]core.Class)
declaredClasses := make(map[felt.Felt]core.Class)
deployedContracts := make(map[felt.Felt]*felt.Felt)
declaredV1Classes := make(map[felt.Felt]*felt.Felt)
var (
class core.Class
classHash *felt.Felt
compiledClassHash *felt.Felt
)

for _, file := range files {
filePath := filepath.Join(dir, file.Name())
class, classHash, err := adaptClassAndHash(filePath)
if err != nil {
return err
switch filepath.Ext(filePath) {
case "json":
class, classHash, err = adaptClassAndHash(filePath)
if err != nil {
return err
}
declaredClasses[*classHash] = class
deployedContracts[felt.Zero] = classHash
case "casm":
casmClass, err := contracts.UnmarshalCasmClass(filePath)
if err != nil {
return err
}
compiledClassHash = hash.CompiledClassHash(*casmClass)
}
classes[*classHash] = class
}

declaredV1Classes[*classHash] = compiledClassHash

return state.Update(0, &core.StateUpdate{
BlockHash: &felt.Zero,
NewRoot: &felt.Zero,
OldRoot: &felt.Zero,
StateDiff: core.EmptyStateDiff(),
}, classes)
StateDiff: &core.StateDiff{
DeployedContracts: deployedContracts,
DeclaredV1Classes: declaredV1Classes,
},
}, declaredClasses)
}

func NewDeclare(sierraFileName, casmFileName string) (*core.DeclareTransaction, core.Class, error) {
Expand Down Expand Up @@ -76,8 +100,8 @@ func NewDeclare(sierraFileName, casmFileName string) (*core.DeclareTransaction,
return &tx, coreClass, err
}

func adaptClassAndHash(fileName string) (core.Class, *felt.Felt, error) {
content, err := os.ReadFile(fileName)
func adaptClassAndHash(sierraFileName string) (core.Class, *felt.Felt, error) {
content, err := os.ReadFile(sierraFileName)
if err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit 1be3bb9

Please sign in to comment.