bosagora / commons-budget-contract Goto Github PK
View Code? Open in Web Editor NEWCommons Budget Contract Code
License: MIT License
Commons Budget Contract Code
License: MIT License
지금 현재 commitment 계산은 VoteraVote 에서 다음과 같이 하고 있습니다.
dataHash = keccak256(abi.encode(voteContract, _proposalID, _validator, _choices[i], _nonces[i]));
여기에서 voteContract는 address voteContract = address(this);
로 현재 contract의 주소를 사용하고 있는데
#11 과 같이 proxy를 사용하거나 다른 연유로 인해 외부에서 호출하는 contract 주소와 내부에서 처리하는 contract 주소가 다른 경우에 문제가 생길 수 있습니다.
해결 방안은
저는 1번 방안으로 하는 것이 좋을 것 같은데 의견 있으시면 알려주시기 바랍니다.
적은 수의 검증자만이 있는 초기 상황에서, 공격자가 검증자로 위장하여 커먼스 버짓의 함수들을 호출상황이 있을수 있다. 공격자의 목적은 자금의 탈취나 부당한 이득을 취하는 것이다. 따라서, 문제가 있을 수 있는 상황을 정리하고, 대응 필요시 방안을 정리하고, 최적의 방안을 구현한다.
추가적인 조사 진행 필요.
VoteraVote
의 addValidators
함수를 CommonsBudget
함수로 옮기고, 커먼스 버짓 관리자가 호출하도록 한다.addValidators
호출시, 각 검증자가 40K 보아를 가지고 있는지와 EOA 계정인지 확인한다. (optional)#14 의 하위 이슈로서 자금인출 가능여부를 확인하는 다음의 함수를 구현합니다. 컨트랙트 사이즈 이슈로 구현이 안되었으며, #11 이슈가 해결되면서 진행할 예정입니다.
// 해당 제안에 대한 인출여부를 확인하는 함수입니다. 리턴되는 code의 값이 "W00" 일때만 인출이 가능합니다.
function checkWithdrawState(bytes32 _proposalID) external returns (string code, uint256 countingFinishTime);
EDIT
withdraw
함수도 원래의 설계대로 다음과 같이 구현하려고 했으나 트랜잭션을 발생하는 함수이기 때문에 리턴값을 제공하지 않는 기존의 구현을 유지 한다.
// 해당 제안에 대해서 펀딩자금을 인출하는 코드입니다.
function withdraw(bytes32 _proposalID) external returns;
컨트랙트 VoteraVote의 함수 countVote에서 투표용지를 집계한 후 커먼스버짓 컨트랙트의 함수 finishVote()를 호출한다.
다음 기능을 커먼스버짓 컨트랙트에 구현한다.
현재 CommonsBuget은 제안 금액 인출시에 발생하는 FundTransfer
Event 만을 가지고 있다. 다음의 상태에 대한 이벤트의 추가가 필요하다.
// @notice This event is emitted when a assessment is finished
// @param proposalID id of proposal
event AssessmentFinish(bytes32 proposalID, bool assessResult);
// @notice This event is emitted when a vote counting is finished
// @param proposalID id of proposal
event VoteCountingFinish(bytes32 proposalID, bool countingResult);
// @notice This event is emitted when funding is refused by the owner
// @param proposalID id of proposal
event FundWithdrawReject(bytes32 proposalID);
// @notice This event is emitted when funding is allowed by the owner
// @param proposalID id of proposal
event FundWithdrawAllow(bytes32 proposalID);
Definition of done:
제안에 대한 데이터를 유지하면서도, 제안을 처리하는 알고리즘을 변경할 필요가 있으므로 업그레이드 가능한 컨트랙트에 대해서 검토가 필요하다.
현재 진행되는 CommonsBudget
컨트랙트의 구현에서도 다음의 룰을 컨트랙트 오너가 수정할 수 있다.
하지만, 이외의 변경에 대해서는 예측할 수 없으므로, 업그레이드 가능한 컨트랙트가 필요할 수 있으며 다음과 같은 composition
방식을 고려할 수 있다. 이외에도 inheritance
방식과 proxy contract
방식이 있다.
contract ProposalStorage is Ownable {
mapping(bytes32 => ProposalData) private proposalMaps;
function saveProposalData(...) public { ... }
}
contract CommonsBudget is Ownable, IERC165, ICommonsBudget {
ProposalStorage store;
constructor (address storage) {
store = ProposalStorage(storage);
}
function createFundProposal(...) external payable override onlyInvalidaProposal(_proposalID) {
store.saveProposalData(...);
}
function createSystemProposal(...) external payable override onlyInvalidaProposal(_proposalID) {
store.saveProposalData(...);
}
}
컨트랙트 사이즈 이슈때문에 제거된 다음의 정책 변수 세팅함수를 복원해야 합니다.
setFundProposalFeePermil
, setSystemProposalFee
, setVoteQuorumFactor
, setVoterFee
#11 이슈가 컨트랙트 분리와 관련이 있어서 함께 진행될 예정입니다.
CommonsBudget.createFundProposal()이 호출되었을 때, 펀딩금액이 커먼스버짓보다 작거나 같을 경우에만 허용되도록 한다.
다음 조건일 때 펀딩제안에 대한 펀딩금액을 지급받을 수 있도록 합니다.
거부권을 행사할 수 조건은 다음과 같습니다.
이 거부권을 행사할 수 있는 권한을 가진 주소를 추가하고 제거하는 메소드를 추가합니다.
지금까지 hardhat 네트워크를 기반으로 많아야 100명 정도의 검증자로 테스트를 진행하였다. 이 테스트들을 DevNet과 TestNet 네트워트에서 진행할 수 있도록 하는, 1000명 이상의 검증자를 기반으로 진행될 수 있는 테스트 코드를 작성한다.
기존의 테스트 코드를 활용하기에는 중복되는 내용이 많기 때문에 따로 대용량 검증자을 가지고 테스트 네트워크(DevNet, TestNet) 상에서 테스트할 수 있는 테스트 코드를 작성한다.
Definition of done:
validator
정보 json 파일로부터 1000명 이상의 검증자 정보 만들기인출 거부권에 대해서 취소기간이 개표후 24시간으로 제한되어 있다.
이 코멘트에 제시된 의견에 따라 7일로 변경한다.
Definition of done:
현재 구현되어 있는 CommonsBudget 컨트랙트에 탈중화 내용을 반영하기 위한 다음의 작업을 진행한다.
Definition of done:
고려할 사항
현재 VoteState는 다음과 같이 정의되어 있다.
enum VoteState {
INVALID,
CREATED,
RUNNING,
FINISHED
}
현재의 구현에서 setupVoteInfo
함수에서 다음과 같이 투표 상태를 VoteState.RUNNING
으로 세팅한다.
voteInfos[_proposalID].state = VoteState.RUNNING;
현재 #15 에서 투표하기 시작하기 전에, 검증자 비용을 전달하는 것으로 구현하고 있다. 따라서, RUNNING
의 상태는 검증자들에게 투표 비용을 모두 지불한 이후에 설정되고, 기존의 RUNNING
을 사용하던 부분에 대해서는 READY
와 같은 추가적인 상태가 필요할 것으로 보인다. CommonsBudget은 검증자들에게 투표비용을 모두 지불했는지를 체크할 수 있는 isVoteFeePaid
함수를 제공한다.
추가적으로 setupVoteInfo
라는 함수명 대신 readyToVote
나 setReadyVote
같이 제안 프로세스 상에서의 하나의 상태를 지정하는 의미를 가진 함수명으로 변경되어야 할 것으로 보인다.
다른 의견이나 추가적인 의견이 있으면 말씀해 주세요.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.