{"id":13673957,"url":"https://github.com/androlo/standard-contracts","last_synced_at":"2025-04-15T16:29:52.868Z","repository":{"id":57365942,"uuid":"57780831","full_name":"androlo/standard-contracts","owner":"androlo","description":"Storage repo for Solidity contracts, tests, and docs.","archived":false,"fork":false,"pushed_at":"2019-11-18T13:06:05.000Z","size":143,"stargazers_count":98,"open_issues_count":8,"forks_count":25,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-15T16:29:42.455Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/androlo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-01T19:51:34.000Z","updated_at":"2024-08-21T13:29:02.000Z","dependencies_parsed_at":"2022-08-23T19:01:01.175Z","dependency_job_id":null,"html_url":"https://github.com/androlo/standard-contracts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androlo%2Fstandard-contracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androlo%2Fstandard-contracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androlo%2Fstandard-contracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/androlo%2Fstandard-contracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/androlo","download_url":"https://codeload.github.com/androlo/standard-contracts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249107905,"owners_count":21213941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T11:00:32.125Z","updated_at":"2025-04-15T16:29:52.849Z","avatar_url":"https://github.com/androlo.png","language":"JavaScript","funding_links":[],"categories":["Solidity","Libraries","JavaScript"],"sub_categories":[],"readme":"# Solidity contracts (Beta)\n\nThis repository has a number of Solidity contracts in it. Some of these contracts will potentially make it into an official Solidity standard library.\n\nContract imports uses the github path, so can be imported into the online compiler, or the repo can be cloned and contract compiled locally using solc's path re-mapping features.\n\nShort descriptions of contracts and methods can be found in this README, as well as some examples. More detailed documentation can be found in the contracts themselves.\n\n**Warning: All the code in here is still in development, and should be considered unreliable. Do not deploy any of this code onto a public node and use it in production.**\n\n**This is also a personal side project with no deadlines or dev plan.**\n\n## Table of Content\n\n- [Grading](#grading)\n- [Tests and Validation](#tests-and-validation)\n- [Bits](#bits)\n  - [BitOps](#bitops)\n- [Bytes](#bytes)\n  - [ByteSlice](#byteslice)\n- [Codec](#codec)\n  - [RLP](#rlp)\n  - [ECCConversion](#eccconversion)\n- [Crypto](#crypto)\n  - [Curve](#curve)\n  - [ECCMath](#eccmath)\n  - [Secp256k1](#secp256k1)\n  - [Secp256k1curve](#secp256k1curve)\n\n## Grading\n\nThere is a system of grades for contracts. Grades are found along with the version in contract descriptions. They are temporary and will be changed when the library is stable (new contracts will be developed on separate branches then).\n\nGenerally speaking, contracts with a grade less then `3` should not be used, and those less then `5` should only be used when testing.\n\n#### Grades\n\n1. (`Incomplete`) Contract is incomplete; code is still being added.\n\n2. (`Draft`) First draft is complete, and contract is being tested.\n\n3. (`Tested`) Unit-tests are written, and contract has been debugged.\n\n4. (`Optimized`) Contract has been optimized.\n\n5. (`Stable`) Contract is production ready.\n\n## Tests and validation\n\nThe tests are done over RPC calls from Node.js, using `web3` - the official Ethereum JavaScript API. They require a running development node. Any Ethereum client should work in theory, but the tests has only been run against a `geth` node.\n\nLatest compilation and testing was done using: `0.3.4-7dab8902/Release-Emscripten/clang/Interpreter`\n\n### Running\n\nTo run tests, cd into the project root and type:\n\n`npm install`\n\nStart an ethereum development node, for example using the `-dev` flag with `geth` (not a testnet node). The tests assumes that an Ethereum node will answer to RPC calls on port `8545`. It will automatically use the first account in the accounts list (`accounts[0]`) as sender. Some test contracts require a lot of gas, so you may have to crank up the gas limit and make sure the active account has a lot of gas.\n\nWhen all is set up, run: `mocha integration_tests`\n\n#### Test data\n\nTest-data is sometimes generated using [Sage 7.0](http://www.sagemath.org/). The generation scripts are normally included so that the process can be replicated.\n\n#### Note on optimization, inline assembly\n\nThe contracts will not be fully optimized until it's clear how formal verification will work, since that is a requirement for many of these contracts. Assembly might be removed from some contracts and functions.\n\n## Bits\n\nContracts for working with bits.\n\n### BitOps\n\n#### Version 1.0\n\n#### Status: Optimized\n\n`Bits` is a library with methods for reading, writing, and manipulating individual or groups of bits. The methods operates on `uint` variables.\n\n#### Examples\n\n```\nuint u = 10;\n\n/* Get the bit at the given index (0 to 255 inclusive) */\nu.bit(0) // 0 (1)\nu.bit(1) // 1 (2)\nu.bit(2) // 0 (4)\nu.bit(3) // 1 (8)\n\n/* Check if a bit is set */\nu.bitSet(0) // false\nu.bitSet(3) // true\n\n/* Set the bit at the given index */\nu = u.setBit(2) // u = 14\n\n/* bitsSet(i, len) checks if the bits i, i + 1, ... , i + len - 1 are all set */\nu.bitsSet(2, 2) // true  (bits 2 and 3 are both set)\nu.bitsSet(0, 3) // false (bit 0, 1 and 2 are not all set)\n\n/* Toggle a bit */\nu = u.bitToggle(0) // u = 15\n\n/* Clear a bit */\nu = u.bitClear(3) // u = 7\n```\n\nAssuming the indices and lengths are within bounds:\n\n```\nuint(~0).get(i) = 1;\n\nuint u = uint(0).set(i); u == 2**i;\n\nu.bit(i) == u.bits(i, 1); // Same for bitEqual, bitAnd, bitOr, and bitXor.\n\nu.bitEqual(v, i) == (u.bit(i) == v.bit(i))\nu.bitAnd(v, i) == u.bit(i) \u0026 v.bit(i) // etc.\n\nu.bitsEqual(v, i, len) == (u.bits(i, len) == v.bits(i, len)) // Same as above.\n```\n\n## Bytes\n\nContracts used for working with bytes.\n\n### ByteSlice\n\n#### Version 1.0\n\n#### Status: Optimized\n\nA `ByteSlice` is created from memory variables of type `bytes`. It is possible to slice slices, access bytes by index, and to extract a `bytes` variable from the slice.\n\nSince dynamic arrays and internal types are used in function input and output, this contract is meant to be `extended`. Later it will be possible to use as a library, when some (planned) upgrades has been made to libraries.\n\n##### Usage with `string`\n\nStrings are utf encoded, so it is not safe to just cast a string into bytes or vice versa, unless it is known in advance that it is an ASCII string. Then it is safe.\n\n##### Internals\n\nThe `Slice` struct has two members of type `uint`:\n\n`_unsafe_memPtr` - a pointer to the memory address where the bytes are stored.\n\n`_unsafe_len` - the length (number of bytes).\n\nExtracting the bytes out of a slice is done using the `toBytes` function, which creates a new `bytes memory` variable, sets its size to `len`, and copies all the bytes from memory address `memPtr` to `memPtr + len - 1` into the new variable.\n\n#### examples\n\n```\nbytes memory bts = \"abcdefg\"; // Create a new 'bytes' variable in memory.\n\n\n/* Slicing bytes */\n\nvar s = bts.slice(); // Create a slice on \"abcdefg\".\n\nvar sa = bts.slice(uint(2)); // Create a slice on \"cdefg\"\n\nvar sb = bts.slice(-3); // Create a slice on \"efg\"\n\nvar sc = bts.slice(uint(1), 2); // Create a slice on \"b\"\n\n/* Slicing slices */\n\nvar sCopy = s.slice(); // slice on \"abcdefg\"\n\nvar s2 = s.slice(uint(5)); // slice on \"fg\"\n\nvar s3 = s.slice(uint(5), 6); // slice on \"f\"\n\nvar s4 = s.slice(-2); // slice on \"fg\"\n\nvar s5 = s.slice(-4, -1); // slice on \"def\"\n\nvar s6 = s5.slice(uint(1), 2); // slice on \"e\"\n\nvar sEmpt = s.slice(uint(7), 7); // The empty slice.\n\nvar sEmpt2 = (new bytes(0)).slice(); // The empty slice.\n\nvar sWillThrow = s.slice(uint(9));\n\nvar sWillThrowToo = s.slice(uint(0), 8);\n\n\n/* length */\n\nvar len = s.len(); // 7\n\nvar len2 = s2.len(); // 2\n\nvar len3 = sEmpt.len(); // 0\n\n\n/* Index access */\n\nvar b = s.at(uint(2)); // 'c'\n\nvar b2 = s.at(-2); // 'f'\n\nvar bWillThrow = s.at(uint(7)); // Index out of bounds.\n\ns.set(uint(2), 'x'); // s.at(uint(2)) == 'x'\n\ns.set(-2, 'y'); // s.at(-2) == s.at(uint(4)) == 'y'\n\ns.set(uint(7), 'z'); // Will throw\n\n\n/* Converting to 'bytes memory' */\n\nvar bts2 = s.toBytes(); // \"abcdefg\". Copies 7 bytes.\n\nvar bts3 = s.slice(-2).toBytes(); // \"fg\". Copies 2 bytes.\n\n/* Equals */\n\nvar eq = s.equal(s); // true\n\ns.equal(sEmpt); // false\n\ndelete s;\n\ns.equal(sEmpt); // true\n```\n\n## Codec\n\nContracts used for various different types of encoding and decoding.\n\n- [RLP](#rlp)\n- [ECCConversion](#eccconversion)\n\n### RLP\n\n#### Version 2.0\n\n#### Status: Tested\n\nUsed to parse and decode RLP encoded data. The encoded bytes is converted into an `RLPItem` which keeps track of the bytes in memory, and has methods for decoding and extracting new items from lists.\n\nWorking with items will never copy any of the raw RLP encoded bytes; only new `RLPItem`s and `Iterator`s. Those are both simple items that takes 2 and 3 words of memory space.\n\nDecoding an item into a reference type (i.e. `bytes` or `string`) will copy the required bytes, so use with care.\n\nEncoding is not (yet) supported.\n\n#### Examples\n\n```\nbytes memory data; // input\n\n/* data = \"0x880102030405060708\" */\n\nvar itm = data.toRLPItem(); // Create a new RLP Item\n\nitem.isData(); // true\n\nitem.isList(); // false\n\nitem.items(); // 0\n\nitem.toBytes(); // \"0x880102030405060708\" - the raw RLP-encoded bytes.\n\nitem.toData(); // \"0x0102030405060708\" - The data.\n\n/* data = \"0x11\" */\n\nvar itm = data.toRLPItem();\n\nuint u = itm.toUint(); // 17\n\naddress a = itm.toAddress(); // 0x0000000000000000000000000000000000000011\n\n/* data = \"0x80\" */\n\nvar itm = data.toRLPItem();\n\nitm.isEmpty(); // false\n\nitm.isData(); // true\n\n/* data = \"0x01\" */\n\nvar itm = data.toRLPItem();\n\nitm.toBool(); // True\n\n// This is the RLP encoding of [[1, 2], 1, [1, 2, 3]]\n/* data = \"0xC8C2010201C3010203\" */\n\nvar itm = rlpList.toRLPItem();\n\nitm.isList(); // true\n\nitm.items(); // 3\n\nitm.toList(); // RLPItem[] of length 3 (one for each list-item)\n\n// Using iterators.\n\nvar subItm = itm.iterator().next(); // RLPItem for [1, 2]\n\nvar it2 = subItem.iterator();\n\nwhile(it2.hasNext())\n    it2.next().toUint() // 1, 2\n\nit2.next(); // will throw\n\n/* data = \"0x\" */\n\nvar itm = nullBts.toRLPItem();\n\nitm.isNull(); // true\n\nitm.isData(); // false\n\nitm.isList(); // false\n\nitm.isEmpty() // false\n\n// Strict mode (costs more, but useful when RLP data may be malformed).\n\n/* data = \"0x81\" */\n\nvar itm = data.toRLPItem(true); // will throw\n\n/* data = \"0x8101\" */\n\nvar itm = data.toRLPItem(true); // will throw\n\n/* data = \"0xC211 */\n\nvar itm = data.toRLPItem(true); // will throw\n\n```\n\n### ECCConversion\n\n#### Version 1.0\n\n#### Status: Draft\n\nUsed to convert ECC data between different formats.\n\n## Crypto\n\nContracts used for cryptographic operations.\n\nHashing primitives are not implemented, because Solidity already [provide some](http://solidity.readthedocs.io/en/latest/units-and-global-variables.html#mathematical-and-cryptographic-functions).\n\n**Warning: Crypto operations can be very expensive, so should not be done on the public chain. This includes the ECC math functions as well.**\n\n- [Curve](#curve)\n- [ECCMath](#eccmath)\n- [Secp256k1](#secp256k1)\n- [Secp256k1curve](#secp256k1curve)\n\n### Curve\n\n#### Version 1.0\n\n#### Status: Stable\n\nCurve is an interface for elliptic curves. The cryptographic properties (e.g. defined over finite fields) of these curves are implied.\n\nThe only functions that may be implemented are those that does not involve passing a private key to the contract, meaning functions like 'sign' and 'private-to-public' are not included. There is also no public key recovery function in the interface yet, because there is a built in function for secp256k1 (and for some other reasons).\n\nThe contracts use the mathematical representations of coordinates and points, and is thus key-format agnostic. Contracts that require keys to be encoded in a particular way would manage the encoding/decoding themselves; and delegate the actual curve operations to whatever implementation is used (only `secp256k1` is provided at this point).\n\nDetails can be found here:\n\n[SEC 1: Elliptic Curve Cryptography, Version 2.0](http://www.secg.org/sec1-v2.pdf)\n\n[SEC 2: Recommended Elliptic Curve Domain Parameters, Version 2.0](http://www.secg.org/sec2-v2.pdf)\n\n[Lower-s signatures](https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#low-s-values-in-signatures) (requirement for homestead signatures).\n\n#### onCurve\n\nCheck if a point `P` (given in affine coordinates) is on the curve.\n\n#### isPubKey\n\nCheck if a point `P` (given in affine coordinates) is a valid public key.\n\n#### compress\n\nGet the compressed form of a point `Q = (Qx, Qy)`, `C(Q) = (Qx, Qy % 2)`.\n\n#### decompress\n\nFor a given `Px` and a `yBit = Py % 2`, returns the point `P = (Px, Py)`.\n\n#### validateSignature\n\nValidate the signature `(r, s)` of a 32 byte hash `msg` against a public key `Q`. Returns `true` if the signature is valid. Will only validate signatures on lower-s form.\n\n### ECCMath\n\n#### Version 1.0\n\n#### Status: Optimized\n\nMath helper. Naming is trying to be consistent with similar solidity functions, e.g. 'invmod' and 'expmod' is like 'addmod', 'mulmod', etc.\n\n#### invmod\n\n`uint x = invmod(uint a, uint p)` is used to compute the modular inverse `ax = 1 (mod p)`.\n\nConstraints: `a` and `p` must be coprime.\n\nUses the euclidean algorithm to find the modular inverse.\n\n#### expmod\n\n`uint x = expmod(b, e, m)` is used to compute the number `b**e % m`\n\nThe function is a Solidity adaptation of the exponentiation formula found in the [Serpent examples](https://github.com/ethereum/serpent/blob/develop/examples/ecc/modexp.se).\n\n#### toZ1\n\nUsed internally to transform an arbitrary (Jacobian) point `P = (Px, Py, Pz)` to `P' = (Px', Py', 1)`. `(Px, Py)` is the affine coordinates. The second variety (with 4 parameters) is used in `mul` during the Montgomery inversion.\n\n### Secp256k1\n\n#### Version 1.0\n\n#### Status: Optimized\n\nLibrary functions for the `secp256k1` curve. Includes internal versions of the `Curve` functions but also a number of internal functions for doing point arithmetic.\n\nThe output of all function is in Jacobian coordinates.\n\nNOTE: You may notice weird arrays and other types where it looks as if they shouldn't be needed. That's mainly to work around the stack item limitations and some optimizer issues. This is a problem, and I will replace the code gradually as it becomes possible.\n\n#### add\n\nPoint-addition of two points `P` and `Q`. Both input points must be expressed in Jacobian coordinates.\n\n#### addMixed\n\nSame as `add` except the second point is expressed in affine coordinates.\n\n#### addMixedM\n\nSame as `addMixed` but mutates the first point rather then creating a new one.\n\n#### double\n\nDoubles a point `P`. The point must be expressed in Jacobian coordinates.\n\n#### doubleM\n\nSame as `double` but mutates the point.\n\n#### mul\n\nMultiplication of a scalar `d` and a point `P`. The point must be expressed in affine coordinates.\n\n### Secp256k1Curve\n\n#### Version 1.0\n\n#### Status: Optimized\n\nImplementation of `Curve` based on the `secp256k1` library.\n\n### Tests\n\nKeys generated using OpenSSL.\n\nThe ephemeral `k` values used for signatures are just random numbers between 1 and `n - 1` (inclusive), where `n` is the order of the generator point.\n\nTo generate the test signatures from `k`, the following Sagemath script was used:\n\n```\n# ('k', 'private key')\nks = [\n    (0xb578a05106a1e1975d2082add46aad13d76e3ce3b9d2dcabc5f651c9a29fa822, 0x2569d5e120b10d696933074eecb9182719fb3a89b7714bc99037d8416b391436),\n    (0x7a12fac8796af10ce7dbfc68271d87ca685950a27ab4222c8b720210fe2c21c5, 0xe370174cb9fea3b5c1ef39bcdf36d321cefb06e0e8a6cb856e1bb3e9be3c4385),\n    (0x13018a36dc981d6ef697ebcb809dc8966773748284281f2338752d2a889fc798, 0xa5378a4c6db7a076af65cd728f6fe3cf59f416a3d8f74b31b0d76f666a868d09),\n    (0x534813f6aded11b19e45ffc3cd77841783f2928ddd427d4e793808f476c305dd, 0x40a62a62984797e129b9f84fb0202a10c37b52ad83da2d4f3f11c6a8587999f6),\n    (0xa2d19750e168a6faf9f6b406ed2484f990e90bca4c139d6a8a5d298a687286b2, 0x32e3506d0cf7c8e73c5692f67e6b4c2377a5c0728b4719ff948f420609a3bcdf),\n    (0x4bb2d83327145d0fa4e5aa9a28dc3d4cdf87cf13cdf6505109d07b770be0559f, 0x1b3c26da0280b299ecfbdc8d9b6e69677094f1c034010a9a27ba482185355ec2),\n    (0x1f7a57c5f5820236e274ec33802a8c9171f76e5a246bbc71c1dc8afcf51d0f33, 0x9a2e734e0057dc4cbbf8418f9e3d7b9a638e121f1e217884579284b802d0fab3),\n    (0xb42ae0689c162dcd8de571a7e5caa2ea24d5336eaeae3e9fbcf6946613165878, 0xb79a54eb34d1a2f75d956f593dbd08fb75d307847838a64aec9adc0ae74c3bb0),\n    (0xc908c6aad4690e029b66333fce8660ccb7b9953890ef566734a67be156f5a2fd, 0xb15b46827e551c12f8bfe066a634aacfd907be42186ec3e4b3d69baf8efa5bde),\n    (0x22a2b8da7df2da2ced4b4b1ab59cd1f877147cad336ff0d2d01384ddac86c38f, 0xd83a52c3d1965d9ace37fde20da4eb4c98184c6cfc8b33b1b0c56be36f3fc5c0),\n    (0x72407c35a1e2db22521847e9e78f5227bccef8243df1462affe4013e437a875b, 0x013263a84e05ca597f3c6cdeae5b33349c618308ac5ef844de0aa5b788d0a3a8),\n    (0x17a332b7124cbf26c4ee6a49d7f68955b23735e4f10acdd27582a653518609b8, 0x6ac0b7ddefa89ca0f129cba3ddda3b4a6e126d43363b4509bd6c9334dd81e0fa),\n    (0x5f87ee0a303eaf5b88c5b84c307194dc896e462fd0242f512ded874fce5a2b25, 0xba87e08dc57311d5518c7d46958f3e647baed528313952cc5cf34e14f3b523af),\n    (0xa3622fc8d2f1dac4d29e0fddc90d2b99b8eb9d13acec78dfeead2e66452122af, 0xd8c21bd40cdd0603666fa5c6199d8058050872913fa0c68feb53fed3df35695e),\n    (0x950a753f782bb0a103359b4d54101df4c06910a72338a5592f2a17f2e5868659, 0x839793d1f796da91096cd1641d06593b6f6c3dadc12e0ccd7eaaf1f10c752c25),\n    (0xe6f0e82e0bed605dcba808164c809a50da65db8b39ef68658c62c32ba715c069, 0x5c745e065ad28124ca941b02abd0ebdb4502d0c70058ddd7dfa9b659165e76a4),\n    (0xe9d62c056727ccca3946a11f8822df06c14e830d36340181de2075146501091e, 0x03eebcbd7958778591670c9d47c09fccd94a6dd05f13ee6b6f5f4d5a640f293c),\n    (0xa4d0c416ee4a8bd8337455e00f9e9d888d644cf9b0db343f0de8521606c14eda, 0xa46f162d79d24ceaf81ef56d118d904067d1e78d9a17ef91f3542183dfb44665)\n]\n\np = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F\nn = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141\nmsg = 0x590910812c6348ea5bb6a5d503200ffee73d337801843b857f74e3b5a6a2229d\nlowSmax = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0\nZZn = Integers(n)\nsecp256k1 = EllipticCurve(FiniteField(p), (0, 7))\nG = secp256k1.point((\n\t0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798,\n\t0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8\n))\n\ndef sign(k, dQ):\n    R = k*G\n    r = ZZn(R[0])\n    s = ZZn((msg + r*dQ)/k)\n    if s \u003e lowSmax:\n        s = n - s\n    return (\"0x\" + format(Integer(r), '064x'), \"0x\" + format(Integer(s), '064x'))\n\n[sign(k, dQ) for (k, dQ) in ks]\n```\n\nScript for generating random curve-points.\n\n```\ntohex = lambda s: \"0x\" + format(Integer(s), '064x')\ntohex3 = lambda (x, y, z): (tohex(x), tohex(y), tohex(z))\nrandpoints = [tohex3(secp256k1.random_point()) for i in range(0, 40)]\n```\n\nScript for calculating sums from randpoints (each element plus the next one).\n\n```\nsums = []\nfor i in range(1, 40):\n    P = secp256k1.point((Integer(randpoints[i - 1][0]), Integer(randpoints[i - 1][1])));\n    Q = secp256k1.point((Integer(randpoints[i][0]), Integer(randpoints[i][1])));\n    sums.append(tohex2(P + Q))\n```\n\nScript for doubling each point.\n\n```\ndbls = []\nfor i in range(0, 40):\n    P = secp256k1.point((Integer(randpoints[i][0]), Integer(randpoints[i][1])));\n    dbls.append(tohex2(P + P))\n```\n\nScript for generating a series of random elements in Z/pZ.\n\n```\nZZp = Integers(p)\nrandints = [tohex(ZZp.random_element()) for i in range(0, 40)]\n```\n\nScript for doing point multiplication of random integers and points.\n\n```\nprods = []\nfor i in range(0, 40):\n    P = secp256k1.point((Integer(randpoints[i][0]), Integer(randpoints[i][1])));\n    prods.append(tohex2(Integer(randints[i]) * P))\n```\n\nScript used to generate some numbers for modular inverse:\n\n```\ntestVals = [\n    (0x56, 0x55),\n    (0x2, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),\n    (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),\n    (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF),\n    (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F)\n\nOutput:\n['0x0000000000000000000000000000000000000000000000000000000000000001',\n '0x8000000000000000000000000000000000000000000000000000000000000000',\n '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe',\n '0x41bce9245fc72552d8c1b4259d8130978376be5acb4a45d8f4d5b4da913e7eb6',\n '0xbe4316dba038daad273e4bda627ecf687c8941a534b5ba270b2a4b24b07e6798']\n]\n\nim = lambda a, p: \"0x\" + format(inverse_mod(a, p), '064x')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrolo%2Fstandard-contracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrolo%2Fstandard-contracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrolo%2Fstandard-contracts/lists"}