|
1 |
| -There are some must-be-done changes waiting in the generated file. Each area requiring you to add your code is marked with CUSTOM CODE to make them easy to find and modify. |
2 |
| -Additionally there are other files you need to edit to activate your precompile. |
3 |
| -These areas are highlighted with comments "ADD YOUR PRECOMPILE HERE". |
4 |
| -For testing take a look at other precompile tests in contract_test.go and config_test.go in other precompile folders. |
5 |
| -See the tutorial in <https://docs.avax.network/subnets/hello-world-precompile-tutorial> for more information about precompile development. |
6 |
| - |
7 |
| -General guidelines for precompile development: |
8 |
| -1- Set a suitable config key in generated module.go. E.g: "yourPrecompileConfig" |
9 |
| -2- Read the comment and set a suitable contract address in generated module.go. E.g: |
10 |
| -ContractAddress = common.HexToAddress("ASUITABLEHEXADDRESS") |
11 |
| -3- It is recommended to only modify code in the highlighted areas marked with "CUSTOM CODE STARTS HERE". Typically, custom codes are required in only those areas. |
12 |
| -Modifying code outside of these areas should be done with caution and with a deep understanding of how these changes may impact the EVM. |
13 |
| -4- Set gas costs in generated contract.go |
14 |
| -5- Force import your precompile package in precompile/registry/registry.go |
15 |
| -6- Add your config unit tests under generated package config_test.go |
16 |
| -7- Add your contract unit tests under generated package contract_test.go |
17 |
| -8- Additionally you can add a full-fledged VM test for your precompile under plugin/vm/vm_test.go. See existing precompile tests for examples. |
18 |
| -9- Add your solidity interface and test contract to contracts/contracts |
19 |
| -10- Write solidity contract tests for your precompile in contracts/contracts/test |
20 |
| -11- Write TypeScript DS-Test counterparts for your solidity tests in contracts/test |
21 |
| -12- Create your genesis with your precompile enabled in tests/precompile/genesis/ |
22 |
| -13- Create e2e test for your solidity test in tests/precompile/solidity/suites.go |
23 |
| -14- Run your e2e precompile Solidity tests with './scripts/run_ginkgo.sh` |
| 1 | +# Helloworld |
| 2 | + |
| 3 | +There are some must-be-done changes waiting in the generated file. |
| 4 | + |
| 5 | +- Each place requiring you to add your code is marked with `// CUSTOM CODE` |
| 6 | +- Add your precompile where the comment `// ADD YOUR PRECOMPILE HERE` is present, to activate your precompile. |
| 7 | + |
| 8 | +For testing, you can refer to other precompile tests in [contract_test.go](contract_test.go) and [config_test.go](config_test.go). |
| 9 | + |
| 10 | +The [hello world precompile tutorial](https://docs.avax.network/subnets/hello-world-precompile-tutorial) should guide you on precompile development. |
| 11 | + |
| 12 | +## General guidelines for precompile development |
| 13 | + |
| 14 | +- In the generated [`module.go`](module.go): |
| 15 | + - Set a suitable config key, for example |
| 16 | + |
| 17 | + ```go |
| 18 | + const ConfigKey = "yourPrecompileConfig" |
| 19 | + ``` |
| 20 | + |
| 21 | + - Set a suitable contract address, for example: |
| 22 | + |
| 23 | + ```go |
| 24 | + var ContractAddress = common.HexToAddress("ASUITABLEHEXADDRESS") |
| 25 | + ``` |
| 26 | + |
| 27 | +- Only modify code after `// CUSTOM CODE STARTS HERE`. Modifying code outside of these areas should be done with caution and with a good understanding of how changes may impact the EVM. |
| 28 | +- Set gas costs in the generated [`contract.go`](contract.go) file, for example: |
| 29 | + |
| 30 | + ```go |
| 31 | + const ( |
| 32 | + // Gas costs for each function. These are set to 1 by default. |
| 33 | + // You should set a gas cost for each function in your contract. |
| 34 | + // Generally, you should not set gas costs very low as this may cause your network to be vulnerable to DoS attacks. |
| 35 | + // There are some predefined gas costs in contract/utils.go that you can use. |
| 36 | + // This contract also uses AllowList precompile. |
| 37 | + // You should also increase gas costs of functions that read from AllowList storage. |
| 38 | + SayHelloGasCost uint64 = contract.ReadGasCostPerSlot |
| 39 | + SetGreetingGasCost uint64 = contract.WriteGasCostPerSlot + allowlist.ReadAllowListGasCost |
| 40 | + ) |
| 41 | + ``` |
| 42 | + |
| 43 | +- Force import your precompile package in `precompile/registry/registry.go`, for example with: |
| 44 | + |
| 45 | + ```go |
| 46 | + import ( |
| 47 | + _ "github.com/ava-labs/precompile-evm/helloworld" |
| 48 | + ) |
| 49 | + ``` |
| 50 | + |
| 51 | +- Add your config unit tests in [`config_test.go`](config_test.go) |
| 52 | +- Add your contract unit tests in [`contract_test.go`](contract_test.go) |
| 53 | +- You can add a full-fledged VM test for your precompile in [`plugin/vm/vm_test.go`](plugin/vm/vm_test.go). See existing precompile tests for examples. |
| 54 | +- Add your Solidity interface and test contract to [`contracts/contracts`](../contracts/contracts/) |
| 55 | +- Write Solidity contract tests for your precompile in [`contracts/contracts/test`](../contracts/contracts/test) |
| 56 | +- Write TypeScript DS-Test counterparts for your Solidity tests in [`contracts/test`](../contracts/test) |
| 57 | +- Create your genesis with your precompile enabled in [`tests/precompile/genesis/`](../tests/precompile/genesis) |
| 58 | +- Create e2e test for your Solidity test in [`tests/precompile/solidity/suites.go`](../tests/precompile/solidity/suites.go) |
| 59 | +- Run your e2e precompile Solidity tests with `./scripts/run_ginkgo.sh` |
0 commit comments