Address Contract Partially Verified
Address
0xC735478EF7562ecc37662FC7c5e521eb835F9Dab
Balance
0 ETH
Nonce
1
Code Size
7647 bytes
Creator
0x70aD4814...53dd at tx 0x9fc35816...610a77
Indexed Transactions
0
Contract Bytecode
7647 bytes
0x608060405234801561001057600080fd5b50600436106101165760003560e01c80639f06ddf8116100a2578063df97174b11610071578063df97174b1461068d578063e08bf6ea146106b3578063e3cb9f62146106e5578063e5a2b5d214610aa3578063f2b5330714610aab57610116565b80639f06ddf81461066d578063b56561fe14610675578063b9b8af0b1461067d578063d907813c1461068557610116565b8063452a9320116100e9578063452a9320146102435780635429ddcc1461026757806369dd39081461029957806373b20547146102a15780638f32a31b146102a957610116565b8063011b21741461011b5780631762d25a146101535780631a172ea6146102015780632fcb4f041461021d575b600080fd5b6101416004803603602081101561013157600080fd5b50356001600160a01b0316610ab3565b60408051918252519081900360200190f35b6101ff6004803603604081101561016957600080fd5b810190602081018135600160201b81111561018357600080fd5b82018360208201111561019557600080fd5b803590602001918460208302840111600160201b831117156101b657600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505090356001600160a01b03169150610ace9050565b005b610209610bff565b604080519115158252519081900360200190f35b6101ff6004803603602081101561023357600080fd5b50356001600160a01b0316610c0d565b61024b610c90565b604080516001600160a01b039092168252519081900360200190f35b6101ff6004803603606081101561027d57600080fd5b506001600160a01b038135169060208101359060400135610ca5565b610141610d1c565b610141610d22565b6101ff60048036036101408110156102c057600080fd5b810190602081018135600160201b8111156102da57600080fd5b8201836020820111156102ec57600080fd5b803590602001918460208302840111600160201b8311171561030d57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561035c57600080fd5b82018360208201111561036e57600080fd5b803590602001918460208302840111600160201b8311171561038f57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435959094909350604081019250602001359050600160201b8111156103e657600080fd5b8201836020820111156103f857600080fd5b803590602001918460208302840111600160201b8311171561041957600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561046857600080fd5b82018360208201111561047a57600080fd5b803590602001918460208302840111600160201b8311171561049b57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156104ea57600080fd5b8201836020820111156104fc57600080fd5b803590602001918460208302840111600160201b8311171561051d57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561056c57600080fd5b82018360208201111561057e57600080fd5b803590602001918460208302840111600160201b8311171561059f57600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156105ee57600080fd5b82018360208201111561060057600080fd5b803590602001918460208302840111600160201b8311171561062157600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955050823593505050602001356001600160a01b0316610d28565b6101ff6110b4565b610141611121565b610209611127565b6101ff611130565b610141600480360360208110156106a357600080fd5b50356001600160a01b03166111a6565b6101ff600480360360608110156106c957600080fd5b506001600160a01b0381351690602081013590604001356111b8565b6101ff60048036036101208110156106fc57600080fd5b810190602081018135600160201b81111561071657600080fd5b82018360208201111561072857600080fd5b803590602001918460208302840111600160201b8311171561074957600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b81111561079857600080fd5b8201836020820111156107aa57600080fd5b803590602001918460208302840111600160201b831117156107cb57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435959094909350604081019250602001359050600160201b81111561082257600080fd5b82018360208201111561083457600080fd5b803590602001918460208302840111600160201b8311171561085557600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156108a457600080fd5b8201836020820111156108b657600080fd5b803590602001918460208302840111600160201b831117156108d757600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092958435959094909350604081019250602001359050600160201b81111561092e57600080fd5b82018360208201111561094057600080fd5b803590602001918460208302840111600160201b8311171561096157600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b8111156109b057600080fd5b8201836020820111156109c257600080fd5b803590602001918460208302840111600160201b831117156109e357600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295949360208101935035915050600160201b811115610a3257600080fd5b820183602082011115610a4457600080fd5b803590602001918460208302840111600160201b83111715610a6557600080fd5b9190808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152509295506112c9945050505050565b61014161156a565b610141611570565b6001600160a01b031660009081526001602052604090205490565b6006546201000090046001600160a01b03163314610b27576040805162461bcd60e51b81526020600482015260116024820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604482015290519081900360640190fd5b6006805461ff001960ff199091166001171661010017905560005b8251811015610bfa576000838281518110610b5957fe5b60200260200101519050610bf183826001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015610bb457600080fd5b505afa158015610bc8573d6000803e3d6000fd5b505050506040513d6020811015610bde57600080fd5b50516001600160a01b0384169190611576565b50600101610b42565b505050565b600654610100900460ff1681565b6006546201000090046001600160a01b03163314610c66576040805162461bcd60e51b81526020600482015260116024820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604482015290519081900360640190fd5b600680546001600160a01b03909216620100000262010000600160b01b0319909216919091179055565b6006546201000090046001600160a01b031681565b610cba6001600160a01b0384163330846115c8565b600354610cc8906001611628565b60038190556040805183815260208101929092528051849233926001600160a01b038816927fdfe6da02caa4d216f74297b7a3ac766bfdef0fe61309a848f8feda49c0806d2a9281900390910190a4505050565b60045481565b60035481565b60065460ff1615610d72576040805162461bcd60e51b815260206004820152600f60248201526e18dbdb9d1c9858dd081a185b1d1959608a1b604482015290519081900360640190fd5b6001600160a01b0381166000908152600160205260409020548211610dc85760405162461bcd60e51b8152600401808060200182810382526036815260200180611c8e6036913960400191505060405180910390fd5b88518a51148015610dda575086518a51145b8015610de7575085518a51145b8015610df4575084518a51145b610e45576040805162461bcd60e51b815260206004820152601f60248201527f4d616c666f726d65642063757272656e742076616c696461746f722073657400604482015290519081900360640190fd5b600054610e568b8b8b600454611689565b14610e925760405162461bcd60e51b815260040180806020018281038252603f815260200180611c4f603f913960400191505060405180910390fd5b8251845114610ee8576040805162461bcd60e51b815260206004820152601f60248201527f4d616c666f726d6564206261746368206f66207472616e73616374696f6e7300604482015290519081900360640190fd5b610fe18a8a8989896004546f0e8e4c2dce6c2c6e8d2dedc84c2e8c6d60831b8b8b8b8b604051602001808781526020018681526020018060200180602001858152602001846001600160a01b03168152602001838103835287818151815260200191508051906020019060200280838360005b83811015610f73578181015183820152602001610f5b565b50505050905001838103825286818151815260200191508051906020019060200280838360005b83811015610fb2578181015183820152602001610f9a565b505050509050019850505050505050505060405160208183030381529060405280519060200120600554611773565b6001600160a01b03811660009081526001602052604081208390555b84518110156110525761104a84828151811061101557fe5b602002602001015186838151811061102957fe5b6020026020010151846001600160a01b03166115769092919063ffffffff16565b600101610ffd565b50600354611061906001611628565b6003819055604080519182525133916001600160a01b0384169185917f39e7a6d1d0bed258d48d61a3f17fe1250f6360d4bb71d8d8401f1e9020a84937919081900360200190a450505050505050505050565b6006546201000090046001600160a01b0316331461110d576040805162461bcd60e51b81526020600482015260116024820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604482015290519081900360640190fd5b6006805460ff19811660ff90911615179055565b60025481565b60065460ff1681565b6006546201000090046001600160a01b03163314611189576040805162461bcd60e51b81526020600482015260116024820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604482015290519081900360640190fd5b6006805461ff001981166101009182900460ff1615909102179055565b60016020526000908152604090205481565b60065460ff1615611202576040805162461bcd60e51b815260206004820152600f60248201526e18dbdb9d1c9858dd081a185b1d1959608a1b604482015290519081900360640190fd5b600654610100900460ff1615611252576040805162461bcd60e51b815260206004820152601060248201526f19195c1bdcda5d1cc81cdd1bdc1c195960821b604482015290519081900360640190fd5b6112676001600160a01b0384163330846115c8565b600354611275906001611628565b60038190556040805183815260208101929092528051849233926001600160a01b038816927f8a90c92ae4d3ad99d0e0af0871264ba019979b4532daba15508810d224e8bbf69281900390910190a4505050565b60065460ff1615611313576040805162461bcd60e51b815260206004820152600f60248201526e18dbdb9d1c9858dd081a185b1d1959608a1b604482015290519081900360640190fd5b8387116113515760405162461bcd60e51b8152600401808060200182810382526037815260200180611d496037913960400191505060405180910390fd5b87518951146113a7576040805162461bcd60e51b815260206004820152601b60248201527f4d616c666f726d6564206e65772076616c696461746f72207365740000000000604482015290519081900360640190fd5b845186511480156113b9575082518651145b80156113c6575081518651145b80156113d3575080518651145b611424576040805162461bcd60e51b815260206004820152601f60248201527f4d616c666f726d65642063757272656e742076616c696461746f722073657400604482015290519081900360640190fd5b600054611435878787600454611689565b146114715760405162461bcd60e51b815260040180806020018281038252603f815260200180611c4f603f913960400191505060405180910390fd5b60006114818a8a8a600454611689565b9050611494878786868686600554611773565b8060008190555087600281905550877fc6d025c076bafcdd040f00632d5e280b3a5188963f110f8c70c4f810184b30f38b8b604051808060200180602001838103835285818151815260200191508051906020019060200280838360005b8381101561150a5781810151838201526020016114f2565b50505050905001838103825284818151815260200191508051906020019060200280838360005b83811015611549578181015183820152602001611531565b5050505090500194505050505060405180910390a250505050505050505050565b60055481565b60005481565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610bfa9084906118a8565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526116229085906118a8565b50505050565b600082820183811015611682576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6000806918da1958dadc1bda5b9d60b21b60001b905060008382868989604051602001808681526020018581526020018481526020018060200180602001838103835285818151815260200191508051906020019060200280838360005b838110156116ff5781810151838201526020016116e7565b50505050905001838103825284818151815260200191508051906020019060200280838360005b8381101561173e578181015183820152602001611726565b505050509050019750505050505050506040516020818303038152906040528051906020012090508092505050949350505050565b6000805b885181101561185f5786818151811061178c57fe5b602002602001015160ff16600014611857576117f78982815181106117ad57fe5b6020026020010151858984815181106117c257fe5b60200260200101518985815181106117d657fe5b60200260200101518986815181106117ea57fe5b6020026020010151611959565b6118325760405162461bcd60e51b8152600401808060200182810382526023815260200180611cc46023913960400191505060405180910390fd5b87818151811061183e57fe5b602002602001015182019150828211156118575761185f565b600101611777565b5081811161189e5760405162461bcd60e51b815260040180806020018281038252603c815260200180611d0d603c913960400191505060405180910390fd5b5050505050505050565b60606118fd826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611a319092919063ffffffff16565b805190915015610bfa5780806020019051602081101561191c57600080fd5b5051610bfa5760405162461bcd60e51b815260040180806020018281038252602a815260200180611d80602a913960400191505060405180910390fd5b6000808560405160200180807f19457468657265756d205369676e6564204d6573736167653a0a333200000000815250601c0182815260200191505060405160208183030381529060405280519060200120905060018186868660405160008152602001604052604051808581526020018460ff1681526020018381526020018281526020019450505050506020604051602081039080840390855afa158015611a07573d6000803e3d6000fd5b505050602060405103516001600160a01b0316876001600160a01b03161491505095945050505050565b6060611a408484600085611a48565b949350505050565b606082471015611a895760405162461bcd60e51b8152600401808060200182810382526026815260200180611ce76026913960400191505060405180910390fd5b611a9285611ba4565b611ae3576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310611b225780518252601f199092019160209182019101611b03565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611b84576040519150601f19603f3d011682016040523d82523d6000602084013e611b89565b606091505b5091509150611b99828286611baa565b979650505050505050565b3b151590565b60608315611bb9575081611682565b825115611bc95782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611c13578181015183820152602001611bfb565b50505050905090810190601f168015611c405780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe537570706c6965642063757272656e742076616c696461746f727320616e6420706f7765727320646f206e6f74206d6174636820636865636b706f696e742e4e6577206261746368206e6f6e6365206d7573742062652067726561746572207468616e207468652063757272656e74206e6f6e636556616c696461746f72207369676e617475726520646f6573206e6f74206d617463682e416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c5375626d69747465642076616c696461746f7220736574207369676e61747572657320646f206e6f74206861766520656e6f75676820706f7765722e4e65772076616c736574206e6f6e6365206d7573742062652067726561746572207468616e207468652063757272656e74206e6f6e63655361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a26469706673582212200614f7554c6795b7e2139662a075cf61276ccccfed8888b94bd358adc51aa37464736f6c634300060c0033
Verified Source Code Partial Match
Compiler: v0.6.12+commit.27d51765
EVM: istanbul
Optimization: Yes (200 runs)
Peggy.sol 424 lines
pragma solidity ^0.6.0;
import "./SafeMath.sol";
import "./IERC20.sol";
import "./SafeERC20.sol";
contract Peggy {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// These are updated often
bytes32 public state_lastValsetCheckpoint;
mapping(address => uint256) public state_lastBatchNonces;
uint256 public state_lastValsetNonce = 0;
uint256 public state_lastEventNonce = 0;
// These are set once at initialization
bytes32 public state_peggyId;
uint256 public state_powerThreshold;
bool public halted = false;
bool public depositsStopped = false;
address public guardian;
event TransactionBatchExecutedEvent(
uint256 indexed _batchNonce,
address indexed _token,
address indexed _sender,
uint256 _eventNonce
);
event SendToHubEvent(
address indexed _tokenContract,
address indexed _sender,
bytes32 indexed _destination,
uint256 _amount,
uint256 _eventNonce
);
event SendToMinterEvent(
address indexed _tokenContract,
address indexed _sender,
bytes32 indexed _destination,
uint256 _amount,
uint256 _eventNonce
);
event ValsetUpdatedEvent(
uint256 indexed _newValsetNonce,
address[] _validators,
uint256[] _powers
);
function lastBatchNonce(address _erc20Address) public view returns (uint256) {
return state_lastBatchNonces[_erc20Address];
}
// Utility function to verify geth style signatures
function verifySig(
address _signer,
bytes32 _theHash,
uint8 _v,
bytes32 _r,
bytes32 _s
) private pure returns (bool) {
bytes32 messageDigest = keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", _theHash)
);
return _signer == ecrecover(messageDigest, _v, _r, _s);
}
// Make a new checkpoint from the supplied validator set
// A checkpoint is a hash of all relevant information about the valset. This is stored by the contract,
// instead of storing the information directly. This saves on storage and gas.
// The format of the checkpoint is:
// h(peggyId, "checkpoint", valsetNonce, validators[], powers[])
// Where h is the keccak256 hash function.
// The validator powers must be decreasing or equal. This is important for checking the signatures on the
// next valset, since it allows the caller to stop verifying signatures once a quorum of signatures have been verified.
function makeCheckpoint(
address[] memory _validators,
uint256[] memory _powers,
uint256 _valsetNonce,
bytes32 _peggyId
) private pure returns (bytes32) {
// bytes32 encoding of the string "checkpoint"
bytes32 methodName = 0x636865636b706f696e7400000000000000000000000000000000000000000000;
bytes32 checkpoint = keccak256(
abi.encode(_peggyId, methodName, _valsetNonce, _validators, _powers)
);
return checkpoint;
}
function checkValidatorSignatures(
// The current validator set and their powers
address[] memory _currentValidators,
uint256[] memory _currentPowers,
// The current validator's signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s,
// This is what we are checking they have signed
bytes32 _theHash,
uint256 _powerThreshold
) private pure {
uint256 cumulativePower = 0;
for (uint256 i = 0; i < _currentValidators.length; i++) {
// If v is set to 0, this signifies that it was not possible to get a signature from this validator and we skip evaluation
// (In a valid signature, it is either 27 or 28)
if (_v[i] != 0) {
// Check that the current validator has signed off on the hash
require(
verifySig(_currentValidators[i], _theHash, _v[i], _r[i], _s[i]),
"Validator signature does not match."
);
// Sum up cumulative power
cumulativePower = cumulativePower + _currentPowers[i];
// Break early to avoid wasting gas
if (cumulativePower > _powerThreshold) {
break;
}
}
}
// Check that there was enough power
require(
cumulativePower > _powerThreshold,
"Submitted validator set signatures do not have enough power."
);
// Success
}
// This updates the valset by checking that the validators in the current valset have signed off on the
// new valset. The signatures supplied are the signatures of the current valset over the checkpoint hash
// generated from the new valset.
// Anyone can call this function, but they must supply valid signatures of state_powerThreshold of the current valset over
// the new valset.
function updateValset(
// The new version of the validator set
address[] memory _newValidators,
uint256[] memory _newPowers,
uint256 _newValsetNonce,
// The current validators that approve the change
address[] memory _currentValidators,
uint256[] memory _currentPowers,
uint256 _currentValsetNonce,
// These are arrays of the parts of the current validator's signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s
) public {
// CHECKS
require(!halted, "contract halted");
// Check that the valset nonce is greater than the old one
require(
_newValsetNonce > _currentValsetNonce,
"New valset nonce must be greater than the current nonce"
);
// Check that new validators and powers set is well-formed
require(_newValidators.length == _newPowers.length, "Malformed new validator set");
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
require(
_currentValidators.length == _currentPowers.length &&
_currentValidators.length == _v.length &&
_currentValidators.length == _r.length &&
_currentValidators.length == _s.length,
"Malformed current validator set"
);
// Check that the supplied current validator set matches the saved checkpoint
require(
makeCheckpoint(
_currentValidators,
_currentPowers,
_currentValsetNonce,
state_peggyId
) == state_lastValsetCheckpoint,
"Supplied current validators and powers do not match checkpoint."
);
// Check that enough current validators have signed off on the new validator set
bytes32 newCheckpoint = makeCheckpoint(
_newValidators,
_newPowers,
_newValsetNonce,
state_peggyId
);
checkValidatorSignatures(
_currentValidators,
_currentPowers,
_v,
_r,
_s,
newCheckpoint,
state_powerThreshold
);
// ACTIONS
// Stored to be used next time to validate that the valset
// supplied by the caller is correct.
state_lastValsetCheckpoint = newCheckpoint;
// Store new nonce
state_lastValsetNonce = _newValsetNonce;
// LOGS
emit ValsetUpdatedEvent(_newValsetNonce, _newValidators, _newPowers);
}
// submitBatch processes a batch of Hub -> Ethereum transactions by sending the tokens in the transactions
// to the destination addresses. It is approved by the current Hub validator set.
// Anyone can call this function, but they must supply valid signatures of state_powerThreshold of the current valset over
// the batch.
function submitBatch(
// The validators that approve the batch
address[] memory _currentValidators,
uint256[] memory _currentPowers,
uint256 _currentValsetNonce,
// These are arrays of the parts of the validators signatures
uint8[] memory _v,
bytes32[] memory _r,
bytes32[] memory _s,
// The batch of transactions
uint256[] memory _amounts,
address[] memory _destinations,
uint256 _batchNonce,
address _tokenContract
) public {
// CHECKS scoped to reduce stack depth
{
require(!halted, "contract halted");
// Check that the batch nonce is higher than the last nonce for this token
require(
state_lastBatchNonces[_tokenContract] < _batchNonce,
"New batch nonce must be greater than the current nonce"
);
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
require(
_currentValidators.length == _currentPowers.length &&
_currentValidators.length == _v.length &&
_currentValidators.length == _r.length &&
_currentValidators.length == _s.length,
"Malformed current validator set"
);
// Check that the supplied current validator set matches the saved checkpoint
require(
makeCheckpoint(
_currentValidators,
_currentPowers,
_currentValsetNonce,
state_peggyId
) == state_lastValsetCheckpoint,
"Supplied current validators and powers do not match checkpoint."
);
// Check that the transaction batch is well-formed
require(
_amounts.length == _destinations.length,
"Malformed batch of transactions"
);
// Check that enough current validators have signed off on the transaction batch and valset
checkValidatorSignatures(
_currentValidators,
_currentPowers,
_v,
_r,
_s,
// Get hash of the transaction batch and checkpoint
keccak256(
abi.encode(
state_peggyId,
// bytes32 encoding of "transactionBatch"
0x7472616e73616374696f6e426174636800000000000000000000000000000000,
_amounts,
_destinations,
_batchNonce,
_tokenContract
)
),
state_powerThreshold
);
// ACTIONS
// Store batch nonce
state_lastBatchNonces[_tokenContract] = _batchNonce;
{
// Send transaction amounts to destinations
for (uint256 i = 0; i < _amounts.length; i++) {
IERC20(_tokenContract).safeTransfer(_destinations[i], _amounts[i]);
}
}
}
// LOGS scoped to reduce stack depth
{
state_lastEventNonce = state_lastEventNonce.add(1);
emit TransactionBatchExecutedEvent(_batchNonce, _tokenContract, msg.sender, state_lastEventNonce);
}
}
function sendToHub(
address _tokenContract,
bytes32 _destination,
uint256 _amount
) public {
require(!halted, "contract halted");
require(!depositsStopped, "deposits stopped");
IERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);
state_lastEventNonce = state_lastEventNonce.add(1);
emit SendToHubEvent(
_tokenContract,
msg.sender,
_destination,
_amount,
state_lastEventNonce
);
}
function sendToMinter(
address _tokenContract,
bytes32 _destination,
uint256 _amount
) public {
IERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);
state_lastEventNonce = state_lastEventNonce.add(1);
emit SendToMinterEvent(
_tokenContract,
msg.sender,
_destination,
_amount,
state_lastEventNonce
);
}
function toggleHalt() public {
require(msg.sender == guardian, "permission denied");
halted = !halted;
}
function toggleDeposits() public {
require(msg.sender == guardian, "permission denied");
depositsStopped = !depositsStopped;
}
function changeGuardian(address _guardian) public {
require(msg.sender == guardian, "permission denied");
guardian = _guardian;
}
function panicHalt(address[] memory _tokenContracts, address _safeAddress) public {
require(msg.sender == guardian, "permission denied");
halted = true;
depositsStopped = true;
for (uint256 i = 0; i < _tokenContracts.length; i++) {
IERC20 token = IERC20(_tokenContracts[i]);
token.safeTransfer(_safeAddress, token.balanceOf(address(this)));
}
}
constructor(
// A unique identifier for this peggy instance to use in signatures
bytes32 _peggyId,
// How much voting power is needed to approve operations
uint256 _powerThreshold,
// The validator set
address[] memory _validators,
uint256[] memory _powers,
address _guardian
) public {
// CHECKS
// Check that validators, powers, and signatures (v,r,s) set is well-formed
require(_validators.length == _powers.length, "Malformed current validator set");
// Check cumulative power to ensure the contract has sufficient power to actually
// pass a vote
uint256 cumulativePower = 0;
for (uint256 i = 0; i < _powers.length; i++) {
cumulativePower = cumulativePower + _powers[i];
if (cumulativePower > _powerThreshold) {
break;
}
}
require(
cumulativePower > _powerThreshold,
"Submitted validator set signatures do not have enough power."
);
bytes32 newCheckpoint = makeCheckpoint(_validators, _powers, 0, _peggyId);
// ACTIONS
state_peggyId = _peggyId;
state_powerThreshold = _powerThreshold;
state_lastValsetCheckpoint = newCheckpoint;
guardian = _guardian;
// LOGS
emit ValsetUpdatedEvent(0, _validators, _powers);
}
}
IERC20.sol 80 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./SafeMath.sol";
import "./Address.sol";
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
Address.sol 189 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
SafeMath.sol 214 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
SafeERC20.sol 75 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./SafeMath.sol";
import "./Address.sol";
import "./IERC20.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Read Contract
depositsStopped 0x1a172ea6 → bool
guardian 0x452a9320 → address
halted 0xb9b8af0b → bool
lastBatchNonce 0x011b2174 → uint256
state_lastBatchNonces 0xdf97174b → uint256
state_lastEventNonce 0x73b20547 → uint256
state_lastValsetCheckpoint 0xf2b53307 → bytes32
state_lastValsetNonce 0xb56561fe → uint256
state_peggyId 0x69dd3908 → bytes32
state_powerThreshold 0xe5a2b5d2 → uint256
Write Contract 8 functions
These functions modify contract state and require a wallet transaction to execute.
changeGuardian 0x2fcb4f04
address _guardian
panicHalt 0x1762d25a
address[] _tokenContracts
address _safeAddress
sendToHub 0xe08bf6ea
address _tokenContract
bytes32 _destination
uint256 _amount
sendToMinter 0x5429ddcc
address _tokenContract
bytes32 _destination
uint256 _amount
submitBatch 0x8f32a31b
address[] _currentValidators
uint256[] _currentPowers
uint256 _currentValsetNonce
uint8[] _v
bytes32[] _r
bytes32[] _s
uint256[] _amounts
address[] _destinations
uint256 _batchNonce
address _tokenContract
toggleDeposits 0xd907813c
No parameters
toggleHalt 0x9f06ddf8
No parameters
updateValset 0xe3cb9f62
address[] _newValidators
uint256[] _newPowers
uint256 _newValsetNonce
address[] _currentValidators
uint256[] _currentPowers
uint256 _currentValsetNonce
uint8[] _v
bytes32[] _r
bytes32[] _s
Recent Transactions
No transactions found for this address