Skip to content

Instantly share code, notes, and snippets.

View DoguD's full-sized avatar
🎯
Focusing

Doğu Deniz Uğur DoguD

🎯
Focusing
View GitHub Profile
@DoguD
DoguD / ChaliceDeployPolicy.json
Created August 28, 2024 14:18
Policy to be used for running `chalice deploy` with Github Actions.
{
"Version": "2024-08-28",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"iam:GetRole",
"logs:DeleteLogGroup",
"apigateway:PUT",
function buy(uint256 tokenId) payable {
require(msg.value >= price, "Payment not enough");
address _currentOwner = ownerOf(tokenId);
_transfer(_currentOwner, msg.sender, tokenId);
bool sent = _currentOwner.send(msg.value);
require(sent, "Failed to send Ether");
}
@DoguD
DoguD / Version2-Dangerous.sol
Created November 15, 2022 08:46
A banking smart contract with a malicious steal function inside.
// contracts/Version1-Safe.sol
pragma solidity ^0.8.0;
interface IERC20 {
function transferFrom(address from, address to, uint256 value) external returns(bool);
function transfer(address to, uint256 value) external returns(bool);
}
contract Bank2 {
@DoguD
DoguD / Version1-Safe.sol
Created November 15, 2022 08:39
A simple bank smart contract.
// contracts/Version1-Safe.sol
pragma solidity ^0.8.0;
interface IERC20 {
function transferFrom(address from, address to, uint256 value) external returns(bool);
function transfer(address to, uint256 value) external returns(bool);
}
contract Bank {
@DoguD
DoguD / pipex.c
Created October 16, 2022 10:37 — forked from aspatic/pipex.c
Multiple pipes in C
/*
** pipex.c - multipipes support
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
/*
* loop over commands by sharing
// SPDX-License-Identifier: MIT
/**
A simple Solidity smart contract which generates a random number between 0 and the desired max number.
Uses two functions to generate the random number:
- First "prepareRandom" should be called. The function will set the "preparationBlockNumber" to the current block number.
- Second "roll" should be called to generate the number. The function generates a random number using the blockhash of the block when "prepareRandom" has been called. This way, as the blockhash of the block can't be know before the "prepareRandom" transaction goes thorugh,
the result of the roll can't be predicted and thus manipulated.
How many times the roll has been called and all the previous results are recorded in the blockchain.
*/
pragma solidity ^0.8.0;
contract RandomNumbers{
// Result varibles
uint256[] public winnerNumbers;
uint256 public rollCount;
function random(uint256 maxNumber) public view returns (uint256) {
/**
Generates a random number between 0 and maxNumber. Uses current block difficulty, timestamp, caller address, and the blockhash of the block when prepareRandom has been called.
Although the output of this function can be precalculated, the manager not knowing the blockhash of the block they called "prepareRandom" makes the system fair.
pragma solidity ^0.8.0;
contract RandomNumbers{
uint256 public preparationBlockNumber;
bool public canCallRandom;
function prepareRandom() public {
/**
When called sets the preparation block number to the current block number.
*/
// Source: https://blog.finxter.com/how-to-generate-random-numbers-in-solidity/
pragma solidity ^0.8.0;
contract RandomNumbers{
function createRandom(uint number) public view returns(uint){
return uint(blockhash(block.number-1)) % number;
}
}
// Source: https://blog.finxter.com/how-to-generate-random-numbers-in-solidity/
pragma solidity ^0.8.0;
contract RandomNumbers{
function random(uint number) public view returns(uint){
return uint(keccak256(abi.encodePacked(block.timestamp,block.difficulty,
msg.sender))) % number;
}
}