This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
library Vote { | |
uint256 constant BITS_PER_CANDIDATE = 5; | |
uint256 constant BITMASK = (2**BITS_PER_CANDIDATE) - 1; | |
// Storage Layout: | |
// Voter (160bit) | size (5bit) | votes (5~90bit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Lottery { | |
// PRICE PER TICKET | |
uint256 constant TICKET_PRICE = (10 ** 18) / 100; // 0.01eth | |
uint256 constant TICKET_OPTIONS = 30; | |
uint256 constant OPTIONS_PER_TICKET = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
library ECDSA { | |
/** | |
* @notice Recovers the address for an ECDSA signature and message hash, | |
* note that the hash must be prefixed with "\x19Ethereum Signed Message:\n{msg.length}" | |
* @return address The address that was used to sign the message | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webcrypto = require('crypto').webcrypto.subtle; | |
const enc = new TextEncoder(); | |
function bytesToBase64url(bytes) { | |
return Buffer.from(bytes).toString('base64url'); | |
} | |
function jsonToBase64url(obj) { | |
const bytes = enc.encode(JSON.stringify(obj)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "dependencies": { | |
// "axios": "^1.3.6" | |
// } | |
const axios = require('axios'); | |
const CLIENT_ID = '<client_id_aqui>'; | |
async function run(token) { | |
console.log(token); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [dependencies] | |
// blake2b_simd = "1.0.1" | |
// num-bigint = "0.4.3" | |
// num-integer = "0.1.45" | |
// num-prime = { version = "0.4.3", features=["num-bigint"] } | |
// num-traits = "0.2.15" | |
use blake2b_simd; | |
use num_bigint::{BigInt, BigUint, Sign}; | |
use num_integer::Integer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
from random import SystemRandom | |
from collections import namedtuple | |
''' | |
FROST: Flexible Round-Optimized Schnorr Threshold Signatures | |
Implementation based in this paper: | |
https://eprint.iacr.org/2020/852.pdf | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
-- requirements.txt | |
bip_utils==2.9.1 | |
mnemonic==0.21 | |
""" | |
from mnemonic import Mnemonic | |
from bip_utils import Bip44, Bip44Changes, Bip44Coins | |
mnemonic = "bottom drive obey lake curtain smoke basket hold race lonely fit walk" | |
passphrase = "password here" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gas efficient SQRT method, computes floor(sqrt(x)). | |
// Constant gas cost of 355 | |
// | |
// For testing use this tool: https://www.evm.codes/playground?fork=cancun | |
// Author: Lohann Ferreira | |
PUSH0 | |
CALLDATALOAD | |
PUSH1 1 | |
DUP2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
/** | |
* Workaround example on how to inject and execute arbitrary bytecode in solidity contract | |
* Currently only YUL supports verbatim: https://github.com/ethereum/solidity/issues/12067 | |
* But you cannot import Solidity code in YUL, or YUL code in solidity, so this workaround is necessary. | |
* It works as long the byte sequence `0x7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F00` appear in the runtime code. | |
* |
OlderNewer