├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── cmd
├── chain-blast
│ ├── erc20_mock.gen.go
│ └── main.go
├── chain-ethgas
│ └── main.go
├── chain-mempool
│ └── main.go
├── chain-newheads
│ └── main.go
├── chain-receipts
│ └── main.go
├── chain-watch
│ ├── .gitignore
│ ├── fixtures
│ │ └── vcr
│ │ │ ├── ethmonitor_watch1.json
│ │ │ ├── ethmonitor_watch2.json
│ │ │ ├── ethmonitor_watch3.json
│ │ │ └── ethmonitor_watch4.json
│ ├── main.go
│ └── summary.go
└── ethkit
│ ├── README.md
│ ├── _contract.go
│ ├── _gas.go
│ ├── _receipts.go
│ ├── abigen.go
│ ├── artifacts.go
│ ├── balance.go
│ ├── balance_test.go
│ ├── block.go
│ ├── block_test.go
│ ├── main.go
│ ├── print.go
│ ├── print_test.go
│ └── wallet.go
├── ethartifact
├── ethartifact.go
└── registry.go
├── ethcoder
├── abi.go
├── abi_deprecated.go
├── abi_helpers.go
├── abi_sig.go
├── abi_sig_parser.go
├── abi_sig_parser_test.go
├── abi_sig_test.go
├── abi_test.go
├── ethcoder.go
├── ethcoder_test.go
├── events.go
├── events_test.go
├── hex.go
├── hex_test.go
├── keccak256.go
├── merkle_proof.go
├── merkle_proof_test.go
├── solidity_pack.go
├── solidity_pack_test.go
├── typed_data.go
├── typed_data_json.go
├── typed_data_test.go
└── types.go
├── ethcontract
├── abi.go
└── ethcontract.go
├── ethdeploy
└── ethdeploy.go
├── ethgas
├── ema.go
├── ema_test.go
├── ethgas.go
├── ethgas_test.go
├── fixtures
│ └── vcr
│ │ └── ethgas_mainnet.json
├── histogram_test.go
└── readers.go
├── ethkit-test.json.sample
├── ethkit.go
├── ethmempool
├── ethmempool.go
└── subscription.go
├── ethmonitor
├── bootstrap.go
├── chain.go
├── ethmonitor.go
├── ethmonitor_test.go
├── fixtures
│ └── vcr
│ │ └── ethmonitor_sepolia.json
├── pubsub.go
└── pubsub_test.go
├── ethproviders
├── config.go
├── ethproviders.go
└── ethproviders_test.go
├── ethreceipts
├── ethreceipts.go
├── ethreceipts_test.go
├── filterer.go
├── finalizer.go
├── receipt.go
└── subscription.go
├── ethrpc
├── batch.go
├── ens.go
├── ens_test.go
├── ethrpc.go
├── ethrpc_test.go
├── filter.go
├── interface.go
├── jsonrpc.go
├── jsonrpc
│ └── jsonrpc.go
├── methods.go
├── networks.go
├── option.go
├── strictness.go
├── strictness_test.go
├── syncing.go
├── unmarshal.go
└── utils.go
├── ethtest
├── contracts.go
├── contracts
│ ├── CallReceiverMock.json
│ └── ERC20Mock.json
├── erc20.go
├── ethtest.go
├── helpers.go
├── reorgme.go
├── reorgme
│ ├── .gitignore
│ ├── isRunning.sh
│ ├── package.json
│ └── pnpm-lock.yaml
├── testchain.go
├── testchain
│ ├── .gitignore
│ ├── hardhat.config.js
│ ├── package.json
│ └── pnpm-lock.yaml
└── testchain_test.go
├── ethtxn
├── ethtxn.go
└── ethtxn_test.go
├── ethutil
├── validate_logs_with_block.go
└── validate_logs_with_block_test.go
├── ethwallet
├── README.md
├── ethwallet.go
├── ethwallet_test.go
├── hdnode.go
├── hdnode_test.go
├── provider.go
└── utils.go
├── go-ethereum
├── AUTHORS
├── COPYING
├── COPYING.LESSER
├── README.md
├── SECURITY.md
├── accounts
│ ├── abi
│ │ ├── abi.go
│ │ ├── abi_test.go
│ │ ├── abifuzzer_test.go
│ │ ├── abigen
│ │ │ ├── bind.go
│ │ │ ├── bind_test.go
│ │ │ ├── bindv2.go
│ │ │ ├── bindv2_test.go
│ │ │ ├── source.go.tpl
│ │ │ ├── source2.go.tpl
│ │ │ ├── template.go
│ │ │ └── testdata
│ │ │ │ └── v2
│ │ │ │ ├── callbackparam.go.txt
│ │ │ │ ├── crowdsale.go.txt
│ │ │ │ ├── dao.go.txt
│ │ │ │ ├── deeplynestedarray.go.txt
│ │ │ │ ├── empty.go.txt
│ │ │ │ ├── eventchecker.go.txt
│ │ │ │ ├── getter.go.txt
│ │ │ │ ├── identifiercollision.go.txt
│ │ │ │ ├── inputchecker.go.txt
│ │ │ │ ├── interactor.go.txt
│ │ │ │ ├── nameconflict.go.txt
│ │ │ │ ├── numericmethodname.go.txt
│ │ │ │ ├── outputchecker.go.txt
│ │ │ │ ├── overload.go.txt
│ │ │ │ ├── rangekeyword.go.txt
│ │ │ │ ├── slicer.go.txt
│ │ │ │ ├── structs.go.txt
│ │ │ │ ├── token.go.txt
│ │ │ │ ├── tuple.go.txt
│ │ │ │ ├── tupler.go.txt
│ │ │ │ └── underscorer.go.txt
│ │ ├── argument.go
│ │ ├── bind
│ │ │ ├── old.go
│ │ │ └── v2
│ │ │ │ ├── auth.go
│ │ │ │ ├── backend.go
│ │ │ │ ├── base.go
│ │ │ │ ├── base_test.go
│ │ │ │ ├── dep_tree.go
│ │ │ │ ├── dep_tree_test.go
│ │ │ │ ├── internal
│ │ │ │ └── contracts
│ │ │ │ │ ├── db
│ │ │ │ │ ├── bindings.go
│ │ │ │ │ ├── combined-abi.json
│ │ │ │ │ └── contract.sol
│ │ │ │ │ ├── events
│ │ │ │ │ ├── bindings.go
│ │ │ │ │ ├── combined-abi.json
│ │ │ │ │ └── contract.sol
│ │ │ │ │ ├── nested_libraries
│ │ │ │ │ ├── abi.json
│ │ │ │ │ ├── bindings.go
│ │ │ │ │ ├── combined-abi.json
│ │ │ │ │ └── contract.sol
│ │ │ │ │ ├── solc_errors
│ │ │ │ │ ├── bindings.go
│ │ │ │ │ ├── combined-abi.json
│ │ │ │ │ └── contract.sol
│ │ │ │ │ └── uint256arrayreturn
│ │ │ │ │ ├── bindings.go
│ │ │ │ │ ├── combined-abi.json
│ │ │ │ │ └── contract.sol
│ │ │ │ ├── lib.go
│ │ │ │ └── util.go
│ │ ├── doc.go
│ │ ├── error.go
│ │ ├── error_handling.go
│ │ ├── event.go
│ │ ├── event_test.go
│ │ ├── method.go
│ │ ├── method_test.go
│ │ ├── pack.go
│ │ ├── pack_test.go
│ │ ├── packing_test.go
│ │ ├── reflect.go
│ │ ├── reflect_test.go
│ │ ├── selector_parser.go
│ │ ├── selector_parser_test.go
│ │ ├── topics.go
│ │ ├── topics_test.go
│ │ ├── type.go
│ │ ├── type_test.go
│ │ ├── unpack.go
│ │ ├── unpack_test.go
│ │ └── utils.go
│ ├── accounts.go
│ ├── accounts_test.go
│ ├── errors.go
│ ├── hd.go
│ ├── hd_test.go
│ ├── keystore
│ │ ├── account_cache.go
│ │ ├── account_cache_test.go
│ │ ├── file_cache.go
│ │ ├── key.go
│ │ ├── keystore.go
│ │ ├── keystore_fuzzing_test.go
│ │ ├── keystore_test.go
│ │ ├── passphrase.go
│ │ ├── passphrase_test.go
│ │ ├── plain.go
│ │ ├── plain_test.go
│ │ ├── presale.go
│ │ ├── testdata
│ │ │ ├── keystore
│ │ │ │ ├── .hiddenfile
│ │ │ │ ├── README
│ │ │ │ ├── UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8
│ │ │ │ ├── aaa
│ │ │ │ ├── empty
│ │ │ │ ├── foo
│ │ │ │ │ └── fd9bd350f08ee3c0c19b85a8e16114a11a60aa4e
│ │ │ │ ├── garbage
│ │ │ │ ├── no-address
│ │ │ │ ├── zero
│ │ │ │ └── zzz
│ │ │ ├── v1
│ │ │ │ └── cb61d5a9c4896fb9658090b597ef0e7be6f7b67e
│ │ │ │ │ └── cb61d5a9c4896fb9658090b597ef0e7be6f7b67e
│ │ │ ├── v1_test_vector.json
│ │ │ ├── v3_test_vector.json
│ │ │ └── very-light-scrypt.json
│ │ ├── wallet.go
│ │ ├── watch.go
│ │ └── watch_fallback.go
│ ├── manager.go
│ ├── sort.go
│ ├── url.go
│ └── url_test.go
├── common
│ ├── big.go
│ ├── bitutil
│ │ ├── bitutil.go
│ │ ├── bitutil_test.go
│ │ ├── compress.go
│ │ └── compress_test.go
│ ├── bytes.go
│ ├── bytes_test.go
│ ├── compiler
│ │ ├── helpers.go
│ │ └── solidity.go
│ ├── debug.go
│ ├── fdlimit
│ │ ├── fdlimit_bsd.go
│ │ ├── fdlimit_darwin.go
│ │ ├── fdlimit_test.go
│ │ ├── fdlimit_unix.go
│ │ └── fdlimit_windows.go
│ ├── format.go
│ ├── hexutil
│ │ ├── hexutil.go
│ │ ├── hexutil_test.go
│ │ ├── json.go
│ │ ├── json_example_test.go
│ │ └── json_test.go
│ ├── lru
│ │ ├── basiclru.go
│ │ ├── basiclru_test.go
│ │ ├── blob_lru.go
│ │ ├── blob_lru_test.go
│ │ └── lru.go
│ ├── math
│ │ ├── big.go
│ │ ├── big_test.go
│ │ ├── integer.go
│ │ └── integer_test.go
│ ├── mclock
│ │ ├── alarm.go
│ │ ├── alarm_test.go
│ │ ├── mclock.go
│ │ ├── mclock.s
│ │ ├── simclock.go
│ │ └── simclock_test.go
│ ├── path.go
│ ├── prque
│ │ ├── lazyqueue.go
│ │ ├── lazyqueue_test.go
│ │ ├── prque.go
│ │ ├── prque_test.go
│ │ ├── sstack.go
│ │ └── sstack_test.go
│ ├── range.go
│ ├── range_test.go
│ ├── size.go
│ ├── size_test.go
│ ├── test_utils.go
│ ├── types.go
│ └── types_test.go
├── core
│ ├── .gitignore
│ ├── sender_cacher.go
│ ├── state_transition.go
│ └── types
│ │ ├── account.go
│ │ ├── block.go
│ │ ├── block_test.go
│ │ ├── bloom9.go
│ │ ├── bloom9_test.go
│ │ ├── deposit.go
│ │ ├── deposit_test.go
│ │ ├── gen_access_tuple.go
│ │ ├── gen_account.go
│ │ ├── gen_account_rlp.go
│ │ ├── gen_authorization.go
│ │ ├── gen_header_json.go
│ │ ├── gen_header_rlp.go
│ │ ├── gen_log_json.go
│ │ ├── gen_log_rlp.go
│ │ ├── gen_receipt_json.go
│ │ ├── gen_withdrawal_json.go
│ │ ├── gen_withdrawal_rlp.go
│ │ ├── hashes.go
│ │ ├── hashing.go
│ │ ├── log.go
│ │ ├── log_test.go
│ │ ├── receipt.go
│ │ ├── receipt_test.go
│ │ ├── rlp_fuzzer_test.go
│ │ ├── state_account.go
│ │ ├── transaction.go
│ │ ├── transaction_marshalling.go
│ │ ├── transaction_signing.go
│ │ ├── transaction_signing_test.go
│ │ ├── transaction_test.go
│ │ ├── tx_access_list.go
│ │ ├── tx_blob.go
│ │ ├── tx_blob_test.go
│ │ ├── tx_dynamic_fee.go
│ │ ├── tx_legacy.go
│ │ ├── tx_setcode.go
│ │ ├── tx_setcode_test.go
│ │ ├── types_test.go
│ │ └── withdrawal.go
├── crypto
│ ├── blake2b
│ │ ├── blake2b.go
│ │ ├── blake2bAVX2_amd64.go
│ │ ├── blake2bAVX2_amd64.s
│ │ ├── blake2b_amd64.go
│ │ ├── blake2b_amd64.s
│ │ ├── blake2b_f_fuzz_test.go
│ │ ├── blake2b_f_test.go
│ │ ├── blake2b_generic.go
│ │ ├── blake2b_ref.go
│ │ ├── blake2b_test.go
│ │ ├── blake2x.go
│ │ └── register.go
│ ├── bn256
│ │ ├── LICENSE
│ │ ├── bn256_fast.go
│ │ ├── bn256_slow.go
│ │ ├── cloudflare
│ │ │ ├── LICENSE
│ │ │ ├── bn256.go
│ │ │ ├── bn256_test.go
│ │ │ ├── constants.go
│ │ │ ├── curve.go
│ │ │ ├── example_test.go
│ │ │ ├── gfp.go
│ │ │ ├── gfp12.go
│ │ │ ├── gfp2.go
│ │ │ ├── gfp6.go
│ │ │ ├── gfp_amd64.s
│ │ │ ├── gfp_arm64.s
│ │ │ ├── gfp_decl.go
│ │ │ ├── gfp_generic.go
│ │ │ ├── gfp_test.go
│ │ │ ├── lattice.go
│ │ │ ├── lattice_test.go
│ │ │ ├── main_test.go
│ │ │ ├── mul_amd64.h
│ │ │ ├── mul_arm64.h
│ │ │ ├── mul_bmi2_amd64.h
│ │ │ ├── optate.go
│ │ │ └── twist.go
│ │ ├── gnark
│ │ │ ├── g1.go
│ │ │ ├── g2.go
│ │ │ ├── gt.go
│ │ │ └── pairing.go
│ │ └── google
│ │ │ ├── bn256.go
│ │ │ ├── bn256_test.go
│ │ │ ├── constants.go
│ │ │ ├── curve.go
│ │ │ ├── example_test.go
│ │ │ ├── gfp12.go
│ │ │ ├── gfp2.go
│ │ │ ├── gfp6.go
│ │ │ ├── main_test.go
│ │ │ ├── optate.go
│ │ │ └── twist.go
│ ├── crypto.go
│ ├── crypto_test.go
│ ├── ecies
│ │ ├── .gitignore
│ │ ├── LICENSE
│ │ ├── README
│ │ ├── ecies.go
│ │ ├── ecies_test.go
│ │ └── params.go
│ ├── kzg4844
│ │ ├── kzg4844.go
│ │ ├── kzg4844_ckzg_cgo.go
│ │ ├── kzg4844_ckzg_nocgo.go
│ │ ├── kzg4844_gokzg.go
│ │ ├── kzg4844_test.go
│ │ └── trusted_setup.json
│ ├── secp256k1
│ │ ├── .gitignore
│ │ ├── LICENSE
│ │ ├── curve.go
│ │ ├── dummy.go
│ │ ├── ext.h
│ │ ├── libsecp256k1
│ │ │ ├── .cirrus.yml
│ │ │ ├── .gitattributes
│ │ │ ├── .github
│ │ │ │ ├── actions
│ │ │ │ │ ├── install-homebrew-valgrind
│ │ │ │ │ │ └── action.yml
│ │ │ │ │ └── run-in-docker-action
│ │ │ │ │ │ └── action.yml
│ │ │ │ └── workflows
│ │ │ │ │ └── ci.yml
│ │ │ ├── .gitignore
│ │ │ ├── CHANGELOG.md
│ │ │ ├── CMakeLists.txt
│ │ │ ├── CMakePresets.json
│ │ │ ├── CONTRIBUTING.md
│ │ │ ├── COPYING
│ │ │ ├── Makefile.am
│ │ │ ├── README.md
│ │ │ ├── SECURITY.md
│ │ │ ├── autogen.sh
│ │ │ ├── build-aux
│ │ │ │ └── m4
│ │ │ │ │ ├── ax_jni_include_dir.m4
│ │ │ │ │ ├── ax_prog_cc_for_build.m4
│ │ │ │ │ └── bitcoin_secp.m4
│ │ │ ├── configure.ac
│ │ │ ├── contrib
│ │ │ │ ├── dummy.go
│ │ │ │ ├── lax_der_parsing.c
│ │ │ │ ├── lax_der_parsing.h
│ │ │ │ ├── lax_der_privatekey_parsing.c
│ │ │ │ └── lax_der_privatekey_parsing.h
│ │ │ ├── doc
│ │ │ │ ├── ellswift.md
│ │ │ │ ├── musig.md
│ │ │ │ ├── release-process.md
│ │ │ │ └── safegcd_implementation.md
│ │ │ ├── dummy.go
│ │ │ ├── include
│ │ │ │ ├── dummy.go
│ │ │ │ ├── secp256k1.h
│ │ │ │ ├── secp256k1_ecdh.h
│ │ │ │ ├── secp256k1_ellswift.h
│ │ │ │ ├── secp256k1_extrakeys.h
│ │ │ │ ├── secp256k1_musig.h
│ │ │ │ ├── secp256k1_preallocated.h
│ │ │ │ ├── secp256k1_recovery.h
│ │ │ │ └── secp256k1_schnorrsig.h
│ │ │ ├── libsecp256k1.pc.in
│ │ │ ├── sage
│ │ │ │ ├── gen_exhaustive_groups.sage
│ │ │ │ ├── gen_split_lambda_constants.sage
│ │ │ │ ├── group_prover.sage
│ │ │ │ ├── prove_group_implementations.sage
│ │ │ │ ├── secp256k1_params.sage
│ │ │ │ └── weierstrass_prover.sage
│ │ │ ├── src
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── asm
│ │ │ │ │ └── field_10x26_arm.s
│ │ │ │ ├── assumptions.h
│ │ │ │ ├── bench.c
│ │ │ │ ├── bench.h
│ │ │ │ ├── bench_ecmult.c
│ │ │ │ ├── bench_internal.c
│ │ │ │ ├── checkmem.h
│ │ │ │ ├── ctime_tests.c
│ │ │ │ ├── dummy.go
│ │ │ │ ├── ecdsa.h
│ │ │ │ ├── ecdsa_impl.h
│ │ │ │ ├── eckey.h
│ │ │ │ ├── eckey_impl.h
│ │ │ │ ├── ecmult.h
│ │ │ │ ├── ecmult_compute_table.h
│ │ │ │ ├── ecmult_compute_table_impl.h
│ │ │ │ ├── ecmult_const.h
│ │ │ │ ├── ecmult_const_impl.h
│ │ │ │ ├── ecmult_gen.h
│ │ │ │ ├── ecmult_gen_compute_table.h
│ │ │ │ ├── ecmult_gen_compute_table_impl.h
│ │ │ │ ├── ecmult_gen_impl.h
│ │ │ │ ├── ecmult_impl.h
│ │ │ │ ├── field.h
│ │ │ │ ├── field_10x26.h
│ │ │ │ ├── field_10x26_impl.h
│ │ │ │ ├── field_5x52.h
│ │ │ │ ├── field_5x52_impl.h
│ │ │ │ ├── field_5x52_int128_impl.h
│ │ │ │ ├── field_impl.h
│ │ │ │ ├── group.h
│ │ │ │ ├── group_impl.h
│ │ │ │ ├── hash.h
│ │ │ │ ├── hash_impl.h
│ │ │ │ ├── hsort.h
│ │ │ │ ├── hsort_impl.h
│ │ │ │ ├── int128.h
│ │ │ │ ├── int128_impl.h
│ │ │ │ ├── int128_native.h
│ │ │ │ ├── int128_native_impl.h
│ │ │ │ ├── int128_struct.h
│ │ │ │ ├── int128_struct_impl.h
│ │ │ │ ├── modinv32.h
│ │ │ │ ├── modinv32_impl.h
│ │ │ │ ├── modinv64.h
│ │ │ │ ├── modinv64_impl.h
│ │ │ │ ├── modules
│ │ │ │ │ ├── dummy.go
│ │ │ │ │ ├── ecdh
│ │ │ │ │ │ ├── Makefile.am.include
│ │ │ │ │ │ ├── bench_impl.h
│ │ │ │ │ │ ├── dummy.go
│ │ │ │ │ │ ├── main_impl.h
│ │ │ │ │ │ └── tests_impl.h
│ │ │ │ │ ├── ellswift
│ │ │ │ │ │ ├── Makefile.am.include
│ │ │ │ │ │ ├── bench_impl.h
│ │ │ │ │ │ ├── main_impl.h
│ │ │ │ │ │ ├── tests_exhaustive_impl.h
│ │ │ │ │ │ └── tests_impl.h
│ │ │ │ │ ├── extrakeys
│ │ │ │ │ │ ├── Makefile.am.include
│ │ │ │ │ │ ├── main_impl.h
│ │ │ │ │ │ ├── tests_exhaustive_impl.h
│ │ │ │ │ │ └── tests_impl.h
│ │ │ │ │ ├── musig
│ │ │ │ │ │ ├── Makefile.am.include
│ │ │ │ │ │ ├── keyagg.h
│ │ │ │ │ │ ├── keyagg_impl.h
│ │ │ │ │ │ ├── main_impl.h
│ │ │ │ │ │ ├── session.h
│ │ │ │ │ │ ├── session_impl.h
│ │ │ │ │ │ ├── tests_impl.h
│ │ │ │ │ │ └── vectors.h
│ │ │ │ │ ├── recovery
│ │ │ │ │ │ ├── Makefile.am.include
│ │ │ │ │ │ ├── bench_impl.h
│ │ │ │ │ │ ├── dummy.go
│ │ │ │ │ │ ├── main_impl.h
│ │ │ │ │ │ ├── tests_exhaustive_impl.h
│ │ │ │ │ │ └── tests_impl.h
│ │ │ │ │ └── schnorrsig
│ │ │ │ │ │ ├── Makefile.am.include
│ │ │ │ │ │ ├── bench_impl.h
│ │ │ │ │ │ ├── main_impl.h
│ │ │ │ │ │ ├── tests_exhaustive_impl.h
│ │ │ │ │ │ └── tests_impl.h
│ │ │ │ ├── precompute_ecmult.c
│ │ │ │ ├── precompute_ecmult_gen.c
│ │ │ │ ├── precomputed_ecmult.c
│ │ │ │ ├── precomputed_ecmult.h
│ │ │ │ ├── precomputed_ecmult_gen.c
│ │ │ │ ├── precomputed_ecmult_gen.h
│ │ │ │ ├── scalar.h
│ │ │ │ ├── scalar_4x64.h
│ │ │ │ ├── scalar_4x64_impl.h
│ │ │ │ ├── scalar_8x32.h
│ │ │ │ ├── scalar_8x32_impl.h
│ │ │ │ ├── scalar_impl.h
│ │ │ │ ├── scalar_low.h
│ │ │ │ ├── scalar_low_impl.h
│ │ │ │ ├── scratch.h
│ │ │ │ ├── scratch_impl.h
│ │ │ │ ├── secp256k1.c
│ │ │ │ ├── selftest.h
│ │ │ │ ├── testrand.h
│ │ │ │ ├── testrand_impl.h
│ │ │ │ ├── tests.c
│ │ │ │ ├── tests_exhaustive.c
│ │ │ │ ├── testutil.h
│ │ │ │ ├── util.h
│ │ │ │ └── wycheproof
│ │ │ │ │ ├── WYCHEPROOF_COPYING
│ │ │ │ │ ├── ecdsa_secp256k1_sha256_bitcoin_test.h
│ │ │ │ │ └── ecdsa_secp256k1_sha256_bitcoin_test.json
│ │ │ └── tools
│ │ │ │ ├── check-abi.sh
│ │ │ │ ├── test_vectors_musig2_generate.py
│ │ │ │ └── tests_wycheproof_generate.py
│ │ ├── panic_cb.go
│ │ ├── scalar_mult_cgo.go
│ │ ├── scalar_mult_nocgo.go
│ │ ├── secp256.go
│ │ └── secp256_test.go
│ ├── signature_cgo.go
│ ├── signature_nocgo.go
│ ├── signature_test.go
│ └── signify
│ │ ├── signify.go
│ │ └── signify_fuzz.go
├── ethclient
│ ├── ethclient.go
│ ├── gethclient
│ │ └── gethclient.go
│ └── signer.go
├── event
│ ├── event.go
│ ├── event_test.go
│ ├── example_feed_test.go
│ ├── example_scope_test.go
│ ├── example_subscription_test.go
│ ├── example_test.go
│ ├── feed.go
│ ├── feed_test.go
│ ├── feedof.go
│ ├── feedof_test.go
│ ├── multisub.go
│ ├── multisub_test.go
│ ├── subscription.go
│ └── subscription_test.go
├── interfaces.go
├── internal
│ ├── blocktest
│ │ └── test_hash.go
│ └── testrand
│ │ └── rand.go
├── log
│ ├── format.go
│ ├── format_test.go
│ ├── handler.go
│ ├── handler_glog.go
│ ├── logger.go
│ ├── logger_test.go
│ ├── root.go
│ └── root_test.go
├── p2p
│ └── server.go
├── params
│ ├── bootnodes.go
│ ├── config.go
│ ├── config_test.go
│ ├── dao.go
│ ├── denomination.go
│ ├── forks
│ │ └── forks.go
│ ├── network_params.go
│ ├── protocol_params.go
│ └── verkle_params.go
├── rlp
│ ├── decode.go
│ ├── decode_tail_test.go
│ ├── decode_test.go
│ ├── doc.go
│ ├── encbuffer.go
│ ├── encbuffer_example_test.go
│ ├── encode.go
│ ├── encode_test.go
│ ├── encoder_example_test.go
│ ├── internal
│ │ └── rlpstruct
│ │ │ └── rlpstruct.go
│ ├── iterator.go
│ ├── iterator_test.go
│ ├── raw.go
│ ├── raw_test.go
│ ├── rlpgen
│ │ ├── gen.go
│ │ ├── gen_test.go
│ │ ├── main.go
│ │ ├── testdata
│ │ │ ├── bigint.in.txt
│ │ │ ├── bigint.out.txt
│ │ │ ├── nil.in.txt
│ │ │ ├── nil.out.txt
│ │ │ ├── optional.in.txt
│ │ │ ├── optional.out.txt
│ │ │ ├── rawvalue.in.txt
│ │ │ ├── rawvalue.out.txt
│ │ │ ├── uint256.in.txt
│ │ │ ├── uint256.out.txt
│ │ │ ├── uints.in.txt
│ │ │ └── uints.out.txt
│ │ └── types.go
│ ├── safe.go
│ ├── typecache.go
│ └── unsafe.go
└── rpc
│ ├── _client_test.go
│ ├── _server_test.go
│ ├── client.go
│ ├── client_example_test.go
│ ├── client_opt.go
│ ├── client_opt_test.go
│ ├── context_headers.go
│ ├── doc.go
│ ├── errors.go
│ ├── handler.go
│ ├── http.go
│ ├── http_test.go
│ ├── ipc.go
│ ├── ipc_js.go
│ ├── ipc_unix.go
│ ├── json.go
│ ├── server.go
│ ├── service.go
│ ├── stdio.go
│ ├── subscription.go
│ ├── subscription_test.go
│ ├── testservice_test.go
│ ├── types.go
│ ├── types_test.go
│ ├── websocket.go
│ └── websocket_test.go
├── go.mod
├── go.sum
├── types.go
└── util
├── alerter.go
└── testing.go
/.gitignore:
--------------------------------------------------------------------------------
1 | ethkit-test.json
2 | bin/
3 |
4 | # Ignore everything in vendor/, except for certain files.
5 | # LICENSE and COPYING. Ignore Go tests.
6 | vendor/**/*
7 |
8 | # keep files..
9 | !vendor/**/
10 | !vendor/modules.txt
11 | !vendor/**/*.go
12 | !vendor/**/*.h
13 | !vendor/**/*.s
14 | !vendor/**/*.c
15 | !vendor/**/*.sh
16 | !vendor/**/*.pl
17 | !vendor/**/*.proto
18 | !vendor/**/LICENSE*
19 | !vendor/**/COPYING*
20 |
21 | # Misc
22 | .DS_Store
23 |
--------------------------------------------------------------------------------
/cmd/chain-watch/.gitignore:
--------------------------------------------------------------------------------
1 | snapshot.json
2 |
--------------------------------------------------------------------------------
/cmd/ethkit/README.md:
--------------------------------------------------------------------------------
1 | ethkit cli
2 | ==========
3 |
4 | ## Install
5 |
6 | ```
7 | go get github.com/0xsequence/ethkit/cmd/ethkit
8 | ```
9 |
10 |
11 | ## Usage
12 |
13 | ```shell
14 | $ ethkit --help
15 | ```
16 |
17 | ```
18 | ethkit - Ethereum dev toolkit
19 |
20 | Usage:
21 | ethkit [command]
22 |
23 | Available Commands:
24 | abigen generate contract client code from a truffle artifacts file
25 | artifacts print the contract abi or bytecode from a truffle artifacts file
26 | help Help about any command
27 | version print the version number
28 | wallet encrypted wallet creation+management
29 |
30 | Flags:
31 | -h, --help help for ethkit
32 |
33 | Use "ethkit [command] --help" for more information about a command
34 | ```
35 |
36 |
--------------------------------------------------------------------------------
/cmd/ethkit/_contract.go:
--------------------------------------------------------------------------------
1 | package main
2 |
--------------------------------------------------------------------------------
/cmd/ethkit/_gas.go:
--------------------------------------------------------------------------------
1 | package main
2 |
--------------------------------------------------------------------------------
/cmd/ethkit/artifacts.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "log"
6 |
7 | "github.com/0xsequence/ethkit/ethartifact"
8 | "github.com/spf13/cobra"
9 | )
10 |
11 | func init() {
12 | artifacts := &artifacts{}
13 | cmd := &cobra.Command{
14 | Use: "artifacts",
15 | Short: "Print the contract abi or bytecode from a truffle artifacts file",
16 | Run: artifacts.Run,
17 | }
18 |
19 | cmd.Flags().String("file", "", "path to truffle contract artifacts file (required)")
20 | cmd.Flags().Bool("abi", false, "abi")
21 | cmd.Flags().Bool("bytecode", false, "bytecode")
22 |
23 | rootCmd.AddCommand(cmd)
24 | }
25 |
26 | type artifacts struct {
27 | }
28 |
29 | func (c *artifacts) Run(cmd *cobra.Command, args []string) {
30 | fFile, _ := cmd.Flags().GetString("file")
31 | fAbi, _ := cmd.Flags().GetBool("abi")
32 | fBytecode, _ := cmd.Flags().GetBool("bytecode")
33 |
34 | if fFile == "" {
35 | fmt.Println("error: please pass --file")
36 | help(cmd)
37 | return
38 | }
39 | if !fAbi && !fBytecode {
40 | fmt.Println("error: please pass either --abi or --bytecode")
41 | help(cmd)
42 | return
43 | }
44 | if fAbi && fBytecode {
45 | fmt.Println("error: please pass either --abi or --bytecode, not both")
46 | help(cmd)
47 | return
48 | }
49 |
50 | artifacts, err := ethartifact.ParseArtifactFile(fFile)
51 | if err != nil {
52 | log.Fatal(err)
53 | return
54 | }
55 |
56 | if fAbi {
57 | fmt.Println(string(artifacts.ABI))
58 | }
59 |
60 | if fBytecode {
61 | fmt.Println(artifacts.Bytecode)
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ethcoder/ethcoder.go:
--------------------------------------------------------------------------------
1 | package ethcoder
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | )
7 |
8 | func BytesToBytes32(slice []byte) [32]byte {
9 | var bytes32 [32]byte
10 | copy(bytes32[:], slice)
11 | return bytes32
12 | }
13 |
14 | func PaddedAddress(address string) string {
15 | if strings.HasPrefix(address, "0x") {
16 | address = address[2:]
17 | }
18 | if len(address) < 64 {
19 | address = strings.Repeat("0", 64-len(address)) + address
20 | }
21 | return address[0:64]
22 | }
23 |
24 | func FunctionSignature(functionExpr string) string {
25 | return HexEncode(Keccak256([]byte(functionExpr))[0:4])
26 | }
27 |
28 | func StringifyValues(values []any) ([]string, error) {
29 | strs := []string{}
30 |
31 | for _, value := range values {
32 | stringer, ok := value.(fmt.Stringer)
33 | if ok {
34 | strs = append(strs, stringer.String())
35 | continue
36 | }
37 |
38 | switch v := value.(type) {
39 | case nil:
40 | strs = append(strs, "")
41 | case string:
42 | strs = append(strs, v)
43 | default:
44 | strs = append(strs, fmt.Sprintf("%v", value))
45 | }
46 | }
47 |
48 | return strs, nil
49 | }
50 |
--------------------------------------------------------------------------------
/ethcoder/ethcoder_test.go:
--------------------------------------------------------------------------------
1 | package ethcoder
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/stretchr/testify/assert"
7 | )
8 |
9 | func TestFunctionSignature(t *testing.T) {
10 | fnsig := FunctionSignature("balanceOf(address,uint256)")
11 | assert.Equal(t, "0x00fdd58e", fnsig)
12 | }
13 |
--------------------------------------------------------------------------------
/ethcoder/hex.go:
--------------------------------------------------------------------------------
1 | package ethcoder
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "math/big"
7 | "strings"
8 |
9 | "github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
10 | )
11 |
12 | func HexEncode(h []byte) string {
13 | return hexutil.Encode(h)
14 | }
15 |
16 | func HexDecode(h string) ([]byte, error) {
17 | return hexutil.Decode(h)
18 | }
19 |
20 | func MustHexDecode(h string) []byte {
21 | b, err := HexDecode(h)
22 | if err != nil {
23 | panic(fmt.Errorf("ethcoder: must hex decode but failed due to, %v", err))
24 | }
25 | return b
26 | }
27 |
28 | func HexDecodeBytes32(h string) ([32]byte, error) {
29 | slice, err := hexutil.Decode(h)
30 | if err != nil {
31 | return [32]byte{}, err
32 | }
33 | if len(slice) != 32 {
34 | return [32]byte{}, errors.New("hex input is not 32 bytes")
35 | }
36 |
37 | return BytesToBytes32(slice), nil
38 | }
39 |
40 | func HexDecodeBigIntArray(bigNumsHex []string) ([]*big.Int, error) {
41 | var err error
42 | nums := make([]*big.Int, len(bigNumsHex))
43 | for i := 0; i < len(bigNumsHex); i++ {
44 | nums[i], err = hexutil.DecodeBig(bigNumsHex[i])
45 | if err != nil {
46 | return nil, err
47 | }
48 | }
49 | return nums, nil
50 | }
51 |
52 | func HexEncodeBigIntArray(bigNums []*big.Int) ([]string, error) {
53 | nums := make([]string, len(bigNums))
54 | for i := 0; i < len(bigNums); i++ {
55 | nums[i] = hexutil.EncodeBig(bigNums[i])
56 | }
57 | return nums, nil
58 | }
59 |
60 | func HexTrimLeadingZeros(hex string) (string, error) {
61 | if hex[0:2] != "0x" {
62 | return "", errors.New("ethcoder: expecting hex value")
63 | }
64 | hex = fmt.Sprintf("0x%s", strings.TrimLeft(hex[2:], "0"))
65 | if hex == "0x" {
66 | return "0x0", nil
67 | } else {
68 | return hex, nil
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/ethcoder/hex_test.go:
--------------------------------------------------------------------------------
1 | package ethcoder
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/stretchr/testify/assert"
7 | )
8 |
9 | func TestHexTrimLeadingZeros(t *testing.T) {
10 | v, err := HexTrimLeadingZeros("0x00000000001")
11 | assert.NoError(t, err)
12 | assert.Equal(t, "0x1", v)
13 |
14 | v, err = HexTrimLeadingZeros("0x000000000000")
15 | assert.NoError(t, err)
16 | assert.Equal(t, "0x0", v)
17 | }
18 |
--------------------------------------------------------------------------------
/ethcoder/keccak256.go:
--------------------------------------------------------------------------------
1 | package ethcoder
2 |
3 | import (
4 | "github.com/0xsequence/ethkit/go-ethereum/common"
5 | "golang.org/x/crypto/sha3"
6 | )
7 |
8 | func Keccak256Hash(input []byte) common.Hash {
9 | return common.BytesToHash(Keccak256(input))
10 | }
11 |
12 | func Keccak256(input []byte) []byte {
13 | hasher := sha3.NewLegacyKeccak256()
14 | hasher.Write(input)
15 | return hasher.Sum(nil)
16 | }
17 |
18 | func SHA3(input []byte) common.Hash {
19 | return Keccak256Hash(input)
20 | }
21 |
--------------------------------------------------------------------------------
/ethcoder/types.go:
--------------------------------------------------------------------------------
1 | package ethcoder
2 |
3 | import "github.com/0xsequence/ethkit/go-ethereum/accounts/abi"
4 |
5 | func MustNewType(str string) abi.Type {
6 | typ, err := abi.NewType(str, "", nil)
7 | if err != nil {
8 | panic(err)
9 | }
10 | return typ
11 | }
12 |
13 | func MustNewArrayTypeTuple(components []abi.ArgumentMarshaling) abi.Type {
14 | typ, err := abi.NewType("tuple[]", "", components)
15 | if err != nil {
16 | panic(err)
17 | }
18 | return typ
19 | }
20 |
--------------------------------------------------------------------------------
/ethcontract/abi.go:
--------------------------------------------------------------------------------
1 | package ethcontract
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 |
7 | "github.com/0xsequence/ethkit/go-ethereum/accounts/abi"
8 | )
9 |
10 | func ParseABI(abiJSON string) (abi.ABI, error) {
11 | parsed, err := abi.JSON(strings.NewReader(abiJSON))
12 | if err != nil {
13 | return abi.ABI{}, fmt.Errorf("unable to parse abi json: %w", err)
14 | }
15 | return parsed, nil
16 | }
17 |
18 | func MustParseABI(abiJSON string) abi.ABI {
19 | parsed, err := ParseABI(abiJSON)
20 | if err != nil {
21 | panic(err)
22 | }
23 | return parsed
24 | }
25 |
--------------------------------------------------------------------------------
/ethcontract/ethcontract.go:
--------------------------------------------------------------------------------
1 | package ethcontract
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/0xsequence/ethkit"
7 | "github.com/0xsequence/ethkit/ethcoder"
8 | "github.com/0xsequence/ethkit/go-ethereum/accounts/abi"
9 | "github.com/0xsequence/ethkit/go-ethereum/accounts/abi/bind"
10 | "github.com/0xsequence/ethkit/go-ethereum/common"
11 | )
12 |
13 | type Contract struct {
14 | *bind.BoundContract
15 | Address common.Address
16 | ABI abi.ABI
17 | }
18 |
19 | func NewContractCaller(address common.Address, abi abi.ABI, caller bind.ContractCaller) *Contract {
20 | return NewContract(address, abi, caller, nil, nil)
21 | }
22 |
23 | func NewContractTransactor(address common.Address, abi abi.ABI, caller bind.ContractCaller, transactor bind.ContractTransactor) *Contract {
24 | return NewContract(address, abi, caller, transactor, nil)
25 | }
26 |
27 | func NewContractFilterer(address common.Address, abi abi.ABI, filterer bind.ContractFilterer) *Contract {
28 | return NewContract(address, abi, nil, nil, filterer)
29 | }
30 |
31 | func NewContract(address common.Address, abi abi.ABI, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) *Contract {
32 | contract := &Contract{
33 | BoundContract: bind.NewBoundContract(address, abi, caller, transactor, filterer),
34 | Address: address,
35 | ABI: abi,
36 | }
37 | return contract
38 | }
39 |
40 | func (c *Contract) Encode(method string, args ...interface{}) ([]byte, error) {
41 | m, ok := c.ABI.Methods[method]
42 | if !ok {
43 | return nil, fmt.Errorf("contract method %s not found", method)
44 | }
45 | input, err := m.Inputs.Pack(args...)
46 | if err != nil {
47 | return nil, err
48 | }
49 | input = append(m.ID, input...)
50 | return input, nil
51 | }
52 |
53 | func (c *Contract) EventTopicHash(eventName string) (ethkit.Hash, error) {
54 | ev, ok := c.ABI.Events[eventName]
55 | if !ok {
56 | return ethkit.Hash{}, fmt.Errorf("ethcontract: event '%s' not found in contract abi", eventName)
57 | }
58 | h := ethcoder.Keccak256Hash([]byte(ev.Sig))
59 | return h, nil
60 | }
61 |
--------------------------------------------------------------------------------
/ethgas/ema.go:
--------------------------------------------------------------------------------
1 | package ethgas
2 |
3 | import "math/big"
4 |
5 | // NewEMA(decay) returns a new exponential moving average. It weighs new values more than
6 | // existing values according to the decay. For example: NewEMA(0.05) would give 5% weight
7 | // to the present and 95% weight to the past. Common to use 2/(selected time period+1).
8 | func NewEMA(decay float64) *EMA {
9 | return &EMA{decay: big.NewFloat(decay)}
10 | }
11 |
12 | // EMA is a moving average with exponential decay. It doesn't have any concept of weight
13 | // so it will only work on homogenous (evenly spaced) time series.
14 | // ema := NewEMA(0.1818)
15 | // avg1 = ema.Tick(price1)
16 | // avg2 = ema.Tick(price2)
17 | // spike := checkPriceMovingAvg(price, avg, 20%)
18 | type EMA struct {
19 | decay *big.Float
20 | value *big.Int
21 | }
22 |
23 | func (ema *EMA) Tick(price *big.Int) *big.Int {
24 | if ema.value == nil {
25 | ema.value = new(big.Int).Set(price)
26 | }
27 | current := new(big.Float).Mul(new(big.Float).SetInt(price), ema.decay)
28 | past := new(big.Float).Mul(
29 | new(big.Float).Sub(big.NewFloat(1), ema.decay),
30 | new(big.Float).SetInt(ema.value),
31 | )
32 | new(big.Float).Add(current, past).Int(ema.value)
33 | return ema.Value()
34 | }
35 |
36 | func (ema *EMA) Value() *big.Int {
37 | return new(big.Int).Set(ema.value)
38 | }
39 |
--------------------------------------------------------------------------------
/ethgas/ema_test.go:
--------------------------------------------------------------------------------
1 | package ethgas_test
2 |
3 | import (
4 | "math/big"
5 | "testing"
6 |
7 | "github.com/0xsequence/ethkit/ethgas"
8 | "github.com/stretchr/testify/assert"
9 | )
10 |
11 | func TestEMA(t *testing.T) {
12 | tt := []struct {
13 | decay float64
14 | values []int64
15 | expected int64
16 | }{
17 | {
18 | decay: 0.1,
19 | values: []int64{1, 1, 1},
20 | expected: 1,
21 | },
22 | {
23 | decay: 0.5,
24 | values: []int64{100, 200},
25 | expected: 150,
26 | },
27 | {
28 | decay: 0.5,
29 | values: []int64{100, 200, 300},
30 | expected: 225,
31 | },
32 | {
33 | decay: 0.5,
34 | values: []int64{300, 200, 100},
35 | expected: 175,
36 | },
37 | {
38 | decay: 0.1818,
39 | values: []int64{2227, 2219, 2208, 2217, 2218, 2213, 2223, 2243, 2224},
40 | expected: 2222,
41 | },
42 | }
43 | for _, tc := range tt {
44 | ema := ethgas.NewEMA(tc.decay)
45 | for _, v := range tc.values {
46 | ema.Tick(big.NewInt(v))
47 | }
48 | assert.Equal(t, tc.expected, ema.Value().Int64())
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ethgas/readers.go:
--------------------------------------------------------------------------------
1 | package ethgas
2 |
3 | import (
4 | "math/big"
5 |
6 | "github.com/0xsequence/ethkit/ethmonitor"
7 | "github.com/0xsequence/ethkit/go-ethereum/core/types"
8 | )
9 |
10 | type GasPriceReader func(block *ethmonitor.Block) []*big.Int
11 |
12 | var CustomGasPriceBidReaders = map[uint64]GasPriceReader{}
13 |
14 | var CustomGasPricePaidReaders = map[uint64]GasPriceReader{
15 | 42161: arbitrumGasPricePaidReader, // arbitrum one
16 | 42170: arbitrumGasPricePaidReader, // arbitrum nova
17 | 421611: arbitrumGasPricePaidReader, // arbitrum rinkeby
18 | 421613: arbitrumGasPricePaidReader, // arbitrum goerli
19 | 421614: arbitrumGasPricePaidReader, // arbitrum sepolia
20 | 200: arbitrumGasPricePaidReader, // arbitrum xdai
21 | }
22 |
23 | func DefaultGasPriceBidReader(block *ethmonitor.Block) []*big.Int {
24 | transactions := block.Transactions()
25 | prices := make([]*big.Int, 0, len(transactions))
26 |
27 | for _, transaction := range transactions {
28 | prices = append(prices, transaction.GasFeeCap())
29 | }
30 |
31 | return prices
32 | }
33 |
34 | func DefaultGasPricePaidReader(block *ethmonitor.Block) []*big.Int {
35 | transactions := block.Transactions()
36 | prices := make([]*big.Int, 0, len(transactions))
37 |
38 | for _, transaction := range transactions {
39 | var price *big.Int
40 |
41 | switch transaction.Type() {
42 | case types.LegacyTxType:
43 | price = transaction.GasPrice()
44 | case types.AccessListTxType:
45 | price = transaction.GasPrice()
46 | case types.DynamicFeeTxType:
47 | price = new(big.Int).Add(block.BaseFee(), transaction.GasTipCap())
48 | }
49 |
50 | prices = append(prices, price)
51 | }
52 |
53 | return prices
54 | }
55 |
56 | func arbitrumGasPricePaidReader(block *ethmonitor.Block) []*big.Int {
57 | transactions := block.Transactions()
58 | prices := make([]*big.Int, 0, len(transactions))
59 |
60 | for range transactions {
61 | prices = append(prices, block.BaseFee())
62 | }
63 |
64 | return prices
65 | }
66 |
--------------------------------------------------------------------------------
/ethkit-test.json.sample:
--------------------------------------------------------------------------------
1 | {
2 | "GANACHE_URL": "http://localhost:8545/",
3 |
4 | "MAINNET_URL": "",
5 | "MAINNET_WSS_URL": "",
6 |
7 | "SEPOLIA_URL": "",
8 | "SEPOLIA_WSS_URL": "",
9 |
10 | "POLYGON_MAINNET_URL": "",
11 | "POLYGON_MAINNET_WSS_URL": "",
12 |
13 | "ARBITRUM_MAINNET_URL": "",
14 | "ARBITRUM_MAINNET_WSS_URL": "",
15 |
16 | "OPTIMISM_MAINNET_URL": "",
17 | "OPTIMISM_MAINNET_WSS_URL": "",
18 |
19 | "PRIVATE_WALLET_MNEMONIC": ""
20 | }
21 |
--------------------------------------------------------------------------------
/ethkit.go:
--------------------------------------------------------------------------------
1 | package ethkit
2 |
--------------------------------------------------------------------------------
/ethmempool/subscription.go:
--------------------------------------------------------------------------------
1 | package ethmempool
2 |
3 | type Subscription interface {
4 | PendingTransactionHash() <-chan string
5 | Done() <-chan struct{}
6 | Unsubscribe()
7 | }
8 |
9 | type subscriber struct {
10 | ch chan string
11 | done chan struct{}
12 | unsubscribe func()
13 | notifyFilterFunc NotifyFilterFunc
14 | }
15 |
16 | func (s *subscriber) PendingTransactionHash() <-chan string {
17 | return s.ch
18 | }
19 |
20 | func (s *subscriber) Done() <-chan struct{} {
21 | return s.done
22 | }
23 |
24 | func (s *subscriber) Unsubscribe() {
25 | s.unsubscribe()
26 | }
27 |
28 | type NotifyFilterFunc func(pendingTxnHash string) bool
29 |
--------------------------------------------------------------------------------
/ethproviders/config.go:
--------------------------------------------------------------------------------
1 | package ethproviders
2 |
3 | import "strings"
4 |
5 | type Config map[string]NetworkConfig
6 |
7 | type NetworkConfig struct {
8 | // ID is the globally unique chain ID. See https://chainlist.wtf
9 | ID uint64 `toml:"id" json:"id"`
10 |
11 | // URL is the URL for the blockchain node JSON-RPC endpoint
12 | URL string `toml:"url" json:"url"`
13 |
14 | // WSEnabled marks the chain to support websocket connections.
15 | // NOTE: you may leave `WSURL` empty and it will use the `URL`
16 | // of the node as the WSURL by default. Or you can set `WSURL` to
17 | // another URL for websocket connections
18 | WSEnabled bool `toml:"ws_enabled" json:"wsEnabled"`
19 |
20 | // WSURL is the URL for the websocket. You must also set `WSEnabled`
21 | // to `true`
22 | WSURL string `toml:"ws_url" json:"wsUrl"`
23 |
24 | // Testnet marks the chain as a testnet.
25 | Testnet bool `toml:"testnet" json:"testnet"`
26 |
27 | // AuthChain marks the chain as an auth chain.
28 | // Deprecated: no longer required.
29 | AuthChain bool `toml:"auth_chain" json:"authChain"`
30 |
31 | // Disabled marks the chain as disabled, and will not be included
32 | // in the list of providers at runtime.
33 | Disabled bool `toml:"disabled" json:"disabled"`
34 | }
35 |
36 | func (n Config) GetByID(id uint64) (NetworkConfig, bool) {
37 | for _, v := range n {
38 | if v.ID == id {
39 | return v, true
40 | }
41 | }
42 | return NetworkConfig{}, false
43 | }
44 |
45 | func (n Config) GetByName(name string) (NetworkConfig, bool) {
46 | name = strings.ToLower(name)
47 | for k, v := range n {
48 | if k == name {
49 | return v, true
50 | }
51 | }
52 | return NetworkConfig{}, false
53 | }
54 |
55 | // Deprecated: no longer required.
56 | func (n Config) AuthChain() (NetworkConfig, bool) {
57 | for _, v := range n {
58 | if v.AuthChain && !v.Testnet {
59 | return v, true
60 | }
61 | }
62 | return NetworkConfig{}, false
63 | }
64 |
65 | // Deprecated: no longer required.
66 | func (n Config) TestAuthChain() (NetworkConfig, bool) {
67 | for _, v := range n {
68 | if v.AuthChain && v.Testnet {
69 | return v, true
70 | }
71 | }
72 | return NetworkConfig{}, false
73 | }
74 |
--------------------------------------------------------------------------------
/ethrpc/batch.go:
--------------------------------------------------------------------------------
1 | package ethrpc
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 |
7 | "github.com/0xsequence/ethkit/ethrpc/jsonrpc"
8 | )
9 |
10 | type BatchCall []*Call
11 |
12 | func (b *BatchCall) MarshalJSON() ([]byte, error) {
13 | if len(*b) == 1 {
14 | return json.Marshal((*b)[0].request)
15 | }
16 | reqBody := make([]jsonrpc.Message, len(*b))
17 | for i, r := range *b {
18 | reqBody[i] = r.request
19 | }
20 | return json.Marshal(reqBody)
21 | }
22 |
23 | func (b *BatchCall) UnmarshalJSON(data []byte) error {
24 | var (
25 | results []*jsonrpc.Message
26 | target any = &results
27 | )
28 | if data[0] != '[' {
29 | results = make([]*jsonrpc.Message, 1)
30 | target = &results[0]
31 | }
32 |
33 | if err := json.Unmarshal(data, target); err != nil {
34 | return fmt.Errorf("failed to unmarshal batch response: %w", err)
35 | }
36 | if len(results) > len(*b) {
37 | return fmt.Errorf("more responses (%d) than requests (%d)", len(results), len(*b))
38 | }
39 | for i, msg := range results {
40 | (*b)[i].response = msg
41 | if msg.Error != nil {
42 | (*b)[i].err = msg.Error
43 | }
44 | }
45 | return nil
46 | }
47 |
48 | func (b *BatchCall) ErrorOrNil() error {
49 | err := make(BatchError)
50 | for i, r := range *b {
51 | if r.err != nil {
52 | err[i] = r
53 | }
54 | }
55 | if len(err) > 0 {
56 | return err
57 | }
58 | return nil
59 | }
60 |
61 | type BatchError map[int]*Call
62 |
63 | func (e BatchError) Error() string {
64 | if len(e) == 0 {
65 | return ""
66 | }
67 | if len(e) == 1 {
68 | return e.Unwrap().Error()
69 | }
70 | return fmt.Sprintf("%d errors", len(e))
71 | }
72 |
73 | func (e BatchError) ErrorMap() map[int]error {
74 | errMap := make(map[int]error, len(e))
75 | for i, c := range e {
76 | errMap[i] = c
77 | }
78 | return errMap
79 | }
80 |
81 | func (e BatchError) Unwrap() error {
82 | for _, nested := range e {
83 | return nested
84 | }
85 | return nil
86 | }
87 |
--------------------------------------------------------------------------------
/ethrpc/ens_test.go:
--------------------------------------------------------------------------------
1 | package ethrpc_test
2 |
3 | import (
4 | "context"
5 | "testing"
6 |
7 | "github.com/0xsequence/ethkit/ethrpc"
8 | "github.com/stretchr/testify/assert"
9 | )
10 |
11 | var (
12 | ctx context.Context
13 | provider *ethrpc.Provider
14 | )
15 |
16 | func init() {
17 | ctx = context.Background()
18 |
19 | // Mainnet Node only
20 | provider, _ = ethrpc.NewProvider("https://mainnet...node...url...")
21 | }
22 |
23 | func XXTestEns(t *testing.T) {
24 | {
25 | address, ok, err := ethrpc.ResolveEnsAddress(ctx, "0xsequence.eth", provider)
26 | assert.NoError(t, err)
27 | assert.True(t, ok)
28 | assert.Equal(t, address.Hex(), "0xdAd546CA5332d24c02f5834ce2fac07197677Eac")
29 | }
30 | {
31 | address, ok, err := ethrpc.ResolveEnsAddress(ctx, "vitalik.eth", provider)
32 | assert.NoError(t, err)
33 | assert.True(t, ok)
34 | assert.Equal(t, address.Hex(), "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
35 | }
36 | {
37 | _, ok, _ := ethrpc.ResolveEnsAddress(ctx, "0x22", provider)
38 | assert.False(t, ok)
39 | }
40 | {
41 | address, ok, err := ethrpc.ResolveEnsAddress(ctx, "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", provider)
42 | assert.NoError(t, err)
43 | assert.True(t, ok)
44 | assert.Equal(t, address.Hex(), "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ethrpc/filter.go:
--------------------------------------------------------------------------------
1 | package ethrpc
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/0xsequence/ethkit/go-ethereum"
7 | )
8 |
9 | func toFilterArg(q ethereum.FilterQuery) (interface{}, error) {
10 | arg := map[string]interface{}{
11 | "topics": q.Topics,
12 | }
13 | if len(q.Addresses) > 0 {
14 | arg["address"] = q.Addresses
15 | }
16 | if q.BlockHash != nil {
17 | arg["blockHash"] = *q.BlockHash
18 | if q.FromBlock != nil || q.ToBlock != nil {
19 | return nil, fmt.Errorf("cannot specify both BlockHash and FromBlock/ToBlock")
20 | }
21 | } else {
22 | if q.FromBlock == nil {
23 | arg["fromBlock"] = "0x0"
24 | } else {
25 | arg["fromBlock"] = toBlockNumArg(q.FromBlock)
26 | }
27 | arg["toBlock"] = toBlockNumArg(q.ToBlock)
28 | }
29 | return arg, nil
30 | }
31 |
--------------------------------------------------------------------------------
/ethrpc/jsonrpc/jsonrpc.go:
--------------------------------------------------------------------------------
1 | package jsonrpc
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | )
7 |
8 | // Message is either a JSONRPC request or response.
9 | type Message struct {
10 | Version string `json:"jsonrpc"`
11 | ID uint64 `json:"id"`
12 | Method string `json:"method,omitempty"`
13 | Params []any `json:"params,omitempty"`
14 | Result json.RawMessage `json:"result,omitempty"`
15 | Error *Error `json:"error,omitempty"`
16 | }
17 |
18 | // NewRequest returns a new JSONRPC request Message.
19 | func NewRequest(id uint64, method string, params []any) Message {
20 | return Message{
21 | Version: "2.0",
22 | ID: id,
23 | Method: method,
24 | Params: params,
25 | }
26 | }
27 |
28 | // Error is a JSONRPC error returned from the node.
29 | type Error struct {
30 | Code int `json:"code,omitempty"`
31 | Message string `json:"message,omitempty"`
32 | Data json.RawMessage `json:"data,omitempty"`
33 | }
34 |
35 | // Error implements the error interface.
36 | func (e Error) Error() string {
37 | return fmt.Sprintf("jsonrpc error %d: %s", e.Code, e.Message)
38 | }
39 |
--------------------------------------------------------------------------------
/ethrpc/option.go:
--------------------------------------------------------------------------------
1 | package ethrpc
2 |
3 | import (
4 | "log/slog"
5 | "net/http"
6 | "strings"
7 |
8 | "github.com/goware/breaker"
9 | )
10 |
11 | type Option func(*Provider)
12 |
13 | type httpClient interface {
14 | Do(req *http.Request) (*http.Response, error)
15 | }
16 |
17 | func WithStreaming(nodeWebsocketURL string) Option {
18 | return func(p *Provider) {
19 | nodeWSURL := nodeWebsocketURL
20 | nodeWSURL = strings.Replace(nodeWSURL, "http://", "ws://", 1)
21 | nodeWSURL = strings.Replace(nodeWSURL, "https://", "wss://", 1)
22 | p.nodeWSURL = nodeWSURL
23 | }
24 | }
25 |
26 | func WithHTTPClient(c httpClient) Option {
27 | return func(p *Provider) {
28 | p.httpClient = c
29 | }
30 | }
31 |
32 | func WithLogger(log *slog.Logger) Option {
33 | return func(p *Provider) {
34 | p.log = log
35 | }
36 | }
37 |
38 | func WithBreaker(br breaker.Breaker) Option {
39 | return func(p *Provider) {
40 | p.br = br
41 | }
42 | }
43 |
44 | // func WithCache(cache cachestore.Store[[]byte]) Option {
45 | // return func(p *Provider) {
46 | // p.cache = cache
47 | // }
48 | // }
49 |
50 | // 0: disabled, no validation (default)
51 | // 1: semi-strict transactions – validates only transaction V, R, S values
52 | // 2: strict block and transactions – validates block hash, sender address, and transaction signatures
53 | func WithStrictness(strictness StrictnessLevel) Option {
54 | return func(p *Provider) {
55 | p.strictness = strictness
56 | }
57 | }
58 |
59 | func WithSemiValidation() Option {
60 | return func(p *Provider) {
61 | p.strictness = StrictnessLevel_Semi
62 | }
63 | }
64 |
65 | func WithStrictValidation() Option {
66 | return func(p *Provider) {
67 | p.strictness = StrictnessLevel_Strict
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/ethrpc/strictness.go:
--------------------------------------------------------------------------------
1 | package ethrpc
2 |
3 | // StrictnessLevel is the level of strictness for validation when unmarshalling
4 | // blocks and transactions from RPC responses from a node.
5 | type StrictnessLevel uint8
6 |
7 | const (
8 | StrictnessLevel_None StrictnessLevel = iota // 0: disabled, no validation on blocks or transactions (default)
9 | StrictnessLevel_Semi // 1: semi-strict transactions – validates only transaction V, R, S values
10 | StrictnessLevel_Strict // 2: strict block and transactions – validates block hash, sender address, and transaction signatures
11 | )
12 |
13 | var StrictnessLevels = map[uint8]string{
14 | 0: "NONE",
15 | 1: "SEMI",
16 | 2: "STRICT",
17 | }
18 |
19 | func (x StrictnessLevel) String() string {
20 | return StrictnessLevels[uint8(x)]
21 | }
22 |
--------------------------------------------------------------------------------
/ethrpc/utils.go:
--------------------------------------------------------------------------------
1 | package ethrpc
2 |
3 | import (
4 | "context"
5 | "errors"
6 | "fmt"
7 | "time"
8 |
9 | "github.com/0xsequence/ethkit/go-ethereum"
10 | "github.com/0xsequence/ethkit/go-ethereum/common"
11 | "github.com/0xsequence/ethkit/go-ethereum/core/types"
12 | )
13 |
14 | func WaitForTxnReceipt(ctx context.Context, provider *Provider, txHash common.Hash) (*types.Receipt, error) {
15 | var clearTimeout context.CancelFunc
16 | if _, ok := ctx.Deadline(); !ok {
17 | ctx, clearTimeout = context.WithTimeout(ctx, 120*time.Second) // default timeout of 120 seconds
18 | defer clearTimeout()
19 | }
20 |
21 | for {
22 | select {
23 | case <-ctx.Done():
24 | if err := ctx.Err(); err != nil {
25 | return nil, fmt.Errorf("ethwallet, WaitReceipt for %v: %w", txHash, err)
26 | }
27 | default:
28 | }
29 |
30 | receipt, err := provider.TransactionReceipt(ctx, txHash)
31 | if err != nil && !errors.Is(err, ethereum.NotFound) {
32 | return nil, err
33 | }
34 |
35 | if receipt != nil {
36 | return receipt, nil
37 | }
38 |
39 | time.Sleep(1 * time.Second)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ethtest/ethtest.go:
--------------------------------------------------------------------------------
1 | package ethtest
2 |
--------------------------------------------------------------------------------
/ethtest/reorgme.go:
--------------------------------------------------------------------------------
1 | package ethtest
2 |
3 | type Reorgme struct {
4 | }
5 |
6 | // TODO: implement controls to Reorgme
7 | // See ethmonitor_test.go for example. We just need to build a wrapper interface for it here.
8 |
--------------------------------------------------------------------------------
/ethtest/reorgme/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/ethtest/reorgme/isRunning.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | yarn chain:ip --index 0 > /dev/null 2>&1
4 | RES=$?
5 |
6 | if [ $RES == 1 ]
7 | then
8 | echo "*****"
9 | echo "Oops! reorgme is not running. Please run 'make start-reorgme'."
10 | echo "*****"
11 | exit 1
12 | fi
13 |
14 | exit 0
15 |
--------------------------------------------------------------------------------
/ethtest/reorgme/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reorgme",
3 | "version": "0.0.0",
4 | "main": "index.js",
5 | "license": "MIT",
6 | "scripts": {
7 | "start:stop:detached": "./node_modules/.bin/reorgme stop",
8 | "start:server:detached": "./node_modules/.bin/reorgme start --allocation 0xf41c74c9ae680c1aa78f42e5647a62f353b7bdde=1000000000000000000",
9 | "start:server": "./node_modules/.bin/reorgme start --detach false --allocation 0xf41c74c9ae680c1aa78f42e5647a62f353b7bdde=1000000000000000000",
10 | "chain:ip": "./node_modules/.bin/reorgme node ip --index",
11 | "chain:fork": "./node_modules/.bin/reorgme fork",
12 | "chain:logs": "./node_modules/.bin/reorgme logs",
13 | "chain:join": "./node_modules/.bin/reorgme join"
14 | },
15 | "dependencies": {
16 | "reorgme": "https://github.com/0xsequence/reorgme#geth-v1.10.4"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ethtest/testchain/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/ethtest/testchain/hardhat.config.js:
--------------------------------------------------------------------------------
1 | // see https://hardhat.org/hardhat-network/docs/reference#config
2 | module.exports = {
3 | solidity: "0.8.28",
4 |
5 | networks: {
6 | hardhat: {
7 | mining: {
8 | auto: false,
9 | interval: 1000
10 | },
11 |
12 | // gas: 10000000000000,
13 | // blockGasLimit: 10000000000000,
14 | // gasPrice: 2,
15 | initialBaseFeePerGas: 1,
16 | chainId: 1337,
17 | accounts: {
18 | mnemonic: 'major danger this key only test please avoid main net use okay'
19 | },
20 | // loggingEnabled: true
21 | // verbose: true
22 | },
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ethtest/testchain/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "testchain",
3 | "version": "0.0.0",
4 | "private": true,
5 | "license": "none",
6 | "scripts": {
7 | "start:hardhat": "hardhat node --hostname 0.0.0.0",
8 | "start:hardhat:verbose": "hardhat --verbose node --hostname 0.0.0.0",
9 | "start:geth": "docker run -p 8545:8545 --rm ethereum/client-go:v1.15.11 --networkid ${npm_package_config_testchainChainID} --dev --dev.period 1 --dev.gaslimit ${npm_package_config_testchainGasLimit} --miner.gaslimit ${npm_package_config_testchainGasLimit} --miner.gasprice 1 --http --http.addr 0.0.0.0 --rpc.allow-unprotected-txs --verbosity 1",
10 | "start:geth:verbose": "docker run -p 8545:8545 --rm ethereum/client-go:v1.15.11 --networkid ${npm_package_config_testchainChainID} --dev --dev.period 1 --dev.gaslimit ${npm_package_config_testchainGasLimit} --miner.gaslimit ${npm_package_config_testchainGasLimit} --miner.gasprice 1 --http --http.addr 0.0.0.0 --rpc.allow-unprotected-txs",
11 | "start:anvil": "anvil --mnemonic \"${npm_package_config_mnemonic}\" --block-time 1 --balance ${npm_package_config_etherBalance} --host 0.0.0.0 --chain-id ${npm_package_config_testchainChainID} --gas-limit ${npm_package_config_testchainGasLimit} --gas-price ${npm_package_config_testchainGasPrice}",
12 | "start:anvil:verbose": "anvil --mnemonic \"${npm_package_config_mnemonic}\" --block-time 1 --balance ${npm_package_config_etherBalance} --host 0.0.0.0 --chain-id ${npm_package_config_testchainChainID} --gas-limit ${npm_package_config_testchainGasLimit} --gas-price ${npm_package_config_testchainGasPrice} -vvv",
13 | "install:anvil": "curl -L https://foundry.paradigm.xyz | bash; foundryup",
14 | "wait:server": "wait-on -t 120000 tcp:127.0.0.1:8545"
15 | },
16 | "devDependencies": {
17 | "concurrently": "^9.1.2",
18 | "hardhat": "^2.24.1",
19 | "wait-on": "^8.0.3"
20 | },
21 | "config": {
22 | "mnemonic": "major danger this key only test please avoid main net use okay",
23 | "testchainChainID": 1337,
24 | "testchainPort": 8545,
25 | "testchainGasLimit": "15000000",
26 | "testchainGasPrice": "20000000000",
27 | "etherBalance": "100000",
28 | "extra": ""
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ethtest/testchain_test.go:
--------------------------------------------------------------------------------
1 | package ethtest_test
2 |
3 | import (
4 | "math/big"
5 | "testing"
6 |
7 | "github.com/0xsequence/ethkit/ethcoder"
8 | "github.com/0xsequence/ethkit/ethtest"
9 | "github.com/0xsequence/ethkit/go-ethereum/core/types"
10 | "github.com/stretchr/testify/assert"
11 | )
12 |
13 | // yes, we even have to test the testutil
14 |
15 | var (
16 | testchain *ethtest.Testchain
17 | )
18 |
19 | func init() {
20 | var err error
21 | testchain, err = ethtest.NewTestchain()
22 | if err != nil {
23 | panic(err)
24 | }
25 | }
26 |
27 | func TestTestchainID(t *testing.T) {
28 | assert.Equal(t, testchain.ChainID().Uint64(), uint64(1337))
29 | }
30 |
31 | func TestContractHelpers(t *testing.T) {
32 | callmockContract, receipt := testchain.Deploy(t, "CallReceiverMock")
33 | assert.NotNil(t, callmockContract)
34 | assert.NotNil(t, receipt)
35 |
36 | // Update contract value on CallReceiver by calling 'testCall' contract function
37 | receipt, err := ethtest.ContractTransact(
38 | testchain.MustWallet(2),
39 | callmockContract.Address, callmockContract.ABI,
40 | "testCall", big.NewInt(143), ethcoder.MustHexDecode("0x112233"),
41 | )
42 | assert.NoError(t, err)
43 | assert.NotNil(t, receipt)
44 | assert.Equal(t, types.ReceiptStatusSuccessful, receipt.Status)
45 |
46 | // Query the value ensuring its been updated on-chain
47 | ret, err := ethtest.ContractQuery(testchain.Provider, callmockContract.Address, "lastValA()", "uint256", nil)
48 | assert.NoError(t, err)
49 | assert.Equal(t, []string{"143"}, ret)
50 |
51 | // Query the value using different method, where we unpack the value
52 | var result *big.Int
53 | _, err = ethtest.ContractCall(testchain.Provider, callmockContract.Address, callmockContract.ABI, &result, "lastValA")
54 | assert.NoError(t, err)
55 | assert.Equal(t, uint64(143), result.Uint64())
56 | }
57 |
--------------------------------------------------------------------------------
/ethtxn/ethtxn_test.go:
--------------------------------------------------------------------------------
1 | package ethtxn_test
2 |
3 | import "testing"
4 |
5 | func TestTxnSend(t *testing.T) {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/ethutil/validate_logs_with_block.go:
--------------------------------------------------------------------------------
1 | package ethutil
2 |
3 | import (
4 | "bytes"
5 |
6 | "github.com/0xsequence/ethkit/go-ethereum/core/types"
7 | )
8 |
9 | // ValidateLogsWithBlockHeader validates that the logs comes from given block.
10 | // If the list of logs is not complete or the logs are not from the block, it
11 | // will return false.
12 | func ValidateLogsWithBlockHeader(logs []types.Log, header *types.Header) bool {
13 | return bytes.Compare(logsToBloom(logs).Bytes(), header.Bloom.Bytes()) == 0
14 | }
15 |
16 | func logsToBloom(logs []types.Log) types.Bloom {
17 | var logBloom types.Bloom
18 | for _, log := range logs {
19 | logBloom.Add(log.Address.Bytes())
20 | for _, b := range log.Topics {
21 | logBloom.Add(b[:])
22 | }
23 | }
24 | return logBloom
25 | }
26 |
--------------------------------------------------------------------------------
/ethutil/validate_logs_with_block_test.go:
--------------------------------------------------------------------------------
1 | package ethutil
2 |
3 | import (
4 | "context"
5 | "math/big"
6 | "testing"
7 |
8 | "github.com/0xsequence/ethkit/ethrpc"
9 | "github.com/0xsequence/ethkit/go-ethereum"
10 | "github.com/stretchr/testify/require"
11 | )
12 |
13 | func TestValidateLogsWithBlockHeader(t *testing.T) {
14 | p, err := ethrpc.NewProvider("https://nodes.sequence.app/polygon")
15 | require.NoError(t, err)
16 |
17 | header, err := p.HeaderByNumber(context.Background(), big.NewInt(20_000_003))
18 | require.NoError(t, err)
19 | require.NotNil(t, header)
20 |
21 | logs, err := p.FilterLogs(context.Background(), ethereum.FilterQuery{
22 | FromBlock: big.NewInt(20_000_003),
23 | ToBlock: big.NewInt(20_000_003),
24 | })
25 | require.NoError(t, err)
26 |
27 | require.True(t, ValidateLogsWithBlockHeader(logs, header))
28 | }
29 |
--------------------------------------------------------------------------------
/ethwallet/README.md:
--------------------------------------------------------------------------------
1 | ethwallet
2 | =========
3 |
4 | inspired by the work of Miguel Mota at github.com/miguelmota/go-ethereum-hdwallet and
5 | Richard Moore at github.com/ethers-io/ethers.js
6 |
7 |
--------------------------------------------------------------------------------
/ethwallet/provider.go:
--------------------------------------------------------------------------------
1 | package ethwallet
2 |
3 | import (
4 | "context"
5 | "math/big"
6 |
7 | "github.com/0xsequence/ethkit/ethrpc"
8 | "github.com/0xsequence/ethkit/go-ethereum/accounts/abi/bind"
9 | )
10 |
11 | // WalletProvider is a helper to query the provider in context of the wallet address
12 | type WalletProvider struct {
13 | wallet *Wallet
14 | provider *ethrpc.Provider
15 | }
16 |
17 | func (w *WalletProvider) Backend() *ethrpc.Provider {
18 | return w.provider
19 | }
20 |
21 | func (w *WalletProvider) NewTransactor(ctx context.Context) (*bind.TransactOpts, error) {
22 | // Get suggested gas price, the user can change this on their own too
23 | gasPrice, err := w.provider.SuggestGasPrice(ctx)
24 | if err != nil {
25 | return nil, err
26 | }
27 |
28 | auth, err := w.wallet.Transactor(ctx)
29 | if err != nil {
30 | return nil, err
31 | }
32 |
33 | auth.Value = big.NewInt(0)
34 | auth.GasLimit = 0 // (0 = estimate)
35 | auth.GasPrice = gasPrice
36 | auth.Nonce = nil // remains unset, will be auto-set or user can specify
37 |
38 | return auth, nil
39 | }
40 |
41 | func (w *WalletProvider) GetEtherBalanceAt(ctx context.Context, blockNum *big.Int) (*big.Int, error) {
42 | balance, err := w.provider.BalanceAt(ctx, w.wallet.Address(), blockNum)
43 | if err != nil {
44 | return nil, err
45 | }
46 | return balance, nil
47 | }
48 |
49 | func (w *WalletProvider) GetTransactionCount(ctx context.Context) (uint64, error) {
50 | nonce, err := w.provider.PendingNonceAt(ctx, w.wallet.Address())
51 | if err != nil {
52 | return 0, err
53 | }
54 | return nonce, nil
55 | }
56 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/abigen/testdata/v2/empty.go.txt:
--------------------------------------------------------------------------------
1 | // Code generated via abigen V2 - DO NOT EDIT.
2 | // This file is a generated binding and any manual changes will be lost.
3 |
4 | package bindtests
5 |
6 | import (
7 | "bytes"
8 | "errors"
9 | "math/big"
10 |
11 | "github.com/0xsequence/ethkit/go-ethereum/accounts/abi"
12 | "github.com/0xsequence/ethkit/go-ethereum/accounts/abi/bind/v2"
13 | "github.com/0xsequence/ethkit/go-ethereum/common"
14 | "github.com/0xsequence/ethkit/go-ethereum/core/types"
15 | )
16 |
17 | // Reference imports to suppress errors if they are not otherwise used.
18 | var (
19 | _ = bytes.Equal
20 | _ = errors.New
21 | _ = big.NewInt
22 | _ = common.Big1
23 | _ = types.BloomLookup
24 | _ = abi.ConvertType
25 | )
26 |
27 | // EmptyMetaData contains all meta data concerning the Empty contract.
28 | var EmptyMetaData = bind.MetaData{
29 | ABI: "[]",
30 | ID: "c4ce3210982aa6fc94dabe46dc1dbf454d",
31 | Bin: "0x606060405260068060106000396000f3606060405200",
32 | }
33 |
34 | // Empty is an auto generated Go binding around an Ethereum contract.
35 | type Empty struct {
36 | abi abi.ABI
37 | }
38 |
39 | // NewEmpty creates a new instance of Empty.
40 | func NewEmpty() *Empty {
41 | parsed, err := EmptyMetaData.ParseABI()
42 | if err != nil {
43 | panic(errors.New("invalid ABI: " + err.Error()))
44 | }
45 | return &Empty{abi: *parsed}
46 | }
47 |
48 | // Instance creates a wrapper for a deployed contract instance at the given address.
49 | // Use this to create the instance object passed to abigen v2 library functions Call, Transact, etc.
50 | func (c *Empty) Instance(backend bind.ContractBackend, addr common.Address) *bind.BoundContract {
51 | return bind.NewBoundContract(addr, c.abi, backend, backend, backend)
52 | }
53 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/db/contract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0
2 | pragma solidity >=0.7.0 <0.9.0;
3 |
4 | contract DB {
5 | uint balance = 0;
6 | mapping(uint => uint) private _store;
7 | uint[] private _keys;
8 | struct Stats {
9 | uint gets;
10 | uint inserts;
11 | uint mods; // modifications
12 | }
13 | Stats _stats;
14 |
15 | event KeyedInsert(uint indexed key, uint value);
16 | event Insert(uint key, uint value, uint length);
17 |
18 | constructor() {
19 | _stats = Stats(0, 0, 0);
20 | }
21 |
22 | // insert adds a key value to the store, returning the new length of the store.
23 | function insert(uint k, uint v) external returns (uint) {
24 | // No need to store 0 values
25 | if (v == 0) {
26 | return _keys.length;
27 | }
28 | // Check if a key is being overriden
29 | if (_store[k] == 0) {
30 | _keys.push(k);
31 | _stats.inserts++;
32 | } else {
33 | _stats.mods++;
34 | }
35 | _store[k] = v;
36 | emit Insert(k, v, _keys.length);
37 | emit KeyedInsert(k, v);
38 |
39 | return _keys.length;
40 | }
41 |
42 | function get(uint k) public returns (uint) {
43 | _stats.gets++;
44 | return _store[k];
45 | }
46 |
47 | function getStatParams() public view returns (uint, uint, uint) {
48 | return (_stats.gets, _stats.inserts, _stats.mods);
49 | }
50 |
51 | function getNamedStatParams() public view returns (uint gets, uint inserts, uint mods) {
52 | return (_stats.gets, _stats.inserts, _stats.mods);
53 | }
54 |
55 | function getStatsStruct() public view returns (Stats memory) {
56 | return _stats;
57 | }
58 |
59 | receive() external payable {
60 | balance += msg.value;
61 | }
62 |
63 | fallback(bytes calldata _input) external returns (bytes memory _output) {
64 | _output = _input;
65 | }
66 | }
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/events/combined-abi.json:
--------------------------------------------------------------------------------
1 | {"contracts":{"contract.sol:C":{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"data","type":"uint256"}],"name":"basic1","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"flag","type":"bool"},{"indexed":false,"internalType":"uint256","name":"data","type":"uint256"}],"name":"basic2","type":"event"},{"inputs":[],"name":"EmitMulti","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"EmitOne","outputs":[],"stateMutability":"nonpayable","type":"function"}],"bin":"6080604052348015600e575f5ffd5b506101a08061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c8063cb49374914610038578063e8e49a7114610042575b5f5ffd5b61004061004c565b005b61004a6100fd565b005b60017f8f17dc823e2f9fcdf730b8182c935574691e811e7d46399fe0ff0087795cd207600260405161007e9190610151565b60405180910390a260037f8f17dc823e2f9fcdf730b8182c935574691e811e7d46399fe0ff0087795cd20760046040516100b89190610151565b60405180910390a25f15157f3b29b9f6d15ba80d866afb3d70b7548ab1ffda3ef6e65f35f1cb05b0e2b29f4e60016040516100f39190610151565b60405180910390a2565b60017f8f17dc823e2f9fcdf730b8182c935574691e811e7d46399fe0ff0087795cd207600260405161012f9190610151565b60405180910390a2565b5f819050919050565b61014b81610139565b82525050565b5f6020820190506101645f830184610142565b9291505056fea26469706673582212207331c79de16a73a1639c4c4b3489ea78a3ed35fe62a178824f586df12672ac0564736f6c634300081c0033"}},"version":"0.8.28+commit.7893614a.Darwin.appleclang"}
2 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/events/contract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.26;
3 |
4 | contract C {
5 | event basic1(
6 | uint256 indexed id,
7 | uint256 data
8 | );
9 | event basic2(
10 | bool indexed flag,
11 | uint256 data
12 | );
13 |
14 | function EmitOne() public {
15 | emit basic1(
16 | uint256(1),
17 | uint256(2));
18 | }
19 |
20 | // emit multiple events, different types
21 | function EmitMulti() public {
22 | emit basic1(
23 | uint256(1),
24 | uint256(2));
25 | emit basic1(
26 | uint256(3),
27 | uint256(4));
28 | emit basic2(
29 | false,
30 | uint256(1));
31 | }
32 |
33 | constructor() {
34 | // do something with these
35 | }
36 | }
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/nested_libraries/contract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.26;
3 |
4 |
5 | // L1
6 | // \
7 | // L2 L3 L1
8 | // \ / /
9 | // L4 /
10 | // \ /
11 | // C1
12 | //
13 | library L1 {
14 | function Do(uint256 val) public pure returns (uint256) {
15 | return uint256(1);
16 | }
17 | }
18 |
19 | library L2 {
20 | function Do(uint256 val) public pure returns (uint256) {
21 | return L1.Do(val) + uint256(1);
22 | }
23 | }
24 |
25 | library L3 {
26 | function Do(uint256 val) public pure returns (uint256) {
27 | return uint256(1);
28 | }
29 | }
30 |
31 | library L4 {
32 | function Do(uint256 val) public pure returns (uint256) {
33 | return L2.Do(uint256(val)) + L3.Do(uint256(val)) + uint256(1);
34 | }
35 | }
36 |
37 | contract C1 {
38 | function Do(uint256 val) public pure returns (uint256 res) {
39 | return L4.Do(uint256(val)) + L1.Do(uint256(0)) + uint256(1);
40 | }
41 |
42 | constructor(uint256 v1, uint256 v2) {
43 | // do something with these
44 | }
45 | }
46 |
47 | // second contract+libraries: slightly different library deps than V1, but sharing several
48 | // L1
49 | // \
50 | // L2b L3 L1
51 | // \ / /
52 | // L4b /
53 | // \ /
54 | // C2
55 | //
56 | library L4b {
57 | function Do(uint256 val) public pure returns (uint256) {
58 | return L2b.Do(uint256(val)) + uint256(1);
59 | }
60 | }
61 |
62 | library L2b {
63 | function Do(uint256 val) public pure returns (uint256) {
64 | return L1.Do(uint256(val)) + uint256(1);
65 | }
66 | }
67 |
68 | contract C2 {
69 | function Do(uint256 val) public pure returns (uint256 res) {
70 | return L4b.Do(uint256(val)) + L1.Do(uint256(0)) + uint256(1);
71 | }
72 |
73 | constructor(uint256 v1, uint256 v2) {
74 | // do something with these
75 | }
76 | }
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/solc_errors/contract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.26;
3 |
4 | error BadThing(uint256 arg1, uint256 arg2, uint256 arg3, bool arg4);
5 | error BadThing2(uint256 arg1, uint256 arg2, uint256 arg3, uint256 arg4);
6 |
7 | contract C {
8 | function Foo() public pure {
9 | revert BadThing({
10 | arg1: uint256(0),
11 | arg2: uint256(1),
12 | arg3: uint256(2),
13 | arg4: false
14 | });
15 | }
16 | function Bar() public pure {
17 | revert BadThing2({
18 | arg1: uint256(0),
19 | arg2: uint256(1),
20 | arg3: uint256(2),
21 | arg4: uint256(3)
22 | });
23 | }
24 | }
25 |
26 | // purpose of this is to test that generation of metadata for contract that emits one error produces valid Go code
27 | contract C2 {
28 | function Foo() public pure {
29 | revert BadThing({
30 | arg1: uint256(0),
31 | arg2: uint256(1),
32 | arg3: uint256(2),
33 | arg4: false
34 | });
35 | }
36 | }
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/uint256arrayreturn/combined-abi.json:
--------------------------------------------------------------------------------
1 | {"contracts":{"contract.sol:MyContract":{"abi":[{"inputs":[],"name":"GetNums","outputs":[{"internalType":"uint256[5]","name":"","type":"uint256[5]"}],"stateMutability":"pure","type":"function"}],"bin":"6080604052348015600e575f5ffd5b506101a78061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610029575f3560e01c8063bd6d10071461002d575b5f5ffd5b61003561004b565b6040516100429190610158565b60405180910390f35b610053610088565b5f6040518060a001604052805f8152602001600181526020016002815260200160038152602001600481525090508091505090565b6040518060a00160405280600590602082028036833780820191505090505090565b5f60059050919050565b5f81905092915050565b5f819050919050565b5f819050919050565b6100d9816100c7565b82525050565b5f6100ea83836100d0565b60208301905092915050565b5f602082019050919050565b61010b816100aa565b61011581846100b4565b9250610120826100be565b805f5b8381101561015057815161013787826100df565b9650610142836100f6565b925050600181019050610123565b505050505050565b5f60a08201905061016b5f830184610102565b9291505056fea2646970667358221220ef76cc678ca215c3e9e5261e3f33ac1cb9901c3186c2af167bfcd8f03b3b864c64736f6c634300081c0033"}},"version":"0.8.28+commit.7893614a.Darwin.appleclang"}
2 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/bind/v2/internal/contracts/uint256arrayreturn/contract.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.26;
3 |
4 | contract MyContract {
5 | // emit multiple events, different types
6 | function GetNums() public pure returns (uint256[5] memory) {
7 | uint256[5] memory myNums = [uint256(0), uint256(1), uint256(2), uint256(3), uint256(4)];
8 | return myNums;
9 | }
10 | }
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/doc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | // Package abi implements the Ethereum ABI (Application Binary
18 | // Interface).
19 | //
20 | // The Ethereum ABI is strongly typed, known at compile time
21 | // and static. This ABI will handle basic type casting; unsigned
22 | // to signed and visa versa. It does not handle slice casting such
23 | // as unsigned slice to signed slice. Bit size type casting is also
24 | // handled. ints with a bit size of 32 will be properly cast to int256,
25 | // etc.
26 | package abi
27 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/abi/utils.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package abi
18 |
19 | import "fmt"
20 |
21 | // ResolveNameConflict returns the next available name for a given thing.
22 | // This helper can be used for lots of purposes:
23 | //
24 | // - In solidity function overloading is supported, this function can fix
25 | // the name conflicts of overloaded functions.
26 | // - In golang binding generation, the parameter(in function, event, error,
27 | // and struct definition) name will be converted to camelcase style which
28 | // may eventually lead to name conflicts.
29 | //
30 | // Name conflicts are mostly resolved by adding number suffix. e.g. if the abi contains
31 | // Methods "send" and "send1", ResolveNameConflict would return "send2" for input "send".
32 | func ResolveNameConflict(rawName string, used func(string) bool) string {
33 | name := rawName
34 | ok := used(name)
35 | for idx := 0; ok; idx++ {
36 | name = fmt.Sprintf("%s%d", rawName, idx)
37 | ok = used(name)
38 | }
39 | return name
40 | }
41 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/accounts_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package accounts
18 |
19 | import (
20 | "bytes"
21 | "testing"
22 |
23 | "github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
24 | )
25 |
26 | func TestTextHash(t *testing.T) {
27 | t.Parallel()
28 | hash := TextHash([]byte("Hello Joe"))
29 | want := hexutil.MustDecode("0xa080337ae51c4e064c189e113edd0ba391df9206e2f49db658bb32cf2911730b")
30 | if !bytes.Equal(hash, want) {
31 | t.Fatalf("wrong hash: %x", hash)
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/keystore_fuzzing_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package keystore
18 |
19 | import (
20 | "testing"
21 | )
22 |
23 | func FuzzPassword(f *testing.F) {
24 | f.Fuzz(func(t *testing.T, password string) {
25 | ks := NewKeyStore(t.TempDir(), LightScryptN, LightScryptP)
26 | a, err := ks.NewAccount(password)
27 | if err != nil {
28 | t.Fatal(err)
29 | }
30 | if err := ks.Unlock(a, password); err != nil {
31 | t.Fatal(err)
32 | }
33 | })
34 | }
35 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/plain.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package keystore
18 |
19 | import (
20 | "encoding/json"
21 | "fmt"
22 | "os"
23 | "path/filepath"
24 |
25 | "github.com/0xsequence/ethkit/go-ethereum/common"
26 | )
27 |
28 | type keyStorePlain struct {
29 | keysDirPath string
30 | }
31 |
32 | func (ks keyStorePlain) GetKey(addr common.Address, filename, auth string) (*Key, error) {
33 | fd, err := os.Open(filename)
34 | if err != nil {
35 | return nil, err
36 | }
37 | defer fd.Close()
38 | key := new(Key)
39 | if err := json.NewDecoder(fd).Decode(key); err != nil {
40 | return nil, err
41 | }
42 | if key.Address != addr {
43 | return nil, fmt.Errorf("key content mismatch: have address %x, want %x", key.Address, addr)
44 | }
45 | return key, nil
46 | }
47 |
48 | func (ks keyStorePlain) StoreKey(filename string, key *Key, auth string) error {
49 | content, err := json.Marshal(key)
50 | if err != nil {
51 | return err
52 | }
53 | return writeKeyFile(filename, content)
54 | }
55 |
56 | func (ks keyStorePlain) JoinPath(filename string) string {
57 | if filepath.IsAbs(filename) {
58 | return filename
59 | }
60 | return filepath.Join(ks.keysDirPath, filename)
61 | }
62 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/.hiddenfile:
--------------------------------------------------------------------------------
1 | {"address":"f466859ead1932d743d622cb74fc058882e8648a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3}
2 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/README:
--------------------------------------------------------------------------------
1 | This directory contains accounts for testing.
2 | The password that unlocks them is "foobar".
3 |
4 | The "good" key files which are supposed to be loadable are:
5 |
6 | - File: UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8
7 | Address: 0x7ef5a6135f1fd6a02593eedc869c6d41d934aef8
8 | - File: aaa
9 | Address: 0xf466859ead1932d743d622cb74fc058882e8648a
10 | - File: zzz
11 | Address: 0x289d485d9771714cce91d3393d764e1311907acc
12 |
13 | The other files (including this README) are broken in various ways
14 | and should not be picked up by package accounts:
15 |
16 | - File: no-address (missing address field, otherwise same as "aaa")
17 | - File: garbage (file with random data)
18 | - File: empty (file with no content)
19 | - File: swapfile~ (should be skipped)
20 | - File: .hiddenfile (should be skipped)
21 | - File: foo/... (should be skipped because it is a directory)
22 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/UTC--2016-03-22T12-57-55.920751759Z--7ef5a6135f1fd6a02593eedc869c6d41d934aef8:
--------------------------------------------------------------------------------
1 | {"address":"7ef5a6135f1fd6a02593eedc869c6d41d934aef8","crypto":{"cipher":"aes-128-ctr","ciphertext":"1d0839166e7a15b9c1333fc865d69858b22df26815ccf601b28219b6192974e1","cipherparams":{"iv":"8df6caa7ff1b00c4e871f002cb7921ed"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"e5e6ef3f4ea695f496b643ebd3f75c0aa58ef4070e90c80c5d3fb0241bf1595c"},"mac":"6d16dfde774845e4585357f24bce530528bc69f4f84e1e22880d34fa45c273e5"},"id":"950077c7-71e3-4c44-a4a1-143919141ed4","version":3}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/aaa:
--------------------------------------------------------------------------------
1 | {"address":"f466859ead1932d743d622cb74fc058882e8648a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/empty:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xsequence/ethkit/30cad09e46a486c77e25ea68987377abf8473000/go-ethereum/accounts/keystore/testdata/keystore/empty
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/foo/fd9bd350f08ee3c0c19b85a8e16114a11a60aa4e:
--------------------------------------------------------------------------------
1 | {"address":"fd9bd350f08ee3c0c19b85a8e16114a11a60aa4e","crypto":{"cipher":"aes-128-ctr","ciphertext":"8124d5134aa4a927c79fd852989e4b5419397566f04b0936a1eb1d168c7c68a5","cipherparams":{"iv":"e2febe17176414dd2cda28287947eb2f"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":4096,"p":6,"r":8,"salt":"44b415ede89f3bdd6830390a21b78965f571b347a589d1d943029f016c5e8bd5"},"mac":"5e149ff25bfd9dd45746a84bb2bcd2f015f2cbca2b6d25c5de8c29617f71fe5b"},"id":"d6ac5452-2b2c-4d3c-ad80-4bf0327d971c","version":3}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/garbage:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xsequence/ethkit/30cad09e46a486c77e25ea68987377abf8473000/go-ethereum/accounts/keystore/testdata/keystore/garbage
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/no-address:
--------------------------------------------------------------------------------
1 | {"crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/zero:
--------------------------------------------------------------------------------
1 | {"address":"0000000000000000000000000000000000000000","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb664472deacb41a2e995fa7f96fe29ce744471deb8d146a0e43c7898c9ddd4d","cipherparams":{"iv":"dfd9ee70812add5f4b8f89d0811c9158"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"0d6769bf016d45c479213990d6a08d938469c4adad8a02ce507b4a4e7b7739f1"},"mac":"bac9af994b15a45dd39669fc66f9aa8a3b9dd8c22cb16e4d8d7ea089d0f1a1a9"},"id":"472e8b3d-afb6-45b5-8111-72c89895099a","version":3}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/keystore/zzz:
--------------------------------------------------------------------------------
1 | {"address":"289d485d9771714cce91d3393d764e1311907acc","crypto":{"cipher":"aes-128-ctr","ciphertext":"faf32ca89d286b107f5e6d842802e05263c49b78d46eac74e6109e9a963378ab","cipherparams":{"iv":"558833eec4a665a8c55608d7d503407d"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":8,"p":16,"r":8,"salt":"d571fff447ffb24314f9513f5160246f09997b857ac71348b73e785aab40dc04"},"mac":"21edb85ff7d0dab1767b9bf498f2c3cb7be7609490756bd32300bb213b59effe"},"id":"3279afcf-55ba-43ff-8997-02dcc46a6525","version":3}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/v1/cb61d5a9c4896fb9658090b597ef0e7be6f7b67e/cb61d5a9c4896fb9658090b597ef0e7be6f7b67e:
--------------------------------------------------------------------------------
1 | {"address":"cb61d5a9c4896fb9658090b597ef0e7be6f7b67e","Crypto":{"cipher":"aes-128-cbc","ciphertext":"6143d3192db8b66eabd693d9c4e414dcfaee52abda451af79ccf474dafb35f1bfc7ea013aa9d2ee35969a1a2e8d752d0","cipherparams":{"iv":"35337770fc2117994ecdcad026bccff4"},"kdf":"scrypt","kdfparams":{"n":262144,"r":8,"p":1,"dklen":32,"salt":"9afcddebca541253a2f4053391c673ff9fe23097cd8555d149d929e4ccf1257f"},"mac":"3f3d5af884b17a100b0b3232c0636c230a54dc2ac8d986227219b0dd89197644","version":"1"},"id":"e25f7c1f-d318-4f29-b62c-687190d4d299","version":"1"}
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/v1_test_vector.json:
--------------------------------------------------------------------------------
1 | {
2 | "test1": {
3 | "json": {
4 | "Crypto": {
5 | "cipher": "aes-128-cbc",
6 | "cipherparams": {
7 | "iv": "35337770fc2117994ecdcad026bccff4"
8 | },
9 | "ciphertext": "6143d3192db8b66eabd693d9c4e414dcfaee52abda451af79ccf474dafb35f1bfc7ea013aa9d2ee35969a1a2e8d752d0",
10 | "kdf": "scrypt",
11 | "kdfparams": {
12 | "dklen": 32,
13 | "n": 262144,
14 | "p": 1,
15 | "r": 8,
16 | "salt": "9afcddebca541253a2f4053391c673ff9fe23097cd8555d149d929e4ccf1257f"
17 | },
18 | "mac": "3f3d5af884b17a100b0b3232c0636c230a54dc2ac8d986227219b0dd89197644",
19 | "version": "1"
20 | },
21 | "address": "cb61d5a9c4896fb9658090b597ef0e7be6f7b67e",
22 | "id": "e25f7c1f-d318-4f29-b62c-687190d4d299",
23 | "version": "1"
24 | },
25 | "password": "g",
26 | "priv": "d1b1178d3529626a1a93e073f65028370d14c7eb0936eb42abef05db6f37ad7d"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/testdata/very-light-scrypt.json:
--------------------------------------------------------------------------------
1 | {"address":"45dea0fb0bba44f4fcf290bba71fd57d7117cbb8","crypto":{"cipher":"aes-128-ctr","ciphertext":"b87781948a1befd247bff51ef4063f716cf6c2d3481163e9a8f42e1f9bb74145","cipherparams":{"iv":"dc4926b48a105133d2f16b96833abf1e"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":2,"p":1,"r":8,"salt":"004244bbdc51cadda545b1cfa43cff9ed2ae88e08c61f1479dbb45410722f8f0"},"mac":"39990c1684557447940d4c69e06b1b82b2aceacb43f284df65c956daf3046b85"},"id":"ce541d8d-c79b-40f8-9f8c-20f59616faba","version":3}
2 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/keystore/watch_fallback.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | //go:build (darwin && !cgo) || ios || (linux && arm64) || windows || (!darwin && !freebsd && !linux && !netbsd && !solaris)
18 | // +build darwin,!cgo ios linux,arm64 windows !darwin,!freebsd,!linux,!netbsd,!solaris
19 |
20 | // This is the fallback implementation of directory watching.
21 | // It is used on unsupported platforms.
22 |
23 | package keystore
24 |
25 | type watcher struct {
26 | running bool
27 | runEnded bool
28 | }
29 |
30 | func newWatcher(*accountCache) *watcher { return new(watcher) }
31 | func (*watcher) start() {}
32 | func (*watcher) close() {}
33 |
34 | // enabled returns false on systems not supported.
35 | func (*watcher) enabled() bool { return false }
36 |
--------------------------------------------------------------------------------
/go-ethereum/accounts/sort.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package accounts
18 |
19 | // AccountsByURL implements sort.Interface for []Account based on the URL field.
20 | type AccountsByURL []Account
21 |
22 | func (a AccountsByURL) Len() int { return len(a) }
23 | func (a AccountsByURL) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
24 | func (a AccountsByURL) Less(i, j int) bool { return a[i].URL.Cmp(a[j].URL) < 0 }
25 |
26 | // WalletsByURL implements sort.Interface for []Wallet based on the URL field.
27 | type WalletsByURL []Wallet
28 |
29 | func (w WalletsByURL) Len() int { return len(w) }
30 | func (w WalletsByURL) Swap(i, j int) { w[i], w[j] = w[j], w[i] }
31 | func (w WalletsByURL) Less(i, j int) bool { return w[i].URL().Cmp(w[j].URL()) < 0 }
32 |
--------------------------------------------------------------------------------
/go-ethereum/common/big.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "math/big"
21 |
22 | "github.com/holiman/uint256"
23 | )
24 |
25 | // Common big integers often used
26 | var (
27 | Big1 = big.NewInt(1)
28 | Big2 = big.NewInt(2)
29 | Big3 = big.NewInt(3)
30 | Big0 = big.NewInt(0)
31 | Big32 = big.NewInt(32)
32 | Big256 = big.NewInt(256)
33 | Big257 = big.NewInt(257)
34 |
35 | U2560 = uint256.NewInt(0)
36 | )
37 |
--------------------------------------------------------------------------------
/go-ethereum/common/debug.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "fmt"
21 | "os"
22 | "runtime"
23 | "runtime/debug"
24 | "strings"
25 | )
26 |
27 | // Report gives off a warning requesting the user to submit an issue to the github tracker.
28 | func Report(extra ...interface{}) {
29 | fmt.Fprintln(os.Stderr, "You've encountered a sought after, hard to reproduce bug. Please report this to the developers <3 https://github.com/ethereum/go-ethereum/issues")
30 | fmt.Fprintln(os.Stderr, extra...)
31 |
32 | _, file, line, _ := runtime.Caller(1)
33 | fmt.Fprintf(os.Stderr, "%v:%v\n", file, line)
34 |
35 | debug.PrintStack()
36 |
37 | fmt.Fprintln(os.Stderr, "#### BUG! PLEASE REPORT ####")
38 | }
39 |
40 | // PrintDeprecationWarning prints the given string in a box using fmt.Println.
41 | func PrintDeprecationWarning(str string) {
42 | line := strings.Repeat("#", len(str)+4)
43 | emptyLine := strings.Repeat(" ", len(str))
44 | fmt.Printf(`
45 | %s
46 | # %s #
47 | # %s #
48 | # %s #
49 | %s
50 |
51 | `, line, emptyLine, str, emptyLine, line)
52 | }
53 |
--------------------------------------------------------------------------------
/go-ethereum/common/fdlimit/fdlimit_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package fdlimit
18 |
19 | import (
20 | "testing"
21 | )
22 |
23 | // TestFileDescriptorLimits simply tests whether the file descriptor allowance
24 | // per this process can be retrieved.
25 | func TestFileDescriptorLimits(t *testing.T) {
26 | target := 4096
27 | hardlimit, err := Maximum()
28 | if err != nil {
29 | t.Fatal(err)
30 | }
31 | if hardlimit < target {
32 | t.Skipf("system limit is less than desired test target: %d < %d", hardlimit, target)
33 | }
34 |
35 | if limit, err := Current(); err != nil || limit <= 0 {
36 | t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
37 | }
38 | if _, err := Raise(uint64(target)); err != nil {
39 | t.Fatalf("failed to raise file allowance")
40 | }
41 | if limit, err := Current(); err != nil || limit < target {
42 | t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/go-ethereum/common/hexutil/json_example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package hexutil_test
18 |
19 | import (
20 | "encoding/json"
21 | "fmt"
22 |
23 | "github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
24 | )
25 |
26 | type MyType [5]byte
27 |
28 | func (v *MyType) UnmarshalText(input []byte) error {
29 | return hexutil.UnmarshalFixedText("MyType", input, v[:])
30 | }
31 |
32 | func (v MyType) String() string {
33 | return hexutil.Bytes(v[:]).String()
34 | }
35 |
36 | func ExampleUnmarshalFixedText() {
37 | var v1, v2 MyType
38 | fmt.Println("v1 error:", json.Unmarshal([]byte(`"0x01"`), &v1))
39 | fmt.Println("v2 error:", json.Unmarshal([]byte(`"0x0101010101"`), &v2))
40 | fmt.Println("v2:", v2)
41 | // Output:
42 | // v1 error: hex string has length 2, want 10 for MyType
43 | // v2 error:
44 | // v2: 0x0101010101
45 | }
46 |
--------------------------------------------------------------------------------
/go-ethereum/common/mclock/mclock.s:
--------------------------------------------------------------------------------
1 | // This file exists in order to be able to use go:linkname.
2 |
--------------------------------------------------------------------------------
/go-ethereum/common/path.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "os"
21 | "path/filepath"
22 | )
23 |
24 | // FileExist checks if a file exists at filePath.
25 | func FileExist(filePath string) bool {
26 | _, err := os.Stat(filePath)
27 | if err != nil && os.IsNotExist(err) {
28 | return false
29 | }
30 | return true
31 | }
32 |
33 | // AbsolutePath returns datadir + filename, or filename if it is absolute.
34 | func AbsolutePath(datadir string, filename string) string {
35 | if filepath.IsAbs(filename) {
36 | return filename
37 | }
38 | return filepath.Join(datadir, filename)
39 | }
40 |
--------------------------------------------------------------------------------
/go-ethereum/common/range_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2025 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "slices"
21 | "testing"
22 | )
23 |
24 | func TestRangeIter(t *testing.T) {
25 | r := NewRange[uint32](1, 7)
26 | values := slices.Collect(r.Iter())
27 | if !slices.Equal(values, []uint32{1, 2, 3, 4, 5, 6, 7}) {
28 | t.Fatalf("wrong iter values: %v", values)
29 | }
30 |
31 | empty := NewRange[uint32](1, 0)
32 | values = slices.Collect(empty.Iter())
33 | if !slices.Equal(values, []uint32{}) {
34 | t.Fatalf("wrong iter values: %v", values)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/go-ethereum/common/size.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "fmt"
21 | )
22 |
23 | // StorageSize is a wrapper around a float value that supports user friendly
24 | // formatting.
25 | type StorageSize float64
26 |
27 | // String implements the stringer interface.
28 | func (s StorageSize) String() string {
29 | if s > 1099511627776 {
30 | return fmt.Sprintf("%.2f TiB", s/1099511627776)
31 | } else if s > 1073741824 {
32 | return fmt.Sprintf("%.2f GiB", s/1073741824)
33 | } else if s > 1048576 {
34 | return fmt.Sprintf("%.2f MiB", s/1048576)
35 | } else if s > 1024 {
36 | return fmt.Sprintf("%.2f KiB", s/1024)
37 | } else {
38 | return fmt.Sprintf("%.2f B", s)
39 | }
40 | }
41 |
42 | // TerminalString implements log.TerminalStringer, formatting a string for console
43 | // output during logging.
44 | func (s StorageSize) TerminalString() string {
45 | if s > 1099511627776 {
46 | return fmt.Sprintf("%.2fTiB", s/1099511627776)
47 | } else if s > 1073741824 {
48 | return fmt.Sprintf("%.2fGiB", s/1073741824)
49 | } else if s > 1048576 {
50 | return fmt.Sprintf("%.2fMiB", s/1048576)
51 | } else if s > 1024 {
52 | return fmt.Sprintf("%.2fKiB", s/1024)
53 | } else {
54 | return fmt.Sprintf("%.2fB", s)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/go-ethereum/common/size_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "testing"
21 | )
22 |
23 | func TestStorageSizeString(t *testing.T) {
24 | tests := []struct {
25 | size StorageSize
26 | str string
27 | }{
28 | {2839274474874, "2.58 TiB"},
29 | {2458492810, "2.29 GiB"},
30 | {2381273, "2.27 MiB"},
31 | {2192, "2.14 KiB"},
32 | {12, "12.00 B"},
33 | }
34 |
35 | for _, test := range tests {
36 | if test.size.String() != test.str {
37 | t.Errorf("%f: got %q, want %q", float64(test.size), test.size.String(), test.str)
38 | }
39 | }
40 | }
41 |
42 | func TestStorageSizeTerminalString(t *testing.T) {
43 | tests := []struct {
44 | size StorageSize
45 | str string
46 | }{
47 | {2839274474874, "2.58TiB"},
48 | {2458492810, "2.29GiB"},
49 | {2381273, "2.27MiB"},
50 | {2192, "2.14KiB"},
51 | {12, "12.00B"},
52 | }
53 |
54 | for _, test := range tests {
55 | if test.size.TerminalString() != test.str {
56 | t.Errorf("%f: got %q, want %q", float64(test.size), test.size.TerminalString(), test.str)
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/go-ethereum/common/test_utils.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package common
18 |
19 | import (
20 | "encoding/json"
21 | "fmt"
22 | "os"
23 | )
24 |
25 | // LoadJSON reads the given file and unmarshals its content.
26 | func LoadJSON(file string, val interface{}) error {
27 | content, err := os.ReadFile(file)
28 | if err != nil {
29 | return err
30 | }
31 | if err := json.Unmarshal(content, val); err != nil {
32 | if syntaxerr, ok := err.(*json.SyntaxError); ok {
33 | line := findLine(content, syntaxerr.Offset)
34 | return fmt.Errorf("JSON syntax error at %v:%v: %v", file, line, err)
35 | }
36 | return fmt.Errorf("JSON unmarshal error in %v: %v", file, err)
37 | }
38 | return nil
39 | }
40 |
41 | // findLine returns the line number for the given offset into data.
42 | func findLine(data []byte, offset int64) (line int) {
43 | line = 1
44 | for i, r := range string(data) {
45 | if int64(i) >= offset {
46 | return
47 | }
48 | if r == '\n' {
49 | line++
50 | }
51 | }
52 | return
53 | }
54 |
--------------------------------------------------------------------------------
/go-ethereum/core/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile ~/.gitignore_global
6 |
7 | /tmp
8 | */**/*un~
9 | *un~
10 | .DS_Store
11 | */**/.DS_Store
12 |
13 |
--------------------------------------------------------------------------------
/go-ethereum/core/types/gen_access_tuple.go:
--------------------------------------------------------------------------------
1 | // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
2 |
3 | package types
4 |
5 | import (
6 | "encoding/json"
7 | "errors"
8 |
9 | "github.com/0xsequence/ethkit/go-ethereum/common"
10 | )
11 |
12 | // MarshalJSON marshals as JSON.
13 | func (a AccessTuple) MarshalJSON() ([]byte, error) {
14 | type AccessTuple struct {
15 | Address common.Address `json:"address" gencodec:"required"`
16 | StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
17 | }
18 | var enc AccessTuple
19 | enc.Address = a.Address
20 | enc.StorageKeys = a.StorageKeys
21 | return json.Marshal(&enc)
22 | }
23 |
24 | // UnmarshalJSON unmarshals from JSON.
25 | func (a *AccessTuple) UnmarshalJSON(input []byte) error {
26 | type AccessTuple struct {
27 | Address *common.Address `json:"address" gencodec:"required"`
28 | StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
29 | }
30 | var dec AccessTuple
31 | if err := json.Unmarshal(input, &dec); err != nil {
32 | return err
33 | }
34 | if dec.Address == nil {
35 | return errors.New("missing required field 'address' for AccessTuple")
36 | }
37 | a.Address = *dec.Address
38 | if dec.StorageKeys == nil {
39 | return errors.New("missing required field 'storageKeys' for AccessTuple")
40 | }
41 | a.StorageKeys = dec.StorageKeys
42 | return nil
43 | }
44 |
--------------------------------------------------------------------------------
/go-ethereum/core/types/gen_account_rlp.go:
--------------------------------------------------------------------------------
1 | // Code generated by rlpgen. DO NOT EDIT.
2 |
3 | package types
4 |
5 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
6 | import "io"
7 |
8 | func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
9 | w := rlp.NewEncoderBuffer(_w)
10 | _tmp0 := w.List()
11 | w.WriteUint64(obj.Nonce)
12 | if obj.Balance == nil {
13 | w.Write(rlp.EmptyString)
14 | } else {
15 | w.WriteUint256(obj.Balance)
16 | }
17 | w.WriteBytes(obj.Root[:])
18 | w.WriteBytes(obj.CodeHash)
19 | w.ListEnd(_tmp0)
20 | return w.Flush()
21 | }
22 |
--------------------------------------------------------------------------------
/go-ethereum/core/types/gen_log_rlp.go:
--------------------------------------------------------------------------------
1 | // Code generated by rlpgen. DO NOT EDIT.
2 |
3 | package types
4 |
5 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
6 | import "io"
7 |
8 | func (obj *Log) EncodeRLP(_w io.Writer) error {
9 | w := rlp.NewEncoderBuffer(_w)
10 | _tmp0 := w.List()
11 | w.WriteBytes(obj.Address[:])
12 | _tmp1 := w.List()
13 | for _, _tmp2 := range obj.Topics {
14 | w.WriteBytes(_tmp2[:])
15 | }
16 | w.ListEnd(_tmp1)
17 | w.WriteBytes(obj.Data)
18 | w.ListEnd(_tmp0)
19 | return w.Flush()
20 | }
21 |
--------------------------------------------------------------------------------
/go-ethereum/core/types/gen_withdrawal_json.go:
--------------------------------------------------------------------------------
1 | // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
2 |
3 | package types
4 |
5 | import (
6 | "encoding/json"
7 |
8 | "github.com/0xsequence/ethkit/go-ethereum/common"
9 | "github.com/0xsequence/ethkit/go-ethereum/common/hexutil"
10 | )
11 |
12 | var _ = (*withdrawalMarshaling)(nil)
13 |
14 | // MarshalJSON marshals as JSON.
15 | func (w Withdrawal) MarshalJSON() ([]byte, error) {
16 | type Withdrawal struct {
17 | Index hexutil.Uint64 `json:"index"`
18 | Validator hexutil.Uint64 `json:"validatorIndex"`
19 | Address common.Address `json:"address"`
20 | Amount hexutil.Uint64 `json:"amount"`
21 | }
22 | var enc Withdrawal
23 | enc.Index = hexutil.Uint64(w.Index)
24 | enc.Validator = hexutil.Uint64(w.Validator)
25 | enc.Address = w.Address
26 | enc.Amount = hexutil.Uint64(w.Amount)
27 | return json.Marshal(&enc)
28 | }
29 |
30 | // UnmarshalJSON unmarshals from JSON.
31 | func (w *Withdrawal) UnmarshalJSON(input []byte) error {
32 | type Withdrawal struct {
33 | Index *hexutil.Uint64 `json:"index"`
34 | Validator *hexutil.Uint64 `json:"validatorIndex"`
35 | Address *common.Address `json:"address"`
36 | Amount *hexutil.Uint64 `json:"amount"`
37 | }
38 | var dec Withdrawal
39 | if err := json.Unmarshal(input, &dec); err != nil {
40 | return err
41 | }
42 | if dec.Index != nil {
43 | w.Index = uint64(*dec.Index)
44 | }
45 | if dec.Validator != nil {
46 | w.Validator = uint64(*dec.Validator)
47 | }
48 | if dec.Address != nil {
49 | w.Address = *dec.Address
50 | }
51 | if dec.Amount != nil {
52 | w.Amount = uint64(*dec.Amount)
53 | }
54 | return nil
55 | }
56 |
--------------------------------------------------------------------------------
/go-ethereum/core/types/gen_withdrawal_rlp.go:
--------------------------------------------------------------------------------
1 | // Code generated by rlpgen. DO NOT EDIT.
2 |
3 | package types
4 |
5 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
6 | import "io"
7 |
8 | func (obj *Withdrawal) EncodeRLP(_w io.Writer) error {
9 | w := rlp.NewEncoderBuffer(_w)
10 | _tmp0 := w.List()
11 | w.WriteUint64(obj.Index)
12 | w.WriteUint64(obj.Validator)
13 | w.WriteBytes(obj.Address[:])
14 | w.WriteUint64(obj.Amount)
15 | w.ListEnd(_tmp0)
16 | return w.Flush()
17 | }
18 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/blake2b/blake2bAVX2_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build go1.7 && amd64 && !gccgo && !appengine
6 | // +build go1.7,amd64,!gccgo,!appengine
7 |
8 | package blake2b
9 |
10 | import "golang.org/x/sys/cpu"
11 |
12 | func init() {
13 | useAVX2 = cpu.X86.HasAVX2
14 | useAVX = cpu.X86.HasAVX
15 | useSSE4 = cpu.X86.HasSSE41
16 | }
17 |
18 | //go:noescape
19 | func fAVX2(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64)
20 |
21 | //go:noescape
22 | func fAVX(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64)
23 |
24 | //go:noescape
25 | func fSSE4(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64)
26 |
27 | func f(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64) {
28 | switch {
29 | case useAVX2:
30 | fAVX2(h, m, c0, c1, flag, rounds)
31 | case useAVX:
32 | fAVX(h, m, c0, c1, flag, rounds)
33 | case useSSE4:
34 | fSSE4(h, m, c0, c1, flag, rounds)
35 | default:
36 | fGeneric(h, m, c0, c1, flag, rounds)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/blake2b/blake2b_amd64.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !go1.7 && amd64 && !gccgo && !appengine
6 | // +build !go1.7,amd64,!gccgo,!appengine
7 |
8 | package blake2b
9 |
10 | import "golang.org/x/sys/cpu"
11 |
12 | func init() {
13 | useSSE4 = cpu.X86.HasSSE41
14 | }
15 |
16 | //go:noescape
17 | func fSSE4(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64)
18 |
19 | func f(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64) {
20 | if useSSE4 {
21 | fSSE4(h, m, c0, c1, flag, rounds)
22 | } else {
23 | fGeneric(h, m, c0, c1, flag, rounds)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/blake2b/blake2b_f_fuzz_test.go:
--------------------------------------------------------------------------------
1 | // Only enable fuzzer on platforms with AVX enabled
2 | //go:build go1.7 && amd64 && !gccgo && !appengine
3 | // +build go1.7,amd64,!gccgo,!appengine
4 |
5 | package blake2b
6 |
7 | import (
8 | "encoding/binary"
9 | "testing"
10 | )
11 |
12 | func Fuzz(f *testing.F) {
13 | f.Fuzz(func(t *testing.T, data []byte) {
14 | fuzz(data)
15 | })
16 | }
17 |
18 | func fuzz(data []byte) {
19 | // Make sure the data confirms to the input model
20 | if len(data) != 211 {
21 | return
22 | }
23 | // Parse everything and call all the implementations
24 | var (
25 | rounds = binary.BigEndian.Uint16(data[0:2])
26 |
27 | h [8]uint64
28 | m [16]uint64
29 | t [2]uint64
30 | f uint64
31 | )
32 |
33 | for i := 0; i < 8; i++ {
34 | offset := 2 + i*8
35 | h[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
36 | }
37 | for i := 0; i < 16; i++ {
38 | offset := 66 + i*8
39 | m[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
40 | }
41 | t[0] = binary.LittleEndian.Uint64(data[194:202])
42 | t[1] = binary.LittleEndian.Uint64(data[202:210])
43 |
44 | if data[210]%2 == 1 { // Avoid spinning the fuzzer to hit 0/1
45 | f = 0xFFFFFFFFFFFFFFFF
46 | }
47 |
48 | // Run the blake2b compression on all instruction sets and cross reference
49 | want := h
50 | fGeneric(&want, &m, t[0], t[1], f, uint64(rounds))
51 |
52 | have := h
53 | if useSSE4 {
54 | fSSE4(&have, &m, t[0], t[1], f, uint64(rounds))
55 | if have != want {
56 | panic("SSE4 mismatches generic algo")
57 | }
58 | }
59 |
60 | if useAVX {
61 | have = h
62 | fAVX(&have, &m, t[0], t[1], f, uint64(rounds))
63 | if have != want {
64 | panic("AVX mismatches generic algo")
65 | }
66 | }
67 |
68 | if useAVX2 {
69 | have = h
70 | fAVX2(&have, &m, t[0], t[1], f, uint64(rounds))
71 | if have != want {
72 | panic("AVX2 mismatches generic algo")
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/blake2b/blake2b_f_test.go:
--------------------------------------------------------------------------------
1 | package blake2b
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | "testing"
7 | )
8 |
9 | func TestF(t *testing.T) {
10 | for i, test := range testVectorsF {
11 | t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) {
12 | //toEthereumTestCase(test)
13 |
14 | h := test.hIn
15 | F(&h, test.m, test.c, test.f, test.rounds)
16 |
17 | if !reflect.DeepEqual(test.hOut, h) {
18 | t.Errorf("Unexpected result\nExpected: [%#x]\nActual: [%#x]\n", test.hOut, h)
19 | }
20 | })
21 | }
22 | }
23 |
24 | type testVector struct {
25 | hIn [8]uint64
26 | m [16]uint64
27 | c [2]uint64
28 | f bool
29 | rounds uint32
30 | hOut [8]uint64
31 | }
32 |
33 | // https://tools.ietf.org/html/rfc7693#appendix-A
34 | var testVectorsF = []testVector{
35 | {
36 | hIn: [8]uint64{
37 | 0x6a09e667f2bdc948, 0xbb67ae8584caa73b,
38 | 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
39 | 0x510e527fade682d1, 0x9b05688c2b3e6c1f,
40 | 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
41 | },
42 | m: [16]uint64{
43 | 0x0000000000636261, 0x0000000000000000, 0x0000000000000000,
44 | 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
45 | 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
46 | 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
47 | 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
48 | 0x0000000000000000,
49 | },
50 | c: [2]uint64{3, 0},
51 | f: true,
52 | rounds: 12,
53 | hOut: [8]uint64{
54 | 0x0D4D1C983FA580BA, 0xE9F6129FB697276A, 0xB7C45A68142F214C,
55 | 0xD1A2FFDB6FBB124B, 0x2D79AB2A39C5877D, 0x95CC3345DED552C2,
56 | 0x5A92F1DBA88AD318, 0x239900D4ED8623B9,
57 | },
58 | },
59 | }
60 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/blake2b/blake2b_ref.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !amd64 || appengine || gccgo
6 | // +build !amd64 appengine gccgo
7 |
8 | package blake2b
9 |
10 | func f(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64) {
11 | fGeneric(h, m, c0, c1, flag, rounds)
12 | }
13 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/blake2b/register.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build go1.9
6 | // +build go1.9
7 |
8 | package blake2b
9 |
10 | import (
11 | "crypto"
12 | "hash"
13 | )
14 |
15 | func init() {
16 | newHash256 := func() hash.Hash {
17 | h, _ := New256(nil)
18 | return h
19 | }
20 | newHash384 := func() hash.Hash {
21 | h, _ := New384(nil)
22 | return h
23 | }
24 |
25 | newHash512 := func() hash.Hash {
26 | h, _ := New512(nil)
27 | return h
28 | }
29 |
30 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256)
31 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384)
32 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512)
33 | }
34 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 The Go Authors. All rights reserved.
2 | Copyright (c) 2018 Péter Szilágyi. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/bn256_fast.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Péter Szilágyi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be found
3 | // in the LICENSE file.
4 |
5 | //go:build amd64 || arm64
6 | // +build amd64 arm64
7 |
8 | // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
9 | package bn256
10 |
11 | import (
12 | bn256cf "github.com/0xsequence/ethkit/go-ethereum/crypto/bn256/cloudflare"
13 | )
14 |
15 | // G1 is an abstract cyclic group. The zero value is suitable for use as the
16 | // output of an operation, but cannot be used as an input.
17 | type G1 = bn256cf.G1
18 |
19 | // G2 is an abstract cyclic group. The zero value is suitable for use as the
20 | // output of an operation, but cannot be used as an input.
21 | type G2 = bn256cf.G2
22 |
23 | // PairingCheck calculates the Optimal Ate pairing for a set of points.
24 | func PairingCheck(a []*G1, b []*G2) bool {
25 | return bn256cf.PairingCheck(a, b)
26 | }
27 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/bn256_slow.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Péter Szilágyi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be found
3 | // in the LICENSE file.
4 |
5 | //go:build !amd64 && !arm64
6 | // +build !amd64,!arm64
7 |
8 | // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
9 | package bn256
10 |
11 | import bn256 "github.com/0xsequence/ethkit/go-ethereum/crypto/bn256/google"
12 |
13 | // G1 is an abstract cyclic group. The zero value is suitable for use as the
14 | // output of an operation, but cannot be used as an input.
15 | type G1 = bn256.G1
16 |
17 | // G2 is an abstract cyclic group. The zero value is suitable for use as the
18 | // output of an operation, but cannot be used as an input.
19 | type G2 = bn256.G2
20 |
21 | // PairingCheck calculates the Optimal Ate pairing for a set of points.
22 | func PairingCheck(a []*G1, b []*G2) bool {
23 | return bn256.PairingCheck(a, b)
24 | }
25 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/cloudflare/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/cloudflare/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bn256
6 |
7 | import (
8 | "crypto/rand"
9 | "testing"
10 |
11 | "github.com/stretchr/testify/require"
12 | )
13 |
14 | func TestExamplePair(t *testing.T) {
15 | // This implements the tripartite Diffie-Hellman algorithm from "A One
16 | // Round Protocol for Tripartite Diffie-Hellman", A. Joux.
17 | // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf
18 |
19 | // Each of three parties, a, b and c, generate a private value.
20 | a, _ := rand.Int(rand.Reader, Order)
21 | b, _ := rand.Int(rand.Reader, Order)
22 | c, _ := rand.Int(rand.Reader, Order)
23 |
24 | // Then each party calculates g₁ and g₂ times their private value.
25 | pa := new(G1).ScalarBaseMult(a)
26 | qa := new(G2).ScalarBaseMult(a)
27 |
28 | pb := new(G1).ScalarBaseMult(b)
29 | qb := new(G2).ScalarBaseMult(b)
30 |
31 | pc := new(G1).ScalarBaseMult(c)
32 | qc := new(G2).ScalarBaseMult(c)
33 |
34 | // Now each party exchanges its public values with the other two and
35 | // all parties can calculate the shared key.
36 | k1 := Pair(pb, qc)
37 | k1.ScalarMult(k1, a)
38 |
39 | k2 := Pair(pc, qa)
40 | k2.ScalarMult(k2, b)
41 |
42 | k3 := Pair(pa, qb)
43 | k3.ScalarMult(k3, c)
44 |
45 | // k1, k2 and k3 will all be equal.
46 |
47 | require.Equal(t, k1, k2)
48 | require.Equal(t, k1, k3)
49 |
50 | require.Equal(t, len(np), 4) //Avoid gometalinter varcheck err on np
51 | }
52 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/cloudflare/gfp.go:
--------------------------------------------------------------------------------
1 | package bn256
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | )
7 |
8 | type gfP [4]uint64
9 |
10 | func newGFp(x int64) (out *gfP) {
11 | if x >= 0 {
12 | out = &gfP{uint64(x)}
13 | } else {
14 | out = &gfP{uint64(-x)}
15 | gfpNeg(out, out)
16 | }
17 |
18 | montEncode(out, out)
19 | return out
20 | }
21 |
22 | func (e *gfP) String() string {
23 | return fmt.Sprintf("%16.16x%16.16x%16.16x%16.16x", e[3], e[2], e[1], e[0])
24 | }
25 |
26 | func (e *gfP) Set(f *gfP) {
27 | e[0] = f[0]
28 | e[1] = f[1]
29 | e[2] = f[2]
30 | e[3] = f[3]
31 | }
32 |
33 | func (e *gfP) Invert(f *gfP) {
34 | bits := [4]uint64{0x3c208c16d87cfd45, 0x97816a916871ca8d, 0xb85045b68181585d, 0x30644e72e131a029}
35 |
36 | sum, power := &gfP{}, &gfP{}
37 | sum.Set(rN1)
38 | power.Set(f)
39 |
40 | for word := 0; word < 4; word++ {
41 | for bit := uint(0); bit < 64; bit++ {
42 | if (bits[word]>>bit)&1 == 1 {
43 | gfpMul(sum, sum, power)
44 | }
45 | gfpMul(power, power, power)
46 | }
47 | }
48 |
49 | gfpMul(sum, sum, r3)
50 | e.Set(sum)
51 | }
52 |
53 | func (e *gfP) Marshal(out []byte) {
54 | for w := uint(0); w < 4; w++ {
55 | for b := uint(0); b < 8; b++ {
56 | out[8*w+b] = byte(e[3-w] >> (56 - 8*b))
57 | }
58 | }
59 | }
60 |
61 | func (e *gfP) Unmarshal(in []byte) error {
62 | // Unmarshal the bytes into little endian form
63 | for w := uint(0); w < 4; w++ {
64 | e[3-w] = 0
65 | for b := uint(0); b < 8; b++ {
66 | e[3-w] += uint64(in[8*w+b]) << (56 - 8*b)
67 | }
68 | }
69 | // Ensure the point respects the curve modulus
70 | for i := 3; i >= 0; i-- {
71 | if e[i] < p2[i] {
72 | return nil
73 | }
74 | if e[i] > p2[i] {
75 | return errors.New("bn256: coordinate exceeds modulus")
76 | }
77 | }
78 | return errors.New("bn256: coordinate equals modulus")
79 | }
80 |
81 | func montEncode(c, a *gfP) { gfpMul(c, a, r2) }
82 | func montDecode(c, a *gfP) { gfpMul(c, a, &gfP{1}) }
83 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/cloudflare/gfp_decl.go:
--------------------------------------------------------------------------------
1 | //go:build (amd64 && !generic) || (arm64 && !generic)
2 | // +build amd64,!generic arm64,!generic
3 |
4 | package bn256
5 |
6 | // This file contains forward declarations for the architecture-specific
7 | // assembly implementations of these functions, provided that they exist.
8 |
9 | import (
10 | "golang.org/x/sys/cpu"
11 | )
12 |
13 | //nolint:varcheck,unused,deadcode
14 | var hasBMI2 = cpu.X86.HasBMI2
15 |
16 | //go:noescape
17 | func gfpNeg(c, a *gfP)
18 |
19 | //go:noescape
20 | func gfpAdd(c, a, b *gfP)
21 |
22 | //go:noescape
23 | func gfpSub(c, a, b *gfP)
24 |
25 | //go:noescape
26 | func gfpMul(c, a, b *gfP)
27 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/cloudflare/lattice_test.go:
--------------------------------------------------------------------------------
1 | package bn256
2 |
3 | import (
4 | "crypto/rand"
5 |
6 | "testing"
7 | )
8 |
9 | func TestLatticeReduceCurve(t *testing.T) {
10 | k, _ := rand.Int(rand.Reader, Order)
11 | ks := curveLattice.decompose(k)
12 |
13 | if ks[0].BitLen() > 130 || ks[1].BitLen() > 130 {
14 | t.Fatal("reduction too large")
15 | } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 {
16 | t.Fatal("reduction must be positive")
17 | }
18 | }
19 |
20 | func TestLatticeReduceTarget(t *testing.T) {
21 | k, _ := rand.Int(rand.Reader, Order)
22 | ks := targetLattice.decompose(k)
23 |
24 | if ks[0].BitLen() > 66 || ks[1].BitLen() > 66 || ks[2].BitLen() > 66 || ks[3].BitLen() > 66 {
25 | t.Fatal("reduction too large")
26 | } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 || ks[2].Sign() < 0 || ks[3].Sign() < 0 {
27 | t.Fatal("reduction must be positive")
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/gnark/g1.go:
--------------------------------------------------------------------------------
1 | package bn256
2 |
3 | import (
4 | "math/big"
5 |
6 | "github.com/consensys/gnark-crypto/ecc/bn254"
7 | )
8 |
9 | // G1 is the affine representation of a G1 group element.
10 | //
11 | // Since this code is used for precompiles, using Jacobian
12 | // points are not beneficial because there are no intermediate
13 | // points to allow us to save on inversions.
14 | //
15 | // Note: We also use this struct so that we can conform to the existing API
16 | // that the precompiles want.
17 | type G1 struct {
18 | inner bn254.G1Affine
19 | }
20 |
21 | // Add adds `a` and `b` together, storing the result in `g`
22 | func (g *G1) Add(a, b *G1) {
23 | g.inner.Add(&a.inner, &b.inner)
24 | }
25 |
26 | // ScalarMult computes the scalar multiplication between `a` and
27 | // `scalar`, storing the result in `g`
28 | func (g *G1) ScalarMult(a *G1, scalar *big.Int) {
29 | g.inner.ScalarMultiplication(&a.inner, scalar)
30 | }
31 |
32 | // Unmarshal deserializes `buf` into `g`
33 | //
34 | // Note: whether the deserialization is of a compressed
35 | // or an uncompressed point, is encoded in the bytes.
36 | //
37 | // For our purpose, the point will always be serialized
38 | // as uncompressed, ie 64 bytes.
39 | //
40 | // This method also checks whether the point is on the
41 | // curve and in the prime order subgroup.
42 | func (g *G1) Unmarshal(buf []byte) (int, error) {
43 | return g.inner.SetBytes(buf)
44 | }
45 |
46 | // Marshal serializes the point into a byte slice.
47 | //
48 | // Note: The point is serialized as uncompressed.
49 | func (p *G1) Marshal() []byte {
50 | return p.inner.Marshal()
51 | }
52 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/gnark/g2.go:
--------------------------------------------------------------------------------
1 | package bn256
2 |
3 | import (
4 | "github.com/consensys/gnark-crypto/ecc/bn254"
5 | )
6 |
7 | // G2 is the affine representation of a G2 group element.
8 | //
9 | // Since this code is used for precompiles, using Jacobian
10 | // points are not beneficial because there are no intermediate
11 | // points and G2 in particular is only used for the pairing input.
12 | //
13 | // Note: We also use this struct so that we can conform to the existing API
14 | // that the precompiles want.
15 | type G2 struct {
16 | inner bn254.G2Affine
17 | }
18 |
19 | // Unmarshal deserializes `buf` into `g`
20 | //
21 | // Note: whether the deserialization is of a compressed
22 | // or an uncompressed point, is encoded in the bytes.
23 | //
24 | // For our purpose, the point will always be serialized
25 | // as uncompressed, ie 128 bytes.
26 | //
27 | // This method also checks whether the point is on the
28 | // curve and in the prime order subgroup.
29 | func (g *G2) Unmarshal(buf []byte) (int, error) {
30 | return g.inner.SetBytes(buf)
31 | }
32 |
33 | // Marshal serializes the point into a byte slice.
34 | //
35 | // Note: The point is serialized as uncompressed.
36 | func (g *G2) Marshal() []byte {
37 | return g.inner.Marshal()
38 | }
39 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/gnark/gt.go:
--------------------------------------------------------------------------------
1 | package bn256
2 |
3 | import (
4 | "fmt"
5 | "math/big"
6 |
7 | "github.com/consensys/gnark-crypto/ecc/bn254"
8 | )
9 |
10 | // GT is the affine representation of a GT field element.
11 | //
12 | // Note: GT is not explicitly used in mainline code.
13 | // It is needed for fuzzing.
14 | type GT struct {
15 | inner bn254.GT
16 | }
17 |
18 | // Pair compute the optimal Ate pairing between a G1 and
19 | // G2 element.
20 | //
21 | // Note: This method is not explicitly used in mainline code.
22 | // It is needed for fuzzing. It should also be noted,
23 | // that the output of this function may not match other
24 | func Pair(a_ *G1, b_ *G2) *GT {
25 | a := a_.inner
26 | b := b_.inner
27 |
28 | pairingOutput, err := bn254.Pair([]bn254.G1Affine{a}, []bn254.G2Affine{b})
29 |
30 | if err != nil {
31 | // Since this method is only called during fuzzing, it is okay to panic here.
32 | // We do not return an error to match the interface of the other bn256 libraries.
33 | panic(fmt.Sprintf("gnark/bn254 encountered error: %v", err))
34 | }
35 |
36 | return >{
37 | inner: pairingOutput,
38 | }
39 | }
40 |
41 | // Unmarshal deserializes `buf` into `g`
42 | //
43 | // Note: This method is not explicitly used in mainline code.
44 | // It is needed for fuzzing.
45 | func (g *GT) Unmarshal(buf []byte) error {
46 | return g.inner.SetBytes(buf)
47 | }
48 |
49 | // Marshal serializes the point into a byte slice.
50 | //
51 | // Note: This method is not explicitly used in mainline code.
52 | // It is needed for fuzzing.
53 | func (g *GT) Marshal() []byte {
54 | bytes := g.inner.Bytes()
55 | return bytes[:]
56 | }
57 |
58 | // Exp raises `base` to the power of `exponent`
59 | //
60 | // Note: This method is not explicitly used in mainline code.
61 | // It is needed for fuzzing.
62 | func (g *GT) Exp(base GT, exponent *big.Int) *GT {
63 | g.inner.Exp(base.inner, exponent)
64 | return g
65 | }
66 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/bn256/google/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2012 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package bn256
6 |
7 | import (
8 | "crypto/rand"
9 | )
10 |
11 | func ExamplePair() {
12 | // This implements the tripartite Diffie-Hellman algorithm from "A One
13 | // Round Protocol for Tripartite Diffie-Hellman", A. Joux.
14 | // http://www.springerlink.com/content/cddc57yyva0hburb/fulltext.pdf
15 |
16 | // Each of three parties, a, b and c, generate a private value.
17 | a, _ := rand.Int(rand.Reader, Order)
18 | b, _ := rand.Int(rand.Reader, Order)
19 | c, _ := rand.Int(rand.Reader, Order)
20 |
21 | // Then each party calculates g₁ and g₂ times their private value.
22 | pa := new(G1).ScalarBaseMult(a)
23 | qa := new(G2).ScalarBaseMult(a)
24 |
25 | pb := new(G1).ScalarBaseMult(b)
26 | qb := new(G2).ScalarBaseMult(b)
27 |
28 | pc := new(G1).ScalarBaseMult(c)
29 | qc := new(G2).ScalarBaseMult(c)
30 |
31 | // Now each party exchanges its public values with the other two and
32 | // all parties can calculate the shared key.
33 | k1 := Pair(pb, qc)
34 | k1.ScalarMult(k1, a)
35 |
36 | k2 := Pair(pc, qa)
37 | k2.ScalarMult(k2, b)
38 |
39 | k3 := Pair(pa, qb)
40 | k3.ScalarMult(k3, c)
41 |
42 | // k1, k2 and k3 will all be equal.
43 | }
44 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/ecies/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 |
24 | *~
25 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/ecies/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Kyle Isom
2 | Copyright (c) 2012 The Go Authors. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above
11 | copyright notice, this list of conditions and the following disclaimer
12 | in the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Google Inc. nor the names of its
15 | contributors may be used to endorse or promote products derived from
16 | this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files, Static and Dynamic libs (Shared Objects)
2 | *.o
3 | *.a
4 | *.so
5 |
6 | # Folders
7 | _obj
8 | _test
9 |
10 | # Architecture specific extensions/prefixes
11 | *.[568vq]
12 | [568vq].out
13 |
14 | *.cgo1.go
15 | *.cgo2.c
16 | _cgo_defun.c
17 | _cgo_gotypes.go
18 | _cgo_export.*
19 |
20 | _testmain.go
21 |
22 | *.exe
23 |
24 | *~
25 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010 The Go Authors. All rights reserved.
2 | Copyright (c) 2011 ThePiachu. All rights reserved.
3 | Copyright (c) 2015 Jeffrey Wilcke. All rights reserved.
4 | Copyright (c) 2015 Felix Lange. All rights reserved.
5 | Copyright (c) 2015 Gustav Simonsson. All rights reserved.
6 |
7 | Redistribution and use in source and binary forms, with or without
8 | modification, are permitted provided that the following conditions are
9 | met:
10 |
11 | * Redistributions of source code must retain the above copyright
12 | notice, this list of conditions and the following disclaimer.
13 | * Redistributions in binary form must reproduce the above
14 | copyright notice, this list of conditions and the following disclaimer
15 | in the documentation and/or other materials provided with the
16 | distribution.
17 | * Neither the name of the copyright holder. nor the names of its
18 | contributors may be used to endorse or promote products derived from
19 | this software without specific prior written permission.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // This file is part of a workaround for `go mod vendor` which won't vendor
5 | // C files if there's no Go file in the same directory.
6 | // This would prevent the crypto/secp256k1/libsecp256k1/include/secp256k1.h file to be vendored.
7 | //
8 | // This Go file imports the c directory where there is another dummy.go file which
9 | // is the second part of this workaround.
10 | //
11 | // These two files combined make it so `go mod vendor` behaves correctly.
12 | //
13 | // See this issue for reference: https://github.com/golang/go/issues/26366
14 |
15 | package secp256k1
16 |
17 | import (
18 | _ "github.com/0xsequence/ethkit/go-ethereum/crypto/secp256k1/libsecp256k1/include"
19 | _ "github.com/0xsequence/ethkit/go-ethereum/crypto/secp256k1/libsecp256k1/src"
20 | _ "github.com/0xsequence/ethkit/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/recovery"
21 | )
22 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/.gitattributes:
--------------------------------------------------------------------------------
1 | src/precomputed_ecmult.c linguist-generated
2 | src/precomputed_ecmult_gen.c linguist-generated
3 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/.github/actions/install-homebrew-valgrind/action.yml:
--------------------------------------------------------------------------------
1 | name: "Install Valgrind"
2 | description: "Install Homebrew's Valgrind package and cache it."
3 | runs:
4 | using: "composite"
5 | steps:
6 | - run: |
7 | brew tap LouisBrunner/valgrind
8 | brew fetch --HEAD LouisBrunner/valgrind/valgrind
9 | echo "CI_HOMEBREW_CELLAR_VALGRIND=$(brew --cellar valgrind)" >> "$GITHUB_ENV"
10 | shell: bash
11 |
12 | - run: |
13 | sw_vers > valgrind_fingerprint
14 | brew --version >> valgrind_fingerprint
15 | git -C "$(brew --cache)/valgrind--git" rev-parse HEAD >> valgrind_fingerprint
16 | cat valgrind_fingerprint
17 | shell: bash
18 |
19 | - uses: actions/cache@v4
20 | id: cache
21 | with:
22 | path: ${{ env.CI_HOMEBREW_CELLAR_VALGRIND }}
23 | key: ${{ github.job }}-valgrind-${{ hashFiles('valgrind_fingerprint') }}
24 |
25 | - if: steps.cache.outputs.cache-hit != 'true'
26 | run: |
27 | brew install --HEAD LouisBrunner/valgrind/valgrind
28 | shell: bash
29 |
30 | - if: steps.cache.outputs.cache-hit == 'true'
31 | run: |
32 | brew link valgrind
33 | shell: bash
34 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/.github/actions/run-in-docker-action/action.yml:
--------------------------------------------------------------------------------
1 | name: 'Run in Docker with environment'
2 | description: 'Run a command in a Docker container, while passing explicitly set environment variables into the container.'
3 | inputs:
4 | dockerfile:
5 | description: 'A Dockerfile that defines an image'
6 | required: true
7 | tag:
8 | description: 'A tag of an image'
9 | required: true
10 | command:
11 | description: 'A command to run in a container'
12 | required: false
13 | default: ./ci/ci.sh
14 | runs:
15 | using: "composite"
16 | steps:
17 | - uses: docker/setup-buildx-action@v3
18 |
19 | - uses: docker/build-push-action@v5
20 | id: main_builder
21 | continue-on-error: true
22 | with:
23 | context: .
24 | file: ${{ inputs.dockerfile }}
25 | tags: ${{ inputs.tag }}
26 | load: true
27 | cache-from: type=gha
28 |
29 | - uses: docker/build-push-action@v5
30 | id: retry_builder
31 | if: steps.main_builder.outcome == 'failure'
32 | with:
33 | context: .
34 | file: ${{ inputs.dockerfile }}
35 | tags: ${{ inputs.tag }}
36 | load: true
37 | cache-from: type=gha
38 |
39 | - # Workaround for https://github.com/google/sanitizers/issues/1614 .
40 | # The underlying issue has been fixed in clang 18.1.3.
41 | run: sudo sysctl -w vm.mmap_rnd_bits=28
42 | shell: bash
43 |
44 | - # Tell Docker to pass environment variables in `env` into the container.
45 | run: >
46 | docker run \
47 | $(echo '${{ toJSON(env) }}' | jq -r 'keys[] | "--env \(.) "') \
48 | --volume ${{ github.workspace }}:${{ github.workspace }} \
49 | --workdir ${{ github.workspace }} \
50 | ${{ inputs.tag }} bash -c "
51 | git config --global --add safe.directory ${{ github.workspace }}
52 | ${{ inputs.command }}
53 | "
54 | shell: bash
55 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/.gitignore:
--------------------------------------------------------------------------------
1 | bench
2 | bench_ecmult
3 | bench_internal
4 | noverify_tests
5 | tests
6 | exhaustive_tests
7 | precompute_ecmult_gen
8 | precompute_ecmult
9 | ctime_tests
10 | ecdh_example
11 | ecdsa_example
12 | schnorr_example
13 | ellswift_example
14 | musig_example
15 | *.exe
16 | *.so
17 | *.a
18 | *.csv
19 | *.log
20 | *.trs
21 | *.sage.py
22 |
23 | Makefile
24 | configure
25 | .libs/
26 | Makefile.in
27 | aclocal.m4
28 | autom4te.cache/
29 | config.log
30 | config.status
31 | conftest*
32 | *.tar.gz
33 | *.la
34 | libtool
35 | .deps/
36 | .dirstamp
37 | *.lo
38 | *.o
39 | *~
40 |
41 | coverage/
42 | coverage.html
43 | coverage.*.html
44 | *.gcda
45 | *.gcno
46 | *.gcov
47 |
48 | build-aux/ar-lib
49 | build-aux/config.guess
50 | build-aux/config.sub
51 | build-aux/depcomp
52 | build-aux/install-sh
53 | build-aux/ltmain.sh
54 | build-aux/m4/libtool.m4
55 | build-aux/m4/lt~obsolete.m4
56 | build-aux/m4/ltoptions.m4
57 | build-aux/m4/ltsugar.m4
58 | build-aux/m4/ltversion.m4
59 | build-aux/missing
60 | build-aux/compile
61 | build-aux/test-driver
62 | libsecp256k1.pc
63 |
64 | ### CMake
65 | /CMakeUserPresets.json
66 | # Default CMake build directory.
67 | /build
68 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/CMakePresets.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0},
3 | "version": 3,
4 | "configurePresets": [
5 | {
6 | "name": "dev-mode",
7 | "displayName": "Development mode (intended only for developers of the library)",
8 | "cacheVariables": {
9 | "SECP256K1_EXPERIMENTAL": "ON",
10 | "SECP256K1_ENABLE_MODULE_RECOVERY": "ON",
11 | "SECP256K1_BUILD_EXAMPLES": "ON"
12 | },
13 | "warnings": {
14 | "dev": true,
15 | "uninitialized": true
16 | }
17 | }
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/COPYING:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Pieter Wuille
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Reporting a Vulnerability
4 |
5 | To report security issues send an email to secp256k1-security@bitcoincore.org (not for support).
6 |
7 | The following keys may be used to communicate sensitive information to developers:
8 |
9 | | Name | Fingerprint |
10 | |------|-------------|
11 | | Pieter Wuille | 133E AC17 9436 F14A 5CF1 B794 860F EB80 4E66 9320 |
12 | | Jonas Nick | 36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366 |
13 | | Tim Ruffing | 09E0 3F87 1092 E40E 106E 902B 33BC 86AB 80FF 5516 |
14 |
15 | You can import a key by running the following command with that individual’s fingerprint: `gpg --keyserver hkps://keys.openpgp.org --recv-keys ""` Ensure that you put quotes around fingerprints containing spaces.
16 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/autogen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 | autoreconf -if --warnings=all
4 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/contrib/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package contrib
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package libsecp256k1
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/include/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package include
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/libsecp256k1.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | includedir=@includedir@
5 |
6 | Name: libsecp256k1
7 | Description: Optimized C library for EC operations on curve secp256k1
8 | URL: https://github.com/bitcoin-core/secp256k1
9 | Version: @PACKAGE_VERSION@
10 | Cflags: -I${includedir}
11 | Libs: -L${libdir} -lsecp256k1
12 |
13 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/sage/secp256k1_params.sage:
--------------------------------------------------------------------------------
1 | """Prime order of finite field underlying secp256k1 (2^256 - 2^32 - 977)"""
2 | P = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
3 |
4 | """Finite field underlying secp256k1"""
5 | F = FiniteField(P)
6 |
7 | """Elliptic curve secp256k1: y^2 = x^3 + 7"""
8 | C = EllipticCurve([F(0), F(7)])
9 |
10 | """Base point of secp256k1"""
11 | G = C.lift_x(0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798)
12 | if int(G[1]) & 1:
13 | # G.y is even
14 | G = -G
15 |
16 | """Prime order of secp256k1"""
17 | N = C.order()
18 |
19 | """Finite field of scalars of secp256k1"""
20 | Z = FiniteField(N)
21 |
22 | """ Beta value of secp256k1 non-trivial endomorphism: lambda * (x, y) = (beta * x, y)"""
23 | BETA = F(2)^((P-1)/3)
24 |
25 | """ Lambda value of secp256k1 non-trivial endomorphism: lambda * (x, y) = (beta * x, y)"""
26 | LAMBDA = Z(3)^((N-1)/3)
27 |
28 | assert is_prime(P)
29 | assert is_prime(N)
30 |
31 | assert BETA != F(1)
32 | assert BETA^3 == F(1)
33 | assert BETA^2 + BETA + 1 == 0
34 |
35 | assert LAMBDA != Z(1)
36 | assert LAMBDA^3 == Z(1)
37 | assert LAMBDA^2 + LAMBDA + 1 == 0
38 |
39 | assert Integer(LAMBDA)*G == C(BETA*G[0], G[1])
40 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package src
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecdsa.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2013, 2014 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_ECDSA_H
8 | #define SECP256K1_ECDSA_H
9 |
10 | #include
11 |
12 | #include "scalar.h"
13 | #include "group.h"
14 | #include "ecmult.h"
15 |
16 | static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size);
17 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s);
18 | static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message);
19 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid);
20 |
21 | #endif /* SECP256K1_ECDSA_H */
22 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/eckey.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2013, 2014 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_ECKEY_H
8 | #define SECP256K1_ECKEY_H
9 |
10 | #include
11 |
12 | #include "group.h"
13 | #include "scalar.h"
14 | #include "ecmult.h"
15 | #include "ecmult_gen.h"
16 |
17 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size);
18 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed);
19 |
20 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak);
21 | static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak);
22 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak);
23 | static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak);
24 |
25 | #endif /* SECP256K1_ECKEY_H */
26 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult_compute_table.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************************
2 | * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php. *
5 | *****************************************************************************************************/
6 |
7 | #ifndef SECP256K1_ECMULT_COMPUTE_TABLE_H
8 | #define SECP256K1_ECMULT_COMPUTE_TABLE_H
9 |
10 | /* Construct table of all odd multiples of gen in range 1..(2**(window_g-1)-1). */
11 | static void secp256k1_ecmult_compute_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen);
12 |
13 | /* Like secp256k1_ecmult_compute_table, but one for both gen and gen*2^128. */
14 | static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen);
15 |
16 | #endif /* SECP256K1_ECMULT_COMPUTE_TABLE_H */
17 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult_compute_table_impl.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************************
2 | * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php. *
5 | *****************************************************************************************************/
6 |
7 | #ifndef SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H
8 | #define SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H
9 |
10 | #include "ecmult_compute_table.h"
11 | #include "group_impl.h"
12 | #include "field_impl.h"
13 | #include "ecmult.h"
14 | #include "util.h"
15 |
16 | static void secp256k1_ecmult_compute_table(secp256k1_ge_storage* table, int window_g, const secp256k1_gej* gen) {
17 | secp256k1_gej gj;
18 | secp256k1_ge ge, dgen;
19 | int j;
20 |
21 | gj = *gen;
22 | secp256k1_ge_set_gej_var(&ge, &gj);
23 | secp256k1_ge_to_storage(&table[0], &ge);
24 |
25 | secp256k1_gej_double_var(&gj, gen, NULL);
26 | secp256k1_ge_set_gej_var(&dgen, &gj);
27 |
28 | for (j = 1; j < ECMULT_TABLE_SIZE(window_g); ++j) {
29 | secp256k1_gej_set_ge(&gj, &ge);
30 | secp256k1_gej_add_ge_var(&gj, &gj, &dgen, NULL);
31 | secp256k1_ge_set_gej_var(&ge, &gj);
32 | secp256k1_ge_to_storage(&table[j], &ge);
33 | }
34 | }
35 |
36 | /* Like secp256k1_ecmult_compute_table, but one for both gen and gen*2^128. */
37 | static void secp256k1_ecmult_compute_two_tables(secp256k1_ge_storage* table, secp256k1_ge_storage* table_128, int window_g, const secp256k1_ge* gen) {
38 | secp256k1_gej gj;
39 | int i;
40 |
41 | secp256k1_gej_set_ge(&gj, gen);
42 | secp256k1_ecmult_compute_table(table, window_g, &gj);
43 | for (i = 0; i < 128; ++i) {
44 | secp256k1_gej_double_var(&gj, &gj, NULL);
45 | }
46 | secp256k1_ecmult_compute_table(table_128, window_g, &gj);
47 | }
48 |
49 | #endif /* SECP256K1_ECMULT_COMPUTE_TABLE_IMPL_H */
50 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult_const.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2015 Andrew Poelstra *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_ECMULT_CONST_H
8 | #define SECP256K1_ECMULT_CONST_H
9 |
10 | #include "scalar.h"
11 | #include "group.h"
12 |
13 | /**
14 | * Multiply: R = q*A (in constant-time for q)
15 | */
16 | static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, const secp256k1_scalar *q);
17 |
18 | /**
19 | * Same as secp256k1_ecmult_const, but takes in an x coordinate of the base point
20 | * only, specified as fraction n/d (numerator/denominator). Only the x coordinate of the result is
21 | * returned.
22 | *
23 | * If known_on_curve is 0, a verification is performed that n/d is a valid X
24 | * coordinate, and 0 is returned if not. Otherwise, 1 is returned.
25 | *
26 | * d being NULL is interpreted as d=1. If non-NULL, d must not be zero. q must not be zero.
27 | *
28 | * Constant time in the value of q, but not any other inputs.
29 | */
30 | static int secp256k1_ecmult_const_xonly(
31 | secp256k1_fe *r,
32 | const secp256k1_fe *n,
33 | const secp256k1_fe *d,
34 | const secp256k1_scalar *q,
35 | int known_on_curve
36 | );
37 |
38 | #endif /* SECP256K1_ECMULT_CONST_H */
39 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/ecmult_gen_compute_table.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) Pieter Wuille, Gregory Maxwell *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H
8 | #define SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H
9 |
10 | #include "ecmult_gen.h"
11 |
12 | static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, const secp256k1_ge* gen, int blocks, int teeth, int spacing);
13 |
14 | #endif /* SECP256K1_ECMULT_GEN_COMPUTE_TABLE_H */
15 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/hash.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2014 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_HASH_H
8 | #define SECP256K1_HASH_H
9 |
10 | #include
11 | #include
12 |
13 | typedef struct {
14 | uint32_t s[8];
15 | unsigned char buf[64];
16 | uint64_t bytes;
17 | } secp256k1_sha256;
18 |
19 | static void secp256k1_sha256_initialize(secp256k1_sha256 *hash);
20 | static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size);
21 | static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32);
22 | static void secp256k1_sha256_clear(secp256k1_sha256 *hash);
23 |
24 | typedef struct {
25 | secp256k1_sha256 inner, outer;
26 | } secp256k1_hmac_sha256;
27 |
28 | static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256 *hash, const unsigned char *key, size_t size);
29 | static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256 *hash, const unsigned char *data, size_t size);
30 | static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256 *hash, unsigned char *out32);
31 | static void secp256k1_hmac_sha256_clear(secp256k1_hmac_sha256 *hash);
32 |
33 | typedef struct {
34 | unsigned char v[32];
35 | unsigned char k[32];
36 | int retry;
37 | } secp256k1_rfc6979_hmac_sha256;
38 |
39 | static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256 *rng, const unsigned char *key, size_t keylen);
40 | static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256 *rng, unsigned char *out, size_t outlen);
41 | static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256 *rng);
42 | static void secp256k1_rfc6979_hmac_sha256_clear(secp256k1_rfc6979_hmac_sha256 *rng);
43 |
44 | #endif /* SECP256K1_HASH_H */
45 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/hsort.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2021 Russell O'Connor, Jonas Nick *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_HSORT_H
8 | #define SECP256K1_HSORT_H
9 |
10 | #include
11 | #include
12 |
13 | /* In-place, iterative heapsort with an interface matching glibc's qsort_r. This
14 | * is preferred over standard library implementations because they generally
15 | * make no guarantee about being fast for malicious inputs.
16 | * Remember that heapsort is unstable.
17 | *
18 | * In/Out: ptr: pointer to the array to sort. The contents of the array are
19 | * sorted in ascending order according to the comparison function.
20 | * In: count: number of elements in the array.
21 | * size: size in bytes of each element.
22 | * cmp: pointer to a comparison function that is called with two
23 | * arguments that point to the objects being compared. The cmp_data
24 | * argument of secp256k1_hsort is passed as third argument. The
25 | * function must return an integer less than, equal to, or greater
26 | * than zero if the first argument is considered to be respectively
27 | * less than, equal to, or greater than the second.
28 | * cmp_data: pointer passed as third argument to cmp.
29 | */
30 | static void secp256k1_hsort(void *ptr, size_t count, size_t size,
31 | int (*cmp)(const void *, const void *, void *),
32 | void *cmp_data);
33 | #endif
34 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/int128_impl.h:
--------------------------------------------------------------------------------
1 | #ifndef SECP256K1_INT128_IMPL_H
2 | #define SECP256K1_INT128_IMPL_H
3 |
4 | #include "util.h"
5 |
6 | #include "int128.h"
7 |
8 | #if defined(SECP256K1_WIDEMUL_INT128)
9 | # if defined(SECP256K1_INT128_NATIVE)
10 | # include "int128_native_impl.h"
11 | # elif defined(SECP256K1_INT128_STRUCT)
12 | # include "int128_struct_impl.h"
13 | # else
14 | # error "Please select int128 implementation"
15 | # endif
16 | #endif
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/int128_native.h:
--------------------------------------------------------------------------------
1 | #ifndef SECP256K1_INT128_NATIVE_H
2 | #define SECP256K1_INT128_NATIVE_H
3 |
4 | #include
5 | #include "util.h"
6 |
7 | #if !defined(UINT128_MAX) && defined(__SIZEOF_INT128__)
8 | SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t;
9 | SECP256K1_GNUC_EXT typedef __int128 int128_t;
10 | # define UINT128_MAX ((uint128_t)(-1))
11 | # define INT128_MAX ((int128_t)(UINT128_MAX >> 1))
12 | # define INT128_MIN (-INT128_MAX - 1)
13 | /* No (U)INT128_C macros because compilers providing __int128 do not support 128-bit literals. */
14 | #endif
15 |
16 | typedef uint128_t secp256k1_uint128;
17 | typedef int128_t secp256k1_int128;
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/int128_struct.h:
--------------------------------------------------------------------------------
1 | #ifndef SECP256K1_INT128_STRUCT_H
2 | #define SECP256K1_INT128_STRUCT_H
3 |
4 | #include
5 | #include "util.h"
6 |
7 | typedef struct {
8 | uint64_t lo;
9 | uint64_t hi;
10 | } secp256k1_uint128;
11 |
12 | typedef secp256k1_uint128 secp256k1_int128;
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modinv32.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2020 Peter Dettman *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | **********************************************************************/
6 |
7 | #ifndef SECP256K1_MODINV32_H
8 | #define SECP256K1_MODINV32_H
9 |
10 | #include "util.h"
11 |
12 | /* A signed 30-bit limb representation of integers.
13 | *
14 | * Its value is sum(v[i] * 2^(30*i), i=0..8). */
15 | typedef struct {
16 | int32_t v[9];
17 | } secp256k1_modinv32_signed30;
18 |
19 | typedef struct {
20 | /* The modulus in signed30 notation, must be odd and in [3, 2^256]. */
21 | secp256k1_modinv32_signed30 modulus;
22 |
23 | /* modulus^{-1} mod 2^30 */
24 | uint32_t modulus_inv30;
25 | } secp256k1_modinv32_modinfo;
26 |
27 | /* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus).
28 | * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of
29 | * x and modulus must be 1). These rules are automatically satisfied if the modulus is prime.
30 | *
31 | * On output, all of x's limbs will be in [0, 2^30).
32 | */
33 | static void secp256k1_modinv32_var(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);
34 |
35 | /* Same as secp256k1_modinv32_var, but constant time in x (not in the modulus). */
36 | static void secp256k1_modinv32(secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);
37 |
38 | /* Compute the Jacobi symbol for (x | modinfo->modulus). x must be coprime with modulus (and thus
39 | * cannot be 0, as modulus >= 3). All limbs of x must be non-negative. Returns 0 if the result
40 | * cannot be computed. */
41 | static int secp256k1_jacobi32_maybe_var(const secp256k1_modinv32_signed30 *x, const secp256k1_modinv32_modinfo *modinfo);
42 |
43 | #endif /* SECP256K1_MODINV32_H */
44 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modinv64.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2020 Peter Dettman *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | **********************************************************************/
6 |
7 | #ifndef SECP256K1_MODINV64_H
8 | #define SECP256K1_MODINV64_H
9 |
10 | #include "util.h"
11 |
12 | #ifndef SECP256K1_WIDEMUL_INT128
13 | #error "modinv64 requires 128-bit wide multiplication support"
14 | #endif
15 |
16 | /* A signed 62-bit limb representation of integers.
17 | *
18 | * Its value is sum(v[i] * 2^(62*i), i=0..4). */
19 | typedef struct {
20 | int64_t v[5];
21 | } secp256k1_modinv64_signed62;
22 |
23 | typedef struct {
24 | /* The modulus in signed62 notation, must be odd and in [3, 2^256]. */
25 | secp256k1_modinv64_signed62 modulus;
26 |
27 | /* modulus^{-1} mod 2^62 */
28 | uint64_t modulus_inv62;
29 | } secp256k1_modinv64_modinfo;
30 |
31 | /* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus).
32 | * If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of
33 | * x and modulus must be 1). These rules are automatically satisfied if the modulus is prime.
34 | *
35 | * On output, all of x's limbs will be in [0, 2^62).
36 | */
37 | static void secp256k1_modinv64_var(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo);
38 |
39 | /* Same as secp256k1_modinv64_var, but constant time in x (not in the modulus). */
40 | static void secp256k1_modinv64(secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo);
41 |
42 | /* Compute the Jacobi symbol for (x | modinfo->modulus). x must be coprime with modulus (and thus
43 | * cannot be 0, as modulus >= 3). All limbs of x must be non-negative. Returns 0 if the result
44 | * cannot be computed. */
45 | static int secp256k1_jacobi64_maybe_var(const secp256k1_modinv64_signed62 *x, const secp256k1_modinv64_modinfo *modinfo);
46 |
47 | #endif /* SECP256K1_MODINV64_H */
48 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package module
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/Makefile.am.include:
--------------------------------------------------------------------------------
1 | include_HEADERS += include/secp256k1_ecdh.h
2 | noinst_HEADERS += src/modules/ecdh/main_impl.h
3 | noinst_HEADERS += src/modules/ecdh/tests_impl.h
4 | noinst_HEADERS += src/modules/ecdh/bench_impl.h
5 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/bench_impl.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2015 Pieter Wuille, Andrew Poelstra *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_MODULE_ECDH_BENCH_H
8 | #define SECP256K1_MODULE_ECDH_BENCH_H
9 |
10 | #include "../../../include/secp256k1_ecdh.h"
11 |
12 | typedef struct {
13 | secp256k1_context *ctx;
14 | secp256k1_pubkey point;
15 | unsigned char scalar[32];
16 | } bench_ecdh_data;
17 |
18 | static void bench_ecdh_setup(void* arg) {
19 | int i;
20 | bench_ecdh_data *data = (bench_ecdh_data*)arg;
21 | const unsigned char point[] = {
22 | 0x03,
23 | 0x54, 0x94, 0xc1, 0x5d, 0x32, 0x09, 0x97, 0x06,
24 | 0xc2, 0x39, 0x5f, 0x94, 0x34, 0x87, 0x45, 0xfd,
25 | 0x75, 0x7c, 0xe3, 0x0e, 0x4e, 0x8c, 0x90, 0xfb,
26 | 0xa2, 0xba, 0xd1, 0x84, 0xf8, 0x83, 0xc6, 0x9f
27 | };
28 |
29 | for (i = 0; i < 32; i++) {
30 | data->scalar[i] = i + 1;
31 | }
32 | CHECK(ethkit_secp256k1_ec_pubkey_parse(data->ctx, &data->point, point, sizeof(point)) == 1);
33 | }
34 |
35 | static void bench_ecdh(void* arg, int iters) {
36 | int i;
37 | unsigned char res[32];
38 | bench_ecdh_data *data = (bench_ecdh_data*)arg;
39 |
40 | for (i = 0; i < iters; i++) {
41 | CHECK(secp256k1_ecdh(data->ctx, res, &data->point, data->scalar, NULL, NULL) == 1);
42 | }
43 | }
44 |
45 | static void run_ecdh_bench(int iters, int argc, char** argv) {
46 | bench_ecdh_data data;
47 | int d = argc == 1;
48 |
49 | /* create a context with no capabilities */
50 | data.ctx = ethkit_secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT);
51 |
52 | if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
53 |
54 | ethkit_secp256k1_context_destroy(data.ctx);
55 | }
56 |
57 | #endif /* SECP256K1_MODULE_ECDH_BENCH_H */
58 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ecdh/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package ecdh
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ellswift/Makefile.am.include:
--------------------------------------------------------------------------------
1 | include_HEADERS += include/secp256k1_ellswift.h
2 | noinst_HEADERS += src/modules/ellswift/bench_impl.h
3 | noinst_HEADERS += src/modules/ellswift/main_impl.h
4 | noinst_HEADERS += src/modules/ellswift/tests_impl.h
5 | noinst_HEADERS += src/modules/ellswift/tests_exhaustive_impl.h
6 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/ellswift/tests_exhaustive_impl.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Distributed under the MIT software license, see the accompanying *
3 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
4 | ***********************************************************************/
5 |
6 | #ifndef SECP256K1_MODULE_ELLSWIFT_TESTS_EXHAUSTIVE_H
7 | #define SECP256K1_MODULE_ELLSWIFT_TESTS_EXHAUSTIVE_H
8 |
9 | #include "../../../include/secp256k1_ellswift.h"
10 | #include "main_impl.h"
11 |
12 | static void test_exhaustive_ellswift(const secp256k1_context *ctx, const secp256k1_ge *group) {
13 | int i;
14 |
15 | /* Note that SwiftEC/ElligatorSwift are inherently curve operations, not
16 | * group operations, and this test only checks the curve points which are in
17 | * a tiny subgroup. In that sense it can't be really seen as exhaustive as
18 | * it doesn't (and for computational reasons obviously cannot) test the
19 | * entire domain ellswift operates under. */
20 | for (i = 1; i < EXHAUSTIVE_TEST_ORDER; i++) {
21 | secp256k1_scalar scalar_i;
22 | unsigned char sec32[32];
23 | unsigned char ell64[64];
24 | secp256k1_pubkey pub_decoded;
25 | secp256k1_ge ge_decoded;
26 |
27 | /* Construct ellswift pubkey from exhaustive loop scalar i. */
28 | secp256k1_scalar_set_int(&scalar_i, i);
29 | secp256k1_scalar_get_b32(sec32, &scalar_i);
30 | CHECK(secp256k1_ellswift_create(ctx, ell64, sec32, NULL));
31 |
32 | /* Decode ellswift pubkey and check that it matches the precomputed group element. */
33 | secp256k1_ellswift_decode(ctx, &pub_decoded, ell64);
34 | secp256k1_pubkey_load(ctx, &ge_decoded, &pub_decoded);
35 | CHECK(secp256k1_ge_eq_var(&ge_decoded, &group[i]));
36 | }
37 | }
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/extrakeys/Makefile.am.include:
--------------------------------------------------------------------------------
1 | include_HEADERS += include/secp256k1_extrakeys.h
2 | noinst_HEADERS += src/modules/extrakeys/tests_impl.h
3 | noinst_HEADERS += src/modules/extrakeys/tests_exhaustive_impl.h
4 | noinst_HEADERS += src/modules/extrakeys/main_impl.h
5 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/musig/Makefile.am.include:
--------------------------------------------------------------------------------
1 | include_HEADERS += include/secp256k1_musig.h
2 | noinst_HEADERS += src/modules/musig/main_impl.h
3 | noinst_HEADERS += src/modules/musig/keyagg.h
4 | noinst_HEADERS += src/modules/musig/keyagg_impl.h
5 | noinst_HEADERS += src/modules/musig/session.h
6 | noinst_HEADERS += src/modules/musig/session_impl.h
7 | noinst_HEADERS += src/modules/musig/tests_impl.h
8 | noinst_HEADERS += src/modules/musig/vectors.h
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/musig/keyagg.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Distributed under the MIT software license, see the accompanying *
3 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
4 | ***********************************************************************/
5 |
6 | #ifndef SECP256K1_MODULE_MUSIG_KEYAGG_H
7 | #define SECP256K1_MODULE_MUSIG_KEYAGG_H
8 |
9 | #include "../../../include/secp256k1.h"
10 | #include "../../../include/secp256k1_musig.h"
11 |
12 | #include "../../group.h"
13 | #include "../../scalar.h"
14 |
15 | typedef struct {
16 | secp256k1_ge pk;
17 | /* If there is no "second" public key, second_pk is set to the point at
18 | * infinity */
19 | secp256k1_ge second_pk;
20 | unsigned char pks_hash[32];
21 | /* tweak is identical to value tacc[v] in the specification. */
22 | secp256k1_scalar tweak;
23 | /* parity_acc corresponds to (1 - gacc[v])/2 in the spec. So if gacc[v] is
24 | * -1, parity_acc is 1. Otherwise, parity_acc is 0. */
25 | int parity_acc;
26 | } secp256k1_keyagg_cache_internal;
27 |
28 | static int secp256k1_keyagg_cache_load(const secp256k1_context* ctx, secp256k1_keyagg_cache_internal *cache_i, const secp256k1_musig_keyagg_cache *cache);
29 |
30 | static void secp256k1_musig_keyaggcoef(secp256k1_scalar *r, const secp256k1_keyagg_cache_internal *cache_i, secp256k1_ge *pk);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/musig/main_impl.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 | * Distributed under the MIT software license, see the accompanying *
3 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
4 | **********************************************************************/
5 |
6 | #ifndef SECP256K1_MODULE_MUSIG_MAIN_H
7 | #define SECP256K1_MODULE_MUSIG_MAIN_H
8 |
9 | #include "keyagg_impl.h"
10 | #include "session_impl.h"
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/musig/session.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Distributed under the MIT software license, see the accompanying *
3 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
4 | ***********************************************************************/
5 |
6 | #ifndef SECP256K1_MODULE_MUSIG_SESSION_H
7 | #define SECP256K1_MODULE_MUSIG_SESSION_H
8 |
9 | #include "../../../include/secp256k1.h"
10 | #include "../../../include/secp256k1_musig.h"
11 |
12 | #include "../../scalar.h"
13 |
14 | typedef struct {
15 | int fin_nonce_parity;
16 | unsigned char fin_nonce[32];
17 | secp256k1_scalar noncecoef;
18 | secp256k1_scalar challenge;
19 | secp256k1_scalar s_part;
20 | } secp256k1_musig_session_internal;
21 |
22 | static int secp256k1_musig_session_load(const secp256k1_context* ctx, secp256k1_musig_session_internal *session_i, const secp256k1_musig_session *session);
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/recovery/Makefile.am.include:
--------------------------------------------------------------------------------
1 | include_HEADERS += include/secp256k1_recovery.h
2 | noinst_HEADERS += src/modules/recovery/main_impl.h
3 | noinst_HEADERS += src/modules/recovery/tests_impl.h
4 | noinst_HEADERS += src/modules/recovery/tests_exhaustive_impl.h
5 | noinst_HEADERS += src/modules/recovery/bench_impl.h
6 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/recovery/dummy.go:
--------------------------------------------------------------------------------
1 | //go:build dummy
2 | // +build dummy
3 |
4 | // Package c contains only a C file.
5 | //
6 | // This Go file is part of a workaround for `go mod vendor`.
7 | // Please see the file crypto/secp256k1/dummy.go for more information.
8 | package recovery
9 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/modules/schnorrsig/Makefile.am.include:
--------------------------------------------------------------------------------
1 | include_HEADERS += include/secp256k1_schnorrsig.h
2 | noinst_HEADERS += src/modules/schnorrsig/main_impl.h
3 | noinst_HEADERS += src/modules/schnorrsig/tests_impl.h
4 | noinst_HEADERS += src/modules/schnorrsig/tests_exhaustive_impl.h
5 | noinst_HEADERS += src/modules/schnorrsig/bench_impl.h
6 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/precomputed_ecmult.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************************************
2 | * Copyright (c) 2013, 2014, 2017, 2021 Pieter Wuille, Andrew Poelstra, Jonas Nick, Russell O'Connor *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php. *
5 | *****************************************************************************************************/
6 |
7 | #ifndef SECP256K1_PRECOMPUTED_ECMULT_H
8 | #define SECP256K1_PRECOMPUTED_ECMULT_H
9 |
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 |
14 | #include "ecmult.h"
15 | #include "group.h"
16 | #if defined(EXHAUSTIVE_TEST_ORDER)
17 | # if EXHAUSTIVE_TEST_ORDER == 7
18 | # define WINDOW_G 3
19 | # elif EXHAUSTIVE_TEST_ORDER == 13
20 | # define WINDOW_G 4
21 | # elif EXHAUSTIVE_TEST_ORDER == 199
22 | # define WINDOW_G 8
23 | # else
24 | # error No known generator for the specified exhaustive test group order.
25 | # endif
26 | static secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)];
27 | static secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)];
28 | #else /* !defined(EXHAUSTIVE_TEST_ORDER) */
29 | # define WINDOW_G ECMULT_WINDOW_SIZE
30 | extern const secp256k1_ge_storage secp256k1_pre_g[ECMULT_TABLE_SIZE(WINDOW_G)];
31 | extern const secp256k1_ge_storage secp256k1_pre_g_128[ECMULT_TABLE_SIZE(WINDOW_G)];
32 | #endif /* defined(EXHAUSTIVE_TEST_ORDER) */
33 |
34 | #ifdef __cplusplus
35 | }
36 | #endif
37 |
38 | #endif /* SECP256K1_PRECOMPUTED_ECMULT_H */
39 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/precomputed_ecmult_gen.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************************
2 | * Copyright (c) 2013, 2014, 2015, 2021 Thomas Daede, Cory Fields, Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php. *
5 | *********************************************************************************/
6 |
7 | #ifndef SECP256K1_PRECOMPUTED_ECMULT_GEN_H
8 | #define SECP256K1_PRECOMPUTED_ECMULT_GEN_H
9 |
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 |
14 | #include "group.h"
15 | #include "ecmult_gen.h"
16 | #ifdef EXHAUSTIVE_TEST_ORDER
17 | static secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS];
18 | #else
19 | extern const secp256k1_ge_storage secp256k1_ecmult_gen_prec_table[COMB_BLOCKS][COMB_POINTS];
20 | #endif /* defined(EXHAUSTIVE_TEST_ORDER) */
21 |
22 | #ifdef __cplusplus
23 | }
24 | #endif
25 |
26 | #endif /* SECP256K1_PRECOMPUTED_ECMULT_GEN_H */
27 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_4x64.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2014 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_SCALAR_REPR_H
8 | #define SECP256K1_SCALAR_REPR_H
9 |
10 | #include
11 |
12 | /** A scalar modulo the group order of the secp256k1 curve. */
13 | typedef struct {
14 | uint64_t d[4];
15 | } secp256k1_scalar;
16 |
17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}}
18 |
19 | #endif /* SECP256K1_SCALAR_REPR_H */
20 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_8x32.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2014 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_SCALAR_REPR_H
8 | #define SECP256K1_SCALAR_REPR_H
9 |
10 | #include
11 |
12 | /** A scalar modulo the group order of the secp256k1 curve. */
13 | typedef struct {
14 | uint32_t d[8];
15 | } secp256k1_scalar;
16 |
17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}}
18 |
19 | #endif /* SECP256K1_SCALAR_REPR_H */
20 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/scalar_low.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2015, 2022 Andrew Poelstra, Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_SCALAR_REPR_H
8 | #define SECP256K1_SCALAR_REPR_H
9 |
10 | #include
11 |
12 | /** A scalar modulo the group order of the secp256k1 curve. */
13 | typedef uint32_t secp256k1_scalar;
14 |
15 | /* A compile-time constant equal to 2^32 (modulo order). */
16 | #define SCALAR_2P32 ((0xffffffffUL % EXHAUSTIVE_TEST_ORDER) + 1U)
17 |
18 | /* Compute a*2^32 + b (modulo order). */
19 | #define SCALAR_HORNER(a, b) (((uint64_t)(a) * SCALAR_2P32 + (b)) % EXHAUSTIVE_TEST_ORDER)
20 |
21 | /* Evaluates to the provided 256-bit constant reduced modulo order. */
22 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER(SCALAR_HORNER((d7), (d6)), (d5)), (d4)), (d3)), (d2)), (d1)), (d0))
23 |
24 | #endif /* SECP256K1_SCALAR_REPR_H */
25 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/selftest.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2020 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_SELFTEST_H
8 | #define SECP256K1_SELFTEST_H
9 |
10 | #include "hash.h"
11 |
12 | #include
13 |
14 | static int secp256k1_selftest_sha256(void) {
15 | static const char *input63 = "For this sample, this 63-byte string will be used as input data";
16 | static const unsigned char output32[32] = {
17 | 0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e,
18 | 0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42,
19 | };
20 | unsigned char out[32];
21 | secp256k1_sha256 hasher;
22 | secp256k1_sha256_initialize(&hasher);
23 | secp256k1_sha256_write(&hasher, (const unsigned char*)input63, 63);
24 | secp256k1_sha256_finalize(&hasher, out);
25 | return secp256k1_memcmp_var(out, output32, 32) == 0;
26 | }
27 |
28 | static int secp256k1_selftest_passes(void) {
29 | return secp256k1_selftest_sha256();
30 | }
31 |
32 | #endif /* SECP256K1_SELFTEST_H */
33 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/libsecp256k1/src/testrand.h:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 | * Copyright (c) 2013, 2014 Pieter Wuille *
3 | * Distributed under the MIT software license, see the accompanying *
4 | * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 | ***********************************************************************/
6 |
7 | #ifndef SECP256K1_TESTRAND_H
8 | #define SECP256K1_TESTRAND_H
9 |
10 | #include "util.h"
11 |
12 | /* A non-cryptographic RNG used only for test infrastructure. */
13 |
14 | /** Seed the pseudorandom number generator for testing. */
15 | SECP256K1_INLINE static void testrand_seed(const unsigned char *seed16);
16 |
17 | /** Generate a pseudorandom number in the range [0..2**32-1]. */
18 | SECP256K1_INLINE static uint32_t testrand32(void);
19 |
20 | /** Generate a pseudorandom number in the range [0..2**64-1]. */
21 | SECP256K1_INLINE static uint64_t testrand64(void);
22 |
23 | /** Generate a pseudorandom number in the range [0..2**bits-1]. Bits must be 1 or
24 | * more. */
25 | SECP256K1_INLINE static uint64_t testrand_bits(int bits);
26 |
27 | /** Generate a pseudorandom number in the range [0..range-1]. */
28 | static uint32_t testrand_int(uint32_t range);
29 |
30 | /** Generate a pseudorandom 32-byte array. */
31 | static void testrand256(unsigned char *b32);
32 |
33 | /** Generate a pseudorandom 32-byte array with long sequences of zero and one bits. */
34 | static void testrand256_test(unsigned char *b32);
35 |
36 | /** Generate pseudorandom bytes with long sequences of zero and one bits. */
37 | static void testrand_bytes_test(unsigned char *bytes, size_t len);
38 |
39 | /** Flip a single random bit in a byte array */
40 | static void testrand_flip(unsigned char *b, size_t len);
41 |
42 | /** Initialize the test RNG using (hex encoded) array up to 16 bytes, or randomly if hexseed is NULL. */
43 | static void testrand_init(const char* hexseed);
44 |
45 | /** Print final test information. */
46 | static void testrand_finish(void);
47 |
48 | #endif /* SECP256K1_TESTRAND_H */
49 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/panic_cb.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be found in
3 | // the LICENSE file.
4 |
5 | //go:build !gofuzz && cgo
6 | // +build !gofuzz,cgo
7 |
8 | package secp256k1
9 |
10 | import "C"
11 | import "unsafe"
12 |
13 | // Callbacks for converting libsecp256k1 internal faults into
14 | // recoverable Go panics.
15 |
16 | //export ethkitSecp256k1GoPanicIllegal
17 | func ethkitSecp256k1GoPanicIllegal(msg *C.char, data unsafe.Pointer) {
18 | panic("illegal argument: " + C.GoString(msg))
19 | }
20 |
21 | //export ethkitSecp256k1GoPanicError
22 | func ethkitSecp256k1GoPanicError(msg *C.char, data unsafe.Pointer) {
23 | panic("internal error: " + C.GoString(msg))
24 | }
25 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/scalar_mult_cgo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be found in
3 | // the LICENSE file.
4 |
5 | //go:build !gofuzz && cgo
6 | // +build !gofuzz,cgo
7 |
8 | package secp256k1
9 |
10 | import (
11 | "math/big"
12 | "unsafe"
13 | )
14 |
15 | /*
16 |
17 | #include "libsecp256k1/include/secp256k1.h"
18 |
19 | extern int ethkit_secp256k1_ext_scalar_mul(const secp256k1_context* ctx, const unsigned char *point, const unsigned char *scalar);
20 |
21 | */
22 | import "C"
23 |
24 | func (bitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
25 | // Ensure scalar is exactly 32 bytes. We pad always, even if
26 | // scalar is 32 bytes long, to avoid a timing side channel.
27 | if len(scalar) > 32 {
28 | panic("can't handle scalars > 256 bits")
29 | }
30 | // NOTE: potential timing issue
31 | padded := make([]byte, 32)
32 | copy(padded[32-len(scalar):], scalar)
33 | scalar = padded
34 |
35 | // Do the multiplication in C, updating point.
36 | point := make([]byte, 64)
37 | readBits(Bx, point[:32])
38 | readBits(By, point[32:])
39 |
40 | pointPtr := (*C.uchar)(unsafe.Pointer(&point[0]))
41 | scalarPtr := (*C.uchar)(unsafe.Pointer(&scalar[0]))
42 | res := C.ethkit_secp256k1_ext_scalar_mul(context, pointPtr, scalarPtr)
43 |
44 | // Unpack the result and clear temporaries.
45 | x := new(big.Int).SetBytes(point[:32])
46 | y := new(big.Int).SetBytes(point[32:])
47 | clear(point)
48 | clear(scalar)
49 | if res != 1 {
50 | return nil, nil
51 | }
52 | return x, y
53 | }
54 |
--------------------------------------------------------------------------------
/go-ethereum/crypto/secp256k1/scalar_mult_nocgo.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved.
2 | // Use of this source code is governed by a BSD-style license that can be found in
3 | // the LICENSE file.
4 |
5 | //go:build gofuzz || !cgo
6 | // +build gofuzz !cgo
7 |
8 | package secp256k1
9 |
10 | import "math/big"
11 |
12 | func (bitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int, *big.Int) {
13 | panic("ScalarMult is not available when secp256k1 is built without cgo")
14 | }
15 |
--------------------------------------------------------------------------------
/go-ethereum/event/example_subscription_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2016 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package event_test
18 |
19 | import (
20 | "fmt"
21 |
22 | "github.com/0xsequence/ethkit/go-ethereum/event"
23 | )
24 |
25 | func ExampleNewSubscription() {
26 | // Create a subscription that sends 10 integers on ch.
27 | ch := make(chan int)
28 | sub := event.NewSubscription(func(quit <-chan struct{}) error {
29 | for i := 0; i < 10; i++ {
30 | select {
31 | case ch <- i:
32 | case <-quit:
33 | fmt.Println("unsubscribed")
34 | return nil
35 | }
36 | }
37 | return nil
38 | })
39 |
40 | // This is the consumer. It reads 5 integers, then aborts the subscription.
41 | // Note that Unsubscribe waits until the producer has shut down.
42 | for i := range ch {
43 | fmt.Println(i)
44 | if i == 4 {
45 | sub.Unsubscribe()
46 | break
47 | }
48 | }
49 | // Output:
50 | // 0
51 | // 1
52 | // 2
53 | // 3
54 | // 4
55 | // unsubscribed
56 | }
57 |
--------------------------------------------------------------------------------
/go-ethereum/event/example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package event
18 |
19 | import "fmt"
20 |
21 | func ExampleTypeMux() {
22 | type someEvent struct{ I int }
23 | type otherEvent struct{ S string }
24 | type yetAnotherEvent struct{ X, Y int }
25 |
26 | var mux TypeMux
27 |
28 | // Start a subscriber.
29 | done := make(chan struct{})
30 | sub := mux.Subscribe(someEvent{}, otherEvent{})
31 | go func() {
32 | for event := range sub.Chan() {
33 | fmt.Printf("Received: %#v\n", event.Data)
34 | }
35 | fmt.Println("done")
36 | close(done)
37 | }()
38 |
39 | // Post some events.
40 | mux.Post(someEvent{5})
41 | mux.Post(yetAnotherEvent{X: 3, Y: 4})
42 | mux.Post(someEvent{6})
43 | mux.Post(otherEvent{"whoa"})
44 |
45 | // Stop closes all subscription channels.
46 | // The subscriber goroutine will print "done"
47 | // and exit.
48 | mux.Stop()
49 |
50 | // Wait for subscriber to return.
51 | <-done
52 |
53 | // Output:
54 | // Received: event.someEvent{I:5}
55 | // Received: event.someEvent{I:6}
56 | // Received: event.otherEvent{S:"whoa"}
57 | // done
58 | }
59 |
--------------------------------------------------------------------------------
/go-ethereum/event/multisub.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package event
18 |
19 | // JoinSubscriptions joins multiple subscriptions to be able to track them as
20 | // one entity and collectively cancel them or consume any errors from them.
21 | func JoinSubscriptions(subs ...Subscription) Subscription {
22 | return NewSubscription(func(unsubbed <-chan struct{}) error {
23 | // Unsubscribe all subscriptions before returning
24 | defer func() {
25 | for _, sub := range subs {
26 | sub.Unsubscribe()
27 | }
28 | }()
29 | // Wait for an error on any of the subscriptions and propagate up
30 | errc := make(chan error, len(subs))
31 | for i := range subs {
32 | go func(sub Subscription) {
33 | select {
34 | case err := <-sub.Err():
35 | if err != nil {
36 | errc <- err
37 | }
38 | case <-unsubbed:
39 | }
40 | }(subs[i])
41 | }
42 |
43 | select {
44 | case err := <-errc:
45 | return err
46 | case <-unsubbed:
47 | return nil
48 | }
49 | })
50 | }
51 |
--------------------------------------------------------------------------------
/go-ethereum/internal/blocktest/test_hash.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | // Package utesting provides a standalone replacement for package testing.
18 | //
19 | // This package exists because package testing cannot easily be embedded into a
20 | // standalone go program. It provides an API that mirrors the standard library
21 | // testing API.
22 |
23 | package blocktest
24 |
25 | import (
26 | "hash"
27 |
28 | "github.com/0xsequence/ethkit/go-ethereum/common"
29 | "golang.org/x/crypto/sha3"
30 | )
31 |
32 | // testHasher is the helper tool for transaction/receipt list hashing.
33 | // The original hasher is trie, in order to get rid of import cycle,
34 | // use the testing hasher instead.
35 | type testHasher struct {
36 | hasher hash.Hash
37 | }
38 |
39 | // NewHasher returns a new testHasher instance.
40 | func NewHasher() *testHasher {
41 | return &testHasher{hasher: sha3.NewLegacyKeccak256()}
42 | }
43 |
44 | // Reset resets the hash state.
45 | func (h *testHasher) Reset() {
46 | h.hasher.Reset()
47 | }
48 |
49 | // Update updates the hash state with the given key and value.
50 | func (h *testHasher) Update(key, val []byte) error {
51 | h.hasher.Write(key)
52 | h.hasher.Write(val)
53 | return nil
54 | }
55 |
56 | // Hash returns the hash value.
57 | func (h *testHasher) Hash() common.Hash {
58 | return common.BytesToHash(h.hasher.Sum(nil))
59 | }
60 |
--------------------------------------------------------------------------------
/go-ethereum/internal/testrand/rand.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package testrand
18 |
19 | import (
20 | crand "crypto/rand"
21 | "encoding/binary"
22 | mrand "math/rand"
23 |
24 | "github.com/0xsequence/ethkit/go-ethereum/common"
25 | )
26 |
27 | // prng is a pseudo random number generator seeded by strong randomness.
28 | // The randomness is printed on startup in order to make failures reproducible.
29 | var prng = initRand()
30 |
31 | func initRand() *mrand.Rand {
32 | var seed [8]byte
33 | crand.Read(seed[:])
34 | rnd := mrand.New(mrand.NewSource(int64(binary.LittleEndian.Uint64(seed[:]))))
35 | return rnd
36 | }
37 |
38 | // Bytes generates a random byte slice with specified length.
39 | func Bytes(n int) []byte {
40 | r := make([]byte, n)
41 | prng.Read(r)
42 | return r
43 | }
44 |
45 | // Hash generates a random hash.
46 | func Hash() common.Hash {
47 | return common.BytesToHash(Bytes(common.HashLength))
48 | }
49 |
50 | // Address generates a random address.
51 | func Address() common.Address {
52 | return common.BytesToAddress(Bytes(common.AddressLength))
53 | }
54 |
--------------------------------------------------------------------------------
/go-ethereum/log/format_test.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | import (
4 | "math/rand"
5 | "testing"
6 | )
7 |
8 | var sink []byte
9 |
10 | func BenchmarkPrettyInt64Logfmt(b *testing.B) {
11 | buf := make([]byte, 100)
12 | b.ReportAllocs()
13 | for i := 0; i < b.N; i++ {
14 | sink = appendInt64(buf, rand.Int63())
15 | }
16 | }
17 |
18 | func BenchmarkPrettyUint64Logfmt(b *testing.B) {
19 | buf := make([]byte, 100)
20 | b.ReportAllocs()
21 | for i := 0; i < b.N; i++ {
22 | sink = appendUint64(buf, rand.Uint64(), false)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/go-ethereum/log/root_test.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | // SetDefault should properly set the default logger when custom loggers are
8 | // provided.
9 | func TestSetDefaultCustomLogger(t *testing.T) {
10 | type customLogger struct {
11 | Logger // Implement the Logger interface
12 | }
13 |
14 | customLog := &customLogger{}
15 | SetDefault(customLog)
16 | if Root() != customLog {
17 | t.Error("expected custom logger to be set as default")
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/go-ethereum/p2p/server.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | // Package p2p implements the Ethereum p2p network protocols.
18 | package p2p
19 |
20 | // NodeInfo represents a short summary of the information known about the host.
21 | type NodeInfo struct {
22 | ID string `json:"id"` // Unique node identifier (also the encryption key)
23 | Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
24 | Enode string `json:"enode"` // Enode URL for adding this peer from remote peers
25 | ENR string `json:"enr"` // Ethereum Node Record
26 | IP string `json:"ip"` // IP address of the node
27 | Ports struct {
28 | Discovery int `json:"discovery"` // UDP listening port for discovery protocol
29 | Listener int `json:"listener"` // TCP listening port for RLPx
30 | } `json:"ports"`
31 | ListenAddr string `json:"listenAddr"`
32 | Protocols map[string]interface{} `json:"protocols"`
33 | }
34 |
--------------------------------------------------------------------------------
/go-ethereum/params/denomination.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package params
18 |
19 | // These are the multipliers for ether denominations.
20 | // Example: To get the wei value of an amount in 'gwei', use
21 | //
22 | // new(big.Int).Mul(value, big.NewInt(params.GWei))
23 | const (
24 | Wei = 1
25 | GWei = 1e9
26 | Ether = 1e18
27 | )
28 |
--------------------------------------------------------------------------------
/go-ethereum/params/network_params.go:
--------------------------------------------------------------------------------
1 | // Copyright 2017 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package params
18 |
19 | // These are network parameters that need to be constant between clients, but
20 | // aren't necessarily consensus related.
21 |
22 | const (
23 | // FullImmutabilityThreshold is the number of blocks after which a chain segment is
24 | // considered immutable (i.e. soft finality). It is used by the downloader as a
25 | // hard limit against deep ancestors, by the blockchain against deep reorgs, by
26 | // the freezer as the cutoff threshold and by clique as the snapshot trust limit.
27 | FullImmutabilityThreshold = 90000
28 | )
29 |
--------------------------------------------------------------------------------
/go-ethereum/params/verkle_params.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package params
18 |
19 | // Verkle tree EIP: costs associated to witness accesses
20 | var (
21 | WitnessBranchReadCost uint64 = 1900
22 | WitnessChunkReadCost uint64 = 200
23 | WitnessBranchWriteCost uint64 = 3000
24 | WitnessChunkWriteCost uint64 = 500
25 | WitnessChunkFillCost uint64 = 6200
26 | )
27 |
28 | // ClearVerkleWitnessCosts sets all witness costs to 0, which is necessary
29 | // for historical block replay simulations.
30 | func ClearVerkleWitnessCosts() {
31 | WitnessBranchReadCost = 0
32 | WitnessChunkReadCost = 0
33 | WitnessBranchWriteCost = 0
34 | WitnessChunkWriteCost = 0
35 | WitnessChunkFillCost = 0
36 | }
37 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/decode_tail_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rlp
18 |
19 | import (
20 | "bytes"
21 | "fmt"
22 | )
23 |
24 | type structWithTail struct {
25 | A, B uint
26 | C []uint `rlp:"tail"`
27 | }
28 |
29 | func ExampleDecode_structTagTail() {
30 | // In this example, the "tail" struct tag is used to decode lists of
31 | // differing length into a struct.
32 | var val structWithTail
33 |
34 | err := Decode(bytes.NewReader([]byte{0xC4, 0x01, 0x02, 0x03, 0x04}), &val)
35 | fmt.Printf("with 4 elements: err=%v val=%v\n", err, val)
36 |
37 | err = Decode(bytes.NewReader([]byte{0xC6, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}), &val)
38 | fmt.Printf("with 6 elements: err=%v val=%v\n", err, val)
39 |
40 | // Note that at least two list elements must be present to
41 | // fill fields A and B:
42 | err = Decode(bytes.NewReader([]byte{0xC1, 0x01}), &val)
43 | fmt.Printf("with 1 element: err=%q\n", err)
44 |
45 | // Output:
46 | // with 4 elements: err= val={1 2 [3 4]}
47 | // with 6 elements: err= val={1 2 [3 4 5 6]}
48 | // with 1 element: err="rlp: too few elements for rlp.structWithTail"
49 | }
50 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/encbuffer_example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rlp_test
18 |
19 | import (
20 | "bytes"
21 | "fmt"
22 |
23 | "github.com/0xsequence/ethkit/go-ethereum/rlp"
24 | )
25 |
26 | func ExampleEncoderBuffer() {
27 | var w bytes.Buffer
28 |
29 | // Encode [4, [5, 6]] to w.
30 | buf := rlp.NewEncoderBuffer(&w)
31 | l1 := buf.List()
32 | buf.WriteUint64(4)
33 | l2 := buf.List()
34 | buf.WriteUint64(5)
35 | buf.WriteUint64(6)
36 | buf.ListEnd(l2)
37 | buf.ListEnd(l1)
38 |
39 | if err := buf.Flush(); err != nil {
40 | panic(err)
41 | }
42 | fmt.Printf("%X\n", w.Bytes())
43 | // Output:
44 | // C404C20506
45 | }
46 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/encoder_example_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rlp_test
18 |
19 | import (
20 | "fmt"
21 | "io"
22 |
23 | "github.com/0xsequence/ethkit/go-ethereum/rlp"
24 | )
25 |
26 | type MyCoolType struct {
27 | Name string
28 | a, b uint
29 | }
30 |
31 | // EncodeRLP writes x as RLP list [a, b] that omits the Name field.
32 | func (x *MyCoolType) EncodeRLP(w io.Writer) (err error) {
33 | return rlp.Encode(w, []uint{x.a, x.b})
34 | }
35 |
36 | func ExampleEncoder() {
37 | var t *MyCoolType // t is nil pointer to MyCoolType
38 | bytes, _ := rlp.EncodeToBytes(t)
39 | fmt.Printf("%v → %X\n", t, bytes)
40 |
41 | t = &MyCoolType{Name: "foobar", a: 5, b: 6}
42 | bytes, _ = rlp.EncodeToBytes(t)
43 | fmt.Printf("%v → %X\n", t, bytes)
44 |
45 | // Output:
46 | // → C0
47 | // &{foobar 5 6} → C20506
48 | }
49 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/iterator.go:
--------------------------------------------------------------------------------
1 | // Copyright 2020 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rlp
18 |
19 | type listIterator struct {
20 | data []byte
21 | next []byte
22 | err error
23 | }
24 |
25 | // NewListIterator creates an iterator for the (list) represented by data
26 | func NewListIterator(data RawValue) (*listIterator, error) {
27 | k, t, c, err := readKind(data)
28 | if err != nil {
29 | return nil, err
30 | }
31 | if k != List {
32 | return nil, ErrExpectedList
33 | }
34 | it := &listIterator{
35 | data: data[t : t+c],
36 | }
37 | return it, nil
38 | }
39 |
40 | // Next forwards the iterator one step, returns true if it was not at end yet
41 | func (it *listIterator) Next() bool {
42 | if len(it.data) == 0 {
43 | return false
44 | }
45 | _, t, c, err := readKind(it.data)
46 | it.next = it.data[:t+c]
47 | it.data = it.data[t+c:]
48 | it.err = err
49 | return true
50 | }
51 |
52 | // Value returns the current value
53 | func (it *listIterator) Value() []byte {
54 | return it.next
55 | }
56 |
57 | func (it *listIterator) Err() error {
58 | return it.err
59 | }
60 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/bigint.in.txt:
--------------------------------------------------------------------------------
1 | // -*- mode: go -*-
2 |
3 | package test
4 |
5 | import "math/big"
6 |
7 | type Test struct {
8 | Int *big.Int
9 | IntNoPtr big.Int
10 | }
11 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/bigint.out.txt:
--------------------------------------------------------------------------------
1 | package test
2 |
3 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
4 | import "io"
5 |
6 | func (obj *Test) EncodeRLP(_w io.Writer) error {
7 | w := rlp.NewEncoderBuffer(_w)
8 | _tmp0 := w.List()
9 | if obj.Int == nil {
10 | w.Write(rlp.EmptyString)
11 | } else {
12 | if obj.Int.Sign() == -1 {
13 | return rlp.ErrNegativeBigInt
14 | }
15 | w.WriteBigInt(obj.Int)
16 | }
17 | if obj.IntNoPtr.Sign() == -1 {
18 | return rlp.ErrNegativeBigInt
19 | }
20 | w.WriteBigInt(&obj.IntNoPtr)
21 | w.ListEnd(_tmp0)
22 | return w.Flush()
23 | }
24 |
25 | func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
26 | var _tmp0 Test
27 | {
28 | if _, err := dec.List(); err != nil {
29 | return err
30 | }
31 | // Int:
32 | _tmp1, err := dec.BigInt()
33 | if err != nil {
34 | return err
35 | }
36 | _tmp0.Int = _tmp1
37 | // IntNoPtr:
38 | _tmp2, err := dec.BigInt()
39 | if err != nil {
40 | return err
41 | }
42 | _tmp0.IntNoPtr = (*_tmp2)
43 | if err := dec.ListEnd(); err != nil {
44 | return err
45 | }
46 | }
47 | *obj = _tmp0
48 | return nil
49 | }
50 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/nil.in.txt:
--------------------------------------------------------------------------------
1 | // -*- mode: go -*-
2 |
3 | package test
4 |
5 | type Aux struct{
6 | A uint32
7 | }
8 |
9 | type Test struct{
10 | Uint8 *byte `rlp:"nil"`
11 | Uint8List *byte `rlp:"nilList"`
12 |
13 | Uint32 *uint32 `rlp:"nil"`
14 | Uint32List *uint32 `rlp:"nilList"`
15 |
16 | Uint64 *uint64 `rlp:"nil"`
17 | Uint64List *uint64 `rlp:"nilList"`
18 |
19 | String *string `rlp:"nil"`
20 | StringList *string `rlp:"nilList"`
21 |
22 | ByteArray *[3]byte `rlp:"nil"`
23 | ByteArrayList *[3]byte `rlp:"nilList"`
24 |
25 | ByteSlice *[]byte `rlp:"nil"`
26 | ByteSliceList *[]byte `rlp:"nilList"`
27 |
28 | Struct *Aux `rlp:"nil"`
29 | StructString *Aux `rlp:"nilString"`
30 | }
31 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/optional.in.txt:
--------------------------------------------------------------------------------
1 | // -*- mode: go -*-
2 |
3 | package test
4 |
5 | type Aux struct {
6 | A uint64
7 | }
8 |
9 | type Test struct {
10 | Uint64 uint64 `rlp:"optional"`
11 | Pointer *uint64 `rlp:"optional"`
12 | String string `rlp:"optional"`
13 | Slice []uint64 `rlp:"optional"`
14 | Array [3]byte `rlp:"optional"`
15 | NamedStruct Aux `rlp:"optional"`
16 | AnonStruct struct{ A string } `rlp:"optional"`
17 | }
18 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/rawvalue.in.txt:
--------------------------------------------------------------------------------
1 | // -*- mode: go -*-
2 |
3 | package test
4 |
5 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
6 |
7 | type Test struct {
8 | RawValue rlp.RawValue
9 | PointerToRawValue *rlp.RawValue
10 | SliceOfRawValue []rlp.RawValue
11 | }
12 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/rawvalue.out.txt:
--------------------------------------------------------------------------------
1 | package test
2 |
3 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
4 | import "io"
5 |
6 | func (obj *Test) EncodeRLP(_w io.Writer) error {
7 | w := rlp.NewEncoderBuffer(_w)
8 | _tmp0 := w.List()
9 | w.Write(obj.RawValue)
10 | if obj.PointerToRawValue == nil {
11 | w.Write([]byte{0x80})
12 | } else {
13 | w.Write((*obj.PointerToRawValue))
14 | }
15 | _tmp1 := w.List()
16 | for _, _tmp2 := range obj.SliceOfRawValue {
17 | w.Write(_tmp2)
18 | }
19 | w.ListEnd(_tmp1)
20 | w.ListEnd(_tmp0)
21 | return w.Flush()
22 | }
23 |
24 | func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
25 | var _tmp0 Test
26 | {
27 | if _, err := dec.List(); err != nil {
28 | return err
29 | }
30 | // RawValue:
31 | _tmp1, err := dec.Raw()
32 | if err != nil {
33 | return err
34 | }
35 | _tmp0.RawValue = _tmp1
36 | // PointerToRawValue:
37 | _tmp2, err := dec.Raw()
38 | if err != nil {
39 | return err
40 | }
41 | _tmp0.PointerToRawValue = &_tmp2
42 | // SliceOfRawValue:
43 | var _tmp3 []rlp.RawValue
44 | if _, err := dec.List(); err != nil {
45 | return err
46 | }
47 | for dec.MoreDataInList() {
48 | _tmp4, err := dec.Raw()
49 | if err != nil {
50 | return err
51 | }
52 | _tmp3 = append(_tmp3, _tmp4)
53 | }
54 | if err := dec.ListEnd(); err != nil {
55 | return err
56 | }
57 | _tmp0.SliceOfRawValue = _tmp3
58 | if err := dec.ListEnd(); err != nil {
59 | return err
60 | }
61 | }
62 | *obj = _tmp0
63 | return nil
64 | }
65 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/uint256.in.txt:
--------------------------------------------------------------------------------
1 | // -*- mode: go -*-
2 |
3 | package test
4 |
5 | import "github.com/holiman/uint256"
6 |
7 | type Test struct {
8 | Int *uint256.Int
9 | IntNoPtr uint256.Int
10 | }
11 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/uint256.out.txt:
--------------------------------------------------------------------------------
1 | package test
2 |
3 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
4 | import "github.com/holiman/uint256"
5 | import "io"
6 |
7 | func (obj *Test) EncodeRLP(_w io.Writer) error {
8 | w := rlp.NewEncoderBuffer(_w)
9 | _tmp0 := w.List()
10 | if obj.Int == nil {
11 | w.Write(rlp.EmptyString)
12 | } else {
13 | w.WriteUint256(obj.Int)
14 | }
15 | w.WriteUint256(&obj.IntNoPtr)
16 | w.ListEnd(_tmp0)
17 | return w.Flush()
18 | }
19 |
20 | func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
21 | var _tmp0 Test
22 | {
23 | if _, err := dec.List(); err != nil {
24 | return err
25 | }
26 | // Int:
27 | var _tmp1 uint256.Int
28 | if err := dec.ReadUint256(&_tmp1); err != nil {
29 | return err
30 | }
31 | _tmp0.Int = &_tmp1
32 | // IntNoPtr:
33 | var _tmp2 uint256.Int
34 | if err := dec.ReadUint256(&_tmp2); err != nil {
35 | return err
36 | }
37 | _tmp0.IntNoPtr = _tmp2
38 | if err := dec.ListEnd(); err != nil {
39 | return err
40 | }
41 | }
42 | *obj = _tmp0
43 | return nil
44 | }
45 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/uints.in.txt:
--------------------------------------------------------------------------------
1 | // -*- mode: go -*-
2 |
3 | package test
4 |
5 | type Test struct{
6 | A uint8
7 | B uint16
8 | C uint32
9 | D uint64
10 | }
11 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/rlpgen/testdata/uints.out.txt:
--------------------------------------------------------------------------------
1 | package test
2 |
3 | import "github.com/0xsequence/ethkit/go-ethereum/rlp"
4 | import "io"
5 |
6 | func (obj *Test) EncodeRLP(_w io.Writer) error {
7 | w := rlp.NewEncoderBuffer(_w)
8 | _tmp0 := w.List()
9 | w.WriteUint64(uint64(obj.A))
10 | w.WriteUint64(uint64(obj.B))
11 | w.WriteUint64(uint64(obj.C))
12 | w.WriteUint64(obj.D)
13 | w.ListEnd(_tmp0)
14 | return w.Flush()
15 | }
16 |
17 | func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
18 | var _tmp0 Test
19 | {
20 | if _, err := dec.List(); err != nil {
21 | return err
22 | }
23 | // A:
24 | _tmp1, err := dec.Uint8()
25 | if err != nil {
26 | return err
27 | }
28 | _tmp0.A = _tmp1
29 | // B:
30 | _tmp2, err := dec.Uint16()
31 | if err != nil {
32 | return err
33 | }
34 | _tmp0.B = _tmp2
35 | // C:
36 | _tmp3, err := dec.Uint32()
37 | if err != nil {
38 | return err
39 | }
40 | _tmp0.C = _tmp3
41 | // D:
42 | _tmp4, err := dec.Uint64()
43 | if err != nil {
44 | return err
45 | }
46 | _tmp0.D = _tmp4
47 | if err := dec.ListEnd(); err != nil {
48 | return err
49 | }
50 | }
51 | *obj = _tmp0
52 | return nil
53 | }
54 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/safe.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | //go:build nacl || js || !cgo
18 | // +build nacl js !cgo
19 |
20 | package rlp
21 |
22 | import "reflect"
23 |
24 | // byteArrayBytes returns a slice of the byte array v.
25 | func byteArrayBytes(v reflect.Value, length int) []byte {
26 | return v.Slice(0, length).Bytes()
27 | }
28 |
--------------------------------------------------------------------------------
/go-ethereum/rlp/unsafe.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | //go:build !nacl && !js && cgo
18 | // +build !nacl,!js,cgo
19 |
20 | package rlp
21 |
22 | import (
23 | "reflect"
24 | "unsafe"
25 | )
26 |
27 | // byteArrayBytes returns a slice of the byte array v.
28 | func byteArrayBytes(v reflect.Value, length int) []byte {
29 | return unsafe.Slice((*byte)(unsafe.Pointer(v.UnsafeAddr())), length)
30 | }
31 |
--------------------------------------------------------------------------------
/go-ethereum/rpc/client_opt_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rpc_test
18 |
19 | import (
20 | "context"
21 | "net/http"
22 | "time"
23 |
24 | "github.com/0xsequence/ethkit/go-ethereum/rpc"
25 | )
26 |
27 | // This example configures a HTTP-based RPC client with two options - one setting the
28 | // overall request timeout, the other adding a custom HTTP header to all requests.
29 | func ExampleDialOptions() {
30 | tokenHeader := rpc.WithHeader("x-token", "foo")
31 | httpClient := rpc.WithHTTPClient(&http.Client{
32 | Timeout: 10 * time.Second,
33 | })
34 |
35 | ctx := context.Background()
36 | c, err := rpc.DialOptions(ctx, "http://rpc.example.com", httpClient, tokenHeader)
37 | if err != nil {
38 | panic(err)
39 | }
40 | c.Close()
41 | }
42 |
--------------------------------------------------------------------------------
/go-ethereum/rpc/context_headers.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rpc
18 |
19 | import (
20 | "context"
21 | "net/http"
22 | )
23 |
24 | type mdHeaderKey struct{}
25 |
26 | // NewContextWithHeaders wraps the given context, adding HTTP headers. These headers will
27 | // be applied by Client when making a request using the returned context.
28 | func NewContextWithHeaders(ctx context.Context, h http.Header) context.Context {
29 | if len(h) == 0 {
30 | // This check ensures the header map set in context will never be nil.
31 | return ctx
32 | }
33 |
34 | var ctxh http.Header
35 | prev, ok := ctx.Value(mdHeaderKey{}).(http.Header)
36 | if ok {
37 | ctxh = setHeaders(prev.Clone(), h)
38 | } else {
39 | ctxh = h.Clone()
40 | }
41 | return context.WithValue(ctx, mdHeaderKey{}, ctxh)
42 | }
43 |
44 | // headersFromContext is used to extract http.Header from context.
45 | func headersFromContext(ctx context.Context) http.Header {
46 | source, _ := ctx.Value(mdHeaderKey{}).(http.Header)
47 | return source
48 | }
49 |
50 | // setHeaders sets all headers from src in dst.
51 | func setHeaders(dst http.Header, src http.Header) http.Header {
52 | for key, values := range src {
53 | dst[http.CanonicalHeaderKey(key)] = values
54 | }
55 | return dst
56 | }
57 |
--------------------------------------------------------------------------------
/go-ethereum/rpc/ipc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | package rpc
18 |
19 | import (
20 | "context"
21 | )
22 |
23 | // DialIPC create a new IPC client that connects to the given endpoint. On Unix it assumes
24 | // the endpoint is the full path to a unix socket, and Windows the endpoint is an
25 | // identifier for a named pipe.
26 | //
27 | // The context is used for the initial connection establishment. It does not
28 | // affect subsequent interactions with the client.
29 | func DialIPC(ctx context.Context, endpoint string) (*Client, error) {
30 | cfg := new(clientConfig)
31 | return newClient(ctx, cfg, newClientTransportIPC(endpoint))
32 | }
33 |
34 | func newClientTransportIPC(endpoint string) reconnectFunc {
35 | return func(ctx context.Context) (ServerCodec, error) {
36 | conn, err := newIPCConnection(ctx, endpoint)
37 | if err != nil {
38 | return nil, err
39 | }
40 | return NewCodec(conn), err
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/go-ethereum/rpc/ipc_js.go:
--------------------------------------------------------------------------------
1 | // Copyright 2018 The go-ethereum Authors
2 | // This file is part of the go-ethereum library.
3 | //
4 | // The go-ethereum library is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU Lesser General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 | //
9 | // The go-ethereum library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU Lesser General Public License for more details.
13 | //
14 | // You should have received a copy of the GNU Lesser General Public License
15 | // along with the go-ethereum library. If not, see .
16 |
17 | //go:build js
18 | // +build js
19 |
20 | package rpc
21 |
22 | import (
23 | "context"
24 | "errors"
25 | "net"
26 | )
27 |
28 | var errNotSupported = errors.New("rpc: not supported")
29 |
30 | // ipcListen will create a named pipe on the given endpoint.
31 | func ipcListen(endpoint string) (net.Listener, error) {
32 | return nil, errNotSupported
33 | }
34 |
35 | // newIPCConnection will connect to a named pipe with the given endpoint as name.
36 | func newIPCConnection(ctx context.Context, endpoint string) (net.Conn, error) {
37 | return nil, errNotSupported
38 | }
39 |
--------------------------------------------------------------------------------
/types.go:
--------------------------------------------------------------------------------
1 | package ethkit
2 |
3 | import "github.com/0xsequence/ethkit/go-ethereum/common"
4 |
5 | type Address = common.Address
6 |
7 | type Hash = common.Hash
8 |
9 | const HashLength = common.HashLength
10 |
11 | func ToPtr[T any](v T) *T {
12 | return &v
13 | }
14 |
15 | func ToSlicePtrs[T any](in []T) []*T {
16 | out := make([]*T, len(in))
17 | for i := range in {
18 | out[i] = &in[i]
19 | }
20 | return out
21 | }
22 |
23 | func ToSliceValues[T any](in []*T) []T {
24 | out := make([]T, len(in))
25 | for i := range in {
26 | out[i] = *in[i]
27 | }
28 | return out
29 | }
30 |
--------------------------------------------------------------------------------
/util/alerter.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import "context"
4 |
5 | type Alerter interface {
6 | Alert(ctx context.Context, format string, v ...interface{})
7 | }
8 |
9 | func NoopAlerter() Alerter {
10 | return noopAlerter{}
11 | }
12 |
13 | type noopAlerter struct{}
14 |
15 | func (noopAlerter) Alert(ctx context.Context, format string, v ...interface{}) {}
16 |
--------------------------------------------------------------------------------
/util/testing.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "os"
7 | )
8 |
9 | func ReadTestConfig(testConfigFile string) (map[string]string, error) {
10 | config := map[string]string{}
11 |
12 | _, err := os.Stat(testConfigFile)
13 | if err != nil {
14 | return config, nil
15 | }
16 |
17 | data, err := os.ReadFile(testConfigFile)
18 | if err != nil {
19 | return nil, fmt.Errorf("%s file could not be read", testConfigFile)
20 | }
21 |
22 | err = json.Unmarshal(data, &config)
23 | if err != nil {
24 | return nil, fmt.Errorf("%s file json parsing error", testConfigFile)
25 | }
26 |
27 | return config, nil
28 | }
29 |
--------------------------------------------------------------------------------