{"id":19460131,"url":"https://github.com/offchainlabs/methodical-ssz","last_synced_at":"2025-04-25T07:32:45.628Z","repository":{"id":81889219,"uuid":"601810259","full_name":"OffchainLabs/methodical-ssz","owner":"OffchainLabs","description":"Code generation tool for adding Ethereum SimpleSerialiZe support methods to existing go types","archived":false,"fork":false,"pushed_at":"2024-07-12T20:14:39.000Z","size":259,"stargazers_count":18,"open_issues_count":3,"forks_count":5,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-07-13T00:39:53.787Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OffchainLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-14T21:43:43.000Z","updated_at":"2024-07-13T00:39:53.788Z","dependencies_parsed_at":null,"dependency_job_id":"51d39ae8-9702-4e0c-8d48-6d72cb97546d","html_url":"https://github.com/OffchainLabs/methodical-ssz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fmethodical-ssz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fmethodical-ssz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fmethodical-ssz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fmethodical-ssz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OffchainLabs","download_url":"https://codeload.github.com/OffchainLabs/methodical-ssz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223989485,"owners_count":17237089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T17:35:41.152Z","updated_at":"2024-11-10T17:35:41.795Z","avatar_url":"https://github.com/OffchainLabs.png","language":"Go","readme":"methodical-ssz\n--------------\n\nThis tool generates code that uses the [prysm fork](https://github.com/prysmaticlabs/fastssz/) of the [fastssz api](https://github.com/ferranbt/fastssz/) (with bindings for [go-hashtree](https://github.com/prysmaticlabs/gohashtree) coming very soon!), for marshaling, unmarshaling and merkleization of go types.\n\nGenerate ssz methodsets\n-----------------------\n\n The source types are parsed using `go/types`, which locates the source code for a given package path through go's local package discovery utilities, so a current limitation is that you need to fetch the package to your go package tree before using the tool. This can be done with go get:\n```\ngo get github.com/prysmaticlabs/prysm/v3@v3.2.1\n```\n\nOnce this is done, code generation can be run against go types in the desired package:\n```\ngo run ./cmd/ssz gen --output=beacon-state.ssz.go --type-names BeaconState,BeaconStateAltair,BeaconStateBellatrix github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1\nGenerating methods for github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/BeaconState\nGenerating methods for github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/BeaconStateAltair\nGenerating methods for github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/BeaconStateBellatrix\n```\n\nThe generated file can then be placed in a local directory for the source package so that the generated methods become part of the methodset of the source type.\n\nGenerate spectests for a package\n--------------------------------\n\nThis tool has a subcommand to generate go tests from the `ssz_static` tests in the ethereum/consensus-spec-tests repository. The generated tests can be run as normal go tests, which is helpful in identifying specific failure cases and walking through generated code with a debugger.\n\nspectest tarball\n================\n\nTo get the spec test fixtures for codegen, go to the [consensus-spec-test repository releases page](https://github.com/ethereum/consensus-spec-tests/releases) and download the most recent `pre-release` or `latest` spec tests release.\n```\ncurl -L https://github.com/ethereum/consensus-spec-tests/releases/download/v1.3.0-rc.2-hotfix/mainnet.tar.gz \u003e mainnet-v1.3.0-rc.2.tar.gz\n```\n\nyaml config\n===========\n\nThe spectest generation tool needs a mapping between go types and consensus spec container types. This mapping is described as a yaml config file. The mappings for prysm types are committed to the repo in a go `testdata` fixture directory, in `specs/testdata/prysm.yaml`. The following snippet illustrates the format:\n```\npackage: github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1\npreset: mainnet\ndefs:\n  - fork: phase0\n    types:\n      - name: AggregateAndProof\n        type_name: AggregateAttestationAndProof\n      - name: Attestation\n      # ...\n      - name: BeaconBlock\n      # ...\n  - fork: altair\n    types:\n      - name: BeaconBlock\n        type_name: BeaconBlockAltair\n      - name: BeaconBlockBody\n        type_name: BeaconBlockBodyAltair\n```\n`package` is the go package containing the types for code generation. Each yaml holds the description for one go package. `preset` is one of mainnet or minimal. At this time only mainnet is supported as preset customization is specific to an implementation's build tooling. `defs` contains a list of yaml objects, with the `fork` key matching the fork directory in the spectest layout, and the `types` key containing a list of objects connecting the `name` of the type from consensus specs / spectest directory names, to the `type_name` found in the `package`. If `type_name` is not present, `name` is the default, so for go types with the same spelling and capitalization as the consensus type, the `name` field alone is all that's needed to specify the type.\n\nThe config reader processes type mappings in canonical fork order, so if a type's schema has not changed since the previous fork, it does not need to be redeclared. For instance the mapping for `Attestation` is only described once in the `phase0` mapping; the same go type will be used to execute the spectest for the Attestation value for all subsequent forks. `BeaconBlock`, on the other hand, has been redefined at every fork, so tests will use `BeaconBlockAltair` for spectests in the `altair` tree and so on. Any types observed in the tarball that don't have an entry defined in the config yaml will be skipped with a warning.\n\nspectest subcommand\n===================\n\nThe `generated` directory is a good place to stick generated tests as it is already in the .gitignore for the project. Assuming the tarball in the example above has been downloaded to the repo directory, running the following command there will generate spectests for all prysm types described in the test fixture yaml config:\n```\ngo run ./cmd/ssz spectest --release-uri=file://$PWD/mainnet-v1.3.0-rc.2.tar.gz --config=$PWD/specs/testdata/prysm.yaml --output=$PWD/generated\n```\n\nRun the spectest like normal go tests:\n```\ngo test ./generated\nok  \tgithub.com/OffchainLabs/methodical-ssz/generated\t1.003s\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchainlabs%2Fmethodical-ssz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffchainlabs%2Fmethodical-ssz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchainlabs%2Fmethodical-ssz/lists"}