Official Golang implementation of the Ethereum protocol.
MiMC7 is mapped to Opcode 0x13.
Detail MiMC protocol : https://eprint.iacr.org/2016/492.pdf
Detail MiMC7 protocol : https://iden3-docs.readthedocs.io/en/latest/_downloads/a04267077fb3fdbf2b608e014706e004/Ed-DSA.pdf
MiMC7 algorithm :
SEED = keccak256("mimc7_seed")
ORDER = 21888242871839275222246405745257275088548364400416034343698204186575808495617
function MiMC7(inputs)
if len(inputs) <= 1 then
output = mimc7round(inputs[0], inputsinputs[0])
else
output = input[0]
for i = 1 to i < len(inputs) do
output = mimc7round(output, input[i])
endfor
endif
return output
function mimc7round(m, key)
rc = keccak256(SEED)
c = (m + key)^7 mod ORDER // round 1
for i = 2 to i < 92 do // round 2 ~ 91
c = (c + key + rc)^7 mod ORDER
rc = keccak256(rc)
endfor
output = (c + key + m + key) mod ORDER
return output
Poseidon is mapped to Opcode 0x14.
The Poseidon protocol referred to https://github.com/iden3/go-iden3-crypto/tree/master/poseidon
For prerequisites and detailed build instructions please read the Installation Instructions.
Building geth
requires both a Go (version 1.16 or later) and a C compiler. You can install
them using your favourite package manager. Once the dependencies are installed, run
make geth
or, to build the full suite of utilities:
make all
To do
First setup & start :
bash script.sh setup start
Restart Geth :
bash script.sh start
Attach Geth :
bash script.sh console
Stop Geth :
bash script.sh stop
View log :
bash script.sh log
If modify Geth's options, change go-ethereum/genesis & go-ethereum/script.sh files.
The default options are:
Command | Description |
---|---|
chainId |
2757 |
http.corsdomain |
* |
http.port |
8545 |
http.addr |
0.0.0.0 |
http.api |
admin,eth,debug,miner,net,txpool,personal,web3 |
ws.corsdomain |
* |
ws.addr |
0.0.0.0 |
ws.port |
8545 |
ws.api |
admin,eth,debug,miner,net,txpool,personal,web3 |
The input data must padded the remaining left side of 32bytes to "0". (ex 0x01 -> 0x0000000000000000000000000000000000000000000000000000000000000001)
If solidity version order than v0.5.0, use "gas" instead of "gas()" as the first factor in the call function.
pragma solidity >=0.5.0
function callmimc(bytes32[] memory data) public returns (bytes32 result) {
uint256 len = data.length*32;
assembly {
let memPtr := mload(0x40)
let success := call(gas(), 0x13, 0, add(data, 0x20), len, memPtr, 0x20)
//solc -v < 0.5.0 let success := call(gas, 0x13, 0, add(data, 0x20), len, memPtr, 0x20)
switch success
case 0 {
revert(0,0)
} default {
result := mload(memPtr)
}
}
}
The input data must padded the remaining left side of 32bytes to "0". (ex 0x01 -> 0x0000000000000000000000000000000000000000000000000000000000000001)
If solidity version order than v0.5.0, use "gas" instead of "gas()" as the first factor in the call function.
pragma solidity >=0.5.0
function callposeidon(bytes32[] memory data) public returns (bytes32 result) {
uint256 len = data.length*32;
assembly {
let memPtr := mload(0x40)
let success := call(gas(), 0x14, 0, add(data, 0x20), len, memPtr, 0x20)
//let success := call(gas, 0x14, 0, add(data, 0x20), len, memPtr, 0x20)
switch success
case 0 {
revert(0,0)
} default {
result := mload(memPtr)
}
}
}